randombit / botan

Cryptography Toolkit
https://botan.randombit.net
BSD 2-Clause "Simplified" License
2.59k stars 570 forks source link

x509 module without sha1 dependency #2931

Open securitykernel opened 2 years ago

securitykernel commented 2 years ago

Our high-level goal is to be able to use the BSI module policy and additionally enable the tls module, but leave the sha1 module disabled. This is currently not possible, as tls depends on x509, which depends on sha1. From looking at the code, it seems the x509 module already handles non-existence of the sha1 module by throwing, e.g., at runtime in X509Cert::subject_public_key_bitstring_sha1(). This function seems to be used by Flatfile_Certificate_Store, which we could potentially replace. Also, ocsp relies on subject_public_key_bitstring_sha1(). Additionally, the CertificateStore interface and implementations rely on it via CertificateStore::find_cert_by_pubkey_sha1(), I am not sure what the consequences would be here.

Temporarily removing sha1 from x509's info.txt builds just fine, but unsurprisingly some tests fail:

$ ./configure.py --module-policy=bsi --enable-modules=tls
...
make check
...
Tests complete ran 171854 tests in 23.68 sec 129 tests failed (in ecdsa_unit ocsp x509_path_name_constraint x509_path_nist x509_path_rsa_pss x509_path_with_ocsp x509_path_x509test x509_v1_ca)

Probably we can replace most of the test certificates using SHA-1 with SHA-256 ones, that depends on the source. I will check these.

randombit commented 2 years ago

I think one issue is that OCSP relies on SHA-1 as a key identifier, though I don't recall the details at the moment.

Absolutely in favor of any changes which allow disabling SHA-1 in more configurations.

Possibly for OCSP we can use some different key identifier mechanism instead.

securitykernel commented 2 years ago

So from what I can see, the following things need to be done to fix the tests:

securitykernel commented 2 years ago

Re OCSP (via Feisty Duck TLS News):

The CA/Browser Forum has decided to deprecate the use of SHA-1 signatures in OCSP signing. SHA-1 signatures for certificates were deprecated in the web PKI a long time ago, but in OCSP they were still allowed. Some further discussion around this issue can be found in the bug tracker of the Go x509 module. The module’s developer, Filippo Valsorda, recently tried to disable SHA-1 signatures and had to re-enable them for OCSP.

randombit commented 2 years ago

It's not just the signatures either - IIRC, OCSP uses the SHA-1 of the certificate as a key identifier.

Oh, or looking at this code again, perhaps it just was "required" by the ecosystem at the time I wrote the OCSP code? It may be we can start using SHA-256 here, given that this comment dates back to 2012.