標籤:ca https openssl
1.說明
部署之前,先舉例說明一下,方便理解。
比如我想去租房子,於是便在某網站上搜尋,結果聯絡的時候發現好多都是假的。
有看上的房子吧,又擔心房東是個騙子。這個時候,我為了租房,找到了一家房屋中介公司,雖然收費,但是可以放心的租到房子。
650) this.width=650;" src="https://s3.51cto.com/wyfs02/M01/97/A3/wKiom1kwz6SxV5SEAAC9fvbngJE199.png-wh_500x0-wm_3-wmp_4-s_1986526782.png" title="https.png" alt="wKiom1kwz6SxV5SEAAC9fvbngJE199.png-wh_50" />
2.部署
CA server: 192.168.1.10
http server: 192.168.1.200
2-1)在CA上產生自簽證 cacert.pem
切換到CA server: 192.168.1.10
2-1-1)建立私密金鑰
#(umask 077;openssl genrsa -out /etc/pki/CA/private/cakey.pem)
*說明:私密金鑰的許可權要設定到最低,可以使用子shell方式建立。
2-1-2)產生自簽認證(用於發放給個人使用者)
#openssl req -new -x509 -key /etc/pki/CA/private/cakey.pem -out /etc/pki/CA/cacert.pem
650) this.width=650;" src="https://s5.51cto.com/wyfs02/M00/97/A5/wKioL1kw07jTXzjlAACHoMimGoI730.png-wh_500x0-wm_3-wmp_4-s_3600412225.png" title="CA.png" alt="wKioL1kw07jTXzjlAACHoMimGoI730.png-wh_50" />
需要填寫的內容,可以在設定檔中設定
#vim /etc/pki/tls/openssl.cnf
650) this.width=650;" src="https://s2.51cto.com/wyfs02/M02/97/A4/wKiom1kw1T3g_RaHAABRjoLya-4763.png-wh_500x0-wm_3-wmp_4-s_2403684741.png" title="sslfile.png" alt="wKiom1kw1T3g_RaHAABRjoLya-4763.png-wh_50" />
2-2-1)服務端請求產生認證
切換到http server:192.168.1.200
#yum install mod_ssl -y #用於https的配置
#mkdir /etc/httpd/ssl
#cd /etc/httpd/ssl
#(umask 077;openssl genrsa -out httpd.key) #產生私密金鑰
#openssl req -new -key httpd.key -out httpd.csr #產生認證請求
*注意:紅色框中填寫的內容要與在CA上設定內容一致(參考2-1-2)),黃色框中的網域名稱就是CA要認證的網域名稱。
650) this.width=650;" src="https://s1.51cto.com/wyfs02/M01/97/A5/wKiom1kw14LidN64AACBivdKles847.png-wh_500x0-wm_3-wmp_4-s_1255796940.png" title="httpdcsr.png" alt="wKiom1kw14LidN64AACBivdKles847.png-wh_50" />
2-2-2)將產生的httpd.csr認證請求檔案傳到CA server,由CA發送認證。
#pwd
/etc/httpd/ssl
#scp httpd.csr [email protected]:/tmp
2-2-3)切換到CA server,進行認證分發
#openssl ca -in /tmp/httpd.csr -out /tmp/httpd.crt -days 365
將產生的認證發送給http server
#scp /tmp/httpd.crt [email protected]:/etc/httpd/ssl
2-2-4)切換到http server查看
#ls /etc/httpd/ssl
httpd.crt httpd.csr http.key
在/etc/httpd/conf.d/ssl.conf修改私密金鑰和認證的儲存位置,重啟apache,查看443連接埠
SSLCertificateKeyFile /etc/httpd/ssl/httpd.key
SSLCertificateFile /etc/httpd/ssl/httpd.crt
#netstat -tunlp |grep httpd
tcp 0 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 15608/httpd
tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 15608/httpd
2-3)用戶端下載CA上的認證 cacert.pem檔案 ,改名為cecert.crt.雙擊安裝認證。
在本機hosts中做網域名稱映射
192.168.1.200 www.slitobo.com
瀏覽器訪問即可;
650) this.width=650;" src="https://s2.51cto.com/wyfs02/M02/97/A7/wKioL1kw3EDCaluUAACsOfenYvs929.png-wh_500x0-wm_3-wmp_4-s_1577656434.png" title="c1.png" alt="wKioL1kw3EDCaluUAACsOfenYvs929.png-wh_50" />
650) this.width=650;" src="https://s2.51cto.com/wyfs02/M00/97/A6/wKiom1kw3ECzdSHSAACd5ylhzdY400.png-wh_500x0-wm_3-wmp_4-s_2896313806.png" style="float:none;" title="c2.png" alt="wKiom1kw3ECzdSHSAACd5ylhzdY400.png-wh_50" />
650) this.width=650;" src="https://s2.51cto.com/wyfs02/M00/97/A7/wKioL1kw3f6gdJHLAAAiqMDTDig506.png-wh_500x0-wm_3-wmp_4-s_1902198745.png" title="c3.png" alt="wKioL1kw3f6gdJHLAAAiqMDTDig506.png-wh_50" />
本文出自 “遙西向南” 部落格,請務必保留此出處http://slitobo.blog.51cto.com/12957087/1931603
基於openssl實現https訪問