【问题标题】:Using custom SslStream in WCF client在 WCF 客户端中使用自定义 SslStream
【发布时间】:2012-10-03 09:25:09
【问题描述】:

我正在通过带有客户端身份验证的 https 使用 WCF 服务。代码如下所示

var webHttpBinding = new WebHttpBinding(WebHttpSecurityMode.Transport);
webHttpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
var webChannelFactory = new WebChannelFactory<MyService>(webHttpBinding, serviceUri);
webChannelFactory.Credentials.ClientCertificate.Certificate = clientCertificate;
webChannelFactory.Credentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;

var service = webChannelFactory.CreateChannel();

service.SomeMethod();

问题在于,每当我使用某些客户端证书(来自 pfx 文件)时,.NET SslStream 都希望其签名者和根证书需要存在于 Windows 证书存储中。如果它们不存在,则不会在 TLS 握手期间发送客户端证书,从而导致身份验证失败。

我认为这是 SslStream 的一种行为,无法更改。如果是真的,有没有办法在上面的 WCF 客户端代码中使用自定义 SslStream?例如,OpenSSL.NET 提供了一个没有此限制的 SslStream 类。

提前感谢您的帮助。

【问题讨论】:

    标签: c# wcf


    【解决方案1】:

    您的 clientCertificateX509Certificate 类型吗?在我的测试中,创建 X509Certificate2 类型的证书有助于使用证书,而无需将其安装到 Windows 存储中。

    【讨论】:

    • clientCertificate 是 X509Certificate2 的类型。我在创建它的对象时将 pfx 文件名传递给 X509Certificate2 构造函数。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-30
    • 1970-01-01
    • 2010-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-17
    相关资源
    最近更新 更多