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