jdk/src/java.base/share/classes/sun/security/provider/certpath/CertId.java
author ascarpino
Wed, 03 May 2017 09:04:35 -0700
changeset 44920 5b66112437ba
parent 34687 d302ed125dc9
permissions -rw-r--r--
8176457: Add verbose option to java.security.debug Reviewed-by: vinnie
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
16492
4cd9aa345503 8010112: NullPointerException in sun.security.provider.certpath.CertId()
mullan
parents: 5506
diff changeset
     2
 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5457
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5457
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5457
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5457
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5457
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.security.provider.certpath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 2
diff changeset
    28
import java.io.IOException;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.math.BigInteger;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.security.MessageDigest;
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 2
diff changeset
    31
import java.security.NoSuchAlgorithmException;
16492
4cd9aa345503 8010112: NullPointerException in sun.security.provider.certpath.CertId()
mullan
parents: 5506
diff changeset
    32
import java.security.PublicKey;
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 2
diff changeset
    33
import java.security.cert.X509Certificate;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.Arrays;
16492
4cd9aa345503 8010112: NullPointerException in sun.security.provider.certpath.CertId()
mullan
parents: 5506
diff changeset
    35
import javax.security.auth.x500.X500Principal;
34687
d302ed125dc9 8144995: Move sun.misc.HexDumpEncoder to sun.security.util
chegar
parents: 25859
diff changeset
    36
import sun.security.util.HexDumpEncoder;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import sun.security.x509.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import sun.security.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * This class corresponds to the CertId field in OCSP Request
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * and the OCSP Response. The ASN.1 definition for CertID is defined
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * in RFC 2560 as:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * CertID          ::=     SEQUENCE {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *      hashAlgorithm       AlgorithmIdentifier,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *      issuerNameHash      OCTET STRING, -- Hash of Issuer's DN
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *      issuerKeyHash       OCTET STRING, -- Hash of Issuers public key
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *      serialNumber        CertificateSerialNumber
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * @author      Ram Marti
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
public class CertId {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private static final boolean debug = false;
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 2
diff changeset
    61
    private static final AlgorithmId SHA1_ALGID
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 2
diff changeset
    62
        = new AlgorithmId(AlgorithmId.SHA_oid);
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 2
diff changeset
    63
    private final AlgorithmId hashAlgId;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 2
diff changeset
    64
    private final byte[] issuerNameHash;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 2
diff changeset
    65
    private final byte[] issuerKeyHash;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 2
diff changeset
    66
    private final SerialNumber certSerialNumber;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    private int myhash = -1; // hashcode for this CertId
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * Creates a CertId. The hash algorithm used is SHA-1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     */
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 2
diff changeset
    72
    public CertId(X509Certificate issuerCert, SerialNumber serialNumber)
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 2
diff changeset
    73
        throws IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
16492
4cd9aa345503 8010112: NullPointerException in sun.security.provider.certpath.CertId()
mullan
parents: 5506
diff changeset
    75
        this(issuerCert.getSubjectX500Principal(),
4cd9aa345503 8010112: NullPointerException in sun.security.provider.certpath.CertId()
mullan
parents: 5506
diff changeset
    76
             issuerCert.getPublicKey(), serialNumber);
4cd9aa345503 8010112: NullPointerException in sun.security.provider.certpath.CertId()
mullan
parents: 5506
diff changeset
    77
    }
4cd9aa345503 8010112: NullPointerException in sun.security.provider.certpath.CertId()
mullan
parents: 5506
diff changeset
    78
4cd9aa345503 8010112: NullPointerException in sun.security.provider.certpath.CertId()
mullan
parents: 5506
diff changeset
    79
    public CertId(X500Principal issuerName, PublicKey issuerKey,
4cd9aa345503 8010112: NullPointerException in sun.security.provider.certpath.CertId()
mullan
parents: 5506
diff changeset
    80
                  SerialNumber serialNumber) throws IOException {
4cd9aa345503 8010112: NullPointerException in sun.security.provider.certpath.CertId()
mullan
parents: 5506
diff changeset
    81
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        // compute issuerNameHash
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 2
diff changeset
    83
        MessageDigest md = null;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 2
diff changeset
    84
        try {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 2
diff changeset
    85
            md = MessageDigest.getInstance("SHA1");
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 2
diff changeset
    86
        } catch (NoSuchAlgorithmException nsae) {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 2
diff changeset
    87
            throw new IOException("Unable to create CertId", nsae);
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 2
diff changeset
    88
        }
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 2
diff changeset
    89
        hashAlgId = SHA1_ALGID;
16492
4cd9aa345503 8010112: NullPointerException in sun.security.provider.certpath.CertId()
mullan
parents: 5506
diff changeset
    90
        md.update(issuerName.getEncoded());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        issuerNameHash = md.digest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        // compute issuerKeyHash (remove the tag and length)
16492
4cd9aa345503 8010112: NullPointerException in sun.security.provider.certpath.CertId()
mullan
parents: 5506
diff changeset
    94
        byte[] pubKey = issuerKey.getEncoded();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        DerValue val = new DerValue(pubKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        DerValue[] seq = new DerValue[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        seq[0] = val.data.getDerValue(); // AlgorithmID
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        seq[1] = val.data.getDerValue(); // Key
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        byte[] keyBytes = seq[1].getBitString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        md.update(keyBytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        issuerKeyHash = md.digest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        certSerialNumber = serialNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        if (debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            HexDumpEncoder encoder = new HexDumpEncoder();
16492
4cd9aa345503 8010112: NullPointerException in sun.security.provider.certpath.CertId()
mullan
parents: 5506
diff changeset
   106
            System.out.println("Issuer Name is " + issuerName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            System.out.println("issuerNameHash is " +
5457
d2782f1ecc9f 6947487: use HexDumpEncoder.encodeBuffer()
weijun
parents: 3841
diff changeset
   108
                encoder.encodeBuffer(issuerNameHash));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            System.out.println("issuerKeyHash is " +
5457
d2782f1ecc9f 6947487: use HexDumpEncoder.encodeBuffer()
weijun
parents: 3841
diff changeset
   110
                encoder.encodeBuffer(issuerKeyHash));
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 2
diff changeset
   111
            System.out.println("SerialNumber is " + serialNumber.getNumber());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * Creates a CertId from its ASN.1 DER encoding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    public CertId(DerInputStream derIn) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        hashAlgId = AlgorithmId.parse(derIn.getDerValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        issuerNameHash = derIn.getOctetString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        issuerKeyHash = derIn.getOctetString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        certSerialNumber = new SerialNumber(derIn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * Return the hash algorithm identifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    public AlgorithmId getHashAlgorithm() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        return hashAlgId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * Return the hash value for the issuer name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    public byte[] getIssuerNameHash() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        return issuerNameHash;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * Return the hash value for the issuer key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    public byte[] getIssuerKeyHash() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        return issuerKeyHash;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * Return the serial number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    public BigInteger getSerialNumber() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        return certSerialNumber.getNumber();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * Encode the CertId using ASN.1 DER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * The hash algorithm used is SHA-1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    public void encode(DerOutputStream out) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        DerOutputStream tmp = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        hashAlgId.encode(tmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        tmp.putOctetString(issuerNameHash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        tmp.putOctetString(issuerKeyHash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        certSerialNumber.encode(tmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        out.write(DerValue.tag_Sequence, tmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        if (debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            HexDumpEncoder encoder = new HexDumpEncoder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            System.out.println("Encoded certId is " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                encoder.encode(out.toByteArray()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * Returns a hashcode value for this CertId.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * @return the hashcode value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     */
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 2
diff changeset
   178
    @Override public int hashCode() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        if (myhash == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            myhash = hashAlgId.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            for (int i = 0; i < issuerNameHash.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                myhash += issuerNameHash[i] * i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            for (int i = 0; i < issuerKeyHash.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                myhash += issuerKeyHash[i] * i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            myhash += certSerialNumber.getNumber().hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        return myhash;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * Compares this CertId for equality with the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * object. Two CertId objects are considered equal if their hash algorithms,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * their issuer name and issuer key hash values and their serial numbers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * are equal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * @param other the object to test for equality with this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * @return true if the objects are considered equal, false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     */
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 2
diff changeset
   201
    @Override public boolean equals(Object other) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        if (this == other) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        if (other == null || (!(other instanceof CertId))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        CertId that = (CertId) other;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        if (hashAlgId.equals(that.getHashAlgorithm()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            Arrays.equals(issuerNameHash, that.getIssuerNameHash()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            Arrays.equals(issuerKeyHash, that.getIssuerKeyHash()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            certSerialNumber.getNumber().equals(that.getSerialNumber())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * Create a string representation of the CertId.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     */
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 2
diff changeset
   223
    @Override public String toString() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        StringBuilder sb = new StringBuilder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        sb.append("CertId \n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        sb.append("Algorithm: " + hashAlgId.toString() +"\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        sb.append("issuerNameHash \n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        HexDumpEncoder encoder = new HexDumpEncoder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        sb.append(encoder.encode(issuerNameHash));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        sb.append("\nissuerKeyHash: \n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        sb.append(encoder.encode(issuerKeyHash));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        sb.append("\n" +  certSerialNumber.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        return sb.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
}