双向认证:
单向认证:
这就完成了客户端和服务器之间通信的安全问题,但是单向认证没有验证客户端的合法性。
在OpenSSL的安装目录下的misc目录下,运行脚本sudo ./CA.sh -newCA。运行完后会生成一个demoCA的目录,里面存放了CA的证书和私钥。在serial文件中写入第一个序列号“01”。
生成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 ca/ca-cert.pem -CAkey ca/ca-key.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 ca/ca-cert.pem -CAkey ca/ca-key.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
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
出现错误
产生的原因是:
This thing happens when certificates share common data. You cannot have two
certificates that look otherwise the same.
方法一:
修改demoCA下 index.txt.attr
将
改为
方法二:
删除demoCA下的index.txt,并再touch下
方法三:
将 common name设置成不同的
genrsa -des3 -out server.key 1024
openssl req -new -key server.key -out server.csr