aboutsummaryrefslogtreecommitdiff
path: root/tests
AgeCommit message (Collapse)AuthorFilesLines
43 hoursextensions: EKU must contain at least one member (#11383)William Woodruff1-0/+10
* extensions: EKU must contain at least one member Signed-off-by: William Woodruff <william@trailofbits.com> * record changes Signed-off-by: William Woodruff <william@trailofbits.com> * empty EKU test vector Signed-off-by: William Woodruff <william@trailofbits.com> * typo Signed-off-by: William Woodruff <william@trailofbits.com> --------- Signed-off-by: William Woodruff <william@trailofbits.com>
2024-07-20Fix exchange with keys that had Q automatically computed (#11309)Alex Gaynor1-0/+10
fixes #10790 closes #10864 closes #11218
2024-07-20don't assign unused name (#11310)Alex Gaynor1-1/+1
2024-07-18Add support for encrypting S/MIME messages (#10889)Facundo Tuesca1-1/+248
* Add support for encrypting S/MIME messages * Move PKCS7 decrypt test function to Rust * Use symmetric encryption function from PKCS12 * Remove debug file write from tests * Remove unneeded backend parameter * docs and changelog
2024-07-17Bump vectors (#11288)William Woodruff1-1/+7
* Bump x509-limbo and/or wycheproof in CI * test_limbo: allow build_server_verifier to fail ...in a predictable way. * test_limbo: remove assert * test_limbo: return early when exceptional --------- Co-authored-by: pyca-boringbot[bot] <pyca-boringbot[bot]+106132319@users.noreply.github.com>
2024-07-15Migrate PKCS#7 test_support function to Rust (#11282)Alex Gaynor1-85/+19
2024-07-15Move rust code that exists for our tests to its own module (#11280)Alex Gaynor1-4/+4
* Move rust code that exists for our tests to its own module * Update src/rust/src/test_support.rs Co-authored-by: Paul Kehrer <paul.l.kehrer@gmail.com> --------- Co-authored-by: Paul Kehrer <paul.l.kehrer@gmail.com>
2024-07-15Try removing a workaround for old OpenSSL (#11275)Alex Gaynor1-5/+0
* Try removing a workaround for old OpenSSL * Update test_pkcs7.py
2024-07-14Remove workaround for old libressl (#11274)Alex Gaynor1-4/+1
* Remove workaround for old libressl * Update backend.py
2024-07-07Remove typechecking that pyo3 does automatically (#11212)Alex Gaynor1-2/+4
2024-07-05Enforce length for CommonName (#11201)Alex Gaynor1-1/+8
fixes #10553
2024-07-05add support for CipherContext.update_nonce (#10437)Paul Kehrer3-2/+124
* add support for CipherContext.reset_nonce This only supports ChaCha20 and ciphers in CTR mode. * expand tests to reset to different nonces
2024-07-05Add rsa_recover_private_exponent function (#11193)Daniel Lenski1-1/+30
Given the RSA public exponent (`e`), and the RSA primes (`p`, `q`), it is possible to calculate the corresponding private exponent `d = e⁻¹ mod λ(n)` where `λ(n) = lcm(p-1, q-1)`. With this function added, it becomes possible to use the library to reconstruct an RSA private key given *only* `p`, `q`, and `e`: from cryptography.hazmat.primitives.asymmetric import rsa n = p * q d = rsa.rsa_recover_private_exponent(e, p, q) # newly-added piece iqmp = rsa.rsa_crt_iqmp(p, q) # preexisting dmp1 = rsa.rsa_crt_dmp1(d, p) # preexisting dmq1 = rsa.rsa_crt_dmq1(d, q) # preexisting assert rsa.rsa_recover_prime_factors(n, e, d) in ((p, q), (q, p)) # verify consistency privk = rsa.RSAPrivateNumbers(p, q, d, dmp1, dmq1, iqmp, rsa.RSAPublicNumbers(e, n)).private_key() Older RSA implementations, including the original RSA paper, often used the Euler totient function `ɸ(n) = (p-1) * (q-1)` instead of `λ(n)`. The private exponents generated by that method work equally well, but may be larger than strictly necessary (`λ(n)` always divides `ɸ(n)`). This commit additionally implements `_rsa_recover_euler_private_exponent`, so that tests of the internal structure of RSA private keys can allow for either the Euler or the Carmichael versions of the private exponents. It makes sense to expose only the more modern version (using the Carmichael totient function) for public usage, given that it is slightly more computationally efficient to use the keys in this form, and that some standards like FIPS 186-4 require this form. (See https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.186-4.pdf#page=63)
2024-07-05Convert the remainder of PKCS#12 encryption to Rust (#11200)Alex Gaynor2-58/+2
2024-06-30Add _utc datetime methods to x509.ocsp (#11183)Magnus Watn1-37/+132
Fixes #11170.
2024-06-29utils.int_to_bytes: guard against zero-length (#11173)David Buchanan2-0/+37
* utils: guard against zero-length int_to_bytes * add tests for HBKDF with llen=0 * kbkdf: guard against llen==0 * test that kbkdf rejects llen==0 at __init__ * add standalone test for zero-length int_to_bytes * Update src/cryptography/hazmat/primitives/kdf/kbkdf.py typo Co-authored-by: Alex Gaynor <alex.gaynor@gmail.com> --------- Co-authored-by: Alex Gaynor <alex.gaynor@gmail.com>
2024-06-25policy/extension: improve extension policy errors (#11162)William Woodruff1-1/+31
* policy/extension: improve extension policy errors * verification: ValidationError::ExtensionError variant Begin cleaning things up. * policy/extension: remove redundant clone * ensure that we render the ext OID * lib: coverage for other display arms * relocate custom vector * test-vectors: typo
2024-06-10Convert `PKCS7PaddingContext` to Rust (#11089)Alex Gaynor1-2/+2
2024-06-08Added a benchmark for fernet (#11088)Alex Gaynor1-0/+10
This tests many different primitives
2024-06-03Register OCSPSingleResponse implementation with interface (#11066)Alex Gaynor1-0/+1
2024-06-03added tests for PKCS12Certificate with encryption builder (#11060)Alex Gaynor1-0/+6
2024-06-03fixes #11062 -- register OCSP implementations with interfaces (#11063)Alex Gaynor1-0/+2
2024-05-27re-add branch we dropped in the past (#11030)Paul Kehrer2-0/+33
* re-add branch we dropped in the past * add the test * test all key types * Update src/rust/src/backend/utils.rs Co-authored-by: Alex Gaynor <alex.gaynor@gmail.com> --------- Co-authored-by: Alex Gaynor <alex.gaynor@gmail.com>
2024-05-09Support empty string in `Name.from_rfc4514_string()` (#10964)Marti Raudsepp2-0/+4
Empty string is a valid result from RFC4514 serialization, and should parse successfully. According to https://datatracker.ietf.org/doc/html/rfc4514#section-2.1 > If the RDNSequence is an empty sequence, the result is the empty or zero-length string.
2024-05-05Apply ruff/flake8-implicit-str-concat rule ISC001 (#10932)Dimitri Papadopoulos Orfanos3-7/+7
ISC001 Implicitly concatenated string literals on one line This rule is currently disabled because it conflicts with the formatter: https://github.com/astral-sh/ruff/issues/8272
2024-05-01Ensure curves are supported in determinisic ECDSA tests (#10917)Alex Gaynor2-0/+21
* Ensure curves are supported in determinisic ECDSA tests * x25519/x448 isnt fips anymore i guess
2024-04-29Added additional PKCS#12 tests (#10902)Alex Gaynor1-4/+12
2024-04-28Begin migrating PKCS#12 serialization to Rust (#10616)Alex Gaynor1-3/+0
For now, only handle unencrypted cert-only PKCS#12.
2024-04-25fix for upcoming ruff lint (#10891)Alex Gaynor1-1/+1
2024-04-21Add timezone-aware API variant for `x509.InvalidityDate.invalidity_date` ↵Facundo Tuesca1-0/+20
(#10848)
2024-03-29Added test for ClientVerifier.store (#10665)Alex Gaynor1-0/+1
2024-03-27Add public_key_algorithm_oid to certificate and CSR (#10517)Julien Castiaux1-3/+88
2024-03-22Adding support for OpenSSH ecdsa-sk & ed25519-sk public keys (#10608)commonism1-4/+29
* Adding support for OpenSSH ecdsa-sk & ed25519-sk public keys fixes #10604 * Revert changing the keygen * Add application string to sk key generation * Typing - fix load_application return value annotation * fix sk keys skipping loading in the tests * fix ruff E509 * Fix ruff … * comment wording Co-authored-by: Alex Gaynor <alex.gaynor@gmail.com> * requested changes * no subclassing * fix SyntaxError: annotated name '_KEY_FORMATS' can't be global in python 3.7 c.f. https://github.com/python/cpython/issues/79120 * typo * Update src/cryptography/hazmat/primitives/serialization/ssh.py Co-authored-by: Alex Gaynor <alex.gaynor@gmail.com> * Update src/cryptography/hazmat/primitives/serialization/ssh.py Co-authored-by: Alex Gaynor <alex.gaynor@gmail.com> --------- Co-authored-by: Alex Gaynor <alex.gaynor@gmail.com>
2024-03-22Added additional PKCS#12 tests (#10625)Alex Gaynor1-0/+24
2024-03-21Added additional PKCS#12 tests (#10622)Alex Gaynor1-0/+26
2024-03-20verification: client verification APIs (#10345)William Woodruff2-14/+65
* verification: WIP client verification skeleton Signed-off-by: William Woodruff <william@yossarian.net> * verify: fill in build_client_verifier Signed-off-by: William Woodruff <william@yossarian.net> * implement ClientVerifier.verify Signed-off-by: William Woodruff <william@yossarian.net> * verification: make Python 3.8 happy Signed-off-by: William Woodruff <william@yossarian.net> * switch to a full VerifiedClient type Signed-off-by: William Woodruff <william@yossarian.net> * remove the SubjectOwner::None hack Signed-off-by: William Woodruff <william@yossarian.net> * docs: fix ClientVerifier Signed-off-by: William Woodruff <william@yossarian.net> * verification: replace match with if Signed-off-by: William Woodruff <william@yossarian.net> * return GNs directly, not whole extension Signed-off-by: William Woodruff <william@yossarian.net> * docs/verification: document UnsupportedGeneralNameType raise Signed-off-by: William Woodruff <william@yossarian.net> * lib: RFC822 checks on NCs * test_limbo: enable client tests * tests: flake * test_verification: more Python API coverage * verification: filter GNs by NC support * verification: forbid unsupported NC GNs This is what we should have been doing originally, per RFC 5280 4.2.1.10: > If a name constraints extension that is marked as critical > imposes constraints on a particular name form, and an instance of > that name form appears in the subject field or subjectAltName > extension of a subsequent certificate, then the application MUST > either process the constraint or reject the certificate. * docs/verification: remove old sentence Signed-off-by: William Woodruff <william@yossarian.net> * verification: ensure the right EKU for client/server paths Signed-off-by: William Woodruff <william@yossarian.net> * test_limbo: fixup EKU assertion * verification: feedback --------- Signed-off-by: William Woodruff <william@yossarian.net>
2024-03-09Additional type asserts for latest mypy (#10560)Alex Gaynor1-3/+10
2024-03-07Updates for ruff 0.3.1 (#10548)Alex Gaynor4-22/+15
2024-03-05test_limbo: skip things more idiomatically (#10539)William Woodruff1-7/+8
2024-03-05test_limbo: skip non-SERVER cases for now (#10538)William Woodruff1-0/+3
* test_limbo: skip non-SERVER cases for now Signed-off-by: William Woodruff <william@yossarian.net> * Bump x509-limbo and/or wycheproof in CI --------- Signed-off-by: William Woodruff <william@yossarian.net> Co-authored-by: pyca-boringbot[bot] <pyca-boringbot[bot]+106132319@users.noreply.github.com>
2024-03-03Conert PKCS12Certificate to Rust (#10521)Alex Gaynor1-1/+1
2024-02-29Upgraded version of ruff (#10509)Alex Gaynor10-17/+15
2024-02-26Support for ECDSA deterministic signing (RFC 6979) (#10369)Facundo Tuesca2-0/+118
* Add support for deterministic ECDSA (RFC 6979)
2024-02-20Fix ASN.1 issues in PKCS#7 and S/MIME signing (#10373)Facundo Tuesca1-2/+52
* Fix ASN.1 for S/MIME capabilities. The current implementation defines the SMIMECapabilities attribute so that its value is a SEQUENCE of all the algorithm OIDs that are supported. However, the S/MIME v3 spec (RFC 2633) specifies that each algorithm should be specified in its own SEQUENCE: SMIMECapabilities ::= SEQUENCE OF SMIMECapability SMIMECapability ::= SEQUENCE { capabilityID OBJECT IDENTIFIER, parameters ANY DEFINED BY capabilityID OPTIONAL } (RFC 2633, Appendix A) This commit changes the implementation so that each algorithm is inside its own SEQUENCE. This also matches the OpenSSL implementation. * Fix the RSA OID used for signing PKCS#7/SMIME The current implementation computes the algorithm identifier used in the `digest_encryption_algorithm` PKCS#7 field (or `SignatureAlgorithmIdentifier` in S/MIME) based on both the algorithm used to sign (e.g. RSA) and the digest algorithm (e.g. SHA512). This is correct for ECDSA signatures, where the OIDs used include the digest algorithm (e.g: ecdsa-with-SHA512). However, due to historical reasons, when signing with RSA the OID specified should be the one corresponding to just RSA ("1.2.840.113549.1.1.1" rsaEncryption), rather than OIDs which also include the digest algorithm (such as "1.2.840.113549.1.1.13", sha512WithRSAEncryption). This means that the logic to compute the algorithm identifier is the same except when signing with RSA, in which case the OID will always be `rsaEncryption`. This is consistent with the OpenSSL implementation, and the RFCs that define PKCS#7 and S/MIME. See RFC 3851 (section 2.2), and RFC 3370 (section 3.2) for more details. * Add tests for the changes in PKCS7 signing * PKCS7 fixes from code review * Update CHANGELOG
2024-02-19Convert PKCS#12 loading to Rust (#10434)Alex Gaynor2-11/+15
2024-02-19Move a few more constants fully to Rust (#10428)Alex Gaynor8-18/+24
2024-02-19Fixes #10422 -- don't crash when a PKCS#12 key and cert don't match (#10423)Alex Gaynor1-0/+18
2024-02-18Convert symmetric ciphers to Rust (#9859)Alex Gaynor2-71/+13
2024-02-17support RC2-CBC (#10407)Paul Kehrer2-2/+42
This PR supports a bad old algorithm to support a scapy use case, but does not expose support for effective key bits or any key length other than 128-bit. CBC support only -- no other modes.
2024-02-08skip overflow aead tests on 32-bit systems (#10366)Paul Kehrer1-11/+13
* Revert "smaller mmap in tests to fit in a 32-bit ssize_t (#10365)" This reverts commit b6934e7301d3401ee7f4dcb153f8fa265f577bbf. * skip overflow aead tests on 32-bit systems