-
Notifications
You must be signed in to change notification settings - Fork 68
Description
Hello,
I'm currently looking into using rustls-webpki for one of my projects to validate a certificate chain. Upon reviewing the documentation, I identified the webpki::EndEntityCert::verify_for_usage
method to do the job and I was able to check my certificate chain and I found the library nice to use.
However, I wanted to give a (hopefully helpful) feedback regarding the EndEntityCert::verify_for_usage
method that I find a bit confusing. It caught my attention that the usage argument, which accepts a webpki::KeyUsage struct, is actually used by the method to check the Extended Key Usage 1, rather than the Key Usage2. Though this is clearly described in the documentation I found it a bit surprising.
The x509v3 format allows specifying "key usages" through both the x509v3 Key Usage and x509v3 Extended Key Usage extensions. The verify_for_usage
function can only check the latter but not the former. And I was unable to locate a function in the library to check for the key usage (against the " Key Usage" extension) on the resulting path -- if it existed one could simply provide it through a function passed via the verify_path argument. This leaves me unclear on how I am supposed to ensure that a key is used in compliance with the intended purposes stated in the Key Usage extension.
For a moment I thought that this might be because the Extended Key Usage extension when defined could override the Key Usage extension. However, RFC 5280 Section 4.2.1.12 on Extended Key Usage explicitly states:
If a certificate contains both a key usage extension and an extended key usage extension, then both extensions MUST be processed independently and the certificate MUST only be used for a purpose consistent with both extensions. If there is no purpose consistent with both extensions, then the certificate MUST NOT be used for any purpose.
So this is not the case and the key should only be used for purposes compatible with both extensions.
Given the above, I believe it would be better if rustls-webpki provided a way to check the Key Usage along with the check regarding the Extended Key Usage. But I might have missed something, so if there are specific reasons why webpki only checks the Extended Key Usage I'd be curious to know.
Best regards