grthtrhthjhtyjytjytkergtrhtrjytjerhrfh3 «F\”ˆã$@s¬ddlZddlmZddlmZddlmZmZmZm Z m Z m Z ddl m ZmZmZddlmZddlmZmZddlmZdd lmZmZmZ m!Z"m#Z$m%Z&m'Z(m)Z*d d d d ddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-g$Z+ej,Z-ej.Z/dnZ0ej1Z2ej3Z4ej5Z6ej7Z8Gd1d„de9ƒZ:ee e:ƒZ;e*e:ƒZdod6d7„Z?d8d9„Z@d:d;„ZAdd?„d?eCƒZDGd@d„deCƒZEeeEeFdAeGƒZHGdBdC„dCeCƒZIdDd„ZJdEd„ZKGdFd„deCƒZLeeLeFdGeGƒZMGdHd„deCƒZNeeNeFdIeGƒZOGdJd„deCƒZPeePeFdKeGƒZQGdLd„deCƒZReeReFdMeGƒZSGdNd„deCƒZTGdOd„deCƒZUeeUeFdPeGƒZVGdQd„de9ƒZWGdRd„deCƒZXdSd„ZYdTd„ZZdUd„Z[dpdVd„Z\GdWd„deCƒZ]GdXd „d eCƒZ^ee^eFdYeGƒZ_GdZd!„d!eCƒZ`ee`eFd[eGƒZaGd\d"„d"eCƒZbeebeFd]eGƒZcGd^d#„d#eCƒZdeedeFd_eGƒZeGd`da„daeCƒZfdbd$„Zgdqdcd%„Zhddd&„Zided'„Zjdfd(„Zkdgd)„Zldhd*„Zmdid+„Zndjd,„Zodrdkd-„ZpejqƒejrƒejsdlƒdS)séN)Ú b16encode)Úpartial)Ú__eq__Ú__ne__Ú__lt__Ú__le__Ú__gt__Ú__ge__)Ú integer_typesÚ text_typeÚPY3)Úx509)ÚdsaÚrsa)Ú deprecated)ÚffiÚlibÚexception_from_error_queueÚ byte_stringÚnativeÚ UNSPECIFIEDÚtext_to_bytes_and_warnÚ make_assertÚ FILETYPE_PEMÚ FILETYPE_ASN1Ú FILETYPE_TEXTÚTYPE_RSAÚTYPE_DSAÚErrorÚPKeyÚget_elliptic_curvesÚget_elliptic_curveÚX509NameÚ X509ExtensionÚX509ReqÚX509ÚX509StoreFlagsÚ X509StoreÚX509StoreContextErrorÚX509StoreContextÚload_certificateÚdump_certificateÚdump_publickeyÚdump_privatekeyÚRevokedÚCRLÚPKCS7ÚPKCS12Ú NetscapeSPKIÚload_publickeyÚload_privatekeyÚdump_certificate_requestÚload_certificate_requestÚsignÚverifyÚdump_crlÚload_crlÚload_pkcs7_dataÚ load_pkcs12éééc@seZdZdZdS)rz7 An error occurred in an `OpenSSL.crypto` API. N)Ú__name__Ú __module__Ú __qualname__Ú__doc__©rDrDú/usr/lib/python3.6/crypto.pyrNscCsddlm}|S)ap Importing the backend from cryptography has the side effect of activating the osrandom engine. This mutates the global state of OpenSSL in the process and causes issues for various programs that use subinterpreters or embed Python. By putting the import in this function we can avoid triggering this side effect unless _get_backend is called. r)Úbackend)Z,cryptography.hazmat.backends.openssl.backendrF)rFrDrDrEÚ _get_backendXs rGcCstd|fƒ‚dS)zÐ An OpenSSL API failed somehow. Additionally, the failure which was encountered isn't one that's exercised by the test suite so future behavior of pyOpenSSL is now somewhat less predictable. zUnknown %s failureN)Ú RuntimeError)ÚwhererDrDrEÚ_untested_errordsrJcCsd|dkrtjtjƒƒ}tj}n(tjd|ƒ}tj|t|ƒƒ}|fdd„}t|tj kƒtj ||ƒ}|S)zÙ Allocate a new OpenSSL memory BIO. Arrange for the garbage collector to clean it up automatically. :param buffer: None or some bytes to use to put into the BIO so that they can be read out. Nzchar[]cSs tj|ƒS)N)Ú_libÚBIO_free)ÚbioÚrefrDrDrEÚfree~sz_new_mem_buf..free) rKÚBIO_newÚ BIO_s_memrLÚ_ffiÚnewZBIO_new_mem_bufÚlenÚ_openssl_assertÚNULLÚgc)ÚbufferrMrOÚdatarDrDrEÚ _new_mem_bufms    rZcCs.tjdƒ}tj||ƒ}tj|d|ƒdd…S)zO Copy the contents of an OpenSSL BIO object into a Python byte string. zchar**rN)rRrSrKZBIO_get_mem_datarX)rMÚ result_bufferZ buffer_lengthrDrDrEÚ_bio_to_string‡s  r\cCs2t|tƒstdƒ‚tj||ƒ}|dkr.tdƒ‚dS)aô The the time value of an ASN1 time object. @param boundary: An ASN1_TIME pointer (or an object safely castable to that type) which will have its value set. @param when: A string representation of the desired time value. @raise TypeError: If C{when} is not a L{bytes} string. @raise ValueError: If C{when} does not represent a time in the required format. @raise RuntimeError: If the time value cannot be set for some other (unspecified) reason. zwhen must be a byte stringrzInvalid stringN)Ú isinstanceÚbytesÚ TypeErrorrKZASN1_TIME_set_stringÚ ValueError)ÚboundaryÚwhenÚ set_resultrDrDrEÚ_set_asn1_time�s   rdcCs¦tjd|ƒ}tj|ƒdkrdStj|ƒtjkr>tjtj|ƒƒStjdƒ}tj ||ƒ|dtj krlt dƒn6tjd|dƒ}tj|ƒ}tj|ƒ}tj |dƒ|SdS)a] Retrieve the time value of an ASN1 time object. @param timestamp: An ASN1_GENERALIZEDTIME* (or an object safely castable to that type) from which the time value will be retrieved. @return: The time value from C{timestamp} as a L{bytes} string in a certain format. Or C{None} if the object contains no time value. z ASN1_STRING*rNzASN1_GENERALIZEDTIME**ÚASN1_TIME_to_generalizedtime) rRÚcastrKÚASN1_STRING_lengthZASN1_STRING_typeZV_ASN1_GENERALIZEDTIMEÚstringÚASN1_STRING_datarSrerVrJZASN1_GENERALIZEDTIME_free)Z timestampZstring_timestampZgeneralized_timestampZ string_dataÚ string_resultrDrDrEÚ_get_asn1_time¦s       rkc@s$eZdZdd„Zdd„Zdd„ZdS)Ú_X509NameInvalidatorcCs g|_dS)N)Ú_names)ÚselfrDrDrEÚ__init__Ïsz_X509NameInvalidator.__init__cCs|jj|ƒdS)N)rmÚappend)rnÚnamerDrDrEÚaddÒsz_X509NameInvalidator.addcCsx|jD]}|`qWdS)N)rmÚ_name)rnrqrDrDrEÚclearÕs z_X509NameInvalidator.clearN)r@rArBrorrrtrDrDrDrErlÎsrlc@sTeZdZdZdZdZdd„Zdd„Zedd „ƒZ d d „Z d d „Z dd„Z dd„Z dS)rzD A class representing an DSA or RSA public key or key pair. FTcCs"tjƒ}tj|tjƒ|_d|_dS)NF)rKZ EVP_PKEY_newrRrWÚ EVP_PKEY_freeÚ_pkeyÚ _initialized)rnÚpkeyrDrDrEroâsz PKey.__init__cCs(tƒ}|jr|j|jƒS|j|jƒSdS)a Export as a ``cryptography`` key. :rtype: One of ``cryptography``'s `key interfaces`_. .. _key interfaces: https://cryptography.io/en/latest/hazmat/ primitives/asymmetric/rsa/#key-interfaces .. versionadded:: 16.1.0 N)rGÚ _only_publicZ_evp_pkey_to_public_keyrvZ_evp_pkey_to_private_key)rnrFrDrDrEÚto_cryptography_keyçs  zPKey.to_cryptography_keycCsR|ƒ}t|tjtjtjtjfƒs(tdƒ‚|j|_ t|tjtjfƒrHd|_ d|_ |S)zø Construct based on a ``cryptography`` *crypto_key*. :param crypto_key: A ``cryptography`` key. :type crypto_key: One of ``cryptography``'s `key interfaces`_. :rtype: PKey .. versionadded:: 16.1.0 zUnsupported key typeT) r]rZ RSAPublicKeyZ RSAPrivateKeyrZ DSAPublicKeyZ DSAPrivateKeyr_Z _evp_pkeyrvryrw)ÚclsZ crypto_keyrxrDrDrEÚfrom_cryptography_keyøs  zPKey.from_cryptography_keycCs6t|tƒstdƒ‚t|tƒs$tdƒ‚|tkr¢|dkr= 0`` :raises TypeError: If :py:data:`type` or :py:data:`bits` isn't of the appropriate type. :raises ValueError: If the number of bits isn't an integer of the appropriate size. :return: ``None`` ztype must be an integerzbits must be an integerrzInvalid number of bitsr?zNo such key typeTN)r]Úintr_rr`rKÚBN_newrRrWÚBN_freeZ BN_set_wordZRSA_F4ZRSA_newZRSA_generate_key_exrVrUZEVP_PKEY_assign_RSArvrZDSA_newZDSA_freeZDSA_generate_parameters_exZDSA_generate_keyZEVP_PKEY_set1_DSArrw)rnÚtypeÚbitsZexponentrÚresultrÚresrDrDrEÚ generate_keys4     zPKey.generate_keycCs`|jrtdƒ‚tj|jƒƒtjkr*tdƒ‚tj|jƒ}tj |tj ƒ}tj |ƒ}|rVdSt ƒdS)ax Check the consistency of an RSA private key. This is the Python equivalent of OpenSSL's ``RSA_check_key``. :return: ``True`` if key is consistent. :raise OpenSSL.crypto.Error: if the key is inconsistent. :raise TypeError: if the key is of a type which cannot be checked. Only RSA keys can currently be checked. zpublic key onlyzkey type unsupportedTN) ryr_rKZ EVP_PKEY_typer€Ú EVP_PKEY_RSAÚEVP_PKEY_get1_RSArvrRrWÚRSA_freeZ RSA_check_keyÚ_raise_current_error)rnrr‚rDrDrEÚcheckGs   z PKey.checkcCs tj|jƒS)zT Returns the type of the key :return: The type of the key. )rKÚ EVP_PKEY_idrv)rnrDrDrEr€asz PKey.typecCs tj|jƒS)zh Returns the number of bits of the key :return: The number of bits of the key. )rKZ EVP_PKEY_bitsrv)rnrDrDrEr�isz PKey.bitsN)r@rArBrCryrwrorzÚ classmethodr|r„r‰r€r�rDrDrDrErÛs 8z.PKeyType has been deprecated, use PKey insteadcsdeZdZdZdZer ‡fdd„Zedd„ƒZedd„ƒZ ed d „ƒZ d d „Z d d„Z dd„Z ‡ZS)Ú_EllipticCurveaZ A representation of a supported elliptic curve. @cvar _curves: :py:obj:`None` until an attempt is made to load the curves. Thereafter, a :py:type:`set` containing :py:type:`_EllipticCurve` instances each of which represents one curve supported by the system. @type _curves: :py:type:`NoneType` or :py:type:`set` Ncst|tƒrtt|ƒj|ƒStS)zÇ Implement cooperation with the right-hand side argument of ``!=``. Python 3 seems to have dropped this cooperation in this very narrow circumstance. )r]rŒÚsuperrÚNotImplemented)rnÚother)Ú __class__rDrEr†s z_EllipticCurve.__ne__cs>ˆjtjdƒ}tjd|ƒ}ˆj||ƒt‡‡fdd„|DƒƒS)zü Get the curves supported by OpenSSL. :param lib: The OpenSSL library binding object. :return: A :py:type:`set` of ``cls`` instances giving the names of the elliptic curves the underlying library supports. rzEC_builtin_curve[]c3s|]}ˆjˆ|jƒVqdS)N)Úfrom_nidÚnid)Ú.0Úc)r{rrDrEú ¢sz7_EllipticCurve._load_elliptic_curves..)ZEC_get_builtin_curvesrRrVrSÚset)r{rZ num_curvesZbuiltin_curvesrD)r{rrEÚ_load_elliptic_curves‘s    z$_EllipticCurve._load_elliptic_curvescCs|jdkr|j|ƒ|_|jS)a Get, cache, and return the curves supported by OpenSSL. :param lib: The OpenSSL library binding object. :return: A :py:type:`set` of ``cls`` instances giving the names of the elliptic curves the underlying library supports. N)Ú_curvesr—)r{rrDrDrEÚ_get_elliptic_curves¥s  z#_EllipticCurve._get_elliptic_curvescCs|||tj|j|ƒƒjdƒƒS)aË Instantiate a new :py:class:`_EllipticCurve` associated with the given OpenSSL NID. :param lib: The OpenSSL library binding object. :param nid: The OpenSSL NID the resulting curve object will represent. This must be a curve NID (and not, for example, a hash NID) or subsequent operations will fail in unpredictable ways. :type nid: :py:class:`int` :return: The curve object. Úascii)rRrhÚ OBJ_nid2snÚdecode)r{rr’rDrDrEr‘³sz_EllipticCurve.from_nidcCs||_||_||_dS)a‰ :param _lib: The :py:mod:`cryptography` binding instance used to interface with OpenSSL. :param _nid: The OpenSSL NID identifying the curve this object represents. :type _nid: :py:class:`int` :param name: The OpenSSL short name identifying the curve this object represents. :type name: :py:class:`unicode` N)rKÚ_nidrq)rnrr’rqrDrDrEroÄs z_EllipticCurve.__init__cCs d|jfS)Nz )rq)rnrDrDrEÚ__repr__Õsz_EllipticCurve.__repr__cCs|jj|jƒ}tj|tjƒS)zÅ Create a new OpenSSL EC_KEY structure initialized to use this curve. The structure is automatically garbage collected when the Python object is garbage collected. )rKZEC_KEY_new_by_curve_namer�rRrWZ EC_KEY_free)rnÚkeyrDrDrEÚ _to_EC_KEYØsz_EllipticCurve._to_EC_KEY)r@rArBrCr˜Ú_PY3rr‹r—r™r‘roržr Ú __classcell__rDrD)r�rErŒys   rŒcCs tjtƒS)a“ Return a set of objects representing the elliptic curves supported in the OpenSSL build in use. The curve objects have a :py:class:`unicode` ``name`` attribute by which they identify themselves. The curve objects are useful as values for the argument accepted by :py:meth:`Context.set_tmp_ecdh` to specify which elliptical curve should be used for ECDHE key exchange. )rŒr™rKrDrDrDrEr ãs cCs,xtƒD]}|j|kr|SqWtd|ƒ‚dS)aT Return a single curve object selected by name. See :py:func:`get_elliptic_curves` for information about curve objects. :param name: The OpenSSL short name identifying the curve object to retrieve. :type name: :py:class:`unicode` If the named curve is not supported then :py:class:`ValueError` is raised. zunknown curve nameN)r rqr`)rqZcurverDrDrEr!òs  csŒeZdZdZdd„Z‡fdd„Z‡fdd„Zdd „ZeeƒZee ƒZ ee ƒZ ee ƒZ ee ƒZ ee ƒZ d d „Zd d „Zdd„Zdd„Z‡ZS)r"a An X.509 Distinguished Name. :ivar countryName: The country of the entity. :ivar C: Alias for :py:attr:`countryName`. :ivar stateOrProvinceName: The state or province of the entity. :ivar ST: Alias for :py:attr:`stateOrProvinceName`. :ivar localityName: The locality of the entity. :ivar L: Alias for :py:attr:`localityName`. :ivar organizationName: The organization name of the entity. :ivar O: Alias for :py:attr:`organizationName`. :ivar organizationalUnitName: The organizational unit of the entity. :ivar OU: Alias for :py:attr:`organizationalUnitName` :ivar commonName: The common name of the entity. :ivar CN: Alias for :py:attr:`commonName`. :ivar emailAddress: The e-mail address of the entity. cCs tj|jƒ}tj|tjƒ|_dS)zž Create a new X509Name, copying the given X509Name instance. :param name: The name to copy. :type name: :py:class:`X509Name` N)rKÚ X509_NAME_duprsrRrWÚX509_NAME_free)rnrqrDrDrEros zX509Name.__init__c s|jdƒrtt|ƒj||ƒSt|ƒtk r.frD)r½r¾rD)r½rEÚ_cmpss z X509Name._cmpcCsBtjddƒ}tj|j|t|ƒƒ}t|tjkƒdttj |ƒƒfS)z6 String representation of an X509Name zchar[]iz) rRrSrKZX509_NAME_onelinersrTrUrVÚ_nativerh)rnr[Z format_resultrDrDrErž„s  zX509Name.__repr__cCs tj|jƒS)a& Return an integer representation of the first four bytes of the MD5 digest of the DER representation of the name. This is the Python equivalent of OpenSSL's ``X509_NAME_hash``. :return: The (integer) hash of this name. :rtype: :py:class:`int` )rKZX509_NAME_hashrs)rnrDrDrEÚhash�s z X509Name.hashcCsNtjdƒ}tj|j|ƒ}t|dkƒtj|d|ƒdd…}tj|dƒ|S)zŽ Return the DER encoding of this name. :return: The DER encoded form of this name. :rtype: :py:class:`bytes` zunsigned char**rN)rRrSrKZ i2d_X509_NAMErsrUrXr»)rnr[Z encode_resultrjrDrDrEÚderœs   z X509Name.derc CsŒg}x‚ttj|jƒƒD]n}tj|j|ƒ}tj|ƒ}tj|ƒ}tj|ƒ}tj|ƒ}t j tj |ƒtj |ƒƒdd…}|j t j|ƒ|fƒqW|S)z¼ Returns the components of this name, as a sequence of 2-tuples. :return: The components of this name. :rtype: :py:class:`list` of ``name, value`` tuples. N)r®rKr¯rsr°r±rºr²r›rRrXrirgrprh) rnr‚r¶r·ZfnameZfvalr’rqrµrDrDrEÚget_components«s     zX509Name.get_components)r@rArBrCror¨r¹r¿rrrrrr ržrÁrÂrÃr¢rDrD)r�rEr"s $ (  z6X509NameType has been deprecated, use X509Name insteadc@sdeZdZdZddd„Zedd„ƒZejdej dej d iZ d d „Z d d „Z dd„Zdd„Zdd„ZdS)r#z, An X.509 v3 certificate extension. NcCs¶tjdƒ}tj|tjtjtjtjdƒtj|ƒ|dk rRt|tƒsJtdƒ‚|j |_ |dk rtt|tƒsltdƒ‚|j |_ |r€d|}tj tj|||ƒ}|tjkr¢t ƒtj|tjƒ|_dS)a° Initializes an X509 extension. :param type_name: The name of the type of extension_ to create. :type type_name: :py:data:`bytes` :param bool critical: A flag indicating whether this is a critical extension. :param value: The value of the extension. :type value: :py:data:`bytes` :param subject: Optional X509 certificate to use as subject. :type subject: :py:class:`X509` :param issuer: Optional X509 certificate to use as issuer. :type issuer: :py:class:`X509` .. _extension: https://www.openssl.org/docs/manmaster/man5/ x509v3_config.html#STANDARD-EXTENSIONS z X509V3_CTX*rNzissuer must be an X509 instancez subject must be an X509 instances critical,)rRrSrKZX509V3_set_ctxrVZX509V3_set_ctx_nodbr]r%r_Ú_x509Ú issuer_certZ subject_certZX509V3_EXT_nconfrˆrWÚX509_EXTENSION_freeÚ _extension)rnZ type_nameZcriticalrµÚsubjectÚissuerZctxÚ extensionrDrDrEroÑs"     zX509Extension.__init__cCstjtj|jƒƒS)N)rKr²ÚX509_EXTENSION_get_objectrÇ)rnrDrDrEr�szX509Extension._nidZemailZDNSZURIc CsÔtjdtj|jƒƒ}tj|tjƒ}g}x¢ttj|ƒƒD]�}tj ||ƒ}y|j |j }Wn8t k rŽt ƒ}tj||ƒ|jtt|ƒƒƒYq6Xttj|jjj|jjjƒdd…ƒ}|j|d|ƒq6Wdj|ƒS)NzGENERAL_NAMES*ú:z, )rRrfrKZX509V3_EXT_d2irÇrWZGENERAL_NAMES_freer®Zsk_GENERAL_NAME_numZsk_GENERAL_NAME_valueÚ _prefixesr€ÚKeyErrorrZZGENERAL_NAME_printrprÀr\rXÚdZia5rYÚlengthÚjoin)rnÚnamesÚpartsr¶rqZlabelrMrµrDrDrEÚ_subjectAltNameStrings   "z#X509Extension._subjectAltNameStringcCsDtj|jkr|jƒStƒ}tj||jddƒ}t|dkƒtt |ƒƒS)zF :return: a nice text representation of the extension r) rKZNID_subject_alt_namer�rÔrZÚX509V3_EXT_printrÇrUrÀr\)rnrMÚ print_resultrDrDrEÚ__str__/s   zX509Extension.__str__cCs tj|jƒS)zk Returns the critical field of this X.509 extension. :return: The critical field. )rKZX509_EXTENSION_get_criticalrÇ)rnrDrDrEÚ get_critical<szX509Extension.get_criticalcCs&tj|jƒ}tj|ƒ}tjtj|ƒƒS)zü Returns the short type name of this X.509 extension. The result is a byte string such as :py:const:`b"basicConstraints"`. :return: The short type name. :rtype: :py:data:`bytes` .. versionadded:: 0.12 )rKrËrÇr²rRrhr›)rnÚobjr’rDrDrEÚget_short_nameDs  zX509Extension.get_short_namecCs@tj|jƒ}tjd|ƒ}tj|ƒ}tj|ƒ}tj||ƒdd…S)zÍ Returns the data of the X509 extension, encoded as ASN.1. :return: The ASN.1 encoded data of this X509 extension. :rtype: :py:data:`bytes` .. versionadded:: 0.12 z ASN1_STRING*N)rKÚX509_EXTENSION_get_datarÇrRrfrirgrX)rnZ octet_resultrjZ char_resultÚ result_lengthrDrDrEÚget_dataSs    zX509Extension.get_data)NN)r@rArBrCroÚpropertyr�rKZ GEN_EMAILZGEN_DNSZGEN_URIrÍrÔr×rØrÚrÝrDrDrDrEr#Ìs =   z@X509ExtensionType has been deprecated, use X509Extension insteadc@steZdZdZdd„Zdd„Zedd„ƒZdd „Zd d „Z d d „Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„ZdS)r$z0 An X.509 certificate signing requests. cCs&tjƒ}tj|tjƒ|_|jdƒdS)Nr)rKZ X509_REQ_newrRrWÚ X509_REQ_freeÚ_reqÚ set_version)rnÚreqrDrDrErooszX509Req.__init__cCsddlm}tƒ}|||jƒS)z® Export as a ``cryptography`` certificate signing request. :rtype: ``cryptography.x509.CertificateSigningRequest`` .. versionadded:: 17.1.0 r)Ú_CertificateSigningRequest)Ú)cryptography.hazmat.backends.openssl.x509rãrGrà)rnrãrFrDrDrEÚto_cryptographyus zX509Req.to_cryptographycCs&t|tjƒstdƒ‚|ƒ}|j|_|S)a Construct based on a ``cryptography`` *crypto_req*. :param crypto_req: A ``cryptography`` X.509 certificate signing request :type crypto_req: ``cryptography.x509.CertificateSigningRequest`` :rtype: X509Req .. versionadded:: 17.1.0 z%Must be a certificate signing request)r]r ZCertificateSigningRequestr_Z _x509_reqrà)r{Z crypto_reqrârDrDrEÚfrom_cryptographyƒs zX509Req.from_cryptographycCs tj|j|jƒ}t|dkƒdS)zµ Set the public key of the certificate signing request. :param pkey: The public key to use. :type pkey: :py:class:`PKey` :return: ``None`` r?N)rKZX509_REQ_set_pubkeyràrvrU)rnrxrcrDrDrEÚ set_pubkey–s zX509Req.set_pubkeycCsDtjtƒ}tj|jƒ|_t|jtjkƒtj |jtj ƒ|_d|_ |S)z‹ Get the public key of the certificate signing request. :return: The public key. :rtype: :py:class:`PKey` T) rÚ__new__rKZX509_REQ_get_pubkeyràrvrUrRrVrWrury)rnrxrDrDrEÚ get_pubkey¢s  zX509Req.get_pubkeycCstj|j|ƒ}t|dkƒdS)zµ Set the version subfield (RFC 2459, section 4.1.2.1) of the certificate request. :param int version: The version number. :return: ``None`` r?N)rKZX509_REQ_set_versionràrU)rnÚversionrcrDrDrErá°szX509Req.set_versioncCs tj|jƒS)z¿ Get the version subfield (RFC 2459, section 4.1.2.1) of the certificate request. :return: The value of the version subfield. :rtype: :py:class:`int` )rKZX509_REQ_get_versionrà)rnrDrDrEÚ get_version»szX509Req.get_versioncCs2tjtƒ}tj|jƒ|_t|jtjkƒ||_ |S)aÝ Return the subject of this certificate signing request. This creates a new :class:`X509Name` that wraps the underlying subject name field on the certificate signing request. Modifying it will modify the underlying signing request, and will have the effect of modifying any other :class:`X509Name` that refers to this subject. :return: The subject of this certificate signing request. :rtype: :class:`X509Name` ) r"rèrKZX509_REQ_get_subject_nameràrsrUrRrVÚ_owner)rnrqrDrDrEÚ get_subjectÅs zX509Req.get_subjectcCsptjƒ}t|tjkƒtj|tjƒ}x,|D]$}t|tƒs@t dƒ‚tj ||j ƒq*Wtj |j |ƒ}t|dkƒdS)z× Add extensions to the certificate signing request. :param extensions: The X.509 extensions to add. :type extensions: iterable of :py:class:`X509Extension` :return: ``None`` z+One of the elements is not an X509Extensionr?N)rKZsk_X509_EXTENSION_new_nullrUrRrVrWZsk_X509_EXTENSION_freer]r#r`Zsk_X509_EXTENSION_pushrÇZX509_REQ_add_extensionsrà)rnÚ extensionsÚstackÚextr¸rDrDrEÚadd_extensionsÛs  zX509Req.add_extensionscCsNg}tj|jƒ}x8ttj|ƒƒD]&}tjtƒ}tj||ƒ|_|j |ƒq W|S)zé Get X.509 extensions in the certificate signing request. :return: The X.509 extensions in this request. :rtype: :py:class:`list` of :py:class:`X509Extension` objects. .. versionadded:: 0.15 ) rKZX509_REQ_get_extensionsràr®Zsk_X509_EXTENSION_numr#rèZsk_X509_EXTENSION_valuerÇrp)rnZextsZnative_exts_objr¶rðrDrDrEÚget_extensionsòs   zX509Req.get_extensionscCs^|jrtdƒ‚|jstdƒ‚tjt|ƒƒ}|tjkrd?„Z#d@dA„Z$dBS)Cr%z An X.509 certificate. cCs:tjƒ}t|tjkƒtj|tjƒ|_tƒ|_ tƒ|_ dS)N) rKZX509_newrUrRrVrWÚ X509_freerÄrlÚ_issuer_invalidatorÚ_subject_invalidator)rnr rDrDrEro<s z X509.__init__cCs.|j|ƒ}tj|tjƒ|_tƒ|_tƒ|_|S)N) rèrRrWrKr÷rÄrlrørù)r{r ÚcertrDrDrEÚ_from_raw_x509_ptrDs  zX509._from_raw_x509_ptrcCsddlm}tƒ}|||jƒS)z� Export as a ``cryptography`` certificate. :rtype: ``cryptography.x509.Certificate`` .. versionadded:: 17.1.0 r)Ú _Certificate)rärürGrÄ)rnrürFrDrDrEråLs zX509.to_cryptographycCs&t|tjƒstdƒ‚|ƒ}|j|_|S)zü Construct based on a ``cryptography`` *crypto_cert*. :param crypto_key: A ``cryptography`` X.509 certificate. :type crypto_key: ``cryptography.x509.Certificate`` :rtype: X509 .. versionadded:: 17.1.0 zMust be a certificate)r]r Z Certificater_rÄ)r{Z crypto_certrúrDrDrEræXs zX509.from_cryptographycCs$t|tƒstdƒ‚tj|j|ƒdS)a  Set the version number of the certificate. Note that the version value is zero-based, eg. a value of 0 is V1. :param version: The version number of the certificate. :type version: :py:class:`int` :return: ``None`` zversion must be an integerN)r]r}r_rKZX509_set_versionrÄ)rnrêrDrDrEráks zX509.set_versioncCs tj|jƒS)z˜ Return the version number of the certificate. :return: The version number of the certificate. :rtype: :py:class:`int` )rKZX509_get_versionrÄ)rnrDrDrErëzszX509.get_versioncCsFtjtƒ}tj|jƒ|_|jtjkr*tƒtj |jtj ƒ|_d|_ |S)z{ Get the public key of the certificate. :return: The public key. :rtype: :py:class:`PKey` T) rrèrKÚX509_get_pubkeyrÄrvrRrVrˆrWrury)rnrxrDrDrEréƒs  zX509.get_pubkeycCs2t|tƒstdƒ‚tj|j|jƒ}t|dkƒdS)z¥ Set the public key of the certificate. :param pkey: The public key. :type pkey: :py:class:`PKey` :return: :py:data:`None` zpkey must be a PKey instancer?N)r]rr_rKZX509_set_pubkeyrÄrvrU)rnrxrcrDrDrErç’s zX509.set_pubkeycCspt|tƒstdƒ‚|jr tdƒ‚|js.tdƒ‚tjt|ƒƒ}|t j krNtdƒ‚tj |j |j |ƒ}t|dkƒdS)a Sign the certificate with this key and digest type. :param pkey: The key to sign with. :type pkey: :py:class:`PKey` :param digest: The name of the message digest to use. :type digest: :py:class:`bytes` :return: :py:data:`None` zpkey must be a PKey instancezKey only has public partzKey is uninitializedzNo such digest methodrN)r]rr_ryr`rwrKrór«rRrVZ X509_signrÄrvrU)rnrxrôZevp_mdrörDrDrEr7¡s  z X509.signcCs:tj|jƒ}tj|jƒ}|tjkr*tdƒ‚tjtj |ƒƒS)zþ Return the signature algorithm used in the certificate. :return: The name of the algorithm. :rtype: :py:class:`bytes` :raises ValueError: If the signature algorithm is undefined. .. versionadded:: 0.13 zUndefined signature algorithm) rKZX509_get0_tbs_sigalgrÄr²Ú algorithmr¬r`rRrhZ OBJ_nid2ln)rnZalgorr’rDrDrEÚget_signature_algorithm½s   zX509.get_signature_algorithmcCs„tjt|ƒƒ}|tjkr tdƒ‚tjdtjƒ}tjddƒ}t|ƒ|d<tj |j |||ƒ}t |dkƒdj dd„tj ||dƒDƒƒS) a7 Return the digest of the X509 object. :param digest_name: The name of the digest algorithm to use. :type digest_name: :py:class:`bytes` :return: The digest of the object, formatted as :py:const:`b":"`-delimited hex pairs. :rtype: :py:class:`bytes` zNo such digest methodzunsigned char[]zunsigned int[]r?ró:cSsg|]}t|ƒjƒ‘qSrD)rÚupper)r“ZchrDrDrEú æszX509.digest..)rKrór«rRrVr`rSZEVP_MAX_MD_SIZErTZ X509_digestrÄrUrÑrX)rnZ digest_namerôr[rÜZ digest_resultrDrDrErôÎs     z X509.digestcCs tj|jƒS)zƒ Return the hash of the X509 subject. :return: The hash of the subject. :rtype: :py:class:`bytes` )rKZX509_subject_name_hashrÄ)rnrDrDrEÚsubject_name_hashészX509.subject_name_hashcCsÖt|tƒstdƒ‚t|ƒdd…}t|tƒs6|jdƒ}tjdƒ}tj ||ƒ}|dtj krztj tj |j ƒ|ƒ}|rÒtƒnXtj|dtj ƒ}tj|dƒ|tj krªtƒtj|tjƒ}tj|j |ƒ}t|dkƒdS)z± Set the serial number of the certificate. :param serial: The new serial number. :type serial: :py:class:`int` :return: :py:data`None` zserial must be an integerr=NršzBIGNUM**rr?)r]Ú_integer_typesr_Úhexr^r´rRrSrKÚ BN_hex2bnrVZASN1_INTEGER_setÚX509_get_serialNumberrÄrˆÚBN_to_ASN1_INTEGERrrWÚASN1_INTEGER_freeZX509_set_serialNumberrU)rnÚserialÚ hex_serialÚ bignum_serialZ small_serialrcÚ asn1_serialrDrDrEÚset_serial_numberòs&      zX509.set_serial_numbercCs`tj|jƒ}tj|tjƒ}z4tj|ƒ}ztj|ƒ}t|dƒ}|Stj |ƒXWdtj |ƒXdS)zx Return the serial number of this certificate. :return: The serial number. :rtype: int r>N) rKrrÄZASN1_INTEGER_to_BNrRrVZ BN_bn2hexrhr}r»r)rnr r r Zhexstring_serialr rDrDrEÚget_serial_numbers    zX509.get_serial_numbercCs.t|tƒstdƒ‚tj|jƒ}tj||ƒdS)zÍ Adjust the time stamp on which the certificate stops being valid. :param int amount: The number of seconds by which to adjust the timestamp. :return: ``None`` zamount must be an integerN)r]r}r_rKÚX509_get_notAfterrÄÚX509_gmtime_adj)rnÚamountZnotAfterrDrDrEÚgmtime_adj_notAfter-s  zX509.gmtime_adj_notAftercCs.t|tƒstdƒ‚tj|jƒ}tj||ƒdS)z½ Adjust the timestamp on which the certificate starts being valid. :param amount: The number of seconds by which to adjust the timestamp. :return: ``None`` zamount must be an integerN)r]r}r_rKÚX509_get_notBeforerÄr)rnrZ notBeforerDrDrEÚgmtime_adj_notBefore;s  zX509.gmtime_adj_notBeforecCs(t|jƒƒ}tjj|dƒ}|tjjƒkS)z¡ Check whether the certificate has expired. :return: ``True`` if the certificate has expired, ``False`` otherwise. :rtype: bool z %Y%m%d%H%M%SZ)rÀÚ get_notAfterÚdatetimeZstrptimeZutcnow)rnZ time_stringZ not_afterrDrDrEÚ has_expiredHs zX509.has_expiredcCst||jƒƒS)N)rkrÄ)rnÚwhichrDrDrEÚ_get_boundary_timeTszX509._get_boundary_timecCs |jtjƒS)a  Get the timestamp at which the certificate starts being valid. The timestamp is formatted as an ASN.1 TIME:: YYYYMMDDhhmmssZ :return: A timestamp string, or ``None`` if there is none. :rtype: bytes or NoneType )rrKr)rnrDrDrEÚ get_notBeforeWs zX509.get_notBeforecCst||jƒ|ƒS)N)rdrÄ)rnrrbrDrDrEÚ_set_boundary_timedszX509._set_boundary_timecCs|jtj|ƒS)zî Set the timestamp at which the certificate starts being valid. The timestamp is formatted as an ASN.1 TIME:: YYYYMMDDhhmmssZ :param bytes when: A timestamp string. :return: ``None`` )rrKr)rnrbrDrDrEÚ set_notBeforegs zX509.set_notBeforecCs |jtjƒS)a  Get the timestamp at which the certificate stops being valid. The timestamp is formatted as an ASN.1 TIME:: YYYYMMDDhhmmssZ :return: A timestamp string, or ``None`` if there is none. :rtype: bytes or NoneType )rrKr)rnrDrDrErts zX509.get_notAftercCs|jtj|ƒS)zí Set the timestamp at which the certificate stops being valid. The timestamp is formatted as an ASN.1 TIME:: YYYYMMDDhhmmssZ :param bytes when: A timestamp string. :return: ``None`` )rrKr)rnrbrDrDrEÚ set_notAfter�s zX509.set_notAftercCs0tjtƒ}||jƒ|_t|jtjkƒ||_|S)N)r"rèrÄrsrUrRrVrì)rnrrqrDrDrEÚ _get_nameŽs   zX509._get_namecCs0t|tƒstdƒ‚||j|jƒ}t|dkƒdS)Nzname must be an X509Namer?)r]r"r_rÄrsrU)rnrrqrcrDrDrEÚ _set_name™s zX509._set_namecCs|jtjƒ}|jj|ƒ|S)a¥ Return the issuer of this certificate. This creates a new :class:`X509Name` that wraps the underlying issuer name field on the certificate. Modifying it will modify the underlying certificate, and will have the effect of modifying any other :class:`X509Name` that refers to this issuer. :return: The issuer of this certificate. :rtype: :class:`X509Name` )rrKZX509_get_issuer_namerørr)rnrqrDrDrEÚ get_issuerŸs  zX509.get_issuercCs|jtj|ƒ|jjƒdS)zŸ Set the issuer of this certificate. :param issuer: The issuer. :type issuer: :py:class:`X509Name` :return: ``None`` N)r rKZX509_set_issuer_namerørt)rnrÉrDrDrEÚ set_issuer¯s zX509.set_issuercCs|jtjƒ}|jj|ƒ|S)a© Return the subject of this certificate. This creates a new :class:`X509Name` that wraps the underlying subject name field on the certificate. Modifying it will modify the underlying certificate, and will have the effect of modifying any other :class:`X509Name` that refers to this subject. :return: The subject of this certificate. :rtype: :class:`X509Name` )rrKÚX509_get_subject_namerùrr)rnrqrDrDrErí»s  zX509.get_subjectcCs|jtj|ƒ|jjƒdS)z£ Set the subject of this certificate. :param subject: The subject. :type subject: :py:class:`X509Name` :return: ``None`` N)r rKZX509_set_subject_namerùrt)rnrÈrDrDrEÚ set_subjectËs zX509.set_subjectcCs tj|jƒS)z¯ Get the number of extensions on this certificate. :return: The number of extensions. :rtype: :py:class:`int` .. versionadded:: 0.12 )rKZX509_get_ext_countrÄ)rnrDrDrEÚget_extension_count×s zX509.get_extension_countcCs@x:|D]2}t|tƒstdƒ‚tj|j|jdƒ}|stƒqWdS)zÍ Add extensions to the certificate. :param extensions: The extensions to add. :type extensions: An iterable of :py:class:`X509Extension` objects. :return: ``None`` z+One of the elements is not an X509Extensionr?Nr¦)r]r#r`rKZ X509_add_extrÄrÇrˆ)rnrîrðr¸rDrDrErñâs   zX509.add_extensionscCsNtjtƒ}tj|j|ƒ|_|jtjkr.tdƒ‚tj |jƒ}tj |tj ƒ|_|S)aÏ Get a specific extension of the certificate by index. Extensions on a certificate are kept in order. The index parameter selects which extension will be returned. :param int index: The index of the extension to retrieve. :return: The extension at the specified index. :rtype: :py:class:`X509Extension` :raises IndexError: If the extension index was out of bounds. .. versionadded:: 0.12 zextension index out of bounds) r#rèrKZ X509_get_extrÄrÇrRrVÚ IndexErrorZX509_EXTENSION_duprWrÆ)rnÚindexrðrÊrDrDrEÚ get_extensionòs   zX509.get_extensionN)%r@rArBrCror‹rûrårærárërérçr7rÿrôrrrrrrrrrrrrrr r!r"rír$r%rñr(rDrDrDrEr%8sB    '          z.X509Type has been deprecated, use X509 insteadc@sReZdZdZejZejZej Z ej Z ej ZejZejZejZejZejZejZdS)r&a  Flags for X509 verification, used to change the behavior of :class:`X509Store`. See `OpenSSL Verification Flags`_ for details. .. _OpenSSL Verification Flags: https://www.openssl.org/docs/manmaster/man3/X509_VERIFY_PARAM_set_flags.html N)r@rArBrCrKZX509_V_FLAG_CRL_CHECKZ CRL_CHECKZX509_V_FLAG_CRL_CHECK_ALLZ CRL_CHECK_ALLZX509_V_FLAG_IGNORE_CRITICALZIGNORE_CRITICALZX509_V_FLAG_X509_STRICTZ X509_STRICTZX509_V_FLAG_ALLOW_PROXY_CERTSZALLOW_PROXY_CERTSZX509_V_FLAG_POLICY_CHECKZ POLICY_CHECKZX509_V_FLAG_EXPLICIT_POLICYZEXPLICIT_POLICYZX509_V_FLAG_INHIBIT_MAPZ INHIBIT_MAPZX509_V_FLAG_NOTIFY_POLICYZ NOTIFY_POLICYZX509_V_FLAG_CHECK_SS_SIGNATUREZCHECK_SS_SIGNATUREZX509_V_FLAG_CB_ISSUER_CHECKZCB_ISSUER_CHECKrDrDrDrEr&s c@s8eZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd S) r'aº An X.509 store. An X.509 store is used to describe a context in which to verify a certificate. A description of a context may include a set of certificates to trust, a set of certificate revocation lists, verification flags and more. An X.509 store, being only a description, cannot be used by itself to verify a certificate. To carry out the actual verification process, see :class:`X509StoreContext`. cCstjƒ}tj|tjƒ|_dS)N)rKZX509_STORE_newrRrWZX509_STORE_freeÚ_store)rnÚstorerDrDrEro6szX509Store.__init__cCsPt|tƒstƒ‚tj|j|jƒdkrLtjƒ}tj|ƒ}t |tj kƒtj ƒdS)aÔ Adds a trusted certificate to this store. Adding a certificate with this method adds this certificate as a *trusted* certificate. :param X509 cert: The certificate to add to this store. :raises TypeError: If the certificate is not an :class:`X509`. :raises OpenSSL.crypto.Error: If OpenSSL was unhappy with your certificate. :return: ``None`` if the certificate was added successfully. rN) r]r%r_rKZX509_STORE_add_certr)rÄZERR_peek_errorZERR_GET_REASONrUZ!X509_R_CERT_ALREADY_IN_HASH_TABLEZERR_clear_error)rnrúÚcodeZ err_reasonrDrDrEÚadd_cert:s   zX509Store.add_certcCsttj|j|jƒdkƒdS)a¿ Add a certificate revocation list to this store. The certificate revocation lists added to a store will only be used if the associated flags are configured to check certificate revocation lists. .. versionadded:: 16.1.0 :param CRL crl: The certificate revocation list to add to this store. :return: ``None`` if the certificate revocation list was added successfully. rN)rUrKZX509_STORE_add_crlr)Ú_crl)rnÚcrlrDrDrEÚadd_crlXszX509Store.add_crlcCsttj|j|ƒdkƒdS)aÒ Set verification flags to this store. Verification flags can be combined by oring them together. .. note:: Setting a verification flag sometimes requires clients to add additional information to the store, otherwise a suitable error will be raised. For example, in setting flags to enable CRL checking a suitable CRL must be added to the store otherwise an error will be raised. .. versionadded:: 16.1.0 :param int flags: The verification flags to set on this store. See :class:`X509StoreFlags` for available constants. :return: ``None`` if the verification flags were successfully set. rN)rUrKZX509_STORE_set_flagsr))rnÚflagsrDrDrEÚ set_flagshszX509Store.set_flagscCsFtjƒ}tj|tjƒ}tj|t|jdƒƒƒttj |j |ƒdkƒdS)a¤ Set the time against which the certificates are verified. Normally the current time is used. .. note:: For example, you can determine if a certificate was valid at a given time. .. versionadded:: 17.0.0 :param datetime vfy_time: The verification time to set on this store. :return: ``None`` if the verification time was successfully set. z%srN) rKZX509_VERIFY_PARAM_newrRrWZX509_VERIFY_PARAM_freeZX509_VERIFY_PARAM_set_timer}ZstrftimerUZX509_STORE_set1_paramr))rnZvfy_timeZparamrDrDrEÚset_time€szX509Store.set_timeN) r@rArBrCror,r/r1r2rDrDrDrEr'(s  z8X509StoreType has been deprecated, use X509Store insteadcs eZdZdZ‡fdd„Z‡ZS)r(zù An exception raised when an error occurred while verifying a certificate using `OpenSSL.X509StoreContext.verify_certificate`. :ivar certificate: The certificate which caused verificate failure. :type certificate: :class:`X509` cstt|ƒj|ƒ||_dS)N)r�r(roÚ certificate)rnÚmessager3)r�rDrEro§szX509StoreContextError.__init__)r@rArBrCror¢rDrD)r�rEr(žsc@s@eZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dS)r)a® An X.509 store context. An X.509 store context is used to carry out the actual verification process of a certificate in a described context. For describing such a context, see :class:`X509Store`. :ivar _store_ctx: The underlying X509_STORE_CTX structure used by this instance. It is dynamically allocated and automatically garbage collected. :ivar _store: See the ``store`` ``__init__`` parameter. :ivar _cert: See the ``certificate`` ``__init__`` parameter. :param X509Store store: The certificates which will be trusted for the purposes of any verifications. :param X509 certificate: The certificate to be verified. cCs0tjƒ}tj|tjƒ|_||_||_|jƒdS)N) rKZX509_STORE_CTX_newrRrWZX509_STORE_CTX_freeÚ _store_ctxr)Ú_certÚ_init)rnr*r3Z store_ctxrDrDrEro¾s zX509StoreContext.__init__cCs.tj|j|jj|jjtjƒ}|dkr*tƒdS)zÀ Set up the store context for a subsequent verification operation. Calling this method more than once without first calling :meth:`_cleanup` will leak memory. rN) rKZX509_STORE_CTX_initr5r)r6rÄrRrVrˆ)rnÚretrDrDrEr7ÈszX509StoreContext._initcCstj|jƒdS)z‰ Internally cleans up the store context. The store context can then be reused with a new call to :meth:`_init`. N)rKZX509_STORE_CTX_cleanupr5)rnrDrDrEÚ_cleanupÕszX509StoreContext._cleanupcCs\tj|jƒtj|jƒttjtjtj|jƒƒƒƒg}tj|jƒ}tj |ƒ}t j |ƒ}t ||ƒS)zú Convert an OpenSSL native context error failure into a Python exception. When a call to native OpenSSL X509_verify_cert fails, additional information about the failure can be obtained from the store context. ) rKZX509_STORE_CTX_get_errorr5ZX509_STORE_CTX_get_error_depthrÀrRrhZX509_verify_cert_error_stringZX509_STORE_CTX_get_current_certZX509_dupr%rûr()rnÚerrorsrÄr6ÚpycertrDrDrEÚ_exception_from_contextÝs      z(X509StoreContext._exception_from_contextcCs ||_dS)zÖ Set the context's X.509 store. .. versionadded:: 0.15 :param X509Store store: The store description which will be used for the purposes of any *future* verifications. N)r))rnr*rDrDrEÚ set_storeòs zX509StoreContext.set_storecCs8|jƒ|jƒtj|jƒ}|jƒ|dkr4|jƒ‚dS)a" Verify a certificate in a context. .. versionadded:: 0.15 :raises X509StoreContextError: If an error occurred when validating a certificate in the context. Sets ``certificate`` attribute to indicate which certificate caused the error. rN)r9r7rKZX509_verify_certr5r<)rnr8rDrDrEÚverify_certificateýs  z#X509StoreContext.verify_certificateN) r@rArBrCror7r9r<r=r>rDrDrDrEr)¬s   cCsvt|tƒr|jdƒ}t|ƒ}|tkr.rr?)rNr]r^r_rQÚreplaceÚ _crl_reasonsr'rKZASN1_ENUMERATED_newrUrRrVrWZASN1_ENUMERATED_freeZASN1_ENUMERATED_setZX509_REVOKED_add1_ext_i2drGrM)rnÚreasonZ reason_codeZnew_reason_extrcr¸rDrDrEÚ set_reasonês    zRevoked.set_reasoncCs†x€ttj|jƒƒD]l}tj|j|ƒ}tj|ƒ}tj|ƒtjkrtƒ}tj ||ddƒ}|svtj |tj |ƒƒ}t |dkƒt |ƒSqWdS)a  Get the reason of this revocation. :return: The reason, or ``None`` if there is none. :rtype: bytes or NoneType .. seealso:: :meth:`all_reasons`, which gives you a list of all supported reasons this method might return. rN)r®rKrKrGrLrËr²rMrZrÕZM_ASN1_OCTET_STRING_printrÛrUr\)rnr¶rðrÙrMrÖrDrDrEÚ get_reasons   zRevoked.get_reasoncCs|jdd…S)a Return a list of all the supported reason strings. This list is a copy; modifying it does not change the supported reason strings. :return: A list of reason strings. :rtype: :class:`list` of :class:`bytes` N)rT)rnrDrDrEÚ all_reasons)s zRevoked.all_reasonscCstj|jƒ}t||ƒS)z¡ Set the revocation timestamp. :param bytes when: The timestamp of the revocation, as ASN.1 TIME. :return: ``None`` )rKÚ X509_REVOKED_get0_revocationDaterGrd)rnrbÚdtrDrDrEÚ set_rev_date5s zRevoked.set_rev_datecCstj|jƒ}t|ƒS)z‡ Get the revocation timestamp. :return: The timestamp of the revocation, as ASN.1 TIME. :rtype: bytes )rKrYrGrk)rnrZrDrDrEÚ get_rev_date@s zRevoked.get_rev_dateN)r@rArBrCrTrorIrJrNrVrWrXr[r\rDrDrDrEr.¡s" $  c@s|eZdZdZdd„Zdd„Zedd„ƒZdd „Zd d „Z d d „Z dd„Z dd„Z dd„Z dd„Zdd„Zedefdd„ZdS)r/z( A certificate revocation list. cCstjƒ}tj|tjƒ|_dS)N)rKZ X509_CRL_newrRrWÚ X509_CRL_freer-)rnr.rDrDrEroPsz CRL.__init__cCsddlm}tƒ}|||jƒS)z– Export as a ``cryptography`` CRL. :rtype: ``cryptography.x509.CertificateRevocationList`` .. versionadded:: 17.1.0 r)Ú_CertificateRevocationList)rär^rGr-)rnr^rFrDrDrEråTs zCRL.to_cryptographycCs&t|tjƒstdƒ‚|ƒ}|j|_|S)a Construct based on a ``cryptography`` *crypto_crl*. :param crypto_crl: A ``cryptography`` certificate revocation list :type crypto_crl: ``cryptography.x509.CertificateRevocationList`` :rtype: CRL .. versionadded:: 17.1.0 z%Must be a certificate revocation list)r]r ZCertificateRevocationListr_Z _x509_crlr-)r{Z crypto_crlr.rDrDrEræbs zCRL.from_cryptographycCsrg}tj|jƒ}xPttj|ƒƒD]>}tj||ƒ}tj|ƒ}tjtƒ}t j |tj ƒ|_ |j |ƒq W|rnt|ƒSdS)aA Return the revocations in this certificate revocation list. These revocations will be provided by value, not by reference. That means it's okay to mutate them: it won't affect this CRL. :return: The revocations in this CRL. :rtype: :class:`tuple` of :class:`Revocation` N)rKZX509_CRL_get_REVOKEDr-r®Zsk_X509_REVOKED_numZsk_X509_REVOKED_valueÚCryptography_X509_REVOKED_dupr.rèrRrWrFrGrpÚtuple)rnÚresultsZ revoked_stackr¶rHZ revoked_copyZpyrevrDrDrEÚ get_revokedus     zCRL.get_revokedcCs8tj|jƒ}t|tjkƒtj|j|ƒ}t|dkƒdS)a9 Add a revoked (by value not reference) to the CRL structure This revocation will be added by value, not by reference. That means it's okay to mutate it after adding: it won't affect this CRL. :param Revoked revoked: The new revocation. :return: ``None`` rN)rKr_rGrUrRrVZX509_CRL_add0_revokedr-)rnrHÚcopyr¸rDrDrEÚ add_revokedŠs zCRL.add_revokedcCsBtjtj|jƒƒ}t|tjkƒtj|tjƒ}t j t ƒ}||_ |S)zc Get the CRL's issuer. .. versionadded:: 16.1.0 :rtype: X509Name ) rKr£ZX509_CRL_get_issuerr-rUrRrVrWr¤r"rèrs)rnZ_issuerrÉrDrDrEr!›s  zCRL.get_issuercCsttj|j|ƒdkƒdS)z— Set the CRL version. .. versionadded:: 16.1.0 :param int version: The version of the CRL. :return: ``None`` rN)rUrKZX509_CRL_set_versionr-)rnrêrDrDrEráªs zCRL.set_versioncCst||jƒ|ƒS)N)rdr-)rnrrbrDrDrErµszCRL._set_boundary_timecCs|jtj|ƒS)zô Set when the CRL was last updated. The timestamp is formatted as an ASN.1 TIME:: YYYYMMDDhhmmssZ .. versionadded:: 16.1.0 :param bytes when: A timestamp string. :return: ``None`` )rrKZX509_CRL_get_lastUpdate)rnrbrDrDrEÚset_lastUpdate¸s zCRL.set_lastUpdatecCs|jtj|ƒS)zø Set when the CRL will next be udpated. The timestamp is formatted as an ASN.1 TIME:: YYYYMMDDhhmmssZ .. versionadded:: 16.1.0 :param bytes when: A timestamp string. :return: ``None`` )rrKZX509_CRL_get_nextUpdate)rnrbrDrDrEÚset_nextUpdateÇs zCRL.set_nextUpdatecCs\tj|ƒ}t|tjkƒtj|jtj|jƒƒtj |jƒtj |j|j |ƒ}t|dkƒdS)a; Sign the CRL. Signing a CRL enables clients to associate the CRL itself with an issuer. Before a CRL is meaningful to other OpenSSL functions, it must be signed by an issuer. This method implicitly sets the issuer's name based on the issuer certificate and private key used to sign the CRL. .. versionadded:: 16.1.0 :param X509 issuer_cert: The issuer's certificate. :param PKey issuer_key: The issuer's private key. :param bytes digest: The digest method to sign the CRL with. rN) rKrórUrRrVÚX509_CRL_set_issuer_namer-r#rÄZ X509_CRL_sortÚ X509_CRL_signrv)rnrÅZ issuer_keyrôrõr‚rDrDrEr7Ös  zCRL.signédc Cst|tƒstdƒ‚t|tƒs$tdƒ‚t|tƒs6tdƒ‚|tkrFtdƒ‚tj|ƒ}|tj krbt dƒ‚tj tj ƒƒ}t |tj kƒtjƒ}t |tj kƒtj|dƒtj|j|ƒtj||dddƒtj|j|ƒtj|jtj|jƒƒtj|j|j|ƒ} | �stƒt||ƒS) aô Export the CRL as a string. :param X509 cert: The certificate used to sign the CRL. :param PKey key: The key used to sign the CRL. :param int type: The export format, either :data:`FILETYPE_PEM`, :data:`FILETYPE_ASN1`, or :data:`FILETYPE_TEXT`. :param int days: The number of days until the next update of this CRL. :param bytes digest: The name of the message digest to use (eg ``b"sha2566"``). :rtype: bytes zcert must be an X509 instancezkey must be a PKey instanceztype must be an integerzdigest must be providedzNo such digest methodréé<)r]r%r_rr}Ú _UNSPECIFIEDrKrórRrVr`rPrQrUZ ASN1_TIME_newrZX509_CRL_set_lastUpdater-ZX509_CRL_set_nextUpdatergr#rÄrhrvrˆr9) rnrúrŸr€ZdaysrôrõrMZsometimerörDrDrEÚexportïs2      z CRL.exportN)r@rArBrCrorår‹rærbrdr!rárrerfr7rrlrmrDrDrDrEr/Ks  z,CRLType has been deprecated, use CRL insteadc@s4eZdZdd„Zdd„Zdd„Zdd„Zd d „Zd S) r0cCsttj|jƒƒS)zm Check if this NID_pkcs7_signed object :return: True if the PKCS7 is of type signed )ÚboolrKZPKCS7_type_is_signedÚ_pkcs7)rnrDrDrEÚtype_is_signed- szPKCS7.type_is_signedcCsttj|jƒƒS)zt Check if this NID_pkcs7_enveloped object :returns: True if the PKCS7 is of type enveloped )rnrKZPKCS7_type_is_envelopedro)rnrDrDrEÚtype_is_enveloped5 szPKCS7.type_is_envelopedcCsttj|jƒƒS)z† Check if this NID_pkcs7_signedAndEnveloped object :returns: True if the PKCS7 is of type signedAndEnveloped )rnrKZ PKCS7_type_is_signedAndEnvelopedro)rnrDrDrEÚtype_is_signedAndEnveloped= sz PKCS7.type_is_signedAndEnvelopedcCsttj|jƒƒS)zi Check if this NID_pkcs7_data object :return: True if the PKCS7 is of type data )rnrKZPKCS7_type_is_dataro)rnrDrDrEÚ type_is_dataE szPKCS7.type_is_datacCs"tj|jjƒ}tj|ƒ}tj|ƒS)zk Returns the type name of the PKCS7 structure :return: A string with the typename )rKr²ror€r›rRrh)rnr’Z string_typerDrDrEÚ get_type_nameM s zPKCS7.get_type_nameN)r@rArBrprqrrrsrtrDrDrDrEr0, s z0PKCS7Type has been deprecated, use PKCS7 insteadc@sbeZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z dd„Z dd„Z ddd„Z dS)r1z A PKCS #12 archive. cCsd|_d|_d|_d|_dS)N)rvr6Ú_cacertsÚ _friendlyname)rnrDrDrErod szPKCS12.__init__cCs|jS)z¾ Get the certificate in the PKCS #12 structure. :return: The certificate, or :py:const:`None` if there is none. :rtype: :py:class:`X509` or :py:const:`None` )r6)rnrDrDrEÚget_certificatej szPKCS12.get_certificatecCst|tƒstdƒ‚||_dS)zà Set the certificate in the PKCS #12 structure. :param cert: The new certificate, or :py:const:`None` to unset it. :type cert: :py:class:`X509` or :py:const:`None` :return: ``None`` zcert must be an X509 instanceN)r]r%r_r6)rnrúrDrDrEÚset_certificates s zPKCS12.set_certificatecCs|jS)zª Get the private key in the PKCS #12 structure. :return: The private key, or :py:const:`None` if there is none. :rtype: :py:class:`PKey` )rv)rnrDrDrEÚget_privatekey€ szPKCS12.get_privatekeycCst|tƒstdƒ‚||_dS)zè Set the certificate portion of the PKCS #12 structure. :param pkey: The new private key, or :py:const:`None` to unset it. :type pkey: :py:class:`PKey` or :py:const:`None` :return: ``None`` zpkey must be a PKey instanceN)r]rr_rv)rnrxrDrDrEÚset_privatekey‰ s zPKCS12.set_privatekeycCs|jdk rt|jƒSdS)a Get the CA certificates in the PKCS #12 structure. :return: A tuple with the CA certificates in the chain, or :py:const:`None` if there are none. :rtype: :py:class:`tuple` of :py:class:`X509` or :py:const:`None` N)rur`)rnrDrDrEÚget_ca_certificates– s zPKCS12.get_ca_certificatescCsB|dkrd|_n.t|ƒ}x|D]}t|tƒstdƒ‚qW||_dS)a Replace or set the CA certificates within the PKCS12 object. :param cacerts: The new CA certificates, or :py:const:`None` to unset them. :type cacerts: An iterable of :py:class:`X509` or :py:const:`None` :return: ``None`` Nz)iterable must only contain X509 instances)ruÚlistr]r%r_)rnÚcacertsrúrDrDrEÚset_ca_certificates¡ s    zPKCS12.set_ca_certificatescCs2|dkrd|_nt|tƒs(td|fƒ‚||_dS)zâ Set the friendly name in the PKCS #12 structure. :param name: The new friendly name, or :py:const:`None` to unset. :type name: :py:class:`bytes` or :py:const:`None` :return: ``None`` Nz+name must be a byte string or None (not %r))rvr]r^r_)rnrqrDrDrEÚset_friendlyname¶ s   zPKCS12.set_friendlynamecCs|jS)zÅ Get the friendly name in the PKCS# 12 structure. :returns: The friendly name, or :py:const:`None` if there is none. :rtype: :py:class:`bytes` or :py:const:`None` )rv)rnrDrDrEÚget_friendlynameÇ szPKCS12.get_friendlynameNér?c Csþtd|ƒ}|jdkrtj}n4tjƒ}tj|tjƒ}x|jD]}tj||j ƒq:W|dkr^tj}|j }|dkrrtj}|j dkr„tj}n|j j }|j dkržtj}n|j j }tj |||||tjtj||dƒ }|tjkrÖtƒtj|tjƒ}tƒ} tj| |ƒt| ƒS)a€ Dump a PKCS12 object as a string. For more information, see the :c:func:`PKCS12_create` man page. :param passphrase: The passphrase used to encrypt the structure. Unlike some other passphrase arguments, this *must* be a string, not a callback. :type passphrase: :py:data:`bytes` :param iter: Number of times to repeat the encryption step. :type iter: :py:data:`int` :param maciter: Number of times to repeat the MAC step. :type maciter: :py:data:`int` :return: The string representation of the PKCS #12 structure. :rtype: rDNr)Ú_text_to_bytes_and_warnrurRrVrKZsk_X509_new_nullrWÚ sk_X509_freeZ sk_X509_pushrÄrvrvr6Z PKCS12_createZ&NID_pbe_WithSHA1And3_Key_TripleDES_CBCrˆÚ PKCS12_freerZZi2d_PKCS12_bior\) rnrDÚiterZmaciterr}rúÚ friendlynamerxÚpkcs12rMrDrDrErmÐ s:         z PKCS12.export)Nr�r?)r@rArBrCrorwrxryrzr{r~rr€rmrDrDrDrEr1_ s      z2PKCS12Type has been deprecated, use PKCS12 insteadc@s@eZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dS)r2z! A Netscape SPKI object. cCstjƒ}tj|tjƒ|_dS)N)rKZNETSCAPE_SPKI_newrRrWZNETSCAPE_SPKI_freeÚ_spki)rnZspkirDrDrEro szNetscapeSPKI.__init__cCs^|jrtdƒ‚|jstdƒ‚tjt|ƒƒ}|tjkrNetscapeSPKIType has been deprecated, use NetscapeSPKI insteadc@sBeZdZd dd„Zedd„ƒZedd„ƒZefdd „Zd d „Z d S)r@FcCs4|tkr|dk rtdƒ‚||_||_||_g|_dS)Nz0only FILETYPE_PEM key format supports encryption)rr`Ú _passphraseÚ _more_argsÚ _truncateÚ _problems)rnr€rDZ more_argsÚtruncaterDrDrErov sz_PassphraseHelper.__init__cCsF|jdkrtjSt|jtƒr"tjSt|jƒr:tjd|jƒStdƒ‚dS)NZpem_password_cbz2Last argument must be a byte string or a callable.) rŠrRrVr]r^ÚcallablerAÚ_read_passphraser_)rnrDrDrErA€ s   z_PassphraseHelper.callbackcCs>|jdkrtjSt|jtƒr"|jSt|jƒr2tjStdƒ‚dS)Nz2Last argument must be a byte string or a callable.)rŠrRrVr]r^r�r_)rnrDrDrErB� s   z_PassphraseHelper.callback_argsc Cs8|jr4y t|ƒWn|k r&YnX|jjdƒ‚dS)Nr)r�Ú_exception_from_error_queueÚpop)rnZ exceptionTyperDrDrErCš s  z"_PassphraseHelper.raise_if_problemcCs¾yŒ|jr|j|||ƒ}n |j|ƒ}t|tƒs4tdƒ‚t|ƒ|kr\|jrT|d|…}ntdƒ‚x(tt|ƒƒD]}|||d…||<qjWt|ƒStk r¸}z|j j |ƒdSd}~XnXdS)NzString expectedz+passphrase returned by callback is too longr?r) r‹rŠr]r^r`rTrŒr®Ú Exceptionr�rp)rnZbufÚsizeZrwflagZuserdatar‚r¶ÚerDrDrEr�¥ s"    z"_PassphraseHelper._read_passphraseN)FF) r@rArBrorÞrArBrrCr�rDrDrDrEr@u s  r@cCs�t|tƒr|jdƒ}t|ƒ}|tkrs$     (     ( jBHUoh ;+[,/ZG! $"$ `