LegacyTlsAuthentication.cs 1.3 KB

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