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
8 changes: 8 additions & 0 deletions harness/gocryptox509/schema.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion limbo-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"pedantic-rfc5280",
"rfc5280-incompatible-with-webpki",
"denial-of-service",
"has-crl"
"has-crl",
"has-mldsa"
],
"title": "Feature",
"type": "string"
Expand Down Expand Up @@ -156,6 +157,9 @@
"DSA_WITH_SHA512",
"ED25519",
"ED448",
"ML_DSA_44",
"ML_DSA_65",
"ML_DSA_87",
"GOSTR3411_94_WITH_3410_2001",
"GOSTR3410_2012_WITH_3411_2012_256",
"GOSTR3410_2012_WITH_3411_2012_512"
Expand Down
2,521 changes: 1,346 additions & 1,175 deletions limbo.json

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion limbo/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from cryptography import x509
from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.primitives.asymmetric import dsa, ec, rsa
from cryptography.hazmat.primitives.asymmetric.types import CertificateIssuerPrivateKeyTypes
from cryptography.x509 import ExtensionType

Expand Down Expand Up @@ -51,9 +52,17 @@ class CertificatePair(Certificate):

@cached_property
def key_pem(self) -> str:
# NOTE: Not every key type has a "traditional" (i.e. non-PKCS#8)
# serialization; ML-DSA and EdDSA keys are PKCS#8 only.
match self.key:
case dsa.DSAPrivateKey() | ec.EllipticCurvePrivateKey() | rsa.RSAPrivateKey():
format = serialization.PrivateFormat.TraditionalOpenSSL
case _:
format = serialization.PrivateFormat.PKCS8

return self.key.private_bytes(
encoding=serialization.Encoding.PEM,
format=serialization.PrivateFormat.TraditionalOpenSSL,
format=format,
encryption_algorithm=serialization.NoEncryption(),
).decode()

Expand Down
8 changes: 8 additions & 0 deletions limbo/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ class SignatureAlgorithm(StrEnum):
DSA_WITH_SHA512 = "DSA_WITH_SHA512"
ED25519 = "ED25519"
ED448 = "ED448"
ML_DSA_44 = "ML_DSA_44"
ML_DSA_65 = "ML_DSA_65"
ML_DSA_87 = "ML_DSA_87"
GOSTR3411_94_WITH_3410_2001 = "GOSTR3411_94_WITH_3410_2001"
GOSTR3410_2012_WITH_3411_2012_256 = "GOSTR3410_2012_WITH_3411_2012_256"
GOSTR3410_2012_WITH_3411_2012_512 = "GOSTR3410_2012_WITH_3411_2012_512"
Expand Down Expand Up @@ -221,6 +224,11 @@ class Feature(StrEnum):
Tests that use Certificate Revocation Lists (CRLs).
"""

has_mldsa = "has-mldsa"
"""
Tests that use ML-DSA keys or signatures, per RFC 9881.
"""


class Importance(StrEnum):
"""
Expand Down
1 change: 1 addition & 0 deletions limbo/testcases/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from .pathlen import * # noqa: F403
from .pathological import * # noqa: F403
from .rfc5280 import * # noqa: F403
from .rfc9881 import * # noqa: F403
from .webpki import * # noqa: F403

__all__ = [
Expand Down
28 changes: 23 additions & 5 deletions limbo/testcases/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from cryptography import x509
from cryptography.hazmat.primitives import hashes, serialization
from cryptography.hazmat.primitives.asymmetric import ec
from cryptography.hazmat.primitives.asymmetric import ec, ed448, ed25519, mldsa
from cryptography.hazmat.primitives.asymmetric.types import CertificateIssuerPrivateKeyTypes

from limbo.assets import (
Expand All @@ -32,6 +32,24 @@
logger = logging.getLogger(__name__)


def signature_hash(key: CertificateIssuerPrivateKeyTypes) -> hashes.SHA256 | None:
"""
Returns the hash algorithm to sign with under the given key, or `None` for
key types that don't take a separate digest (EdDSA and ML-DSA).
"""
match key:
case (
ed25519.Ed25519PrivateKey()
| ed448.Ed448PrivateKey()
| mldsa.MLDSA44PrivateKey()
| mldsa.MLDSA65PrivateKey()
| mldsa.MLDSA87PrivateKey()
):
return None
case _:
return hashes.SHA256()


class Builder:
def _ca(
self,
Expand Down Expand Up @@ -116,9 +134,9 @@ def _ca(
builder = builder.add_extension(extra_extension.ext, critical=extra_extension.critical)

if parent:
cert = builder.sign(parent.key, algorithm=hashes.SHA256())
cert = builder.sign(parent.key, algorithm=signature_hash(parent.key))
else:
cert = builder.sign(key, algorithm=hashes.SHA256())
cert = builder.sign(key, algorithm=signature_hash(key))

return CertificatePair(cert, key)

Expand Down Expand Up @@ -360,7 +378,7 @@ def leaf_cert(

certificate = builder.sign(
private_key=parent.key,
algorithm=hashes.SHA256(),
algorithm=signature_hash(parent.key),
)

return CertificatePair(certificate, key)
Expand Down Expand Up @@ -407,7 +425,7 @@ def crl(

crl = builder.sign(
private_key=key,
algorithm=hashes.SHA256(),
algorithm=signature_hash(key),
)

return crl
Expand Down
10 changes: 8 additions & 2 deletions limbo/testcases/invalid.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def sign(
self,
data: bytes,
padding: AsymmetricPadding,
algorithm: asym_utils.Prehashed | hashes.HashAlgorithm,
algorithm: asym_utils.Prehashed | hashes.HashAlgorithm | asym_utils.NoDigestInfo,
) -> bytes:
# SEQUENCE {}
return b"\x30\x00"
Expand Down Expand Up @@ -46,6 +46,9 @@ def private_numbers(self) -> rsa.RSAPrivateNumbers:
def __copy__(self) -> MalformedRSAPrivateKey:
raise NotImplementedError

def __deepcopy__(self, memo: dict) -> MalformedRSAPrivateKey:
raise NotImplementedError


class MalformedRSAPublicKey(rsa.RSAPublicKey):
def public_bytes(
Expand Down Expand Up @@ -88,7 +91,7 @@ def recover_data_from_signature(
self,
signature: bytes,
padding: AsymmetricPadding,
algorithm: hashes.HashAlgorithm | None,
algorithm: hashes.HashAlgorithm | asym_utils.NoDigestInfo | None,
) -> bytes:
raise NotImplementedError

Expand All @@ -104,6 +107,9 @@ def verify(
def __copy__(self) -> MalformedRSAPublicKey:
raise NotImplementedError

def __deepcopy__(self, memo: dict) -> MalformedRSAPublicKey:
raise NotImplementedError


@testcase
def invalid_issuer_key(builder: Builder) -> None:
Expand Down
Loading
Loading