jdk/src/share/classes/java/security/cert/X509CRLEntry.java
author xuelei
Wed, 20 Jan 2010 21:38:37 +0800
changeset 4807 2521b7dcf505
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
6862064: incorrect implementation of PKIXParameters.clone() Reviewed-by: weijun, mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1997-2003 Sun Microsystems, Inc.  All Rights Reserved.
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
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 java.security.cert;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.math.BigInteger;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.Date;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.security.auth.x500.X500Principal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import sun.security.x509.X509CRLEntryImpl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * <p>Abstract class for a revoked certificate in a CRL (Certificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * Revocation List).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * The ASN.1 definition for <em>revokedCertificates</em> is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * revokedCertificates    SEQUENCE OF SEQUENCE  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *     userCertificate    CertificateSerialNumber,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *     revocationDate     ChoiceOfTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *     crlEntryExtensions Extensions OPTIONAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *                        -- if present, must be v2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * }  OPTIONAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * CertificateSerialNumber  ::=  INTEGER
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * Extensions  ::=  SEQUENCE SIZE (1..MAX) OF Extension
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * Extension  ::=  SEQUENCE  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *     extnId        OBJECT IDENTIFIER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *     critical      BOOLEAN DEFAULT FALSE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *     extnValue     OCTET STRING
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *                   -- contains a DER encoding of a value
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *                   -- of the type registered for use with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *                   -- the extnId object identifier value
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * @see X509CRL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * @see X509Extension
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * @author Hemma Prafullchandra
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
public abstract class X509CRLEntry implements X509Extension {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * Compares this CRL entry for equality with the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * object. If the <code>other</code> object is an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * <code>instanceof</code> <code>X509CRLEntry</code>, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * its encoded form (the inner SEQUENCE) is retrieved and compared
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * with the encoded form of this CRL entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * @param other the object to test for equality with this CRL entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * @return true iff the encoded forms of the two CRL entries
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * match, false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    public boolean equals(Object other) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        if (this == other)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        if (!(other instanceof X509CRLEntry))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            byte[] thisCRLEntry = this.getEncoded();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            byte[] otherCRLEntry = ((X509CRLEntry)other).getEncoded();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            if (thisCRLEntry.length != otherCRLEntry.length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            for (int i = 0; i < thisCRLEntry.length; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                 if (thisCRLEntry[i] != otherCRLEntry[i])
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                     return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        } catch (CRLException ce) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * Returns a hashcode value for this CRL entry from its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * encoded form.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * @return the hashcode value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        int     retval = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            byte[] entryData = this.getEncoded();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            for (int i = 1; i < entryData.length; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                 retval += entryData[i] * i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        } catch (CRLException ce) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            return(retval);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        return(retval);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * Returns the ASN.1 DER-encoded form of this CRL Entry,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * that is the inner SEQUENCE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * @return the encoded form of this certificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * @exception CRLException if an encoding error occurs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    public abstract byte[] getEncoded() throws CRLException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * Gets the serial number from this X509CRLEntry,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * the <em>userCertificate</em>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * @return the serial number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    public abstract BigInteger getSerialNumber();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * Get the issuer of the X509Certificate described by this entry. If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * the certificate issuer is also the CRL issuer, this method returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * <p>This method is used with indirect CRLs. The default implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * always returns null. Subclasses that wish to support indirect CRLs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * should override it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * @return the issuer of the X509Certificate described by this entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * or null if it is issued by the CRL issuer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    public X500Principal getCertificateIssuer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * Gets the revocation date from this X509CRLEntry,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * the <em>revocationDate</em>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * @return the revocation date.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    public abstract Date getRevocationDate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * Returns true if this CRL entry has extensions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * @return true if this entry has extensions, false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    public abstract boolean hasExtensions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * Returns a string representation of this CRL entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * @return a string representation of this CRL entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    public abstract String toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * Returns the reason the certificate has been revoked, as specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * in the Reason Code extension of this CRL entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * @return the reason the certificate has been revoked, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     *    <code>null</code> if this CRL entry does not have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     *    a Reason Code extension
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * @since 1.7
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    public CRLReason getRevocationReason() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        if (!hasExtensions()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        return X509CRLEntryImpl.getRevocationReason(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
}