OpenSSL CA服务器搭建与管理指南
创作时间:
作者:
@小白创作中心
OpenSSL CA服务器搭建与管理指南
引用
CSDN
1.
https://blog.csdn.net/weixin_44524357/article/details/145564499
本文将详细介绍如何使用OpenSSL搭建和管理CA(证书颁发机构)服务器。从配置文件修改、目录创建、密钥生成到证书签发和吊销,每个步骤都配有详细的命令行操作示例,帮助读者快速掌握CA服务器的搭建和管理方法。
一、修改openssl配置文件
- 设置证书路径
- 48.ca服务器路径:
/csk-rootca,用于存放CA服务器相关的所有文件。 - 56.ca服务器证书路径:
/csk-rootca/csk-ca.pem,CA服务器证书的存储位置。
二、设置ca服务器路径
- 创建CA服务器相关目录并生成必要文件
root@debian:~# mkdir /csk-rootca
root@debian:/csk-rootca# mkdir newcerts
root@debian:/csk-rootca# touch index.txt
root@debian:/csk-rootca# echo 01 > serial
执行上述命令,在系统中创建了/csk-rootca目录及其子目录newcerts,并生成了index.txt和serial文件,这些是生成认证证书的必要文件。
三、生成密钥
- 执行命令生成CA服务器的RSA私钥
root@debian:/csk-rootca# openssl genrsa -out private/cakey.pem
Generating RSA private key, 2048 bit long modulus (2 primes)
..............................+++++
................................+++++
e is 65537 (0x010001)
root@debian:/csk-rootca#
该命令生成一个2048位的RSA私钥,存储在/csk-rootca/private/cakey.pem文件中。
四、生成CA服务器证书
- 方式一:交互式输入信息生成证书
root@debian:/csk-rootca# openssl req -x509 -new -key private/cakey.pem -out csk-ca.pem -days 3650
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
State or Province Name (full name) [Some-State] :China
Locality Name (eg,city) []:BeiJing
Organization Name (eg, company) [Internet Widgits Pty Ltd] :skills
Organizational Unit Name (eg, section) []:Operations Departments
Common Name (e.g. server FQDN or YOuR name) []:Csk Global Root CA
Email Address []:
root@debian:/csk-rootca#
- 方式二:通过指定主题信息生成证书
root@AppSrv:/csk-rootca# openssl req -x509 -new -key private/cakey.pem -out csk-ca.pem -subj "/C=CN/ST=China/L=BeiJing/O=skills/OU=Operations Departments/CN=CsK Global Root CA"
root@AppSrv:/csk-rootca#
注意:设置证书有效时间为3650天(-days 3650),若不设置,默认有效期为1个月。若客户端时间不在证书有效时间内,客户端将不信任CA服务器及其签名的所有证书。
五、服务端生成私钥
- 创建目录并生成服务端私钥
root@debian:~# mkdir /ssl
root@debian:~# cd /ssl
root@debian:/ssl# openssl genrsa -out server.key
Generating RSA private key, 2048 bit long modulus (2 primes)
..............................+++++
................................+++++
e is 65537 (0x010001)
root@debian:/ssl#
在/ssl目录下生成了服务端的RSA私钥server.key。
六、服务端生成证书申请文件
- 方式一:交互式输入信息生成证书申请文件
root@debian:/ssl# 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) [AU]:CN
State or Province Name (full name) [Some-State] :China
Locality Name (eg,city) []:BeiJing
Organization Name (eg, company) [Internet Nidgits Pty Ltd] :skills
Organizational Unit Name (eg,section) []:Operations Departments
Common Name (e.g. server FQDN or YouR name) []:*.qwe.com
Email Address []:
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
root@debian:/ssl#
- 方式二:通过指定主题信息生成证书申请文件
root@AppSrv:/ssl# openssl req -new -key server.key -out server.csr -subj "/C=CN/ST=Chine/L=BeiJing/O=skills/OU=Operations Departments/CN=*.qwe.com"
root@AppSrv:/ssl#
注意:一般证书申请文件的国家地区等信息需和CA服务器相同。若题目要求不同国家地区,则需修改/etc/ssl/openssl.cnf文件中的policy配置项。
七、服务端将证书申请文件传给CA服务器,CA服务器进行签名
- 方式一:不指定输出文件名进行签名
- 方式二:指定输出文件名进行签名
CA服务器签名服务端证书默认有效期是1年,若客户端时间不在服务端证书有效期内,客户端将不信任此证书。签名后的证书存储在/csk-rootca/newcerts/目录下(如01.pem)。
查看证书详细信息:
八、注销证书
- 创建注销必要文件
root@AppSrv:/csk-rootca# mkdir crl
root@AppSrv:/csk-rootca# echo 01 > crlnumber
- 客户端查看要吊销的证书,确保吊销正确
root@AppSrv:/ssl# openssl x509 -in server.pem -noout -serial
serial=01
root@AppSrv:/ssl#
吊销证书:(此处未给出具体命令,需补充完整操作)
生成更新注销证书
root@AppSrv:/csk-rootca# openssl ca -gencrl -out cr1.pem
Using configuration from /usr/lib/ssl/openssl.cnf
root@AppSrv:/csk-rootca#
- 查看已吊销哪些证书
#显示以吊销证书的值
九、客户端信任CA服务器
- 将CA的公钥发送给客户端后,在客户端执行以下操作
root@AppSrv:/csk-rootca# cp csk-ca.pem /usr/local/share/ca-certificates/ca.crt
root@AppSrv:/csk-rootca# update-ca-certificates
Updating certificates in /etc/ssl/certs...
1 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d...
done.
root@AppSrv:/csk-rootca#
注:如果系统中没有/usr/local/share/ca-certificates/路径或update-ca-certificates命令,则需安装ca-certificates包,可通过apt list ca-certificates查看该包的安装情况。
热门推荐
中国社会科学院的“八思巴文学派”
从王莽改制看中国士大夫阶层思想体系的核心命题
区域医疗中心首创“运动院士+医学主诊”模式,浦东这个医联体踏上国际化之路
“私下达成和解协议”,能否反悔要求再次赔偿?
脐带缠绕不要慌,检测胎动是关键
Redis Sentinel详解:高可用架构下的监控与故障转移机制
学会课题分离,解决90%的人际问题
江苏宿迁六大景点全攻略:从项王故里到骆马湖,领略楚风水韵
办公椅调节全攻略:靠背角度、高度和轮子速度调节方法
运动完“脸白”和“脸红”的人,谁的身体更健康?
推免!34所高校有望升级
柴油车燃油滤清器更换全攻略:以新款H9为例
小学生语文如何纠正错别字
负债经营风险的总体防范与控制策略
【美国H1B签证最新政策】一文读懂申请条件+抽签流程+费用
土霉素与莫西沙星能联用吗?
如何妥善处理碎屏险的理赔事宜?这些理赔流程有什么要点?
Excel生产模板制作指南:从需求分析到维护更新
医疗保险1万元免赔额是啥意思
献血之后吃什么比较好
初学者指南:如何挑选优质咖啡豆
功能点估算方法(FP)详解
购买香港保险的流程与风险全解析
颈椎变直时,头部应仰后还是低头走路?
芡实的功效与作用 芡实与莲子的区别
SCARA工业机器人:两个旋转关节实现精准操作
2025国考新动向:应届生岗位占比近七成,国考新机遇不容错过
陈皮普洱茶:养生佳品的完美结合
官宣了!刀郎复出记:那些年他隐遁江湖的日子
骨质疏松适合做哪些运动