python (3.12.0)

(root)/
lib/
python3.12/
__pycache__/
ssl.cpython-312.pyc

ˑeA
pdZddlZddlZddlmZddlmZmZ	m
ZddlmZddl
Z
ddl
mZmZmZddl
mZmZmZddl
mZmZmZmZmZmZmZdd	l
mZmZdd
l
mZm Z m!Z!	ddl
m"Z"dd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.m/Z/e	j`de1de
ej`de1de
e	j`de1de
e	j`de1de
ej`de1de
e	j`de1de
e2jfxZ4e2_4e2jjjmDcic]\}}||
c}}Z7e8e2ddZ9ee	GddZ:ee	GddZ;ee	Gd d!Z<ee	Gd"d#Z=ej|d$k(rdd%l
m?Z?m@Z@dd&lAmAZAmBZBmCZCdd'lAmDZDmEZEmFZFddlAZGddlHZHddlIZIddlJZJeKZLd(gZMeNe
d)ZOe.ZPeZQd*ZRd+ZSd,ZTed-d.ZUd/ZVGd0d1ed1d2ZWGd3d4eWeZXGd5d6eZYeXjfdddd7d8Z[dHe\d9eXjdddddd:d;Z]e[Z^e]Z_Gd<d=Z`d>ZaGd?d@eAZbebeY_ce`eY_ddAZedBZfdCZgdDZhdEZiejdeFfdFZkdGZly#e#$rYJwxYwcc}}w)Ia
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)SSLErrorSSLZeroReturnErrorSSLWantReadErrorSSLWantWriteErrorSSLSyscallErrorSSLEOFErrorSSLCertVerificationError)txt2objnid2obj)RAND_statusRAND_add
RAND_bytes)RAND_egd)
HAS_SNIHAS_ECDHHAS_NPNHAS_ALPN	HAS_SSLv2	HAS_SSLv3	HAS_TLSv1HAS_TLSv1_1HAS_TLSv1_2HAS_TLSv1_3)_DEFAULT_CIPHERS_OPENSSL_API_VERSION
_SSLMethodc2|jdxr|dk7S)N	PROTOCOL_PROTOCOL_SSLv23
startswithnames 7/BuggyBox/python/3.12.0/bootstrap/lib/python3.12/ssl.py<lambda>r0}s-K$:K2K)sourceOptionsc$|jdS)NOP_r+r-s r/r0r0s'r1AlertDescriptionc$|jdS)NALERT_DESCRIPTION_r+r-s r/r0r0s!56r1SSLErrorNumberc$|jdS)N
SSL_ERROR_r+r-s r/r0r0s.r1VerifyFlagsc$|jdS)NVERIFY_r+r-s r/r0r0s+r1
VerifyModec$|jdS)NCERT_r+r-s r/r0r0s)r1PROTOCOL_SSLv2ceZdZejZejZejZ	ejZejZ
ejZej Zy)
TLSVersionN)__name__
__module____qualname___sslPROTO_MINIMUM_SUPPORTEDMINIMUM_SUPPORTEDPROTO_SSLv3SSLv3PROTO_TLSv1TLSv1
PROTO_TLSv1_1TLSv1_1
PROTO_TLSv1_2TLSv1_2
PROTO_TLSv1_3TLSv1_3PROTO_MAXIMUM_SUPPORTEDMAXIMUM_SUPPORTEDr1r/rDrDsQ44EE  G  G  G44r1rDc(eZdZdZdZdZdZdZdZdZ	y)	_TLSContentTypez@Content types (record layer)

    See RFC 8446, section B.1
    N)
rErFrG__doc__CHANGE_CIPHER_SPECALERT	HANDSHAKEAPPLICATION_DATAHEADERINNER_CONTENT_TYPErWr1r/rYrYs*EI
Fr1rYceZdZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZ
dZd
ZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZ dZ!d Z"d!Z#d"Z$d#Z%y$)%
_TLSAlertTypezQAlert types for TLSContentType.ALERT messages

    See RFC 8466, section B.2
    r
rZr[r\()*+,-./0123<FGPVZdmnopqrstxN)&rErFrGr`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_PROTOCOLrWr1r/rhrhsLNONO JMLMNM"&)#!$!r1rhcheZdZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZ
dZd
ZdZdZdZdZdZdZdZdZdZdZy)_TLSMessageTypezFMessage types (handshake protocol)

    See RFC 8446, section B.3
    r
rZr[r\r]Cr_N)rErFrGr`
HELLO_REQUESTCLIENT_HELLOSERVER_HELLOHELLO_VERIFY_REQUESTNEWSESSION_TICKETEND_OF_EARLY_DATAHELLO_RETRY_REQUESTENCRYPTED_EXTENSIONSCERTIFICATESERVER_KEY_EXCHANGECERTIFICATE_REQUESTSERVER_DONECERTIFICATE_VERIFYCLIENT_KEY_EXCHANGEFINISHEDCERTIFICATE_URLCERTIFICATE_STATUSSUPPLEMENTAL_DATA
KEY_UPDATE
NEXT_PROTOMESSAGE_HASHrarWr1r/rrsMLLKKHOJJLr1rwin32)enum_certificates	enum_crls)socketSOCK_STREAMcreate_connection)
SOL_SOCKETSO_TYPE_GLOBAL_DEFAULT_TIMEOUT
tls-uniqueHOSTFLAG_NEVER_CHECK_SUBJECTc|sy|jd}|s!|j|jk(S|dkDrtdj||j	d\}}}d|vrtdj||stdj||dk7rtdj||j	d\}}}|r|sy|j|jk(S)	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<partial wildcards in leftmost label are not supported: {!r}.)countlowerCertificateErrorformat	partition)dnhostname	wildcardsdn_leftmostsepdn_remainderhostname_leftmosthostname_remainders        r/_dnsname_matchrs
IxxzX^^---1}?FFrJL	L&(\\#%6"Kl
l
F2J 	 
F2J 	 c
F2J 	 2:1C1CC1H.s.C#5#;#;#===r1c	tj|}tj||k(r|Stdj	|#t
$rYnwxYw	tjtj|S#t
$rtdj	|t$rYnwxYwtdj	|)zTry to convert an IP address to packed binary form

    Supports IPv4 addresses on all platforms and IPv6 on platforms with IPv6
    support.
    z'{!r} is not a quad-dotted IPv4 address.z+{!r} is neither an IPv4 nor an IP6 address.z{!r} is not an IPv4 address.)	_socket	inet_aton	inet_ntoa
ValueErrorrOSError	inet_ptonAF_INET6AttributeError)ipnameaddrs  r/_inet_patonrIs
  (
T"f,K9@@H



  !1!16::4$$*F6N4	4

3::6B
CCs#A	AA#A??+B-,B-c>t|j}||k(S)zExact matching of IP addresses.

    RFC 6125 explicitly doesn't define an algorithm for this
    (section 1.7.2 - "Out of Scope").
    )rrstrip)cert_ipaddresshost_ipips   r/_ipaddress_matchrls!
^**,	-B
=r1DefaultVerifyPathszQcafile capath openssl_cafile_env openssl_cafile openssl_capath_env openssl_capathc`tj}tjj	|d|d}tjj	|d|d}ttjj|r|ndtjj|r|ndg|S)z/Return paths to default cafile and capath.
    rrrrN)	rHget_default_verify_pathsosenvirongetrpathisfileisdir)partscafilecapaths   r/rr|s
))+EZZ^^E!HeAh
/F
ZZ^^E!HeAh
/Fv(>fD(*

f(=f4&$&&r1cNeZdZdZdZfdZefdZefdZxZ	S)_ASN1Objectz#ASN.1 object identifier lookup
    rWc:t||gt|dS)NFr-super__new___txt2obj)clsoid	__class__s  r/rz_ASN1Object.__new__sws?Xc%>??r1c6t||gt|S)z3Create _ASN1Object from OpenSSL numeric ID
        )rr_nid2obj)rnidrs  r/fromnidz_ASN1Object.fromnidsws3Xc]33r1c:t||gt|dS)z=Create _ASN1Object from short name, long name or OID
        Tr-r
)rr.rs  r/fromnamez_ASN1Object.fromnames ws?Xd%>??r1)
rErFrGr`	__slots__rclassmethodrr
__classcell__rs@r/rrs=I@44
@@r1rznid shortname longname oidceZdZdZdZdZy)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)rErFrGr`SERVER_AUTHCLIENT_AUTHrWr1r/rrs%K%Kr1rcjeZdZdZdZdZdZddZdZ				d dZ			d!dZ
dZd	Zd
Z
dZej fdZeed
r<efdZej,fdZefdZej,fdZefdZej,fdZeedredZej,dZnedZefdZej,fdZefdZefdZej,fdZefdZej,fdZxZS)"
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.r)category
stacklevel)warningswarnDeprecationWarningPROTOCOL_TLSrr)rprotocolargskwargsselfs     r/rzSSLContext.__new__s;MMK+

$H""31r1c|yt|tr |jdjdS|jdS)Nidnaascii)
isinstancestrencodedecode)r0rs  r/_encode_hostnamezSSLContext._encode_hostnames>
#
&??6*11'::??7++r1c	F|jj|||||||S)N)sockserver_sidedo_handshake_on_connectsuppress_ragged_eofsserver_hostnamecontextsession)sslsocket_class_create)r0r:r;r<r=r>r@s       r/wrap_socketzSSLContext.wrap_sockets7##++#$;!5+,
	
r1cb|jj||||j|||S)N)r;r>r@r?)sslobject_classrBr8)r0incomingoutgoingr;r>r@s      r/wrap_biozSSLContext.wrap_bios<##++hK 11/BT,
	
r1c<tjdtdt}|D]`}t	|d}t|dk(st|dkDrt
d|jt||j|b|j|y)N'ssl NPN is deprecated, use ALPN insteadrr(r3rz(NPN protocols must be 1 to 255 in length)
r)r*r+	bytearraybyteslenrappendextend_set_npn_protocols)r0
npn_protocolsprotosr-bs     r/set_npn_protocolszSSLContext.set_npn_protocolss

5	

%	Hh(A1v{c!fslIJJMM#a&!MM!		
'r1cbd_ytstdfd}|_y)Nznot a callable objectc:j|}|||SN)r8)sslobj
servernamesslctxr0server_name_callbacks   r/shim_cbz3SSLContext.set_servername_callback.<locals>.shim_cbs"!22:>
+FJGGr1)sni_callbackcallable	TypeError)r0r]r^s`` r/set_servername_callbackz"SSLContext.set_servername_callbacks6' $D01 788
H!(Dr1ct}|D]`}t|d}t|dk(st|dkDrtd|j	t||j|b|j
|y)Nr3rrLz)ALPN protocols must be 1 to 255 in length)rMrNrOrrPrQ_set_alpn_protocols)r0alpn_protocolsrTr-rUs     r/set_alpn_protocolszSSLContext.set_alpn_protocolssq&	Hh(A1v{c!fslJKKMM#a&!MM!		
  (r1c
t}	t|D]0\}}}|dk(s
|dus|j|vs |j|2	|r|j||S#t$rtjdY6wxYw)Nx509_asnTz-unable to enumerate Windows certificate store)cadata)rMrrrQPermissionErrorr)r*load_verify_locations)r0	storenamepurposecertscertencodingtrusts       r/_load_windows_store_certsz$SSLContext._load_windows_store_certss	K):9)E
+%hz)}u(<T*	
+&&e&4		KMMIJ	KsA!A!A!!BBct|tst|tjdk(r#|j
D]}|j
|||jy)Nr)r4rrasysplatform_windows_cert_storesrrset_default_verify_paths)r0rmrls   r/load_default_certszSSLContext.load_default_certssV';/G$$<<7"!66
C	..y'B
C%%'r1minimum_versionc*tt|SrY)rDrryr0rs r/ryzSSLContext.minimum_versioneg566r1c|tjk(r$|xjtjzc_t
ttj||yrY)	rDrLoptionsr3OP_NO_SSLv3rr#ry__set__r0valuers  r/ryzSSLContext.minimum_versions?
(((!4!4 44*j9AA$Nr1c*tt|SrY)rDrmaximum_versionr{s r/rzSSLContext.maximum_version$r|r1cJttt
j||yrY)rr#rrrs  r/rzSSLContext.maximum_version(s*j9AA$Nr1c*tt|SrY)r3rr~r{s r/r~zSSLContext.options,suw''r1cJttt
j||yrY)rr#r~rrs  r/r~zSSLContext.options0s
j*-55dEBr1rcb|jtjz}|tjk7SrY_host_flagsrHr)r0ncss  r/hostname_checks_common_namez&SSLContext.hostname_checks_common_name5s)""T%F%FFC$;;;;r1c|r%|xjtjzc_y|xjtjzc_yrYr)r0rs  r/rz&SSLContext.hostname_checks_common_name:s6  T%F%F$FF   D$E$EE r1cy)NTrWr0s r/rz&SSLContext.hostname_checks_common_nameAsr1c6t|}||jSy)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)r0innerrs  r/rzSSLContext._msg_callbackEs%B%&&&r1c#ttt
j|dyt	dstdfd}|_ttt
j||y)N__call__z is not callable.c.	t|}	t|}|tjk(rt}n |tjk(rt
}nt}	||}||||||S#t$rYgwxYw#t$rYjwxYw#t$rY6wxYwrY)rDrrYrerbrhr)conn	directionversioncontent_typemsg_typedatamsg_enumcallbacks       r/rz'SSLContext._msg_callback.<locals>.innerus
$W-
.|<555*!6!66(*
#H-D)W((D:
:'






s4A*A9B*	A65A69	BB	BB)rr#rrhasattrrar)r0rrrs ` r/rzSSLContext._msg_callbacklsf*j7??dKx,xj(9:;;	:2'
j*3;;D%Hr1c*tt|SrY)r'rr-r{s r/r-zSSLContext.protocols%'*++r1c*tt|SrY)r<rverify_flagsr{s r/rzSSLContext.verify_flagss57/00r1cJttt
j||yrY)rr#rrrs  r/rzSSLContext.verify_flagss
j*2::4Gr1cRt|}	t|S#t$r|cYSwxYwrY)rverify_moder?rrs  r/rzSSLContext.verify_modes1#	e$$	L	s
&&cJttt
j||yrY)rr#rrrs  r/rzSSLContext.verify_modes
j*199$Fr1rY)FTTNN)FNN) rErFrGr`rvrArErr8rCrHrVrbrfrrrr rxrrpropertyrysetterrr~rHrrr-rrrrs@r/r#r#s>)OO	,-2,0)-26
 8=/3
( (	)*1)<)<({-.		7
	7
			O
 	O

	7
	7
			O
 	O((
^^CCt34		<
	<
%	+	+	F
,	F
	
	$$L#I#IJ,,11HHGGr1r#)rr	rict|tst||tjk(r"tt}t|_d|_	n.|tjk(rtt}nt||s|s|r|j|||n$|jtk7r|j|t!|drBt"j$j'd}|r!t(j*j,s||_|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)r4rrarr r#PROTOCOL_TLS_CLIENT
CERT_REQUIREDrcheck_hostnamer!PROTOCOL_TLS_SERVERrrk	CERT_NONErxrrrrrtflagsignore_environmentr)rmrr	rir?
keylogfiles      r/create_default_contextrsg{+  
'%%%01+!%	G''	'01!!
6%%fff=					)	""7+w)*ZZ^^O4
cii::&0G#Nr1F)	cert_reqsrrmcertfilekeyfilerr	riclt|tst||tjk(r	|.t
}n'|tjk(r	|t}nt|t|}	||	_
|||	_|rd|	_
|r
|std|s|r|	j|||s|s|r|	j|||n$|	jtk7r|	j|t!|	drBt"j$j'd}
|
r!t(j*j,s|
|	_|	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.
    Tzcertfile must be specifiedrr)r4rrarr rr!rrr#rrload_cert_chainrkrrxrrrrrtrrr)r-rrrmrrrr	rir?rs           r/_create_unverified_contextrsg{+  
'%%%*H	G''	'*H!!"G+G'!%x5667'26%%fff=					)	""7+w)*ZZ^^O4
cii::&0G#Nr1ceZdZdZdZe		ddZedZejdZedZ
e
jdZ
ed	Zed
ZedZ
ddZd
ZddZdZdZdZdZdZdZdZdZddZdZdZy)	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.
    cFt|jjd)NzU does not have a public constructor. Instances are returned by SSLContext.wrap_bio().rarrEr0r.r/s   r/__init__zSSLObject.__init__s+~~&&'(L
M
	
r1Ncd|j|}|j||||||}||_|S)N)r;r>ownerr@)r	_wrap_bio_sslobj)	rrFrGr;r>r@r?r0rZs	         r/rBzSSLObject._create$sD{{3""hK+#

r1c.|jjS)z(The SSLContext that is currently in use.rr?rs r/r?zSSLObject.context0||###r1c&||j_yrYrr0ctxs  r/r?zSSLObject.context5s"r1c.|jjS)z!The SSLSession for client socket.rr@rs r/r@zSSLObject.session9rr1c&||j_yrYrr0r@s  r/r@zSSLObject.session>s&r1c.|jjS)z.Was the client session reused during handshakersession_reusedrs r/rzSSLObject.session_reusedBs||***r1c.|jjS)z%Whether this is a server-side socket.)rr;rs r/r;zSSLObject.server_sideGs||'''r1c.|jjS)z^The currently set server hostname (for SNI), or ``None`` if no
        server hostname is set.)rr>rs r/r>zSSLObject.server_hostnameLs||+++r1c|||jj||}|S|jj|}|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)r0rObuffervs    r/rzSSLObject.readRsB!!#v.A!!#&Ar1c8|jj|S)zWrite 'data' to the SSL object and return the number of bytes
        written.

        The 'data' argument must support the buffer interface.
        )rwriter0rs  r/rzSSLObject.write^s||!!$''r1c8|jj|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.
        )rgetpeercertr0binary_forms  r/rzSSLObject.getpeercertfs||''44r1c<tjdtdy)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.rJrrKN)r)r*r+rs r/selected_npn_protocolzSSLObject.selected_npn_protocolos	

5	
r1c6|jjS)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 r/rz SSLObject.selected_alpn_protocolys||2244r1c6|jjS)z_Return the currently selected cipher as a 3-tuple ``(name,
        ssl_version, secret_bits)``.)rcipherrs r/rzSSLObject.ciphers||""$$r1c6|jjS)zReturn a list of ciphers shared by the client during the handshake or
        None if this is not a valid server connection.
        )rshared_ciphersrs r/rzSSLObject.shared_cipherss||**,,r1c6|jjS)zReturn the current compression algorithm in use, or ``None`` if
        compression was not negotiated or not supported by one of the peers.)rcompressionrs r/rzSSLObject.compressions||''))r1c6|jjS)z8Return the number of bytes that can be read immediately.)rpendingrs r/rzSSLObject.pendings||##%%r1c8|jjy)zStart the SSL/TLS handshake.N)rdo_handshakers r/rzSSLObject.do_handshakes!!#r1c6|jjS)z!Start the SSL shutdown handshake.)rshutdownrs r/unwrapzSSLObject.unwraps||$$&&r1c8|jj|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_bindingr0cb_types  r/rzSSLObject.get_channel_bindings||//88r1c6|jjS)zZReturn a string identifying the protocol version used by the
        current SSL channel. rrrs r/rzSSLObject.versions||##%%r1c6|jjSrY)rverify_client_post_handshakers r/rz&SSLObject.verify_client_post_handshakes||88::r1)FNNNNFr)rErFrGr`rrrBrr?rr@rr;r>rrrrrrrrrrrrrrrWr1r/rrs

5:=A		$$
^^##$$
^^''++((,,

(5
5%
-*
&$'9&
;r1rcXtt|jj|_|S)z*Copy docstring from SSLObject to SSLSocket)getattrrrEr`)funcs r/_sslcopydocrs9dmm4<<DLKr1c^eZdZdZdZe			d+fd	ZeedZ	e	jdZ	eedZejdZeedZd	Z
d,d
ZdZd-dZd
Zed.dZedZedZedZedZedZd/fd	Zd,fd	ZdZd/fd	Zd0fd	Zd1fd	Zd2fd	Zd1fd	Zd2fd	Z dZ!dZ"edZ#fd Z$ed!Z%ed"Z&fd#Z'ed.d$Z(fd%Z)d&Z*d'Z+fd(Z,ed3d)Z-ed*Z.xZ/S)4	SSLSocketzThis class implements a subtype of socket.socket that wraps
    the underlying OS socket in an SSL context when necessary, and
    provides read and write methods over that channel. cFt|jjd)NzX does not have a public constructor. Instances are returned by SSLContext.wrap_socket().rrs   r/rzSSLSocket.__init__s)~~&&'((
)
	
r1c|jtttk7rt	d|r|rtd|td|jr
|stdt|j|j|j|j}|j|fi|}	tt|	>di||j!}
|j#||	_||	_d|	_d|	_||	_|j/||	_||	_||	_	|	j7d}|	jO|
||	_(|rn	|	j$jS|	||	j0|	|	j&|	_|r0|	j!}|dk(rtd
|	jU|	S|	S#t8$r}|j:t:j<k7rd}|	j?}
|	jAd	|	jCd}nE#t8$r9}|j:t:j<t:jDfvrd	}Yd}~nd}~wwxYw|	jA|
|rQd
}tGj:|}||_$d|_%	|	jMn#t8$rYnwxYw	|#d}wxYwYd}~d}~wwxYw#t8t
f$r|	jMwxYw)Nz!only stream sockets are supportedz4server_hostname can only be specified in client modez,session can only be specified in client modez'check_hostname requires server_hostname)familytypeprotofilenoFTrr1z5Closed before TLS handshake with data in recv buffer.rr@zHdo_handshake_on_connect should not be specified for non-blocking socketsrW)+
getsockoptrrrNotImplementedErrorrrdictrrrrrrrr
gettimeoutdetach_context_session_closedrr;r8r>r<r=getpeernamererrnoENOTCONNgetblockingsetblockingrecvEINVALrreasonlibraryclose
settimeout
_connected_wrap_socketr)rr:r;r<r=r>r?r@r/r0sock_timeout	connectedeblockingnotconn_pre_handshake_datar notconn_pre_handshake_data_errortimeoutrs                  r/rBzSSLSocket._creates??:w/;>%&IJJ "233" "/00!!/FGG;;TYYdjj;;=
s{{3)&)
i'1&1(


&&77H'>$$8!'	LI%#

#}}99+t';';

 : +"oo/G#~()stt%%'ts#	<ww%..(I'')HU#

1
.2YYq\*
1775>>5<<"@@-0*	
1

X&)Q3;AGGV3L0:@07;?08JJL<::8<4#*%#	<lZ(



s,GA+K
KAKH&%K&	I(//I#K#I((<K%J65K6	K?KKKKKKK!K>c|jSrY)rrs r/r?zSSLSocket.contexts}}r1c4||_||j_yrY)rrr?rs  r/r?zSSLSocket.context!s
"r1cH|j|jjSyrYrrs r/r@zSSLSocket.session&s#<<#<<'''$r1cN||_|j||j_yyrY)rrr@rs  r/r@zSSLSocket.session,s$
<<##*DLL $r1cH|j|jjSyrYrrs r/rzSSLSocket.session_reused2s#<<#<<...$r1cFtd|jjz)NzCan't dup() %s instances)rrrErs r/dupz
SSLSocket.dup8s$!"<"&.."9"9#:;	;r1cyrYrW)r0msgs  r/_checkClosedzSSLSocket._checkClosed<sr1c>|js|jyyrY)rrrs r/_check_connectedzSSLSocket._check_connected@s

r1cD|j|jtd	||jj||S|jj|S#t$r4}|j
dtk(r|jr|Yd}~yYd}~yd}~wwxYw)zORead up to LEN bytes and return them.
        Return zero-length string on EOF.Nz'Read on closed or unwrapped SSL socket.rr1)r/rrrrr.
SSL_ERROR_EOFr=)r0rOrxs    r/rzSSLSocket.readHs	
<<FGG	!||((f55||((--	vvayM)d.G.G%	s#A"A""	B+$BBBc|j|jtd|jj|S)zhWrite DATA to the underlying SSL channel.  Returns
        number of bytes of DATA actually transmitted.z(Write on closed or unwrapped SSL socket.)r/rrrrs  r/rzSSLSocket.write]s;	
<<GHH||!!$''r1cx|j|j|jj|SrY)r/r1rrrs  r/rzSSLSocket.getpeercertfs/||''44r1c\|jtjdtdy)NrJrrK)r/r)r*r+rs r/rzSSLSocket.selected_npn_protocolls(

5	

r1c|j|jtjsy|jj	SrY)r/rrHrrrs r/rz SSLSocket.selected_alpn_protocolvs4<<t}}<<6688r1cp|j|jy|jjSrY)r/rrrs r/rzSSLSocket.cipher~s.<<<<&&((r1cp|j|jy|jjSrY)r/rrrs r/rzSSLSocket.shared_cipherss.<<<<..00r1cp|j|jy|jjSrY)r/rrrs r/rzSSLSocket.compressions.<<<<++--r1c|j|j8|dk7rtd|jz|jj	|St
|||S)Nrz3non-zero flags not allowed in calls to send() on %s)r/rrrrrsend)r0rrrs   r/r=zSSLSocket.sendsd<<#z INN#$$<<%%d++7<e,,r1c|j|jtd|jz|t|||St||||S)Nz%sendto not allowed on instances of %s)r/rrrrsendto)r0r
flags_or_addrrrs    r/r?zSSLSocket.sendtos^<<#D!^^,-
-
\7>$
667>$
t<<r1c2td|jz)Nz&sendmsg not allowed on instances of %srrrs   r/sendmsgzSSLSocket.sendmsgs ""J"&..#12	2r1c|j|j}|dk7rtd|jzd}t	|5}|jd5}t
|}||kr|j||d}||z
}||krddddddyt|%||S#1swY"xYw#1swYyxYw)Nrz6non-zero flags not allowed in calls to sendall() on %sB)
r/rrr
memoryviewcastrOr=rsendall)	r0rrrview	byte_viewamountrrs	        r/rHzSSLSocket.sendalls<<#z LNN#$$ED!
T499S>
YYfn		)EF"34AQJEfn


7?4//




s$B7/B+
B7+B4	0B77Ccd|j|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_sendrsendfile)r0fileoffsetrrs    r/rNzSSLSocket.sendfiles:<<#**4??7#D&%88r1c|j|j.|dk7rtd|jz|j	|St
|||S)Nrz3non-zero flags not allowed in calls to recv() on %s)r/rrrrrrr0buflenrrs   r/rzSSLSocket.recvs^<<#z INN#$$99V$$7<..r1c|j|r|t|}n|d}|j/|dk7rtd|jz|j||St||||S)Nrrz8non-zero flags not allowed in calls to recv_into() on %s)r/rOrrrrr	recv_intor0rnbytesrrs    r/rUzSSLSocket.recv_intos}v~[F
^F<<#z L..!""99VV,,7$VVU;;r1c|j|jtd|jzt|||S)Nz'recvfrom not allowed on instances of %s)r/rrrrrecvfromrRs   r/rYzSSLSocket.recvfromsI<<#F!^^,-
-7#FE22r1c|j|jtd|jzt||||S)Nz,recvfrom_into not allowed on instances of %s)r/rrrr
recvfrom_intorVs    r/r[zSSLSocket.recvfrom_intosK<<#K!^^,-
-7(??r1c2td|jz)Nz&recvmsg not allowed on instances of %srBrs   r/recvmsgzSSLSocket.recvmsgs!"J"&..#12	2r1c2td|jz)Nz+recvmsg_into not allowed on instances of %srBrs   r/recvmsg_intozSSLSocket.recvmsg_intos !#')-#89	9r1cp|j|j|jjSyNr)r/rrrs r/rzSSLSocket.pendings.<<#<<''))r1cR|jd|_t|
|yrY)r/rrr)r0howrs  r/rzSSLSocket.shutdowns#
r1c|jr#|jj}d|_|Stdt|zNzNo SSL wrapper around )rrrr5)r0ss  r/rzSSLSocket.unwrap
s<<<%%'ADLH5D	ABBr1c||jr|jjStdt|zre)rrrr5rs r/rz&SSLSocket.verify_client_post_handshakes1<<<<<<>>5D	ABBr1c0d|_t|	yrY)rr_real_closer{s r/rizSSLSocket._real_closes
r1c|j|j}	|dk(r|r|jd|jj	|j|y#|j|wxYw)Nr	)r1r
rrr)r0blockr%s   r/rzSSLSocket.do_handshakes]//#	%#~%%LL%%'OOG$DOOG$s2A&&A9c|jrtd|js|jtd|jj|d|j||j|_	|rt|%|}nd}t|)||s#d|_|jr|j|S#ttf$r	d|_wxYw)Nz!can't connect in server-side modez/attempt to connect already-connected SSLSocket!FrT)r;rrrr?rr>rr
connect_exconnectr<rr)r0rrmrcrs    r/
_real_connectzSSLSocket._real_connect)s@AA??dll6NOO||00%--

1

	W'-%"&//%%'I$	DL	s
6A	CCc(|j|dy)QConnects to remote ADDR, and then wraps the connection in
        an SSL channel.FNrpr0rs  r/rnzSSLSocket.connectCs	
4'r1c&|j|dS)rrTrsrts  r/rmzSSLSocket.connect_exHs!!$--r1ct|\}}|jj||j|j
d}||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)r<r=r;)racceptr?rCr<r=)r0newsockrrs   r/rwzSSLSocket.acceptMsQ
(
,,**7,0,H,H)-)B)B $+&}r1c|j|jj|S|tvrtdj	|y)Nz({0} channel binding type not implemented)rrCHANNEL_BINDING_TYPESrrrs  r/rzSSLSocket.get_channel_bindingYsJ<<#<<33G<<33 >EEgNr1cP|j|jjSyrYrrs r/rzSSLSocket.versionds"<<#<<''))r1)FTTNNNrYrr)r)rN)rrrar)0rErFrGr`rrrBrrr?rr@rr,r/r1rrrrrrrrr=r?rCrHrNrrUrYr[r]r_rrrrrirrprnrmrwrrrrs@r/rrs;
FJ;?&*]]~
^^##((
^^++
//;
*(55
99))11..	-=20 9	/
<3@29
CCCC%%4(
.

r1rcddlm}ddlm}d}d}	|j	|ddjdz}||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")timer}calendarr~indextitler)	cert_timer}r~monthstime_formatmonth_numbertts       r/cert_time_to_secondsrssF(K
7||IbqM$7$7$9:Q>im[
1r!ul+b1g566F-6EF	FFs%AA2z-----BEGIN CERTIFICATE-----z-----END CERTIFICATE-----cttj|dd}tg}|t	dt|dDcgc]
}|||dzc}z
}|j
tdzdj|Scc}w)z[Takes a certificate in binary DER format and returns the
    PEM version of it as a string.ASCIIstrictr@
)	r5base64standard_b64encode
PEM_HEADERrangerOrP
PEM_FOOTERjoin)der_cert_bytesfssis    r/DER_cert_to_PEM_certrst	F%%n5wIA
BeAs1vr2
31Qqt9
33BIIj4 99R=4sA>c`|jtstdtz|jj	t
stdt
z|jt
tt
t
}tj|jddS)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,rrstripendswithrrOrdecodebytesr6)pem_cert_stringds  r/PEM_cert_to_DER_certrs%%j1C%&'	'  "++J7A%&'	'JZ0@AAahhw9::r1c&|\}}|t}nt}t|||}t||5}|j	||5}	|	jd}
ddddddt

S#1swYxYw#1swYt

SxYw)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%)r>T)rr_create_stdlib_contextrrCrr)rssl_versionca_certsr%hostportrr?r:sslsockdercerts           r/get_server_certificatersJD$!		$[/8,46G
4	10T

 
 t
 
<	0))$/G	00 ((	0	00 ((s#A=A1A=1A:	6A==Bc.tj|dS)Nz	<unknown>)_PROTOCOL_NAMESr)
protocol_codes r/get_protocol_namers}k::r1rY)mr`rtrcollectionsrenumr_Enumr_IntEnumr_IntFlagrrHrr	r
rrr
rrrrrrrrrrrrrrrImportErrorrrrrrr r!r"r#r$r%r&	_convert_rEr'r,r*__members__itemsrr_SSLv2_IF_EXISTSrDrYrhrrurrrrrrrrrrrr)rsocket_errorrzrHAS_NEVER_CHECK_COMMON_NAME_RESTRICTED_SERVER_CIPHERSrrrrrrrrr#r rrr_create_default_https_contextrrrrrArErrrrrrrr)r.rs00r/<module>rs[Xt	"HHNN33:22	8(K

x'
6
h.
8+
()
0:/F/FF*,2<2H2H2N2N2PQ;45$;Q:'7>h555hh&"&"&"Rh   :<<7199??
%%d,JK.+.>b DF	  4&@*],HI@*&k5&BGBGJ$+#6#6$$"&t$L49*/9L9L$($"&tD4n!74X;X;vyyz
'
&

7<+

(
;.A$(2I),;c*		TRsJ&>
J2&J/.J/