diff options
| author | Laurens Van Houtven <_@lvh.cc> | 2014-03-29 11:30:06 +0100 |
|---|---|---|
| committer | Laurens Van Houtven <_@lvh.cc> | 2014-03-29 11:30:06 +0100 |
| commit | e8b2d3013a3d1536f6bf9ae5ca7ee0752d710311 (patch) | |
| tree | 1ba50249feda18e16954ae9fe181112cef80b96f /OpenSSL/SSL.py | |
| parent | 63e99fe6f9ee799ae9914a3704b1fe540cc8a4b7 (diff) | |
| parent | 4064ea18c2a68bb5d6e82f40be7ecddc0752d6f9 (diff) | |
| download | pyopenssl-e8b2d3013a3d1536f6bf9ae5ca7ee0752d710311.tar.gz | |
Merge branch 'ecdhe' of git://github.com/amluto/pyopenssl into ecdhe
Diffstat (limited to 'OpenSSL/SSL.py')
| -rw-r--r-- | OpenSSL/SSL.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/OpenSSL/SSL.py b/OpenSSL/SSL.py index fcc7da4..e6a629b 100644 --- a/OpenSSL/SSL.py +++ b/OpenSSL/SSL.py @@ -124,6 +124,18 @@ SSL_CB_CONNECT_EXIT = _lib.SSL_CB_CONNECT_EXIT SSL_CB_HANDSHAKE_START = _lib.SSL_CB_HANDSHAKE_START SSL_CB_HANDSHAKE_DONE = _lib.SSL_CB_HANDSHAKE_DONE +_Cryptography_HAS_EC = _lib.Cryptography_HAS_EC +ELLIPTIC_CURVE_DESCRIPTIONS = {} # In case there's no EC support +if _Cryptography_HAS_EC: + _num_curves = _lib.EC_get_builtin_curves(_ffi.NULL, 0) + _curves = _ffi.new('EC_builtin_curve[]', _num_curves) + if _lib.EC_get_builtin_curves(_curves, _num_curves) == _num_curves: + ELLIPTIC_CURVE_DESCRIPTIONS = dict((_ffi.string(_lib.OBJ_nid2sn(c.nid)), + _ffi.string(c.comment)) + for c in _curves) + del _num_curves + del _curves + class Error(Exception): """ @@ -598,6 +610,35 @@ class Context(object): _lib.SSL_CTX_set_tmp_dh(self._context, dh) + def set_tmp_ecdh_curve(self, curve_name): + """ + Select a curve to use for ECDHE key exchange. + + The valid values of *curve_name* are the keys in + :py:data:OpenSSL.SSL.ELLIPTIC_CURVE_DESCRIPTIONS. + + Raises a ``ValueError`` if the linked OpenSSL was not compiled with + elliptical curve support, or the specified curve is not available. + + :param curve_name: The 'short name' of a curve, e.g. 'prime256v1' + :type curve_name: str + :return: None + """ + if _lib.Cryptography_HAS_EC: + nid = _lib.OBJ_sn2nid(curve_name) + if nid == _lib.NID_undef: + raise ValueError("No such OpenSSL object '%s'" % curve_name) + ecdh = _lib.EC_KEY_new_by_curve_name(nid) + 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 |
