SSL Web服务:无法创建SSL / TLS安全通道

时间:2012-11-16 08:51:29

标签: c# ssl https

我的C#.net应用程序正在使用HTTPS Web服务。由于证书现在即将到期,我正在尝试使用我已经给出的新版本更新它(我使用javasdks的keytool转换为.p12的.jks文件)。我认为这很容易,因为我知道该怎么做,但它不会合作。

到目前为止我做了什么:

  • 导入的证书到CURRENT_USER \ Personal
  • 导入的证书到LOCAL_MACHINE \ Personal
  • 通过winhttpcertcfg工具给出正确的用户(apppoolidentity)访问证书私钥的权利。以下是权利列表 证书。
  • 使用findprivatekey工具,我还找到了实际的密钥文件,并给予apppoolidentity访问权限。 (无奈之下)。

    C:\ Program Files(x86)\ Windows Resource Kits \ Tools> winhttpcertcfg -l -c LOCAL_MACHINE \ My -s“9000 - Blabla” Microsoft(R)WinHTTP证书配置工具 版权所有(C)Microsoft Corporation 2001。

    匹配证书: CN = 9000 - Blabla C = NO L =“c / o Blabla AS,Blablaaddress” OU = 957839827 OID.1.2.240.111111.1.9.8 = 12345678 OID.1.2.240.111111.1.9.2 = Blabla测试 O = BlaBla AS OU = MULTI-ALLOWED

    有权访问私钥的其他帐户和群组包括:     BUILTIN \管理员     NT AUTHORITY \ SYSTEM     IIS APPPOOL \ ASP.NET v4.0     BUILTIN \用户     NT AUTHORITY \ NETWORK SERVICE     DIGITROLLDMZ \ IIS_WPG

我正在访问的网址看起来像这样:

https://test.blabla.com/blabla-5.0/services/Blabla?wsdl

...如果我从服务器网络浏览器访问它,我选择证书,我选择新的证书,它说它没关系,绿色和SSL按顺序和所有,但我的应用程序代码,看起来像这样:

public static blabla.service.NettforhandlerService getNettforhandlerService(string applicationPath) 
    {
    blabla.service.NettforhandlerService service = new blabla.service.NettforhandlerService();
    if (System.Configuration.ConfigurationManager.AppSettings["CertificateSerialNumber"] != null && System.Configuration.ConfigurationManager.AppSettings["CertificateSerialNumber"].Length > 0)
    {
        string serviceurl = service.Url;
        X509Store store = new X509Store(StoreName.Root, StoreLocation.LocalMachine);
        store.Open(OpenFlags.ReadOnly);
        X509Certificate2Collection col = store.Certificates.Find(X509FindType.FindBySerialNumber, System.Configuration.ConfigurationManager.AppSettings["CertificateSerialNumber"], true);

        ServicePointManager.Expect100Continue = true;
        ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
        ServicePointManager.CertificatePolicy = new TrustHBSCertificatePolicy();

        service.ClientCertificates.Add(col[0]);

    }
    return service;
    }

仅输出此错误:

The request was aborted: Could not create SSL/TLS secure channel.

...我已经在web.config中添加了一些跟踪/调试信息,我从错误中发现的是:

[Public Key]
  Algorithm: RSA
  Length: 2048
  Key Blob: 30 82 01 0a 02 82 01 01 00 8e a6 72 c2 e1 67 16 e2 be be c3 30 89 8d bb 57 0b 48 f8 1d 09 b1 e3 26 42 c9 45 9e 02 b2 43 49 16 81 94 1b 18 d6 6d ef ....
System.Net Information: 0 : [15624] SecureChannel#32061089 - Certificate is of type X509Certificate2 and contains the private key.
System.Net Information: 0 : [15624] AcquireCredentialsHandle(package = Microsoft Unified Security Protocol Provider, intent  = Outbound, scc     = System.Net.SecureCredential)
System.Net Error: 0 : [15624] AcquireCredentialsHandle() failed with error 0X8009030D.
System.Net Information: 0 : [15624] AcquireCredentialsHandle(package = Microsoft Unified Security Protocol Provider, intent  = Outbound, scc     = System.Net.SecureCredential)
System.Net Error: 0 : [15624] AcquireCredentialsHandle() failed with error 0X8009030D.
System.Net.Sockets Verbose: 0 : [15624] Socket#38259205::Dispose()
System.Net Error: 0 : [15624] Exception in the HttpWebRequest#54558071:: - The request was aborted: Could not create SSL/TLS secure channel.
System.Net Error: 0 : [15624] Exception in the HttpWebRequest#54558071::GetResponse - The request was aborted: Could not create SSL/TLS secure channel.
System.Net Verbose: 0 : [15624] 

我知道这看起来正确的用户/身份没有获得证书的访问权限(来自winhttpcertcfg),但我非常肯定它有,这就是我在这里失去的原因,

希望有一些认真的https-certificate / web-service -skills的人可以帮助我: - )

感谢。

此致 JørgenE。

edit1:将标题更改为更精确的内容。 edit2:新信息:

In EventViewer/Windows Logs/Security there is an event "Audit Failure" connected to this:

Cryptographic operation.

Subject:
    Security ID:        IIS APPPOOL\ASP.NET v4.0
    Account Name:       ASP.NET v4.0
    Account Domain:     IIS APPPOOL
    Logon ID:       0x32498

Cryptographic Parameters:
    Provider Name:  Microsoft Software Key Storage Provider
    Algorithm Name: Not Available.
    Key Name:   {00E1A3F5-7400-41CA-8290-02983473AEAF}
    Key Type:   Machine key.

Cryptographic Operation:
    Operation:  Open Key.
    Return Code:    0x80090010

3 个答案:

答案 0 :(得分:12)

从日志中提取的内容不多,但是......

Google-fu产生以下结果:0x80090010很可能是证书访问错误。

由此可见,我得出结论,您需要为SSL证书私钥设置权限,以便IIS可以访问它。 看到: http://www.dotnetnoob.com/2011/01/how-to-give-iis-access-to-private-keys.html

与其他选项类似的问题:The request was aborted: Could not create SSL/TLS secure channel

答案 1 :(得分:3)

问题解决了,似乎缺少中级证书,将其导入MMC的中级证书,一切都很好: - )

答案 2 :(得分:0)

迟到的回复,但我遇到了同样的问题,以下更改为我解决了问题。 尝试更改线路 ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3; 与下面的一个 - ServicePointManager.SecurityProtocol =(SecurityProtocolType)3072;

P.S - 我在我的应用程序中使用.Net framework 3.5。