jdk/src/share/classes/sun/security/x509/CRLExtensions.java
author ohair
Tue, 25 May 2010 15:58:33 -0700
changeset 5506 202f599c92aa
parent 2 90ce3da70b43
child 10336 0bb1999251f8
child 13038 e6024efff1b6
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1997, 2006, 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.io.OutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.lang.reflect.Constructor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.lang.reflect.InvocationTargetException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.security.cert.CRLException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.security.cert.CertificateException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.Collection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.Enumeration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.Hashtable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import sun.security.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import sun.misc.HexDumpEncoder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * This class defines the CRL Extensions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * It is used for both CRL Extensions and CRL Entry Extensions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * which are defined are follows:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * TBSCertList  ::=  SEQUENCE  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *    version              Version OPTIONAL,   -- if present, must be v2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *    signature            AlgorithmIdentifier,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *    issuer               Name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *    thisUpdate           Time,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *    nextUpdate           Time  OPTIONAL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *    revokedCertificates  SEQUENCE OF SEQUENCE  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *        userCertificate         CertificateSerialNumber,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *        revocationDate          Time,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *        crlEntryExtensions      Extensions OPTIONAL  -- if present, must be v2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *    }  OPTIONAL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *    crlExtensions        [0] EXPLICIT Extensions OPTIONAL  -- if present, must be v2
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
 * @author Hemma Prafullchandra
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
public class CRLExtensions {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    private Hashtable<String,Extension> map = new Hashtable<String,Extension>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    private boolean unsupportedCritExt = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * Default constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    public CRLExtensions() { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * Create the object, decoding the values from the passed DER stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * @param in the DerInputStream to read the Extension from, i.e. the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     *        sequence of extensions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * @exception CRLException on decoding errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    public CRLExtensions(DerInputStream in) throws CRLException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        init(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    // helper routine
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    private void init(DerInputStream derStrm) throws CRLException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            DerInputStream str = derStrm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            byte nextByte = (byte)derStrm.peekByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            // check for context specific byte 0; skip it
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            if (((nextByte & 0x0c0) == 0x080) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                ((nextByte & 0x01f) == 0x000)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                DerValue val = str.getDerValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                str = val.data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            DerValue[] exts = str.getSequence(5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            for (int i = 0; i < exts.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                Extension ext = new Extension(exts[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                parseExtension(ext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            throw new CRLException("Parsing error: " + e.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    private static final Class[] PARAMS = {Boolean.class, Object.class};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    // Parse the encoded extension
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    private void parseExtension(Extension ext) throws CRLException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            Class extClass = OIDMap.getClass(ext.getExtensionId());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            if (extClass == null) {   // Unsupported extension
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                if (ext.isCritical())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                    unsupportedCritExt = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                if (map.put(ext.getExtensionId().toString(), ext) != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                    throw new CRLException("Duplicate extensions not allowed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            Constructor cons = ((Class<?>)extClass).getConstructor(PARAMS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            Object[] passed = new Object[] {Boolean.valueOf(ext.isCritical()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                                            ext.getExtensionValue()};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            CertAttrSet crlExt = (CertAttrSet)cons.newInstance(passed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            if (map.put(crlExt.getName(), (Extension)crlExt) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                throw new CRLException("Duplicate extensions not allowed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        } catch (InvocationTargetException invk) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            throw new CRLException(invk.getTargetException().getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            throw new CRLException(e.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * Encode the extensions in DER form to the stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * @param out the DerOutputStream to marshal the contents to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * @param isExplicit the tag indicating whether this is an entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * extension (false) or a CRL extension (true).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * @exception CRLException on encoding errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    public void encode(OutputStream out, boolean isExplicit)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    throws CRLException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            DerOutputStream extOut = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            Collection<Extension> allExts = map.values();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            Object[] objs = allExts.toArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            for (int i = 0; i < objs.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                if (objs[i] instanceof CertAttrSet)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                    ((CertAttrSet)objs[i]).encode(extOut);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                else if (objs[i] instanceof Extension)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                    ((Extension)objs[i]).encode(extOut);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                    throw new CRLException("Illegal extension object");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            DerOutputStream seq = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            seq.write(DerValue.tag_Sequence, extOut);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            DerOutputStream tmp = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            if (isExplicit)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                tmp.write(DerValue.createTag(DerValue.TAG_CONTEXT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                                             true, (byte)0), seq);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                tmp = seq;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            out.write(tmp.toByteArray());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            throw new CRLException("Encoding error: " + e.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        } catch (CertificateException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            throw new CRLException("Encoding error: " + e.toString());
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * Get the extension with this alias.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * @param alias the identifier string for the extension to retrieve.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    public Extension get(String alias) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        X509AttributeName attr = new X509AttributeName(alias);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        String name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        String id = attr.getPrefix();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        if (id.equalsIgnoreCase(X509CertImpl.NAME)) { // fully qualified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            int index = alias.lastIndexOf(".");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            name = alias.substring(index + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            name = alias;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        return map.get(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * Set the extension value with this alias.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * @param alias the identifier string for the extension to set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * @param obj the Object to set the extension identified by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     *        alias.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    public void set(String alias, Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        map.put(alias, (Extension)obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * Delete the extension value with this alias.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * @param alias the identifier string for the extension to delete.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    public void delete(String alias) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        map.remove(alias);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * Return an enumeration of the extensions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * @return an enumeration of the extensions in this CRL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    public Enumeration<Extension> getElements() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        return map.elements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * Return a collection view of the extensions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * @return a collection view of the extensions in this CRL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    public Collection<Extension> getAllExtensions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        return map.values();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * Return true if a critical extension is found that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * not supported, otherwise return false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    public boolean hasUnsupportedCriticalExtension() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        return unsupportedCritExt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * Compares this CRLExtensions for equality with the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * object. If the <code>other</code> object is an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * <code>instanceof</code> <code>CRLExtensions</code>, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * all the entries are compared with the entries from this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * @param other the object to test for equality with this CRLExtensions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * @return true iff all the entries match that of the Other,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    public boolean equals(Object other) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        if (this == other)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        if (!(other instanceof CRLExtensions))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        Collection<Extension> otherC =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                        ((CRLExtensions)other).getAllExtensions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        Object[] objs = otherC.toArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        int len = objs.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        if (len != map.size())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        Extension otherExt, thisExt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        String key = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        for (int i = 0; i < len; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            if (objs[i] instanceof CertAttrSet)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                key = ((CertAttrSet)objs[i]).getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            otherExt = (Extension)objs[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            if (key == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                key = otherExt.getExtensionId().toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            thisExt = map.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            if (thisExt == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            if (! thisExt.equals(otherExt))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * Returns a hashcode value for this CRLExtensions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * @return the hashcode value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        return map.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * Returns a string representation of this <tt>CRLExtensions</tt> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * in the form of a set of entries, enclosed in braces and separated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * by the ASCII characters "<tt>,&nbsp;</tt>" (comma and space).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * <p>Overrides to <tt>toString</tt> method of <tt>Object</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * @return  a string representation of this CRLExtensions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        return map.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
}