diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2011-07-20 23:11:30 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2011-07-20 23:11:30 (GMT) |
commit | d649480739dba77d9bfb1f320b52e9a838c33a05 (patch) | |
tree | 93c59364a01cfa770342eba85ba99d2e5a3ad99c /Lib/ssl.py | |
parent | 875048bd4c95ae90c3e541cad681b11436ce1f3f (diff) | |
download | cpython-d649480739dba77d9bfb1f320b52e9a838c33a05.zip cpython-d649480739dba77d9bfb1f320b52e9a838c33a05.tar.gz cpython-d649480739dba77d9bfb1f320b52e9a838c33a05.tar.bz2 |
Issue #12551: Provide a get_channel_binding() method on SSL sockets so as
to get channel binding data for the current SSL session (only the
"tls-unique" channel binding is implemented). This allows the
implementation of certain authentication mechanisms such as SCRAM-SHA-1-PLUS.
Patch by Jacek Konieczny.
Diffstat (limited to 'Lib/ssl.py')
-rw-r--r-- | Lib/ssl.py | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -99,6 +99,10 @@ import base64 # for DER-to-PEM translation import traceback import errno +if _ssl.HAS_TLS_UNIQUE: + CHANNEL_BINDING_TYPES = ['tls-unique'] +else: + CHANNEL_BINDING_TYPES = [] class CertificateError(ValueError): pass @@ -495,6 +499,21 @@ class SSLSocket(socket): self.do_handshake_on_connect), addr) + def get_channel_binding(self, cb_type="tls-unique"): + """Get 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). + """ + if cb_type not in CHANNEL_BINDING_TYPES: + raise ValueError("Unsupported channel binding type") + if cb_type != "tls-unique": + raise NotImplementedError( + "{0} channel binding type not implemented" + .format(cb_type)) + if self._sslobj is None: + return None + return self._sslobj.tls_unique_cb() + def __del__(self): # sys.stderr.write("__del__ on %s\n" % repr(self)) self._real_close() |