BcTlsRsaPssVerifier.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto;
  5. using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Engines;
  6. using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
  7. using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Signers;
  8. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Tls.Crypto.Impl.BC
  9. {
  10. /// <summary>Operator supporting the verification of RSASSA-PSS signatures using the BC light-weight API.</summary>
  11. public class BcTlsRsaPssVerifier
  12. : BcTlsVerifier
  13. {
  14. private readonly int m_signatureScheme;
  15. public BcTlsRsaPssVerifier(BcTlsCrypto crypto, RsaKeyParameters publicKey, int signatureScheme)
  16. : base(crypto, publicKey)
  17. {
  18. if (!SignatureScheme.IsRsaPss(signatureScheme))
  19. throw new ArgumentException("signatureScheme");
  20. this.m_signatureScheme = signatureScheme;
  21. }
  22. public override bool VerifyRawSignature(DigitallySigned signature, byte[] hash)
  23. {
  24. throw new NotSupportedException();
  25. }
  26. public override TlsStreamVerifier GetStreamVerifier(DigitallySigned signature)
  27. {
  28. SignatureAndHashAlgorithm algorithm = signature.Algorithm;
  29. if (algorithm == null || SignatureScheme.From(algorithm) != m_signatureScheme)
  30. throw new InvalidOperationException("Invalid algorithm: " + algorithm);
  31. int cryptoHashAlgorithm = SignatureScheme.GetCryptoHashAlgorithm(m_signatureScheme);
  32. IDigest digest = m_crypto.CreateDigest(cryptoHashAlgorithm);
  33. PssSigner verifier = new PssSigner(new RsaEngine(), digest, digest.GetDigestSize());
  34. verifier.Init(false, m_publicKey);
  35. return new BcTlsStreamVerifier(verifier, signature.Signature);
  36. }
  37. }
  38. }
  39. #pragma warning restore
  40. #endif