ServiceEndpointConfiguration.cs 969 B

1234567891011121314151617181920212223242526272829303132333435363738
  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 class ServiceEndpointConfiguration
  11. {
  12. public readonly HashSet<string> _hosts = new HashSet<string>();
  13. public void EnableHttps( params string[] hosts )
  14. {
  15. foreach( var host in hosts )
  16. {
  17. _hosts.Add( host );
  18. }
  19. }
  20. internal RemoteCertificateValidationCallback GetCertificateValidationCheck()
  21. {
  22. if( _hosts.Count == 0 ) return null;
  23. return ( sender, certificate, chain, sslPolicyErrors ) =>
  24. {
  25. var request = sender as HttpWebRequest;
  26. if( request != null )
  27. {
  28. return _hosts.Contains( request.Address.Host );
  29. }
  30. return false;
  31. };
  32. }
  33. }
  34. }