Skip to content

PKCS#12: AES-GCM PBES2 emits AlgorithmIdentifier without GCMParameters — openssl import fails #486

Description

@dotCooCoo

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions