Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 591
user1219721 Avatar asked Jun 02 '18 12:06

user1219721


People also ask

How do I get an SSL certificate for a Node JS server?

The csr.pem file should be submitted to any valid Certificate Authority like Comodo , Symantec, GoDaddy or other entity that issues digital certificates if you want to buy a SSL certificate. Once you do all the process you should receive a valid certificate. Use that certificate with your Node.js server. Happy coding ❤️!

How to create an HTTPS server in Node JS?

The Ca Bundle file containing the root and intermediate certificates. ( .ca-bundle extension) Create an HTTPS server in Node.js environment. In the command line, use the following values to create your HTTPS server. For this demonstration, we’ve named it https_server.js, but you can give any name to the server.js file

Is it possible to create a secure connection in Node JS?

If you're working with web servers in Node.js you may probably already wanted to create a secure connection, either to provide indeed a secure connection or to allow the access of APIs in the browser that only are accessible if the protocol is HTTPS and not HTTP e.g getUserMedia or webkitSpeechRecognition etc.

How does a self signed client certificate work in Java?

In our case, the self-signed client certificate is in the server trust store so that the socket will accept the connection. The server proceeds to read the message using the InputStream. It then uses the OuputStream to echo back the incoming message appending an acknowledgment. 5. Client Java Implementation


1 Answers

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
like image 146
Gary Sheppard Avatar answered Oct 03 '22 05:10

Gary Sheppard