忽略无效的SSL证书

时间:2011-11-14 11:55:10

标签: c# .net asp.net-mvc-3 svn ssl

我正在尝试从子版本打印出日志消息。但我正在努力绕过无效的SSL证书。这是错误:

  

选项   'https://xxxxx/svn/SiteFabrics/trunk/AppLaunch/Bloc/Frontend':服务器   证书验证失败:为不同的证书颁发   主机名,颁发者不受信任(https://xxxx

我忽略证书错误的尝试是添加以下行:

ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;

然而,由于.net错误仍然相同,这没有任何区别。下面是代码,谁能看到我做错了什么?

        using (SvnClient client = new SvnClient())
        {
            Collection<SvnLogEventArgs> list;
            client.Authentication.DefaultCredentials = new NetworkCredential("user", "pass");

            ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;

            SvnLogArgs la = new SvnLogArgs(); //{ Start=128; End=132; };
            client.LoadConfiguration(Path.Combine(Path.GetTempPath(), "Svn"), true);
            client.GetLog(new Uri("https://[svnurl]"), la, out list);
            ViewBag.SVNLog = list;
        }

5 个答案:

答案 0 :(得分:3)

找到解决这个问题的方法:

首先添加:

        static void SVN_SSL_Override(object sender, SharpSvn.Security.SvnSslServerTrustEventArgs e)
    {
        e.AcceptedFailures = e.Failures;
        e.Save = true;
    }

然后替换我原来的魔术线:

            ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;

用这个:

client.Authentication.SslServerTrustHandlers += new EventHandler<SharpSvn.Security.SvnSslServerTrustEventArgs>(SVN_SSL_Override);

答案 1 :(得分:0)

您可以使用SVN UI(例如tortoisesvn)一次连接到存储库并接受错误的SSL证书,然后它将正常工作。不是代码修复,但可能在您的实例中有效。它确实在我的。

答案 2 :(得分:0)

private void GetClaimParams(string targetUrl, out string loginUrl, out Uri navigationEndUrl)
        {
HttpWebRequest webRequest = null;
            WebResponse response = null;
            webRequest = (HttpWebRequest)WebRequest.Create(targetUrl);
            webRequest.Method = Constants.WR_METHOD_OPTIONS;
            #if DEBUG
                ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(IgnoreCertificateErrorHandler);
            #endif
            try
            {
                response = (WebResponse)webRequest.GetResponse();
                ExtraHeadersFromResponse(response, out loginUrl, out navigationEndUrl);
            }
            catch (WebException webEx)
            {
                ExtraHeadersFromResponse(webEx.Response, out loginUrl, out navigationEndUrl);
            }
}



#if DEBUG
        private bool IgnoreCertificateErrorHandler
           (object sender,
           System.Security.Cryptography.X509Certificates.X509Certificate certificate,
           System.Security.Cryptography.X509Certificates.X509Chain chain,
           System.Net.Security.SslPolicyErrors sslPolicyErrors)
        {
            return true;
        }
#endif // DEBUG

答案 3 :(得分:0)

我正在使用这个......试一试:

//As given in the url to handle invalid SSL : http://msdn.microsoft.com/en-us/library/system.net.servicepointmanager.servercertificatevalidationcallback.aspx

                ServicePointManager.ServerCertificateValidationCallback += new System.Net.Security.RemoteCertificateValidationCallback(AcceptAllCertificatePolicy.CheckValidationResult);

答案 4 :(得分:0)

与上述答案几乎相同,只是将回调作为委托传递。你可以尝试一下,可能适合你 -

ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };