When constructing a PKCS#12 PFX with contentEncryptionAlgorithm: { name: "AES-GCM", length: 256 } for either PKCS8ShroudedKeyBag.makeInternalValues or AuthenticatedSafe.makeInternalValues, pkijs 3.4.0 emits the AlgorithmIdentifier with parameters absent (or NULL) instead of the required GCMParameters SEQUENCE. The resulting P12 file fails to import in openssl 3.5.5 with PKCS5_v2_PBE_keyivgen_ex: cipher parameter error.
RFC 5084 §3.2 requires:
GCMParameters ::= SEQUENCE {
aes-nonce OCTET STRING,
aes-ICVlen AES-GCM-ICVlen DEFAULT 12 }
AES-GCM-ICVlen ::= INTEGER (12 | 13 | 14 | 15 | 16)
in the parameters field of the AlgorithmIdentifier for any AES-GCM OID.
Reproducer
const pkijs = require("pkijs");
// ... build a PFX with:
await pfx.parsedValue.authenticatedSafe.parsedValue.safeContents[0]
.value.safeBags[0].bagValue.makeInternalValues({
password: passwordBuf,
contentEncryptionAlgorithm: { name: "AES-GCM", length: 256 },
hmacHashAlgorithm: "SHA-512",
iterationCount: 600000,
});
// ... then pipe pfx.toSchema().toBER() through:
// openssl pkcs12 -info -in client.p12 -passin pass:...
// → PKCS5_v2_PBE_keyivgen_ex: cipher parameter error
Same construction with { name: "AES-CBC", length: 256 } works correctly — the OCTET STRING IV that PBES2/AES-CBC expects matches what pkijs emits, but AES-GCM needs the GCMParameters SEQUENCE instead.
Related
When constructing a PKCS#12 PFX with
contentEncryptionAlgorithm: { name: "AES-GCM", length: 256 }for eitherPKCS8ShroudedKeyBag.makeInternalValuesorAuthenticatedSafe.makeInternalValues, pkijs 3.4.0 emits the AlgorithmIdentifier withparametersabsent (or NULL) instead of the requiredGCMParametersSEQUENCE. The resulting P12 file fails to import in openssl 3.5.5 withPKCS5_v2_PBE_keyivgen_ex: cipher parameter error.RFC 5084 §3.2 requires:
in the
parametersfield of the AlgorithmIdentifier for any AES-GCM OID.Reproducer
Same construction with
{ name: "AES-CBC", length: 256 }works correctly — the OCTET STRING IV that PBES2/AES-CBC expects matches what pkijs emits, but AES-GCM needs the GCMParameters SEQUENCE instead.Related
GCMParamsclass (RFC 5084 §3.2) and routing AES-GCM AlgorithmIdentifier emission through it on both the PBES2 and CMS code paths, with an OCTET-STRING legacy decrypt fallback so previously-produced pkijs output still decrypts.