AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 1149702
Accepted
user53815
user53815
Asked: 2023-12-13 13:31:03 +0800 CST2023-12-13 13:31:03 +0800 CST 2023-12-13 13:31:03 +0800 CST

使用 openssl 3 创建自签名证书,就像“New-SelfSignedCertificate”一样

  • 772

首先,我在谷歌上搜索了 openssl,比如这个,并且还尝试了数十次创建有效的自签名证书。
但我想询问服务器故障会快得多。

我的平台是一台安装了 openssl 3.2.0 精简版的 Windows 10 计算机。基础设施没有域存在,只是一个测试环境。

目标是为Windows主机和Windows远程管理https协议创建一个自签名证书以供使用,我确实知道Windows powershell“New-SelfSignedCertificate”可以直接解决我的需求,但这不是我想要的。

Openssl 是我需要的工具。我想使用 openssl 生成一个自签名证书(从 0 开始),与“New-SelfSignedCertificate”可以生成的证书相同。

我在导入证书(从 openssl 生成)后配置“winrm”时遇到问题。错误消息是:

settings Error number:  -2144108306 0x803380EE
The WinRM client cannot process the request. 
The Enhanced Key Usage (EKU) field of the certificate is not set to "Server Authentication". 
Retry the request with a certificate that has the correct EKU.  

这是我用来创建自签名证书的命令:
#Generate a private key
openssl genpkey -algorithm RSA -out private-key.pem

#生成证书签名请求(CSR)
openssl req -new -key private-key.pem -out certificatesigningrequest.pem -days 3650 -subj "/C=US/ST=Colorado/L=aspen/CN=10.0.2.4/OU=myhostgroup/O=testinfra" -addext "keyUsage=digitalSignature,keyEncipherment" -addext "extendedKeyUsage=serverAuth,clientAuth"

#生成自签名证书
openssl x509 -req -in certificatesigningrequest.pem -signkey private-key.pem -out self-signed.crt

#将私钥和证书合并到PKCS#12文件中(PFX/P12)
openssl pkcs12 -export -in self-signed.crt -inkey private-key.pem -out certificate.pfx -password pass:P@ssw0rd

执行上面列出的命令行时,它们都没有错误消息,但是,“keyUsage”和“extendedKeyUsage”永远无法插入,并且这些扩展永远不会出现在证书中。当尝试使用 https 配置 winrm 以使用此证书时,结果是错误消息,如上所示。

我想逐一解决问题。
任何人都可以提供一些关于如何使用 openssl 3 处理证书扩展的提示吗?

ssl-certificate
  • 1 1 个回答
  • 73 Views

1 个回答

  • Voted
  1. Best Answer
    Esa Jokinen
    2023-12-13T14:29:52+08:002023-12-13T14:29:52+08:00

    without不会从 CSR 复制扩展名,openssl x509 -req因此-copy_extensions您必须添加,例如-copy_extensions=copyall.

    另外,您-days 3650在错误的命令中指定了; 它也抱怨这一点。

    尝试像这样改变你的工作流程:

    1. 生成私钥(按原样):

      openssl genpkey -algorithm RSA -out private-key.pem
      
    2. 生成证书签名请求 (CSR):

      openssl req -new -key private-key.pem -out certificatesigningrequest.pem \
        -subj "/C=US/ST=Colorado/L=aspen/CN=10.0.2.4/OU=myhostgroup/O=testinfra" \
        -addext "keyUsage=digitalSignature,keyEncipherment" \
        -addext "extendedKeyUsage=serverAuth,clientAuth"
      

      (将 移至-days 3650下一个命令。)

    3. 生成自签名证书:

      openssl x509 -req \
        -days 3650 \
        -copy_extensions=copyall \
        -in certificatesigningrequest.pem \
        -signkey private-key.pem \
        -out self-signed.crt
      

      您现在可以测试openssl x509 -in self-signed.crt -text -noout它是否具有扩展名:

      Certificate:
          Data:
              X509v3 extensions:
                  X509v3 Key Usage: 
                      Digital Signature, Key Encipherment
                  X509v3 Extended Key Usage: 
                      TLS Web Server Authentication, TLS Web Client Authentication
      
      
    4. 将私钥和证书合并到 PKCS#12 文件 (PFX/P12) 中(按原样):

      openssl pkcs12 -export -in self-signed.crt -inkey private-key.pem \
        -out certificate.pfx -password pass:P@ssw0rd
      
    • 4

相关问题

  • SSL证书的区别?

  • 如何修复邮件服务器 SSL?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve