.net X509证书和SSL

.net X509证书和SSL,.net,certificate,.net,Certificate,尝试使用从WSDL创建的VisualStudio2008.NET3.5“服务引用”对象执行基本的SSL身份验证Web服务。我们尝试了三种方法:1)设置客户端证书(以匹配服务器提供的证书),2)为服务器提供的证书设置存储,以及3)使用自定义服务器验证器 .NET异常(如下所述)是一致的(对于以下所述的三种方法),“无法为具有权限“ABC.DEF.com”的SSL/TLS安全通道建立信任关系。” Ethereal捕获是一致的(对于下面描述的三种方法),并显示了服务器提供的SSL证书版本的正确客户端和

尝试使用从WSDL创建的VisualStudio2008.NET3.5“服务引用”对象执行基本的SSL身份验证Web服务。我们尝试了三种方法:1)设置客户端证书(以匹配服务器提供的证书),2)为服务器提供的证书设置存储,以及3)使用自定义服务器验证器

.NET异常(如下所述)是一致的(对于以下所述的三种方法),“无法为具有权限“ABC.DEF.com”的SSL/TLS安全通道建立信任关系。”

Ethereal捕获是一致的(对于下面描述的三种方法),并显示了服务器提供的SSL证书版本的正确客户端和服务握手。也就是说,我们可以看到这里描述的所有基本消息():

客户端-->服务器:客户端你好
服务器-->客户端:服务器你好,证书,服务器你好完成
客户端-->服务器:客户端密钥交换、更改密码规范、加密握手消息
服务器-->客户端:更改密码规范,加密握手消息。

在收到最后一条(我们假设是SSL MAC消息)后,客户端立即关闭(TCP FIN/ACK)连接

1) 尝试使用服务器提供的内容设置客户端凭据(预期X509库将使用它来验证服务器在SSL协商期间提供的内容,但需要理解的是,这很可能意味着仅在客户端提供的证书协商期间从客户端向服务器提供)

X509Certificate2\u cert=new X509Certificate2(“\\SomePath\…\ServerSuppliedCert.cer”);
getPrequalInfo_v1 _getInfo=新建getPrequalInfo_v1();//特定于WEB服务
_getInfo.arg0=GetRequestArgs();//特定于WEB服务
PreQualBeanClient _preq=新的PreQualBeanClient();//特定于WEB服务
_preq.ClientCredentials.ClientCertificate.Certificate=\u cert;
getPrequalInfo_v1Response _resp=新建getPrequalInfo_v1Response();//特定于WEB服务

_resp=_preq.getPrequalInfo_v1(_getInfo);// 客户端似乎不信任签署服务器证书(或链中的某个证书,如果使用中间CA签署)的CA。您可以尝试将服务器证书的签名者添加到客户端的信任存储中

您还可以通过执行以下操作获得有关问题的更详细信息,也可以忽略它:

      ServicePointManager.ServerCertificateValidationCallback += ValidateServerCertificate;
...
public static bool ValidateServerCertificate(Object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
   // Here you can display the sslPolicyErrors and/or go through the chain to see which certificate(s) is(are) causing the problem.
   return true; // returning true here will probably "fix" your client side problem
}
X509Certificate2Collection _collection = new X509Certificate2Collection();
        _store = new X509Store(StoreLocation.CurrentUser);
        _store.Open(OpenFlags.ReadOnly);
        X509Certificate2 _cert = new X509Certificate2("\\SomePath\...\ServerSuppliedCert.cer");
        _collection.Add(_cert);
        _store.AddRange(_collection);
        _store.Close();

        getPrequalInfo_v1 _getInfo = new getPrequalInfo_v1();  // WEB SERVICE-SPECIFIC
        _getInfo.arg0 = GetRequestArgs();             // WEB SERVICE-SPECIFIC
        PreQualBeanClient _preq = new PreQualBeanClient();    // WEB SERVICE-SPECIFIC

        _preq.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode
            = System.ServiceModel.Security.X509CertificateValidationMode.PeerOrChainTrust;
        _preq.ClientCredentials.ServiceCertificate.Authentication.TrustedStoreLocation = _store.Location;

        getPrequalInfo_v1Response _resp = new getPrequalInfo_v1Response();  // WEB SERVICE-SPECIFIC
        _resp = _preq.getPrequalInfo_v1(_getInfo);  // << EXCEPTION RAISED HERE,    // WEB SERVICE-SPECIFIC
            getPrequalInfo_v1 _getInfo = new getPrequalInfo_v1();  // WEB SERVICE-SPECIFIC
        _getInfo.arg0 = GetRequestArgs();             // WEB SERVICE-SPECIFIC
        PreQualBeanClient _preq = new PreQualBeanClient();    // WEB SERVICE-SPECIFIC

        _preq.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode
            = System.ServiceModel.Security.X509CertificateValidationMode.Custom;
        _preq.ClientCredentials.ServiceCertificate.Authentication.CustomCertificateValidator
            = new MyX509CertificateValidator("Name");


        getPrequalInfo_v1Response _resp = new getPrequalInfo_v1Response();  // WEB SERVICE-SPECIFIC
        _resp = _preq.getPrequalInfo_v1(_getInfo);  // << EXCEPTION RAISED HERE,    // WEB SERVICE-SPECIFIC
<soap:address location='https://ABC.DEF.com/.../PreQualBean'/>
      ServicePointManager.ServerCertificateValidationCallback += ValidateServerCertificate;
...
public static bool ValidateServerCertificate(Object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
   // Here you can display the sslPolicyErrors and/or go through the chain to see which certificate(s) is(are) causing the problem.
   return true; // returning true here will probably "fix" your client side problem
}