1 package club.wpia.gigi.ocsp;
3 import java.security.MessageDigest;
4 import java.security.cert.X509Certificate;
5 import java.util.Arrays;
7 import javax.security.auth.x500.X500Principal;
9 import sun.security.provider.certpath.CertId;
10 import sun.security.x509.AlgorithmId;
13 * Idenfies an {@link OCSPIssuer} by remembering its public key hash and its
14 * name hash together with the used hash algorithm. A {@link OCSPIssuer} can be
15 * identified by several {@link OCSPIssuerId}s when they use different hash
18 public class OCSPIssuerId {
20 private final byte[] keyHash;
22 private final byte[] nameHash;
24 private final AlgorithmId alg;
27 * Creates a new OCSPIssuerId for a given {@link OCSPIssuer}. The hash
28 * algorithm has to be specified twice, once for description purposes as
29 * {@link AlgorithmId} and once instantiated as {@link MessageDigest}.
32 * the description of the hash algorithm
34 * the instantiated hash algorithm
38 public OCSPIssuerId(AlgorithmId alg, MessageDigest md, X509Certificate target) {
39 X500Principal dn = target.getSubjectX500Principal();
40 this.keyHash = OCSPResponder.calcKeyHash(target, md);
41 this.nameHash = md.digest(dn.getEncoded());
46 * Creates a new OCSPIssuerId from the {@link CertId} inside an OCSP
52 public OCSPIssuerId(CertId id) {
53 keyHash = id.getIssuerKeyHash();
54 nameHash = id.getIssuerNameHash();
55 alg = id.getHashAlgorithm();
59 public int hashCode() {
62 result = prime * result + ((alg == null) ? 0 : alg.hashCode());
63 result = prime * result + Arrays.hashCode(keyHash);
64 result = prime * result + Arrays.hashCode(nameHash);
69 public boolean equals(Object obj) {
76 if (getClass() != obj.getClass()) {
79 OCSPIssuerId other = (OCSPIssuerId) obj;
81 if (other.alg != null) {
84 } else if ( !alg.equals(other.alg)) {
87 if ( !Arrays.equals(keyHash, other.keyHash)) {
90 if ( !Arrays.equals(nameHash, other.nameHash)) {
96 public AlgorithmId getAlg() {