aboutsummaryrefslogtreecommitdiffstats
path: root/tests/hazmat/backends/test_openssl.py
diff options
context:
space:
mode:
authorIan Cordasco <graffatcolmingov@gmail.com>2015-08-03 08:26:42 -0500
committerIan Cordasco <graffatcolmingov@gmail.com>2015-08-03 08:26:42 -0500
commita0f00f47ea3aa53a31213843d60a4141e468f021 (patch)
treea663f2bb14b0ed45054c03971cb47005155cecb2 /tests/hazmat/backends/test_openssl.py
parent36a1238703a1aa7aff44654e2e551f2a022c9c1a (diff)
parent93b5e3efab0337c51c84c27208d9034b607f09e2 (diff)
downloadcryptography-a0f00f47ea3aa53a31213843d60a4141e468f021.tar.gz
cryptography-a0f00f47ea3aa53a31213843d60a4141e468f021.tar.bz2
cryptography-a0f00f47ea3aa53a31213843d60a4141e468f021.zip
Merge remote-tracking branch 'upstream/master' into cert-builder
Diffstat (limited to 'tests/hazmat/backends/test_openssl.py')
-rw-r--r--tests/hazmat/backends/test_openssl.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/hazmat/backends/test_openssl.py b/tests/hazmat/backends/test_openssl.py
index 5b611cd0..c2a4f544 100644
--- a/tests/hazmat/backends/test_openssl.py
+++ b/tests/hazmat/backends/test_openssl.py
@@ -36,6 +36,20 @@ from ..primitives.test_ec import _skip_curve_unsupported
from ...utils import load_vectors_from_file, raises_unsupported_algorithm
+def skip_if_libre_ssl(openssl_version):
+ if u'LibreSSL' in openssl_version:
+ pytest.skip("LibreSSL hard-codes RAND_bytes to use arc4random.")
+
+
+class TestLibreSkip(object):
+ def test_skip_no(self):
+ assert skip_if_libre_ssl(u"OpenSSL 0.9.8zf 19 Mar 2015") is None
+
+ def test_skip_yes(self):
+ with pytest.raises(pytest.skip.Exception):
+ skip_if_libre_ssl(u"LibreSSL 2.1.6")
+
+
@utils.register_interface(Mode)
class DummyMode(object):
name = "dummy-mode"
@@ -218,6 +232,19 @@ class TestOpenSSL(object):
bn = backend._int_to_bn(0)
assert backend._bn_to_int(bn) == 0
+ def test_actual_osrandom_bytes(self, monkeypatch):
+ skip_if_libre_ssl(backend.openssl_version_text())
+ sample_data = (b"\x01\x02\x03\x04" * 4)
+ length = len(sample_data)
+
+ def notrandom(size):
+ assert size == length
+ return sample_data
+ monkeypatch.setattr(os, "urandom", notrandom)
+ buf = backend._ffi.new("char[]", length)
+ backend._lib.RAND_bytes(buf, length)
+ assert backend._ffi.buffer(buf)[0:length] == sample_data
+
class TestOpenSSLRandomEngine(object):
def teardown_method(self, method):