PeculiarVentures / PKI.js

PKI.js is a pure JavaScript library implementing the formats that are used in PKI applications (signing, encryption, certificate requests, OCSP and TSP requests/responses). It is built on WebCrypto (Web Cryptography API) and requires no plug-ins.
http://pkijs.org
Other
1.25k stars 204 forks source link

Allow specifying salt size for better compatibility with Windows #300

Open ovk opened 3 years ago

ovk commented 3 years ago

I've been trying to get PKCS12/PFX file generated by the openSSLLikeInternal function from the PKCS12SimpleExample to work on Windows 10, and after some debugging it turned out that what was preventing it from working is the salt size.

When OpenSSL generates similar file (also with AES) it always sets salt size to 8, while PKI.js has it hard-coded to 64. So suprisingly enough, after changing 64 to 8 in CryptoEngine:

https://github.com/PeculiarVentures/PKI.js/blob/275992a9abd3da14ce02194594d3d59042826be6/src/CryptoEngine.js#L1842

the resulting PKCS12 file suddenly works in Windows.

This is clearly not a bug in the PKI.js, but rather in Windows. However, it would be really helpful if PKI.js would allow to specify this salt size, to make it possible to generate PKCS12 files that work on Windows.

Linking #211 as it is tangentially related.

pboguslawski commented 5 months ago

Same problem here with importing p12 file generated with pkijs 3.0.15 to Windows 10 and Windows 11. Tested that no such problem when

https://github.com/PeculiarVentures/PKI.js/blob/ace03e1c1f141d0c52da26360012e58ebe77932a/src/CryptoEngine/CryptoEngine.ts#L1573

is changed from 64 to 8 or 16 or 32.

OpenSSL 3.2+ changed salt from 8 to 16 bytes.

Please verify and consider reducing this salt length in pkijs from 64 to 32 or 16 bytes or making it configurable as proposed in this issue for Windows compatibility.