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
Spent a couple of hours trying to fix this. The following way worked for me:
Create a config file (for example req.cnf)
[req]
distinguished_name = req_distinguished_name
x509_extensions = v3_req
prompt = no
[req_distinguished_name]
C = US
ST = VA
L = SomeCity
O = MyCompany
OU = MyDivision
CN = local.com
[v3_req]
keyUsage = critical, digitalSignature, keyAgreement
extendedKeyUsage = serverAuth
subjectAltName = @alt_names
[alt_names]
DNS.1 = local.com
IP.1 = 127.0.0.1
and then generate a certificate and private key
openssl req -x509 -nodes -days 730 -newkey rsa:2048 -keyout local.com.key -out local.com.crt -config req.cnf -sha256
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With