双向认证:
单向认证:
这就完成了客户端和服务器之间通信的安全问题,但是单向认证没有验证客户端的合法性。
在OpenSSL的安装目录下的misc目录下,运行脚本
% /usr/local/ssl/misc/CA.sh -newca
生成server证书
1.创建私钥 :
% openssl genrsa -out server/server-key.pem 1024
2.创建证书请求 :
% openssl req -new -out server/server-req.csr -key server/server-key.pem
-----
Country Name (2 letter code) [AU]:cn
State or Province Name (full name) [Some-State]:bj
Locality Name (eg, city) []:bj
Organization Name (eg, company) [Internet Widgits Pty Ltd]:tb
Organizational Unit Name (eg, section) []:tb
Common Name (eg, YOUR name) []:localhost #此处一定要写服务器所在ip
Email Address []:[email protected]
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
3.自签署证书 :
% openssl x509 -req -in server/server-req.csr -out server/server-cert.pem -signkey server/server-key.pem -CA demoCA/cacert.pem -CAkey demoCA/private/cakey.pem -CAcreateserial -days 3650
4.将证书导出成浏览器支持的.p12格式 :
% openssl pkcs12 -export -clcerts -in server/server-cert.pem -inkey server/server-key.pem -out server/server.p12
密码:123456
1.创建私钥 :
% openssl genrsa -out client/client-key.pem 1024
2.创建证书请求 :
% openssl req -new -out client/client-req.csr -key client/client-key.pem
-----
Country Name (2 letter code) [AU]:cn
State or Province Name (full name) [Some-State]:bj
Locality Name (eg, city) []:bj
Organization Name (eg, company) [Internet Widgits Pty Ltd]:tb
Organizational Unit Name (eg, section) []:tb
Common Name (eg, YOUR name) []:dong
Email Address []:[email protected]
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
3.自签署证书 :
% openssl x509 -req -in client/client-req.csr -out client/client-cert.pem -signkey client/client-key.pem -CA demoCA/cacert.pem -CAkey demoCA/private/cakey.pem -CAcreateserial -days 3650
4.将证书导出成浏览器支持的.p12格式 :
% openssl pkcs12 -export -clcerts -in client/client-cert.pem -inkey client/client-key.pem -out client/client.p12
密码:123456
验证可以:openssl verify -CAfile /etc/ins/ca.crt /etc/ins/client.crt
生成 apache ssl 证书
% cp server/server-req.csr newreq.pem
/usr/local/ssl/misc/CA.sh -sign
创建 apache 需要 ssl 证书内容:
% mkdir ssl
% cp newcert.pem ssl/server.crt
% cp demoCA/cacert.pem ssl/cacert.pem
同时复制一份证书:
% cp demoCA/cacert.pem ssl/ca.crt
apache配置
% vi /usr/local/apache/conf/extra/ssl.conf
# 指定服务器证书位置
SSLCertificateFile /usr/local/apache/conf/ssl/server.crt
# 指定服务器证书key位置
SSLCertificateKeyFile /usr/local/apache/conf/ssl/server.key
# 证书目录
SSLCACertificatePath /usr/local/apache/conf/ssl
# 根证书位置
SSLCACertificateFile /usr/local/apache/conf/ssl/cacert.pem
% vi /usr/local/apache/conf/extra/httpd_vhosts.conf
listen 443 https
NameVirtualHost *:443
DocumentRoot "/home/zhangy/www/metbee/trunk/src/web"
ServerName *:443
ErrorLog "/home/zhangy/apache/www.metbee.com-error.log"
CustomLog "/home/zhangy/apache/www.metbee.com-access.log" common
Include conf/extra/ssl.conf
来源
http://zhumeng8337797.blog.163.com/blog/static/10076891420133130138156/
...