-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Getting Invalid keystore format (magic) #4
Comments
Hi @jor3l , I do not have any troubles with retrieving certs. I generated keystore using attached command and extract certs as following:
Here is an output: {
"alias": {
"cert": "-----BEGIN CERTIFICATE-----\nMIICvTCCAaWgAwIBAgIEf5uZ6DANBgkqhkiG9w0BAQsFADAPMQ0wCwYDVQQDEwRO\nQU1FMB4XDTIwMDgxODE3MTkwOFoXDTIwMTExNjE3MTkwOFowDzENMAsGA1UEAxME\nTkFNRTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAKM3T3J5sy/K77k2\nVVgL6wZceBfBltD0b3abgq4uNycP5nDCE2Xv8LuKzy7dO+xntQeFFt9nD6zrwEVA\ntwcOk3R/JareB9t+gdHl2tSMoUGpiwPRXiMjFxVimfIEC/jYkZMu/BWv8pbr19+a\nw78uA6pLRwB52guB0ic3oiKol91mGOKQkTyAkJwroNdsClE4KVlC+FULuZ2cxPMC\n4qjiFXN0AcVI1i6M7n0WQoUhB4YW/PTzc9NWi0U414kybkisA+NgW+gAtsuybIsv\nvbzodmIYg3TC7HIz2JHtY1eiPAj/pVlVBM//asKpaj6mQnWlk1ryUUCC4d1efAwK\nrP8RVNcCAwEAAaMhMB8wHQYDVR0OBBYEFCacO6WgMchlHuJJ2nTmRDzb6iL1MA0G\nCSqGSIb3DQEBCwUAA4IBAQANWhqIVzFI0N/PYl3kWOAdQk18k7R6SIdTNWrYzk1u\n5+7C5Q5i9O/oGsSEkT4ilIRmOF+BOUuUorADJgdQX02hRmY4QTqsnzYwUy9uSeJB\nasnfaNZVHE7WIbrQcVeMzGrOyvWJXv2L873912Opn4l1rUUEOdsGg1cTSQrXxfrw\nN7tdJyD9MwVfpnXGw5Aun9900layWiP9ofhcLzaclwK2jSf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iKJjWTWgIo2\neaR/9eA/MaiZtPBSvnYM9d9oYwKBgQC6ZPHOBxCEEbtzlQ6C7G6K2Rnaixe+kBZ5\nMPNOKg+BO3mtSIriyfM7mw3QhbexcW9cRM1P5+o8I69wPL6oCq43ziy3GzV9fAav\nX59JArdnKRUM3TprSjIoealn7+DJBgOXy+0Qizd3mFeufwpyZx7aI9B0MhxlMQzA\nEaWnj8yZ/QKBgQCzbhyIFyV9qk8lCEBiPs0gOuPl6xV4/ksOHzAGrm09J0g8aMi+\nY4WqealoUFwMap92moKYtcscLzfZkh0mlQ2Nsu6D5Vlkx7pOI1wrJpohyNXjm+dU\nfq/KMB4bVrXtxAO/UTz51pNKmxz9/YGkPRYJPtwyeSNFdWlwMff4Q86BlQKBgQCx\n4zjqmc9nW8z8aBsrVB3DoaKM8gY9NiJckx0BUh7uBScA+6ShAH+EOVybz6IaVNok\nwvz276yarKv4f+CtW1QdqkT+k5cfJUj0AlxwP4ltiMWwO0pPrsXj3wiQS1zKPVUc\nf+DF0zeiid/UhyYfPM8y/M8qtdBnusIiZDUmj5SCuQKBgH0BaA93dB2siZYkLjP6\nYrurNMpFsoW76H+m7HOd8eIXt0nGhBEAwgpAVjYKnAUAjQJPPZpTC5+zcxIyvDTN\n1FUR2nibUbZiFkh80U6CM97o6bl6C2DOzuc6cN2mOUUkRZ5DxKJj4VkwUnev5ZTj\nlN685SoYMbM7vbC2teIiESE5\n-----END PRIVATE KEY-----\n"
}
} could you provide the error the library throws? |
Very strange, this is the error I get, same code as yours, same command to create the jks. I'm on MAC, maybe it has something to do?
|
|
I see it is because of "Keystore type: PKCS12", currently the lib supports "Keystore type: jks". I'll see what I can do and update the issue |
I thought it had something to do with that but I'm not sure why my key is getting that type instead of jks, maybe is a Mac thing? |
Actually, I don't know, not sure it is related to Mac, probably the java version. As a solution you can use node-forge lib: const fs = require('fs');
const forge = require('node-forge');
const parse = (keystore, alias, password) => {
const p12Buffer = keystore.toString("base64");
const p12Der = forge.util.decode64(p12Buffer);
const p12Asn1 = forge.asn1.fromDer(p12Der);
const p12 = forge.pkcs12.pkcs12FromAsn1(p12Asn1, password || "");
const bags = p12.getBags({friendlyName: alias}).friendlyName;
const key = forge.pki.privateKeyToPem(bags[0].key);
const cert = forge.pki.certificateToPem(bags[1].cert);
return {
key: key.replace(/\r\n/g, '\n'),
cert: cert.replace(/\r\n/g, '\n')
};
};
const parsed = parse(
fs.readFileSync(__dirname + '/test.jks'),
'alias',
'password'
); |
Please, let me know if it helps |
Hi,
I'm trying to use this to consume SOAP but my generated jks does not work (giving me the error in the title), this is the command I used to generate the keystore:
keytool -genkey -alias alias -keypass password -keystore test.jks -storepass password -dname "cn=NAME" -keyalg RSA
Any idea why? Thanks!
The text was updated successfully, but these errors were encountered: