
    f8                       d dl Z d dlZd dlmZ d dlmZmZ d dlmZm	Z	 d dl
mZ d dlmZ d dlmZmZmZmZmZmZmZmZ d dlm Z m!Z!m"Z"m#Z#m$Z$m%Z% g d	Z&ejN                  Z'ejP                  xZ(Z)ejT                  xZ*Z+ejX                  xZ,Z-ej\                  xZ.Z/ej`                  xZ0Z1ejd                  Z3ejh                  Z5d
Z6dZ7dZ8dZ9dZ:dZ;dZ<dZ=dZ>dZ?	 ej                  Z@ej                  ZAej                  ZBej                  ZCej                  ZDej                  ZGej                  ZIej                  ZKej                  ZMej                  ZO	 ej                  ZQe&j                  d       ej                  ZTej                  ZVej                  ZXej                  ZZej                  Z\ej                  Z^ej                  Z`ej                  Zbej                  Zdej                  Zfej                  Zhej                  Zjej                  Zlej                  Znej                  Zpej                  Zrej                  Ztej                  Zvej                  Zxej                  Zzej                  Z|ej                  Z~ej                  Zej                  Z	 ej                  Ze&j                  d       	 ej
                  Ze&j                  d       ej                  Zej                  Zej                  Zej                  Zej                  Zej"                  Zej&                  Zej*                  Zej.                  Zej2                  Zej6                  Zej:                  Zej>                  ZejB                  ZejD                  ZejF                  ZejH                  ZejJ                  ZejL                  ZejN                  ZejP                  ZejR                  ZejT                  ZejV                  ZejX                  ZejZ                  Zej\                  Zej^                  Zej`                  Z G d d      Zg dZdgZd Zd!Z G d" d#e      Z eee      Z ee      Z G d$ d%e      Z G d& d'e      Z G d( d)e      Z G d* d+e      Z G d, d-e      Z G d. d/      Z G d0 d1e      Z e       Z G d2 d3e      Z G d4 d5e      Z G d6 d7e      Z G d8 d9e      Z G d: d;e      Zd< Zd= ZeZd> Z eej                  d?      Z e eed@d      dA      Z G dB dC      Z G dD dE      Z G dF dG      Zy# eE$ r dZ@dZAdZBdZCdZDY Nw xY w# eE$ r Y  w xY w# eE$ r Y w xY w# eE$ r Y w xY w)H    N)	errorcode)partialwraps)chaincount)platform)WeakValueDictionary)UNSPECIFIEDexception_from_error_queueffilibmake_assertno_zero_allocator
path_bytestext_to_bytes_and_warn)FILETYPE_PEMPKeyX509X509Name	X509Store_PassphraseHelper)bOPENSSL_VERSION_NUMBERSSLEAY_VERSIONSSLEAY_CFLAGSSSLEAY_PLATFORM
SSLEAY_DIRSSLEAY_BUILT_ONOPENSSL_VERSIONOPENSSL_CFLAGSOPENSSL_PLATFORMOPENSSL_DIROPENSSL_BUILT_ONSENT_SHUTDOWNRECEIVED_SHUTDOWNSSLv23_METHODTLSv1_METHODTLSv1_1_METHODTLSv1_2_METHOD
TLS_METHODTLS_SERVER_METHODTLS_CLIENT_METHODDTLS_METHODDTLS_SERVER_METHODDTLS_CLIENT_METHODSSL3_VERSIONTLS1_VERSIONTLS1_1_VERSIONTLS1_2_VERSIONTLS1_3_VERSIONOP_NO_SSLv2OP_NO_SSLv3OP_NO_TLSv1OP_NO_TLSv1_1OP_NO_TLSv1_2MODE_RELEASE_BUFFERSOP_SINGLE_DH_USEOP_SINGLE_ECDH_USEOP_EPHEMERAL_RSAOP_MICROSOFT_SESS_ID_BUGOP_NETSCAPE_CHALLENGE_BUG#OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUGOP_SSLREF2_REUSE_CERT_TYPE_BUGOP_MICROSOFT_BIG_SSLV3_BUFFEROP_MSIE_SSLV2_RSA_PADDINGOP_SSLEAY_080_CLIENT_DH_BUGOP_TLS_D5_BUGOP_TLS_BLOCK_PADDING_BUGOP_DONT_INSERT_EMPTY_FRAGMENTSOP_CIPHER_SERVER_PREFERENCEOP_TLS_ROLLBACK_BUGOP_PKCS1_CHECK_1OP_PKCS1_CHECK_2OP_NETSCAPE_CA_DN_BUG"OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUGOP_NO_COMPRESSIONOP_NO_QUERY_MTUOP_COOKIE_EXCHANGEOP_NO_TICKETOP_ALLVERIFY_PEERVERIFY_FAIL_IF_NO_PEER_CERTVERIFY_CLIENT_ONCEVERIFY_NONESESS_CACHE_OFFSESS_CACHE_CLIENTSESS_CACHE_SERVERSESS_CACHE_BOTHSESS_CACHE_NO_AUTO_CLEARSESS_CACHE_NO_INTERNAL_LOOKUPSESS_CACHE_NO_INTERNAL_STORESESS_CACHE_NO_INTERNALSSL_ST_CONNECTSSL_ST_ACCEPTSSL_ST_MASKSSL_CB_LOOPSSL_CB_EXITSSL_CB_READSSL_CB_WRITESSL_CB_ALERTSSL_CB_READ_ALERTSSL_CB_WRITE_ALERTSSL_CB_ACCEPT_LOOPSSL_CB_ACCEPT_EXITSSL_CB_CONNECT_LOOPSSL_CB_CONNECT_EXITSSL_CB_HANDSHAKE_STARTSSL_CB_HANDSHAKE_DONEErrorWantReadErrorWantWriteErrorWantX509LookupErrorZeroReturnErrorSysCallErrorNO_OVERLAPPING_PROTOCOLSSSLeay_versionSessionContext
ConnectionX509VerificationCodes                  	   
         i   i  i  i  i  OP_NO_TLSv1_3OP_NO_RENEGOTIATIONOP_IGNORE_UNEXPECTED_EOFc                   h   e Zd ZdZej
                  Zej                  Zej                  Z
ej                  Zej                  Zej                  Zej"                  Zej&                  Zej*                  Zej.                  Zej2                  Zej6                  Zej:                  Zej>                  Z ejB                  Z"ejF                  Z$ejJ                  Z&ejN                  Z(ejR                  Z*ejV                  Z,ejZ                  Z.ej^                  Z0ejb                  Z2ejf                  Z4ejj                  Z6ejn                  Z8ejr                  Z:ejv                  Z<ejz                  Z>ej~                  Z@ej                  ZBej                  ZDej                  ZFej                  ZHej                  ZJej                  ZLej                  ZNej                  ZPej                  ZRej                  ZTej                  ZVej                  ZXej                  ZZej                  Z\ej                  Z^ej                  Z`ej                  Zbej                  Zdej                  Zfej                  Zhej                  Zjej                  Zlej                  Znej                  Zpej                  Zrej                  Ztej                  Zvy)ry   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.
    N)w__name__
__module____qualname____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_VERIFICATION     -/usr/lib/python3/dist-packages/OpenSSL/SSL.pyry   ry      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   ry   )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                       e Zd ZdZy)rn   z4
    An error occurred in an `OpenSSL.SSL` API.
    Nr   r   r   r   r   r   r  rn   rn   |  s    r   rn   c                       e Zd Zy)ro   Nr   r   r   r   r   r  ro   ro         r   ro   c                       e Zd Zy)rp   Nr  r   r   r  rp   rp     r  r   rp   c                       e Zd Zy)rq   Nr  r   r   r  rq   rq     r  r   rq   c                       e Zd Zy)rr   Nr  r   r   r  rr   rr     r  r   rr   c                       e Zd Zy)rs   Nr  r   r   r  rs   rs     r  r   rs   c                       e Zd ZdZd Zd Zy)_CallbackExceptionHelpera  
    A base class for wrapper classes that allow for intelligent exception
    handling in OpenSSL callbacks.

    :ivar list _problems: Any exceptions that occurred while executing in a
        context where they could not be raised in the normal way.  Typically
        this is because OpenSSL has called into some Python code and requires a
        return value.  The exceptions are saved to be raised later when it is
        possible to do so.
    c                     g | _         y N)	_problemsselfs    r  __init__z!_CallbackExceptionHelper.__init__  s	    r   c                     | j                   r&	 t                | j                   j                  d      y# t        $ r Y 'w xY w)z
        Raise an exception from the OpenSSL error queue or that was previously
        captured whe running a callback.
        r   N)r  _raise_current_errorrn   popr  s    r  raise_if_problemz)_CallbackExceptionHelper.raise_if_problem  sF    
 >>$& ..$$Q''   s   
4 	A A N)r   r   r   r   r  r  r   r   r  r  r    s    	
(r   r  c                       e Zd ZdZd Zy)_VerifyHelperz^
    Wrap a callback such that it can be used as a certificate verification
    callback.
    c                      t         j                          t               fd       }t        j                  d|       _        y )Nc                    t        j                  |      }t        j                  |       t        j                  |      }t        j
                  |      }t        j                  |      }t        j                         }t        j                  ||      }t        j                  |   }	  |||||       }	|	r%t        j                  |t         j                         yy# t        $ r%}
j                  j                  |
       Y d }
~
yd }
~
ww xY w)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_datarx   _reverse_mappingX509_STORE_CTX_set_errorr   	Exceptionr  append)ok	store_ctxx509certerror_numbererror_depthindexssl
connectionresultecallbackr  s              r  wrapperz'_VerifyHelper.__init__.<locals>.wrapper  s    77	BDT"**40D88CL==iHK;;=E11)UCC#44S9J!lK 11)T^^L  %%a(s   )C 	D&DDzint (*)(int, X509_STORE_CTX *)r  r  r   _ffir2  r  r2  r3  s   `` r  r  z_VerifyHelper.__init__  s>     ))$/	x	 
	2 ,g
r   Nr   r   r   r   r  r   r   r  r  r    s    

r   r  c                       e Zd ZdZd Zy)_ALPNSelectHelperzQ
    Wrap a callback such that it can be used as an ALPN selection callback.
    c                      t         j                          t               fd       }t        j                  d|       _        y )Nc                    	 t         j                  |    }t        j                  ||      d d  }g }|r)|d   }	|d|	dz    }
|j	                  |
       ||	dz   d  }|r) ||      }d}|t
        u rd}d}nt        |t              st        d      t        j                  dt        |            t        j                  d|      g|_        |j                  d   d   |d<   |j                  d   |d<   |st        j                  S t        j                  S # t        $ r5}j                   j	                  |       t        j"                  cY d }~S d }~ww xY w)	Nr   r  Tr   Fz^ALPN callback must return a bytestring or the special NO_OVERLAPPING_PROTOCOLS sentinel value.zunsigned char *unsigned char[])rx   r#  r5  bufferr&  rt   
isinstancebytes	TypeErrornewlen_alpn_select_callback_argsr   SSL_TLSEXT_ERR_NOACKSSL_TLSEXT_ERR_OKr%  r  SSL_TLSEXT_ERR_ALERT_FATAL)r.  outoutlenin_inlenargconninstr	protolistencoded_lenprotooutbytesany_acceptedr1  r2  r  s                 r  r3  z+_ALPNSelectHelper.__init__.<locals>.wrapper  s]   (7!2237
 C/2	"'(K!!kAo6E$$U+!+/"34E	  $D)4#77"H#(L#He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 B%D D 	E*EEEz^int (*)(SSL *, unsigned char **, unsigned char *, const unsigned char *, unsigned int, void *)r4  r6  s   `` r  r  z_ALPNSelectHelper.__init__  sD     ))$/	x)	7 
)	7V ? 
r   Nr7  r   r   r  r9  r9    s    5
r   r9  c                       e Zd ZdZd Zy)_OCSPServerCallbackHelpera  
    Wrap a callback such that it can be used as an OCSP callback for the server
    side.

    Annoyingly, OpenSSL defines one OCSP callback but uses it in two different
    ways. For servers, that callback is expected to retrieve some OCSP data and
    hand it to OpenSSL, and may return only SSL_TLSEXT_ERR_OK,
    SSL_TLSEXT_ERR_FATAL, and SSL_TLSEXT_ERR_NOACK. For clients, that callback
    is expected to check the OCSP data, and returns a negative value on error,
    0 if the response is not acceptable, or positive if it is. These are
    mutually exclusive return code behaviours, and they mean that we need two
    helpers so that we always return an appropriate error code if the user's
    code throws an exception.

    Given that we have to have two helpers anyway, these helpers are a bit more
    helpery than most: specifically, they hide a few more of the OpenSSL
    functions so that the user has an easier time writing these callbacks.

    This helper implements the server side.
    c                      t         j                          t               fd       }t        j                  d|       _        y )Nc                    	 t         j                  |    }|t        j                  k7  rt        j                  |      }nd } ||      }t        |t              st        d      |syt        |      }t        j                  |      }|t        j                  ||      d d  t        j                  | ||       y# t        $ r%}	j                  j                  |       Y d }~yd }~ww xY w)Nz'OCSP callback must return a bytestring.rz   r      )rx   r#  r5  NULLfrom_handler>  r?  r@  rB  r   OPENSSL_mallocr=  SSL_set_tlsext_status_ocsp_respr%  r  r&  )
r.  cdatarL  data	ocsp_dataocsp_data_lengthdata_ptrr1  r2  r  s
           r  r3  z3_OCSPServerCallbackHelper.__init__.<locals>.wrapper7  s    #!2237 DII%++E2DD %T40	!)U3#$MNN ! $'y> ../?@=FH&67:44#3  %%a(s   A$B9 (AB9 9	C'C""C'int (*)(SSL *, void *)r4  r6  s   `` r  r  z"_OCSPServerCallbackHelper.__init__4  s=     ))$/	x$	 
$	L &>Hr   Nr7  r   r   r  rT  rT    s    **Ir   rT  c                       e Zd ZdZd Zy)_OCSPClientCallbackHelpera  
    Wrap a callback such that it can be used as an OCSP callback for the client
    side.

    Annoyingly, OpenSSL defines one OCSP callback but uses it in two different
    ways. For servers, that callback is expected to retrieve some OCSP data and
    hand it to OpenSSL, and may return only SSL_TLSEXT_ERR_OK,
    SSL_TLSEXT_ERR_FATAL, and SSL_TLSEXT_ERR_NOACK. For clients, that callback
    is expected to check the OCSP data, and returns a negative value on error,
    0 if the response is not acceptable, or positive if it is. These are
    mutually exclusive return code behaviours, and they mean that we need two
    helpers so that we always return an appropriate error code if the user's
    code throws an exception.

    Given that we have to have two helpers anyway, these helpers are a bit more
    helpery than most: specifically, they hide a few more of the OpenSSL
    functions so that the user has an easier time writing these callbacks.

    This helper implements the client side.
    c                      t         j                          t               fd       }t        j                  d|       _        y )Nc                    	 t         j                  |    }|t        j                  k7  rt        j                  |      }nd }t        j
                  d      }t        j                  | |      }|dk  rd}nt        j                  |d   |      d d  } 	|||      }t        t        |            S # t        $ r%}
j                  j                  |       Y d }~yd }~ww xY w)Nunsigned char **r   r   )rx   r#  r5  rX  rY  rA  r   SSL_get_tlsext_status_ocsp_respr=  intboolr%  r  r&  )r.  r\  rL  r]  ocsp_ptrocsp_lenr^  validr1  r2  r  s            r  r3  z3_OCSPClientCallbackHelper.__init__.<locals>.wrapperz  s    !2237 DII%++E2DD  88$67??XNa< #I !%HQK B1 EI y$7 4;'' %%a(s   B*B. .	C7CCra  r4  r6  s   `` r  r  z"_OCSPClientCallbackHelper.__init__w  s<     ))$/	x	 
	< &>Hr   Nr7  r   r   r  rc  rc  a  s    *"Ir   rc  c                       e Zd Zd Zy)_CookieGenerateCallbackHelperc                      t         j                          t               fd       }t        j                  d|       _        y )Nc                     	 t         j                  |    } |      }||dt        |       t        |      |d<   y# t        $ r%}j                  j                  |       Y d }~yd }~ww xY w)Nr   r  )rx   r#  rB  r%  r  r&  )r.  rG  rH  rL  cookier1  r2  r  s         r  r3  z7_CookieGenerateCallbackHelper.__init__.<locals>.wrapper  sf    	!2237!$'-AF$Kq	 %%a(s   7; 	A)A$$A)z/int (*)(SSL *, unsigned char *, unsigned int *)r4  r6  s   `` r  r  z&_CookieGenerateCallbackHelper.__init__  s?     ))$/	x
	 

	 =
r   Nr   r   r   r  r   r   r  ro  ro    s    
r   ro  c                       e Zd Zd Zy)_CookieVerifyCallbackHelperc                      t         j                          t               fd       }t        j                  d|       _        y )Nc                     	 t         j                  |    } |t        |d|             S # t        $ r%}j                  j                  |       Y d }~yd }~ww xY wNr   )rx   r#  r?  r%  r  r&  )r.  c_cookie
cookie_lenrL  r1  r2  r  s        r  r3  z5_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)r4  r6  s   `` r  r  z$_CookieVerifyCallbackHelper.__init__  s?     ))$/	x	 
	 ;
r   Nrs  r   r   r  ru  ru    s    
r   ru  c                     d }t        | t              st        | dd       }| |       } t        | t              r| }t        |t              st        d      |dk  rt	        d|fz        |S )Nfilenoz3argument must be an int, or have a fileno() method.r   z1file descriptor cannot be a negative integer (%i))r>  ri  getattrr@  
ValueError)objfdmeths      r  _asFileDescriptorr    sv    	Bc3sHd+&C#sb#MNN	a?2%G
 	
 Ir   c                 R    t        j                  t        j                  |             S )z
    Return a string describing the version of OpenSSL in use.

    :param type: One of the :const:`OPENSSL_` constants defined in this module.
    )r5  stringr   OpenSSL_version)types    r  r  r    s     ;;t++D122r   c                       fd}|S )a  
    Builds a decorator that ensures that functions that rely on OpenSSL
    functions that are not present in this build raise NotImplementedError,
    rather than AttributeError coming out of cryptography.

    :param flag: A cryptography flag that guards the functions, e.g.
        ``Cryptography_HAS_NEXTPROTONEG``.
    :param error: The string to be used in the exception if the flag is false.
    c                 6    st        |       fd       }|S | S )Nc                      t              r  NotImplementedError)argskwargserrors     r  explodez<_make_requires.<locals>._requires_decorator.<locals>.explode  s    )%00r   )r   )funcr  r  flags     r  _requires_decoratorz+_make_requires.<locals>._requires_decorator  s(    4[1 1 NKr   r   )r  r  r  s   `` r  _make_requiresr    s    	 r   zALPN not availableCryptography_HAS_KEYLOGzKey logging not availablec                       e Zd ZdZy)rv   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
    Nr  r   r   r  rv   rv   	  s     	r   rv   c                   |   e Zd ZdZeej                  dfeej                  efe	ej                  e
feej                  efeej                  dfeej                  dfeej"                  dfeej&                  dfeej*                  dfeej.                  dfi
Zd Zd Zd Zd3dZd Zd3dZd	 Zd
 Z d Z!d Z"e#fdZ$d Z%d Z&d Z'e(fdZ)d Z*d Z+d Z,d Z-d Z.d Z/d3dZ0d Z1d Z2d Z3d Z4d Z5d Z6d Z7d  Z8d! Z9d" Z:d# Z;e<d$        Z=d% Z>d& Z?d' Z@d( ZAd) ZBd* ZCd+ ZDeEd,        ZFeEd-        ZGd. ZHd3d/ZId3d0ZJd1 ZKd2 ZLy)4rw   au  
    :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.
    Nc                    t        |t              st        d      	 | j                  |   \  }} |       }t        |t        j                  k7         t        j                  |      }t        |t        j                  k7         t        j                  |t        j                        }|| _        d | _        d | _        d | _        d | _        d | _        d | _        d | _        d | _        d | _        d | _        d | _        d | _        d | _        d | _        d | _        d | _        | j=                  t        j>                         |#| jA                  |       | jC                  |       y y # t        $ r t        d      w xY w)Nzmethod must be an integerzNo such protocol)"r>  ri  r@  _methodsKeyErrorr~  _openssl_assertr5  rX  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  zContext.__init__-  s\   &#&788	1#'==#8 K !]

dii/0"":.499,-'''4#4#45"&$(!$(!" $" $+/(#' %)" "'+$%)"d889&&w/&&w/ ;  	1/00	1s   E# #E8c                 \    t        t        j                  | j                  |      dk(         y)aD  
        Set the minimum supported protocol version. Setting the minimum
        version to 0 will enable protocol versions down to the lowest version
        supported by the library.

        If the underlying OpenSSL build is missing support for the selected
        version, this method will raise an exception.
        r  N)r  r   SSL_CTX_set_min_proto_versionr  r  r  s     r  r  zContext.set_min_proto_versionT  %     	..t}}gF!K	
r   c                 \    t        t        j                  | j                  |      dk(         y)aC  
        Set the maximum supported protocol version. Setting the maximum
        version to 0 will enable protocol versions up to the highest version
        supported by the library.

        If the underlying OpenSSL build is missing support for the selected
        version, this method will raise an exception.
        r  N)r  r   SSL_CTX_set_max_proto_versionr  r  s     r  r  zContext.set_max_proto_versiona  r  r   c                     |t         j                  }nt        |      }|t         j                  }nt        |      }t        j                  | j
                  ||      }|st                yy)aU  
        Let SSL know where we can find trusted certificates for the certificate
        chain.  Note that the certificates have to be in PEM format.

        If capath is passed, it must be a directory prepared using the
        ``c_rehash`` tool included with OpenSSL.  Either, but not both, of
        *pemfile* or *capath* may be :data:`None`.

        :param cafile: In which file we can find the certificates (``bytes`` or
            ``unicode``).
        :param capath: In which directory we can find the certificates
            (``bytes`` or ``unicode``).

        :return: None
        N)r5  rX  _path_bytesr   SSL_CTX_load_verify_locationsr  r  )r  cafilecapathload_results       r  load_verify_locationszContext.load_verify_locationsn  s_      >YYF (F>YYF (F88MM66
  " r   c                 T     t               fd       }t        t        |dd      S )Nc                 ,     | |j                         S r  )r  )sizeverifyuserdatar2  r  s      r  r3  z'Context._wrap_callback.<locals>.wrapper  s    D&$*C*CDDr   T)	more_argstruncate)r   r   r   r6  s   `` r  _wrap_callbackzContext._wrap_callback  s3    	x	E 
	E !'TD
 	
r   c                     t        |      st        d      | j                  |      | _        | j                  j                  | _        t        j                  | j                  | j
                         || _	        y)a  
        Set the passphrase callback.  This function will be called
        when a private key with a passphrase is loaded.

        :param callback: The Python callback to use.  This must accept three
            positional arguments.  First, an integer giving the maximum length
            of the passphrase it may return.  If the returned passphrase is
            longer than this, it will be truncated.  Second, a boolean value
            which will be true if the user should be prompted for the
            passphrase twice and the callback should verify that the two values
            supplied are equal. Third, the value given as the *userdata*
            parameter to :meth:`set_passwd_cb`.  The *callback* must return
            a byte string. If an error occurs, *callback* should return a false
            value (e.g. an empty string).
        :param userdata: (optional) A Python object which will be given as
                         argument to the callback
        :return: None
        callback must be callableN)
callabler@  r  r  r2  r  r   SSL_CTX_set_default_passwd_cbr  r  )r  r2  r  s      r  set_passwd_cbzContext.set_passwd_cb  sf    & !788"&"5"5h"?$($;$;$D$D!**MM444	
 %-!r   c                 T   t        j                  | j                        }t        |dk(         t	        j
                  t        j                               j                  d      }t	        j
                  t        j                               j                  d      }| j                  ||      s}t	        j
                  t        j                               }t	        j
                  t        j                               }|t        k(  r%|t        k(  r| j                  t        t                yyyy)a  
        Specify that the platform provided CA certificates are to be used for
        verification purposes. This method has some caveats related to the
        binary wheels that cryptography (pyOpenSSL's primary dependency) ships:

        *   macOS will only load certificates using this method if the user has
            the ``openssl@1.1`` `Homebrew <https://brew.sh>`_ formula installed
            in the default location.
        *   Windows will not work.
        *   manylinux1 cryptography wheels will work on most common Linux
            distributions in pyOpenSSL 17.1.0 and above.  pyOpenSSL detects the
            manylinux1 wheel and attempts to load roots via a fallback path.

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

&/ 	 ''\B++d&D&D&FGK;;t'F'F'HIL
 == $CC 33/1L D > Cr   c                     t         j                  j                  |      duxs! t         j                  j                  |      duS )zp
        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  zContext._check_env_vars_set  s8     JJNN<(4 7zz~~k*$6	
r   c                     |D ]4  }t         j                  j                  |      s#| j                  |        n |D ]5  }t         j                  j	                  |      s#| j                  d|        y y)aW  
        Default verify paths are based on the compiled version of OpenSSL.
        However, when pyca/cryptography is compiled as a manylinux1 wheel
        that compiled location can potentially be wrong. So, like Go, we
        will try a predefined set of paths and attempt to load roots
        from there.

        :return: None
        N)r  pathisfiler  isdir)r  	file_pathdir_pathr  r  s        r  r  z&Context._fallback_default_verify_paths  sh       	Fww~~f%**62	
  	Fww}}V$**48	r   c                 t    t        |      }t        j                  | j                  |      }|st	                yy)z
        Load a certificate chain from a file.

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

        :return: None
        N)r  r   "SSL_CTX_use_certificate_chain_filer  r  )r  certfiler0  s      r  use_certificate_chain_filez"Context.use_certificate_chain_file  s7     x(88MM8
  " r   c                     t        |      }t        |t              st        d      t	        j
                  | j                  ||      }|st                yy)ah  
        Load a certificate from a file

        :param certfile: The name of the certificate file (``bytes`` or
            ``unicode``).
        :param filetype: (optional) The encoding of the file, which is either
            :const:`FILETYPE_PEM` or :const:`FILETYPE_ASN1`.  The default is
            :const:`FILETYPE_PEM`.

        :return: None
        filetype must be an integerN)r  r>  ri  r@  r   SSL_CTX_use_certificate_filer  r  )r  r  filetype
use_results       r  use_certificate_filezContext.use_certificate_file  sO     x((C(9::66MM8X

  " r   c                     t        |t              st        d      t        j                  | j
                  |j                        }|st                yyzs
        Load a certificate from a X509 object

        :param cert: The X509 object
        :return: None
        zcert must be an X509 instanceN)r>  r   r@  r   SSL_CTX_use_certificater  _x509r  r  r*  r  s      r  use_certificatezContext.use_certificate*  sB     $%;<<11$--L
 " r   c                     t        |t              st        d      t        j                  |j
                        }t        j                  | j                  |      }|s t        j                  |       t                yy)z
        Add certificate to chain

        :param certobj: The X509 certificate object to add to the chain
        :return: None
        z certobj must be an X509 instanceN)
r>  r   r@  r   X509_dupr  SSL_CTX_add_extra_chain_certr  	X509_freer  )r  certobjcopy
add_results       r  add_extra_chain_certzContext.add_extra_chain_cert9  s\     '4(>??}}W]]+66t}}dK
NN4  " r   c                 n    | j                   | j                   j                  t               t                y r  )r  r  rn   r  r  s    r  _raise_passphrase_exceptionz#Context._raise_passphrase_exceptionJ  s(    "".##44U;r   c                     t        |      }|t        u rt        }nt        |t              st        d      t        j                  | j                  ||      }|s| j                          yy)aR  
        Load a private key from a file

        :param keyfile: The name of the key file (``bytes`` or ``unicode``)
        :param filetype: (optional) The encoding of the file, which is either
            :const:`FILETYPE_PEM` or :const:`FILETYPE_ASN1`.  The default is
            :const:`FILETYPE_PEM`.

        :return: None
        r  N)
r  _UNSPECIFIEDr   r>  ri  r@  r   SSL_CTX_use_PrivateKey_filer  r	  )r  keyfiler  r  s       r  use_privatekey_filezContext.use_privatekey_fileP  sb     g&|##HHc*9::55MM7H

 ,,. r   c                     t        |t              st        d      t        j                  | j
                  |j                        }|s| j                          yyzs
        Load a private key from a PKey object

        :param pkey: The PKey object
        :return: None
        zpkey must be a PKey instanceN)r>  r   r@  r   SSL_CTX_use_PrivateKeyr  _pkeyr	  r  pkeyr  s      r  use_privatekeyzContext.use_privatekeyh  sH     $%:;;00

K
,,. r   c                 X    t        j                  | j                        st                yy)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_privatekeyzContext.check_privatekeyw  s!     --dmm< " =r   c                     t        j                  t        d|            }t        |t        j
                  k7         t        j                  | j                  |       y)a%  
        Load the trusted certificates that will be sent to the client.  Does
        not actually imply any of the certificates are trusted; that must be
        configured separately.

        :param bytes cafile: The path to a certificates file in PEM format.
        :return: None
        r  N)r   SSL_load_client_CA_file_text_to_bytes_and_warnr  r5  rX  SSL_CTX_set_client_CA_listr  )r  r  ca_lists      r  load_client_cazContext.load_client_ca  sE     ..#Hf5
 	499,-''w?r   c           	          t        d|      }t        t        j                  | j                  |t        |            dk(         y)aV  
        Set the session id to *buf* within which a session can be reused for
        this Context object.  This is needed when doing session resumption,
        because there is no way for a stored session to know which Context
        object it is associated with.

        :param bytes buf: The session id.

        :returns: None
        bufr  N)r  r  r   SSL_CTX_set_session_id_contextr  rB  )r  r   s     r  set_session_idzContext.set_session_id  s:     &eS1//sCHM	
r   c                 x    t        |t              st        d      t        j                  | j
                  |      S )a  
        Set the behavior of the session cache used by all connections using
        this Context.  The previously set mode is returned.  See
        :const:`SESS_CACHE_*` for details about particular modes.

        :param mode: One or more of the SESS_CACHE_* flags (combine using
            bitwise or)
        :returns: The previously set caching mode.

        .. versionadded:: 0.14
        mode must be an integer)r>  ri  r@  r   SSL_CTX_set_session_cache_moder  r  modes     r  set_session_cache_modezContext.set_session_cache_mode  s1     $$566224==$GGr   c                 @    t        j                  | j                        S )z
        Get the current session cache mode.

        :returns: The currently used cache mode.

        .. versionadded:: 0.14
        )r   SSL_CTX_get_session_cache_moder  r  s    r  get_session_cache_modezContext.get_session_cache_mode  s     224==AAr   c                    t        |t              st        d      |>d| _        d| _        t        j                  | j                  |t        j                         yt        |      st        d      t        |      | _        | j                  j                  | _        t        j                  | j                  || j                         y)a  
        Set the verification flags for this Context object to *mode* and
        specify that *callback* should be used for verification callbacks.

        :param mode: The verify mode, this should be one of
            :const:`VERIFY_NONE` and :const:`VERIFY_PEER`. If
            :const:`VERIFY_PEER` is used, *mode* can be OR:ed with
            :const:`VERIFY_FAIL_IF_NO_PEER_CERT` and
            :const:`VERIFY_CLIENT_ONCE` to further control the behaviour.
        :param callback: The optional Python verification callback to use.
            This should take five arguments: A Connection object, an X509
            object, and three integer variables, which are in turn potential
            error number, error depth and return code. *callback* should
            return True if verification passes and False otherwise.
            If omitted, OpenSSL's default verification is used.
        :return: None

        See SSL_CTX_set_verify(3SSL) for further details.
        r$  Nr  )r>  ri  r@  r  r  r   SSL_CTX_set_verifyr  r5  rX  r  r  r2  r  r'  r2  s      r  
set_verifyzContext.set_verify  s    ( $$566"&D$(D!##DMM4CH% ;<<"/"9D$($7$7$@$@D!##DMM49N9NOr   c                 z    t        |t              st        d      t        j                  | j
                  |       y)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)r>  ri  r@  r   SSL_CTX_set_verify_depthr  )r  depths     r  set_verify_depthzContext.set_verify_depth  s.     %%677%%dmmU;r   c                 @    t        j                  | j                        S )z
        Retrieve the Context object's verify mode, as set by
        :meth:`set_verify`.

        :return: The verify mode
        )r   SSL_CTX_get_verify_moder  r  s    r  get_verify_modezContext.get_verify_mode  s     ++DMM::r   c                 @    t        j                  | j                        S )z
        Retrieve the Context object's verify depth, as set by
        :meth:`set_verify_depth`.

        :return: The verify depth
        )r   SSL_CTX_get_verify_depthr  r  s    r  get_verify_depthzContext.get_verify_depth  s     ,,T]];;r   c                    t        |      }t        j                  |d      }|t        j                  k(  r
t                t        j                  |t        j                        }t        j                  |t        j                  t        j                  t        j                        }t        j                  |t        j                        }t        j                  | j                  |      }t        |dk(         y)z
        Load parameters for Ephemeral Diffie-Hellman

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

        :return: None
           rr  N)r  r   BIO_new_filer5  rX  r  r  BIO_freePEM_read_bio_DHparamsDH_freeSSL_CTX_set_tmp_dhr  r  )r  dhfilebiodhress        r  load_tmp_dhzContext.load_tmp_dh  s     V$-$)) "ggc4==)''TYY		499MWWR&%%dmmR8q!r   c                 `    t        j                  | j                  |j                                y)a
  
        Select a curve to use for ECDHE key exchange.

        :param curve: A curve object to use as returned by either
            :meth:`OpenSSL.crypto.get_elliptic_curve` or
            :meth:`OpenSSL.crypto.get_elliptic_curves`.

        :return: None
        N)r   SSL_CTX_set_tmp_ecdhr  
_to_EC_KEY)r  curves     r  set_tmp_ecdhzContext.set_tmp_ecdh  s!     	!!$--1A1A1CDr   c                    t        d|      }t        |t              st        d      t	        t        j                  | j                  |      dk(         t        | d      }|j                         g dk(  rt        dg      y)z
        Set the list of ciphers to be used in this context.

        See the OpenSSL manual for more information (e.g.
        :manpage:`ciphers(1)`).

        :param bytes cipher_list: An OpenSSL cipher string.
        :return: None
        cipher_listz"cipher_list must be a byte string.r  N)TLS_AES_256_GCM_SHA384TLS_CHACHA20_POLY1305_SHA256TLS_AES_128_GCM_SHA256)zSSL routinesSSL_CTX_set_cipher_listzno cipher match)r  r>  r?  r@  r  r   rP  r  rx   get_cipher_listrn   )r  rL  tmpconns      r  set_cipher_listzContext.set_cipher_list  s     .m[I+u-@AA((DI	
 T4(""$ )
 

  
r   c                 F   t        j                         }t        |t        j                  k7         	 |D ]  }t        |t              s"t        dt        |      j                  d      t        j                  |j                        }t        |t        j                  k7         t        j                  ||      }|rt        j                  |       t                 	 t        j"                  | j$                  |       y# t        $ r t        j                   |        w xY w)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  r5  rX  r>  r   r@  r  r   X509_NAME_dup_namesk_X509_NAME_pushX509_NAME_freer  r%  sk_X509_NAME_freer  r  )r  certificate_authorities
name_stackca_namer  push_results         r  set_client_ca_listzContext.set_client_ca_listF  s     //1

dii/0	2 +!'84#%)']%;%;>  ))'--8		 12"44ZF"''-(*+  	''zB	  	"":.	s   B
D  =!D    D c                     t        |t              st        d      t        j                  | j
                  |j                        }t        |dk(         y)ai  
        Add the CA certificate to the list of preferred signers for this
        context.

        The list of certificate authorities will be sent to the client when the
        server requests a client certificate.

        :param certificate_authority: certificate authority's X509 certificate.
        :return: None

        .. versionadded:: 0.10
        z.certificate_authority must be an X509 instancer  N)r>  r   r@  r   SSL_CTX_add_client_CAr  r  r  )r  certificate_authorityr  s      r  add_client_cazContext.add_client_cai  sI     /6LMM//MM066

 	
a(r   c                 x    t        |t              st        d      t        j                  | j
                  |      S )aQ  
        Set the timeout for newly created sessions for this Context object to
        *timeout*.  The default value is 300 seconds. See the OpenSSL manual
        for more information (e.g. :manpage:`SSL_CTX_set_timeout(3)`).

        :param timeout: The timeout in (whole) seconds
        :return: The previous session timeout
        ztimeout must be an integer)r>  ri  r@  r   SSL_CTX_set_timeoutr  )r  timeouts     r  set_timeoutzContext.set_timeout~  s1     '3'899''w??r   c                 @    t        j                  | j                        S )z
        Retrieve session timeout, as set by :meth:`set_timeout`. The default
        is 300 seconds.

        :return: The session timeout
        )r   SSL_CTX_get_timeoutr  r  s    r  get_timeoutzContext.get_timeout  s     ''66r   c                     t              fd       }t        j                  d|      | _        t	        j
                  | j                  | j                         y)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         j                  |    ||       y r  rx   r#  )r.  wherereturn_coder2  s      r  r3  z*Context.set_info_callback.<locals>.wrapper  s    Z005ukJr   zvoid (*)(const SSL *, int, int)N)r   r5  r2  r  r   SSL_CTX_set_info_callbackr  r6  s    ` r  set_info_callbackzContext.set_info_callback  sQ     
x	K 
	K #mm-w
 	&&t}}d6I6IJr   c                     t              fd       }t        j                  d|      | _        t	        j
                  | j                  | j                         y)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                 d    t        j                  |      } t        j                  |    |       y r  )r5  r  rx   r#  )r.  liner2  s     r  r3  z,Context.set_keylog_callback.<locals>.wrapper  s&    ;;t$DZ005t<r   z#void (*)(const SSL *, const char *)N)r   r5  r2  r  r   SSL_CTX_set_keylog_callbackr  r6  s    ` r  set_keylog_callbackzContext.set_keylog_callback  sO     
x	= 
	= !%17!
 	((8M8MNr   c                     | j                   S )zw
        Get the application data (supplied via :meth:`set_app_data()`)

        :return: The application data
        r  r  s    r  get_app_datazContext.get_app_data       ~~r   c                     || _         y)z
        Set the application data (will be returned from get_app_data())

        :param data: Any Python object
        :return: None
        Nrx  r  r]  s     r  set_app_datazContext.set_app_data       r   c                     t        j                  | j                        }|t        j                  k(  ryt        j                  t
              }||_        |S )z
        Get the certificate store for the context.  This can be used to add
        "trusted" certificates without using the
        :meth:`load_verify_locations` method.

        :return: A X509Store object or None if it does not have one.
        N)r   SSL_CTX_get_cert_storer  r5  rX  r   __new___store)r  storepystores      r  get_cert_storezContext.get_cert_store  sC     ++DMM:DII##I.r   c                 x    t        |t              st        d      t        j                  | j
                  |      S )z
        Add options. Options set before are not cleared!
        This method should be used with the :const:`OP_*` constants.

        :param options: The options to add.
        :return: The new option bitmask.
        zoptions must be an integer)r>  ri  r@  r   SSL_CTX_set_optionsr  )r  optionss     r  set_optionszContext.set_options  s1     '3'899''w??r   c                 x    t        |t              st        d      t        j                  | j
                  |      S )z
        Add modes via bitmask. Modes set before are not cleared!  This method
        should be used with the :const:`MODE_*` constants.

        :param mode: The mode to add.
        :return: The new mode bitmask.
        r$  )r>  ri  r@  r   SSL_CTX_set_moder  r&  s     r  r  zContext.set_mode  s1     $$566$$T]]D99r   c                     t              fd       }t        j                  d|      | _        t	        j
                  | j                  | j                         y)a  
        Specify a callback function to be called when clients specify a server
        name.

        :param callback: The callback function.  It will be invoked with one
            argument, the Connection instance.

        .. versionadded:: 0.13
        c                 8     t         j                  |           yrx  rm  )r.  alertrK  r2  s      r  r3  z7Context.set_tlsext_servername_callback.<locals>.wrapper  s    Z0056r   zint (*)(SSL *, int *, void *)N)r   r5  r2  r  r   &SSL_CTX_set_tlsext_servername_callbackr  r6  s    ` r  set_tlsext_servername_callbackz&Context.set_tlsext_servername_callback   sR     
x	 
	 ,0==+W,
( 	33MM4;;	
r   c                     t        |t              st        d      t        t	        j
                  | j                  |      dk(         y)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)r>  r?  r@  r  r   SSL_CTX_set_tlsext_use_srtpr  )r  profiless     r  set_tlsext_use_srtpzContext.set_tlsext_use_srtp  s;     (E*=>>,,T]]HEJ	
r   c           	         |st        d      dj                  t        j                  d |D                    }t	        j
                  d|      }t        t        j                  | j                  |t        |            dk(         y)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   J   K   | ]  }t        t        |      f      |f  y wr  r?  rB  .0ps     r  	<genexpr>z*Context.set_alpn_protos.<locals>.<genexpr>:        F!Ay!11 5F   !#r<  r   N)r~  joinr   from_iterabler5  rA  r  r   SSL_CTX_set_alpn_protosr  rB  r  protosprotostr	input_strs       r  set_alpn_protoszContext.set_alpn_protos&  s{     FGG 88FvFF
 HH.9	 	((y#h- 	
r   c                     t        |      | _        | j                  j                  | _        t	        j
                  | j                  | j                  t        j                         y)a  
        Specify a callback function that will be called on the server when a
        client offers protocols using ALPN.

        :param callback: The callback function.  It will be invoked with two
            arguments: the Connection, and a list of offered protocols as
            bytestrings, e.g ``[b'http/1.1', b'spdy/2']``.  It can return
            one of those bytestrings to indicate the chosen protocol, the
            empty bytestring to terminate the TLS connection, or the
            :py:obj:`NO_OVERLAPPING_PROTOCOLS` to indicate that no offered
            protocol was selected, but that the connection should not be
            aborted.
        N)	r9  r  r2  r  r   SSL_CTX_set_alpn_select_cbr  r5  rX  r  r2  s     r  set_alpn_select_callbackz Context.set_alpn_select_callbackL  sH     $5X#> %)%=%=%F%F"''MM455tyy	
r   c                 x   || _         |j                  | _        |t        j                  | _        nt        j                  |      | _        t        j                  | j                  | j                        }t        |dk(         t        j                  | j                  | j
                        }t        |dk(         y)z
        This internal helper does the common work for
        ``set_ocsp_server_callback`` and ``set_ocsp_client_callback``, which is
        almost all of it.
        Nr  )r  r2  r  r5  rX  r  
new_handler   SSL_CTX_set_tlsext_status_cbr  r  SSL_CTX_set_tlsext_status_arg)r  helperr]  rcs       r  _set_ocsp_callbackzContext._set_ocsp_callbacka  s     #$oo<"iiDO"ood3DO..MM4..
 	a //tOa r   c                 >    t        |      }| j                  ||       y)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)rT  r  r  r2  r]  r  s       r  set_ocsp_server_callbackz Context.set_ocsp_server_callbacku  s     +84-r   c                 >    t        |      }| j                  ||       y)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)rc  r  r  s       r  set_ocsp_client_callbackz Context.set_ocsp_client_callback  s    " +84-r   c                     t        |      | _        t        j                  | j                  | j                  j
                         y r  )ro  r  r   SSL_CTX_set_cookie_generate_cbr  r2  r  s     r  set_cookie_generate_callbackz$Context.set_cookie_generate_callback  s3    'DX'N$++MM((11	
r   c                     t        |      | _        t        j                  | j                  | j                  j
                         y r  )ru  r  r   SSL_CTX_set_cookie_verify_cbr  r2  r  s     r  set_cookie_verify_callbackz"Context.set_cookie_verify_callback  s3    %@%J"))MM&&//	
r   r  )Mr   r   r   r   r%   r   
TLS_methodr&   r0   r'   r1   r(   r2   r)   r*   TLS_server_methodr+   TLS_client_methodr,   DTLS_methodr-   DTLS_server_methodr.   DTLS_client_methodr  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  r6  r9  rE  rJ  rS  r_  rc  rg  rj  rq  _requires_keylogrv  ry  r}  r  r  r  r  r  _requires_alpnr  r  r  r  r  r  r  r   r   r  rw   rw     s    	.t5.9.9T__d+D22D9D22D9d&&-T44d;T44d;H%0N

#@
-:.`	
(#" 7C #,##" 5A /0/#@
"H"B!PF<;<"*
E%N!CF)*@7K, O O0"@:
.
 #
 #
J 
 
(!(.$.(

r   rw   c                      e Zd Z e       ZdFdZd Zd Zd Zd Z	d Z
dFdZd	 Zd
 Zd Zd Zd Zd Zd ZdGdZeZdGdZdFdZeZdHdZd Zd Zd Zd Zd Zd Zd Zd Z d Z!d Z"d Z#d Z$d  Z%d! Z&d" Z'd# Z(d$ Z)d% Z*d& Z+d' Z,d( Z-d) Z.d* Z/d+ Z0d, Z1d- Z2dFd.Z3d/ Z4d0 Z5d1 Z6e7d2        Z8d3 Z9d4 Z:d5 Z;d6 Z<d7 Z=d8 Z>d9 Z?d: Z@d; ZAd< ZBd= ZCd> ZDd? ZEd@ ZFdA ZGdB ZHeIdC        ZJeIdD        ZKdE ZLy)Irx   Nc                 |   t        |t              st        d      t        j                  |j
                        }t        j                  |t        j                        | _	        t        j                  | j                  t        j                         || _        d| _        d| _        |j                  | _        |j                  | _        |j                   | _        |j"                  | _        | | j$                  | j                  <   |d| _        t        j(                  t        j*                               | _        t/        | j,                  t        j0                  k7         t        j(                  t        j*                               | _        t/        | j2                  t        j0                  k7         t        j4                  | j                  | j,                  | j2                         yd| _        d| _        || _        t        j6                  | j                  t9        | j&                              }t/        |dk(         y)z
        Create a new Connection object, using the given OpenSSL.SSL.Context
        instance and socket.

        :param context: An SSL Context to use for this connection
        :param socket: The socket to use for transport layer
        "context must be a Context instanceNr  )r>  rw   r@  r   SSL_newr  r5  r  SSL_free_sslSSL_set_modeSSL_MODE_AUTO_RETRYr  rC  r  r  r  r  r#  _socketBIO_new	BIO_s_mem	_into_sslr  rX  	_from_sslSSL_set_bio
SSL_set_fdr  )r  r  socketr.  r  s        r  r  zConnection.__init__  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!DL		,T\\:J J!O,r   c                     | j                   &t        d| j                  j                  d|d      t	        | j                   |      S )zy
        Look up attributes on the wrapped socket object if they are not found
        on the Connection object.
        'z' object has no attribute ')r  AttributeError	__class__r   r}  r  names     r  __getattr__zConnection.__getattr__  sB    
 << >>**D2 
 4<<..r   c                 :   | j                   j                  $| j                   j                  j                          | j                   j                  $| j                   j                  j                          | j                   j                  $| j                   j                  j                          t        j                  ||      }|t
        j                  k(  r
t               |t
        j                  k(  r
t               |t
        j                  k(  r
t               |t
        j                  k(  r
t               |t
        j                  k(  rt        j                          dk(  rf|dk  rUt"        dk(  rt%        j&                         d   }nt$        j(                  }|dk7  rt+        |t-        j.                  |            t+        dd      t1                y |t
        j2                  k(  rt        j                          dk7  rt        j                          }t        j4                  |      }t
        j6                  r<t9        |t
        j:                  k(         t        j<                          t+        dd      t1                y |t
        j>                  k(  ry t1                y )Nr   win32rg  zUnexpected EOF) r  r  r  r  r  r   SSL_get_errorSSL_ERROR_WANT_READro   SSL_ERROR_WANT_WRITErp   SSL_ERROR_ZERO_RETURNrr   SSL_ERROR_WANT_X509_LOOKUPrq   SSL_ERROR_SYSCALLERR_peek_errorr   r5  getwinerrorerrnors   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  r.  r0  r  r  peeked_errorreasons          r  _raise_ssl_errorz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,,,""$)A:7* $ 0 0 21 5 $

z*5)--2FGG"2'788 %&d(((T-@-@-Ba-G  ..0L((6FAAdEEE $$&"2'788$&d))) "r   c                     | j                   S )zh
        Retrieve the :class:`Context` object associated with this
        :class:`Connection`.
        )r  r  s    r  get_contextzConnection.get_context+  s    
 }}r   c                     t        |t              st        d      t        j                  | j
                  |j                         || _        y)z
        Switch this connection to a new session context.

        :param context: A :class:`Context` instance giving the new session
            context to use.
        r  N)r>  rw   r@  r   SSL_set_SSL_CTXr  r  )r  r  s     r  set_contextzConnection.set_context2  s;     '7+@AATYY(8(89r   c                     t        j                  | j                  t         j                        }|t        j
                  k(  ryt	        j                  |      S )z
        Retrieve the servername extension value if provided in the client hello
        message, or None if there wasn't one.

        :return: A byte string giving the server name or :data:`None`.

        .. versionadded:: 0.13
        N)r   SSL_get_servernamer  TLSEXT_NAMETYPE_host_namer5  rX  r  r  s     r  get_servernamezConnection.get_servername?  sC     &&IIt55
 499{{4  r   c                    t        |t              st        d      |>d| _        d| _        t        j                  | j                  |t        j                         yt        |      st        d      t        |      | _        | j                  j                  | _        t        j                  | j                  || j                         y)z
        Override the Context object's verification flags for this specific
        connection. See :py:meth:`Context.set_verify` for details.
        r$  Nr  )r>  ri  r@  r  r  r   SSL_set_verifyr  r5  rX  r  r  r2  r.  s      r  r/  zConnection.set_verifyP  s    
 $$566"&D$(D!		4;H% ;<<"/"9D$($7$7$@$@D!		41F1FGr   c                 @    t        j                  | j                        S )z
        Retrieve the Connection object's verify mode, as set by
        :meth:`set_verify`.

        :return: The verify mode
        )r   SSL_get_verify_moder  r  s    r  r6  zConnection.get_verify_moded  s     ''		22r   c                     t        |t              st        d      t        j                  | j
                  |j                        }|st                yyr  )r>  r   r@  r   SSL_use_certificater  r  r  r  s      r  r  zConnection.use_certificatem  sB     $%;<<--diiD
 " r   c                     t        |t              st        d      t        j                  | j
                  |j                        }|s| j                  j                          yyr  )	r>  r   r@  r   SSL_use_PrivateKeyr  r  r  r	  r  s      r  r  zConnection.use_privatekey|  sL     $%:;;,,TYY

C
MM557 r   c                 D    t        j                  | j                  |       y)aK  
        For DTLS, set the maximum UDP payload size (*not* including IP/UDP
        overhead).

        Note that you might have to set :data:`OP_NO_QUERY_MTU` to prevent
        OpenSSL from spontaneously clearing this.

        :param mtu: An integer giving the maximum transmission unit.

        .. versionadded:: 21.1
        N)r   SSL_set_mtur  )r  mtus     r  set_ciphertext_mtuzConnection.set_ciphertext_mtu  s     	C(r   c                 v    t        t        d      st        d      t        j                  | j                        S )a
  
        For DTLS, get the maximum size of unencrypted data you can pass to
        :meth:`write` without exceeding the MTU (as passed to
        :meth:`set_ciphertext_mtu`).

        :return: The effective MTU as an integer.

        .. versionadded:: 21.1
        DTLS_get_data_mtuz requires OpenSSL 1.1.1 or better)hasattrr   r  r  r  r  s    r  get_cleartext_mtuzConnection.get_cleartext_mtu  s0     t01%&HII%%dii00r   c                     t        |t              st        d      d|v rt        d      t        j                  | j
                  |       y)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)r>  r?  r@  r   SSL_set_tlsext_host_namer  r  s     r  set_tlsext_host_namezConnection.set_tlsext_host_name  sC     $&899d]<== 	%%dii6r   c                 @    t        j                  | j                        S )z
        Get the number of bytes that can be safely read from the SSL buffer
        (**not** the underlying transport buffer).

        :return: The number of bytes available in the receive buffer.
        )r   SSL_pendingr  r  s    r  pendingzConnection.pending  s     		**r   c                 2   t        d|      }t        j                  |      5 }t        |      dkD  rt	        d      t        j                  | j                  |t        |            }| j                  | j                  |       |cddd       S # 1 sw Y   yxY w)a  
        Send data on the connection. NOTE: If you get one of the WantRead,
        WantWrite or WantX509Lookup exceptions on this, you have to call the
        method again with the SAME buffer.

        :param buf: The string, buffer or memoryview to send
        :param flags: (optional) Included for compatibility with the socket
                      API, the value is ignored
        :return: The number of bytes written
        r   z,Cannot send more than 2**31-1 bytes at once.N)	r  r5  from_bufferrB  r~  r   	SSL_writer  r  )r  r   flagsr]  r0  s        r  sendzConnection.send  s     &eS1c" 
	d3x*$ B  ^^DIItSY?F!!$))V4
	 
	 
	s   A!BBc           	      @   t        d|      }t        j                  |      5 }t        |      }d}|rWt	        j
                  | j                  ||z   t        |d            }| j                  | j                  |       ||z  }||z  }|rW|cddd       S # 1 sw Y   yxY w)a  
        Send "all" data on the connection. This calls send() repeatedly until
        all data is sent. If an error occurs, it's impossible to tell how much
        data has been sent.

        :param buf: The string, buffer or memoryview to send
        :param flags: (optional) Included for compatibility with the socket
                      API, the value is ignored
        :return: The number of bytes written
        r   r   r  N)	r  r5  r  rB  r   r  r  minr  )r  r   r  r]  left_to_send
total_sentr0  s          r  sendallzConnection.sendall  s     &eS1c" 	ds8LJ IItj0#lJ2O %%dii8f$
&  	 	 	s   A&B	BBc                 4   t        d|      }|5|t        j                  z  r"t        j                  | j
                  ||      }n!t        j                  | j
                  ||      }| j                  | j
                  |       t        j                  ||      dd S )a  
        Receive data on the connection.

        :param bufsiz: The maximum number of bytes to read
        :param flags: (optional) The only supported flag is ``MSG_PEEK``,
            all other flags are ignored.
        :return: The string read from the Connection
        char[]N)
_no_zero_allocatorr  MSG_PEEKr   SSL_peekr  SSL_readr  r5  r=  )r  bufsizr  r   r0  s        r  recvzConnection.recv  sw     !62!8]]499c6:F]]499c6:Fdii0{{3'**r   c                    |t        |      }nt        |t        |            }t        d|      }|5|t        j                  z  r"t        j                  | j                  ||      }n!t        j                  | j                  ||      }| j                  | j                  |       t        t        j                  ||            |d| |S )ae  
        Receive data on the connection and copy it directly into the provided
        buffer, rather than creating a new string.

        :param buffer: The buffer to copy into.
        :param nbytes: (optional) The maximum number of bytes to read into the
            buffer. If not present, defaults to the size of the buffer. If
            larger than the size of the buffer, is reduced to the size of the
            buffer.
        :param flags: (optional) The only supported flag is ``MSG_PEEK``,
            all other flags are ignored.
        :return: The number of bytes read into the buffer.
        Nr  )rB  r  r  r  r  r   r  r  r   r  
memoryviewr5  r=  )r  r=  nbytesr  r   r0  s         r  	recv_intozConnection.recv_into  s     >[FV-F
 !62!8]]499c6:F]]499c6:Fdii0 %T[[f%=>wr   c                    t        j                  |      rit        j                  |      r
t               t        j                  |      r
t               t        j                  |      rt        d      t        d      t                y )NBIO_should_io_specialzunknown bio failure)	r   BIO_should_retryBIO_should_readro   BIO_should_writerp   r(  r~  r  )r  rB  r0  s      r  _handle_bio_errorszConnection._handle_bio_errors2  so      %##C(#o%&&s+$&&++C0 !!899 !!677 !"r   c                 4   | j                   t        d      t        |t              st        d      t	        d|      }t        j                  | j                   ||      }|dk  r| j                  | j                   |       t        j                  ||      dd S )a  
        If the Connection was created with a memory BIO, this method can be
        used to read bytes from the write end of that memory BIO.  Many
        Connection methods will add bytes which must be read in this manner or
        the buffer will eventually fill up and the Connection will be able to
        take no further actions.

        :param bufsiz: The maximum number of bytes to read
        :return: The string read.
        NConnection sock was not Nonezbufsiz must be an integerr  r   )
r  r@  r>  ri  r  r   BIO_readr,  r5  r=  )r  r!  r   r0  s       r  bio_readzConnection.bio_readD  s     >>!:;;&#&788 62t~~sF;Q;##DNNF;{{3'**r   c                 8   t        d|      }| j                  t        d      t        j                  |      5 }t        j                  | j                  |t        |            }|dk  r| j                  | j                  |       |cddd       S # 1 sw Y   yxY w)aj  
        If the Connection was created with a memory BIO, this method can be
        used to add bytes to the read end of that memory BIO.  The Connection
        can then read the bytes (for example, in response to a call to
        :meth:`recv`).

        :param buf: The string to put into the memory BIO.
        :return: The number of bytes written
        r   Nr.  r   )	r  r  r@  r5  r  r   	BIO_writerB  r,  )r  r   r]  r0  s       r  	bio_writezConnection.bio_write\  s     &eS1>>!:;;c" 	d^^DNND#d)DF{''?		 	 	s   ABBc                 |    | j                         s,t        t        j                  | j                        dk(         yy)z
        Renegotiate the session.

        :return: True if the renegotiation can be started, False otherwise
        :rtype: bool
        r  TF)renegotiate_pendingr  r   SSL_renegotiater  r  s    r  renegotiatezConnection.renegotiateq  s2     '')D00;q@Ar   c                 z    t        j                  | j                        }| j                  | j                  |       y)a  
        Perform an SSL handshake (usually called after :meth:`renegotiate` or
        one of :meth:`set_accept_state` or :meth:`set_connect_state`). This can
        raise the same exceptions as :meth:`send` and :meth:`recv`.

        :return: None.
        N)r   SSL_do_handshaker  r  r  r0  s     r  do_handshakezConnection.do_handshake}  s,     &&tyy1dii0r   c                 F    t        j                  | j                        dk(  S )z
        Check if there's a renegotiation in progress, it will return False once
        a renegotiation is finished.

        :return: Whether there's a renegotiation in progress
        :rtype: bool
        r  )r   SSL_renegotiate_pendingr  r  s    r  r5  zConnection.renegotiate_pending  s     ++DII6!;;r   c                 @    t        j                  | j                        S )z
        Find out the total number of renegotiations.

        :return: The number of renegotiations.
        :rtype: int
        )r   SSL_total_renegotiationsr  r  s    r  total_renegotiationszConnection.total_renegotiations  s     ,,TYY77r   c                 v    t        j                  | j                         | j                  j	                  |      S )a4  
        Call the :meth:`connect` method of the underlying socket and set up SSL
        on the socket, using the :class:`Context` object supplied to this
        :class:`Connection` object at creation.

        :param addr: A remote address
        :return: What the socket's connect method returns
        )r   SSL_set_connect_stater  r  connect)r  addrs     r  rC  zConnection.connect  s+     	""499-||##D))r   c                 ^    | j                   j                  }| j                           ||      S )a  
        Call the :meth:`connect_ex` method of the underlying socket and set up
        SSL on the socket, using the Context object supplied to this Connection
        object at creation. Note that if the :meth:`connect_ex` method of the
        socket doesn't return 0, SSL won't be initialized.

        :param addr: A remove address
        :return: What the socket's connect_ex method returns
        )r  
connect_exset_connect_state)r  rD  rF  s      r  rF  zConnection.connect_ex  s*     \\,,
 $r   c                     | j                   j                         \  }}t        | j                  |      }|j	                          ||fS )a  
        Call the :meth:`accept` method of the underlying socket and set up SSL
        on the returned socket, using the Context object supplied to this
        :class:`Connection` object at creation.

        :return: A *(conn, addr)* pair where *conn* is the new
            :class:`Connection` object created, and *address* is as returned by
            the socket's :meth:`accept`.
        )r  acceptrx   r  set_accept_state)r  clientrD  rL  s       r  rI  zConnection.accept  s@     ||**,$--0d|r   c                    t        j                         }	 t        j                  | j                  |      }t        j                  |       | j
                  | j
                  j                          | j                  | j                  j                          |dk(  r
t               |dk  r| j                  | j                  |       yy# t        j                  |       w xY w)z
        Call the OpenSSL function DTLSv1_listen on this connection. See the
        OpenSSL manual for more details.

        :return: None
        Nr   )
r   BIO_ADDR_newDTLSv1_listenr  BIO_ADDR_freer  r  r  ro   r  )r  bio_addrr0  s      r  rN  zConnection.DTLSv1_listen  s     $$&	)''		8<Fx(
 ''3((99;%%1&&779Q;/!A:!!$))V4  x(s    C	 	C c                     t        j                  d      }t        j                  d      }t        j                  | j                  ||      r|d   |d   dz  z   S y)a}  
        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)r5  rA  r   Cryptography_DTLSv1_get_timeoutr  )r  ptv_secptv_usecs      r  DTLSv1_get_timeoutzConnection.DTLSv1_get_timeout  sQ     ((:&88H%//		7HM1:!w!677r   c                     t        j                  | j                        }|dk  r| j                  | j                  |       yt	        |      S )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   N)r   DTLSv1_handle_timeoutr  r  rj  r:  s     r  rW  z Connection.DTLSv1_handle_timeout  s=     ++DII6A:!!$))V4<r   c                 r    | j                   t        d      t        j                  | j                  d       y)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   )r  r@  r   BIO_set_mem_eof_returnr  r  s    r  bio_shutdownzConnection.bio_shutdown  s.     >>!:;;##DNNA6r   c                     t        j                  | j                        }|dk  r| j                  | j                  |       y|dkD  ryy)aQ  
        Send the shutdown message to the Connection.

        :return: True if the shutdown completed successfully (i.e. both sides
                 have sent closure alerts), False otherwise (in which case you
                 call :meth:`recv` or :meth:`send` when the connection becomes
                 readable/writeable).
        r   TFN)r   SSL_shutdownr  r  r:  s     r  shutdownzConnection.shutdown
	  s@     ""499-A:!!$))V4aZr   c                     g }t               D ]k  }t        j                  | j                  |      }|t        j
                  k(  r |S |j                  t	        j                  |      j                  d             m |S )z
        Retrieve the list of ciphers used by the Connection object.

        :return: A list of native cipher strings.
        utf-8)	r   r   SSL_get_cipher_listr  r5  rX  r&  r  r  )r  ciphersir0  s       r  rQ  zConnection.get_cipher_list	  so      	@A--dii;F" NN4;;v.55g>?		@
 r   c                    t        j                  | j                        }|t        j                  k(  rg S g }t        t        j                  |            D ]  }t        j                  ||      }t        j                  |      }t        |t        j                  k7         t        j                  t              }t        j                  |t         j                        |_        |j                  |        |S )a  
        Get CAs whose certificates are suggested for client authentication.

        :return: If this is a server connection, the list of certificate
            authorities that will be sent or has been sent to the client, as
            controlled by this :class:`Connection`'s :class:`Context`.

            If this is a client connection, the list will be empty until the
            connection with the server is established.

        .. versionadded:: 0.10
        )r   SSL_get_client_CA_listr  r5  rX  rangesk_X509_NAME_numsk_X509_NAME_valuerV  r  r   r  r  rY  rW  r&  )r  ca_namesr0  rb  r  r  pynames          r  get_client_ca_listzConnection.get_client_ca_list)	  s     ..tyy9tyy It,,X67 	"A**8Q7D%%d+DDDII-.%%h/F774)<)<=FLMM&!	" r   c                     t        d      )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  makefilezConnection.makefileF	  s     "?
 	
r   c                     | j                   S )zr
        Retrieve application data as set by :meth:`set_app_data`.

        :return: The application data
        rx  r  s    r  ry  zConnection.get_app_dataQ	  rz  r   c                     || _         y)zg
        Set application data

        :param data: The application data
        :return: None
        Nrx  r|  s     r  r}  zConnection.set_app_dataY	  r~  r   c                 @    t        j                  | j                        S )z
        Get the shutdown state of the Connection.

        :return: The shutdown state, a bitvector of SENT_SHUTDOWN,
            RECEIVED_SHUTDOWN.
        )r   SSL_get_shutdownr  r  s    r  get_shutdownzConnection.get_shutdownb	  s     $$TYY//r   c                 z    t        |t              st        d      t        j                  | j
                  |       y)z
        Set the shutdown state of the Connection.

        :param state: bitvector of SENT_SHUTDOWN, RECEIVED_SHUTDOWN.
        :return: None
        zstate must be an integerN)r>  ri  r@  r   SSL_set_shutdownr  )r  states     r  set_shutdownzConnection.set_shutdownk	  s.     %%677dii/r   c                 f    t        j                  t        j                  | j                              S )z
        Retrieve a verbose string detailing the state of the Connection.

        :return: A string representing the state
        :rtype: bytes
        )r5  r  r   SSL_state_string_longr  r  s    r  get_state_stringzConnection.get_state_stringw	  s"     {{455dii@AAr   c                 n   t        j                  | j                        }|t        j                  k(  ryt        j
                  | j                  t        j                  d      }t        |dkD         t        d|      }t        j
                  | j                  ||       t        j                  ||      dd S )z
        Retrieve the random value used with the server hello message.

        :return: A string representing the state
        Nr   r<  )	r   SSL_get_sessionr  r5  rX  SSL_get_server_randomr  r  r=  r  sessionlengthoutps       r  server_randomzConnection.server_random	  s     &&tyy1dii++DIItyy!D
#!"3V<""499dF;{{4(++r   c                 n   t        j                  | j                        }|t        j                  k(  ryt        j
                  | j                  t        j                  d      }t        |dkD         t        d|      }t        j
                  | j                  ||       t        j                  ||      dd S )z
        Retrieve the random value used with the client hello message.

        :return: A string representing the state
        Nr   r<  )	r   r{  r  r5  rX  SSL_get_client_randomr  r  r=  r}  s       r  client_randomzConnection.client_random	  s     &&tyy1dii++DIItyy!D
#!"3V<""499dF;{{4(++r   c                 F   t        j                  | j                        }|t        j                  k(  ryt        j
                  |t        j                  d      }t        |dkD         t        d|      }t        j
                  |||       t        j                  ||      dd S )zz
        Retrieve the value of the master key for this session.

        :return: A string representing the state
        Nr   r<  )	r   r{  r  r5  rX  SSL_SESSION_get_master_keyr  r  r=  r}  s       r  
master_keyzConnection.master_key	  s     &&tyy1dii00$))QG
#!"3V<''v>{{4(++r   c           
         t        d|      }t        j                  }d}d}||}t        |      }d}t	        j
                  | j                  |||t        |      |||      }t        |dk(         t        j                  ||      dd S )aH  
        Obtain keying material for application use.

        :param: label - a disambiguating label string as described in RFC 5705
        :param: olen - the length of the exported key material in bytes
        :param: context - a per-association context value
        :return: the exported key material bytes or None
        r<  r   Nr  )	r  r5  rX  rB  r   SSL_export_keying_materialr  r  r=  )	r  labelolenr  r  context_bufcontext_lenuse_contextsuccesss	            r  export_keying_materialz!Connection.export_keying_material	  s     ""3T:ii!Kg,KK11IIJ	
 	1%{{4&q))r   c                 :     | j                   j                  |i |S )z
        Call the :meth:`shutdown` method of the underlying socket.
        See :manpage:`shutdown(2)`.

        :return: What the socket's shutdown() method returns
        )r  r]  rl  s      r  sock_shutdownzConnection.sock_shutdown	  s      %t||$$d5f55r   c                     t        j                  | j                        }|t        j                  k7  r*t        j
                  |       t        j                  |      S y)za
        Retrieve the local certificate (if any)

        :return: The local certificate
        N)r   SSL_get_certificater  r5  rX  r  r   r  r  r*  s     r  get_certificatezConnection.get_certificate	  sF     ''		2499T"**400r   c                     t        j                  | j                        }|t        j                  k7  rt        j                  |      S y)zi
        Retrieve the other side's certificate (if any)

        :return: The peer's certificate
        N)r   SSL_get_peer_certificater  r5  rX  r   r  r  s     r  get_peer_certificatezConnection.get_peer_certificate	  s8     ,,TYY7499**400r   c                 F   g }t        t        j                  |             D ]}  }t        j                  | |      }t	        |t
        j                  k7         t        j                  |      }t	        |dk\         t        j                  |      }|j                  |        |S )zb
        Internal helper to convert a STACK_OF(X509) to a list of X509
        instances.
        r  )re  r   sk_X509_numsk_X509_valuer  r5  rX  r  r   r  r&  )
cert_stackr0  rb  r*  rD  pycerts         r  _cert_stack_to_listzConnection._cert_stack_to_list	  s     t''
34 	"A%%j!4DDDII-.""4(CC1H%,,T2FMM&!	" r   c                     t        j                  | j                        }|t        j                  k(  ry| j                  |      S )z
        Retrieve the other side's certificate (if any)

        :return: A list of X509 instances giving the peer's certificate chain,
                 or None if it does not have one.
        N)r   SSL_get_peer_cert_chainr  r5  rX  r  r  r  s     r  get_peer_cert_chainzConnection.get_peer_cert_chain	  s8     11$))<
"''
33r   c                     t        j                  | j                        }|t        j                  k(  ry| j                  |      S )a  
        Retrieve the verified certificate chain of the peer including the
        peer's end entity certificate. It must be called after a session has
        been successfully established. If peer verification was not successful
        the chain may be incomplete, invalid, or None.

        :return: A list of X509 instances giving the peer's verified
                 certificate chain, or None if it does not have one.

        .. versionadded:: 20.0
        N)r   SSL_get0_verified_chainr  r5  rX  r  r  s     r  get_verified_chainzConnection.get_verified_chain

  s8     11$))<
"''
33r   c                 @    t        j                  | j                        S )z
        Checks if more data has to be read from the transport layer to complete
        an operation.

        :return: True iff more data has to be read
        )r   SSL_want_readr  r  s    r  	want_readzConnection.want_read
  s     !!$)),,r   c                 @    t        j                  | j                        S )z
        Checks if there is data to write to the transport layer to complete an
        operation.

        :return: True iff there is data to write
        )r   SSL_want_writer  r  s    r  
want_writezConnection.want_write&
  s     ""499--r   c                 B    t        j                  | j                         y)z
        Set the connection to work in server mode. The handshake will be
        handled automatically by read/write.

        :return: None
        N)r   SSL_set_accept_stater  r  s    r  rJ  zConnection.set_accept_state/
  s     	!!$)),r   c                 B    t        j                  | j                         y)z
        Set the connection to work in client mode. The handshake will be
        handled automatically by read/write.

        :return: None
        N)r   rB  r  r  s    r  rG  zConnection.set_connect_state8
  s     	""499-r   c                     t        j                  | j                        }|t        j                  k(  ryt
        j                  t
              }t        j                  |t         j                        |_	        |S )z
        Returns the Session currently used.

        :return: An instance of :class:`OpenSSL.SSL.Session` or
            :obj:`None` if no session exists.

        .. versionadded:: 0.14
        N)
r   SSL_get1_sessionr  r5  rX  rv   r  r  SSL_SESSION_free_session)r  r~  	pysessions      r  get_sessionzConnection.get_sessionA
  sT     ''		2diiOOG,	!WWWd.C.CD	r   c                     t        |t              st        d      t        j                  | j
                  |j                        }t        |dk(         y)z
        Set the session to be used when the TLS/SSL connection is established.

        :param session: A Session instance representing the session to use.
        :returns: None

        .. versionadded:: 0.14
        z"session must be a Session instancer  N)r>  rv   r@  r   SSL_set_sessionr  r  r  )r  r~  r0  s      r  set_sessionzConnection.set_sessionR
  sB     '7+@AA%%dii1A1AB!$r   c                     t        j                  dd      } || j                  |d      }|dk(  ryt        d|      } || j                  ||       t        j                  ||      dd S )a  
        Helper to implement :meth:`get_finished` and
        :meth:`get_peer_finished`.

        :param function: Either :data:`SSL_get_finished`: or
            :data:`SSL_get_peer_finished`.

        :return: :data:`None` if the desired message has not yet been
            received, otherwise the contents of the message.
        :rtype: :class:`bytes` or :class:`NoneType`
        r  r   N)r5  rA  r  r  r=  )r  functionemptyr  r   s        r  _get_finished_messagez Connection._get_finished_messagea
  sb    0 1%		5!,19 40C&{{3%a((r   c                 @    | j                  t        j                        S )a  
        Obtain the latest TLS Finished message that we sent.

        :return: The contents of the message or :obj:`None` if the TLS
            handshake has not yet completed.
        :rtype: :class:`bytes` or :class:`NoneType`

        .. versionadded:: 0.15
        )r  r   SSL_get_finishedr  s    r  get_finishedzConnection.get_finished
  s     ))$*?*?@@r   c                 @    | j                  t        j                        S )a!  
        Obtain the latest TLS Finished message that we received from the peer.

        :return: The contents of the message or :obj:`None` if the TLS
            handshake has not yet completed.
        :rtype: :class:`bytes` or :class:`NoneType`

        .. versionadded:: 0.15
        )r  r   SSL_get_peer_finishedr  s    r  get_peer_finishedzConnection.get_peer_finished
  s     ))$*D*DEEr   c                     t        j                  | j                        }|t        j                  k(  ryt        j
                  t        j                  |            }|j                  d      S )a  
        Obtain the name of the currently used cipher.

        :returns: The name of the currently used cipher or :obj:`None`
            if no connection has been established.
        :rtype: :class:`unicode` or :class:`NoneType`

        .. versionadded:: 0.15
        Nr_  )r   SSL_get_current_cipherr  r5  rX  r  SSL_CIPHER_get_namer  )r  cipherr  s      r  get_cipher_namezConnection.get_cipher_name
  sO     ,,TYY7TYY;;t77?@D;;w''r   c                     t        j                  | j                        }|t        j                  k(  ryt        j
                  |t        j                        S )a.  
        Obtain the number of secret bits of the currently used cipher.

        :returns: The number of secret bits of the currently used cipher
            or :obj:`None` if no connection has been established.
        :rtype: :class:`int` or :class:`NoneType`

        .. versionadded:: 0.15
        N)r   r  r  r5  rX  SSL_CIPHER_get_bits)r  r  s     r  get_cipher_bitszConnection.get_cipher_bits
  s>     ,,TYY7TYY++FDII>>r   c                     t        j                  | j                        }|t        j                  k(  ryt        j
                  t        j                  |            }|j                  d      S )a%  
        Obtain the protocol version of the currently used cipher.

        :returns: The protocol name of the currently used cipher
            or :obj:`None` if no connection has been established.
        :rtype: :class:`unicode` or :class:`NoneType`

        .. versionadded:: 0.15
        Nr_  )r   r  r  r5  rX  r  SSL_CIPHER_get_versionr  )r  r  r  s      r  get_cipher_versionzConnection.get_cipher_version
  sO     ,,TYY7TYYkk$"="=f"EFG>>'**r   c                     t        j                  t        j                  | j                              }|j                  d      S )a>  
        Retrieve the protocol version of the current connection.

        :returns: The TLS version of the current connection, for example
            the value for TLS 1.2 would be ``TLSv1.2``or ``Unknown``
            for connections that were not successfully established.
        :rtype: :class:`unicode`
        r_  )r5  r  r   SSL_get_versionr  r  r  s     r  get_protocol_version_namez$Connection.get_protocol_version_name
  s0     ++d22499=>~~g&&r   c                 D    t        j                  | j                        }|S )a  
        Retrieve the SSL or TLS protocol version of the current connection.

        :returns: The TLS version of the current connection.  For example,
            it will return ``0x769`` for connections made over TLS version 1.
        :rtype: :class:`int`
        )r   SSL_versionr  r  s     r  get_protocol_versionzConnection.get_protocol_version
  s     ""499-r   c           	         |st        d      dj                  t        j                  d |D                    }t	        j
                  d|      }t        t        j                  | j                  |t        |            dk(         y)ah  
        Specify the client's ALPN protocol list.

        These protocols are offered to the server during protocol negotiation.

        :param protos: A list of the protocols to be offered to the server.
            This list should be a Python list of bytestrings representing the
            protocols to offer, e.g. ``[b'http/1.1', b'spdy/2']``.
        r  r   c              3   J   K   | ]  }t        t        |      f      |f  y wr  r  r  s     r  r  z-Connection.set_alpn_protos.<locals>.<genexpr>
  r  r  r<  r   N)r~  r  r   r  r5  rA  r  r   SSL_set_alpn_protosr  rB  r  s       r  r  zConnection.set_alpn_protos
  ss     FGG 88FvFF
 HH.9	 	$$TYY	3x=IQN	
r   c                     t        j                  d      }t        j                  d      }t        j                  | j                  ||       |syt        j
                  |d   |d         dd 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.
        rf  zunsigned int *r   r   N)r5  rA  r   SSL_get0_alpn_selectedr  r=  )r  r]  data_lens      r  get_alpn_proto_negotiatedz$Connection.get_alpn_proto_negotiated  s\     xx*+88,-##DIItX>{{47HQK033r   c                 |    t        j                  | j                  t         j                        }t	        |dk(         y)a  
        Called to request that the server sends stapled OCSP data, if
        available. If this is not called on the client side then the server
        will not send OCSP data. Should be used in conjunction with
        :meth:`Context.set_ocsp_client_callback`.
        r  N)r   SSL_set_tlsext_status_typer  TLSEXT_STATUSTYPE_ocspr  )r  r  s     r  request_ocspzConnection.request_ocsp  s1     ,,IIt22
 	a r   r  )r   )NN)Mr   r   r   r	   r#  r  r  r  r  r  r  r/  r6  r  r  r  r  r  r  r  writer  r"  readr&  r,  r0  r3  r7  r;  r5  r@  rC  rF  rI  rN  rU  rW  rZ  r]  rQ  rj  rm  ry  r}  rr  rv  ry  r  r  r  r  r  r  r  staticmethodr  r  r  r  r  rJ  rG  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r   r  rx   rx     s   *,8-t/5#n !"H(3#8)17 +4 E:+" D#J#$+0*
	1<8
* 54$ 7":	
0
0B,, , *<6
	  44&-.-."% )D
A
F("? +"
'	  
  
D 4 4"
!r   rx   )r  r  r  r   	functoolsr   r   	itertoolsr   r   sysr   weakrefr	   OpenSSL._utilr
   r  r   _exception_from_error_queuer   r5  r   r   r   _make_assertr   r  r   r  r   r  OpenSSL.cryptor   r   r   r   r   r   __all__r   r   r   r   r   r    r   r!   r   r"   r   SSL_SENT_SHUTDOWNr#   SSL_RECEIVED_SHUTDOWNr$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r  SSL_OP_NO_SSLv2r4   SSL_OP_NO_SSLv3r5   SSL_OP_NO_TLSv1r6   SSL_OP_NO_TLSv1_1r7   SSL_OP_NO_TLSv1_2r8   SSL_OP_NO_TLSv1_3r   r&  SSL_MODE_RELEASE_BUFFERSr9   SSL_OP_SINGLE_DH_USEr:   SSL_OP_SINGLE_ECDH_USEr;   SSL_OP_EPHEMERAL_RSAr<   SSL_OP_MICROSOFT_SESS_ID_BUGr=   SSL_OP_NETSCAPE_CHALLENGE_BUGr>   'SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUGr?   "SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUGr@   !SSL_OP_MICROSOFT_BIG_SSLV3_BUFFERrA   SSL_OP_MSIE_SSLV2_RSA_PADDINGrB   SSL_OP_SSLEAY_080_CLIENT_DH_BUGrC   SSL_OP_TLS_D5_BUGrD   SSL_OP_TLS_BLOCK_PADDING_BUGrE   "SSL_OP_DONT_INSERT_EMPTY_FRAGMENTSrF   SSL_OP_CIPHER_SERVER_PREFERENCErG   SSL_OP_TLS_ROLLBACK_BUGrH   SSL_OP_PKCS1_CHECK_1rI   SSL_OP_PKCS1_CHECK_2rJ   SSL_OP_NETSCAPE_CA_DN_BUGrK   &SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUGrL   SSL_OP_NO_COMPRESSIONrM   SSL_OP_NO_QUERY_MTUrN   SSL_OP_COOKIE_EXCHANGErO   SSL_OP_NO_TICKETrP   SSL_OP_NO_RENEGOTIATIONr   SSL_OP_IGNORE_UNEXPECTED_EOFr   
SSL_OP_ALLrQ   SSL_VERIFY_PEERrR   SSL_VERIFY_FAIL_IF_NO_PEER_CERTrS   SSL_VERIFY_CLIENT_ONCErT   SSL_VERIFY_NONErU   SSL_SESS_CACHE_OFFrV   SSL_SESS_CACHE_CLIENTrW   SSL_SESS_CACHE_SERVERrX   SSL_SESS_CACHE_BOTHrY   SSL_SESS_CACHE_NO_AUTO_CLEARrZ   !SSL_SESS_CACHE_NO_INTERNAL_LOOKUPr[    SSL_SESS_CACHE_NO_INTERNAL_STOREr\   SSL_SESS_CACHE_NO_INTERNALr]   r^   r_   r`   ra   rb   rc   rd   re   rf   rg   rh   ri   rj   rk   rl   rm   ry   r  r  r  r  r%  rn   r  r  ro   rp   rq   rr   rs   r  r  objectrt   r9  rT  rc  ro  ru  r  r  ru   r  Cryptography_HAS_ALPNr  r}  r  rv   rw   rx   r   r   r  <module>r     s   	   $ "  '	 	 	 cL 44 #'#7#7 7.!%!4!4 4%)%:%: : ?++ +j%)%:%: : ?&&.. 
    $$L$$L((N((N((N """"""&&&&	**MNN?# 44 ,, 00 ,, <<  >> 00 $ "&!H!H  $ F F  >> "BB &&<< !%!H!H "BB 22 ,, ,, 66 // # .. **00 $$	66NN()	#@@NN-. 
"""BB 00 ""((.. .. **<<  $ F F #DD 88 $$""    ** ,, ,, ,, .. .. 44 22 gL gLV    "I "L I  :EB u%	E 		U 		% 		e 		5 	( (8%
, %
P "8 :
0 :
z@I 8 @IF8I 8 8Iv
$< 
.
": 
&(3 !2   4
 "D+T24O 
		 		R
 R
jy! y![0   LLNNN"  		J  		  		sH   <U
 U  
U, )U8 
UU U)(U),U54U58V V