tzh
2024-08-22 c7d0944258c7d0943aa7b2211498fd612971ce27
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
M\¬Qc
@sdZddlZddlZddlmZmZmZddlmZddlmZmZm    Z    ddlm
Z
m Z m Z ddlm Z mZmZmZmZmZmZmZmZddlmZmZmZid    e6d
e6d e6Zydd lmZeZWnek
r,eZn Xd ee<ddlmZmZm Z m!Z"ddlm#Z$ddl%Z%ddl&Z&dZ'defd„ƒYZ(eee)eeee*e*ed„    Z+d„Z,dZ-dZ.d„Z/d„Z0eed„Z1d„Z2eed„Z3dS(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ÿÿÿÿ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 getnameinfos)DEFAULT:!aNULL:!eNULL:!LOW:!EXPORT:!SSLv2t    SSLSocketc
BseZdZddeeedeedd„    Zdd„Z    d„Z
ed„Z d„Z dd„Z dd    „Zdd
„Zddd „Zddd „Zddd „Zddd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zddd„ZRS(sµThis 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.c Csotj|d|jƒx3tD]+} yt|| ƒWqtk
rGqXqW|
dkrm|tkrmt}
n|rƒ| rƒ|}nytj    |ƒWn=t
k
rÓ} | j t j kr¾‚nt |_d|_nGXt|_tj|j|||||||
ƒ|_|r|jƒn||_||_||_||_||_|
|_||_|    |_d|_dS(Nt_socki(Rt__init__R!RtdelattrtAttributeErrortNonet_SSLv2_IF_EXISTSt_DEFAULT_CIPHERSt getpeernamet socket_errorterrnotENOTCONNtFalset
_connectedt_sslobjtTruet_ssltsslwrapt do_handshaketkeyfiletcertfilet    cert_reqst ssl_versiontca_certstcipherstdo_handshake_on_connecttsuppress_ragged_eofst_makefile_refs( tselftsockR3R4t server_sideR5R6R7R9R:R8tattrte((sK/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/ssl.pyR"jsB                                                          icCsQy|jj|ƒSWn6tk
rL}|jdtkrF|jrFdS‚nXdS(sORead up to LEN bytes and return them.
        Return zero-length string on EOF.itN(R.treadRtargsRR:(R<tlentx((sK/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/ssl.pyRBšs cCs|jj|ƒS(shWrite DATA to the underlying SSL channel.  Returns
        number of bytes of DATA actually transmitted.(R.twrite(R<tdata((sK/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/ssl.pyRF§scCs|jj|ƒS(sáReturns 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.tpeer_certificate(R<t binary_form((sK/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/ssl.pyt getpeercert®scCs|js dS|jjƒSdS(N(R.R%tcipher(R<((sK/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/ssl.pyRK·s    icCs³|jrœ|dkr+td|jƒ‚nxtr˜y|jj|ƒ}WnDtk
r}|jdtkrsdS|jdtkrŠdS‚q.X|Sq.Wn|j    j
||ƒSdS(Nis3non-zero flags not allowed in calls to send() on %s( R.t
ValueErrort    __class__R/RFRRCR R R!tsend(R<RGtflagstvRE((sK/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/ssl.pyRN¾s           cCsX|jrtd|jƒ‚n5|dkr>|jj||ƒS|jj|||ƒSdS(Ns%sendto not allowed on instances of %s(R.RLRMR%R!tsendto(R<RGt flags_or_addrtaddr((sK/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/ssl.pyRQÓs      cCsˆ|jrq|dkr+td|jƒ‚nt|ƒ}d}x-||krl|j||ƒ}||7}q@W|Stj|||ƒSdS(Nis6non-zero flags not allowed in calls to sendall() on %s(R.RLRMRDRNRtsendall(R<RGROtamounttcountRP((sK/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/ssl.pyRTÜs      cCsO|jr8|dkr+td|jƒ‚n|j|ƒS|jj||ƒSdS(Nis3non-zero flags not allowed in calls to recv() on %s(R.RLRMRBR!trecv(R<tbuflenRO((sK/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/ssl.pyRWës      cCs¤|r!|dkr!t|ƒ}n|dkr6d}n|jrŠ|dkratd|jƒ‚n|j|ƒ}t|ƒ}|||*|S|jj|||ƒSdS(Niis8non-zero flags not allowed in calls to recv_into() on %s(R%RDR.RLRMRBR!t    recv_into(R<tbuffertnbytesROt
tmp_bufferRP((sK/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/ssl.pyRYõs           
cCs6|jrtd|jƒ‚n|jj||ƒSdS(Ns'recvfrom not allowed on instances of %s(R.RLRMR!trecvfrom(R<RXRO((sK/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/ssl.pyR]s    cCs9|jrtd|jƒ‚n|jj|||ƒSdS(Ns,recvfrom_into not allowed on instances of %s(R.RLRMR!t recvfrom_into(R<RZR[RO((sK/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/ssl.pyR^ s    cCs|jr|jjƒSdSdS(Ni(R.tpending(R<((sK/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/ssl.pyR_s     cCs?|jr%|jjƒ}d|_|Stdt|ƒƒ‚dS(NsNo SSL wrapper around (R.tshutdownR%RLtstr(R<ts((sK/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/ssl.pytunwraps
        cCsd|_tj||ƒdS(N(R%R.RR`(R<thow((sK/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/ssl.pyR`"s    cCs;|jdkr(d|_tj|ƒn|jd8_dS(Ni(R;R%R.Rtclose(R<((sK/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/ssl.pyRe&s    cCs|jjƒdS(sPerform a TLS/SSL handshake.N(R.R2(R<((sK/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/ssl.pyR2-sc    CsÙ|jrtdƒ‚ntj|jt|j|j|j|j    |j
|j ƒ|_ ya|rrt j||ƒ}nd}t j||ƒ|s°|jr¤|jƒnt|_n|SWntk
rÔd|_ ‚nXdS(Ns/attempt to connect already-connected SSLSocket!(R-RLR0R1R!R,R3R4R5R6R7R8R.Rt
connect_exR%tconnectR9R2R/R)(R<RSt return_errnotrc((sK/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/ssl.pyt _real_connect3s$                cCs|j|tƒdS(sQConnects to remote ADDR, and then wraps the connection in
        an SSL channel.N(RjR,(R<RS((sK/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/ssl.pyRgJscCs|j|tƒS(sQConnects to remote ADDR, and then wraps the connection in
        an SSL channel.(RjR/(R<RS((sK/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/ssl.pyRfOscCs¡tj|ƒ\}}ybt|d|jd|jdtd|jd|jd|jd|j    d|j
d    |j ƒ    |fSWn#t k
rœ}|j ƒ|‚nXd
S( s¿Accepts 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.R3R4R>R5R6R7R8R9R:N(RtacceptR R3R4R/R5R6R7R8R9R:R)Re(R<tnewsockRSR@((sK/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/ssl.pyRkTs                                      
triÿÿÿÿcCs%|jd7_t|||dtƒS(sMake and return a file-like object that
        works with the SSL connection.  Just use the code
        from the socket module.iRe(R;RR/(R<tmodetbufsize((sK/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/ssl.pytmakefileksN(t__name__t
__module__t__doc__R%R,RRR/R"RBRFRJRKRNRQRTRWRYR]R^R_RcR`ReR2RjRgRfRkRp(((sK/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/ssl.pyR ds6,                  
                                    c
 
Cs@t|d|d|d|d|d|d|d|d|d    |    ƒ    S(
NR3R4R>R5R6R7R9R:R8(R (
R=R3R4R>R5R6R7R9R:R8((sK/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/ssl.pyt wrap_socketxs   cCs%ddl}|j|j|dƒƒS(s¢Takes a date-time string in standard ASN1_print form
    ("MON DAY 24HOUR:MINUTE:SEC YEAR TIMEZONE") and return
    a Python time value in seconds past the epoch.iÿÿÿÿNs%b %d %H:%M:%S %Y GMT(ttimetmktimetstrptime(t    cert_timeRu((sK/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/ssl.pytcert_time_to_secondsˆs s-----BEGIN CERTIFICATE-----s-----END CERTIFICATE-----cCscttdƒrBtj|ƒ}tdtj|dƒdtdStdtj|ƒtdSdS(s[Takes a certificate in binary DER format and returns the
    PEM version of it as a string.tstandard_b64encodes
i@N(thasattrtbase64Rzt
PEM_HEADERttextwraptfillt
PEM_FOOTERt encodestring(tder_cert_bytestf((sK/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/ssl.pytDER_cert_to_PEM_cert”s$cCsw|jtƒs"tdtƒ‚n|jƒjtƒsJtdtƒ‚n|jƒttƒttƒ !}tj|ƒS(shTakes a certificate in ASCII PEM format and returns the
    DER-encoded version of it as a byte sequences(Invalid PEM encoding; must start with %ss&Invalid PEM encoding; must end with %s(    t
startswithR}RLtstriptendswithR€RDR|t decodestring(tpem_cert_stringtd((sK/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/ssl.pytPEM_cert_to_DER_cert¤s   cCsx|\}}|dk    r!t}nt}ttƒd|d|d|ƒ}|j|ƒ|jtƒ}|jƒt    |ƒS(s÷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.R6R5R7N(
R%RRRtRRgRJR/ReR„(RSR6R7thosttportR5Rbtdercert((sK/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/ssl.pytget_server_certificate²s       
cCstj|dƒS(Ns    <unknown>(t_PROTOCOL_NAMEStget(t protocol_code((sK/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/ssl.pytget_protocol_nameÅscCslt|dƒr|j}ntj|d||ttdƒ}y|jƒWntk
r]n X|j    ƒ|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(
R{R!R0R1RRR%R(R)R2(R=R3R4tssl_sock((sK/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/ssl.pytsslwrap_simpleËs   
(4RsR~R0RRRRRRRRRR    R
R R R RRRRRRRRRRR&t ImportErrorR%RRRRR)Rt _getnameinfoR|R*R'R R,R/RtRyR}R€R„R‹RR“R•(((sK/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/ssl.pyt<module>8sL  @
 
 
 
 
"  ÿ