Bläddra i källkod

Merge branch 'master' into new_vimek_merge

Scrublord1336 6 år sedan
förälder
incheckning
2ba981c708

+ 1 - 1
README.md

@@ -16,7 +16,7 @@ The mod can be installed into the following Plugin Managers:
 
 Installations instructions for both methods can be found below.
 
-Additionally it can be installed without a dependency on a plugin manager through ReiPatcher.
+Additionally it can be installed without a dependency on a plugin manager through ReiPatcher. However, this approach is not recommended if you use one of the above mentioned Plugin Managers!
 
 ## Configuration
 The default configuration file, looks as such (2.6.0+):

+ 1 - 0
src/XUnity.AutoTranslator.Plugin.Core/Web/BaiduTranslateEndpoint.cs

@@ -45,6 +45,7 @@ namespace XUnity.AutoTranslator.Plugin.Core.Web
 
       public override void ConfigureServicePointManager()
       {
+         ServicePointManager.ServerCertificateValidationCallback += Security.AlwaysAllowByHosts( "api.fanyi.baidu.com" );
       }
 
       public override bool TryExtractTranslated( string result, out string translated )

+ 1 - 12
src/XUnity.AutoTranslator.Plugin.Core/Web/GoogleTranslateEndpoint.cs

@@ -18,7 +18,6 @@ namespace XUnity.AutoTranslator.Plugin.Core.Web
 {
    public class GoogleTranslateEndpoint : KnownEndpoint
    {
-      private static readonly string CertificateIssuer = "CN=Google Internet Authority G3, O=Google Trust Services, C=US";
       private static readonly string HttpsServicePointTemplateUrl = "https://translate.googleapis.com/translate_a/single?client=t&dt=t&sl={0}&tl={1}&ie=UTF-8&oe=UTF-8&tk={2}&q={3}";
       private static readonly string FallbackHttpsServicePointTemplateUrl = "https://translate.googleapis.com/translate_a/single?client=gtx&sl={0}&tl={1}&dt=t&q={2}";
       private static readonly string HttpsTranslateUserSite = "https://translate.google.com";
@@ -181,17 +180,7 @@ namespace XUnity.AutoTranslator.Plugin.Core.Web
 
       public override void ConfigureServicePointManager()
       {
-         try
-         {
-            ServicePointManager.ServerCertificateValidationCallback += ( sender, certificate, chain, sslPolicyErrors ) =>
-            {
-               return certificate.Issuer == CertificateIssuer;
-            };
-
-         }
-         catch
-         {
-         }
+         ServicePointManager.ServerCertificateValidationCallback += Security.AlwaysAllowByHosts( "translate.google.com", "translate.googleapis.com" );
       }
 
       public override bool TryExtractTranslated( string result, out string translated )

+ 28 - 0
src/XUnity.AutoTranslator.Plugin.Core/Web/Security.cs

@@ -0,0 +1,28 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net;
+using System.Net.Security;
+using System.Security.Cryptography.X509Certificates;
+using System.Text;
+
+namespace XUnity.AutoTranslator.Plugin.Core.Web
+{
+   public static class Security
+   {
+      public static RemoteCertificateValidationCallback AlwaysAllowByHosts( params string[] hosts )
+      {
+         var lookup = new HashSet<string>( hosts, StringComparer.OrdinalIgnoreCase );
+
+         return ( sender, certificate, chain, sslPolicyErrors ) =>
+         {
+            var request = sender as HttpWebRequest;
+            if( request != null )
+            {
+               return lookup.Contains( request.Address.Host );
+            }
+            return false;
+         };
+      }
+   }
+}