Skip to content

Commit

Permalink
Merge branch 'main' into ww/downstream-sigstore
Browse files Browse the repository at this point in the history
  • Loading branch information
woodruffw authored Dec 2, 2024
2 parents 9edac7c + ac8c300 commit 959879c
Show file tree
Hide file tree
Showing 14 changed files with 83 additions and 47 deletions.
28 changes: 14 additions & 14 deletions .github/requirements/build-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,20 @@ flit-core==3.10.1 \
--hash=sha256:66e5b87874a0d6e39691f0e22f09306736b633548670ad3c09ec9db03c5662f7 \
--hash=sha256:cb31a76e8b31ad3351bb89e531f64ef2b05d1e65bd939183250bf81ddf4922a8
# via -r build-requirements.in
maturin==1.7.6 \
--hash=sha256:18c3f192c0f48e820fe684c9b89cc099f0107fd93845d39d6001610e3b1b94c4 \
--hash=sha256:37f42a6e15cd49e12a13475b105239e1da20763d50213d541ad56c78d900df9d \
--hash=sha256:41395b4b4d8c35fb2c86143bc3a8808024076a60ed72bfa0002f032f2913ee3d \
--hash=sha256:41d3f0af4a15ee328aa16ba5581f1bfdf0ad88f2a3e1ee9ebf77d2fe269d05af \
--hash=sha256:44c39226a22c2c587e3b886890c76b6ba950ab0f7b129932f8f0498441d47981 \
--hash=sha256:517a0b469199fab8a5e05a2f2477e156c90f80ed160e28e6ee42d5315c2c424b \
--hash=sha256:534c0663c10b590f9c1de8c49f06c0d7da7e1d3078f3975b0191b139a73f051b \
--hash=sha256:84382c7a10d3c84cdfeb230d9b88f78fd99c2aebbd121fd8f04efc706ff65507 \
--hash=sha256:8455cecb948c01ff20689a953a2fd034d4ef94f2bf256cf817beb12572e3051c \
--hash=sha256:85eb76c502f3d9923371623fa153f67afc07b81aa3a28a2620340564bf521e6a \
--hash=sha256:8c23309b75624cf4dc76682bbfe587ce42c9ba595bdc954c1c0b35ef3869470e \
--hash=sha256:cc5a14f42d6f2cf3eff944f2d00d0ce45fc6060d61e51aa8b8c407efbea4dea8 \
--hash=sha256:f64b3a30f3af59fbdbeba980508c7a8294b5f5202a292f41800d22cb8ab69238
maturin==1.7.7 \
--hash=sha256:056a0b688fe697976b9b4683030544773db88c001ea10cde4e89cefcc6a873f9 \
--hash=sha256:0b6de26cfd294d6235e0f1283f6d3eb68d4ee26dd080e654df535c115c52ff3e \
--hash=sha256:3be20897905d7c2cbecebb95c23d5b61af2a20787284fbe3259861f093e4d0e6 \
--hash=sha256:3c5d1c50f4368e83ce35d480aa7767f8c2261e51cf05b2c451b4860b62d028fc \
--hash=sha256:3c7118ffb33bff79ef316fbcffbc4abcc6f7a94a3a28632342309495b2e46743 \
--hash=sha256:4340c1f14ed6f99cb32b2b600695c36777cc8495c0379bd39c48fdfec14ec217 \
--hash=sha256:46eba416c6e94bea5242217c1c6e59b4589a50f5e7a0564c69caba79703d1ea1 \
--hash=sha256:81dad806dc58479fcf6ae06d7fc6ae297569143ef46fd8c11e0cfbc1495b13d0 \
--hash=sha256:c7b421600bbd1b23247e63426d24740ae4f29b9c1ef6c498f605a9b58205c4b6 \
--hash=sha256:e057fc15885feb3b190cfe5d5aa126882f382cb3b7f32f3cd4f93e98cde7f54d \
--hash=sha256:f4df863a3ffafeb0dbeefc017bcf42ad202c8ea54425ebda950ddfcb27e67d93 \
--hash=sha256:f5263b710e512f62298912742cbb86f264a049e90d36f907e6db33ad00ef4a96 \
--hash=sha256:f8d6324296918f8c6bfc0d80fc64584358b46e9a41c671ca5f9f6f8430ff9611
# via -r build-requirements.in
pycparser==2.22 \
--hash=sha256:491c8be9c040f5390f5bf44a5b07752bd07f56edf992381b05c701439eec10f6 \
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion ci-constraints-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ pytest==7.4.4 ; python_full_version < '3.8'
# pytest-cov
# pytest-randomly
# pytest-xdist
pytest==8.3.3 ; python_full_version >= '3.8'
pytest==8.3.4 ; python_full_version >= '3.8'
# via
# cryptography (pyproject.toml)
# pytest-benchmark
Expand Down
7 changes: 5 additions & 2 deletions docs/development/test-vectors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -877,8 +877,11 @@ Custom PKCS7 Test Vectors
CA 2 and 3 generated by OpenSSL.
* ``pkcs7/enveloped.pem`` - A PEM encoded PKCS7 file with enveloped data.
* ``pkcs7/enveloped-aes-256-cbc.pem`` - A PEM encoded PKCS7 file with
enveloped data, with content encrypted using AES-256-CBC, under the public key of
``x509/custom/ca/rsa_ca.pem``.
enveloped data, with content encrypted using AES-256-CBC, under the public
key of ``x509/custom/ca/rsa_ca.pem``.
* ``pkcs7/enveloped-triple-des.pem`` - A PEM encoded PKCS7 file with
enveloped data, with content encrypted using DES EDE3 CBC (also called
Triple DES), under the public key of ``x509/custom/ca/rsa_ca.pem``.
* ``pkcs7/enveloped-rsa-oaep.pem``- A PEM encoded PKCS7 file with
enveloped data, with key encrypted using RSA-OAEP, under the public key of
``x509/custom/ca/rsa_ca.pem``.
Expand Down
6 changes: 3 additions & 3 deletions docs/hazmat/primitives/asymmetric/serialization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1363,7 +1363,7 @@ contain certificates, CRLs, and much more. PKCS7 files commonly have a ``p7b``,
with another algorithm than RSA with PKCS1 v1.5 padding.

:raises cryptography.exceptions.UnsupportedAlgorithm: If the content is encrypted with
another algorithm than AES-128-CBC.
another algorithm than AES (with key sizes 128 and 256), with CBC mode.

:raises ValueError: If the PKCS7 data does not contain encrypted content.

Expand Down Expand Up @@ -1420,7 +1420,7 @@ contain certificates, CRLs, and much more. PKCS7 files commonly have a ``p7b``,
with another algorithm than RSA with PKCS1 v1.5 padding.

:raises cryptography.exceptions.UnsupportedAlgorithm: If the content is encrypted with
another algorithm than AES-128-CBC.
another algorithm than AES (with key sizes 128 and 256), with CBC mode.

:raises ValueError: If the PKCS7 data does not contain encrypted content.

Expand Down Expand Up @@ -1478,7 +1478,7 @@ contain certificates, CRLs, and much more. PKCS7 files commonly have a ``p7b``,
with another algorithm than RSA with PKCS1 v1.5 padding.

:raises cryptography.exceptions.UnsupportedAlgorithm: If the content is encrypted with
another algorithm than AES-128-CBC.
another algorithm than AES (with key sizes 128 and 256), with CBC mode.

:raises ValueError: If the PKCS7 data does not contain encrypted content.

Expand Down
6 changes: 0 additions & 6 deletions src/_cffi_src/openssl/asn1.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
/* ASN1 INTEGER */
void ASN1_INTEGER_free(ASN1_INTEGER *);
int ASN1_INTEGER_set(ASN1_INTEGER *, long);
/* ASN1 TIME */
ASN1_TIME *ASN1_TIME_new(void);
Expand All @@ -49,11 +48,6 @@
/* ASN1 GENERALIZEDTIME */
void ASN1_GENERALIZEDTIME_free(ASN1_GENERALIZEDTIME *);
/* ASN1 ENUMERATED */
ASN1_ENUMERATED *ASN1_ENUMERATED_new(void);
void ASN1_ENUMERATED_free(ASN1_ENUMERATED *);
int ASN1_ENUMERATED_set(ASN1_ENUMERATED *, long);
int ASN1_STRING_type(const ASN1_STRING *);
int ASN1_STRING_to_UTF8(unsigned char **, const ASN1_STRING *);
int i2a_ASN1_INTEGER(BIO *, const ASN1_INTEGER *);
Expand Down
1 change: 0 additions & 1 deletion src/_cffi_src/openssl/nid.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
static const int NID_undef;
static const int NID_subject_alt_name;
static const int NID_crl_reason;
"""

FUNCTIONS = """
Expand Down
1 change: 0 additions & 1 deletion src/_cffi_src/openssl/rand.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
FUNCTIONS = """
void RAND_add(const void *, int, double);
int RAND_status(void);
int RAND_bytes(unsigned char *, int);
"""

CUSTOMIZATIONS = """
Expand Down
2 changes: 1 addition & 1 deletion src/cryptography/hazmat/bindings/_rust/x509.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class CertificateRevocationList:
def fingerprint(self, algorithm: hashes.HashAlgorithm) -> bytes: ...
def get_revoked_certificate_by_serial_number(
self, serial_number: int
) -> RevokedCertificate | None: ...
) -> x509.RevokedCertificate | None: ...
@property
def signature_hash_algorithm(
self,
Expand Down
22 changes: 11 additions & 11 deletions src/rust/cryptography-x509-verification/src/policy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,30 @@ use crate::types::{DNSName, DNSPattern, IPAddress};
use crate::{ValidationError, ValidationErrorKind, ValidationResult, VerificationCertificate};

// RSA key constraints, as defined in CA/B 6.1.5.
static WEBPKI_MINIMUM_RSA_MODULUS: usize = 2048;
const WEBPKI_MINIMUM_RSA_MODULUS: usize = 2048;

// SubjectPublicKeyInfo AlgorithmIdentifier constants, as defined in CA/B 7.1.3.1.

// RSA
static SPKI_RSA: AlgorithmIdentifier<'_> = AlgorithmIdentifier {
const SPKI_RSA: AlgorithmIdentifier<'_> = AlgorithmIdentifier {
oid: asn1::DefinedByMarker::marker(),
params: AlgorithmParameters::Rsa(Some(())),
};

// SECP256R1
static SPKI_SECP256R1: AlgorithmIdentifier<'_> = AlgorithmIdentifier {
const SPKI_SECP256R1: AlgorithmIdentifier<'_> = AlgorithmIdentifier {
oid: asn1::DefinedByMarker::marker(),
params: AlgorithmParameters::Ec(EcParameters::NamedCurve(EC_SECP256R1)),
};

// SECP384R1
static SPKI_SECP384R1: AlgorithmIdentifier<'_> = AlgorithmIdentifier {
const SPKI_SECP384R1: AlgorithmIdentifier<'_> = AlgorithmIdentifier {
oid: asn1::DefinedByMarker::marker(),
params: AlgorithmParameters::Ec(EcParameters::NamedCurve(EC_SECP384R1)),
};

// SECP521R1
static SPKI_SECP521R1: AlgorithmIdentifier<'_> = AlgorithmIdentifier {
const SPKI_SECP521R1: AlgorithmIdentifier<'_> = AlgorithmIdentifier {
oid: asn1::DefinedByMarker::marker(),
params: AlgorithmParameters::Ec(EcParameters::NamedCurve(EC_SECP521R1)),
};
Expand All @@ -73,19 +73,19 @@ pub static WEBPKI_PERMITTED_SPKI_ALGORITHMS: Lazy<Arc<HashSet<AlgorithmIdentifie
// Signature AlgorithmIdentifier constants, as defined in CA/B 7.1.3.2.

// RSASSA‐PKCS1‐v1_5 with SHA‐256
static RSASSA_PKCS1V15_SHA256: AlgorithmIdentifier<'_> = AlgorithmIdentifier {
const RSASSA_PKCS1V15_SHA256: AlgorithmIdentifier<'_> = AlgorithmIdentifier {
oid: asn1::DefinedByMarker::marker(),
params: AlgorithmParameters::RsaWithSha256(Some(())),
};

// RSASSA‐PKCS1‐v1_5 with SHA‐384
static RSASSA_PKCS1V15_SHA384: AlgorithmIdentifier<'_> = AlgorithmIdentifier {
const RSASSA_PKCS1V15_SHA384: AlgorithmIdentifier<'_> = AlgorithmIdentifier {
oid: asn1::DefinedByMarker::marker(),
params: AlgorithmParameters::RsaWithSha384(Some(())),
};

// RSASSA‐PKCS1‐v1_5 with SHA‐512
static RSASSA_PKCS1V15_SHA512: AlgorithmIdentifier<'_> = AlgorithmIdentifier {
const RSASSA_PKCS1V15_SHA512: AlgorithmIdentifier<'_> = AlgorithmIdentifier {
oid: asn1::DefinedByMarker::marker(),
params: AlgorithmParameters::RsaWithSha512(Some(())),
};
Expand Down Expand Up @@ -124,19 +124,19 @@ static RSASSA_PSS_SHA512: Lazy<AlgorithmIdentifier<'_>> = Lazy::new(|| Algorithm
});

// For P-256: the signature MUST use ECDSA with SHA‐256
static ECDSA_SHA256: AlgorithmIdentifier<'_> = AlgorithmIdentifier {
const ECDSA_SHA256: AlgorithmIdentifier<'_> = AlgorithmIdentifier {
oid: asn1::DefinedByMarker::marker(),
params: AlgorithmParameters::EcDsaWithSha256(None),
};

// For P-384: the signature MUST use ECDSA with SHA‐384
static ECDSA_SHA384: AlgorithmIdentifier<'_> = AlgorithmIdentifier {
const ECDSA_SHA384: AlgorithmIdentifier<'_> = AlgorithmIdentifier {
oid: asn1::DefinedByMarker::marker(),
params: AlgorithmParameters::EcDsaWithSha384(None),
};

// For P-521: the signature MUST use ECDSA with SHA‐512
static ECDSA_SHA512: AlgorithmIdentifier<'_> = AlgorithmIdentifier {
const ECDSA_SHA512: AlgorithmIdentifier<'_> = AlgorithmIdentifier {
oid: asn1::DefinedByMarker::marker(),
params: AlgorithmParameters::EcDsaWithSha512(None),
};
Expand Down
2 changes: 1 addition & 1 deletion src/rust/cryptography-x509-verification/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::str::FromStr;
use asn1::IA5String;

// RFC 2822 3.2.4
static ATEXT_CHARS: &str = "!#$%&'*+-/=?^_`{|}~";
const ATEXT_CHARS: &str = "!#$%&'*+-/=?^_`{|}~";

/// Represents a DNS name can be used in X.509 name matching.
///
Expand Down
14 changes: 11 additions & 3 deletions src/rust/src/pkcs7.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,10 @@ fn decrypt_der<'p>(
}
};

// Get algorithm
// TODO: implement all the possible algorithms
// The function can decrypt content encrypted with AES-128-CBC, which the S/MIME v3.2
// RFC specifies as MUST support, and AES-256-CBC, which is specified as SHOULD+
// support. More info: https://datatracker.ietf.org/doc/html/rfc5751#section-2.7
// TODO: implement the possible algorithms from S/MIME 3.2 (and 4.0?)
let algorithm_identifier = enveloped_data
.encrypted_content_info
.content_encryption_algorithm;
Expand All @@ -279,10 +281,16 @@ fn decrypt_der<'p>(
.get(py)?
.call1((pyo3::types::PyBytes::new(py, &iv),))?,
),
AlgorithmParameters::Aes256Cbc(iv) => (
types::AES256.get(py)?.call1((key,))?,
types::CBC
.get(py)?
.call1((pyo3::types::PyBytes::new(py, &iv),))?,
),
_ => {
return Err(CryptographyError::from(
exceptions::UnsupportedAlgorithm::new_err((
"Only AES-128-CBC is currently supported for content decryption.",
"Only AES (with key sizes 128 or 256) with CBC mode is currently supported for content decryption.",
exceptions::Reasons::UNSUPPORTED_SERIALIZATION,
)),
));
Expand Down
19 changes: 18 additions & 1 deletion tests/hazmat/primitives/test_pkcs7.py
Original file line number Diff line number Diff line change
Expand Up @@ -1148,6 +1148,23 @@ def test_pkcs7_decrypt_der(
)
assert decrypted == data.replace(b"\n", b"\r\n")

def test_pkcs7_decrypt_aes_256_cbc_encrypted_content(
self, backend, data, certificate, private_key
):
# Loading encrypted content (for now, not possible natively)
enveloped = load_vectors_from_file(
os.path.join("pkcs7", "enveloped-aes-256-cbc.pem"),
loader=lambda pemfile: pemfile.read(),
mode="rb",
)

# Test decryption: new lines are canonicalized to '\r\n' when
# encryption has no Binary option
decrypted = pkcs7.pkcs7_decrypt_pem(
enveloped, certificate, private_key, []
)
assert decrypted == data.replace(b"\n", b"\r\n")

@pytest.mark.parametrize(
"header",
[
Expand Down Expand Up @@ -1318,7 +1335,7 @@ def test_smime_decrypt_unsupported_content_encryption_algorithm(
self, backend, data, certificate, private_key
):
enveloped = load_vectors_from_file(
os.path.join("pkcs7", "enveloped-aes-256-cbc.pem"),
os.path.join("pkcs7", "enveloped-triple-des.pem"),
loader=lambda pemfile: pemfile.read(),
mode="rb",
)
Expand Down
16 changes: 16 additions & 0 deletions vectors/cryptography_vectors/pkcs7/enveloped-triple-des.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-----BEGIN PKCS7-----
MIICkgYJKoZIhvcNAQcDoIICgzCCAn8CAQAxggJDMIICPwIBADAnMBoxGDAWBgNV
BAMMD2NyeXB0b2dyYXBoeSBDQQIJAOcS06ClbtbJMA0GCSqGSIb3DQEBAQUABIIC
AFCp88C3EJNc3WTTMaWqoKL/aBhrW/utkceKN89Vjmqk1gbdsbK/jZhuBlleSESj
HrZ2wcfubY8UthsVLUfxMUvjSJh2WdZ99IwmPGOtvvPcEWN8mYXO+Q7wN3zyl0cu
aVOZS0NpXm1y9bnbLt2RrohSrTlQ+zyDDPEYUOa1eNX7WOr7hUuVEVchraFHMX7O
kKjWdbVolXvFeqXn3TuHSxRoRIWhhmLNpFUH3lFTUtmpmHHL5W0Qfld/kL0Cagar
gMjSWWWPB0uyd7ufVbDAfGuQFzxWrUy3hQiLhWHxe3hV2vsXcpvBBieIwJKlb5G7
GwbkdOV7wyqiRv8WUtWSwpn1finxypfGGeNfeYdU9M7WuWJ88govos9nIsP2bbyB
hITtKZlZIYBTCimihy691v6QlbdQ79pENq6QWaZlXtcZW6K9Iqq+GY4P2Se6phow
gnGSgR19NRr7rhe78qAJR1fMGDyPPSMSAAEWyrEMupMig23/iLSlZPt+fG58STOq
3eHw2zNSWSwqbrA0ZUB+YtAh03dy6bWzSx8//Pu64DiJYFtkwR5J+Wzu1S3xZPiy
DRLhlfYSzEGZVqd/8b459WU5t4VnyRL0kFSqMLiTl1Drowut7qypWcBoaRgq9j+D
lZxCM5YYPeetGBWZb7zLNWH16h29t5yuoHDoLl1IJunbMDMGCSqGSIb3DQEHATAU
BggqhkiG9w0DBwQI1ISrWpzpTc+AEBSqVJaeybYcyk7DnBT2pyE=
-----END PKCS7-----

0 comments on commit 959879c

Please sign in to comment.