搭建CA并签发数字证书
Openssl完成私有CA
yum install openssl openssl-devel -y ---完成私有软件包的安装
修改openssl.cnf配置文件
[root@CA ~]# vim /etc/pki/tls/openssl.cnf
[CA_default]
dir = /etc/pki/CA //CA签署工作目录
certs = $dir/certs //用户证书存放路径
certificate = $dir/my-ca.crt //CA根证书文件
private_key = $dir/private/my-ca.key //CA私钥文件创建相关的文件
cd /etc/pki/CA //前往CA签署工作目录
genrsa 生成一段私钥
格式: openssl genrsa 密钥长度
生成私有密钥以后需要将私有密钥进行保存
方法一:先生成私有密钥 openssl genrsa 密钥长度
再进行重定向保存 openssl genrsa 密钥长度 > cakey.pem
由于是私钥最后修改权限: chown 600 cakey.pem
方法二:使用()进行操作
使用括号括起来的命令只在子shell中执行,执行完子shell就退出了,就和当前的无冲突
(umask 077, opensll genrsa -out cakey.pem 密钥长度)
openssl rsa -in 私钥位置 -puboot
格式: openssl genrsa -out /PATH/TO/KEYFILENAME NUMBITS
Openssl rsa -in /PATH/TO/KEYFILENAME puboot
openssl req -new -x509 -key 私钥位置 -out 输出位置 -days 有效天数
Openssl x509 -text -in 查看文件
CA配置文件
[CA_default]
dir = /etc/pki/CA //CA签署工作目录
certs = $dir/certs //用户证书存放路径
certificate = $dir/my-ca.crt //CA根证书文件
private_key = $dir/private/my-ca.key //CA私钥文件
Country Name (2 letter code) [XX]:
国家名称(2个字母代码)
State or Province Name (full name) []:
省/自治区名称
Locality Name (eg, city) [Default City]:
地点名称
Organization Name (eg, company) [Default Company Ltd]:
组织名称
Organizational Unit Name (eg, section) []:
组织单位名称
Common Name (eg, your name or your server's hostname) []:
或者您的服务器名
Email Address []:
电子邮件地址
根据要求将上面的修改为题目要求的数值
[ req_distinguished_name ]
countryName = Country Name (2 letter code)
countryName_default = CN
countryName_min = 2
countryName_max = 2
stateOrProvinceName = State or Province Name (full name)
stateOrProvinceName_default = ZB
localityName = Locality Name (eg, city)
localityName_default = ZB
0.organizationName = Organization Name (eg, company)
0.organizationName_default = chinaskill
organizationalUnitName = Organizational Unit Name (eg, section)
organizationalUnitName_default =sever
commonName = Common Name (eg, your name or your server\'s hostname)
commonName_max = 64
emailAddress = Email Address
emailAddress_max = 64
生成 RSA 私钥
openssl genrsa [args] [numbits]
-des: CBC模式的DES加密
-des3: CBC模式的3DES加密
-aes128: CBC模式的AES128加密
-aes192: CBC模式的AES192加密
-aes256: CBC模式的AES256加密
-passout arg arg为对称加密(des、3des、aes)的密码,使用该参数可以省去指令行交互提示输入密码环节
-out file 输出证书私钥文件
[numbits] 密钥长度
example 生成一个1024位的RSA私钥,并用3DES加密(密码为1111),保存为server.key文件
openssl genrsa -out server.key -passout pass:1111 -des3 1024
输出文件位置 设置对称加密密码 设置加密模式 设置密钥长度
生成证书签名请求(CSR)
openssl req [options] <infile> outfile
-inform arg 输入文件格式 DER、PEM
-outform arg 输出文件格式 DER、PEM
-in arg 待处理文件
-out arg 待输出文件
-passin 用于签名待生成的请求证书的私钥文件的解密密码
-key file 用于签名待生成的请求证书的私钥文件
-keyform arg DER、NET、PEM
-new 新的请求
-x509 输出一个X509格式的证书
-days X509证书的有效时间
-newkey rsa:bits 生成一个bits长度的RSA私钥文件,用于签发
-[digest] HASH算法 md5、sha1、md2、mdc2、md4
-config file 指定openssl配置文件
-text text显示格式
example1 利用CA的RSA密钥创建一个自签署的CA证书(X.509结构)
openssl req -new -x509 -days 365 -key server.key -out ca.crt
新的请求 证书格式 证书有效时间 请求证书私钥文件 待输出文件
example2 用server.key生成证书签署请求CSR(这个CSR用于之外发送待CA中心等待签发)
Openssl req -new -key server.key -out server.cs
新的请求 请求证书私钥文件 待输出文件
example3 查看CSR的细节:
Openssl req -noout -text -in server.csr
CA 签名
openssl ca [options]:
-selfsign 使用对证书请求进行签名的密钥对来签发证书。即"自签名",这种情况发生在生成证书的CA客户端与签发证书的CA服务器都是同一台机器,此时我们可以使用同一个密钥对来进行"自签名"
-in file 需要进行处理的PEM格式的证书
-out file 处理结束后输出的证书文件
-cert file 用于签发的根CA证书
-days arg 指定签发的证书的有效时间
-keyfile arg CA的私钥证书文件
-keyform arg CA的根私钥证书文件格式: PEM、ENGINE
-key arg CA的根私钥证书文件的解密密码(如果加密了的话)
-config file 配置文件
example 利用 CA 证书 ca.crt 签署请求证书 server.crt:
openssl ca -in server.csr -out server.crt -cert ca.crt -keyfile ca.key
进行处理证书格式 输出证书格式 用于签发艮证书 CA的私钥证书文件
x509 证书操作
openssl x509 [args]
-inform arg 待处理X509证书文件格式 DER、NET、PEM
-outform arg 待输出X509证书文件格式 DER、NET、PEM
-in arg 待处理X509证书文件
-out arg 待输出X509证书文件
-req 表明输入文件是一个"请求签发证书文件(CSR)",等待进行签发
-days arg 表明将要签发的证书的有效时间
-CA arg 指定用于签发请求证书的根CA证书
-CAform arg 根CA证书格式(默认是PEM)
-CAkey arg 指定用于签发请求证书的CA私钥证书文件,缺省认为私有密钥在CA证书文件里有
-CAkeyform arg 指定根CA私钥证书文件格式(默认为PEM格式)
-CAserial arg 指定序列号文件(serial number file)
-CAcreateserial 如果序列号文件(serial number file)没有指定,则自动创建它
example1 转换DER证书为PEM格式
openssl x509 -in cert.cer -inform DER -outform PEM -out cert.pem
待处理证书文件 待处理证书格式 待输出证书格式 待输出证书文件
example2 使用根CA证书对"请求签发证书"进行签发,生成x509格式证书
openssl x509 -req -days 3650 -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out server.crt
example3 打印出证书的内容
openssl x509 -in server.crt -noout -text
具体搭建步骤
1、安装yum包
yum install openssl* -y
确认openssl包是否安装成功
[root@localhost ~]# rpm -q openssl
openssl-1.0.2k-19.el7.x86_64
//已经查询到openssl包,表示安装成功
- 创建关键目录和文件
[root@localhost ~]# vi /etc/pki/tls/openssl.cnf
[ CA_default ]
dir = /etc/pki/CA # Where everything is kept
certs = $dir/certs # Where the issued certs are kept
crl_dir = $dir/crl # Where the issued crl are kept
database = $dir/index.txt # database index file.
...
serial = $dir/serial # The current serial number
需要在CA目录下查看是否有如上三个目录和两个文本
[root@localhost ~]# cd /etc/pki/CA
[root@localhost CA]# ll
总用量 0
drwxr-xr-x. 2 root root 6 8月 9 2019 certs
drwxr-xr-x. 2 root root 6 8月 9 2019 crl
drwxr-xr-x. 2 root root 6 8月 9 2019 newcerts
drwx------. 2 root root 6 8月 9 2019 private
//查到只有三个目录
[root@localhost CA]# touch index.txt
[root@localhost CA]# touch serial
[root@localhost CA]# echo 01 > serial //起始号01
[root@localhost CA]# ls
certs crl index.txt newcerts private serial
- 私有CA配置
openssl完成私有CA
- 先生成一段私有密钥
- 生成自签署证书
首先根据配置文件要求需要将密钥放在CA目录下
[root@localhost ~]# cd /etc/pki/CA
[root@localhost CA]# (umask 077; openssl genrsa -out private/cakey.pem 2048)
Generating RSA private key, 2048 bit long modulus
...................................+++
............+++
e is 65537 (0x10001)
//生成2048位私钥cakey.pem
[root@localhost CA]# ll -l private/
总用量 4
-rw-------. 1 root root 1679 11月 22 15:54 cakey.pem
//查询是否创建成功
生成自签证书
[root@localhost CA]# openssl req -new -x509 -key private/cakey.pem -out cacert.pem
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 //国家名称(2个字母代码)
State or Province Name (full name) []:ZB //省/自治区名称
Locality Name (eg, city) [Default City]:ZB //地点名称
Organization Name (eg, company) [Default Company Ltd]:chianskill //组织名称
Organizational Unit Name (eg, section) []:server //组织单位名称
Common Name (eg, your name or your server's hostname) []:chinaskill.com
//或者您的服务器名
Email Address []:admin@chinaskill.com 电子邮件地址
4、生成httpd的签署证书
首先创建对应目录
[root@localhost CA]# mkdir /etc/httpd
[root@localhost CA]# cd /etc/httpd
[root@localhost httpd]# mkdir ssl
[root@localhost httpd]# cd ssl
创建1024位私钥
[root@localhost ssl]# (umask 077; openssl genrsa -out httpd.key 1024)
Generating RSA private key, 1024 bit long modulus
.......++++++
....................................++++++
e is 65537 (0x10001)
生成自签证书
[root@localhost ssl]# openssl req -new -key httpd.key -out httpd.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) []:ZB
Locality Name (eg, city) [Default City]:ZB
Organization Name (eg, company) [Default Company Ltd]:chinaskill
Organizational Unit Name (eg, section) []:web
Common Name (eg, your name or your server's hostname) []:www.chinaskill.com
Email Address []:
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
[root@localhost ssl]# ll
总用量 8
-rw-r--r--. 1 root root 651 11月 22 16:04 httpd.csr
-rw-------. 1 root root 887 11月 22 16:02 httpd.key
//查看私钥和证书是否生成成功
签发证书
[root@localhost ssl]# openssl ca -in httpd.csr -out httpd.crt -days 365
Using configuration from /etc/pki/tls/openssl.cnf
Check that the request matches the signature
Signature ok
Certificate Details:
Serial Number: 1 (0x1)
Validity
Not Before: Nov 22 08:10:28 2020 GMT
Not After : Nov 22 08:10:28 2021 GMT
Subject:
countryName = CN
stateOrProvinceName = ZB
organizationName = chinaskill
organizationalUnitName = web
commonName = www.chinaskill.com
X509v3 extensions:
X509v3 Basic Constraints:
CA:FALSE
Netscape Comment:
OpenSSL Generated Certificate
X509v3 Subject Key Identifier:
63:B7:78:A6:CD:49:AA:C9:42:7C:70:75:0A:AB:43:EF:38:71:88:FD
X509v3 Authority Key Identifier:
keyid:42:84:AC:D1:77:09:AF:6C:81:45:56:39:0B:D9:35:AC:BC:3A:8B:10
Certificate is to be certified until Nov 22 08:10:28 2021 GMT (365 days)
Sign the certificate? [y/n]:y
1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated
搭建CA并签发数字证书相关推荐
- centos7搭建CA服务器颁发ssl证书
2019年12月16日 星期一 CQCEE 使用ssl来保证web通信安全 apache服务器与客户机采用明文通信 对HTTP传输加密的协议为HTTPS,是通过ssl进行http传输的协议,它通过公用 ...
- http系列---OpenSSL生成根证书CA及签发子证书
文章目录 1. 前言 2. 修改OpenSSL的配置 3. 生成根证书 4. 用根证书签发server端证书 5. 用根证书签发client端证书 6. 导出证书 7. 附项目证书目录 1. 前言 系 ...
- OpenSSL生成根证书CA及签发子证书
转自:https://yq.aliyun.com/articles/40398 摘要: 系统:CentOS7 32位 目标:使用OpenSSL生成一个CA根证书,并用这个根证书颁发两个子证书serve ...
- 主流CA吊销俄罗斯数字证书启示:升级国密算法SSL证书,助力我国网络安全自主可控
随着国际和民间黑客组织的加入,俄乌的战争快速蔓延成一场全球化的网络信息战.国际上主流CA机构不再为俄罗斯提供数字证书服务,甚至吊销俄罗斯相关的一些国家基础设施网站的证书.这让俄罗斯不得不开始建立国家C ...
- OpenSSL 与 SSL 数字证书概念贴
SSL/TLS 介绍见文章 SSL/TLS原理详解. 如果你想快速自建CA然后签发数字证书,请移步 基于OpenSSL自建CA和颁发SSL证书 . 首先简单区分一下HTTPS.SSL.OpenSSL三 ...
- 密码学应用-身份认证+数字证书
1.身份认证 身份认证又称为"验证","鉴权",是指通过一定的手段,完成对用户身份的确认.身份认证可分为三类:实体所知,实体所有,实体特性. 身份认证最为广泛的 ...
- Linux 部署CA数字证书服务
CA数字证书服务 CA Certificate Authority 数字证书授权中心 被通信双方信任的,独立的第三方机构 负责证书颁发,验证,撤销等管理 PKI公钥基础设施 一套标准的密钥管理平台 通 ...
- PKI/CA与数字证书
写在前面 现在开始接触CA相关的内容,对一些名词还是不甚了解,在遇到一些问题的时候也不能理解,刚好最近看了一本<PKI/CA与数字证书技术大全>,里面介绍的比较系统全面,也对刚接触这方面的 ...
- CA与数字证书的自结
1.CA CA(Certificate Authority)是数字证书认证中心的简称,是指发放数字证书.管理数字证书.废除数字证书的权威机构. 2.数字证书 如果向CA申请数字证书的单位为A.则他申请 ...
最新文章
- 看不懂代码?AI给你做翻译,说人话的那种
- HTML为什么认为“ chucknorris”是一种颜色?
- 数组和集合的区别?你还知道这些吗?
- springmvc中对日期格式化的处理
- SpringCloud(笔记)
- 专有网络、云产品、路由器和交换机
- spark User class threw exception: java.lang.NoSuchMethodError
- Quartz 配置详解
- ZedGraph的一些属性
- libreelec投屏_【树莓派】树莓派与XBMC及Kodi、LibreELEC插件(一)
- 关于跨团队合作的一些思考
- java ligerui_[Java教程]ligerUI
- 数学建模竞赛论文写作规范
- 计算机管理为什么没有端口,Win7设备管理器没有端口选项的三大原因及解决措施...
- poj 1383 Labyrinth 树的直径
- linux RT_PREEMPT 高CPU负载下的驱动稳定性?
- python 脚本 .py文件执行
- STM32使用串口1配合DMA接收不定长数据,减轻CPU载荷
- Springboot 系列(十一)使用 Mybatis(结合自动化生成插件) 访问数据库
- 通信系统CMMB调研报告
热门文章
- IPv6 NAT-PT配置【下一代互联网03】
- 2020投资入籍项目排名:圣基茨和尼维斯投资移民项目全球最快批复
- 【Web3 系列开发教程——创建你的第一个 NFT(6)】为 NFT 设置价格
- 常见的TikTok变现方式,你知道几种?
- flutter nfc
- python2.7安装手把手教程_手把手windows64位配置安装python2.7
- Linux下安装tuned以使用tuned-adm命令优化Linux系统性能
- 【Android Gradle 插件】DexOptions 配置 ⑤ ( additionalParameters 属性配置 | --minimal-main-dex 参数最小化主 dex 字节码 )
- 网页设计作业 HTML5期末大作业:旅游网站设计——蓝色的地方旅游门户(9页) HTML+CSS+JavaScript
- Python 计算KDJ指标