From 5c8cf158dbe08e6638b1e2a707e064677a31b478 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Tue, 15 Jul 2014 03:38:33 +0000 Subject: [PATCH] with love --- .gitignore | 4 ++++ README.md | 32 +++++++++++++++++++++++++------- request-without-warnings.js | 5 +++-- serve.js | 2 +- test.sh | 32 ++++++++++++++++++++++++++------ 5 files changed, 59 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index da23d0d..ee918ba 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ +all/ +server/ +client/ + # Logs logs *.log diff --git a/README.md b/README.md index 5514bd6..d38a304 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,33 @@ nodejs-self-signed-certificate-example ====================================== -An example that works. - 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](https://github.com/coolaj86/node-ssl-root-cas/wiki/Painless-Self-Signed-Certificates-in-node.js) for +the many details. + Test for yourself --- -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. +An example that works. + +```bash +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 @@ -25,7 +43,7 @@ npm install bash test.sh ``` -### Create certificates for `local.ldsconnect.org` +### Create certificates for your FQDN `local.ldsconnect.org` points to `localhost`, so it's ideal for your first test. @@ -36,7 +54,7 @@ bash make-root-ca-and-certificates.sh 'local.ldsconnect.org' ### Run the server ```bash -node ./serve.js 4443 & +node ./serve.js 8043 & # use `fg` and `ctrl+c` to kill ``` @@ -50,7 +68,7 @@ Visit in a web browser Test (warning free) in node.js ```bash -node ./request-without-warnings.js 4443 +node ./request-without-warnings.js 8043 ``` Test (warning free) with cURL diff --git a/request-without-warnings.js b/request-without-warnings.js index 6fe002f..8d177ac 100755 --- a/request-without-warnings.js +++ b/request-without-warnings.js @@ -5,11 +5,12 @@ var https = require('https') , fs = require('fs') , path = require('path') , ca = fs.readFileSync(path.join(__dirname, 'client', 'my-private-root-ca.crt.pem')) - , port = process.argv[2] || 4443 + , port = process.argv[2] || 8043 + , hostname = process.argv[3] || 'local.ldsconnect.org' ; var options = { - host: 'local.ldsconnect.org' + host: hostname , port: port , path: '/' , ca: ca diff --git a/serve.js b/serve.js index 0892c24..11784d8 100755 --- a/serve.js +++ b/serve.js @@ -2,7 +2,7 @@ 'use strict'; var https = require('https') - , port = process.argv[2] || 4443 + , port = process.argv[2] || 8043 , fs = require('fs') , path = require('path') , server diff --git a/test.sh b/test.sh index 5745268..7d5560d 100755 --- a/test.sh +++ b/test.sh @@ -1,10 +1,30 @@ #!/bin/bash bash make-root-ca-and-certificates.sh 'local.ldsconnect.org' - -node ./serve.js & - -sleep 2 - -node ./request-without-warnings.js +echo "" + +echo "" +node ./serve.js 8043 & +NODE_PID=$! +sleep 1 + +echo "" +echo "" +node ./request-without-warnings.js 8043 'local.ldsconnect.org' +echo -n " - without warnings, love node.js' https" +echo "" +sleep 1 + +echo "" +curl https://local.ldsconnect.org:8043 \ + --cacert client/my-private-root-ca.crt.pem +echo -n " - without warnings, love cURL" +echo "" +sleep 1 + +# For lots of output about the ssl connection try -v +#curl -v https://local.ldsconnect.org:8043 \ +# --cacert client/my-private-root-ca.crt.pem + +kill ${NODE_PID} echo ""