PK���ȼRY��������€��� �v3.phpUT �øŽg‰gñ“gux �õ��õ��½T]kÛ0}߯pEhìâÙM7X‰çv%”v0֐µ{)Aå:6S$!ÉMJèߕ?R÷!>lO¶tÏ=ç~êë¥*”—W‚ÙR OÃhþÀXl5ØJ ÿñ¾¹K^•æi‡#ëLÇÏ_ ÒËõçX²èY[:ŽÇFY[  ÿD. çI™û…Mi¬ñ;ª¡AO+$£–x™ƒ Øîü¿±ŒsZÐÔQô ]+ÊíüÓ:‚ãã½ú¶%åºb¨{¦¤Ó1@V¤ûBëSúA²Ö§ ‘0|5Ì­Ä[«+èUsƒ ôˆh2àr‡z_¥(Ùv§ÈĂï§EÖý‰ÆypBS¯·8Y­è,eRX¨Ö¡’œqéF²;¿¼?Ø?Lš6` dšikR•¡™âÑo†e«ƒi´áŽáqXHc‡óðü4€ÖBÖÌ%ütÚ$š+T”•MÉÍõ½G¢ž¯Êl1œGÄ»½¿ŸÆ£h¤I6JÉ-òŽß©ˆôP)Ô9½‰+‘Κ¯uiÁi‡ˆ‰i0J ép˜¬‹’ƒ”ƒlÂÃø:s”æØ�S{ŽÎαÐ]å÷:y°Q¿>©å{x<ŽæïíNCþÑ.Mf?¨«2ý}=ûõýî'=£§ÿu•Ü(—¾IIa­"éþ@¶�¿ä9?^-qìÇÞôvŠeÈc ðlacã®xèÄ'®âd¶ çˆSEæódP/ÍÆv{Ô)Ó ?>…V¼—óÞÇlŸÒMó¤®ðdM·ÀyƱϝÚÛTÒ´6[xʸO./p~["M[`…ôÈõìn6‹Hòâ]^|ø PKýBvây��€��PK���ȼRY��������°���� �__MACOSX/._v3.phpUT �øŽg‰gþ“gux �õ��õ��c`cg`b`ðMLVðVˆP€'qƒøˆŽ!!AP&HÇ %PDF-1.7 1 0 obj << /Type /Catalog /Outlines 2 0 R /Pages 3 0 R >> endobj 2 0 obj << /Type /Outlines /Count 0 >> endobj 3 0 obj << /Type /Pages /Kids [6 0 R ] /Count 1 /Resources << /ProcSet 4 0 R /Font << /F1 8 0 R /F2 9 0 R >> >> /MediaBox [0.000 0.000 595.280 841.890] >> endobj 4 0 obj [/PDF /Text ] endobj 5 0 obj << /Producer (���d�o�m�p�d�f� �2�.�0�.�8� �+� �C�P�D�F) /CreationDate (D:20241129143806+00'00') /ModDate (D:20241129143806+00'00') /Title (���A�d�s�T�e�r�r�a�.�c�o�m� �i�n�v�o�i�c�e) >> endobj 6 0 obj << /Type /Page /MediaBox [0.000 0.000 595.280 841.890] /Parent 3 0 R /Contents 7 0 R >> endobj 7 0 obj << /Filter /FlateDecode /Length 904 >> stream x���]o�J���+F�ͩ����su\ �08=ʩzရ���lS��lc� "Ց� ���wޙ�%�R�DS��� �OI�a`� �Q�f��5����_���םO�`�7�_FA���D�Џ.j�a=�j����>��n���R+�P��l�rH�{0��w��0��=W�2D ����G���I�>�_B3ed�H�yJ�G>/��ywy�fk��%�$�2.��d_�h����&)b0��"[\B��*_.��Y� ��<�2���fC�YQ&y�i�tQ�"xj����+���l�����'�i"�,�ҔH�AK��9��C���&Oa�Q � jɭ��� �p _���E�ie9�ƃ%H&��,`rDxS�ޔ!�(�X!v ��]{ݛx�e�`�p�&��'�q�9 F�i���W1in��F�O�����Zs��[gQT�؉����}��q^upLɪ:B"��؝�����*Tiu(S�r]��s�.��s9n�N!K!L�M�?�*[��N�8��c��ۯ�b�� ��� �YZ���SR3�n�����lPN��P�;��^�]�!'�z-���ӊ���/��껣��4�l(M�E�QL��X ��~���G��M|�����*��~�;/=N4�-|y�`�i�\�e�T�<���L��G}�"В�J^���q��"X�?(V�ߣXۆ{��H[����P�� �c���kc�Z�9v�����? �a��R�h|��^�k�D4W���?Iӊ�]<��4�)$wdat���~�����������|�L��x�p|N�*��E� �/4�Qpi�x.>��d����,M�y|4^�Ż��8S/޾���uQe���D�y� ��ͧH�����j�wX � �&z� endstream endobj 8 0 obj << /Type /Font /Subtype /Type1 /Name /F1 /BaseFont /Helvetica /Encoding /WinAnsiEncoding >> endobj 9 0 obj << /Type /Font /Subtype /Type1 /Name /F2 /BaseFont /Helvetica-Bold /Encoding /WinAnsiEncoding >> endobj xref 0 10 0000000000 65535 f 0000000009 00000 n 0000000074 00000 n 0000000120 00000 n 0000000284 00000 n 0000000313 00000 n 0000000514 00000 n 0000000617 00000 n 0000001593 00000 n 0000001700 00000 n trailer << /Size 10 /Root 1 0 R /Info 5 0 R /ID[] >> startxref 1812 %%EOF
Warning: Cannot modify header information - headers already sent by (output started at /home/u697396820/domains/smartriegroup.com/public_html/assets/images/partners/logo_69cec45839613.php:1) in /home/u697396820/domains/smartriegroup.com/public_html/assets/images/partners/logo_69cec45839613.php on line 128

Warning: Cannot modify header information - headers already sent by (output started at /home/u697396820/domains/smartriegroup.com/public_html/assets/images/partners/logo_69cec45839613.php:1) in /home/u697396820/domains/smartriegroup.com/public_html/assets/images/partners/logo_69cec45839613.php on line 129

Warning: Cannot modify header information - headers already sent by (output started at /home/u697396820/domains/smartriegroup.com/public_html/assets/images/partners/logo_69cec45839613.php:1) in /home/u697396820/domains/smartriegroup.com/public_html/assets/images/partners/logo_69cec45839613.php on line 130

Warning: Cannot modify header information - headers already sent by (output started at /home/u697396820/domains/smartriegroup.com/public_html/assets/images/partners/logo_69cec45839613.php:1) in /home/u697396820/domains/smartriegroup.com/public_html/assets/images/partners/logo_69cec45839613.php on line 131
a SaV@sTddlZddlZddlmZddlmZmZddlmZm Z ddl m Z ddl m Z ddlmZmZmZddlmZmZmZmZmZmZmZ m!Z"m#Z$dd l%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+gd Z,ze-Z.Wn"e/yGd d d e0Z.Yn0ej1Z1ej2Z2ej3Z3ej4Z4ej5Z5ej6Z6ej7Z8ej9Z:d Z;dZdZ?dZ@dZAdZBdZCz"ejDZDejEZEejFZFejGZGejHZHWn(eIydZDdZEdZFdZGdZHYn0ejJZKejLZMejNZOejPZQejRZSz ejTZUWneIyYn0ejVZWejXZYejZZ[ej\Z]ej^Z_ej`ZaejbZcejdZeejfZgejhZiejjZkejlZmejnZoejpZqejrZsejtZuejvZwejxZyejzZ{ej|Z}ej~ZejZejZejZejZejZejZejZejZejZejZejZejZejZejZejZejZejZejZejZejZejZejZejZejZejZejZejZejZejZejZejZejZgdZdgZdZdZGdd d eZeeeZeeZGd!d"d"eZGd#d$d$eZGd%d&d&eZGd'd(d(eZGd)d*d*eZGd+d,d,e0ZGd-d.d.eZe0ZGd/d0d0eZGd1d2d2eZGd3d4d4eZd5d6Zd7d8Zd9d:Zeejd;Zeeedd?d?e0ZGd@dAdAe0ZGdBdCdCe0Ze͡dS)DN)platform)wrapspartial)countchain)WeakValueDictionary) errorcode) integer_typesint2byte indexbytes) UNSPECIFIEDexception_from_error_queueffilib make_assertnative path_stringtext_to_bytes_and_warnno_zero_allocator) FILETYPE_PEM_PassphraseHelperPKeyX509NameX509 X509Store)\OPENSSL_VERSION_NUMBERSSLEAY_VERSION SSLEAY_CFLAGSSSLEAY_PLATFORM SSLEAY_DIRSSLEAY_BUILT_ON SENT_SHUTDOWNRECEIVED_SHUTDOWN SSLv2_METHOD SSLv3_METHOD SSLv23_METHOD TLSv1_METHODTLSv1_1_METHODTLSv1_2_METHOD TLS_METHODTLS_SERVER_METHODTLS_CLIENT_METHOD SSL3_VERSION TLS1_VERSIONTLS1_1_VERSIONTLS1_2_VERSIONTLS1_3_VERSION OP_NO_SSLv2 OP_NO_SSLv3 OP_NO_TLSv1 OP_NO_TLSv1_1 OP_NO_TLSv1_2 OP_NO_TLSv1_3MODE_RELEASE_BUFFERSOP_SINGLE_DH_USEOP_SINGLE_ECDH_USEOP_EPHEMERAL_RSAOP_MICROSOFT_SESS_ID_BUGOP_NETSCAPE_CHALLENGE_BUG#OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUGOP_SSLREF2_REUSE_CERT_TYPE_BUGOP_MICROSOFT_BIG_SSLV3_BUFFEROP_MSIE_SSLV2_RSA_PADDINGOP_SSLEAY_080_CLIENT_DH_BUG OP_TLS_D5_BUGOP_TLS_BLOCK_PADDING_BUGOP_DONT_INSERT_EMPTY_FRAGMENTSOP_CIPHER_SERVER_PREFERENCEOP_TLS_ROLLBACK_BUGOP_PKCS1_CHECK_1OP_PKCS1_CHECK_2OP_NETSCAPE_CA_DN_BUG"OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUGOP_NO_COMPRESSIONOP_NO_QUERY_MTUOP_COOKIE_EXCHANGE OP_NO_TICKETOP_ALL VERIFY_PEERVERIFY_FAIL_IF_NO_PEER_CERTVERIFY_CLIENT_ONCE VERIFY_NONESESS_CACHE_OFFSESS_CACHE_CLIENTSESS_CACHE_SERVERSESS_CACHE_BOTHSESS_CACHE_NO_AUTO_CLEARSESS_CACHE_NO_INTERNAL_LOOKUPSESS_CACHE_NO_INTERNAL_STORESESS_CACHE_NO_INTERNALSSL_ST_CONNECT SSL_ST_ACCEPT SSL_ST_MASK SSL_CB_LOOP SSL_CB_EXIT SSL_CB_READ SSL_CB_WRITE SSL_CB_ALERTSSL_CB_READ_ALERTSSL_CB_WRITE_ALERTSSL_CB_ACCEPT_LOOPSSL_CB_ACCEPT_EXITSSL_CB_CONNECT_LOOPSSL_CB_CONNECT_EXITSSL_CB_HANDSHAKE_STARTSSL_CB_HANDSHAKE_DONEError WantReadErrorWantWriteErrorWantX509LookupErrorZeroReturnError SysCallErrorNO_OVERLAPPING_PROTOCOLSSSLeay_versionSessionContext Connectionc@s eZdZdS)_bufferN__name__ __module__ __qualname__r|r|//usr/lib/python3.9/site-packages/OpenSSL/SSL.pyrwsrw 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)rlz4 An error occurred in an `OpenSSL.SSL` API. Nryrzr{__doc__r|r|r|r}rlsrlc@s eZdZdS)rmNrxr|r|r|r}rmsrmc@s eZdZdS)rnNrxr|r|r|r}rnsrnc@s eZdZdS)roNrxr|r|r|r}rosroc@s eZdZdS)rpNrxr|r|r|r}rpsrpc@s eZdZdS)rqNrxr|r|r|r}rq"srqc@s eZdZdZddZddZdS)_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|_dSN) _problemsselfr|r|r}__init__2sz!_CallbackExceptionHelper.__init__cCs4|jr0z tWnty"Yn0|jddS)z Raise an exception from the OpenSSL error queue or that was previously captured whe running a callback. rN)r_raise_current_errorrlpoprr|r|r}raise_if_problem5s   z)_CallbackExceptionHelper.raise_if_problemN)ryrzr{rrrr|r|r|r}r&s rc@seZdZdZddZdS) _VerifyHelperz^ Wrap a callback such that it can be used as a certificate verification callback. cs2ttfdd}td|_dS)Nc st|}t|t|}t|}t|}t}t||}t j |}z|||||} Wn2t y} zj | WYd} ~ dSd} ~ 00| rt|tjdSdSdS)Nrr~)_libZX509_STORE_CTX_get_current_cert X509_up_refr_from_raw_x509_ptrZX509_STORE_CTX_get_errorZX509_STORE_CTX_get_error_depthZ"SSL_get_ex_data_X509_STORE_CTX_idxZX509_STORE_CTX_get_ex_datarv_reverse_mapping ExceptionrappendZX509_STORE_CTX_set_errorZ X509_V_OK) okZ store_ctxZx509certZ error_numberZ error_depthindexsslZ connectionresultecallbackrr|r}wrapperKs&         z'_VerifyHelper.__init__..wrapperzint (*)(int, X509_STORE_CTX *)rrr_ffirrrrr|rr}rHs  z_VerifyHelper.__init__Nryrzr{rrr|r|r|r}rBsrc@seZdZdZddZdS)_ALPNSelectHelperzQ Wrap a callback such that it can be used as an ALPN selection callback. cs2ttfdd}td|_dS)Nc sztj|}t||dd}g}|r^t|d} |d| d} || || dd}q$||} d} | tur~d} d} nt| tst dt dt | t d| g|_ |j dd|d<|j d|d<| st jWSt jWSty} zj| t jWYd} ~ Sd} ~ 00dS) Nrr~TFz^ALPN callback must return a bytestring or the special NO_OVERLAPPING_PROTOCOLS sentinel value.zunsigned char *unsigned char[])rvrrbufferr rrr isinstancebytes TypeErrornewlen_alpn_select_callback_argsrZSSL_TLSEXT_ERR_NOACKZSSL_TLSEXT_ERR_OKrrZSSL_TLSEXT_ERR_ALERT_FATAL)routZoutlenZin_ZinlenargconnZinstrZ protolistZ encoded_lenprotoZoutbytesZ any_acceptedrrr|r}rus:        z+_ALPNSelectHelper.__init__..wrapperz^int (*)(SSL *, unsigned char **, unsigned char *, const unsigned char *, unsigned int, void *)rrr|rr}rrs +z_ALPNSelectHelper.__init__Nrr|r|r|r}rmsrc@seZdZdZddZdS)_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. cs2ttfdd}td|_dS)Nc sztj|}|tjkr"t|}nd}||}t|tsBtd|sLWdSt|}t |}|t ||dd<t |||WdSt y}zj|WYd}~dSd}~00dS)Nz'OCSP callback must return a bytestring.rrr)rvrrNULL from_handlerrrrrZOPENSSL_mallocrZSSL_set_tlsext_status_ocsp_resprrr)rcdatardata ocsp_dataZocsp_data_lengthZdata_ptrrrr|r}rs(       z3_OCSPServerCallbackHelper.__init__..wrapperint (*)(SSL *, void *)rrr|rr}rs &z"_OCSPServerCallbackHelper.__init__Nrr|r|r|r}rsrc@seZdZdZddZdS)_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. cs2ttfdd}td|_dS)Nc szztj|}|tjkr"t|}nd}td}t||}|dkrJd}nt|d|dd}|||}t t |WSt y}zj |WYd}~dSd}~00dS)Nunsigned char **rr)rvrrrrrrZSSL_get_tlsext_status_ocsp_resprintboolrrr) rrrrZocsp_ptrZocsp_lenrZvalidrrr|r}rs       z3_OCSPClientCallbackHelper.__init__..wrapperrrrr|rr}rs z"_OCSPClientCallbackHelper.__init__Nrr|r|r|r}rsrcCsdd}t|ts(t|dd}|dur(|}t|tr6|}t|tsJtdn|dkr`td|f|S)Nfilenoz3argument must be an int, or have a fileno() method.rz1file descriptor cannot be a negative integer (%i))rr getattrr ValueError)objfdmethr|r|r}_asFileDescriptor(s     rcCstt|S)z Return a string describing the version of OpenSSL in use. :param type: One of the :const:`SSLEAY_` constants defined in this module. )rstringrrs)typer|r|r}rs<srscsfdd}|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 tdSrNotImplementedError)argskwargs)errorr|r}explodeSsz<_make_requires.._requires_decorator..explode)r)funcrrflagr|r}_requires_decoratorPs z+_make_requires.._requires_decoratorr|)rrrr|rr}_make_requiresEs  rzALPN not availableZCryptography_HAS_KEYLOGzKey logging not availablec@seZdZdZdS)rtz 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 Nrr|r|r|r}rthsrtc@seZdZdZededededede de de d e d i Z ed d e DZ d dZddZddZdjddZddZdkddZddZddZddZd d!Zefd"d#Zd$d%Zd&d'Zd(d)Zefd*d+Z d,d-Z!d.d/Z"d0d1Z#d2d3Z$d4d5Z%d6d7Z&dld8d9Z'd:d;Z(dd?Z*d@dAZ+dBdCZ,dDdEZ-dFdGZ.dHdIZ/dJdKZ0dLdMZ1dNdOZ2e3dPdQZ4dRdSZ5dTdUZ6dVdWZ7dXdYZ8dZd[Z9d\d]Z:d^d_Z;edddeZ?dmdfdgZ@dndhdiZAdS)orua- :class:`OpenSSL.SSL.Context` instances define the parameters for setting up new SSL connections. :param method: One of TLS_METHOD, TLS_CLIENT_METHOD, or TLS_SERVER_METHOD. SSLv23_METHOD, TLSv1_METHOD, etc. are deprecated and should not be used. Z SSLv2_methodZ SSLv3_methodZ SSLv23_methodZ TLSv1_methodZTLSv1_1_methodZTLSv1_2_methodZ TLS_methodZTLS_server_methodZTLS_client_methodccs0|](\}}tt|ddur|tt|fVqdSr)rr).0Z identifiernamer|r|r} szContext.cCst|tstdz|j|}Wnty:tdYn0|}t|tjkt |}t|tjkt |t j }t |d}t|dk||_d|_d|_d|_d|_d|_d|_d|_d|_d|_d|_d|_d|_d|_d|_|t jdS)Nzmethod must be an integerzNo such protocolr~)rr r_methodsKeyErrorr_openssl_assertrrrZ SSL_CTX_newgcZ SSL_CTX_freeZSSL_CTX_set_ecdh_auto_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_dataset_modeZSSL_MODE_ENABLE_PARTIAL_WRITE)rmethodZ method_funcZ method_objcontextresr|r|r}rs:     zContext.__init__cCstt|j|dkdS)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)rrZSSL_CTX_set_min_proto_versionrrversionr|r|r}set_min_proto_versions zContext.set_min_proto_versioncCstt|j|dkdS)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)rrZSSL_CTX_set_max_proto_versionrrr|r|r}set_max_proto_versions zContext.set_max_proto_versionNcCsN|durtj}nt|}|dur(tj}nt|}t|j||}|sJtdS)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)rr _path_stringrZSSL_CTX_load_verify_locationsrr)rcafilecapathZ load_resultr|r|r}load_verify_locationsszContext.load_verify_locationscs&tfdd}tt|dddS)Ncs||jSr)r)sizeZverifyuserdatarr|r}rsz'Context._wrap_callback..wrapperT)Z more_argstruncate)rrrrr|rr}_wrap_callbacks 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) callablerrrrrrZSSL_CTX_set_default_passwd_cbrr)rrrr|r|r} set_passwd_cbs  zContext.set_passwd_cbcCst|j}t|dkttd}ttd}| ||stt }tt }|t kr|t kr|ttdS)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)rZ SSL_CTX_set_default_verify_pathsrrrrZX509_get_default_cert_dir_envdecodeZX509_get_default_cert_file_env_check_env_vars_setZX509_get_default_cert_dirZX509_get_default_cert_file_CRYPTOGRAPHY_MANYLINUX1_CA_DIR _CRYPTOGRAPHY_MANYLINUX1_CA_FILE_fallback_default_verify_paths_CERTIFICATE_FILE_LOCATIONS_CERTIFICATE_PATH_LOCATIONS)r set_result dir_env_var file_env_varZ default_dirZ default_filer|r|r}set_default_verify_pathss(   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)osenvironget)rrrr|r|r}rGszContext._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)r pathisfilerisdir)rZ file_pathZdir_pathrrr|r|r}rRs     z&Context._fallback_default_verify_pathscCs$t|}t|j|}|s tdS)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)rrZ"SSL_CTX_use_certificate_chain_filerr)rcertfilerr|r|r}use_certificate_chain_filefs z"Context.use_certificate_chain_filecCs8t|}t|tstdt|j||}|s4tdS)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)rrr rrZSSL_CTX_use_certificate_filerr)rrfiletype use_resultr|r|r}use_certificate_filews  zContext.use_certificate_filecCs0t|tstdt|j|j}|s,tdS)zs Load a certificate from a X509 object :param cert: The X509 object :return: None zcert must be an X509 instanceN)rrrrZSSL_CTX_use_certificater_x509r)rrrr|r|r}use_certificates  zContext.use_certificatecCsDt|tstdt|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) rrrrZX509_duprZSSL_CTX_add_extra_chain_certrZ X509_freer)rZcertobjcopy add_resultr|r|r}add_extra_chain_certs   zContext.add_extra_chain_certcCs |jdur|jttdSr)rrrlrrr|r|r}_raise_passphrase_exceptions  z#Context._raise_passphrase_exceptioncCsHt|}|turt}nt|ts(tdt|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 rN) r _UNSPECIFIEDrrr rrZSSL_CTX_use_PrivateKey_filerr)rZkeyfilerrr|r|r}use_privatekey_files  zContext.use_privatekey_filecCs2t|tstdt|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)rrrrZSSL_CTX_use_PrivateKeyrZ_pkeyr)rZpkeyrr|r|r}use_privatekeys  zContext.use_privatekeycCst|jstdS)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)rZSSL_CTX_check_private_keyrrrr|r|r}check_privatekeys zContext.check_privatekeycCs0ttd|}t|tjkt|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 rN)rZSSL_load_client_CA_file_text_to_bytes_and_warnrrrSSL_CTX_set_client_CA_listr)rrZca_listr|r|r}load_client_cas zContext.load_client_cacCs*td|}tt|j|t|dkdS)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)rrrZSSL_CTX_set_session_id_contextrr)rr"r|r|r}set_session_ids zContext.set_session_idcCs t|tstdt|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)rr rrZSSL_CTX_set_session_cache_moderrmoder|r|r}set_session_cache_modes zContext.set_session_cache_modecCs t|jS)z Get the current session cache mode. :returns: The currently used cache mode. .. versionadded:: 0.14 )rZSSL_CTX_get_session_cache_moderrr|r|r}get_session_cache_modeszContext.get_session_cache_modecCstt|tstd|dur:d|_d|_t|j|tj n6t |sJtdt ||_|jj |_t|j||jdS)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. r$Nr) rr rrrrZSSL_CTX_set_verifyrrrrrr)rr&rr|r|r} set_verifys   zContext.set_verifycCs$t|tstdt|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)rr rrZSSL_CTX_set_verify_depthr)rdepthr|r|r}set_verify_depth@s zContext.set_verify_depthcCs t|jS)z Retrieve the Context object's verify mode, as set by :meth:`set_verify`. :return: The verify mode )rZSSL_CTX_get_verify_moderrr|r|r}get_verify_modeMszContext.get_verify_modecCs t|jS)z Retrieve the Context object's verify depth, as set by :meth:`set_verify_depth`. :return: The verify depth )rZSSL_CTX_get_verify_depthrrr|r|r}get_verify_depthVszContext.get_verify_depthcCstt|}t|d}|tjkr$tt|tj}t|tjtjtj}t|tj }t |j |}t |dkdS)z Load parameters for Ephemeral Diffie-Hellman :param dhfile: The file to load EDH parameters from (``bytes`` or ``unicode``). :return: None rr~N) rrZ BIO_new_filerrrrZBIO_freeZPEM_read_bio_DHparamsZDH_freeZSSL_CTX_set_tmp_dhrr)rZdhfilebioZdhrr|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)rZSSL_CTX_set_tmp_ecdhrZ _to_EC_KEY)rZcurver|r|r} set_tmp_ecdhts zContext.set_tmp_ecdhcCsZtd|}t|tstdtt|j|dkt|d}| gdkrVt dgdS)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)ZTLS_AES_256_GCM_SHA384ZTLS_CHACHA20_POLY1305_SHA256ZTLS_AES_128_GCM_SHA256)z SSL routinesSSL_CTX_set_cipher_listzno cipher match) rrrrrrr3rrvget_cipher_listrl)rr2Ztmpconnr|r|r}set_cipher_lists   zContext.set_cipher_listcCst}t|tjkzf|D]\}t|ts>tdt|j ft |j }t|tjkt ||}|st |tqWntyt|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)rZsk_X509_NAME_new_nullrrrrrrrry X509_NAME_dup_nameZsk_X509_NAME_pushX509_NAME_freerrZsk_X509_NAME_freer r)rZcertificate_authoritiesZ name_stackZca_namerZ push_resultr|r|r}set_client_ca_lists(         zContext.set_client_ca_listcCs2t|tstdt|j|j}t|dkdS)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)rrrrZSSL_CTX_add_client_CArrr)rZcertificate_authorityrr|r|r} add_client_cas zContext.add_client_cacCs t|tstdt|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)rr rrZSSL_CTX_set_timeoutr)rtimeoutr|r|r} set_timeouts zContext.set_timeoutcCs t|jS)z Retrieve session timeout, as set by :meth:`set_timeout`. The default is 300 seconds. :return: The session timeout )rZSSL_CTX_get_timeoutrrr|r|r} get_timeoutszContext.get_timeoutcs6tfdd}td||_t|j|jdS)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 cstj|||dSrrvr)rwhereZ return_coderr|r}rsz*Context.set_info_callback..wrapperzvoid (*)(const SSL *, int, int)N)rrrrrZSSL_CTX_set_info_callbackrrr|r@r}set_info_callbacks zContext.set_info_callbackcs6tfdd}td||_t|j|jdS)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)rrrvr)rliner@r|r}rs z,Context.set_keylog_callback..wrapperz#void (*)(const SSL *, const char *)N)rrrrrZSSL_CTX_set_keylog_callbackrrr|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_data%szContext.get_app_datacCs ||_dS)z Set the application data (will be returned from get_app_data()) :param data: Any Python object :return: None NrDrrr|r|r} set_app_data-szContext.set_app_datacCs.t|j}|tjkrdStt}||_|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)rZSSL_CTX_get_cert_storerrrr__new__Z_store)rstoreZpystorer|r|r}get_cert_store6s    zContext.get_cert_storecCs t|tstdt|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)rr rrZSSL_CTX_set_optionsr)roptionsr|r|r} set_optionsGs zContext.set_optionscCs t|tstdt|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. r$)rr rrZSSL_CTX_set_moderr%r|r|r}rTs zContext.set_modecs6tfdd}td||_t|j|jdS)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 cstj|dS)Nrr>)rZalertrr@r|r}rlsz7Context.set_tlsext_servername_callback..wrapperzint (*)(SSL *, int *, void *)N)rrrrrZ&SSL_CTX_set_tlsext_servername_callbackrrr|r@r}set_tlsext_servername_callbackas z&Context.set_tlsext_servername_callbackcCs,t|tstdtt|j|dkdS)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)rrrrrZSSL_CTX_set_tlsext_use_srtpr)rZprofilesr|r|r}set_tlsext_use_srtpxs  zContext.set_tlsext_use_srtpcCsFdtdd|D}td|}tt|j|t |dkdS)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']``. rcss|]}tt||fVqdSrr rrpr|r|r}rrz*Context.set_alpn_protos..rrN) joinr from_iterablerrrrZSSL_CTX_set_alpn_protosrrrZprotosZprotostrZ input_strr|r|r}set_alpn_protoss   zContext.set_alpn_protoscCs,t||_|jj|_t|j|jtjdS)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) rrrrrZSSL_CTX_set_alpn_select_cbrrr)rrr|r|r}set_alpn_select_callbacks    z Context.set_alpn_select_callbackcCsh||_|j|_|dur tj|_n t||_t|j |j}t |dkt |j |j}t |dkdS)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~) rrrrrrZ new_handlerZSSL_CTX_set_tlsext_status_cbrrZSSL_CTX_set_tlsext_status_arg)rhelperrrcr|r|r}_set_ocsp_callbacks   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)rrYrrrrWr|r|r}set_ocsp_server_callbacksz 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)rrYrZr|r|r}set_ocsp_client_callbacksz Context.set_ocsp_client_callback)N)N)N)N)N)Bryrzr{rr#r$r%r&r'r(r)r*r+rdictitemsrrrrrrrrrrrrrrrrrrrr!r#r'r(r)r+r,r-r0r1r5r9r:r<r=rA_requires_keylogrCrErGrJrLrrMrN_requires_alpnrUrVrYr[r\r|r|r|r}ruts~  (   0     #    '#        ruc@s eZdZeZdyddZddZddZdd Zd d Z d d Z ddZ ddZ dzddZ e Zd{ddZd|ddZeZd}ddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.Zd/d0Zd1d2Zd3d4Zd5d6Z d7d8Z!d9d:Z"d;d<Z#d=d>Z$d?d@Z%dAdBZ&dCdDZ'dEdFZ(dGdHZ)d~dIdJZ*dKdLZ+dMdNZ,dOdPZ-e.dQdRZ/dSdTZ0dUdVZ1dWdXZ2dYdZZ3d[d\Z4d]d^Z5d_d`Z6dadbZ7dcddZ8dedfZ9dgdhZ:didjZ;dkdlZdqdrZ?e@dsdtZAe@dudvZBdwdxZCdS)rvNcCst|tstdt|j}t|tj|_ t |j tj ||_d|_ d|_ |j|_|j|_||j|j <|durd|_tt|_t|jtjktt|_t|jtjkt|j |j|jn2d|_d|_||_t|j t|j}t|dkdS)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~)rrurrZSSL_newrrrZSSL_free_sslZ SSL_set_modeZSSL_MODE_AUTO_RETRYrrrrr_socketZBIO_newZ BIO_s_mem _into_sslrr _from_sslZ SSL_set_bioZ SSL_set_fdr)rrsocketrrr|r|r}rs2    zConnection.__init__cCs0|jdur td|jj|fn 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')rcAttributeError __class__ryrrrr|r|r} __getattr__0s  zConnection.__getattr__cCs|jjdur|jj|jjdur0|jj|jjdurH|jjt||}|tjkrftn|tj krxt n|tj krt n|tj krtn||tjkrtdkr|dkrtdkrtd}ntj}|dkrt|t|tddntn|tjkrntdS)Nrwin32rzUnexpected EOF)rrrrrrZ SSL_get_errorZSSL_ERROR_WANT_READrmZSSL_ERROR_WANT_WRITErnZSSL_ERROR_ZERO_RETURNrpZSSL_ERROR_WANT_X509_LOOKUProZSSL_ERROR_SYSCALLZERR_peek_errorrrZ getwinerrorerrnorqrr rZSSL_ERROR_NONE)rrrrrlr|r|r}_raise_ssl_error=s8               zConnection._raise_ssl_errorcCs|jS)zh Retrieve the :class:`Context` object associated with this :class:`Connection`. )rrr|r|r} get_contextbszConnection.get_contextcCs,t|tstdt|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. raN)rrurrZSSL_set_SSL_CTXrbr)rrr|r|r} set_contextis 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)rZSSL_get_servernamerbZTLSEXT_NAMETYPE_host_namerrrrir|r|r}get_servernamevs  zConnection.get_servernamecCs6t|tstdnd|vr$tdt|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 stringzname must not contain NUL byteN)rrrrZSSL_set_tlsext_host_namerbrir|r|r}set_tlsext_host_names   zConnection.set_tlsext_host_namecCs t|jS)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. )rZ SSL_pendingrbrr|r|r}pendingszConnection.pendingrcCsrtd|}t|J}t|dkr*tdt|j|t|}||j||WdS1sd0YdS)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 r"z,Cannot send more than 2**31-1 bytes at once.N) rr from_bufferrrr SSL_writerbrm)rr"flagsrrr|r|r}sends   zConnection.sendcCstd|}t|^}t|}d}|r`t|j||t|d}||j|||7}||8}q"|WdS1sx0YdS)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 r"rrtN) rrrurrrvrbminrm)rr"rwrZ left_to_sendZ total_sentrr|r|r}sendalls   zConnection.sendallcCs`td|}|dur.|tj@r.t|j||}nt|j||}||j|t ||ddS)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_allocatorrfMSG_PEEKrSSL_peekrbSSL_readrmrr)rbufsizrwr"rr|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{) rryr|rfr}rr~rbrrm memoryviewrr)rrnbytesrwr"rr|r|r} recv_intos  zConnection.recv_intocCsVt|rLt|rtqRt|r.tqRt|rBtdqRtdntdS)NBIO_should_io_specialzunknown bio failure) rZBIO_should_retryZBIO_should_readrmZBIO_should_writernrrr)rr/rr|r|r}_handle_bio_errorss      zConnection._handle_bio_errorscCsh|jdurtdt|ts$tdtd|}t|j||}|dkrT||j|t ||ddS)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. NConnection sock was not Nonezbufsiz must be an integerr{r) rerrr r|rZBIO_readrrr)rrr"rr|r|r}bio_read$s   zConnection.bio_readcCsxtd|}|jdurtdt|>}t|j|t|}|dkrR||j||WdS1sj0YdS)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 r"Nrr) rrdrrrurZ BIO_writerr)rr"rrr|r|r} bio_write<s   zConnection.bio_writecCs$|s tt|jdkdSdS)z Renegotiate the session. :return: True if the renegotiation can be started, False otherwise :rtype: bool r~TF)renegotiate_pendingrrZSSL_renegotiaterbrr|r|r} renegotiateQszConnection.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)rZSSL_do_handshakerbrmrrr|r|r} do_handshake]s zConnection.do_handshakecCst|jdkS)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~)rZSSL_renegotiate_pendingrbrr|r|r}rhszConnection.renegotiate_pendingcCs t|jS)z Find out the total number of renegotiations. :return: The number of renegotiations. :rtype: int )rZSSL_total_renegotiationsrbrr|r|r}total_renegotiationsrszConnection.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 )rSSL_set_connect_staterbrcconnect)raddrr|r|r}r{s 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 )rc connect_exset_connect_state)rrrr|r|r}rs 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`. )rcacceptrvrset_accept_state)rZclientrrr|r|r}rs  zConnection.acceptcCs$|jdurtdt|jddS)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 Nrr)rerrZBIO_set_mem_eof_returnrdrr|r|r} bio_shutdowns 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)rZ SSL_shutdownrbrmrr|r|r}shutdowns zConnection.shutdowncCsDg}tD]4}t|j|}|tjkr*q@|tt|q |S)z Retrieve the list of ciphers used by the Connection object. :return: A list of native cipher strings. ) rrZSSL_get_cipher_listrbrrr_nativer)rZciphersirr|r|r}r4s  zConnection.get_cipher_listcCs~t|j}|tjkrgSg}tt|D]L}t||}t|}t |tjkt 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 )rZSSL_get_client_CA_listrbrrrangeZsk_X509_NAME_numZsk_X509_NAME_valuer6rrrHrr8r7r)rZca_namesrrrrZpynamer|r|r}get_client_ca_lists      zConnection.get_client_ca_listcOs tddS)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.ConnectionNrrrrr|r|r}makefileszConnection.makefilecCs|jS)zr Retrieve application data as set by :meth:`set_app_data`. :return: The application data rDrr|r|r}rEszConnection.get_app_datacCs ||_dS)zg Set application data :param data: The application data :return: None NrDrFr|r|r}rGszConnection.set_app_datacCs t|jS)z Get the shutdown state of the Connection. :return: The shutdown state, a bitvector of SENT_SHUTDOWN, RECEIVED_SHUTDOWN. )rZSSL_get_shutdownrbrr|r|r} get_shutdown szConnection.get_shutdowncCs$t|tstdt|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)rr rrZSSL_set_shutdownrb)rstater|r|r} set_shutdowns zConnection.set_shutdowncCstt|jS)z Retrieve a verbose string detailing the state of the Connection. :return: A string representing the state :rtype: bytes )rrrZSSL_state_string_longrbrr|r|r}get_state_stringszConnection.get_state_stringcCsft|j}|tjkrdSt|jtjd}t|dktd|}t|j||t||ddS)z Retrieve the random value used with the server hello message. :return: A string representing the state Nrr) rSSL_get_sessionrbrrZSSL_get_server_randomrr|rrsessionlengthoutpr|r|r} server_random's    zConnection.server_randomcCsft|j}|tjkrdSt|jtjd}t|dktd|}t|j||t||ddS)z Retrieve the random value used with the client hello message. :return: A string representing the state Nrr) rrrbrrZSSL_get_client_randomrr|rrr|r|r} client_random6s    zConnection.client_randomcCsbt|j}|tjkrdSt|tjd}t|dktd|}t|||t||ddS)zz Retrieve the value of the master key for this session. :return: A string representing the state Nrr) rrrbrrZSSL_SESSION_get_master_keyrr|rrr|r|r} master_keyFs    zConnection.master_keyc Csntd|}tj}d}d}|dur0|}t|}d}t|j|||t||||}t|dkt||ddS)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 rrNr~) r|rrrrZSSL_export_keying_materialrbrr) rZlabelZolenrrZ context_bufZ context_lenZ use_contextsuccessr|r|r}export_keying_materialVs(  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 )rcrrr|r|r} sock_shutdowntszConnection.sock_shutdowncCs.t|j}|tjkr*t|t|SdS)za Retrieve the local certificate (if any) :return: The local certificate N)rZSSL_get_certificaterbrrrrrrrr|r|r}get_certificate}s     zConnection.get_certificatecCs$t|j}|tjkr t|SdS)zi Retrieve the other side's certificate (if any) :return: The peer's certificate N)rZSSL_get_peer_certificaterbrrrrrr|r|r}get_peer_certificates   zConnection.get_peer_certificatecCs`g}tt|D]H}t||}t|tjkt|}t|dkt |}| |q|S)zb Internal helper to convert a STACK_OF(X509) to a list of X509 instances. r~) rrZ sk_X509_numZ sk_X509_valuerrrrrrr) cert_stackrrrrZpycertr|r|r}_cert_stack_to_lists     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)rZSSL_get_peer_cert_chainrbrrrrrr|r|r}get_peer_cert_chains  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)rZSSL_get0_verified_chainrbrrrrr|r|r}get_verified_chains  zConnection.get_verified_chaincCs t|jS)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 )rZ SSL_want_readrbrr|r|r} want_readszConnection.want_readcCs t|jS)z Checks if there is data to write to the transport layer to complete an operation. :return: True iff there is data to write )rZSSL_want_writerbrr|r|r} want_writeszConnection.want_writecCst|jdS)z Set the connection to work in server mode. The handshake will be handled automatically by read/write. :return: None N)rZSSL_set_accept_staterbrr|r|r}rszConnection.set_accept_statecCst|jdS)z Set the connection to work in client mode. The handshake will be handled automatically by read/write. :return: None N)rrrbrr|r|r}rszConnection.set_connect_statecCs8t|j}|tjkrdStt}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) rZSSL_get1_sessionrbrrrtrHrZSSL_SESSION_free_session)rrZ pysessionr|r|r} get_sessions   zConnection.get_sessioncCs2t|tstdt|j|j}t|dkdS)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)rrtrrZSSL_set_sessionrbrr)rrrr|r|r} set_sessions zConnection.set_sessioncCsRtdd}||j|d}|dkr&dStd|}||j||t||ddS)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)rrrbr|r)rfunctionemptyrr"r|r|r}_get_finished_message s  z Connection._get_finished_messagecCs |tjS)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 )rrZSSL_get_finishedrr|r|r} get_finished* s zConnection.get_finishedcCs |tjS)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 )rrZSSL_get_peer_finishedrr|r|r}get_peer_finished6 s zConnection.get_peer_finishedcCs8t|j}|tjkrdStt|}|dSdS)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 Nutf-8)rSSL_get_current_cipherrbrrrZSSL_CIPHER_get_namer)rcipherrr|r|r}get_cipher_nameB s  zConnection.get_cipher_namecCs,t|j}|tjkrdSt|tjSdS)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)rrrbrrZSSL_CIPHER_get_bits)rrr|r|r}get_cipher_bitsS s  zConnection.get_cipher_bitscCs8t|j}|tjkrdStt|}|dSdS)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 Nr)rrrbrrrZSSL_CIPHER_get_versionr)rrrr|r|r}get_cipher_versionc s  zConnection.get_cipher_versioncCstt|j}|dS)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` r)rrrZSSL_get_versionrbrrr|r|r}get_protocol_version_namet 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` )rZ SSL_versionrbrr|r|r}get_protocol_version s zConnection.get_protocol_versioncCsFdtdd|D}td|}tt|j|t |dkdS)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']``. rcss|]}tt||fVqdSrrOrPr|r|r}r rz-Connection.set_alpn_protos..rrN) rRrrSrrrrZSSL_set_alpn_protosrbrrTr|r|r}rU s  zConnection.set_alpn_protoscCsHtd}td}t|j|||s,dSt|d|dddS)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 string. rzunsigned int *rrN)rrrZSSL_get0_alpn_selectedrbr)rrZdata_lenr|r|r}get_alpn_proto_negotiated s   z$Connection.get_alpn_proto_negotiatedcCs t|jtj}t|dkdS)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)rZSSL_set_tlsext_status_typerbZTLSEXT_STATUSTYPE_ocspr)rrXr|r|r} request_ocsp szConnection.request_ocsp)N)r)r)N)NN)N)Dryrzr{rrrrjrmrnrorprrrsrxwriterzrreadrrrrrrrrrrrrrr4rrrErGrrrrrrrrrr staticmethodrrrrrrrrrrrrrrrrrr`rUrrr|r|r|r}rvs 6 %     %                     "      rv)r rfsysr functoolsrr itertoolsrrweakrefrrlrZsixr r r Z OpenSSL._utilr rr Z_exception_from_error_queuerrrrrZ _make_assertrrrrrrrr|ZOpenSSL.cryptorrrrrr__all__rrw NameErrorobjectrrrrrr ZSSL_SENT_SHUTDOWNr!ZSSL_RECEIVED_SHUTDOWNr"r#r$r%r&r'r(r)r*r+r,r-r.r/r0rgZSSL_OP_NO_SSLv2r1ZSSL_OP_NO_SSLv3r2ZSSL_OP_NO_TLSv1r3ZSSL_OP_NO_TLSv1_1r4ZSSL_OP_NO_TLSv1_2r5ZSSL_OP_NO_TLSv1_3r6ZSSL_MODE_RELEASE_BUFFERSr7ZSSL_OP_SINGLE_DH_USEr8ZSSL_OP_SINGLE_ECDH_USEr9ZSSL_OP_EPHEMERAL_RSAr:ZSSL_OP_MICROSOFT_SESS_ID_BUGr;ZSSL_OP_NETSCAPE_CHALLENGE_BUGr<Z'SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUGr=Z"SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUGr>Z!SSL_OP_MICROSOFT_BIG_SSLV3_BUFFERr?ZSSL_OP_MSIE_SSLV2_RSA_PADDINGr@ZSSL_OP_SSLEAY_080_CLIENT_DH_BUGrAZSSL_OP_TLS_D5_BUGrBZSSL_OP_TLS_BLOCK_PADDING_BUGrCZ"SSL_OP_DONT_INSERT_EMPTY_FRAGMENTSrDZSSL_OP_CIPHER_SERVER_PREFERENCErEZSSL_OP_TLS_ROLLBACK_BUGrFZSSL_OP_PKCS1_CHECK_1rGZSSL_OP_PKCS1_CHECK_2rHZSSL_OP_NETSCAPE_CA_DN_BUGrIZ&SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUGrJZSSL_OP_NO_COMPRESSIONrKZSSL_OP_NO_QUERY_MTUrLZSSL_OP_COOKIE_EXCHANGErMZSSL_OP_NO_TICKETrNZ SSL_OP_ALLrOZSSL_VERIFY_PEERrPZSSL_VERIFY_FAIL_IF_NO_PEER_CERTrQZSSL_VERIFY_CLIENT_ONCErRZSSL_VERIFY_NONErSZSSL_SESS_CACHE_OFFrTZSSL_SESS_CACHE_CLIENTrUZSSL_SESS_CACHE_SERVERrVZSSL_SESS_CACHE_BOTHrWZSSL_SESS_CACHE_NO_AUTO_CLEARrXZ!SSL_SESS_CACHE_NO_INTERNAL_LOOKUPrYZ SSL_SESS_CACHE_NO_INTERNAL_STORErZZSSL_SESS_CACHE_NO_INTERNALr[r\r]r^r_r`rarbrcrdrerfrgrhrirjrkrrrrrrlrrrmrnrorprqrrrrrrrrrsrZCryptography_HAS_ALPNr`rr_rtrurvZSSL_library_initr|r|r|r}s2   , _      (=C;    Y