码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • Linux openssl 搭建CA、签名证书


    目录

    • 前言
    • 配置CA
      • 安装openssl
      • 修改 openssl 配置文件
      • 创建所需要的文件
      • 创建CA KEY
      • 创建CA 证书
    • 创建证书
      • 生成密钥
      • 生成签名请求文件
    • 签名证书请求文件
    • 自签名证书
      • 创建 KEY
      • 生成自签名证书
    • 错误
      • openssl TXT_DB error number 2 failed to update database

    前言

    略

    配置CA

    安装openssl

    shell> yum list installed | grep openssl
    shell> yum install -y openssl
    
    • 1
    • 2

    修改 openssl 配置文件

    shell> vim /etc/pki/tls/openssl.cnf
    
    • 1

    将 policy = policy_match 改为 policy = policy_anything

    创建所需要的文件

    生成证书索引数据库文件 (默认为空文件)

    shell> touch /etc/pki/CA/index.txt
    
    • 1

    指定第一个颁发证书的序列号

    shell> echo 01 > /etc/pki/CA/serial
    
    • 1

    创建CA KEY

    shell> cd /etc/pki/CA/ 
    shell> openssl genrsa -out private/cakey.pem 2048 
    shell> chmod 400 private/cakey.pem
    
    • 1
    • 2
    • 3

    创建CA 证书

    shell> cd /etc/pki/CA/ 
    shell> openssl req -new -x509 -key private/cakey.pem -out cacert.pem -days 3650
    
    • 1
    • 2
    • -new: 生成新证书签署请求
    • -x509: 专用于CA生成自签证书
    • -key : 指向私钥文件
    • -days :证书的有效期限
    • -out : 证书的保存路径

    创建证书

    生成密钥

    shell> openssl genrsa -out com.mydomain.key 2048
    
    • 1

    生成签名请求文件

    shell> openssl req -new -key com.mydomain.key -out com.mydomain.csr
    
    • 1

    签名证书请求文件

    shell> cd /etc/httpd/cert.d/
    shell> openssl ca -in com.mydomain.csr -out com.mydomain.crt -days 360
    Using configuration from /etc/pki/tls/openssl.cnf
    Check that the request matches the signature
    Signature ok
    Certificate Details:
            Serial Number: 2 (0x2)
            Validity
                Not Before: Sep  4 12:28:26 2022 GMT
                Not After : Aug 30 12:28:26 2023 GMT
            Subject:
                countryName               = CN
                stateOrProvinceName       = BEIJING
                localityName              = BEIJING
                organizationName          = COMPANY
                organizationalUnitName    = SECTION
                commonName                = mydomain.com
                emailAddress              = admin@mydomain.com
            X509v3 extensions:
                X509v3 Basic Constraints: 
                    CA:FALSE
                Netscape Comment: 
                    OpenSSL Generated Certificate
                X509v3 Subject Key Identifier: 
                    41:E1:70:F4:38:7E:88:92:E2:6D:8C:6B:45:FC:B9:26:DF:D9:1C:5B
                X509v3 Authority Key Identifier: 
                    keyid:B6:12:B9:F5:91:13:D1:F7:90:09:0F:5A:49:2C:9E:5B:D1:0B:B9:DC
    
    Certificate is to be certified until Aug 30 12:28:26 2023 GMT (360 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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • -cert : 指向CA证书。不指定该参数时,默认指向/etc/pki/CA/cacert.pem。
    • -keyfile : 指向CA KEY。不指定该参数时,默认指向/etc/pki/CA/private/cakey.pem。

    自签名证书

    创建 KEY

    shell> openssl genrsa -out com.mydomain.key 2048
    
    • 1

    生成自签名证书

    shell> openssl req -new -x509 -key com.mydomain.key -out com.mydomain.crt -days 365
    
    • 1
    • -x509: 用于生成自签证书

    错误

    openssl TXT_DB error number 2 failed to update database

    这种情况一般发生在你之前生成过一样的证书,又想重新生成一模一样的证书。

    解决方法有2种:

    • 解决方法1:修改/etc/pki/CA/index.txt.attr,将 unique_subject = yes改为 unique_subject = no。一旦修改,无法再修改回来。
    • 解决方法2:删除/etc/pki/CA/index.txt、/etc/pki/CA/serial及相关文件,并重新创建/etc/pki/CA/index.txt、/etc/pki/CA/serial。
  • 相关阅读:
    CSS常见选择器
    java计算机毕业设计高中生学业水平测试系统MyBatis+系统+LW文档+源码+调试部署
    JS——日期字符串yyyymmdd转yyyy-mm-dd的两种方法
    Python武器库开发-高级特性篇(七)
    量化接口代码能不能用?
    代码随想录 | Day 50 - LeetCode 123. 买卖股票的最佳时机III、LeetCode 188. 买卖股票的最佳时机IV
    小程序 打开方式 页面效果 表单页面 点击跳到详情页 图标 获取后台数据 进行页面渲染
    JVM 类的加载子系统
    实战:基于卷积的MNIST手写体分类
    SMBGhost漏洞技术分析与防御方案
  • 原文地址:https://blog.csdn.net/sayyy/article/details/126694764
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号