AbstractTlsCrypto.cs 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using System.IO;
  5. using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
  6. using BestHTTP.SecureProtocol.Org.BouncyCastle.Security;
  7. using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  8. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Tls.Crypto.Impl
  9. {
  10. /// <summary>Base class for a TlsCrypto implementation that provides some needed methods from elsewhere in the impl
  11. /// package.</summary>
  12. public abstract class AbstractTlsCrypto
  13. : TlsCrypto
  14. {
  15. public abstract bool HasAllRawSignatureAlgorithms();
  16. public abstract bool HasDHAgreement();
  17. public abstract bool HasECDHAgreement();
  18. public abstract bool HasEncryptionAlgorithm(int encryptionAlgorithm);
  19. public abstract bool HasCryptoHashAlgorithm(int cryptoHashAlgorithm);
  20. public abstract bool HasCryptoSignatureAlgorithm(int cryptoSignatureAlgorithm);
  21. public abstract bool HasMacAlgorithm(int macAlgorithm);
  22. public abstract bool HasNamedGroup(int namedGroup);
  23. public abstract bool HasRsaEncryption();
  24. public abstract bool HasSignatureAlgorithm(short signatureAlgorithm);
  25. public abstract bool HasSignatureAndHashAlgorithm(SignatureAndHashAlgorithm sigAndHashAlgorithm);
  26. public abstract bool HasSignatureScheme(int signatureScheme);
  27. public abstract bool HasSrpAuthentication();
  28. public abstract TlsSecret CreateSecret(byte[] data);
  29. public abstract TlsSecret GenerateRsaPreMasterSecret(ProtocolVersion clientVersion);
  30. public abstract SecureRandom SecureRandom { get; }
  31. public abstract TlsCertificate CreateCertificate(byte[] encoding);
  32. public abstract TlsCipher CreateCipher(TlsCryptoParameters cryptoParams, int encryptionAlgorithm, int macAlgorithm);
  33. public abstract TlsDHDomain CreateDHDomain(TlsDHConfig dhConfig);
  34. public abstract TlsECDomain CreateECDomain(TlsECConfig ecConfig);
  35. public virtual TlsSecret AdoptSecret(TlsSecret secret)
  36. {
  37. // TODO[tls] Need an alternative that doesn't require AbstractTlsSecret (which holds literal data)
  38. if (secret is AbstractTlsSecret)
  39. {
  40. AbstractTlsSecret sec = (AbstractTlsSecret)secret;
  41. return CreateSecret(sec.CopyData());
  42. }
  43. throw new ArgumentException("unrecognized TlsSecret - cannot copy data: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(secret));
  44. }
  45. public abstract TlsHash CreateHash(int cryptoHashAlgorithm);
  46. public abstract TlsHmac CreateHmac(int macAlgorithm);
  47. public abstract TlsHmac CreateHmacForHash(int cryptoHashAlgorithm);
  48. public abstract TlsNonceGenerator CreateNonceGenerator(byte[] additionalSeedMaterial);
  49. public abstract TlsSrp6Client CreateSrp6Client(TlsSrpConfig srpConfig);
  50. public abstract TlsSrp6Server CreateSrp6Server(TlsSrpConfig srpConfig, BigInteger srpVerifier);
  51. public abstract TlsSrp6VerifierGenerator CreateSrp6VerifierGenerator(TlsSrpConfig srpConfig);
  52. public abstract TlsSecret HkdfInit(int cryptoHashAlgorithm);
  53. }
  54. }
  55. #pragma warning restore
  56. #endif