LegacyTlsAuthentication.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. using System;
  3. using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Tls;
  4. namespace Org.BouncyCastle.Crypto.Tls2
  5. {
  6. public interface IClientCredentialsProvider
  7. {
  8. TlsCredentials GetClientCredentials(TlsContext context, CertificateRequest certificateRequest);
  9. }
  10. /// <summary>
  11. /// A temporary class to wrap old CertificateVerifyer stuff for new TlsAuthentication.
  12. /// </summary>
  13. public class LegacyTlsAuthentication : TlsAuthentication
  14. {
  15. protected ICertificateVerifyer verifyer;
  16. protected IClientCredentialsProvider credProvider;
  17. protected Uri TargetUri;
  18. public LegacyTlsAuthentication(Uri targetUri, ICertificateVerifyer verifyer, IClientCredentialsProvider prov)
  19. {
  20. this.TargetUri = targetUri;
  21. this.verifyer = verifyer;
  22. this.credProvider = prov;
  23. }
  24. public virtual void NotifyServerCertificate(Certificate serverCertificate)
  25. {
  26. if (!this.verifyer.IsValid(this.TargetUri, serverCertificate.GetCertificateList()))
  27. throw new TlsFatalAlert(AlertDescription.user_canceled);
  28. }
  29. public virtual TlsCredentials GetClientCredentials(TlsContext context, CertificateRequest certificateRequest)
  30. {
  31. return credProvider == null ? null : credProvider.GetClientCredentials(context, certificateRequest);
  32. }
  33. }
  34. }
  35. #endif