cow*_*ert 3 iis curl openssl certificate self-signed
我在 Windows Server Enterprise 2008 上使用 IIS 7 来生成自签名证书以与 IIS 一起使用(基本上是一键式按钮)。
但是,即使我将此证书导出并将其添加到 Windows 客户端的 curl-ca-bundle.crt,它和 openssl.exe 都不会正确验证证书:
openssl s_client -CAfile curl-ca-bundle.crt -showcerts -connect myserver.ad.pri:443
CONNECTED(00000003)
depth=0 /CN=myserver.ad.pri
verify error:num=20:unable to get local issuer certificate
verify return:1
depth=0 /CN=myserver.ad.pri
verify error:num=21:unable to verify the first certificate
verify return:1
---
Certificate chain
0 s:/CN=myserver.ad.pri
i:/CN=myserver.ad.pri
-----BEGIN CERTIFICATE-----
MIIDADCCAeigAwIBAgIQTi9gdBLdo6pJ1h4Zljr/wzANBgkqhkiG9w0BAQUFADAp
....
-----END CERTIFICATE-----
---
Server certificate
subject=/CN=myserver.ad.pri
issuer=/CN=myserver.ad.pri
---
No client certificate CA names sent
---
SSL handshake has read 924 bytes and written 444 bytes
---
New, TLSv1/SSLv3, Cipher is AES128-SHA
Server public key is 2048 bit
Compression: NONE
Expansion: NONE
SSL-Session:
Protocol : TLSv1
Cipher : AES128-SHA
Session-ID:
Session-ID-ctx:
Master-Key:
Key-Arg : None
Start Time: 1377728216
Timeout : 300 (sec)
Verify return code: 21 (unable to verify the first certificate)
---
read:errno=104
Run Code Online (Sandbox Code Playgroud)
我使用 IE 将证书导出为 Base-64 Encoded,这是 openssl 可读的 PEM: openssl x509 -inform PEM -in myserver.crt -text
Certificate:
Data:
Version: 3 (0x2)
Serial Number:
4e:2f:60:74:12:dd:a3:aa:49:d6:1e:19:96:3a:ff:c3
Signature Algorithm: sha1WithRSAEncryption
Issuer: CN=myserver.ad.pri
Validity
Not Before: Aug 26 15:38:46 2013 GMT
Not After : Aug 26 00:00:00 2014 GMT
Subject: CN=myserver.ad.pri
Subject Public Key Info:
Public Key Algorithm: rsaEncryption
RSA Public Key: (2048 bit)
Modulus (2048 bit):
....
Exponent: 65537 (0x10001)
X509v3 extensions:
X509v3 Key Usage:
Key Encipherment, Data Encipherment
X509v3 Extended Key Usage:
TLS Web Server Authentication
Signature Algorithm: sha1WithRSAEncryption
...
-----BEGIN CERTIFICATE-----
....
Run Code Online (Sandbox Code Playgroud)
具有相同 curl-ca-bundle.crt 的 openssl/curl 将验证来自 google.com:443 等的证书。
当我无法让 NodeJS HTTP(s) 客户端连接到带有自签名证书的 IIS 实例(一个创建通过 IIS 管理器)刚刚得到可怕的'无法验证第一个证书错误!
似乎这是因为 IISManager 为此目的创建的证书指定了一些“密钥用法”扩展;“密钥加密”和“数据加密”。
事实证明,当 openssl 遇到指定“密钥用法”但未能指定“certSign”用法的证书时,即使该证书已正确提供给 openssl 代码,openssl 代码也会将该证书视为可能的 CA 证书(意思是它无法根据所说的缺席 CA 验证证书!)。
解决方案与上面已经提到的一样,即使用正确的密钥用法(或没有密钥用法扩展!)创建自己的证书。
我还认为我应该包括另一种创建自签名证书的方法,如果您在 Windows 环境中,openssl 客户端会很满意。
首先从这里下载powershell脚本
在 powershell 控制台(管理)中,从包含下载的脚本的文件夹中执行以下命令
New-SelfsignedCertificateEx -StoreLocation "LocalMachine" -KeyUsage "DigitalSignature,KeyEncipherment,KeyCertSign" -Subject "CN=<HOST_NAME_TO_USE>" -FriendlyName "<HOST_NAME_TO_USE>" -SignatureAlgorithm sha256 -SubjectAlternativeName "<HOST_NAME_TO_USE>","anotherhost.org","someotherdomain.com"
Run Code Online (Sandbox Code Playgroud)
执行上述命令后,您的 LocalMachine\Personal Certificates 存储将包含一个自签名证书,IIS 可以使用该证书进行 SSL 通信。(请注意,您可能还需要将此证书复制到受信任的根存储区之一,以确保该证书在该计算机上受信任)
| 归档时间: |
|
| 查看次数: |
3455 次 |
| 最近记录: |