添加或创建“主题备用名称”使用 makecert 将字段添加到自签名证书

发布于 2024-11-16 00:59:36 字数 253 浏览 2 评论 0 原文

如何使用带有“主题备用名称”字段的 makecert 创建证书?

在此处输入图像描述

您可以使用 - 添加一些字段,例如“增强密钥使用” eku 选项,我尝试过 -san 选项,但 makecert 不喜欢它。

这是一个自签名证书,因此任何使用 IIS 创建发送到 CA 的内容的方法都是不合适的。

How can I create a certificate using makecert with a 'Subject Alternative Name' field ?

enter image description here

You can add some fields eg, 'Enhanced Key Usage' with the -eku option and I've tried the -san option but makecert doesn't like it.

This is a self-signed certificate so any method that uses IIS to create something to send off to a CA won't be appropriate.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

离鸿 2024-11-23 00:59:36

一种更简单的方法是使用 New-SelfSignedCertificate PowerShell commandlet,它默认包含 SAN。您可以通过单个命令创建证书并将其添加到存储中。

New-SelfSignedCertificate -DnsName localhost -CertStoreLocation cert:\LocalMachine\My

请注意,您需要以管理员身份运行 PowerShell。

An even easier way is to use the New-SelfSignedCertificate PowerShell commandlet, which includes a SAN by default. In a single command you can create the certificate and add it to the store.

New-SelfSignedCertificate -DnsName localhost -CertStoreLocation cert:\LocalMachine\My

Note that you need to run PowerShell as an administrator.

铁轨上的流浪者 2024-11-23 00:59:36

Makecert 似乎不支持 SAN,因此我创建了一个包含 SAN 的证书,以便使用 OpenSSL 与 IIS 一起使用。查看我的博客文章:

IIS 7提供了一些易于使用的向导来创建SSL证书,
但不是很强大。我需要做的是创建 SSL
包含 x.509 V3 扩展的证书,即 subject
替代名称,又名 SAN。 SAN 的作用是允许网站
用于验证多个 URL 域传入请求的证书
姓名。当 Web 服务器运行 Web 时,这一点非常重要
服务(例如 WCF 服务)以及其他 Web 服务连接到时
它们通过 SSL 连接与面向服务的架构一样。
除非向 Web 服务添加特殊代码来覆盖
默认 SSL 验证处理程序例程,通用名称 (CN)
证书必须与传入请求 URL 域匹配。所以如果
请求是使用 FQDN 发出的,证书的 FQDN 必须为
CN 或 SAN、IP 地址或主机名都会导致 SSL
验证错误,连接将失败。

SAN 来救援……SAN 支持 DNS 名称和 IP 等
地址。因此,通过使用服务器 FQDN 的 SAN 创建证书
和 IP 地址,它增加了其他 Web 服务可以使用的方式
连接。

有很多可以生成证书的工具:
makecert.exe、keytool.exe (java)、selfssl.exe 和 openssl.exe。在
此外,从 Windows Vista 和 Server 2008 开始 Microsoft 添加了
CertEnroll API,也可以通过编程方式创建证书
通过 COM 接口。

OpenSSL 最终完成了我需要它做的事情。过程是
相当简单。

  1. 构建 OpenSSL 配置文件。

[req] 杰出名称 = 要求杰出名称 x509_extensions =
v3_req 提示 = no [req_distinguished_name] C = US ST = VAL =
某处 O = MyOrg OU = MyOU CN = MyServerName [v3_req] keyUsage =
密钥加密、数据加密扩展密钥使用 = serverAuth
subjectAltName = @alt_names [alt_names] DNS.1 = MyServerName DNS.2 =
10.0.1.34 IP.1 = 10.0.1.34 IP.2 = 192.167.20.1

  • 使用 OpenSSL 创建 x509 请求
  • openssl.exe req -x509 -nodes -days 730 -newkey rsa:2048 -keyout
    C:\cert.pem -out C:\cert.pem -config C:\PathToConfigFileAbove.txt

  • 创建包含密钥对的 PFX
  • openssl.exe pkcs12 -export -out C:\cert.pfx -in C:\cert.pem -name "我的
    证书”-passout pass:mypassword

  • 使用服务器中的导入链接将 PFX 导入 IIS
    证书区。

  • 将证书绑定到 IIS 网站。

  • 还有 viola,我们知道 IIS 和 SAN 都有 SSL 证书,所以我们可以
    使用多个域名进行连接,无需证书验证
    错误。

    来源:使用 OpenSSL 通过 SAN 创建证书< /em> 作者:Andy Arismeti,2011 年 9 月 1 日,星期四

    Makecert doesn't appear to support SANs so I created a certificate with SANs for use with IIS using OpenSSL. Check out my blog post about it:

    IIS 7 provides some easy to use wizards to create SSL certificates,
    however not very powerful ones. What I needed to do was to create SSL
    certificates that included a x.509 V3 extension, namely subject
    alternative names, a.k.a SANs. What SANs do is allow the website
    certificate to validate incoming requests by more than one URL domain
    name. This is really important when the web server is running web
    services such as WCF services and when other web services connect to
    them over SSL connections as with service oriented architectures.
    Unless special code is added to the web services to override the
    default SSL validation handler routines, the common name (CN) of the
    certificate MUST match the incoming request URL domain. So if the
    request was made using an FQDN, the certificate must have the FQDN as
    a CN or a SAN, a IP address or just a hostname will cause an SSL
    validation error and the connection will fail.

    SANs to the rescue… SANs support, among other things, DNS names and IP
    addresses. So by creating the certificate with SANs of the server FQDN
    and IP address, it increases the ways that other web services can
    connect.

    There are a number of tools that can generate certificates:
    makecert.exe, keytool.exe (java), selfssl.exe and openssl.exe. In
    addition, starting with Windows Vista and Server 2008 Microsoft added
    the CertEnroll API which can also create certificates programmatically
    either through COM interfaces.

    OpenSSL ended up doing exactly what I needed it to do. The process was
    fairly straight forward.

    1. Construct an OpenSSL config file.

    [req] distinguished_name = req_distinguished_name x509_extensions =
    v3_req prompt = no [req_distinguished_name] C = US ST = VA L =
    Somewhere O = MyOrg OU = MyOU CN = MyServerName [v3_req] keyUsage =
    keyEncipherment, dataEncipherment extendedKeyUsage = serverAuth
    subjectAltName = @alt_names [alt_names] DNS.1 = MyServerName DNS.2 =
    10.0.1.34 IP.1 = 10.0.1.34 IP.2 = 192.167.20.1

    1. Create x509 request with OpenSSL

    openssl.exe req -x509 -nodes -days 730 -newkey rsa:2048 -keyout
    C:\cert.pem -out C:\cert.pem -config C:\PathToConfigFileAbove.txt

    1. Create a PFX containing the keypair

    openssl.exe pkcs12 -export -out C:\cert.pfx -in C:\cert.pem -name "My
    Cert" -passout pass:mypassword

    1. Import the PFX into IIS using the import link in the server
      certificates area.

    2. Bind the certificate to the IIS websites.

    And viola, we know have a SSL certificate for IIS with SANs so we can
    connect using multiple domain names without certificate validation
    errors.

    Source: Creating certificates with SANs using OpenSSL by Andy Arismeti, Thursday, September 1, 2011

    想你的星星会说话 2024-11-23 00:59:36

    更新

    使用下面的 makecert 方法生成的证书不能在所有浏览器中可靠地工作,因为它实际上并不生成“主题备用名称”。

    如果您检查证书,您会发现它实际上没有 Subject Alternative Name 字段,而是在 Subject 字段中指定多个 CN

    例如

    Subject:
    CN = blah.foo.corp
    CN = blah
    

    ,真正的“SAN”证书将具有以下内容:

    Subject Alternative Name:
    DNS Name=blah.foo.corp
    DNS Name=blah
    

    要了解“主题”字段与“通用名称”和“主题备用名称”字段之间的差异和历史,我建议阅读 (很快)不那么通用的名称

    因此,makecert不能用于生成真正的“SAN”证书,您将需要使用其他工具,例如openssl


    原始答案:

    至少在 Visual Studio 2012 附带的 makecert 版本中,您可以指定多个主题,只需指定逗号分隔的列表 -n " CN=domain1, CN=domain2"

    例如(来自 technet 博客 Makecert.exe SAN 和通配符证书)

    makecert -r -pe -n "CN=*.fabrikam.com, CN=*.contoso.com" -b 01/01/2010 -e 01/01/2100 -eku 1.3.6.1.5.5.7.3.1,1.3.6.1.5.5.7.3.2,1.3.6.1.5.5.7.3.3,1.3.6.1.5.5.7.3.4 -ss my -sr localMachine -sky exchange -sp "Microsoft RSA SChannel Cryptographic Provider" -sy 12 -len 2048
    

    Update

    The certificate generated using the below makecert method does not work reliably in all browsers, because it does not actually generate a "Subject Alternative Name".

    If you examine the certificate you will see that it does not actually have a Subject Alternative Name field, but instead specifies multiple CN in the Subject field.

    E.g.

    Subject:
    CN = blah.foo.corp
    CN = blah
    

    Whereas a real "SAN" cert would have something like:

    Subject Alternative Name:
    DNS Name=blah.foo.corp
    DNS Name=blah
    

    To understand the differences and history between the "Subject" field with "Common Name" and the "Subject Alternative Name" field, I recommend reading The (soon to be) not-so Common Name.

    So it appears that makecert cannot be used to generate a true "SAN" cert, and you will need to use other tools, such as openssl.


    Original Answer:

    At least with the version of makecert that comes with Visual Studio 2012, you can specify multiple subjects, simply by specifying a comma separated list -n "CN=domain1, CN=domain2"

    E.g. (from the technet blog Makecert.exe SAN and Wildcard certificate)

    makecert -r -pe -n "CN=*.fabrikam.com, CN=*.contoso.com" -b 01/01/2010 -e 01/01/2100 -eku 1.3.6.1.5.5.7.3.1,1.3.6.1.5.5.7.3.2,1.3.6.1.5.5.7.3.3,1.3.6.1.5.5.7.3.4 -ss my -sr localMachine -sky exchange -sp "Microsoft RSA SChannel Cryptographic Provider" -sy 12 -len 2048
    
    我很坚强 2024-11-23 00:59:36

    https://learn.microsoft。 com/en-us/powershell/module/pki/new-selfsignedcertificate?view=windowsserver2022-ps

    $params = @{DnsName = 'www.fabrikam.com', 'www.contoso.com' 
    CertStoreLocation = 'Cert:\LocalMachine\My' } 
    
    New-SelfSignedCertificate @params 
    

    New-SelfSignedCertificate -DnsName 'www.fabrikam.com','www.contoso.com' -CertStoreLocation Cert:\LocalMachine\My
    

    这两个示例在以下位置创建自签名 SSL 服务器证书计算机我的商店,主题备用名称为 www.fabrikam.comwww.contoso.com 并将主题和颁发者名称设置为 www.fabrikam.com。 (除非另有说明,第一个将设置为主题/发行人。

    https://learn.microsoft.com/en-us/powershell/module/pki/new-selfsignedcertificate?view=windowsserver2022-ps

    $params = @{DnsName = 'www.fabrikam.com', 'www.contoso.com' 
    CertStoreLocation = 'Cert:\LocalMachine\My' } 
    
    New-SelfSignedCertificate @params 
    

    OR

    New-SelfSignedCertificate -DnsName 'www.fabrikam.com','www.contoso.com' -CertStoreLocation Cert:\LocalMachine\My
    

    These two examples create a self-signed SSL server certificate in the computer MY store with the subject alternative names www.fabrikam.com and www.contoso.com and the Subject and Issuer name set to www.fabrikam.com. (First one will be set to subject/Issuer unless otherwise indicated.

    ~没有更多了~
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文