【问题标题】:WCF Client Certificate Validation + Windows AuthenticationWCF 客户端证书验证 + Windows 身份验证
【发布时间】:2018-02-12 09:13:22
【问题描述】:

我已经成功创建了一个 WCF 服务,该服务根据 IIS 中配置的链验证传入的客户端证书。但是,由于这只是一种支持身份验证的安全机制,因此我还需要 Windows 用户调用我的 WCF 服务来处理授权。

通常在提取 Windows 用户时,您会这样做

ServiceSecurityContext.Current.WindowsIdentity.Name

当我的服务配置安全模式TransportWithMessageCredentials 时,ServiceSecurityContext 中的PrimaryIdentity 将返回证书的SubjectName,WindowsIdentity 将为空。

为了查看客户端配置,我指定了 WsHttpBinding 像这样

private static Binding GetHttpsBinding()
{
    var binding = new WSHttpBinding();
    binding.Security.Mode = SecurityMode.TransportWithMessageCredential;
    binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
    binding.Security.Message.ClientCredentialType = MessageCredentialType.Certificate;

    return binding;
}

客户端证书像这样添加到代理客户端:

private static void ApplyClientCertificate(HelloServiceClient client)
{
    client.ClientCredentials.ClientCertificate.SetCertificate(

        storeLocation: StoreLocation.CurrentUser,
        storeName: StoreName.My,
        findType: X509FindType.FindBySubjectName,
        findValue: "ClientCertificatesTest"

   );
}

切换两个ClientCredentialType 值,使绑定看起来像这样

private static Binding GetHttpsBinding()
{
    var binding = new WSHttpBinding();
    binding.Security.Mode = SecurityMode.TransportWithMessageCredential;
    binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
    binding.Security.Message.ClientCredentialType = MessageCredentialType.Windows;

    return binding;
}

将用于提取上述 Windows 凭据,但在提供无效证书或根本没有证书时也可以接受!因此不满足认证要求。我还可以补充一点,以这种方式配置时,我在服务器端的X509CertificateValidator 实现不会触发,因此我怀疑没有添加客户端证书。

肯定有某种方法可以添加客户端证书以进行身份​​验证并添加 Windows 凭据以处理 WCF 中的授权?除了将证书添加到客户端凭据之外,还有其他方法可以添加证书吗?

提前致谢!

【问题讨论】:

    标签: c# wcf authentication ssl iis


    【解决方案1】:

    因此,此问题的答案将是创建您自己的CustomBinding 以获取 Windows 凭据和证书验证。

    【讨论】:

      【解决方案2】:

      通过 Web 服务引用,您可以同时提供客户端证书和 Windows 身份验证凭据,所以奇怪的是,这不适用于 WCF?

      您是否实现了自定义绑定或有任何使其工作的示例链接?

      更新:这是创建自定义绑定以获取 Windows 身份验证和客户端证书的解决方案。 http://david-homer.blogspot.com/2021/05/using-net-wcf-basichttpbinding-to.html

      谢谢,

      戴夫

      【讨论】:

        猜你喜欢
        • 2011-04-09
        • 2013-10-07
        • 1970-01-01
        • 2015-06-13
        • 2022-06-23
        • 1970-01-01
        • 1970-01-01
        • 2012-08-01
        • 1970-01-01
        相关资源
        最近更新 更多