src/java.base/share/classes/sun/security/x509/DNSName.java
author igerasim
Tue, 02 Oct 2018 10:19:07 -0700
changeset 51986 c1db377f6300
parent 47413 17b77ca4d419
child 52856 5f3b9b633731
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
/*
47413
17b77ca4d419 8178714: PKIX validator nameConstraints check failing after change 8175940
weijun
parents: 47410
diff changeset
     2
 * Copyright (c) 1997, 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;
6122
16fa7ed7ff1b 6867345: Turkish regional options cause NPE in sun.security.x509.AlgorithmId.algOID
xuelei
parents: 5506
diff changeset
    29
import java.util.Locale;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import sun.security.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * This class implements the DNSName as required by the GeneralNames
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * ASN.1 object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * [RFC2459] When the subjectAltName extension contains a domain name service
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * label, the domain name MUST be stored in the dNSName (an IA5String).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * The name MUST be in the "preferred name syntax," as specified by RFC
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * 1034 [RFC 1034]. Note that while upper and lower case letters are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * allowed in domain names, no signifigance is attached to the case.  In
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * addition, while the string " " is a legal domain name, subjectAltName
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * extensions with a dNSName " " are not permitted.  Finally, the use of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * the DNS representation for Internet mail addresses (wpolk.nist.gov
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * instead of wpolk@nist.gov) is not permitted; such identities are to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * be encoded as rfc822Name.
30374
2abaf49910ea 8079478: some docs cleanup for sun.security
avstepan
parents: 25859
diff changeset
    47
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * @author Amit Kapoor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * @author Hemma Prafullchandra
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
public class DNSName implements GeneralNameInterface {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    private String name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    private static final String alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    private static final String digitsAndHyphen = "0123456789-";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private static final String alphaDigitsAndHyphen = alpha + digitsAndHyphen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * Create the DNSName object from the passed encoded Der value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * @param derValue the encoded DER DNSName.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * @exception IOException on error.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    public DNSName(DerValue derValue) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        name = derValue.getIA5String();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * Create the DNSName object with the specified name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * @param name the DNSName.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * @throws IOException if the name is not a valid DNSName subjectAltName
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    public DNSName(String name) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        if (name == null || name.length() == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            throw new IOException("DNS name must not be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        if (name.indexOf(' ') != -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            throw new IOException("DNS names or NameConstraints with blank components are not permitted");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        if (name.charAt(0) == '.' || name.charAt(name.length() -1) == '.')
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            throw new IOException("DNS names or NameConstraints may not begin or end with a .");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        //Name will consist of label components separated by "."
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        //startIndex is the index of the first character of a component
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        //endIndex is the index of the last character of a component plus 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        for (int endIndex,startIndex=0; startIndex < name.length(); startIndex = endIndex+1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            endIndex = name.indexOf('.', startIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            if (endIndex < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                endIndex = name.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            if ((endIndex-startIndex) < 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                throw new IOException("DNSName SubjectAltNames with empty components are not permitted");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            //DNSName components must begin with a letter A-Z or a-z
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            if (alpha.indexOf(name.charAt(startIndex)) < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                throw new IOException("DNSName components must begin with a letter");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            //nonStartIndex: index for characters in the component beyond the first one
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            for (int nonStartIndex=startIndex+1; nonStartIndex < endIndex; nonStartIndex++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                char x = name.charAt(nonStartIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                if ((alphaDigitsAndHyphen).indexOf(x) < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                    throw new IOException("DNSName components must consist of letters, digits, and hyphens");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        this.name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * Return the type of the GeneralName.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    public int getType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        return (GeneralNameInterface.NAME_DNS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * Return the actual name value of the GeneralName.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    public String getName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * Encode the DNS name into the DerOutputStream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * @param out the DER stream to encode the DNSName to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * @exception IOException on encoding errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    public void encode(DerOutputStream out) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        out.putIA5String(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * Convert the name into user readable string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        return ("DNSName: " + name);
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
     * Compares this name with another, for equality.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * @return true iff the names are equivalent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * according to RFC2459.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        if (this == obj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        if (!(obj instanceof DNSName))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        DNSName other = (DNSName)obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        // RFC2459 mandates that these names are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        // not case-sensitive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        return name.equalsIgnoreCase(other.name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * Returns the hash code value for this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * @return a hash code value for this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    public int hashCode() {
10369
e9d2e59e53f0 7059542: JNDI name operations should be locale independent
xuelei
parents: 6122
diff changeset
   162
        return name.toUpperCase(Locale.ENGLISH).hashCode();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * Return type of constraint inputName places on this name:<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     *   <li>NAME_DIFF_TYPE = -1: input name is different type from name (i.e. does not constrain).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     *   <li>NAME_MATCH = 0: input name matches name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     *   <li>NAME_NARROWS = 1: input name narrows name (is lower in the naming subtree)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     *   <li>NAME_WIDENS = 2: input name widens name (is higher in the naming subtree)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     *   <li>NAME_SAME_TYPE = 3: input name does not match or narrow name, but is same type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * </ul>.  These results are used in checking NameConstraints during
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * certification path verification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * RFC2459: DNS name restrictions are expressed as foo.bar.com. Any subdomain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * satisfies the name constraint. For example, www.foo.bar.com would
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * satisfy the constraint but bigfoo.bar.com would not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * draft-ietf-pkix-new-part1-00.txt:  DNS name restrictions are expressed as foo.bar.com.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * Any DNS name that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * can be constructed by simply adding to the left hand side of the name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * satisfies the name constraint. For example, www.foo.bar.com would
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * satisfy the constraint but foo1.bar.com would not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * RFC1034: By convention, domain names can be stored with arbitrary case, but
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * domain name comparisons for all present domain functions are done in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * case-insensitive manner, assuming an ASCII character set, and a high
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * order zero bit.
30374
2abaf49910ea 8079478: some docs cleanup for sun.security
avstepan
parents: 25859
diff changeset
   189
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * @param inputName to be checked for being constrained
30374
2abaf49910ea 8079478: some docs cleanup for sun.security
avstepan
parents: 25859
diff changeset
   191
     * @return constraint type above
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * @throws UnsupportedOperationException if name is not exact match, but narrowing and widening are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     *          not supported for this name type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    public int constrains(GeneralNameInterface inputName) throws UnsupportedOperationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        int constraintType;
47413
17b77ca4d419 8178714: PKIX validator nameConstraints check failing after change 8175940
weijun
parents: 47410
diff changeset
   197
        if (inputName == null)
17b77ca4d419 8178714: PKIX validator nameConstraints check failing after change 8175940
weijun
parents: 47410
diff changeset
   198
            constraintType = NAME_DIFF_TYPE;
17b77ca4d419 8178714: PKIX validator nameConstraints check failing after change 8175940
weijun
parents: 47410
diff changeset
   199
        else if (inputName.getType() != NAME_DNS)
17b77ca4d419 8178714: PKIX validator nameConstraints check failing after change 8175940
weijun
parents: 47410
diff changeset
   200
            constraintType = NAME_DIFF_TYPE;
17b77ca4d419 8178714: PKIX validator nameConstraints check failing after change 8175940
weijun
parents: 47410
diff changeset
   201
        else {
17b77ca4d419 8178714: PKIX validator nameConstraints check failing after change 8175940
weijun
parents: 47410
diff changeset
   202
            String inName =
17b77ca4d419 8178714: PKIX validator nameConstraints check failing after change 8175940
weijun
parents: 47410
diff changeset
   203
                (((DNSName)inputName).getName()).toLowerCase(Locale.ENGLISH);
17b77ca4d419 8178714: PKIX validator nameConstraints check failing after change 8175940
weijun
parents: 47410
diff changeset
   204
            String thisName = name.toLowerCase(Locale.ENGLISH);
17b77ca4d419 8178714: PKIX validator nameConstraints check failing after change 8175940
weijun
parents: 47410
diff changeset
   205
            if (inName.equals(thisName))
17b77ca4d419 8178714: PKIX validator nameConstraints check failing after change 8175940
weijun
parents: 47410
diff changeset
   206
                constraintType = NAME_MATCH;
17b77ca4d419 8178714: PKIX validator nameConstraints check failing after change 8175940
weijun
parents: 47410
diff changeset
   207
            else if (thisName.endsWith(inName)) {
17b77ca4d419 8178714: PKIX validator nameConstraints check failing after change 8175940
weijun
parents: 47410
diff changeset
   208
                int inNdx = thisName.lastIndexOf(inName);
17b77ca4d419 8178714: PKIX validator nameConstraints check failing after change 8175940
weijun
parents: 47410
diff changeset
   209
                if (thisName.charAt(inNdx-1) == '.' )
17b77ca4d419 8178714: PKIX validator nameConstraints check failing after change 8175940
weijun
parents: 47410
diff changeset
   210
                    constraintType = NAME_WIDENS;
17b77ca4d419 8178714: PKIX validator nameConstraints check failing after change 8175940
weijun
parents: 47410
diff changeset
   211
                else
17b77ca4d419 8178714: PKIX validator nameConstraints check failing after change 8175940
weijun
parents: 47410
diff changeset
   212
                    constraintType = NAME_SAME_TYPE;
17b77ca4d419 8178714: PKIX validator nameConstraints check failing after change 8175940
weijun
parents: 47410
diff changeset
   213
            } else if (inName.endsWith(thisName)) {
17b77ca4d419 8178714: PKIX validator nameConstraints check failing after change 8175940
weijun
parents: 47410
diff changeset
   214
                int ndx = inName.lastIndexOf(thisName);
17b77ca4d419 8178714: PKIX validator nameConstraints check failing after change 8175940
weijun
parents: 47410
diff changeset
   215
                if (inName.charAt(ndx-1) == '.' )
17b77ca4d419 8178714: PKIX validator nameConstraints check failing after change 8175940
weijun
parents: 47410
diff changeset
   216
                    constraintType = NAME_NARROWS;
17b77ca4d419 8178714: PKIX validator nameConstraints check failing after change 8175940
weijun
parents: 47410
diff changeset
   217
                else
17b77ca4d419 8178714: PKIX validator nameConstraints check failing after change 8175940
weijun
parents: 47410
diff changeset
   218
                    constraintType = NAME_SAME_TYPE;
17b77ca4d419 8178714: PKIX validator nameConstraints check failing after change 8175940
weijun
parents: 47410
diff changeset
   219
            } else {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                constraintType = NAME_SAME_TYPE;
47413
17b77ca4d419 8178714: PKIX validator nameConstraints check failing after change 8175940
weijun
parents: 47410
diff changeset
   221
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        return constraintType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * Return subtree depth of this name for purposes of determining
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * NameConstraints minimum and maximum bounds and for calculating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * path lengths in name subtrees.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     *
30374
2abaf49910ea 8079478: some docs cleanup for sun.security
avstepan
parents: 25859
diff changeset
   231
     * @return distance of name from root
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * @throws UnsupportedOperationException if not supported for this name type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    public int subtreeDepth() throws UnsupportedOperationException {
35283
c5082624b79f 8074068: Cleanup in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   235
        // subtree depth is always at least 1
c5082624b79f 8074068: Cleanup in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   236
        int sum = 1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
35283
c5082624b79f 8074068: Cleanup in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   238
        // count dots
c5082624b79f 8074068: Cleanup in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   239
        for (int i = name.indexOf('.'); i >= 0; i = name.indexOf('.', i + 1)) {
c5082624b79f 8074068: Cleanup in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   240
            ++sum;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
35283
c5082624b79f 8074068: Cleanup in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   243
        return sum;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
}