openssl制作CA自签证书

作者: 玄德公笔记 | 来源:发表于2022-01-27 14:01 被阅读0次

@[toc]

1. 根证书

1.1 创建根证书密钥文件(root.key)

[root@n9e-client-01 cert]# openssl genrsa -des3 -out root.key
Generating RSA private key, 2048 bit long modulus
......+++
..................+++
e is 65537 (0x10001)
Enter pass phrase for root.key:
Verifying - Enter pass phrase for root.key:

密码本次 40010355

1.2 创建根证书的申请文件( root.csr)

[root@n9e-client-01 cert]# openssl genrsa -des3 -out root.key
Generating RSA private key, 2048 bit long modulus
......+++
..................+++
e is 65537 (0x10001)
Enter pass phrase for root.key:
Verifying - Enter pass phrase for root.key:
[root@n9e-client-01 cert]# 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) [XX]:CN
State or Province Name (full name) []:BeiJing
Locality Name (eg, city) [Default City]:BeiJing
Organization Name (eg, company) [Default Company Ltd]:XiShu
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) []:
Email Address []:

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:

1.3 创建自己的根证书 (root.crt)

创建一个100年的根证书。

[root@n9e-client-01 cert]# openssl x509 -req -days 36500 -sha1 -extensions v3_ca -signkey root.key -in root.csr -out root.crt
Signature ok
subject=/C=CN/ST=BeiJing/L=BeiJing/O=XiShu
Getting Private key
Enter pass phrase for root.key:

2. 创建服务器证书

2.1 创建服务器证书密钥(server.key)

[root@n9e-client-01 cert]# openssl genrsa -out server.key 2048
Generating RSA private key, 2048 bit long modulus
.......+++
......................................+++
e is 65537 (0x10001)

2.2 创建服务器证书的申请文件(server.csr)

[root@n9e-client-01 cert]# openssl req -new -key server.key -out server.csr
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) [XX]:CN
State or Province Name (full name) []:BeiJing
Locality Name (eg, city) [Default City]:BeiJing
Organization Name (eg, company) [Default Company Ltd]:XiShu
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) []:
Email Address []:

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:

2.3 创建服务器证书(server.crt)

[root@n9e-client-01 cert]# openssl x509 -req -days 3650 -sha1 -extensions v3_req -CA root.crt -CAkey root.key -CAserial root.srl -CAcreateserial -in server.csr -out server.crt
Signature ok
subject=/C=CN/ST=BeiJing/L=BeiJing/O=XiShu
Getting CA Private Key
Enter pass phrase for root.key:

3. 创建客户证书

3.1 创建客户证书 (client.key)

[root@n9e-client-01 cert]# openssl genrsa -des3 -out client.key 2048
Generating RSA private key, 2048 bit long modulus
...............................+++
..........+++
e is 65537 (0x10001)
Enter pass phrase for client.key:
Verifying - Enter pass phrase for client.key:

3.2 创建客户端证书的申请文件(client.csr)

[root@n9e-client-01 cert]# openssl genrsa -des3 -out client.key 2048
Generating RSA private key, 2048 bit long modulus
...............................+++
..........+++
e is 65537 (0x10001)
Enter pass phrase for client.key:
Verifying - Enter pass phrase for client.key:
[root@n9e-client-01 cert]# 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) [XX]:CN
State or Province Name (full name) []:BeiJing
Locality Name (eg, city) [Default City]:BeiJing
Organization Name (eg, company) [Default Company Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) []:
Email Address []:

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:

3.3 创建一个客户端证书(client.crt)

创建一个自即日起,有效期为两年的证书。

[root@n9e-client-01 cert]# 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
Signature ok
subject=/C=CN/ST=BeiJing/L=BeiJing/O=Default Company Ltd
Getting CA Private Key
Enter pass phrase for root.key:

3.4 client.pfx 文件(非必要)

将客户端证书文件client.crt和客户端证书密钥文件client.key合并成客户端证书安装包client.pfx

[root@n9e-client-01 cert]# 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
Signature ok
subject=/C=CN/ST=BeiJing/L=BeiJing/O=Default Company Ltd
Getting CA Private Key
Enter pass phrase for root.key:
[root@n9e-client-01 cert]# 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:

3.5 使用

  • server.crt和server.key是配置单向SSL时需要使用的证书文件
  • client.crt是配置双向SSL时需要使用的证书文件
  • client.pfx是配置双向SSL时需要客户端安装的证书文件

3.6 pem文件(非必要)

如需使用pem文件:
将.crt文件和.key可以合到一个文件里面(直接拷贝过去就行了),2个文件合成了一个.pem文件。

相关文章

  • gRpc 相关

    CA证书自签单向验证Openssl命令 应用 grpc server_http CA证书自签双向验证Openssl...

  • OpenSSL生成SSL证书

    1.制作CA证书 ca.key CA私钥步骤与使用OpenSSL自签发服务器https证书所述大同小异。opens...

  • nginx配置https

    1 使用openssl生成证书 这里我们使用openssl进行CA证书自签,用来学习,有条件的可以让第三方机构进行...

  • 2020-03-23 关于openssl 双向认证

    工作中解决利用Openssl自签名证书,双向认证的总结: 创建文件夹,证书编号存放文件: 生成ca key, 自签...

  • nginx ssl双向认证实战

    本次实验所使用操作系统为Ubuntu20.04,通过openssl工具生成所有的ssl证书。 1、生成自签CA证书...

  • openssl制作CA自签证书

    @[toc] 1. 根证书 1.1 创建根证书密钥文件(root.key) 密码本次 40010355 1.2 创...

  • 配合阿里云Slb证书过程

    以下全部是阿里的官方文档,这里只是备份。 使用OpenSSL生成自签CA证书前提条件确保您已经了解负载均衡的证书要...

  • iOS 自签名证书建立(ca)

    请求ca key:openssl genrsa -out ca.key 1024 建立ca 证书:openssl ...

  • 数字证书系列--利用自签名证书实现认证的大致过程

    对于自签名证书,完成自签名后,我们会获得如下的几个文件:CA 证书文件,CA证书的私钥,个人证书的私钥,获得CA签...

  • openssl自签名CA证书

    原博客链接 本文非原创,系浏览各博客后结合自身使用的一个总结,方便回顾。 前情提要 通俗理解SSL/TLS协议区别...

网友评论

    本文标题:openssl制作CA自签证书

    本文链接:https://www.haomeiwen.com/subject/dslahrtx.html