`
sking777
  • 浏览: 24229 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

用openssl创建双向证书

阅读更多
1. 创建根证书密钥文件(自己做CA)root.key:
openssl genrsa -des3 -out root.key
输出内容为:
[lenin@archer ~]$ openssl genrsa -des3 -out root.key
Generating RSA private key, 512 bit long modulus
……………..++++++++++++
..++++++++++++
e is 65537 (0×10001)
Enter pass phrase for root.key: ← 输入一个新密码
Verifying – Enter pass phrase for root.key: ← 重新输入一遍密码
2. 创建根证书的申请文件root.csr:
openssl req -new -key root.key -out root.csr
输出内容为:
[lenin@archer ~]$ openssl req -new -key root.key -out root.csr
Enter pass phrase for root.key: ← 输入前面创建的密码
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 ← 国家代号,中国输入CN
State or Province Name (full name) [Some-State]:BeiJing ← 省的全名,拼音
Locality Name (eg, city) []:BeiJing ← 市的全名,拼音
Organization Name (eg, company) [Internet Widgits Pty Ltd]:MyCompany Corp. ← 公司英文名
Organizational Unit Name (eg, section) []: ← 可以不输入
Common Name (eg, YOUR name) []: ← 此时不输入
Email Address []:admin@mycompany.com ← 电子邮箱,可随意填
Please enter the following ‘extra’ attributes
to be sent with your certificate request
A challenge password []: ← 可以不输入
An optional company name []: ← 可以不输入
3. 创建一个自当前日期起为期十年的根证书root.crt:
openssl x509 -req -days 3650 -sha1 -extensions v3_ca -signkey root.key -in root.req -out root.crt
输出内容为:
[lenin@archer ~]$ openssl x509 -req -days 3650 -sha1 -extensions v3_ca -signkey root.key -in root.csr -out root.crt
Signature ok
subject=/C=CN/ST=BeiJing/L=BeiJing/O=MyCompany Corp./emailAddress=admin@mycompany.com
Getting Private key
Enter pass phrase for root.key: ← 输入前面创建的密码
4. 创建服务器证书密钥server.key:
openssl genrsa –des3 -out server.key 2048
输出内容为:
[lenin@archer ~]$ openssl genrsa -out server.key 2048
Generating RSA private key, 2048 bit long modulus
….+++
…………………………………………..+++
e is 65537 (0×10001)
运行时会提示输入密码,此密码用于加密key文件(参数des3便是指加密算法,当然也可以选用其他你认为安全的算法.),以后每当需读取此文件(通过openssl提供的命令或API)都需输入口令.如果觉得不方便,也可以去除这个口令,但一定要采取其他的保护措施!
去除key文件口令的命令:
openssl rsa -in server.key -out server.key
5.创建服务器证书的申请文件server.csr:
openssl req -new -key server.key -out server.csr
输出内容为:
[lenin@archer ~]$ openssl req -new -key server.key -out server.req
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 ← 国家名称,中国输入CN
State or Province Name (full name) [Some-State]:BeiJing ← 省名,拼音
Locality Name (eg, city) []:BeiJing ← 市名,拼音
Organization Name (eg, company) [Internet Widgits Pty Ltd]:MyCompany Corp. ← 公司英文名
Organizational Unit Name (eg, section) []: ← 可以不输入
Common Name (eg, YOUR name) []:www.mycompany.com ← 服务器主机名,若填写不正确,浏览器会报告证书无效,但并不影响使用
Email Address []:admin@mycompany.com ← 电子邮箱,可随便填
Please enter the following ‘extra’ attributes
to be sent with your certificate request
A challenge password []: ← 可以不输入
An optional company name []: ← 可以不输入
6. 创建自当前日期起有效期为期两年的服务器证书server.crt:
openssl x509 -req -days 730 -sha1 -extensions v3_req -CA root.crt -CAkey root.key -CAserial root.srl -CAcreateserial -in server.csr -out server.crt
输出内容为:
[lenin@archer ~]$ openssl x509 -req -days 730 -sha1 -extensions v3_req -CA root.crt -CAkey root.key -CAcreateserial -in server.csr -out server.crt
Signature ok
subject=/C=CN/ST=BeiJing/L=BeiJing/O=MyCompany Corp./CN=www.mycompany.com/emailAddress=admin@mycompany.com
Getting CA Private Key
Enter pass phrase for root.key: ← 输入前面创建的密码
7. 创建客户端证书密钥文件client.key:
openssl genrsa -des3 -out client.key 2048
输出内容为:
[lenin@archer ~]$ openssl genrsa -des3 -out client.key 2048
Generating RSA private key, 2048 bit long modulus
……………………………………………………………………………..+++
……………………………………………………………………………………………………….+++
e is 65537 (0×10001)
Enter pass phrase for client.key: ← 输入一个新密码
Verifying – Enter pass phrase for client.key: ← 重新输入一遍密码
8. 创建客户端证书的申请文件client.csr:
openssl req -new -key client.key -out client.csr
输出内容为:
[lenin@archer ~]$ openssl req -new -key client.key -out client.csr
Enter pass phrase for client.key: ← 输入上一步中创建的密码
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 ← 国家名称,中国输入CN
State or Province Name (full name) [Some-State]:BeiJing ← 省名称,拼音
Locality Name (eg, city) []:BeiJing ← 市名称,拼音
Organization Name (eg, company) [Internet Widgits Pty Ltd]:MyCompany Corp. ← 公司英文名
Organizational Unit Name (eg, section) []: ← 可以不填
Common Name (eg, YOUR name) []:Lenin ← 自己的英文名,可以随便填
Email Address []:admin@mycompany.com ← 电子邮箱,可以随便填
Please enter the following ‘extra’ attributes
to be sent with your certificate request
A challenge password []: ← 可以不填
An optional company name []: ← 可以不填
9. 创建一个自当前日期起有效期为两年的客户端证书client.crt:
openssl x509 -req -days 730 -sha1 -extensions v3_req -CA root.crt -CAkey root.key -CAserial root.srl -CAcreateserial -in client.csr -out client.crt
输出内容为:
[lenin@archer ~]$ openssl x509 -req -days 730 -sha1 -extensions v3_req -CA root.crt -CAkey root.key -CAcreateserial -in client.csr -out client.crt
Signature ok
subject=/C=CN/ST=BeiJing/L=BeiJing/O=MyCompany Corp./CN=www.mycompany.com/emailAddress=admin@mycompany.com
Getting CA Private Key
Enter pass phrase for root.key: ← 输入上面创建的密码
10. 将客户端证书文件client.crt和客户端证书密钥文件client.key合并成客户端证书安装包client.pfx:
openssl pkcs12 -export -in client.crt -inkey client.key -out client.pfx
输出内容为:
[lenin@archer ~]$ openssl pkcs12 -export -in client.crt -inkey client.key -out client.pfx
Enter pass phrase for client.key: ← 输入上面创建的密码
Enter Export Password: ← 输入一个新的密码,用作客户端证书的保护密码,在客户端安装证书时需要输入此密码
Verifying – Enter Export Password: ← 确认密码
11. 保存生成的文件备用,其中server.crt和server.key是配置单向SSL时需要使用的证书文件,client.crt是配置双向SSL时需要使用的证书文件,client.pfx是配置双向SSL时需要客户端安装的证书文件
.crt文件和.key可以合到一个文件里面,把2个文件合成了一个.pem文件(直接拷贝过去就行了)
分享到:
评论
1 楼 根号九加一 2017-09-02  
怎么部署在welogic上?

相关推荐

    使用 OpenSSL 创建生成CA 证书服务器客户端证书及密钥

    本文将详细介绍如何使用 OpenSSL 创建和管理CA证书、服务器证书和客户端证书,以实现SSL单向认证和双向认证。 首先,我们来看一下如何生成 CA(证书颁发机构)证书。CA证书是信任的根,用于签署其他证书,确保网络...

    用tomcat和openSSL构建https双向认证

    一、创建服务器证书、客户端证书以及CA 1、生成--服务器端--私钥和证书请求 2、生成--客户端-----私钥和证书请求 3、生成CA 4、通过CA签发证书 5、生成pem格式证书 6、生成pkcs12格式证书 二、tomcat实现双向认证 1...

    OpenSSL 一键生成证书

    使用OpenSSL生成服务器证书,首先需要生成服务器私钥,然后创建CSR,最后用CA证书签署这个CSR。一键生成Server证书的功能可以极大地节省时间,减少错误。 3. **Client证书**:客户端证书则用于验证客户端的身份,常...

    使用OpenSSL来制作证书,在IIS中配置HTTPS(SSL)笔记.pdf

    本文档详细介绍了如何使用OpenSSL工具为基于Internet Information Services (IIS) 的Web服务器创建自签名证书的过程,包括生成服务器端证书和客户端证书,以实现双向认证。 #### 二、准备工作 在开始之前,请确保...

    tomcat的双向ssl配置

    2. **创建根证书**:使用`openssl`的`req`命令生成根证书的私钥和CSR,然后用`x509`命令自签发证书。 3. **创建服务器证书**:生成服务器私钥,然后用`req`命令生成CSR,再用根证书的私钥签署这个CSR,得到服务器...

    利用openssl生成CA证书的方法及证书

    2. **创建自签名CA证书(ca.crt)**:基于私钥生成自签名的根证书,使用`openssl req`命令创建证书签名请求,然后用`openssl x509`命令签署它: ``` openssl req -x509 -new -nodes -key ca.key -sha256 -days ...

    OpenSSL创建生成CA证书、服务器、客户端证书及密钥

    本文将详细介绍如何使用OpenSSL来创建生成CA(Certificate Authority)证书、服务器证书和客户端证书以及它们对应的密钥。 首先,我们需要理解证书的基本概念。在SSL/TLS协议中,证书用于验证通信双方的身份,通常...

    https双向认证证书配置详解

    3. **创建证书请求**:使用 `openssl req -new` 命令生成证书签名请求文件(CSR),其中包含了 CA 的基本信息。 4. **自签 CA 证书**:利用 CA 的私钥文件,通过 `openssl x509 -req` 命令来自签署 CA 证书。 5. **...

    openssl ssl 加密 证书

    本文将深入探讨如何在 Windows 32 位平台上使用 OpenSSL 来处理 SSL 加密证书。 ### 1. 证书概述 SSL 证书是包含公钥和身份信息的数据文件,通常由权威的证书颁发机构 (CA) 签名。它验证了服务器的身份,确保用户...

    https双向证书制作详细制作步骤

    - 使用`openssl req`命令,其中`-new`选项表示创建新的CSR文件,`-key`指定私钥文件路径。 - 示例命令:`openssl req -new -key root-key.key -out root-req.csr` - 在创建过程中,会提示输入一些必要的信息,如国家...

    Openssl实现双向认证教程(附服务端客户端代码)

    - 签发证书:对于自签名证书,使用`openssl x509 -req -signkey`命令用自己的私钥签署CSR;如果是CA签发,将CSR提交给CA。 3. **配置OpenSSL上下文** 在C++程序中,你需要创建一个`SSL_CTX`对象来设置双向认证的...

    OpenSSL证书制作过程

    本文详细介绍了使用OpenSSL制作证书的过程,包括自签名CA的创建、服务器证书和客户端证书的颁发,以及如何在J2EE环境中使用这些证书。通过这些步骤,可以构建一个完整的安全通信体系,保障数据传输的安全性和通信...

    OPenssl生成证书.docx

    在本文中,我们将详细探讨如何使用 OpenSSL 生成证书,包括服务器端和客户端的私钥、证书签名请求 (CSR) 以及去除私钥口令的过程。 首先,你需要下载并安装 OpenSSL。安装完成后,确保你在 `/bin` 目录下,然后将 `...

    openssl安装配置(win64版,附ActivePerl安装包和openssl安装包)

    本文将详细讲解如何在Windows 64位系统上安装配置OpenSSL,同时还会涉及到ActivePerl的安装,以及如何使用OpenSSL配置Tomcat SSL双向认证。 首先,我们来看OpenSSL的安装。下载的压缩包中应该包含了适用于Windows ...

    linux-openssl

    4. 证书管理:OpenSSL可以创建自签名证书或处理由权威机构签发的证书,用于SSL/TLS连接的身份验证。 5. 安全通信:在Web服务器上配置OpenSSL,可以实现HTTPS,为HTTP协议提供安全通道,防止数据在传输过程中被窃取或...

    Tomcat6和5.5配置使用SSL双向认证(使用openssl生成密钥).rar

    在这个场景中,我们将探讨如何在Tomcat 6和5.5版本中配置SSL双向认证,并使用openssl工具生成必要的密钥文件。 **一、生成CA证书** 创建一个自签名的根证书颁发机构(Root CA)是SSL双向认证的第一步。这可以通过...

    openssl教程(c语言)

    - 生成自签名证书:使用`openssl req`和`openssl x509`命令创建本地测试证书。 - 验证证书:检查证书的签名、有效期和颁发者信息。 8. **错误处理** - OpenSSL错误栈:了解如何处理OpenSSL的错误,使用`ERR_...

    Openssl Socket实现SSL双向认证连接 -易语言

    总结来说,使用OpenSSL通过Socket实现SSL双向认证连接涉及证书的生成、SSL上下文的配置、Socket连接的建立和SSL握手的执行。在易语言环境下,可以借助提供的库文件和示例代码实现这一功能,从而为网络通信提供安全的...

Global site tag (gtag.js) - Google Analytics