https
http over ssl = https 443/tcp
ssl: v3
tls: v1
https://
SSL會話的簡化過程
(1) 客戶端發送可供選擇的加密方式,并向服務器請求證書;
(2) 服務器端發送證書以及選定的加密方式給客戶端;
(3) 客戶端取得證書并進行證書驗正:
如果信任給其發證書的CA:
(a) 驗正證書來源的合法性;用CA的公鑰解密證書上數字簽名;
(b) 驗正證書的內容的合法性:完整性驗正
(c) 檢查證書的有效期限;
(d) 檢查證書是否被吊銷;
(e) 證書中擁有者的名字,與訪問的目標主機要一致;
(4) 客戶端生成臨時會話密鑰(對稱密鑰),并使用服務器端的公鑰加密此數據發送給服務器,完成密鑰交換;
(5) 服務用此密鑰加密用戶請求的資源,響應給客戶端;
注意:SSL會話是基于IP地址創建;所以單IP的主機上,僅可以使用一個https虛擬主機;
配置httpd支持https:
(1) 為服務器申請數字證書;
測試:通過私建CA發證書
(a) 創建私有CA
(b) 在服務器創建證書簽署請求
(c) CA簽證
(2) 配置httpd支持使用ssl,及使用的證書;
# yum -y install mod_ssl
配置文件:/etc/httpd/conf.d/ssl.conf
DocumentRoot
ServerName
SSLCertificateFile
SSLCertificateKeyFile
(3) 測試基于https訪問相應的主機;
# openssl s_client [-connect host:port] [-cert filename] [-CApath directory] [-CAfile filename]
openssl CA配置部分詳解
]# vim /etc/pki/tls/openssl.cnf
[ CA_default ]
dir = /etc/pki/CA # Where everything is kept 默認工作目錄,數據存儲目錄
certs = $dir/certs # Where the issued certs are kept 存放已簽署的證書
crl_dir = $dir/crl # Where the issued crl are kept 吊銷列表
database = $dir/index.txt # database index file. 數據庫索引文件
#unique_subject = no # Set to 'no' to allow creation of
# several ctificates with same subject.
new_certs_dir = $dir/newcerts # default place for new certs. 剛簽署完的證書
certificate = $dir/cacert.pem # The CA certificate 自己的證書
serial = $dir/serial # The current serial number 被吊銷的證書的序列號
crlnumber = $dir/crlnumber # the current crl number
# must be commented out to leave a V1 CRL
crl = $dir/crl.pem # The current CRL 當前正在使用的吊銷列表文件
private_key = $dir/private/cakey.pem# The private key 自己私鑰存放路徑
RANDFILE = $dir/private/.rand # private random number file
x509_extensions = usr_cert # The extentions to add to the cert
主機ip:192.168.8.98
創建私有CA
]# cd /etc/pki/CA/
]# ls
certs crl newcerts private
(1) 創建所需要的文件
]# touch index.txt
]# echo 01 > serial
]# ll
total 20
drwxr-xr-x. 2 root root 4096 Sep 27 2013 certs
drwxr-xr-x. 2 root root 4096 Sep 27 2013 crl
-rw-r–r– 1 root root 0 Jun 21 23:39 index.txt
drwxr-xr-x. 2 root root 4096 Sep 27 2013 newcerts
drwx——. 2 root root 4096 Sep 27 2013 private
-rw-r–r– 1 root root 3 Jun 21 23:39 serial
(2) CA自簽證書
生成私鑰
]# (umask 077; openssl genrsa -out /etc/pki/CA/private/cakey.pem 2048)
生成證書請求
]# openssl req -new -x509 -key /etc/pki/CA/private/cakey.pem -days 3650 -out /etc/pki/CA/cacert.pem
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
—–
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:Shanghai
Locality Name (eg, city) [Default City]:Shanghai
Organization Name (eg, company) [Default Company Ltd]:anneng
Organizational Unit Name (eg, section) []:ops
Common Name (eg, your name or your server's hostname) []:ca.anneng.com
Email Address []:809889031@qq.com
-new: 生成新證書簽署請求;
-x509: 專用于CA生成自簽證書;
-key: 生成請求時用到的私鑰文件;
-days n:證書的有效期限;
-out /PATH/TO/SOMECERTFILE: 證書的保存路徑;
主機ip:192.168.8.94
配置httpd支持https:
]# cd /etc/httpd/
]# mkdir ssl
]# cd ssl/
生成私鑰
]# (umask 077; openssl genrsa -out httpd.key 2048)
創建證書簽署請求
]# openssl req -new -key httpd.key -days 365 -out httpd.csr
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
—–
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:Shanghai
Locality Name (eg, city) [Default City]:Shanghai
Organization Name (eg, company) [Default Company Ltd]:anneng
Organizational Unit Name (eg, section) []:ops
Common Name (eg, your name or your server's hostname) []:www.xzx.com
Email Address []:
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
]# ll
總用量 8
-rw-r–r– 1 root root 1005 6月 21 19:34 httpd.csr
-rw——- 1 root root 1679 6月 21 19:29 httpd.key
講證書簽署請求傳遞給CA
]# scp httpd.csr root@192.168.8.98:/tmp/
主機ip:192.168.8.98
簽署證書并講簽署后的證書發還黑httpd服務器
]# openssl ca -in /tmp/httpd.csr -out /etc/pki/CA/certs/httpd.crt -days 365
]# scp httpd.crt root@192.168.8.94:/etc/httpd/ssl/
主機ip:192.168.8.94
安裝httpd的ssl模塊
]# yum -y install mod_ssl
查看模塊生成的文件
]# rpm -ql mod_ssl
/etc/httpd/conf.d/ssl.conf
/usr/lib64/httpd/modules/mod_ssl.so
/var/cache/mod_ssl
/var/cache/mod_ssl/scache.dir
/var/cache/mod_ssl/scache.pag
/var/cache/mod_ssl/scache.sem
編輯httpd關于ssl的配置
]# vim /etc/httpd/conf.d/ssl.conf
<VirtualHost *:443>
DocumentRoot "/var/www/html"
ServerName www.xzx.com:44
]# service httpd restart
停止 httpd: [確定]
正在啟動 httpd: [確定]
測試基于https訪問相應的主機;
# openssl s_client [-connect host:port] [-cert filename] [-CApath directory] [-CAfile filename]
從本地windows端訪問https服務器
修改本地hosts文件,將CA的自簽證書下載到本地,并將cacert.pem修改為cacert.crt,本地安裝證書,然后通過瀏覽器訪問
原創文章,作者:809889031@qq.com,如若轉載,請注明出處:http://www.www58058.com/20724
文章有待提高呀~