保存为openssl.cnf
[req]
prompt=no
distinguished_name = req_distinguished_name
req_extensions = v3_req
[req_distinguished_name]
C=ZH
ST=China
L=ShangHai
O=Treemonster Self-signed place
OU=Treemonster Self-signed place
CN=Chen.wg1993
[ v3_req ]
# Extensions to add to a certificate request
basicConstraints = CA:FALSE
keyUsage = nonRepudiation, digitalSignature, keyEncipherment
subjectAltName = @alt_names
[alt_names]
DNS.1 = proxy.svr
保存为 ssl.sh
#!/bin/bash
if [[ "$1" == "ca" ]]; then
openssl genrsa -out ca-key.pem
openssl req -new -key ca-key.pem -config openssl.cnf -out ca-csr.pem
openssl x509 -req -in ca-csr.pem -signkey ca-key.pem -out ca-cert.pem
fi
if [[ "$1" == "svr" ]]; then
openssl genrsa -out server-key.pem 2048
openssl req -new -key server-key.pem -config openssl.cnf -out server-csr.pem
openssl x509 -req -CA ca-cert.pem -CAkey ca-key.pem -CAcreateserial -in server-csr.pem -out server-cert.pem -extensions v3_req -extfile openssl.cnf
fi
ca参数生成证书颁发机构(签名),svr生成服务端证书,cli生成客户端证书。
自签名证书需要在nodejs访问时带上ca-cert.pem,否则会被认为不安全连接而无法访问,如果设置环境变量允许不安全连接则可能会导致ssl中间人攻击。
设置环境变量允许不安全连接:
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
相关文档
暂无
随便看看
畅言模块加载中