src/java.base/share/classes/sun/security/x509/AVA.java
author igerasim
Tue, 02 Oct 2018 10:19:07 -0700
changeset 51986 c1db377f6300
parent 51398 3c389a284345
child 53018 8bf9268df0e2
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
/*
51398
3c389a284345 8209416: Refactoring GetPropertyAction calls in security libs
weijun
parents: 47216
diff changeset
     2
 * Copyright (c) 1996, 2018, 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: 715
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: 715
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: 715
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
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.ByteArrayOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.OutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.Reader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.text.Normalizer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import sun.security.action.GetBooleanAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import sun.security.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import sun.security.pkcs.PKCS9Attribute;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * X.500 Attribute-Value-Assertion (AVA):  an attribute, as identified by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * some attribute ID, has some particular value.  Values are as a rule ASN.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * printable strings.  A conventional set of type IDs is recognized when
10370
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents: 10336
diff changeset
    45
 * parsing (and generating) RFC 1779, 2253 or 4514 syntax strings.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * <P>AVAs are components of X.500 relative names.  Think of them as being
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * individual fields of a database record.  The attribute ID is how you
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * identify the field, and the value is part of a particular record.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * Note that instances of this class are immutable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * @see X500Name
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * @see RDN
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * @author David Brownell
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * @author Amit Kapoor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * @author Hemma Prafullchandra
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
public class AVA implements DerEncoder {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    private static final Debug debug = Debug.getInstance("x509", "\t[AVA]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    // See CR 6391482: if enabled this flag preserves the old but incorrect
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    // PrintableString encoding for DomainComponent. It may need to be set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    // avoid breaking preexisting certificates generated with sun.security APIs.
51398
3c389a284345 8209416: Refactoring GetPropertyAction calls in security libs
weijun
parents: 47216
diff changeset
    67
    private static final boolean PRESERVE_OLD_DC_ENCODING = GetBooleanAction
3c389a284345 8209416: Refactoring GetPropertyAction calls in security libs
weijun
parents: 47216
diff changeset
    68
            .privilegedGetProperty("com.sun.security.preserveOldDCEncoding");
2
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 format allows both RFC1779 and RFC2253 syntax and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * additional keywords.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 31538
diff changeset
    74
    static final int DEFAULT = 1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * RFC1779 specifies format according to RFC1779.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 31538
diff changeset
    78
    static final int RFC1779 = 2;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * RFC2253 specifies format according to RFC2253.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 31538
diff changeset
    82
    static final int RFC2253 = 3;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    // currently not private, accessed directly from RDN
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    final ObjectIdentifier oid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    final DerValue value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * If the value has any of these characters in it, it must be quoted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * Backslash and quote characters must also be individually escaped.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * Leading and trailing spaces, also multiple internal spaces, also
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * call for quoting the whole string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     */
10370
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents: 10336
diff changeset
    94
    private static final String specialChars1779 = ",=\n+<>#;\\\"";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * In RFC2253, if the value has any of these characters in it, it
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * must be quoted by a preceding \.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     */
10370
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents: 10336
diff changeset
   100
    private static final String specialChars2253 = ",=+<>#;\\\"";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    /*
10370
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents: 10336
diff changeset
   103
     * includes special chars from RFC1779 and RFC2253, as well as ' ' from
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents: 10336
diff changeset
   104
     * RFC 4514.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     */
10370
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents: 10336
diff changeset
   106
    private static final String specialCharsDefault = ",=\n+<>#;\\\" ";
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents: 10336
diff changeset
   107
    private static final String escapedDefault = ",+<>;\"";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * Values that aren't printable strings are emitted as BER-encoded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * hex data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    private static final String hexDigits = "0123456789ABCDEF";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    public AVA(ObjectIdentifier type, DerValue val) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        if ((type == null) || (val == null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        oid = type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        value = val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    /**
10370
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents: 10336
diff changeset
   124
     * Parse an RFC 1779, 2253 or 4514 style AVA string:  CN=fee fie foe fum
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * or perhaps with quotes.  Not all defined AVA tags are supported;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * of current note are X.400 related ones (PRMD, ADMD, etc).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * This terminates at unescaped AVA separators ("+") or RDN
10370
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents: 10336
diff changeset
   129
     * separators (",", ";"), and removes cosmetic whitespace at the end of
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents: 10336
diff changeset
   130
     * values.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    AVA(Reader in) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        this(in, DEFAULT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    /**
10370
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents: 10336
diff changeset
   137
     * Parse an RFC 1779, 2253 or 4514 style AVA string:  CN=fee fie foe fum
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * or perhaps with quotes. Additional keywords can be specified in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * keyword/OID map.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * This terminates at unescaped AVA separators ("+") or RDN
10370
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents: 10336
diff changeset
   142
     * separators (",", ";"), and removes cosmetic whitespace at the end of
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents: 10336
diff changeset
   143
     * values.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    AVA(Reader in, Map<String, String> keywordMap) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        this(in, DEFAULT, keywordMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * Parse an AVA string formatted according to format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    AVA(Reader in, int format) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        this(in, format, Collections.<String, String>emptyMap());
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
     * Parse an AVA string formatted according to format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * @param in Reader containing AVA String
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * @param format parsing format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * @param keywordMap a Map where a keyword String maps to a corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     *   OID String. Each AVA keyword will be mapped to the corresponding OID.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     *   If an entry does not exist, it will fallback to the builtin
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     *   keyword/OID mapping.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * @throws IOException if the AVA String is not valid in the specified
10370
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents: 10336
diff changeset
   166
     *   format or an OID String from the keywordMap is improperly formatted
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    AVA(Reader in, int format, Map<String, String> keywordMap)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        throws IOException {
10370
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents: 10336
diff changeset
   170
        // assume format is one of DEFAULT or RFC2253
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        StringBuilder   temp = new StringBuilder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        int             c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
         * First get the keyword indicating the attribute's type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
         * and map it to the appropriate OID.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            c = readChar(in, "Incorrect AVA format");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            if (c == '=') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            temp.append((char)c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        oid = AVAKeyword.getOID(temp.toString(), format, keywordMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
         * Now parse the value.  "#hex", a quoted string, or a string
10370
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents: 10336
diff changeset
   191
         * terminated by "+", ",", ";".  Whitespace before or after
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
         * the value is stripped away unless format is RFC2253.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        temp.setLength(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        if (format == RFC2253) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            // read next character
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            c = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            if (c == ' ') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                throw new IOException("Incorrect AVA RFC2253 format - " +
10370
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents: 10336
diff changeset
   200
                                      "leading space must be escaped");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            // read next character skipping whitespace
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                c = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            } while ((c == ' ') || (c == '\n'));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        if (c == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            // empty value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            value = new DerValue("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        if (c == '#') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            value = parseHexString(in, format);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        } else if ((c == '"') && (format != RFC2253)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            value = parseQuotedString(in, temp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            value = parseString(in, c, format, temp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        }
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
     * Get the ObjectIdentifier of this AVA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    public ObjectIdentifier getObjectIdentifier() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        return oid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * Get the value of this AVA as a DerValue.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    public DerValue getDerValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * Get the value of this AVA as a String.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * @exception RuntimeException if we could not obtain the string form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     *    (should not occur)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    public String getValueString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            String s = value.getAsString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            if (s == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                throw new RuntimeException("AVA string is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            return s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            // should not occur
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            throw new RuntimeException("AVA error: " + e, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    private static DerValue parseHexString
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        (Reader in, int format) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        int c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        byte b = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        int cNdx = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            c = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            if (isTerminator(c, format)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            int cVal = hexDigits.indexOf(Character.toUpperCase((char)c));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            if (cVal == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                throw new IOException("AVA parse, invalid hex " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                                              "digit: "+ (char)c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            if ((cNdx % 2) == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                b = (byte)((b * 16) + (byte)(cVal));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                baos.write(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                b = (byte)(cVal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            cNdx++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        // throw exception if no hex digits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        if (cNdx == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            throw new IOException("AVA parse, zero hex digits");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        // throw exception if odd number of hex digits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        if (cNdx % 2 == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            throw new IOException("AVA parse, odd number of hex digits");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        return new DerValue(baos.toByteArray());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    private DerValue parseQuotedString
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        (Reader in, StringBuilder temp) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        // RFC1779 specifies that an entire RDN may be enclosed in double
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        // quotes. In this case the syntax is any sequence of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        // backslash-specialChar, backslash-backslash,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        // backslash-doublequote, or character other than backslash or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        // doublequote.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        int c = readChar(in, "Quoted string did not end in quote");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
30033
b9c86c17164a 8078468: Update security libraries to use diamond with anonymous classes
darcy
parents: 25859
diff changeset
   309
        List<Byte> embeddedHex = new ArrayList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        boolean isPrintableString = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        while (c != '"') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            if (c == '\\') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                c = readChar(in, "Quoted string did not end in quote");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                // check for embedded hex pairs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                Byte hexByte = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                if ((hexByte = getEmbeddedHexPair(c, in)) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                    // always encode AVAs with embedded hex as UTF8
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                    isPrintableString = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                    // append consecutive embedded hex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                    // as single string later
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                    embeddedHex.add(hexByte);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                    c = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
10370
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents: 10336
diff changeset
   329
                if (specialChars1779.indexOf((char)c) < 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                    throw new IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                        ("Invalid escaped character in AVA: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                        (char)c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            // add embedded hex bytes before next char
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            if (embeddedHex.size() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                String hexString = getEmbeddedHexString(embeddedHex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                temp.append(hexString);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                embeddedHex.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            // check for non-PrintableString chars
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            isPrintableString &= DerValue.isPrintableStringChar((char)c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            temp.append((char)c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            c = readChar(in, "Quoted string did not end in quote");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        // add trailing embedded hex bytes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        if (embeddedHex.size() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            String hexString = getEmbeddedHexString(embeddedHex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            temp.append(hexString);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            embeddedHex.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            c = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        } while ((c == '\n') || (c == ' '));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        if (c != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            throw new IOException("AVA had characters other than "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                    + "whitespace after terminating quote");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        // encode as PrintableString unless value contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        // non-PrintableString chars
31426
9cd672654f97 8022444: Remove sun.security.util.ObjectIdentifier.equals(ObjectIdentifier other) method
juh
parents: 30649
diff changeset
   366
        if (this.oid.equals(PKCS9Attribute.EMAIL_ADDRESS_OID) ||
9cd672654f97 8022444: Remove sun.security.util.ObjectIdentifier.equals(ObjectIdentifier other) method
juh
parents: 30649
diff changeset
   367
            (this.oid.equals(X500Name.DOMAIN_COMPONENT_OID) &&
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                PRESERVE_OLD_DC_ENCODING == false)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            // EmailAddress and DomainComponent must be IA5String
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            return new DerValue(DerValue.tag_IA5String,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                                        temp.toString().trim());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        } else if (isPrintableString) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            return new DerValue(temp.toString().trim());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            return new DerValue(DerValue.tag_UTF8String,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                                        temp.toString().trim());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    private DerValue parseString
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        (Reader in, int c, int format, StringBuilder temp) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
10370
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents: 10336
diff changeset
   383
        List<Byte> embeddedHex = new ArrayList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        boolean isPrintableString = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        boolean escape = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        boolean leadingChar = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        int spaceCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            escape = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            if (c == '\\') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                escape = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                c = readChar(in, "Invalid trailing backslash");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                // check for embedded hex pairs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                Byte hexByte = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                if ((hexByte = getEmbeddedHexPair(c, in)) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                    // always encode AVAs with embedded hex as UTF8
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                    isPrintableString = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                    // append consecutive embedded hex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                    // as single string later
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                    embeddedHex.add(hexByte);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                    c = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                    leadingChar = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
                // check if character was improperly escaped
10370
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents: 10336
diff changeset
   410
                if (format == DEFAULT &&
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents: 10336
diff changeset
   411
                       specialCharsDefault.indexOf((char)c) == -1) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                    throw new IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                        ("Invalid escaped character in AVA: '" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                        (char)c + "'");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                } else if (format == RFC2253) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                    if (c == ' ') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                        // only leading/trailing space can be escaped
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                        if (!leadingChar && !trailingSpace(in)) {
10370
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents: 10336
diff changeset
   419
                            throw new IOException
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents: 10336
diff changeset
   420
                                    ("Invalid escaped space character " +
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents: 10336
diff changeset
   421
                                    "in AVA.  Only a leading or trailing " +
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents: 10336
diff changeset
   422
                                    "space character can be escaped.");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                    } else if (c == '#') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                        // only leading '#' can be escaped
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                        if (!leadingChar) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                            throw new IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                                ("Invalid escaped '#' character in AVA.  " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                                "Only a leading '#' can be escaped.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                    } else if (specialChars2253.indexOf((char)c) == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                        throw new IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                                ("Invalid escaped character in AVA: '" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                                (char)c + "'");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                // check if character should have been escaped
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                if (format == RFC2253) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                    if (specialChars2253.indexOf((char)c) != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                        throw new IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                                ("Character '" + (char)c +
10370
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents: 10336
diff changeset
   443
                                 "' in AVA appears without escape");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                    }
10370
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents: 10336
diff changeset
   445
                } else if (escapedDefault.indexOf((char)c) != -1) {
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents: 10336
diff changeset
   446
                    throw new IOException
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents: 10336
diff changeset
   447
                            ("Character '" + (char)c +
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents: 10336
diff changeset
   448
                            "' in AVA appears without escape");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            // add embedded hex bytes before next char
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            if (embeddedHex.size() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                // add space(s) before embedded hex bytes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                for (int i = 0; i < spaceCount; i++) {
30649
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30033
diff changeset
   456
                    temp.append(' ');
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                spaceCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                String hexString = getEmbeddedHexString(embeddedHex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                temp.append(hexString);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                embeddedHex.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            // check for non-PrintableString chars
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
            isPrintableString &= DerValue.isPrintableStringChar((char)c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            if (c == ' ' && escape == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                // do not add non-escaped spaces yet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                // (non-escaped trailing spaces are ignored)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                spaceCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                // add space(s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                for (int i = 0; i < spaceCount; i++) {
30649
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30033
diff changeset
   474
                    temp.append(' ');
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                spaceCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                temp.append((char)c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            c = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            leadingChar = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        } while (isTerminator(c, format) == false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        if (format == RFC2253 && spaceCount > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            throw new IOException("Incorrect AVA RFC2253 format - " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                                        "trailing space must be escaped");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        // add trailing embedded hex bytes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        if (embeddedHex.size() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            String hexString = getEmbeddedHexString(embeddedHex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            temp.append(hexString);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            embeddedHex.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        // encode as PrintableString unless value contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        // non-PrintableString chars
31426
9cd672654f97 8022444: Remove sun.security.util.ObjectIdentifier.equals(ObjectIdentifier other) method
juh
parents: 30649
diff changeset
   497
        if (this.oid.equals(PKCS9Attribute.EMAIL_ADDRESS_OID) ||
9cd672654f97 8022444: Remove sun.security.util.ObjectIdentifier.equals(ObjectIdentifier other) method
juh
parents: 30649
diff changeset
   498
            (this.oid.equals(X500Name.DOMAIN_COMPONENT_OID) &&
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                PRESERVE_OLD_DC_ENCODING == false)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            // EmailAddress and DomainComponent must be IA5String
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
            return new DerValue(DerValue.tag_IA5String, temp.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        } else if (isPrintableString) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
            return new DerValue(temp.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
            return new DerValue(DerValue.tag_UTF8String, temp.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    private static Byte getEmbeddedHexPair(int c1, Reader in)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        if (hexDigits.indexOf(Character.toUpperCase((char)c1)) >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            int c2 = readChar(in, "unexpected EOF - " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                        "escaped hex value must include two valid digits");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
            if (hexDigits.indexOf(Character.toUpperCase((char)c2)) >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                int hi = Character.digit((char)c1, 16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                int lo = Character.digit((char)c2, 16);
25187
08aff438def8 8048874: Replace uses of 'new Byte', 'new Short' and 'new Character' with appropriate alternative across core classes
prappo
parents: 10590
diff changeset
   519
                return (byte)((hi<<4) + lo);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                throw new IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                        ("escaped hex value must include two valid digits");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    private static String getEmbeddedHexString(List<Byte> hexList)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                                                throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        int n = hexList.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        byte[] hexBytes = new byte[n];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                hexBytes[i] = hexList.get(i).byteValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        return new String(hexBytes, "UTF8");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    private static boolean isTerminator(int ch, int format) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        switch (ch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        case -1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        case '+':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        case ',':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        case ';':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
            return format != RFC2253;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
    private static int readChar(Reader in, String errMsg) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        int c = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        if (c == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            throw new IOException(errMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        return c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
    private static boolean trailingSpace(Reader in) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        boolean trailing = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        if (!in.markSupported()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
            // oh well
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
            // make readAheadLimit huge -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
            // in practice, AVA was passed a StringReader from X500Name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
            // and StringReader ignores readAheadLimit anyways
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
            in.mark(9999);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
            while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                int nextChar = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
                if (nextChar == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                    trailing = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                } else if (nextChar == ' ') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                } else if (nextChar == '\\') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
                    int followingChar = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
                    if (followingChar != ' ') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
                        trailing = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                    trailing = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
            in.reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
            return trailing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
    AVA(DerValue derval) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        // Individual attribute value assertions are SEQUENCE of two values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        // That'd be a "struct" outside of ASN.1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        if (derval.tag != DerValue.tag_Sequence) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
            throw new IOException("AVA not a sequence");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        oid = X500Name.intern(derval.data.getOID());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        value = derval.data.getDerValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        if (derval.data.available() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
            throw new IOException("AVA, extra bytes = "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
                + derval.data.available());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
    AVA(DerInputStream in) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        this(in.getDerValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        if (this == obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        if (obj instanceof AVA == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        AVA other = (AVA)obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        return this.toRFC2253CanonicalString().equals
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
                                (other.toRFC2253CanonicalString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     * Returns a hashcode for this AVA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     * @return a hashcode for this AVA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        return toRFC2253CanonicalString().hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     * AVAs are encoded as a SEQUENCE of two elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
    public void encode(DerOutputStream out) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        derEncode(out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     * DER encode this object onto an output stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     * Implements the <code>DerEncoder</code> interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     * @param out
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     * the output stream on which to write the DER encoding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     * @exception IOException on encoding error.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
    public void derEncode(OutputStream out) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        DerOutputStream         tmp = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        DerOutputStream         tmp2 = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        tmp.putOID(oid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        value.encode(tmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        tmp2.write(DerValue.tag_Sequence, tmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        out.write(tmp2.toByteArray());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
    private String toKeyword(int format, Map<String, String> oidMap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        return AVAKeyword.getKeyword(oid, format, oidMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     * Returns a printable form of this attribute, using RFC 1779
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     * syntax for individual attribute/value assertions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
        return toKeywordValueString
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
            (toKeyword(DEFAULT, Collections.<String, String>emptyMap()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     * Returns a printable form of this attribute, using RFC 1779
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
     * syntax for individual attribute/value assertions. It only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
     * emits standardised keywords.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
    public String toRFC1779String() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
        return toRFC1779String(Collections.<String, String>emptyMap());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
     * Returns a printable form of this attribute, using RFC 1779
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
     * syntax for individual attribute/value assertions. It
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
     * emits standardised keywords, as well as keywords contained in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
     * OID/keyword map.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
    public String toRFC1779String(Map<String, String> oidMap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        return toKeywordValueString(toKeyword(RFC1779, oidMap));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
     * Returns a printable form of this attribute, using RFC 2253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
     * syntax for individual attribute/value assertions. It only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
     * emits standardised keywords.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
    public String toRFC2253String() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        return toRFC2253String(Collections.<String, String>emptyMap());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     * Returns a printable form of this attribute, using RFC 2253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
     * syntax for individual attribute/value assertions. It
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
     * emits standardised keywords, as well as keywords contained in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     * OID/keyword map.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
    public String toRFC2253String(Map<String, String> oidMap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
         * Section 2.3: The AttributeTypeAndValue is encoded as the string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
         * representation of the AttributeType, followed by an equals character
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
         * ('=' ASCII 61), followed by the string representation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
         * AttributeValue. The encoding of the AttributeValue is given in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
         * section 2.4.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        StringBuilder typeAndValue = new StringBuilder(100);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        typeAndValue.append(toKeyword(RFC2253, oidMap));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
        typeAndValue.append('=');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
         * Section 2.4: Converting an AttributeValue from ASN.1 to a String.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
         * If the AttributeValue is of a type which does not have a string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
         * representation defined for it, then it is simply encoded as an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
         * octothorpe character ('#' ASCII 35) followed by the hexadecimal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
         * representation of each of the bytes of the BER encoding of the X.500
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
         * AttributeValue.  This form SHOULD be used if the AttributeType is of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
         * the dotted-decimal form.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
        if ((typeAndValue.charAt(0) >= '0' && typeAndValue.charAt(0) <= '9') ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
            !isDerString(value, false))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
            byte[] data = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
                data = value.toByteArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
            } catch (IOException ie) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
                throw new IllegalArgumentException("DER Value conversion");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
            typeAndValue.append('#');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
            for (int j = 0; j < data.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
                byte b = data[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
                typeAndValue.append(Character.forDigit(0xF & (b >>> 4), 16));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
                typeAndValue.append(Character.forDigit(0xF & b, 16));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
             * 2.4 (cont): Otherwise, if the AttributeValue is of a type which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
             * has a string representation, the value is converted first to a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
             * UTF-8 string according to its syntax specification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
             * NOTE: this implementation only emits DirectoryStrings of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
             * types returned by isDerString().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
            String valStr = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
                valStr = new String(value.getDataBytes(), "UTF8");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
            } catch (IOException ie) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
                throw new IllegalArgumentException("DER Value conversion");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
             * 2.4 (cont): If the UTF-8 string does not have any of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
             * following characters which need escaping, then that string can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
             * used as the string representation of the value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
             *   o   a space or "#" character occurring at the beginning of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
             *       string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
             *   o   a space character occurring at the end of the string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
             *   o   one of the characters ",", "+", """, "\", "<", ">" or ";"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
             * Implementations MAY escape other characters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
             * NOTE: this implementation also recognizes "=" and "#" as
95
aa9ad05818b0 6611991: Add support for parsing RFC4514 DNs to X500Principal
mullan
parents: 2
diff changeset
   773
             * characters which need escaping, and null which is escaped as
aa9ad05818b0 6611991: Add support for parsing RFC4514 DNs to X500Principal
mullan
parents: 2
diff changeset
   774
             * '\00' (see RFC 4514).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
             * If a character to be escaped is one of the list shown above, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
             * it is prefixed by a backslash ('\' ASCII 92).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
             * Otherwise the character to be escaped is replaced by a backslash
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
             * and two hex digits, which form a single byte in the code of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
             * character.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
            final String escapees = ",=+<>#;\"\\";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
            StringBuilder sbuffer = new StringBuilder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
            for (int i = 0; i < valStr.length(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
                char c = valStr.charAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
                if (DerValue.isPrintableStringChar(c) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
                    escapees.indexOf(c) >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
                    // escape escapees
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
                    if (escapees.indexOf(c) >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
                        sbuffer.append('\\');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
                    // append printable/escaped char
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
                    sbuffer.append(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
95
aa9ad05818b0 6611991: Add support for parsing RFC4514 DNs to X500Principal
mullan
parents: 2
diff changeset
   799
                } else if (c == '\u0000') {
aa9ad05818b0 6611991: Add support for parsing RFC4514 DNs to X500Principal
mullan
parents: 2
diff changeset
   800
                    // escape null character
aa9ad05818b0 6611991: Add support for parsing RFC4514 DNs to X500Principal
mullan
parents: 2
diff changeset
   801
                    sbuffer.append("\\00");
aa9ad05818b0 6611991: Add support for parsing RFC4514 DNs to X500Principal
mullan
parents: 2
diff changeset
   802
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
                } else if (debug != null && Debug.isOn("ava")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
                    // embed non-printable/non-escaped char
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
                    // as escaped hex pairs for debugging
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
                    byte[] valueBytes = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
                        valueBytes = Character.toString(c).getBytes("UTF8");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
                    } catch (IOException ie) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
                        throw new IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
                                        ("DER Value conversion");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
                    for (int j = 0; j < valueBytes.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
                        sbuffer.append('\\');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
                        char hexChar = Character.forDigit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
                                (0xF & (valueBytes[j] >>> 4), 16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
                        sbuffer.append(Character.toUpperCase(hexChar));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
                        hexChar = Character.forDigit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
                                (0xF & (valueBytes[j]), 16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
                        sbuffer.append(Character.toUpperCase(hexChar));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
                    // append non-printable/non-escaped char
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
                    sbuffer.append(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
            char[] chars = sbuffer.toString().toCharArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
            sbuffer = new StringBuilder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
            // Find leading and trailing whitespace.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
            int lead;   // index of first char that is not leading whitespace
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
            for (lead = 0; lead < chars.length; lead++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
                if (chars[lead] != ' ' && chars[lead] != '\r') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
            int trail;  // index of last char that is not trailing whitespace
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
            for (trail = chars.length - 1; trail >= 0; trail--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
                if (chars[trail] != ' ' && chars[trail] != '\r') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
            // escape leading and trailing whitespace
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
            for (int i = 0; i < chars.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
                char c = chars[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
                if (i < lead || i > trail) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
                    sbuffer.append('\\');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
                sbuffer.append(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
            }
30649
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30033
diff changeset
   855
            typeAndValue.append(sbuffer);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
        return typeAndValue.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
    public String toRFC2253CanonicalString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
         * Section 2.3: The AttributeTypeAndValue is encoded as the string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
         * representation of the AttributeType, followed by an equals character
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
         * ('=' ASCII 61), followed by the string representation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
         * AttributeValue. The encoding of the AttributeValue is given in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
         * section 2.4.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
        StringBuilder typeAndValue = new StringBuilder(40);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
        typeAndValue.append
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
            (toKeyword(RFC2253, Collections.<String, String>emptyMap()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
        typeAndValue.append('=');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
         * Section 2.4: Converting an AttributeValue from ASN.1 to a String.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
         * If the AttributeValue is of a type which does not have a string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
         * representation defined for it, then it is simply encoded as an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
         * octothorpe character ('#' ASCII 35) followed by the hexadecimal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
         * representation of each of the bytes of the BER encoding of the X.500
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
         * AttributeValue.  This form SHOULD be used if the AttributeType is of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
         * the dotted-decimal form.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
        if ((typeAndValue.charAt(0) >= '0' && typeAndValue.charAt(0) <= '9') ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
            !isDerString(value, true))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
            byte[] data = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
                data = value.toByteArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
            } catch (IOException ie) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
                throw new IllegalArgumentException("DER Value conversion");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
            typeAndValue.append('#');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
            for (int j = 0; j < data.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
                byte b = data[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
                typeAndValue.append(Character.forDigit(0xF & (b >>> 4), 16));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
                typeAndValue.append(Character.forDigit(0xF & b, 16));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
             * 2.4 (cont): Otherwise, if the AttributeValue is of a type which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
             * has a string representation, the value is converted first to a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
             * UTF-8 string according to its syntax specification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
             * NOTE: this implementation only emits DirectoryStrings of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
             * types returned by isDerString().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
            String valStr = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
                valStr = new String(value.getDataBytes(), "UTF8");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
            } catch (IOException ie) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
                throw new IllegalArgumentException("DER Value conversion");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
             * 2.4 (cont): If the UTF-8 string does not have any of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
             * following characters which need escaping, then that string can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
             * used as the string representation of the value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
             *   o   a space or "#" character occurring at the beginning of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
             *       string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
             *   o   a space character occurring at the end of the string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
             *   o   one of the characters ",", "+", """, "\", "<", ">" or ";"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
             * If a character to be escaped is one of the list shown above, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
             * it is prefixed by a backslash ('\' ASCII 92).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
             * Otherwise the character to be escaped is replaced by a backslash
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
             * and two hex digits, which form a single byte in the code of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
             * character.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
            final String escapees = ",+<>;\"\\";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
            StringBuilder sbuffer = new StringBuilder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
            boolean previousWhite = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
            for (int i = 0; i < valStr.length(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
                char c = valStr.charAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
                if (DerValue.isPrintableStringChar(c) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
                    escapees.indexOf(c) >= 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
                    (i == 0 && c == '#')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
                    // escape leading '#' and escapees
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
                    if ((i == 0 && c == '#') || escapees.indexOf(c) >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
                        sbuffer.append('\\');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
                    // convert multiple whitespace to single whitespace
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
                    if (!Character.isWhitespace(c)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
                        previousWhite = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
                        sbuffer.append(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
                        if (previousWhite == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
                            // add single whitespace
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
                            previousWhite = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
                            sbuffer.append(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
                            // ignore subsequent consecutive whitespace
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
                            continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
                } else if (debug != null && Debug.isOn("ava")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
                    // embed non-printable/non-escaped char
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
                    // as escaped hex pairs for debugging
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
                    previousWhite = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
31538
0981099a3e54 8130022: Use Java-style array declarations consistently
igerasim
parents: 31426
diff changeset
   969
                    byte[] valueBytes = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
                        valueBytes = Character.toString(c).getBytes("UTF8");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
                    } catch (IOException ie) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
                        throw new IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
                                        ("DER Value conversion");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
                    for (int j = 0; j < valueBytes.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
                        sbuffer.append('\\');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
                        sbuffer.append(Character.forDigit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
                                        (0xF & (valueBytes[j] >>> 4), 16));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
                        sbuffer.append(Character.forDigit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
                                        (0xF & (valueBytes[j]), 16));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
                    // append non-printable/non-escaped char
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
                    previousWhite = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
                    sbuffer.append(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
            // remove leading and trailing whitespace from value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
            typeAndValue.append(sbuffer.toString().trim());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
        String canon = typeAndValue.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
        canon = canon.toUpperCase(Locale.US).toLowerCase(Locale.US);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
        return Normalizer.normalize(canon, Normalizer.Form.NFKD);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
     * Return true if DerValue can be represented as a String.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
    private static boolean isDerString(DerValue value, boolean canonical) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
        if (canonical) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
            switch (value.tag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
                case DerValue.tag_PrintableString:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
                case DerValue.tag_UTF8String:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
                default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
            switch (value.tag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
                case DerValue.tag_PrintableString:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
                case DerValue.tag_T61String:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
                case DerValue.tag_IA5String:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
                case DerValue.tag_GeneralString:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
                case DerValue.tag_BMPString:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
                case DerValue.tag_UTF8String:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
                default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
    boolean hasRFC2253Keyword() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
        return AVAKeyword.hasKeyword(oid, RFC2253);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
    private String toKeywordValueString(String keyword) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
         * Construct the value with as little copying and garbage
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
         * production as practical.  First the keyword (mandatory),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
         * then the equals sign, finally the value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
        StringBuilder   retval = new StringBuilder(40);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
        retval.append(keyword);
30649
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30033
diff changeset
  1041
        retval.append('=');
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
            String valStr = value.getAsString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
            if (valStr == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
                // rfc1779 specifies that attribute values associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
                // with non-standard keyword attributes may be represented
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
                // using the hex format below.  This will be used only
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
                // when the value is not a string type
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
31538
0981099a3e54 8130022: Use Java-style array declarations consistently
igerasim
parents: 31426
diff changeset
  1053
                byte[] data = value.toByteArray();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
                retval.append('#');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
                for (int i = 0; i < data.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
                    retval.append(hexDigits.charAt((data [i] >> 4) & 0x0f));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
                    retval.append(hexDigits.charAt(data [i] & 0x0f));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
                boolean quoteNeeded = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
                StringBuilder sbuffer = new StringBuilder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
                boolean previousWhite = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
                final String escapees = ",+=\n<>#;\\\"";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
                 * Special characters (e.g. AVA list separators) cause strings
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
                 * to need quoting, or at least escaping.  So do leading or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
                 * trailing spaces, and multiple internal spaces.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
                 */
10590
f184672e4617 7049963: DISTINGUISHED NAMES FOR CERT ARE ESCAPED IN JROCKIT 1.6(NOT COMPATIBLE WITH JROC
mbankal
parents: 10370
diff changeset
  1073
                int length = valStr.length();
f184672e4617 7049963: DISTINGUISHED NAMES FOR CERT ARE ESCAPED IN JROCKIT 1.6(NOT COMPATIBLE WITH JROC
mbankal
parents: 10370
diff changeset
  1074
                boolean alreadyQuoted =
f184672e4617 7049963: DISTINGUISHED NAMES FOR CERT ARE ESCAPED IN JROCKIT 1.6(NOT COMPATIBLE WITH JROC
mbankal
parents: 10370
diff changeset
  1075
                    (length > 1 && valStr.charAt(0) == '\"'
f184672e4617 7049963: DISTINGUISHED NAMES FOR CERT ARE ESCAPED IN JROCKIT 1.6(NOT COMPATIBLE WITH JROC
mbankal
parents: 10370
diff changeset
  1076
                     && valStr.charAt(length - 1) == '\"');
f184672e4617 7049963: DISTINGUISHED NAMES FOR CERT ARE ESCAPED IN JROCKIT 1.6(NOT COMPATIBLE WITH JROC
mbankal
parents: 10370
diff changeset
  1077
f184672e4617 7049963: DISTINGUISHED NAMES FOR CERT ARE ESCAPED IN JROCKIT 1.6(NOT COMPATIBLE WITH JROC
mbankal
parents: 10370
diff changeset
  1078
                for (int i = 0; i < length; i++) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
                    char c = valStr.charAt(i);
10590
f184672e4617 7049963: DISTINGUISHED NAMES FOR CERT ARE ESCAPED IN JROCKIT 1.6(NOT COMPATIBLE WITH JROC
mbankal
parents: 10370
diff changeset
  1080
                    if (alreadyQuoted && (i == 0 || i == length - 1)) {
f184672e4617 7049963: DISTINGUISHED NAMES FOR CERT ARE ESCAPED IN JROCKIT 1.6(NOT COMPATIBLE WITH JROC
mbankal
parents: 10370
diff changeset
  1081
                        sbuffer.append(c);
f184672e4617 7049963: DISTINGUISHED NAMES FOR CERT ARE ESCAPED IN JROCKIT 1.6(NOT COMPATIBLE WITH JROC
mbankal
parents: 10370
diff changeset
  1082
                        continue;
f184672e4617 7049963: DISTINGUISHED NAMES FOR CERT ARE ESCAPED IN JROCKIT 1.6(NOT COMPATIBLE WITH JROC
mbankal
parents: 10370
diff changeset
  1083
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
                    if (DerValue.isPrintableStringChar(c) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
                        escapees.indexOf(c) >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
                        // quote if leading whitespace or special chars
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
                        if (!quoteNeeded &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
                            ((i == 0 && (c == ' ' || c == '\n')) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
                                escapees.indexOf(c) >= 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
                            quoteNeeded = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
                        // quote if multiple internal whitespace
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
                        if (!(c == ' ' || c == '\n')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
                            // escape '"' and '\'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
                            if (c == '"' || c == '\\') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
                                sbuffer.append('\\');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
                            previousWhite = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
                            if (!quoteNeeded && previousWhite) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
                                quoteNeeded = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
                            previousWhite = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
                        sbuffer.append(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
                    } else if (debug != null && Debug.isOn("ava")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
                        // embed non-printable/non-escaped char
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
                        // as escaped hex pairs for debugging
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
                        previousWhite = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
                        // embed escaped hex pairs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
                        byte[] valueBytes =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
                                Character.toString(c).getBytes("UTF8");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
                        for (int j = 0; j < valueBytes.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
                            sbuffer.append('\\');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
                            char hexChar = Character.forDigit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
                                        (0xF & (valueBytes[j] >>> 4), 16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
                            sbuffer.append(Character.toUpperCase(hexChar));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
                            hexChar = Character.forDigit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
                                        (0xF & (valueBytes[j]), 16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
                            sbuffer.append(Character.toUpperCase(hexChar));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
                        // append non-printable/non-escaped char
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
                        previousWhite = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
                        sbuffer.append(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
                // quote if trailing whitespace
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
                if (sbuffer.length() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
                    char trailChar = sbuffer.charAt(sbuffer.length() - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
                    if (trailChar == ' ' || trailChar == '\n') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
                        quoteNeeded = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
                // Emit the string ... quote it if needed
10590
f184672e4617 7049963: DISTINGUISHED NAMES FOR CERT ARE ESCAPED IN JROCKIT 1.6(NOT COMPATIBLE WITH JROC
mbankal
parents: 10370
diff changeset
  1147
                // if string is already quoted, don't re-quote
f184672e4617 7049963: DISTINGUISHED NAMES FOR CERT ARE ESCAPED IN JROCKIT 1.6(NOT COMPATIBLE WITH JROC
mbankal
parents: 10370
diff changeset
  1148
                if (!alreadyQuoted && quoteNeeded) {
30649
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30033
diff changeset
  1149
                    retval.append('\"')
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30033
diff changeset
  1150
                        .append(sbuffer)
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30033
diff changeset
  1151
                        .append('\"');
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
                } else {
30649
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30033
diff changeset
  1153
                    retval.append(sbuffer);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
            throw new IllegalArgumentException("DER Value conversion");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
        return retval.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
 * Helper class that allows conversion from String to ObjectIdentifier and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
 * vice versa according to RFC1779, RFC2253, and an augmented version of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
 * those standards.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
class AVAKeyword {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
    private static final Map<ObjectIdentifier,AVAKeyword> oidMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
    private static final Map<String,AVAKeyword> keywordMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
    private String keyword;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
    private ObjectIdentifier oid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
    private boolean rfc1779Compliant, rfc2253Compliant;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
    private AVAKeyword(String keyword, ObjectIdentifier oid,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
               boolean rfc1779Compliant, boolean rfc2253Compliant) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
        this.keyword = keyword;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
        this.oid = oid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
        this.rfc1779Compliant = rfc1779Compliant;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
        this.rfc2253Compliant = rfc2253Compliant;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
        // register it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
        oidMap.put(oid, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
        keywordMap.put(keyword, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
    private boolean isCompliant(int standard) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
        switch (standard) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
        case AVA.RFC1779:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
            return rfc1779Compliant;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
        case AVA.RFC2253:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
            return rfc2253Compliant;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
        case AVA.DEFAULT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
            // should not occur, internal error
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
            throw new IllegalArgumentException("Invalid standard " + standard);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
     * Get an object identifier representing the specified keyword (or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
     * string encoded object identifier) in the given standard.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
     * @param keywordMap a Map where a keyword String maps to a corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
     *   OID String. Each AVA keyword will be mapped to the corresponding OID.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
     *   If an entry does not exist, it will fallback to the builtin
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
     *   keyword/OID mapping.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
     * @throws IOException If the keyword is not valid in the specified standard
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
     *   or the OID String to which a keyword maps to is improperly formatted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
    static ObjectIdentifier getOID
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
        (String keyword, int standard, Map<String, String> extraKeywordMap)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
            throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
6122
16fa7ed7ff1b 6867345: Turkish regional options cause NPE in sun.security.x509.AlgorithmId.algOID
xuelei
parents: 5506
diff changeset
  1220
        keyword = keyword.toUpperCase(Locale.ENGLISH);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
        if (standard == AVA.RFC2253) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
            if (keyword.startsWith(" ") || keyword.endsWith(" ")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
                throw new IOException("Invalid leading or trailing space " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
                        "in keyword \"" + keyword + "\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
            keyword = keyword.trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
        // check user-specified keyword map first, then fallback to built-in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
        // map
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
        String oidString = extraKeywordMap.get(keyword);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
        if (oidString == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
            AVAKeyword ak = keywordMap.get(keyword);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
            if ((ak != null) && ak.isCompliant(standard)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
                return ak.oid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
            return new ObjectIdentifier(oidString);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
10370
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents: 10336
diff changeset
  1242
        // no keyword found, check if OID string
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents: 10336
diff changeset
  1243
        if (standard == AVA.DEFAULT && keyword.startsWith("OID.")) {
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents: 10336
diff changeset
  1244
            keyword = keyword.substring(4);
5db0cf452a50 7024771: "\\<>" in attribute value part of X500Principal constructor parameter makes strange effect
mullan
parents: 10336
diff changeset
  1245
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
        boolean number = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
        if (keyword.length() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
            char ch = keyword.charAt(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
            if ((ch >= '0') && (ch <= '9')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
                number = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
        if (number == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
            throw new IOException("Invalid keyword \"" + keyword + "\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
        return new ObjectIdentifier(keyword);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
     * Get a keyword for the given ObjectIdentifier according to standard.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
     * If no keyword is available, the ObjectIdentifier is encoded as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
     * String.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
    static String getKeyword(ObjectIdentifier oid, int standard) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
        return getKeyword
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
            (oid, standard, Collections.<String, String>emptyMap());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
     * Get a keyword for the given ObjectIdentifier according to standard.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
     * Checks the extraOidMap for a keyword first, then falls back to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
     * builtin/default set. If no keyword is available, the ObjectIdentifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
     * is encoded as a String.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
    static String getKeyword
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
        (ObjectIdentifier oid, int standard, Map<String, String> extraOidMap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
        // check extraOidMap first, then fallback to built-in map
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
        String oidString = oid.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
        String keywordString = extraOidMap.get(oidString);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
        if (keywordString == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
            AVAKeyword ak = oidMap.get(oid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
            if ((ak != null) && ak.isCompliant(standard)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
                return ak.keyword;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
            if (keywordString.length() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
                throw new IllegalArgumentException("keyword cannot be empty");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
            keywordString = keywordString.trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
            char c = keywordString.charAt(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
            if (c < 65 || c > 122 || (c > 90 && c < 97)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
                throw new IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
                    ("keyword does not start with letter");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
            for (int i=1; i<keywordString.length(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
                c = keywordString.charAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
                if ((c < 65 || c > 122 || (c > 90 && c < 97)) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
                    (c < 48 || c > 57) && c != '_') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
                    throw new IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
                    ("keyword character is not a letter, digit, or underscore");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
            return keywordString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
        // no compliant keyword, use OID
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
        if (standard == AVA.RFC2253) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
            return oidString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
            return "OID." + oidString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
     * Test if oid has an associated keyword in standard.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
    static boolean hasKeyword(ObjectIdentifier oid, int standard) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
        AVAKeyword ak = oidMap.get(oid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
        if (ak == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
        return ak.isCompliant(standard);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
        oidMap = new HashMap<ObjectIdentifier,AVAKeyword>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
        keywordMap = new HashMap<String,AVAKeyword>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
        // NOTE if multiple keywords are available for one OID, order
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
        // is significant!! Preferred *LAST*.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
        new AVAKeyword("CN",           X500Name.commonName_oid,   true,  true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
        new AVAKeyword("C",            X500Name.countryName_oid,  true,  true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
        new AVAKeyword("L",            X500Name.localityName_oid, true,  true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
        new AVAKeyword("S",            X500Name.stateName_oid,    false, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
        new AVAKeyword("ST",           X500Name.stateName_oid,    true,  true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
        new AVAKeyword("O",            X500Name.orgName_oid,      true,  true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
        new AVAKeyword("OU",           X500Name.orgUnitName_oid,  true,  true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
        new AVAKeyword("T",            X500Name.title_oid,        false, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
        new AVAKeyword("IP",           X500Name.ipAddress_oid,    false, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
        new AVAKeyword("STREET",       X500Name.streetAddress_oid,true,  true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
        new AVAKeyword("DC",           X500Name.DOMAIN_COMPONENT_OID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
                                                                  false, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
        new AVAKeyword("DNQUALIFIER",  X500Name.DNQUALIFIER_OID,  false, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
        new AVAKeyword("DNQ",          X500Name.DNQUALIFIER_OID,  false, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
        new AVAKeyword("SURNAME",      X500Name.SURNAME_OID,      false, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
        new AVAKeyword("GIVENNAME",    X500Name.GIVENNAME_OID,    false, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
        new AVAKeyword("INITIALS",     X500Name.INITIALS_OID,     false, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
        new AVAKeyword("GENERATION",   X500Name.GENERATIONQUALIFIER_OID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
                                                                  false, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
        new AVAKeyword("EMAIL", PKCS9Attribute.EMAIL_ADDRESS_OID, false, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
        new AVAKeyword("EMAILADDRESS", PKCS9Attribute.EMAIL_ADDRESS_OID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
                                                                  false, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
        new AVAKeyword("UID",          X500Name.userid_oid,       false, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
        new AVAKeyword("SERIALNUMBER", X500Name.SERIALNUMBER_OID, false, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
}