【问题标题】:WCF Client 4.5 C# using CA certificate authority ssl cert. Need assistance, given upWCF 客户端 4.5 C# 使用 CA 证书颁发机构 ssl 证书。需要帮助,放弃
【发布时间】:2015-03-10 12:37:36
【问题描述】:

这里有很多人问同样的问题。但很少有答案或成功的报告。服务器是第三方,所以我不知道他们的配置,但他们确实报告了他们在日志中发现的内容如下:

他们在日志中看到的唯一内容就是这个错误。 “基于 IP,它来自他们的 DEV 环境,但没有有效负载,并且它进入调试时,URL 的格式不正确。”

节点: 时间:20150105 10:21:45.798 严重性:警告 请求编号:00000149c32c8869-3801 消息:消息处理成功

事件类型:消息摘要 客户端IP:56.6.66.6 服务:包罗万象的调试服务 [/*] 操作:空 请求长度:0 响应长度:0 响应状态:0 响应时间:0ms 用户身份 : 用户名:空

这是完整的故事,

我在调用 https 服务器上的 WebService 时从来没有遇到过问题。但他们有 ip 安全性和证书安全性(没有用户名和密码安全性)

奇怪的是,当我通常使用 Visual Studio 时,它们发送了物理 .wsdl 文件,指向它们,一切就绪。不是这种情况。我必须在本地添加文件,并在本地指向它们 c:\project\Server References\file.wsdl 并且一切都正常填充。

我已经在 Google 上搜索了大约 10 个示例(所有示例都有些不同),以了解如何完成此操作。当然,这可以通过配置少(所有代码)或配置中定义的所有内容来完成。它也可以在控制台应用程序或 Web 应用程序中完成。出于理智的目的,我更喜欢控制台,但我都只是装箱。

附:我们持有 SSL 证书和作为客户端的权限,并在没有私钥的情况下向他们发送 SSL 证书。

P.S.S 我用过 Wireshark 和 Fiddler。 Wireshark 显示 8443 端口上的 TCP 连接和纯文本的 url,但数据部分似乎太小而无法保存证书(但这只是正常工作的开放调用吗?)

http://tinypic.com/r/34ihld4/8(wireshark 截图)

http://tinypic.com/r/14jrbx3/8(监视中的wsclient)

Fiddler 显示“握手成功”

这是我正在使用的“无配置代码”

        ws.AccountInfo ai = new ws.AccountInfo();
        ws.BasicAccountInfo[] info = new ws.BasicAccountInfo[10];

        ws.ProductAndService PaS = new ws.ProductAndService();
            System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Ssl3 //have tried them all | System.Net.SecurityProtocolType.Tls | System.Net.SecurityProtocolType.Tls11 | System.Net.SecurityProtocolType.Tls12;
        WSHttpBinding myBinding = new WSHttpBinding();
        myBinding.Security.Mode = SecurityMode.Transport;
        myBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
        myBinding.ReaderQuotas.MaxArrayLength = int.MaxValue;
        myBinding.MaxReceivedMessageSize = int.MaxValue;
        myBinding.UseDefaultWebProxy = false;
        EndpointAddress ea = new EndpointAddress("https://www.some-company.com:8443/DSMProgramsV4/PgnDSMProgramsService");  //odly no .svc ending



        ws.PgnDSMProgramsServiceClient wsclient = new ws.PgnDSMProgramsServiceClient(myBinding,ea);


        // Specify a certificate to use for authenticating the client.
        wsclient.ClientCredentials.ClientCertificate.SetCertificate(StoreLocation.LocalMachine,StoreName.My, X509FindType.FindByIssuerName, "Network Solutions DV Server CA");//the cert i want is found under this name for example www.somesite.com is found and shows up in watch in wsclient below

        string s = "";
        try
        {
            wsclient.Open();//success always
            info = wsclient.GetAccountList("9999", "TEST", "99999999");
            wsclient.Close();
        }

        catch(Exception ex)
        {
             s = ex.Message;// hang and error happens on GetAccount List
        }
        Console.Write(s);
        Console.Write(info[0].ToString());//if we were ever successful, never are though

我得到的错误是向https://www.some-company.com:8443/DSMProgramsV4/PgnDSMProgramsService 发出 HTTP 请求时发生错误。这可能是由于在 HTTPS 情况下未使用 HTTP.SYS 正确配置服务器证书。这也可能是由于客户端和服务器之间的安全绑定不匹配造成的。底层连接已关闭:发送时发生意外错误。身份验证失败,因为远程方已关闭传输流

我永远无法收到这条消息

我也尝试过使用 ChannelFactory

            ws.AccountInfo ai = new ws.AccountInfo();
        ws.BasicAccountInfo[] info = new ws.BasicAccountInfo[10];

        ws.ProductAndService PaS = new ws.ProductAndService();

        System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Ssl3;
        string address = "https://www.some-company.com:8443/DSMProgramsV4/PgnDSMProgramsService";
        WSHttpBinding binding = new WSHttpBinding();
        binding.Security.Mode = SecurityMode.Transport;
        binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;


        ChannelFactory<ws.PgnDSMProgramsService> factory = new ChannelFactory<ws.PgnDSMProgramsService>(binding, address);
        factory.Credentials.ClientCertificate.SetCertificate(System.Security.Cryptography.X509Certificates.StoreLocation.LocalMachine, System.Security.Cryptography.X509Certificates.StoreName.My, System.Security.Cryptography.X509Certificates.X509FindType.FindByIssuerName, "Network Solutions DV Server CA");

        ws.PgnDSMProgramsService client = factory.CreateChannel();
        var infoz = client.GetAccountList("9999", "TEST", "999999");

也没有运气,同样的错误信息。

我已经尝试过各种 web.config 和 app.config ,如下所示:

  <system.serviceModel>

<behaviors>
  <endpointBehaviors>
    <behavior name="CustomerEndpointBehavior" >
      <clientCredentials supportInteractive="True">
        <clientCertificate storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName" findValue="www.our-cert.org" />

       <!-- <serviceCertificate>
          <authentication certificateValidationMode="None" revocationMode="NoCheck"  />
          <sslCertificateAuthentication certificateValidationMode="PeerOrChainTrust" trustedStoreLocation="LocalMachine"/>
        </serviceCertificate>-->
      </clientCredentials>

    </behavior>

  </endpointBehaviors>

</behaviors>

<bindings>






  <basicHttpBinding>

    <binding name="CustomerBindingConfig">
      <!--  closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Mtom" textEncoding="utf-8" useDefaultWebProxy="false"  allowCookies="false" > -->
      <!--     <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /> -->
      <security mode="Transport" >
        <transport clientCredentialType="Certificate"/>
      </security>

    </binding>
  </basicHttpBinding>


</bindings>

<client>
  <endpoint address="https://www.some-company.com:8443/DSMProgramsV4/PgnDSMProgramsService"
    binding="basicHttpBinding" bindingConfiguration="CustomerBindingConfig" behaviorConfiguration="CustomerEndpointBehavior"
    contract="ws.PgnDSMProgramsService" name="serviceEndpoint" />
</client>

更复杂的

  <system.serviceModel>

<behaviors>
  <endpointBehaviors>
    <behavior name="CustomerEndpointBehavior">

      <clientCredentials>
        <clientCertificate storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName" findValue="www.our-cert.org" />
        <serviceCertificate>
          <authentication certificateValidationMode="PeerTrust" />
        </serviceCertificate>
      </clientCredentials>

    </behavior>
  </endpointBehaviors>
</behaviors>

<bindings>

  <wsHttpBinding>
    <binding name="CustomerBindingConfig" closeTimeout="00:01:00" openTimeout="00:01:00"
                receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false"
                transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
                allowCookies="false">
      <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
          maxBytesPerRead="4096" maxNameTableCharCount="16384" />
      <reliableSession ordered="true" inactivityTimeout="00:10:00"
          enabled="false" />
      <security mode="Transport">
        <transport clientCredentialType="None" proxyCredentialType="None"
            realm="" />
        <message clientCredentialType="Certificate" negotiateServiceCredential="true"
            algorithmSuite="Default" />
      </security>
    </binding>


  </wsHttpBinding>


</bindings>

<client>
  <endpoint address="https://www.some-company.com:8443/DSMProgramsV4/PgnDSMProgramsService" binding="wsHttpBinding" bindingConfiguration="CustomerBindingConfig" behaviorConfiguration="CustomerEndpointBehavior" contract="ws.PgnDSMProgramsService" name="serviceEndpoint" />
</client>

不像我一直在做尽职调查,见下文

http://www.codeproject.com/Articles/36705/7-simple-steps-to-enable-HTTPS-on-WCF-WsHttp-bindi

http://msdn.microsoft.com/en-us/library/ms789011.aspx

http://robbincremers.me/2011/12/27/wcf-transport-security-and-client-certificate-authentication-with-self-signed-certificates/

http://www.codeproject.com/Articles/18601/An-easy-way-to-use-certificates-for-WCF-security

http://blogs.ugidotnet.org/cfolini/archive/2008/01/04/90561.aspx

Client certificates in wcf

https://notgartner.wordpress.com/2007/09/06/using-certificate-based-authentication-and-protection-with-windows-communication-foundation-wcf/

http://www.codeproject.com/Articles/348595/Use-Mutual-SSL-Authentication-in-WCF

https://social.msdn.microsoft.com/Forums/vstudio/en-US/45df57f0-e010-43ef-92f6-ed06c247d733/ssl-with-client-certificate

【问题讨论】:

  • 如果您正在进行客户端证书身份验证,您不应该向他们发送 SSL 证书(您在“PS”中说您向他们发送了没有私钥的 SSL 证书),您应该发送他们是您的客户身份验证证书。
  • 我们确实在没有私钥的情况下向他们发送了我们的证书。他们告诉我们我们需要建立一个连接,在我们给他们我们的公钥后使用我们的证书(因为他们要求没有私钥)。因此,当您说客户端身份验证证书时,我在没有私钥的情况下导出我的 ssl 证书密钥不是他们想要的吗?我如何向他们发送我的“客户端身份验证证书?我们已经发送了 pfx 文件,其中没有私钥
  • SSL 证书不是客户端身份验证证书。您将无法将 SSL 证书用作客户端身份验证证书。
  • 所以我必须使用自签名证书?我不能使用像网络解决方案这样的证书颁发机构?这家伙正在使用一个stackoverflow.com/questions/7238936/…
  • 您可以使用公共 CA(例如 VeriSign 等),但是您需要获得颁发给您的客户端身份验证证书,而不是 SSL 证书。

标签: c# wcf ssl https


【解决方案1】:

如果您还没有,您应该启用 WCF 跟踪,这可能有助于确定 WCF 安全问题的根本原因。我们发现 WCF 跟踪日志将揭示以前“隐藏”的问题。

http://msdn.microsoft.com/en-us/library/ms733025(v=vs.110).aspx

【讨论】:

  • 它似乎对我没有帮助,也许有人? pastebin.com/UwJuZR8qwww.some-site.com 已被虚构替换
  • 内部异常:“System.IO.IOException:身份验证失败,因为远程方已关闭传输流”。有什么方法可以查询服务器端错误/问题?
  • 我也在看。我转发了
【解决方案2】:

很遗憾,这不是一个答案,版主可能想删除这个问题,但仍想感谢那些提供帮助的人。服务器端(我无法控制其他电话呼叫)必须为 TLS 使用不同的端口 4443 而不是 8443(ps 分配的地方已禁用 SSL,这被标记为我在分配中的问题的答案地点)

【讨论】:

    【解决方案3】:

    由于在这种情况下我只是 WCF 客户端,所以我能做的很少。显然 SoapUI 可以帮助证明它有效。但是,如果您在 .NET 中开发并使用 WCF 对您没有帮助。客户使用 Layer7 中间件 XML 硬件设备也使事情复杂化。最后我不得不创建一个特定的自定义绑定:

      <customBinding>
    <binding name="Secured">
      <textMessageEncoding messageVersion="Soap11"/>
      <httpsTransport authenticationScheme="Anonymous" realm="" requireClientCertificate="true"/>
    </binding>
    

    这似乎从 Soap1.2 “回滚”

    另外,我给他们的 IP 地址也是个问题。我的网站位于 IIS 中,并且在绑定到网络花园 ip 的工作进程下。在外部,如果您执行 nslookup,它会显示为 205.14.55.250,例如我的域。但是,当添加代码以获取我的外部 IP 地址时,它实际上使用了另一个 ip 205.14.55.251(未分配给我的 IIS 中的任何网站)

    这两个变化解决了问题

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-12-26
      • 1970-01-01
      • 1970-01-01
      • 2018-03-28
      • 2013-11-04
      • 1970-01-01
      相关资源
      最近更新 更多