Closed Bug 2079584 Opened 1 month ago Closed 2 days ago

Summary: CERT_CheckKeyUsage requires keyAgreement for ML-KEM keys, so an RFC 9935 ML-KEM certificate (keyEncipherment only) fails path validation for every usage

Categories

(NSS :: Libraries, defect, P3)

Tracking

(nss 3.134)

RESOLVED FIXED
Tracking Status
nss --- 3.134

People

(Reporter: rdisiena, Assigned: gtamvada-mozilla)

Details

Attachments

(1 file, 2 external files)

Attached file Archive.zip —

Steps to reproduce

RFC 9935 (ML-KEM in X.509) says an ML-KEM end-entity certificate's keyUsage asserts keyEncipherment and nothing else. NSS 3.130 refuses such a certificate for every certificate usage with SEC_ERROR_INADEQUATE_KEY_USAGE (-8102), in both the classic engine (CERT_VerifyCertificate) and libpkix (CERT_PKIXVerifyCert), while the same certificate re-issued with keyUsage keyAgreement instead validates. Every other library I have tried that validates ML-KEM leaves (OpenSSL 3.6, pyca/cryptography, Go, Bouncy Castle, Botan, AWS-LC, BoringSSL, OpenJDK) accepts the keyEncipherment form.

Cause (lib/cryptohi/seckey.c and lib/certdb/certdb.c, unchanged on master as of 2026-10-08): seckey_GetKeyType maps SEC_OID_ML_KEM_512/768/1024 to kyberKey, and CERT_CheckKeyUsage's switch on the key type adds KU_KEY_AGREEMENT to the required usage for kyberKey, as it does for dhKey. A KEM is not a key-agreement key: it is used by encapsulation, which RFC 9935 maps to keyEncipherment, as RSA key transport is.

Steps to reproduce (attachments: root.der, an ML-DSA-65 self-signed test root; leaf-keyEncipherment.der, an ML-KEM-768 leaf with keyUsage critical keyEncipherment, no EKU, per RFC 9935; leaf-keyAgreement.der, the same key and issuer with keyUsage keyAgreement instead):

certutil -N -d sql:db --empty-password
certutil -A -d sql:db -n root -t "C,C,C" -i root.der
vfychain -d sql:db -p  -u 1 leaf-keyEncipherment.der
vfychain -d sql:db -pp -u 1 leaf-keyEncipherment.der
vfychain -d sql:db -p  -u 5 leaf-keyEncipherment.der
vfychain -d sql:db -p  -u 1 leaf-keyAgreement.der

Actual results

Actual results:

Chain is bad!  PROBLEM WITH THE CERT CHAIN: CERT 0. CN=kem.example.test : ERROR -8102: Certificate key usage inadequate for attempted operation.
(the same for -pp, and for -u 5 email recipient, -u 0 SSL client, -u 12 IPsec)
leaf-keyAgreement.der:  Chain is good!

Expected results

Expected results: the keyEncipherment certificate validates for SSL server (-u 1) and email recipient (-u 5), the usages whose key-usage requirement is "key agreement or encipherment"; the keyAgreement one is the non-conformant form.

Suggested fix: in CERT_CheckKeyUsage, add KU_KEY_ENCIPHERMENT rather than KU_KEY_AGREEMENT for kyberKey (the ML-KEM OIDs). If pre-standard Kyber certificates with keyAgreement exist anywhere, accepting either bit for kyberKey would keep them working; RFC 9935 only permits keyEncipherment.

Found while cross-checking X.509 path validation across libraries with ML-KEM end-entity certificates built by several issuers (including NSS's own CERT_CreateCertificate). Happy to test a patch.

Assignee: nobody → gtamvada
Severity: -- → S3
Status: UNCONFIRMED → NEW
Ever confirmed: true
Priority: -- → P3

Hi rdisiena, thank you for the detailed bug report. Could you confirm the attached patch works?

Pushed by jschanck@mozilla.com:
https://hg.mozilla.org/projects/nss/rev/93bcfb6e7495
support ML-KEM end-entity keys in certutil. r=goutam

Status: NEW → RESOLVED
Closed: 2 days ago
Resolution: --- → FIXED
Status: RESOLVED → REOPENED
Resolution: FIXED → ---

Pushed by jschanck@mozilla.com:
https://hg.mozilla.org/projects/nss/rev/533422161f6d
ML-KEM certificates can only assert keyEncipherment. r=jschanck,nss-reviewers

Status: REOPENED → RESOLVED
Closed: 2 days ago → 2 days ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: