目录

  • 一、CA中心申请证书的过程
  • 二、CA介绍
  • 三、构建私有CA
    • 1.环境:
    • 2.检查安装openSSL
    • 3.查看配置文件
    • 4.根证书服务器目录
    • 5.创建所需文件
    • 6.创建密钥
    • 7.生成自签名证书
    • 8.下载安装证书
  • 四、客户端CA证书申请及签名
    • 1.检查安装openSSL
    • 2.客户端生成密钥
    • 3.客户端用私钥加密生成证书请求
    • 4.CA服务端签署证书
    • 5.CA服务端将证书发给请求服务端
    • 6.CA服务端调整
    • 7.测试

一、CA中心申请证书的过程

1、web服务器,生成一对非对称加密密钥(web公钥,web私钥)
2、web服务器使用 web私钥生成 web服务器的证书请求,并将证书请求发给CA服务器
3、CA服务器使用 CA的私钥 对 web 服务器的证书请求 进行数字签名得到 web服务器的数字证书,并将web服务器的数字证书颁发给web服务器。

二、CA介绍

  CA(Certificate Authority)证书颁发机构主要负责证书的颁发、管理以及归档和吊销。证书内包含了拥有证书者的姓名、地址、电子邮件帐号、公钥、证书有效期、发放证书的CA、CA的数字签名等信息。证书主要有三大功能:加密、签名、身份验证。

三、构建私有CA

1.环境:

10.8.161.142 CA服务端
10.8.161.154 web服务端

2.检查安装openSSL

[root@xiong ~]# rpm -qa openssl
openssl-1.0.2k-21.el7_9.x86_64
没有则需下载
[root@xiong ~]#yum install openssl openssl-devel -y

3.查看配置文件

[root@xiong ~]# vim /etc/pki/tls/openssl.cnf
[ ca ]
default_ca = CA_default       # 默认的CA配置;CA_default指向下面配置块[ CA_default ]
dir             = /etc/pki/CA           # CA的默认工作目录
certs           = $dir/certs            # 认证证书的目录
crl_dir         = $dir/crl              # 证书吊销列表的路径
database        = $dir/index.txt        # 数据库的索引文件
new_certs_dir   = $dir/newcerts         # 新颁发证书的默认路径
certificate     = $dir/cacert.pem       # 此服务认证证书,如果此服务器为根CA那么这里为自颁发证书
serial          = $dir/serial           # 下一个证书的证书编号
crlnumber       = $dir/crlnumber        # 下一个吊销的证书编号
crl             = $dir/crl.pem          # The current CRL
private_key     = $dir/private/cakey.pem  # CA的私钥
RANDFILE        = $dir/private/.rand    # 随机数文件
x509_extensions = usr_cert              # The extentions to add to the cert
name_opt        = ca_default            #命名方式,以ca_default定义为准
cert_opt        = ca_default            #证书参数,以ca_default定义为准
default_days    = 365                   # 证书默认有效期
default_crl_days= 30                    # CRl的有效期
default_md      = sha256                # 加密算法
preserve        = no                    # keep passed DN ordering
policy          = policy_match          #policy_match策略生效[ policy_match ]
countryName = match    #国家;match表示申请者的申请信息必须与此一致
stateOrProvinceName     = match         #州、省
organizationName        = match         #组织名、公司名
organizationalUnitName  = optional      #部门名称;optional表示申请者可以的信息与此可以不一致
commonName              = supplied
emailAddress            = optional[ policy_anything ]  #由于定义了policy_match策略生效,所以此策略暂未生效
countryName             = optional
stateOrProvinceName     = optional
localityName            = optional
organizationName        = optional
organizationalUnitName  = optional
commonName              = supplied
emailAddress            = optional

4.根证书服务器目录

根CA服务器:因为只有 CA 服务器的角色,所以用到的目录只有/etc/pki/CA。
网站服务器:只是证书申请者的角色,所以用到的目录只有/etc/pki/tls。

5.创建所需文件

[root@xiong ~]# cd /etc/pki/CA/
[root@xiong CA]# touch index.txt   //生成证书索引数据库文件
[root@xiong CA]# echo 01 > serial   //指定第一个颁发证书的序列号
[root@xiong CA]# ls
certs  crl  index.txt  newcerts  private  serial

6.创建密钥

在根CA服务器上创建密钥,密钥的位置必须为/etc/pki/CA/private/cakey.pem,这个是openssl.cnf中中指定的路径,只要与配置文件中指定的匹配即可。

[root@xiong CA]# (umask 066;openssl genrsa -out private/cakey.pem 2048)
Generating RSA private key, 2048 bit long modulus
..................+++
...........................+++
e is 65537 (0x10001)

7.生成自签名证书

根CA自签名证书,根CA是最顶级的认证机构,没有人能够认证他,所以只能自己认证自己生成自签名证书。

[root@xiong CA]# openssl req -new -x509 -key /etc/pki/CA/private/cakey.pem -days 7300 -out /etc/pki/CA/cacert.pem -days 7300
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]:CA
Organizational Unit Name (eg, section) []:OPT
Common Name (eg, your name or your server's hostname) []:ca.xx.com
Email Address []:

释义:

-new: 生成新证书签署请求
-x509: 专用于CA生成自签证书
-key: 生成请求时用到的私钥文件
-days : 证书的有效期限
-out /PATH/TO/SOMECERTFILE:证书的保存路径

8.下载安装证书

/etc/pki/CA/cacert.pem就是生成的自签名证书文件,使用 SZ/xftp工具将他导出到窗口机器中。然后双击安装此证书到受信任的根证书颁发机构。

[root@xiong CA]# yum -y install lrzsz
[root@xiong CA]# sz cacert.pem         //导出证书文件

打开本机浏览器->设置->管理证书->受信任颁发机构->导入->选择导出文件-> 下一步->确定->完成

四、客户端CA证书申请及签名

1.检查安装openSSL

[root@xiong ~]# rpm -qa openssl
openssl-1.0.2k-21.el7_9.x86_64
没有则需下载
[root@xiong ~]#yum install openssl openssl-devel -y

2.客户端生成密钥

[root@cheng ~]# (umask 066;openssl genrsa -out      /etc/pki/tls/private/www.xx.com.key 2048)
Generating RSA private key, 2048 bit long modulus
................................................................................................+++
....+++
e is 65537 (0x10001)
[root@cheng ~]# cd /etc/pki/tls/private/
[root@cheng private]# ls       //查看生成的密钥文件
www.xx.com.key

3.客户端用私钥加密生成证书请求

[root@cheng private]# openssl req -new -key /etc/pki/tls/private/www.xx.com.key -days 365 -out /etc/pki/tls/www.xx.com.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]:CC
Organizational Unit Name (eg, section) []:OPT
Common Name (eg, your name or your server's hostname) []:www.cc.com
Email Address []:Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:        //回车,不填写
[root@cheng private]# cd ../
[root@cheng tls]# scp www.xx.com.csr 10.8.161.142://etc/pki/CA/private/
//使用scp命令,通过ssh协议,将该文件传输到CA服务端下的/etc/pki/CA/private/目录
The authenticity of host '10.8.161.142 (10.8.161.142)' can't be established.
ECDSA key fingerprint is SHA256:Pnn4ujYjcIxLfT+6p61HLQ/oyZ13/2cCzcKxa71EHaU.
ECDSA key fingerprint is MD5:fe:2f:60:e0:39:dd:7e:79:6a:e9:0f:13:d3:a5:99:5f.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.8.161.142' (ECDSA) to the list of known hosts.
root@10.8.161.142's password:         //填写CA服务端密码
www.xx.com.csr                   100%  997     1.1MB/s   00:00

CSR(Certificate Signing Request)包含了公钥和名字信息。通常以.csr为后缀,是网站向CA发起认证请求的文件,是中间文件。

4.CA服务端签署证书

[root@xiong CA]# vim /etc/pki/tls/openssl.cnf
87行:organizationName        = supplied
[root@xiong CA]# openssl ca -in /etc/pki/CA/private/www.xx.com.csr -out /etc/pki/CA/certs/www.cc.com.crt -days 365
Certificate is to be certified until Jan 20 06:23:04 2022 GMT (365 days)
Sign the certificate? [y/n]:y1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated
//证书通常以.crt为后缀,表示证书文件
[root@xiong CA]# openssl x509 -in ./certs/www.cc.com.crt -noout -subject   //查看生成的证书的信息
subject= /C=CN/ST=BEIJING/O=CC/OU=OPT/CN=www.cc.com

5.CA服务端将证书发给请求服务端

[root@xiong certs]# scp www.cc.com.crt 10.8.161.154:/etc/pki/CA/certs/
The authenticity of host '10.8.161.154 (10.8.161.154)' can't be established.
ECDSA key fingerprint is        SHA256:ewDoyjXC/1bXCiPkc7yJDLpTAV86DIX8mbit7VH0Yc4.
ECDSA key fingerprint is MD5:e8:56:7c:dd:f2:26:1e:67:98:71:1d:c5:96:ec:80:3b.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.8.161.154' (ECDSA) to the list of known hosts.
root@10.8.161.154's password:
www.cc.com.crt                                              100%    4422     4.6MB/s   00:00

6.CA服务端调整

[root@xiong certs]# vim /etc/nginx/conf.d/default.conf
server {listen       443 ssl;server_name  localhost;ssl_certificate      /etc/pki/CA/certs/www.cc.com.crt;#指定证书路径  ssl_certificate_key /etc/pki/tls/private/www.cc.com.key;#指定私钥路径ssl_session_timeout  5m;  #配置用于SSL会话的缓存 ssl_protocols  SSLv2 SSLv3 TLSv1;   #指定使用的协议ssl_ciphers   ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP; #密码指定为 OpenSSL支持的格式ssl_prefer_server_ciphers   on;
#设置协商加密算法时,优先使用服务端的加密,而不是客户端浏览器的。location / {root /usr/share/nginx/html;index index.html index.htm;}
}
[root@xiong certs]#nginx -t
[root@xiong certs]#nginx -s reload

7.测试

访问http://10.8.161.154,以下为样式

构建CA证书详解过程步骤相关推荐

  1. HTTPS及CA证书详解

    https目录 HTTPS 术语解释 1. HTTP 2. SSL/TLS(Secure sockets Layer/transport layer security) 3. HTTPS 4. 对称加 ...

  2. http\https的连接过程及数字证书详解

    http\https的连接过程及数字证书详解 内推军p185 http连接过程(相当于输入url会发生什么) 1.域名解析 2.发起TCP的三次握手 3.Web浏览器向服务器发送http请求命令 4. ...

  3. SSL证书详解和CFSSL工具使用

    SSL证书详解和CFSSL工具使用 1.公钥基础设施PKI基础概念 CA(Certification Authority)证书,指的是权威机构给我们颁发的证书. 密钥就是用来加解密用的文件或者字符串. ...

  4. 七、Oracle11g R2服务端卸载图文详解过程

    Oracle11g R2服务端卸载图文详解过程 注:由于Oracle 11g R2服务端安装的时候已经包含了客户端,所以服务端的卸载方案跟客户端的一样,也就是说,客户端卸载按照以下步骤同样适用. 一. ...

  5. CSMA/CA协议详解

    参考:(20条消息) CSMA/CA协议详解[计算机网络]_蓝莓派Alex的博客-CSDN博客_csma/ca 笔记: 无线电波能够向所有的方向传播,且其传播距离受限.当电磁波在传播过程中遇到障碍物时 ...

  6. IOS开发环境更换后重新制作Provisioning Profile证书详解

    IOS开发环境更换后重新制作Provisioning Profile证书详解 新换了台Macbook,又折腾了一遍Provisioning Profile证书,苹果的证书繁锁复杂,每次制作都相当麻烦, ...

  7. Java加密与解密的艺术~数字证书详解

    数字证书具备常规加密/解密必要的信息,包含签名算法,可用于网络数据加密/解密交互,标识网络用户(计算机)身份.数字证书为发布公钥提供了一种简便的途径,其数字证书则成为加密算法以及公钥的载体.依靠数字证 ...

  8. Kubernetes 之 二进制安装(二) 证书详解

    前言 在进行二进制搭建K8S集群前,我们需要梳理通最磨人的一个点,就是各种各样的证书机制.这一步是在安装配置kubernetes的所有步骤中最容易出错也是最难排查问题的一步,而这却刚好是第一步,万事开 ...

  9. 【201】openssl生成服务端和客户端证书详解

    内容目录(原文见公众号python宝) 一.基本知识点介绍二.openssl生成服务端和客户端证书www.xmmup.com 一.基本知识点介绍   要支持https请求,那就需要一个SSL证书. S ...

最新文章

  1. 自律到极致-人生才精致:第5期
  2. CONVERT_DATE_INPUT
  3. 【k8s】kuboard获取token命令
  4. python写的购物车程序
  5. 这周,全球首个IT技术全中文免费学习平台诞生了!太惊艳!
  6. 画函数图形的C#程序(改进版) (转)
  7. hadoop--Map Join
  8. adcetris研发历程_抗体类药物质量控制—张伯彦20130730.pdf
  9. Entity Framework 6.x - Code First 默认创建数据库的位置
  10. 小米开源文件管理器MiCodeFileExplorer-源码研究(1)-2个模型Model
  11. python抢小米6自动化脚本
  12. [Python图像处理] .获取图像属性、兴趣ROI区域及通道处理
  13. .net Reactor 使用说明详解
  14. SparseLDA算法
  15. 超级简单的方法重装win10系统
  16. php curl post 很慢,php的curl函数模拟post数据提交,首次速度非常慢的处理办法 | 学步园...
  17. SGE集群主机和执行机的正确卸载
  18. Qlikview---集合分析
  19. html word 批注,word怎么批注修改文章
  20. 微信小程序(微信开发者工具及工程创建、小程序配置、逻辑层、模块化)

热门文章

  1. 【黑客故事】钢铁侠Musk的音影记录
  2. 鞍部在哪里_富春江,富春江在哪里_富春江在哪个省_属于哪个省_就去旅游网
  3. google v8 实战 -- 构建v8
  4. 微信表情150个限制怎么破?教你一招
  5. 坚果云显示连接服务器失败怎么办,坚果云提示同步过程中遇到错误,怎么解决?...
  6. NOJ [1509] 挖宝
  7. 多个中通快运的物流情况是怎么批量查询并保存到电脑的
  8. Facebook中国程序员之死:年仅38岁跳楼轻生,浙大EE毕业生,去年刚入职
  9. 工图怎么进行三维标注
  10. [Sensor]LSM6DSL-加速度计、陀螺仪传感器