jdk/src/java.base/share/classes/sun/security/x509/X509CRLImpl.java
author martin
Tue, 15 Sep 2015 21:56:04 -0700
changeset 32649 2ee9017c7597
parent 31538 0981099a3e54
child 34687 d302ed125dc9
permissions -rw-r--r--
8136583: Core libraries should use blessed modifier order Summary: Run blessed-modifier-order script (see bug) Reviewed-by: psandoz, chegar, alanb, plevart
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
31426
9cd672654f97 8022444: Remove sun.security.util.ObjectIdentifier.equals(ObjectIdentifier other) method
juh
parents: 30649
diff changeset
     2
 * Copyright (c) 1997, 2015, 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;
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 31538
diff changeset
   110
    private static final boolean isExplicit = true;
2
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.
30374
2abaf49910ea 8079478: some docs cleanup for sun.security
avstepan
parents: 26967
diff changeset
   188
     * @param thisDate the Date of this issue.
2abaf49910ea 8079478: some docs cleanup for sun.security
avstepan
parents: 26967
diff changeset
   189
     * @param nextDate the Date of the next CRL.
2
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.
30374
2abaf49910ea 8079478: some docs cleanup for sun.security
avstepan
parents: 26967
diff changeset
   201
     * @param thisDate the Date of this issue.
2abaf49910ea 8079478: some docs cleanup for sun.security
avstepan
parents: 26967
diff changeset
   202
     * @param nextDate the Date of the next CRL.
2
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.
30374
2abaf49910ea 8079478: some docs cleanup for sun.security
avstepan
parents: 26967
diff changeset
   240
     * @param thisDate the Date of this issue.
2abaf49910ea 8079478: some docs cleanup for sun.security
avstepan
parents: 26967
diff changeset
   241
     * @param nextDate the Date of the next CRL.
2
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();
30649
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   540
        sb.append("X.509 CRL v")
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   541
            .append(version+1)
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   542
            .append('\n');
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        if (sigAlgId != null)
30649
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   544
            sb.append("Signature Algorithm: ")
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   545
                .append(sigAlgId)
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   546
                .append(", OID=")
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   547
                .append(sigAlgId.getOID())
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   548
                .append('\n');
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        if (issuer != null)
30649
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   550
            sb.append("Issuer: ")
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   551
                .append(issuer)
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   552
                .append('\n');
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        if (thisUpdate != null)
30649
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   554
            sb.append("\nThis Update: ")
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   555
                .append(thisUpdate)
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   556
                .append('\n');
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
        if (nextUpdate != null)
30649
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   558
            sb.append("Next Update: ")
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   559
                .append(nextUpdate)
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   560
                .append('\n');
13038
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 7040
diff changeset
   561
        if (revokedList.isEmpty())
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
            sb.append("\nNO certificates have been revoked\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        else {
30649
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   564
            sb.append("\nRevoked Certificates: ")
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   565
                .append(revokedList.size());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
            int i = 1;
13038
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 7040
diff changeset
   567
            for (X509CRLEntry entry: revokedList) {
30649
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   568
                sb.append("\n[")
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   569
                    .append(i++)
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   570
                    .append("] ")
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   571
                    .append(entry);
13038
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 7040
diff changeset
   572
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        if (extensions != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
            Collection<Extension> allExts = extensions.getAllExtensions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
            Object[] objs = allExts.toArray();
30649
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   577
            sb.append("\nCRL Extensions: ")
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   578
                .append(objs.length);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
            for (int i = 0; i < objs.length; i++) {
30649
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   580
                sb.append("\n[").append(i+1).append("]: ");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
                Extension ext = (Extension)objs[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                try {
30649
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   583
                    if (OIDMap.getClass(ext.getExtensionId()) == null) {
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   584
                        sb.append(ext);
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   585
                        byte[] extValue = ext.getExtensionValue();
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   586
                        if (extValue != null) {
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   587
                            DerOutputStream out = new DerOutputStream();
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   588
                            out.putOctetString(extValue);
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   589
                            extValue = out.toByteArray();
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   590
                            HexDumpEncoder enc = new HexDumpEncoder();
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   591
                            sb.append("Extension unknown: ")
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   592
                                .append("DER encoded OCTET string =\n")
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   593
                                .append(enc.encodeBuffer(extValue))
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   594
                                .append('\n');
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   595
                        }
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   596
                    } else {
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   597
                        sb.append(ext); // sub-class exists
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   598
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                    sb.append(", Error parsing this extension");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        if (signature != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
            HexDumpEncoder encoder = new HexDumpEncoder();
30649
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   606
            sb.append("\nSignature:\n")
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   607
                .append(encoder.encodeBuffer(signature))
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   608
                .append('\n');
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   609
        } else {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            sb.append("NOT signed yet\n");
30649
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   611
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        return sb.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     * Checks whether the given certificate is on this CRL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     * @param cert the certificate to check for.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     * @return true if the given certificate is on this CRL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
     * false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
    public boolean isRevoked(Certificate cert) {
13038
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 7040
diff changeset
   623
        if (revokedMap.isEmpty() || (!(cert instanceof X509Certificate))) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        X509Certificate xcert = (X509Certificate) cert;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        X509IssuerSerial issuerSerial = new X509IssuerSerial(xcert);
13038
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 7040
diff changeset
   628
        return revokedMap.containsKey(issuerSerial);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     * Gets the version number from this CRL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     * The ASN.1 definition for this is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     * Version  ::=  INTEGER  {  v1(0), v2(1), v3(2)  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     *             -- v3 does not apply to CRLs but appears for consistency
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     *             -- with definition of Version for certs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     * @return the version number, i.e. 1 or 2.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
    public int getVersion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        return version+1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     * Gets the issuer distinguished name from this CRL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     * The issuer name identifies the entity who has signed (and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     * issued the CRL). The issuer name field contains an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     * X.500 distinguished name (DN).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     * The ASN.1 definition for this is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
     * issuer    Name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     * Name ::= CHOICE { RDNSequence }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     * RDNSequence ::= SEQUENCE OF RelativeDistinguishedName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     * RelativeDistinguishedName ::=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     *     SET OF AttributeValueAssertion
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     * AttributeValueAssertion ::= SEQUENCE {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     *                               AttributeType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     *                               AttributeValue }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     * AttributeType ::= OBJECT IDENTIFIER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
     * AttributeValue ::= ANY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     * The Name describes a hierarchical name composed of attributes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     * such as country name, and corresponding values, such as US.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     * The type of the component AttributeValue is determined by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     * AttributeType; in general it will be a directoryString.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     * A directoryString is usually one of PrintableString,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     * TeletexString or UniversalString.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     * @return the issuer name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
    public Principal getIssuerDN() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        return (Principal)issuer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     * Return the issuer as X500Principal. Overrides method in X509CRL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     * to provide a slightly more efficient version.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
    public X500Principal getIssuerX500Principal() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        if (issuerPrincipal == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
            issuerPrincipal = issuer.asX500Principal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        return issuerPrincipal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
     * Gets the thisUpdate date from the CRL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
     * The ASN.1 definition for this is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
     * @return the thisUpdate date from the CRL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
    public Date getThisUpdate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        return (new Date(thisUpdate.getTime()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     * Gets the nextUpdate date from the CRL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
     * @return the nextUpdate date from the CRL, or null if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
     * not present.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
    public Date getNextUpdate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        if (nextUpdate == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
        return (new Date(nextUpdate.getTime()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     * Gets the CRL entry with the given serial number from this CRL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
     * @return the entry with the given serial number, or <code>null</code> if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
     * no such entry exists in the CRL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
     * @see X509CRLEntry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
    public X509CRLEntry getRevokedCertificate(BigInteger serialNumber) {
13038
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 7040
diff changeset
   718
        if (revokedMap.isEmpty()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
        // assume this is a direct CRL entry (cert and CRL issuer are the same)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
        X509IssuerSerial issuerSerial = new X509IssuerSerial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
            (getIssuerX500Principal(), serialNumber);
13038
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 7040
diff changeset
   724
        return revokedMap.get(issuerSerial);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
     * Gets the CRL entry for the given certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
    public X509CRLEntry getRevokedCertificate(X509Certificate cert) {
13038
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 7040
diff changeset
   731
        if (revokedMap.isEmpty()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
        X509IssuerSerial issuerSerial = new X509IssuerSerial(cert);
13038
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 7040
diff changeset
   735
        return revokedMap.get(issuerSerial);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
     * Gets all the revoked certificates from the CRL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     * A Set of X509CRLEntry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
     * @return all the revoked certificates or <code>null</code> if there are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
     * none.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
     * @see X509CRLEntry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
    public Set<X509CRLEntry> getRevokedCertificates() {
13038
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 7040
diff changeset
   747
        if (revokedList.isEmpty()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
        } else {
13038
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 7040
diff changeset
   750
            return new TreeSet<X509CRLEntry>(revokedList);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
     * Gets the DER encoded CRL information, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
     * <code>tbsCertList</code> from this CRL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
     * This can be used to verify the signature independently.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
     * @return the DER encoded CRL information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
     * @exception CRLException on encoding errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
    public byte[] getTBSCertList() throws CRLException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
        if (tbsCertList == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
            throw new CRLException("Uninitialized CRL");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
        byte[] dup = new byte[tbsCertList.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
        System.arraycopy(tbsCertList, 0, dup, 0, dup.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        return dup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
     * Gets the raw Signature bits from the CRL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
     * @return the signature.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
    public byte[] getSignature() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
        if (signature == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
        byte[] dup = new byte[signature.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
        System.arraycopy(signature, 0, dup, 0, dup.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
        return dup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
     * Gets the signature algorithm name for the CRL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
     * signature algorithm. For example, the string "SHA1withDSA".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
     * The ASN.1 definition for this is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
     * AlgorithmIdentifier  ::=  SEQUENCE  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
     *     algorithm               OBJECT IDENTIFIER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
     *     parameters              ANY DEFINED BY algorithm OPTIONAL  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
     *                             -- contains a value of the type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
     *                             -- registered for use with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
     *                             -- algorithm object identifier value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
     * @return the signature algorithm name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
    public String getSigAlgName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
        if (sigAlgId == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
        return sigAlgId.getName();
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 signature algorithm OID string from the CRL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
     * An OID is represented by a set of positive whole number separated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
     * by ".", that means,<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
     * &lt;positive whole number&gt;.&lt;positive whole number&gt;.&lt;...&gt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
     * For example, the string "1.2.840.10040.4.3" identifies the SHA-1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
     * with DSA signature algorithm defined in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
     * <a href="http://www.ietf.org/rfc/rfc3279.txt">RFC 3279: Algorithms and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
     * Identifiers for the Internet X.509 Public Key Infrastructure Certificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
     * and CRL Profile</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
     * @return the signature algorithm oid string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
    public String getSigAlgOID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
        if (sigAlgId == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
        ObjectIdentifier oid = sigAlgId.getOID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
        return oid.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
     * Gets the DER encoded signature algorithm parameters from this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
     * CRL's signature algorithm. In most cases, the signature
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
     * algorithm parameters are null, the parameters are usually
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
     * supplied with the Public Key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
     * @return the DER encoded signature algorithm parameters, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
     *         null if no parameters are present.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
    public byte[] getSigAlgParams() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
        if (sigAlgId == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
            return sigAlgId.getEncodedParams();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
    /**
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   844
     * Gets the signature AlgorithmId from the CRL.
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   845
     *
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   846
     * @return the signature AlgorithmId
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   847
     */
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   848
    public AlgorithmId getSigAlgId() {
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   849
        return sigAlgId;
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   850
    }
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   851
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   852
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
     * return the AuthorityKeyIdentifier, if any.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
     *
30374
2abaf49910ea 8079478: some docs cleanup for sun.security
avstepan
parents: 26967
diff changeset
   855
     * @return AuthorityKeyIdentifier or null
2abaf49910ea 8079478: some docs cleanup for sun.security
avstepan
parents: 26967
diff changeset
   856
     *         (if no AuthorityKeyIdentifierExtension)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
     * @throws IOException on error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
    public KeyIdentifier getAuthKeyId() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
        AuthorityKeyIdentifierExtension aki = getAuthKeyIdExtension();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
        if (aki != null) {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 7040
diff changeset
   862
            KeyIdentifier keyId = (KeyIdentifier)aki.get(
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 7040
diff changeset
   863
                    AuthorityKeyIdentifierExtension.KEY_ID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
            return keyId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
     * return the AuthorityKeyIdentifierExtension, if any.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
     *
30374
2abaf49910ea 8079478: some docs cleanup for sun.security
avstepan
parents: 26967
diff changeset
   873
     * @return AuthorityKeyIdentifierExtension or null (if no such extension)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
     * @throws IOException on error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
    public AuthorityKeyIdentifierExtension getAuthKeyIdExtension()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
        throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
        Object obj = getExtension(PKIXExtensions.AuthorityKey_Id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
        return (AuthorityKeyIdentifierExtension)obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
     * return the CRLNumberExtension, if any.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
     *
30374
2abaf49910ea 8079478: some docs cleanup for sun.security
avstepan
parents: 26967
diff changeset
   885
     * @return CRLNumberExtension or null (if no such extension)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
     * @throws IOException on error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
    public CRLNumberExtension getCRLNumberExtension() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
        Object obj = getExtension(PKIXExtensions.CRLNumber_Id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
        return (CRLNumberExtension)obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
     * return the CRL number from the CRLNumberExtension, if any.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
     *
30374
2abaf49910ea 8079478: some docs cleanup for sun.security
avstepan
parents: 26967
diff changeset
   896
     * @return number or null (if no such extension)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
     * @throws IOException on error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
    public BigInteger getCRLNumber() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
        CRLNumberExtension numExt = getCRLNumberExtension();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
        if (numExt != null) {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 7040
diff changeset
   902
            BigInteger num = numExt.get(CRLNumberExtension.NUMBER);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
            return num;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
     * return the DeltaCRLIndicatorExtension, if any.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
     *
30374
2abaf49910ea 8079478: some docs cleanup for sun.security
avstepan
parents: 26967
diff changeset
   912
     * @return DeltaCRLIndicatorExtension or null (if no such extension)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
     * @throws IOException on error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
    public DeltaCRLIndicatorExtension getDeltaCRLIndicatorExtension()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
        throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
        Object obj = getExtension(PKIXExtensions.DeltaCRLIndicator_Id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
        return (DeltaCRLIndicatorExtension)obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
     * return the base CRL number from the DeltaCRLIndicatorExtension, if any.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
     *
30374
2abaf49910ea 8079478: some docs cleanup for sun.security
avstepan
parents: 26967
diff changeset
   925
     * @return number or null (if no such extension)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
     * @throws IOException on error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
    public BigInteger getBaseCRLNumber() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
        DeltaCRLIndicatorExtension dciExt = getDeltaCRLIndicatorExtension();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
        if (dciExt != null) {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 7040
diff changeset
   931
            BigInteger num = dciExt.get(DeltaCRLIndicatorExtension.NUMBER);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
            return num;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
     * return the IssuerAlternativeNameExtension, if any.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
     *
30374
2abaf49910ea 8079478: some docs cleanup for sun.security
avstepan
parents: 26967
diff changeset
   941
     * @return IssuerAlternativeNameExtension or null (if no such extension)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
     * @throws IOException on error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
    public IssuerAlternativeNameExtension getIssuerAltNameExtension()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
        throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
        Object obj = getExtension(PKIXExtensions.IssuerAlternativeName_Id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
        return (IssuerAlternativeNameExtension)obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
     * return the IssuingDistributionPointExtension, if any.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
     *
30374
2abaf49910ea 8079478: some docs cleanup for sun.security
avstepan
parents: 26967
diff changeset
   953
     * @return IssuingDistributionPointExtension or null
2abaf49910ea 8079478: some docs cleanup for sun.security
avstepan
parents: 26967
diff changeset
   954
     *         (if no such extension)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
     * @throws IOException on error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
    public IssuingDistributionPointExtension
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
        getIssuingDistributionPointExtension() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
        Object obj = getExtension(PKIXExtensions.IssuingDistributionPoint_Id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
        return (IssuingDistributionPointExtension) obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
     * Return true if a critical extension is found that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
     * not supported, otherwise return false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
    public boolean hasUnsupportedCriticalExtension() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
        if (extensions == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
        return extensions.hasUnsupportedCriticalExtension();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
     * Gets a Set of the extension(s) marked CRITICAL in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
     * CRL. In the returned set, each extension is represented by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
     * its OID string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
     * @return a set of the extension oid strings in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
     * CRL that are marked critical.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
    public Set<String> getCriticalExtensionOIDs() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
        if (extensions == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
        }
13038
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 7040
diff changeset
   986
        Set<String> extSet = new TreeSet<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
        for (Extension ex : extensions.getAllExtensions()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
            if (ex.isCritical()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
                extSet.add(ex.getExtensionId().toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
        return extSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
     * Gets a Set of the extension(s) marked NON-CRITICAL in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
     * CRL. In the returned set, each extension is represented by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
     * its OID string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
     * @return a set of the extension oid strings in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
     * CRL that are NOT marked critical.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
    public Set<String> getNonCriticalExtensionOIDs() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
        if (extensions == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
        }
13038
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 7040
diff changeset
  1007
        Set<String> extSet = new TreeSet<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
        for (Extension ex : extensions.getAllExtensions()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
            if (!ex.isCritical()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
                extSet.add(ex.getExtensionId().toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
        return extSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
     * Gets the DER encoded OCTET string for the extension value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
     * (<code>extnValue</code>) identified by the passed in oid String.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
     * The <code>oid</code> string is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
     * represented by a set of positive whole number separated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
     * by ".", that means,<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
     * &lt;positive whole number&gt;.&lt;positive whole number&gt;.&lt;...&gt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
     * @param oid the Object Identifier value for the extension.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
     * @return the der encoded octet string of the extension value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
    public byte[] getExtensionValue(String oid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
        if (extensions == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
            String extAlias = OIDMap.getName(new ObjectIdentifier(oid));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
            Extension crlExt = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
            if (extAlias == null) { // may be unknown
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
                ObjectIdentifier findOID = new ObjectIdentifier(oid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
                Extension ex = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
                ObjectIdentifier inCertOID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
                for (Enumeration<Extension> e = extensions.getElements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
                                                 e.hasMoreElements();) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
                    ex = e.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
                    inCertOID = ex.getExtensionId();
31426
9cd672654f97 8022444: Remove sun.security.util.ObjectIdentifier.equals(ObjectIdentifier other) method
juh
parents: 30649
diff changeset
  1042
                    if (inCertOID.equals(findOID)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
                        crlExt = ex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
            } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
                crlExt = extensions.get(extAlias);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
            if (crlExt == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
            byte[] extData = crlExt.getExtensionValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
            if (extData == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
            DerOutputStream out = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
            out.putOctetString(extData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
            return out.toByteArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
     * get an extension
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
     * @param oid ObjectIdentifier of extension desired
30374
2abaf49910ea 8079478: some docs cleanup for sun.security
avstepan
parents: 26967
diff changeset
  1066
     * @return Object of type {@code <extension>} or null, if not found
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
     * @throws IOException on error
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
    public Object getExtension(ObjectIdentifier oid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
        if (extensions == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
        // XXX Consider cloning this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
        return extensions.get(OIDMap.getName(oid));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
     * Parses an X.509 CRL, should be used only by constructors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
    private void parse(DerValue val) throws CRLException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
        // check if can over write the certificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
        if (readOnly)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
            throw new CRLException("cannot over-write existing CRL");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
        if ( val.getData() == null || val.tag != DerValue.tag_Sequence)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
            throw new CRLException("Invalid DER-encoded CRL data");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
        signedCRL = val.toByteArray();
31538
0981099a3e54 8130022: Use Java-style array declarations consistently
igerasim
parents: 31426
diff changeset
  1089
        DerValue[] seq = new DerValue[3];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
        seq[0] = val.data.getDerValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
        seq[1] = val.data.getDerValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
        seq[2] = val.data.getDerValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
        if (val.data.available() != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
            throw new CRLException("signed overrun, bytes = "
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
                                     + val.data.available());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
        if (seq[0].tag != DerValue.tag_Sequence)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
            throw new CRLException("signed CRL fields invalid");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
        sigAlgId = AlgorithmId.parse(seq[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
        signature = seq[2].getBitString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
        if (seq[1].data.available() != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
            throw new CRLException("AlgorithmId field overrun");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
        if (seq[2].data.available() != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
            throw new CRLException("Signature field overrun");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
        // the tbsCertsList
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
        tbsCertList = seq[0].toByteArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
        // parse the information
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
        DerInputStream derStrm = seq[0].data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
        DerValue       tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
        byte           nextByte;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
        // version (optional if v1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
        version = 0;   // by default, version = v1 == 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
        nextByte = (byte)derStrm.peekByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
        if (nextByte == DerValue.tag_Integer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
            version = derStrm.getInteger();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
            if (version != 1)  // i.e. v2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
                throw new CRLException("Invalid version");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
        tmp = derStrm.getDerValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
        // signature
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
        AlgorithmId tmpId = AlgorithmId.parse(tmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
        // the "inner" and "outer" signature algorithms must match
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
        if (! tmpId.equals(sigAlgId))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
            throw new CRLException("Signature algorithm mismatch");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
        infoSigAlgId = tmpId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
        // issuer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
        issuer = new X500Name(derStrm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
        if (issuer.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
            throw new CRLException("Empty issuer DN not allowed in X509CRLs");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
        // thisUpdate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
        // check if UTCTime encoded or GeneralizedTime
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
        nextByte = (byte)derStrm.peekByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
        if (nextByte == DerValue.tag_UtcTime) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
            thisUpdate = derStrm.getUTCTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
        } else if (nextByte == DerValue.tag_GeneralizedTime) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
            thisUpdate = derStrm.getGeneralizedTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
            throw new CRLException("Invalid encoding for thisUpdate"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
                                   + " (tag=" + nextByte + ")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
        if (derStrm.available() == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
           return;     // done parsing no more optional fields present
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
        // nextUpdate (optional)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
        nextByte = (byte)derStrm.peekByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
        if (nextByte == DerValue.tag_UtcTime) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
            nextUpdate = derStrm.getUTCTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
        } else if (nextByte == DerValue.tag_GeneralizedTime) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
            nextUpdate = derStrm.getGeneralizedTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
        } // else it is not present
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
        if (derStrm.available() == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
            return;     // done parsing no more optional fields present
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
        // revokedCertificates (optional)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
        nextByte = (byte)derStrm.peekByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
        if ((nextByte == DerValue.tag_SequenceOf)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
            && (! ((nextByte & 0x0c0) == 0x080))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
            DerValue[] badCerts = derStrm.getSequence(4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
            X500Principal crlIssuer = getIssuerX500Principal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
            X500Principal badCertIssuer = crlIssuer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
            for (int i = 0; i < badCerts.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
                X509CRLEntryImpl entry = new X509CRLEntryImpl(badCerts[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
                badCertIssuer = getCertIssuer(entry, badCertIssuer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
                entry.setCertificateIssuer(crlIssuer, badCertIssuer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
                X509IssuerSerial issuerSerial = new X509IssuerSerial
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
                    (badCertIssuer, entry.getSerialNumber());
13038
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 7040
diff changeset
  1184
                revokedMap.put(issuerSerial, entry);
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 7040
diff changeset
  1185
                revokedList.add(entry);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
        if (derStrm.available() == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
            return;     // done parsing no extensions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
        // crlExtensions (optional)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
        tmp = derStrm.getDerValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
        if (tmp.isConstructed() && tmp.isContextSpecific((byte)0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
            extensions = new CRLExtensions(tmp.data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
        readOnly = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
     * Extract the issuer X500Principal from an X509CRL. Parses the encoded
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
     * form of the CRL to preserve the principal's ASN.1 encoding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
     * Called by java.security.cert.X509CRL.getIssuerX500Principal().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
    public static X500Principal getIssuerX500Principal(X509CRL crl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
            byte[] encoded = crl.getEncoded();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
            DerInputStream derIn = new DerInputStream(encoded);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
            DerValue tbsCert = derIn.getSequence(3)[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
            DerInputStream tbsIn = tbsCert.data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
            DerValue tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
            // skip version number if present
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
            byte nextByte = (byte)tbsIn.peekByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
            if (nextByte == DerValue.tag_Integer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
                tmp = tbsIn.getDerValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
            tmp = tbsIn.getDerValue();  // skip signature
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
            tmp = tbsIn.getDerValue();  // issuer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
            byte[] principalBytes = tmp.toByteArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
            return new X500Principal(principalBytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
            throw new RuntimeException("Could not parse issuer", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
     * Returned the encoding of the given certificate for internal use.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
     * Callers must guarantee that they neither modify it nor expose it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
     * to untrusted code. Uses getEncodedInternal() if the certificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
     * is instance of X509CertImpl, getEncoded() otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
    public static byte[] getEncodedInternal(X509CRL crl) throws CRLException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
        if (crl instanceof X509CRLImpl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
            return ((X509CRLImpl)crl).getEncodedInternal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
            return crl.getEncoded();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
     * Utility method to convert an arbitrary instance of X509CRL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
     * to a X509CRLImpl. Does a cast if possible, otherwise reparses
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
     * the encoding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
    public static X509CRLImpl toImpl(X509CRL crl)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
            throws CRLException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
        if (crl instanceof X509CRLImpl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
            return (X509CRLImpl)crl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
            return X509Factory.intern(crl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
     * Returns the X500 certificate issuer DN of a CRL entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
     * @param entry the entry to check
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
     * @param prevCertIssuer the previous entry's certificate issuer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
     * @return the X500Principal in a CertificateIssuerExtension, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
     *   prevCertIssuer if it does not exist
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
    private X500Principal getCertIssuer(X509CRLEntryImpl entry,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
        X500Principal prevCertIssuer) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
        CertificateIssuerExtension ciExt =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
            entry.getCertificateIssuerExtension();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
        if (ciExt != null) {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 7040
diff changeset
  1271
            GeneralNames names = ciExt.get(CertificateIssuerExtension.ISSUER);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
            X500Name issuerDN = (X500Name) names.get(0).getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
            return issuerDN.asX500Principal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
            return prevCertIssuer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
5462
cb614e59f7f9 6890876: jarsigner can add CRL info into signed jar
weijun
parents: 2
diff changeset
  1279
    @Override
cb614e59f7f9 6890876: jarsigner can add CRL info into signed jar
weijun
parents: 2
diff changeset
  1280
    public void derEncode(OutputStream out) throws IOException {
cb614e59f7f9 6890876: jarsigner can add CRL info into signed jar
weijun
parents: 2
diff changeset
  1281
        if (signedCRL == null)
cb614e59f7f9 6890876: jarsigner can add CRL info into signed jar
weijun
parents: 2
diff changeset
  1282
            throw new IOException("Null CRL to encode");
cb614e59f7f9 6890876: jarsigner can add CRL info into signed jar
weijun
parents: 2
diff changeset
  1283
        out.write(signedCRL.clone());
cb614e59f7f9 6890876: jarsigner can add CRL info into signed jar
weijun
parents: 2
diff changeset
  1284
    }
cb614e59f7f9 6890876: jarsigner can add CRL info into signed jar
weijun
parents: 2
diff changeset
  1285
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
     * Immutable X.509 Certificate Issuer DN and serial number pair
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 31538
diff changeset
  1289
    private static final class X509IssuerSerial
13038
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 7040
diff changeset
  1290
            implements Comparable<X509IssuerSerial> {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
        final X500Principal issuer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
        final BigInteger serial;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
        volatile int hashcode = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
         * Create an X509IssuerSerial.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
         * @param issuer the issuer DN
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
         * @param serial the serial number
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
        X509IssuerSerial(X500Principal issuer, BigInteger serial) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
            this.issuer = issuer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
            this.serial = serial;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
         * Construct an X509IssuerSerial from an X509Certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
        X509IssuerSerial(X509Certificate cert) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
            this(cert.getIssuerX500Principal(), cert.getSerialNumber());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
         * Returns the issuer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
         * @return the issuer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
        X500Principal getIssuer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
            return issuer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
         * Returns the serial number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
         * @return the serial number
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
        BigInteger getSerial() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
            return serial;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
         * Compares this X509Serial with another and returns true if they
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
         * are equivalent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
         * @param o the other object to compare with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
         * @return true if equal, false otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
        public boolean equals(Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
            if (o == this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
            if (!(o instanceof X509IssuerSerial)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
            X509IssuerSerial other = (X509IssuerSerial) o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
            if (serial.equals(other.getSerial()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
                issuer.equals(other.getIssuer())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
         * Returns a hash code value for this X509IssuerSerial.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
         * @return the hash code value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
        public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
            if (hashcode == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
                int result = 17;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
                result = 37*result + issuer.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
                result = 37*result + serial.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
                hashcode = result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
            return hashcode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
        }
13038
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 7040
diff changeset
  1369
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 7040
diff changeset
  1370
        @Override
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 7040
diff changeset
  1371
        public int compareTo(X509IssuerSerial another) {
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 7040
diff changeset
  1372
            int cissuer = issuer.toString()
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 7040
diff changeset
  1373
                    .compareTo(another.issuer.toString());
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 7040
diff changeset
  1374
            if (cissuer != 0) return cissuer;
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 7040
diff changeset
  1375
            return this.serial.compareTo(another.serial);
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 7040
diff changeset
  1376
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
}