2011-11-14 33 views
11

Estoy tratando de imprimir los mensajes de registro de nuestra versión secundaria. Pero estoy luchando con eludir el certificado SSL no válido. Este es el error:Ignorando el certificado SSL no válido

OPTIONS of ' https://xxxxx/svn/SiteFabrics/trunk/AppLaunch/Bloc/Frontend ': Server certificate verification failed: certificate issued for a different hostname, issuer is not trusted (https://xxxx)

Mi intento de ignorar el error de certificado fue la de añadir esta línea:

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

Sin embargo, eso no hace ninguna diferencia ya que el error .net sigue siendo el mismo. Debajo está el código, ¿alguien puede ver lo que estoy haciendo mal?

 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; 
     } 
+0

¿Has visto esta publicación ?: http://stackoverflow.com/questions/3099392/svn-repository-authentication-using-sharpsvn – Tomas

+0

En las versiones recientes de SharpSvn puedes usar .UseDefaultConfiguration() en lugar de .LoadConfiguration para evite usar un directorio de temperatura. –

Respuesta

3

encontrado la solución a este problema:

Primera añadir lo siguiente:

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

y luego reemplazar mi línea mágica originales:

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

con esto:

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

Se podía conectar con el repositorio SVN utilizando una interfaz de usuario como tortoisesvn una sola vez y aceptar la mala certificado SSL y entonces todo funcionará bien. No es una corrección de código, pero podría funcionar en su instancia. Lo hizo en el mío.

+0

A la derecha, agregue el emisor del certificado a su lista de autoridades de certificación de confianza, lo cual es mucho mejor en seguridad que aceptar cualquier certificado. – Paciv

+1

Esto es exactamente lo que hace la implementación .SslServerTrustHandlers al establecer .Save = true. Pero guardar por sí mismo probablemente no funcionará porque la ubicación de configuración predeterminada no se utiliza cuando se llama a .LoadConfiguration(). –

0

También es posible usar una expresión lambda (aquí en VB):

AddHandler client.Authentication.SslServerTrustHandlers, Sub(ssender As Object, ev As SharpSvn.Security.SvnSslServerTrustEventArgs) 
    ev.AcceptedFailures = ev.Failures 
    ev.Save = True 
End Sub 
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 
0

estoy usando este ... solo tiene una oportunidad:

//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); 
0

Bastante muy similar a las respuestas anteriores, solo pasando la devolución de llamada como delegado. Puede darle una oportunidad, podría funcionar para usted -

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