Commit graph

2615 commits

Author SHA1 Message Date
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
Nathan Easton
73717542c4
Update reference.rst (#11137)
* Update reference.rst

This code snippet works when importing the extension oid

* Apply suggestions from code review

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

---------

Co-authored-by: Alex Gaynor <alex.gaynor@gmail.com>
2024-06-22 13:16:50 +00:00
Alex Gaynor
da45641e46
Convert PKCS7PaddingContext to Rust (#11089) 2024-06-10 12:22:36 -04:00
Paul Kehrer
5dc620daa4
document creating a CA hierarchy: root -> int -> ee (#11031)
* document creating a CA hierarchy: root -> int -> ee

* fix things
2024-05-27 13:00:44 +00:00
Dimitri Papadopoulos Orfanos
1ce23d008a
Fix more misspellings (#10933)
* Fix more misspellings

* Apply codespell suggestion: implementor → implementer

This is not exactly a misspelling, but:
* From Garner's Modern English Usage (4 ed.)
  	Although the variant spelling ✳implementor predominated for much of
  	the late 20th century, today implementer is considered standard.
* The Google Ngram Viewer shows a ratio of almost 10:1 in 2019.
2024-05-05 16:12:27 +00:00
Alex Gaynor
07642cfe48
Test on rolling for arm64 (#10897)
* Test on rolling for arm64

* Update installation.rst
2024-04-25 20:32:32 -07: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
368e3505d5
Document that we test with ubuntu 24.04 (#10831) 2024-04-16 07:40:29 -06:00
Paul Kehrer
126c144aee
Update testing docs (#10829) 2024-04-16 12:23:40 +00:00
Julien Castiaux
031d407e4d
Add public_key_algorithm_oid to certificate and CSR (#10517) 2024-03-27 14:32:35 -04:00
Alex Gaynor
e9954a0a31
fixes #10631 -- remove documentation for method that was removed (#10632)
* fixes #10631 -- remove documentation for method that was removed

* Update CHANGELOG.rst
2024-03-23 12:53:01 +00:00
Alex Gaynor
8436316862
Wycheproof lives under C2SP now (#10628) 2024-03-22 19:34:41 -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
dcf6ac240d
Updates for ruff 0.3.1 (#10548) 2024-03-07 10:57:37 -08: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