a L•ºf uã@s|ddlZddlZddlmZddlmZmZddlmZm Z ddl m Z ddl m Z ddlmZmZmZmZmZmZmZmZddlm Z m!Z!m"Z"m#Z#m$Z$m%Z%gd ¢Z&ej'Z'ej(Z(Z)ej*Z*Z+ej,Z,Z-ej.Z.Z/ej0Z0Z1ej2Z3ej4Z5d Z6d Z7d Z8d Z9dZ:dZ;dZdZ?z"ej@Z@ejAZAejBZBejCZCejDZDWn(eEyZdZ@dZAdZBdZCdZDYn0ejFZGejHZIejJZKejLZMejNZOz ejPZQWneEy˜Yn0ejRZSejTZUejVZWejXZYejZZ[ej\Z]ej^Z_ej`ZaejbZcejdZeejfZgejhZiejjZkejlZmejnZoejpZqejrZsejtZuejvZwejxZyejzZ{ej|Z}ej~Zej€Zz ej‚ZƒWneEyHYn0z ej„Z…WneEyhYn0ej†Z‡ejˆZ‰ejŠZ‹ejŒZejŽZejZ‘ej’Z“ej”Z•ej–Z—ej˜Z™ejšZ›ejœZejžZŸej Z ej¡Z¡ej¢Z¢ej£Z£ej¤Z¤ej¥Z¥ej¦Z¦ej§Z§ej¨Z¨ej©Z©ejªZªej«Z«ej¬Z¬ej­Z­ej®Z®ej¯Z¯gd¢Z°dgZ±dZ²dZ³Gdd„de´ƒZµeeeµƒZ¶eeµƒZ·Gdd „d eµƒZ¸Gd!d"„d"eµƒZ¹Gd#d$„d$eµƒZºGd%d&„d&eµƒZ»Gd'd(„d(eµƒZ¼Gd)d*„d*ƒZ½Gd+d,„d,e½ƒZ¾e¿ƒZÀGd-d.„d.e½ƒZÁGd/d0„d0e½ƒZÂGd1d2„d2e½ƒZÃGd3d4„d4e½ƒZÄGd5d6„d6e½ƒZÅd7d8„ZÆd9d:„ZÇeÇZÈd;d<„ZÉeÉejÊd=ƒZËeÉeÌed>dƒd?ƒZÍGd@dA„dAƒZÎGdBdC„dCƒZÏGdDdE„dEƒZÐdS)FéN)Ú errorcode)ÚpartialÚwraps)ÚchainÚcount)Úplatform)ÚWeakValueDictionary)Ú UNSPECIFIEDÚexception_from_error_queueÚffiÚlibÚ make_assertÚno_zero_allocatorÚ path_bytesÚtext_to_bytes_and_warn)Ú FILETYPE_PEMÚPKeyÚX509ÚX509NameÚ X509StoreÚ_PassphraseHelper)dÚOPENSSL_VERSION_NUMBERÚSSLEAY_VERSIONÚ SSLEAY_CFLAGSÚSSLEAY_PLATFORMÚ SSLEAY_DIRÚSSLEAY_BUILT_ONÚOPENSSL_VERSIONÚOPENSSL_CFLAGSÚOPENSSL_PLATFORMÚ OPENSSL_DIRÚOPENSSL_BUILT_ONÚ SENT_SHUTDOWNÚRECEIVED_SHUTDOWNÚ SSLv23_METHODÚ TLSv1_METHODÚTLSv1_1_METHODÚTLSv1_2_METHODÚ TLS_METHODÚTLS_SERVER_METHODÚTLS_CLIENT_METHODÚ DTLS_METHODÚDTLS_SERVER_METHODÚDTLS_CLIENT_METHODÚ SSL3_VERSIONÚ TLS1_VERSIONÚTLS1_1_VERSIONÚTLS1_2_VERSIONÚTLS1_3_VERSIONÚ OP_NO_SSLv2Ú OP_NO_SSLv3Ú OP_NO_TLSv1Ú OP_NO_TLSv1_1Ú OP_NO_TLSv1_2Ú OP_NO_TLSv1_3ÚMODE_RELEASE_BUFFERSÚOP_SINGLE_DH_USEÚOP_SINGLE_ECDH_USEÚOP_EPHEMERAL_RSAÚOP_MICROSOFT_SESS_ID_BUGÚOP_NETSCAPE_CHALLENGE_BUGÚ#OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUGÚOP_SSLREF2_REUSE_CERT_TYPE_BUGÚOP_MICROSOFT_BIG_SSLV3_BUFFERÚOP_MSIE_SSLV2_RSA_PADDINGÚOP_SSLEAY_080_CLIENT_DH_BUGÚ OP_TLS_D5_BUGÚOP_TLS_BLOCK_PADDING_BUGÚOP_DONT_INSERT_EMPTY_FRAGMENTSÚOP_CIPHER_SERVER_PREFERENCEÚOP_TLS_ROLLBACK_BUGÚOP_PKCS1_CHECK_1ÚOP_PKCS1_CHECK_2ÚOP_NETSCAPE_CA_DN_BUGÚ"OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUGÚOP_NO_COMPRESSIONÚOP_NO_QUERY_MTUÚOP_COOKIE_EXCHANGEÚ OP_NO_TICKETÚOP_NO_RENEGOTIATIONÚOP_IGNORE_UNEXPECTED_EOFÚOP_ALLÚ VERIFY_PEERÚVERIFY_FAIL_IF_NO_PEER_CERTÚVERIFY_CLIENT_ONCEÚ VERIFY_NONEÚSESS_CACHE_OFFÚSESS_CACHE_CLIENTÚSESS_CACHE_SERVERÚSESS_CACHE_BOTHÚSESS_CACHE_NO_AUTO_CLEARÚSESS_CACHE_NO_INTERNAL_LOOKUPÚSESS_CACHE_NO_INTERNAL_STOREÚSESS_CACHE_NO_INTERNALÚSSL_ST_CONNECTÚ SSL_ST_ACCEPTÚ SSL_ST_MASKÚ SSL_CB_LOOPÚ SSL_CB_EXITÚ SSL_CB_READÚ SSL_CB_WRITEÚ SSL_CB_ALERTÚSSL_CB_READ_ALERTÚSSL_CB_WRITE_ALERTÚSSL_CB_ACCEPT_LOOPÚSSL_CB_ACCEPT_EXITÚSSL_CB_CONNECT_LOOPÚSSL_CB_CONNECT_EXITÚSSL_CB_HANDSHAKE_STARTÚSSL_CB_HANDSHAKE_DONEÚErrorÚ WantReadErrorÚWantWriteErrorÚWantX509LookupErrorÚZeroReturnErrorÚ SysCallErrorÚNO_OVERLAPPING_PROTOCOLSÚSSLeay_versionÚSessionÚContextÚ Connectionééééééé é é é iiiii)z"/etc/ssl/certs/ca-certificates.crtz /etc/pki/tls/certs/ca-bundle.crtz/etc/ssl/ca-bundle.pemz/etc/pki/tls/cacert.pemz1/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pemz/etc/ssl/certss$/opt/pyca/cryptography/openssl/certss'/opt/pyca/cryptography/openssl/cert.pemc@seZdZdZdS)rpz4 An error occurred in an `OpenSSL.SSL` API. N©Ú__name__Ú __module__Ú __qualname__Ú__doc__©rŠrŠúo/sparta/input/_build_configuration/image_build+validate/lib/bmcenv/lib64/python3.9/site-packages/OpenSSL/SSL.pyrpsrpc@s eZdZdS)rqN©r†r‡rˆrŠrŠrŠr‹rqsrqc@s eZdZdS)rrNrŒrŠrŠrŠr‹rrsrrc@s eZdZdS)rsNrŒrŠrŠrŠr‹rs"srsc@s eZdZdS)rtNrŒrŠrŠrŠr‹rt&srtc@s eZdZdS)ruNrŒrŠrŠrŠr‹ru*sruc@s eZdZdZdd„Zdd„ZdS)Ú_CallbackExceptionHelperaÅ A base class for wrapper classes that allow for intelligent exception handling in OpenSSL callbacks. :ivar list _problems: Any exceptions that occurred while executing in a context where they could not be raised in the normal way. Typically this is because OpenSSL has called into some Python code and requires a return value. The exceptions are saved to be raised later when it is possible to do so. cCs g|_dS©N)Ú _problems©ÚselfrŠrŠr‹Ú__init__:sz!_CallbackExceptionHelper.__init__cCs4|jr0z tƒWnty"Yn0|j d¡‚dS)z Raise an exception from the OpenSSL error queue or that was previously captured whe running a callback. rN)rÚ_raise_current_errorrpÚpoprrŠrŠr‹Úraise_if_problem=s   z)_CallbackExceptionHelper.raise_if_problemN)r†r‡rˆr‰r’r•rŠrŠrŠr‹r.s rc@seZdZdZdd„ZdS)Ú _VerifyHelperz^ Wrap a callback such that it can be used as a certificate verification callback. cs2t ˆ¡tˆƒ‡‡fdd„ƒ}t d|¡ˆ_dS)Nc s¶t |¡}t |¡t |¡}t |¡}t |¡}t ¡}t ||¡}t j |}zˆ|||||ƒ} Wn2t y–} zˆj   | ¡WYd} ~ dSd} ~ 00| r®t |tj¡dSdSdS©Nré)Ú_libÚX509_STORE_CTX_get_current_certÚ X509_up_refrÚ_from_raw_x509_ptrÚX509_STORE_CTX_get_errorÚX509_STORE_CTX_get_error_depthÚ"SSL_get_ex_data_X509_STORE_CTX_idxÚX509_STORE_CTX_get_ex_datarzÚ_reverse_mappingÚ ExceptionrÚappendÚX509_STORE_CTX_set_errorÚ X509_V_OK) ÚokÚ store_ctxÚx509ÚcertÚ error_numberÚ error_depthÚindexÚsslÚ connectionÚresultÚe©Úcallbackr‘rŠr‹ÚwrapperSs&        ÿ z'_VerifyHelper.__init__..wrapperzint (*)(int, X509_STORE_CTX *)©rr’rÚ_ffir²©r‘r²r³rŠr±r‹r’Ps  ÿz_VerifyHelper.__init__N©r†r‡rˆr‰r’rŠrŠrŠr‹r–Jsr–c@seZdZdZdd„ZdS)Ú_ALPNSelectHelperzQ Wrap a callback such that it can be used as an ALPN selection callback. cs2t ˆ¡tˆƒ‡‡fdd„ƒ}t d|¡ˆ_dS)Nc szÞtj|}t ||¡dd…}g}|r\|d} |d| d…} | | ¡|| dd…}q$ˆ||ƒ} d} | tur|d} d} nt| tƒsŽtdƒ‚t  dt | ƒ¡t  d| ¡g|_ |j dd|d<|j d|d<| sØt j WSt jWSty} zˆj | ¡t jWYd} ~ Sd} ~ 00dS) Nrr˜TóFz^ALPN callback must return a bytestring or the special NO_OVERLAPPING_PROTOCOLS sentinel value.zunsigned char *úunsigned char[])rzr¡rµÚbufferr£rvÚ isinstanceÚbytesÚ TypeErrorÚnewÚlenÚ_alpn_select_callback_argsr™ÚSSL_TLSEXT_ERR_NOACKÚSSL_TLSEXT_ERR_OKr¢rÚSSL_TLSEXT_ERR_ALERT_FATAL)r­ÚoutÚoutlenÚin_ÚinlenÚargÚconnÚinstrÚ protolistÚ encoded_lenÚprotoÚoutbytesÚ any_acceptedr°r±rŠr‹r³}s:    ÿ  þ z+_ALPNSelectHelper.__init__..wrapperz^int (*)(SSL *, unsigned char **, unsigned char *, const unsigned char *, unsigned int, void *)r´r¶rŠr±r‹r’zs +ûz_ALPNSelectHelper.__init__Nr·rŠrŠrŠr‹r¸usr¸c@seZdZdZdd„ZdS)Ú_OCSPServerCallbackHelperað Wrap a callback such that it can be used as an OCSP callback for the server side. Annoyingly, OpenSSL defines one OCSP callback but uses it in two different ways. For servers, that callback is expected to retrieve some OCSP data and hand it to OpenSSL, and may return only SSL_TLSEXT_ERR_OK, SSL_TLSEXT_ERR_FATAL, and SSL_TLSEXT_ERR_NOACK. For clients, that callback is expected to check the OCSP data, and returns a negative value on error, 0 if the response is not acceptable, or positive if it is. These are mutually exclusive return code behaviours, and they mean that we need two helpers so that we always return an appropriate error code if the user's code throws an exception. Given that we have to have two helpers anyway, these helpers are a bit more helpery than most: specifically, they hide a few more of the OpenSSL functions so that the user has an easier time writing these callbacks. This helper implements the server side. cs2t ˆ¡tˆƒ‡‡fdd„ƒ}t d|¡ˆ_dS)Nc s¼z„tj|}|tjkr"t |¡}nd}ˆ||ƒ}t|tƒsBtdƒ‚|sLWdSt|ƒ}t   |¡}|t  ||¡dd…<t   |||¡WdSt y¶}zˆj |¡WYd}~dSd}~00dS)Nz'OCSP callback must return a bytestring.r{ré)rzr¡rµÚNULLÚ from_handler¼r½r¾rÀr™ÚOPENSSL_mallocr»ÚSSL_set_tlsext_status_ocsp_respr¢rr£)r­ÚcdatarÊÚdataÚ ocsp_dataÚocsp_data_lengthÚdata_ptrr°r±rŠr‹r³Ës(      ÿ z3_OCSPServerCallbackHelper.__init__..wrapperúint (*)(SSL *, void *)r´r¶rŠr±r‹r’Ès &z"_OCSPServerCallbackHelper.__init__Nr·rŠrŠrŠr‹rѲsrÑc@seZdZdZdd„ZdS)Ú_OCSPClientCallbackHelperað Wrap a callback such that it can be used as an OCSP callback for the client side. Annoyingly, OpenSSL defines one OCSP callback but uses it in two different ways. For servers, that callback is expected to retrieve some OCSP data and hand it to OpenSSL, and may return only SSL_TLSEXT_ERR_OK, SSL_TLSEXT_ERR_FATAL, and SSL_TLSEXT_ERR_NOACK. For clients, that callback is expected to check the OCSP data, and returns a negative value on error, 0 if the response is not acceptable, or positive if it is. These are mutually exclusive return code behaviours, and they mean that we need two helpers so that we always return an appropriate error code if the user's code throws an exception. Given that we have to have two helpers anyway, these helpers are a bit more helpery than most: specifically, they hide a few more of the OpenSSL functions so that the user has an easier time writing these callbacks. This helper implements the client side. cs2t ˆ¡tˆƒ‡‡fdd„ƒ}t d|¡ˆ_dS)Nc s²zztj|}|tjkr"t |¡}nd}t d¡}t ||¡}|dkrJd}nt |d|¡dd…}ˆ|||ƒ}t t |ƒƒWSt y¬}zˆj   |¡WYd}~dSd}~00dS)Núunsigned char **rr¹éÿÿÿÿ)rzr¡rµrÓrÔr¿r™ÚSSL_get_tlsext_status_ocsp_respr»ÚintÚboolr¢rr£) r­r×rÊrØÚocsp_ptrÚocsp_lenrÙÚvalidr°r±rŠr‹r³s       z3_OCSPClientCallbackHelper.__init__..wrapperrÜr´r¶rŠr±r‹r’ s z"_OCSPClientCallbackHelper.__init__Nr·rŠrŠrŠr‹rÝõsrÝc@seZdZdd„ZdS)Ú_CookieGenerateCallbackHelpercs2t ˆ¡tˆƒ‡‡fdd„ƒ}t d|¡ˆ_dS)Nc slz4tj|}ˆ|ƒ}||dt|ƒ…<t|ƒ|d<WdStyf}zˆj |¡WYd}~dSd}~00dSr—)rzr¡rÀr¢rr£)r­rÅrÆrÊÚcookier°r±rŠr‹r³4s   z7_CookieGenerateCallbackHelper.__init__..wrapperz/int (*)(SSL *, unsigned char *, unsigned int *)r´r¶rŠr±r‹r’1s  þz&_CookieGenerateCallbackHelper.__init__N©r†r‡rˆr’rŠrŠrŠr‹ræ0sræc@seZdZdd„ZdS)Ú_CookieVerifyCallbackHelpercs2t ˆ¡tˆƒ‡‡fdd„ƒ}t d|¡ˆ_dS)Nc sZz"tj|}ˆ|t|d|…ƒƒWStyT}zˆj |¡WYd}~dSd}~00dS©Nr)rzr¡r½r¢rr£)r­Úc_cookieÚ cookie_lenrÊr°r±rŠr‹r³Ks   z5_CookieVerifyCallbackHelper.__init__..wrapperz-int (*)(SSL *, unsigned char *, unsigned int)r´r¶rŠr±r‹r’Hs þz$_CookieVerifyCallbackHelper.__init__NrèrŠrŠrŠr‹réGsrécCsdd}t|tƒs(t|ddƒ}|dur(|ƒ}t|tƒr6|}t|tƒsJtdƒ‚n|dkr`td|fƒ‚|S)NÚfilenoz3argument must be an int, or have a fileno() method.rz1file descriptor cannot be a negative integer (%i))r¼ráÚgetattrr¾Ú ValueError)ÚobjÚfdÚmethrŠrŠr‹Ú_asFileDescriptorZs     ÿrócCst t |¡¡S)z” Return a string describing the version of OpenSSL in use. :param type: One of the :const:`OPENSSL_` constants defined in this module. )rµÚstringr™ÚOpenSSL_version)ÚtyperŠrŠr‹rõnsrõcs‡‡fdd„}|S)a” Builds a decorator that ensures that functions that rely on OpenSSL functions that are not present in this build raise NotImplementedError, rather than AttributeError coming out of cryptography. :param flag: A cryptography flag that guards the functions, e.g. ``Cryptography_HAS_NEXTPROTONEG``. :param error: The string to be used in the exception if the flag is false. cs$ˆst|ƒ‡fdd„ƒ}|S|SdS)Ncs tˆƒ‚dSrŽ©ÚNotImplementedError)ÚargsÚkwargs)ÚerrorrŠr‹Úexplodeˆsz<_make_requires.._requires_decorator..explode)r)Úfuncrü©rûÚflagrŠr‹Ú_requires_decorator…s z+_make_requires.._requires_decoratorrŠ)rÿrûrrŠrþr‹Ú_make_requireszs  rzALPN not availableÚCryptography_HAS_KEYLOGzKey logging not availablec@seZdZdZdS)rxzÉ A class representing an SSL session. A session defines certain connection parameters which may be re-used to speed up the setup of subsequent connections. .. versionadded:: 0.14 Nr…rŠrŠrŠr‹rxsrxc@seZdZdZeejdfeejefe eje fe eje fe ejdfeejdfeejdfeejdfeejdfeejdfi Zdd„Zdd„Zdd„Zdcd d „Zd d „Zddd d„Zdd„Zdd„Z dd„Z!dd„Z"e#fdd„Z$dd„Z%dd„Z&dd„Z'e(fdd „Z)d!d"„Z*d#d$„Z+d%d&„Z,d'd(„Z-d)d*„Z.d+d,„Z/ded-d.„Z0d/d0„Z1d1d2„Z2d3d4„Z3d5d6„Z4d7d8„Z5d9d:„Z6d;d<„Z7d=d>„Z8d?d@„Z9dAdB„Z:dCdD„Z;edIdJ„Z?dKdL„Z@dMdN„ZAdOdP„ZBdQdR„ZCdSdT„ZDeEdUdV„ƒZFeEdWdX„ƒZGdYdZ„ZHdfd[d\„ZIdgd]d^„ZJd_d`„ZKdadb„ZLdS)hryau :class:`OpenSSL.SSL.Context` instances define the parameters for setting up new SSL connections. :param method: One of TLS_METHOD, TLS_CLIENT_METHOD, TLS_SERVER_METHOD, DTLS_METHOD, DTLS_CLIENT_METHOD, or DTLS_SERVER_METHOD. SSLv23_METHOD, TLSv1_METHOD, etc. are deprecated and should not be used. NcCst|tƒstdƒ‚z|j|\}}Wnty>tdƒ‚Yn0|ƒ}t|tjkƒt   |¡}t|tjkƒt  |t j ¡}||_ d|_d|_d|_d|_d|_d|_d|_d|_d|_d|_d|_d|_d|_d|_d|_d|_| t j¡|dur |  |¡| !|¡dS)Nzmethod must be an integerzNo such protocol)"r¼rár¾Ú_methodsÚKeyErrorrïÚ_openssl_assertrµrÓr™Ú SSL_CTX_newÚgcÚ SSL_CTX_freeÚ_contextÚ_passphrase_helperÚ_passphrase_callbackÚ_passphrase_userdataÚ_verify_helperÚ_verify_callbackÚ_info_callbackÚ_keylog_callbackÚ_tlsext_servername_callbackÚ _app_dataÚ_alpn_select_helperÚ_alpn_select_callbackÚ _ocsp_helperÚ_ocsp_callbackÚ _ocsp_dataÚ_cookie_generate_helperÚ_cookie_verify_helperÚset_modeÚSSL_MODE_ENABLE_PARTIAL_WRITEÚset_min_proto_versionÚset_max_proto_version)r‘ÚmethodÚ method_funcÚversionÚ method_objÚcontextrŠrŠr‹r’Ás@      zContext.__init__cCstt |j|¡dkƒdS)aD Set the minimum supported protocol version. Setting the minimum version to 0 will enable protocol versions down to the lowest version supported by the library. If the underlying OpenSSL build is missing support for the selected version, this method will raise an exception. r˜N)rr™ÚSSL_CTX_set_min_proto_versionr ©r‘r rŠrŠr‹rès ÿzContext.set_min_proto_versioncCstt |j|¡dkƒdS)aC Set the maximum supported protocol version. Setting the maximum version to 0 will enable protocol versions up to the highest version supported by the library. If the underlying OpenSSL build is missing support for the selected version, this method will raise an exception. r˜N)rr™ÚSSL_CTX_set_max_proto_versionr r$rŠrŠr‹rõs ÿzContext.set_max_proto_versioncCsN|durtj}nt|ƒ}|dur(tj}nt|ƒ}t |j||¡}|sJtƒdS)aU Let SSL 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 *pemfile* or *capath* may be :data:`None`. :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 N)rµrÓÚ _path_bytesr™ÚSSL_CTX_load_verify_locationsr r“)r‘ÚcafileÚcapathÚ load_resultrŠrŠr‹Úload_verify_locationssÿzContext.load_verify_locationscs&tˆƒ‡‡fdd„ƒ}tt|dddS)Ncsˆ||ˆjƒSrŽ)r )ÚsizeÚverifyÚuserdatar±rŠr‹r³#sz'Context._wrap_callback..wrapperT)Ú more_argsÚtruncate)rrrr¶rŠr±r‹Ú_wrap_callback"s ÿzContext._wrap_callbackcCs@t|ƒstdƒ‚| |¡|_|jj|_t |j|j¡||_ dS)aò Set the passphrase callback. This function will be called when a private key with a passphrase is loaded. :param callback: The Python callback to use. This must accept three positional arguments. First, an integer giving the maximum length of the passphrase it may return. If the returned passphrase is longer than this, it will be truncated. Second, a boolean value which will be true if the user should be prompted for the passphrase twice and the callback should verify that the two values supplied are equal. Third, the value given as the *userdata* parameter to :meth:`set_passwd_cb`. The *callback* must return a byte string. If an error occurs, *callback* should return a false value (e.g. an empty string). :param userdata: (optional) A Python object which will be given as argument to the callback :return: None úcallback must be callableN) Úcallabler¾r1r r²r r™ÚSSL_CTX_set_default_passwd_cbr r )r‘r²r.rŠrŠr‹Ú set_passwd_cb+s  ÿzContext.set_passwd_cbcCsˆt |j¡}t|dkƒt t ¡¡ d¡}t t ¡¡ d¡}|  ||¡s„t t  ¡¡}t t  ¡¡}|t kr„|t kr„| tt¡dS)aÙ Specify that the platform provided CA certificates are to be used for verification purposes. This method has some caveats related to the binary wheels that cryptography (pyOpenSSL's primary dependency) ships: * macOS will only load certificates using this method if the user has the ``openssl@1.1`` `Homebrew `_ formula installed in the default location. * Windows will not work. * manylinux1 cryptography wheels will work on most common Linux distributions in pyOpenSSL 17.1.0 and above. pyOpenSSL detects the manylinux1 wheel and attempts to load roots via a fallback path. :return: None r˜ÚasciiN)r™Ú SSL_CTX_set_default_verify_pathsr rrµrôÚX509_get_default_cert_dir_envÚdecodeÚX509_get_default_cert_file_envÚ_check_env_vars_setÚX509_get_default_cert_dirÚX509_get_default_cert_fileÚ_CRYPTOGRAPHY_MANYLINUX_CA_DIRÚ_CRYPTOGRAPHY_MANYLINUX_CA_FILEÚ_fallback_default_verify_pathsÚ_CERTIFICATE_FILE_LOCATIONSÚ_CERTIFICATE_PATH_LOCATIONS)r‘Ú set_resultÚ dir_env_varÚ file_env_varÚ default_dirÚ default_filerŠrŠr‹Úset_default_verify_pathsHs(  ÿÿþ ÿþÿz Context.set_default_verify_pathscCs tj |¡duptj |¡duS)zp Check to see if the default cert dir/file environment vars are present. :return: bool N)ÚosÚenvironÚget)r‘rDrErŠrŠr‹r;xsþzContext._check_env_vars_setcCsN|D]}tj |¡r| |¡q$q|D] }tj |¡r(| d|¡qJq(dS)aW Default verify paths are based on the compiled version of OpenSSL. However, when pyca/cryptography is compiled as a manylinux1 wheel that compiled location can potentially be wrong. So, like Go, we will try a predefined set of paths and attempt to load roots from there. :return: None N)rIÚpathÚisfiler+Úisdir)r‘Ú file_pathÚdir_pathr(r)rŠrŠr‹r@ƒs     z&Context._fallback_default_verify_pathscCs$t|ƒ}t |j|¡}|s tƒdS)zÍ Load a certificate chain from a file. :param certfile: The name of the certificate chain file (``bytes`` or ``unicode``). Must be PEM encoded. :return: None N)r&r™Ú"SSL_CTX_use_certificate_chain_filer r“)r‘Úcertfiler¯rŠrŠr‹Úuse_certificate_chain_file—s ÿz"Context.use_certificate_chain_filecCs8t|ƒ}t|tƒstdƒ‚t |j||¡}|s4tƒdS)ah Load a certificate from a file :param certfile: The name of the certificate file (``bytes`` or ``unicode``). :param filetype: (optional) The encoding of the file, which is either :const:`FILETYPE_PEM` or :const:`FILETYPE_ASN1`. The default is :const:`FILETYPE_PEM`. :return: None úfiletype must be an integerN)r&r¼rár¾r™ÚSSL_CTX_use_certificate_filer r“)r‘rRÚfiletypeÚ use_resultrŠrŠr‹Úuse_certificate_file¨s  ÿzContext.use_certificate_filecCs0t|tƒstdƒ‚t |j|j¡}|s,tƒdS©zs Load a certificate from a X509 object :param cert: The X509 object :return: None zcert must be an X509 instanceN)r¼rr¾r™ÚSSL_CTX_use_certificater Ú_x509r“©r‘r©rWrŠrŠr‹Úuse_certificate¾s  zContext.use_certificatecCsDt|tƒstdƒ‚t |j¡}t |j|¡}|s@t |¡t ƒdS)z‰ Add certificate to chain :param certobj: The X509 certificate object to add to the chain :return: None z certobj must be an X509 instanceN) r¼rr¾r™ÚX509_dupr[ÚSSL_CTX_add_extra_chain_certr Ú X509_freer“)r‘ÚcertobjÚcopyÚ add_resultrŠrŠr‹Úadd_extra_chain_certÍs   zContext.add_extra_chain_certcCs |jdur|j t¡tƒdSrŽ)r r•rpr“rrŠrŠr‹Ú_raise_passphrase_exceptionÞs  z#Context._raise_passphrase_exceptioncCsHt|ƒ}|turt}nt|tƒs(tdƒ‚t |j||¡}|sD|  ¡dS)aR Load a private key from a file :param keyfile: The name of the key file (``bytes`` or ``unicode``) :param filetype: (optional) The encoding of the file, which is either :const:`FILETYPE_PEM` or :const:`FILETYPE_ASN1`. The default is :const:`FILETYPE_PEM`. :return: None rTN) r&Ú _UNSPECIFIEDrr¼rár¾r™ÚSSL_CTX_use_PrivateKey_filer re)r‘ÚkeyfilerVrWrŠrŠr‹Úuse_privatekey_fileäs  ÿzContext.use_privatekey_filecCs2t|tƒstdƒ‚t |j|j¡}|s.| ¡dS©zs Load a private key from a PKey object :param pkey: The PKey object :return: None zpkey must be a PKey instanceN)r¼rr¾r™ÚSSL_CTX_use_PrivateKeyr Ú_pkeyre©r‘ÚpkeyrWrŠrŠr‹Úuse_privatekeyüs  zContext.use_privatekeycCst |j¡stƒdS)zß Check if the private key (loaded with :meth:`use_privatekey`) matches the certificate (loaded with :meth:`use_certificate`) :return: :data:`None` (raises :exc:`Error` if something's wrong) N)r™ÚSSL_CTX_check_private_keyr r“rrŠrŠr‹Úcheck_privatekey s zContext.check_privatekeycCs0t td|ƒ¡}t|tjkƒt |j|¡dS)a% Load the trusted certificates that will be sent to the client. Does not actually imply any of the certificates are trusted; that must be configured separately. :param bytes cafile: The path to a certificates file in PEM format. :return: None r(N)r™ÚSSL_load_client_CA_fileÚ_text_to_bytes_and_warnrrµrÓÚSSL_CTX_set_client_CA_listr )r‘r(Úca_listrŠrŠr‹Úload_client_cas ÿzContext.load_client_cacCs*td|ƒ}tt |j|t|ƒ¡dkƒdS)aV Set the session id to *buf* within which a session can be reused for this Context object. This is needed when doing session resumption, because there is no way for a stored session to know which Context object it is associated with. :param bytes buf: The session id. :returns: None Úbufr˜N)rsrr™ÚSSL_CTX_set_session_id_contextr rÀ)r‘rwrŠrŠr‹Úset_session_id$s ÿÿzContext.set_session_idcCs t|tƒstdƒ‚t |j|¡S)aŽ Set the behavior of the session cache used by all connections using this Context. The previously set mode is returned. See :const:`SESS_CACHE_*` for details about particular modes. :param mode: One or more of the SESS_CACHE_* flags (combine using bitwise or) :returns: The previously set caching mode. .. versionadded:: 0.14 úmode must be an integer)r¼rár¾r™ÚSSL_CTX_set_session_cache_moder ©r‘ÚmoderŠrŠr‹Úset_session_cache_mode5s zContext.set_session_cache_modecCs t |j¡S)z‡ Get the current session cache mode. :returns: The currently used cache mode. .. versionadded:: 0.14 )r™ÚSSL_CTX_get_session_cache_moder rrŠrŠr‹Úget_session_cache_modeFszContext.get_session_cache_modecCstt|tƒstdƒ‚|dur:d|_d|_t |j|tj ¡n6t |ƒsJtdƒ‚t |ƒ|_|jj |_t |j||j¡dS)aÚ Set the verification flags for this Context object to *mode* and specify that *callback* should be used for verification callbacks. :param mode: The verify mode, this should be one of :const:`VERIFY_NONE` and :const:`VERIFY_PEER`. If :const:`VERIFY_PEER` is used, *mode* can be OR:ed with :const:`VERIFY_FAIL_IF_NO_PEER_CERT` and :const:`VERIFY_CLIENT_ONCE` to further control the behaviour. :param callback: The optional Python verification callback to use. This should take five arguments: A Connection object, an X509 object, and three integer variables, which are in turn potential error number, error depth and return code. *callback* should return True if verification passes and False otherwise. If omitted, OpenSSL's default verification is used. :return: None See SSL_CTX_set_verify(3SSL) for further details. rzNr2) r¼rár¾r rr™ÚSSL_CTX_set_verifyr rµrÓr3r–r²©r‘r}r²rŠrŠr‹Ú set_verifyPs   zContext.set_verifycCs$t|tƒstdƒ‚t |j|¡dS)zÙ Set the maximum depth for the certificate chain verification that shall be allowed for this Context object. :param depth: An integer specifying the verify depth :return: None zdepth must be an integerN)r¼rár¾r™ÚSSL_CTX_set_verify_depthr )r‘ÚdepthrŠrŠr‹Úset_verify_depthss zContext.set_verify_depthcCs t |j¡S)z„ Retrieve the Context object's verify mode, as set by :meth:`set_verify`. :return: The verify mode )r™ÚSSL_CTX_get_verify_moder rrŠrŠr‹Úget_verify_mode€szContext.get_verify_modecCs t |j¡S)zŒ Retrieve the Context object's verify depth, as set by :meth:`set_verify_depth`. :return: The verify depth )r™ÚSSL_CTX_get_verify_depthr rrŠrŠr‹Úget_verify_depth‰szContext.get_verify_depthcCstt|ƒ}t |d¡}|tjkr$tƒt |tj¡}t |tjtjtj¡}t |tj ¡}t  |j |¡}t |dkƒdS)zº Load parameters for Ephemeral Diffie-Hellman :param dhfile: The file to load EDH parameters from (``bytes`` or ``unicode``). :return: None órr˜N) r&r™Ú BIO_new_filerµrÓr“rÚBIO_freeÚPEM_read_bio_DHparamsÚDH_freeÚSSL_CTX_set_tmp_dhr r)r‘ÚdhfileÚbioÚdhÚresrŠrŠr‹Ú load_tmp_dh’s   zContext.load_tmp_dhcCst |j| ¡¡dS)a  Select a curve to use for ECDHE key exchange. :param curve: A curve object to use as returned by either :meth:`OpenSSL.crypto.get_elliptic_curve` or :meth:`OpenSSL.crypto.get_elliptic_curves`. :return: None N)r™ÚSSL_CTX_set_tmp_ecdhr Ú _to_EC_KEY)r‘ÚcurverŠrŠr‹Ú set_tmp_ecdh§s zContext.set_tmp_ecdhcCsZtd|ƒ}t|tƒstdƒ‚tt |j|¡dkƒt|dƒ}|  ¡gd¢krVt dgƒ‚dS)zó Set the list of ciphers to be used in this context. See the OpenSSL manual for more information (e.g. :manpage:`ciphers(1)`). :param bytes cipher_list: An OpenSSL cipher string. :return: None Ú cipher_listz"cipher_list must be a byte string.r˜N)ÚTLS_AES_256_GCM_SHA384ÚTLS_CHACHA20_POLY1305_SHA256ÚTLS_AES_128_GCM_SHA256)z SSL routinesÚSSL_CTX_set_cipher_listzno cipher match) rsr¼r½r¾rr™ržr rzÚget_cipher_listrp)r‘ršÚtmpconnrŠrŠr‹Úset_cipher_list³s  ÿ ÿÿzContext.set_cipher_listcCs®t ¡}t|tjkƒzf|D]\}t|tƒs>tdt|ƒj fƒ‚t  |j ¡}t|tjkƒt  ||¡}|st  |¡tƒqWntyšt |¡‚Yn0t |j|¡dS)a_ Set the list of preferred client certificate signers for this server context. This list of certificate authorities will be sent to the client when the server requests a client certificate. :param certificate_authorities: a sequence of X509Names. :return: None .. versionadded:: 0.10 z3client CAs must be X509Name objects, not %s objectsN)r™Úsk_X509_NAME_new_nullrrµrÓr¼rr¾rör†Ú X509_NAME_dupÚ_nameÚsk_X509_NAME_pushÚX509_NAME_freer“r¢Úsk_X509_NAME_freertr )r‘Úcertificate_authoritiesÚ name_stackÚca_namerbÚ push_resultrŠrŠr‹Úset_client_ca_listÚs(   ÿÿ      zContext.set_client_ca_listcCs2t|tƒstdƒ‚t |j|j¡}t|dkƒdS)ai Add the CA certificate to the list of preferred signers for this context. The list of certificate authorities will be sent to the client when the server requests a client certificate. :param certificate_authority: certificate authority's X509 certificate. :return: None .. versionadded:: 0.10 z.certificate_authority must be an X509 instancer˜N)r¼rr¾r™ÚSSL_CTX_add_client_CAr r[r)r‘Úcertificate_authorityrcrŠrŠr‹Ú add_client_caýs ÿzContext.add_client_cacCs t|tƒstdƒ‚t |j|¡S)aQ Set the timeout for newly created sessions for this Context object to *timeout*. The default value is 300 seconds. See the OpenSSL manual for more information (e.g. :manpage:`SSL_CTX_set_timeout(3)`). :param timeout: The timeout in (whole) seconds :return: The previous session timeout ztimeout must be an integer)r¼rár¾r™ÚSSL_CTX_set_timeoutr )r‘ÚtimeoutrŠrŠr‹Ú set_timeouts zContext.set_timeoutcCs t |j¡S)z” Retrieve session timeout, as set by :meth:`set_timeout`. The default is 300 seconds. :return: The session timeout )r™ÚSSL_CTX_get_timeoutr rrŠrŠr‹Ú get_timeout szContext.get_timeoutcs6tˆƒ‡fdd„ƒ}t d|¡|_t |j|j¡dS)að Set the information callback to *callback*. This function will be called from time to time during SSL handshakes. :param callback: The Python callback to use. This should take three arguments: a Connection object and two integers. The first integer specifies where in the SSL handshake the function was called, and the other the return code from a (possibly failed) internal function call. :return: None csˆtj|||ƒdSrŽ©rzr¡)r­ÚwhereÚ return_code©r²rŠr‹r³6sz*Context.set_info_callback..wrapperzvoid (*)(const SSL *, int, int)N)rrµr²rr™ÚSSL_CTX_set_info_callbackr r¶rŠr¸r‹Úset_info_callback)s ÿzContext.set_info_callbackcs6tˆƒ‡fdd„ƒ}t d|¡|_t |j|j¡dS)a Set the TLS key logging callback to *callback*. This function will be called whenever TLS key material is generated or received, in order to allow applications to store this keying material for debugging purposes. :param callback: The Python callback to use. This should take two arguments: a Connection object and a bytestring that contains the key material in the format used by NSS for its SSLKEYLOGFILE debugging output. :return: None cst |¡}ˆtj||ƒdSrŽ)rµrôrzr¡)r­Úliner¸rŠr‹r³Ns z,Context.set_keylog_callback..wrapperz#void (*)(const SSL *, const char *)N)rrµr²rr™ÚSSL_CTX_set_keylog_callbackr r¶rŠr¸r‹Úset_keylog_callback?s ÿzContext.set_keylog_callbackcCs|jS)zw Get the application data (supplied via :meth:`set_app_data()`) :return: The application data ©rrrŠrŠr‹Ú get_app_dataXszContext.get_app_datacCs ||_dS)z Set the application data (will be returned from get_app_data()) :param data: Any Python object :return: None Nr¾©r‘rØrŠrŠr‹Ú set_app_data`szContext.set_app_datacCs.t |j¡}|tjkrdSt t¡}||_|S)zú Get the certificate store for the context. This can be used to add "trusted" certificates without using the :meth:`load_verify_locations` method. :return: A X509Store object or None if it does not have one. N)r™ÚSSL_CTX_get_cert_storer rµrÓrÚ__new__Ú_store)r‘ÚstoreÚpystorerŠrŠr‹Úget_cert_storeis    zContext.get_cert_storecCs t|tƒstdƒ‚t |j|¡S)zÝ Add options. Options set before are not cleared! This method should be used with the :const:`OP_*` constants. :param options: The options to add. :return: The new option bitmask. zoptions must be an integer)r¼rár¾r™ÚSSL_CTX_set_optionsr )r‘ÚoptionsrŠrŠr‹Ú set_optionszs zContext.set_optionscCs t|tƒstdƒ‚t |j|¡S)zà Add modes via bitmask. Modes set before are not cleared! This method should be used with the :const:`MODE_*` constants. :param mode: The mode to add. :return: The new mode bitmask. rz)r¼rár¾r™ÚSSL_CTX_set_moder r|rŠrŠr‹r‡s zContext.set_modecs6tˆƒ‡fdd„ƒ}t d|¡|_t |j|j¡dS)a Specify a callback function to be called when clients specify a server name. :param callback: The callback function. It will be invoked with one argument, the Connection instance. .. versionadded:: 0.13 csˆtj|ƒdSrêrµ)r­ÚalertrÉr¸rŠr‹r³Ÿsz7Context.set_tlsext_servername_callback..wrapperzint (*)(SSL *, int *, void *)N)rrµr²rr™Ú&SSL_CTX_set_tlsext_servername_callbackr r¶rŠr¸r‹Úset_tlsext_servername_callback”s ÿÿz&Context.set_tlsext_servername_callbackcCs,t|tƒstdƒ‚tt |j|¡dkƒdS)z÷ Enable support for negotiating SRTP keying material. :param bytes profiles: A colon delimited list of protection profile names, like ``b'SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32'``. :return: None zprofiles must be a byte string.rN)r¼r½r¾rr™ÚSSL_CTX_set_tlsext_use_srtpr )r‘ÚprofilesrŠrŠr‹Úset_tlsext_use_srtp«s  ÿzContext.set_tlsext_use_srtpcCsR|s tdƒ‚d t dd„|Dƒ¡¡}t d|¡}tt |j |t |ƒ¡dkƒdS)a• Specify the protocols that the client is prepared to speak after the TLS connection has been negotiated using Application Layer Protocol Negotiation. :param protos: A list of the protocols to be offered to the server. This list should be a Python list of bytestrings representing the protocols to offer, e.g. ``[b'http/1.1', b'spdy/2']``. ú'at least one protocol must be specifiedr¹css |]}tt|ƒfƒ|fVqdSrŽ©r½rÀ©Ú.0ÚprŠrŠr‹Ú Îr¹z*Context.set_alpn_protos..rºrN) rïÚjoinrÚ from_iterablerµr¿rr™ÚSSL_CTX_set_alpn_protosr rÀ©r‘ÚprotosÚprotostrÚ input_strrŠrŠr‹Úset_alpn_protosºsÿ  ÿýÿzContext.set_alpn_protoscCs,t|ƒ|_|jj|_t |j|jtj¡dS)aœ Specify a callback function that will be called on the server when a client offers protocols using ALPN. :param callback: The callback function. It will be invoked with two arguments: the Connection, and a list of offered protocols as bytestrings, e.g ``[b'http/1.1', b'spdy/2']``. It can return one of those bytestrings to indicate the chosen protocol, the empty bytestring to terminate the TLS connection, or the :py:obj:`NO_OVERLAPPING_PROTOCOLS` to indicate that no offered protocol was selected, but that the connection should not be aborted. N) r¸rr²rr™ÚSSL_CTX_set_alpn_select_cbr rµrÓ©r‘r²rŠrŠr‹Úset_alpn_select_callbackàs    ÿz Context.set_alpn_select_callbackcCsh||_|j|_|dur tj|_n t |¡|_t |j |j¡}t |dkƒt  |j |j¡}t |dkƒdS)z© This internal helper does the common work for ``set_ocsp_server_callback`` and ``set_ocsp_client_callback``, which is almost all of it. Nr˜) rr²rrµrÓrÚ new_handler™ÚSSL_CTX_set_tlsext_status_cbr rÚSSL_CTX_set_tlsext_status_arg)r‘ÚhelperrØÚrcrŠrŠr‹Ú_set_ocsp_callbackõs  ÿ zContext._set_ocsp_callbackcCst|ƒ}| ||¡dS)aû Set a callback to provide OCSP data to be stapled to the TLS handshake on the server side. :param callback: The callback function. It will be invoked with two arguments: the Connection, and the optional arbitrary data you have provided. The callback must return a bytestring that contains the OCSP data to staple to the handshake. If no OCSP data is available for this connection, return the empty bytestring. :param data: Some opaque data that will be passed into the callback function when called. This can be used to avoid needing to do complex data lookups or to keep track of what context is being used. This parameter is optional. N)rÑrè©r‘r²rØrærŠrŠr‹Úset_ocsp_server_callback sz Context.set_ocsp_server_callbackcCst|ƒ}| ||¡dS)a Set a callback to validate OCSP data stapled to the TLS handshake on the client side. :param callback: The callback function. It will be invoked with three arguments: the Connection, a bytestring containing the stapled OCSP assertion, and the optional arbitrary data you have provided. The callback must return a boolean that indicates the result of validating the OCSP data: ``True`` if the OCSP data is valid and the certificate can be trusted, or ``False`` if either the OCSP data is invalid or the certificate has been revoked. :param data: Some opaque data that will be passed into the callback function when called. This can be used to avoid needing to do complex data lookups or to keep track of what context is being used. This parameter is optional. N)rÝrèrérŠrŠr‹Úset_ocsp_client_callbacksz Context.set_ocsp_client_callbackcCs t|ƒ|_t |j|jj¡dSrŽ)rærr™ÚSSL_CTX_set_cookie_generate_cbr r²rárŠrŠr‹Úset_cookie_generate_callback/s  þz$Context.set_cookie_generate_callbackcCs t|ƒ|_t |j|jj¡dSrŽ)rérr™ÚSSL_CTX_set_cookie_verify_cbr r²rárŠrŠr‹Úset_cookie_verify_callback6s  þz"Context.set_cookie_verify_callback)N)N)N)N)N)Mr†r‡rˆr‰r$r™Ú TLS_methodr%r/r&r0r'r1r(r)ÚTLS_server_methodr*ÚTLS_client_methodr+Ú DTLS_methodr,ÚDTLS_server_methodr-ÚDTLS_client_methodrr’rrr+r1r5rHr;r@rSrrXr]rdrerfrirorqrvryr~r€rƒr†rˆrŠr•r™r¡r¬r¯r²r´rºÚ_requires_keylogr½r¿rÁrÇrÊrrÎrÑÚ_requires_alpnrßrârèrêrërírïrŠrŠrŠr‹ry©s~          ö '   0     #    '#      %   ryc@sDeZdZeƒZd‡dd„Zdd„Zdd„Zdd „Zd d „Z d d „Z dˆdd„Z dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zdd„Zd‰dd „ZeZdŠd!d"„Zd‹d#d$„ZeZdŒd%d&„Zd'd(„Zd)d*„Zd+d,„Zd-d.„Zd/d0„Zd1d2„Zd3d4„Zd5d6„Z d7d8„Z!d9d:„Z"d;d<„Z#d=d>„Z$d?d@„Z%dAdB„Z&dCdD„Z'dEdF„Z(dGdH„Z)dIdJ„Z*dKdL„Z+dMdN„Z,dOdP„Z-dQdR„Z.dSdT„Z/dUdV„Z0ddWdX„Z1dYdZ„Z2d[d\„Z3d]d^„Z4e5d_d`„ƒZ6dadb„Z7dcdd„Z8dedf„Z9dgdh„Z:didj„Z;dkdl„Zdqdr„Z?dsdt„Z@dudv„ZAdwdx„ZBdydz„ZCd{d|„ZDd}d~„ZEdd€„ZFeGdd‚„ƒZHeGdƒd„„ƒZId…d†„ZJdS)ŽrzNcCst|tƒstdƒ‚t |j¡}t |tj¡|_ t  |j tj ¡||_d|_ d|_ |j|_|j|_|j|_|j|_||j|j <|duràd|_t t ¡¡|_t|jtjkƒt t ¡¡|_t|jtjkƒt |j |j|j¡n2d|_d|_||_t |j t|jƒ¡}t|dkƒdS)zò Create a new Connection object, using the given OpenSSL.SSL.Context instance and socket. :param context: An SSL Context to use for this connection :param socket: The socket to use for transport layer ú"context must be a Context instanceNr˜)r¼ryr¾r™ÚSSL_newr rµrÚSSL_freeÚ_sslÚ SSL_set_modeÚSSL_MODE_AUTO_RETRYrrÁr rrrr¡Ú_socketÚBIO_newÚ BIO_s_memÚ _into_sslrrÓÚ _from_sslÚ SSL_set_bioÚ SSL_set_fdró)r‘r"Úsocketr­rCrŠrŠr‹r’As6    ÿzConnection.__init__cCs0|jdur td|jj|fƒ‚n t|j|ƒSdS)zy Look up attributes on the wrapped socket object if they are not found on the Connection object. Nz!'%s' object has no attribute '%s')rþÚAttributeErrorÚ __class__r†rî©r‘ÚnamerŠrŠr‹Ú __getattr__{s  ÿÿzConnection.__getattr__cCs||jjdur|jj ¡|jjdur0|jj ¡|jjdurH|jj ¡t ||¡}|tjkrhtƒ‚n|tj krzt ƒ‚nþ|tj krŒt ƒ‚nì|tj kržtƒ‚nÚ|tjkrt ¡dkrþ|dkròtdkrÔt ¡d}ntj}|dkròt|t |¡ƒ‚tddƒ‚ntƒnr|tjkrdt ¡dkrdt ¡}t |¡}tjr\t|tjkƒt ¡tddƒ‚ntƒn|tjkrrntƒdS)NrÚwin32rßzUnexpected EOF) r r r•rrr™Ú SSL_get_errorÚSSL_ERROR_WANT_READrqÚSSL_ERROR_WANT_WRITErrÚSSL_ERROR_ZERO_RETURNrtÚSSL_ERROR_WANT_X509_LOOKUPrsÚSSL_ERROR_SYSCALLÚERR_peek_errorrrµÚ getwinerrorÚerrnorurrKr“Ú SSL_ERROR_SSLÚERR_GET_REASONÚ-Cryptography_HAS_UNEXPECTED_EOF_WHILE_READINGrÚ"SSL_R_UNEXPECTED_EOF_WHILE_READINGÚERR_clear_errorÚSSL_ERROR_NONE)r‘r­r¯rûrÚ peeked_errorÚreasonrŠrŠr‹Ú_raise_ssl_errorˆsL                ÿ  zConnection._raise_ssl_errorcCs|jS)zh Retrieve the :class:`Context` object associated with this :class:`Connection`. )r rrŠrŠr‹Ú get_context¿szConnection.get_contextcCs,t|tƒstdƒ‚t |j|j¡||_dS)zª Switch this connection to a new session context. :param context: A :class:`Context` instance giving the new session context to use. røN)r¼ryr¾r™ÚSSL_set_SSL_CTXrûr )r‘r"rŠrŠr‹Ú set_contextÆs zConnection.set_contextcCs(t |jtj¡}|tjkrdSt |¡S)zï Retrieve the servername extension value if provided in the client hello message, or None if there wasn't one. :return: A byte string giving the server name or :data:`None`. .. versionadded:: 0.13 N)r™ÚSSL_get_servernamerûÚTLSEXT_NAMETYPE_host_namerµrÓrôrrŠrŠr‹Úget_servernameÓs ÿ zConnection.get_servernamecCstt|tƒstdƒ‚|dur:d|_d|_t |j|tj ¡n6t |ƒsJtdƒ‚t |ƒ|_|jj |_t |j||j¡dS)z— Override the Context object's verification flags for this specific connection. See :py:meth:`Context.set_verify` for details. rzNr2) r¼rár¾r rr™ÚSSL_set_verifyrûrµrÓr3r–r²r‚rŠrŠr‹rƒäs   zConnection.set_verifycCs t |j¡S)z‡ Retrieve the Connection object's verify mode, as set by :meth:`set_verify`. :return: The verify mode )r™ÚSSL_get_verify_moderûrrŠrŠr‹rˆøszConnection.get_verify_modecCs0t|tƒstdƒ‚t |j|j¡}|s,tƒdSrY)r¼rr¾r™ÚSSL_use_certificaterûr[r“r\rŠrŠr‹r]s  zConnection.use_certificatecCs4t|tƒstdƒ‚t |j|j¡}|s0|j ¡dSrj) r¼rr¾r™ÚSSL_use_PrivateKeyrûrlr rermrŠrŠr‹ros  zConnection.use_privatekeycCst |j|¡dS)aK For DTLS, set the maximum UDP payload size (*not* including IP/UDP overhead). Note that you might have to set :data:`OP_NO_QUERY_MTU` to prevent OpenSSL from spontaneously clearing this. :param mtu: An integer giving the maximum transmission unit. .. versionadded:: 21.1 N)r™Ú SSL_set_mturû)r‘ÚmturŠrŠr‹Úset_ciphertext_mtus zConnection.set_ciphertext_mtucCsttdƒstdƒ‚t |j¡S)a  For DTLS, get the maximum size of unencrypted data you can pass to :meth:`write` without exceeding the MTU (as passed to :meth:`set_ciphertext_mtu`). :return: The effective MTU as an integer. .. versionadded:: 21.1 ÚDTLS_get_data_mtuz requires OpenSSL 1.1.1 or better)Úhasattrr™rør+rûrrŠrŠr‹Úget_cleartext_mtu-s zConnection.get_cleartext_mtucCs6t|tƒstdƒ‚nd|vr$tdƒ‚t |j|¡dS)z­ Set the value of the servername extension to send in the client hello. :param name: A byte string giving the name. .. versionadded:: 0.13 zname must be a byte stringózname must not contain NUL byteN)r¼r½r¾r™ÚSSL_set_tlsext_host_namerûrrŠrŠr‹Úset_tlsext_host_name<s   zConnection.set_tlsext_host_namecCs t |j¡S)zÏ Get the number of bytes that can be safely read from the SSL buffer (**not** the underlying transport buffer). :return: The number of bytes available in the receive buffer. )r™Ú SSL_pendingrûrrŠrŠr‹ÚpendingLszConnection.pendingrcCsrtd|ƒ}t |¡J}t|ƒdkr*tdƒ‚t |j|t|ƒ¡}| |j|¡|WdƒS1sd0YdS)a³ Send data on the connection. NOTE: If you get one of the WantRead, WantWrite or WantX509Lookup exceptions on this, you have to call the method again with the SAME buffer. :param buf: The string, buffer or memoryview to send :param flags: (optional) Included for compatibility with the socket API, the value is ignored :return: The number of bytes written rwéÿÿÿz,Cannot send more than 2**31-1 bytes at once.N) rsrµÚ from_bufferrÀrïr™Ú SSL_writerûr)r‘rwÚflagsrØr¯rŠrŠr‹ÚsendUs   ÿzConnection.sendcCs†td|ƒ}t |¡^}t|ƒ}d}|r`t |j||t|dƒ¡}| |j|¡||7}||8}q"|WdƒS1sx0YdS)a© Send "all" data on the connection. This calls send() repeatedly until all data is sent. If an error occurs, it's impossible to tell how much data has been sent. :param buf: The string, buffer or memoryview to send :param flags: (optional) Included for compatibility with the socket API, the value is ignored :return: The number of bytes written rwrr3N) rsrµr4rÀr™r5rûÚminr)r‘rwr6rØÚ left_to_sendÚ total_sentr¯rŠrŠr‹Úsendallqs  ÿ zConnection.sendallcCs`td|ƒ}|dur.|tj@r.t |j||¡}nt |j||¡}| |j|¡t  ||¡dd…S)a Receive data on the connection. :param bufsiz: The maximum number of bytes to read :param flags: (optional) The only supported flag is ``MSG_PEEK``, all other flags are ignored. :return: The string read from the Connection úchar[]N) Ú_no_zero_allocatorrÚMSG_PEEKr™ÚSSL_peekrûÚSSL_readrrµr»)r‘Úbufsizr6rwr¯rŠrŠr‹Úrecvs zConnection.recvcCsˆ|durt|ƒ}nt|t|ƒƒ}td|ƒ}|durN|tj@rNt |j||¡}nt |j||¡}|  |j|¡t t   ||¡ƒ|d|…<|S)ae Receive data on the connection and copy it directly into the provided buffer, rather than creating a new string. :param buffer: The buffer to copy into. :param nbytes: (optional) The maximum number of bytes to read into the buffer. If not present, defaults to the size of the buffer. If larger than the size of the buffer, is reduced to the size of the buffer. :param flags: (optional) The only supported flag is ``MSG_PEEK``, all other flags are ignored. :return: The number of bytes read into the buffer. Nr<) rÀr8r=rr>r™r?rûr@rÚ memoryviewrµr»)r‘r»Únbytesr6rwr¯rŠrŠr‹Ú recv_into¢s  zConnection.recv_intocCsVt |¡rLt |¡rtƒ‚qRt |¡r.tƒ‚qRt |¡rBtdƒ‚qRtdƒ‚ntƒdS)NÚBIO_should_io_specialzunknown bio failure) r™ÚBIO_should_retryÚBIO_should_readrqÚBIO_should_writerrrFrïr“)r‘r’r¯rŠrŠr‹Ú_handle_bio_errorsÇs      zConnection._handle_bio_errorscCsh|jdurtdƒ‚t|tƒs$tdƒ‚td|ƒ}t |j||¡}|dkrT| |j|¡t  ||¡dd…S)a¹ If the Connection was created with a memory BIO, this method can be used to read bytes from the write end of that memory BIO. Many Connection methods will add bytes which must be read in this manner or the buffer will eventually fill up and the Connection will be able to take no further actions. :param bufsiz: The maximum number of bytes to read :return: The string read. NúConnection sock was not Nonezbufsiz must be an integerr<r) rr¾r¼rár=r™ÚBIO_readrJrµr»)r‘rArwr¯rŠrŠr‹Úbio_readÙs   zConnection.bio_readcCsxtd|ƒ}|jdurtdƒ‚t |¡>}t |j|t|ƒ¡}|dkrR| |j|¡|WdƒS1sj0YdS)aj If the Connection was created with a memory BIO, this method can be used to add bytes to the read end of that memory BIO. The Connection can then read the bytes (for example, in response to a call to :meth:`recv`). :param buf: The string to put into the memory BIO. :return: The number of bytes written rwNrKr) rsrr¾rµr4r™Ú BIO_writerÀrJ)r‘rwrØr¯rŠrŠr‹Ú bio_writeñs   zConnection.bio_writecCs$| ¡s tt |j¡dkƒdSdS)z‹ Renegotiate the session. :return: True if the renegotiation can be started, False otherwise :rtype: bool r˜TF)Úrenegotiate_pendingrr™ÚSSL_renegotiaterûrrŠrŠr‹Ú renegotiateszConnection.renegotiatecCst |j¡}| |j|¡dS)a Perform an SSL handshake (usually called after :meth:`renegotiate` or one of :meth:`set_accept_state` or :meth:`set_connect_state`). This can raise the same exceptions as :meth:`send` and :meth:`recv`. :return: None. N)r™ÚSSL_do_handshakerûr©r‘r¯rŠrŠr‹Ú do_handshakes zConnection.do_handshakecCst |j¡dkS)zÑ Check if there's a renegotiation in progress, it will return False once a renegotiation is finished. :return: Whether there's a renegotiation in progress :rtype: bool r˜)r™ÚSSL_renegotiate_pendingrûrrŠrŠr‹rPszConnection.renegotiate_pendingcCs t |j¡S)z‚ Find out the total number of renegotiations. :return: The number of renegotiations. :rtype: int )r™ÚSSL_total_renegotiationsrûrrŠrŠr‹Útotal_renegotiations'szConnection.total_renegotiationscCst |j¡|j |¡S)a4 Call the :meth:`connect` method of the underlying socket and set up SSL on the socket, using the :class:`Context` object supplied to this :class:`Connection` object at creation. :param addr: A remote address :return: What the socket's connect method returns )r™ÚSSL_set_connect_staterûrþÚconnect)r‘ÚaddrrŠrŠr‹rZ0s zConnection.connectcCs|jj}| ¡||ƒS)a• Call the :meth:`connect_ex` method of the underlying socket and set up SSL on the socket, using the Context object supplied to this Connection object at creation. Note that if the :meth:`connect_ex` method of the socket doesn't return 0, SSL won't be initialized. :param addr: A remove address :return: What the socket's connect_ex method returns )rþÚ connect_exÚset_connect_state)r‘r[r\rŠrŠr‹r\<s zConnection.connect_excCs*|j ¡\}}t|j|ƒ}| ¡||fS)a‹ Call the :meth:`accept` method of the underlying socket and set up SSL on the returned socket, using the Context object supplied to this :class:`Connection` object at creation. :return: A *(conn, addr)* pair where *conn* is the new :class:`Connection` object created, and *address* is as returned by the socket's :meth:`accept`. )rþÚacceptrzr Úset_accept_state)r‘Úclientr[rÊrŠrŠr‹r^Js  zConnection.acceptc Cs‚t ¡}zt |j|¡}Wt |¡n t |¡0|jdurF|j ¡|jdurZ|j ¡|dkrhtƒ‚|dkr~|  |j|¡dS)z• Call the OpenSSL function DTLSv1_listen on this connection. See the OpenSSL manual for more details. :return: None Nr) r™Ú BIO_ADDR_newÚ DTLSv1_listenrûÚ BIO_ADDR_freerr•rrqr)r‘Úbio_addrr¯rŠrŠr‹rbYs    zConnection.DTLSv1_listencCs$|jdurtdƒ‚t |jd¡dS)zÕ If the Connection was created with a memory BIO, this method can be used to indicate that *end of file* has been reached on the read end of that memory BIO. :return: None NrKr)rr¾r™ÚBIO_set_mem_eof_returnrrrŠrŠr‹Ú bio_shutdownss zConnection.bio_shutdowncCs8t |j¡}|dkr$| |j|¡n|dkr0dSdSdS)aQ Send the shutdown message to the Connection. :return: True if the shutdown completed successfully (i.e. both sides have sent closure alerts), False otherwise (in which case you call :meth:`recv` or :meth:`send` when the connection becomes readable/writeable). rTFN)r™Ú SSL_shutdownrûrrTrŠrŠr‹Úshutdown€s zConnection.shutdowncCsFg}tƒD]6}t |j|¡}|tjkr*qB| t |¡ d¡¡q |S)z€ Retrieve the list of ciphers used by the Connection object. :return: A list of native cipher strings. úutf-8) rr™ÚSSL_get_cipher_listrûrµrÓr£rôr9)r‘ÚciphersÚir¯rŠrŠr‹rŸ‘s  zConnection.get_cipher_listcCs~t |j¡}|tjkrgSg}tt |¡ƒD]L}t ||¡}t |¡}t |tjkƒt   t ¡}t  |tj ¡|_| |¡q,|S)aØ Get CAs whose certificates are suggested for client authentication. :return: If this is a server connection, the list of certificate authorities that will be sent or has been sent to the client, as controlled by this :class:`Connection`'s :class:`Context`. If this is a client connection, the list will be empty until the connection with the server is established. .. versionadded:: 0.10 )r™ÚSSL_get_client_CA_listrûrµrÓÚrangeÚsk_X509_NAME_numÚsk_X509_NAME_valuer£rrrÃrr¦r¤r£)r‘Úca_namesr¯rlr rbÚpynamerŠrŠr‹Úget_client_ca_listŸs      zConnection.get_client_ca_listcOs tdƒ‚dS)zœ The makefile() method is not implemented, since there is no dup semantics for SSL connections :raise: NotImplementedError z1Cannot make file object of OpenSSL.SSL.ConnectionNr÷©r‘rùrúrŠrŠr‹Úmakefile¼sÿzConnection.makefilecCs|jS)zr Retrieve application data as set by :meth:`set_app_data`. :return: The application data r¾rrŠrŠr‹r¿ÇszConnection.get_app_datacCs ||_dS)zg Set application data :param data: The application data :return: None Nr¾rÀrŠrŠr‹rÁÏszConnection.set_app_datacCs t |j¡S)zž Get the shutdown state of the Connection. :return: The shutdown state, a bitvector of SENT_SHUTDOWN, RECEIVED_SHUTDOWN. )r™ÚSSL_get_shutdownrûrrŠrŠr‹Ú get_shutdownØszConnection.get_shutdowncCs$t|tƒstdƒ‚t |j|¡dS)z— Set the shutdown state of the Connection. :param state: bitvector of SENT_SHUTDOWN, RECEIVED_SHUTDOWN. :return: None zstate must be an integerN)r¼rár¾r™ÚSSL_set_shutdownrû)r‘ÚstaterŠrŠr‹Ú set_shutdownás zConnection.set_shutdowncCst t |j¡¡S)zš Retrieve a verbose string detailing the state of the Connection. :return: A string representing the state :rtype: bytes )rµrôr™ÚSSL_state_string_longrûrrŠrŠr‹Úget_state_stringíszConnection.get_state_stringcCsft |j¡}|tjkrdSt |jtjd¡}t|dkƒtd|ƒ}t |j||¡t ||¡dd…S)z Retrieve the random value used with the server hello message. :return: A string representing the state Nrrº) r™ÚSSL_get_sessionrûrµrÓÚSSL_get_server_randomrr=r»©r‘ÚsessionÚlengthÚoutprŠrŠr‹Ú server_randomös    zConnection.server_randomcCsft |j¡}|tjkrdSt |jtjd¡}t|dkƒtd|ƒ}t |j||¡t ||¡dd…S)z Retrieve the random value used with the client hello message. :return: A string representing the state Nrrº) r™r}rûrµrÓÚSSL_get_client_randomrr=r»rrŠrŠr‹Ú client_random s    zConnection.client_randomcCsbt |j¡}|tjkrdSt |tjd¡}t|dkƒtd|ƒ}t |||¡t ||¡dd…S)zz Retrieve the value of the master key for this session. :return: A string representing the state Nrrº) r™r}rûrµrÓÚSSL_SESSION_get_master_keyrr=r»rrŠrŠr‹Ú master_key s    zConnection.master_keyc Csntd|ƒ}tj}d}d}|dur0|}t|ƒ}d}t |j|||t|ƒ|||¡}t|dkƒt ||¡dd…S)aH Obtain keying material for application use. :param: label - a disambiguating label string as described in RFC 5705 :param: olen - the length of the exported key material in bytes :param: context - a per-association context value :return: the exported key material bytes or None rºrNr˜) r=rµrÓrÀr™ÚSSL_export_keying_materialrûrr») r‘ÚlabelÚolenr"r‚Ú context_bufÚ context_lenÚ use_contextÚsuccessrŠrŠr‹Úexport_keying_material% s( ø z!Connection.export_keying_materialcOs|jj|i|¤ŽS)z® Call the :meth:`shutdown` method of the underlying socket. See :manpage:`shutdown(2)`. :return: What the socket's shutdown() method returns )rþrhrtrŠrŠr‹Ú sock_shutdownC szConnection.sock_shutdowncCs.t |j¡}|tjkr*t |¡t |¡SdS)za Retrieve the local certificate (if any) :return: The local certificate N)r™ÚSSL_get_certificaterûrµrÓr›rrœ©r‘r©rŠrŠr‹Úget_certificateL s     zConnection.get_certificatecCs$t |j¡}|tjkr t |¡SdS)zi Retrieve the other side's certificate (if any) :return: The peer's certificate N)r™ÚSSL_get_peer_certificaterûrµrÓrrœr’rŠrŠr‹Úget_peer_certificateX s   zConnection.get_peer_certificatecCs`g}tt |¡ƒD]H}t ||¡}t|tjkƒt |¡}t|dkƒt  |¡}|  |¡q|S)zb Internal helper to convert a STACK_OF(X509) to a list of X509 instances. r˜) rnr™Ú sk_X509_numÚ sk_X509_valuerrµrÓr›rrœr£)Ú cert_stackr¯rlr©r”ÚpycertrŠrŠr‹Ú_cert_stack_to_listc s     zConnection._cert_stack_to_listcCs$t |j¡}|tjkrdS| |¡S)z Retrieve the other side's certificate (if any) :return: A list of X509 instances giving the peer's certificate chain, or None if it does not have one. N)r™ÚSSL_get_peer_cert_chainrûrµrÓrš©r‘r˜rŠrŠr‹Úget_peer_cert_chains s  zConnection.get_peer_cert_chaincCs$t |j¡}|tjkrdS| |¡S)aÑ Retrieve the verified certificate chain of the peer including the peer's end entity certificate. It must be called after a session has been successfully established. If peer verification was not successful the chain may be incomplete, invalid, or None. :return: A list of X509 instances giving the peer's verified certificate chain, or None if it does not have one. .. versionadded:: 20.0 N)r™ÚSSL_get0_verified_chainrûrµrÓršrœrŠrŠr‹Úget_verified_chain€ s  zConnection.get_verified_chaincCs t |j¡S)z£ Checks if more data has to be read from the transport layer to complete an operation. :return: True iff more data has to be read )r™Ú SSL_want_readrûrrŠrŠr‹Ú want_read“ szConnection.want_readcCs t |j¡S)z Checks if there is data to write to the transport layer to complete an operation. :return: True iff there is data to write )r™ÚSSL_want_writerûrrŠrŠr‹Ú want_writeœ szConnection.want_writecCst |j¡dS)z– Set the connection to work in server mode. The handshake will be handled automatically by read/write. :return: None N)r™ÚSSL_set_accept_staterûrrŠrŠr‹r_¥ szConnection.set_accept_statecCst |j¡dS)z– Set the connection to work in client mode. The handshake will be handled automatically by read/write. :return: None N)r™rYrûrrŠrŠr‹r]® szConnection.set_connect_statecCs8t |j¡}|tjkrdSt t¡}t |tj¡|_ |S)zÄ Returns the Session currently used. :return: An instance of :class:`OpenSSL.SSL.Session` or :obj:`None` if no session exists. .. versionadded:: 0.14 N) r™ÚSSL_get1_sessionrûrµrÓrxrÃrÚSSL_SESSION_freeÚ_session)r‘r€Ú pysessionrŠrŠr‹Ú get_session· s   zConnection.get_sessioncCs2t|tƒstdƒ‚t |j|j¡}t|dkƒdS)zÜ Set the session to be used when the TLS/SSL connection is established. :param session: A Session instance representing the session to use. :returns: None .. versionadded:: 0.14 z"session must be a Session instancer˜N)r¼rxr¾r™ÚSSL_set_sessionrûr§r)r‘r€r¯rŠrŠr‹Ú set_sessionÈ s zConnection.set_sessioncCsRt dd¡}||j|dƒ}|dkr&dStd|ƒ}||j||ƒt ||¡dd…S)a‚ Helper to implement :meth:`get_finished` and :meth:`get_peer_finished`. :param function: Either :data:`SSL_get_finished`: or :data:`SSL_get_peer_finished`. :return: :data:`None` if the desired message has not yet been received, otherwise the contents of the message. :rtype: :class:`bytes` or :class:`NoneType` r<rN)rµr¿rûr=r»)r‘ÚfunctionÚemptyr,rwrŠrŠr‹Ú_get_finished_message× s  z Connection._get_finished_messagecCs | tj¡S)a Obtain the latest TLS Finished message that we sent. :return: The contents of the message or :obj:`None` if the TLS handshake has not yet completed. :rtype: :class:`bytes` or :class:`NoneType` .. versionadded:: 0.15 )r®r™ÚSSL_get_finishedrrŠrŠr‹Ú get_finishedù s zConnection.get_finishedcCs | tj¡S)a! Obtain the latest TLS Finished message that we received from the peer. :return: The contents of the message or :obj:`None` if the TLS handshake has not yet completed. :rtype: :class:`bytes` or :class:`NoneType` .. versionadded:: 0.15 )r®r™ÚSSL_get_peer_finishedrrŠrŠr‹Úget_peer_finished s zConnection.get_peer_finishedcCs8t |j¡}|tjkrdSt t |¡¡}| d¡SdS)a Obtain the name of the currently used cipher. :returns: The name of the currently used cipher or :obj:`None` if no connection has been established. :rtype: :class:`unicode` or :class:`NoneType` .. versionadded:: 0.15 Nri)r™ÚSSL_get_current_cipherrûrµrÓrôÚSSL_CIPHER_get_namer9)r‘Úcipherr rŠrŠr‹Úget_cipher_name s  zConnection.get_cipher_namecCs,t |j¡}|tjkrdSt |tj¡SdS)a. Obtain the number of secret bits of the currently used cipher. :returns: The number of secret bits of the currently used cipher or :obj:`None` if no connection has been established. :rtype: :class:`int` or :class:`NoneType` .. versionadded:: 0.15 N)r™r³rûrµrÓÚSSL_CIPHER_get_bits)r‘rµrŠrŠr‹Úget_cipher_bits" s  zConnection.get_cipher_bitscCs8t |j¡}|tjkrdSt t |¡¡}| d¡SdS)a% Obtain the protocol version of the currently used cipher. :returns: The protocol name of the currently used cipher or :obj:`None` if no connection has been established. :rtype: :class:`unicode` or :class:`NoneType` .. versionadded:: 0.15 Nri)r™r³rûrµrÓrôÚSSL_CIPHER_get_versionr9)r‘rµr rŠrŠr‹Úget_cipher_version2 s  zConnection.get_cipher_versioncCst t |j¡¡}| d¡S)a> Retrieve the protocol version of the current connection. :returns: The TLS version of the current connection, for example the value for TLS 1.2 would be ``TLSv1.2``or ``Unknown`` for connections that were not successfully established. :rtype: :class:`unicode` ri)rµrôr™ÚSSL_get_versionrûr9r$rŠrŠr‹Úget_protocol_version_nameC s z$Connection.get_protocol_version_namecCst |j¡}|S)a  Retrieve the SSL or TLS protocol version of the current connection. :returns: The TLS version of the current connection. For example, it will return ``0x769`` for connections made over TLS version 1. :rtype: :class:`int` )r™Ú SSL_versionrûr$rŠrŠr‹Úget_protocol_versionO s zConnection.get_protocol_versioncCsR|s tdƒ‚d t dd„|Dƒ¡¡}t d|¡}tt |j |t |ƒ¡dkƒdS)ah Specify the client's ALPN protocol list. These protocols are offered to the server during protocol negotiation. :param protos: A list of the protocols to be offered to the server. This list should be a Python list of bytestrings representing the protocols to offer, e.g. ``[b'http/1.1', b'spdy/2']``. rÒr¹css |]}tt|ƒfƒ|fVqdSrŽrÓrÔrŠrŠr‹r×n r¹z-Connection.set_alpn_protos..rºrN) rïrØrrÙrµr¿rr™ÚSSL_set_alpn_protosrûrÀrÛrŠrŠr‹rßZ sÿ ÿzConnection.set_alpn_protoscCsHt d¡}t d¡}t |j||¡|s,dSt |d|d¡dd…S)zÇ Get the protocol that was negotiated by ALPN. :returns: A bytestring of the protocol name. If no protocol has been negotiated yet, returns an empty bytestring. rÞzunsigned int *r¹rN)rµr¿r™ÚSSL_get0_alpn_selectedrûr»)r‘rØÚdata_lenrŠrŠr‹Úget_alpn_proto_negotiated} s   z$Connection.get_alpn_proto_negotiatedcCs t |jtj¡}t|dkƒdS)a Called to request that the server sends stapled OCSP data, if available. If this is not called on the client side then the server will not send OCSP data. Should be used in conjunction with :meth:`Context.set_ocsp_client_callback`. r˜N)r™ÚSSL_set_tlsext_status_typerûÚTLSEXT_STATUSTYPE_ocspr)r‘rçrŠrŠr‹Ú request_ocsp sÿzConnection.request_ocsp)N)N)r)r)N)NN)N)Kr†r‡rˆrr¡r’r rrr r#rƒrˆr]ror*r-r0r2r7Úwriter;rBÚreadrErJrMrOrRrUrPrXrZr\r^rbrfrhrŸrsrur¿rÁrwrzr|rƒr…r‡rrr“r•Ú staticmethodršrrŸr¡r£r_r]r©r«r®r°r²r¶r¸rºr¼r¾r÷rßrÂrÅrŠrŠrŠr‹rz>s : 7       %                     "     " rz)ÑrIrrrÚ functoolsrrÚ itertoolsrrÚsysrÚweakrefrÚ OpenSSL._utilr rfr Ú_exception_from_error_queuer rµr r™r Ú _make_assertrr=rr&rrsÚOpenSSL.cryptorrrrrrÚ__all__rrrrrrrr rr!rÚSSL_SENT_SHUTDOWNr"ÚSSL_RECEIVED_SHUTDOWNr#r$r%r&r'r(r)r*r+r,r-r.r/r0r1r2rÚSSL_OP_NO_SSLv2r3ÚSSL_OP_NO_SSLv3r4ÚSSL_OP_NO_TLSv1r5ÚSSL_OP_NO_TLSv1_1r6ÚSSL_OP_NO_TLSv1_2r7ÚSSL_OP_NO_TLSv1_3r8ÚSSL_MODE_RELEASE_BUFFERSr9ÚSSL_OP_SINGLE_DH_USEr:ÚSSL_OP_SINGLE_ECDH_USEr;ÚSSL_OP_EPHEMERAL_RSAr<ÚSSL_OP_MICROSOFT_SESS_ID_BUGr=ÚSSL_OP_NETSCAPE_CHALLENGE_BUGr>Ú'SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUGr?Ú"SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUGr@Ú!SSL_OP_MICROSOFT_BIG_SSLV3_BUFFERrAÚSSL_OP_MSIE_SSLV2_RSA_PADDINGrBÚSSL_OP_SSLEAY_080_CLIENT_DH_BUGrCÚSSL_OP_TLS_D5_BUGrDÚSSL_OP_TLS_BLOCK_PADDING_BUGrEÚ"SSL_OP_DONT_INSERT_EMPTY_FRAGMENTSrFÚSSL_OP_CIPHER_SERVER_PREFERENCErGÚSSL_OP_TLS_ROLLBACK_BUGrHÚSSL_OP_PKCS1_CHECK_1rIÚSSL_OP_PKCS1_CHECK_2rJÚSSL_OP_NETSCAPE_CA_DN_BUGrKÚ&SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUGrLÚSSL_OP_NO_COMPRESSIONrMÚSSL_OP_NO_QUERY_MTUrNÚSSL_OP_COOKIE_EXCHANGErOÚSSL_OP_NO_TICKETrPÚSSL_OP_NO_RENEGOTIATIONrQÚSSL_OP_IGNORE_UNEXPECTED_EOFrRÚ SSL_OP_ALLrSÚSSL_VERIFY_PEERrTÚSSL_VERIFY_FAIL_IF_NO_PEER_CERTrUÚSSL_VERIFY_CLIENT_ONCErVÚSSL_VERIFY_NONErWÚSSL_SESS_CACHE_OFFrXÚSSL_SESS_CACHE_CLIENTrYÚSSL_SESS_CACHE_SERVERrZÚSSL_SESS_CACHE_BOTHr[ÚSSL_SESS_CACHE_NO_AUTO_CLEARr\Ú!SSL_SESS_CACHE_NO_INTERNAL_LOOKUPr]Ú SSL_SESS_CACHE_NO_INTERNAL_STOREr^ÚSSL_SESS_CACHE_NO_INTERNALr_r`rarbrcrdrerfrgrhrirjrkrlrmrnrorArBr>r?r¢rpr“rrqrrrsrtrurr–Úobjectrvr¸rÑrÝrærérórõrwrÚCryptography_HAS_ALPNr÷rîrörxryrzrŠrŠrŠr‹Ús0   ( h        ÿÿ   ÿ (=C; ÿ ÿ