CertHash.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
  5. using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  6. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.IsisMtt.Ocsp
  7. {
  8. /**
  9. * ISIS-MTT PROFILE: The responder may include this extension in a response to
  10. * send the hash of the requested certificate to the responder. This hash is
  11. * cryptographically bound to the certificate and serves as evidence that the
  12. * certificate is known to the responder (i.e. it has been issued and is present
  13. * in the directory). Hence, this extension is a means to provide a positive
  14. * statement of availability as described in T8.[8]. As explained in T13.[1],
  15. * clients may rely on this information to be able to validate signatures after
  16. * the expiry of the corresponding certificate. Hence, clients MUST support this
  17. * extension. If a positive statement of availability is to be delivered, this
  18. * extension syntax and OID MUST be used.
  19. * <p/>
  20. * <p/>
  21. * <pre>
  22. * CertHash ::= SEQUENCE {
  23. * hashAlgorithm AlgorithmIdentifier,
  24. * certificateHash OCTET STRING
  25. * }
  26. * </pre>
  27. */
  28. public class CertHash
  29. : Asn1Encodable
  30. {
  31. private readonly AlgorithmIdentifier hashAlgorithm;
  32. private readonly byte[] certificateHash;
  33. public static CertHash GetInstance(
  34. object obj)
  35. {
  36. if (obj == null || obj is CertHash)
  37. {
  38. return (CertHash) obj;
  39. }
  40. if (obj is Asn1Sequence)
  41. {
  42. return new CertHash((Asn1Sequence) obj);
  43. }
  44. throw new ArgumentException("unknown object in factory: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
  45. }
  46. /**
  47. * Constructor from Asn1Sequence.
  48. * <p/>
  49. * The sequence is of type CertHash:
  50. * <p/>
  51. * <pre>
  52. * CertHash ::= SEQUENCE {
  53. * hashAlgorithm AlgorithmIdentifier,
  54. * certificateHash OCTET STRING
  55. * }
  56. * </pre>
  57. *
  58. * @param seq The ASN.1 sequence.
  59. */
  60. private CertHash(
  61. Asn1Sequence seq)
  62. {
  63. if (seq.Count != 2)
  64. throw new ArgumentException("Bad sequence size: " + seq.Count);
  65. this.hashAlgorithm = AlgorithmIdentifier.GetInstance(seq[0]);
  66. this.certificateHash = DerOctetString.GetInstance(seq[1]).GetOctets();
  67. }
  68. /**
  69. * Constructor from a given details.
  70. *
  71. * @param hashAlgorithm The hash algorithm identifier.
  72. * @param certificateHash The hash of the whole DER encoding of the certificate.
  73. */
  74. public CertHash(
  75. AlgorithmIdentifier hashAlgorithm,
  76. byte[] certificateHash)
  77. {
  78. if (hashAlgorithm == null)
  79. throw new ArgumentNullException("hashAlgorithm");
  80. if (certificateHash == null)
  81. throw new ArgumentNullException("certificateHash");
  82. this.hashAlgorithm = hashAlgorithm;
  83. this.certificateHash = (byte[]) certificateHash.Clone();
  84. }
  85. public AlgorithmIdentifier HashAlgorithm
  86. {
  87. get { return hashAlgorithm; }
  88. }
  89. public byte[] CertificateHash
  90. {
  91. get { return (byte[]) certificateHash.Clone(); }
  92. }
  93. /**
  94. * Produce an object suitable for an Asn1OutputStream.
  95. * <p/>
  96. * Returns:
  97. * <p/>
  98. * <pre>
  99. * CertHash ::= SEQUENCE {
  100. * hashAlgorithm AlgorithmIdentifier,
  101. * certificateHash OCTET STRING
  102. * }
  103. * </pre>
  104. *
  105. * @return an Asn1Object
  106. */
  107. public override Asn1Object ToAsn1Object()
  108. {
  109. return new DerSequence(hashAlgorithm, new DerOctetString(certificateHash));
  110. }
  111. }
  112. }
  113. #pragma warning restore
  114. #endif