user1219721
user1219721

Reputation: 803

How to use JKS certificate for NODE https client request

I would like to use certificate from a JKS keystore within a NodeJS application.

var fs = require('fs'); 
var https = require('https'); 

var options = { 
  hostname: 'XXX.com', 
  port: 4443, 
  path: '/endpoint', 
  method: 'GET', 
  key: fs.readFileSync('private.pem'), 
  cert: fs.readFileSync('public.pem'), 
};


var req = https.request(options, function(res) { 
  res.on('data', function(data) { 
    process.stdout.write(data); 
  }); 
}); 

req.end(); 

req.on('error', function(e) { 
  console.error(e); 
});

How can i convert the JKS to PEM ? Thank you

Upvotes: 6

Views: 11369

Answers (2)

Kim Zeevaarders
Kim Zeevaarders

Reputation: 805

Late to the party but this library does exactly that: https://www.npmjs.com/package/jks-js

Look at the the toPem method in the docs.

Upvotes: 1

Gary Sheppard
Gary Sheppard

Reputation: 4932

How to use JKS certificate for NODE https client request

I don't know if there's a way to do that. But...

How can i convert the JKS to PEM ?

There is definitely a way to do that:

$ keytool -importkeystore -srckeystore keystore.jks -destkeystore keystore.p12
-deststoretype PKCS12 -srcalias <jkskeyalias> -deststorepass <password>
-destkeypass <password>
$ openssl pkcs12 -in keystore.p12  -nokeys -out public.pem
$ openssl pkcs12 -in keystore.p12  -nodes -nocerts -out private.pem

Upvotes: 6

Related Questions