jdk/src/java.base/share/classes/sun/security/x509/X509CRLEntryImpl.java
author martin
Tue, 15 Sep 2015 21:56:04 -0700
changeset 32649 2ee9017c7597
parent 31426 9cd672654f97
child 34687 d302ed125dc9
permissions -rw-r--r--
8136583: Core libraries should use blessed modifier order Summary: Run blessed-modifier-order script (see bug) Reviewed-by: psandoz, chegar, alanb, plevart
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
31426
9cd672654f97 8022444: Remove sun.security.util.ObjectIdentifier.equals(ObjectIdentifier other) method
juh
parents: 30649
diff changeset
     2
 * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
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: 2
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: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
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.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.security.cert.CRLException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.security.cert.CRLReason;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.security.cert.X509CRLEntry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.math.BigInteger;
13038
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 5506
diff changeset
    33
import java.util.*;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.security.auth.x500.X500Principal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import sun.security.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import sun.misc.HexDumpEncoder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * <p>Abstract class for a revoked certificate in a CRL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * This class is for each entry in the <code>revokedCertificates</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * so it deals with the inner <em>SEQUENCE</em>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * The ASN.1 definition for this is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * revokedCertificates    SEQUENCE OF SEQUENCE  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *     userCertificate    CertificateSerialNumber,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *     revocationDate     ChoiceOfTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *     crlEntryExtensions Extensions OPTIONAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *                        -- if present, must be v2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * }  OPTIONAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * CertificateSerialNumber  ::=  INTEGER
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * Extensions  ::=  SEQUENCE SIZE (1..MAX) OF Extension
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * Extension  ::=  SEQUENCE  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *     extnId        OBJECT IDENTIFIER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *     critical      BOOLEAN DEFAULT FALSE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *     extnValue     OCTET STRING
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *                   -- contains a DER encoding of a value
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *                   -- of the type registered for use with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *                   -- the extnId object identifier value
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * @author Hemma Prafullchandra
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
13038
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 5506
diff changeset
    70
public class X509CRLEntryImpl extends X509CRLEntry
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 5506
diff changeset
    71
        implements Comparable<X509CRLEntryImpl> {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    private SerialNumber serialNumber = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    private Date revocationDate = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    private CRLExtensions extensions = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    private byte[] revokedCert = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    private X500Principal certIssuer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 31426
diff changeset
    79
    private static final boolean isExplicit = false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    private static final long YR_2050 = 2524636800000L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * Constructs a revoked certificate entry using the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * serial number and revocation date.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * @param num the serial number of the revoked certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * @param date the Date on which revocation took place.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    public X509CRLEntryImpl(BigInteger num, Date date) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        this.serialNumber = new SerialNumber(num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        this.revocationDate = date;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * Constructs a revoked certificate entry using the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * serial number, revocation date and the entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * extensions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * @param num the serial number of the revoked certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * @param date the Date on which revocation took place.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * @param crlEntryExts the extensions for this entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    public X509CRLEntryImpl(BigInteger num, Date date,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                           CRLExtensions crlEntryExts) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        this.serialNumber = new SerialNumber(num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        this.revocationDate = date;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        this.extensions = crlEntryExts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * Unmarshals a revoked certificate from its encoded form.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * @param revokedCert the encoded bytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * @exception CRLException on parsing errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    public X509CRLEntryImpl(byte[] revokedCert) throws CRLException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            parse(new DerValue(revokedCert));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            this.revokedCert = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            throw new CRLException("Parsing error: " + e.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * Unmarshals a revoked certificate from its encoded form.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     *
30374
2abaf49910ea 8079478: some docs cleanup for sun.security
avstepan
parents: 25859
diff changeset
   128
     * @param derValue the DER value containing the revoked certificate.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * @exception CRLException on parsing errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    public X509CRLEntryImpl(DerValue derValue) throws CRLException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            parse(derValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            revokedCert = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            throw new CRLException("Parsing error: " + e.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * Returns true if this revoked certificate entry has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * extensions, otherwise false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * @return true if this CRL entry has extensions, otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    public boolean hasExtensions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        return (extensions != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * Encodes the revoked certificate to an output stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * @param outStrm an output stream to which the encoded revoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * certificate is written.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * @exception CRLException on encoding errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    public void encode(DerOutputStream outStrm) throws CRLException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            if (revokedCert == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                DerOutputStream tmp = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                // sequence { serialNumber, revocationDate, extensions }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                serialNumber.encode(tmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                if (revocationDate.getTime() < YR_2050) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                    tmp.putUTCTime(revocationDate);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                    tmp.putGeneralizedTime(revocationDate);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                if (extensions != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                    extensions.encode(tmp, isExplicit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                DerOutputStream seq = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                seq.write(DerValue.tag_Sequence, tmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                revokedCert = seq.toByteArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            outStrm.write(revokedCert);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
             throw new CRLException("Encoding error: " + e.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * Returns the ASN.1 DER-encoded form of this CRL Entry,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * which corresponds to the inner SEQUENCE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * @exception CRLException if an encoding error occurs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    public byte[] getEncoded() throws CRLException {
13038
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 5506
diff changeset
   192
        return getEncoded0().clone();
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 5506
diff changeset
   193
    }
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 5506
diff changeset
   194
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 5506
diff changeset
   195
    // Called internally to avoid clone
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 5506
diff changeset
   196
    private byte[] getEncoded0() throws CRLException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        if (revokedCert == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            this.encode(new DerOutputStream());
13038
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 5506
diff changeset
   199
        return revokedCert;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    public X500Principal getCertificateIssuer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        return certIssuer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    void setCertificateIssuer(X500Principal crlIssuer, X500Principal certIssuer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        if (crlIssuer.equals(certIssuer)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            this.certIssuer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            this.certIssuer = certIssuer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * Gets the serial number from this X509CRLEntry,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * i.e. the <em>userCertificate</em>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * @return the serial number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    public BigInteger getSerialNumber() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        return serialNumber.getNumber();
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
     * Gets the revocation date from this X509CRLEntry,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * the <em>revocationDate</em>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * @return the revocation date.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    public Date getRevocationDate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        return new Date(revocationDate.getTime());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * This method is the overridden implementation of the getRevocationReason
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * method in X509CRLEntry. It is better performance-wise since it returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * cached values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    public CRLReason getRevocationReason() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        Extension ext = getExtension(PKIXExtensions.ReasonCode_Id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        if (ext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        CRLReasonCodeExtension rcExt = (CRLReasonCodeExtension) ext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        return rcExt.getReasonCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * This static method is the default implementation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * getRevocationReason method in X509CRLEntry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    public static CRLReason getRevocationReason(X509CRLEntry crlEntry) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            byte[] ext = crlEntry.getExtensionValue("2.5.29.21");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            if (ext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            DerValue val = new DerValue(ext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            byte[] data = val.getOctetString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            CRLReasonCodeExtension rcExt =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                new CRLReasonCodeExtension(Boolean.FALSE, data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            return rcExt.getReasonCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        } catch (IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            return null;
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * get Reason Code from CRL entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     *
30374
2abaf49910ea 8079478: some docs cleanup for sun.security
avstepan
parents: 25859
diff changeset
   274
     * @return Integer or null, if no such extension
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * @throws IOException on error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    public Integer getReasonCode() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        Object obj = getExtension(PKIXExtensions.ReasonCode_Id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        if (obj == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        CRLReasonCodeExtension reasonCode = (CRLReasonCodeExtension)obj;
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   282
        return reasonCode.get(CRLReasonCodeExtension.REASON);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * Returns a printable string of this revoked certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * @return value of this revoked certificate in a printable form.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        StringBuilder sb = new StringBuilder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
30649
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   294
        sb.append(serialNumber)
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   295
            .append("  On: ")
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   296
            .append(revocationDate);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        if (certIssuer != null) {
30649
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   298
            sb.append("\n    Certificate issuer: ")
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   299
                .append(certIssuer);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        if (extensions != null) {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   302
            Collection<Extension> allEntryExts = extensions.getAllExtensions();
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   303
            Extension[] exts = allEntryExts.toArray(new Extension[0]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
30649
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   305
            sb.append("\n    CRL Entry Extensions: ")
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   306
                .append(exts.length);
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   307
            for (int i = 0; i < exts.length; i++) {
30649
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   308
                sb.append("\n    [")
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   309
                    .append(i+1)
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   310
                    .append("]: ");
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   311
                Extension ext = exts[i];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                    if (OIDMap.getClass(ext.getExtensionId()) == null) {
30649
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   314
                        sb.append(ext);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                        byte[] extValue = ext.getExtensionValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                        if (extValue != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                            DerOutputStream out = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                            out.putOctetString(extValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                            extValue = out.toByteArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                            HexDumpEncoder enc = new HexDumpEncoder();
30649
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   321
                            sb.append("Extension unknown: ")
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   322
                                .append("DER encoded OCTET string =\n")
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   323
                                .append(enc.encodeBuffer(extValue))
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   324
                                .append('\n');
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                        }
30649
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   326
                    } else {
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   327
                        sb.append(ext); //sub-class exists
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   328
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                    sb.append(", Error parsing this extension");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        }
30649
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   334
        sb.append('\n');
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        return sb.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * Return true if a critical extension is found that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * not supported, otherwise return false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    public boolean hasUnsupportedCriticalExtension() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        if (extensions == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        return extensions.hasUnsupportedCriticalExtension();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * Gets a Set of the extension(s) marked CRITICAL in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * X509CRLEntry.  In the returned set, each extension is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * represented by its OID string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * @return a set of the extension oid strings in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * Object that are marked critical.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    public Set<String> getCriticalExtensionOIDs() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        if (extensions == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        }
13038
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 5506
diff changeset
   360
        Set<String> extSet = new TreeSet<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        for (Extension ex : extensions.getAllExtensions()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            if (ex.isCritical()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                extSet.add(ex.getExtensionId().toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        return extSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * Gets a Set of the extension(s) marked NON-CRITICAL in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * X509CRLEntry. In the returned set, each extension is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * represented by its OID string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * @return a set of the extension oid strings in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * Object that are marked critical.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    public Set<String> getNonCriticalExtensionOIDs() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        if (extensions == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        }
13038
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 5506
diff changeset
   381
        Set<String> extSet = new TreeSet<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        for (Extension ex : extensions.getAllExtensions()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            if (!ex.isCritical()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                extSet.add(ex.getExtensionId().toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        return extSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * Gets the DER encoded OCTET string for the extension value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * (<em>extnValue</em>) identified by the passed in oid String.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * The <code>oid</code> string is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * represented by a set of positive whole number separated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * by ".", that means,<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * &lt;positive whole number&gt;.&lt;positive whole number&gt;.&lt;positive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * whole number&gt;.&lt;...&gt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * @param oid the Object Identifier value for the extension.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * @return the DER encoded octet string of the extension value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    public byte[] getExtensionValue(String oid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        if (extensions == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            String extAlias = OIDMap.getName(new ObjectIdentifier(oid));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            Extension crlExt = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            if (extAlias == null) { // may be unknown
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                ObjectIdentifier findOID = new ObjectIdentifier(oid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                Extension ex = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                ObjectIdentifier inCertOID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                for (Enumeration<Extension> e = extensions.getElements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                                                 e.hasMoreElements();) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                    ex = e.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                    inCertOID = ex.getExtensionId();
31426
9cd672654f97 8022444: Remove sun.security.util.ObjectIdentifier.equals(ObjectIdentifier other) method
juh
parents: 30649
diff changeset
   417
                    if (inCertOID.equals(findOID)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                        crlExt = ex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                crlExt = extensions.get(extAlias);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            if (crlExt == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            byte[] extData = crlExt.getExtensionValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            if (extData == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
            DerOutputStream out = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            out.putOctetString(extData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
            return out.toByteArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * get an extension
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * @param oid ObjectIdentifier of extension desired
30374
2abaf49910ea 8079478: some docs cleanup for sun.security
avstepan
parents: 25859
diff changeset
   442
     * @return Extension of type {@code <extension>} or null, if not found
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    public Extension getExtension(ObjectIdentifier oid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        if (extensions == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        // following returns null if no such OID in map
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        //XXX consider cloning this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        return extensions.get(OIDMap.getName(oid));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    private void parse(DerValue derVal)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    throws CRLException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        if (derVal.tag != DerValue.tag_Sequence) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            throw new CRLException("Invalid encoded RevokedCertificate, " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                                  "starting sequence tag missing.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        if (derVal.data.available() == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            throw new CRLException("No data encoded for RevokedCertificates");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        revokedCert = derVal.toByteArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        // serial number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        DerInputStream in = derVal.toDerInputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        DerValue val = in.getDerValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        this.serialNumber = new SerialNumber(val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        // revocationDate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        int nextByte = derVal.data.peekByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        if ((byte)nextByte == DerValue.tag_UtcTime) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
            this.revocationDate = derVal.data.getUTCTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        } else if ((byte)nextByte == DerValue.tag_GeneralizedTime) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            this.revocationDate = derVal.data.getGeneralizedTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            throw new CRLException("Invalid encoding for revocation date");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        if (derVal.data.available() == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            return;  // no extensions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        // crlEntryExtensions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        this.extensions = new CRLExtensions(derVal.toDerInputStream());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * Utility method to convert an arbitrary instance of X509CRLEntry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * to a X509CRLEntryImpl. Does a cast if possible, otherwise reparses
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * the encoding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    public static X509CRLEntryImpl toImpl(X509CRLEntry entry)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            throws CRLException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        if (entry instanceof X509CRLEntryImpl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            return (X509CRLEntryImpl)entry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            return new X509CRLEntryImpl(entry.getEncoded());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * Returns the CertificateIssuerExtension
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * @return the CertificateIssuerExtension, or null if it does not exist
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    CertificateIssuerExtension getCertificateIssuerExtension() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        return (CertificateIssuerExtension)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
            getExtension(PKIXExtensions.CertificateIssuer_Id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
13038
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 5506
diff changeset
   509
    /**
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 5506
diff changeset
   510
     * Returns all extensions for this entry in a map
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 5506
diff changeset
   511
     * @return the extension map, can be empty, but not null
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 5506
diff changeset
   512
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    public Map<String, java.security.cert.Extension> getExtensions() {
13038
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 5506
diff changeset
   514
        if (extensions == null) {
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 5506
diff changeset
   515
            return Collections.emptyMap();
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 5506
diff changeset
   516
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        Collection<Extension> exts = extensions.getAllExtensions();
13038
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 5506
diff changeset
   518
        Map<String, java.security.cert.Extension> map = new TreeMap<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        for (Extension ext : exts) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            map.put(ext.getId(), ext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        return map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    }
13038
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 5506
diff changeset
   524
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 5506
diff changeset
   525
    @Override
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 5506
diff changeset
   526
    public int compareTo(X509CRLEntryImpl that) {
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 5506
diff changeset
   527
        int compSerial = getSerialNumber().compareTo(that.getSerialNumber());
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 5506
diff changeset
   528
        if (compSerial != 0) {
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 5506
diff changeset
   529
            return compSerial;
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 5506
diff changeset
   530
        }
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 5506
diff changeset
   531
        try {
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 5506
diff changeset
   532
            byte[] thisEncoded = this.getEncoded0();
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 5506
diff changeset
   533
            byte[] thatEncoded = that.getEncoded0();
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 5506
diff changeset
   534
            for (int i=0; i<thisEncoded.length && i<thatEncoded.length; i++) {
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 5506
diff changeset
   535
                int a = thisEncoded[i] & 0xff;
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 5506
diff changeset
   536
                int b = thatEncoded[i] & 0xff;
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 5506
diff changeset
   537
                if (a != b) return a-b;
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 5506
diff changeset
   538
            }
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 5506
diff changeset
   539
            return thisEncoded.length -thatEncoded.length;
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 5506
diff changeset
   540
        } catch (CRLException ce) {
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 5506
diff changeset
   541
            return -1;
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 5506
diff changeset
   542
        }
e6024efff1b6 7143872: Improve certificate extension processing
weijun
parents: 5506
diff changeset
   543
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
}