在特殊情况下,我们需要使用TLS的双向认证,大部分网站都是支持双向认证的,但是并不是强制的。
在连接网站时,我们只关注这个网站是不是经过认证的网站,而不是钓鱼网站。但很少有网站要求,客户端必须是我允许的,经过我认证的,才可以连接。
在此我们对双向验证做个测试,使用的公司必须进行双向认证的服务器。
测试分为三个:
1、不带证书,连接服务器
2、带错误证书,连接服务器
3、带正确证书连接服务器
测试准备
操作工具:OPENSSL 可自行下载安装。
自签名证书,自签名证书的私钥
不带证书访问服务器
连接服务器
OPENSSL 指令,此处服务器地址无法公示。
1 | openssl s_client -host ******** -port 443 -showcerts -msg -state -tls1_2 |
证书验证结果
1 2 3 4 | --- SSL handshake has read 3490 bytes and written 324 bytes Verification error: unable to get local issuer certificate --- |
由于涉及到公司信息,证书验证过程信息就不公示了。
从验证结果上看,无法确认客户端,因为我们证书就没有上传。
访问网站结果
1 2 3 4 5 6 7 8 9 10 | GET /HTTP/V1.0/index.html <html> <head><title>400 No required SSL certificate was sent</title></head> <body bgcolor="white"> <center><h1>400 Bad Request</h1></center> <center>No required SSL certificate was sent</center> <hr><center>nginx/1.13.3</center> </body> </html> |
从访问的结果上看,服务器请求客户端证书,但是没有请求到。 所以无法访问。
带错误证书访问
连接服务器
OPENSSL 指令,此处服务器地址无法公示。此处使用的证书,是自签名使用OPENSSL生成的。
1 | openssl s_client -host ********* -port 443 -showcerts -msg -state -tls1_2 -cert c:\working\key\123\client\client.crt -key c:\working\key\123\client\client.key |
证书验证结果
1 2 3 4 | --- SSL handshake has read 4242 bytes and written 1338 bytes Verification error: unable to get local issuer certificate --- |
由于涉及到公司信息,证书验证过程信息就不公示了。
从验证结果上看,无法确认客户端。
由于我们的证书是自签名的,未经权威机构签名,所以无法识别。
访问网站结果
1 2 3 4 5 6 7 8 9 10 | GET /HTTP/V1.0/index.html <html> <head><title>400 The SSL certificate error</title></head> <body bgcolor="white"> <center><h1>400 Bad Request</h1></center> <center>The SSL certificate error</center> <hr><center>nginx/1.13.3</center> </body> </html> |
访问网站时,返回SSL 验证错误。
带服务器允许的自签名证书访问
连接服务器
OPENSSL 指令,此处服务器地址无法公示。此处使用的证书,是自签名使用OPENSSL生成的。但是已经将签名时的ca.crt放在了服务器上,服务器允许此ca.crt签名的证书访问。
1 | openssl s_client -host ********** -port 443 -showcerts -msg -state -tls1_2 -cert c:\working\key\client.pem -key c:\working\key\client_rsa_key_private.pem |
证书验证结果
1 2 3 4 | --- SSL handshake has read 4242 bytes and written 1338 bytes Verification error: unable to get local issuer certificate --- |
由于涉及到公司信息,证书验证过程信息就不公示了。
从验证结果上看,无法确认客户端。
由于我们的证书是自签名的,未经权威机构签名,所以无法识别。
访问网站结果
1 2 3 4 5 6 7 8 9 | GET /HTTP/V1.0/index.html <html> <head><title>404 Not Found</title></head> <body bgcolor="white"> <center><h1>404 Not Found</h1></center> <hr><center>nginx/1.13.3</center> </body> </html> |
由于我们访问的页面不存在,所以返回数据为 Not Found. 但是,网站我们是可以访问的。
如果大家想要证书验证的过程,以及wireshark的抓包,可以给我一个必须双向验证通过才能访问内容的网站,我再同步过程数据。
以上过程中使用的OPENSSL命令以及参数,就可以看到整个过程。