Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install root certificate to Node.js (HTTPS Client)

I would like to connect to an internal corporate server with Node.js as a client via HTTPS. How do I install my internal root certificate to Node.js, so the certificate validation is successful?

I don't want to disable certificate validation.

like image 414
mitchkman Avatar asked May 19 '14 20:05

mitchkman


People also ask

How do I enable HTTPS in node JS?

To built an HTTPS server with nodeJs, we need an SSL (Secure Sockets Layer) certificate. We can create a self-signed SSL certificate on our local machine. Let's first create an SSL certificate on our machine first. After running this command, we would get some options to fill.


2 Answers

I solved the problem.

Use this, it works as charm: https://github.com/coolaj86/node-ssl-root-cas

  1. Create a certificates folder
  2. Place your root certificate there
  3. Load the certificate with the module metnioned above

If you use Sails.js, put the code to config/bootstrap.js

like image 183
mitchkman Avatar answered Sep 19 '22 03:09

mitchkman


Add an environment variable:

NODE_EXTRA_CA_CERTS=file

When set, the well known "root" CAs (like VeriSign) will be extended with the extra certificates in file. The file should consist of one or more trusted certificates in PEM format. A message will be emitted (once) with process.emitWarning() if the file is missing or malformed, but any errors are otherwise ignored.

Note that neither the well known nor extra certificates are used when the ca options property is explicitly specified for a TLS or HTTPS client or server.

This environment variable is ignored when node runs as setuid root or has Linux file capabilities set.

like image 40
Daniel Fisher lennybacon Avatar answered Sep 19 '22 03:09

Daniel Fisher lennybacon