X509V3_EXT_nconf_nid/X509V3_EXT_nconf: Add validation checks for ML-DSA keyUsage certficate extension
According to the RFC 9881 Section 5 - Key Usage Bits, the following keyUsage extension values are not allowed for ML-DSA (ML-DSA-44, ML-DSA-65, ML-DSA-87).
https://www.rfc-editor.org/rfc/rfc9881.html#section-5
ML-DSA subject public keys cannot be used to establish keys or encrypt data, so the keyUsage extension MUST NOT have any of the following bits set:
- keyEncipherment
- dataEncipherment
- keyAgreement
- encipherOnly
- decipherOnly
However, it seems that the X509V3_EXT_nconf_nid and X509V3_EXT_nconf don't verify these prohibited values for ML-DSA keyUsage extension. I think these 2 functions need the logic to raise an error when any of the above 5 values are used for ML-DSA.
The values are defined in crypto/x509/v3_bitst.c - key_usage_type_table.
The X509V3_EXT_nconf_nid and X509V3_EXT_nconf are defined in crypto/x509/v3_conf.c.
I created the following reproducing C program reproducer.c using X509V3_EXT_nconf_nid. I ran the reproducer on the OpenSSL latest master branch 26d762a108e532bb0ca8d510e5d56ac9718dd02d.
https://github.com/junaruga/report-openssl-ml-dsa-key-usage-cert-ext
For example, related to the reproducer, I think the following X509V3_EXT_nconf_nid with prohibited values should return NULL as an error.
ext = X509V3_EXT_nconf_nid(NULL, &ctx, NID_key_usage, "digitalSignature,keyEncipherment,dataEncipherment,keyAgreement,encipherOnly,decipherOnly");Originally we faced this issue with Ruby OpenSSL library using X509V3_EXT_nconf.
I also couldn't find the manual documents about X509V3_EXT_nconf_nid and X509V3_EXT_nconf. Perhaps did you remove the documents?
Note unfortunately I don't have enough time to implement this, and send a PR right now. I hope you guys implement this.
What do you think?
Source: openssl/openssl