SSL證書: 是數字證書的一種,相似於駕駛證、護照和營業執照的電子副本。由於配置在服務器上,也稱爲SSL服務器證書。linux
ssl也是傳輸協議。算法
基於ssl協議開發的一款軟件叫opensslapache
linux系統默認已經安裝安全
openssl服務器
配置文件:測試
/etc/pki/tls/openssl.conf網站
dir=/etc/pki/CA <<<指定CA工做目錄ui
certs=$dir/certs <<<指定撤銷存儲庫的位置加密
crl_dir=$dir/crl <<<證書撤銷列表spa
database=$dir/index.txt <<<已生成的證書信息的索引文件(此文件默認不存在,須要本身建立)
new_certs_dir=$dir/newcerts <<<新簽發的證書的保存位置
certificate=$dir/cacert.pem <<<CA本身的證書名稱
serial = $dir/serial <<<記錄證書的序號,默承認以從1開始(此文件默認不存在,內容也不能爲空,須要手動往裏面添加一個數字)
crlnumber = $dir/crlnumber <<<吊銷的證書序列號
crl = $dir/crl.pem<<< 吊銷的證書的列表
private_key = $dir/private/cakey.pem <<< CA本身的私鑰的位置
RANDFILE = $dir/private/.rand <<<隨機數文件位置
x509_extensions = usr_cert <<<擴展項
建立CA
1.建立不存在的文件
index,txt
serial
2.給本身(CA)建立證書
實現步驟
1.建立那些不存在的文件
[root@ ~]# touch /etc/pki/CA/index.txt [root@ ~]# echo "01">/etc/pki/CA/serial [root@~]# cat/etc/pki/CA/serial [root@~]# cat /etc/pki/CA/serial 01
2.給CA建立證書
(1)生成CA的私鑰文件
[root@ ~]# openssl genrsa -out /etc/pki/CA/private/cakey.pem 1024 <<<數字越大加密強度越大,然而小消耗系統資源也越多 Generating RSA private key, 1024 bit long modulus .......++++++ ....++++++ e is 65537 (0x10001)
(2)從私鑰文件中抽取公鑰,並製做證書
-new:申請新的證書
-x509:證書版本號,509是給CA本身建立證書的準用選項
-key:指定私鑰文件
-days:指定證書有效期
[root@~]# openssl req -new -x509 -key /etc/pki/CA/private/cakey.pem -days 360 -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) []:henan <<<所在省 Locality Name (eg, city) [Default City]:zhengzhou <<< 所在市 Organization Name (eg, company) [Default Company Ltd]:baidu 組織名(公司名) Organizational Unit Name (eg, section) []:nuomi <<<組織單位名 Common Name (eg, your name or your server's hostname) []:www.baidu.com <<<公司網站域名(必定不能錯,不然證書無效) Email Address []:123456789@126.com <<< 郵箱地址
給其餘主機制做頒發證書的流程
1.客戶端生成一個證書請求文件
2.客戶端將證書申請文件發送到CA請求證書
3.檢查證書請求文件中的信息的真僞,若是爲真,則製做證書並頒發個客戶端
實現步驟(以給apache頒發證書爲例,服務器端10.220.5.67,客戶端10.220.5.63)
1.給apache建立私鑰文件(用於存放私鑰,公鑰以及頒發的證書)
(1)生成客戶端私鑰
[root@apache ~]# mkdir /etc/httpd/ssl
[root@apache ~]# openssl genrsa -out /etc/httpd/ssl/httpd.key 1024 Generating RSA private key, 1024 bit long modulus ........................................................++++++ ........................................++++++ e is 65537 (0x10001)
(2)生成請求文件
[root@apache ~]# openssl req -new -key /etc/httpd/ssl/httpd.key -days 365 -out /etc/httpd/ssl/httpd.req
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) []:henan
Locality Name (eg, city) [Default City]:zhengzhou Organization Name (eg, company) [Default Company Ltd]:baidu Organizational Unit Name (eg, section) []:nuomi Common Name (eg, your name or your server's hostname) []:www.baidu.com Email Address []:123456789@126.com
Please enter the following 'extra' attributesto be sent with your certificate request
A challenge password []: <<<對生成的證書進行加密,這裏省略
An optional company name []:
(3)查看生成的文件
[root@apache ~]# ls /etc/httpd/ssl/
httpd.key httpd.req<<此文件就是生成的請求文件
(4)將請求文件發送到服務器端
[root@apache ~]# scp /etc/httpd/ssl/httpd.req root@10.220.5.67:/tmp
The authenticity of host '10.220.5.67 (10.220.5.67)' can't be established.
ECDSA key fingerprint is SHA256:Fi2Rlnl2uce8/7OiRG1JReD158iHVydpZ+bW+IgoutY.
ECDSA key fingerprint is MD5:d0:96:1f:a9:83:fc:0a:bf:1f:20:1b:ec:4d:79:6e:7e.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.220.5.67' (ECDSA) to the list of known hosts.
root@10.220.5.67's password:
httpd.req 100% 700 321.8KB/s 00:00
2.服務端檢查請求文件中的信息的真實性(在服務端操做)
[root@e ~]# openssl ca -in /tmp/httpd.req -out /tmp/httpd.crt -days 7000 Using configuration from /etc/pki/tls/openssl.cnf Check that the request matches the signature Signature ok Certificate Details: Serial Number: 1 (0x1) Validity Not Before: Nov 3 16:53:28 2018 GMT Not After : Jan 2 16:53:28 2038 GMT Subject: countryName = CN stateOrProvinceName = henan organizationName = baidu organizationalUnitName = nuomi commonName = www.baidu.com emailAddress = 123456789@126.com X509v3 extensions: X509v3 Basic Constraints: CA:FALSE Netscape Comment: OpenSSL Generated Certificate X509v3 Subject Key Identifier: 90:DA:6B:61:2B:D1:3D:AD:10:45:47:15:6D:9D:A6:B0:AB:7B:80:39 X509v3 Authority Key Identifier: keyid:50:EF:77:9C:65:CD:D1:42:C2:FC:9E:C4:09:82:16:9C:BB:41:0C:18 Certificate is to be certified until Jan 2 16:53:28 2038 GMT (7000 days) Sign the certificate? [y/n]:y 1 out of 1 certificate requests certified, commit? [y/n]y Write out database with 1 new entries Data Base Updated
2)將生成的證書發送給客戶端
[root@ ~]# scp /tmp/httpd.crt root@10.220.5.63:/etc/httpd/ssl httpd.crt 100% 3233 1.1MB/s 00:00