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