Commit graph

2629 commits

Author SHA1 Message Date
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
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
Anton Hvornum
4c9ef892db
Corrected the documented intent of the HKDFExpand.derive() function so that it clearly states only expand is performed, and not extract and expand. (#12248) 2025-01-07 12:26:29 +00:00
MajorTanya
5f160b90fe
Update recommended PBKDF2HMAC iteration counts (#12243)
This uses the current (as of 2025-01-07) default of 1,000,000
iterations used by Django.
2025-01-07 04:42:29 +00:00
Alex Gaynor
96dbd56065
Bump year for copyright (#12219) 2025-01-01 07:05:07 +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
Brian Sipos
f6ee2a5106
Add RFC9174 OIDs (#12143)
* Add BUNDLE_SECURITY EKU

* Adding Other Name Form OIDs

* Adding public access to OtherNameFormOID

* Sorting names for lint

* Sort imports

* Fix format

* Adding OID docs

* Add specific next version
2024-12-13 19:17:50 +00:00
Alex Gaynor
ce4c5dfc23
test on centos stream 10 (#12145)
* test on centos stream 10

* Update ci.yml

* Update installation.rst
2024-12-13 08:19:33 -08: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
Alex Gaynor
6525eac13a
Use inline tabs in install docs (#12115) 2024-12-06 06:18:15 -08:00
Alex Gaynor
89422a5679
Adopt sphinx-inline-tabs (#12114)
Use it in one demo place to show how to install us with multiple installers
2024-12-06 05:40:49 -08: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
Oleg Höfling
74f262155d
chore: replace plaing hyperlinks to rfc sections with rfc roles with section argument (#11985)
Signed-off-by: oleg.hoefling <oleg.hoefling@gmail.com>
2024-11-17 08:33:49 -05:00
Oleg Höfling
120583a073
docs(admissions): add documentation for the admissions extension (#11964)
* docs: add intersphinx refs for the admission types

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

* chore: add types and description for the admissions fields and classes

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

---------

Signed-off-by: oleg.hoefling <oleg.hoefling@gmail.com>
2024-11-16 17:50:12 -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
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
Jiashuo Li
15e2125fb6
Update serialization.rst (#11746) 2024-10-10 12:52:25 +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
Alex Gaynor
06f3fdbfb3
fixed grammar in getting-started.rst (#11649) 2024-09-24 07:21:01 -07:00
Gonzalo Atienza
9c11549e2c
mac-docs-updates (#11644) 2024-09-22 21:23:47 -04:00
Gonzalo Atienza
184aa0fe4c
docs-chacha20-update (#11617) 2024-09-17 15:49:44 -04:00
Paul Kehrer
408b9f8a7a
argon2id test vectors (#11523) 2024-09-02 13:38:17 -04:00
Paul Kehrer
002419dcd6
properly document what key types raw works with (#11507) 2024-08-30 03:35:46 +00:00
Paul Kehrer
e4757c48ab
webstore.ansi.org is now behind cloudflare (#11477)
* webstore.ansi.org is now behind cloudflare

* CMU is also bad at certificates
2024-08-22 20:53:08 -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
Alex Gaynor
e6cf6cab99
fix preview ruff warning (#11435) 2024-08-15 09:45:08 -07: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
5f20b23dc6
Added additional notes to cert verification docs (#11380)
Closes #11376
2024-08-01 21:12:01 +00:00
DandyDrop
2c5664b93b
Update fernet.rst (#11335) 2024-07-22 18:40:21 +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
Facundo Tuesca
0faaffc2f5
Add support for encrypting S/MIME messages (#10889)
* 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-18 08:52:09 -07:00
Facundo Tuesca
783223f5f6
docs: Add instructions to build the docs (#11290)
* docs: Add instructions to build the docs

* docs: Fix single backticks

* docs: remove troubleshooting section

* Update docs/development/getting-started.rst

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

---------

Co-authored-by: Alex Gaynor <alex.gaynor@gmail.com>
2024-07-17 21:07:37 +00:00
Paul Kehrer
2b371f418b
add support for CipherContext.update_nonce (#10437)
* add support for CipherContext.reset_nonce

This only supports ChaCha20 and ciphers in CTR mode.

* expand tests to reset to different nonces
2024-07-05 18:54:12 -04:00
Daniel Lenski
8a7f27be3d
Add rsa_recover_private_exponent function (#11193)
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-05 15:14:04 -07:00
Magnus Watn
eae331491c
Add _utc datetime methods to x509.ocsp (#11183)
Fixes #11170.
2024-06-30 12:08:56 -04:00
Alex Gaynor
85fba50add
Remove buster from CI (#11182)
* Remove buster from CI

It is EOL

* Update installation.rst
2024-06-30 14:07:09 +03: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