自做CA自簽發SSL證書


一、把證書准備好。
步驟與使用OpenSSL自簽發服務器https證書所述大同小異。在這里再重復一次。
1、制作CA證書:
ca.key CA私鑰:

openssl genrsa -des3 -out ca.key 2048
Enter pass phrase for ca.key:*****          要求創建密碼

制作解密后的CA私鑰(一般無此必要):

openssl rsa -in ca.key -out ca_decrypted.key

ca.crt CA根證書(公鑰):

openssl req -new -x509 -days 7305 -key ca.key -out ca.crt

2、制作生成網站的證書並用CA簽名認證
在這里,假設網站域名為blog.creke.net
生成tdp.up.com證書私鑰:

openssl genrsa -des3 -out tdp.up.com.pem 1024
Enter pass phrase for tdp.up.com.pem:*****    要求創建密碼

制作解密后的blog.creke.net證書私鑰:

 openssl rsa -in tdp.up.com.pem -out tdp.up.com.key

 

生成簽名請求:

openssl req -new -key tdp.up.com.pem -out tdp.up.com.csr

在common name中填入網站域名,如:tdp.up.com,即可生成改站點的證書,同時也可以使用泛域名如*.up.com來生成所有二級域名可用的網站證書。

用CA進行簽名:

openssl ca -policy policy_anything -days 1460 -cert ca.crt -keyfile ca.key -in tdp.up.com.csr -out tdp.up.com.crt

其中,policy參數允許簽名的CA和網站證書可以有不同的國家、地名等信息,days參數則是簽名時限。

 

如果在執行簽名命令時,出現“I am unable to access the ../../CA/newcerts directory”
修改/etc/pki/tls/openssl.cnf中“dir = ./CA”

然后:

mkdir -p CA/newcerts
touch CA/index.txt
touch CA/serial
echo "01" > CA/serial

再重新執行簽名命令。
最后把ca.crt的內容粘貼到tdp.up.com.crt后面。這個比較重要!因為不這樣做,可能會有某些瀏覽器不支持。
好了,現在https需要到的網站私鑰tdp.up.com.key和網站證書tdp.up.com.crt都准備完畢。接下來開始配置服務端。

二、以nginx為例
新開一個虛擬主機,並在server{}段中設置:

listen 443;
ssl on;
ssl_certificate /path/to/tdp.up.com.crt;
ssl_certificate_key /path/to/tdp.up.com.key;
ssl_session_timeout 5m;
ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_prefer_server_ciphers on;

其中的路徑是剛剛生成的網站證書的路徑。
然后使用一下命令檢測配置和重新加載nginx:
檢測配置:
nginx -t
重新加載:
nginx -s reload


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM