Mac openssl 开发环境测试
准备工作
1. 别人给我的他在 ubuntu 下的 openssl 1.0.2o以及他自己写的 client.c,server.c ,他生成的证书等
2. 我的重点在于搭建一个可以测试 client.c 程序的服务器环境
3. 把他提供的程序、证书都放到 /Users/dhbm/Desktop/lxn/lxntransfer/tests
创建一个 openssl 服务器
1、参考:http://www.cnblogs.com/aixiaoxiaoyu/articles/8796410.html
2、进入存放证书、公钥、私钥 的目录
服务端 (/Users/dhbm/Desktop/lxn/lxntransfer/tests)
cd /Users/dhbm/Desktop/lxn/lxntransfer/tests
3、openssl s_server -key server-key.pem -cert server-cert.pem
参数说明:
-cert filename
证书文件名
-key filename
私钥文件
运行结果:
Using default temp DH parameters
ACCEPT
建立客户端
连接到 openssl 服务器(Mac 的 openssl s_server缺省端口是 4433)
1、参考:http://www.cnblogs.com/aixiaoxiaoyu/articles/8796398.html
客户端证书位置 (/Users/dhbm/Desktop/lxn/lxntransfer/testc)
cd /Users/dhbm/Desktop/lxn/lxntransfer/testc
2、本机测试
openssl s_client -connect 127.0.0.1:4433
或者本机ip (我的ip是 192.168.1.100 以下列举我的几个虚拟机ip,纯粹为了我自己 copy 方便)
openssl s_client -connect 192.168.1.199:4433
openssl s_client -connect 192.168.1.166:4433
openssl s_client -connect 192.168.1.177:4433
openssl s_client -connect 192.168.1.100:4433
运行结果
Server is connect to you!
有个疑问:为什么不用加上 key cert 参数?自己就能找到?
4、连接另一个服务器,另一个端口测试
s_client -connect 192.168.1.166:5060
别人提供的 ubuntu 服务器,server.c编译运行在 192.168.1.166,端口是 5060
5、运行结果
没有带上参数的时候,错误信息
find a customer to try to connect
can not find the customer's certificate
完整命令
** 只是为了自己操作方便,所以按照自己的环境复制,留在这里,每次直接从这里 copy
cd /Users/dhbm/Desktop/lxn/lxntransfer/testc
openssl s_client -connect 192.168.1.166:5060 -key client-key.pem -cert client-cert.pem
运行结果
Server is connect to you!
openssl s_client -connect 192.168.1.100:4433 -key client-key.pem -cert client-cert.pem
运行结果:
同上!
客户端的输入发送(回车),在 2 端都是显示出来
openssl s_client -connect 192.168.1.199:4433 -key client-key.pem -cert client-cert.pem
openssl s_client -connect 127.0.0.1:4433 -key client-key.pem -cert client-cert.pem
运行结果:
同上!
客户端的输入发送(回车),在 2 端都是显示出来