大网数据广告活动
服务器运维问答

Use openssl 3 to create a self-signed certificate just like what "New-SelfSignedCertificate" can

· 52CE 我爱测

First of all, I did googling about openssl, such as this one , and also tried dozens of time on creating a valid self-signed certificate. But I guess asking on serverfault would be much quicker. My platform is a Windows 10 comput…

问题原文

原帖链接 · user53815 · CC BY-SA 4.0

First of all, I did googling about openssl, such as this one, and also tried dozens of time on creating a valid self-signed certificate.
But I guess asking on serverfault would be much quicker.

My platform is a Windows 10 computer with openssl 3.2.0 light edition installed. The infrastructure has no domain exist, just a testing environment.

The goal is to create a self-signed certificate for windows hosts and windows remote management https protocol to utilize and I did know that the windows powershell "New-SelfSignedCertificate" can solve my demand directly but this is not what I want.

Openssl is the tool I need. I want to use openssl to generate a self-signed certificate(from 0) same as what "New-SelfSignedCertificate" can generate.

I encountered issues when configuring "winrm" after imported the certificate(generated from openssl). The error messages are:

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.  

Here is the commands that I use to create the self-signed certificate:
#Generate a private key
openssl genpkey -algorithm RSA -out private-key.pem

#Generate a certificate signing request (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"

#Generate a self-signed certificate
openssl x509 -req -in certificatesigningrequest.pem -signkey private-key.pem -out self-signed.crt

#combine the private key and certificate into a PKCS#12 file (PFX/P12)
openssl pkcs12 -export -in self-signed.crt -inkey private-key.pem -out certificate.pfx -password pass:P@ssw0rd

When executing the command lines listed above, they all worked with no error messages, however, the "keyUsage" and "extendedKeyUsage" can never be inserted and these extensions never appear in the certificate. The outcome is error messages when trying to configure winrm with https to utilize this certificate, as shown above.

I wanna troubleshoot the issues ony-by-one.
Can anyone provide some hints about how to deal with the extensions for certificate using openssl 3?

已采纳解答

原帖链接 · Esa Jokinen · CC BY-SA 4.0

The openssl x509 -req without -copy_extensions does not copy the extensions from the CSR, so you would have to add, e.g., -copy_extensions=copyall.

Also, you specify the -days 3650 in a wrong command; of which it complains, too.

Try to alter your workflow like this:

  1. Generate a private key (as is):

    openssl genpkey -algorithm RSA -out private-key.pem
    
  2. Generate a certificate signing request (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"
    

    (Moved the -days 3650 to the next command.)

  3. Generate a self-signed certificate:

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

    You can now test with openssl x509 -in self-signed.crt -text -noout that it has the extensions:

    Certificate:
        Data:
            X509v3 extensions:
                X509v3 Key Usage: 
                    Digital Signature, Key Encipherment
                X509v3 Extended Key Usage: 
                    TLS Web Server Authentication, TLS Web Client Authentication
    
    
  4. Combine the private key and certificate into a PKCS#12 file (PFX/P12) (as is):

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

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2023-12-13)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。