jdk/src/java.base/share/classes/sun/security/x509/X509CRLImpl.java
author juh
Tue, 07 Oct 2014 22:23:19 -0700
changeset 26967 c182469301ee
parent 25859 3317bb8137f4
child 30374 2abaf49910ea
permissions -rw-r--r--
8037550: Update RFC references in javadoc to RFC 5280 Reviewed-by: mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
26967
c182469301ee 8037550: Update RFC references in javadoc to RFC 5280
juh
parents: 25859
diff changeset
     2
 * Copyright (c) 1997, 2014, 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: 5462
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: 5462
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: 5462
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5462
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5462
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.x509;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.InputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.OutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.math.BigInteger;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.security.Principal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.security.PublicKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.security.PrivateKey;
13406
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 13040
diff changeset
    35
import java.security.Provider;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.security.Signature;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.security.NoSuchAlgorithmException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.security.InvalidKeyException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.security.NoSuchProviderException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.security.SignatureException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.security.cert.Certificate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.security.cert.X509CRL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.security.cert.X509Certificate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.security.cert.X509CRLEntry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.security.cert.CRLException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import javax.security.auth.x500.X500Principal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import sun.security.provider.X509Factory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import sun.security.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import sun.misc.HexDumpEncoder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * <p>
13038
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 7040
diff changeset
    56
 * An implementation for X509 CRL (Certificate Revocation List).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * The X.509 v2 CRL format is described below in ASN.1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * CertificateList  ::=  SEQUENCE  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *     tbsCertList          TBSCertList,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *     signatureAlgorithm   AlgorithmIdentifier,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *     signature            BIT STRING  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * More information can be found in
26967
c182469301ee 8037550: Update RFC references in javadoc to RFC 5280
juh
parents: 25859
diff changeset
    66
 * <a href="http://tools.ietf.org/html/rfc5280">RFC 5280: Internet X.509
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * Public Key Infrastructure Certificate and CRL Profile</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * The ASN.1 definition of <code>tbsCertList</code> is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * TBSCertList  ::=  SEQUENCE  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 *     version                 Version OPTIONAL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 *                             -- if present, must be v2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 *     signature               AlgorithmIdentifier,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 *     issuer                  Name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 *     thisUpdate              ChoiceOfTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 *     nextUpdate              ChoiceOfTime OPTIONAL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 *     revokedCertificates     SEQUENCE OF SEQUENCE  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 *         userCertificate         CertificateSerialNumber,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 *         revocationDate          ChoiceOfTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 *         crlEntryExtensions      Extensions OPTIONAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 *                                 -- if present, must be v2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 *         }  OPTIONAL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 *     crlExtensions           [0]  EXPLICIT Extensions OPTIONAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 *                                  -- if present, must be v2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 *     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * @author Hemma Prafullchandra
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * @see X509CRL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 */
5462
cb614e59f7f9 6890876: jarsigner can add CRL info into signed jar
weijun
parents: 2
diff changeset
    92
public class X509CRLImpl extends X509CRL implements DerEncoder {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    // CRL data, and its envelope
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    private byte[]      signedCRL = null; // DER encoded crl
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    private byte[]      signature = null; // raw signature bits
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    private byte[]      tbsCertList = null; // DER encoded "to-be-signed" CRL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    private AlgorithmId sigAlgId = null; // sig alg in CRL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    // crl information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    private int              version;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    private AlgorithmId      infoSigAlgId; // sig alg in "to-be-signed" crl
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    private X500Name         issuer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    private X500Principal    issuerPrincipal = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    private Date             thisUpdate = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    private Date             nextUpdate = null;
13038
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 7040
diff changeset
   107
    private Map<X509IssuerSerial,X509CRLEntry> revokedMap = new TreeMap<>();
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 7040
diff changeset
   108
    private List<X509CRLEntry> revokedList = new LinkedList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    private CRLExtensions    extensions = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    private final static boolean isExplicit = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    private static final long YR_2050 = 2524636800000L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    private boolean readOnly = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * PublicKey that has previously been used to successfully verify
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * the signature of this CRL. Null if the CRL has not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * yet been verified (successfully).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    private PublicKey verifiedPublicKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * If verifiedPublicKey is not null, name of the provider used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * successfully verify the signature of this CRL, or the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * empty String if no provider was explicitly specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    private String verifiedProvider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * Not to be used. As it would lead to cases of uninitialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * CRL objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    private X509CRLImpl() { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * Unmarshals an X.509 CRL from its encoded form, parsing the encoded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * bytes.  This form of constructor is used by agents which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * need to examine and use CRL contents. Note that the buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * must include only one CRL, and no "garbage" may be left at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * the end.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * @param crlData the encoded bytes, with no trailing padding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * @exception CRLException on parsing errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    public X509CRLImpl(byte[] crlData) throws CRLException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            parse(new DerValue(crlData));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            signedCRL = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            throw new CRLException("Parsing error: " + e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        }
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
     * Unmarshals an X.509 CRL from an DER value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * @param val a DER value holding at least one CRL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * @exception CRLException on parsing errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    public X509CRLImpl(DerValue val) throws CRLException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            parse(val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            signedCRL = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            throw new CRLException("Parsing error: " + e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * Unmarshals an X.509 CRL from an input stream. Only one CRL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * is expected at the end of the input stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * @param inStrm an input stream holding at least one CRL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * @exception CRLException on parsing errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    public X509CRLImpl(InputStream inStrm) throws CRLException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            parse(new DerValue(inStrm));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            signedCRL = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            throw new CRLException("Parsing error: " + e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * Initial CRL constructor, no revoked certs, and no extensions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * @param issuer the name of the CA issuing this CRL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * @param thisUpdate the Date of this issue.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * @param nextUpdate the Date of the next CRL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    public X509CRLImpl(X500Name issuer, Date thisDate, Date nextDate) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        this.issuer = issuer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        this.thisUpdate = thisDate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        this.nextUpdate = nextDate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * CRL constructor, revoked certs, no extensions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * @param issuer the name of the CA issuing this CRL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * @param thisUpdate the Date of this issue.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * @param nextUpdate the Date of the next CRL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * @param badCerts the array of CRL entries.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * @exception CRLException on parsing/construction errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    public X509CRLImpl(X500Name issuer, Date thisDate, Date nextDate,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                       X509CRLEntry[] badCerts)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        throws CRLException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        this.issuer = issuer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        this.thisUpdate = thisDate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        this.nextUpdate = nextDate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        if (badCerts != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            X500Principal crlIssuer = getIssuerX500Principal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            X500Principal badCertIssuer = crlIssuer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            for (int i = 0; i < badCerts.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                X509CRLEntryImpl badCert = (X509CRLEntryImpl)badCerts[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                    badCertIssuer = getCertIssuer(badCert, badCertIssuer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                } catch (IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                    throw new CRLException(ioe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                badCert.setCertificateIssuer(crlIssuer, badCertIssuer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                X509IssuerSerial issuerSerial = new X509IssuerSerial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                    (badCertIssuer, badCert.getSerialNumber());
13038
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 7040
diff changeset
   227
                this.revokedMap.put(issuerSerial, badCert);
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 7040
diff changeset
   228
                this.revokedList.add(badCert);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                if (badCert.hasExtensions()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                    this.version = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * CRL constructor, revoked certs and extensions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * @param issuer the name of the CA issuing this CRL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * @param thisUpdate the Date of this issue.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * @param nextUpdate the Date of the next CRL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * @param badCerts the array of CRL entries.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * @param crlExts the CRL extensions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * @exception CRLException on parsing/construction errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    public X509CRLImpl(X500Name issuer, Date thisDate, Date nextDate,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
               X509CRLEntry[] badCerts, CRLExtensions crlExts)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        throws CRLException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        this(issuer, thisDate, nextDate, badCerts);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        if (crlExts != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            this.extensions = crlExts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            this.version = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * Returned the encoding as an uncloned byte array. Callers must
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * guarantee that they neither modify it nor expose it to untrusted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    public byte[] getEncodedInternal() throws CRLException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        if (signedCRL == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            throw new CRLException("Null CRL to encode");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        return signedCRL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * Returns the ASN.1 DER encoded form of this CRL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * @exception CRLException if an encoding error occurs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    public byte[] getEncoded() throws CRLException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        return getEncodedInternal().clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * Encodes the "to-be-signed" CRL to the OutputStream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * @param out the OutputStream to write to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * @exception CRLException on encoding errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    public void encodeInfo(OutputStream out) throws CRLException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            DerOutputStream tmp = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            DerOutputStream rCerts = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            DerOutputStream seq = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            if (version != 0) // v2 crl encode version
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                tmp.putInteger(version);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            infoSigAlgId.encode(tmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            if ((version == 0) && (issuer.toString() == null))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                throw new CRLException("Null Issuer DN not allowed in v1 CRL");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            issuer.encode(tmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            if (thisUpdate.getTime() < YR_2050)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                tmp.putUTCTime(thisUpdate);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                tmp.putGeneralizedTime(thisUpdate);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            if (nextUpdate != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                if (nextUpdate.getTime() < YR_2050)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                    tmp.putUTCTime(nextUpdate);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                    tmp.putGeneralizedTime(nextUpdate);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
13038
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 7040
diff changeset
   310
            if (!revokedList.isEmpty()) {
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 7040
diff changeset
   311
                for (X509CRLEntry entry : revokedList) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                    ((X509CRLEntryImpl)entry).encode(rCerts);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                tmp.write(DerValue.tag_Sequence, rCerts);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            if (extensions != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                extensions.encode(tmp, isExplicit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            seq.write(DerValue.tag_Sequence, tmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            tbsCertList = seq.toByteArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            out.write(tbsCertList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
             throw new CRLException("Encoding error: " + e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * Verifies that this CRL was signed using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * private key that corresponds to the given public key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * @param key the PublicKey used to carry out the verification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * @exception NoSuchAlgorithmException on unsupported signature
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * algorithms.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * @exception InvalidKeyException on incorrect key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * @exception NoSuchProviderException if there's no default provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * @exception SignatureException on signature errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * @exception CRLException on encoding errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    public void verify(PublicKey key)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    throws CRLException, NoSuchAlgorithmException, InvalidKeyException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
           NoSuchProviderException, SignatureException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        verify(key, "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * Verifies that this CRL was signed using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * private key that corresponds to the given public key,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * and that the signature verification was computed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * the given provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * @param key the PublicKey used to carry out the verification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * @param sigProvider the name of the signature provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * @exception NoSuchAlgorithmException on unsupported signature
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * algorithms.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * @exception InvalidKeyException on incorrect key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * @exception NoSuchProviderException on incorrect provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * @exception SignatureException on signature errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * @exception CRLException on encoding errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    public synchronized void verify(PublicKey key, String sigProvider)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            throws CRLException, NoSuchAlgorithmException, InvalidKeyException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            NoSuchProviderException, SignatureException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        if (sigProvider == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            sigProvider = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        if ((verifiedPublicKey != null) && verifiedPublicKey.equals(key)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
            // this CRL has already been successfully verified using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            // this public key. Make sure providers match, too.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            if (sigProvider.equals(verifiedProvider)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        if (signedCRL == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            throw new CRLException("Uninitialized CRL");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        Signature   sigVerf = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        if (sigProvider.length() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            sigVerf = Signature.getInstance(sigAlgId.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            sigVerf = Signature.getInstance(sigAlgId.getName(), sigProvider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        sigVerf.initVerify(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        if (tbsCertList == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            throw new CRLException("Uninitialized CRL");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        sigVerf.update(tbsCertList, 0, tbsCertList.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        if (!sigVerf.verify(signature)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
            throw new SignatureException("Signature does not match.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        verifiedPublicKey = key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        verifiedProvider = sigProvider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    /**
13406
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 13040
diff changeset
   403
     * Verifies that this CRL was signed using the
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 13040
diff changeset
   404
     * private key that corresponds to the given public key,
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 13040
diff changeset
   405
     * and that the signature verification was computed by
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 13040
diff changeset
   406
     * the given provider. Note that the specified Provider object
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 13040
diff changeset
   407
     * does not have to be registered in the provider list.
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 13040
diff changeset
   408
     *
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 13040
diff changeset
   409
     * @param key the PublicKey used to carry out the verification.
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 13040
diff changeset
   410
     * @param sigProvider the signature provider.
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 13040
diff changeset
   411
     *
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 13040
diff changeset
   412
     * @exception NoSuchAlgorithmException on unsupported signature
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 13040
diff changeset
   413
     * algorithms.
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 13040
diff changeset
   414
     * @exception InvalidKeyException on incorrect key.
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 13040
diff changeset
   415
     * @exception SignatureException on signature errors.
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 13040
diff changeset
   416
     * @exception CRLException on encoding errors.
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 13040
diff changeset
   417
     */
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 13040
diff changeset
   418
    public synchronized void verify(PublicKey key, Provider sigProvider)
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 13040
diff changeset
   419
            throws CRLException, NoSuchAlgorithmException, InvalidKeyException,
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 13040
diff changeset
   420
            SignatureException {
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 13040
diff changeset
   421
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 13040
diff changeset
   422
        if (signedCRL == null) {
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 13040
diff changeset
   423
            throw new CRLException("Uninitialized CRL");
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 13040
diff changeset
   424
        }
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 13040
diff changeset
   425
        Signature sigVerf = null;
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 13040
diff changeset
   426
        if (sigProvider == null) {
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 13040
diff changeset
   427
            sigVerf = Signature.getInstance(sigAlgId.getName());
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 13040
diff changeset
   428
        } else {
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 13040
diff changeset
   429
            sigVerf = Signature.getInstance(sigAlgId.getName(), sigProvider);
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 13040
diff changeset
   430
        }
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 13040
diff changeset
   431
        sigVerf.initVerify(key);
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 13040
diff changeset
   432
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 13040
diff changeset
   433
        if (tbsCertList == null) {
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 13040
diff changeset
   434
            throw new CRLException("Uninitialized CRL");
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 13040
diff changeset
   435
        }
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 13040
diff changeset
   436
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 13040
diff changeset
   437
        sigVerf.update(tbsCertList, 0, tbsCertList.length);
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 13040
diff changeset
   438
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 13040
diff changeset
   439
        if (!sigVerf.verify(signature)) {
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 13040
diff changeset
   440
            throw new SignatureException("Signature does not match.");
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 13040
diff changeset
   441
        }
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 13040
diff changeset
   442
        verifiedPublicKey = key;
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 13040
diff changeset
   443
    }
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 13040
diff changeset
   444
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 13040
diff changeset
   445
    /**
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 13040
diff changeset
   446
     * This static method is the default implementation of the
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 13040
diff changeset
   447
     * verify(PublicKey key, Provider sigProvider) method in X509CRL.
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 13040
diff changeset
   448
     * Called from java.security.cert.X509CRL.verify(PublicKey key,
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 13040
diff changeset
   449
     * Provider sigProvider)
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 13040
diff changeset
   450
     */
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 13040
diff changeset
   451
    public static void verify(X509CRL crl, PublicKey key,
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 13040
diff changeset
   452
            Provider sigProvider) throws CRLException,
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 13040
diff changeset
   453
            NoSuchAlgorithmException, InvalidKeyException, SignatureException {
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 13040
diff changeset
   454
        crl.verify(key, sigProvider);
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 13040
diff changeset
   455
    }
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 13040
diff changeset
   456
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 13040
diff changeset
   457
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * Encodes an X.509 CRL, and signs it using the given key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * @param key the private key used for signing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * @param algorithm the name of the signature algorithm used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     * @exception NoSuchAlgorithmException on unsupported signature
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     * algorithms.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * @exception InvalidKeyException on incorrect key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * @exception NoSuchProviderException on incorrect provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     * @exception SignatureException on signature errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     * @exception CRLException if any mandatory data was omitted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    public void sign(PrivateKey key, String algorithm)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    throws CRLException, NoSuchAlgorithmException, InvalidKeyException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        NoSuchProviderException, SignatureException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        sign(key, algorithm, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     * Encodes an X.509 CRL, and signs it using the given key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     * @param key the private key used for signing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     * @param algorithm the name of the signature algorithm used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * @param provider the name of the provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * @exception NoSuchAlgorithmException on unsupported signature
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * algorithms.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * @exception InvalidKeyException on incorrect key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * @exception NoSuchProviderException on incorrect provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * @exception SignatureException on signature errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * @exception CRLException if any mandatory data was omitted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    public void sign(PrivateKey key, String algorithm, String provider)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    throws CRLException, NoSuchAlgorithmException, InvalidKeyException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        NoSuchProviderException, SignatureException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            if (readOnly)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                throw new CRLException("cannot over-write existing CRL");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
            Signature sigEngine = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
            if ((provider == null) || (provider.length() == 0))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                sigEngine = Signature.getInstance(algorithm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                sigEngine = Signature.getInstance(algorithm, provider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
            sigEngine.initSign(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
                                // in case the name is reset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
            sigAlgId = AlgorithmId.get(sigEngine.getAlgorithm());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
            infoSigAlgId = sigAlgId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
            DerOutputStream out = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
            DerOutputStream tmp = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
            // encode crl info
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            encodeInfo(tmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
            // encode algorithm identifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
            sigAlgId.encode(tmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            // Create and encode the signature itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            sigEngine.update(tbsCertList, 0, tbsCertList.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            signature = sigEngine.sign();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            tmp.putBitString(signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            // Wrap the signed data in a SEQUENCE { data, algorithm, sig }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
            out.write(DerValue.tag_Sequence, tmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
            signedCRL = out.toByteArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
            readOnly = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            throw new CRLException("Error while encoding data: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                                   e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * Returns a printable string of this CRL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * @return value of this CRL in a printable form.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    public String toString() {
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 14342
diff changeset
   539
        StringBuilder sb = new StringBuilder();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        sb.append("X.509 CRL v" + (version+1) + "\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        if (sigAlgId != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
            sb.append("Signature Algorithm: " + sigAlgId.toString() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                  ", OID=" + (sigAlgId.getOID()).toString() + "\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        if (issuer != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
            sb.append("Issuer: " + issuer.toString() + "\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        if (thisUpdate != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
            sb.append("\nThis Update: " + thisUpdate.toString() + "\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        if (nextUpdate != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
            sb.append("Next Update: " + nextUpdate.toString() + "\n");
13038
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 7040
diff changeset
   550
        if (revokedList.isEmpty())
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
            sb.append("\nNO certificates have been revoked\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        else {
13038
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 7040
diff changeset
   553
            sb.append("\nRevoked Certificates: " + revokedList.size());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            int i = 1;
13038
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 7040
diff changeset
   555
            for (X509CRLEntry entry: revokedList) {
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 7040
diff changeset
   556
                sb.append("\n[" + i++ + "] " + entry.toString());
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 7040
diff changeset
   557
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        if (extensions != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
            Collection<Extension> allExts = extensions.getAllExtensions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            Object[] objs = allExts.toArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
            sb.append("\nCRL Extensions: " + objs.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
            for (int i = 0; i < objs.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                sb.append("\n[" + (i+1) + "]: ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                Extension ext = (Extension)objs[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                   if (OIDMap.getClass(ext.getExtensionId()) == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                       sb.append(ext.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                       byte[] extValue = ext.getExtensionValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                       if (extValue != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
                           DerOutputStream out = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                           out.putOctetString(extValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
                           extValue = out.toByteArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                           HexDumpEncoder enc = new HexDumpEncoder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                           sb.append("Extension unknown: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                                     + "DER encoded OCTET string =\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                                     + enc.encodeBuffer(extValue) + "\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
                   } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
                       sb.append(ext.toString()); // sub-class exists
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
                } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                    sb.append(", Error parsing this extension");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        if (signature != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
            HexDumpEncoder encoder = new HexDumpEncoder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
            sb.append("\nSignature:\n" + encoder.encodeBuffer(signature)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                      + "\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
            sb.append("NOT signed yet\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        return sb.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     * Checks whether the given certificate is on this CRL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     * @param cert the certificate to check for.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     * @return true if the given certificate is on this CRL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     * false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
    public boolean isRevoked(Certificate cert) {
13038
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 7040
diff changeset
   603
        if (revokedMap.isEmpty() || (!(cert instanceof X509Certificate))) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        X509Certificate xcert = (X509Certificate) cert;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
        X509IssuerSerial issuerSerial = new X509IssuerSerial(xcert);
13038
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 7040
diff changeset
   608
        return revokedMap.containsKey(issuerSerial);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     * Gets the version number from this CRL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     * The ASN.1 definition for this is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     * Version  ::=  INTEGER  {  v1(0), v2(1), v3(2)  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     *             -- v3 does not apply to CRLs but appears for consistency
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     *             -- with definition of Version for certs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     * @return the version number, i.e. 1 or 2.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
    public int getVersion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        return version+1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     * Gets the issuer distinguished name from this CRL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     * The issuer name identifies the entity who has signed (and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     * issued the CRL). The issuer name field contains an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     * X.500 distinguished name (DN).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     * The ASN.1 definition for this is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     * issuer    Name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     * Name ::= CHOICE { RDNSequence }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     * RDNSequence ::= SEQUENCE OF RelativeDistinguishedName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     * RelativeDistinguishedName ::=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     *     SET OF AttributeValueAssertion
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     * AttributeValueAssertion ::= SEQUENCE {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     *                               AttributeType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     *                               AttributeValue }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     * AttributeType ::= OBJECT IDENTIFIER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     * AttributeValue ::= ANY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     * The Name describes a hierarchical name composed of attributes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     * such as country name, and corresponding values, such as US.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     * The type of the component AttributeValue is determined by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     * AttributeType; in general it will be a directoryString.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     * A directoryString is usually one of PrintableString,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     * TeletexString or UniversalString.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     * @return the issuer name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
    public Principal getIssuerDN() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        return (Principal)issuer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     * Return the issuer as X500Principal. Overrides method in X509CRL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     * to provide a slightly more efficient version.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
    public X500Principal getIssuerX500Principal() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        if (issuerPrincipal == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
            issuerPrincipal = issuer.asX500Principal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        return issuerPrincipal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     * Gets the thisUpdate date from the CRL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     * The ASN.1 definition for this is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     * @return the thisUpdate date from the CRL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
    public Date getThisUpdate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        return (new Date(thisUpdate.getTime()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     * Gets the nextUpdate date from the CRL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     * @return the nextUpdate date from the CRL, or null if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     * not present.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
    public Date getNextUpdate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        if (nextUpdate == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        return (new Date(nextUpdate.getTime()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
     * Gets the CRL entry with the given serial number from this CRL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
     * @return the entry with the given serial number, or <code>null</code> if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
     * no such entry exists in the CRL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
     * @see X509CRLEntry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
    public X509CRLEntry getRevokedCertificate(BigInteger serialNumber) {
13038
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 7040
diff changeset
   698
        if (revokedMap.isEmpty()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        // assume this is a direct CRL entry (cert and CRL issuer are the same)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        X509IssuerSerial issuerSerial = new X509IssuerSerial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
            (getIssuerX500Principal(), serialNumber);
13038
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 7040
diff changeset
   704
        return revokedMap.get(issuerSerial);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
     * Gets the CRL entry for the given certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
    public X509CRLEntry getRevokedCertificate(X509Certificate cert) {
13038
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 7040
diff changeset
   711
        if (revokedMap.isEmpty()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        X509IssuerSerial issuerSerial = new X509IssuerSerial(cert);
13038
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 7040
diff changeset
   715
        return revokedMap.get(issuerSerial);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
     * Gets all the revoked certificates from the CRL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
     * A Set of X509CRLEntry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
     * @return all the revoked certificates or <code>null</code> if there are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
     * none.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
     * @see X509CRLEntry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
    public Set<X509CRLEntry> getRevokedCertificates() {
13038
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 7040
diff changeset
   727
        if (revokedList.isEmpty()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
        } else {
13038
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 7040
diff changeset
   730
            return new TreeSet<X509CRLEntry>(revokedList);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
     * Gets the DER encoded CRL information, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
     * <code>tbsCertList</code> from this CRL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
     * This can be used to verify the signature independently.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
     * @return the DER encoded CRL information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     * @exception CRLException on encoding errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
    public byte[] getTBSCertList() throws CRLException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
        if (tbsCertList == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
            throw new CRLException("Uninitialized CRL");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
        byte[] dup = new byte[tbsCertList.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
        System.arraycopy(tbsCertList, 0, dup, 0, dup.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
        return dup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
     * Gets the raw Signature bits from the CRL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
     * @return the signature.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
    public byte[] getSignature() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
        if (signature == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
        byte[] dup = new byte[signature.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
        System.arraycopy(signature, 0, dup, 0, dup.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
        return dup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
     * Gets the signature algorithm name for the CRL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
     * signature algorithm. For example, the string "SHA1withDSA".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
     * The ASN.1 definition for this is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
     * AlgorithmIdentifier  ::=  SEQUENCE  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
     *     algorithm               OBJECT IDENTIFIER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
     *     parameters              ANY DEFINED BY algorithm OPTIONAL  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
     *                             -- contains a value of the type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
     *                             -- registered for use with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
     *                             -- algorithm object identifier value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
     * @return the signature algorithm name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
    public String getSigAlgName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
        if (sigAlgId == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
        return sigAlgId.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
     * Gets the signature algorithm OID string from the CRL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
     * An OID is represented by a set of positive whole number separated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
     * by ".", that means,<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
     * &lt;positive whole number&gt;.&lt;positive whole number&gt;.&lt;...&gt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
     * For example, the string "1.2.840.10040.4.3" identifies the SHA-1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
     * with DSA signature algorithm defined in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
     * <a href="http://www.ietf.org/rfc/rfc3279.txt">RFC 3279: Algorithms and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
     * Identifiers for the Internet X.509 Public Key Infrastructure Certificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
     * and CRL Profile</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
     * @return the signature algorithm oid string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
    public String getSigAlgOID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
        if (sigAlgId == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
        ObjectIdentifier oid = sigAlgId.getOID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
        return oid.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
     * Gets the DER encoded signature algorithm parameters from this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
     * CRL's signature algorithm. In most cases, the signature
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
     * algorithm parameters are null, the parameters are usually
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
     * supplied with the Public Key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
     * @return the DER encoded signature algorithm parameters, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
     *         null if no parameters are present.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
    public byte[] getSigAlgParams() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
        if (sigAlgId == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
            return sigAlgId.getEncodedParams();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
    /**
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   824
     * Gets the signature AlgorithmId from the CRL.
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   825
     *
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   826
     * @return the signature AlgorithmId
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   827
     */
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   828
    public AlgorithmId getSigAlgId() {
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   829
        return sigAlgId;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   830
    }
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   831
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   832
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
     * return the AuthorityKeyIdentifier, if any.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
     * @returns AuthorityKeyIdentifier or null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
     *          (if no AuthorityKeyIdentifierExtension)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
     * @throws IOException on error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
    public KeyIdentifier getAuthKeyId() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
        AuthorityKeyIdentifierExtension aki = getAuthKeyIdExtension();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
        if (aki != null) {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 7040
diff changeset
   842
            KeyIdentifier keyId = (KeyIdentifier)aki.get(
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 7040
diff changeset
   843
                    AuthorityKeyIdentifierExtension.KEY_ID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
            return keyId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
     * return the AuthorityKeyIdentifierExtension, if any.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
     * @returns AuthorityKeyIdentifierExtension or null (if no such extension)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
     * @throws IOException on error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
    public AuthorityKeyIdentifierExtension getAuthKeyIdExtension()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
        throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
        Object obj = getExtension(PKIXExtensions.AuthorityKey_Id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
        return (AuthorityKeyIdentifierExtension)obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
     * return the CRLNumberExtension, if any.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
     * @returns CRLNumberExtension or null (if no such extension)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
     * @throws IOException on error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
    public CRLNumberExtension getCRLNumberExtension() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
        Object obj = getExtension(PKIXExtensions.CRLNumber_Id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
        return (CRLNumberExtension)obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
     * return the CRL number from the CRLNumberExtension, if any.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
     * @returns number or null (if no such extension)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
     * @throws IOException on error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
    public BigInteger getCRLNumber() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
        CRLNumberExtension numExt = getCRLNumberExtension();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
        if (numExt != null) {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 7040
diff changeset
   882
            BigInteger num = numExt.get(CRLNumberExtension.NUMBER);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
            return num;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
     * return the DeltaCRLIndicatorExtension, if any.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
     * @returns DeltaCRLIndicatorExtension or null (if no such extension)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
     * @throws IOException on error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
    public DeltaCRLIndicatorExtension getDeltaCRLIndicatorExtension()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
        throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
        Object obj = getExtension(PKIXExtensions.DeltaCRLIndicator_Id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
        return (DeltaCRLIndicatorExtension)obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
     * return the base CRL number from the DeltaCRLIndicatorExtension, if any.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
     * @returns number or null (if no such extension)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
     * @throws IOException on error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
    public BigInteger getBaseCRLNumber() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
        DeltaCRLIndicatorExtension dciExt = getDeltaCRLIndicatorExtension();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
        if (dciExt != null) {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 7040
diff changeset
   911
            BigInteger num = dciExt.get(DeltaCRLIndicatorExtension.NUMBER);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
            return num;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
     * return the IssuerAlternativeNameExtension, if any.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
     * @returns IssuerAlternativeNameExtension or null (if no such extension)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
     * @throws IOException on error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
    public IssuerAlternativeNameExtension getIssuerAltNameExtension()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
        throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
        Object obj = getExtension(PKIXExtensions.IssuerAlternativeName_Id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
        return (IssuerAlternativeNameExtension)obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
     * return the IssuingDistributionPointExtension, if any.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
     * @returns IssuingDistributionPointExtension or null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
     *          (if no such extension)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
     * @throws IOException on error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
    public IssuingDistributionPointExtension
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
        getIssuingDistributionPointExtension() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
        Object obj = getExtension(PKIXExtensions.IssuingDistributionPoint_Id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
        return (IssuingDistributionPointExtension) obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
     * Return true if a critical extension is found that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
     * not supported, otherwise return false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
    public boolean hasUnsupportedCriticalExtension() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
        if (extensions == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
        return extensions.hasUnsupportedCriticalExtension();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
     * Gets a Set of the extension(s) marked CRITICAL in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
     * CRL. In the returned set, each extension is represented by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
     * its OID string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
     * @return a set of the extension oid strings in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
     * CRL that are marked critical.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
    public Set<String> getCriticalExtensionOIDs() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
        if (extensions == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
        }
13038
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 7040
diff changeset
   966
        Set<String> extSet = new TreeSet<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
        for (Extension ex : extensions.getAllExtensions()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
            if (ex.isCritical()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
                extSet.add(ex.getExtensionId().toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
        return extSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
     * Gets a Set of the extension(s) marked NON-CRITICAL in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
     * CRL. In the returned set, each extension is represented by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
     * its OID string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
     * @return a set of the extension oid strings in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
     * CRL that are NOT marked critical.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
    public Set<String> getNonCriticalExtensionOIDs() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
        if (extensions == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
        }
13038
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 7040
diff changeset
   987
        Set<String> extSet = new TreeSet<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
        for (Extension ex : extensions.getAllExtensions()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
            if (!ex.isCritical()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
                extSet.add(ex.getExtensionId().toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
        return extSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
     * Gets the DER encoded OCTET string for the extension value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
     * (<code>extnValue</code>) identified by the passed in oid String.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
     * The <code>oid</code> string is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
     * represented by a set of positive whole number separated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
     * by ".", that means,<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
     * &lt;positive whole number&gt;.&lt;positive whole number&gt;.&lt;...&gt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
     * @param oid the Object Identifier value for the extension.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
     * @return the der encoded octet string of the extension value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
    public byte[] getExtensionValue(String oid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
        if (extensions == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
            String extAlias = OIDMap.getName(new ObjectIdentifier(oid));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
            Extension crlExt = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
            if (extAlias == null) { // may be unknown
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
                ObjectIdentifier findOID = new ObjectIdentifier(oid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
                Extension ex = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
                ObjectIdentifier inCertOID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
                for (Enumeration<Extension> e = extensions.getElements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
                                                 e.hasMoreElements();) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
                    ex = e.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
                    inCertOID = ex.getExtensionId();
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 7040
diff changeset
  1022
                    if (inCertOID.equals((Object)findOID)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
                        crlExt = ex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
            } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
                crlExt = extensions.get(extAlias);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
            if (crlExt == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
            byte[] extData = crlExt.getExtensionValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
            if (extData == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
            DerOutputStream out = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
            out.putOctetString(extData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
            return out.toByteArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
     * get an extension
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
     * @param oid ObjectIdentifier of extension desired
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
     * @returns Object of type <extension> or null, if not found
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
     * @throws IOException on error
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
    public Object getExtension(ObjectIdentifier oid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
        if (extensions == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
        // XXX Consider cloning this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
        return extensions.get(OIDMap.getName(oid));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
     * Parses an X.509 CRL, should be used only by constructors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
    private void parse(DerValue val) throws CRLException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
        // check if can over write the certificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
        if (readOnly)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
            throw new CRLException("cannot over-write existing CRL");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
        if ( val.getData() == null || val.tag != DerValue.tag_Sequence)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
            throw new CRLException("Invalid DER-encoded CRL data");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
        signedCRL = val.toByteArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
        DerValue seq[] = new DerValue[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
        seq[0] = val.data.getDerValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
        seq[1] = val.data.getDerValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
        seq[2] = val.data.getDerValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
        if (val.data.available() != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
            throw new CRLException("signed overrun, bytes = "
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
                                     + val.data.available());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
        if (seq[0].tag != DerValue.tag_Sequence)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
            throw new CRLException("signed CRL fields invalid");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
        sigAlgId = AlgorithmId.parse(seq[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
        signature = seq[2].getBitString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
        if (seq[1].data.available() != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
            throw new CRLException("AlgorithmId field overrun");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
        if (seq[2].data.available() != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
            throw new CRLException("Signature field overrun");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
        // the tbsCertsList
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
        tbsCertList = seq[0].toByteArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
        // parse the information
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
        DerInputStream derStrm = seq[0].data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
        DerValue       tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
        byte           nextByte;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
        // version (optional if v1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
        version = 0;   // by default, version = v1 == 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
        nextByte = (byte)derStrm.peekByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
        if (nextByte == DerValue.tag_Integer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
            version = derStrm.getInteger();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
            if (version != 1)  // i.e. v2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
                throw new CRLException("Invalid version");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
        tmp = derStrm.getDerValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
        // signature
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
        AlgorithmId tmpId = AlgorithmId.parse(tmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
        // the "inner" and "outer" signature algorithms must match
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
        if (! tmpId.equals(sigAlgId))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
            throw new CRLException("Signature algorithm mismatch");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
        infoSigAlgId = tmpId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
        // issuer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
        issuer = new X500Name(derStrm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
        if (issuer.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
            throw new CRLException("Empty issuer DN not allowed in X509CRLs");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
        // thisUpdate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
        // check if UTCTime encoded or GeneralizedTime
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
        nextByte = (byte)derStrm.peekByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
        if (nextByte == DerValue.tag_UtcTime) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
            thisUpdate = derStrm.getUTCTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
        } else if (nextByte == DerValue.tag_GeneralizedTime) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
            thisUpdate = derStrm.getGeneralizedTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
            throw new CRLException("Invalid encoding for thisUpdate"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
                                   + " (tag=" + nextByte + ")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
        if (derStrm.available() == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
           return;     // done parsing no more optional fields present
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
        // nextUpdate (optional)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
        nextByte = (byte)derStrm.peekByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
        if (nextByte == DerValue.tag_UtcTime) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
            nextUpdate = derStrm.getUTCTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
        } else if (nextByte == DerValue.tag_GeneralizedTime) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
            nextUpdate = derStrm.getGeneralizedTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
        } // else it is not present
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
        if (derStrm.available() == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
            return;     // done parsing no more optional fields present
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
        // revokedCertificates (optional)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
        nextByte = (byte)derStrm.peekByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
        if ((nextByte == DerValue.tag_SequenceOf)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
            && (! ((nextByte & 0x0c0) == 0x080))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
            DerValue[] badCerts = derStrm.getSequence(4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
            X500Principal crlIssuer = getIssuerX500Principal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
            X500Principal badCertIssuer = crlIssuer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
            for (int i = 0; i < badCerts.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
                X509CRLEntryImpl entry = new X509CRLEntryImpl(badCerts[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
                badCertIssuer = getCertIssuer(entry, badCertIssuer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
                entry.setCertificateIssuer(crlIssuer, badCertIssuer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
                X509IssuerSerial issuerSerial = new X509IssuerSerial
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
                    (badCertIssuer, entry.getSerialNumber());
13038
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 7040
diff changeset
  1164
                revokedMap.put(issuerSerial, entry);
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 7040
diff changeset
  1165
                revokedList.add(entry);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
        if (derStrm.available() == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
            return;     // done parsing no extensions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
        // crlExtensions (optional)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
        tmp = derStrm.getDerValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
        if (tmp.isConstructed() && tmp.isContextSpecific((byte)0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
            extensions = new CRLExtensions(tmp.data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
        readOnly = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
     * Extract the issuer X500Principal from an X509CRL. Parses the encoded
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
     * form of the CRL to preserve the principal's ASN.1 encoding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
     * Called by java.security.cert.X509CRL.getIssuerX500Principal().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
    public static X500Principal getIssuerX500Principal(X509CRL crl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
            byte[] encoded = crl.getEncoded();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
            DerInputStream derIn = new DerInputStream(encoded);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
            DerValue tbsCert = derIn.getSequence(3)[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
            DerInputStream tbsIn = tbsCert.data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
            DerValue tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
            // skip version number if present
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
            byte nextByte = (byte)tbsIn.peekByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
            if (nextByte == DerValue.tag_Integer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
                tmp = tbsIn.getDerValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
            tmp = tbsIn.getDerValue();  // skip signature
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
            tmp = tbsIn.getDerValue();  // issuer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
            byte[] principalBytes = tmp.toByteArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
            return new X500Principal(principalBytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
            throw new RuntimeException("Could not parse issuer", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
     * Returned the encoding of the given certificate for internal use.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
     * Callers must guarantee that they neither modify it nor expose it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
     * to untrusted code. Uses getEncodedInternal() if the certificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
     * is instance of X509CertImpl, getEncoded() otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
    public static byte[] getEncodedInternal(X509CRL crl) throws CRLException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
        if (crl instanceof X509CRLImpl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
            return ((X509CRLImpl)crl).getEncodedInternal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
            return crl.getEncoded();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
     * Utility method to convert an arbitrary instance of X509CRL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
     * to a X509CRLImpl. Does a cast if possible, otherwise reparses
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
     * the encoding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
    public static X509CRLImpl toImpl(X509CRL crl)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
            throws CRLException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
        if (crl instanceof X509CRLImpl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
            return (X509CRLImpl)crl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
            return X509Factory.intern(crl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
     * Returns the X500 certificate issuer DN of a CRL entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
     * @param entry the entry to check
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
     * @param prevCertIssuer the previous entry's certificate issuer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
     * @return the X500Principal in a CertificateIssuerExtension, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
     *   prevCertIssuer if it does not exist
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
    private X500Principal getCertIssuer(X509CRLEntryImpl entry,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
        X500Principal prevCertIssuer) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
        CertificateIssuerExtension ciExt =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
            entry.getCertificateIssuerExtension();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
        if (ciExt != null) {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 7040
diff changeset
  1251
            GeneralNames names = ciExt.get(CertificateIssuerExtension.ISSUER);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
            X500Name issuerDN = (X500Name) names.get(0).getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
            return issuerDN.asX500Principal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
            return prevCertIssuer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
5462
cb614e59f7f9 6890876: jarsigner can add CRL info into signed jar
weijun
parents: 2
diff changeset
  1259
    @Override
cb614e59f7f9 6890876: jarsigner can add CRL info into signed jar
weijun
parents: 2
diff changeset
  1260
    public void derEncode(OutputStream out) throws IOException {
cb614e59f7f9 6890876: jarsigner can add CRL info into signed jar
weijun
parents: 2
diff changeset
  1261
        if (signedCRL == null)
cb614e59f7f9 6890876: jarsigner can add CRL info into signed jar
weijun
parents: 2
diff changeset
  1262
            throw new IOException("Null CRL to encode");
cb614e59f7f9 6890876: jarsigner can add CRL info into signed jar
weijun
parents: 2
diff changeset
  1263
        out.write(signedCRL.clone());
cb614e59f7f9 6890876: jarsigner can add CRL info into signed jar
weijun
parents: 2
diff changeset
  1264
    }
cb614e59f7f9 6890876: jarsigner can add CRL info into signed jar
weijun
parents: 2
diff changeset
  1265
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
     * Immutable X.509 Certificate Issuer DN and serial number pair
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
     */
13038
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 7040
diff changeset
  1269
    private final static class X509IssuerSerial
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 7040
diff changeset
  1270
            implements Comparable<X509IssuerSerial> {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
        final X500Principal issuer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
        final BigInteger serial;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
        volatile int hashcode = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
         * Create an X509IssuerSerial.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
         * @param issuer the issuer DN
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
         * @param serial the serial number
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
        X509IssuerSerial(X500Principal issuer, BigInteger serial) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
            this.issuer = issuer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
            this.serial = serial;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
         * Construct an X509IssuerSerial from an X509Certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
        X509IssuerSerial(X509Certificate cert) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
            this(cert.getIssuerX500Principal(), cert.getSerialNumber());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
         * Returns the issuer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
         * @return the issuer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
        X500Principal getIssuer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
            return issuer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
         * Returns the serial number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
         * @return the serial number
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
        BigInteger getSerial() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
            return serial;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
         * Compares this X509Serial with another and returns true if they
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
         * are equivalent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
         * @param o the other object to compare with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
         * @return true if equal, false otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
        public boolean equals(Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
            if (o == this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
            if (!(o instanceof X509IssuerSerial)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
            X509IssuerSerial other = (X509IssuerSerial) o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
            if (serial.equals(other.getSerial()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
                issuer.equals(other.getIssuer())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
         * Returns a hash code value for this X509IssuerSerial.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
         * @return the hash code value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
        public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
            if (hashcode == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
                int result = 17;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
                result = 37*result + issuer.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
                result = 37*result + serial.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
                hashcode = result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
            return hashcode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
        }
13038
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 7040
diff changeset
  1349
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 7040
diff changeset
  1350
        @Override
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 7040
diff changeset
  1351
        public int compareTo(X509IssuerSerial another) {
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 7040
diff changeset
  1352
            int cissuer = issuer.toString()
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 7040
diff changeset
  1353
                    .compareTo(another.issuer.toString());
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 7040
diff changeset
  1354
            if (cissuer != 0) return cissuer;
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 7040
diff changeset
  1355
            return this.serial.compareTo(another.serial);
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 7040
diff changeset
  1356
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
}