CertificateStatus.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cmp;
  5. using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
  6. using BestHTTP.SecureProtocol.Org.BouncyCastle.Cms;
  7. using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.IO;
  8. using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
  9. using BestHTTP.SecureProtocol.Org.BouncyCastle.Security;
  10. using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  11. using BestHTTP.SecureProtocol.Org.BouncyCastle.X509;
  12. namespace BestHTTP.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 PkiStatusInfo PkiStatusInfo
  25. {
  26. get { return certStatus.StatusInfo; }
  27. }
  28. public BigInteger CertRequestId
  29. {
  30. get { return certStatus.CertReqID.Value; }
  31. }
  32. public bool IsVerified(X509Certificate cert)
  33. {
  34. AlgorithmIdentifier digAlg = digestAlgFinder.find(sigAlgFinder.Find(cert.SigAlgName));
  35. if (null == digAlg)
  36. throw new CmpException("cannot find algorithm for digest from signature " + cert.SigAlgName);
  37. byte[] digest = DigestUtilities.CalculateDigest(digAlg.Algorithm, cert.GetEncoded());
  38. return Arrays.ConstantTimeAreEqual(certStatus.CertHash.GetOctets(), digest);
  39. }
  40. }
  41. }
  42. #pragma warning restore
  43. #endif