I'm trying to setup a site on localhost using a self-signed certificate for Express.js on Windows 10. Here is the Express.js server code.
index.js
const https = require('https')
const express = require('express')
const app = express()
const fs = require('fs')
const path = require('path')
const httpsOptions = {
cert: fs.readFileSync(path.resolve(__dirname, 'ssl', 'ca.crt')),
key: fs.readFileSync(path.resolve(__dirname, 'ssl', 'ca.key'))
}
const router = require('./router')
app.use('/people', router)
https.createServer(httpsOptions, app)
.listen(3443)
I have also imported the certificate authority ca.crt file to chrome, and restarted chrome. But I still have error on chrome as shown below:
Please guide how to solve this problem Thanks
I created the keys and certificate using the following commands.
# certificate authority key
openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048 -out ca.key
# server key
openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048 -out server.key
# certificate authority
openssl req -new -x509 -days 365 -key ca.key -subj "/CN=Test CA/O=Test Organization" -out ca.crt
# certificate signing request
openssl req -new -key server.key -subj "/CN=localhost/O=Test Organization" -out server.csr
# server certificate
openssl x509 -days 365 -req -in server.csr -CAcreateserial -CA ca.crt -CAkey ca.key -out server.crt
# verification
openssl verify -verbose -CAfile ca.crt server.crt
System Info
- OpenSSL: 1.1.0e 16 Feb 2017
- Node: 7.7.1
- Windows 10