summaryrefslogtreecommitdiff
path: root/src/OpenSSL/crypto.py
Commit message (Collapse)AuthorAgeFilesLines
* Drop CI for OpenSSL 1.0.2 (#953)Alex Gaynor2020-10-261-10/+2
| | | | | | | * Drop CI for OpenSSL 1.0.2 * Delete code for coverage reasons * Bump minimum cryptography version
* Fixing issue #798 (#907)jalberdi0042020-10-181-1/+4
| | | | | | * Fixing issue #798, thanks to @reaperhulk; removing undocumented '%s' option and getting the date in a more robust way Co-authored-by: Joseba Alberdi <j.alberdi@simuneatomistics.com> Co-authored-by: Alex Gaynor <alex.gaynor@gmail.com>
* Correct typos in crypto.py (#949)Felix Yan2020-10-141-2/+2
|
* crypto._PassphraseHelper: pass non-callable passphrase using callback (#947)Huw Jones2020-10-121-10/+9
| | | | | | | | | | | | * crypto._PassphraseHelper: pass non-callable passphrase using callback Fixes #945 Before this commit, we would pass a bytes passphrase as a null terminated string. This causes issue when a randomly generated key's first byte is null because OpenSSL rightly determines the key length is 0. This commit modifies the passphrase helper to pass the passphrase via the callback * Update changelog to document bug fix
* Allow using additional untrusted certificates for chain building in ↵Sándor Oroszi2020-10-121-2/+34
| | | | | | | | | | | | X509StoreContext (#948) The additional certificates provided in the new `chain` parameter will be untrusted but may be used to build the chain. This makes it easier to validate a certificate against a store which contains only root ca certificates, and the intermediates come from e.g. the same untrusted source as the certificate to be verified. Co-authored-by: Sandor Oroszi <sandor.oroszi@balabit.com>
* Allow using an OpenSSL hashed directory for verification in X509Store (#943)Sándor Oroszi2020-09-111-0/+48
| | | | | | | Add X509Store.load_locations() to set a CA bundle file and/or an OpenSSL- style hashed CA/CRL lookup directory, similar to the already existing SSL.Context.load_verify_locations(). Co-authored-by: Sandor Oroszi <sandor.oroszi@balabit.com>
* Switch to new notBefore/After APIs (#843)Rosen Penev2020-08-131-6/+6
| | | Signed-off-by: Rosen Penev <rosenp@gmail.com>
* Allow accessing a connection's verfied certificate chain (#894)Shane Harvey2020-08-051-1/+41
| | | | | | | | | | | | | | | | | | | | | | | | | * Allow accessing a connection's verfied certificate chain Add X509StoreContext.get_verified_chain using X509_STORE_CTX_get1_chain. Add Connection.get_verified_chain using SSL_get0_verified_chain if available (ie OpenSSL 1.1+) and X509StoreContext.get_verified_chain otherwise. Fixes #740. * TLSv1_METHOD -> SSLv23_METHOD * Use X509_up_ref instead of X509_dup * Add _openssl_assert where appropriate * SSL_get_peer_cert_chain should not be null * Reformat with black * Fix <OpenSSL.crypto.X509 object at 0x7fdbb59e8050> != <OpenSSL.crypto.X509 object at 0x7fdbb59daad0> * Add Changelog entry * Remove _add_chain
* Deprecated pkcs7 and pkcs12 support (#921)Alex Gaynor2020-08-051-1/+23
|
* Paint it Black by the Rolling Stones (#920)Alex Gaynor2020-07-231-97/+151
|
* Remove asserts (#904)Adrián Chaves2020-03-311-2/+2
|
* Fix PKey.check for some broken keys (#897)Mrmaxmeier2020-03-111-1/+1
| | | | | | | | | * fix PKey.check for some broken keys RSA_check_key is documented to return 1 for valid keys. It (currently) returns 0 or -1 for invalid ones. The previous code accepted invalid keys if RSA_check_key returns -1! * add test
* Make the code slightly resillient to python4 (#880)Alex Gaynor2019-11-181-2/+2
|
* Removed deprecated Type aliases (#814)Alex Gaynor2019-02-071-71/+0
| | | | | | | | | | | | * Removed deprecated Type aliases * typo * typo * missed this somehow * Line wrap
* Provide a valid digest option (#811)Wayne Werner2019-01-301-1/+1
| | | 2566 is not a valid digest, whoops!
* add key types consts (#776)Igr2019-01-211-0/+2
|
* Fixes incorrect rtype in documentation (#802)Gaurav Malhotra2019-01-211-2/+2
| | | | | rtype for the following was incorrect: X509Req.from_cryptography X509.from_cryptography
* Handle NULL bytes in get_components() values (#804)Romuald Brunet2019-01-211-5/+5
| | | | | | | | | | | * Handle NULL bytes in get_components() values Some old software may generate "bogus" CN with each character preceded by a NULL. This is already handled in commonName, but wasn't in get_components() * review fixes (fix py3 test & avoid unpack/cast)
* Update OpenSSL manpage link to x509v3_config (#789)Cyril Stoller2018-08-271-1/+1
|
* Add note on zero-based certificate version value (#790)Cyril Stoller2018-08-271-1/+2
|
* X509Store.add_cert no longer raises an error on duplicate cert (#787)Paul Kehrer2018-08-231-1/+10
| | | | | | * X509Store.add_cert no longer raises an error on duplicate cert * move changelog entry
* Only allocate exponent in the TYPE_RSA path. (#767)David Benjamin2018-06-051-5/+5
| | | Not much point in making it otherwise.
* Use autofocus for all module documentation/docstrings (#737)Alex Chan2018-02-151-12/+28
| | | | | | | | * Use autodoc for OpenSSL.crypto * Use autodoc for the SSL.Context class * Use autodoc for SSL.Connection
* fix a memory leak and a potential UAF and also #722 (#723)Paul Kehrer2017-11-301-4/+3
| | | | | | | | * fix a memory leak and a potential UAF and also #722 * sanity check * bump cryptography minimum version, add changelog
* define __all__ to make wildcard import work (#719)Nicolas Karolak2017-11-261-0/+39
|
* Don't use things after they're freed...duh (#709)Alex Gaynor2017-11-201-9/+36
| | | | | | | | * Don't use things after they're freed...duh * changelog * more details
* Avoid a double call to X509_STORE_CTX_init as it leaks memory (#691)Jeremy Cline2017-09-141-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This fixes an issue where each instance of ``X509StoreContext`` would leak a small amount of memory, but only if ``verify_certificate`` was called. The reason for this is that ``X509_STORE_CTX_init`` is called in ``X509StoreContext.__init__`` and at the start of ``X509StoreContext.verify_certificate``. According to the man page for ``X509_STORE_CTX_init``: "X509_STORE_CTX_init() sets up ctx for a subsequent verification operation. It must be called before each call to X509_verify_cert(), i.e. a ctx is only good for one call to X509_verify_cert(); if you want to verify a second certificate with the same ctx then you must call X509_STORE_CTX_cleanup() and then X509_STORE_CTX_init() again before the second call to X509_verify_cert()." Prior to this commit, the following script would cause a memory leak: ``` from OpenSSL.crypto import ( X509Store, X509StoreContext, load_certificate, FILETYPE_PEM) certificate = """ -----BEGIN CERTIFICATE----- MIIESTCCA7KgAwIBAgIBAzANBgkqhkiG9w0BAQUFAD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sHZtM 8rqii/Y2PPF5PbpgVjJLYsJk4SSv84aH+VPYcaEtYlPClXgHb3J9jgAxgHBHkJMQ 7mvxiIau7frKFqmJGZkxO2M+Sv8eLCKLJP8CAwEAAaOCAQkwggEFMB0GA1UdDgQW BBQAmKXV58RVDoSjZ/5mShbgBBXdITCB1QYDVR0jBIHNMIHKgBQAmKXV58RVDoSj Z/5mShbgBBXdIaGBpqSBozCBoDELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAk5DMRAw DgYDVQQHEwdSYWxlaWdoMRcwFQYDVQQKEw5GZWRvcmEgUHJvamVjdDEPMA0GA1UE CxMGZmVkbXNnMQ8wDQYDVQQDEwZmZWRtc2cxDzANBgNVBCkTBmZlZG1zZzEmMCQG CSqGSIb3DQEJARYXYWRtaW5AZmVkb3JhcHJvamVjdC5vcmeCCQCO6yjYqROdfDAM BgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBBQUAA4GBAN5r+1rbeTyGDdlelbqWOXBu uS0a9BfusO0uwf3tHK9zeB5CDKFgxdfSZ+Fxg1w2HFRHhCOYoZ2ASPfbyANTzxUF fVAId1uhBD1SlhXpTb3Ndo4uXfalf3W8MrQzFiVHbevvfsyd+RwoVT/PDokE3i4A fftCd0uwvSqVgyE28SFt -----END CERTIFICATE----- """ ca_cert = load_certificate(FILETYPE_PEM, ca_certificate) cert = load_certificate(FILETYPE_PEM, certificate) cert_store = X509Store() cert_store.add_cert(ca_cert) while True: cert_store_context = X509StoreContext(cert_store, cert) cert_store_context.verify_certificate() ``` Moving the creation of ``X509StoreContext`` outside the loop stops the memory leak. Signed-off-by: Jeremy Cline <jeremy@jcline.org>
* Provide a destructor for the CRL object (#690)Jeremy Cline2017-09-071-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | This frees the memory allocated for the CRL object. Prior to this commit, the following script would leak memory: ``` from OpenSSL.crypto import load_crl, FILETYPE_PEM crl = """ -----BEGIN X509 CRL----- MIIBfDCB5jANBgkqhkiG9w0BAQsFADCBoDELMAkGA1UEBhMCVVMxCzAJBgNVBAgT Ak5DMRAwDgYDVQQHEwdSYWxlaWdoMRcwFQYDVQQKEw5GZWRvcmEgUHJvamVjdDEP MA0GA1UECxMGZmVkbXNnMQ8wDQYDVQQDEwZmZWRtc2cxDzANBgNVBCkTBmZlZG1z ZzEmMCQGCSqGSIb3DQEJARYXYWRtaW5AZmVkb3JhcHJvamVjdC5vcmcXDTE3MDYx NTIxMDMwOFoXDTM3MDYxMDIxMDMwOFowFDASAgECFw0xMjA3MTUyMTE4NTJaMA0G CSqGSIb3DQEBCwUAA4GBAGOBuDxmRFNcYP71LBsCOfFzKij00qpxM01d5/G6+0kM WJT8oTajMQoY6oISvQDq6TkwEoKc1yl6Ld1/XTtCNOhbybzRBAVf/Lxi/nRPP1JO qOdZs5jMLLQq1mRJz+MgKHHTDlnvpbjHMuyTss1RblFDr4iZPHMcBNKPGIj3pmpA -----END X509 CRL----- """ for _ in range(0, 1000000): load_crl(FILETYPE_PEM, crl) ``` Signed-off-by: Jeremy Cline <jeremy@jcline.org>
* (EC)DSA signature fix (#670)Paul Kehrer2017-07-201-3/+4
| | | | | | | | | | | | | * Write a test - signatures with EC keys (#609) * Ask for signature length before allocating a buffer. This fixes a potential heap buffer overflow that may happen when a signature is longer than the private key, as with X9.62 ECDSA (#609). * change approach to EVP_PKEY_size and add changelog * add a small assert
* Removed the deprecated md5 default on CRL.export() (#652)Alex Gaynor2017-06-301-8/+1
| | | | | | | | | | | | | | * Removed the deprecated md5 default on CRL.export() * Doh * unused import * fixed tests * last one * py3k!!!!!
* Kill some commented out code and other cleanups (#649)Alex Gaynor2017-06-301-17/+3
|
* dump_privatekey with FILETYPE_TEXT only supports RSA keys (#646)Paul Kehrer2017-06-291-0/+6
| | | | | | | | * dump_privatekey with FILETYPE_TEXT only supports RSA keys FILETYPE_TEXT is terrible but everyone hold their nose * also verify it's a pkey
* add to_cryptography/from_cryptography on CRL and X509Req (#645)Paul Kehrer2017-06-291-0/+66
| | | | | | * add to_cryptography/from_cryptography on CRL and X509Req * add changelog entry
* Fixed #486 -- deprecate the backwards compat names (#643)Alex Gaynor2017-06-291-10/+51
| | | | | | | | * Fixed #486 -- deprecate the backwards compat names * remove the docs for these, pretend they don't exist * CHANGELOG
* Added an API for converting X509 to/from cryptography (#640)Alex Gaynor2017-06-251-0/+32
| | | | | | * Added an API for converting X509 to/from cryptography * changelog
* update docs and and changelog for #612 (#639)Paul Kehrer2017-06-211-20/+8
| | | | | | | | * update docs and and changelog for #612 * update changelog * more detail
* Fix invalid cast from ASN1_TIME to ASN1_GENERALIZEDTIME (#612)Moriyoshi Koizumi2017-06-211-11/+3
| | | | | | * Fix invalid cast from ASN1_TIME to ASN1_GENERALIZEDTIME, which ends up with an error with LibreSSL. * Require cryptography >= 1.9
* Use the normal OpenSSL function instead of the crypto wrapper (#629)Alex Gaynor2017-05-311-1/+1
| | | We don’t support 0.9.8 anymore.
* Remove code for checking if EC support is present (#616)Alex Chan2017-04-201-11/+9
|
* Prepare for 17.0.0 (#615)Hynek Schlawack2017-04-201-1/+1
| | | | | | | | * Prepare for 17.0.0 Fix a bunch URLs and account for the non-existance of 16.3. * Fix codecov link
* Fix broken links in the documentation (#611)Alex Chan2017-03-211-2/+2
| | | | | | * Fix broken link described in #610 * Fix two other broken links
* Prevent _PassphraseHelper.raise_if_problem() from eating exceptions (#581)Greg Bowser2017-01-251-6/+8
| | | | | | | | | | | | | | | | | | | | | | | * Modify tests to detect empty crypto.Errors from load_privatekey This reproduces #119 and #456. * Prevent _PassphraseHelper.raise_if_problem() from eating exceptions. This resolves #119, resolves #456. `_PassphraseHelper.raise_if_problem()` always flushes the OpenSSL exception queue, but does not always raise an exception. In some cases, other code attempts to raise an error from OpenSSL after `raise_if_problem()` has flushed the queue, thus causing an empty exception to be raised (i.e. `raise Error([])`). This commit modifies `_PassphraseHelper.raise_if_problem` to flush the OpenSSL error queue only if it has en exception to raise. Subsequent code that detects an error should now be able to raise an non-empty exception. * Add CHANGELOG entry for #581.
* Activate intersphinx (#583)Hynek Schlawack2016-12-111-14/+20
| | | | | | | | | | | * Activate intersphinx That adds links to CPython docs and cryptography. Also let the copyright at 2001 which seems to be just fine and gives us reproducible builds. * Appease docs builder
* Add the ability to set a custom verification time on X509Store (#567)Thomas Sileo2016-11-221-0/+22
|
* Clarify error message (#573)Hynek Schlawack2016-11-181-2/+6
|
* Convert X509ExtTests to use pytest-style tests (#564)Alex Chan2016-11-181-0/+3
|
* Prepare 16.2.0 (#555)16.2.0Hynek Schlawack2016-10-151-1/+1
| | | | | | | | * Add empty line to CHANGELOG so extraction works * Fix a bunch of links * Prepare 16.2.0
* move our cryptography backend import (#552)Paul Kehrer2016-10-061-1/+13
| | | sad trombone
* Test on OpenSSL 1.1.0 with travis. Fixes #524 (#526)Alex Gaynor2016-09-241-0/+2
|
* fix cffi warnings for proper buffer types (#545)Paul Kehrer2016-09-201-1/+1
|