-
-
Notifications
You must be signed in to change notification settings - Fork 34
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
Unable to fetch certificate #88
Comments
Hello! As I can see from your steps you don't import certificate to SoftHSM. You use PKCS#8 which is private key and import it to SoftHSM Eech SessionObject has There is another npm module which allows to use PKCS#11 tokens easier node-webcrypto-p11 you can get list of allowed keys or certificates by using |
@microshine Thanks for the quick response! 😄 Regarding node-webcrypto-p11, I was a bit worried when I saw this https://www.npmjs.com/package/node-webcrypto-p11#warning Question 1: Is there a way to get the certificate contents via only graphene? Also regarding your comment:
Question 2: Do you mean according to my steps, I forgot to import the certificate to SoftHSM (I thought I did in step 2 😉 )? Or do you mean, I shouldn't use SoftHSM to import the certificate? Follow-up question (that's more about the use of SoftHSM 😅 ): Question 3: Is there a way to import a certificate using |
1You can use this example. I use filter for find function. var graphene = require("graphene-pk11");
const lib = "/usr/local/lib/softhsm/libsofthsm2.so";
const mod = graphene.Module.load(lib, "LIB");
mod.initialize();
try {
const slot = mod.getSlots(0);
const session = slot.open(4);
const objects = session.find({class: graphene.ObjectClass.CERTIFICATE});
for (let i=0; i<objects.length; i++) {
const cert = objects.items(i).toType();
console.log(cert.value.toString("hex"));
}
} catch (e) {
console.error(e);
}
mod.finalize(); 2You use
As I can see it's private key. I don't see openssl certificate creation and cert.pem file importing 3It looks you cannot use softhsm2-util to import certificate
You can use |
@microshine 😄 Thanks again for the quick response! I've tried several things since yesterday, but I still can't find a way to see my private certificate contents in plain text 😞
Output:
...I'm not sure why Am I completely on the wrong path here? I just want to be able to securely store a private key in my HSM and use a node module to fetch the private key in plain text for use in my node app |
It's not secure to put private key to HSM and then export it as plain text. May I ask you? What are you using for exported private key? Maybe I can suggest you another way Otherwise I can write example how to export private key from KeyStorage |
Mainstream HSMs do not support clear text export of private keys. I think there must be some confusion here. |
I'd love to see an example on how to export private key from KeyStorage! 😃 I have a pretty simple use case - I just want to store my private keys on an HSM and access those private keys using a node module when creating my https node server (https://nodejs.org/api/https.html#https_https_createserver_options_requestlistener) |
I see. You need PKCS#8 private key // @ts-check
const { WebCrypto } = require("node-webcrypto-p11");
const crypto = new WebCrypto({
library: '/usr/local/lib/softhsm/libsofthsm2.so',
slot: 0,
readWrite: true,
pin: "12345", // you need login to get private objects
});
async function main() {
if (crypto.isLoggedIn) {
crypto.login("12345"); // you need login to get private objects
}
const indexes = await crypto.keyStorage.keys();
let privateKey;
for(const index of indexes) {
const parts = index.split("-");
if (parts[0] === "private") {
privateKey = await crypto.keyStorage.getItem(index);
break;
}
}
if (privateKey) {
// NOTE: You can export only exportable private key
const raw = await crypto.subtle.exportKey("pkcs8", privateKey);
const bufRaw = new Buffer(raw);
console.log(bufRaw.toString("hex"));
} else {
console.log("Private key is not found");
}
}
main()
.catch((err) => {
console.error(err);
}) |
|
Thanks for all the support so far, @microshine and @rmhrisk 😸 I think I'm asking for the impossible here 😆 I just opened up another ticket at nodejs (nodejs/help#964) now that I'm a bit more knowledgeable about the actual functionality of an HSM, but I'm doubtful regarding any positive response there |
Re:
HSMs are used most commonly when keys live cradle to grave in the HSM. |
FYI: Node crypto is a just a thin layer ontop of OpenSSL. It is possible to have node honor your OpenSSL configuration file when doing crypto, specifically with TLS. It is possible to specify a "OpenSSL engine module" in your configuration. You can usually get your HSM to be loaded in this fashion. |
Thanks for the info, @rmhrisk ! I responded to your comment on the nodejs issue (nodejs/help#964) 😄 I'm going to close this issue on the graphene repo since I think it's evolved into a generic nodejs question, so if you happen to have any further comments, please add them to the nodejs thread! |
I just started using graphene, and I'm trying to read a certificate in plain text that I stored using SoftHSMv2. Here's all I've done:
Output:
I'm not seeing the certificate contents in my certificate object at all!
Any help would be appreciated!
The text was updated successfully, but these errors were encountered: