还原SSL证书覆盖检查 [英] Restore SSL certificate override check
问题描述
我写一个测试,测试服务,我部署,绕过SSL证书检查我用下面的代码片段实现的SSL覆盖:
I am writing a test to test a service I am deploying, to bypass the ssl cert check I implemented an ssl override using the snippet below:
public static void SSLValidationOverride()
{
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(OnValidationCallback);
}
private static bool OnValidationCallback(object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors errors)
{
if (cert.subject == MyCertSubject)
return true;
else
return false;
}
现在我在代码中使用SSL来调用另一个Web服务,并且要切换调用一个之前默认的SSL检查。什么是做到这一点的最好办法。 MS的帮助表示ServicePointManager.SecurityProtocol的默认值为null(http://msdn.microsoft.com/en-us/library/system.net.servicepointmanager.securityprotocol.aspx)。将其设置为null切换到默认的SSL验证和是否有任何其他的方式来做到这一点。
Now I have to call another webservice using ssl in the code and want to switch to default ssl check before calling that. What's the best way to do that. MS help says the default value of ServicePointManager.SecurityProtocol is null(http://msdn.microsoft.com/en-us/library/system.net.servicepointmanager.securityprotocol.aspx). Will setting it to null switch to default ssl validation and is there any other way to do this.
推荐答案
我结束了设置ServicePointManager .SecurityProtocol为null,它工作正常。虽然我仍然开放,以更好的方式来做到这一点。
I ended up setting ServicePointManager.SecurityProtocol to null and it works fine. Though am still open to better ways to do this
public static void SSLValidationRestore()
{
ServicePointManager.ServerCertificateValidationCallback = null;
}
这篇关于还原SSL证书覆盖检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!