1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
- #pragma warning disable
- using System;
- using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto;
- using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Digests;
- using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Signers;
- namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Tls.Crypto.Impl.BC
- {
- /// <summary>BC light-weight base class for the verifiers supporting the two DSA style algorithms from FIPS PUB
- /// 186-4: DSA and ECDSA.</summary>
- public abstract class BcTlsDssVerifier
- : BcTlsVerifier
- {
- protected BcTlsDssVerifier(BcTlsCrypto crypto, AsymmetricKeyParameter publicKey)
- : base(crypto, publicKey)
- {
- }
- protected abstract IDsa CreateDsaImpl();
- protected abstract short SignatureAlgorithm { get; }
- public override bool VerifyRawSignature(DigitallySigned digitallySigned, byte[] hash)
- {
- SignatureAndHashAlgorithm algorithm = digitallySigned.Algorithm;
- if (algorithm != null && algorithm.Signature != SignatureAlgorithm)
- throw new InvalidOperationException("Invalid algorithm: " + algorithm);
- ISigner signer = new DsaDigestSigner(CreateDsaImpl(), new NullDigest());
- signer.Init(false, m_publicKey);
- if (algorithm == null)
- {
- // Note: Only use the SHA1 part of the (MD5/SHA1) hash
- signer.BlockUpdate(hash, 16, 20);
- }
- else
- {
- signer.BlockUpdate(hash, 0, hash.Length);
- }
- return signer.VerifySignature(digitallySigned.Signature);
- }
- }
- }
- #pragma warning restore
- #endif
|