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