CertificateStatus.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cmp;
  5. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
  6. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Cms;
  7. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.IO;
  8. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Math;
  9. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Security;
  10. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  11. using Best.HTTP.SecureProtocol.Org.BouncyCastle.X509;
  12. namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Cmp
  13. {
  14. public class CertificateStatus
  15. {
  16. private static readonly DefaultSignatureAlgorithmIdentifierFinder sigAlgFinder = new DefaultSignatureAlgorithmIdentifierFinder();
  17. private readonly DefaultDigestAlgorithmIdentifierFinder digestAlgFinder;
  18. private readonly CertStatus certStatus;
  19. public CertificateStatus(DefaultDigestAlgorithmIdentifierFinder digestAlgFinder, CertStatus certStatus)
  20. {
  21. this.digestAlgFinder = digestAlgFinder;
  22. this.certStatus = certStatus;
  23. }
  24. public virtual PkiStatusInfo StatusInfo => certStatus.StatusInfo;
  25. public virtual BigInteger CertRequestID => certStatus.CertReqID.Value;
  26. public virtual bool IsVerified(X509Certificate cert)
  27. {
  28. AlgorithmIdentifier digAlg = digestAlgFinder.Find(sigAlgFinder.Find(cert.SigAlgName));
  29. if (null == digAlg)
  30. throw new CmpException("cannot find algorithm for digest from signature " + cert.SigAlgName);
  31. byte[] digest = DigestUtilities.CalculateDigest(digAlg.Algorithm, cert.GetEncoded());
  32. return Arrays.ConstantTimeAreEqual(certStatus.CertHash.GetOctets(), digest);
  33. }
  34. }
  35. }
  36. #pragma warning restore
  37. #endif