【问题标题】:Custom X509CertificateValidator Check Requestor Against CN针对 CN 的自定义 X509CertificateValidator 检查请求者
【发布时间】:2012-12-13 16:14:22
【问题描述】:

我有一个自定义 X509CertificateValidator,它当前根据为 WCF SOAP 消息提供的证书验证一系列规则。

需要根据提供证书的域检查证书上的 CN 名称,但我不知道我可以从 X509CertificateValidator 中访问请求。

有没有办法检查证书是否与请求域匹配?

【问题讨论】:

    标签: wcf wcf-security x509certificate


    【解决方案1】:

    我没有在 X509CertificateValidator 中找到任何方法来执行此操作,但可以在服务中执行此操作。

    这是我的第一个剪辑 - 我将对其进行改进以使其更优雅,但这很有效。

        private static void ValidateRequestIsFromCertificateDomain()
        {
            RemoteEndpointMessageProperty endpointProperty = OperationContext.Current.IncomingMessageProperties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
            var claimSet = OperationContext.Current.ServiceSecurityContext.AuthorizationContext.ClaimSets[0] as X509CertificateClaimSet;
    
            string domain = claimSet.X509Certificate.GetNameInfo(X509NameType.DnsName, false);
            var resolvedAddress = System.Net.Dns.GetHostAddresses(domain);
    
            if (resolvedAddress.Count() == 0 || endpointProperty.Address != resolvedAddress[0].ToString())
            {
                throw new SecurityException("Client address mismatch");
            }
        }
    

    这并不是真正需要的,因为客户端使用其私钥加密数据,而该私钥只能使用其公钥解密 - 因此您知道证书是由真实客户端提供的。

    但是,如果您像我一样将其作为集成要求,那么这可能对您有用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-02-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-04
      相关资源
      最近更新 更多