AbstractTlsCrypto.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using System.Collections.Generic;
  5. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Math;
  6. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Security;
  7. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  8. namespace Best.HTTP.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 HasAnyStreamVerifiers(IList<SignatureAndHashAlgorithm> signatureAndHashAlgorithms);
  16. public abstract bool HasAnyStreamVerifiersLegacy(short[] clientCertificateTypes);
  17. public abstract bool HasCryptoHashAlgorithm(int cryptoHashAlgorithm);
  18. public abstract bool HasCryptoSignatureAlgorithm(int cryptoSignatureAlgorithm);
  19. public abstract bool HasDHAgreement();
  20. public abstract bool HasECDHAgreement();
  21. public abstract bool HasEncryptionAlgorithm(int encryptionAlgorithm);
  22. public abstract bool HasHkdfAlgorithm(int cryptoHashAlgorithm);
  23. public abstract bool HasMacAlgorithm(int macAlgorithm);
  24. public abstract bool HasNamedGroup(int namedGroup);
  25. public abstract bool HasRsaEncryption();
  26. public abstract bool HasSignatureAlgorithm(short signatureAlgorithm);
  27. public abstract bool HasSignatureAndHashAlgorithm(SignatureAndHashAlgorithm sigAndHashAlgorithm);
  28. public abstract bool HasSignatureScheme(int signatureScheme);
  29. public abstract bool HasSrpAuthentication();
  30. public abstract TlsSecret CreateSecret(byte[] data);
  31. public abstract TlsSecret GenerateRsaPreMasterSecret(ProtocolVersion clientVersion);
  32. public abstract SecureRandom SecureRandom { get; }
  33. public virtual TlsCertificate CreateCertificate(byte[] encoding)
  34. {
  35. return CreateCertificate(CertificateType.X509, encoding);
  36. }
  37. public abstract TlsCertificate CreateCertificate(short type, byte[] encoding);
  38. public abstract TlsCipher CreateCipher(TlsCryptoParameters cryptoParams, int encryptionAlgorithm, int macAlgorithm);
  39. public abstract TlsDHDomain CreateDHDomain(TlsDHConfig dhConfig);
  40. public abstract TlsECDomain CreateECDomain(TlsECConfig ecConfig);
  41. public virtual TlsSecret AdoptSecret(TlsSecret secret)
  42. {
  43. // TODO[tls] Need an alternative that doesn't require AbstractTlsSecret (which holds literal data)
  44. if (secret is AbstractTlsSecret)
  45. {
  46. AbstractTlsSecret sec = (AbstractTlsSecret)secret;
  47. return CreateSecret(sec.CopyData());
  48. }
  49. throw new ArgumentException("unrecognized TlsSecret - cannot copy data: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(secret));
  50. }
  51. public abstract TlsHash CreateHash(int cryptoHashAlgorithm);
  52. public abstract TlsHmac CreateHmac(int macAlgorithm);
  53. public abstract TlsHmac CreateHmacForHash(int cryptoHashAlgorithm);
  54. public abstract TlsNonceGenerator CreateNonceGenerator(byte[] additionalSeedMaterial);
  55. #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
  56. public abstract TlsNonceGenerator CreateNonceGenerator(ReadOnlySpan<byte> additionalSeedMaterial);
  57. #endif
  58. public abstract TlsSrp6Client CreateSrp6Client(TlsSrpConfig srpConfig);
  59. public abstract TlsSrp6Server CreateSrp6Server(TlsSrpConfig srpConfig, BigInteger srpVerifier);
  60. public abstract TlsSrp6VerifierGenerator CreateSrp6VerifierGenerator(TlsSrpConfig srpConfig);
  61. public abstract TlsSecret HkdfInit(int cryptoHashAlgorithm);
  62. }
  63. }
  64. #pragma warning restore
  65. #endif