-
Notifications
You must be signed in to change notification settings - Fork 422
Expose support for using ecdhe with SSL connections #9
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
Changes from all commits
7b8d57a
a683fc0
12dc084
2c04e86
807853c
d5419e2
479878d
32f016f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| *.py[co] | ||
| build | ||
| dist | ||
| *.egg-info | ||
| *.egg-info |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -122,6 +122,17 @@ class _memoryview(object): | |
| SSL_CB_HANDSHAKE_DONE = _lib.SSL_CB_HANDSHAKE_DONE | ||
|
|
||
|
|
||
| NID_X9_62_prime192v1 = _lib.NID_X9_62_prime192v1 | ||
| NID_X9_62_prime192v2 = _lib.NID_X9_62_prime192v2 | ||
| NID_X9_62_prime192v3 = _lib.NID_X9_62_prime192v3 | ||
| NID_X9_62_prime239v1 = _lib.NID_X9_62_prime239v1 | ||
| NID_X9_62_prime239v2 = _lib.NID_X9_62_prime239v2 | ||
| NID_X9_62_prime239v3 = _lib.NID_X9_62_prime239v3 | ||
| NID_X9_62_prime256v1 = _lib.NID_X9_62_prime256v1 | ||
|
|
||
| _Cryptography_HAS_EC = _lib.Cryptography_HAS_EC | ||
|
|
||
|
|
||
| class Error(Exception): | ||
| """ | ||
| An error occurred in an `OpenSSL.SSL` API. | ||
|
|
@@ -594,6 +605,26 @@ def load_tmp_dh(self, dhfile): | |
| _lib.SSL_CTX_set_tmp_dh(self._context, dh) | ||
|
|
||
|
|
||
| def set_tmp_ecdh_by_curve_name(self, curve_name): | ||
| """ | ||
| Configure this connection to people to use Elliptical Curve | ||
| Diffie-Hellman key exchanges. | ||
|
|
||
| :param curve_name: One of the named curve constants. | ||
| :return: 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. `None`I think? 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. None of the other places uses backticks. On Fri, Jan 17, 2014 at 12:11 PM, Hynek Schlawack
"I disapprove of what you say, but I will defend to the death your right to |
||
| """ | ||
| if _lib.Cryptography_HAS_EC: | ||
| ecdh = _lib.EC_KEY_new_by_curve_name(curve_name) | ||
| if ecdh == _ffi.NULL: | ||
| raise ValueError( | ||
| "OpenSSL could not load the requested elliptic curve" | ||
| ) | ||
| _lib.SSL_CTX_set_tmp_ecdh(self._context, ecdh) | ||
| _lib.EC_KEY_free(ecdh) | ||
| else: | ||
| raise ValueError("OpenSSL is compiled without ECDH support") | ||
|
|
||
|
|
||
| def set_cipher_list(self, cipher_list): | ||
| """ | ||
| Change the cipher list | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,6 +35,7 @@ | |
| SESS_CACHE_OFF, SESS_CACHE_CLIENT, SESS_CACHE_SERVER, SESS_CACHE_BOTH, | ||
| SESS_CACHE_NO_AUTO_CLEAR, SESS_CACHE_NO_INTERNAL_LOOKUP, | ||
| SESS_CACHE_NO_INTERNAL_STORE, SESS_CACHE_NO_INTERNAL) | ||
| from OpenSSL.SSL import NID_X9_62_prime256v1, _Cryptography_HAS_EC | ||
|
|
||
| from OpenSSL.SSL import ( | ||
| Error, SysCallError, WantReadError, WantWriteError, ZeroReturnError) | ||
|
|
@@ -1172,6 +1173,17 @@ def test_load_tmp_dh(self): | |
| # XXX What should I assert here? -exarkun | ||
|
|
||
|
|
||
| if _Cryptography_HAS_EC: | ||
| def test_set_tmp_ecdh_by_curve_name(self): | ||
| """ | ||
| :py:obj:`Context.set_tmp_ecdh_by_curve_name` sets the Eliptical | ||
| Curve for Diffie-Hellman by the named curve. | ||
| """ | ||
| context = Context(TLSv1_METHOD) | ||
| context.set_tmp_ecdh_by_curve_name(NID_X9_62_prime256v1) | ||
| # XXX What should I assert here? -alex | ||
|
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. Something about the cipher that is used by a connection established using this context? With this you should be able to get something that starts with ECDH- and without it you should not be able to? |
||
|
|
||
|
|
||
| def test_set_cipher_list_bytes(self): | ||
| """ | ||
| :py:obj:`Context.set_cipher_list` accepts a :py:obj:`bytes` naming the | ||
|
|
||
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.
I think that the idiom thus far in pyOpenSSL is to wrap the kind of stateful object that a ...
EC_KEY*(whatSSL_CTX_set_tmp_ecdhtakes) is in a thin object and unwrap it as necessary when going down to OpenSSL.What do you think about an ...
EllipticalCurveKeyclass that wraps thisEC_KEY*and changing this method so that it is merely a wrapper aroundSSL_CTX_set_tmp_ecdh?EllipcitalCurveKey.new_by_curve_name(nid)might be the way the other half of this functionality is accessed.Just thinking out loud here, let me know if this sounds dumb.