HEX

Warning: set_time_limit() [function.set-time-limit]: Cannot set time limit - prohibited by configuration in /home/u547966/brikov.ru/www/wp-content/plugins/admin-menu-editor/menu-editor.php on line 745
Server: Apache
System: Linux 4.19.0-0.bpo.9-amd64 x86_64 at red40
User: u547966 (5490)
PHP: 5.3.29-mh2
Disabled: syslog, dl, popen, proc_open, proc_nice, proc_get_status, proc_close, proc_terminate, posix_mkfifo, chown, chgrp, accelerator_reset, opcache_reset, accelerator_get_status, opcache_get_status, pcntl_alarm, pcntl_fork, pcntl_waitpid, pcntl_wait, pcntl_wifexited, pcntl_wifstopped, pcntl_wifsignaled, pcntl_wifcontinued, pcntl_wexitstatus, pcntl_wtermsig, pcntl_wstopsig, pcntl_signal, pcntl_signal_dispatch, pcntl_get_last_error, pcntl_strerror, pcntl_sigprocmask, pcntl_sigwaitinfo, pcntl_sigtimedwait, pcntl_exec, pcntl_getpriority, pcntl_setpriority
Upload Files
File: //usr/lib/python3.7/__pycache__/ssl.cpython-37.pyc
B

{ax
@sdZddlZddlZddlmZddlmZmZ	m
ZddlZddlm
Z
mZmZddlmZmZmZddlmZmZmZmZmZmZmZddlmZmZdd	lmZmZm Z m!Z!ydd
lm"Z"Wne#k
rYnXddl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	j0d
e1ddedej0de1ddede	j0de1ddede	j0de1ddedej0de1ddede	j0de1ddede2j3Z4e2_4dde2j56DZ7e8e2ddZ9Gddde	Z:ej;d krdd!lm<Z<m=Z=dd"l>m>Z>m?Z?m@Z@mAZAdd#l>mBZBmCZCddl>ZDddlEZEddlFZFddlGZGeHZId$gZJeKed%ZLe.ZMeZNd&d'ZOd(d)ZPd*d+ZQd,d-ZRed.d/ZSd0d1ZTGd2d3d3ed3d4ZUGd5d6d6eUeZVGd7d8d8eZWeVjXfdddd9d:d;ZYe3feZd<eVjXdddddd=d>d?Z[eYZ\e[Z]Gd@dAdAZ^GdBdCdCe>Z_e_eW_`e^eW_addd<eZe3ddDdDdf	dEdFZbdGdHZcdIZddJZedKdLZfdMdNZge3dfdOdPZhdQdRZidS)Sa
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())

  fetch_server_certificate (HOST, PORT) -- fetch the certificate provided
                          by the server running on HOST at port PORT.  No
                          validation of the certificate is performed.

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)OPENSSL_VERSION_NUMBEROPENSSL_VERSION_INFOOPENSSL_VERSION)_SSLContext	MemoryBIO
SSLSession)SSLErrorSSLZeroReturnErrorSSLWantReadErrorSSLWantWriteErrorSSLSyscallErrorSSLEOFErrorSSLCertVerificationError)txt2objnid2obj)RAND_statusRAND_add
RAND_bytesRAND_pseudo_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
_SSLMethodcCs|do|dkS)NZ	PROTOCOL_PROTOCOL_SSLv23)
startswith)namer*/usr/lib/python3.7/ssl.py<lambda>|r,)sourceOptionscCs
|dS)NZOP_)r()r)r*r*r+r,r-ZAlertDescriptioncCs
|dS)NZALERT_DESCRIPTION_)r()r)r*r*r+r,r-ZSSLErrorNumbercCs
|dS)NZ
SSL_ERROR_)r()r)r*r*r+r,r-VerifyFlagscCs
|dS)NZVERIFY_)r()r)r*r*r+r,r-
VerifyModecCs
|dS)NZCERT_)r()r)r*r*r+r,r-cCsi|]\}}||qSr*r*).0r)valuer*r*r+
<dictcomp>sr4ZPROTOCOL_SSLv2c@s6eZdZejZejZejZ	ej
ZejZ
ejZejZdS)
TLSVersionN)__name__
__module____qualname___sslZPROTO_MINIMUM_SUPPORTEDZMINIMUM_SUPPORTEDZPROTO_SSLv3SSLv3ZPROTO_TLSv1ZTLSv1Z
PROTO_TLSv1_1ZTLSv1_1Z
PROTO_TLSv1_2ZTLSv1_2Z
PROTO_TLSv1_3ZTLSv1_3ZPROTO_MAXIMUM_SUPPORTEDZMAXIMUM_SUPPORTEDr*r*r*r+r5sr5win32)enum_certificates	enum_crls)socketAF_INETSOCK_STREAMcreate_connection)
SOL_SOCKETSO_TYPEz
tls-uniqueHOSTFLAG_NEVER_CHECK_SUBJECTcCs|sdS|d}|s&||kS|dkr<td||d\}}}d|krbtd||sttd||dkrtd||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*z1too 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)ZdnhostnameZ	wildcardsZdn_leftmostsepZdn_remainderZhostname_leftmostZhostname_remainderr*r*r+_dnsname_matchs2

rOcCs|ddkr.y
t|Stk
r,YnXyttj|Stk
r^td|Yntk
rpYnXtd|dS)zTry to convert an IP address to packed binary form

    Supports IPv4 addresses on all platforms and IPv6 on platforms with IPv6
    support.
    rGz+{!r} is neither an IPv4 nor an IP6 address.z{!r} is not an IPv4 address.N)	rH_socketZ	inet_atonOSErrorZ	inet_ptonZAF_INET6
ValueErrorrKAttributeError)ipnamer*r*r+_inet_patons
rVcCst|}||kS)zExact matching of IP addresses.

    RFC 6125 explicitly doesn't define an algorithm for this
    (section 1.7.2 - "Out of Scope").
    )rVrstrip)rUhost_ipZipr*r*r+_ipaddress_match	srYcCsN|stdyt|}Wntk
r0d}YnXg}|dd}xb|D]Z\}}|dkrz|dkrnt||rndS||qH|dkrH|dk	rt||rdS||qHW|sxF|ddD]6}x0|D](\}}|dkrt||rdS||qWqWt|d	krtd
|dt	t
|fn,t|d	krBtd||d
fntddS)aVerify that *cert* (in decoded format as returned by
    SSLSocket.getpeercert()) matches the *hostname*.  RFC 2818 and RFC 6125
    rules are followed.

    The function matches IP addresses rather than dNSNames if hostname is a
    valid ipaddress string. IPv4 addresses are supported on all platforms.
    IPv6 addresses are supported on platforms with IPv6 support (AF_INET6
    and inet_pton).

    CertificateError is raised on failure. On success, the function
    returns nothing.
    ztempty or no certificate, match_hostname needs a SSL socket or SSL context with either CERT_OPTIONAL or CERT_REQUIREDNZsubjectAltNamer*ZDNSz
IP AddressZsubjectZ
commonNamerFz&hostname %r doesn't match either of %sz, zhostname %r doesn't match %rrz=no appropriate commonName or subjectAltName fields were found)rSrVgetrOappendrYlenrJjoinmaprepr)certrMrXZdnsnamesZsankeyr3subr*r*r+match_hostnames>


rcDefaultVerifyPathszQcafile capath openssl_cafile_env openssl_cafile openssl_capath_env openssl_capathcCsdt}tj|d|d}tj|d|d}ttj|rF|ndtj|rX|ndf|S)z/Return paths to default cafile and capath.
    rrFrPN)	r9get_default_verify_pathsosenvironrZrdpathisfileisdir)partscafilecapathr*r*r+rfQsrfcsDeZdZdZdZfddZefddZefddZZ	S)	_ASN1Objectz#ASN.1 object identifier lookup
    r*cstj|ft|ddS)NF)r))super__new___txt2obj)clsoid)	__class__r*r+rqdsz_ASN1Object.__new__cstj|ft|S)z3Create _ASN1Object from OpenSSL numeric ID
        )rprq_nid2obj)rsZnid)rur*r+fromnidgsz_ASN1Object.fromnidcstj|ft|ddS)z=Create _ASN1Object from short name, long name or OID
        T)r))rprqrr)rsr))rur*r+fromnamemsz_ASN1Object.fromname)
r6r7r8__doc__	__slots__rqclassmethodrwrx
__classcell__r*r*)rur+ro_s
roznid shortname longname oidc@seZdZdZdZdZdS)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)r6r7r8rySERVER_AUTHZCLIENT_AUTHr*r*r*r+r}tsr}csneZdZdZdZdZdZefddZddZ	d/d
dZ
d0dd
ZddZddZ
ddZddZejfddZeedrefddZejfddZefddZejfddZefdd Zejfd!d Zeed"red#d$Zejd%d$Zned&d$Zefd'd(Zefd)d*Zejfd+d*Zefd,d-Zejfd.d-ZZS)1
SSLContextz|An SSLContext holds various SSL-related configuration options and
    data, such as certificates and possibly a private key.)ZCAZROOTNcOst||}|S)N)r	rq)rsprotocolargskwargsselfr*r*r+rqszSSLContext.__new__cCs4|dkrdSt|tr&|ddS|dSdS)NZidnaascii)
isinstancestrencodedecode)rrMr*r*r+_encode_hostnames

zSSLContext._encode_hostnameFTc	Cs|jj|||||||dS)N)sockserver_sidedo_handshake_on_connectsuppress_ragged_eofsserver_hostnamecontextsession)sslsocket_class_create)rrrrrrrr*r*r+wrap_socketszSSLContext.wrap_socketcCs|jj|||||||dS)N)rrrr)sslobject_classrr)rincomingoutgoingrrrr*r*r+wrap_bioszSSLContext.wrap_biocCsdt}xN|D]F}t|d}t|dks2t|dkr:td|t|||qW||dS)Nrrz(NPN protocols must be 1 to 255 in length)	bytearraybytesr\rr[extendZ_set_npn_protocols)rZ
npn_protocolsprotosrbr*r*r+set_npn_protocolss

zSSLContext.set_npn_protocolscs8dkrd_n$ts tdfdd}|_dS)Nznot a callable objectcs|}|||S)N)r)sslobjZ
servernameZsslctx)rserver_name_callbackr*r+shim_cbs
z3SSLContext.set_servername_callback.<locals>.shim_cb)Zsni_callbackcallable	TypeError)rrrr*)rrr+set_servername_callbacksz"SSLContext.set_servername_callbackcCsdt}xN|D]F}t|d}t|dks2t|dkr:td|t|||qW||dS)Nrrrz)ALPN protocols must be 1 to 255 in length)rrr\rr[rZ_set_alpn_protocols)rZalpn_protocolsrrrr*r*r+set_alpn_protocolss

zSSLContext.set_alpn_protocolscCszt}y@x:t|D].\}}}|dkr|dks6|j|kr||qWWntk
rdtdYnX|rv|j|d|S)NZx509_asnTz-unable to enumerate Windows certificate store)cadata)rr<rtrPermissionErrorwarningswarnload_verify_locations)r	storenamepurposeZcertsr`encodingZtrustr*r*r+_load_windows_store_certssz$SSLContext._load_windows_store_certscCsDt|tst|tjdkr8x|jD]}|||q$W|dS)Nr;)rrorsysplatform_windows_cert_storesrZset_default_verify_paths)rrrr*r*r+load_default_certss

zSSLContext.load_default_certsminimum_versioncsttjS)N)r5rpr)r)rur*r+rszSSLContext.minimum_versioncs4|tjkr|jtjM_tttj||dS)N)	r5r:optionsr/ZOP_NO_SSLv3rprr__set__)rr3)rur*r+rs
csttjS)N)r5rpmaximum_version)r)rur*r+rszSSLContext.maximum_versioncstttj||dS)N)rprrr)rr3)rur*r+rscsttjS)N)r/rpr)r)rur*r+rszSSLContext.optionscstttj||dS)N)rprrr)rr3)rur*r+rsrDcCs|jtj@}|tjkS)N)_host_flagsr9rD)rZncsr*r*r+hostname_checks_common_namesz&SSLContext.hostname_checks_common_namecCs,|r|jtjM_n|jtjO_dS)N)rr9rD)rr3r*r*r+rscCsdS)NTr*)rr*r*r+r
scsttjS)N)r&rpr)r)rur*r+rszSSLContext.protocolcsttjS)N)r0rpverify_flags)r)rur*r+rszSSLContext.verify_flagscstttj||dS)N)rprrr)rr3)rur*r+rscs*tj}yt|Stk
r$|SXdS)N)rpverify_moder1rS)rr3)rur*r+rs
zSSLContext.verify_modecstttj||dS)N)rprrr)rr3)rur*r+r"s)FTTNN)FNN) r6r7r8ryrrrPROTOCOL_TLSrqrrrrrrrr}r~rhasattrr	propertyrsetterrrr9rrrrr|r*r*)rur+r{sB


	

r)rmrnrcCsdt|tst|tt}|tjkr0t|_d|_	|s<|s<|rL|
|||n|jtkr`|||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.
    T)
rrorrrr}r~
CERT_REQUIREDrcheck_hostnamer	CERT_NONEr)rrmrnrrr*r*r+create_default_context's



rF)	cert_reqsrrcertfilekeyfilermrnrc
Cst|tst|t|}	|s$d|	_|dk	r2||	_|r<d|	_|rL|sLtd|sT|r`|	|||sl|sl|r||	|||n|	jt	kr|	
||	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.
    FNTzcertfile must be specified)rrorrrrrSload_cert_chainrrr)
rrrrrrrmrnrrr*r*r+_create_unverified_contextEs$


rc@seZdZdZddZed2ddZedd	Zej	d
d	ZeddZ
e
j	d
dZ
eddZeddZeddZ
d3ddZddZd4ddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd5d,d-Zd.d/Zd0d1ZdS)6	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.
    cOst|jjddS)NzU does not have a public constructor. Instances are returned by SSLContext.wrap_bio().)rrur6)rrrr*r*r+__init__szSSLObject.__init__FNc	Cs*||}|j||||||d}||_|S)N)rrownerr)rqZ	_wrap_bio_sslobj)	rsrrrrrrrrr*r*r+rs

zSSLObject._createcCs|jjS)z(The SSLContext that is currently in use.)rr)rr*r*r+rszSSLObject.contextcCs||j_dS)N)rr)rctxr*r*r+rscCs|jjS)z!The SSLSession for client socket.)rr)rr*r*r+rszSSLObject.sessioncCs||j_dS)N)rr)rrr*r*r+rscCs|jjS)z.Was the client session reused during handshake)rsession_reused)rr*r*r+rszSSLObject.session_reusedcCs|jjS)z%Whether this is a server-side socket.)rr)rr*r*r+rszSSLObject.server_sidecCs|jjS)z]The currently set server hostname (for SNI), or ``None`` if no
        server hostame is set.)rr)rr*r*r+rszSSLObject.server_hostnamecCs(|dk	r|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.
        N)rread)rr\buffervr*r*r+rszSSLObject.readcCs|j|S)zWrite 'data' to the SSL object and return the number of bytes
        written.

        The 'data' argument must support the buffer interface.
        )rwrite)rdatar*r*r+rszSSLObject.writecCs|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.
        )rgetpeercert)rbinary_formr*r*r+rszSSLObject.getpeercertcCstjr|jSdS)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.N)r9rrselected_npn_protocol)rr*r*r+rszSSLObject.selected_npn_protocolcCstjr|jSdS)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.N)r9rrselected_alpn_protocol)rr*r*r+rsz SSLObject.selected_alpn_protocolcCs
|jS)z_Return the currently selected cipher as a 3-tuple ``(name,
        ssl_version, secret_bits)``.)rcipher)rr*r*r+rszSSLObject.ciphercCs
|jS)zReturn a list of ciphers shared by the client during the handshake or
        None if this is not a valid server connection.
        )rshared_ciphers)rr*r*r+rszSSLObject.shared_cipherscCs
|jS)zReturn the current compression algorithm in use, or ``None`` if
        compression was not negotiated or not supported by one of the peers.)rcompression)rr*r*r+rszSSLObject.compressioncCs
|jS)z8Return the number of bytes that can be read immediately.)rpending)rr*r*r+rszSSLObject.pendingcCs|jdS)zStart the SSL/TLS handshake.N)rdo_handshake)rr*r*r+rszSSLObject.do_handshakecCs
|jS)z!Start the SSL shutdown handshake.)rshutdown)rr*r*r+unwrapszSSLObject.unwrap
tls-uniquecCs|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_binding)rcb_typer*r*r+rszSSLObject.get_channel_bindingcCs
|jS)zZReturn a string identifying the protocol version used by the
        current SSL channel. )rversion)rr*r*r+rszSSLObject.versioncCs
|jS)N)rverify_client_post_handshake)rr*r*r+rsz&SSLObject.verify_client_post_handshake)FNNN)rN)F)r)r6r7r8ryrr{rrrrrrrrrrrrrrrrrrrrrrr*r*r*r+rws4


	
rcseZdZdZddZedXfdd	Zed	d
Zej	dd
Zedd
Z
e
j	dd
Z
eddZddZdYddZ
ddZdZddZddZd[ddZddZd d!Zd"d#Zd$d%Zd&d'Zd\fd)d*	Zd]fd+d,	Zd-d.Zd^fd/d0	Zd_fd1d2	Zd`fd3d4	Zdafd5d6	Zdbfd7d8	Zdcfd9d:	Zd;d<Z d=d>Z!d?d@Z"fdAdBZ#dCdDZ$dEdFZ%fdGdHZ&dddIdJZ'fdKdLZ(dMdNZ)dOdPZ*fdQdRZ+dedTdUZ,dVdWZ-Z.S)f	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. cOst|jjddS)NzX does not have a public constructor. Instances are returned by SSLContext.wrap_socket().)rrur6)rrrr*r*r+rszSSLSocket.__init__FTNc

s|tttkrtd|r8|r(td|dk	r8td|jrJ|sJtdt|j|j	|j
|d}|j|f|}	t
t|	jf||	||||	_||	_d|	_d|	_||	_|||	_||	_||	_y|	Wn6tk
r}
z|
jtjkrd}Wdd}
~
XYnXd}||	_ |ryH|	jj!|	||	j|	|	jd|	_|rj|	}|d	krbtd
|	"Wn$ttfk
r|	#YnX|	S)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)familytypeprotofilenoFT)rrgzHdo_handshake_on_connect should not be specified for non-blocking sockets)$Z
getsockoptrBrCr@NotImplementedErrorrSrdictrrrrrqrprr
settimeout
gettimeoutdetach_context_sessionZ_closedrrrrrrgetpeernamerRerrnoZENOTCONN
_connected_wrap_socketrclose)
rsrrrrrrrrreZ	connectedtimeout)rur*r+rs\

zSSLSocket._createcCs|jS)N)r)rr*r*r+r[szSSLSocket.contextcCs||_||j_dS)N)rrr)rrr*r*r+r_scCs|jdk	r|jjSdS)z!The SSLSession for client socket.N)rr)rr*r*r+rds
zSSLSocket.sessioncCs||_|jdk	r||j_dS)N)rrr)rrr*r*r+rjs
cCs|jdk	r|jjSdS)z.Was the client session reused during handshakeN)rr)rr*r*r+rps
zSSLSocket.session_reusedcCstd|jjdS)NzCan't dup() %s instances)rrur6)rr*r*r+dupvsz
SSLSocket.dupcCsdS)Nr*)rmsgr*r*r+_checkClosedzszSSLSocket._checkClosedcCs|js|dS)N)rr)rr*r*r+_check_connected~szSSLSocket._check_connectedc
Cs||jdkrtdy&|dk	r2|j||S|j|SWnJtk
r}z,|jdtkrx|jrx|dk	rrdSdSnWdd}~XYnXdS)zORead up to LEN bytes and return them.
        Return zero-length string on EOF.Nz'Read on closed or unwrapped SSL socket.rr-)rrrSrrrZ
SSL_ERROR_EOFr)rr\rxr*r*r+rs
zSSLSocket.readcCs&||jdkrtd|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.)rrrSr)rrr*r*r+rs
zSSLSocket.writecCs|||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.)rrrr)rrr*r*r+rszSSLSocket.getpeercertcCs*||jdkstjsdS|jSdS)N)rrr9rr)rr*r*r+rszSSLSocket.selected_npn_protocolcCs*||jdkstjsdS|jSdS)N)rrr9rr)rr*r*r+rsz SSLSocket.selected_alpn_protocolcCs$||jdkrdS|jSdS)N)rrr)rr*r*r+rs
zSSLSocket.ciphercCs$||jdkrdS|jSdS)N)rrr)rr*r*r+rs
zSSLSocket.shared_cipherscCs$||jdkrdS|jSdS)N)rrr)rr*r*r+rs
zSSLSocket.compressionrcsF||jdk	r4|dkr(td|j|j|St||SdS)Nrz3non-zero flags not allowed in calls to send() on %s)rrrSrurrpsend)rrflags)rur*r+rs

zSSLSocket.sendcsL||jdk	r"td|jn&|dkr8t||St|||SdS)Nz%sendto not allowed on instances of %s)rrrSrurpsendto)rrZ
flags_or_addraddr)rur*r+rs
zSSLSocket.sendtocOstd|jdS)Nz&sendmsg not allowed on instances of %s)rru)rrrr*r*r+sendmsgszSSLSocket.sendmsgc
s||jdk	r|dkr(td|jd}t|L}|d6}t|}x&||krp|||d}||7}qLWWdQRXWdQRXnt	||SdS)Nrz6non-zero flags not allowed in calls to sendall() on %sB)
rrrSru
memoryviewcastr\rrpsendall)rrrrHZviewZ	byte_viewZamountr)rur*r+rs


"zSSLSocket.sendallcs,|jdk	r||||St|||SdS)zSend a file, possibly by using os.sendfile() if this is a
        clear-text socket.  Return the total number of bytes sent.
        N)rZ_sendfile_use_sendrpsendfile)rfileoffsetrH)rur*r+rs
zSSLSocket.sendfilecsD||jdk	r2|dkr(td|j||St||SdS)Nrz3non-zero flags not allowed in calls to recv() on %s)rrrSrurrprecv)rbuflenr)rur*r+r	s


zSSLSocket.recvcsj||r|dkrt|}n|dkr*d}|jdk	rV|dkrJtd|j|||St|||SdS)Nirz8non-zero flags not allowed in calls to recv_into() on %s)rr\rrSrurrp	recv_into)rrnbytesr)rur*r+rs


zSSLSocket.recv_intocs4||jdk	r"td|jnt||SdS)Nz'recvfrom not allowed on instances of %s)rrrSrurprecvfrom)rr
r)rur*r+r
 s

zSSLSocket.recvfromcs6||jdk	r"td|jnt|||SdS)Nz,recvfrom_into not allowed on instances of %s)rrrSrurp
recvfrom_into)rrrr)rur*r+r(s

zSSLSocket.recvfrom_intocOstd|jdS)Nz&recvmsg not allowed on instances of %s)rru)rrrr*r*r+recvmsg0szSSLSocket.recvmsgcOstd|jdS)Nz+recvmsg_into not allowed on instances of %s)rru)rrrr*r*r+recvmsg_into4szSSLSocket.recvmsg_intocCs$||jdk	r|jSdSdS)Nr)rrr)rr*r*r+r8s

zSSLSocket.pendingcs|d|_t|dS)N)rrrpr)rZhow)rur*r+r?szSSLSocket.shutdowncCs.|jr|j}d|_|Stdt|dS)NzNo SSL wrapper around )rrrSr)rsr*r*r+rDs

zSSLSocket.unwrapcCs$|jr|jStdt|dS)NzNo SSL wrapper around )rrrSr)rr*r*r+rLs
z&SSLSocket.verify_client_post_handshakecsd|_tdS)N)rrp_real_close)r)rur*r+rRszSSLSocket._real_closec	CsF||}z$|dkr(|r(|d|jWd||XdS)zPerform a TLS/SSL handshake.gN)rrrrr)rblockrr*r*r+rVs
zSSLSocket.do_handshakec	s|jrtd|js|jdk	r&td|jj|d|j||jd|_y>|rVt	|}nd}t
||s~d|_|jr~||St
tfk
rd|_YnXdS)Nz!can't connect in server-side modez/attempt to connect already-connected SSLSocket!F)rrT)rrSrrrrrrrp
connect_exconnectrrrR)rrrZrc)rur*r+
_real_connectas(zSSLSocket._real_connectcCs||ddS)zQConnects to remote ADDR, and then wraps the connection in
        an SSL channel.FN)r)rrr*r*r+r{szSSLSocket.connectcCs||dS)zQConnects to remote ADDR, and then wraps the connection in
        an SSL channel.T)r)rrr*r*r+rszSSLSocket.connect_excs.t\}}|jj||j|jdd}||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)rrr)rpacceptrrrr)rZnewsockr)rur*r+rszSSLSocket.accept
tls-uniquecCs4|jdk	r|j|S|tkr,td|dSdS)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).
        Nz({0} channel binding type not implemented)rrCHANNEL_BINDING_TYPESrSrK)rrr*r*r+rs
zSSLSocket.get_channel_bindingcCs|jdk	r|jSdSdS)z
        Return a string identifying the protocol version used by the
        current SSL channel, or None if there is no established channel.
        N)rr)rr*r*r+rs

zSSLSocket.version)FTTNNN)N)rN)F)r)N)r)rN)rr)Nr)rr)Nr)F)r)/r6r7r8ryrr{rrrrrrrrrrrrrrrrrrrrrrr	rr
rrrrrrrrrrrrrrrr|r*r*)rur+rsZ<

	





rTc
Csl|r|std|r |s tdt|}
||
_|r<|
||rL|
|||	rZ|
|	|
j||||dS)Nz5certfile must be specified for server-side operationszcertfile must be specified)rrrr)rSrrrrZset_ciphersr)rrrrrssl_versionca_certsrrZciphersrr*r*r+rs 

rcCsddlm}ddlm}d}d}y||ddd}Wn$tk
rbtd	||fYn0X||dd|}||d|f|d
dSdS)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)ZJanZFebZMarZAprZMayZJunZJulZAugZSepZOctZNovZDecz %d %H:%M:%S %Y GMTNrPrFz*time data %r does not match format "%%b%s"re)ZtimerZcalendarrindextitlerS)Z	cert_timerrZmonthsZtime_formatZmonth_numberZttr*r*r+cert_time_to_secondss
r!z-----BEGIN CERTIFICATE-----z-----END CERTIFICATE-----csRtt|ddtg}|fddtdtdD7}|tdd|S)z[Takes a certificate in binary DER format and returns the
    PEM version of it as a string.ASCIIstrictcsg|]}||dqS)@r*)r2i)fr*r+
<listcomp>sz(DER_cert_to_PEM_cert.<locals>.<listcomp>rr$
)	rbase64Zstandard_b64encode
PEM_HEADERranger\r[
PEM_FOOTERr])Zder_cert_bytesZssr*)r&r+DER_cert_to_PEM_certs
"r-cCs\|tstdt|ts0tdt|tttt}t|	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 %sr"r#)
r(r*rSstripendswithr,r\r)Zdecodebytesr)Zpem_cert_stringdr*r*r+PEM_cert_to_DER_certs
r1c

Csd|\}}|dk	rt}nt}t|||d}t|&}||}|d}	WdQRXWdQRXt|	S)zRetrieve 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.N)rrmT)rr_create_stdlib_contextrArrr-)
rrrZhostZportrrrZsslsockZdercertr*r*r+get_server_certificates
r3cCst|dS)Nz	<unknown>)_PROTOCOL_NAMESrZ)Z
protocol_coder*r*r+get_protocol_namesr5)jryrrgcollectionsrenumrZ_EnumrZ_IntEnumrZ_IntFlagr9rrrr	r
rrr
rrrrrrrrrrvrrrrrImportErrorrrrrrrr r!r"r#r$r%_convertr6r&rr'__members__itemsr4getattrZ_SSLv2_IF_EXISTSr5rr<r=r>r?r@rArBrCrQr)rrrRZsocket_errorrrZHAS_NEVER_CHECK_COMMON_NAMEZ_RESTRICTED_SERVER_CIPHERSrJrOrVrYrcrdrfror}rr~rrrZ_create_default_https_contextr2rrrrrr!r*r,r-r1r3r5r*r*r*r+<module>[s$0

19-(