Skip to content

Commit

Permalink
lint!
Browse files Browse the repository at this point in the history
  • Loading branch information
mhils committed Jul 28, 2020
1 parent 25e36c6 commit 3fff0dd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
23 changes: 16 additions & 7 deletions src/OpenSSL/SSL.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ def explode(*args, **kwargs):


_requires_keylog = _make_requires(
getattr(_lib,"Cryptography_HAS_KEYLOG", None), "Key logging not available"
getattr(_lib, "Cryptography_HAS_KEYLOG", None), "Key logging not available"
)


Expand Down Expand Up @@ -1331,20 +1331,29 @@ def wrapper(ssl, where, return_code):
def set_keylog_callback(self, callback):
"""
Set the TLS key logging callback to *callback*. This function will be
called whenever TLS key material is generated or received,
in order to allow applications to store this keying material for debugging purposes.
called whenever TLS key material is generated or received, in order
to allow applications to store this keying material for debugging
purposes.
:param callback: The Python callback to use. This should take two
arguments: a Connection object and a bytestring that contains the key material
in the format used by NSS for its SSLKEYLOGFILE debugging output.
arguments: a Connection object and a bytestring that contains
the key material in the format used by NSS for its SSLKEYLOGFILE
debugging output.
:return: None
"""
@wraps(callback)
def wrapper(ssl, line):
line = _ffi.string(line)
callback(Connection._reverse_mapping[ssl], line)
self._keylog_callback = _ffi.callback("void (*)(const SSL *, const char *)", wrapper)
_lib.SSL_CTX_set_keylog_callback(self._context, self._keylog_callback)

self._keylog_callback = _ffi.callback(
"void (*)(const SSL *, const char *)",
wrapper
)
_lib.SSL_CTX_set_keylog_callback(
self._context,
self._keylog_callback
)

def get_app_data(self):
"""
Expand Down
10 changes: 7 additions & 3 deletions tests/test_ssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,7 @@ def info(conn, where, ret):

@pytest.mark.skipif(
not getattr(_lib, "Cryptography_HAS_KEYLOG", None),
reason="SSL_CTX_set_keylog_callback unavailable - OpenSSL version may be too old"
reason="SSL_CTX_set_keylog_callback unavailable"
)
def test_set_keylog_callback(self):
"""
Expand All @@ -962,8 +962,12 @@ def keylog(conn, line):

server_context = Context(TLSv1_METHOD)
server_context.set_keylog_callback(keylog)
server_context.use_certificate(load_certificate(FILETYPE_PEM, cleartextCertificatePEM))
server_context.use_privatekey(load_privatekey(FILETYPE_PEM, cleartextPrivateKeyPEM))
server_context.use_certificate(
load_certificate(FILETYPE_PEM, cleartextCertificatePEM)
)
server_context.use_privatekey(
load_privatekey(FILETYPE_PEM, cleartextPrivateKeyPEM)
)

client_context = Context(TLSv1_METHOD)

Expand Down

0 comments on commit 3fff0dd

Please sign in to comment.