Skip to content

Commit 7430903

Browse files
authored
fix: install custom crypto engine before pkijs parseInternalValues (#44)
When a P12 file uses legacy encryption (3DES, RC2) for its safe contents, pkijs needs our custom CryptoEngine during parseInternalValues(). Previously, the engine was only installed lazily on first getCrypto() call in extractPrivateKey(), which runs after parseInternalValues(). This caused 'Unknown contentEncryptionAlgorithm: 1.2.840.113549.1.12.1.3' when a legacy P12 was the first one opened in a process. Our tests masked this because AES tests always ran first, installing the engine as a side effect.
1 parent 82e0767 commit 7430903

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/signatures/signers/p12.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ export class P12Signer implements Signer {
110110
options: P12SignerOptions = {},
111111
): Promise<P12Signer> {
112112
try {
113+
// Ensure our custom crypto engine is installed before any pkijs operations.
114+
// pkijs's parseInternalValues() uses the engine internally to decrypt safe
115+
// contents — if they use legacy algorithms (3DES, RC2), the default engine
116+
// will fail with "Unknown contentEncryptionAlgorithm".
117+
getCrypto();
118+
113119
// Ensure we have a proper ArrayBuffer (not SharedArrayBuffer)
114120
const buffer = toArrayBuffer(p12Bytes);
115121

0 commit comments

Comments
 (0)