Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(7)

Side by Side Diff: Lib/ssl.py

Issue 10639: reindent.py converts newlines to platform default
Patch Set: Created 8 years, 8 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/smtplib.py ('k') | Lib/stat.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Wrapper module for _ssl, providing some additional facilities 1 # Wrapper module for _ssl, providing some additional facilities
2 # implemented in Python. Written by Bill Janssen. 2 # implemented in Python. Written by Bill Janssen.
3 3
4 """This module provides some more Pythonic support for SSL. 4 """This module provides some more Pythonic support for SSL.
5 5
6 Object types: 6 Object types:
7 7
8 SSLSocket -- subtype of socket.socket which does SSL over the socket 8 SSLSocket -- subtype of socket.socket which does SSL over the socket
9 9
10 Exceptions: 10 Exceptions:
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 SSL_ERROR_WANT_X509_LOOKUP, 71 SSL_ERROR_WANT_X509_LOOKUP,
72 SSL_ERROR_SYSCALL, 72 SSL_ERROR_SYSCALL,
73 SSL_ERROR_SSL, 73 SSL_ERROR_SSL,
74 SSL_ERROR_WANT_CONNECT, 74 SSL_ERROR_WANT_CONNECT,
75 SSL_ERROR_EOF, 75 SSL_ERROR_EOF,
76 SSL_ERROR_INVALID_ERROR_CODE, 76 SSL_ERROR_INVALID_ERROR_CODE,
77 ) 77 )
78 from _ssl import HAS_SNI 78 from _ssl import HAS_SNI
79 from _ssl import (PROTOCOL_SSLv3, PROTOCOL_SSLv23, 79 from _ssl import (PROTOCOL_SSLv3, PROTOCOL_SSLv23,
80 PROTOCOL_TLSv1) 80 PROTOCOL_TLSv1)
81 from _ssl import _OPENSSL_API_VERSION
82
83 _PROTOCOL_NAMES = { 81 _PROTOCOL_NAMES = {
84 PROTOCOL_TLSv1: "TLSv1", 82 PROTOCOL_TLSv1: "TLSv1",
85 PROTOCOL_SSLv23: "SSLv23", 83 PROTOCOL_SSLv23: "SSLv23",
86 PROTOCOL_SSLv3: "SSLv3", 84 PROTOCOL_SSLv3: "SSLv3",
87 } 85 }
88 try: 86 try:
89 from _ssl import PROTOCOL_SSLv2 87 from _ssl import PROTOCOL_SSLv2
90 except ImportError: 88 except ImportError:
91 pass 89 pass
92 else: 90 else:
93 _PROTOCOL_NAMES[PROTOCOL_SSLv2] = "SSLv2" 91 _PROTOCOL_NAMES[PROTOCOL_SSLv2] = "SSLv2"
94 92
95 from socket import getnameinfo as _getnameinfo 93 from socket import getnameinfo as _getnameinfo
96 from socket import error as socket_error 94 from socket import error as socket_error
97 from socket import socket, AF_INET, SOCK_STREAM, create_connection 95 from socket import socket, AF_INET, SOCK_STREAM, create_connection
98 import base64 # for DER-to-PEM translation 96 import base64 # for DER-to-PEM translation
99 import traceback 97 import traceback
100 import errno 98 import errno
101 99
102 if _ssl.HAS_TLS_UNIQUE:
103 CHANNEL_BINDING_TYPES = ['tls-unique']
104 else:
105 CHANNEL_BINDING_TYPES = []
106 100
107 class CertificateError(ValueError): 101 class CertificateError(ValueError):
108 pass 102 pass
109 103
110 104
111 def _dnsname_to_pat(dn): 105 def _dnsname_to_pat(dn):
112 pats = [] 106 pats = []
113 for frag in dn.split(r'.'): 107 for frag in dn.split(r'.'):
114 if frag == '*': 108 if frag == '*':
115 # When '*' is a fragment by itself, it matches a non-empty dotless 109 # When '*' is a fragment by itself, it matches a non-empty dotless
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 return (SSLSocket(sock=newsock, 485 return (SSLSocket(sock=newsock,
492 keyfile=self.keyfile, certfile=self.certfile, 486 keyfile=self.keyfile, certfile=self.certfile,
493 server_side=True, 487 server_side=True,
494 cert_reqs=self.cert_reqs, 488 cert_reqs=self.cert_reqs,
495 ssl_version=self.ssl_version, 489 ssl_version=self.ssl_version,
496 ca_certs=self.ca_certs, 490 ca_certs=self.ca_certs,
497 ciphers=self.ciphers, 491 ciphers=self.ciphers,
498 do_handshake_on_connect= 492 do_handshake_on_connect=
499 self.do_handshake_on_connect), 493 self.do_handshake_on_connect),
500 addr) 494 addr)
501
502 def get_channel_binding(self, cb_type="tls-unique"):
503 """Get channel binding data for current connection. Raise ValueError
504 if the requested `cb_type` is not supported. Return bytes of the data
505 or None if the data is not available (e.g. before the handshake).
506 """
507 if cb_type not in CHANNEL_BINDING_TYPES:
508 raise ValueError("Unsupported channel binding type")
509 if cb_type != "tls-unique":
510 raise NotImplementedError(
511 "{0} channel binding type not implemented"
512 .format(cb_type))
513 if self._sslobj is None:
514 return None
515 return self._sslobj.tls_unique_cb()
516 495
517 def __del__(self): 496 def __del__(self):
518 # sys.stderr.write("__del__ on %s\n" % repr(self)) 497 # sys.stderr.write("__del__ on %s\n" % repr(self))
519 self._real_close() 498 self._real_close()
520 499
521 500
522 def wrap_socket(sock, keyfile=None, certfile=None, 501 def wrap_socket(sock, keyfile=None, certfile=None,
523 server_side=False, cert_reqs=CERT_NONE, 502 server_side=False, cert_reqs=CERT_NONE,
524 ssl_version=PROTOCOL_SSLv23, ca_certs=None, 503 ssl_version=PROTOCOL_SSLv23, ca_certs=None,
525 do_handshake_on_connect=True, 504 do_handshake_on_connect=True,
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 cert_reqs = CERT_NONE 559 cert_reqs = CERT_NONE
581 s = create_connection(addr) 560 s = create_connection(addr)
582 s = wrap_socket(s, ssl_version=ssl_version, 561 s = wrap_socket(s, ssl_version=ssl_version,
583 cert_reqs=cert_reqs, ca_certs=ca_certs) 562 cert_reqs=cert_reqs, ca_certs=ca_certs)
584 dercert = s.getpeercert(True) 563 dercert = s.getpeercert(True)
585 s.close() 564 s.close()
586 return DER_cert_to_PEM_cert(dercert) 565 return DER_cert_to_PEM_cert(dercert)
587 566
588 def get_protocol_name(protocol_code): 567 def get_protocol_name(protocol_code):
589 return _PROTOCOL_NAMES.get(protocol_code, '<unknown>') 568 return _PROTOCOL_NAMES.get(protocol_code, '<unknown>')
OLDNEW
« no previous file with comments | « Lib/smtplib.py ('k') | Lib/stat.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+