HEX
Server: LiteSpeed
System: Linux shams.tasjeel.ae 5.14.0-611.5.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Nov 11 08:09:09 EST 2025 x86_64
User: infowars (1469)
PHP: 8.2.29
Disabled: NONE
Upload Files
File: //lib/python3.9/site-packages/jwcrypto/__pycache__/jwe.cpython-39.pyc
a

���e_�@sTddlZddlmZddlmZmZddlmZmZddlmZm	Z	ddlm
Z
mZddlm
Z
ddlmZd	Zed
ddd�ed
ddd�edddd�edddd�edddd�edddd�edddd�edddd�edddd�edddd�edddd�edddd�edddd�d�
Zgd�ZGdd�de�ZejZejZejZejZGdd�d�ZdS)�N)�common)�JWException�
JWKeyNotFound)�JWSEHeaderParameter�JWSEHeaderRegistry)�base64url_decode�base64url_encode)�json_decode�json_encode)�JWA)�JWKSetiZ	AlgorithmFTzEncryption AlgorithmzCompression AlgorithmzJWK Set URLzJSON Web KeyzKey IDz	X.509 URLzX.509 Certificate Chainz"X.509 Certificate SHA-1 Thumbprintz$X.509 Certificate SHA-256 Thumbprint�TypezContent TypeZCritical)
�alg�enc�zipZjkuZjwk�kidZx5uZx5cZx5tzx5t#S256�typZcty�crit)zRSA-OAEPzRSA-OAEP-256ZA128KWZA192KWZA256KW�dirzECDH-ESzECDH-ES+A128KWzECDH-ES+A192KWzECDH-ES+A256KWZ	A128GCMKWZ	A192GCMKWZ	A256GCMKWzPBES2-HS256+A128KWzPBES2-HS384+A192KWzPBES2-HS512+A256KWz
A128CBC-HS256z
A192CBC-HS384z
A256CBC-HS512ZA128GCMZA192GCMZA256GCMcs"eZdZdZd�fdd�	Z�ZS)�InvalidJWEDatazvInvalid JWE Object.

    This exception is raised when the JWE Object is invalid and/or
    improperly formatted.
    Ncs:d}|r|}nd}|r&|dt|�7}tt|��|�dS)Nz!Unknown Data Verification Failurez {%s})�str�superr�__init__)�self�message�	exception�msg��	__class__��0/usr/lib/python3.9/site-packages/jwcrypto/jwe.pyr;szInvalidJWEData.__init__)NN)�__name__�
__module__�__qualname__�__doc__r�
__classcell__rrrr r4src@s�eZdZdZd/dd�Zdd�Zdd�Zed	d
��Zej	dd
��Zdd
�Z
d0dd�Zdd�Zdd�Z
d1dd�Zd2dd�Zdd�Zdd�Zdd�Zdd �Zd3d!d"�Zed#d$��Zed%d&��Zed'd(��Zd)d*�Zd+d,�Zd-d.�ZdS)4�JWEzGJSON Web Encryption object

    This object represent a JWE token.
    Nc		Cs�d|_i|_d|_tt�|_|r,|j�|�|durRt|t�rF||_n|�	d�|_d|_
d|_|rl||jd<|r�t|t�r�t
|�}nt|�||jd<|r�t|t�r�t
|�}nt|�||jd<|r�||_|r�|j||d�n|r�td��dS)aBCreates a JWE token.

        :param plaintext(bytes): An arbitrary plaintext to be encrypted.
        :param protected: A JSON string with the protected header.
        :param unprotected: A JSON string with the shared unprotected header.
        :param aad(bytes): Arbitrary additional authenticated data
        :param algs: An optional list of allowed algorithms
        :param recipient: An optional, default recipient key
        :param header: An optional header for the default recipient
        :param header_registry: Optional additions to the header registry
        N�utf-8�aad�	protected�unprotected)�headerz-Header is allowed only with default recipient)�
_allowed_algs�objects�	plaintextr�JWEHeaderRegistry�header_registry�update�
isinstance�bytes�encode�cek�
decryptlog�dictr
r	�
add_recipient�
ValueError)	rr.r)r*r(�algsZ	recipientr+r0rrr rSs<








zJWE.__init__cCs$|jpt}||vrtd��t�|�S�NzAlgorithm not allowed)r,�default_allowed_algs�InvalidJWEOperationrZkeymgmt_alg�r�name�allowedrrr �_jwa_keymgmt�s
zJWE._jwa_keymgmtcCs$|jpt}||vrtd��t�|�Sr;)r,r<r=rZencryption_algr>rrr �_jwa_enc�s
zJWE._jwa_enccCs|jr|jStSdS)z�Allowed algorithms.

        The list of allowed algorithms.
        Can be changed by setting a list of algorithm names.
        N)r,r<�rrrr �allowed_algs�szJWE.allowed_algscCst|t�std��||_dS)NzAllowed Algs must be a list)r2�list�	TypeErrorr,)rr:rrr rD�s
cCs4t|���D]}||vrtd|��q|�|�|S)NzDuplicate header: "%s")rE�keysrr1)rZh1Zh2�krrr �_merge_headers�s

zJWE._merge_headerscCshi}d|jvr(t|jd�}|�||�}d|jvrLt|jd�}|�||�}|rdt|�}|�||�}|S)Nr)r*)r-r	rI)rr+�jh�phZuhZrhrrr �_get_jose_header�s

zJWE._get_jose_headercCsT|�dd�}|durtd��|�|�}|�dd�}|durBtd��|�|�}||fS)NrzMissing "alg" from headersrzMissing "enc" from headers)�getrrArB)rrJZalgnamerZencnamerrrr �_get_alg_enc_from_headers�s

zJWE._get_alg_enc_from_headersc
Cs�t|j�dd��}d|jvr2|dt|jd�7}|�d�}|�dd�}|dkrft�|j�dd	�}n|durv|j}ntd
��|�|j	||�\}}}	||jd<||jd<|	|jd
<dS)Nr)�r(�.r'r�DEF�����Unknown compression�iv�
ciphertext�tag)
rr-rMr4�zlib�compressr.r9Zencryptr5)
rrrrJr(rY�datarUrVrWrrr �_encrypt�s



zJWE._encryptcCs�|jdurtd��t|jt�s&td��t|t�r8t|�}|�|�}|�|�\}}i}|r`||d<|�||j	|j
|�}|d|_
d|vr�|d|d<d|vr�t|�dd��}|�
||d�}	t|	�|d<d	|jvr�|�|||�d
|jvr�|jd
�|�n�d|jv�sd|jv�rzg|jd
<i}
d|jv�r<|j�d�|
d<d|jv�rX|j�d�|
d<|jd
�|
�|jd
�|�n|j�|�dS)aEncrypt the plaintext with the given key.

        :param key: A JWK key or password of appropriate type for the 'alg'
         provided in the JOSE Headers.
        :param header: A JSON string representing the per-recipient header.

        :raises ValueError: if the plaintext is missing or not of type bytes.
        :raises ValueError: if the compression type is unknown.
        :raises InvalidJWAAlgorithm: if the 'alg' provided in the JOSE
         headers is missing or unknown, or otherwise not implemented.
        NzMissing plaintextzPlaintext must be 'bytes'r+r5Zek�
encrypted_keyz{}rV�
recipients)r.r9r2r3r7r
rLrN�wrap�
wrap_key_sizer5r	rMrIr-r[�append�popr1)r�keyr+rJrr�rec�wrapped�hZnh�nrrr r8�sB






zJWE.add_recipientFc
	Cs�d|jvrtd��|�rbdD]}||jvrtd|��qd|jvrLtd��n,t|jd�}dD]}||vr^td|��q^d	|jvr�t|jd	�d
kr�td��|jd	d}n|j}d
|v�rt|d
�}t|jd�}|�||�}t|�|jd<|��}|�|�\}	}
|�|	|
|�|d
=d�	t
|jd�t
|�dd��t
|jd�t
|jd�t
|jd�g�S|j}t
|d�t
|d�t
|jd�d�}
d|v�r�t
|d�|
d<d|v�r�t|d�|
d<d|v�r�t
|d�|
d<d	|v�rFg|
d	<|d	D]L}i}d|v�rt
|d�|d<d
|v�r2t|d
�|d
<|
d	�|��q�n4d|v�r`t
|d�|
d<d
|v�rzt|d
�|
d
<t|
�SdS)a�Serializes the object into a JWE token.

        :param compact(boolean): if True generates the compact
         representation, otherwise generates a standard JSON format.

        :raises InvalidJWEOperation: if the object cannot be serialized
         with the compact representation and `compact` is True.
        :raises InvalidJWEOperation: if no recipients have been added
         to the object.

        :return: A json formatted string or a compact representation string
        :rtype: `str`
        rV�No available ciphertext)r(r*z9Can't use compact encoding when the '%s' parameter is setr)z4Can't use compact encoding without protected headers)rrz@Can't use compact encoding, '%s' must be in the protected headerr]�zInvalid number of recipientsrr+rPr\rOrUrW)rVrUrWr*r(N)
r-r=r	�lenrIr
rLrNr[�joinrrMr`)
rZcompactZinvalidrK�requiredrcreZnphrJrr�obj�errr �	serializes�

��
���

�

�





�


�
z
JWE.serializecCs>|D]4}||jvr td|��q|j|jstd|��qdS)NzUnknown critical header: "%s"z!Unsupported critical header: "%s")r0rZ	supported)rrrHrrr �_check_critds
�zJWE._check_critc
Cs:|�||j||�}
|�|
||||	�}|j�d�|
|_|S)N�Success)�unwrapr_�decryptr6r`r5)rrrrbZenckeyr+r(rUrVrWr5rZrrr �_unwrap_decryptms
zJWE._unwrap_decryptc
CsN|�|�dd��}|�|�di��|D]$}||jvr(|j�||�s(td��q(|�|�dd��}|�|�dd��}t|j	�dd��}d|j	vr�|d	t|j	d�7}|�
d
�}t|t��r�|}d|j
vr�|�|j
d�}	|	s�td�|j
d���|	}|D]�}
zL|�|||
|�d
d�|||j	d|j	d|j	d�	}|j�d�W�q�Wq�t�y�}z4|
�d|
���}
|j�d�|
t|���WYd}~q�d}~00q�d|jv�r�td��n4|�||||�d
d�|||j	d|j	d|j	d�	}|�dd�}|dk�r0t|�tk�rtddt�d���t�|tj�|_n|du�rB||_ntd��dS)Nr+rzFailed header checkrrr)rOr(rPr'rzKey ID {} not in key setr\�rUrVrWrpzKey [{}] failed: [{}]zNo working key found in key setrrQz+Compressed data exceeds maximum allowedsizez (�)rT)rLrMror0Zcheck_headerrrArBrr-r4r2r�jose_headerZget_keysr�formatrsr6r`�	ExceptionZ
thumbprint�reprri�default_max_compressed_sizerX�
decompress�	MAX_WBITSr.r9)rrbZpperJZhdrrrr(rGZkid_keysrHrZrmZkeyidrYrrr �_decryptvsp




�

�
�


�

��
zJWE._decryptcCsd|jvrtd��g|_d}d|jvr�|jdD]\}z|�||�Wq0ty�}z.t|t�rbd}|j�dt|��WYd}~q0d}~00q0nZz|�||j�WnFty�}z.t|t�r�d}|j�dt|��WYd}~n
d}~00|j	�s|r�td��t
d	t|j���dS)
a@Decrypt a JWE token.

        :param key: The (:class:`jwcrypto.jwk.JWK`) decryption key.
        :param key: A (:class:`jwcrypto.jwk.JWK`) decryption key,
         or a (:class:`jwcrypto.jwk.JWKSet`) that contains a key indexed
         by the 'kid' header or (deprecated) a string containing a password.

        :raises InvalidJWEOperation: if the key is not a JWK object.
        :raises InvalidJWEData: if the ciphertext can't be decrypted or
         the object is otherwise malformed.
        :raises JWKeyNotFound: if key is a JWKSet and the key is not found.
        rVrgFr]TzFailed: [%s]NzKey Not found in JWKSetz%No recipient matched the provided key)r-r=r6r}rxr2rr`ryr.r)rrbZ
missingkeyrcrmrrr rr�s0


.
*�zJWE.decryptc

CsNi|_d|_d|_i}�z�z&t|�}t|d�|d<t|d�|d<t|d�|d<d|vrxt|d�}|�d�|d<d|vr�t|d�|d<d|vr�t|d�|d<d	|v�rg|d	<|d	D]F}i}d
|vr�t|d
�|d
<d|vr�t|d�|d<|d	�|�q�n4d
|v�r&t|d
�|d
<d|v�r@t|d�|d<Wn�t�y�}z�|�	d�}t
|�d
k�rtt�|�t|d�}|�d�|d<t|d�}	|	dk�r�t|d�|d
<t|d�|d<t|d�|d<t|d�|d<WYd}~n
d}~00||_Wn6t�y8}ztdt
|��|�WYd}~n
d}~00|�rJ|�|�dS)a�Deserialize a JWE token.

        NOTE: Destroys any current status and tries to import the raw
        JWE provided.

        If a key is provided a decryption step will be attempted after
        the object is successfully deserialized.

        :param raw_jwe: a 'raw' JWE token (JSON Encoded or Compact
         notation) string.
        :param key: A (:class:`jwcrypto.jwk.JWK`) decryption key,
         or a (:class:`jwcrypto.jwk.JWKSet`) that contains a key indexed
         by the 'kid' header or (deprecated) a string containing a password
         (optional).

        :raises InvalidJWEData: if the raw object is an invalid JWE token.
        :raises InvalidJWEOperation: if the decryption fails.
        NrUrVrWr)r'r*r(r]r\r+rP�rrhrtrR��zInvalid format)r-r.r5r	r�decoder
r`r9�splitrirrxryrr)
rZraw_jwerb�oZdjwe�prcrmrZZekeyrrr �deserialize�sb

�

�


&
&zJWE.deserializecCs|jstd��|jS)NzPlaintext not available)r.r=rCrrr �payload+szJWE.payloadcCs*|�|j�d��}t|�dkr&td��|S)Nr+rzJOSE Header not available)rLr-rMrir=)rrJrrr rv1szJWE.jose_headercCs|�}|�|�|S)aCreates a JWE object from a serialized JWE token.

        :param token: A string with the json or compat representation
         of the token.

        :raises InvalidJWEData: if the raw object is an invalid JWE token.

        :return: A JWE token
        :rtype: JWE
        )r�)�cls�tokenrlrrr �from_jose_token8s

zJWE.from_jose_tokencCslt|t�sdSz|��|��kWStyfd|ji}|�|j�d|ji}|�|j�||kYS0dS)NFr.)r2r&rnrxr.r1r-)r�otherZdata1Zdata2rrr �__eq__Is


z
JWE.__eq__cCs*z
|��WSty$|��YS0dS)N)rnrx�__repr__rCrrr �__str__Us
zJWE.__str__c	Cs�zd|���d�WSty�t|j�}|j�d�}|j�d�}|j�d�}|j}d|�d�d|�d�d	|�d�d
|�d|�d�YS0dS)
NzJWE.from_json_token("z")r)r*r(zJWE(plaintext=z, z
protected=zunprotected=zaad=z, algs=ru)rnrxryr.r-rMr,)rr.r)r*r(r:rrr r�[s


�
��zJWE.__repr__)NNNNNNNN)N)N)F)N)r!r"r#r$rrArB�propertyrD�setterrIrLrNr[r8rnrorsr}rrr�r�rv�classmethodr�r�r�r�rrrr r&Ms>�
1




7
X		@)
L


r&)rXZjwcryptorZjwcrypto.commonrrrrrrr	r
Zjwcrypto.jwarZjwcrypto.jwkrrzr/r<rZInvalidCEKeyLengthZInvalidJWEKeyLengthZInvalidJWEKeyTyper=r&rrrr �<module>sB���