\d dZddlZddlZddlmZddlmZmZ m Z ddlm Z ddl Z ddl mZmZmZddl mZmZmZddl mZmZmZmZmZmZmZdd l mZmZdd l mZm Z m!Z!m"Z" dd l m#Z#n #e$$rYnwxYwdd l m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.dd l m/Z/m0Z0e j1de2de e j1de2de e j1de2de e j1de2de e j1de2de e j1de2de e3j4xZ5e3_5de3j67DZ8e9e3ddZ:e e GddZ;e e Gdd Z<e e Gd!d"Z=e e Gd#d$Z>ej?d%krdd&l m@Z@mAZAdd'lBmBZBmCZCmDZDdd(lBmEZEmFZFmGZGddlBZHddlIZIddlJZJddlKZKeLZMd)gZNeOe d*ZPe/ZQeZRd+ZSd,ZTd-ZUd.ZVed/d0ZWd1ZXGd2d3ed3d4ZYGd5d6eYeZZGd7d8eZ[eZj\fdddd9d:Z]dLe^d;eZj\dddddd<d=Z_e]Z`e_ZaGd>d?Zbd@ZcGdAdBeBZdede[_eebe[_fddd;e^e4ddCdCdf dDZgdEZhdFZidGZjdHZkdIZlemdeGfdJZndKZodS)Ma This module provides some more Pythonic support for SSL. Object types: SSLSocket -- subtype of socket.socket which does SSL over the socket Exceptions: SSLError -- exception raised for I/O errors Functions: cert_time_to_seconds -- convert time string used for certificate notBefore and notAfter functions to integer seconds past the Epoch (the time values returned from time.time()) get_server_certificate (addr, ssl_version, ca_certs, timeout) -- Retrieve the certificate from the server at the specified address and return it as a PEM-encoded string Integer constants: SSL_ERROR_ZERO_RETURN SSL_ERROR_WANT_READ SSL_ERROR_WANT_WRITE SSL_ERROR_WANT_X509_LOOKUP SSL_ERROR_SYSCALL SSL_ERROR_SSL SSL_ERROR_WANT_CONNECT SSL_ERROR_EOF SSL_ERROR_INVALID_ERROR_CODE The following group define certificate requirements that one side is allowing/requiring from the other side: CERT_NONE - no certificates from the other side are required (or will be looked at if provided) CERT_OPTIONAL - certificates are not required, but if provided will be validated, and if validation fails, the connection will also fail CERT_REQUIRED - certificates are required, and will be validated, and if validation fails, the connection will also fail The following constants identify various SSL protocol variants: PROTOCOL_SSLv2 PROTOCOL_SSLv3 PROTOCOL_SSLv23 PROTOCOL_TLS PROTOCOL_TLS_CLIENT PROTOCOL_TLS_SERVER PROTOCOL_TLSv1 PROTOCOL_TLSv1_1 PROTOCOL_TLSv1_2 The following constants identify various SSL alert message descriptions as per http://www.iana.org/assignments/tls-parameters/tls-parameters.xml#tls-parameters-6 ALERT_DESCRIPTION_CLOSE_NOTIFY ALERT_DESCRIPTION_UNEXPECTED_MESSAGE ALERT_DESCRIPTION_BAD_RECORD_MAC ALERT_DESCRIPTION_RECORD_OVERFLOW ALERT_DESCRIPTION_DECOMPRESSION_FAILURE ALERT_DESCRIPTION_HANDSHAKE_FAILURE ALERT_DESCRIPTION_BAD_CERTIFICATE ALERT_DESCRIPTION_UNSUPPORTED_CERTIFICATE ALERT_DESCRIPTION_CERTIFICATE_REVOKED ALERT_DESCRIPTION_CERTIFICATE_EXPIRED ALERT_DESCRIPTION_CERTIFICATE_UNKNOWN ALERT_DESCRIPTION_ILLEGAL_PARAMETER ALERT_DESCRIPTION_UNKNOWN_CA ALERT_DESCRIPTION_ACCESS_DENIED ALERT_DESCRIPTION_DECODE_ERROR ALERT_DESCRIPTION_DECRYPT_ERROR ALERT_DESCRIPTION_PROTOCOL_VERSION ALERT_DESCRIPTION_INSUFFICIENT_SECURITY ALERT_DESCRIPTION_INTERNAL_ERROR ALERT_DESCRIPTION_USER_CANCELLED ALERT_DESCRIPTION_NO_RENEGOTIATION ALERT_DESCRIPTION_UNSUPPORTED_EXTENSION ALERT_DESCRIPTION_CERTIFICATE_UNOBTAINABLE ALERT_DESCRIPTION_UNRECOGNIZED_NAME ALERT_DESCRIPTION_BAD_CERTIFICATE_STATUS_RESPONSE ALERT_DESCRIPTION_BAD_CERTIFICATE_HASH_VALUE ALERT_DESCRIPTION_UNKNOWN_PSK_IDENTITY N) namedtuple)EnumIntEnumIntFlag) _simple_enum)OPENSSL_VERSION_NUMBEROPENSSL_VERSION_INFOOPENSSL_VERSION) _SSLContext MemoryBIO SSLSession)SSLErrorSSLZeroReturnErrorSSLWantReadErrorSSLWantWriteErrorSSLSyscallError SSLEOFErrorSSLCertVerificationError)txt2objnid2obj) RAND_statusRAND_add RAND_bytesRAND_pseudo_bytes)RAND_egd) HAS_SNIHAS_ECDHHAS_NPNHAS_ALPN HAS_SSLv2 HAS_SSLv3 HAS_TLSv1 HAS_TLSv1_1 HAS_TLSv1_2 HAS_TLSv1_3)_DEFAULT_CIPHERS_OPENSSL_API_VERSION _SSLMethodc8|do|dkS)N PROTOCOL_PROTOCOL_SSLv23 startswithnames ..\python\lib\ssl.pyr1}s--K$:K2K)sourceOptionsc,|dS)NOP_r,r.s r0r1r1s''r2AlertDescriptionc,|dS)NALERT_DESCRIPTION_r,r.s r0r1r1s!566r2SSLErrorNumberc,|dS)N SSL_ERROR_r,r.s r0r1r1s..r2 VerifyFlagsc,|dS)NVERIFY_r,r.s r0r1r1s++r2 VerifyModec,|dS)NCERT_r,r.s r0r1r1s))r2ci|]\}}|| SrD).0r/values r0 rGsQQQ;45$QQQr2PROTOCOL_SSLv2cpeZdZejZejZejZ ej Z ej Z ejZejZdS) TLSVersionN)__name__ __module__ __qualname___sslPROTO_MINIMUM_SUPPORTEDMINIMUM_SUPPORTED PROTO_SSLv3SSLv3 PROTO_TLSv1TLSv1 PROTO_TLSv1_1TLSv1_1 PROTO_TLSv1_2TLSv1_2 PROTO_TLSv1_3TLSv1_3PROTO_MAXIMUM_SUPPORTEDMAXIMUM_SUPPORTEDrDr2r0rJrJsJ4  E  E G G G4r2rJc*eZdZdZdZdZdZdZdZdZ dS) _TLSContentTypez@Content types (record layer) See RFC 8446, section B.1 N) rKrLrM__doc__CHANGE_CIPHER_SPECALERT HANDSHAKEAPPLICATION_DATAHEADERINNER_CONTENT_TYPErDr2r0r^r^s= EI Fr2r^ceZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZ dZ!d Z"d!Z#d"Z$d#Z%d$S)% _TLSAlertTypezQAlert types for TLSContentType.ALERT messages See RFC 8466, section B.2 r r_r`ra()*+,-./0123<FGPVZdmnopqrstxN)&rKrLrMre CLOSE_NOTIFYUNEXPECTED_MESSAGEBAD_RECORD_MACDECRYPTION_FAILEDRECORD_OVERFLOWDECOMPRESSION_FAILUREHANDSHAKE_FAILURENO_CERTIFICATEBAD_CERTIFICATEUNSUPPORTED_CERTIFICATECERTIFICATE_REVOKEDCERTIFICATE_EXPIREDCERTIFICATE_UNKNOWNILLEGAL_PARAMETER UNKNOWN_CA ACCESS_DENIED DECODE_ERROR DECRYPT_ERROREXPORT_RESTRICTIONPROTOCOL_VERSIONINSUFFICIENT_SECURITYINTERNAL_ERRORINAPPROPRIATE_FALLBACK USER_CANCELEDNO_RENEGOTIATIONMISSING_EXTENSIONUNSUPPORTED_EXTENSIONCERTIFICATE_UNOBTAINABLEUNRECOGNIZED_NAMEBAD_CERTIFICATE_STATUS_RESPONSEBAD_CERTIFICATE_HASH_VALUEUNKNOWN_PSK_IDENTITYCERTIFICATE_REQUIREDNO_APPLICATION_PROTOCOLrDr2r0rmrmsLNONO JMLMNM"&)#!$!r2rmcjeZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZdZdZdZdZdZdZdZdS)_TLSMessageTypezFMessage types (handshake protocol) See RFC 8446, section B.3 r r_r`rarbCrdN)rKrLrMre HELLO_REQUEST CLIENT_HELLO SERVER_HELLOHELLO_VERIFY_REQUESTNEWSESSION_TICKETEND_OF_EARLY_DATAHELLO_RETRY_REQUESTENCRYPTED_EXTENSIONS CERTIFICATESERVER_KEY_EXCHANGECERTIFICATE_REQUEST SERVER_DONECERTIFICATE_VERIFYCLIENT_KEY_EXCHANGEFINISHEDCERTIFICATE_URLCERTIFICATE_STATUSSUPPLEMENTAL_DATA KEY_UPDATE NEXT_PROTO MESSAGE_HASHrfrDr2r0rrsMLLKKHOJJLr2rwin32)enum_certificates enum_crls)socket SOCK_STREAMcreate_connection) SOL_SOCKETSO_TYPE_GLOBAL_DEFAULT_TIMEOUT tls-uniqueHOSTFLAG_NEVER_CHECK_SUBJECTc|sdS|d}|s*||kS|dkr"td||d\}}}d|vr"td||s"td||dkr"td||d\}}}|r|sdS||kS) aMatching according to RFC 6125, section 6.4.3 - Hostnames are compared lower-case. - For IDNA, both dn and hostname must be encoded as IDN A-label (ACE). - Partial wildcards like 'www*.example.org', multiple wildcards, sole wildcard or wildcards in labels other then the left-most label are not supported and a CertificateError is raised. - A wildcard must match at least one character. F*rz1too many wildcards in certificate DNS name: {!r}..z9wildcard can only be present in the leftmost label: {!r}.z>sole wildcard without additional labels are not support: {!r}.z M,# ;:;; ;h'' H ((#R ( (C## U %<<>%#B#B OOE " " " " L "'7w'G'G" OOE " " "  +88Ir** + +C! + + U,&&%eX66OOE***  + 8}}qxx3tX#6#6777 9:: : X!  xx! &'' ' /00 0s? A ADefaultVerifyPathszQcafile capath openssl_cafile_env openssl_cafile openssl_capath_env openssl_capathcxtj}tj|d|d}tj|d|d}t tj|r|ndtj|r|ndg|RS)z/Return paths to default cafile and capath. rrrrN) rNget_default_verify_pathsosenvironrrpathisfileisdir)partscafilecapaths r0rrs  ) + +EZ^^E!HeAh / /F Z^^E!HeAh / /F v(>(>HffD(* f(=(=Gff4 &$ & & &&r2cZeZdZdZdZfdZefdZefdZxZ S) _ASN1Objectz#ASN.1 object identifier lookup rDcVtj|gt|dRS)NFr.super__new___txt2obj)clsoid __class__s r0r*z_ASN1Object.__new__s.uwws?Xc%>%>%>????r2cRtj|gt|RS)z3Create _ASN1Object from OpenSSL numeric ID )r)r*_nid2obj)r,nidr.s r0fromnidz_ASN1Object.fromnids)uwws3Xc]]3333r2cVtj|gt|dRS)z=Create _ASN1Object from short name, long name or OID Tr.r()r,r/r.s r0fromnamez_ASN1Object.fromnames0uwws?Xd%>%>%>????r2) rKrLrMre __slots__r* classmethodr2r4 __classcell__r.s@r0r&r&sI@@@@@4444[4 @@@@[@@@@@r2r&znid shortname longname oidceZdZdZdZdZdS)PurposezDSSLContext purpose flags with X509v3 Extended Key Usage objects z1.3.6.1.5.5.7.3.1z1.3.6.1.5.5.7.3.2N)rKrLrMre SERVER_AUTH CLIENT_AUTHrDr2r0r:r:s"%K%KKKr2r:ceZdZdZdZdZdZd!dZdZ d"dZ d#d Z d Z d Z d Z d ZejfdZeedr>efdZejfdZefdZejfdZefdZejfdZeedredZejdZn edZefdZejfdZefdZefdZejfdZefdZejfd ZxZS)$ SSLContextz|An SSLContext holds various SSL-related configuration options and data, such as certificates and possibly a private key.)CAROOTNcz|#tjdtdt}t j||}|S)Nz9ssl.SSLContext() without protocol argument is deprecated.rr)r r r  PROTOCOL_TLSr r*)r,protocolargskwargsselfs r0r*zSSLContext.__new__sH   MK+     $H"311 r2c|dSt|tr(|ddS|dS)Nidnaascii) isinstancestrencodedecode)rFrs r0_encode_hostnamezSSLContext._encode_hostnamesQ  4 # & & ,??6**11':: :??7++ +r2FTc D|j|||||||S)N)sock server_sidedo_handshake_on_connectsuppress_ragged_eofsserver_hostnamecontextsession)sslsocket_class_create)rFrPrQrRrSrTrVs r0 wrap_socketzSSLContext.wrap_sockets9 #++#$;!5+,   r2ch|j|||||||S)N)rQrTrVrU)sslobject_classrXrN)rFincomingoutgoingrQrTrVs r0wrap_biozSSLContext.wrap_biosA#++ hK 11/BBT,   r2ctjdtdt}|D]~}t |d}t |dkst |dkrt d|t |||| |dS)N'ssl NPN is deprecated, use ALPN insteadrrrIrz(NPN protocols must be 1 to 255 in length) r r r  bytearraybytesrrrextend_set_npn_protocols)rF npn_protocolsprotosrCbs r0set_npn_protocolszSSLContext.set_npn_protocolss 5     %  Hh((A1vv{{c!ffsllIJJJ MM#a&& ! ! ! MM!     '''''r2cv d_dStstdfd}|_dS)Nznot a callable objectcH|}|||SN)rN)sslobj servernamesslctxrFserver_name_callbacks r0shim_cbz3SSLContext.set_servername_callback..shim_cb0s+!22:>> ++FJGGGr2) sni_callbackcallable TypeError)rFrqrrs`` r0set_servername_callbackz"SSLContext.set_servername_callback)sl  ' $D   011 9 7888 H H H H H H!(D   r2cNt}|D]~}t|d}t|dkst|dkrtd|t|||||dS)NrIrrbz)ALPN protocols must be 1 to 255 in length)rcrdrrrre_set_alpn_protocols)rFalpn_protocolsrhrCris r0set_alpn_protocolszSSLContext.set_alpn_protocols6s&  Hh((A1vv{{c!ffsllJKKK MM#a&& ! ! ! MM!       (((((r2ct} t|D].\}}}|dkr"|dus |j|vr||/n$#t$rt jdYnwxYw|r|||S)Nx509_asnTz-unable to enumerate Windows certificate store)cadata)rcrr-rePermissionErrorr r load_verify_locations)rF storenamepurposecertsrencodingtrusts r0_load_windows_store_certsz$SSLContext._load_windows_store_certsAs  K):9)E)E + +%hz))}} u(<(< T***  +  K K K MI J J J J J K  5  & &e & 4 4 4 s>AA0/A0ct|tst|tjdkr |jD]}||||dS)Nr)rJr&rusysplatform_windows_cert_storesrset_default_verify_paths)rFrrs r0load_default_certszSSLContext.load_default_certsOst';// %G$$ $ <7 " "!6 C C ..y'BBBB %%'''''r2minimum_versioncDttjSrm)rJr)rrFr.s r0rzSSLContext.minimum_versionXegg566 6r2c|tjkr|xjtjzc_t t t j||dSrm) rJrRoptionsr4 OP_NO_SSLv3r)r>r__set__rFrFr.s r0rzSSLContext.minimum_version\sP ((( !4 44 *j ) ) 9 A A$ N N N N Nr2cDttjSrm)rJr)maximum_versionrs r0rzSSLContext.maximum_versionbrr2cntttj||dSrm)r)r>rrrs r0rzSSLContext.maximum_versionfs, *j ) ) 9 A A$ N N N N Nr2cDttjSrm)r4r)rrs r0rzSSLContext.optionsjsuww'''r2cntttj||dSrm)r)r>rrrs r0rzSSLContext.optionsns, j*%%-55dEBBBBBr2rcJ|jtjz}|tjkSrm _host_flagsrNr)rFncss r0hostname_checks_common_namez&SSLContext.hostname_checks_common_namess "T%FFC$;; ;r2cx|r|xjtjzc_dS|xjtjzc_dSrmr)rFrFs r0rz&SSLContext.hostname_checks_common_namexsH F  T%F$FF      D$EE    r2cdS)NTrDrFs r0rz&SSLContext.hostname_checks_common_names4r2c@tj}||jSdS)a9TLS message callback The message callback provides a debugging hook to analyze TLS connections. The callback is called for any TLS protocol message (header, handshake, alert, and more), but not for application data. Due to technical limitations, the callback can't be used to filter traffic or to abort a connection. Any exception raised in the callback is delayed until the handshake, read, or write operation has been performed. def msg_cb(conn, direction, version, content_type, msg_type, data): pass conn :class:`SSLSocket` or :class:`SSLObject` instance direction ``read`` or ``write`` version :class:`TLSVersion` enum member or int for unknown version. For a frame header, it's the header version. content_type :class:`_TLSContentType` enum member or int for unsupported content type. msg_type Either a :class:`_TLSContentType` enum number for a header message, a :class:`_TLSAlertType` enum member for an alert message, a :class:`_TLSMessageType` enum member for other messages, or int for unsupported message types. data Raw, decrypted message content as bytes N)r) _msg_callback user_function)rFinnerr.s r0rzSSLContext._msg_callbacks&B%  & &4r2c:5tttj|ddSt dst dfd}|_tttj||dS)N__call__z is not callable.cP t|}n#t$rYnwxYw t|}n#t$rYnwxYw|tjkrt}n|tjkrt }nt } ||}n#t$rYnwxYw||||||Srm)rJrr^rjrgrmr)conn directionversion content_typemsg_typedatamsg_enumcallbacks r0rz'SSLContext._msg_callback..inners $W--     .|<<     555*!666(* #8H--    8D)W((D:: :s-  4 AA< B BB)r)r>rrhasattrrur)rFrrr.s ` r0rzSSLContext._msg_callbacks   *j ) ) 7 ? ?d K K K Fx,, <x:::;; ; : : : : :2' j*%%3;;D%HHHHHr2cDttjSrm)r(r)rCrs r0rCzSSLContext.protocols%''*+++r2cDttjSrm)r=r) verify_flagsrs r0rzSSLContext.verify_flagss577/000r2cntttj||dSrm)r)r>rrrs r0rzSSLContext.verify_flagss, j*%%2::4GGGGGr2cntj} t|S#t$r|cYSwxYwrm)r) verify_moder@rrs r0rzSSLContext.verify_modesF# e$$ $   LLL s % 44cntttj||dSrm)r)r>rrrs r0rzSSLContext.verify_modes, j*%%199$FFFFFr2rm)FTTNN)FNN) rKrLrMrerrWr[r*rNrYr^rjrvrzrr:r;rrr propertyrsetterrrrNrrrCrrr7r8s@r0r>r>s>>)OO    ,,,-2,0)-26    8=/3    ((( ( ( ( ) ) )   *1)<((((w{-..O  7 7 7 7  7   O O O O  O  7 7 7 7  7   O O O O  O((((X( ^CCCC^Cwt344  < <  < % + F F , + F F     $$$$X$L#I#I#I#I#IJ,,,,X,1111X1HHHHHXGGGGGGGGGr2r>)r#r$r}c>t|tst||tjkr(t t }t|_d|_ n4|tj krt t}nt||s|s|r| |||n%|jtkr||t!|dr9t"jd}|rt(jjs||_|S)zCreate a SSLContext object with default settings. NOTE: The protocol and settings may change anytime without prior deprecation. The values represent a fair balance between maximum compatibility and security. Tkeylog_filename SSLKEYLOGFILE)rJr&rur:r;r>PROTOCOL_TLS_CLIENT CERT_REQUIREDrcheck_hostnamer<PROTOCOL_TLS_SERVERrr CERT_NONErrrrrrflagsignore_environmentr)rr#r$r}rU keylogfiles r0create_default_contextrs g{ + +!   '%%%011+!% G' ' '011!!! ,,6,%%fff====   ) ) ""7+++w)**1Z^^O44  1ci: 1&0G # Nr2F) cert_reqsrrcertfilekeyfiler#r$r}ct|tst||tjkr |t }n)|tjkr |t}nt|t|} || _ ||| _ |rd| _ |r|std|s|r| |||s|s|r| |||n%| j tkr| |t!| dr9t"jd} | rt(jjs| | _| S)a/Create a SSLContext object for Python stdlib modules All Python stdlib modules shall use this function to create SSLContext objects in order to keep common settings in one place. The configuration is less restrict than create_default_context()'s to increase backward compatibility. NTcertfile must be specifiedrr)rJr&rur:r;rr<rrr>rrload_cert_chainrrrrrrrrrrr) rCrrrrrr#r$r}rUrs r0_create_unverified_contextrs| g{ + +!   '%%%  *H G' ' '  *H!!!""G+G'&!%7x75666373'222,,6,%%fff====   ) ) ""7+++w)**1Z^^O44  1ci: 1&0G # Nr2c<eZdZdZdZe ddZedZej dZedZ e j d Z ed Z ed Z ed Z ddZdZddZdZdZdZdZdZdZdZdZd dZdZdZdS)! SSLObjectaThis class implements an interface on top of a low-level SSL object as implemented by OpenSSL. This object captures the state of an SSL connection but does not provide any network IO itself. IO needs to be performed through separate "BIO" objects which are OpenSSL's IO abstraction layer. This class does not have a public constructor. Instances are returned by ``SSLContext.wrap_bio``. This class is typically used by framework authors that want to implement asynchronous IO for SSL through memory buffers. When compared to ``SSLSocket``, this object lacks the following features: * Any form of network IO, including methods such as ``recv`` and ``send``. * The ``do_handshake_on_connect`` and ``suppress_ragged_eofs`` machinery. c:t|jjd)NzU does not have a public constructor. Instances are returned by SSLContext.wrap_bio().rur.rKrFrDrEs r0__init__zSSLObject.__init__\s.~& M M M   r2FNct||}|||||||}||_|S)N)rQrTownerrV)r* _wrap_bio_sslobj) r,r\r]rQrTrVrUrFrns r0rXzSSLObject._createbsL{{3"" hK+#     r2c|jjS)z(The SSLContext that is currently in use.rrUrs r0rUzSSLObject.contextn|##r2c||j_dSrmrrFctxs r0rUzSSLObject.contextss" r2c|jjS)z!The SSLSession for client socket.rrVrs r0rVzSSLObject.sessionwrr2c||j_dSrmrrFrVs r0rVzSSLObject.session|s& r2c|jjS)z.Was the client session reused during handshakersession_reusedrs r0rzSSLObject.session_reuseds|**r2c|jjS)z%Whether this is a server-side socket.)rrQrs r0rQzSSLObject.server_sides|''r2c|jjS)z^The currently set server hostname (for SNI), or ``None`` if no server hostname is set.)rrTrs r0rTzSSLObject.server_hostnames|++r2cv||j||}n|j|}|S)zRead up to 'len' bytes from the SSL object and return them. If 'buffer' is provided, read into this buffer and return the number of bytes read. )rread)rFrbuffervs r0rzSSLObject.reads=   !!#v..AA !!#&&Ar2c6|j|S)zWrite 'data' to the SSL object and return the number of bytes written. The 'data' argument must support the buffer interface. )rwriterFrs r0rzSSLObject.writes |!!$'''r2c6|j|S)zReturns a formatted version of the data in the certificate provided by the other end of the SSL channel. Return None if no certificate was provided, {} if a certificate was provided, but not validated. )r getpeercertrF binary_forms r0rzSSLObject.getpeercerts|'' 444r2c>tjdtddS)zReturn the currently selected NPN protocol as a string, or ``None`` if a next protocol was not negotiated or if NPN is not supported by one of the peers.r`rraN)r r r rs r0selected_npn_protocolzSSLObject.selected_npn_protocols0  5       r2c4|jS)zReturn the currently selected ALPN protocol as a string, or ``None`` if a next protocol was not negotiated or if ALPN is not supported by one of the peers.)rselected_alpn_protocolrs r0rz SSLObject.selected_alpn_protocols|22444r2c4|jS)z_Return the currently selected cipher as a 3-tuple ``(name, ssl_version, secret_bits)``.)rcipherrs r0rzSSLObject.ciphers|""$$$r2c4|jS)zReturn a list of ciphers shared by the client during the handshake or None if this is not a valid server connection. )rshared_ciphersrs r0rzSSLObject.shared_cipherss|**,,,r2c4|jS)zReturn the current compression algorithm in use, or ``None`` if compression was not negotiated or not supported by one of the peers.)r compressionrs r0rzSSLObject.compressions|'')))r2c4|jS)z8Return the number of bytes that can be read immediately.)rpendingrs r0rzSSLObject.pendings|##%%%r2c8|jdS)zStart the SSL/TLS handshake.N)r do_handshakers r0rzSSLObject.do_handshakes !!#####r2c4|jS)z!Start the SSL shutdown handshake.)rshutdownrs r0unwrapzSSLObject.unwraps|$$&&&r2rc6|j|S)zGet channel binding data for current connection. Raise ValueError if the requested `cb_type` is not supported. Return bytes of the data or None if the data is not available (e.g. before the handshake).)rget_channel_bindingrFcb_types r0rzSSLObject.get_channel_bindings|//888r2c4|jS)zZReturn a string identifying the protocol version used by the current SSL channel. rrrs r0rzSSLObject.versions|##%%%r2c4|jSrm)rverify_client_post_handshakers r0r z&SSLObject.verify_client_post_handshakes|88:::r2)FNNNrNFr)rKrLrMrerr6rXrrUrrVrrQrTrrrrrrrrrrrrrr rDr2r0rrMs     5:=A   [ $$X$ ^##^#$$X$ ^''^'++X+((X(,,X,    (((5555   555 %%% --- *** &&&$$$'''9999 &&& ;;;;;r2rcNtt|jj|_|S)z*Copy docstring from SSLObject to SSLSocket)getattrrrKre)funcs r0 _sslcopydocrs9dm44 >%&IJJ J  0 3 "2333" "/000  ! H/ HFGG G;TYdj;;==   s{3))&))'i'11&111 ))***     &&77HH'>$$8!        II    w%.((IIIIII $   #}99+t';  :   +("oo//G#~~()sttt%%'''Z(      s%E66 F"FF"/A-H'Ic|jSrm)r#rs r0rUzSSLSocket.context9s }r2c,||_||j_dSrm)r#rrUrs r0rUzSSLSocket.context>s " r2c,|j |jjSdSrmrrs r0rVzSSLSocket.sessionCs < #<' ' $ #r2c>||_|j||j_dSdSrm)r$rrVrs r0rVzSSLSocket.sessionIs) < ##*DL  $ #r2c,|j |jjSdSrmrrs r0rzSSLSocket.session_reusedOs < #<. . $ #r2c:td|jjz)NzCan't dup() %s instances)rr.rKrs r0dupz SSLSocket.dupUs$!"<"&."9#:;; ;r2cdSrmrD)rFmsgs r0 _checkClosedzSSLSocket._checkClosedYs r2c@|js|dSdSrm)r)r&rs r0_check_connectedzSSLSocket._check_connected]s0            r2rcB||jtd ||j||S|j|S#t$r1}|jdt kr|jr|Yd}~dSYd}~dSd}~wwxYw)zORead up to LEN bytes and return them. Return zero-length string on EOF.Nz'Read on closed or unwrapped SSL socket.rr2)r8rrrrrD SSL_ERROR_EOFrS)rFrrxs r0rzSSLSocket.reades  < FGG G !|((f555|((---   vayM))d.G)%1111133333 s#A# A## B-BBBc||jtd|j|S)zhWrite DATA to the underlying SSL channel. Returns number of bytes of DATA actually transmitted.Nz(Write on closed or unwrapped SSL socket.)r8rrrrs r0rzSSLSocket.writezsC  < GHH H|!!$'''r2c|||j|Srm)r8r:rrrs r0rzSSLSocket.getpeercerts<  |'' 444r2cf|tjdtddS)Nr`rra)r8r r r rs r0rzSSLSocket.selected_npn_protocols=  5     tr2c||j tjsdS|jSrm)r8rrNrrrs r0rz SSLSocket.selected_alpn_protocols<  < t} 4<6688 8r2cn||jdS|jSrm)r8rrrs r0rzSSLSocket.ciphers5  < 4<&&(( (r2cn||jdS|jSrm)r8rrrs r0rzSSLSocket.shared_cipherss5  < 4<..00 0r2cn||jdS|jSrm)r8rrrs r0rzSSLSocket.compressions5  < 4<++-- -r2rc||j7|dkrtd|jz|j|St ||S)Nrz3non-zero flags not allowed in calls to send() on %s)r8rrr.rr)send)rFrrr.s r0rFzSSLSocket.sendsu  < #zz IN#$$$<%%d++ +77<<e,, ,r2c||jtd|jz|"t ||St |||S)Nz%sendto not allowed on instances of %s)r8rrr.r)sendto)rFr flags_or_addrrr.s r0rHzSSLSocket.sendtoss  < #D!^,-- - \77>>$ 66 677>>$ t<< > YYfnn )EFF"344AQJEfnn                                  77??4// /s6 C!>B+ C+B/ /C2B/ 3CC Cc|j||||St|||S)zSend a file, possibly by using os.sendfile() if this is a clear-text socket. Return the total number of bytes sent. )r_sendfile_use_sendr)sendfile)rFfileoffsetrr.s r0rWzSSLSocket.sendfilesC < #**4?? ?77##D&%88 8r2c||j2|dkrtd|jz||St ||S)Nrz3non-zero flags not allowed in calls to recv() on %s)r8rrr.rr)recvrFbuflenrr.s r0r[zSSLSocket.recvsq  < #zz IN#$$$99V$$ $77<<.. .r2c||r|t|}n|d}|j3|dkrtd|jz|||St |||S)Nrrz8non-zero flags not allowed in calls to recv_into() on %s)r8rrrr.rr) recv_intorFrnbytesrr.s r0r_zSSLSocket.recv_intos   v~[[FF ^F < #zz L.!"""99VV,, ,77$$VVU;; ;r2c||jtd|jzt ||S)Nz'recvfrom not allowed on instances of %s)r8rrr.r)recvfromr\s r0rczSSLSocket.recvfromsX  < #F!^,-- -77##FE22 2r2c||jtd|jzt |||S)Nz,recvfrom_into not allowed on instances of %s)r8rrr.r) recvfrom_intor`s r0rezSSLSocket.recvfrom_into sZ  < #K!^,-- -77((?? ?r2c0td|jz)Nz&recvmsg not allowed on instances of %srKrs r0recvmsgzSSLSocket.recvmsgs!!"J"&.#122 2r2c0td|jz)Nz+recvmsg_into not allowed on instances of %srKrs r0 recvmsg_intozSSLSocket.recvmsg_intos#!#')-#899 9r2cn||j|jSdSNr)r8rrrs r0rzSSLSocket.pendings5  < #<'')) )1r2c|d|_t|dSrm)r8rr)r)rFhowr.s r0rzSSLSocket.shutdown"s:   r2c|jr"|j}d|_|Stdt|zNzNo SSL wrapper around )rrrrK)rFss r0rzSSLSocket.unwrap'sF < C %%''ADLH5D ABB Br2c|jr|jStdt|zro)rr rrKrs r0r z&SSLSocket.verify_client_post_handshake0s; < C<<<>> >5D ABB Br2cVd|_tdSrm)rr) _real_closers r0rszSSLSocket._real_close7s&  r2c"||} |dkr|r|d|j||dS#||wxYw)Nr)r:r!r rr)rFblockr.s r0rzSSLSocket.do_handshake;s //## %#~~%~%%% L % % ' ' ' OOG $ $ $ $ $DOOG $ $ $ $s 6A77Bc|jrtd|js|jtd|j|d|j||j|_ |r"t |}n#d}t ||s"d|_|j r| |S#ttf$r d|_wxYw)Nz!can't connect in server-side modez/attempt to connect already-connected SSLSocket!FrT)rQrr)rrUr*rTr$r) connect_exconnectrRrr)rFrrwrcr.s r0 _real_connectzSSLSocket._real_connectFs    B@AA A ? Pdl6NOO O|00 %- 1     &WW''--%%% ("&/(%%'''I$   DL  s $A,CC+c2||ddS)QConnects to remote ADDR, and then wraps the connection in an SSL channel.FNrzrFrs r0rxzSSLSocket.connect`s  4'''''r2c.||dS)r|Tr}r~s r0rwzSSLSocket.connect_exes!!$---r2ct\}}|j||j|jd}||fS)zAccepts a new connection from a remote client, and returns a tuple containing that new connection wrapped with a server-side SSL channel, and the address of the remote client.T)rRrSrQ)r)acceptrUrYrRrS)rFnewsockrr.s r0rzSSLSocket.acceptjsU (( ,**7,0,H)-)B $+&&}r2rc|j|j|S|tvr"td|dS)Nz({0} channel binding type not implemented)rrCHANNEL_BINDING_TYPESrrrs r0rzSSLSocket.get_channel_bindingvsV < #<33G<< <333 >EEgNN4r2cF|j|jSdSrmr rs r0rzSSLSocket.versions# < #<'')) )4r2)FTTNNNrmr r )r)rN)rrrkr)0rKrLrMrerr6rXrrrUrrVrr5r8r:rrrrrrrrrFrHrLrQrWr[r_rcrergrirrrr rsrrzrxrwrrrr7r8s@r0rrsh;;   FJ;?&*<<<<<[<|[X ^##^#(([X( ^++^+ //[X/;;;    *(((555[5 [99[9))[)11[1..[. - - - - - -======222 000000 999999 / / / / / / < < < < < <333333@@@@@@222999[ CC[CCC[C %%%[%4((( ...     [[r2rTc ptjdtd|r|std|r|stdt |} || _|r| ||r| ||| r| | | ||||S)Nz=ssl.wrap_socket() is deprecated, use SSLContext.wrap_socket()rrz5certfile must be specified for server-side operationsr)rPrQrRrS) r r r rr>rrr set_ciphersrY) rPrrrQr ssl_versionca_certsrRrSciphersrUs r0rYrYs  MG# '8'&'' '7x75666%%G#G0%%h///3'222%G$$$    { 71   r2c4ddlm}ddlm}d}d} ||dddz}||dd|}||d|f|d d zS#t $rt d |d |d wxYw)aReturn the time in seconds since the Epoch, given the timestring representing the "notBefore" or "notAfter" date from a certificate in ``"%b %d %H:%M:%S %Y %Z"`` strptime format (C locale). "notBefore" or "notAfter" dates must use UTC (RFC 5280). Month is one of: Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec UTC should be specified as GMT (see ASN1_TIME_print()) r)strptime)timegm) JanFebMarAprMayJunJulAugSepOctNovDecz %d %H:%M:%S %Y GMTNrrrrz time data z does not match format "%b")timercalendarrindextitler) cert_timerrmonths time_format month_numbertts r0cert_time_to_secondsrsF(K 7||IbqbM$7$7$9$9::Q> Xim[ 1 1vr!ul+b1g5666 FFFj-6YY EFF FFs 2A66!Bz-----BEGIN CERTIFICATE-----z-----END CERTIFICATE-----cttj|ddtg}|fdt dt dDz }|tdzd|S)z[Takes a certificate in binary DER format and returns the PEM version of it as a string.ASCIIstrictc*g|]}||dzS)@rD)rEifs r0 z(DER_cert_to_PEM_cert..s% 3 3 31QqtV9 3 3 3r2rr ) rKbase64standard_b64encode PEM_HEADERrangerr PEM_FOOTERr)der_cert_bytesssrs @r0DER_cert_to_PEM_certrs F %n 5 5wIIA B 3 3 3 3eAs1vvr22 3 3 33BIIj4   99R==r2c|tstdtz|t stdt z|t tt t  }tj| ddS)zhTakes a certificate in ASCII PEM format and returns the DER-encoded version of it as a byte sequencez(Invalid PEM encoding; must start with %sz&Invalid PEM encoding; must end with %srr) r-rrstripendswithrrr decodebytesrL)pem_cert_stringds r0PEM_cert_to_DER_certrs  % %j 1 1'C%&'' '  " " + +J 7 7'A%&'' 'JZ0@ @AA  ahhw99 : ::r2cJ|\}}|t}nt}t|||}t||5}|||5} | d} dddn #1swxYwYdddn #1swxYwYt | S)a=Retrieve the certificate from the server at the specified address, and return it as a PEM-encoded string. If 'ca_certs' is specified, validate the server cert against it. If 'ssl_version' is specified, use it in the connection attempt. If 'timeout' is specified, use it in the connection attempt. N)rr#)r.)rTT)rr_create_stdlib_contextrrYrr) rrrr.hostportrrUrPsslsockdercerts r0get_server_certificaters0JD$!  $[/8,4666G 4 1 1 10T  t < < 0))$//G 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0000000000000000  ( ((s5B A4( B 4A8 8B ;A8 <B  BBc8t|dS)Nz )_PROTOCOL_NAMESr) protocol_codes r0get_protocol_namers   }k : ::r2rm)prerr collectionsrenumr_Enumr_IntEnumr_IntFlagrrNrr r r r r rrrrrrrrr+rr0rrrrr ImportErrorrrrrr r!r"r#r$r%r&r' _convert_rKr(rBr+ __members__itemsrr_SSLv2_IF_EXISTSrJr^rmrrrrrrrrrrrrr'r r socket_errorrrHAS_NEVER_CHECK_COMMON_NAME_RESTRICTED_SERVER_CIPHERSrrrrrrrr&r:r>r;rrr_create_default_https_contextrrrrrWr[rYrrrrrrrrrDr2r0rsXXt """"""HHHHHHHHHH NNNNNNNNNN3333333333:9999999EEEEEEEEEEEE    D 87777777(KK   x''  66  h..  8++  ())  0:/FF*,QQ*2H2N2N2P2PQQQ7:'7>>h55555555h        h&"&"&"&"&"&"&"&"Rh        :<7111111119999999999??????????  %%gd,JKK.+.>.>.>b D D DF   ;0;0;0| Z 4 & & &@@@@@**],HII@@@*&&&&&k5&&&BGBGBGBGBGBGBGBGJ$+#6$$"&t$$$$$L49*/9L$($"&tD44444n!74X;X;X;X;X;X;X;X;v XXXXXXXXx ' & #T!Y(4(,%) @777<+ (  ; ; ;.A$(2I)))),;;;;;s A''A/.A/