SSL 双向认证
利用OpenSSL生成库和命令程序,在生成的命令程序中包括对加/解密算法的测试,openssl程序,ca程序.利用openssl,ca可生成用于C/S模式的证书文件以及CA文件.下面以C/S模式说明证书文件的生成步骤:
证书文件生成:
一.服务器端
1.生成服务器端的私钥(key文件);
openssl genrsa -des3 -out server.key 1024
运行时会提示输入密码,此密码用于加密key文件(参数des3是加密算法,也可以选用其他安全的算法),以后每当需读取此文件(通过openssl提供的命令或API)都需输入口令.如果不要口令,则可用以下命令去除口令:
openssl rsa -in server.key -out server.key
2.生成服务器端证书签名请求文件(csr文件);
openssl req -new -key server.key -out server.csr
生成Certificate Signing Request(CSR),生成的csr文件交给CA签名后形成服务端自己的证书.屏幕上将有提示,依照其 提示一步一步输入要求的个人信息即可(如:Country,province,city,company等).
二.客户端
1.对客户端也作同样的命令生成key及csr文件;
openssl genrsa -des3 -out client.key 1024
openssl req -new -key client.key -out client.csr
三.生成CA证书文件
server.csr与client.csr文件必须有CA的签名才可形成证书.
1.首先生成CA的key文件:
openssl genrsa -des3 -out ca.key 1024
2.生成CA自签名证书:
openssl req -new -x509 -key ca.key -out ca.crt
可以加证书过期时间选项 "-days 365".
四.利用CA证书进行签名
用生成的CA证书为server.csr,client.csr文件签名,利用openssl中附带的CA.pl文件(在安装目录中openssl/apps目录下),
1.ca.pl -newca, 在提示输入已有的证书文件时,输入上面已生成的ca.crt证书文件;
2.生成服务端证书文件
Openssl ca -in server.csr -out server.crt -cert ca.crt -keyfile ca.key -config openssl.cnf
3.生成客户端证书文件
Openssl ca -in client.csr -out client.crt -cert ca.crt -keyfile ca.key -config openssl.cnf
必须保证openssl.cnf在当前目录下,这个文件可以在apps目录中找到.
1.首先要生成服务器端的私钥(key文件):
[root@qiujicai.com~/ssl]#openssl genrsa -des3 -out server.key 1024
运行时会提示输入密码,此密码用于加密key文件(参数des3便是指加密算法,当然也可以选用其他你认为安全的算法.),以后每当需读取此文件(通过openssl提供的命令或API)都需输入口令.如果觉得不方便,也可以去除这个口令,但一定要采取其他的保护措施!
去除key文件口令的命令:
[root@qiujicai.com~/ssl]#openssl rsa -in server.key -out server.key
2.用server.key生成一个证书:
[root@qiujicai.com~/ssl]#openssl req -new -key server.key -out server.csr
Enter pass phrase for server.key:12345
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) [AU]:CN
State or Province Name (full name) [Some-State]:china
Locality Name (eg, city) []:Zhuhai
Organization Name (eg, company) [Internet Widgits Pty Ltd]:xxxx Ltd....
Organizational Unit Name (eg, section) []:jecks
Common Name (eg, YOUR name) []:www.qiuicai.com
Email Address []:xxx@qiujicai.com
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:12345
An optional company name []:xxx@qiujicai.com
生成Certificate Signing Request(CSR),生成的csr文件交给CA签名后形成服务端自己的证书.屏幕上将有提示,依照其指示一步一步输入要求的个人信息即可.
3.对客户端也作同样的命令生成key及csr文件(在这两步写在一起):
A: [root@qiujicai.com~/ssl]#openssl genrsa -des3 -out client.key 1024
Generating RSA private key, 1024 bit long modulus
...........++++++
..++++++
e is 65537 (0x10001)
Enter pass phrase for client.key:12345
Verifying - Enter pass phrase for client.key:12345
B: [root@qiujicai.com~/ssl]# openssl req -new -key client.key -out client.csr
Enter pass phrase for client.key:12345
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) [AU]:CN
State or Province Name (full name) [Some-State]:china
Locality Name (eg, city) []:Zhuhai
Organization Name (eg, company) [Internet Widgits Pty Ltd]:xxxx Ltd....
Organizational Unit Name (eg, section) []:jecks
Common Name (eg, YOUR name) []:www.qiuicai.com
Email Address []:xxx@qiujicai.com
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:12345
An optional company name []:xxx@qiujicai.com
4.生成的CSR证书文件必须有CA的签名才可形成证书.这时生成一个KEY文件ca.key 和根证书ca.crt
[root@qiujicai.com~/ssl]# openssl req -new -x509 -keyout ca.key -out ca.crt
Generating a 1024 bit RSA private key
...++++++
...................++++++
writing new private key to 'ca.key'
Enter PEM pass phrase:12345
Verifying - Enter PEM pass phrase:
-----
Country Name (2 letter code) [AU]:CN
State or Province Name (full name) [Some-State]:china
Locality Name (eg, city) []:Zhuhai
Organization Name (eg, company) [Internet Widgits Pty Ltd]:xxxx Ltd....
Organizational Unit Name (eg, section) []:jecks
Common Name (eg, YOUR name) []:www.qiuicai.com
Email Address []:xxx@qiujicai.com
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:12345
An optional company name []:xxx@qiujicai.com
5.用生成的CA的证书为刚才生成的server.csr,client.csr文件签名(这也是两写在一起):
A: [root@qiujicai.com~/ssl]# openssl ca -in server.csr -out server.crt -cert ca.crt -keyfile ca.key
Using configuration from openssl.cnf
Enter pass phrase for ca.key:
Check that the request matches the signature
Signature ok
Certificate Details:
Serial Number: 1 (0x1)
Validity
Not Before: Feb 26 04:15:02 2010 GMT
Not After : Feb 26 04:15:02 2011 GMT
Subject:
countryName = CN
stateOrProvinceName = china
organizationName = xxx.Ltd.C
organizationalUnitName = jecks
commonName = www.qiujicai.com
X509v3 extensions:
X509v3 Basic Constraints:
CA:FALSE
Netscape Comment:
OpenSSL Generated Certificate
X509v3 Subject Key Identifier:
30:70:D2:EB:9B:73:AE:7B:0E:8E:F6:94:33:7C:53:5B:EF:93:FC:38
X509v3 Authority Key Identifier:
keyid:DB:D6:83:BB:7F:28:C2:A9:40:6A:D8:32:FC:01:E0:5C:48:27:51:19
Certificate is to be certified until Feb 26 04:15:02 2010 GMT (365 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
B: [root@qiujicai.com~/ssl]#openssl ca -in client.csr -out client.crt -cert ca.crt -keyfile ca.key
[root@airwaySSL bin]# openssl ca -in client.csr -out client.crt -cert ca.crt -keyfile ca.key -config openssl.cnf
Using configuration from openssl.cnf
Enter pass phrase for ca.key:
Check that the request matches the signature
Signature ok
The countryName field needed to be the same in the
CA certificate (CN) and the request (cn)
..................
另外,这个certificate是BASE64形式的,要转成PKCS12才能装到IE,/NETSCAPE上.所以还要:
[root@qiujicai.com~/ssl]# openssl pkcs12 -export -in client.pem -inkey client.key -out client.pfx
Enter pass phrase for client.key:
Enter Export Password: # 设置client.pfx密码
Verifying - Enter Export Password:
现在我们所需的全部文件便生成了.
另:
client使用的文件有:ca.crt,client.crt,client.key,client.pfx
server使用的文件有:ca.crt,server.crt,server.key
6.最后
编辑/etc/apache2/sites-enabled/000-default
NameVirtualHost *:443
ServerSignature
OnSSLEngine On
SSLCertificateFile /usr/local/apache/conf/ssl.crt/server.crt #指定服务器证书位置
SSLCertificateKeyFile /usr/local/apache/conf/ssl.crt/server.key #指定服务器证书key位置
SSLCACertificatePath /usr/local/apache/conf/ssl.crt #证书目录
SSLCACertificateFile /usr/local/apache/conf/ssl.crt/ca.csr #根证书位置
#开启客户端SSL请求
SSLVerifyClient require
SSLVerifyDepth 1
ServerAdmin webmaster@localhost
ServerName www.qiujicai.com
DocumentRoot /var/www/test
ErrorDocument 404 http://www.qiujicai.com/err.php
Options FollowSymLinks
AllowOverride None
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
证书安装及使用
把
刚才生成的证书:根证书ca.crt和客户证书client.crt(client.pfx)安装到客户端,
ca.crt安装到信任的机构,client.crt直接在windows安装或安装到个人证书位置,然后用IP访问HTTP和https服务器。在IE
中我们一般导入client.pfx证书,导入时会提示上面设置的密码。
转载:http://blog.chinaunix.net/uid-26760055-id-3128132.html
SSL 双向认证的更多相关文章
- tomcat配置SSL双向认证
一.SSL简单介绍 SSL(Secure Sockets Layer 安全套接层)就是一种协议(规范),用于保障客户端和服务器端通信的安全,以免通信时传输的信息被窃取或者修改. 怎样保障数据传输安全? ...
- SSL双向认证java实现(转)
本文通过模拟场景,介绍SSL双向认证的java实现 默认的情况下,我认为读者已经对SSL原理有一定的了解,所以文章中对SSL的原理,不做详细的介绍. 如果有这个需要,那么通过GOOGLE,可以搜索到很 ...
- SSL双向认证(高清版)
介绍了SSL双向认证的一些基本问题,以及使用Nginx+PHP基于它搭建https的Webservice. 之前的方式只是实现1:1的模式,昨天同事继续实现了n:1的模式,这里我再整理记录下. 由于n ...
- Nginx、SSL双向认证、PHP、SOAP、Webservice、https
本文是1:1模式,N:1模式请参见新的一篇博客<SSL双向认证(高清版)> ----------------------------------------------------- 我是 ...
- apache用户认证,ssl双向认证配置
安装环境: OS:contos 6.4 httpd:httpd-2.2.15-59.el6.centos.i686.rpm openssl:openssl-1.0.1e-57.el6.i686.rpm ...
- ssl双向认证
ssl双向认证 一.背景知识 1.名词解释 ca.key: 根证书的私钥 , ca.crt: 根证书的签名证书 server.key, server.crt client.key, client.cr ...
- SSL双向认证和SSL单向认证的流程和区别
refs: SSL双向认证和SSL单向认证的区别https://www.jianshu.com/p/fb5fe0165ef2 图解 https 单向认证和双向认证!https://cloud.tenc ...
- php实现https(tls/ssl)双向认证
php实现https(tls/ssl)双向认证 通常情况下,在部署https的时候,是基于ssl单向认证的,也就是说只要客户端认证服务器,而服务器不需要认证客户端. 但在一些安全性较高的场景,如银行, ...
- nginx支持ssl双向认证配置
nginx支持ssl双向认证配置 listen 443; server_name test.com; ssl on; ssl_certificate server.crt; //server端公钥 s ...
- php使用curl库进行ssl双向认证
官方文档: http://www.php.net/manual/zh/function.curl-setopt.php#10692 官方举例: <?phpcurl_setopt($ch, CUR ...
随机推荐
- HDU 1072/BFS
题目链接 Nightmare Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
- 最小点集覆盖=最大匹配<二分图>/证明
来源 最小点集覆盖==最大匹配. 首先,最小点集覆盖一定>=最大匹配,因为假设最大匹配为n,那么我们就得到了n条互不相邻的边,光覆盖这些边就要用到n个点. 现在我们来思考为什么最小点击覆盖一定& ...
- centos6.5 安装git
1.安装编译git时需要的包 # yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel # yum ins ...
- Firebase 相关
谷歌在 2016年 I/O 大会上推出了 Firebase 的新版本.Firebase 平台提供了为移动端(iOS和Android)和 Web 端创建后端架构的完整解决方案. 从一开始的移动后端即服务 ...
- mysql问题总结,远程登录
http://blog.sina.com.cn/s/blog_4550f3ca0101axzd.html 更改mysql数据库的数据库名 http://tech.sina.com.cn/s/s/200 ...
- apache-tomcat-7.0.70无法进入Manager管理App项目
在tomcat文件夹找到conf文件夹中的tomcat-user.xml文件,用记事本打开,在最下面可以看到tomcat默认把用户注释掉了,也就是说打开tomcat主页是进不去管理页面的.方法如下:找 ...
- Linux学习 -- 启动管理
1 CentOS 6.x启动管理 系统运行级别 运行级别命令 #runlevel 查看级别 #init 运行级别 改变级别 系统默认运行级别 配置文件 /etc/inittab id:3:ini ...
- 河南多校大一训练赛 D
题目链接:http://acm.hust.edu.cn/vjudge/contest/125004#problem/D 密码:acm Description If an integer is not ...
- 转:lr_eval_string函数的用法解析
在LR中,C的变量和LR的参数是不一样的. 任何C的变量都不能被LR的函数直接调用. 应该用lr_eval_string来取值. 比如{NewParam}(LR中参数化的变量)直接用这个引用是没有问题 ...
- oracle 管理
1.管理数据的用户主要是:sys和system. 区别:(1)sys所有oracle的数据字典的基表和视图都存放在sys用户中,这些基表和视图对于oracle是至关重要的,由数据库自己维护,任何用户都 ...