
"2VRF                 @   s  d  Z  d d l m Z m Z m Z m Z d d l m Z m Z d d l	 m
 Z
 m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z d d l m Z m Z d d l m Z d d l m Z m Z m Z m  Z  Gd	 d
   d
 e  Z! Gd d   d e  Z" Gd d   d e  Z# Gd d   d e  Z$ Gd d   d e  Z% Gd d   d e  Z& Gd d   d e  Z' Gd d   d e  Z( Gd d   d e  Z) Gd d   d e  Z* Gd d   d e  Z+ Gd d    d  e  Z, Gd! d"   d" e  Z- Gd# d$   d$ e  Z. Gd% d&   d& e  Z/ Gd' d(   d( e  Z0 Gd) d*   d* e  Z1 Gd+ d,   d, e  Z2 Gd- d.   d. e  Z3 Gd/ d0   d0 e  Z4 Gd1 d2   d2 e  Z5 Gd3 d4   d4 e  Z6 Gd5 d6   d6 e  Z7 Gd7 d8   d8 e  Z8 Gd9 d:   d: e  Z9 Gd; d<   d< e  Z: Gd= d>   d> e  Z; Gd? d@   d@ e  Z< GdA dB   dB e  Z= GdC dD   dD e  Z> GdE dF   dF e  Z? GdG dH   dH e  Z@ GdI dJ   dJ e  ZA GdK dL   dL e  ZB GdM dN   dN e  ZC GdO dP   dP e  ZD dQ S)Rz
ASN.1 type classes for the online certificate status protocol (OCSP). Exports
the following items:

 - OCSPRequest()
 - OCSPResponse()

Other type classes are defined that help compose the types listed above.
    )unicode_literalsdivisionabsolute_importprint_function   )DigestAlgorithmSignedDigestAlgorithm)BooleanChoice
EnumeratedGeneralizedTime	IA5StringIntegerNullObjectIdentifierOctetBitStringOctetStringParsableOctetStringSequence
SequenceOf)AuthorityInfoAccessSyntax	CRLReason)PublicKeyAlgorithm)CertificateGeneralNameGeneralNamesNamec               @   s   e  Z d  Z d d i Z d S)Versionr   v1N)__name__
__module____qualname___map r#   r#   1/usr/lib/python3/dist-packages/asn1crypto/ocsp.pyr   '   s   r   c               @   s:   e  Z d  Z d e f d e f d e f d e f g Z d S)CertIdZhash_algorithmZissuer_name_hashZissuer_key_hashZserial_numberN)r   r    r!   r   r   r   _fieldsr#   r#   r#   r$   r%   -   s   			r%   c               @   s(   e  Z d  Z d e f d e f g Z d S)ServiceLocatorZissuerZlocatorN)r   r    r!   r   r   r&   r#   r#   r#   r$   r'   6   s   	r'   c               @   s   e  Z d  Z d d i Z d S)RequestExtensionIdz1.3.6.1.5.5.7.48.1.7service_locatorN)r   r    r!   r"   r#   r#   r#   r$   r(   =   s   r(   c               @   sL   e  Z d  Z d e f d e d d i f d e f g Z d Z d e i Z	 d S)	RequestExtensionextn_idcriticaldefaultF
extn_valuer)   N)r+   r.   )
r   r    r!   r(   r	   r   r&   	_oid_pairr'   
_oid_specsr#   r#   r#   r$   r*   C   s
   	r*   c               @   s   e  Z d  Z e Z d S)RequestExtensionsN)r   r    r!   r*   _child_specr#   r#   r#   r$   r1   P   s   r1   c            	   @   s   e  Z d  Z d e f d e d d d d d d i f g Z d	 Z d
 Z d
 Z d d   Z	 e
 d d    Z e
 d d    Z d
 S)RequestZreq_certsingle_request_extensionstag_typeexplicittagr   optionalTFNc             C   s   t    |  _ xl |  d D]` } | d j } d | } t |  |  rZ t |  | | d j  | d j r |  j j |  q Wd |  _ d S)zv
        Sets common named extensions to private attributes and creates a list
        of critical extensions
        r4   r+   z	_%s_valuer.   r,   TN)set_critical_extensionsnativehasattrsetattrparsedadd_processed_extensions)self	extensionnameattribute_namer#   r#   r$   _set_extensions^   s    
zRequest._set_extensionsc             C   s   |  j  s |  j   |  j S)z
        Returns a set of the names (or OID if not a known extension) of the
        extensions marked as critical

        :return:
            A set of unicode strings
        )r@   rE   r:   )rA   r#   r#   r$   critical_extensionsp   s    
	
zRequest.critical_extensionsc             C   s    |  j  d k r |  j   |  j S)z
        This extension is used when communicating with an OCSP responder that
        acts as a proxy for OCSP requests

        :return:
            None or a ServiceLocator object
        F)r@   rE   _service_locator_value)rA   r#   r#   r$   service_locator_value~   s    

zRequest.service_locator_value)r   r    r!   r%   r1   r&   r@   r:   rG   rE   propertyrF   rH   r#   r#   r#   r$   r3   T   s   	$r3   c               @   s   e  Z d  Z e Z d S)RequestsN)r   r    r!   r3   r2   r#   r#   r#   r$   rJ      s   rJ   c               @   s   e  Z d  Z d d i Z d S)ResponseTypez1.3.6.1.5.5.7.48.1.1basic_ocsp_responseN)r   r    r!   r"   r#   r#   r#   r$   rK      s   rK   c               @   s   e  Z d  Z e Z d S)AcceptableResponsesN)r   r    r!   rK   r2   r#   r#   r#   r$   rM      s   rM   c               @   s1   e  Z d  Z d e f d e d d i f g Z d S)PreferredSignatureAlgorithmZsig_identifierZcert_identifierr8   TN)r   r    r!   r   r   r&   r#   r#   r#   r$   rN      s   	rN   c               @   s   e  Z d  Z e Z d S)PreferredSignatureAlgorithmsN)r   r    r!   rN   r2   r#   r#   r#   r$   rO      s   rO   c               @   s(   e  Z d  Z d d d d d d i Z d S)TBSRequestExtensionIdz1.3.6.1.5.5.7.48.1.2noncez1.3.6.1.5.5.7.48.1.4acceptable_responsesz1.3.6.1.5.5.7.48.1.8preferred_signature_algorithmsN)r   r    r!   r"   r#   r#   r#   r$   rP      s   rP   c               @   sX   e  Z d  Z d e f d e d d i f d e f g Z d
 Z d e d e	 d e
 i Z d	 S)TBSRequestExtensionr+   r,   r-   Fr.   rQ   rR   rS   N)zextn_idz
extn_value)r   r    r!   rP   r	   r   r&   r/   r   rM   rO   r0   r#   r#   r#   r$   rT      s   	rT   c               @   s   e  Z d  Z e Z d S)TBSRequestExtensionsN)r   r    r!   rT   r2   r#   r#   r#   r$   rU      s   rU   c               @   sy   e  Z d  Z d e d d d d d d i f d e d d d d	 d
 d i f d e f d e d d d d d
 d i f g Z d S)
TBSRequestversionr5   r6   r7   r   r-   r   Zrequestor_namer   r8   TZrequest_listrequest_extensions   N)r   r    r!   r   r   rJ   rU   r&   r#   r#   r#   r$   rV      s   	rV   c               @   s   e  Z d  Z e Z d S)CertificatesN)r   r    r!   r   r2   r#   r#   r#   r$   rZ      s   rZ   c            
   @   sF   e  Z d  Z d e f d e f d e d d d d d d	 i f g Z d
 S)	Signaturesignature_algorithm	signaturecertsr5   r6   r7   r   r8   TN)r   r    r!   r   r   rZ   r&   r#   r#   r#   r$   r[      s   		r[   c            	   @   s   e  Z d  Z d e f d e d d d d d d i f g Z d	 Z d
 Z d
 Z d
 Z	 d
 Z
 d d   Z e d d    Z e d d    Z e d d    Z e d d    Z d
 S)OCSPRequesttbs_requestZoptional_signaturer5   r6   r7   r   r8   TFNc             C   s   t    |  _ xp |  d d D]` } | d j } d | } t |  |  r^ t |  | | d j  | d j r |  j j |  q Wd |  _ d S)	zv
        Sets common named extensions to private attributes and creates a list
        of critical extensions
        r`   rX   r+   z	_%s_valuer.   r,   TN)r9   r:   r;   r<   r=   r>   r?   r@   )rA   rB   rC   rD   r#   r#   r$   rE      s    
zOCSPRequest._set_extensionsc             C   s   |  j  s |  j   |  j S)z
        Returns a set of the names (or OID if not a known extension) of the
        extensions marked as critical

        :return:
            A set of unicode strings
        )r@   rE   r:   )rA   r#   r#   r$   rF      s    
	
zOCSPRequest.critical_extensionsc             C   s    |  j  d k r |  j   |  j S)z
        This extension is used to prevent replay attacks by including a unique,
        random value with each request/response pair

        :return:
            None or an OctetString object
        F)r@   rE   _nonce_value)rA   r#   r#   r$   nonce_value  s    

zOCSPRequest.nonce_valuec             C   s    |  j  d k r |  j   |  j S)a(  
        This extension is used to allow the client and server to communicate
        with alternative response formats other than just basic_ocsp_response,
        although no other formats are defined in the standard.

        :return:
            None or an AcceptableResponses object
        F)r@   rE   _acceptable_responses_value)rA   r#   r#   r$   acceptable_responses_value  s    
z&OCSPRequest.acceptable_responses_valuec             C   s    |  j  d k r |  j   |  j S)aj  
        This extension is used by the client to define what signature algorithms
        are preferred, including both the hash algorithm and the public key
        algorithm, with a level of detail down to even the public key algorithm
        parameters, such as curve name.

        :return:
            None or a PreferredSignatureAlgorithms object
        F)r@   rE   %_preferred_signature_algorithms_value)rA   r#   r#   r$   $preferred_signature_algorithms_value  s    
z0OCSPRequest.preferred_signature_algorithms_value)r   r    r!   rV   r[   r&   r@   r:   ra   rc   re   rE   rI   rF   rb   rd   rf   r#   r#   r#   r$   r_      s   	$r_   c               @   s:   e  Z d  Z d d d d d d d d d	 d
 d d i Z d S)OCSPResponseStatusr   Z
successfulr   Zmalformed_requestrY   Zinternal_error   Z	try_later   Zsign_required   ZunauthorizedN)r   r    r!   r"   r#   r#   r#   r$   rg   0  s   rg   c               @   sF   e  Z d  Z d e d d d d i f d e d d d d i f g Z d S)	ResponderIdZby_namer5   r6   r7   r   Zby_keyrY   N)r   r    r!   r   r   _alternativesr#   r#   r#   r$   rk   ;  s   rk   c            	   @   s=   e  Z d  Z d e f d e d d d d d d i f g Z d	 S)
RevokedInfoZrevocation_timeZrevocation_reasonr5   r6   r7   r   r8   TN)r   r    r!   r   r   r&   r#   r#   r#   r$   rm   B  s   	rm   c               @   s^   e  Z d  Z d e d d d d i f d e d d d d i f d e d d d d	 i f g Z d
 S)
CertStatusZgoodr5   Zimplicitr7   r   Zrevokedr   unknownrY   N)r   r    r!   r   rm   rl   r#   r#   r#   r$   rn   I  s   rn   c            
   @   sp   e  Z d  Z d e d d d d d d i f d e d d d d	 d d i f d
 e d d d d d d i f g Z d S)CrlIdZcrl_urlr5   r6   r7   r   r8   TZcrl_numr   Zcrl_timerY   N)r   r    r!   r   r   r   r&   r#   r#   r#   r$   rp   Q  s   rp   c            
   @   s4   e  Z d  Z d d d d d d d d d	 d
 i Z d S)SingleResponseExtensionIdz1.3.6.1.5.5.7.48.1.3crlz1.3.6.1.5.5.7.48.1.6archive_cutoffz	2.5.29.21
crl_reasonz	2.5.29.24invalidity_datez	2.5.29.29certificate_issuerN)r   r    r!   r"   r#   r#   r#   r$   rq   Y  s
   rq   c            
   @   sd   e  Z d  Z d e f d e d d i f d e f g Z d Z d e d e	 d e
 d	 e	 d
 e i Z d S)SingleResponseExtensionr+   r,   r-   Fr.   rr   rs   rt   ru   rv   N)zextn_idz
extn_value)r   r    r!   rq   r	   r   r&   r/   rp   r   r   r   r0   r#   r#   r#   r$   rw   e  s   	rw   c               @   s   e  Z d  Z e Z d S)SingleResponseExtensionsN)r   r    r!   rw   r2   r#   r#   r#   r$   rx   v  s   rx   c               @   s  e  Z d  Z d e f d e f d e f d e d d d d d	 d
 i f d e d d d d d	 d
 i f g Z d Z d Z	 d Z
 d Z d Z d Z d Z d d   Z e d d    Z e d d    Z e d d    Z e d d    Z e d d    Z e d d    Z d S)SingleResponseZcert_idZcert_statusZthis_updateZnext_updater5   r6   r7   r   r8   Tsingle_extensionsr   FNc             C   s   t    |  _ xl |  d D]` } | d j } d | } t |  |  rZ t |  | | d j  | d j r |  j j |  q Wd |  _ d S)zv
        Sets common named extensions to private attributes and creates a list
        of critical extensions
        rz   r+   z	_%s_valuer.   r,   TN)r9   r:   r;   r<   r=   r>   r?   r@   )rA   rB   rC   rD   r#   r#   r$   rE     s    
zSingleResponse._set_extensionsc             C   s   |  j  s |  j   |  j S)z
        Returns a set of the names (or OID if not a known extension) of the
        extensions marked as critical

        :return:
            A set of unicode strings
        )r@   rE   r:   )rA   r#   r#   r$   rF     s    
	
z"SingleResponse.critical_extensionsc             C   s    |  j  d k r |  j   |  j S)z
        This extension is used to locate the CRL that a certificate's revocation
        is contained within.

        :return:
            None or a CrlId object
        F)r@   rE   
_crl_value)rA   r#   r#   r$   	crl_value  s    

zSingleResponse.crl_valuec             C   s    |  j  d k r |  j   |  j S)z
        This extension is used to indicate the date at which an archived
        (historical) certificate status entry will no longer be available.

        :return:
            None or a GeneralizedTime object
        F)r@   rE   _archive_cutoff_value)rA   r#   r#   r$   archive_cutoff_value  s    

z#SingleResponse.archive_cutoff_valuec             C   s    |  j  d k r |  j   |  j S)z
        This extension indicates the reason that a certificate was revoked.

        :return:
            None or a CRLReason object
        F)r@   rE   _crl_reason_value)rA   r#   r#   r$   crl_reason_value  s    	
zSingleResponse.crl_reason_valuec             C   s    |  j  d k r |  j   |  j S)a=  
        This extension indicates the suspected date/time the private key was
        compromised or the certificate became invalid. This would usually be
        before the revocation date, which is when the CA processed the
        revocation.

        :return:
            None or a GeneralizedTime object
        F)r@   rE   _invalidity_date_value)rA   r#   r#   r$   invalidity_date_value  s    
z$SingleResponse.invalidity_date_valuec             C   s    |  j  d k r |  j   |  j S)z
        This extension indicates the issuer of the certificate in question.

        :return:
            None or an x509.GeneralNames object
        F)r@   rE   _certificate_issuer_value)rA   r#   r#   r$   certificate_issuer_value  s    	
z'SingleResponse.certificate_issuer_value)r   r    r!   r%   rn   r   rx   r&   r@   r:   r{   r}   r   r   r   rE   rI   rF   r|   r~   r   r   r   r#   r#   r#   r$   ry   z  s&   			$ry   c               @   s   e  Z d  Z e Z d S)	ResponsesN)r   r    r!   ry   r2   r#   r#   r#   r$   r     s   r   c               @   s"   e  Z d  Z d d d d i Z d S)ResponseDataExtensionIdz1.3.6.1.5.5.7.48.1.2rQ   z1.3.6.1.5.5.7.48.1.9extended_revokeN)r   r    r!   r"   r#   r#   r#   r$   r     s   r   c               @   sR   e  Z d  Z d e f d e d d i f d e f g Z d	 Z d e d e	 i Z
 d S)
ResponseDataExtensionr+   r,   r-   Fr.   rQ   r   N)zextn_idz
extn_value)r   r    r!   r   r	   r   r&   r/   r   r   r0   r#   r#   r#   r$   r     s   	r   c               @   s   e  Z d  Z e Z d S)ResponseDataExtensionsN)r   r    r!   r   r2   r#   r#   r#   r$   r     s   r   c               @   sm   e  Z d  Z d e d d d d d d i f d e f d	 e f d
 e f d e d d d d d d i f g Z d S)ResponseDatarW   r5   r6   r7   r   r-   r   Zresponder_idZproduced_atZ	responsesresponse_extensionsr   r8   TN)	r   r    r!   r   rk   r   r   r   r&   r#   r#   r#   r$   r     s
   			r   c               @   sO   e  Z d  Z d e f d e f d e f d e d d d d d	 d
 i f g Z d S)BasicOCSPResponsetbs_response_datar\   r]   r^   r5   r6   r7   r   r8   TN)r   r    r!   r   r   r   rZ   r&   r#   r#   r#   r$   r     s   			r   c               @   s:   e  Z d  Z d e f d e f g Z d Z d e i Z d S)ResponseBytesresponse_typeresponserL   N)r   r   )	r   r    r!   rK   r   r&   r/   r   r0   r#   r#   r#   r$   r   "  s   	r   c            	   @   s   e  Z d  Z d e f d e d d d d d d i f g Z d	 Z d
 Z d
 Z d
 Z	 d d   Z
 e d d    Z e d d    Z e d d    Z e d d    Z e d d    Z d
 S)OCSPResponseZresponse_statusresponse_bytesr5   r6   r7   r   r8   TFNc             C   s   t    |  _ x{ |  d d j d d D]` } | d j } d | } t |  |  ri t |  | | d j  | d j r& |  j j |  q& Wd	 |  _ d
 S)zv
        Sets common named extensions to private attributes and creates a list
        of critical extensions
        r   r   r   r   r+   z	_%s_valuer.   r,   TN)r9   r:   r>   r;   r<   r=   r?   r@   )rA   rB   rC   rD   r#   r#   r$   rE   9  s     
zOCSPResponse._set_extensionsc             C   s   |  j  s |  j   |  j S)z
        Returns a set of the names (or OID if not a known extension) of the
        extensions marked as critical

        :return:
            A set of unicode strings
        )r@   rE   r:   )rA   r#   r#   r$   rF   K  s    
	
z OCSPResponse.critical_extensionsc             C   s    |  j  d k r |  j   |  j S)z
        This extension is used to prevent replay attacks on the request/response
        exchange

        :return:
            None or an OctetString object
        F)r@   rE   ra   )rA   r#   r#   r$   rb   Y  s    

zOCSPResponse.nonce_valuec             C   s    |  j  d k r |  j   |  j S)z
        This extension is used to signal that the responder will return a
        "revoked" status for non-issued certificates.

        :return:
            None or a Null object (if present)
        F)r@   rE   _extended_revoke_value)rA   r#   r#   r$   extended_revoke_valueg  s    

z"OCSPResponse.extended_revoke_valuec             C   s   |  d d j  S)z
        A shortcut into the BasicOCSPResponse sequence

        :return:
            None or an asn1crypto.ocsp.BasicOCSPResponse object
        r   r   )r>   )rA   r#   r#   r$   rL   u  s    	z OCSPResponse.basic_ocsp_responsec             C   s   |  d d j  d S)z
        A shortcut into the parsed, ResponseData sequence

        :return:
            None or an asn1crypto.ocsp.ResponseData object
        r   r   r   )r>   )rA   r#   r#   r$   response_data  s    	zOCSPResponse.response_data)r   r    r!   rg   r   r&   r@   r:   ra   r   rE   rI   rF   rb   r   rL   r   r#   r#   r#   r$   r   .  s   	$r   N)E__doc__Z
__future__r   r   r   r   Zalgosr   r   Zcorer	   r
   r   r   r   r   r   r   r   r   r   r   r   rr   r   r   keysr   Zx509r   r   r   r   r   r%   r'   r(   r*   r1   r3   rJ   rK   rM   rN   rO   rP   rT   rU   rV   rZ   r[   r_   rg   rk   rm   rn   rp   rq   rw   rx   ry   r   r   r   r   r   r   r   r   r#   r#   r#   r$   <module>   sT   "X"	9	Zx
	