当前位置: 首页 > news >正文

使用OpenSSL生成根证书并自签署证书

生成根CA的私钥和证书

# 生成根 CA 的私钥
[root@developer ssl]# openssl genrsa -out rootCA.key 2048
Generating RSA private key, 2048 bit long modulus (2 primes)
...+++++
............................................................+++++
e is 65537 (0x010001)# 使用私钥生成根 CA 的证书
[root@developer ssl]# openssl req -x509 -new -nodes -key rootCA.key -sha256 -days 1024 -out rootCA.crt
Country Name (2 letter code) [XX]:CN  # 国家名称(2个字母代码)
State or Province Name (full name) []:JS  # 州或省名
Locality Name (eg, city) [Default City]:KS  # 地点名称
Organization Name (eg, company) [Default Company Ltd]:local  # 组织名称
Organizational Unit Name (eg, section) []:developer  # 组织单位名称
Common Name (eg, your name or your server's hostname) []:Local Developer CA  # 通用名称
Email Address []:

为hello-world.test生成私钥和证书请求文件(CSR)

# 生成 hello-world.test 的私钥
[root@developer ssl]# openssl genrsa -out hello-world.test.key 2048
Generating RSA private key, 2048 bit long modulus (2 primes)
..........................................................................+++++
.....+++++
e is 65537 (0x010001)# 使用私钥生成证书请求文件
[root@developer ssl]# openssl req -new -key hello-world.test.key -out hello-world.test.csr
Country Name (2 letter code) [XX]:CN  # 国家名称(2个字母代码)
State or Province Name (full name) []:JS  # 州或省名
Locality Name (eg, city) [Default City]:KS  # 地点名称
Organization Name (eg, company) [Default Company Ltd]:local  # 组织名称
Organizational Unit Name (eg, section) []:developer  # 组织单位名称
Common Name (eg, your name or your server’s hostname) []:*.hello-world.test  # 域名
Email Address []:Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:

创建证书扩展文件

为了确保为 hello-world.test 签名的证书能够用作服务器身份验证,需要为它创建一个扩展文件。创建一个名为 v3.ext 的文件,并添加以下内容:

authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
subjectAltName = @alt_names[alt_names]
DNS.1 = *.hello-world.test
# 如果是IP就使用 IP.1 = 你的IP地址

使用根 CA 的证书为 hello-world.test 签名证书

[root@developer ssl]# openssl x509 -req -in hello-world.test.csr -CA rootCA.crt -CAkey rootCA.key -CAcreateserial -out hello-world.test.crt -days 500 -sha256  -extfile v3.ext
Signature ok
subject=C = CN, ST = JS, L = KS, O = local, OU = developer, CN = *.hello-world.test
Getting CA Private Key

此时文件夹内应该有以下文件:

[root@developer ssl]# ll
-rw-r--r--. 1 root root 1318 523 09:59 rootCA.crt
-rw-------. 1 root root 1675 523 09:59 rootCA.key
-rw-r--r--. 1 root root   41 523 10:14 rootCA.srl
-rw-r--r--. 1 root root  253 523 10:13 v3.ext
-rw-r--r--. 1 root root 1322 523 10:14 hello-world.crt
-rw-r--r--. 1 root root  997 523 10:02 hello-world.csr
-rw-------. 1 root root 1679 523 10:00 hello-world.key

宝塔部署

宝塔网站设置中SSL选项选择当前证书,密钥(KEY)中填入hello-world.key的内容,证书(PEM格式)中填入hello-world.crt的内容,最后将rootCA.crt安装到电脑的本地受信任的根证书颁发机构中。

http://www.dtcms.com/a/208147.html

相关文章:

  • 数据结构(6)线性表-队列
  • 【leetcode】3356. 零数组变换②
  • 字节跳动旗下火山引擎都覆盖哪些领域
  • 四、GPU是如何成为当前电脑中不可或缺的一部分的,opengl在其中起到了什么效果
  • 基于SpringMVC的动态时钟设计
  • youyu:91501
  • 学习黑客Nmap 是什么?
  • React从基础入门到高级实战:React 基础入门 - 简介与开发环境搭建
  • [逻辑回归]机器学习-part11
  • 相机--基础
  • Widget进阶
  • Python训练营打卡 Day25
  • 5.2.3 使用配置文件方式整合MyBatis
  • 《数据结构初阶》【八大排序——巅峰决战】
  • 【论文精读】2022 CVPR--RealBasicVSR现实世界视频超分辨率(RealWorld VSR)
  • 【Harmony OS】作业四 布局
  • Pluto实验报告——基于FM的音频信号传输并解调恢复
  • 机器学习中的维度、过拟合、降维
  • 【数据架构05】数据要素架构篇
  • 采用多维计算策略(分子动力学模拟+机器学习),显著提升 α-半乳糖苷酶热稳定性
  • SpringCloud——MybatisPlus
  • Flask 会话管理:从原理到实战,深度解析 session 机制
  • VueRouter路由组件的用法介绍
  • API自动化与持续集成核心实战知识点!
  • 从数学融智学视域系统地理解《道德经》:38至56,德化社会
  • 【ARM 嵌入式 编译系列 10.4.2 -- 查看 bss 段中有哪些内容】
  • 数据的获取与读取篇---获取数据
  • Helm简介、安装、配置、使用!
  • 极大似然估计
  • PostgreSQL 软件升级