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

Side by Side Diff: Lib/ssl.py

Issue 20421: expose SSL socket protocol version
Patch Set: Created 5 years, 9 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 | « Doc/library/ssl.rst ('k') | Lib/test/test_ssl.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 842 matching lines...) Expand 10 before | Expand all | Expand 10 after
853 """ 853 """
854 if cb_type not in CHANNEL_BINDING_TYPES: 854 if cb_type not in CHANNEL_BINDING_TYPES:
855 raise ValueError("Unsupported channel binding type") 855 raise ValueError("Unsupported channel binding type")
856 if cb_type != "tls-unique": 856 if cb_type != "tls-unique":
857 raise NotImplementedError( 857 raise NotImplementedError(
858 "{0} channel binding type not implemented" 858 "{0} channel binding type not implemented"
859 .format(cb_type)) 859 .format(cb_type))
860 if self._sslobj is None: 860 if self._sslobj is None:
861 return None 861 return None
862 return self._sslobj.tls_unique_cb() 862 return self._sslobj.tls_unique_cb()
863
864 def version(self):
865 """
866 Return a string identifying the protocol version used by the
867 current SSL channel, or None if there is no established channel.
868 """
869 if self._sslobj is None:
870 return None
871 return self._sslobj.version()
863 872
864 873
865 def wrap_socket(sock, keyfile=None, certfile=None, 874 def wrap_socket(sock, keyfile=None, certfile=None,
866 server_side=False, cert_reqs=CERT_NONE, 875 server_side=False, cert_reqs=CERT_NONE,
867 ssl_version=PROTOCOL_SSLv23, ca_certs=None, 876 ssl_version=PROTOCOL_SSLv23, ca_certs=None,
868 do_handshake_on_connect=True, 877 do_handshake_on_connect=True,
869 suppress_ragged_eofs=True, 878 suppress_ragged_eofs=True,
870 ciphers=None): 879 ciphers=None):
871 880
872 return SSLSocket(sock=sock, keyfile=keyfile, certfile=certfile, 881 return SSLSocket(sock=sock, keyfile=keyfile, certfile=certfile,
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
947 context = _create_stdlib_context(ssl_version, 956 context = _create_stdlib_context(ssl_version,
948 cert_reqs=cert_reqs, 957 cert_reqs=cert_reqs,
949 cafile=ca_certs) 958 cafile=ca_certs)
950 with create_connection(addr) as sock: 959 with create_connection(addr) as sock:
951 with context.wrap_socket(sock) as sslsock: 960 with context.wrap_socket(sock) as sslsock:
952 dercert = sslsock.getpeercert(True) 961 dercert = sslsock.getpeercert(True)
953 return DER_cert_to_PEM_cert(dercert) 962 return DER_cert_to_PEM_cert(dercert)
954 963
955 def get_protocol_name(protocol_code): 964 def get_protocol_name(protocol_code):
956 return _PROTOCOL_NAMES.get(protocol_code, '<unknown>') 965 return _PROTOCOL_NAMES.get(protocol_code, '<unknown>')
OLDNEW
« no previous file with comments | « Doc/library/ssl.rst ('k') | Lib/test/test_ssl.py » ('j') | no next file with comments »

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