aboutsummaryrefslogtreecommitdiffstats
path: root/tests/hazmat
diff options
context:
space:
mode:
Diffstat (limited to 'tests/hazmat')
-rw-r--r--tests/hazmat/backends/test_multibackend.py59
-rw-r--r--tests/hazmat/backends/test_openssl.py41
-rw-r--r--tests/hazmat/primitives/test_ec.py21
3 files changed, 118 insertions, 3 deletions
diff --git a/tests/hazmat/backends/test_multibackend.py b/tests/hazmat/backends/test_multibackend.py
index 45c12b34..61bda54c 100644
--- a/tests/hazmat/backends/test_multibackend.py
+++ b/tests/hazmat/backends/test_multibackend.py
@@ -13,6 +13,8 @@
from __future__ import absolute_import, division, print_function
+import pytest
+
from cryptography import utils
from cryptography.exceptions import (
UnsupportedAlgorithm, _Reasons
@@ -191,6 +193,10 @@ class DummyEllipticCurveBackend(object):
if not self.elliptic_curve_supported(curve):
raise UnsupportedAlgorithm(_Reasons.UNSUPPORTED_ELLIPTIC_CURVE)
+ def load_elliptic_curve_private_numbers(self, numbers):
+ if not self.elliptic_curve_supported(numbers.public_numbers.curve):
+ raise UnsupportedAlgorithm(_Reasons.UNSUPPORTED_ELLIPTIC_CURVE)
+
def elliptic_curve_private_key_from_numbers(self, numbers):
if not self.elliptic_curve_supported(numbers.public_numbers.curve):
raise UnsupportedAlgorithm(_Reasons.UNSUPPORTED_ELLIPTIC_CURVE)
@@ -199,6 +205,10 @@ class DummyEllipticCurveBackend(object):
if not self.elliptic_curve_supported(numbers.curve):
raise UnsupportedAlgorithm(_Reasons.UNSUPPORTED_ELLIPTIC_CURVE)
+ def load_elliptic_curve_public_numbers(self, numbers):
+ if not self.elliptic_curve_supported(numbers.curve):
+ raise UnsupportedAlgorithm(_Reasons.UNSUPPORTED_ELLIPTIC_CURVE)
+
@utils.register_interface(PKCS8SerializationBackend)
class DummyPKCS8SerializationBackend(object):
@@ -463,7 +473,7 @@ class TestMultiBackend(object):
backend.generate_elliptic_curve_private_key(ec.SECT283K1())
- backend.elliptic_curve_private_key_from_numbers(
+ backend.load_elliptic_curve_private_numbers(
ec.EllipticCurvePrivateNumbers(
1,
ec.EllipticCurvePublicNumbers(
@@ -474,7 +484,7 @@ class TestMultiBackend(object):
)
)
- backend.elliptic_curve_public_key_from_numbers(
+ backend.load_elliptic_curve_public_numbers(
ec.EllipticCurvePublicNumbers(
2,
3,
@@ -493,6 +503,51 @@ class TestMultiBackend(object):
backend.generate_elliptic_curve_private_key(ec.SECT163K1())
with raises_unsupported_algorithm(_Reasons.UNSUPPORTED_ELLIPTIC_CURVE):
+ backend.load_elliptic_curve_private_numbers(
+ ec.EllipticCurvePrivateNumbers(
+ 1,
+ ec.EllipticCurvePublicNumbers(
+ 2,
+ 3,
+ ec.SECT163K1()
+ )
+ )
+ )
+
+ with raises_unsupported_algorithm(_Reasons.UNSUPPORTED_ELLIPTIC_CURVE):
+ backend.load_elliptic_curve_public_numbers(
+ ec.EllipticCurvePublicNumbers(
+ 2,
+ 3,
+ ec.SECT163K1()
+ )
+ )
+
+ def test_deprecated_elliptic_curve(self):
+ backend = MultiBackend([
+ DummyEllipticCurveBackend([
+ ec.SECT283K1
+ ])
+ ])
+
+ assert backend.elliptic_curve_signature_algorithm_supported(
+ ec.ECDSA(hashes.SHA256()),
+ ec.SECT163K1()
+ ) is False
+
+ pub_numbers = ec.EllipticCurvePublicNumbers(2, 3, ec.SECT283K1())
+ numbers = ec.EllipticCurvePrivateNumbers(1, pub_numbers)
+
+ pytest.deprecated_call(
+ backend.elliptic_curve_private_key_from_numbers,
+ numbers
+ )
+ pytest.deprecated_call(
+ backend.elliptic_curve_public_key_from_numbers,
+ pub_numbers
+ )
+
+ with raises_unsupported_algorithm(_Reasons.UNSUPPORTED_ELLIPTIC_CURVE):
backend.elliptic_curve_private_key_from_numbers(
ec.EllipticCurvePrivateNumbers(
1,
diff --git a/tests/hazmat/backends/test_openssl.py b/tests/hazmat/backends/test_openssl.py
index 110bbdba..bfe6040e 100644
--- a/tests/hazmat/backends/test_openssl.py
+++ b/tests/hazmat/backends/test_openssl.py
@@ -28,12 +28,13 @@ from cryptography.hazmat.backends.openssl.backend import (
Backend, backend
)
from cryptography.hazmat.primitives import hashes, interfaces
-from cryptography.hazmat.primitives.asymmetric import dsa, padding, rsa
+from cryptography.hazmat.primitives.asymmetric import dsa, ec, padding, rsa
from cryptography.hazmat.primitives.ciphers import Cipher
from cryptography.hazmat.primitives.ciphers.algorithms import AES
from cryptography.hazmat.primitives.ciphers.modes import CBC, CTR
from cryptography.hazmat.primitives.interfaces import BlockCipherAlgorithm
+from ..primitives.test_ec import _skip_curve_unsupported
from ...utils import load_vectors_from_file, raises_unsupported_algorithm
@@ -569,3 +570,41 @@ class TestDeprecatedDSABackendMethods(object):
b"\x00" * 128,
hashes.SHA1()
)
+
+
+@pytest.mark.elliptic
+class TestDeprecatedECBackendMethods(object):
+ def test_elliptic_curve_private_key_from_numbers(self):
+ d = 5634846038258869671139984276180670841223409490498798721258
+ y = 4131560123026307384858369684985976479488628761329758810693
+ x = 3402090428547195623222463880060959356423657484435591627791
+ curve = ec.SECP192R1()
+ _skip_curve_unsupported(backend, curve)
+ pub_numbers = ec.EllipticCurvePublicNumbers(
+ x=x,
+ y=y,
+ curve=curve
+ )
+ numbers = ec.EllipticCurvePrivateNumbers(
+ private_value=d,
+ public_numbers=pub_numbers
+ )
+ pytest.deprecated_call(
+ backend.elliptic_curve_private_key_from_numbers,
+ numbers
+ )
+
+ def test_elliptic_curve_public_key_from_numbers(self):
+ y = 4131560123026307384858369684985976479488628761329758810693
+ x = 3402090428547195623222463880060959356423657484435591627791
+ curve = ec.SECP192R1()
+ _skip_curve_unsupported(backend, curve)
+ pub_numbers = ec.EllipticCurvePublicNumbers(
+ x=x,
+ y=y,
+ curve=curve
+ )
+ pytest.deprecated_call(
+ backend.elliptic_curve_public_key_from_numbers,
+ pub_numbers
+ )
diff --git a/tests/hazmat/primitives/test_ec.py b/tests/hazmat/primitives/test_ec.py
index f9eab7ac..c53a0cb6 100644
--- a/tests/hazmat/primitives/test_ec.py
+++ b/tests/hazmat/primitives/test_ec.py
@@ -20,6 +20,7 @@ import os
import pytest
from cryptography import exceptions, utils
+from cryptography.hazmat.backends.interfaces import EllipticCurveBackend
from cryptography.hazmat.primitives import hashes, interfaces
from cryptography.hazmat.primitives.asymmetric import ec
@@ -70,6 +71,15 @@ class DummySignatureAlgorithm(object):
pass
+@utils.register_interface(EllipticCurveBackend)
+class DeprecatedDummyECBackend(object):
+ def elliptic_curve_private_key_from_numbers(self, numbers):
+ return b"private_key"
+
+ def elliptic_curve_public_key_from_numbers(self, numbers):
+ return b"public_key"
+
+
@pytest.mark.elliptic
def test_skip_curve_unsupported(backend):
with pytest.raises(pytest.skip.Exception):
@@ -318,3 +328,14 @@ class TestECDSAVectors(object):
verifier.verify()
else:
verifier.verify()
+
+ def test_deprecated_public_private_key_load(self):
+ b = DeprecatedDummyECBackend()
+ pub_numbers = ec.EllipticCurvePublicNumbers(
+ 2,
+ 3,
+ ec.SECT283K1()
+ )
+ numbers = ec.EllipticCurvePrivateNumbers(1, pub_numbers)
+ assert numbers.private_key(b) == b"private_key"
+ assert pub_numbers.public_key(b) == b"public_key"