Przeglądaj źródła

with love

master
AJ ONeal 10 lat temu
rodzic
commit
5c8cf158db
  1. 4
      .gitignore
  2. 32
      README.md
  3. 5
      request-without-warnings.js
  4. 2
      serve.js
  5. 26
      test.sh

4
.gitignore

@ -1,3 +1,7 @@
all/
server/
client/
# Logs
logs
*.log

32
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

5
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

2
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

26
test.sh

@ -1,10 +1,30 @@
#!/bin/bash
bash make-root-ca-and-certificates.sh 'local.ldsconnect.org'
echo ""
echo ""
node ./serve.js 8043 &
NODE_PID=$!
sleep 1
node ./serve.js &
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
sleep 2
# 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
node ./request-without-warnings.js
kill ${NODE_PID}
echo ""

Ładowanie…
Anuluj
Zapisz