openssl制作CA证书
用于nginx开启https:
openssl req -nodes -newkey rsa:2048 -out req.pem -keyout privateKey.pem
openssl req -in req.pem -x509 -key privateKey.pem -out cert.pem -days 365
nginx配置:
server {
listen 443; ## listen for ipv4; this line is default and implied
root /opt/nginx/default;
index index.php index.html index.htm;
# Make site accessible from http://localhost/
server_name www.enjointhing.cn;
ssl on;
ssl_certificate /opt/nginx/SSL/cert.pem; #指定数字证书文件
ssl_certificate_key /opt/nginx/SSL/privateKey.pem; #指定数字证书私钥文件
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
…
用于服务器和客户端,比如trojan代理:
生成CA根证书(root ca证书):
# Generate CA private key —>ca.key
openssl genrsa -out ca.key 2048
# Generate CSR —>ca.csr
openssl req -new -key ca.key -out ca.csr
# Generate Self Signed certificate(CA 根证书) —> ca.crt
openssl x509 -req -days 365 -in ca.csr -signkey ca.key -out ca.crt
用自签根证书 ca.crt 给用户证书签名:
# private key --->server.key
openssl genrsa -out server.key 1024
# generate csr --->server.csr
openssl req -new -key server.key -out server.csr
# generate certificate --->server.crt
openssl ca -in server.csr -out server.crt -cert ca.crt -keyfile ca.key
这样就可以把server.key server.crt 给trojan服务器配置用,server.crt给trojan客户端用了。
自签证书:
# 生成一个RSA密钥 > openssl genrsa -des3 -out dev.key 1024 # 生成一个证书请求 > openssl req -new -key dev.key -out dev.csr # 自己签发证书 > openssl x509 -req -days 365 -in dev.csr -signkey dev.key -out dev.crt # 拷贝一个不需要输入密码的密钥文件 > openssl rsa -in dev.key -out dev_nopass.key
nginx配置:
server { listen 443; ssl on; ssl_certificate csr/dev.crt; ssl_certificate_key csr/dev_nopass.key; }
把dev.crt发送给客户,导入“受信任的根证书颁发机构”。