Commit graph

314 commits

Author SHA1 Message Date
Alex Gaynor
fe5f3a9217
Two more testscases for key loading (#12370)
* Two more testscases for key loading

* Update tests/hazmat/primitives/test_serialization.py

Co-authored-by: Paul Kehrer <paul.l.kehrer@gmail.com>

---------

Co-authored-by: Paul Kehrer <paul.l.kehrer@gmail.com>
2025-01-31 18:20:31 +00:00
Alex Gaynor
023a2597ec
Added tests for various malformed PEM files (#12338) 2025-01-24 16:06:53 -08:00
Alex Gaynor
45381b4266
Added two new PKCS#8 test cases (#12333)
* Added two new PKCS#8 test cases

* Added two more testcases

* Spelling
2025-01-24 11:04:53 -08:00
Alex Gaynor
5d16313b42
Added tests for two more PKCS#8 key situations (#12310) 2025-01-19 08:04:56 -08:00
Alex Gaynor
17119de16f
Added new test cases for invalid EC keys (#12309) 2025-01-18 20:03:57 -08:00
Alex Gaynor
af76c1f456
Added more serialization test vector tests (#12308) 2025-01-18 12:22:22 -08:00
Alex Gaynor
86b24873c7
Added new test cases for PKCS#8 parsing (#12305) 2025-01-17 20:00:29 -08:00
Quentin Retourne
6143683d87
PKCS7: added encryption with AES-256-CBC (#12172)
* feat: added encryption with AES-256-CBC

added & updated tests accordingly

updated documentation

removed useless test vector

* fixing coverage

* last python coverage fix

* restraining the number of classes

changed name to content_encryption_algorithm

simplified the rust code accordingly

tried to simplify the documentation

* python 3.8 artefacts

* passed content encryption algo locally

adapted rust code accordingly
2024-12-29 13:02:20 -05:00
Paul Kehrer
235f991211
add new invalid EC key (#12103) 2024-12-04 23:36:45 -05:00
Quentin Retourne
ac8c3003cb
PKCS7 Decryption: more content decryption algorithms (#12088)
* pkcs7: added more content encryption algorithms

* removed creation of AES 192 algorithm

* remove AES 192 compat (historical relic)

* minor correction
2024-12-02 14:34:04 +00:00
Quentin Retourne
d6cac753c2
Add support for decrypting S/MIME messages (#11555)
* first python API proposition

first round-trip tests

feat: made asn1 structures readable

refacto: adapted existing functions accordingly

feat/pkcs12: added symmetric_decrypt

feat: deserialize 3 possible encodings

feat: handling AES-128

feat: raise error when no recipient is found

feat/pkcs7: added decanonicalize function

feat/asn1: added decode_der_data

feat/pkcs7: added smime_enveloped_decode

tests are the round-trip (encrypt & decrypt)

more tests for 100% python coverage

test support pkcs7_encrypt with openssl

added algorithm to pkcs7_encrypt signature

refacto: decrypt function is clearer

flow is more natural

refacto: added all rust error tests

refacto: added another CA chain for checking

fix: const handling

Refactor PKCS7Decryptor to pkcs7_decrypt

refacto: removed SMIME_ENVELOPED_DECODE from rust code

refacto: removed decode_der_data

adapted tests accordingly

removed the PEM tag check

added tests for smime_decnonicalize

one more test case

Update src/rust/src/pkcs7.rs

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

took comments into account

pem to der is now outside of decrypt

fix: removed test_support pkcs7_encrypt

added vector for aes_256_cbc encrypted pkcs7

feat: not using test_support decrypt anymore

added new vectors for PKCS7 tests

feat: using pkcs7 vectors

removed previous ones

fix: changed wrong function

feat: added certificate issuer check

test: generating the RSA chain

removed the vectors accordingly

moved symmetric_decrypt to pkcs7.rs

* Update src/cryptography/hazmat/primitives/serialization/pkcs7.py

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

* fix: removed use of deprecated new_bound for PyBytes

* corrected some error types

* updated tests accordingly

* fix: handling other key encryption algorithms

added vectors & tests accordingly

* first attempts raising error when no header to remove

* one more test to handle text data without header

* fix: went back to the previous implementation

* refacto: removed the return part

* feat: Binary option does not seem useful for decryption

removed decanonicalization function

adapted tests accordingly

* moved logic into rust

only left some checks (for now?)

* removed pyfunction for the inner decrypt one

* added checks in rust now :)

changed name for clarity

* removed unused function

* some checks not needed anymore

* removed a parameter

* took comments into account

* removed unused import

removed excess get_type

* added first unwrap corrections

cleaned tests, added some others

added more vectors

* no more unwrap for parameter checks

* removing headers is Python now

added tests accordingly

will compare with OpenSSL

* final corrections?

* first version of documentation

some minor refactoring

* corrected doctests

* better indentation

* doctest: added RSA private key

* oops

---------

Co-authored-by: Alex Gaynor <alex.gaynor@gmail.com>
2024-11-26 08:39:53 -05:00
Quentin Retourne
57401ba194
added vector with different key encryption algo (#11998)
adapted documentation accordingly
2024-11-19 06:44:21 -05:00
Alex Gaynor
8209d63ae7
fixes #11944 -- don't panic on attributes with no values (#11947) 2024-11-14 14:16:43 -08:00
Alex Gaynor
da437d16a9
fixes #11920 raise a clean Python error on DSA signing failure due to nilpotent (#11921) 2024-11-11 14:37:32 +00:00
Oleg Höfling
fef127093b
feat(admissions): implement parsing of admissions extension (#11903)
* feat: implement parsing of admissions extension

Signed-off-by: oleg.hoefling <oleg.hoefling@gmail.com>

* chore: add tests for admissions extension parsing

Signed-off-by: oleg.hoefling <oleg.hoefling@gmail.com>

* chore: use cryptography result return type

Signed-off-by: oleg.hoefling <oleg.hoefling@gmail.com>

* chore: apply fixes done by cargo fmt and clippy

Signed-off-by: oleg.hoefling <oleg.hoefling@gmail.com>

* add gematik company name and the gmbh abbreviations to known words

Signed-off-by: oleg.hoefling <oleg.hoefling@gmail.com>

* fix: regenerate the synthetic certificate with additional admission covering the case of naming authority with no data

Signed-off-by: oleg.hoefling <oleg.hoefling@gmail.com>

* fix: parse none for profession_oids if profession_oids is none

Signed-off-by: oleg.hoefling <oleg.hoefling@gmail.com>

* chore: apply formatting to changes in rust codebase

Signed-off-by: oleg.hoefling <oleg.hoefling@gmail.com>

* refactor: switch return type of parse_profession_infos from PyObject to Bound<PyAny>

Signed-off-by: Oleg Hoefling <oleg.hoefling@gmail.com>

* refactor: switch return type of parse_naming_authority from PyObject to Bound<PyAny>

Signed-off-by: Oleg Hoefling <oleg.hoefling@gmail.com>

* refactor: switch return type of parse_admissions from PyObject to Bound<PyAny>

Signed-off-by: Oleg Hoefling <oleg.hoefling@gmail.com>

* chore: remove gematik certs from repo

Signed-off-by: Oleg Hoefling <oleg.hoefling@gmail.com>

* chore: remove gematik certs from this pr

Signed-off-by: Oleg Hoefling <oleg.hoefling@gmail.com>

* chore: extend parser tests with an additional synthetic certificate to complete rust coverage

Signed-off-by: Oleg Hoefling <oleg.hoefling@gmail.com>

* chore: add description for the additional certificate without authority

Signed-off-by: Oleg Hoefling <oleg.hoefling@gmail.com>

* use into_bound(py) as shortcut, refrain from using to_object() in all added functions

Signed-off-by: Oleg Hoefling <oleg.hoefling@gmail.com>

* add better description for the admissions synthetic cert

Signed-off-by: Oleg Hoefling <oleg.hoefling@gmail.com>

* adjust description to avoid using misspelled words

Signed-off-by: Oleg Hoefling <oleg.hoefling@gmail.com>

---------

Signed-off-by: oleg.hoefling <oleg.hoefling@gmail.com>
Signed-off-by: Oleg Hoefling <oleg.hoefling@gmail.com>
2024-11-10 20:06:01 -05:00
Quentin Retourne
5b425ec416
added new vectors for PKCS7 tests (#11843)
* added new vectors for PKCS7 tests

* some corrections in the documentation

* removed RSA CA, not using it anymore
2024-11-05 22:29:26 +00:00
Alex Gaynor
8b3de53ed8
When failing to parse SANs or IANs, include which it was that failed (#11785) 2024-10-17 20:13:03 -07:00
Paul Kehrer
408b9f8a7a
argon2id test vectors (#11523) 2024-09-02 13:38:17 -04:00
David Benjamin
8755923903
Bump RSA-512 test keys to RSA-2048 (#11443)
* Bump RSA-512 test keys to RSA-2048

RSA-512 was broken in 1999. cryptography.io should not be requesting
its backend library support it in 2024.

* Update test-vectors.rst

The replacement keys were generated fresh, and this document seems to
just cite the external ones.

* Document custom test vectors
2024-08-17 18:38:57 +00:00
William Woodruff
0db3ed8707
extensions: EKU must contain at least one member (#11383)
* 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-08-02 15:06:46 +00:00
Alex Gaynor
42788a0353
Fix exchange with keys that had Q automatically computed (#11309)
fixes #10790
closes #10864
closes #11218
2024-07-20 08:05:18 -07: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
61a5e672e6
fixed rst syntax in test-vectors.rst (#11153) 2024-06-25 08:00:12 +03:00
Julien Castiaux
031d407e4d
Add public_key_algorithm_oid to certificate and CSR (#10517) 2024-03-27 14:32:35 -04:00
Alex Gaynor
8436316862
Wycheproof lives under C2SP now (#10628) 2024-03-22 19:34:41 -04:00
Facundo Tuesca
c97808ca77
Add test vectors for deterministic ECDSA (RFC6979) (#10438) 2024-02-20 06:57:07 -08:00
Paul Kehrer
608ce9520f
add RC2-128-CBC vector (#10402)
vector created using golang's x/crypto internal impl and verified
against openssl
2024-02-16 22:20:14 -05:00
Paul Kehrer
075925fd55
allow SPKI RSA keys to be parsed even if they have an incorrect delimiter (#10248)
* allow SPKI RSA keys to be parsed even if they have an incorrect delimiter

This allows RSA SPKI keys (typically delimited with PUBLIC KEY) to be parsed
even if they are using the RSA PUBLIC KEY delimiter.

* formatting

* use original error if nothing parses, don't let it parse non-RSA
2024-01-25 01:54:23 +00:00
Paul Kehrer
30e5ee2493
add some more EC vectors (#10134) 2024-01-05 18:03:57 +00:00
Alex Gaynor
e31a34398e
Another test case for explicit parameter private key (#10132) 2024-01-05 12:57:12 -03:00
Alex Gaynor
bbf2544c79
Added two test cases for unsupported EC private keys (#10126) 2024-01-05 07:19:16 -03:00
Alex Gaynor
6e106f5584
Update various links in the docs for permanent redirects (#10109) 2024-01-02 21:00:20 -03:00
Alex Gaynor
9e866cc50d
Update various links in the docs for permanent redirects (#10098) 2023-12-31 17:56:51 -03:00
Johnny Hsieh
91541cf726
Add support for GCM mode of SM4 cipher (#10072)
* Add support for SM4-GCM cipher

ref: #7503
ref: https://github.com/openssl/openssl/issues/13667

* Update SM4 GCM tests to use external test vector

* Cite SM4 test vectors sources in document

* Add tests for SM4ModeGCM finalize_with_tag

* Update CHANGELOG.rst
2023-12-29 10:56:29 -03:00
Alex Gaynor
c9578f28a1
Fixed a typo in test-vectors documentation (#10041) 2023-12-23 12:45:31 -03:00
Alex Gaynor
fb4c72c8bf
Added wycheproof vectors for pbkdf2 (#10024) 2023-12-21 08:30:36 -06:00
Paul Kehrer
d06a6a17cb
regenerate x509/custom/ca/ca.pem to expire in 2100 (#9964)
The existing cert doesn't expire until late 2038 but this simplifies
2038 checks for some downstream consumers. We shift the original
cert/key into a new pkcs12/ca directory so that we don't need to
regenerate all the PKCS12 vectors (which don't care about expiry anyway)
2023-12-05 09:21:37 -05:00
Facundo Tuesca
6359dc0e04
Add test vectors for AES-GCM-SIV (#9930) 2023-12-01 10:46:29 -06:00
Facundo Tuesca
b660044dce
Add test vectors for ChaCha20 counter overflow (#9221)
* Adapt ChaCha20 test vectors to 64-bit counter

* Add ChaCha20 test vectors for counter overflow

These vectors test the behavior during counter overflow. Since
different implementations use different counter sizes (e.g. OpenSSL
uses a 64-bit counter, whereas BoringSSL uses a 32-bit counter),
it's important to ensure that the behavior during counter overflow
is consistent between implementations.

These vectors take into account both 32-bit and 64-bit overflows.
2023-08-17 08:54:35 -05:00
Jean Paul Galea
caeafe6c4a
docs: fix broken link to https://ed25519.cr.yp.to/software.html (#9338) 2023-08-02 19:02:56 +12:00
Paul Kehrer
1b4bbea008
tolerate (with warning) invalid DSA params encoding in X.509 (#9271)
fixes #9253
2023-07-20 17:10:15 -04:00
jeanluc
1ca7adc97b
Fix encoding of SSH certs with critical options (#9208)
* Add tests for issue #9207

* Fix encoding of SSH certs with critical options

* Test unexpected additional values for crit opts/exts
2023-07-10 11:50:49 -05:00
Paul Kehrer
1355c2e460
tolerate NULL params in ECDSA SHA2 AlgorithmIdentifier (#9002)
* tolerate NULL params in ECDSA SHA2 AlgorithmIdentifier

Java 11 does this incorrectly. It was fixed in Java16+ and they are
planning to do a backport, but we'll need to tolerate this invalid
encoding for a while.

* test both inner and outer
2023-05-31 23:21:28 -04:00
Paul Kehrer
93c96b777a
allow null params in AlgorithmIdentifiers with SHA hash function OIDs (#8974)
RFC 4055 section 2.1 states "All implementations MUST accept both
NULL and absent parameters as legal and equivalent encodings".

It also makes some somewhat conflicting statements after that, but
LibreSSL omits the null params for PSS, and OpenSSL parses this
without issue so tolerance it is.
2023-05-27 10:07:20 -04:00
Alex Gaynor
5b7dd82561
Fix gitlab URLs for linkcheck (#8938) 2023-05-17 00:39:18 +00:00
Paul Kehrer
cfee3c85a7
add RSA PSS SHA1 hash algorithm + SHA1 MGF1 test vector (#8906) 2023-05-11 00:29:39 +00:00
Paul Kehrer
0f2b72bb12
invalid visible string support (#8884)
* invalid visible string support

this allows utf8 in visiblestring, which is not valid DER. we raise a
warning when this happens, but allow it since belgian eIDs, among
others, have encoding errors. Belgium fixed this by 2021 (and possibly
earlier), but their eID certificates have 10 year validity.

* review comments

* clippy
2023-05-07 16:01:33 +00:00
Paul Kehrer
9425d2376b
add one more RSA PSS invalid test vector (#8798) 2023-04-23 20:22:50 +00:00
Paul Kehrer
5f3871e4df
add two RSA PSS certificate vectors that have invalid encodings (#8797)
* add two RSA PSS certificate vectors that have invalid encodings

The signatures on these vectors are not valid.

* spelling
2023-04-23 19:51:35 +00:00
Paul Kehrer
45bddbfb19
add support for aes256-gcm@openssh.com decryption for SSH keys (#8738)
* add support for aes256-gcm@openssh.com decryption for SSH keys

* review feedback

* skip when bcrypt isn't present
2023-04-15 04:05:11 +00:00