测试浏览器与OpenSSL的双向认证
一、背景
在安全级别要求高的项目中,我们可能采取双向SSL认证的方案来保证数据在通信的过程中的安全。
二、原理
双向SSL认证需要客户端和服务器端都需要证书,并且证书都是同一个CA颁发的。认证的过程会互相认证,从而确定对方的身份是否合法。双向认证生成的密钥被用来加密数据,保证客户端与服务器端的通信数据私密性。
三、测试过程
3.1)安装OpenSSL
打开终端,进入解压后的OpenSSL目录。运行下面的命令
./config --prefix=/usr/local/ssl && make && make install
如果需要更多OpenSSL功能,则需要更多的编译参数。具体的编译参数可以通过在终端输入./config –help 来查看。如下所示:
[root@localhostopenssl-1.0.1c-mp]# ./config --help
Operatingsystem: x86_64-whatever-linux2
Configuringfor linux-x86_64
Usage: Configure [no-<cipher> ...][enable-<cipher> ...] [experimental-<cipher> ...] [-Dxxx] [-lxxx][-Lxxx] [-fxxx] [-Kxxx] [no-hw-xxx|no-hw] [[no-]threads] [[no-]shared][[no-]zlib|zlib-dynamic] [no-asm] [no-dso] [no-krb5] [sctp] [386][--prefix=DIR] [--openssldir=OPENSSLDIR] [--with-xxx[=vvv]] [--test-sanity]os/compiler[:flags]
其中shared 和threads 是用的比较多的参数。分别表示安装后的OpenSSL有动态库、OpenSSL支持多线程。
3.2)生成证书
在Linux环境中制作证书。其中rsa1.key为私钥证书,rsa1.cer为公钥证书。具体生成证书可参考http://blog.csdn.net/xu_0705/article/details/34435445。
把生成的rsa1.p12拷贝到Windows系统。
opensslpkcs12 -export -inkey rsa1.key -in rsa1.cer -out rsa1.p12
Enter Export Password:(输入密码)
Verifying - Enter Export Password:(输入密码)
3.3)导入证书
双击rsa1.p12证书。
浏览rsa1.p12证书。
输入生成rsa1.p12时的密码。
选择证书存放路径。
选择”个人“存储方式。
导入证书成功!
3.4)服务器端运行OpenSSL
[root@localhost bin]# ./ s_server -cert cert/rsa/rsa2.cer -key cert/rsa/rsa2.key -www -port 443 -Verify 1 -CAfile cert/rsa/rsaca.cerverify depth is 1, must return acertificate
Using default temp DH parameters
Using default temp ECDH parameters
ACCEPT
3.5)在浏览器中地址栏中输入: https服务器IP:443
弹出如下的框,选择rsa1证书。
选择“高级”
选择“继续前往”
3.6)浏览器输出如下信息:
s_server -cert cert/rsa/rsa2.cer -key cert/rsa/rsa2.key -www -port 443 -Verify 1 -CAfile cert/rsa/rsaca.cerSecure Renegotiation IS supportedCiphers supported in s_server binaryTLSv1/SSLv3:ECDHE-RSA-AES256-GCM-SHA384TLSv1/SSLv3:ECDHE-ECDSA-AES256-GCM-SHA384TLSv1/SSLv3:ECDHE-RSA-AES256-SHA384 TLSv1/SSLv3:ECDHE-ECDSA-AES256-SHA384TLSv1/SSLv3:ECDHE-RSA-AES256-SHA TLSv1/SSLv3:ECDHE-ECDSA-AES256-SHATLSv1/SSLv3:DHE-DSS-AES256-GCM-SHA384TLSv1/SSLv3:DHE-RSA-AES256-GCM-SHA384TLSv1/SSLv3:DHE-RSA-AES256-SHA256 TLSv1/SSLv3:DHE-DSS-AES256-SHA256TLSv1/SSLv3:DHE-RSA-AES256-SHA TLSv1/SSLv3:DHE-DSS-AES256-SHATLSv1/SSLv3:DHE-RSA-CAMELLIA256-SHA TLSv1/SSLv3:DHE-DSS-CAMELLIA256-SHATLSv1/SSLv3:ECDH-RSA-AES256-GCM-SHA384TLSv1/SSLv3:ECDH-ECDSA-AES256-GCM-SHA384TLSv1/SSLv3:ECDH-RSA-AES256-SHA384 TLSv1/SSLv3:ECDH-ECDSA-AES256-SHA384TLSv1/SSLv3:ECDH-RSA-AES256-SHA TLSv1/SSLv3:ECDH-ECDSA-AES256-SHATLSv1/SSLv3:AES256-GCM-SHA384 TLSv1/SSLv3:AES256-SHA256TLSv1/SSLv3:AES256-SHA TLSv1/SSLv3:CAMELLIA256-SHATLSv1/SSLv3:PSK-AES256-CBC-SHA TLSv1/SSLv3:ECDHE-RSA-AES128-GCM-SHA256TLSv1/SSLv3:ECDHE-ECDSA-AES128-GCM-SHA256TLSv1/SSLv3:ECDHE-RSA-AES128-SHA256TLSv1/SSLv3:ECDHE-ECDSA-AES128-SHA256TLSv1/SSLv3:ECDHE-RSA-AES128-SHATLSv1/SSLv3:ECDHE-ECDSA-AES128-SHA TLSv1/SSLv3:DHE-DSS-AES128-GCM-SHA256TLSv1/SSLv3:DHE-RSA-AES128-GCM-SHA256TLSv1/SSLv3:DHE-RSA-AES128-SHA256TLSv1/SSLv3:DHE-DSS-AES128-SHA256 TLSv1/SSLv3:DHE-RSA-AES128-SHATLSv1/SSLv3:DHE-DSS-AES128-SHA TLSv1/SSLv3:ECDHE-RSA-DES-CBC3-SHATLSv1/SSLv3:ECDHE-ECDSA-DES-CBC3-SHA TLSv1/SSLv3:DHE-RSA-SEED-SHATLSv1/SSLv3:DHE-DSS-SEED-SHA TLSv1/SSLv3:DHE-RSA-CAMELLIA128-SHATLSv1/SSLv3:DHE-DSS-CAMELLIA128-SHA TLSv1/SSLv3:EDH-RSA-DES-CBC3-SHATLSv1/SSLv3:EDH-DSS-DES-CBC3-SHA TLSv1/SSLv3:ECDH-RSA-AES128-GCM-SHA256TLSv1/SSLv3:ECDH-ECDSA-AES128-GCM-SHA256TLSv1/SSLv3:ECDH-RSA-AES128-SHA256TLSv1/SSLv3:ECDH-ECDSA-AES128-SHA256 TLSv1/SSLv3:ECDH-RSA-AES128-SHATLSv1/SSLv3:ECDH-ECDSA-AES128-SHA TLSv1/SSLv3:ECDH-RSA-DES-CBC3-SHATLSv1/SSLv3:ECDH-ECDSA-DES-CBC3-SHA TLSv1/SSLv3:AES128-GCM-SHA256TLSv1/SSLv3:AES128-SHA256 TLSv1/SSLv3:AES128-SHATLSv1/SSLv3:SEED-SHA TLSv1/SSLv3:CAMELLIA128-SHATLSv1/SSLv3:DES-CBC3-SHA TLSv1/SSLv3:IDEA-CBC-SHATLSv1/SSLv3:PSK-AES128-CBC-SHA TLSv1/SSLv3:PSK-3DES-EDE-CBC-SHATLSv1/SSLv3:KRB5-IDEA-CBC-SHA TLSv1/SSLv3:KRB5-DES-CBC3-SHATLSv1/SSLv3:KRB5-IDEA-CBC-MD5 TLSv1/SSLv3:KRB5-DES-CBC3-MD5TLSv1/SSLv3:ECDHE-RSA-RC4-SHA TLSv1/SSLv3:ECDHE-ECDSA-RC4-SHATLSv1/SSLv3:ECDH-RSA-RC4-SHA TLSv1/SSLv3:ECDH-ECDSA-RC4-SHATLSv1/SSLv3:RC4-SHA TLSv1/SSLv3:RC4-MD5TLSv1/SSLv3:PSK-RC4-SHA TLSv1/SSLv3:KRB5-RC4-SHATLSv1/SSLv3:KRB5-RC4-MD5---Ciphers common between both SSL end points:ECDHE-ECDSA-AES128-GCM-SHA256 ECDHE-RSA-AES128-GCM-SHA256 ECDHE-ECDSA-AES256-GCM-SHA384ECDHE-RSA-AES256-GCM-SHA384 ECDHE-RSA-AES128-SHA ECDHE-RSA-AES256-SHAAES128-GCM-SHA256 AES256-GCM-SHA384 AES128-SHAAES256-SHA DES-CBC3-SHA---New, TLSv1/SSLv3, Cipher is ECDHE-RSA-AES128-GCM-SHA256SSL-Session:Protocol : TLSv1.2
Cipher : ECDHE-RSA-AES128-GCM-SHA256
Session-ID:Session-ID-ctx: 01000000Master-Key: 420A5C32CF8400962FF01388F1DD9A7C2950F88CD4C2585D77752D7FE59BA9FD3CCCFB2E289FBEA8B384349202F1F975Key-Arg : NoneKrb5 Principal: NonePSK identity: NonePSK identity hint: NoneStart Time: 1501499886Timeout : 300 (sec)Verify return code: 0 (ok)---0 items in the session cache0 client connects (SSL_connect())0 client renegotiates (SSL_connect())0 client connects that finished5 server accepts (SSL_accept())0 server renegotiates (SSL_accept())2 server accepts that finished0 session cache hits0 session cache misses0 session cache timeouts0 callback cache hits0 cache full overflows (128 allowed)---Client certificate省略。。。。。。。。。。