Security.cs 778 B

12345678910111213141516171819202122232425262728
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net;
  5. using System.Net.Security;
  6. using System.Security.Cryptography.X509Certificates;
  7. using System.Text;
  8. namespace XUnity.AutoTranslator.Plugin.Core.Web
  9. {
  10. public static class Security
  11. {
  12. public static RemoteCertificateValidationCallback AlwaysAllowByHosts( params string[] hosts )
  13. {
  14. var lookup = new HashSet<string>( hosts, StringComparer.OrdinalIgnoreCase );
  15. return ( sender, certificate, chain, sslPolicyErrors ) =>
  16. {
  17. var request = sender as HttpWebRequest;
  18. if( request != null )
  19. {
  20. return lookup.Contains( request.Address.Host );
  21. }
  22. return false;
  23. };
  24. }
  25. }
  26. }