SSL会话的简化过程
(1) 客户端发送可供选择的加密方式,并向服务器请求证书;
(2) 服务器端发送证书以及选定的加密方式给客户端;
(3) 客户端取得证书并进行证书验正:
如果信任给其发证书的CA:
(a) 验正证书来源的合法性;用CA的公钥解密证书上数字签名;
(b) 验正证书的内容的合法性:完整性验正
(c) 检查证书的有效期限;
(d) 检查证书是否被吊销;
(e) 证书中拥有者的名字,与访问的目标主机要一致;
(4) 客户端生成临时会话密钥(对称密钥),并使用服务器端的公钥加密此数据发送给服务器,完成密钥交换;
(5) 服务用此密钥加密用户请求的资源,响应给客户端;
注意:SSL会话是基于IP地址创建;所以单IP的主机上,仅可以使用一个https虚拟主机;
配置httpd支持https:
1、为服务器申请数字证书;
1)创建私有CA(1)生成私钥文件 [size=1em]1
[size=1em]2
[size=1em]3
[size=1em]4
[size=1em]5
[size=1em]6
[size=1em]7
[size=1em]8
[size=1em]9
| [size=1em][iyunv@wlm ~]# mkdir -p /etc/pki/CA/private #创建私钥保存的目录
[size=1em][iyunv@wlm ~]# (umask 077;openssl genrsa -out /etc/pki/CA/private/cakey.pem 4096)
[size=1em]Generating RSA private key, 4096 bit long modulus
[size=1em]....................................................................++
[size=1em]..................................................................++
[size=1em]e is 65537 (0x10001)
[size=1em][iyunv@wlm ~]# ll /etc/pki/CA/private/ # 私钥只能自己保存,对保密性要求高
[size=1em]总用量 4
[size=1em]-rw-------. 1 root root 3243 11月 15 10:34 cakey.pem
|
(2)生成自签证书 [size=1em]1
[size=1em]2
[size=1em]3
[size=1em]4
[size=1em]5
[size=1em]6
[size=1em]7
[size=1em]8
[size=1em]9
[size=1em]10
[size=1em]11
[size=1em]12
[size=1em]13
[size=1em]14
[size=1em]15
[size=1em]16
[size=1em]17
[size=1em]18
[size=1em]19
[size=1em]20
[size=1em]21
[size=1em]22
| [size=1em][iyunv@wlm ~]# openssl req -new -x509 -key /etc/pki/CA/private/cakey.pem -out /etc/pki/CA/cacert.pem -days 3650
[size=1em]# 如果是自请自签 加-x509 如果不是就不用加了
[size=1em]#这个过程会自动从刚才第一步的私钥中抽取公钥
[size=1em]#-new 生成新证书签署请求
[size=1em]#-x509 生成自签格式证书 专用于创建私有CA时
[size=1em]#-key 生成请求时用到的私有文件路径
[size=1em]#-out 生成的请求文件路径 如果是自签操作将生成签署过的证书
[size=1em]#-days 证书的有效时常 但为是day
[size=1em]You are about to be asked to enter information that will be incorporated
[size=1em]into your certificate request.
[size=1em]What you are about to enter is what is called a Distinguished Name or a DN.
[size=1em]There are quite a few fields but you can leave some blank
[size=1em]For some fields there will be a default value,
[size=1em]If you enter '.', the field will be left blank.
[size=1em]-----
[size=1em]Country Name (2 letter code) [XX]:CN #国家
[size=1em]State or Province Name (full name) []:SH #省
[size=1em]Locality Name (eg, city) [Default City]:SH #城市
[size=1em]Organization Name (eg, company) [Default Company Ltd]:DZH #公司组织
[size=1em]Organizational Unit Name (eg, section) []:Ops #职位
[size=1em]Common Name (eg, your name or your server's hostname) []:ca.wlm.com #主机名
[size=1em]Email Address []:mail@wlm.com #邮箱
|
(3)为CA提供所需的目录和文件 [size=1em]1
[size=1em]2
[size=1em]3
[size=1em]4
[size=1em]5
[size=1em]6
[size=1em]7
[size=1em]8
[size=1em]9
[size=1em]10
[size=1em]11
| [size=1em][iyunv@wlm ~]# touch /etc/pki/CA/index.txt # 创建数据库文件
[size=1em][iyunv@wlm ~]# echo 01 > /etc/pki/CA/serial # 创建序列号文件并给明第一个证书的序列号码
[size=1em][iyunv@wlm ~]# ll /etc/pki/CA
[size=1em]总用量 8
[size=1em]-rw-r--r--. 1 root root 2049 11月 15 10:41 cacert.pem
[size=1em]drwxr-xr-x. 2 root root 6 6月 29 2015 certs
[size=1em]drwxr-xr-x. 2 root root 6 6月 29 2015 crl
[size=1em]-rw-r--r--. 1 root root 0 11月 15 10:45 index.txt
[size=1em]drwxr-xr-x. 2 root root 6 6月 29 2015 newcerts
[size=1em]drwx------. 2 root root 22 11月 15 10:34 private
[size=1em]-rw-r--r--. 1 root root 3 11月 15 10:46 serial
|
至此,私有CA创建完毕。 2)证书申请: (1)在证书申请的主机上生成私钥 [size=1em]1
[size=1em]2
[size=1em]3
[size=1em]4
[size=1em]5
[size=1em]6
[size=1em]7
[size=1em]8
[size=1em]9
[size=1em]10
[size=1em]11
| [size=1em][iyunv@wlm ~]# cd /etc/httpd/
[size=1em][iyunv@wlm httpd]# mkdir ssl #创建保存私钥的目录
[size=1em][iyunv@wlm httpd]# cd ssl
[size=1em][iyunv@wlm ssl]# (umask 077;openssl genrsa -out httpd.key 2048) #生成私钥
[size=1em]Generating RSA private key, 2048 bit long modulus
[size=1em]......................................................+++
[size=1em]...........................................+++
[size=1em]e is 65537 (0x10001)
[size=1em][iyunv@wlm ssl]# ll
[size=1em]总用量 4
[size=1em]-rw-------. 1 root root 1675 11月 15 11:05 httpd.key
|
(2)生成证书签署请求
[size=1em]1
[size=1em]2
[size=1em]3
[size=1em]4
[size=1em]5
[size=1em]6
[size=1em]7
[size=1em]8
[size=1em]9
[size=1em]10
[size=1em]11
[size=1em]12
[size=1em]13
[size=1em]14
[size=1em]15
[size=1em]16
[size=1em]17
[size=1em]18
[size=1em]19
[size=1em]20
| [size=1em][iyunv@wlm ssl]# openssl req -new -key httpd.key -out httpd.csr -days 365 # 在本地生成
[size=1em]You are about to be asked to enter information that will be incorporated
[size=1em]into your certificate request.
[size=1em]What you are about to enter is what is called a Distinguished Name or a DN.
[size=1em]There are quite a few fields but you can leave some blank
[size=1em]For some fields there will be a default value,
[size=1em]If you enter '.', the field will be left blank.
[size=1em]-----
[size=1em]Country Name (2 letter code) [XX]:CN
[size=1em]State or Province Name (full name) []:SH
[size=1em]Locality Name (eg, city) [Default City]:SH
[size=1em]Organization Name (eg, company) [Default Company Ltd]:DZH
[size=1em]Organizational Unit Name (eg, section) []:Ops
[size=1em]Common Name (eg, your name or your server's hostname) []:www.wlm.com
[size=1em]Email Address []:mail.wlm.com
[size=1em]Please enter the following 'extra' attributes
[size=1em]to be sent with your certificate request
[size=1em]A challenge password []: #密码可以不设置
[size=1em]An optional company name []:
|
(3)把请求发送给CA [size=1em]1
[size=1em]2
[size=1em]3
[size=1em]4
[size=1em]5
[size=1em]6
[size=1em]7
[size=1em]8
| [size=1em][iyunv@wlm ssl]# scp httpd.csr root@10.10.10.3:/tmp/ # 10.10.10.3位CA主机
[size=1em]# 将请求签发的证书发个证书服务器,我们这里是同一台机器模拟了证书服务器和申请签发的客户机
[size=1em]The authenticity of host '10.10.10.3 (10.10.10.3)' can't be established.
[size=1em]ECDSA key fingerprint is 93:b6:c3:bf:a6:51:a7:4a:be:0c:14:93:ab:86:a1:56.
[size=1em]Are you sure you want to continue connecting (yes/no)? yes
[size=1em]Warning: Permanently added '10.10.10.3' (ECDSA) to the list of known hosts.
[size=1em]root@192.168.208.130's password:
[size=1em]httpd.csr 100% 1025 1.0KB/s 00:0
|
(4)CA签发证书(在CA10.10.10.3主机上操作) [size=1em]1
[size=1em]2
[size=1em]3
[size=1em]4
[size=1em]5
[size=1em]6
[size=1em]7
[size=1em]8
[size=1em]9
[size=1em]10
[size=1em]11
[size=1em]12
[size=1em]13
[size=1em]14
[size=1em]15
[size=1em]16
[size=1em]17
[size=1em]18
[size=1em]19
[size=1em]20
[size=1em]21
[size=1em]22
[size=1em]23
[size=1em]24
[size=1em]25
[size=1em]26
[size=1em]27
[size=1em]28
[size=1em]29
[size=1em]30
[size=1em]31
[size=1em]32
[size=1em]33
[size=1em]34
[size=1em]35
[size=1em]36
[size=1em]37
[size=1em]38
[size=1em]39
[size=1em]40
| [size=1em][iyunv@wlm tmp]# openssl ca -in /tmp/httpd.csr -out /etc/pki/CA/certs/httpd.crt -days 365
[size=1em]# 签发证书,有效期为一年
[size=1em]Using configuration from /etc/pki/tls/openssl.cnf
[size=1em]Check that the request matches the signature
[size=1em]Signature ok
[size=1em]Certificate Details:
[size=1em] Serial Number: 1 (0x1)
[size=1em] Validity
[size=1em] Not Before: Nov 15 03:15:54 2016 GMT
[size=1em] Not After : Nov 15 03:15:54 2017 GMT
[size=1em] Subject:
[size=1em] countryName = CN
[size=1em] stateOrProvinceName = SH
[size=1em] organizationName = DZH
[size=1em] organizationalUnitName = Ops
[size=1em] commonName = www.wlm.com
[size=1em] emailAddress = mail.wlm.com
[size=1em] X509v3 extensions:
[size=1em] X509v3 Basic Constraints:
[size=1em] CA:FALSE
[size=1em] Netscape Comment:
[size=1em] OpenSSL Generated Certificate
[size=1em] X509v3 Subject Key Identifier:
[size=1em] 49:7A:99:41:6E:72:27:8F:B8:F0:C3:77:6C:B8:8B:C0:9F:C7:7D:2A
[size=1em] X509v3 Authority Key Identifier:
[size=1em] keyid:A8:28:9A:3B:91:A9:4C:90:A4:08:3D:79:34:0D:D3:19:0E:68:6F:1A
[size=1em]Certificate is to be certified until Nov 15 03:15:54 2017 GMT (365 days)
[size=1em]Sign the certificate? [y/n]:y
[size=1em]1 out of 1 certificate requests certified, commit? [y/n]y
[size=1em]Write out database with 1 new entries
[size=1em]Data Base Updated
[size=1em][iyunv@wlm tmp]# cd /etc/pki/CA/
[size=1em][iyunv@wlm CA]# ls
[size=1em]cacert.pem crl index.txt.attr newcerts serial
[size=1em]certs index.txt index.txt.old private serial.old
[size=1em][iyunv@wlm CA]# cat index.txt #查看第一个签发的证书
[size=1em]V 171115031554Z 01 unknown /C=CN/ST=SH/O=DZH/OU=Ops/CN=www.wlm.com/emailAddress=mail.wlm.com
|
(5)把签署好的证书发还给请求者 [size=1em]1
[size=1em]2
[size=1em]3
[size=1em]4
[size=1em]5
[size=1em]6
[size=1em]7
[size=1em]8
| [size=1em][iyunv@wlm CA]#
[size=1em][iyunv@wlm CA]# pwd
[size=1em]/etc/pki/CA
[size=1em][iyunv@wlm CA]# scp certs/httpd.crt root@10.10.10.4:/etc/httpd/ssl/ # 发送证书
[size=1em]root@192.168.208.130's password:
[size=1em]httpd.crt 100% 5781 5.7KB/s 00:00
[size=1em][iyunv@wlm CA]# ls /etc/httpd/ssl/
[size=1em]httpd.crt httpd.csr httpd.key root@192.168.208.130 # 查看已经签发好的证书
|
2、配置httpd支持使用ssl,及使用的证书;
(1)安装支持ssl的模块
1
| [iyunv@wlm CA]# yum install -y mod_ssl
|
(2)修改配置文件
1
2
3
4
5
6
| vim /etc/httpd/conf.d/ssl.conf
<VirtualHost _default_:443>
DocumentRoot "/var/www/html"
ServerName www.wlm.com:443
SSLCertificateFile /etc/httpd/ssl/httpd.crt
SSLCertificateKeyFile /etc/httpd/ssl/httpd.key
|
(3) 测试基于https访问相应的主机;
重启httpd服务
1
2
| Linux命令行测试命令:
# openssl s_client [-connect host:port] [-cert filename] [-CApath directory] [-CAfile filename]
|
浏览器:
|