o
    çó·i�  ã                   @  sÚ   d Z ddlmZ ddlZddlmZ ddlmZmZm	Z	m
Z
mZmZmZ ddlmZ ddlmZ ddlmZ d	d
lmZ d	dlmZmZmZmZmZmZmZmZ dgZddd„Z ddd„Z!edƒZ"d dd„Z#d dd„Z$dS )!zL
`cryptography.x509 <https://github.com/pyca/cryptography>`_-specific code.
é    )ÚannotationsN)ÚSequence)ÚCertificateÚDNSNameÚExtensionOIDÚ	IPAddressÚObjectIdentifierÚ	OtherNameÚUniformResourceIdentifier)ÚExtensionNotFound)Údecode)Ú	IA5Stringé   )ÚCertificateError)ÚDNS_IDÚCertificatePatternÚ
DNSPatternÚIPAddress_IDÚIPAddressPatternÚ
SRVPatternÚ
URIPatternÚverify_service_identityÚverify_certificate_hostnameÚcertificater   ÚhostnameÚstrÚreturnÚNonec                 C  ó   t t| ƒt|ƒgg d� dS )a¤  
    Verify whether *certificate* is valid for *hostname*.

    .. note::
        Nothing is verified about the *authority* of the certificate;
        the caller must verify that the certificate chains to an appropriate
        trust root themselves.

    Args:
        certificate: A *cryptography* X509 certificate object.

        hostname: The hostname that *certificate* should be valid for.

    Raises:
        service_identity.VerificationError:
            If *certificate* is not valid for *hostname*.

        service_identity.CertificateError:
            If *certificate* contains invalid / unexpected data. This includes
            the case where the certificate contains no `subjectAltName`\ s.

    .. versionchanged:: 24.1.0
        :exc:`~service_identity.CertificateError` is raised if the certificate
        contains no ``subjectAltName``\ s instead of
        :exc:`~service_identity.VerificationError`.
    ©Zcert_patternsZobligatory_idsZoptional_idsN)r   Úextract_patternsr   )r   r   © r!   úcC:\Users\psant\Downloads\PAF backend\school\venv\Lib\site-packages\service_identity/cryptography.pyr   (   s
   
ýÚ
ip_addressc                 C  r   )a  
    Verify whether *certificate* is valid for *ip_address*.

    .. note::
        Nothing is verified about the *authority* of the certificate;
        the caller must verify that the certificate chains to an appropriate
        trust root themselves.

    Args:
        certificate: A *cryptography* X509 certificate object.

        ip_address:
            The IP address that *connection* should be valid for.  Can be an
            IPv4 or IPv6 address.

    Raises:
        service_identity.VerificationError:
            If *certificate* is not valid for *ip_address*.

        service_identity.CertificateError:
            If *certificate* contains invalid / unexpected data. This includes
            the case where the certificate contains no ``subjectAltName``\ s.

    .. versionadded:: 18.1.0

    .. versionchanged:: 24.1.0
        :exc:`~service_identity.CertificateError` is raised if the certificate
        contains no ``subjectAltName``\ s instead of
        :exc:`~service_identity.VerificationError`.
    r   N)r   r    r   )r   r#   r!   r!   r"   Úverify_certificate_ip_addressL   s
   !
ýr$   z1.3.6.1.5.5.7.8.7ÚcertúSequence[CertificatePattern]c                 C  sÚ   g }z	| j  tj¡}W n
 ty   Y |S w | dd„ |j t¡D ƒ¡ | dd„ |j t	¡D ƒ¡ | dd„ |j t
¡D ƒ¡ |j t¡D ]$}|jtkrjt|jƒ\}}t|tƒrd| t | ¡ ¡¡ qFd}t|ƒ‚qF|S )a
  
    Extract all valid ID patterns from a certificate for service verification.

    Args:
        cert: The certificate to be dissected.

    Returns:
        List of IDs.

    .. versionchanged:: 23.1.0
       ``commonName`` is not used as a fallback anymore.
    c                 S  ó   g | ]
}t  | d ¡¡‘qS ©zutf-8)r   Ú
from_bytesÚencode)Ú.0Únamer!   r!   r"   Ú
<listcomp>�   ó    ÿÿz$extract_patterns.<locals>.<listcomp>c                 S  r'   r(   )r   r)   r*   )r+   Úurir!   r!   r"   r-   “   r.   c                 S  s   g | ]}t |ƒ‘qS r!   )r   )r+   Úipr!   r!   r"   r-   ›   s    ÿÿzUnexpected certificate content.N)Ú
extensionsZget_extension_for_oidr   ZSUBJECT_ALTERNATIVE_NAMEr   ÚextendÚvalueZget_values_for_typer   r
   r   r	   Ztype_idÚID_ON_DNS_SRVr   Ú
isinstancer   Úappendr   r)   ZasOctetsr   )r%   ÚidsÚextÚotherZsrvÚ_Úmsgr!   r!   r"   r    w   sF   ÿà
þÿÿþÿ
þÿ

úr    c                 C  s   t jtddd� t| ƒS )zm
    Deprecated and never public API.  Use :func:`extract_patterns` instead.

    .. deprecated:: 23.1.0
    z?`extract_ids()` is deprecated, please use `extract_patterns()`.é   )ÚcategoryÚmessageÚ
stacklevelN)ÚwarningsÚwarnÚDeprecationWarningr    )r%   r!   r!   r"   Úextract_ids¬   s   ýrC   )r   r   r   r   r   r   )r   r   r#   r   r   r   )r%   r   r   r&   )%Ú__doc__Ú
__future__r   r@   Útypingr   Zcryptography.x509r   r   r   r   r   r	   r
   Zcryptography.x509.extensionsr   Zpyasn1.codec.der.decoderr   Zpyasn1.type.charr   Ú
exceptionsr   Zhazmatr   r   r   r   r   r   r   r   Ú__all__r   r$   r4   r    rC   r!   r!   r!   r"   Ú<module>   s     $	(

$(
5