aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2015-10-24 21:00:19 -0400
committerAlex Gaynor <alex.gaynor@gmail.com>2015-10-24 21:00:19 -0400
commitc6af93903be97612314cbd9a8d8e3264059419df (patch)
tree13c1ae21ac0def7b474406591de72b0a0c8e6927 /src
parentb7ee910c2070a3e5d8d64ac17ceaa5793f114dc1 (diff)
parentd2146ec71afd482073b7b0117184a8689b408b83 (diff)
downloadcryptography-c6af93903be97612314cbd9a8d8e3264059419df.tar.gz
cryptography-c6af93903be97612314cbd9a8d8e3264059419df.tar.bz2
cryptography-c6af93903be97612314cbd9a8d8e3264059419df.zip
Merge pull request #2293 from reaperhulk/idempotent-engine-add
idempotent engine add
Diffstat (limited to 'src')
-rw-r--r--src/_cffi_src/openssl/engine.py2
-rw-r--r--src/cryptography/hazmat/bindings/openssl/binding.py13
2 files changed, 9 insertions, 6 deletions
diff --git a/src/_cffi_src/openssl/engine.py b/src/_cffi_src/openssl/engine.py
index 011f6692..60c6f3e2 100644
--- a/src/_cffi_src/openssl/engine.py
+++ b/src/_cffi_src/openssl/engine.py
@@ -44,6 +44,8 @@ static const unsigned int ENGINE_METHOD_DIGESTS;
static const unsigned int ENGINE_METHOD_STORE;
static const unsigned int ENGINE_METHOD_ALL;
static const unsigned int ENGINE_METHOD_NONE;
+
+static const int ENGINE_R_CONFLICTING_ENGINE_ID;
"""
FUNCTIONS = """
diff --git a/src/cryptography/hazmat/bindings/openssl/binding.py b/src/cryptography/hazmat/bindings/openssl/binding.py
index 47b1d6e2..4fac11d8 100644
--- a/src/cryptography/hazmat/bindings/openssl/binding.py
+++ b/src/cryptography/hazmat/bindings/openssl/binding.py
@@ -97,11 +97,6 @@ class Binding(object):
@classmethod
def _register_osrandom_engine(cls):
_openssl_assert(cls.lib, cls.lib.ERR_peek_error() == 0)
- looked_up_engine = cls.lib.ENGINE_by_id(cls._osrandom_engine_id)
- if looked_up_engine != ffi.NULL:
- raise RuntimeError("osrandom engine already registered")
-
- cls.lib.ERR_clear_error()
engine = cls.lib.ENGINE_new()
_openssl_assert(cls.lib, engine != cls.ffi.NULL)
@@ -113,7 +108,13 @@ class Binding(object):
result = cls.lib.ENGINE_set_RAND(engine, cls._osrandom_method)
_openssl_assert(cls.lib, result == 1)
result = cls.lib.ENGINE_add(engine)
- _openssl_assert(cls.lib, result == 1)
+ if result != 1:
+ errors = _consume_errors(cls.lib)
+ _openssl_assert(
+ cls.lib,
+ errors[0].reason == cls.lib.ENGINE_R_CONFLICTING_ENGINE_ID
+ )
+
finally:
result = cls.lib.ENGINE_free(engine)
_openssl_assert(cls.lib, result == 1)