繁体   English   中英

WCF 客户端证书验证 + Windows 身份验证

[英]WCF Client Certificate Validation + Windows Authentication

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

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

ServiceSecurityContext.Current.WindowsIdentity.Name

当我的服务配置为安全模式TransportWithMessageCredentialsServiceSecurityContextPrimaryIdentity将返回证书的SubjectNameWindowsIdentity将为空。

为了查看客户端配置,我指定了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 中的授权? 除了将证书添加到客户端凭据之外,还有其他方法可以添加证书吗?

提前致谢!

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

使用 Web 服务引用,您可以同时提供客户端证书和 Windows 身份验证凭据,所以奇怪的是,WCF 不能开箱即用?

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

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

谢谢,

戴夫

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM