The end off all your self-sign certificate woes (in node.js at least)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
AJ ONeal f743969b5f clarify 10 years ago
.gitignore with love 10 years ago
LICENSE Initial commit 10 years ago
README.md clarify 10 years ago
make-root-ca-and-certificates.sh working example with self-signed certificates 10 years ago
package.json working example with self-signed certificates 10 years ago
request-without-warnings.js with love 10 years ago
serve.js with love 10 years ago
test.sh with love 10 years ago

README.md

nodejs-self-signed-certificate-example

The end off all your self-signed certificate woes (in node.js at least)

This is an easy-as-git-clone example that will get you on your way without any DEPTH_ZERO_SELF_SIGNED_CERT or SSL certificate problem: Invalid certificate chain headaches.

See the explanation for the many details.

Test for yourself

An example that works.

example
├── package.json
├── make-root-ca-and-certificates.sh
├── serve.js
├── request-without-warnings.js
├── server
|   ├── my-private-root-ca.crt.pem
|   ├── my-server.crt.pem
|   └── my-server.key.pem
└── client
    └── my-private-root-ca.crt.pem

Get the repo

git clone git@github.com:coolaj86/nodejs-self-signed-certificate-example.git
pushd nodejs-self-signed-certificate-example
npm install

For the super impatient:

bash test.sh

Create certificates for your FQDN

local.ldsconnect.org points to localhost, so it's ideal for your first test.

bash make-root-ca-and-certificates.sh 'local.ldsconnect.org'

Run the server

node ./serve.js 8043 &
# use `fg` and `ctrl+c` to kill

Test in a client

Test (warning free) in node.js

node ./request-without-warnings.js 8043

Test (warning free) with cURL

curl -v https://local.ldsconnect.org \
  --cacert client/my-private-root-ca.crt.pem

Visit in a web browser

https://local.ldsconnect.org

To get rid of the warnings, simply add the certificate in the client folder to your list of certificates by alt-clicking "Open With => Keychain Access" on my-private-root-ca.crt.pem

You do have to set Always Trust a few times as explained by Rob Peck.

Now season to taste

You can poke around in the files for generating the certificates, but all you really have to do is replace local.ldsconnect.org with your very own domain name.

But where's the magic?

Who's the man behind the curtain you ask?

Well... I lied. This demo doesn't use self-signed certificates (not in the server at least). It uses a self-signed Root CA and a signed certificate.

It turns out that self-signed certificates were designed to be used by the Root Certificate Authorities, not by web servers.

So instead of trying to work through eleventeen brazillion errors about self-signed certs, you can just create an authority and then add the authority to your chain (viola, now it's trusted).