digitalbazaar / forge

A native implementation of TLS in Javascript and tools to write crypto-based and network-heavy webapps
https://digitalbazaar.com/
Other
5.08k stars 785 forks source link

Reading valid p12 file gives Error: Only 8, 16, 24, or 32 bits supported #802

Open yug4ptc opened 4 years ago

yug4ptc commented 4 years ago
let p12buffer = fs.readFileSync('./wncsslp12/keyStore', 'binary');
const asn = forge.asn1.fromDer(p12buffer, false);

In above code input p12 file is valid p12 file. I can read it using pem package. the asn1.fromDer function not able to convert bytebuffer into DER format.

Error: Only 8, 16, 24, or 32 bits supported: 872
    at _checkBitsParam (c:\Certificates\node_modules\node-forge\lib\util.js:152:11)
    at ByteStringBuffer.util.ByteStringBuffer.getInt (c:\Certificates\node_modules\node-forge\lib\util.js:541:3)
    at _getValueLength (c:\Certificates\node_modules\node-forge\lib\asn1.js:396:20)
    at _fromDer (c:\Certificates\node_modules\node-forge\lib\asn1.js:481:16)
    at Object.asn1.fromDer (c:\Certificates\node_modules\node-forge\lib\asn1.js:448:10)
    at Object.<anonymous> (c:\Certificates\readp12.js:4:24)
    at Module._compile (internal/modules/cjs/loader.js:1138:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
    at Module.load (internal/modules/cjs/loader.js:986:32)
    at Function.Module._load (internal/modules/cjs/loader.js:879:14)
Process exited with code 1

keyStore.zip

edtsz commented 2 years ago

Nothing new about this issue? I'm getting the same error log with a pfx file. In my case the problem was a wrong password.