<#e dUddlZddlZddlZddlmZddlmZddlmZddlm Z m Z m Z m Z m Z mZmZmZmZmZmZddlmZmZddlmZmZmZmZmZddlmZm Z!m"Z#m$Z%m&Z'm(Z)m*Z+m,Z-gd Z.eej^ej`ejbejdfZ3ee4e5efZ6ee5e d e5ffZ7e'jpZ9e:e;d <e'jxZ=e:e;d <d Z>e'j~Z@e:e;d<e'jZBe:e;d<e'jZDe:e;d<e'jZFe:e;d<GddeGZHee#eHZIe)eHZJde4de fdZKdcdee5de fdZLde de5fdZMde de5ddfdZNde5de fdZOde dee5fd ZPGd!d"ZQGd#d$ZRGd%d&ZSded&fd'ZTd(e4deSfd)ZUejGd*d+ZWGd,d-ZXGd.d/ZYGd0d1ZZGd2d3Z[Gd4d5Z\Gd6d7eGZ]Gd8d9Z^d:e:de5deZfd;Z_d:e:deRde5fd?Za ddd:e:d>eRd@ee4dAee7de5f dBZbGdCdDZcGdEdFZdGdGdHZeGdIdJZfGdKdLZgGdMdNZhd:e:dee4e5fdeRfdOZi dcd:e:dee4e5fdAee7deRfdPZjd:e:dQeYde5fdRZkd:e:de5deYfdSZld>eRdTee4e5fdUe4de5fdVZmd.frees==% %rL) rZBIO_new BIO_s_memr[_ffinewBIO_new_mem_buflenr_openssl_assertNULLgc)rSrVr\datas rM _new_mem_bufrgxs~ll4>>+,}}xx&)""4V5'+ &c & &s &C499$% ''#t C JrLrVctjd}tj||}tj|d|ddS)zO Copy the contents of an OpenSSL BIO object into a Python byte string. zchar**rN)r_r`rZBIO_get_mem_datarS)rV result_buffer buffer_lengths rM_bio_to_stringrls?HHX&M))#}=M ;;}Q' 7 ::rLboundarywhenct|ts tdt|tj k7t j||}|dk(r tdy)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) isinstancebytes TypeErrorrcr_rdrZASN1_TIME_set_string ValueError)rmrn set_results rM_set_asn1_timervsW dE "455H )***8T:JQ)**rLctj}t|tjk7tj |tj }t|||S)a Behaves like _set_asn1_time but returns a new ASN1_TIME object. @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. )rZ ASN1_TIME_newrcr_rdreASN1_TIME_freerv)rnrets rM_new_asn1_timer{sH    CC499$% ''#t** +C3 JrL timestampcPtjd|}tj|dk(rytj|tj k(r(tj tj|Stjd}tj|||dtjk(r tdytjd|d}tj|}tj |}tj|d|S)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. ASN1_STRING*rNzASN1_GENERALIZEDTIME**ASN1_TIME_to_generalizedtime) r_castrZASN1_STRING_lengthASN1_STRING_typeV_ASN1_GENERALIZEDTIMEstringASN1_STRING_get0_datar`rrdrRASN1_GENERALIZEDTIME_free)r|string_timestampgeneralized_timestamp string_data string_results rM_get_asn1_timersyy; /0A5 ./43N3NN{{4556FGHH $)A B )))5JK  #tyy 0 : ;#yy 5a 8  445EFK KK 4M  * *+@+C D rLc$eZdZddZddZddZy)_X509NameInvalidatorNcg|_yrY)_namesselfs rM__init__z_X509NameInvalidator.__init__s &( rLc:|jj|yrY)rappendrnames rMaddz_X509NameInvalidator.adds 4 rLc*|jD]}|`yrY)r_namers rMclearz_X509NameInvalidator.clearsKK D  rLrONrr)rON)rGrHrIrrrrKrLrMrrs)!rLrc~eZdZdZdZdZddZdefdZe deddfd Z d e d e ddfd Z de fd Zde fdZde fdZy)r&zD A class representing an DSA or RSA public key or key pair. FTrONctj}tj|tj|_d|_y)NF)rZ EVP_PKEY_newr_re EVP_PKEY_free_pkey _initializedrpkeys rMrz PKey.__init__s0  "WWT4#5#56 !rLcddlm}m}|jrt t |}||St t |}||dS)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 r)load_der_private_keyload_der_public_keyN),cryptography.hazmat.primitives.serializationrr _only_publicr3r!r4)rrrders rMto_cryptography_keyzPKey.to_cryptography_key sB    5C&s+ +!-6C'T2 2rL crypto_keyc Nt|tjtjtj tj tjtjtjfs tdddlm}m}m}m}t|tjtj fr4t't(|j+|j,|j.S|j1|j,|j2|}t5t(|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 typer)Encoding NoEncryption PrivateFormat PublicFormat)rpr RSAPublicKey RSAPrivateKeyr DSAPublicKey DSAPrivateKeyrEllipticCurvePrivateKeyrEd25519PrivateKeyrEd448PrivateKeyrrrrrrrr:r! public_bytesDERSubjectPublicKeyInfo private_bytesPKCS8r;)clsrrrrrrs rMfrom_cryptography_keyzPKey.from_cryptography_key!s   !!  !!**))%%   23 3   j3#3#3S5E5E"F G!''LL,"C"C ** m11<>C#=#6 6rLtypebitsc t|ts tdt|ts td|tk(r|dkr t dt j }tj|t j}t j|t jt j}t j|||tj}t|dk(t j |j"|}t|dk(d|_y|t$k(r t j&}t|tjk7tj|t j(}t j*||tjdtjtjtj}t|dk(tt j,|dk(tt j.|j"|dk(d|_yt1d) a3 Generate a key pair of the given type, with the given number of bits. This generates a key "into" the this object. :param type: The key type. :type type: :py:data:`TYPE_RSA` or :py:data:`TYPE_DSA` :param bits: The number of bits. :type bits: :py:data:`int` ``>= 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`` type must be an integerzbits must be an integerrzInvalid number of bitszNo such key typeTN)rpintrrr#rtrZBN_newr_reBN_free BN_set_wordRSA_F4RSA_newRSA_generate_key_exrdrcEVP_PKEY_assign_RSArr$DSA_newDSA_freeDSA_generate_parameters_exDSA_generate_keyEVP_PKEY_set1_DSAr%r)rrrexponentrresultrress rM generate_keyzPKey.generate_keyOs $$56 6$$56 6 8 qy !9::{{}Hwwx6H   Xt{{ 3,,.C--c4499MF FaK (--djj#>F FaK ("!X ,,.C C499, -''#t}}-C11T499aDIItyyC C1H % D11#6!; < D224::sCqH I!*+ +rLc|jr tdtj|j tj k7r tdtj |j}tj|tj}tj|}|dk(ryty)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 onlyz'Only RSA keys can currently be checked.rTN) rrrrZ EVP_PKEY_typer EVP_PKEY_RSAEVP_PKEY_get1_RSArr_reRSA_free RSA_check_key_raise_current_error)rrrs rMcheckz PKey.checks   -. .   diik *d.?.? ?EF F$$TZZ0ggc4==)##C( Q;rLc@tj|jS)zT Returns the type of the key :return: The type of the key. )rZ EVP_PKEY_idrrs rMrz PKey.types  ++rLc@tj|jS)zh Returns the number of bits of the key :return: The number of bits of the key. )rZ EVP_PKEY_bitsrrs rMrz PKey.bitss !!$**--rLr)rGrHrIrJrrr_Keyr classmethodrrrboolrrrrKrLrMr&r&sLL" 3T3.+7t+7+7+7Z6!6!C6!D6!pt4,c,.c.rLr&ceZdZdZdZdedeffd Zedede dfdZ edede dfdZ eded e ddfd Z ded e d eddfd Zdefd ZdefdZxZS)_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` NotherrOcVt|trtt||StS)z Implement cooperation with the right-hand side argument of ``!=``. Python 3 seems to have dropped this cooperation in this very narrow circumstance. )rprsuper__ne__NotImplemented)rr __class__s rMrz_EllipticCurve.__ne__s' e^ ,5e< <rLrcjtjd}tjd|}j||t fd|DS)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[]c3VK|] }j|j"ywrY)from_nidnid).0crrs rM z7_EllipticCurve._load_elliptic_curves..s D3<<QUU+Ds&))EC_get_builtin_curvesr_rdr`set)rr num_curvesbuiltin_curvess`` rM_load_elliptic_curvesz$_EllipticCurve._load_elliptic_curvessO..tyy!< "6 C !!.*=D^DDDrLc^|j|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. )_curvesr)rrs rM_get_elliptic_curvesz#_EllipticCurve._get_elliptic_curvess* ;; 33C8CK{{rLrc x|||tj|j|jdS)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)r_r OBJ_nid2sndecode)rrrs rMrz_EllipticCurve.from_nids03T[[)<=DDWMNNrLrc.||_||_||_y)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)rZ_nidr)rrrrs rMrz_EllipticCurve.__init__s   rLc"d|jdS)Nzrrs rM__repr__z_EllipticCurve.__repr__ s#yy**rLc|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. )rZEC_KEY_new_by_curve_namerr_re EC_KEY_free)rkeys rM _to_EC_KEYz_EllipticCurve._to_EC_KEYs3ii00;wwsD,,--rL)rGrHrIrJrrrrrr rrrrstrrrr  __classcell__rs@rMrrsG C D EE4D0EEE" s s3C/D  O3OSO-=OO Cc"+#+.C.rLrc4tjtS)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. )rrrZrKrLrMr'r's  . .t 44rLrc^tD]}|j|k(s|cStd|)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 name)r'rrt)rcurves rMr(r((s7%& :: L )4 00rLceZdZdZddZdededdffd ZdedeefdZ d ede fd Z d ede fd Z defd Z defd ZdefdZdeeeeffdZxZS)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. rrONctj|j}tj|tj |_y)z Create a new X509Name, copying the given X509Name instance. :param name: The name to copy. :type name: :py:class:`X509Name` N)rZ X509_NAME_duprr_reX509_NAME_freers rMrzX509Name.__init__Ts0!!$**-''$(;(;< rLvaluec |jdrtt|||St |t ur"t dt |jfztjt|}|tjk(r ttdttj |j"D]}tj$|j"|}tj&|}tj(|}||k(sStj*|j"|}tj,|nt/|t r|j1d}tj2|j"|tj4|ddd}|s tyy#t$r YtdwxYw)N_z+attribute name must be string, not '%.200s'No such attributeutf-8r) startswithrr) __setattr__rr rrrGrZ OBJ_txt2nid _byte_string NID_undefrr%AttributeErrorrangeX509_NAME_entry_countrX509_NAME_get_entryX509_NAME_ENTRY_get_object OBJ_obj2nidX509_NAME_delete_entryX509_NAME_ENTRY_freerpencodeX509_NAME_add_entry_by_NID MBSTRING_UTF8) rrrrientent_objent_nid add_resultrs rMrzX509Name.__setattr__^s ??3 44T5A A :S =;'')*  |D12 $..  $&!!45 5t11$**=> A**4::q9C55c:G&&w/Gg~11$**a@))#.  eS !LL)E44 JJT//B  ")  !45 5 s F66 G  G ctjt|}|tjk(r t t dtj|j|d}|dk(rytj|j|}tj|}tjd}tj||}t|dk\ tj|d|ddj!d}tj"|d|S#t $r Yt dwxYw#tj"|dwxYw)a  Find attribute. An X509Name object has the following attributes: countryName (alias C), stateOrProvince (alias ST), locality (alias L), organization (alias O), organizationalUnit (alias OU), commonName (alias CN) and more... rrNunsigned char**rr)rZrrrrr%r X509_NAME_get_index_by_NIDrr#X509_NAME_ENTRY_get_datar_r`ASN1_STRING_to_UTF8rcrSr OPENSSL_free) rrr entry_indexentryrfrj data_lengthrs rM __getattr__zX509Name.__getattr__s2|D12 $..  $&!!45 555djj#rJ " (([A,,U3!23 ..}dC  q() 0[[q!1;?BIIF   mA. / -  !45 5 *   mA. /s D#+D<# D98D9<Erct|tstStj|j |j dk(SNrrpr)rrZ X509_NAME_cmprrrs rM__eq__zX509Name.__eq__s2%*! !!!$**ekk:a??rLct|tstStj|j |j dkSr;r<r>s rM__lt__zX509Name.__lt__s2%*! !!!$**ekk:Q>>rLc tjdd}tj|j|t |}t |tjk7dtj|jddS)z6 String representation of an X509Name rUiz) r_r`rZX509_NAME_onelinerrbrcrdrr)rrj format_results rMrzX509Name.__repr__sj3/ .. JJ s='9   23 KK & - -g 6  rLc@tj|jS)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` )rZX509_NAME_hashrrs rMhashz X509Name.hashs""4::..rLctjd}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` r1rN)r_r`rZ i2d_X509_NAMErrcrSr5)rrj encode_resultrs rMrz X509Name.dersi!23 **4::}E  *+ M!$4mDQG  -*+rLcg}ttj|jD]}tj|j|}tj |}tj |}tj|}tj|}tjtj|tj|dd}|jtj||f|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!rZr"rr#r$r3r%rr_rSrrrr) rrr+r,fnamefvalrrrs rMget_componentszX509Name.get_componentsst11$**=> 6A**4::q9C33C8E005D""5)C??3'DKK**40$2I2I$2OE MM4;;t,e4 5 6  rLr)rGrHrIrJrr rrr r9rr?rArrrGrqrr rrNr r s@rMr)r):s0=%#%#C%#D%#N&& &P@C@D@ ?C?D?  #   /c / U U5%<%8 9rLr)c eZdZdZ ddededededdedd df d Zed e fd Z e jd e jd e jdiZd efdZd efdZd efdZd efdZd efdZy)r*z, An X.509 v3 certificate extension. N type_namecriticalrsubjectr,issuerrOctjd}tj|tjtjtjtjdtj ||,t |ts td|j|_ |,t |ts td|j|_ |rd|z}tjtj|||}|tjk(r ttj|tj|_y)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 OpenSSL textual representation of the extension's value. :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,)r_r`rZX509V3_set_ctxrdX509V3_set_ctx_nodbrpr,rr_x509 issuer_cert subject_certX509V3_EXT_nconfrreX509_EXTENSION_free _extension)rrPrQrrRrSctx extensions rMrzX509Extension.__init__s<hh}% CDIItyy$))QO   %  fd+ ABB$llCO  gt, BCC&}}C  !5(E))$))S)UK  ! "'')T-E-EFrLcftjtj|jSrY)rZr%X509_EXTENSION_get_objectr\rs rMrzX509Extension._nidGs'  * *4?? ;  rLemailDNSURIc$tjdtj|j}tj |tj }g}ttj|D]}tj||} |j|j}tj|jjj|jjj ddj#d}|j%|dz|zdj/|S#t&$rMt)}tj*|||j%t-|j#dYwxYw)NzGENERAL_NAMES*r:z, )r_rrZX509V3_EXT_d2ir\reGENERAL_NAMES_freer!sk_GENERAL_NAME_numsk_GENERAL_NAME_value _prefixesrrSdia5rflengthrrKeyErrorrgGENERAL_NAME_printrljoin)rnamespartsr+rlabelrrVs rM_subjectAltNameStringz#X509Extension._subjectAltNameStringSs7 d11$//B t667t//67 2A--eQ7D 2tyy1  DFFJJOOTVVZZ5F5FG&/ US[501 2yy B"n''T2 ^C077@A BsD99AFFctj|jk(r|jSt }tj ||j dd}t|dk7t|jdS)zF :return: a nice text representation of the extension rr) rZNID_subject_alt_namerrtrgX509V3_EXT_printr\rcrlr)rrV print_results rM__str__zX509Extension.__str__isi  $ $ 1--/ /n,,S$//1aH  )*c"))'22rLc@tj|jS)zk Returns the critical field of this X.509 extension. :return: The critical field. )rZX509_EXTENSION_get_criticalr\rs rM get_criticalzX509Extension.get_criticalvs //@@rLctj|j}tj|}tj|}|t j k7rt j|Sy)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 sUNDEF)rZr`r\r%rr_rdr)robjrbufs rMget_short_namezX509Extension.get_short_name~sV,,T__=s#ooc" $)) ;;s# #rLctj|j}tjd|}tj |}tj |}tj||ddS)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 r~N)rZX509_EXTENSION_get_datar\r_rrrrS)r octet_resultr char_result result_lengths rMget_datazX509Extension.get_datas^33DOOD  .,? 00? // > {{; 6q99rLNN)rGrHrIrJrqrr rpropertyrrrZ GEN_EMAILGEN_DNSGEN_URIrjr rtryr|rrrKrLrMr*r*s%)#' CGCGCG CG &! CG  CG CGJ c   e eI  s , 3 3AdA, :% :rLr*ceZdZdZddZdej fdZedej ddfdZ de ddfd Z de fd Z d e ddfd Zde fd ZdefdZdeeddfdZdeefdZde deddfdZde defdZy)r+z0 An X.509 certificate signing requests. rONctj}tj|tj|_|j dyr;)rZ X509_REQ_newr_re X509_REQ_free_req set_version)rreqs rMrzX509Req.__init__s6!GGC!3!34  rLc>ddlm}tt|}||S)z Export as a ``cryptography`` certificate signing request. :rtype: ``cryptography.x509.CertificateSigningRequest`` .. versionadded:: 17.1.0 r)load_der_x509_csr)cryptography.x509rr<r!)rrrs rMto_cryptographyzX509Req.to_cryptographys 8&}d; %%rL crypto_reqct|tjs tdddlm}|j |j}tt|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 requestrr) rprCertificateSigningRequestrrrrrrr=r!)rrrrs rMfrom_cryptographyzX509Req.from_cryptographysD*d&D&DECD DI%%hll3' s;;rLrcttj|j|j}t |dk(y)z Set the public key of the certificate signing request. :param pkey: The public key to use. :type pkey: :py:class:`PKey` :return: ``None`` rN)rZX509_REQ_set_pubkeyrrrcrrrus rM set_pubkeyzX509Req.set_pubkeys*--diiD  a(rLc@tjt}tj|j|_t |j tjk7tj|j tj|_d|_ |S)z Get the public key of the certificate signing request. :return: The public key. :rtype: :py:class:`PKey` T) r&__new__rZX509_REQ_get_pubkeyrrrcr_rdrerrrs rM get_pubkeyzX509Req.get_pubkeysf||D!--dii8  dii/0WWTZZ););<   rLversionct|ts td|dk7r tdt j |j |}t|dk(y)z Set the version subfield (RFC 2986, section 4.1) of the certificate request. :param int version: The version number. :return: ``None`` zversion must be an intrz9Invalid version. The only valid version for X509Req is 0.rN)rprrrrtrZX509_REQ_set_versionrrc)rrrus rMrzX509Req.set_versionsU'3'45 5 a<K ..tyy'B  a(rLc@tj|jS)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` )rZX509_REQ_get_versionrrs rM get_versionzX509Req.get_versions((33rLctjt}tj|j|_t |j tjk7||_ |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)rrZX509_REQ_get_subject_namerrrcr_rd_ownerrs rM get_subjectzX509Req.get_subjectsM)33DII>  dii/0  rL extensionsctj}t|tjk7tj |tj }|D]=}t|ts tdtj||j?tj|j|}t|dk(y)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`` +One of the elements is not an X509ExtensionrN)rZsk_X509_EXTENSION_new_nullrcr_rdresk_X509_EXTENSION_freerpr*rtsk_X509_EXTENSION_pushr\X509_REQ_add_extensionsr)rrstackextr/s rMadd_extensionszX509Req.add_extensionss//1*+t::; ?Cc=1 !NOO  ' 's~~ >  ?11$))UC  a(rLcg}tj|j}tj|d}t tj |D]~}tjt}tjtj||}tj|tj|_ |j||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 crtj|tjtjdS)Nr[)rZsk_X509_EXTENSION_pop_freer_ addressof _original_lib)xs rMz(X509Req.get_extensions..Bs)d55t113HIrL)rZX509_REQ_get_extensionsrr_rer!sk_X509_EXTENSION_numr*rX509_EXTENSION_dupsk_X509_EXTENSION_valuer[r\r)rextsnative_exts_objr+rr^s rMget_extensionszX509Req.get_extensions5s66tyyA''   t11/BC A'' 6C//,,_a@I"WWY0H0HICN KK    rLdigestcJ|jr td|js tdtjt |}|t jk(r tdtj|j|j|}t|dkDy)aa Sign the certificate signing request with this key and digest type. :param pkey: The key pair to sign with. :type pkey: :py:class:`PKey` :param digest: The name of the message digest to use for the signature, e.g. :py:data:`"sha256"`. :type digest: :py:class:`str` :return: ``None`` Key has only public partKey is uninitializedNo such digest methodrN) rrtrrZEVP_get_digestbynamerr_rd X509_REQ_signrrrcrrr digest_obj sign_results rMr>z X509Req.signQs   78 8  34 4..|F/CD  "45 5((DJJ K  a(rLct|ts tdtj|j |j }|dkr t|S)a@ Verifies the signature on this certificate signing request. :param PKey key: A public key. :return: ``True`` if the signature is correct. :rtype: bool :raises OpenSSL.crypto.Error: If the signature is invalid or there is a problem verifying the signature. pkey must be a PKey instancer)rpr&rrrZX509_REQ_verifyrrr)rrrs rMr?zX509Req.verifyisF$%:; ;%%dii< Q; " rLr)rGrHrIrJrrrrrrr&rrrrrr)rrr*rr rr r>rr?rKrLrMr+r+s &!?!? &<77< <<* )t ) ) D )3)4)"4S4X,)-)@)T).] 38))s)t)04DrLr+cBeZdZdZd4dZededdfdZdejfdZ edejddfd Z d e ddfd Z de fd Zdefd ZdeddfdZdededdfdZdefdZdedefdZdefdZde ddfdZde fdZde ddfdZde ddfdZdefdZdedeefdZdeefdZ de!d efd!eddfd"Z"d!eddfd#Z#deefd$Z$d!eddfd%Z%dede&fd&Z'ded'e&ddfd(Z(de&fd)Z)d*e&ddfd+Z*de&fd,Z+d-e&ddfd.Z,de fd/Z-d0e.e/ddfd1Z0d2e de/fd3Z1y)5r,z An X.509 certificate. rONctj}t|tjk7tj |tj |_t|_ t|_ yrY) rZX509_newrcr_rdre X509_freerWr_issuer_invalidator_subject_invalidator)rrs rMrz X509.__init__sJ}} )*WWT4>>2 #7#9 $8$:!rLrc|j|}tj|tj|_t |_t |_|SrY) rr_rerZrrWrrr)rrcerts rM_from_raw_x509_ptrzX509._from_raw_x509_ptrsA{{3WWT4>>2 #7#9 $8$:! rLc>ddlm}tt|}||S)z Export as a ``cryptography`` certificate. :rtype: ``cryptography.x509.Certificate`` .. versionadded:: 17.1.0 r)load_der_x509_certificate)rrr2r!)rrrs rMrzX509.to_cryptographys @}d3(--rL crypto_certct|tjs tdddlm}|j |j}tt|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 certificaterr) rpr Certificaterrrrrrr1r!)rrrrs rMrzX509.from_cryptographysD+t'7'7834 4I&&x||4 s33rLrct|ts tdtt j |j |dk(y)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 integerrN)rprrrrcrZX509_set_versionrWrrs rMrzX509.set_versions8'3'89 9--djj'BaGHrLc@tj|jS)z Return the version number of the certificate. :return: The version number of the certificate. :rtype: :py:class:`int` )rZX509_get_versionrWrs rMrzX509.get_versions$$TZZ00rLcBtjt}tj|j|_|j t jk(r tt j|j tj|_d|_ |S)z{ Get the public key of the certificate. :return: The public key. :rtype: :py:class:`PKey` T) r&rrZX509_get_pubkeyrWrr_rdrrerrrs rMrzX509.get_pubkeysg||D!))$**5 :: " "WWTZZ););<   rLrct|ts tdtj|j |j }t|dk(y)z Set the public key of the certificate. :param pkey: The public key. :type pkey: :py:class:`PKey` :return: :py:data:`None` rrN)rpr&rrrZX509_set_pubkeyrWrrcrs rMrzX509.set_pubkeys@$%:; ;))$**djjA  a(rLrct|ts td|jr t d|j s t dt jt|}|tjk(r t dt j|j|j|}t|dkDy)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:`str` :return: :py:data:`None` rzKey only has public partrrrN)rpr&rrrrtrrZrrr_rd X509_signrWrrc)rrrevp_mdrs rMr>z X509.signs$%:; ;   78 8  34 4**<+?@ TYY 45 5nnTZZVD  a(rLc tj|j}tj|j}|tj k(r t dtjtj|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) rZX509_get0_tbs_sigalgrWr% algorithmrrtr_r OBJ_nid2ln)ralgorrs rMget_signature_algorithmzX509.get_signature_algorithms\))$**5u/ $.. <= ={{4??3/00rL digest_namectjt|}|tjk(r t dtj dtj}tj dd}t||d<tj|j|||}t|dk(djtj||dDcgc]}t|jc}Scc}w)a5 Return the digest of the X509 object. :param digest_name: The name of the digest algorithm to use. :type digest_name: :py:class:`str` :return: The digest of the object, formatted as :py:const:`b":"`-delimited hex pairs. :rtype: :py:class:`bytes` runsigned char[]zunsigned int[]rr:)rZrrr_rdrtr`EVP_MAX_MD_SIZErb X509_digestrWrcrprSrupper)rrrrjr digest_resultchs rMrz X509.digests**< +DE TYY 45 5!2D4H4HI !115 }- a(( JJ }   *+yy++m]15EF " ##%    s Dc@tj|jS)z Return the hash of the X509 subject. :return: The hash of the subject. :rtype: :py:class:`bytes` )rZX509_subject_name_hashrWrs rMsubject_name_hashzX509.subject_name_hash7s**4::66rLserialct|ts tdt|dd}|j d}t j d}tj||}|dt jk(rAtjtj|j|}|r tyytj|dt j}tj|d|t jk(r tt j |tj"}tj$|j|}t'|dk(y)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 integerNrBIGNUM**rr)rprrrhexr(r_r`rZ BN_hex2bnrdASN1_INTEGER_setX509_get_serialNumberrWrBN_to_ASN1_INTEGERrreASN1_INTEGER_freeX509_set_serialNumberrc)rr hex_serialhex_serial_bytes bignum_serial small_serialru asn1_serials rMset_serial_numberzX509.set_serial_number@s&#&78 8[_ %,,W5, ~~m5EF  tyy (..**4::6 J$&11-2BDIINK LLq) *dii'$&''+t/E/EFK33DJJ LJ J!O ,rLctj|j}tj|tj } tj |} t j|}t|d}|tj|tj|S#tj|wxYw#tj|wxYw)zx Return the serial number of this certificate. :return: The serial number. :rtype: int ) rZrrWASN1_INTEGER_to_BNr_rd BN_bn2hexrrr5r)rrr r hexstring_serialrs rMget_serial_numberzX509.get_serial_numbergs00< // TYYG  ( 6J .#';;z#: -r2!!*- LL '!!*- LL 's$C"B(=C(B??CCamountct|ts tdtj|j }tj ||y)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`` amount must be an integerN)rprrrrZX509_getm_notAfterrWX509_gmtime_adj)rrnotAfters rMgmtime_adj_notAfterzX509.gmtime_adj_notAfter{s>&#&78 8**4::6 Xv.rLct|ts tdtj|j }tj ||y)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`` rN)rprrrrZX509_getm_notBeforerWr)rr notBefores rMgmtime_adj_notBeforezX509.gmtime_adj_notBefores>&#&78 8,,TZZ8  Y/rLc|j}| td|jd}tjj |d}|tjj kS)z Check whether the certificate has expired. :return: ``True`` if the certificate has expired, ``False`` otherwise. :rtype: bool zUnable to determine notAfterrz %Y%m%d%H%M%SZ) get_notAfterrtrdatetimestrptimeutcnow)r time_bytes time_string not_afters rM has_expiredzX509.has_expiredsf&&(  ;< < ''0 %%..{OL 8,,33555rLwhichc8t||jSrY)rrW)rr*s rM_get_boundary_timezX509._get_boundary_timeseDJJ/00rLc@|jtjS)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 )r,rZrrs rM get_notBeforezX509.get_notBefores&&t'?'?@@rL.rnc:t||j|SrY)rvrW)rr*rns rM_set_boundary_timezX509._set_boundary_timeseDJJ/66rLcB|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`` )r0rZrrrns rM set_notBeforezX509.set_notBefores&&t'?'?FFrLc@|jtjS)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 )r,rZrrs rMr"zX509.get_notAfters&&t'>'>??rLcB|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`` )r0rZrr2s rM set_notAfterzX509.set_notAfters&&t'>'>EErLctjt}||j|_t |jt j k7||_|SrY)r)rrWrrcr_rdr)rr*rs rM _get_namezX509._get_namesE)4::&  dii/0  rLrct|ts td||j|j}t |dk(y)Nzname must be an X509Namer)rpr)rrrWrrc)rr*rrus rM _set_namezX509._set_names8$)67 74::tzz2  a(rLcz|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` )r8rZX509_get_issuer_namerrrs rM get_issuerzX509.get_issuers1~~d778   $$T* rLrScx|jtj||jj y)z Set the issuer of this certificate. :param issuer: The issuer. :type issuer: :py:class:`X509Name` :return: ``None`` N)r:rZX509_set_issuer_namerr)rrSs rM set_issuerzX509.set_issuers* t00&9   &&(rLcz|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` )r8rZX509_get_subject_namerrrs rMrzX509.get_subjects1~~d889 !!%%d+ rLrRcx|jtj||jj y)z Set the subject of this certificate. :param subject: The subject. :type subject: :py:class:`X509Name` :return: ``None`` N)r:rZX509_set_subject_namerr)rrRs rM set_subjectzX509.set_subjects* t117; !!'')rLc@tj|jS)z Get the number of extensions on this certificate. :return: The number of extensions. :rtype: :py:class:`int` .. versionadded:: 0.12 )rZX509_get_ext_countrWrs rMget_extension_countzX509.get_extension_count*s&&tzz22rLrc|D]U}t|ts tdtj|j |j d}|rLtWy)z Add extensions to the certificate. :param extensions: The extensions to add. :type extensions: An iterable of :py:class:`X509Extension` objects. :return: ``None`` rrN)rpr*rtrZ X509_add_extrWr\r)rrrr/s rMrzX509.add_extensions5sN 'Cc=1 !NOO**4::s~~rJJ$&  'rLindexcbtjt}tj|j||_|j t jk(r tdtj|j }t j|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*rrZ X509_get_extrWr\r_rd IndexErrorrrer[)rrKrr^s rM get_extensionzX509.get_extensionEsy##M2**4::u= >>TYY &<= =++CNN; D,D,DE rLr)2rGrHrIrJrrrrrrrrrrrr&rrr r>rqrrrrrrr rr)r r,r.rr0r3r"r6r)r8r:r=r@rrErHrr*rrOrKrLrMr,r,so;cf .!1!1 .4D,<,<444& I3 I4 I1S1 D  )t ) )))s)t)811" # % >757%-%-%-N(3(( /# /$ / 03 04 0 6T 6111 Ax A7c3h'7/47 7 G% GD G @huo @ F F4 F s x )s)()t) H ) )d )X *8 * * 3S 3'-)@'T' 3=rLr,cfeZdZUdZej Zeed<ejZ eed<ejZ eed<ejZeed<ejZeed<ej"Zeed<ej&Zeed<ej*Zeed <ej.Zeed <ej2Zeed <y ) 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 CRL_CHECK CRL_CHECK_ALLIGNORE_CRITICAL X509_STRICTALLOW_PROXY_CERTS POLICY_CHECKEXPLICIT_POLICY INHIBIT_MAPCHECK_SS_SIGNATURE PARTIAL_CHAINN)rGrHrIrJrZX509_V_FLAG_CRL_CHECKrQr__annotations__X509_V_FLAG_CRL_CHECK_ALLrRX509_V_FLAG_IGNORE_CRITICALrSX509_V_FLAG_X509_STRICTrTX509_V_FLAG_ALLOW_PROXY_CERTSrUX509_V_FLAG_POLICY_CHECKrVX509_V_FLAG_EXPLICIT_POLICYrWX509_V_FLAG_INHIBIT_MAPrXX509_V_FLAG_CHECK_SS_SIGNATURErYX509_V_FLAG_PARTIAL_CHAINrZrKrLrMr-r-]s//Is/77M37;;OS;33K3!??s?55L#5;;OS;33K3"AAA77M37rLr-ceZdZdZddZdeddfdZddZdeddfd Z d e jddfd Z dd e d e e ddfdZy)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`. rONc~tj}tj|tj|_yrY)rZX509_STORE_newr_reX509_STORE_free_storerstores rMrzX509Store.__init__s(##%ggeT%9%9: rLrct|ts ttj|j |j }t|dk(y)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)rpr,rrrZX509_STORE_add_certrjrWrc)rrrs rMadd_certzX509Store.add_certs< $%+ &&t{{DJJ?q!rLcpttj|j|jdk7y)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)rcrZX509_STORE_add_crlrj_crlrcrls rMadd_crlzX509Store.add_crls& // SXXF!KLrLflagsc\ttj|j|dk7y)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)rcrZX509_STORE_set_flagsrj)rrvs rM set_flagszX509Store.set_flagss", 11$++uEJKrLvfy_timec:tj}tj|tj}tj |t j|jttj|j|dk7y)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. rN) rZX509_VERIFY_PARAM_newr_reX509_VERIFY_PARAM_freeX509_VERIFY_PARAM_set_timecalendartimegm timetuplercX509_STORE_set1_paramrj)rrzparams rMset_timezX509Store.set_timesm **,t::; '' 8??8#5#5#78  224;;F!KLrLcafilecapathc|tj}n t|}|tj}n t|}tj|j ||}|s t yy)a Let X509Store know where we can find trusted certificates for the certificate chain. Note that the certificates have to be in PEM format. If *capath* is passed, it must be a directory prepared using the ``c_rehash`` tool included with OpenSSL. Either, but not both, of *cafile* or *capath* may be ``None``. .. note:: Both *cafile* and *capath* may be set simultaneously. Call this method multiple times to add more than one location. For example, CA certificates, and certificate revocation list bundles may be passed in *cafile* in subsequent calls to this method. .. versionadded:: 20.0 :param cafile: In which file we can find the certificates (``bytes`` or ``unicode``). :param capath: In which directory we can find the certificates (``bytes`` or ``unicode``). :return: ``None`` if the locations were set successfully. :raises OpenSSL.crypto.Error: If both *cafile* and *capath* is ``None`` or the locations could not be set for any reason. N)r_rd _path_bytesrZX509_STORE_load_locationsrjr)rrr load_results rMload_locationszX509Store.load_locationss`B >YYF (F >YYF (F44 KK  "rLr)rtr6rONrY)rGrHrIrJrr,rorurryr#rStrOrBytesPathr rrKrLrMr.r.ts ;"T"d",M LsLtL0M!2!2MtM2JN/#$/#.6~.F/# /#rLr.c:eZdZdZdedeededdffd ZxZ S)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` messageerrors certificaterONcHtt| |||_||_yrY)rr/rrr)rrrrrs rMrzX509StoreContextError.__init__s$ #T3G< &rL) rGrHrIrJr r rr,rr r s@rMr/r/s6''$(I'<@' ''rLr/c eZdZdZ ddededeeeddfdZe deeeddfd Z dd Z dd Z de fd Zdeddfd ZddZdeefdZy)r0a 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. :ivar _chain: See the ``chain`` ``__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. :param chain: List of untrusted certificates that may be used for building the certificate chain. May be ``None``. :type chain: :class:`list` of :class:`X509` NrlrchainrOctj}tj|tj|_||_||_|j||_ |jyrY) rZX509_STORE_CTX_newr_reX509_STORE_CTX_free _store_ctxrj_cert_build_certificate_stack_chain_init)rrlrr store_ctxs rMrzX509StoreContext.__init__5sU ++- '')T-E-EF   33E:  rL certificatescdtddfd}|t|dk(rtjSt j }t |tjk7tj||}|D]}t|ts tdt t j|jdkDt j||jdksmt j|jt|S)NsrOcttj|D]-}tj||}tj|/tj |yrY)r!rZ sk_X509_num sk_X509_valuer sk_X509_free)rr+rs rMcleanupz:X509StoreContext._build_certificate_stack..cleanupIsQ4++A./ "&&q!,q! "   a rLrz+One of the elements is not an X509 instance)rrbr_rdrZsk_X509_new_nullrcrerpr,rr X509_up_refrW sk_X509_pushrr)rrrrs rMrz)X509StoreContext._build_certificate_stackEs !s !t !  3|#4#999 %%'*+w'  'DdD) MNN D,,TZZ81< =   3q8tzz*$& ' rLctj|j|jj|jj |j }|dkr tyy)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)rZX509_STORE_CTX_initrrjrrWrrrrzs rMrzX509StoreContext._initcsM&& OOT[[//1A1A4;;  !8 " rLcBtj|jy)z Internally cleans up the store context. The store context can then be reused with a new call to :meth:`_init`. N)rZX509_STORE_CTX_cleanuprrs rM_cleanupzX509StoreContext._cleanupps ##DOO4rLctjtjtj|j j d}tj|j tj|j |g}tj|j }tj|}tj|}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. r) r_rrZX509_verify_cert_error_stringX509_STORE_CTX_get_errorrrX509_STORE_CTX_get_error_depthX509_STORE_CTX_get_current_certX509_dupr,rr/)rrrrWrpycerts rM_exception_from_contextz(X509StoreContext._exception_from_contextxs++  . .--doo>   &/   ) )$// :  / / @  44T__E e$((/$Wff==rLc||_y)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)rjrks rM set_storezX509StoreContext.set_stores  rLc|j|jtj|j}|j|dkr|j y)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)rrrZX509_verify_certrrrs rMverify_certificatez#X509StoreContext.verify_certificatesN  ##DOO4  !8..0 0 rLc|j|jtj|j}|dkr |j|j tj |j}t|tjk7g}ttj|D]Z}tj||}t|tjk7tj|}|j|\tj ||j|S)aR Verify a certificate in a context and return the complete validated chain. :raises X509StoreContextError: If an error occurred when validating a certificate in the context. Sets ``certificate`` attribute to indicate which certificate caused the error. .. versionadded:: 20.0 r)rrrZrrrX509_STORE_CTX_get1_chainrcr_rdr!rrr,rrr)rrz cert_stackrr+rrs rMget_verified_chainz#X509StoreContext.get_verified_chains  ##DOO4 !8 MMO..0 033DOOD  dii/0t'' 34 "A%%j!4D DDII- .,,T2F MM& !  " *%  rLrYr)rGrHrIrJr.r,r r r staticmethodrrrr/rrrr rrKrLrMr0r0s2+/ '    x~. : #5>)>>2 y T 1,%DJ%rLr0rct|tr|jd}t|}|tk(rCt j |tjtjtj}n9|tk(r%t j|tj}n td|tjk(r ttj|S)a Load a certificate (X509) from the string *buffer* encoded with the type *type*. :param type: The file type (one of FILETYPE_PEM, FILETYPE_ASN1) :param bytes buffer: The buffer the certificate is stored in :return: The X509 object r3type argument must be FILETYPE_PEM or FILETYPE_ASN1)rpr r(rgr rZPEM_read_bio_X509r_rdr! d2i_X509_biortrr,r)rrSrVrs rMr1r1s&#w' v C |%%c499diiK    dii0NOO tyy  " "4 ((rLrc^t}|tk(r!tj||j}na|t k(r!tj ||j}n7|tk(r#tj||jdd}n tdt|dk(t|S)a Dump the certificate *cert* into a buffer string encoded with the type *type*. :param type: The file type (one of FILETYPE_PEM, FILETYPE_ASN1, or FILETYPE_TEXT) :param cert: The certificate to dump :return: The buffer with the dumped certificate in rCtype argument must be FILETYPE_PEM, FILETYPE_ASN1, or FILETYPE_TEXTr) rgr rZPEM_write_bio_X509rWr! i2d_X509_bior" X509_print_exrtrcrl)rrrV result_codes rMr2r2s .C |--c4::>  ''TZZ8  ((djj!Q?    K1$% # rLrct}|tk(rtj}n%|tk(rtj }n t d|||j}|dk7r tt|S)z Dump a public key to a buffer. :param type: The file type (one of :data:`FILETYPE_PEM` or :data:`FILETYPE_ASN1`). :param PKey pkey: The public key to dump :return: The buffer with the dumped key in it. :rtype: bytes rr) rgr rZPEM_write_bio_PUBKEYr!i2d_PUBKEY_biortrrrl)rrrV write_biors rMr3r3sf .C |--  '' NOOC,Ka # rLcipher passphrasec t}t|ts td|I| tdt j t |}|tjk(rtdtj}t||}|tk(rXt j||j|tjd|j|j}|j!n|t"k(r!t j$||j}n|t&k(rt j(|jtj*k7r tdtj,t j.|jtj0}t j2||d}n tdt5|dk7t7|S)a Dump the private key *pkey* into a buffer string encoded with the type *type*. Optionally (if *type* is :const:`FILETYPE_PEM`) encrypting it using *cipher* and *passphrase*. :param type: The file type (one of :const:`FILETYPE_PEM`, :const:`FILETYPE_ASN1`, or :const:`FILETYPE_TEXT`) :param PKey pkey: The PKey to dump :param cipher: (optional) if encrypted PEM format, the cipher to use :param passphrase: (optional) if encrypted PEM format, this can be either the passphrase to use, or a callback for providing the passphrase. :return: The buffer with the dumped key in :rtype: bytes zpkey must be a PKeyzDif a value is given for cipher one must also be given for passphrasezInvalid cipher namerz-Only RSA keys are supported for FILETYPE_TEXTr)rgrpr&rrrZEVP_get_cipherbynamerr_rdrt_PassphraseHelperr PEM_write_bio_PrivateKeyrcallback callback_argsraise_if_problemr!i2d_PrivateKey_bior"rrrerr RSA_printrcrl) rrrrrV cipher_objhelperrrs rMr4r4,s* .C dD !-..   8 ..|F/CD  "23 3YY tZ 0F |33  JJ  II OO    !  --c4::>     DJJ '4+<+< <KL Lggd,,TZZ8$--HnnS#q1    K1$% # rLceZdZdZgdZddZdeddfdZdefdZdd Z d e eddfd Z de efd Z de efd ZdeddfdZde efdZy)r5z# A certificate revocation. )s unspecifieds keyCompromises CACompromisesaffiliationChangeds supersededscessationOfOperationscertificateHoldrONc~tj}tj|tj|_yrY)rZX509_REVOKED_newr_reX509_REVOKED_free_revoked)rrevokeds rMrzRevoked.__init__s(''))?)?@ rLhex_strctjtjtj}tj d}||d<tj ||}|s tdtjtj|tjtj}tj|j|y)z Set the serial number. The serial number is formatted as a hexadecimal number encoded in ASCII. :param bytes hex_str: The new serial number. :return: ``None`` rrzbad hex stringN) r_rerZrrr`rrtrrdrX509_REVOKED_set_serialNumberr)rrr  bignum_ptr bn_resultrs rM set_serialzRevoked.set_serials t||< XXj) % 1 NN:w7 -. .gg  # #M499 =  " "  **4==+FrLct}tj|j}t |t j k7tj||}t |dk\t|S)z Get the serial number. The serial number is formatted as a hexadecimal number encoded in ASCII. :return: The serial number. :rtype: bytes r) rgrZX509_REVOKED_get0_serialNumberrrcr_rdi2a_ASN1_INTEGERrl)rrVasn1_intrs rM get_serialzRevoked.get_serialsYn66t}}EDII-.&&sH5! $c""rLcttj|jD]}tj|j|}tj |}tj |tjk(s_tj|tj|j|yyrY) r!rZX509_REVOKED_get_ext_countrX509_REVOKED_get_extr`r%NID_crl_reasonr[X509_REVOKED_delete_ext)rr+rr~s rM_delete_reasonzRevoked._delete_reasonst66t}}EF A++DMM1=C005C$(;(;;((-,,T]]A>  rLreasonc||jyt|ts td|j j dd}|j Dcgc]}|j c}j|}tj}t|tjk7tj|tj}tj||}t|tjk7|jtj |j"tj$|dd}t|dk(ycc}w)a Set the reason of this revocation. If :data:`reason` is ``None``, delete the reason instead. :param reason: The reason string. :type reason: :class:`bytes` or :class:`NoneType` :return: ``None`` .. seealso:: :meth:`all_reasons`, which gives you a list of all supported reasons which you might pass to this method. Nz$reason must be None or a byte string rLrr)rrprqrrlowerreplace _crl_reasonsrKrZASN1_ENUMERATED_newrcr_rdreASN1_ENUMERATED_freeASN1_ENUMERATED_setX509_REVOKED_add1_ext_i2drr)rrr reason_codenew_reason_extrur/s rM set_reasonzRevoked.set_reasons >    !FE*BC C\\^++D#6F.2.?.?@1779@FFvNK!557N Ndii7 8!WW^T5N5NON11.+NJ J$))3 4    !77 t22NAqJ J!O ,AsEcttj|jD]}tj|j|}tj |}tj |tjk(s_t}tj||dd}|s7tj|tj|}t|dk7t|cSy)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!rZrrrr`r%rrgrwM_ASN1_OCTET_STRING_printrrcrl)rr+rr~rVrxs rM get_reasonzRevoked.get_reasonst66t}}EF +A++DMM1=C005C$(;(;;"n#44S#q!D ##'#A#AT99#>$L$LA$56%c** +rLc |jddS)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)rrs rM all_reasonszRevoked.all_reasonss  ##rLrncvt|}tj|j|}t |dk(y)z Set the revocation timestamp. :param bytes when: The timestamp of the revocation, as ASN.1 TIME. :return: ``None`` rN)r{rZX509_REVOKED_set_revocationDaterrc)rrnrevocationDaterzs rM set_rev_datezRevoked.set_rev_date s5(-22 MM>  q!rLcVtj|j}t|S)z Get the revocation timestamp. :return: The timestamp of the revocation, as ASN.1 TIME. :rtype: bytes )rZ X509_REVOKED_get0_revocationDaterr)rdts rM get_rev_datezRevoked.get_rev_date s# 2 24== Ab!!rLr)rGrHrIrJrrrqrrrr rrr rrr rKrLrMr5r5qs LAG%GDG0#E#$#-%#-T#-JHUO8 $T%[ $ " "4 ""huo"rLr5c eZdZdZddZdej fdZedej ddfdZ de e e dffd Z d e ddfd Zdefd Zd eddfdZdeddfdZdeddfdZdedededdfdZedefdedededededef dZy)r6z( A certificate revocation list. rONc~tj}tj|tj|_yrY)rZ X509_CRL_newr_re X509_CRL_freerrrss rMrz CRL.__init__' s(!GGC!3!34 rLc>ddlm}tt|}||S)z Export as a ``cryptography`` CRL. :rtype: ``cryptography.x509.CertificateRevocationList`` .. versionadded:: 17.1.0 r)load_der_x509_crl)rrr@r!)rrrs rMrzCRL.to_cryptography+ s 8}d+ %%rL crypto_crlct|tjs tdddlm}|j |j}tt|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 listrr) rprCertificateRevocationListrrrrrrrAr!)rrrrs rMrzCRL.from_cryptography8 sD*d&D&DECD DI%%hll3 s++rL.cg}tj|j}ttj|D]}tj ||}tj |}tjt}tj|tj|_ |j||r t|Sy)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)rZX509_CRL_get_REVOKEDrrr!sk_X509_REVOKED_numsk_X509_REVOKED_valueX509_REVOKED_dupr5rr_rerrrtuple)rresults revoked_stackr+r revoked_copypyrevs rM get_revokedzCRL.get_revokedN s11$))< t// >? "A00BG009LOOG,E!WW\43I3IJEN NN5 !  " > !rLrctj|j}t|tj k7tj |j|}t|dk7y)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)rZrrrcr_rdX509_CRL_add0_revokedrr)rrcopyr/s rM add_revokedzCRL.add_revokedd sM$$W%5%56 )*// 4@  a(rLc*tjtj|j}t |t j k7t j|tj}tjt}||_ |S)zc Get the CRL's issuer. .. versionadded:: 16.1.0 :rtype: X509Name ) rZrX509_CRL_get_issuerrrrcr_rdrerr)rr)r_issuerrSs rMr=zCRL.get_issueru sf$$T%=%=dii%HI499,-'''4#6#67!!(+  rLrc\ttj|j|dk7y)z Set the CRL version. .. versionadded:: 16.1.0 :param int version: The version of the CRL. :return: ``None`` rN)rcrZX509_CRL_set_versionrrrs rMrzCRL.set_version s" 11$))WEJKrLrncvt|}tj|j|}t |dk(y)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`` rN)r{rZX509_CRL_set1_lastUpdaterrrc)rrn lastUpdaterzs rMset_lastUpdatezCRL.set_lastUpdate 0$D) ++DIIzBq!rLcvt|}tj|j|}t |dk(y)z Set when the CRL will next be updated. The timestamp is formatted as an ASN.1 TIME:: YYYYMMDDhhmmssZ .. versionadded:: 16.1.0 :param bytes when: A timestamp string. :return: ``None`` rN)r{rZX509_CRL_set1_nextUpdaterrrc)rrn nextUpdaterzs rMset_nextUpdatezCRL.set_nextUpdate r.rLrX issuer_keyrctj|}t|tjk7tj |j tj|jtj|j tj|j |j|}t|dk7y)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) rZrrcr_rdX509_CRL_set_issuer_namerrrBrW X509_CRL_sort X509_CRL_signr)rrXr3rrrs rMr>zCRL.sign s"..v6  dii/0 %% IIt11+2C2CD  499%##DIIz/?/?L! $rLdrr rdaysct|ts tdt|ts tdt|ts td|t ur tdt j|}|tjk(r tdt j}t|tjk7tj|t j}t j|d}t|tjk7t j |j"|}t|dk(t j||dzd zd z}t|tjk7t j$|j"|}t|dk(t j&|j"t j(|j*}t|dk(t j,|j"|j.|} | s t1t3||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"sha256"``). :rtype: bytes cert must be an X509 instancezkey must be a PKey instancerzdigest must be providedrrr<)rpr,rrr&r _UNSPECIFIEDrZrr_rdrtrxrcreryrr+rrr0r5rBrWr7rrr@) rrr rr9rrsometimerzrs rMexportz CRL.export s*$%;< <#t$9: :$$56 6 \ !56 6..v6  "45 5%%'DII-.778T%8%89""8Q/tyy()++DIIx@q!""8TBY^b-@Atyy()++DIIx@q!++ IIt11$**=  q!((CIIzJ  "d##rLr)rGrHrIrJrrrrrrr rr5r r$r)r=rrrqr-r2r,r&r>r r>r@rKrLrMr6r6" s(5 &!?!? &,77, ,,*XeGSL&9:,)7)t)" H  L3 L4 L"5"T"""5"T""%%$%%$%<!$ <$<$<$ <$  <$  <$ <$rLr6cTeZdZUeed<defdZdefdZdefdZdefdZ de fdZ y) r7_pkcs7rOcRttj|jS)zm Check if this NID_pkcs7_signed object :return: True if the PKCS7 is of type signed )rrZPKCS7_type_is_signedrBrs rMtype_is_signedzPKCS7.type_is_signed s D--dkk:;;rLcRttj|jS)zt Check if this NID_pkcs7_enveloped object :returns: True if the PKCS7 is of type enveloped )rrZPKCS7_type_is_envelopedrBrs rMtype_is_envelopedzPKCS7.type_is_enveloped s D00=>>rLcRttj|jS)z Check if this NID_pkcs7_signedAndEnveloped object :returns: True if the PKCS7 is of type signedAndEnveloped )rrZ PKCS7_type_is_signedAndEnvelopedrBrs rMtype_is_signedAndEnvelopedz PKCS7.type_is_signedAndEnveloped s D99$++FGGrLcRttj|jS)zi Check if this NID_pkcs7_data object :return: True if the PKCS7 is of type data )rrZPKCS7_type_is_datarBrs rM type_is_datazPKCS7.type_is_data% s D++DKK899rLctj|jj}tj|}t j |S)zk Returns the type name of the PKCS7 structure :return: A string with the typename )rZr%rBrrr_r)rr string_types rM get_type_namezPKCS7.get_type_name- s; t{{//0ooc* {{;''rLN) rGrHrIrr\rrErHrKrNr rQrKrLrMr7r7 sE K<<?4?HDH:d:(s(rLr7c eZdZdZddZdeefdZdeddfdZdee fdZ d e ddfd Z dee ed ffd Z d eeeddfdZdeeddfdZdeefdZ ddeedededefdZy)r8z A PKCS #12 archive. rONc<d|_d|_d|_d|_yrY)rr_cacerts _friendlynamers rMrzPKCS12.__init__= s%) %) .2 .2rLc|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` )rrs rMget_certificatezPKCS12.get_certificateC zzrLrcHt|ts td||_y)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`` r;N)rpr,rrr)rrs rMset_certificatezPKCS12.set_certificateL s!$%;< < rLc|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` )rrs rMget_privatekeyzPKCS12.get_privatekeyY rXrLrcHt|ts td||_y)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`` rN)rpr&rrrrs rMset_privatekeyzPKCS12.set_privatekeyb s!$%:; ; rL.cF|jt|jSy)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)rTrrs rMget_ca_certificateszPKCS12.get_ca_certificateso s  == $' 'rLcacertsc|d|_yt|}|D]}t|trt d||_y)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)rTlistrpr,rr)rrars rMset_ca_certificateszPKCS12.set_ca_certificates{ sK ? DM7mG !$-#C  $DMrLrcr|d|_||_yt|tstd|d||_y)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 ))rUrprqrrrs rMset_friendlynamezPKCS12.set_friendlyname sD %? $8HTN+C$$*"Xe_""""(5/"'+ F#UOF#F# F#  F#rLr8cdeZdZdZd dZdededdfdZdedefd Z de fd Z defd Z deddfd Z y)r9z! A Netscape SPKI object. rONc~tj}tj|tj|_yrY)rZNETSCAPE_SPKI_newr_reNETSCAPE_SPKI_free_spki)rspkis rMrzNetscapeSPKI.__init__ s(%%'WWT4#:#:; rLrrcJ|jr td|js tdtjt |}|t jk(r tdtj|j|j|}t|dkDy)a Sign the certificate request with this key and digest type. :param pkey: The private key to sign with. :type pkey: :py:class:`PKey` :param digest: The message digest to use. :type digest: :py:class:`str` :return: ``None`` rrrrN) rrtrrZrrr_rdNETSCAPE_SPKI_signrxrrcrs rMr>zNetscapeSPKI.sign s   78 8  34 4..|F/CD  "45 5-- JJ J   a(rLr cvtj|j|j}|dkr t y)aY Verifies a signature on a certificate request. :param PKey key: The public key that signature is supposedly from. :return: ``True`` if the signature is correct. :rtype: bool :raises OpenSSL.crypto.Error: If the signature is invalid, or there was a problem verifying the signature. rT)rZNETSCAPE_SPKI_verifyrxrr)rr answers rMr?zNetscapeSPKI.verify s.**4::syyA Q; "rLctj|j}tj|}tj ||S)z Generate a base64 encoded representation of this SPKI object. :return: The base64 encoded string. :rtype: :py:class:`bytes` )rZNETSCAPE_SPKI_b64_encoderxr_rr5)rencodedrs rM b64_encodezNetscapeSPKI.b64_encode( s9// ;W% '" rLc@tjt}tj|j|_t |j tjk7tj|j tj|_d|_ |S)z| Get the public key of this certificate. :return: The public key. :rtype: :py:class:`PKey` T) r&rrZNETSCAPE_SPKI_get_pubkeyrxrrcr_rdrerrrs rMrzNetscapeSPKI.get_pubkey4 sf||D!224::>  dii/0WWTZZ););<   rLcttj|j|j}t |dk(y)zv Set the public key of the certificate :param pkey: The public key :return: ``None`` rN)rZNETSCAPE_SPKI_set_pubkeyrxrrcrs rMrzNetscapeSPKI.set_pubkeyB s*224::tzzJ  a(rLr)rGrHrIrJrr&r r>rr?rqrrrrKrLrMr9r9 sd<))s)t)6$4" E  D )t))rLr9c eZdZ ddedeedededdf dZede fdZ ede fd Z e fd e eddfd Zd e d ede de def dZy)rrr more_argstruncaterONch|tk7r | td||_||_||_g|_y)Nz0only FILETYPE_PEM key format supports encryption)r rt _passphrase _more_args _truncate _problems)rrrrrs rMrz_PassphraseHelper.__init__N s@ < J$:B &#!*,rLc|jtjSt|jtst |jr tj d|jStd)Npem_password_cb2Last argument must be a byte string or a callable.) rr_rdrprqcallabler_read_passphraserrrs rMrz_PassphraseHelper.callback^ s]    #99  ((% 0HT=M=M4N==!2D4I4IJ JD rLc|jtjSt|jtst |jrtjSt d)Nr)rr_rdrprqrrrrs rMrz_PassphraseHelper.callback_argsi sO    #99  ((% 0HT=M=M4N99 D rL exceptionTypec|jr' t||jjdy#|$rY#wxYwr;)r_exception_from_error_queuepop)rrs rMrz"_PassphraseHelper.raise_if_problemt sF >> +M:..$$Q' ' !  s 5==rsizerwflaguserdatac t|jr2|jr|j|||}n,|j|}n|jJ|j}t|ts t dt ||kDr|jr|d|}n t dtt |D] }|||dz||<t |S#t$r%}|jj|Yd}~yd}~wwxYw)NzBytes expectedz+passphrase returned by callback is too longrr) rrrrprqrtrbrr! Exceptionrr)rrrrrrr+es rMrz"_PassphraseHelper._read_passphrase~ s (()??!--dFHEF!--f5F''333))fe, !1226{T!>>#ET]F$E3v;' +AE*A +v;   NN ! !! $ sCC D!DD)FF)rGrHrIrr PassphraseCallableTrrrrrrr%rrrrrKrLrMrrM s   --01- -  -  - #sAF(d9o($(!+.:= rLrc4t|tr|jd}t|}|tk(rCt j |tjtjtj}n9|tk(r%t j|tj}n td|tjk(r ttjt}tj|t j |_d|_|S)a< Load a public key from a buffer. :param type: The file type (one of :data:`FILETYPE_PEM`, :data:`FILETYPE_ASN1`). :param buffer: The buffer the key is stored in. :type buffer: A Python string object, either unicode or bytestring. :return: The PKey object. :rtype: :class:`PKey` rrT)rpr r(rgr rZPEM_read_bio_PUBKEYr_rdr!d2i_PUBKEY_biortrr&rrerrr)rrSrVevp_pkeyrs rMr:r: s&#w' v C |++ DIItyy   &&sDII6NOO499 << D4#5#56DJD KrLcNt|tr|jd}t|}t ||}|t k(rKt j|tj|j|j}|jn9|tk(r%t j|tj}n td|tjk(r t!t"j%t"}tj&|t j(|_|S)a Load a private key (PKey) from the string *buffer* encoded with the type *type*. :param type: The file type (one of FILETYPE_PEM, FILETYPE_ASN1) :param buffer: The buffer the key is stored in :param passphrase: (optional) if encrypted PEM format, this can be either the passphrase to use, or a callback for providing the passphrase. :return: The PKey object rr)rpr r(rgrr rZPEM_read_bio_PrivateKeyr_rdrrrr!d2i_PrivateKey_biortrr&rrerr)rrSrrVrrrs rMr;r; s"&#w' v C tZ 0F |// FOOV-A-A  !  **3 :NOO499 << D4#5#56DJ KrLrc^t}|tk(r!tj||j}na|t k(r!tj ||j}n7|tk(r#tj||jdd}n tdt|dk7t|S)a Dump the certificate request *req* into a buffer string encoded with the type *type*. :param type: The file type (one of FILETYPE_PEM, FILETYPE_ASN1) :param req: The certificate request to dump :return: The buffer with the dumped certificate request in rr) rgr rZPEM_write_bio_X509_REQrr!i2d_X509_REQ_bior"X509_REQ_print_exrtrcrl)rrrVrs rMr<r< s .C |11#sxx@  ++C:  ,,S#((AqA    K1$% # rLc$t|tr|jd}t|}|tk(rCt j |tjtjtj}n9|tk(r%t j|tj}n tdt|tjk7tjt}tj|t j |_|S)a Load a certificate request (X509Req) from the string *buffer* encoded with the type *type*. :param type: The file type (one of FILETYPE_PEM, FILETYPE_ASN1) :param buffer: The buffer the certificate request is stored in :return: The X509Req object rr)rpr r(rgr rZPEM_read_bio_X509_REQr_rdr!d2i_X509_REQ_biortrcr+rrerr)rrSrVrx509reqs rMr=r= s&#w' v C |((diiDIIN  ##C3NOOC499$%oog&G773 2 23GL NrLrfrctd|}tjt|}|tj k(r t dtj}t j|tj}tj||tj||t|tj|j}t|dkDt j d|}t j d}tj"||||j}t|dk(t j$||dddS)z Sign a data string using the given key and message digest. :param pkey: PKey to sign with :param data: data to be signed :param digest: message digest to use :return: signature .. versionadded:: 0.11 rfrrrzunsigned int *rN)rmrZrrr_rdrtEVP_MD_CTX_newreEVP_MD_CTX_free EVP_SignInitEVP_SignUpdaterb EVP_PKEY_sizerrcr` EVP_SignFinalrS) rrfrrmd_ctxrmsignature_buffersignature_length final_results rMr>r> s #64 0D**<+?@JTYY011  "F WWVT11 2Ffj)c$i0    +FFQJxx 16:xx 01%% "2DJJLLA%& ;;')9!)< =a @@rL signaturectd|}tjt|}|tj k(r t dtj|j}t|tj k7t j|tj}tj}t j|tj}tj||tj||t!|tj"||t!||}|dk7r t%yy)a Verify the signature for a data string. :param cert: signing certificate (X509 object) corresponding to the private key which generated the signature. :param signature: signature returned by sign function :param data: data to be verified :param digest: message digest to use :return: ``None`` if the signature is correct, raise exception otherwise. .. versionadded:: 0.11 rfrrN)rmrZrrr_rdrtrrWrcrerrrEVP_VerifyInitEVP_VerifyUpdaterbEVP_VerifyFinalr)rrrfrrrr verify_results rMr?r?A s #64 0D**<+?@JTYY011    +DDDII%& 774++ ,D  "F WWVT11 2F +&$D 2(( 3y>4MrLrtcZt}|tk(r!tj||j}n_|t k(r!tj ||j}n5|tk(r!tj||j}n tdt|dk(t|S)a Dump a certificate revocation list to a buffer. :param type: The file type (one of ``FILETYPE_PEM``, ``FILETYPE_ASN1``, or ``FILETYPE_TEXT``). :param CRL crl: The CRL to dump. :return: The buffer with the CRL. :rtype: bytes rr) rgr rZPEM_write_bio_X509_CRLrrr!i2d_X509_CRL_bior"X509_CRL_printrtrcrl)rrtrVrzs rMr@r@g s .C |))#sxx8  ##C2  !!#sxx0   C1H # rLc&t|tr|jd}t|}|tk(rCt j |tjtjtj}n9|tk(r%t j|tj}n td|tjk(r ttjt}tj|t j |_|S)a  Load Certificate Revocation List (CRL) data from a string *buffer*. *buffer* encoded with the type *type*. :param type: The file type (one of FILETYPE_PEM, FILETYPE_ASN1) :param buffer: The buffer the CRL is stored in :return: The CRL object rr)rpr r(rgr rZPEM_read_bio_X509_CRLr_rdr!d2i_X509_CRL_biortrr6rrerrr)rrSrVrtrs rMrArA s&#w' v C |((diiDIIN  ##C3NOO dii [[ F''#t112FK MrLc&t|tr|jd}t|}|tk(rCt j |tjtjtj}n9|tk(r%t j|tj}n td|tjk(r ttjt}tj|t j |_|S)z Load pkcs7 data from the string *buffer* encoded with the type *type*. :param type: The file type (one of FILETYPE_PEM or FILETYPE_ASN1) :param buffer: The buffer with the pkcs7 data. :return: The PKCS7 object rr)rpr r(rgr rZPEM_read_bio_PKCS7r_rdr! d2i_PKCS7_biortrr7rre PKCS7_freerB)rrSrVpkcs7pypkcs7s rMrBrB s&#w' v C |''TYY 499M  ""3 2NOO  mmE"GWWUDOO4GN NrLzSPKCS#7 support in pyOpenSSL is deprecated. You should use the APIs in cryptography.rBrctd|}t|tr|jd}t |}|st j }tj|t j }|t j k(r tt j|tj}t jd}t jd}t jd}tj|||||}|s tt j|dtj} t|dt j k(rd}nEt j#t }t j|dtj$|_|dt j k(rd} d} nwt(j+|d} t jd} tj,|d| } t j.| | ddd} | t j k(rd} g} t1tj2|D]>}tj4||}t(j+|}| j7|@t8j#t8}||_| |_| r| nd|_| |_|S#t$rYwxYw) a Load pkcs12 data from the string *buffer*. If the pkcs12 structure is encrypted, a *passphrase* must be included. The MAC is always checked and thus required. See also the man page for the C function :py:func:`PKCS12_parse`. :param buffer: The buffer the certificate is stored in :param passphrase: (Optional) The password to decrypt the PKCS12 lump :returns: The PKCS12 object rrz EVP_PKEY**zX509**zCryptography_STACK_OF_X509**rNzint*) rmrpr r(rgr_rdrZd2i_PKCS12_biorrerpr` PKCS12_parserr%r&rrrr,rX509_alias_get0rSr!rrrr8rrTrU)rSrrVp12rrra parse_resultpykeyrrrfriendlyname_lengthfriendlyname_buffer pycacertsr+rpycacertrss rMrCrC s])zBJ&#w' v C YY   c499 -C dii ''#t'' (C 88L !D 88H Dhh56G$$S*dD'JL gggaj$"3"34G   Aw$)) T"ggd1gt'9'9:  Aw$)) ((a1"hhv."22 G( {{ !4Q!7   $)) +LI 4##G, -#!!'1-**40"# ^^F #FFLFL#,i$FO'F MI    s< K KKzTPKCS#12 support in pyOpenSSL is deprecated. You should use the APIs in cryptography.rCrYr)vrr# functoolsbase64rrosrtypingrrrr r r r r rrr cryptographyrr)cryptography.hazmat.primitives.asymmetricrrrrr OpenSSL._utilrr>rrrrrr_rrZr _make_assertrrrrm__all__rrrrrr rqrrSSL_FILETYPE_PEMr rr\SSL_FILETYPE_ASN1r!r"rr# EVP_PKEY_DSAr$ EVP_PKEY_DHrD EVP_PKEY_ECrErr%rrcrRrgrlrvr{rrr&rr'r(total_orderingr)r*r+r,r-r.r/r0r1r2r3r4r5r6r7r8r9rr:r;r<r=r>r?r@rArB deprecatedrGDeprecationWarningrCrKrLrMrsC    %   % P s''):):CBT #u* T+3E?T Tn    rL