Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/cryptography/hazmat/backends/openssl/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,11 +276,9 @@ def mldsa_supported(self) -> bool:
return rust_openssl.CRYPTOGRAPHY_IS_AWSLC

def ed25519_supported(self) -> bool:
return not self._fips_enabled
return True

def ed448_supported(self) -> bool:
if self._fips_enabled:
return False
return (
not rust_openssl.CRYPTOGRAPHY_IS_LIBRESSL
and not rust_openssl.CRYPTOGRAPHY_IS_BORINGSSL
Expand Down
25 changes: 0 additions & 25 deletions src/cryptography/hazmat/primitives/asymmetric/ed25519.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import abc

from cryptography.exceptions import UnsupportedAlgorithm, _Reasons
from cryptography.hazmat.bindings._rust import openssl as rust_openssl
from cryptography.hazmat.primitives import _serialization
from cryptography.utils import Buffer
Expand All @@ -15,14 +14,6 @@
class Ed25519PublicKey(metaclass=abc.ABCMeta):
@classmethod
def from_public_bytes(cls, data: bytes) -> Ed25519PublicKey:
from cryptography.hazmat.backends.openssl.backend import backend

if not backend.ed25519_supported():
raise UnsupportedAlgorithm(
"ed25519 is not supported by this version of OpenSSL.",
_Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM,
)

return rust_openssl.ed25519.from_public_bytes(data)

@abc.abstractmethod
Expand Down Expand Up @@ -73,26 +64,10 @@ def __deepcopy__(self, memo: dict) -> Ed25519PublicKey:
class Ed25519PrivateKey(metaclass=abc.ABCMeta):
@classmethod
def generate(cls) -> Ed25519PrivateKey:
from cryptography.hazmat.backends.openssl.backend import backend

if not backend.ed25519_supported():
raise UnsupportedAlgorithm(
"ed25519 is not supported by this version of OpenSSL.",
_Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM,
)

return rust_openssl.ed25519.generate_key()

@classmethod
def from_private_bytes(cls, data: Buffer) -> Ed25519PrivateKey:
from cryptography.hazmat.backends.openssl.backend import backend

if not backend.ed25519_supported():
raise UnsupportedAlgorithm(
"ed25519 is not supported by this version of OpenSSL.",
_Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM,
)

return rust_openssl.ed25519.from_private_bytes(data)

@abc.abstractmethod
Expand Down
49 changes: 4 additions & 45 deletions tests/hazmat/primitives/test_ed25519.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@

import pytest

from cryptography.exceptions import InvalidSignature, _Reasons
from cryptography.exceptions import InvalidSignature
from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.primitives.asymmetric.ed25519 import (
Ed25519PrivateKey,
Ed25519PublicKey,
)

from ...doubles import DummyKeySerializationEncryption
from ...utils import load_vectors_from_file, raises_unsupported_algorithm
from ...utils import load_vectors_from_file


def load_ed25519_vectors(vector_data):
Expand All @@ -45,31 +45,10 @@ def load_ed25519_vectors(vector_data):
return data


@pytest.mark.supported(
only_if=lambda backend: not backend.ed25519_supported(),
skip_message="Requires OpenSSL without Ed25519 support",
)
def test_ed25519_unsupported(backend):
with raises_unsupported_algorithm(
_Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM
):
Ed25519PublicKey.from_public_bytes(b"0" * 32)

with raises_unsupported_algorithm(
_Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM
):
Ed25519PrivateKey.from_private_bytes(b"0" * 32)

with raises_unsupported_algorithm(
_Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM
):
Ed25519PrivateKey.generate()
def test_ed25519_always_supported(backend):
assert backend.ed25519_supported()


@pytest.mark.supported(
only_if=lambda backend: backend.ed25519_supported(),
skip_message="Requires OpenSSL with Ed25519 support",
)
class TestEd25519Signing:
def test_sign_verify_input(self, backend, subtests):
vectors = load_vectors_from_file(
Expand Down Expand Up @@ -292,10 +271,6 @@ def test_buffer_protocol(self, backend):
)


@pytest.mark.supported(
only_if=lambda backend: backend.ed25519_supported(),
skip_message="Requires OpenSSL with Ed25519 support",
)
def test_public_key_equality(backend):
key_bytes = load_vectors_from_file(
os.path.join("asymmetric", "Ed25519", "ed25519-pkcs8.der"),
Expand All @@ -313,10 +288,6 @@ def test_public_key_equality(backend):
key1 < key2 # type: ignore[operator]


@pytest.mark.supported(
only_if=lambda backend: backend.ed25519_supported(),
skip_message="Requires OpenSSL with Ed25519 support",
)
def test_public_key_copy(backend):
key_bytes = load_vectors_from_file(
os.path.join("asymmetric", "Ed25519", "ed25519-pkcs8.der"),
Expand All @@ -329,10 +300,6 @@ def test_public_key_copy(backend):
assert key1 == key2


@pytest.mark.supported(
only_if=lambda backend: backend.ed25519_supported(),
skip_message="Requires OpenSSL with Ed25519 support",
)
def test_public_key_deepcopy(backend):
key_bytes = load_vectors_from_file(
os.path.join("asymmetric", "Ed25519", "ed25519-pkcs8.der"),
Expand All @@ -345,10 +312,6 @@ def test_public_key_deepcopy(backend):
assert key1 == key2


@pytest.mark.supported(
only_if=lambda backend: backend.ed25519_supported(),
skip_message="Requires OpenSSL with Ed25519 support",
)
def test_private_key_copy(backend):
key_bytes = load_vectors_from_file(
os.path.join("asymmetric", "Ed25519", "ed25519-pkcs8.der"),
Expand All @@ -361,10 +324,6 @@ def test_private_key_copy(backend):
assert key1 == key2


@pytest.mark.supported(
only_if=lambda backend: backend.ed25519_supported(),
skip_message="Requires OpenSSL with Ed25519 support",
)
def test_private_key_deepcopy(backend):
key_bytes = load_vectors_from_file(
os.path.join("asymmetric", "Ed25519", "ed25519-pkcs8.der"),
Expand Down
4 changes: 0 additions & 4 deletions tests/hazmat/primitives/test_pkcs12.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,6 @@ class TestPKCS12Creation:
ed25519.Ed25519PrivateKey.generate,
ed25519.Ed25519PrivateKey,
[],
marks=pytest.mark.supported(
only_if=lambda backend: backend.ed25519_supported(),
skip_message="Requires OpenSSL with Ed25519 support",
),
),
(rsa.generate_private_key, rsa.RSAPrivateKey, [65537, 1024]),
(dsa.generate_private_key, dsa.DSAPrivateKey, [1024]),
Expand Down
4 changes: 0 additions & 4 deletions tests/hazmat/primitives/test_pkcs7.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,6 @@ def test_not_a_cert(self, backend):
hashes.SHA256(),
)

@pytest.mark.supported(
only_if=lambda backend: backend.ed25519_supported(),
skip_message="Does not support ed25519.",
)
def test_unsupported_key_type(self, backend):
cert, _ = _load_cert_key()
key = ed25519.Ed25519PrivateKey.generate()
Expand Down
4 changes: 0 additions & 4 deletions tests/hazmat/primitives/test_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -1399,10 +1399,6 @@ def test_encryption_with_zero_length_password(self):
BestAvailableEncryption(b"")


@pytest.mark.supported(
only_if=lambda backend: backend.ed25519_supported(),
skip_message="Requires OpenSSL with Ed25519 support",
)
class TestEd25519Serialization:
def test_load_der_private_key(self, backend):
data = load_vectors_from_file(
Expand Down
42 changes: 1 addition & 41 deletions tests/hazmat/primitives/test_ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ class TestOpenSSHSerialization:
],
)
def test_load_ssh_public_key(self, key_file, cert_file, backend):
if "ed25519" in key_file and not backend.ed25519_supported():
pytest.skip("Requires OpenSSL with Ed25519 support")

# normal public key
pub_data = load_vectors_from_file(
os.path.join("asymmetric", "OpenSSH", key_file),
Expand Down Expand Up @@ -174,8 +171,6 @@ def run_partial_pubkey(self, pubdata, backend):
],
)
def test_load_ssh_private_key(self, key_file, backend):
if "ed25519" in key_file and not backend.ed25519_supported():
pytest.skip("Requires OpenSSL with Ed25519 support")
if "-psw" in key_file and not ssh._bcrypt_supported:
pytest.skip("Requires bcrypt module")

Expand Down Expand Up @@ -261,10 +256,6 @@ def test_load_ssh_private_key(self, key_file, backend):
maxline = max(map(len, priv_data2.split(b"\n")))
assert maxline < 80

@pytest.mark.supported(
only_if=lambda backend: backend.ed25519_supported(),
skip_message="Requires Ed25519 support",
)
@pytest.mark.parametrize(
"key_file",
[
Expand All @@ -281,10 +272,6 @@ def test_load_unsupported_ssh_private_key(self, key_file):
with pytest.raises(UnsupportedAlgorithm):
load_ssh_private_key(data, None)

@pytest.mark.supported(
only_if=lambda backend: backend.ed25519_supported(),
skip_message="Requires Ed25519 support",
)
@pytest.mark.supported(
only_if=lambda backend: ssh._bcrypt_supported,
skip_message="Requires that bcrypt exists",
Expand All @@ -304,10 +291,6 @@ def test_load_ssh_private_key_invalid_tag(self, backend):
with pytest.raises(InvalidTag):
load_ssh_private_key(priv_data, b"password")

@pytest.mark.supported(
only_if=lambda backend: backend.ed25519_supported(),
skip_message="Requires Ed25519 support",
)
@pytest.mark.supported(
only_if=lambda backend: ssh._bcrypt_supported,
skip_message="Requires that bcrypt exists",
Expand Down Expand Up @@ -1140,10 +1123,6 @@ def test_load_ssh_public_key_ecdsa_nist_p256_bad_curve_name(self, backend):
load_ssh_public_key(ssh_key, backend)


@pytest.mark.supported(
only_if=lambda backend: backend.ed25519_supported(),
skip_message="Requires OpenSSL with Ed25519 support",
)
class TestEd25519SSHSerialization:
def test_load_ssh_public_key(self, backend):
ssh_key = (
Expand Down Expand Up @@ -1186,10 +1165,6 @@ def test_load_ssh_public_key_trailing_data(self, backend):


class TestSSHCertificate:
@pytest.mark.supported(
only_if=lambda backend: backend.ed25519_supported(),
skip_message="Requires OpenSSL with Ed25519 support",
)
def test_loads_ssh_cert(self, backend):
# secp256r1 public key, ed25519 signing key
cert = load_ssh_public_identity(
Expand Down Expand Up @@ -1718,10 +1693,6 @@ def test_crit_opts_exts_lexically_sorted(self):
(b"zebra@cryptography.io", b""),
]

@pytest.mark.supported(
only_if=lambda backend: backend.ed25519_supported(),
skip_message="Requires OpenSSL with Ed25519 support",
)
def test_sign_ed25519(self, backend):
private_key = ed25519.Ed25519PrivateKey.generate()
builder = (
Expand Down Expand Up @@ -1818,10 +1789,6 @@ def test_sign_and_byte_compare_rsa(self, monkeypatch):
b"zbwL217Q93R08bJn1hDWuiTiaHGauSy2gPUI+cnkvlEocHM"
)

@pytest.mark.supported(
only_if=lambda backend: backend.ed25519_supported(),
skip_message="Requires OpenSSL with Ed25519 support",
)
def test_sign_and_byte_compare_ed25519(self, monkeypatch, backend):
# Monkey patch urandom to return a known value so we
# get a deterministic signature with Ed25519.
Expand Down Expand Up @@ -1911,10 +1878,7 @@ def test_ssh_key_fingerprint_rsa_sha256(self):
)

@pytest.mark.supported(
only_if=lambda backend: (
backend.hash_supported(hashes.MD5())
and backend.ed25519_supported()
),
only_if=lambda backend: backend.hash_supported(hashes.MD5()),
skip_message="Does not support MD5 or Ed25519",
)
def test_ssh_key_fingerprint_ed25519_md5(self):
Expand All @@ -1927,10 +1891,6 @@ def test_ssh_key_fingerprint_ed25519_md5(self):
fingerprint = ssh_key_fingerprint(public_key, hashes.MD5())
assert fingerprint == b"\xe5R=\x01\x9e\xa0\xc1\xe9\x8c?L|\xc5\x94W\x85"

@pytest.mark.supported(
only_if=lambda backend: backend.ed25519_supported(),
skip_message="Ed25519 not supported",
)
def test_ssh_key_fingerprint_ed25519_sha256(self):
ssh_key = load_vectors_from_file(
os.path.join("asymmetric", "OpenSSH", "ed25519-nopsw.key.pub"),
Expand Down
4 changes: 0 additions & 4 deletions tests/wycheproof/test_eddsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
from .utils import wycheproof_tests


@pytest.mark.supported(
only_if=lambda backend: backend.ed25519_supported(),
skip_message="Requires OpenSSL with Ed25519 support",
)
@wycheproof_tests("ed25519_test.json")
def test_ed25519_signature(backend, wycheproof):
# We want to fail if/when wycheproof adds more edwards curve tests
Expand Down
8 changes: 0 additions & 8 deletions tests/x509/test_ocsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -1638,10 +1638,6 @@ def test_unknown_response_status(self):


class TestOCSPEdDSA:
@pytest.mark.supported(
only_if=lambda backend: backend.ed25519_supported(),
skip_message="Requires OpenSSL with Ed25519 support / OCSP",
)
def test_invalid_algorithm(self, backend):
builder = ocsp.OCSPResponseBuilder()
cert, issuer = _cert_and_issuer()
Expand Down Expand Up @@ -1670,10 +1666,6 @@ def test_invalid_algorithm(self, backend):
with pytest.raises(ValueError):
builder.sign(private_key, hashes.SHA256())

@pytest.mark.supported(
only_if=lambda backend: backend.ed25519_supported(),
skip_message="Requires OpenSSL with Ed25519 support / OCSP",
)
def test_sign_ed25519(self, backend):
builder = ocsp.OCSPResponseBuilder()
cert, issuer = _cert_and_issuer()
Expand Down
Loading