Commit graph

2466 commits

Author SHA1 Message Date
Magnus Watn
eae331491c
Add _utc datetime methods to x509.ocsp (#11183)
Fixes #11170.
2024-06-30 12:08:56 -04:00
David Buchanan
56933bf61a
utils.int_to_bytes: guard against zero-length (#11173)
* 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-29 15:23:57 +00:00
William Woodruff
f370b09810
policy/extension: improve extension policy errors (#11162)
* 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-25 21:51:24 -04:00
Alex Gaynor
da45641e46
Convert PKCS7PaddingContext to Rust (#11089) 2024-06-10 12:22:36 -04:00
Alex Gaynor
f3b0e165f0
Added a benchmark for fernet (#11088)
This tests many different primitives
2024-06-08 07:52:13 -07:00
Alex Gaynor
d54d67353b
Register OCSPSingleResponse implementation with interface (#11066) 2024-06-03 06:32:28 -07:00
Alex Gaynor
064a463eae
added tests for PKCS12Certificate with encryption builder (#11060) 2024-06-03 05:23:51 -07:00
Alex Gaynor
99de528c12
fixes #11062 -- register OCSP implementations with interfaces (#11063) 2024-06-03 05:08:11 -07:00
Paul Kehrer
7f515fc43c
re-add branch we dropped in the past (#11030)
* 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-27 13:09:56 +00:00
Marti Raudsepp
acc3226faa
Support empty string in Name.from_rfc4514_string() (#10964)
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-09 13:54:49 +00:00
Dimitri Papadopoulos Orfanos
9321740c2a
Apply ruff/flake8-implicit-str-concat rule ISC001 (#10932)
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-05 16:11:26 +00:00
Alex Gaynor
b4ca965b0f
Ensure curves are supported in determinisic ECDSA tests (#10917)
* Ensure curves are supported in determinisic ECDSA tests

* x25519/x448 isnt fips anymore i guess
2024-05-01 21:55:41 -07:00
Alex Gaynor
d5a3984a9a
Added additional PKCS#12 tests (#10902) 2024-04-29 08:04:56 -07:00
Alex Gaynor
66cf834fad
Begin migrating PKCS#12 serialization to Rust (#10616)
For now, only handle unencrypted cert-only PKCS#12.
2024-04-28 09:44:04 -07:00
Alex Gaynor
c65975377e
fix for upcoming ruff lint (#10891) 2024-04-25 22:51:24 +00:00
Facundo Tuesca
83d90df3df
Add timezone-aware API variant for x509.InvalidityDate.invalidity_date (#10848) 2024-04-21 15:09:12 -04:00
Alex Gaynor
01561ded0e
Added test for ClientVerifier.store (#10665) 2024-03-29 08:27:29 -04:00
Julien Castiaux
031d407e4d
Add public_key_algorithm_oid to certificate and CSR (#10517) 2024-03-27 14:32:35 -04:00
commonism
51a6dd28cc
Adding support for OpenSSH ecdsa-sk & ed25519-sk public keys (#10608)
* 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-22 03:24:22 +00:00
Alex Gaynor
089039d0f6
Added additional PKCS#12 tests (#10625) 2024-03-22 02:44:41 +00:00
Alex Gaynor
8bd15a1d28
Added additional PKCS#12 tests (#10622) 2024-03-21 22:08:56 -04:00
William Woodruff
4a3e7dcc97
verification: client verification APIs (#10345)
* 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-20 21:00:00 -04:00
Alex Gaynor
dd1d6059b3
Additional type asserts for latest mypy (#10560) 2024-03-09 17:24:00 -06:00
Alex Gaynor
dcf6ac240d
Updates for ruff 0.3.1 (#10548) 2024-03-07 10:57:37 -08:00
William Woodruff
b507701ab4
test_limbo: skip things more idiomatically (#10539) 2024-03-05 01:09:19 +00:00
William Woodruff
8221e18abd
test_limbo: skip non-SERVER cases for now (#10538)
* 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-05 00:44:20 +00:00
Alex Gaynor
6e6b17d8ba
Conert PKCS12Certificate to Rust (#10521) 2024-03-03 23:33:45 -06:00
Alex Gaynor
905983fe56
Upgraded version of ruff (#10509) 2024-02-29 17:54:19 +00:00
Facundo Tuesca
0a1098fcf0
Support for ECDSA deterministic signing (RFC 6979) (#10369)
* Add support for deterministic ECDSA (RFC 6979)
2024-02-26 19:13:47 +00:00
Facundo Tuesca
8ef3b381bf
Fix ASN.1 issues in PKCS#7 and S/MIME signing (#10373)
* 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-20 17:17:34 -05:00
Alex Gaynor
8224447b1e
Convert PKCS#12 loading to Rust (#10434) 2024-02-19 16:44:28 -08:00
Alex Gaynor
732eea3c81
Move a few more constants fully to Rust (#10428) 2024-02-19 12:33:12 -08:00
Alex Gaynor
97d2316727
Fixes #10422 -- don't crash when a PKCS#12 key and cert don't match (#10423) 2024-02-19 08:50:28 -08:00
Alex Gaynor
50ea0faab7
Convert symmetric ciphers to Rust (#9859) 2024-02-18 14:23:21 -08:00
Paul Kehrer
429d34906c
support RC2-CBC (#10407)
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-17 03:40:43 +00:00
Paul Kehrer
4e7c2c72ef
skip overflow aead tests on 32-bit systems (#10366)
* Revert "smaller mmap in tests to fit in a 32-bit ssize_t (#10365)"

This reverts commit b6934e7301.

* skip overflow aead tests on 32-bit systems
2024-02-08 15:19:50 +00:00
Paul Kehrer
b6934e7301
smaller mmap in tests to fit in a 32-bit ssize_t (#10365)
this still triggers the overflows we expect in the tests and should also
work on 32-bit systems
2024-02-08 14:51:21 +00:00
Paul Kehrer
ab83fff3c2
initialize openssl's legacy provider in rust (#10323)
* initialize openssl's legacy provider in rust

as we oxidize we need to do this here to ensure it actually happens

* alex is a comment format pedant
2024-02-02 16:11:37 +00:00
Paul Kehrer
c0c9ec8dbb
remove the memleak tests (#10322)
they are fragile, haven't caught regressions, and increasingly pointless
as we oxidize.
2024-02-02 02:38:52 +00:00
Alex Gaynor
b80629c342
Dropped support for OpenSSL<1.1.1e (#10318) 2024-02-01 19:16:05 -06:00
William Woodruff
e80f3eed8e
verification/policy: tweak key checks (#10311)
* verification/policy: tweak key checks

Needs https://github.com/C2SP/x509-limbo/pull/185.

Signed-off-by: William Woodruff <william@trailofbits.com>

* bump limbo

Signed-off-by: William Woodruff <william@trailofbits.com>

---------

Signed-off-by: William Woodruff <william@trailofbits.com>
2024-01-31 19:26:49 -05:00
William Woodruff
103f123efa
parsing, verification: check RSA key size against WebPKI minimum (#10302)
* parsing, verification: check RSA key size against WebPKI minimum

Signed-off-by: William Woodruff <william@trailofbits.com>

* move key size check to permits_ca

We don't enforce EE key sizes, consistent with other CABF validators.

Signed-off-by: William Woodruff <william@trailofbits.com>

* limit is_rsa to key algorithms

Signed-off-by: William Woodruff <william@trailofbits.com>

* is_rsa -> is_rsa_key

Signed-off-by: William Woodruff <william@trailofbits.com>

* fetch-vectors: bump limbo

Signed-off-by: William Woodruff <william@trailofbits.com>

* reorg, remove helper

Signed-off-by: William Woodruff <william@trailofbits.com>

* Update .github/actions/fetch-vectors/action.yml

Co-authored-by: Alex Gaynor <alex.gaynor@gmail.com>

---------

Signed-off-by: William Woodruff <william@trailofbits.com>
Co-authored-by: Alex Gaynor <alex.gaynor@gmail.com>
2024-01-31 00:45:18 +00:00
Paul Kehrer
722a6393e6
migrate ARC4 and TripleDES to decrepit (#10286) 2024-01-29 19:42:21 -05:00
Paul Kehrer
07b706f336
remove unneeded sha1 and support checks from the rsa tests (#10288) 2024-01-29 18:44:42 -05:00
Paul Kehrer
4ea43098ca
stop using SHA1 in most of test_ec where it isn't needed (#10287) 2024-01-29 18:40:25 -05:00
Alex Gaynor
98dfafeb8d
Migrate AES-CCM to Rust (#10279) 2024-01-28 16:54:54 -06:00
Paul Kehrer
1729edef70
add decrepit namespace and put SEED, IDEA, Blowfish, and CAST5 in it (#10284) 2024-01-28 17:34:33 -05:00
Alex Gaynor
ea5a5b4ad0
Convert AESGCM AEAD to Rust (#9181) 2024-01-28 16:18:00 -06:00
Alex Gaynor
e44e124f4a
Drop LibreSSL <3.8.0 (#10283) 2024-01-28 15:59:56 -06:00
Alex Gaynor
10211b8917
Remove unused generate_rsa_parameters_supported (#10273) 2024-01-27 18:17:30 -06:00