Commit graph

2538 commits

Author SHA1 Message Date
Alex Gaynor
9d2f41cfa2
fix test case, used wrong vector (#12405) 2025-02-05 20:35:32 -08:00
Alex Gaynor
3d4eb5f7a4
Added a test for RC2-CBC with an effectiveKeyLength (#12404)
* Added a test for RC2-CBC with an effectiveKeyLength

* Update docs/development/test-vectors.rst

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

---------

Co-authored-by: Paul Kehrer <paul.l.kehrer@gmail.com>
2025-02-06 00:52:22 +00:00
Alex Gaynor
7fb6b880d7
Test cases for our new PKCS#8 test vectors (#12401) 2025-02-05 14:11:09 -08:00
Ivan Desiatov
4f9ca1c92c
PyPolicyDefinition and related Verifier API changes (#12390)
* Add PyPolicyDefinition, make accessible via verifiers.

* Add python Policy to x509.pyi

* Expose PyPolicyDefinition to Python.

* Rename PyPolicyDefinition to PyPolicy to match python name.

* `test_verification` uses `policy` property.

* Add additional PyPolicy tests.

* Add back direct getters on verifiers with deprecation warnings.

* Correct Policy.subject return type in x509.pyi

* Rename x509.verify.py_policy module to x509.verify.policy

* x509.verify uses mod.rs convention

* Use Optional<SubjectOwner> instead of adding None value to SubjectOwner.

* PyPolicy stores original subject + naming changes in Verifiers.
2025-02-05 12:46:43 -08:00
Paul Kehrer
0ef7c1fa19
add XOFHash (#12380)
* add XOFHash

* refactors for comments

* use cfg_if

* fix docs, fix linting

* don't expose squeeze on unsupported things

* smaller strides

* ellipsis
2025-02-01 17:26:59 -08:00
Paul Kehrer
d20eea8809
raise ValueError if DH parameter numbers are invalid (#12373) 2025-01-31 23:34:21 +00:00
Alex Gaynor
9b59bb671e
Emit warnings on BER PKCS#7 and PKCS#12 (#12372)
* Emit warnings on BER PKCS#7 and PKCS#12

* Update src/rust/src/pkcs7.rs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-01-31 15:14:42 -08:00
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
11b15a309f
fixes #10808 -- allow empty plaintexts for aes-gcm-siv (#12355)
* fixes #10808 -- allow empty plaintexts for aes-gcm-siv

* Update src/rust/build.rs

Co-authored-by: Nick Pope <nick@nickpope.me.uk>

---------

Co-authored-by: Nick Pope <nick@nickpope.me.uk>
2025-01-29 12:21:40 -08:00
Alex Gaynor
ad65dc5231
Provide a password for encryption tests (#12347)
It's never used, because of malformations, but provide one.
2025-01-27 06:39:53 -08:00
Alex Gaynor
652867baaa
fixes #12307 -- added unsafe_skip_rsa_key_validation kwarg to ssh private key loading (#12342) 2025-01-25 17:29:54 +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
2fe2b5a19f
Support AES-GCM-SIV on BoringSSL (#12294) 2025-01-19 07:55:20 -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
Alex Gaynor
da62c2fce7
fixes #12070 -- made SSH private key loading more consistent with other key loading (#12286) 2025-01-15 09:25:43 -07:00
Hanno Böck
e818efc0b5
Reject d, e values <= 1 (#12272)
* Reject d, e values <= 1

This avoids a potential infinite loop (e.g. with d=e=1 or d=e=-1).

* Add tests for possible loop/DoS in rsa_recover_prime_factors()
2025-01-12 16:58:03 -05:00
Alex Gaynor
d7596d0f1f
fixes #12257 -- raise the correct error on an unsupported curve (#12271) 2025-01-11 18:35:46 -08:00
Alex Gaynor
4c8aa4e3b5
Bump to ruff 0.9 (#12259) 2025-01-09 11:44:10 -08:00
Alex Gaynor
8640c1a0fc
Implement fixes to ruff check --preview (#12230) 2025-01-03 17:28:57 +01: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
David Buchanan
4879672702
Add ec.EllipticCurve group_order constants (#12113)
* add ec.EllipticCurve group_order

* punctuation

* update docs
2024-12-10 08:10:36 +03:00
Patrick Rauscher
738598d1cf
make x509.name.NameAttribute use Generic to overload get_attributes_for_oid (#12068)
* make x509.name.NameAttribute use Generic to overload get_attributes_for_oid

* reformat code using ruff format (not only ruff check)

* use subtypes of ObjectIdentifier to allow type detection in get_attributes_for_oid

* add missing overloads for test cases

* revert most changes to achieve base plate

* ruff format

* try typing.Union for python 3.9

* add return_string to get_attributes_for_oid for overload

* fix documentation link and flake8

* fixup docs

* docs: add versionadded for param return_string

* add test case

* Revert "add return_string to get_attributes_for_oid for overload"

This reverts commit c4a2a5f0273ea8e60f3d5425a015b0563586b67a.

* Revert "fix documentation link and flake8"

This reverts commit b79a4ecf73f1425bd9304aefd2eaf8a89329610b.

* make NameAttributeValueType covariant
2024-12-06 22:23:28 -05:00
Joakim Nordling
43d84b1121
Support for copying private keys (#12110)
* Add tests

* Implement __copy__ in private keys

* Fix issue with tests for DHPrivateKey

* Another attempt at fixing the tests

* Revert "Another attempt at fixing the tests"

This reverts commit cc7c2b301e635baa7b958dc1b02666f1c80c7c36.

* Skip tests with weak key on FIPS

* Add __copy__ to abstract base classes of both public and private keys
2024-12-06 11:14:14 -05:00
Paul Kehrer
d49947efb0
handle case where a "valid" pkey does not contain a valid EC key (#12101)
* handle case where a "valid" pkey does not contain a valid EC key

* add test

* skip the test in some scenarios
2024-12-05 05:24:04 +00: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
Alex Gaynor
a1057fda9d
fixes #12062 -- raise a clean error when loading an SK SSH private key (#12063) 2024-11-28 12:19:28 -08: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
Alex Gaynor
8209d63ae7
fixes #11944 -- don't panic on attributes with no values (#11947) 2024-11-14 14:16:43 -08:00
Paul Kehrer
a7aa8cec96
argon2id support (#11524)
* argon2id support

* make it all rust now

* set a threadpool number

* address comments

* set threadpool to max(available, current)

* review comments

* a few more improvements

* Update docs/hazmat/primitives/key-derivation-functions.rst

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

---------

Co-authored-by: Alex Gaynor <alex.gaynor@gmail.com>
2024-11-11 14:42:26 +00: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
Hanno Böck
78e89e4975
Speedup rsa_recover_prime_factors() by using random value (#11899)
* Speedup rsa_recover_prime_factors() by using random value

* Comply with ruff codingstyle

* Reject invalid combinations of n, d, e early to avoid excessive runtime

* Add second failure test case for rsa_recover_prime_factors to hit early error path

* Remove leftover debug code

* Reduce _MAX_RECOVERY_ATTEMPTS and remove obsolete comment

Previously, the code would increase a in steps of 2, therefore,
_MAX_RECOVERY_ATTEMPTS was twice the number of tries. With the new
code, this is no longer the case.
2024-11-10 14:34:58 +00:00
Alex Gaynor
31d9e01b36
fixes #11912 -- when checking ccm decrypt max length, exclude tag (#11913) 2024-11-08 08:36:33 +00:00
Oleg Höfling
53035da3dd
feat(admissions): implement encoding of admissions extension (#11892)
* feat: implement encoding of admissions extension

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

* chore: add encoding tests

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

* refactor: split encoding of inner objects into separate functions

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

* fix: simplify code comment to pass the line length checks

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

* chore: add test to check encoding of none values

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

* chore: extend none values test to also check encoding of naming authority with none values

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

* fix: use none checks when converting python data

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

* fix: raise a valueerror if the url can not be encoded to an ia5string

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

* chore: revert to truthness check for py_oids for now, will be amended in a separate pr

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

* fix: raise a valueerror if the registration_number can not be encoded to a printablestring

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

* fix: encode none for profession_oids if profession_oids is none

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

---------

Signed-off-by: oleg.hoefling <oleg.hoefling@gmail.com>
2024-11-06 23:41:29 -05:00
Oleg Höfling
81d98f4457
fix(admissions): allow profession_oids field being none (#11908)
* fix: allow profession_oids to be none

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

* chore: provide explicit type hints for profession oids in hash calculation

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

* chore: remove unused ignore in profession info init test

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

* fix(profession info): simplify profession oids handling in hash calculation

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

---------

Signed-off-by: oleg.hoefling <oleg.hoefling@gmail.com>
2024-11-06 18:38:20 -05:00
Alex Gaynor
7a7f916e03
fixes #11160 -- include the cert in the error message for verification error (#11898) 2024-11-06 09:50:30 +00:00
Oleg Höfling
cf93084b0e
feat(admissions): add admissions extension type (#11886)
* feat(admissions): add admissions extension type

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

* fix: use tuple for admissions unpacking in hash code calculation

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

---------

Signed-off-by: Oleg Hoefling <oleg.hoefling@gmail.com>
2024-11-04 06:42:08 -05:00
Oleg Höfling
4d86913082
feat(admissions): add admission type for the admissions extension (#11883)
* feat(admissions): add admission type for the admissions extension

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

* refactor: explicitly convert profession infos to tuples for hash calculation

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

* refactor: add asn1 trait derives to admission type, commented out

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-03 17:12:39 -05:00
Oleg Höfling
f65ab4d7f5
feat(admissions): add profession info type for the admissions extension (#11881)
* feat(admissions): add profession info python type for the admissions extension

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

* feat(admissions): add profession info rust type for the admissions extension

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

* feat(admissions): add test for profession info hash implementation

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

* fix(admissions): minor fixes

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

* remove the asn1 traits from the profession info rust type

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

* remove the explicit mark from the naming authority field

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

* chore: add commented out annotation for the naming authority field

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

* fix: use correct type for add_profeccion_info field

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

* refactor: explicitly convert profession items and oids to tuples for hash calculation

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

* refactor: add asn1 trait derives to naming authority and profession info types, commented out

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-03 20:16:23 +00:00
Oleg Höfling
09dfc983a4
feat(admissions): add naming authority type for the admissions extension (#11876)
* feat(admissions): add naming authority python type for the admissions extension

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

* feat(admissions): user short names for naming authority fields

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

* feat(admissions): add naming authority rust type for the admissions extension

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

* chore: use assert_eq macro for value comparison in naming authority test

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

* chore: drop useless test for naming authority rust type

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

* fix: correct the naming authority text type

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

---------

Signed-off-by: oleg.hoefling <oleg.hoefling@gmail.com>
2024-11-03 14:49:47 +00:00
Alex Gaynor
62f1155062
fixes #11878 -- check for keys too large when deriving an EC key from a private value (#11879) 2024-11-03 14:33:28 +00:00
Robby Cornelissen
7fa390cfe2
Support 128-bit OID arcs (#11820)
* Support 128-bit OID arcs

* Update Cargo.lock to reflect updated rust-asn1 dependency
2024-10-24 04:36:14 +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
Han Yu
6bd5d49899
Inconsistent IDP extension constraint check (#11467)
* Per RFC5280 Section 5.2.5, the Issuing Distribution Point extension in a CRL can have only one of onlyContainsUserCerts, onlyContainsCACerts, onlyContainsAttributeCerts set to TRUE. However, extensions.py (lines 1991 : 2003), indirectCRL is also included, which leads to invalid CRL even if the RFC requirement is met. The proposed fix is to drop indirectCRL from the check so it conforms to the RFC.

* Made the comment shorter per line to meet the format requirement.
Removed a invalid test case for IDP
2024-10-12 01:43:23 +00:00
Ivan Desiatov
1767ad0a46
X509 custom verification groundwork (#11559)
* Add CustomPolicyBuilder foundation.

* Add EKU getters to ClientVerifier and ServerVerifier.

* Document the implemented part of custom verification.

* Remove `subject` field from VerifiedClient, rename `sans` back to `subjects`.

* Remove EKU-related setters, getters and documentation from this PR.

* Use double backticks in reStructuredText.

* Remove CustomPolicyBuilder in favor of extending PolicyBuilder.

* Code style improvements.

* Resolve coverage issues.
2024-10-08 22:27:15 -04:00
Gonzalo Atienza
6fbdffed71
otp-generage-hardening (#11703) 2024-10-07 00:57:57 +00:00