jdk/src/java.base/share/classes/sun/security/x509/DistributionPoint.java
author martin
Tue, 15 Sep 2015 21:56:04 -0700
changeset 32649 2ee9017c7597
parent 30649 e7cc8f48f616
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
/*
10051
b96a8c7fefef 7041252: Use j.u.Objects.equals in security classes
darcy
parents: 5506
diff changeset
     2
 * Copyright (c) 2002, 2011, 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.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import sun.security.util.BitArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import sun.security.util.DerOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import sun.security.util.DerValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * Represent the DistributionPoint sequence used in the CRL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * Distribution Points Extension (OID = 2.5.29.31).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * The ASN.1 definition for this is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * DistributionPoint ::= SEQUENCE {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *      distributionPoint       [0]     DistributionPointName OPTIONAL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *      reasons                 [1]     ReasonFlags OPTIONAL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *      cRLIssuer               [2]     GeneralNames OPTIONAL }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * DistributionPointName ::= CHOICE {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *      fullName                [0]     GeneralNames,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *      nameRelativeToCRLIssuer [1]     RelativeDistinguishedName }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * ReasonFlags ::= BIT STRING {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *      unused                  (0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *      keyCompromise           (1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *      cACompromise            (2),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *      affiliationChanged      (3),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *      superseded              (4),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *      cessationOfOperation    (5),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *      certificateHold         (6),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *      privilegeWithdrawn      (7),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *      aACompromise            (8) }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * GeneralNames ::= SEQUENCE SIZE (1..MAX) OF GeneralName
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * GeneralName ::= CHOICE {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *         otherName                   [0] INSTANCE OF OTHER-NAME,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *         rfc822Name                  [1] IA5String,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *         dNSName                     [2] IA5String,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *         x400Address                 [3] ORAddress,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 *         directoryName               [4] Name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *         ediPartyName                [5] EDIPartyName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 *         uniformResourceIdentifier   [6] IA5String,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 *         iPAddress                   [7] OCTET STRING,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 *         registeredID                [8] OBJECT IDENTIFIER }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * RelativeDistinguishedName ::=
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 *   SET OF AttributeTypeAndValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * AttributeTypeAndValue ::= SEQUENCE {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 *   type     AttributeType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 *   value    AttributeValue }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * AttributeType ::= OBJECT IDENTIFIER
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * AttributeValue ::= ANY DEFINED BY AttributeType
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * Instances of this class are designed to be immutable. However, since this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * is an internal API we do not use defensive cloning for values for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * performance reasons. It is the responsibility of the consumer to ensure
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * that no mutable elements are modified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * @author Anne Anderson
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * @author Andreas Sterbenz
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * @since 1.4.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * @see CRLDistributionPointsExtension
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
public class DistributionPoint {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    // reason flag bits
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    // NOTE that these are NOT quite the same as the CRL reason code extension
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 30649
diff changeset
   100
    public static final int KEY_COMPROMISE         = 1;
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 30649
diff changeset
   101
    public static final int CA_COMPROMISE          = 2;
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 30649
diff changeset
   102
    public static final int AFFILIATION_CHANGED    = 3;
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 30649
diff changeset
   103
    public static final int SUPERSEDED             = 4;
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 30649
diff changeset
   104
    public static final int CESSATION_OF_OPERATION = 5;
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 30649
diff changeset
   105
    public static final int CERTIFICATE_HOLD       = 6;
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 30649
diff changeset
   106
    public static final int PRIVILEGE_WITHDRAWN    = 7;
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 30649
diff changeset
   107
    public static final int AA_COMPROMISE          = 8;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    private static final String[] REASON_STRINGS = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        "key compromise",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        "CA compromise",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        "affiliation changed",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        "superseded",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        "cessation of operation",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        "certificate hold",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        "privilege withdrawn",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        "AA compromise",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    // context specific tag values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    private static final byte TAG_DIST_PT = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    private static final byte TAG_REASONS = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    private static final byte TAG_ISSUER = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    private static final byte TAG_FULL_NAME = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    private static final byte TAG_REL_NAME = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    // only one of fullName and relativeName can be set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    private GeneralNames fullName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    private RDN relativeName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    // reasonFlags or null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    private boolean[] reasonFlags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    // crlIssuer or null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    private GeneralNames crlIssuer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    // cached hashCode value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    private volatile int hashCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * Constructor for the class using GeneralNames for DistributionPointName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * @param fullName the GeneralNames of the distribution point; may be null
30374
2abaf49910ea 8079478: some docs cleanup for sun.security
avstepan
parents: 25859
diff changeset
   146
     * @param reasonFlags the CRL reasons included in the CRL at this distribution
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     *        point; may be null
30374
2abaf49910ea 8079478: some docs cleanup for sun.security
avstepan
parents: 25859
diff changeset
   148
     * @param crlIssuer the name(s) of the CRL issuer for the CRL at this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     *        distribution point; may be null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    public DistributionPoint(GeneralNames fullName, boolean[] reasonFlags,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            GeneralNames crlIssuer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        if ((fullName == null) && (crlIssuer == null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            throw new IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                        ("fullName and crlIssuer may not both be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        this.fullName = fullName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        this.reasonFlags = reasonFlags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        this.crlIssuer = crlIssuer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * Constructor for the class using RelativeDistinguishedName for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * DistributionPointName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * @param relativeName the RelativeDistinguishedName of the distribution
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     *        point; may not be null
30374
2abaf49910ea 8079478: some docs cleanup for sun.security
avstepan
parents: 25859
diff changeset
   168
     * @param reasonFlags the CRL reasons included in the CRL at this distribution
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     *        point; may be null
30374
2abaf49910ea 8079478: some docs cleanup for sun.security
avstepan
parents: 25859
diff changeset
   170
     * @param crlIssuer the name(s) of the CRL issuer for the CRL at this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     *        distribution point; may not be null or empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    public DistributionPoint(RDN relativeName, boolean[] reasonFlags,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            GeneralNames crlIssuer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        if ((relativeName == null) && (crlIssuer == null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            throw new IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                        ("relativeName and crlIssuer may not both be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        this.relativeName = relativeName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        this.reasonFlags = reasonFlags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        this.crlIssuer = crlIssuer;
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
     * Create the object from the passed DER encoded form.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * @param val the DER encoded form of the DistributionPoint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * @throws IOException on error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    public DistributionPoint(DerValue val) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        if (val.tag != DerValue.tag_Sequence) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            throw new IOException("Invalid encoding of DistributionPoint.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        // Note that all the fields in DistributionPoint are defined as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        // being OPTIONAL, i.e., there could be an empty SEQUENCE, resulting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        // in val.data being null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        while ((val.data != null) && (val.data.available() != 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            DerValue opt = val.data.getDerValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            if (opt.isContextSpecific(TAG_DIST_PT) && opt.isConstructed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                if ((fullName != null) || (relativeName != null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                    throw new IOException("Duplicate DistributionPointName in "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                                          + "DistributionPoint.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                DerValue distPnt = opt.data.getDerValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                if (distPnt.isContextSpecific(TAG_FULL_NAME)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                        && distPnt.isConstructed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                    distPnt.resetTag(DerValue.tag_Sequence);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                    fullName = new GeneralNames(distPnt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                } else if (distPnt.isContextSpecific(TAG_REL_NAME)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                        && distPnt.isConstructed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                    distPnt.resetTag(DerValue.tag_Set);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                    relativeName = new RDN(distPnt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                    throw new IOException("Invalid DistributionPointName in "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                                          + "DistributionPoint");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            } else if (opt.isContextSpecific(TAG_REASONS)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                                                && !opt.isConstructed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                if (reasonFlags != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                    throw new IOException("Duplicate Reasons in " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                                          "DistributionPoint.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                opt.resetTag(DerValue.tag_BitString);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                reasonFlags = (opt.getUnalignedBitString()).toBooleanArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            } else if (opt.isContextSpecific(TAG_ISSUER)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                                                && opt.isConstructed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                if (crlIssuer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                    throw new IOException("Duplicate CRLIssuer in " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                                          "DistributionPoint.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                opt.resetTag(DerValue.tag_Sequence);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                crlIssuer = new GeneralNames(opt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                throw new IOException("Invalid encoding of " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                                      "DistributionPoint.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        if ((crlIssuer == null) && (fullName == null) && (relativeName == null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            throw new IOException("One of fullName, relativeName, "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                + " and crlIssuer has to be set");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * Return the full distribution point name or null if not set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    public GeneralNames getFullName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        return fullName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * Return the relative distribution point name or null if not set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    public RDN getRelativeName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        return relativeName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * Return the reason flags or null if not set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    public boolean[] getReasonFlags() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        return reasonFlags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * Return the CRL issuer name or null if not set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    public GeneralNames getCRLIssuer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        return crlIssuer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * Write the DistributionPoint value to the DerOutputStream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * @param out the DerOutputStream to write the extension to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * @exception IOException on error.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    public void encode(DerOutputStream out) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        DerOutputStream tagged = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        // NOTE: only one of pointNames and pointRDN can be set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        if ((fullName != null) || (relativeName != null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            DerOutputStream distributionPoint = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            if (fullName != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                DerOutputStream derOut = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                fullName.encode(derOut);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                distributionPoint.writeImplicit(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                    DerValue.createTag(DerValue.TAG_CONTEXT, true, TAG_FULL_NAME),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                    derOut);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            } else if (relativeName != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                DerOutputStream derOut = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                relativeName.encode(derOut);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                distributionPoint.writeImplicit(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                    DerValue.createTag(DerValue.TAG_CONTEXT, true, TAG_REL_NAME),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                    derOut);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            tagged.write(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                DerValue.createTag(DerValue.TAG_CONTEXT, true, TAG_DIST_PT),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                distributionPoint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        if (reasonFlags != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            DerOutputStream reasons = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            BitArray rf = new BitArray(reasonFlags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            reasons.putTruncatedUnalignedBitString(rf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            tagged.writeImplicit(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                DerValue.createTag(DerValue.TAG_CONTEXT, false, TAG_REASONS),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                reasons);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        if (crlIssuer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            DerOutputStream issuer = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            crlIssuer.encode(issuer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            tagged.writeImplicit(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                DerValue.createTag(DerValue.TAG_CONTEXT, true, TAG_ISSUER),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                issuer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        out.write(DerValue.tag_Sequence, tagged);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * Compare an object to this DistributionPoint for equality.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * @param obj Object to be compared to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * @return true if objects match; false otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        if (this == obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        if (obj instanceof DistributionPoint == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        DistributionPoint other = (DistributionPoint)obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
10051
b96a8c7fefef 7041252: Use j.u.Objects.equals in security classes
darcy
parents: 5506
diff changeset
   336
        boolean equal = Objects.equals(this.fullName, other.fullName)
b96a8c7fefef 7041252: Use j.u.Objects.equals in security classes
darcy
parents: 5506
diff changeset
   337
                     && Objects.equals(this.relativeName, other.relativeName)
b96a8c7fefef 7041252: Use j.u.Objects.equals in security classes
darcy
parents: 5506
diff changeset
   338
                     && Objects.equals(this.crlIssuer, other.crlIssuer)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                     && Arrays.equals(this.reasonFlags, other.reasonFlags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        return equal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        int hash = hashCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        if (hash == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            hash = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            if (fullName != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                hash += fullName.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            if (relativeName != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                hash += relativeName.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            if (crlIssuer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                hash += crlIssuer.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            if (reasonFlags != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                for (int i = 0; i < reasonFlags.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                    if (reasonFlags[i]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                        hash += i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            hashCode = hash;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        return hash;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * Return a string representation for reasonFlag bit 'reason'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    private static String reasonToString(int reason) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        if ((reason > 0) && (reason < REASON_STRINGS.length)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            return REASON_STRINGS[reason];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        return "Unknown reason " + reason;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * Return a printable string of the Distribution Point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        StringBuilder sb = new StringBuilder();
30649
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   383
        sb.append("DistributionPoint:\n     ");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        if (fullName != null) {
30649
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   385
            sb.append(fullName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        if (relativeName != null) {
30649
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   388
            sb.append(relativeName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        }
30649
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   390
        sb.append('\n');
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        if (reasonFlags != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            sb.append("   ReasonFlags:\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            for (int i = 0; i < reasonFlags.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                if (reasonFlags[i]) {
30649
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   396
                    sb.append("    ")
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   397
                        .append(reasonToString(i))
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   398
                        .append('\n');
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        if (crlIssuer != null) {
30649
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   403
            sb.append("   CRLIssuer:")
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   404
                .append(crlIssuer)
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   405
                .append('\n');
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        return sb.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
}