首页 > 代码库 > openssl生成https证书 (转)
openssl生成https证书 (转)
openssl genrsa -des3 -out server.key 1024
运行时会提示输入密码,此密码用于加密key文件
去除key文件口令的命令:
openssl rsa -in server.key -out server.key
2.openssl req -new -key server.key -out server.csr -config openssl.cfg
生成Certificate Signing Request(CSR),生成的csr文件交给CA签名后形成服务端自己的证书.屏幕上将有提示,依照其指示一步一步输入要求的个人信息即可.
3.对客户端也作同样的命令生成key及csr文件:
openssl genrsa -des3 -out client.key 1024
openssl req -new -key client.key -out client.csr -config openssl.cfg
4.CSR文件必须有CA的签名才可形成证书.可将此文件发送到verisign等地方由它验证.自己生成:
openssl req -new -x509 -keyout ca.key -out ca.crt -config openssl.cfg
5.用生成的CA的证书为刚才生成的server.csr,client.csr文件签名:
Openssl ca -in server.csr -out server.crt -cert ca.crt -keyfile ca.key -config openssl.cfg
Openssl ca -in client.csr -out client.crt -cert ca.crt -keyfile ca.key -config openssl.cfg
PS:如报update database之类的错误,把index.txt.attr 文件内容更新为 unique_subject = no
注意: 此时会出错:Using configuration from /usr/share/ssl/openssl.cfg I am unable to access the ./demoCA/newcerts directory ./demoCA/newcerts: No such file or directory
解决方法: 1).mkdir -p ./demoCA/newcerts
2).touch demoCA/index.txt
3).touch demoCA/serial
4).echo 01 > demoCA/serial
6.合并证书文件(crt)和私钥文件(key)
1).cat client.crt client.key > client.pem
2).cat server.crt server.key > server.pem
7.合并成pfx证书
1).openssl pkcs12 -export -clcerts -in client.crt -inkey client.key -out client.p12
2).openssl pkcs12 -export -clcerts -in server.crt -inkey server.key -out server.p12
8.文本化证书
1).openssl pkcs12 -in client.p12 -out client.txt
2).openssl pkcs12 -in server.p12 -out server.txt
9.屏幕模式显式:(证书、私钥、公钥)
1).openssl x509 -in client.crt -noout -text -modulus
2).openssl rsa -in server.key -noout -text -modulus
3).openssl rsa -in server.pub -noout -text -modulus
10.得到DH
1).openssl dhparam -out dh1024.pem 1024
(8) 编辑apache的配置文件httpd.cfg
开启: LoadModule ssl_module modules/mod_ssl.so
去掉以下语句的注释, Include conf/extra/httpd-ssl.cfg
# Secure (SSL/TLS) connections
Include conf/extra/httpd-ssl.cfg
#
(9) 编辑 conf/extra/httpd-ssl.cfg
<VirtualHost *:443>
SSLEngine On
SSLCertificateFile conf/ssl/server.crt
SSLCertificateKeyFile conf/ssl/server.key
SSLCertificateChainFile conf/ssl/ca.crt
</VirtualHost>
cd /usr/local/apache/conf
openssl genrsa -des3 -out server.key 1024
openssl req -new -key server.key -out server.csr -config /usr/local/ssl/openssl.cfg
openssl req -new -x509 -keyout ca.key -out ca.crt -config /usr/local/ssl/openssl.cfg
mkdir -p ./demoCA/newcerts
touch demoCA/index.txt
touch demoCA/serial
echo 01 > demoCA/serial
openssl ca -in server.csr -out server.crt -cert ca.crt -keyfile ca.key -config /usr/local/ssl/openssl.cfg
bin/apachectl start
openssl生成https证书 (转)