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