Files
PowerToys/PythonHome/Lib/ssl.pyc

128 lines
15 KiB
Plaintext
Raw Normal View History

2014-07-09 18:15:23 +08:00
<03>
<EFBFBD>W`Sc
@s/dZddlZddlZddlmZmZmZddlmZddlmZmZm Z ddlm
Z
m Z m Z ddlm Z mZmZmZmZmZmZmZmZddlmZmZmZid e6d
e6d e6Zydd lmZeZWnek
r,eZn Xd ee<ddlmZmZm Z m!Z"ddlm#Z$ddlm%Z%m&Z&m'Z'ddl(Z(ddl)Z)dZ*defd<00><00>YZ+eee,eeee-e-ed<00> Z.d<00>Z/dZ0dZ1d<00>Z2d<00>Z3eed<00>Z4d<00>Z5eed<00>Z6dS(sThis 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_TLSv1
i<EFBFBD><EFBFBD><EFBFBD><EFBFBD>N(tOPENSSL_VERSION_NUMBERtOPENSSL_VERSION_INFOtOPENSSL_VERSION(tSSLError(t CERT_NONEt CERT_OPTIONALt CERT_REQUIRED(t RAND_statustRAND_egdtRAND_add( tSSL_ERROR_ZERO_RETURNtSSL_ERROR_WANT_READtSSL_ERROR_WANT_WRITEtSSL_ERROR_WANT_X509_LOOKUPtSSL_ERROR_SYSCALLt SSL_ERROR_SSLtSSL_ERROR_WANT_CONNECTt SSL_ERROR_EOFtSSL_ERROR_INVALID_ERROR_CODE(tPROTOCOL_SSLv3tPROTOCOL_SSLv23tPROTOCOL_TLSv1tTLSv1tSSLv23tSSLv3(tPROTOCOL_SSLv2tSSLv2(tsockett _fileobjectt_delegate_methodsterror(t getnameinfo(t
SOL_SOCKETtSO_TYPEt SOCK_STREAMs)DEFAULT:!aNULL:!eNULL:!LOW:!EXPORT:!SSLv2t SSLSocketc
BseZdZddeeedeedd<00> Zdd<00>Z d<00>Z
ed<00>Z d<00>Z dd<00>Z dd <00>Zdd
<00>Zddd <00>Zddd <00>Zddd <00>Zddd<00>Zd<00>Zd<00>Zd<00>Zd<00>Zd<00>Zd<00>Zd<00>Zd<00>Zd<00>Zddd<00>ZRS(s<>This class implements a subtype of socket.socket that wraps
the underlying OS socket in an SSL context when necessary, and
2014-07-10 23:57:08 +08:00
provides read and write methods over that channel.c Cs<>|jtt<00>tkr'td<00><00>ntj|d|j<00>x3tD]+} yt || <00>WqDt
2014-07-09 18:15:23 +08:00
k
rnqDXqDW|
dkr<>|t kr<>t }
n|r<>| r<>|}nytj|<00>Wn=tk
r<>} | jtjkr<><00>nt|_d|_nGXt|_tj|j|||||||
<00>|_|rA|j<00>n||_||_||_||_||_|
|_||_| |_ d|_!dS(Ns!only stream sockets are supportedt_socki("t
getsockoptR R!R"tNotImplementedErrorRt__init__R$RtdelattrtAttributeErrortNonet_SSLv2_IF_EXISTSt_DEFAULT_CIPHERSt getpeernamet socket_errorterrnotENOTCONNtFalset
2014-07-10 23:57:08 +08:00
_connectedt_sslobjtTruet_ssltsslwrapt do_handshaketkeyfiletcertfilet cert_reqst ssl_versiontca_certstcipherstdo_handshake_on_connecttsuppress_ragged_eofst_makefile_refs( tselftsockR8R9t server_sideR:R;R<R>R?R=tattrte((s8e:\github\Wox.JSONRPC\Output\Debug\PythonHome\lib\ssl.pyR'ksF                   icCsQy|jj|<00>SWn6tk
2014-07-09 18:15:23 +08:00
rL}|jdtkrF|jrFdS<>nXdS(sORead up to LEN bytes and return them.
2014-07-10 23:57:08 +08:00
Return zero-length string on EOF.itN(R3treadRtargsRR?(RAtlentx((s8e:\github\Wox.JSONRPC\Output\Debug\PythonHome\lib\ssl.pyRG<00>s cCs|jj|<00>S(shWrite DATA to the underlying SSL channel. Returns
number of bytes of DATA actually transmitted.(R3twrite(RAtdata((s8e:\github\Wox.JSONRPC\Output\Debug\PythonHome\lib\ssl.pyRK<00>scCs|jj|<00>S(s<>Returns a formatted version of the data in the
2014-07-09 18:15:23 +08:00
certificate provided by the other end of the SSL channel.
Return None if no certificate was provided, {} if a
2014-07-10 23:57:08 +08:00
certificate was provided, but not validated.(R3tpeer_certificate(RAt binary_form((s8e:\github\Wox.JSONRPC\Output\Debug\PythonHome\lib\ssl.pyt getpeercert<72>scCs|js dS|jj<00>SdS(N(R3R*tcipher(RA((s8e:\github\Wox.JSONRPC\Output\Debug\PythonHome\lib\ssl.pyRP<00>s icCs<>|jr<>|dkr+td|j<16><00>nx<>tr<>y|jj|<00>}WnDtk
2014-07-09 18:15:23 +08:00
r<>}|jdtkrsdS|jdtkr<>dS<>q.X|Sq.Wn|j j
||<00>SdS(Nis3non-zero flags not allowed in calls to send() on %s( R3t
2014-07-10 23:57:08 +08:00
ValueErrort __class__R4RKRRHR R R$tsend(RARLtflagstvRJ((s8e:\github\Wox.JSONRPC\Output\Debug\PythonHome\lib\ssl.pyRS<00>s     cCsX|jrtd|j<16><00>n5|dkr>|jj||<00>S|jj|||<00>SdS(Ns%sendto not allowed on instances of %s(R3RQRRR*R$tsendto(RARLt flags_or_addrtaddr((s8e:\github\Wox.JSONRPC\Output\Debug\PythonHome\lib\ssl.pyRV<00>s   cCs<>|jrq|dkr+td|j<16><00>nt|<00>}d}x-||krl|j||<1F>}||7}q@W|Stj|||<00>SdS(Nis6non-zero flags not allowed in calls to sendall() on %s(R3RQRRRIRSRtsendall(RARLRTtamounttcountRU((s8e:\github\Wox.JSONRPC\Output\Debug\PythonHome\lib\ssl.pyRY<00>s   cCsO|jr8|dkr+td|j<16><00>n|j|<00>S|jj||<00>SdS(Nis3non-zero flags not allowed in calls to recv() on %s(R3RQRRRGR$trecv(RAtbuflenRT((s8e:\github\Wox.JSONRPC\Output\Debug\PythonHome\lib\ssl.pyR\<00>s   cCs<>|r!|dkr!t|<00>}n|dkr6d}n|jr<>|dkratd|j<16><00>n|j|<00>}t|<00>}|||*|S|jj|||<00>SdS(Niis8non-zero flags not allowed in calls to recv_into() on %s(R*RIR3RQRRRGR$t recv_into(RAtbuffertnbytesRTt
tmp_bufferRU((s8e:\github\Wox.JSONRPC\Output\Debug\PythonHome\lib\ssl.pyR^<00>s     
cCs6|jrtd|j<16><00>n|jj||<00>SdS(Ns'recvfrom not allowed on instances of %s(R3RQRRR$trecvfrom(RAR]RT((s8e:\github\Wox.JSONRPC\Output\Debug\PythonHome\lib\ssl.pyRb s cCs9|jrtd|j<16><00>n|jj|||<00>SdS(Ns,recvfrom_into not allowed on instances of %s(R3RQRRR$t recvfrom_into(RAR_R`RT((s8e:\github\Wox.JSONRPC\Output\Debug\PythonHome\lib\ssl.pyRcs cCs|jr|jj<00>SdSdS(Ni(R3tpending(RA((s8e:\github\Wox.JSONRPC\Output\Debug\PythonHome\lib\ssl.pyRds  cCs?|jr%|jj<00>}d|_|Stdt|<00><17><00>dS(NsNo SSL wrapper around (R3tshutdownR*RQtstr(RAts((s8e:\github\Wox.JSONRPC\Output\Debug\PythonHome\lib\ssl.pytunwraps
  cCsd|_tj||<00>dS(N(R*R3RRe(RAthow((s8e:\github\Wox.JSONRPC\Output\Debug\PythonHome\lib\ssl.pyRe's cCs;|jdkr(d|_tj|<00>n|jd8_dS(Ni(R@R*R3Rtclose(RA((s8e:\github\Wox.JSONRPC\Output\Debug\PythonHome\lib\ssl.pyRj+s cCs|jj<00>dS(sPerform a TLS/SSL handshake.N(R3R7(RA((s8e:\github\Wox.JSONRPC\Output\Debug\PythonHome\lib\ssl.pyR72sc Cs<>|jrtd<00><00>ntj|jt|j|j|j|j |j
2014-07-09 18:15:23 +08:00
|j <00>|_ ya|rrt j||<00>}nd}t j||<00>|s<>|jr<>|j<00>nt|_n|SWntk
r<>d|_ <00>nXdS(Ns/attempt to connect already-connected SSLSocket!(R2RQR5R6R$R1R8R9R:R;R<R=R3Rt
2014-07-10 23:57:08 +08:00
connect_exR*tconnectR>R7R4R.(RARXt return_errnotrc((s8e:\github\Wox.JSONRPC\Output\Debug\PythonHome\lib\ssl.pyt _real_connect8s$       cCs|j|t<00>dS(sQConnects to remote ADDR, and then wraps the connection in
an SSL channel.N(RoR1(RARX((s8e:\github\Wox.JSONRPC\Output\Debug\PythonHome\lib\ssl.pyRlOscCs|j|t<00>S(sQConnects to remote ADDR, and then wraps the connection in
an SSL channel.(RoR4(RARX((s8e:\github\Wox.JSONRPC\Output\Debug\PythonHome\lib\ssl.pyRkTscCs<>tj|<00>\}}ybt|d|jd|jdtd|jd|jd|jd|j d|j
2014-07-09 18:15:23 +08:00
d |j <00> |fSWn#t k
r<>}|j <00>|<00>nXd
S( s<>Accepts a new connection from a remote client, and returns
a tuple containing that new connection wrapped with a server-side
2014-07-10 23:57:08 +08:00
SSL channel, and the address of the remote client.R8R9RCR:R;R<R=R>R?N(RtacceptR#R8R9R4R:R;R<R=R>R?R.Rj(RAtnewsockRXRE((s8e:\github\Wox.JSONRPC\Output\Debug\PythonHome\lib\ssl.pyRpYs           
2014-07-09 18:15:23 +08:00
tri<72><69><EFBFBD><EFBFBD>cCs%|jd7_t|||dt<00>S(s<>Make and return a file-like object that
works with the SSL connection. Just use the code
2014-07-10 23:57:08 +08:00
from the socket module.iRj(R@RR4(RAtmodetbufsize((s8e:\github\Wox.JSONRPC\Output\Debug\PythonHome\lib\ssl.pytmakefilepsN(t__name__t
__module__t__doc__R*R1RRR4R'RGRKRORPRSRVRYR\R^RbRcRdRhReRjR7RoRlRkRpRu(((s8e:\github\Wox.JSONRPC\Output\Debug\PythonHome\lib\ssl.pyR#es60    
2014-07-09 18:15:23 +08:00
         c
Cs@t|d|d|d|d|d|d|d|d|d | <00> S(
NR8R9RCR:R;R<R>R?R=(R#(
2014-07-10 23:57:08 +08:00
RBR8R9RCR:R;R<R>R?R=((s8e:\github\Wox.JSONRPC\Output\Debug\PythonHome\lib\ssl.pyt wrap_socket}s   cCs%ddl}|j|j|d<00><00>S(s<>Takes a date-time string in standard ASN1_print form
2014-07-09 18:15:23 +08:00
("MON DAY 24HOUR:MINUTE:SEC YEAR TIMEZONE") and return
2014-07-10 23:57:08 +08:00
a Python time value in seconds past the epoch.i<><69><EFBFBD><EFBFBD>Ns%b %d %H:%M:%S %Y GMT(ttimetmktimetstrptime(t cert_timeRz((s8e:\github\Wox.JSONRPC\Output\Debug\PythonHome\lib\ssl.pytcert_time_to_seconds<64>s s-----BEGIN CERTIFICATE-----s-----END CERTIFICATE-----cCscttd<00>rBtj|<00>}tdtj|d<00>dtdStdtj|<00>tdSdS(s[Takes a certificate in binary DER format and returns the
2014-07-09 18:15:23 +08:00
PEM version of it as a string.tstandard_b64encodes
i@N(thasattrtbase64Rt
PEM_HEADERttextwraptfillt
2014-07-10 23:57:08 +08:00
PEM_FOOTERt encodestring(tder_cert_bytestf((s8e:\github\Wox.JSONRPC\Output\Debug\PythonHome\lib\ssl.pytDER_cert_to_PEM_cert<72>s$cCsw|jt<00>s"tdt<16><00>n|j<00>jt<00>sJtdt<16><00>n|j<00>tt<00>tt<00> !}tj|<00>S(shTakes a certificate in ASCII PEM format and returns the
2014-07-09 18:15:23 +08:00
DER-encoded version of it as a byte sequences(Invalid PEM encoding; must start with %ss&Invalid PEM encoding; must end with %s( t
2014-07-10 23:57:08 +08:00
startswithR<68>RQtstriptendswithR<68>RIR<>t decodestring(tpem_cert_stringtd((s8e:\github\Wox.JSONRPC\Output\Debug\PythonHome\lib\ssl.pytPEM_cert_to_DER_cert<72>s   cCsx|\}}|dk r!t}nt}tt<00>d|d|d|<00>}|j|<00>|jt<00>}|j<00>t |<00>S(s<>Retrieve the certificate from the server at the specified address,
2014-07-09 18:15:23 +08:00
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.R;R:R<N(
2014-07-10 23:57:08 +08:00
R*RRRyRRlROR4RjR<>(RXR;R<thosttportR:Rgtdercert((s8e:\github\Wox.JSONRPC\Output\Debug\PythonHome\lib\ssl.pytget_server_certificate<74>s    
cCstj|d<00>S(Ns <unknown>(t_PROTOCOL_NAMEStget(t protocol_code((s8e:\github\Wox.JSONRPC\Output\Debug\PythonHome\lib\ssl.pytget_protocol_name<6D>scCslt|d<00>r|j}ntj|d||ttd<00>}y|j<00>Wntk
2014-07-09 18:15:23 +08:00
r]n X|j <00>|S(s<>A replacement for the old socket.ssl function. Designed
for compability with Python 2.5 and earlier. Will disappear in
Python 3.0.R$iN(
2014-07-10 23:57:08 +08:00
R<>R$R5R6RRR*R-R.R7(RBR8R9tssl_sock((s8e:\github\Wox.JSONRPC\Output\Debug\PythonHome\lib\ssl.pytsslwrap_simple<6C>s   
2014-07-09 18:15:23 +08:00
(7RxR<>R5RRRRRRRRRR R
2014-07-10 23:57:08 +08:00
R R R RRRRRRRRR<>RR+t ImportErrorR*RRRRR.Rt _getnameinfoR R!R"R<>R/R,R#R1R4RyR~R<>R<>R<>R<>R<>R<>R<>(((s8e:\github\Wox.JSONRPC\Output\Debug\PythonHome\lib\ssl.pyt<module>8sN  @
2014-07-09 18:15:23 +08:00


 

"  <16>