webHttpBinding与证书

时间:2014-08-19 11:59:50

标签: c# web-services wcf security certificate

我正在尝试保护自托管服务。 调用服务会返回:
基础连接已关闭:接收时发生意外错误。

服务端点看起来像这样

<endpoint address="https://MACHINE:8010/rest/users" binding="webHttpBinding" bindingConfiguration="certificate" contract="Online.DomainObjects.Remote.IUserManagerRemote" />

我这样做是为了打开访问权限:

 netsh http add urlacl "url=https://+:8010/" user=BUILTIN\Users

我已在服务器中启用了WCF跟踪,但在日志中没有获取任何信息,因此这是客户端连接问题。

我添加了服务行为。

    <behavior name="certificate">
      <serviceCredentials>
        <serviceCertificate
          storeLocation="LocalMachine"
          x509FindType="FindByThumbprint"
          findValue="VALIDTHUMBPRINT" />
      </serviceCredentials>
    </behavior>

我添加了一个绑定配置。

  <webHttpBinding>
    <binding name="certificate">
      <security mode="Transport">
        <transport clientCredentialType="Certificate" />
      </security>
    </binding>
  </webHttpBinding>

以下代码用于调用服务

    X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
    store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);    
    var certificate = store.Certificates.Find(X509FindType.FindByThumbprint, "VALIDTHUMBPRINT", false).OfType<X509Certificate2>().First();

    var request = (HttpWebRequest) WebRequest.Create("https://machine:8010/rest/users/display?key=OnlineStanlibId(1653510)");
    request.ClientCertificates.Add(certificate);
    request.Method = "GET";
    using (var reader = new StreamReader(request.GetResponse().GetResponseStream()))
        reader.ReadToEnd().Dump();

如果我尝试使用fiddler(使用ssl解码)来检查我得到的错误。

A SSLv3-compatible ClientHello handshake was found. Fiddler extracted the parameters below.

    Version: 3.1 (TLS/1.0)
    Random: 53 F3 39 10 E8 4B 5C D6 17 02 8B A0 42 CD 98 B7 37 56 3F B4 35 E6 3E B5 15 89 3B 6D E9 8F BA 19
    SessionID: empty
    Extensions: 
        renegotiation_info  00
        server_name slc11555001
        elliptic_curves secp256r1 [0x17], secp384r1 [0x18]
        ec_point_formats    uncompressed [0x0]
    Ciphers: 
        [002F]  TLS_RSA_AES_128_SHA
        [0035]  TLS_RSA_AES_256_SHA
        [0005]  SSL_RSA_WITH_RC4_128_SHA
        ...(There are more of these)

关于如何进一步调试这一点的任何建议都会很棒......

小提琴文字视图显示了这一点: 对'machine'的HTTPS握手失败。 System.IO.IOException无法从传输连接中读取数据:

1 个答案:

答案 0 :(得分:0)

创建使用传输安全性的自托管Windows Communication Foundation(WCF)服务时,还必须使用X.509证书配置端口。要将证书绑定到服务,您需要使用`netsh add sslcert'命令并提供证书的指纹,应用程序/服务guid和ip / port。

netsh http add sslcert ipport=0.0.0.0:8000 certhash=000...a5e6 appid={001-...-FEFF} 

以下链接提供了很好的参考:
http://msdn.microsoft.com/en-us/library/ms733791(v=vs.110).aspx
HTTPS from a console application?