403Webshell
Server IP : 3.96.16.70  /  Your IP : 216.73.216.15
Web Server : Apache
System : Linux ip-172-31-26-103.ca-central-1.compute.internal 6.1.163-186.299.amzn2023.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Feb 24 16:35:42 UTC 2026 x86_64
User : ec2-user ( 1000)
PHP Version : 8.4.18
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /usr/lib/python3.9/site-packages/certbot/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /usr/lib/python3.9/site-packages/certbot/__pycache__/crypto_util.cpython-39.pyc
a

�]e`�	@s
dZddlZddlZddlZddlZddlmZddlmZddlmZddlm	Z	ddlm
Z
ddlmZdd	lmZdd
l
mZddlmZddlmZdd
lmZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z ddl!m"Z"ddl!m#Z#ddl!m$Z$ddl%Z%ddl&m'Z'ddl&m(Z(ddl)Z)ddl*m+Z,ddl-m.Z.ddl-m/Z/ddl-m0Z0ddl1m2Z2e�r�ddl3m4Z4dd l5m6Z6dd!l7m8Z8dd"l9m:Z:e�;e<�Z=d|e>ee?e?e?e?e@e0jAd'�d(d)�ZBd}e0jAeee?e	e?fee?e@e@e0jCd+�d,d-�ZDeEe@d.�d/d0�ZFeEeEe@d1�d2d3�ZGe?eEe
e>e0jCee?fd4�d5d6�ZHd~e>e?ee?eEd8�d9d:�ZIee?eEfe@d;�d<d=�ZJe/jKdd>�d?d@�ZLe/jKdd>�dAdB�ZMeedCdDee dEdFfeEeEejNddG�dHdI�ZOe?e?ddJ�dKdL�ZPe/jKdd>�dMdN�ZQeEe
e'jRe>fdO�dPdQ�ZSe'jTfeEee>eEgee'jRe'jUffe>ee'jRe'jUfdR�dSdT�ZVe'jTfeEee>eEgee'jRe'jUffe>ee?dR�dUdV�ZWe'jTfeEe>ee?dW�dXdY�ZXeEee>eEgee'jRe'jUffe>ee?dZ�d[d\�ZYee'jRe'jUfee?d]�d^d_�ZZe'jTfeEe>ee?dW�d`da�Z[e'jTfeEe>ee?db�dcdd�Z\e'jTfeee'jRee%j]fe>eEde�dfdg�Z^e?ejdh�didj�Z_e?ejdh�dkdl�Z`e?ee'jRgeeEfejdm�dndo�Zae?e?dp�dqdr�Zbe�cdsejd�Zee?e
e?e?fdt�dudv�Zfe?e>dh�dwdx�Zgdee?e?e@e?dy�dzd{�ZhdS)�z�Certbot client crypto utility functions.

.. todo:: Make the transition to use PSS rather than PKCS1_v1_5 when the server
    is capable of handling the signatures.

�N)�Callable)�List)�Optional)�Set)�Tuple)�
TYPE_CHECKING)�Union)�x509)�InvalidSignature)�UnsupportedAlgorithm)�default_backend)�hashes)�ec)�DSAPublicKey)�ECDSA)�EllipticCurvePublicKey)�PKCS1v15)�RSAPublicKey)�Encoding)�NoEncryption)�
PrivateFormat)�crypto)�SSL)�crypto_util)�errors)�
interfaces)�util)�os)�Ed448PublicKey)�Ed25519PublicKey)�
X448PublicKey)�X25519PublicKey�rsa�	secp256r1�key-certbot.pemT)�key_size�key_dir�key_type�elliptic_curve�keyname�strict_permissions�returnc

Cs�zt||pd|d�}WnFty\}z.tjddd�t�dt|��|�WYd}~n
d}~00d}|r�t�|d|�t�t	j
�||�d	d
�\}	}|	�|	�|�Wd�n1s�0Y|dkr�t�d||�nt�d
||�t�
||�S)a$Initializes and saves a privkey.

    Inits key and saves it in PEM format on the filesystem.

    .. note:: keyname is the attempted filename, it may be different if a file
        already exists at the path.

    :param int key_size: key size in bits if key size is rsa.
    :param str key_dir: Optional key save directory.
    :param str key_type: Key Type [rsa, ecdsa]
    :param str elliptic_curve: Name of the elliptic curve if key type is ecdsa.
    :param str keyname: Filename of key
    :param bool strict_permissions: If true and key_dir exists, an exception is raised if
        the directory doesn't have 0700 permissions or isn't owned by the current user.

    :returns: Key
    :rtype: :class:`certbot.util.Key`

    :raises ValueError: If unable to generate the key given key_size.

    r#)�bitsr(r'�T��exc_infoz&Encountered error while making key: %sNi�i��wbr"z Generating RSA key (%d bits): %sz"Generating ECDSA key (%d bits): %s)�make_key�
ValueError�logger�debug�error�strr�make_or_verify_dir�unique_filer�path�join�write�Key)
r%r&r'r(r)r*Zkey_pem�err�key_pathZkey_f�r?�7/usr/lib/python3.9/site-packages/certbot/crypto_util.py�generate_key8s(
�
�(rAF)�privkey�namesr9�must_stapler*r+cCs�tj|j||d�}d}|r~t�|d|�t�tj�|d�dd�\}}|�|�	|�Wd�n1sh0Yt
�d|�t�||d�S)	aCInitialize a CSR with the given private key.

    :param privkey: Key to include in the CSR
    :type privkey: :class:`certbot.util.Key`
    :param set names: `str` names to include in the CSR
    :param str path: Optional certificate save directory.
    :param bool must_staple: If true, include the TLS Feature extension "OCSP Must-Staple"
    :param bool strict_permissions: If true and path exists, an exception is raised if
        the directory doesn't have 0755 permissions or isn't owned by the current user.

    :returns: CSR
    :rtype: :class:`certbot.util.CSR`

    )rDNi�zcsr-certbot.pemi�r0zCreating CSR: %s�pem)
�acme_crypto_utilZmake_csrrErr7r8rr9r:r;r3r4�CSR)rBrCr9rDr*Zcsr_pemZcsr_filenameZcsr_fr?r?r@�generate_csris��(rH)�csrr+cCsHzt�tj|�}|�|���WStjyBtjddd�YdS0dS)z�Validate CSR.

    Check if `csr` is a valid CSR for the given domains.

    :param bytes csr: CSR in PEM.

    :returns: Validity of CSR.
    :rtype: bool

    r-Tr.FN)r�load_certificate_request�FILETYPE_PEM�verifyZ
get_pubkey�Errorr3r4)rI�reqr?r?r@�	valid_csr�s�rO)rIrBr+cCsRt�tj|�}t�tj|�}z|�|�WStjyLtjddd�YdS0dS)z�Does private key correspond to the subject public key in the CSR?

    :param bytes csr: CSR in PEM.
    :param bytes privkey: Private key file contents (PEM)

    :returns: Correspondence of private key to CSR subject public key.
    :rtype: bool

    r-Tr.FN)rrJrK�load_privatekeyrLrMr3r4)rIrBrNZpkeyr?r?r@�csr_matches_pubkey�s
�rQ)�csrfile�datar+cCs�tj}tj}z|tj|�}WnHtjydz|||�}Wn$tjy^t�d�|���Yn0Yn0t|�}t�||�}|t	j
||dd�|fS)a1Import a CSR file, which can be either PEM or DER.

    :param str csrfile: CSR filename
    :param bytes data: contents of the CSR file

    :returns: (`crypto.FILETYPE_PEM`,
               util.CSR object representing the CSR,
               list of domains requested in the CSR)
    :rtype: tuple

    zFailed to parse CSR file: {0}rE)�filerSZform)rrKrJ�
FILETYPE_ASN1rMr�format�"_get_names_from_loaded_cert_or_reqZdump_certificate_requestrrG)rRrS�PEM�loadrIZdomainsZdata_pemr?r?r@�import_csr_file�srZ�)r,r'r(r+c	
CsD|dkr8|dkr t�d�|���t��}|�tj|�n�|dk�r&|sPt�d��zZ|��}|dvr�tt	|���}|s�t�d|����t	j
|�t�d�}nt�d	�|���WnTty�t�d	�|���Yn4t
y�}z|t�t|���WYd
}~n
d
}~00|jtjtjt�d�}t�tj|�}nt�d�|���t�tj|�S)
a�Generate PEM encoded RSA|EC key.

    :param int bits: Number of bits if key_type=rsa. At least 1024 for RSA.
    :param str key_type: The type of key to generate, but be rsa or ecdsa
    :param str elliptic_curve: The elliptic curve to use.

    :returns: new RSA or ECDSA key in PEM form with specified number of bits
              or of type ec_curve when key_type ecdsa is used.
    :rtype: str
    r"r[zUnsupported RSA key length: {}Zecdsaz3When key_type == ecdsa, elliptic_curve must be set.)Z	SECP256R1Z	SECP384R1Z	SECP521R1zInvalid curve type: )�curveZbackendzUnsupported elliptic curve: {}N)�encodingrVZencryption_algorithmz0Invalid key_type specified: {}.  Use [rsa|ecdsa])rrMrVrZPKeyrAZTYPE_RSA�upper�getattrrZgenerate_private_keyr�	TypeErrorrr6Z
private_bytesrrXrZTraditionalOpenSSLrrPrKZdump_privatekey)	r,r'r(�key�namer\Z_key�eZ_key_pemr?r?r@r1�s>

�&�r1)rBr+c	Cs4zt�tj|���WSttjfy.YdS0dS)z�Is valid RSA private key?

    :param privkey: Private key file contents in PEM

    :returns: Validity of private key.
    :rtype: bool

    FN)rrPrKZcheckr`rM)rBr?r?r@�
valid_privkeys	�
rd)�renewable_certr+cCs"t|�t|�t|j|j�dS)a�For checking that your certs were not corrupted on disk.

    Several things are checked:
        1. Signature verification for the cert.
        2. That fullchain matches cert and chain when concatenated.
        3. Check that the private key matches the certificate.

    :param renewable_cert: cert to verify
    :type renewable_cert: certbot.interfaces.RenewableCert

    :raises errors.Error: If verification fails.
    N)�verify_renewable_cert_sig�verify_fullchain�verify_cert_matches_priv_key�	cert_pathr>)rer?r?r@�verify_renewable_certs
rjc
Cs�z�t|jd��"}t�|��t��}Wd�n1s60Yt|jd��"}t�|��t��}Wd�n1st0Y|��}|js�J�t	||j
|j|j�WnLtt
tfy�}z.d�|j|�}t�|�t�|��WYd}~n
d}~00dS)z�Verifies the signature of a RenewableCert object.

    :param renewable_cert: cert to verify
    :type renewable_cert: certbot.interfaces.RenewableCert

    :raises errors.Error: If signature verification fails.
    �rbNzbverifying the signature of the certificate located at {0} has failed.                 Details: {1})�open�
chain_pathr	�load_pem_x509_certificate�readrri�
public_key�signature_hash_algorithm�verify_signed_payload�	signatureZtbs_certificate_bytes�IOErrorr2r
rVr3�	exceptionrrM)re�
chain_file�chain�	cert_file�certZpkrc�	error_strr?r?r@rf%s 00
��
rfrrr!r )rprs�payloadrqr+cCsJt|t�r|�||t�|�n(t|t�r<|�||t|��n
t�d��dS)a�Check the signature of a payload.

    :param RSAPublicKey/EllipticCurvePublicKey public_key: the public_key to check signature
    :param bytes signature: the signature bytes
    :param bytes payload: the payload bytes
    :param hashes.HashAlgorithm signature_hash_algorithm: algorithm used to hash the payload

    :raises InvalidSignature: If signature verification fails.
    :raises errors.Error: If public key type is not supported
    zUnsupported public key type.N)�
isinstancerrLrrrrrM)rprsr{rqr?r?r@rr=s

�

�rr)rir>r+c
Cs~z,t�tj�}|�|�|�|�|��WnLttjfyx}z.d�|||�}t	�
|�t�|��WYd}~n
d}~00dS)z� Verifies that the private key and cert match.

    :param str cert_path: path to a cert in PEM format
    :param str key_path: path to a private key file

    :raises errors.Error: If they don't match.
    z�verifying the certificate located at {0} matches the                 private key located at {1} has failed.                 Details: {2}N)rZContextZ
SSLv23_METHODZuse_certificate_fileZuse_privatekey_fileZcheck_privatekeyrtrMrVr3rur)rir>�contextrcrzr?r?r@rhXs

�
rhc	
Cs4z�t|j��}|��}Wd�n1s*0Yt|j��}|��}Wd�n1s\0Yt|j��}|��}Wd�n1s�0Y|||kr�d}|�|j�}t�|��Wnnt	�y}z*d�|�}t
�|�t�|��WYd}~n4d}~0tj�y.}z|�WYd}~n
d}~00dS)z� Verifies that fullchain is indeed cert concatenated with chain.

    :param renewable_cert: cert to verify
    :type renewable_cert: certbot.interfaces.RenewableCert

    :raises errors.Error: If cert and chain do not combine to fullchain.
    Nz.fullchain does not match cert + chain for {0}!z8reading one of cert, chain, or fullchain has failed: {0})rlrmroriZfullchain_pathrVZlineagenamerrMrtr3ru)	rervrwrxryZfullchain_fileZ	fullchainrzrcr?r?r@rgns"&&&

rg)rSr+cCs�g}tjtjfD]L}zt�||�|fWStjyZ}z|�|�WYd}~qd}~00qt�d�d�dd�|D�����dS)z:Load PEM/DER certificate.

    :raises errors.Error:

    NzUnable to load: {0}�,css|]}t|�VqdS�N)r6)�.0r5r?r?r@�	<genexpr>�sz-pyopenssl_load_certificate.<locals>.<genexpr>)	rrKrU�load_certificaterM�appendrrVr:)rSZopenssl_errorsZ	file_typer5r?r?r@�pyopenssl_load_certificate�s"�r�)�cert_or_req_str�	load_func�typr+c
CsXz|||�WStjyR}z,tjddd�t�dt|���WYd}~n
d}~00dS)Nr-Tr.z6Encountered error while loading certificate or csr: %s)rrMr3r4r5r6)r�r�r�r=r?r?r@�_load_cert_or_req�sr�cCst�t|||��Sr)rFZ_pyopenssl_cert_or_req_sanr�)r�r�r�r?r?r@�_get_sans_from_cert_or_req�s�r�)ryr�r+cCst|tj|�S)z�Get a list of Subject Alternative Names from a certificate.

    :param str cert: Certificate (encoded).
    :param typ: `crypto.FILETYPE_PEM` or `crypto.FILETYPE_ASN1`

    :returns: A list of Subject Alternative Names.
    :rtype: list

    )r�rr��ryr�r?r?r@�get_sans_from_cert�s
�r�)�cert_or_reqr�r�r+cCst|||�}t|�Sr)r�rW)r�r�r��loaded_cert_or_reqr?r?r@�_get_names_from_cert_or_req�sr�)r�r+cCs
t�|�Sr)rFZ _pyopenssl_cert_or_req_all_names)r�r?r?r@rW�srWcCst|tj|�S)z�Get a list of domains from a cert, including the CN if it is set.

    :param str cert: Certificate (encoded).
    :param typ: `crypto.FILETYPE_PEM` or `crypto.FILETYPE_ASN1`

    :returns: A list of domain names.
    :rtype: list

    )r�rr�r�r?r?r@�get_names_from_cert�s
�r�)rIr�r+cCst|tj|�S)z�Get a list of domains from a CSR, including the CN if it is set.

    :param str csr: CSR (encoded).
    :param typ: `crypto.FILETYPE_PEM` or `crypto.FILETYPE_ASN1`
    :returns: A list of domain names.
    :rtype: list

    )r�rrJ)rIr�r?r?r@�get_names_from_req�s	r�)rw�filetyper+cCst�||�S)z�Dump certificate chain into a bundle.

    :param list chain: List of `crypto.X509` (or wrapped in
        :class:`josepy.util.ComparableX509`).

    )rF�dump_pyopenssl_chain)rwr�r?r?r@r��s
r�)rir+cCst|tjj�S)z�When does the cert at cert_path start being valid?

    :param str cert_path: path to a cert in PEM format

    :returns: the notBefore value from the cert at cert_path
    :rtype: :class:`datetime.datetime`

    )�_notAfterBeforer�X509Z
get_notBefore�rir?r?r@�	notBefore�s	r�cCst|tjj�S)z�When does the cert at cert_path stop being valid?

    :param str cert_path: path to a cert in PEM format

    :returns: the notAfter value from the cert at cert_path
    :rtype: :class:`datetime.datetime`

    )r�rr�Zget_notAfterr�r?r?r@�notAfter�s	r�)ri�methodr+c
Cs�t|d��"}t�tj|���}Wd�n1s20Y||�}|sRt�d��|dd�d|dd�d|dd�d	|dd
�d|d
d�d|dd�g}d
�|�}|�d�}t	�
|�S)aPInternal helper function for finding notbefore/notafter.

    :param str cert_path: path to a cert in PEM format
    :param function method: one of ``crypto.X509.get_notBefore``
        or ``crypto.X509.get_notAfter``

    :returns: the notBefore or notAfter value from the cert at cert_path
    :rtype: :class:`datetime.datetime`

    rkNz>Error while invoking timestamp method, None has been returned.r��-���T�
�:���ascii)rlrr�rKrorrMr:�decode�	pyrfc3339�parse)rir��fr	Z	timestampZreformatted_timestampZtimestamp_bytesZ
timestamp_strr?r?r@r�
s
0
�

r�)�filenamer+cCsNt��}t|d��$}|�|���d��Wd�n1s<0Y|��S)aNCompute a sha256sum of a file.

    NB: In given file, platform specific newlines characters will be converted
    into their equivalent unicode counterparts before calculating the hash.

    :param str filename: path to the file whose hash will be computed

    :returns: sha256 digest of the file in hexadecimal
    :rtype: str
    �rzUTF-8N)�hashlib�sha256rl�updatero�encode�	hexdigest)r�r�Zfile_dr?r?r@�	sha256sum&s2r�s@-----BEGIN CERTIFICATE-----
?
.+?
?
-----END CERTIFICATE-----
?
)�
fullchain_pemr+cCsLt�|���}t|�dkr$t�d��dd�|D�}|dd�|dd��fS)	aSplit fullchain_pem into cert_pem and chain_pem

    :param str fullchain_pem: concatenated cert + chain

    :returns: tuple of string cert_pem and chain_pem
    :rtype: tuple

    :raises errors.Error: If there are less than 2 certificates in the chain.

    �zPfailed to parse fullchain into cert and chain: less than 2 certificates in chainc	Ss(g|] }t�tjt�tj|�����qSr?)rZdump_certificaterKr�r�)r�ryr?r?r@�
<listcomp>Vs��z1cert_and_chain_from_fullchain.<locals>.<listcomp>rr-�N)�CERT_PEM_REGEX�findallr��lenrrMr:)r��certsZcerts_normalizedr?r?r@�cert_and_chain_from_fullchainAs
�r�cCsDt|d��"}t�tj|���}Wd�n1s20Y|��S)z�Retrieve the serial number of a certificate from certificate path

    :param str cert_path: path to a cert in PEM format

    :returns: serial number of the certificate
    :rtype: int
    rkN)rlrr�rKroZget_serial_number)rir�r	r?r?r@�get_serial_from_cert]s	0r�)�
fullchains�	issuer_cn�warn_on_no_matchr+cCsl|D]N}t�|���}t�|dt��}|j�tjj	�}|r|dj
|kr|Sq|rdt�d|�|dS)a'Chooses the first certificate chain from fullchains whose topmost
    intermediate has an Issuer Common Name matching issuer_cn (in other words
    the first chain which chains to a root whose name matches issuer_cn).

    :param fullchains: The list of fullchains in PEM chain format.
    :type fullchains: `list` of `str`
    :param `str` issuer_cn: The exact Subject Common Name to match against any
        issuer in the certificate chain.

    :returns: The best-matching fullchain, PEM-encoded, or the first if none match.
    :rtype: `str`
    ���rz�Certbot has been configured to prefer certificate chains with issuer '%s', but no chain from the CA matched this issuer. Using the default certificate chain instead.)
r�r�r�r	rnrZissuerZget_attributes_for_oidZNameOIDZCOMMON_NAME�valuer3Zwarning)r�r�r�rwr�Ztop_certZ
top_issuer_cnr?r?r@�find_chain_with_issuerks
�r�)r"r#r$T)FT)r[r"N)F)i�__doc__Zdatetimer�Zlogging�re�typingrrrrrrrZcryptographyr	Zcryptography.exceptionsr
rZcryptography.hazmat.backendsrZcryptography.hazmat.primitivesr
Z)cryptography.hazmat.primitives.asymmetricrZ-cryptography.hazmat.primitives.asymmetric.dsarZ,cryptography.hazmat.primitives.asymmetric.ecrrZ1cryptography.hazmat.primitives.asymmetric.paddingrZ-cryptography.hazmat.primitives.asymmetric.rsarZ,cryptography.hazmat.primitives.serializationrrrZjosepyZOpenSSLrrr�ZacmerrFZcertbotrrrZcertbot.compatrZ/cryptography.hazmat.primitives.asymmetric.ed448rZ1cryptography.hazmat.primitives.asymmetric.ed25519rZ.cryptography.hazmat.primitives.asymmetric.x448r Z0cryptography.hazmat.primitives.asymmetric.x25519r!Z	getLogger�__name__r3�intr6�boolr<rArGrH�bytesrOrQrZr1rdZ
RenewableCertrjrfZ
HashAlgorithmrrrhrgr�r�rKZX509Reqr�r�r�r�rWr�r�ZComparableX509r�r�r�r�r��compile�DOTALLr�r�r�r�r?r?r?r@�<module>s�
��2��%"��0�������	���
��
��	�
�

Youez - 2016 - github.com/yon3zu
LinuXploit