-
Notifications
You must be signed in to change notification settings - Fork 419
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added method to export keying material from an ssl connection #686
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
348afd4
added method to export keying material from an ssl connection
kelbyludwig 99ea3b8
updated tests to use bytestrings to avoid breaking python3 tests
kelbyludwig 4798d75
added additional comments to test
kelbyludwig 317c9c8
modified cryptographyMinimum tox dep
kelbyludwig File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1941,6 +1941,31 @@ def master_key(self): | |
_lib.SSL_SESSION_get_master_key(session, outp, length) | ||
return _ffi.buffer(outp, length)[:] | ||
|
||
def export_keying_material(self, label, olen, context=None): | ||
""" | ||
Obtain keying material for application use. | ||
|
||
:param label - a disambiguating label string as described in RFC 5705 | ||
:param olen - the length of the exported key material in bytes | ||
:param context - a per-association context value | ||
:return the exported key material bytes or None | ||
""" | ||
outp = _no_zero_allocator("unsigned char[]", olen) | ||
# RFC 5705: "Labels here have the same definition as in TLS, i.e., an | ||
# ASCII string with no terminating NULL." | ||
# So we must remove the NULL terminator. | ||
label_buf = _ffi.new("char[]", label)[0:len(label)] | ||
context_buf, context_len, use_context, success = _ffi.NULL, 0, 0, 0 | ||
if context is not None: | ||
context_buf = _ffi.new("unsigned char[]", context) | ||
context_len = len(context) | ||
use_context = 1 | ||
success = _lib.SSL_export_keying_material(self._ssl, outp, olen, | ||
label_buf, len(label), | ||
context_buf, context_len, | ||
use_context) | ||
return _ffi.buffer(outp, olen)[:] if success == 1 else None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We shouldn't return |
||
|
||
def sock_shutdown(self, *args, **kwargs): | ||
""" | ||
See shutdown(2) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you need to slice this? cffi will add a terminating NULL but when you pass it to
SSL_export_keying_material
withlen(label)
the terminating NULL simply won't be read.