221 points · by ingve · 2y ago · 83 comments
While I'm a huge fan of formal methods for developing secure code, IMHO well developed suites such as x509-limbo[1] with common, good, problematic, and outright sadistically wrong vectors are the way forward for developing robust cross platform protocols. These are the kinds of unit tests a spec should come with.
[1] https://csrc.nist.gov/projects/pki-testing
EDIT If the authors are reading, are any of the test cases taken from Chrome's codebase?
I looked at NIST's PKITS while building the test suite. We ultimately decided to punt on it for the first round of tests, primarily because it fell slightly out of scope of our MVP on Python Cryptography (being strictly a RFC 3280 suite). We instead chose to integrate the BetterTLS suite[1] (warning: very large page) for the MVP.
With that being said: x509-limbo is open source, and I would be overjoyed if someone added a new `nist::pkits` or similar namespace for these :-). I can't promise that it's an immediate priority for us to add ourselves, however.
> are any of the test cases taken from Chrome's codebase?
Nope. That would also be a valuable thing to have here.
It's been a long time since I looked at them, not sure what's in there exactly any more. Ask Ryan perhaps :)
This could be game-changing for a lot of open source software.
I spent years avoiding X.509 (and ASN.1, for that matter) in my designs because every time someone I trust poked it, a remotely exploitable bug fell out. Most often, it was a Denial of Service issue rather than Remote Code Execution. Moving to Rust would demonstrably improve the security of the entire Internet.
You might be tempted to ask, "What about BouncyCastle?" (or similar queries).
Sure, you're not overwriting the EIP in most Java X.509 bugs, but check the release notes for X.509 and ASN.1 mentions: https://www.bouncycastle.org/releasenotes.html
When I worked for Amazon, we disclosed a few X.509-related vulnerabilities to projects that we almost found by accident.
they're logic bugs
My understanding is that Java doesn't allow this directly, but has adjacent historical deficiencies (e.g., not allowing exhaustive enumeration handling until recently).
Rust isn't just memory-safety. The type system also coaxes developers towards eliminating some types of logic bugs.
Not all, granted, but it does move the needle.
(and I say this as someone who grew up on SML)
... do absolutely nothing to fix denial of service attacks.
A recent example of this is CVE-2024-0567 in GnuTLS: an invariant that otherwise would likely have been noticed at the type level is instead checked with an assert, leading to a remotely trigger-able DoS.
The other details covered in the blog post, however, would absolutely do something to fix denial of service attacks.
To wit: x509-limbo
For the history: https://github.com/pyca/cryptography/issues/2381
That's not to say this is done! There's a set of features we still want to add and we'd like to gain some confidence in the APIs as structured before we mark them as stabilized.
Thanks to Trail of Bits for pulling this off.
'mcpherrim posted a comment below[1] with some additional information, including changes to the Web PKI and CRL distribution techniques that may eventually make them more useful.
CRL/OCSP (which are the only revocation mechanisms close to being generally used standards today) require either online verification (which is unsuitable or unsafe for many applications) or CRL distribution with CA trust root bundles, which is always in danger of being stale.
You can read more in https://en.wikipedia.org/wiki/Certificate_revocation_list#Pr..., https://en.wikipedia.org/wiki/Online_Certificate_Status_Prot...
Revocation in PKI is a hard problem that exposes a fundamental tradeoff between time to revoke and privacy/offline capability.
Curious about revocations though - the post doesn't mention it?
(This is consistent with Go's crypto/x509, which does not do revocation checking as part of the `Verify` API.)
What makes a path building implementation good is (IMO) its adherence to the rules Ryan Sleevi enumerates[1]: as long as you conceptualize the path building process as a dynamic search problem rather than a static one with a "single" result, any implementation you build will probably have the right "primitives" for future constraints (like revocations).
[1]: https://medium.com/@sleevi_/path-building-vs-path-verifying-...
* I shouldn't have to care where the certificates are stored. Just load the os default ones without asking me.
* I shouldn't have to know what a pem is, and I shouldn't have to open() one.
* I don't want a PolicyBuilder. Just give me the normal policy.
* I shouldn't have to construct some verifier object specific to a given dns. I don't want to verify a billion certificates for one domain, just one.
* I shouldn't have to know what an untrusted intermediary is.
Here's what I think it should look like
verifier = Verifier() # constructs a verifier with sensible defaults, overrides are possible though
verifier.verify(chain, "cryptography.io")> * I shouldn't have to know what a pem is, and I shouldn't have to open() one.
Agreed, but what you're requesting is separate from the work being discussed in this blog post, and both are actually compatible.
For the PHP community, we made Certainty - https://github.com/paragonie/certainty
You can just...
<?php
use ParagonIE\Certainty\RemoteFetch;
// cURL boilerplate
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
// Fetch the latest CACert bundle, verify its authenticity, save it locally
$fetcher = new RemoteFetch('/path/to/certainty/data');
$latestCACertBundle = $fetcher->getLatestBundle();
curl_setopt($ch, CURLOPT_CAINFO, $latestCACertBundle->getFilePath());
Writing a Python client should be relatively straightforward, should anyone want to.For Python specifically, there may be some value in storing the relevant PEM files into something like SigStore. That could be an easier proposal for the PyCA team to consider.
I wanted to bundle a chain of certs, check that the leaf was <some domain> and its key signed <some data>, and that the bundle provided a path to a locally-trusted root. This allows third-party serving of signed data, rather than having to trade your IP address for validation.
Doing so with existing tools was so terrible that I was pretty sure my result was grossly insecure :(
I look forward to the promised lower-level APIs!
1. Compatibility: PyCA Cryptography has strict compatibility requirements, including being able to build with older versions of Rust that crates like webpki and rustls-webpki may not be interested in supporting.
2. Generality: PyCA Cryptography is a general purpose cryptographic toolbox, and the plan for X.509 validation is not intrinsically linked to just the Web PKI profiles. In the future, they may wish to make their APIs more flexible than a strictly CABF validator would require, meaning that they would either need to carry patches against `webpki` or get such flexibility upstreamed (to the detriment of the crate's single purpose).
(I am not a maintainer of Cryptography; this is my understanding of the reasons as one of the implementors of this feature.)
I believe it also had various implementations under common API.