-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PKCS#7 signing & verification - Certificate extension policies #12465
base: main
Are you sure you want to change the base?
Conversation
added tests accordingly
@alex wondering if there are best practices for certificates: better store it in |
Depends a bit on the use case. If you're verifying that we handle that certificate itself, it's better in vectors. If you're verifying something else either can work. |
OK, I'll go with storing it in vectors then. Mostly doing it for coverage. |
My excerpt from https://www.rfc-editor.org/rfc/rfc8550#section-4.4 would be:
Section 4.4.4 also discusses some limitations regarding certificates which may only be used for signing, but not for encryption - so maybe two separate policies (which would be quite similar) would be required? |
do not know if a CA policy is needed!
Hey, just pushed a first version of the constraints for certificates used as EE for email signing & verification.
I'd go for constraints linked to signing & verification for now, and address encryption / decryption later. I'm not sure For the constraints, I have no experience with them, I'll implement what seems right w.r.t. RFC 😄 Also, I've left empty the CA constraints, I'm not sure what to fill as of now. |
Not sure about the CA constraints either, from our company-certificate they include EMAIL_PROTECTION in EKU, but not sure if this is required. From this stackexchange-post I read that its application to ca-certificates is application-specific and not required by RFC. So for this use-case ignoring it in the CA might be the best thing (as long as other verifiers in cryptography do not have preference here). From my view (but without deep knowledge about cryptography-inner-works, so feel free to correct me) I change a few parts:
|
Totally agree with you @prauscher, for CA I'd either leave it as a For the changes, feel free to initiate a review, this is mostly draft as it blocks #12267. Good catches for the fixes, modifying the code now. And I totally agree with the |
Since this is specified in https://www.rfc-editor.org/rfc/rfc8550#section-4.4, I'll go with |
tests still to be implemented
First suggestions integrated, missing:
|
For the subjectAlternativeName constraint we probably need to receive the mail address as a parameter of def pkcs7_x509_extension_policies(mail_address: str):
[...]
def _validate_subject_alternative_name(policy, cert, san):
if san is None:
raise ValueError("Subject Alternative Name is required")
if mail_address.split("@")[0].isascii():
if mail_address.lower() not in [name.lower() for name in san.get_values_for_type(x509.RFC822Name)]:
raise ValueError(f"Subject Alternative Name does not contain RFC822Name {mail_address}")
else:
if mail_address.lower() not in [name.value.lower() for name in san.get_values_for_type(x509.OtherName) if name.type_id == x509.ObjectIdentifier("1.3.6.1.5.5.7.8.9")]:
raise ValueError(f"Subject Alternative Name does not contain OtherName {mail_address}") |
Thanks for the code! I'm unsure about specifying all the time an email address in the extension policy. To me, it seems a bit too restrictive (?). Moreover, it seems that there are things checked already in default EE policies in cryptography:
Due to this, I'll pass to To me, what we need to check from RFC 8550 is:
Also, checked RFC 5750 for S/MIME 3.2 (which we are currently supporting), and the differences are minor (such as the ASCII / non-ASCII differentiation). I suggest we go with RFC 8550 for that matter. Will push a nearly final version in the following hours 😄 |
added SAN checking (incomplete though)
As per #12267 and #12104, I'm opening this draft implementation of verification of PKCS#7 (S/MIME) certificates. Tests are not passing yet; still need to build an appropriate certificate for this.
The constraints I've gathered so far:
a PKCS#7/SMIME message) should not have ca=true in their basic
constraints extension.
@alex @woodruffw @prauscher feel free to add some more constraints, I'm not particularly familiar with CA verification.