
    vKgs                   V   % S SK Jr  S SKrS SKrS SKrS SKrS SKJr  S SKJ	r	  S SK
JrJr  S SKJrJr  S SKJr  S SKJrJrJrJr  S S	KJr  S S
KJr  S SKJr  S SKJr  S SKJr   S SKJ!r"  S SKJ#r$  S SKJ%r&  S SKJ'r(  S SKJ)r*  S SKJ+r,  S SK-J.r.J/r/J0r0J1r1J2r2J3r3J4r4J5r5  / SQr6\$Rn                  r7S\8S'   \$Rr                  r9S\8S'   \$Rt                  r:S\8S'   \$Rv                  r;S\8S'   \$Rx                  r<S\8S'   \$Rz                  r=S\8S'   \9r>\:r?\;r@\<rA\=rB\$R                  rD\$R                  rFSrGSrHSrIS rJS!rKS"rLS#rMS$rNS%rOS&rP\$R                  rQS\8S''   \$R                  rRS\8S('   \$R                  rSS\8S)'   \$R                  rTS\8S*'   \$R                  rUS\8S+'   \$R                  rWS\8S,'   \$R                  rYS\8S-'   \$R                  r[S\8S.'   \$R                  r]S\8S/'   \$R                  r_S\8S0'   \$R                  raS\8S1'   \$R                  rcS\8S2'   \$R                  reS\8S3'   \$R                  rgS\8S4'   \$R                  riS\8S5'   \$R                  rkS\8S6'   \$R                  rmS\8S7'   \$R                  roS\8S8'   \$R                  rqS\8S9'   \$R                  rsS\8S:'   \$R                  ruS\8S;'   \$R                  rwS\8S<'   \$R                  ryS\8S='   \$R                  r{S\8S>'   \$R                  r}S\8S?'   \$R                  rS\8S@'   \$GR                   rS\8SA'   \$GR                  r\$GR                  rS\8SB'   \$GR                  rS\8SC'   \$GR                  rS\8SD'   \$GR                  rS\8SE'   \$GR                  rS\8SF'   \$GR                  rS\8SG'   \$GR                   rS\8SH'    \$GR$                  rS\8SI'   \6GR)                  SI5         \$GR,                  rS\8SJ'   \6GR)                  SJ5         \$GR0                  rS\8SK'   \6GR)                  SK5        \$GR4                  rS\8SL'   \$GR8                  rS\8SM'   \$GR<                  rS\8SN'   \$GR@                  rS\8SO'   \$GRD                  rS\8SP'   \$GRH                  rS\8SQ'   \$GRL                  rS\8SR'   \$GRP                  rS\8SS'   \$GRT                  rS\8ST'   \$GRX                  rS\8SU'   \$GR\                  rS\8SV'   \$GR`                  rS\8SW'   \$GRd                  rS\8SX'   \$GRh                  rS\8SY'   \$GRj                  rS\8SZ'   \$GRl                  rS\8S['   \$GRn                  rS\8S\'   \$GRp                  rS\8S]'   \$GRr                  rS\8S^'   \$GRt                  rS\8S_'   \$GRv                  rS\8S`'   \$GRx                  rS\8Sa'   \$GRz                  rS\8Sb'   \$GR|                  rS\8Sc'   \$GR~                  rS\8Sd'   \$GR                  rS\8Se'   \$GR                  rS\8Sf'   \$GR                  rS\8Sg'   \$GR                  rS\8Sh'   \" Si5      r " Sj Sk5      r\" 5       r\Sl\GR                  \GR                  \   \4   /S4   r\Sl/\4   r\Sl\/\4   r\Sl\\\   /\4   r\Sl\\   /\4   r\\\\\   /\4   r\Sl\/\\\/\4   r " Sm Sn5      r/ SoQrSp/rSqrSrr " Ss St\5      r\" \ \5      r\&" \5      r " Su Sv\5      r " Sw Sx\5      r " Sy Sz\5      r " S{ S|\5      r " S} S~\5      r " S S5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      rSS jrSS jr\rSS jr\" \" \$SS 5      S5      r " S S5      r " S S5      r " S Sl5      rg! \ a     GNf = f! \ a     GNf = f! \ a     GNf = f)    )annotationsN)Sequence)	errorcode)partialwraps)chaincount)platform)AnyCallableOptionalTypeVar)WeakValueDictionary)x509)ec)StrOrBytesPath)exception_from_error_queue)ffi)lib)make_assert)no_zero_allocator)
path_bytes)text_to_bytes_and_warn)FILETYPE_PEMX509PKeyX509Name	X509Store_EllipticCurve_PassphraseHelper_PrivateKey)cDTLS_CLIENT_METHODDTLS_METHODDTLS_SERVER_METHODMODE_RELEASE_BUFFERSNO_OVERLAPPING_PROTOCOLSOPENSSL_BUILT_ONOPENSSL_CFLAGSOPENSSL_DIROPENSSL_PLATFORMOPENSSL_VERSIONOPENSSL_VERSION_NUMBEROP_ALLOP_CIPHER_SERVER_PREFERENCEOP_COOKIE_EXCHANGEOP_DONT_INSERT_EMPTY_FRAGMENTSOP_EPHEMERAL_RSAOP_MICROSOFT_BIG_SSLV3_BUFFEROP_MICROSOFT_SESS_ID_BUGOP_MSIE_SSLV2_RSA_PADDINGOP_NETSCAPE_CA_DN_BUGOP_NETSCAPE_CHALLENGE_BUG"OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG#OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUGOP_NO_COMPRESSIONOP_NO_QUERY_MTUOP_NO_TICKETOP_PKCS1_CHECK_1OP_PKCS1_CHECK_2OP_SINGLE_DH_USEOP_SINGLE_ECDH_USEOP_SSLEAY_080_CLIENT_DH_BUGOP_SSLREF2_REUSE_CERT_TYPE_BUGOP_TLS_BLOCK_PADDING_BUGOP_TLS_D5_BUGOP_TLS_ROLLBACK_BUGRECEIVED_SHUTDOWNSENT_SHUTDOWNSESS_CACHE_BOTHSESS_CACHE_CLIENTSESS_CACHE_NO_AUTO_CLEARSESS_CACHE_NO_INTERNALSESS_CACHE_NO_INTERNAL_LOOKUPSESS_CACHE_NO_INTERNAL_STORESESS_CACHE_OFFSESS_CACHE_SERVERSSL3_VERSIONSSLEAY_BUILT_ONSSLEAY_CFLAGS
SSLEAY_DIRSSLEAY_PLATFORMSSLEAY_VERSIONSSL_CB_ACCEPT_EXITSSL_CB_ACCEPT_LOOPSSL_CB_ALERTSSL_CB_CONNECT_EXITSSL_CB_CONNECT_LOOPSSL_CB_EXITSSL_CB_HANDSHAKE_DONESSL_CB_HANDSHAKE_STARTSSL_CB_LOOPSSL_CB_READSSL_CB_READ_ALERTSSL_CB_WRITESSL_CB_WRITE_ALERTSSL_ST_ACCEPTSSL_ST_CONNECTSSL_ST_MASKTLS1_1_VERSIONTLS1_2_VERSIONTLS1_3_VERSIONTLS1_VERSIONTLS_CLIENT_METHOD
TLS_METHODTLS_SERVER_METHODVERIFY_CLIENT_ONCEVERIFY_FAIL_IF_NO_PEER_CERTVERIFY_NONEVERIFY_PEER
ConnectionContextErrorOP_NO_SSLv2OP_NO_SSLv3OP_NO_TLSv1OP_NO_TLSv1_1OP_NO_TLSv1_2OP_NO_TLSv1_3SSLeay_versionSSLv23_METHODSessionSysCallErrorTLSv1_1_METHODTLSv1_2_METHODTLSv1_METHODWantReadErrorWantWriteErrorWantX509LookupErrorX509VerificationCodesZeroReturnErrorintr,   r+   r(   r*   r)   r'                     	   
         rO   rh   re   rf   rg   rs   rt   ru   rv   rw   rx   r%   r>   r?   r1   r3   r6   r8   rA   r2   r4   r@   rC   rB   r0   r.   rD   r=   r5   r7   r9   r:   r/   r;   OP_NO_RENEGOTIATIONOP_IGNORE_UNEXPECTED_EOFOP_LEGACY_SERVER_CONNECTr-   ro   rm   rl   rn   rM   rH   rN   rG   rI   rK   rL   rJ   rc   rb   rd   r]   rZ   r^   r`   rW   r_   ra   rV   rU   rY   rX   r\   r[   _Tc                      \ rS rSrSrg)_NoOverlappingProtocolsi   N__name__
__module____qualname____firstlineno____static_attributes__r       K/var/www/highfloat_scraper/venv/lib/python3.13/site-packages/OpenSSL/SSL.pyr   r         r   r   rp   c                  p   \ rS rSrSr\R                  r\R                  r	\R                  r\R                  r\R                  r\R                   r\R$                  r\R(                  r\R,                  r\R0                  r\R4                  r\R8                  r\R<                  r\R@                  r!\RD                  r#\RH                  r%\RL                  r'\RP                  r)\RT                  r+\RX                  r-\R\                  r/\R`                  r1\Rd                  r3\Rh                  r5\Rl                  r7\Rp                  r9\Rt                  r;\Rx                  r=\R|                  r?\R                  rA\R                  rC\R                  rE\R                  rG\R                  rI\R                  rK\R                  rM\R                  rO\R                  rQ\R                  rS\R                  rU\R                  rW\R                  rY\R                  r[\R                  r]\R                  r_\R                  ra\R                  rc\R                  re\R                  rg\R                  ri\R                  rk\R                  rm\R                  ro\R                  rq\R                  rs\R                  ru\R                  rwSrxg)r   i0  a@  
Success and error codes for X509 verification, as returned by the
underlying ``X509_STORE_CTX_get_error()`` function and passed by pyOpenSSL
to verification callback functions.

See `OpenSSL Verification Errors
<https://www.openssl.org/docs/manmaster/man3/X509_verify_cert_error_string.html#ERROR-CODES>`_
for details.
r   N)yr   r   r   r   __doc___lib	X509_V_OKOK$X509_V_ERR_UNABLE_TO_GET_ISSUER_CERTERR_UNABLE_TO_GET_ISSUER_CERTX509_V_ERR_UNABLE_TO_GET_CRLERR_UNABLE_TO_GET_CRL+X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE$ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE*X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE#ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE-X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY&ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY!X509_V_ERR_CERT_SIGNATURE_FAILUREERR_CERT_SIGNATURE_FAILURE X509_V_ERR_CRL_SIGNATURE_FAILUREERR_CRL_SIGNATURE_FAILUREX509_V_ERR_CERT_NOT_YET_VALIDERR_CERT_NOT_YET_VALIDX509_V_ERR_CERT_HAS_EXPIREDERR_CERT_HAS_EXPIREDX509_V_ERR_CRL_NOT_YET_VALIDERR_CRL_NOT_YET_VALIDX509_V_ERR_CRL_HAS_EXPIREDERR_CRL_HAS_EXPIRED)X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD"ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD(X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD!ERR_ERROR_IN_CERT_NOT_AFTER_FIELD)X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD"ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD)X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD"ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELDX509_V_ERR_OUT_OF_MEMERR_OUT_OF_MEM&X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERTERR_DEPTH_ZERO_SELF_SIGNED_CERT$X509_V_ERR_SELF_SIGNED_CERT_IN_CHAINERR_SELF_SIGNED_CERT_IN_CHAIN,X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY%ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY*X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE#ERR_UNABLE_TO_VERIFY_LEAF_SIGNATUREX509_V_ERR_CERT_CHAIN_TOO_LONGERR_CERT_CHAIN_TOO_LONGX509_V_ERR_CERT_REVOKEDERR_CERT_REVOKEDX509_V_ERR_INVALID_CAERR_INVALID_CAX509_V_ERR_PATH_LENGTH_EXCEEDEDERR_PATH_LENGTH_EXCEEDEDX509_V_ERR_INVALID_PURPOSEERR_INVALID_PURPOSEX509_V_ERR_CERT_UNTRUSTEDERR_CERT_UNTRUSTEDX509_V_ERR_CERT_REJECTEDERR_CERT_REJECTED"X509_V_ERR_SUBJECT_ISSUER_MISMATCHERR_SUBJECT_ISSUER_MISMATCHX509_V_ERR_AKID_SKID_MISMATCHERR_AKID_SKID_MISMATCH&X509_V_ERR_AKID_ISSUER_SERIAL_MISMATCHERR_AKID_ISSUER_SERIAL_MISMATCHX509_V_ERR_KEYUSAGE_NO_CERTSIGNERR_KEYUSAGE_NO_CERTSIGN#X509_V_ERR_UNABLE_TO_GET_CRL_ISSUERERR_UNABLE_TO_GET_CRL_ISSUER'X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION ERR_UNHANDLED_CRITICAL_EXTENSIONX509_V_ERR_KEYUSAGE_NO_CRL_SIGNERR_KEYUSAGE_NO_CRL_SIGN+X509_V_ERR_UNHANDLED_CRITICAL_CRL_EXTENSION$ERR_UNHANDLED_CRITICAL_CRL_EXTENSIONX509_V_ERR_INVALID_NON_CAERR_INVALID_NON_CA%X509_V_ERR_PROXY_PATH_LENGTH_EXCEEDEDERR_PROXY_PATH_LENGTH_EXCEEDED(X509_V_ERR_KEYUSAGE_NO_DIGITAL_SIGNATURE!ERR_KEYUSAGE_NO_DIGITAL_SIGNATURE)X509_V_ERR_PROXY_CERTIFICATES_NOT_ALLOWED"ERR_PROXY_CERTIFICATES_NOT_ALLOWEDX509_V_ERR_INVALID_EXTENSIONERR_INVALID_EXTENSION#X509_V_ERR_INVALID_POLICY_EXTENSIONERR_INVALID_POLICY_EXTENSIONX509_V_ERR_NO_EXPLICIT_POLICYERR_NO_EXPLICIT_POLICYX509_V_ERR_DIFFERENT_CRL_SCOPEERR_DIFFERENT_CRL_SCOPE(X509_V_ERR_UNSUPPORTED_EXTENSION_FEATURE!ERR_UNSUPPORTED_EXTENSION_FEATUREX509_V_ERR_UNNESTED_RESOURCEERR_UNNESTED_RESOURCEX509_V_ERR_PERMITTED_VIOLATIONERR_PERMITTED_VIOLATIONX509_V_ERR_EXCLUDED_VIOLATIONERR_EXCLUDED_VIOLATIONX509_V_ERR_SUBTREE_MINMAXERR_SUBTREE_MINMAX&X509_V_ERR_UNSUPPORTED_CONSTRAINT_TYPEERR_UNSUPPORTED_CONSTRAINT_TYPE(X509_V_ERR_UNSUPPORTED_CONSTRAINT_SYNTAX!ERR_UNSUPPORTED_CONSTRAINT_SYNTAX"X509_V_ERR_UNSUPPORTED_NAME_SYNTAXERR_UNSUPPORTED_NAME_SYNTAX$X509_V_ERR_CRL_PATH_VALIDATION_ERRORERR_CRL_PATH_VALIDATION_ERRORX509_V_ERR_HOSTNAME_MISMATCHERR_HOSTNAME_MISMATCHX509_V_ERR_EMAIL_MISMATCHERR_EMAIL_MISMATCHX509_V_ERR_IP_ADDRESS_MISMATCHERR_IP_ADDRESS_MISMATCH#X509_V_ERR_APPLICATION_VERIFICATIONERR_APPLICATION_VERIFICATIONr   r   r   r   r   r   0  s    
B$($M$M! ==88 ) 	77 ( 	:: + "&!G!G $ E E!??;; ==9966 ' 	55 & 	66 ' 	66 ' //N33 $ %)$M$M!99 * 	77 ( #AA33//N#CC997755"&"I"I!??33 $  $CC#'#K#K 44 %  $CC88 ) 77%)%O%O"55 & 	66 ' !==#'#K#K !??"AA55 & !=="AA!??7733 $ 	55 & #'"I"I$($M$M! ==77"AA#'#K#K r   r   )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                      \ rS rSrSrSrg)rr   i  z,
An error occurred in an `OpenSSL.SSL` API.
r   N)r   r   r   r   r   r   r   r   r   rr   rr     s    r   rr   c                      \ rS rSrSrg)r   i  r   Nr   r   r   r   r   r     r   r   r   c                      \ rS rSrSrg)r   i  r   Nr   r   r   r   r   r     r   r   r   c                      \ rS rSrSrg)r   i  r   Nr   r   r   r   r   r     r   r   r   c                      \ rS rSrSrg)r   i  r   Nr   r   r   r   r   r     r   r   r   c                      \ rS rSrSrg)r|   i  r   Nr   r   r   r   r|   r|     r   r   r|   c                  ,    \ rS rSrSrSS jrSS jrSrg)_CallbackExceptionHelperi  a  
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.
c                    / U l         g N	_problemsselfs    r   __init__!_CallbackExceptionHelper.__init__  s	    *,r   c                    U R                   (       a&   [        5         U R                   R                  S5      eg! [         a     N(f = f)zi
Raise an exception from the OpenSSL error queue or that was previously
captured whe running a callback.
r   N)r   _raise_current_errorrr   popr!  s    r   raise_if_problem)_CallbackExceptionHelper.raise_if_problem  sF    
 >>$& ..$$Q''   s   
9 
AAr  NreturnNone)r   r   r   r   r   r#  r(  r   r   r   r   r  r    s    	-
(r   r  c                  "    \ rS rSrSrSS jrSrg)_VerifyHelperi  zR
Wrap a callback such that it can be used as a certificate verification
callback.
c                   ^ ^ [         R                  T 5        [        T5      UU 4S j5       n[        R                  " SU5      T l        g )Nc                2  > [         R                  " U5      n[         R                  " U5        [        R                  " U5      n[         R
                  " U5      n[         R                  " U5      n[         R                  " 5       n[         R                  " X5      n[        R                  U   n T" XXEU 5      n	U	(       a&  [         R                  " U[         R                  5        gg! [         a%  n
TR                  R                  U
5         S n
A
gS n
A
ff = f)N   r   )r   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_datarp   _reverse_mappingX509_STORE_CTX_set_errorr   	Exceptionr   append)ok	store_ctxr   certerror_numbererror_depthindexssl
connectionresultecallbackr"  s              r   wrapper'_VerifyHelper.__init__.<locals>.wrapper  s    77	BDT"**40D88CL==iHK;;=E11)CC#44S9J!l 11)T^^L  %%a(s   /
C' '
D1DDzint (*)(int, X509_STORE_CTX *)r  r#  r   _ffirG  r"  rG  rH  s   `` r   r#  _VerifyHelper.__init__  s>     ))$/	x	 
	2 ,g
r   rG  N)rG  _VerifyCallbackr+  r,  r   r   r   r   r   r#  r   r   r   r   r.  r.    s    

r   r.  c                  "    \ rS rSrSrSS jrSrg)_ALPNSelectHelperi  zI
Wrap a callback such that it can be used as an ALPN selection callback.
c                   ^ ^ [         R                  T 5        [        T5      UU 4S j5       n[        R                  " SU5      T l        g )Nc                  >  [         R                  U    n[        R                  " X45      S S  n/ nU(       a.  US   n	USU	S-    n
UR	                  U
5        XyS-   S  nU(       a  M.  T" Xh5      nSnU[
        L a  SnSnO [        U[        5      (       d  [        S5      e[        R                  " S[        U5      5      [        R                  " SU5      /Ul        UR                  S   S   US'   UR                  S   US'   U(       d  [        R                  $ [        R                  $ ! [         a5  nTR                   R	                  U5        [        R"                  s S nA$ S nAff = f)	Nr   r1  Tr   Fz^ALPN callback must return a bytestring or the special NO_OVERLAPPING_PROTOCOLS sentinel value.zunsigned char *unsigned char[])rp   r9  rK  bufferr<  r&   
isinstancebytes	TypeErrornewlen_alpn_select_callback_argsr   SSL_TLSEXT_ERR_NOACKSSL_TLSEXT_ERR_OKr;  r   SSL_TLSEXT_ERR_ALERT_FATAL)rC  outoutlenin_inlenargconninstr	protolistencoded_lenprotooutbytesany_acceptedrF  rG  r"  s                 r   rH  +_ALPNSelectHelper.__init__.<locals>.wrapper  s\   (7!2237
 C/2	"'(K!!kAo6E$$U+!/"34E	 e $D4#77"H#(L#He44#K  HH.H>HH.93/ !;;A>qAq	88;A#444--- 7%%a(6667s+   A!D( &B1D( D( (
E'2*E"E'"E'z^int (*)(SSL *, unsigned char **, unsigned char *, const unsigned char *, unsigned int, void *)rJ  rL  s   `` r   r#  _ALPNSelectHelper.__init__  sD     ))$/	x)	7 
)	7V ? 
r   rN  NrG  _ALPNSelectCallbackr+  r,  rP  r   r   r   rR  rR    s    5
r   rR  c                  "    \ rS rSrSrSS jrSrg)_OCSPServerCallbackHelperiL  a  
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.
c                   ^ ^ [         R                  T 5        [        T5      UU 4S j5       n[        R                  " SU5      T l        g )Nc                  >  [         R                  U    nU[        R                  :w  a  [        R                  " U5      nOS nT" X#5      n[        U[        5      (       d  [        S5      eU(       d  g[        U5      n[        R                  " U5      nU[        R                  " Xe5      S S & [        R                  " XU5        g! [         a%  nT	R                  R                  U5         S nAgS nAff = f)Nz'OCSP callback must return a bytestring.r   r      )rp   r9  rK  NULLfrom_handlerW  rX  rY  r[  r   OPENSSL_mallocrV  SSL_set_tlsext_status_ocsp_respr;  r   r<  )
rC  cdatare  data	ocsp_dataocsp_data_lengthdata_ptrrF  rG  r"  s
           r   rH  3_OCSPServerCallbackHelper.__init__.<locals>.wrappere  s    #!2237 DII%++E2DD %T0	!)U33#$MNN ! $'y> ../?@=FH7:44#3  %%a(s   A/C 3AC 
C4C//C4int (*)(SSL *, void *)rJ  rL  s   `` r   r#  "_OCSPServerCallbackHelper.__init__b  s=     ))$/	x$	 
$	L &>Hr   rN  N)rG  z_OCSPServerCallback[Any]r+  r,  rP  r   r   r   rq  rq  L  s    **Ir   rq  c                  "    \ rS rSrSrSS jrSrg)_OCSPClientCallbackHelperi  a  
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.
c                   ^ ^ [         R                  T 5        [        T5      UU 4S j5       n[        R                  " SU5      T l        g )Nc                  >  [         R                  U    nU[        R                  :w  a  [        R                  " U5      nOS n[        R
                  " S5      n[        R                  " X5      nUS:  a  SnO[        R                  " US   U5      S S  nT	" X&U5      n[        [        U5      5      $ ! [         a%  nT
R                  R                  U5         S nAgS nAff = f)Nunsigned char **r   r   )rp   r9  rK  ru  rv  rZ  r   SSL_get_tlsext_status_ocsp_resprV  r   boolr;  r   r<  )rC  ry  re  rz  ocsp_ptrocsp_lenr{  validrF  rG  r"  s            r   rH  3_OCSPClientCallbackHelper.__init__.<locals>.wrapper  s    !2237 DII%++E2DD  88$67??Na< #I !%HQK B1 EI $7 4;'' %%a(s   B.B2 2
C!<CC!r  rJ  rL  s   `` r   r#  "_OCSPClientCallbackHelper.__init__  s<     ))$/	x	 
	< &>Hr   rN  N)rG  z_OCSPClientCallback[Any]r+  r,  rP  r   r   r   r  r    s    *"Ir   r  c                      \ rS rSrSS jrSrg)_CookieGenerateCallbackHelperi  c                   ^ ^ [         R                  T 5        [        T5      UU 4S j5       n[        R                  " SU5      T l        g )Nc                   >  [         R                  U    nT" U5      nXAS[        U5      & [        U5      US'   g! [         a%  nTR                  R                  U5         S nAgS nAff = f)Nr   r1  )rp   r9  r[  r;  r   r<  )rC  r`  ra  re  cookierF  rG  r"  s         r   rH  7_CookieGenerateCallbackHelper.__init__.<locals>.wrapper  sd    	!2237!$'-AF$Kq	 %%a(s   6: 
A)A$$A)z/int (*)(SSL *, unsigned char *, unsigned int *)rJ  rL  s   `` r   r#  &_CookieGenerateCallbackHelper.__init__  s?     ))$/	x
	 

	 =
r   rN  NrG  _CookieGenerateCallbackr+  r,  r   r   r   r   r#  r   r   r   r   r  r    s    
r   r  c                      \ rS rSrSS jrSrg)_CookieVerifyCallbackHelperi  c                   ^ ^ [         R                  T 5        [        T5      UU 4S j5       n[        R                  " SU5      T l        g )Nc                   >  [         R                  U    nT" U[        USU 5      5      $ ! [         a%  nTR                  R                  U5         S nAgS nAff = fNr   )rp   r9  rX  r;  r   r<  )rC  c_cookie
cookie_lenre  rF  rG  r"  s        r   rH  5_CookieVerifyCallbackHelper.__init__.<locals>.wrapper  sV    !2237eHQz,B&CDD %%a(s   '+ 
AAAz-int (*)(SSL *, unsigned char *, unsigned int)rJ  rL  s   `` r   r#  $_CookieVerifyCallbackHelper.__init__  s?     ))$/	x	 
	 ;
r   rN  NrG  _CookieVerifyCallbackr+  r,  r  r   r   r   r  r    s    
r   r  c                    S n[        U [        5      (       d  [        U SS 5      nUb  U" 5       n [        U [        5      (       a  U n[        U[        5      (       d  [        S5      eUS:  a  [	        SUS S35      eU$ )Nfilenoz3argument must be an int, or have a fileno() method.r   z.file descriptor cannot be a negative integer (i))rW  r   getattrrY  
ValueError)objfdmeths      r   _asFileDescriptorr    s    	Bc3sHd+&C#sb#MNN	a<RF!D
 	
 Ir   c                V    [         R                  " [        R                  " U 5      5      $ )z
Return a string describing the version of OpenSSL in use.

:param type: One of the :const:`OPENSSL_` constants defined in this module.
)rK  stringr   OpenSSL_version)types    r   r  r    s     ;;t++D122r   c                   ^ ^ UU 4S jnU$ )ax  
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.
c                B   > T(       d  [        U 5      U4S j5       nU$ U $ )Nc                    > [        T5      er  NotImplementedError)argskwargserrors     r   explode<_make_requires.<locals>._requires_decorator.<locals>.explode"  s    )%00r   )r   )funcr  r  flags     r   _requires_decorator+_make_requires.<locals>._requires_decorator  s(    4[1 1 NKr   r   )r  r  r  s   `` r   _make_requiresr    s    	 r   Cryptography_HAS_KEYLOGzKey logging not availablec                  $    \ rS rSr% SrS\S'   Srg)r{   i2  z
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
r   _sessionr   N)r   r   r   r   r   __annotations__r   r   r   r   r{   r{   2  s     Mr   r{   c                     \ rS rSr% Sr\\R                  S4\\R                  \	4\
\R                  \4\\R                  \4\\R                  S4\\R                   S4\\R$                  S4\\R(                  S4\\R,                  S4\\R0                  S40
rS\S'   S7S jrS8S jrS8S jr S9     S:S	 jjr    S;S
 jr S9     S<S jjr S=S jr!S>S jr"      S?S jr#S@S jr$\%4     SAS jjr&SBS jr'SCS jr(S=S jr)\%4     SDS jjr*SES jr+S=S jr,SFS jr-SGS jr.SHS jr/SIS jr0 S9     SJS jjr1SKS jr2SIS jr3SIS jr4SLS jr5SMS  jr6SNS! jr7    SOS" jr8    SPS# jr9SQS$ jr:SIS% jr;    SRS& jr<\=    SSS' j5       r>STS( jr?SUS) jr@SVS* jrASWS+ jrBSHS, jrC    SXS- jrDSYS. jrESZS/ jrFS[S0 jrG      S\S1 jrH S9     S]S2 jjrI S9     S^S3 jjrJ    S_S4 jrK    S`S5 jrLS6rMg)arq   i>  aY  
: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.
Nz@typing.ClassVar[dict[int, tuple[Callable[[], Any], int | None]]]_methodsc                   [        U[        5      (       d  [        S5      e U R                  U   u  p#U" 5       n[        U[        R                  :g  5        [        R                  " U5      n[        U[        R                  :g  5        [        R                  " U[        R                  5      nXPl        S U l        S U l        S U l        S U l        S U l        S U l        S U l        S U l        S U l        S U l        S U l        S U l        S U l        S U l        S U l        S U l        U R=                  [        R>                  5        Ub#  U RA                  U5        U RC                  U5        g g ! [         a    [        S5      ef = f)Nzmethod must be an integerzNo such protocol)"rW  r   rY  r  KeyErrorr  _openssl_assertrK  ru  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contexts         r   r#  Context.__init__X  so   &#&&788	1#'==#8 K !]

dii/0"":.499,-'''4#4#45<@EI!04!488<" $+/(=A AE"  	
  	 '+ 	$ JN"d889&&w/&&w/ G  	1/00	1s   E) )E?c                ^    [        [        R                  " U R                  U5      S:H  5        g)a  
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.
r1  N)r  r   SSL_CTX_set_min_proto_versionr  r"  r  s     r   r  Context.set_min_proto_version  %     	..t}}gF!K	
r   c                ^    [        [        R                  " U R                  U5      S:H  5        g)a  
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.
r1  N)r  r   SSL_CTX_set_max_proto_versionr  r  s     r   r  Context.set_max_proto_version  r  r   c                    Uc  [         R                  nO[        U5      nUc  [         R                  nO[        U5      n[        R                  " U R
                  X5      nU(       d  [        5         gg)a  
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
    ``str``).
:param capath: In which directory we can find the certificates
    (``bytes`` or ``str``).

:return: None
N)rK  ru  _path_bytesr   SSL_CTX_load_verify_locationsr  r&  )r"  cafilecapathload_results       r   load_verify_locationsContext.load_verify_locations  s]    ( >YYF (F>YYF (F88MM6
  " r   c                T   ^ ^ [        T5      SUU 4S jj5       n[        [        USSS9$ )Nc                *   > T" XTR                   5      $ r  )r  )sizeverifyuserdatarG  r"  s      r   rH  'Context._wrap_callback.<locals>.wrapper  s    D$*C*CDDr   T)	more_argstruncate)r  r   r  r  r  r   r+  rX  )r   r    r   rL  s   `` r   _wrap_callbackContext._wrap_callback  s5     
x	E 
	E !'TD
 	
r   c                    [        U5      (       d  [        S5      eU R                  U5      U l        U R                  R                  U l        [        R                  " U R                  U R
                  5        X l	        g)ar  
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)
callablerY  r  r  rG  r  r   SSL_CTX_set_default_passwd_cbr  r  )r"  rG  r  s      r   set_passwd_cbContext.set_passwd_cb  sg    . !!788"&"5"5h"?$($;$;$D$D!**MM444	
 %-!r   c                r   [         R                  " U R                  5      n[        US:H  5        [        R
                  " [         R                  " 5       5      R                  S5      n[        R
                  " [         R                  " 5       5      R                  S5      nU R                  X#5      (       d  [        R
                  " [         R                  " 5       5      n[        R
                  " [         R                  " 5       5      nU[        :X  a&  U[        :X  a  U R                  [        [         5        gggg)aw  
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 <https://brew.sh>`_ formula installed
    in the default location.
*   Windows will not work.
*   manylinux cryptography wheels will work on most common Linux
    distributions in pyOpenSSL 17.1.0 and above.  pyOpenSSL detects the
    manylinux wheel and attempts to load roots via a fallback path.

:return: None
r1  asciiN)r    SSL_CTX_set_default_verify_pathsr  r  rK  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_files         r   set_default_verify_paths Context.set_default_verify_paths  s    ( ::4==I

a( kk$"D"D"FGNN
 {{//1

&/ 	 ''BB++d&D&D&FGK;;t'F'F'HIL
 == $CC 33/1L D > Cr   c                    [         R                  R                  U5      SL=(       d!    [         R                  R                  U5      SL$ )zX
Check to see if the default cert dir/file environment vars are present.

:return: bool
N)osenvironget)r"  r  r  s      r   r  Context._check_env_vars_set  s8     JJNN<(4 7zz~~k*$6	
r   c                   U H:  n[         R                  R                  U5      (       d  M)  U R                  U5          O   U H;  n[         R                  R	                  U5      (       d  M)  U R                  SU5          g   g)a  
Default verify paths are based on the compiled version of OpenSSL.
However, when pyca/cryptography is compiled as a manylinux 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  pathisfiler  isdir)r"  	file_pathdir_pathr  r  s        r   r  &Context._fallback_default_verify_paths*  sd      Fww~~f%%**62  
 Fww}}V$$**48 r   c                    [        U5      n[        R                  " U R                  U5      nU(       d  [	        5         gg)z
Load a certificate chain from a file.

:param certfile: The name of the certificate chain file (``bytes`` or
    ``str``).  Must be PEM encoded.

:return: None
N)r  r   "SSL_CTX_use_certificate_chain_filer  r&  )r"  certfilerE  s      r   use_certificate_chain_file"Context.use_certificate_chain_file@  s7     x(88MM8
  " r   c                    [        U5      n[        U[        5      (       d  [        S5      e[        R
                  " U R                  X5      nU(       d  [        5         gg)a$  
Load a certificate from a file

:param certfile: The name of the certificate file (``bytes`` or
    ``str``).
: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  rW  r   rY  r   SSL_CTX_use_certificate_filer  r&  )r"  r*  filetype
use_results       r   use_certificate_fileContext.use_certificate_fileQ  sP     x((C((9::66MM8

  " r   c                
   [        U[        5      (       d  [        R                  " U5      nO[        R                  " S[
        SS9  [        R                  " U R                  UR                  5      nU(       d  [        5         ggzS
Load a certificate from a X509 object

:param cert: The X509 object
:return: None
ePassing pyOpenSSL X509 objects is deprecated. You should use a cryptography.x509.Certificate instead.rt  
stacklevelN)rW  r   from_cryptographywarningswarnDeprecationWarningr   SSL_CTX_use_certificater  _x509r&  r"  r?  r1  s      r   use_certificateContext.use_certificatei  se     $%%))$/DMMJ # 11$--L
 " r   c                b   [        U[        5      (       d  [        R                  " U5      nO[        R                  " S[
        SS9  [        R                  " UR                  5      n[        R                  " U R                  U5      nU(       d!  [        R                  " U5        [        5         gg)zi
Add certificate to chain

:param certobj: The X509 certificate object to add to the chain
:return: None
r6  rt  r7  N)rW  r   r9  r:  r;  r<  r   X509_dupr>  SSL_CTX_add_extra_chain_certr  	X509_freer&  )r"  certobjcopy
add_results       r   add_extra_chain_certContext.add_extra_chain_cert  s     '4((,,W5GMMJ # }}W]]+66t}}dK
NN4  " r   c                p    U R                   b  U R                   R                  [        5        [        5         g r  )r  r(  rr   r&  r!  s    r   _raise_passphrase_exception#Context._raise_passphrase_exception  s(    "".##44U;r   c                    [        U5      n[        U[        5      (       d  [        S5      e[        R
                  " U R                  X5      nU(       d  U R                  5         gg)a  
Load a private key from a file

:param keyfile: The name of the key file (``bytes`` or ``str``)
: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
r.  N)r  rW  r   rY  r   SSL_CTX_use_PrivateKey_filer  rL  )r"  keyfiler0  r1  s       r   use_privatekey_fileContext.use_privatekey_file  sV     g&(C((9::55MM7

 ,,. r   c                   [        U[        5      (       d  [        R                  " U5      nO[        R                  " S[
        SS9  [        R                  " U R                  UR                  5      nU(       d  U R                  5         ggzS
Load a private key from a PKey object

:param pkey: The PKey object
:return: None
z`Passing pyOpenSSL PKey objects is deprecated. You should use a cryptography private key instead.rt  r7  N)rW  r   from_cryptography_keyr:  r;  r<  r   SSL_CTX_use_PrivateKeyr  _pkeyrL  r"  pkeyr1  s      r   use_privatekeyContext.use_privatekey  sk     $%%--d3DMME # 00

K
,,. r   c                d    [         R                  " U R                  5      (       d  [        5         gg)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&  r!  s    r   check_privatekeyContext.check_privatekey  s$     --dmm<< " =r   c                    [         R                  " [        SU5      5      n[        U[        R
                  :g  5        [         R                  " U R                  U5        g)z
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_warnr  rK  ru  SSL_CTX_set_client_CA_listr  )r"  r  ca_lists      r   load_client_caContext.load_client_ca  sE     ..#Hf5
 	499,-''w?r   c           	         [        SU5      n[        [        R                  " U R                  U[        U5      5      S:H  5        g)a  
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
bufr1  N)rb  r  r   SSL_CTX_set_session_id_contextr  r[  )r"  rh  s     r   set_session_idContext.set_session_id  s:     &eS1//sCHM	
r   c                    [        U[        5      (       d  [        S5      e[        R                  " U R
                  U5      $ )aN  
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)rW  r   rY  r   SSL_CTX_set_session_cache_moder  r"  modes     r   set_session_cache_modeContext.set_session_cache_mode  s4     $$$566224==$GGr   c                B    [         R                  " U R                  5      $ )zg
Get the current session cache mode.

:returns: The currently used cache mode.

.. versionadded:: 0.14
)r   SSL_CTX_get_session_cache_moder  r!  s    r   get_session_cache_modeContext.get_session_cache_mode  s     224==AAr   c                   [        U[        5      (       d  [        S5      eUc?  SU l        SU l        [
        R                  " U R                  U[        R                  5        g[        U5      (       d  [        S5      e[        U5      U l        U R                  R                  U l        [
        R                  " U R                  XR                  5        g)aZ  
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.
rm  Nr  )rW  r   rY  r  r  r   SSL_CTX_set_verifyr  rK  ru  r  r.  rG  r"  rp  rG  s      r   
set_verifyContext.set_verify  s    , $$$566"&D$(D!##DMM4CH%% ;<<"/"9D$($7$7$@$@D!##DMM49N9NOr   c                    [        U[        5      (       d  [        S5      e[        R                  " U R
                  U5        g)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
zdepth must be an integerN)rW  r   rY  r   SSL_CTX_set_verify_depthr  )r"  depths     r   set_verify_depthContext.set_verify_depth;  s1     %%%677%%dmmU;r   c                B    [         R                  " U R                  5      $ )zd
Retrieve the Context object's verify mode, as set by
:meth:`set_verify`.

:return: The verify mode
)r   SSL_CTX_get_verify_moder  r!  s    r   get_verify_modeContext.get_verify_modeH  s     ++DMM::r   c                B    [         R                  " U R                  5      $ )zl
Retrieve the Context object's verify depth, as set by
:meth:`set_verify_depth`.

:return: The verify depth
)r   SSL_CTX_get_verify_depthr  r!  s    r   get_verify_depthContext.get_verify_depthQ  s     ,,T]];;r   c                   [        U5      n[        R                  " US5      nU[        R                  :X  a
  [        5         [        R                  " U[        R                  5      n[        R                  " U[        R                  [        R                  [        R                  5      n[        R                  " U[        R                  5      n[        R                  " U R                  U5      n[        US:H  5        g)z
Load parameters for Ephemeral Diffie-Hellman

:param dhfile: The file to load EDH parameters from (``bytes`` or
    ``str``).

:return: None
   rr1  N)r  r   BIO_new_filerK  ru  r&  r  BIO_freePEM_read_bio_DHparamsDH_freeSSL_CTX_set_tmp_dhr  r  )r"  dhfilebiodhress        r   load_tmp_dhContext.load_tmp_dhZ  s     V$-$)) "ggc4==)''TYY		499MWWR&%%dmmR8q!r   c                p   [        U[        5      (       aJ  [        R                  " S[        SS9  [
        R                  " U R                  UR                  5       5        gUR                  nUS:X  a  SnOUS:X  a  Sn[
        R                  " UR                  5       5      nU[
        R                  :X  a
  [        5         [
        R                  " U5      n[        U[         R"                  :g  5        [         R$                  " U[
        R&                  5      n[
        R                  " U R                  U5        g)	aZ  
Select a curve to use for ECDHE key exchange.

:param curve: A curve instance from cryptography
    (:class:`~cryptogragraphy.hazmat.primitives.asymmetric.ec.EllipticCurve`).
    Alternatively (deprecated) a curve object from either
    :meth:`OpenSSL.crypto.get_elliptic_curve` or
    :meth:`OpenSSL.crypto.get_elliptic_curves`.

:return: None
z|Passing pyOpenSSL elliptic curves to set_tmp_ecdh is deprecated. You should use cryptography's elliptic curve types instead.rt  r7  	secp192r1
prime192v1	secp256r1
prime256v1N)rW  r   r:  r;  r<  r   SSL_CTX_set_tmp_ecdhr  
_to_EC_KEYnameOBJ_txt2nidencode	NID_undefr&  EC_KEY_new_by_curve_namer  rK  ru  r  EC_KEY_free)r"  curver  nidr   s        r   set_tmp_ecdhContext.set_tmp_ecdho  s     e^,,MM% # %%dmmU5E5E5GH::D{"#$#""4;;=1Cdnn$$&..s3BB$))O,T--.B%%dmmR8r   c                   [        SU5      n[        U[        5      (       d  [        S5      e[	        [
        R                  " U R                  U5      S:H  5        [        U S5      nUR                  5       / SQ:X  a  [        S/5      eg)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.r1  N)TLS_AES_256_GCM_SHA384TLS_CHACHA20_POLY1305_SHA256TLS_AES_128_GCM_SHA256)zSSL routinesSSL_CTX_set_cipher_listzno cipher match)rb  rW  rX  rY  r  r   r  r  rp   get_cipher_listrr   )r"  r  tmpconns      r   set_cipher_listContext.set_cipher_list  s     .m[I+u--@AA((DI	
 T4(""$ )
 

  
r   c                j   [         R                  " 5       n[        U[        R                  :g  5         U H  n[        U[        5      (       d"  [        S[        U5      R                   S35      e[         R                  " UR                  5      n[        U[        R                  :g  5        [         R                  " X$5      nU(       a  M  [         R                  " U5        [        5         M     [         R"                  " U R$                  U5        g! [         a    [         R                   " U5        e f = f)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
z)client CAs must be X509Name objects, not z objectsN)r   sk_X509_NAME_new_nullr  rK  ru  rW  r   rY  r  r   X509_NAME_dup_namesk_X509_NAME_pushX509_NAME_freer&  r;  sk_X509_NAME_freerc  r  )r"  certificate_authorities
name_stackca_namerG  push_results         r   set_client_ca_listContext.set_client_ca_list  s     //1

dii/0	2!'844#C=112(<  ))'--8		 12"44ZF"{''-(* 3  	''zB	  	"":.	s   BD 
$D "D2c                   [        U[        5      (       d  [        R                  " U5      nO[        R                  " S[
        SS9  [        R                  " U R                  UR                  5      n[        US:H  5        g)a)  
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
r6  rt  r7  r1  N)rW  r   r9  r:  r;  r<  r   SSL_CTX_add_client_CAr  r>  r  )r"  certificate_authorityrH  s      r   add_client_caContext.add_client_ca  sr     /66$($:$:%%! MMJ # //MM066

 	
a(r   c                    [        U[        5      (       d  [        S5      e[        R                  " U R
                  U5      $ )a!  
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
ztimeout must be an integer)rW  r   rY  r   SSL_CTX_set_timeoutr  )r"  timeouts     r   set_timeoutContext.set_timeout  s4     '3''899''w??r   c                B    [         R                  " U R                  5      $ )zt
Retrieve session timeout, as set by :meth:`set_timeout`. The default
is 300 seconds.

:return: The session timeout
)r   SSL_CTX_get_timeoutr  r!  s    r   get_timeoutContext.get_timeout  s     ''66r   c                   ^ [        T5      U4S j5       n[        R                  " SU5      U l        [        R
                  " U R                  U R                  5        g)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
c                :   > T" [         R                  U    X5        g r  rp   r9  )rC  wherereturn_coderG  s      r   rH  *Context.set_info_callback.<locals>.wrapper*  s    Z005uJr   zvoid (*)(const SSL *, int, int)N)r   rK  rG  r  r   SSL_CTX_set_info_callbackr  rL  s    ` r   set_info_callbackContext.set_info_callback  sQ     
x	K 
	K #mm-w
 	&&t}}d6I6IJr   c                   ^ [        T5      U4S j5       n[        R                  " SU5      U l        [        R
                  " U R                  U R                  5        g)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
c                f   > [         R                  " U5      nT" [        R                  U    U5        g r  )rK  r  rp   r9  )rC  linerG  s     r   rH  ,Context.set_keylog_callback.<locals>.wrapperD  s&    ;;t$DZ005t<r   z#void (*)(const SSL *, const char *)N)r   rK  rG  r  r   SSL_CTX_set_keylog_callbackr  rL  s    ` r   set_keylog_callbackContext.set_keylog_callback3  sO    " 
x	= 
	= !%17!
 	((8M8MNr   c                    U R                   $ )z_
Get the application data (supplied via :meth:`set_app_data()`)

:return: The application data
r  r!  s    r   get_app_dataContext.get_app_dataN       ~~r   c                    Xl         g)zo
Set the application data (will be returned from get_app_data())

:param data: Any Python object
:return: None
Nr  r"  rz  s     r   set_app_dataContext.set_app_dataV  	     r   c                    [         R                  " U R                  5      nU[        R                  :X  a  g[
        R                  " [
        5      nXl        U$ )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  rK  ru  r   __new___store)r"  storepystores      r   get_cert_storeContext.get_cert_store_  sA     ++DMM:DII##I.r   c                    [        U[        5      (       d  [        S5      e[        R                  " U R
                  U5      $ )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.
zoptions must be an integer)rW  r   rY  r   SSL_CTX_set_optionsr  )r"  optionss     r   set_optionsContext.set_optionsp  s4     '3''899''w??r   c                    [        U[        5      (       d  [        S5      e[        R                  " U R
                  U5      $ )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.
rm  )rW  r   rY  r   SSL_CTX_set_moder  ro  s     r   r  Context.set_mode}  s4     $$$566$$T]]D99r   c                   ^ [        T5      U4S j5       n[        R                  " SU5      U l        [        R
                  " U R                  U R                  5        g)z
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
c                8   > T" [         R                  U    5        gr  r  )rC  alertrd  rG  s      r   rH  7Context.set_tlsext_servername_callback.<locals>.wrapper  s    Z0056r   zint (*)(SSL *, int *, void *)N)r   rK  rG  r  r   &SSL_CTX_set_tlsext_servername_callbackr  rL  s    ` r   set_tlsext_servername_callback&Context.set_tlsext_servername_callback  sR     
x	 
	 ,0==+W,
( 	33MM4;;	
r   c                    [        U[        5      (       d  [        S5      e[        [        R
                  " U R                  U5      S:H  5        g)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
zprofiles must be a byte string.r   N)rW  rX  rY  r  r   SSL_CTX_set_tlsext_use_srtpr  )r"  profiless     r   set_tlsext_use_srtpContext.set_tlsext_use_srtp  s>     (E**=>>,,T]]HEJ	
r   c           	        U(       d  [        S5      eSR                  [        R                  " S U 5       5      5      n[        R
                  " SU5      n[        [        R                  " U R                  U[        U5      5      S:H  5        g)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   c              3  N   #    U H  n[        [        U5      45      U4v   M     g 7fr  rX  r[  .0ps     r   	<genexpr>*Context.set_alpn_protos.<locals>.<genexpr>        Fv!Ay!11 5v   #%rU  r   N)r  joinr   from_iterablerK  rZ  r  r   SSL_CTX_set_alpn_protosr  r[  r"  protosprotostr	input_strs       r   set_alpn_protosContext.set_alpn_protos  s{     FGG 88FvFF
 HH.9	 	((y#h- 	
r   c                    [        U5      U l        U R                  R                  U l        [        R
                  " U R                  U R                  [        R                  5        g)aD  
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)	rR  r  rG  r  r   SSL_CTX_set_alpn_select_cbr  rK  ru  r"  rG  s     r   set_alpn_select_callback Context.set_alpn_select_callback  sH     $5X#> %)%=%=%F%F"''MM455tyy	
r   c                ~   Xl         UR                  U l        Uc  [        R                  U l        O[        R                  " U5      U l        [        R                  " U R                  U R                  5      n[        US:H  5        [        R                  " U R                  U R
                  5      n[        US:H  5        g)z
This internal helper does the common work for
``set_ocsp_server_callback`` and ``set_ocsp_client_callback``, which is
almost all of it.
Nr1  )r  rG  r  rK  ru  r  
new_handler   SSL_CTX_set_tlsext_status_cbr  r  SSL_CTX_set_tlsext_status_arg)r"  helperrz  rcs       r   _set_ocsp_callbackContext._set_ocsp_callback  s     #$oo<"iiDO"ood3DO..MM4..
 	a //tOa r   c                <    [        U5      nU R                  X25        g)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)rq  r!  r"  rG  rz  r  s       r   set_ocsp_server_callback Context.set_ocsp_server_callback  s    & +84-r   c                <    [        U5      nU R                  X25        g)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$  s       r   set_ocsp_client_callback Context.set_ocsp_client_callback  s    * +84-r   c                    [        U5      U l        [        R                  " U R                  U R                  R
                  5        g r  )r  r  r   SSL_CTX_set_cookie_generate_cbr  rG  r  s     r   set_cookie_generate_callback$Context.set_cookie_generate_callback1  s6     (EX'N$++MM((11	
r   c                    [        U5      U l        [        R                  " U R                  U R                  R
                  5        g r  )r  r  r   SSL_CTX_set_cookie_verify_cbr  rG  r  s     r   set_cookie_verify_callback"Context.set_cookie_verify_callback:  s6     &A%J"))MM&&//	
r   )r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  )r  r   r+  r,  )r  r   r+  r,  r  )r  _StrOrBytesPath | Noner  r2  r+  r,  )rG  _PassphraseCallback[_T]r+  r    )rG  r3  r  	_T | Noner+  r,  r*  )r  strr  r5  r+  r  )r%  	list[str]r&  r6  r+  r,  )r*  _StrOrBytesPathr+  r,  )r*  r7  r0  r   r+  r,  r?  X509 | x509.Certificater+  r,  )rF  r9  r+  r,  )rP  r7  r0  r   r+  r,  rY  z_PrivateKey | PKeyr+  r,  )r  rX  r+  r,  )rh  rX  r+  r,  )rp  r   r+  r,  r+  r   rp  r   rG  z_VerifyCallback | Noner+  r,  )r~  r   r+  r,  )r  r7  r+  r,  )r  z!_EllipticCurve | ec.EllipticCurver+  r,  )r  rX  r+  r,  )r  zSequence[X509Name]r+  r,  )r  r9  r+  r,  )r  r   r+  r,  )rG  z&Callable[[Connection, int, int], None]r+  r,  )rG  z#Callable[[Connection, bytes], None]r+  r,  r+  r   rz  r   r+  r,  )r+  zX509Store | None)r  r   r+  r,  )rG  zCallable[[Connection], None]r+  r,  )r  rX  r+  r,  r  zlist[bytes]r+  r,  rn  )r  z5_OCSPClientCallbackHelper | _OCSPServerCallbackHelperrz  z
Any | Noner+  r,  )rG  z_OCSPServerCallback[_T]rz  r4  r+  r,  )rG  z_OCSPClientCallback[_T]rz  r4  r+  r,  r  r  )Nr   r   r   r   r   rz   r   
TLS_methodr   rh   r}   re   r~   rf   rj   rk   TLS_server_methodri   TLS_client_methodr#   DTLS_methodr$   DTLS_server_methodr"   DTLS_client_methodr  r  r#  r  r  r  r  r  r  r  r  r+  r   r2  r@  rI  rL  rQ  rZ  r^  re  rj  rq  ru  rz  r  r  r  r  r  r  r  r  r  r  r  _requires_keylogr  r  r  r  r  r  r  r   r  r  r!  r%  r(  r,  r0  r   r   r   r   rq   rq   >  sa    	.t5.9.9T__d+D22D9D22D9d&&-T44d;T44d;	   +0Z

  *."#&"# '"# 
	"#H	
/	
		
 #-)- - 
	-B.`	
".7	,#$ :F#'#36#	#0#0#4 9E/&/25/	/0/0#@
"H"B =A#P#P#9#P	#PJ<;<"*%9N%N#C'9#C	#CJ )%< )	 )D@7K>K	K0 O;O	O O4"@:
4
	
2
#
J
(!E! ! 
	!6 .). . 
	.2 .). . 
	.0
/
	

-
	
r   rq   c                  <   \ rS rSr% \" 5       rS\S'    SV     SWS jjrSXS jrSYS jr	SZS jr
S[S	 jrS\S
 jr SV     S]S jjrS^S jrS_S jrS`S jrSaS jrS^S jrSbS jrS^S jrScSdS jjr\rScSdS jjrSVSeS jjr\r  Sf       SgS jjrShS jrSiS jrSjS jrSkS jrSlS jrSkS jr S^S jr!SmS jr"SnS jr#SoS  jr$SlS! jr%SpS" jr&SkS# jr'SlS$ jr(SkS% jr)SqS& jr*SrS' jr+SsS( jr,StS) jr-SuS* jr.S^S+ jr/SvS, jr0SwS- jr1S\S. jr2S\S/ jr3S\S0 jr4 SV       SxS1 jjr5SyS2 jr6\7Rp                      SzS3 j5       r9\7Rp                  S4S5.   S{S6 jj5       r9S4S5.   S|S7 jjr9\7Rp                      SzS8 j5       r:\7Rp                  S4S5.   S{S9 jj5       r:S4S5.   S|S: jjr:\;S}S; j5       r<\;    S~S< j5       r=\7Rp                      SS= j5       r>\7Rp                  S4S5.   SS> jj5       r>S4S5.   SS? jjr>\7Rp                      SS@ j5       r?\7Rp                  S4S5.   SSA jj5       r?S4S5.   SSB jjr?SkSC jr@SkSD jrASlSE jrBSlSF jrCSSG jrDSSH jrE    SSI jrFS\SJ jrGS\SK jrHSSL jrISpSM jrJSSN jrKSSO jrLS^SP jrMSSQ jrNSwSR jrOSwSS jrPSlST jrQSUrRg)rp   iD  z&typing.MutableMapping[Any, Connection]r9  Nc                   [        U[        5      (       d  [        S5      e[        R                  " UR
                  5      n[        R                  " U[        R                  5      U l	        [        R                  " U R                  [        R                  5        Xl        SU l        SU l        UR                  U l        UR                  U l        UR                   U l        UR"                  U l        X R$                  U R                  '   Uc  SU l        [        R(                  " [        R*                  " 5       5      U l        [/        U R,                  [        R0                  :g  5        [        R(                  " [        R*                  " 5       5      U l        [/        U R2                  [        R0                  :g  5        [        R4                  " U R                  U R,                  U R2                  5        gSU l        SU l        X l        [        R6                  " U R                  [9        U R&                  5      5      n[/        US:H  5        g)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 instanceNr1  )rW  rq   rY  r   SSL_newr  rK  r  SSL_free_sslSSL_set_modeSSL_MODE_AUTO_RETRYr  r\  r  r  r  r  r9  _socketBIO_new	BIO_s_mem	_into_sslr  ru  	_from_sslSSL_set_bio
SSL_set_fdr  )r"  r  socketrC  r  s        r   r#  Connection.__init__I  s    '7++@AAll7++,GGC/	
 	$))T%=%=> +/'
 &44 ' 8 8 (/'F'F$%,%B%B"+/dii(>DL!\\$..*:;DNDNNdii78!\\$..*:;DNDNNdii78TYYG!DN!DN!L		,T\\:J J!O,r   c                    U R                   c&  [        SU R                  R                   SU S35      e[	        U R                   U5      $ )za
Look up attributes on the wrapped socket object if they are not found
on the Connection object.
'z' object has no attribute ')rO  AttributeError	__class__r   r  r"  r  s     r   __getattr__Connection.__getattr__  sL    
 << DNN++,,GvQO  4<<..r   c                |   U R                   R                  b$  U R                   R                  R                  5         U R                   R                  b$  U R                   R                  R                  5         U R                   R                  b$  U R                   R                  R                  5         [
        R                  " X5      nU[
        R                  :X  a
  [        5       eU[
        R                  :X  a
  [        5       eU[
        R                  :X  a
  [        5       eU[
        R                  :X  a
  [        5       eU[
        R                  :X  a  [         S:X  a  ["        R$                  " 5       S   nO["        R&                  n[
        R(                  " 5       S:X  d  US:w  a8  US:  a&  US:w  a   [+        U[,        R.                  " U5      5      e[+        SS5      e[1        5         g U[
        R2                  :X  a  [
        R(                  " 5       S:w  a  [
        R(                  " 5       n[
        R4                  " U5      n[
        R6                  (       a=  [9        U[
        R:                  :H  5        [
        R<                  " 5         [+        SS5      e[1        5         g U[
        R>                  :X  a  g [1        5         g )Nwin32r   r  zUnexpected EOF) r  r  r(  r  r  r   SSL_get_errorSSL_ERROR_WANT_READr   SSL_ERROR_WANT_WRITEr   SSL_ERROR_ZERO_RETURNr   SSL_ERROR_WANT_X509_LOOKUPr   SSL_ERROR_SYSCALLr
   rK  getwinerrorerrnoERR_peek_errorr|   r   r  r&  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"  rC  rE  r  rh  peeked_errorreasons          r   _raise_ssl_errorConnection._raise_ssl_error  s   ==''3MM((99;==,,8MM-->>@==%%1MM&&779""3/D,,,/!d/// ""d000!##d555%''d,,,7"((*1-

""$)UaZA:%1*&uimmE.BCC"2'788 %&d(((T-@-@-Ba-G  ..0L((6FAAdEEE $$&"2'788$&d))) "r   c                    U R                   $ )zP
Retrieve the :class:`Context` object associated with this
:class:`Connection`.
)r  r!  s    r   get_contextConnection.get_context  s    
 }}r   c                    [        U[        5      (       d  [        S5      e[        R                  " U R
                  UR                  5        Xl        g)z
Switch this connection to a new session context.

:param context: A :class:`Context` instance giving the new session
    context to use.
rI  N)rW  rq   rY  r   SSL_set_SSL_CTXrL  r  )r"  r  s     r   set_contextConnection.set_context  s<     '7++@AATYY(8(89r   c                    [         R                  " U R                  [         R                  5      nU[        R
                  :X  a  g[        R                  " U5      $ )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_servernamerL  TLSEXT_NAMETYPE_host_namerK  ru  r  r\  s     r   get_servernameConnection.get_servername  sC     &&IIt55
 499{{4  r   c                   [        U[        5      (       d  [        S5      eUc?  SU l        SU l        [
        R                  " U R                  U[        R                  5        g[        U5      (       d  [        S5      e[        U5      U l        U R                  R                  U l        [
        R                  " U R                  XR                  5        g)z
Override the Context object's verification flags for this specific
connection. See :py:meth:`Context.set_verify` for details.
rm  Nr  )rW  r   rY  r  r  r   SSL_set_verifyrL  rK  ru  r  r.  rG  ry  s      r   rz  Connection.set_verify  s     $$$566"&D$(D!		4;H%% ;<<"/"9D$($7$7$@$@D!		41F1FGr   c                B    [         R                  " U R                  5      $ )zg
Retrieve the Connection object's verify mode, as set by
:meth:`set_verify`.

:return: The verify mode
)r   SSL_get_verify_moderL  r!  s    r   r  Connection.get_verify_mode  s     ''		22r   c                
   [        U[        5      (       d  [        R                  " U5      nO[        R                  " S[
        SS9  [        R                  " U R                  UR                  5      nU(       d  [        5         ggr5  )rW  r   r9  r:  r;  r<  r   SSL_use_certificaterL  r>  r&  r?  s      r   r@  Connection.use_certificate
  se     $%%))$/DMMJ # --diiD
 " r   c                *   [        U[        5      (       d  [        R                  " U5      nO[        R                  " S[
        SS9  [        R                  " U R                  UR                  5      nU(       d  U R                  R                  5         ggrT  )rW  r   rU  r:  r;  r<  r   SSL_use_PrivateKeyrL  rW  r  rL  rX  s      r   rZ  Connection.use_privatekey"  so     $%%--d3DMME # ,,TYY

C
MM557 r   c                F    [         R                  " U R                  U5        g)a  
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_mturL  )r"  mtus     r   set_ciphertext_mtuConnection.set_ciphertext_mtu:  s     	C(r   c                    [        [        S5      (       d  [        S5      e[        R                  " U R                  5      $ )z
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  rL  r!  s    r   get_cleartext_mtuConnection.get_cleartext_mtuH  s3     t011%&HII%%dii00r   c                    [        U[        5      (       d  [        S5      eSU;   a  [        S5      e[        R                  " U R
                  U5        g)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
zname must be a byte string    zname must not contain NUL byteN)rW  rX  rY  r   SSL_set_tlsext_host_namerL  r\  s     r   set_tlsext_host_nameConnection.set_tlsext_host_nameW  sF     $&&899d]<== 	%%dii6r   c                B    [         R                  " U R                  5      $ )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_pendingrL  r!  s    r   pendingConnection.pendingg  s     		**r   c                B   [        SU5      n[        R                  " U5       n[        U5      S:  a  [	        S5      e[
        R                  " U R                  U[        U5      5      nU R                  U R                  U5        UsSSS5        $ ! , (       d  f       g= f)as  
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
rh  z,Cannot send more than 2**31-1 bytes at once.N)	rb  rK  from_bufferr[  r  r   	SSL_writerL  rr  )r"  rh  flagsrz  rE  s        r   sendConnection.sendp  s{     &eS1c"d3x*$ B  ^^DIItSY?F!!$))V4 #""s   A#B
Bc           	     ^   [        SU5      n[        R                  " U5       n[        U5      nSnU(       a[  [        R
                  " U R                  X5-   [        US5      5      nU R                  U R                  U5        XV-  nXF-  nU(       a  M[  UsSSS5        $ ! , (       d  f       g= f)ai  
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
rh  r   r  N)	rb  rK  r  r[  r   r  rL  minrr  )r"  rh  r  rz  left_to_send
total_sentrE  s          r   sendallConnection.sendall  s     &eS1c"ds8LJ IIt0#lJ2O %%dii8$
& ,  #""s   A.BB
B,c                @   [        SU5      nUb:  U[        R                  -  (       a"  [        R                  " U R
                  X15      nO![        R                  " U R
                  X15      nU R                  U R
                  U5        [        R                  " X45      SS $ )z
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_allocatorrV  MSG_PEEKr   SSL_peekrL  SSL_readrr  rK  rV  )r"  bufsizr  rh  rE  s        r   recvConnection.recv  sq     !62!8]]499c:F]]499c:Fdii0{{3'**r   c                   Uc  [        U5      nO[        U[        U5      5      n[        SU5      nUb:  U[        R                  -  (       a"  [
        R                  " U R                  XB5      nO![
        R                  " U R                  XB5      nU R                  U R                  U5        [        [        R                  " XE5      5      USU& U$ )a  
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[  r  r  rV  r  r   r  rL  r  rr  
memoryviewrK  rV  )r"  rV  nbytesr  rh  rE  s         r   	recv_intoConnection.recv_into  s    & >[FV-F
 !62!8]]499c:F]]499c:Fdii0 %T[[%=>wr   c                D   [         R                  " U5      (       a{  [         R                  " U5      (       a
  [        5       e[         R                  " U5      (       a
  [        5       e[         R                  " U5      (       a  [        S5      e[        S5      e[        5         g )NBIO_should_io_specialzunknown bio failure)	r   BIO_should_retryBIO_should_readr   BIO_should_writer   r  r  r&  )r"  r  rE  s      r   _handle_bio_errorsConnection._handle_bio_errors  s{      %%##C((#o%&&s++$&&++C00 !!899 !!677 !"r   c                B   U R                   c  [        S5      e[        U[        5      (       d  [        S5      e[	        SU5      n[
        R                  " U R                   X!5      nUS::  a  U R                  U R                   U5        [        R                  " X#5      SS $ )ay  
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 Nonezbufsiz must be an integerr  r   )
rS  rY  rW  r   r  r   BIO_readr  rK  rV  )r"  r  rh  rE  s       r   bio_readConnection.bio_read  s     >>!:;;&#&&788 62t~~s;Q;##DNNF;{{3'**r   c                J   [        SU5      nU R                  c  [        S5      e[        R                  " U5       n[
        R                  " U R                  U[        U5      5      nUS::  a  U R                  U R                  U5        UsSSS5        $ ! , (       d  f       g= f)a2  
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
rh  Nr  r   )	rb  rR  rY  rK  r  r   	BIO_writer[  r  )r"  rh  rz  rE  s       r   	bio_writeConnection.bio_write	  sz     &eS1>>!:;;c"d^^DNND#d)DF{''?	 #""s   AB
B"c                    U R                  5       (       d-  [        [        R                  " U R                  5      S:H  5        gg)z^
Renegotiate the session.

:return: True if the renegotiation can be started, False otherwise
r1  TF)renegotiate_pendingr  r   SSL_renegotiaterL  r!  s    r   renegotiateConnection.renegotiate%	  s5     ''))D00;q@Ar   c                |    [         R                  " U R                  5      nU R                  U R                  U5        g)z
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_handshakerL  rr  r"  rE  s     r   do_handshakeConnection.do_handshake0	  s,     &&tyy1dii0r   c                H    [         R                  " U R                  5      S:H  $ )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
r1  )r   SSL_renegotiate_pendingrL  r!  s    r   r  Connection.renegotiate_pending;	  s     ++DII6!;;r   c                B    [         R                  " U R                  5      $ )zV
Find out the total number of renegotiations.

:return: The number of renegotiations.
)r   SSL_total_renegotiationsrL  r!  s    r   total_renegotiationsConnection.total_renegotiationsD	  s     ,,TYY77r   c                x    [         R                  " U R                  5        U R                  R	                  U5      $ )a  
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_staterL  rO  connect)r"  addrs     r   r  Connection.connectL	  s+     	""499-||##D))r   c                ^    U R                   R                  nU R                  5         U" U5      $ )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
)rO  
connect_exset_connect_state)r"  r  r  s      r   r  Connection.connect_exX	  s*     \\,,
 $r   c                    U R                   R                  5       u  p[        U R                  U5      nUR	                  5         X24$ )aS  
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`.
)rO  acceptrp   r  set_accept_state)r"  clientr  re  s       r   r  Connection.acceptf	  s<     ||**,$--0|r   c                   [         R                  " 5       n [         R                  " U R                  U5      n[         R                  " U5        U R
                  b  U R
                  R                  5         U R                  b  U R                  R                  5         US:X  a
  [        5       eUS:  a  U R                  U R                  U5        gg! [         R                  " U5        f = f)zu
Call the OpenSSL function DTLSv1_listen on this connection. See the
OpenSSL manual for more details.

:return: None
Nr   )
r   BIO_ADDR_newDTLSv1_listenrL  BIO_ADDR_freer  r(  r  r   rr  )r"  bio_addrrE  s      r   r  Connection.DTLSv1_listenu	  s     $$&	)''		8<Fx(
 ''3((99;%%1&&779Q;/!A:!!$))V4  x(s   !C C(c                    [         R                  " S5      n[         R                  " S5      n[        R                  " U R                  X5      (       a  US   US   S-  -   $ g)aE  
Determine when the DTLS SSL object next needs to perform internal
processing due to the passage of time.

When the returned number of seconds have passed, the
:meth:`DTLSv1_handle_timeout` method needs to be called.

:return: The time left in seconds before the next timeout or `None`
    if no timeout is currently active.
ztime_t *zlong *r   i@B N)rK  rZ  r   Cryptography_DTLSv1_get_timeoutrL  )r"  ptv_secptv_usecs      r   DTLSv1_get_timeoutConnection.DTLSv1_get_timeout	  sR     ((:&88H%//		7MM1:!w!677r   c                    [         R                  " U R                  5      nUS:  a#  U R                  U R                  U5         S5       e[	        U5      $ )z
Handles any timeout events which have become pending on a DTLS SSL
object.

:return: `True` if there was a pending timeout, `False` otherwise.
r   unreachable)r   DTLSv1_handle_timeoutrL  rr  r  r  s     r   r   Connection.DTLSv1_handle_timeout	  sG     ++DII6A:!!$))V4'-'5<r   c                v    U R                   c  [        S5      e[        R                  " U R                  S5        g)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
Nr  r   )rS  rY  r   BIO_set_mem_eof_returnrR  r!  s    r   bio_shutdownConnection.bio_shutdown	  s.     >>!:;;##DNNA6r   c                    [         R                  " U R                  5      nUS:  a#  U R                  U R                  U5         S5       eUS:  a  gg)a!  
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).
r   Fr  T)r   SSL_shutdownrL  rr  r  s     r   shutdownConnection.shutdown	  sJ     ""499-A:!!$))V4'-'5aZr   c                   / n[        5        Ho  n[        R                  " U R                  U5      nU[        R
                  :X  a    U$ UR                  [        R                  " U5      R                  S5      5        Mq     U$ )zh
Retrieve the list of ciphers used by the Connection object.

:return: A list of native cipher strings.
utf-8)	r	   r   SSL_get_cipher_listrL  rK  ru  r<  r  r  )r"  ciphersr  rE  s       r   r  Connection.get_cipher_list	  sh     A--dii;F" NN4;;v.55g>?	 
 r   c                   [         R                  " U R                  5      nU[        R                  :X  a  / $ / n[        [         R                  " U5      5       H  n[         R                  " X5      n[         R                  " U5      n[        U[        R                  :g  5        [        R                  " [        5      n[        R                  " U[         R                  5      Ul        UR                  U5        M     U$ )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_listrL  rK  ru  rangesk_X509_NAME_numsk_X509_NAME_valuer  r  r   r  r  r  r  r<  )r"  ca_namesrE  r  r  rG  pynames          r   get_client_ca_listConnection.get_client_ca_list	  s     ..tyy9tyy It,,X67A**87D%%d+DDDII-.%%h/F774)<)<=FLMM&! 8 r   c                    [        S5      e)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.Connectionr  r"  r  r  s      r   makefileConnection.makefile	  s     "?
 	
r   c                    U R                   $ )zZ
Retrieve application data as set by :meth:`set_app_data`.

:return: The application data
r  r!  s    r   r  Connection.get_app_data
  r  r   c                    Xl         g)zG
Set application data

:param data: The application data
:return: None
Nr  r  s     r   r  Connection.set_app_data
  r  r   c                B    [         R                  " U R                  5      $ )z~
Get the shutdown state of the Connection.

:return: The shutdown state, a bitvector of SENT_SHUTDOWN,
    RECEIVED_SHUTDOWN.
)r   SSL_get_shutdownrL  r!  s    r   get_shutdownConnection.get_shutdown
  s     $$TYY//r   c                    [        U[        5      (       d  [        S5      e[        R                  " U R
                  U5        g)zw
Set the shutdown state of the Connection.

:param state: bitvector of SENT_SHUTDOWN, RECEIVED_SHUTDOWN.
:return: None
zstate must be an integerN)rW  r   rY  r   SSL_set_shutdownrL  )r"  states     r   set_shutdownConnection.set_shutdown
  s1     %%%677dii/r   c                j    [         R                  " [        R                  " U R                  5      5      $ )zl
Retrieve a verbose string detailing the state of the Connection.

:return: A string representing the state
)rK  r  r   SSL_state_string_longrL  r!  s    r   get_state_stringConnection.get_state_string*
  s"     {{455dii@AAr   c                t   [         R                  " U R                  5      nU[        R                  :X  a  g[         R
                  " U R                  [        R                  S5      n[        US:  5        [        SU5      n[         R
                  " U R                  X25        [        R                  " X25      SS $ )zi
Retrieve the random value used with the server hello message.

:return: A string representing the state
Nr   rU  )	r   SSL_get_sessionrL  rK  ru  SSL_get_server_randomr  r  rV  r"  sessionlengthoutps       r   server_randomConnection.server_random2
  s     &&tyy1dii++DIItyy!D
#!"3V<""499d;{{4(++r   c                t   [         R                  " U R                  5      nU[        R                  :X  a  g[         R
                  " U R                  [        R                  S5      n[        US:  5        [        SU5      n[         R
                  " U R                  X25        [        R                  " X25      SS $ )zi
Retrieve the random value used with the client hello message.

:return: A string representing the state
Nr   rU  )	r   r%  rL  rK  ru  SSL_get_client_randomr  r  rV  r'  s       r   client_randomConnection.client_randomA
  s     &&tyy1dii++DIItyy!D
#!"3V<""499d;{{4(++r   c                L   [         R                  " U R                  5      nU[        R                  :X  a  g[         R
                  " U[        R                  S5      n[        US:  5        [        SU5      n[         R
                  " XU5        [        R                  " X25      SS $ )zb
Retrieve the value of the master key for this session.

:return: A string representing the state
Nr   rU  )	r   r%  rL  rK  ru  SSL_SESSION_get_master_keyr  r  rV  r'  s       r   
master_keyConnection.master_keyQ
  s|     &&tyy1dii00$))QG
#!"3V<''v>{{4(++r   c           
        [        SU5      n[        R                  nSnSnUb  Un[        U5      nSn[        R
                  " U R                  UUU[        U5      UUU5      n[        US:H  5        [        R                  " XB5      SS $ )a  
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
rU  r   Nr1  )	r  rK  ru  r[  r   SSL_export_keying_materialrL  r  rV  )	r"  labelolenr  r*  context_bufcontext_lenuse_contextsuccesss	            r   export_keying_material!Connection.export_keying_materiala
  s     ""3T:ii!Kg,KK11IIJ	
 	1%{{4&q))r   c                :    U R                   R                  " U0 UD6$ )z
Call the :meth:`shutdown` method of the underlying socket.
See :manpage:`shutdown(2)`.

:return: What the socket's shutdown() method returns
)rO  r  r  s      r   sock_shutdownConnection.sock_shutdown
  s     ||$$d5f55r   c                   g r  r   r"  as_cryptographys     r   get_certificateConnection.get_certificate
       	r   F)rD  c                   g r  r   rC  s     r   rE  rF  
  rG  r   c                   [         R                  " U R                  5      nU[        R                  :w  aE  [         R
                  " U5        [        R                  " U5      nU(       a  UR                  5       $ U$ g)z
Retrieve the local certificate (if any)

:param bool as_cryptography: Controls whether a
    ``cryptography.x509.Certificate`` or an ``OpenSSL.crypto.X509``
    object should be returned.

:return: The local certificate
N)	r   SSL_get_certificaterL  rK  ru  r3  r   r4  to_cryptographyr"  rD  r?  pycerts       r   rE  rF  
  s\     ''		2499T",,T2F--//Mr   c                   g r  r   rC  s     r   get_peer_certificateConnection.get_peer_certificate
  rG  r   c                   g r  r   rC  s     r   rO  rP  
  rG  r   c                   [         R                  " U R                  5      nU[        R                  :w  a/  [
        R                  " U5      nU(       a  UR                  5       $ U$ g)z
Retrieve the other side's certificate (if any)

:param bool as_cryptography: Controls whether a
    ``cryptography.x509.Certificate`` or an ``OpenSSL.crypto.X509``
    object should be returned.

:return: The peer's certificate
N)r   SSL_get_peer_certificaterL  rK  ru  r   r4  rK  rL  s       r   rO  rP  
  sN     ,,TYY7499,,T2F--//Mr   c                P   / n[        [        R                  " U 5      5       H  n[        R                  " X5      n[	        U[
        R                  :g  5        [        R                  " U5      n[	        US:  5        [        R                  " U5      nUR                  U5        M     U$ zJ
Internal helper to convert a STACK_OF(X509) to a list of X509
instances.
r1  )r  r   sk_X509_numsk_X509_valuer  rK  ru  r3  r   r4  r<  
cert_stackrE  r  r?  r  rM  s         r   _cert_stack_to_listConnection._cert_stack_to_list
  s     t''
34A%%j4DDDII-.""4(CC1H%,,T2FMM&! 5 r   c                l   / n[        [        R                  " U 5      5       H  n[        R                  " X5      n[	        U[
        R                  :g  5        [        R                  " U5      n[	        US:  5        [        R                  " U5      nUR                  UR                  5       5        M     U$ rU  )r  r   rV  rW  r  rK  ru  r3  r   r4  r<  rK  rX  s         r    _cert_stack_to_cryptography_list+Connection._cert_stack_to_cryptography_list
  s     t''
34A%%j4DDDII-.""4(CC1H%,,T2FMM&0023 5 r   c                   g r  r   rC  s     r   get_peer_cert_chainConnection.get_peer_cert_chain
  rG  r   c                   g r  r   rC  s     r   r`  ra  
  rG  r   c                   [         R                  " U R                  5      nU[        R                  :X  a  gU(       a  U R                  U5      $ U R                  U5      $ )a;  
Retrieve the other side's certificate (if any)

:param bool as_cryptography: Controls whether a list of
    ``cryptography.x509.Certificate`` or ``OpenSSL.crypto.X509``
    object should be returned.

: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_chainrL  rK  ru  r]  rZ  r"  rD  rY  s      r   r`  ra  
  sL     11$))<
"88DD''
33r   c                   g r  r   rC  s     r   get_verified_chainConnection.get_verified_chain  rG  r   c                   g r  r   rC  s     r   rg  rh    rG  r   c                   [         R                  " U R                  5      nU[        R                  :X  a  gU(       a  U R                  U5      $ U R                  U5      $ )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.

:param bool as_cryptography: Controls whether a list of
    ``cryptography.x509.Certificate`` or ``OpenSSL.crypto.X509``
    object should be returned.

: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_chainrL  rK  ru  r]  rZ  re  s      r   rg  rh     sL    * 11$))<
"88DD''
33r   c                B    [         R                  " U R                  5      $ )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_readrL  r!  s    r   	want_readConnection.want_read=  s     !!$)),,r   c                B    [         R                  " U R                  5      $ )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_writerL  r!  s    r   
want_writeConnection.want_writeF  s     ""499--r   c                D    [         R                  " U R                  5        g)zv
Set the connection to work in server mode. The handshake will be
handled automatically by read/write.

:return: None
N)r   SSL_set_accept_staterL  r!  s    r   r  Connection.set_accept_stateO  s     	!!$)),r   c                D    [         R                  " U R                  5        g)zv
Set the connection to work in client mode. The handshake will be
handled automatically by read/write.

:return: None
N)r   r  rL  r!  s    r   r  Connection.set_connect_stateX  s     	""499-r   c                    [         R                  " U R                  5      nU[        R                  :X  a  g[
        R                  [
        5      n[        R                  " U[         R                  5      Ul	        U$ )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_sessionrL  rK  ru  r{   r  r  SSL_SESSION_freer  )r"  r(  	pysessions      r   get_sessionConnection.get_sessiona  sT     ''		2diiOOG,	!WWWd.C.CD	r   c                    [        U[        5      (       d  [        S5      e[        R                  " U R
                  UR                  5      n[        US:H  5        g)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 instancer1  N)rW  r{   rY  r   SSL_set_sessionrL  r  r  )r"  r(  rE  s      r   set_sessionConnection.set_sessionr  sE     '7++@AA%%dii1A1AB!$r   c                    [         R                  " SS5      nU" U R                  US5      nUS:X  a  g[        SU5      nU" U R                  XC5        [         R                  " XC5      S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.
r  r   N)rK  rZ  rL  r  rV  )r"  functionemptyr  rh  s        r   _get_finished_message Connection._get_finished_message  s^    2 1%		5!,19 40C&{{3%a((r   c                @    U R                  [        R                  5      $ )z
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.

.. versionadded:: 0.15
)r  r   SSL_get_finishedr!  s    r   get_finishedConnection.get_finished  s     ))$*?*?@@r   c                @    U R                  [        R                  5      $ )z
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.

.. versionadded:: 0.15
)r  r   SSL_get_peer_finishedr!  s    r   get_peer_finishedConnection.get_peer_finished  s     ))$*D*DEEr   c                    [         R                  " U R                  5      nU[        R                  :X  a  g[        R
                  " [         R                  " U5      5      nUR                  S5      $ )z
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.

.. versionadded:: 0.15
Nr  )r   SSL_get_current_cipherrL  rK  ru  r  SSL_CIPHER_get_namer  )r"  cipherr  s      r   get_cipher_nameConnection.get_cipher_name  sO     ,,TYY7TYY;;t77?@D;;w''r   c                    [         R                  " U R                  5      nU[        R                  :X  a  g[         R
                  " U[        R                  5      $ )z
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.

.. versionadded:: 0.15
N)r   r  rL  rK  ru  SSL_CIPHER_get_bits)r"  r  s     r   get_cipher_bitsConnection.get_cipher_bits  s>     ,,TYY7TYY++FDII>>r   c                    [         R                  " U R                  5      nU[        R                  :X  a  g[        R
                  " [         R                  " U5      5      nUR                  S5      $ )z
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.

.. versionadded:: 0.15
Nr  )r   r  rL  rK  ru  r  SSL_CIPHER_get_versionr  )r"  r  r  s      r   get_cipher_versionConnection.get_cipher_version  sO     ,,TYY7TYYkk$"="=f"EFG>>'**r   c                    [         R                  " [        R                  " U R                  5      5      nUR                  S5      $ )z
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.
r  )rK  r  r   SSL_get_versionrL  r  r  s     r   get_protocol_version_name$Connection.get_protocol_version_name  s0     ++d22499=>~~g&&r   c                F    [         R                  " U R                  5      nU$ )z
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.
)r   SSL_versionrL  r  s     r   get_protocol_versionConnection.get_protocol_version  s     ""499-r   c           	        U(       d  [        S5      eSR                  [        R                  " S U 5       5      5      n[        R
                  " SU5      n[        [        R                  " U R                  U[        U5      5      S:H  5        g)a8  
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   c              3  N   #    U H  n[        [        U5      45      U4v   M     g 7fr  r  r  s     r   r	  -Connection.set_alpn_protos.<locals>.<genexpr>  r  r  rU  r   N)r  r  r   r  rK  rZ  r  r   SSL_set_alpn_protosrL  r[  r  s       r   r  Connection.set_alpn_protos  ss     FGG 88FvFF
 HH.9	 	$$TYY	3x=IQN	
r   c                    [         R                  " S5      n[         R                  " S5      n[        R                  " U R                  X5        U(       d  g[         R
                  " US   US   5      S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  zunsigned int *r   r   N)rK  rZ  r   SSL_get0_alpn_selectedrL  rV  )r"  rz  data_lens      r   get_alpn_proto_negotiated$Connection.get_alpn_proto_negotiated   sZ     xx*+88,-##DIIt>{{47HQK033r   c                    [         R                  " U R                  5      nU(       d  g[        R                  " UR
                  5      $ )z
Get the SRTP protocol which was negotiated.

:returns: A bytestring of the SRTP profile name. If no profile has been
    negotiated yet, returns an empty bytestring.
r   )r   SSL_get_selected_srtp_profilerL  rK  r  r  )r"  profiles     r   get_selected_srtp_profile$Connection.get_selected_srtp_profile1  s1     44TYY?{{7<<((r   c                ~    [         R                  " U R                  [         R                  5      n[	        US:H  5        g)z
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`.
r1  N)r   SSL_set_tlsext_status_typerL  TLSEXT_STATUSTYPE_ocspr  )r"  r   s     r   request_ocspConnection.request_ocsp>  s1     ,,IIt22
 	a r   )r\  r  r  r  r  rS  rR  rO  rL  r  r  r  )r  rq   rV  zsocket.socket | Noner+  r,  )r  r5  r+  r   )rC  r   rE  r   r+  r,  )r+  rq   )r  rq   r+  r,  )r+  bytes | Noner<  r;  r8  r:  )r  r   r+  r,  )r  rX  r+  r,  )r   )rh  rX  r  r   r+  r   )r  r   r  
int | Noner+  rX  )NN)rV  r   r  r  r  r  r+  r   )r  r   rE  r   r+  typing.NoReturn)r  r   r+  rX  )rh  rX  r+  r   )r+  r  r*  )r  r   r+  r,  )r  r   r+  r   )r+  ztuple[Connection, Any])r+  r  )r+  r6  )r+  zlist[X509Name])r  r   r  r   r+  r  r=  r>  )r  r   r+  r,  )r+  rX  )r7  rX  r8  r   r  r  r+  rX  )r  r   r  r   r+  r,  )rD  typing.Literal[True]r+  zx509.Certificate | None)rD  typing.Literal[False]r+  zX509 | None)rD  ,typing.Literal[True] | typing.Literal[False]r+  zX509 | x509.Certificate | None)rY  r   r+  z
list[X509])rY  r   r+  zlist[x509.Certificate])rD  r  r+  zlist[x509.Certificate] | None)rD  r  r+  zlist[X509] | None)rD  r  r+  z*list[X509] | list[x509.Certificate] | None)r+  zSession | None)r(  r{   r+  r,  )r  zCallable[[Any, Any, int], int]r+  r  )r+  z
str | None)r+  r5  r?  )Sr   r   r   r   r   r9  r  r#  r]  rr  ru  ry  r~  rz  r  r@  rZ  r  r  r  r  r  writer  r  readr  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r"  r+  r/  r3  r=  r@  typingoverloadrE  rO  staticmethodrZ  r]  r`  rg  rn  rr  r  r  r}  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r   r   r   rp   rp   D  s    < 
 @D:-:-(<:-	:-x
/3#j !$ =AHH#9H	H,3#080)17 +4 E:+" D
 " 	(( ( 	(
 
(T#$+0*		1<8
* 54$ 7$:	
0
0B,, ," @D**"%*0<*	*@6 __"6	  
 __:?"7	  IN F 
(	. __"6	  
 __:?"7	  IN F 
(	,   	 " __"6	& 
 __:?"7	  IN4 F4 
4	4. __"6	& 
 __:?"7	  IN4 F4 
4	4:-.-."%!)6!)	!)F	A	F( ?+ 	' 
D4")
!r   )r  r   r+  r   )r  r   r+  rX  )r  r   r  r5  r+  zCallable[[_T], _T])
__future__r   r  rV  r  r:  collections.abcr   rh  r   	functoolsr   r   	itertoolsr   r	   sysr
   r   r   r   r   weakrefr   cryptographyr   )cryptography.hazmat.primitives.asymmetricr   OpenSSL._utilr   r7  r   _exception_from_error_queuer   rK  r   r   r   _make_assertr   r  r   r  r   rb  OpenSSL.cryptor   r   r   r   r   r   r    r!   __all__r,   r  r+   r(   r*   r)   r'   rT   rQ   rS   rR   rP   SSL_SENT_SHUTDOWNrF   SSL_RECEIVED_SHUTDOWNrE   rz   r   r}   r~   rj   rk   ri   r#   r$   r"   rO   rh   re   rf   rg   SSL_OP_NO_SSLv2rs   SSL_OP_NO_SSLv3rt   SSL_OP_NO_TLSv1ru   SSL_OP_NO_TLSv1_1rv   SSL_OP_NO_TLSv1_2rw   SSL_OP_NO_TLSv1_3rx   SSL_MODE_RELEASE_BUFFERSr%   SSL_OP_SINGLE_DH_USEr>   SSL_OP_SINGLE_ECDH_USEr?   SSL_OP_EPHEMERAL_RSAr1   SSL_OP_MICROSOFT_SESS_ID_BUGr3   SSL_OP_NETSCAPE_CHALLENGE_BUGr6   'SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUGr8   "SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUGrA   !SSL_OP_MICROSOFT_BIG_SSLV3_BUFFERr2   SSL_OP_MSIE_SSLV2_RSA_PADDINGr4   SSL_OP_SSLEAY_080_CLIENT_DH_BUGr@   SSL_OP_TLS_D5_BUGrC   SSL_OP_TLS_BLOCK_PADDING_BUGrB   "SSL_OP_DONT_INSERT_EMPTY_FRAGMENTSr0   SSL_OP_CIPHER_SERVER_PREFERENCEr.   SSL_OP_TLS_ROLLBACK_BUGrD   SSL_OP_PKCS1_CHECK_1r<   SSL_OP_PKCS1_CHECK_2r=   SSL_OP_NETSCAPE_CA_DN_BUGr5   &SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUGr7   SSL_OP_NO_COMPRESSIONr9   SSL_OP_NO_QUERY_MTUr:   SSL_OP_COOKIE_EXCHANGEr/   SSL_OP_NO_TICKETr;   SSL_OP_NO_RENEGOTIATIONr   r<  rZ  SSL_OP_IGNORE_UNEXPECTED_EOFr   SSL_OP_LEGACY_SERVER_CONNECTr   
SSL_OP_ALLr-   SSL_VERIFY_PEERro   SSL_VERIFY_FAIL_IF_NO_PEER_CERTrm   SSL_VERIFY_CLIENT_ONCErl   SSL_VERIFY_NONErn   SSL_SESS_CACHE_OFFrM   SSL_SESS_CACHE_CLIENTrH   SSL_SESS_CACHE_SERVERrN   SSL_SESS_CACHE_BOTHrG   SSL_SESS_CACHE_NO_AUTO_CLEARrI   !SSL_SESS_CACHE_NO_INTERNAL_LOOKUPrK    SSL_SESS_CACHE_NO_INTERNAL_STORErL   SSL_SESS_CACHE_NO_INTERNALrJ   rc   rb   rd   r]   rZ   r^   r`   rW   r_   ra   rV   rU   rY   rX   r\   r[   r   r   r&   UnionListrX  ro  r  r  r  _OCSPClientCallback_OCSPServerCallbackr   _PassphraseCallbackrO  r   r  r  r  r  r;  rr   r&  r  r   r   r   r   r|   r  r.  rR  rq  r  r  r  r  r  ry   r  r  rF  r{   rq   rp   r   r   r   <module>r     sD   " 	    $  $ "  3 3 '  8	 	 	dN #99  9++ +)) )-- # -##S #-- # - "
"&&.. 
    %%c %%%c %)) ))) ))) )''S '''S '''S '++s +++s +++s + 99 c 911 # 155 C 511 # 1 $ A A # A!%!C!C 3 C00 $S  '+&M&M  M%)%K%K s K!%!C!C 3 C#'#G#G S G++s + $ A A # A&*&M&M  M#'#G#G S G77 S 7,, 11 # 1!;; s ;// #C  33 3 3// /55 C 5))c )	#;;;NN()	$($E$EcENN-.	$($E$EcENN-. oo ''S '#'#G#G S G55 C 5''S '-- -33 3 333 3 3// / $ A A # A%)%K%K s K$($I$I c I"==  =)) )''s '##S ###S ###S ###S #%%c %%%c %// 3 /11 C 111 C 111 C 133 S 333 S 3"99  9!77 s 7T]	 	 34  V[[')@@A 		
  #L>5#89  ,!6!<= eXb\BDHI hrl;UBC T8B<8%?@ L$S#>DEgL gLV    "I "L I  :EB u%	E 		U 		% 		e 		5 	( (8%
, %
P:
0 :
z@I 8 @IF8I 8 8Iv
$< 
.
": 
&(3 !2 "D+Q/1L 
	 	C
 C
L D! D!}2  		  		  		s6   $^ 9$^ $^ ^^^^^('^(