author | weijun |
Tue, 14 Aug 2018 22:39:34 +0800 | |
changeset 51398 | 3c389a284345 |
parent 49555 | 12fe57c319e1 |
child 59024 | b046ba510bbc |
permissions | -rw-r--r-- |
3949
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
1 |
/* |
49555
12fe57c319e1
8200152: KerberosString should use UTF-8 by default
weijun
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2009, 2018, Oracle and/or its affiliates. All rights reserved. |
3949
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
4 |
* |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
3949
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
3949
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
10 |
* |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
15 |
* accompanied this code). |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
16 |
* |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
20 |
* |
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
3949
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
24 |
*/ |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
25 |
|
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
26 |
package sun.security.krb5.internal.util; |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
27 |
|
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
28 |
import java.io.IOException; |
49555
12fe57c319e1
8200152: KerberosString should use UTF-8 by default
weijun
parents:
47216
diff
changeset
|
29 |
import sun.security.action.GetPropertyAction; |
3949
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
30 |
import sun.security.util.DerValue; |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
31 |
|
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
32 |
/** |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
33 |
* Implements the ASN.1 KerberosString type. |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
34 |
* |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
35 |
* <pre> |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
36 |
* KerberosString ::= GeneralString (IA5String) |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
37 |
* </pre> |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
38 |
* |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
39 |
* This definition reflects the Network Working Group RFC 4120 |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
40 |
* specification available at |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
41 |
* <a href="http://www.ietf.org/rfc/rfc4120.txt"> |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
42 |
* http://www.ietf.org/rfc/rfc4120.txt</a>. |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
43 |
*/ |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
44 |
public final class KerberosString { |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
45 |
/** |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
46 |
* RFC 4120 defines KerberosString as GeneralString (IA5String), which |
49555
12fe57c319e1
8200152: KerberosString should use UTF-8 by default
weijun
parents:
47216
diff
changeset
|
47 |
* only includes ASCII characters. However, most implementations have been |
12fe57c319e1
8200152: KerberosString should use UTF-8 by default
weijun
parents:
47216
diff
changeset
|
48 |
* known to use GeneralString to contain UTF-8 encoding. The following |
12fe57c319e1
8200152: KerberosString should use UTF-8 by default
weijun
parents:
47216
diff
changeset
|
49 |
* system property is defined. When set as true, KerberosString is encoded |
12fe57c319e1
8200152: KerberosString should use UTF-8 by default
weijun
parents:
47216
diff
changeset
|
50 |
* as UTF-8. Otherwise, it's ASCII. The default is true. |
12fe57c319e1
8200152: KerberosString should use UTF-8 by default
weijun
parents:
47216
diff
changeset
|
51 |
* |
12fe57c319e1
8200152: KerberosString should use UTF-8 by default
weijun
parents:
47216
diff
changeset
|
52 |
* Note that this only affects the byte encoding, the tag of the ASN.1 |
12fe57c319e1
8200152: KerberosString should use UTF-8 by default
weijun
parents:
47216
diff
changeset
|
53 |
* type is still GeneralString. |
3949
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
54 |
*/ |
49555
12fe57c319e1
8200152: KerberosString should use UTF-8 by default
weijun
parents:
47216
diff
changeset
|
55 |
public static final boolean MSNAME; |
12fe57c319e1
8200152: KerberosString should use UTF-8 by default
weijun
parents:
47216
diff
changeset
|
56 |
|
12fe57c319e1
8200152: KerberosString should use UTF-8 by default
weijun
parents:
47216
diff
changeset
|
57 |
static { |
51398
3c389a284345
8209416: Refactoring GetPropertyAction calls in security libs
weijun
parents:
49555
diff
changeset
|
58 |
String prop = GetPropertyAction |
3c389a284345
8209416: Refactoring GetPropertyAction calls in security libs
weijun
parents:
49555
diff
changeset
|
59 |
.privilegedGetProperty("sun.security.krb5.msinterop.kstring", "true"); |
49555
12fe57c319e1
8200152: KerberosString should use UTF-8 by default
weijun
parents:
47216
diff
changeset
|
60 |
MSNAME = Boolean.parseBoolean(prop); |
12fe57c319e1
8200152: KerberosString should use UTF-8 by default
weijun
parents:
47216
diff
changeset
|
61 |
} |
3949
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
62 |
|
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
63 |
private final String s; |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
64 |
|
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
65 |
public KerberosString(String s) { |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
66 |
this.s = s; |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
67 |
} |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
68 |
|
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
69 |
public KerberosString(DerValue der) throws IOException { |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
70 |
if (der.tag != DerValue.tag_GeneralString) { |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
71 |
throw new IOException( |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
72 |
"KerberosString's tag is incorrect: " + der.tag); |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
73 |
} |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
74 |
s = new String(der.getDataBytes(), MSNAME?"UTF8":"ASCII"); |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
75 |
} |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
76 |
|
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
77 |
public String toString() { |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
78 |
return s; |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
79 |
} |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
80 |
|
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
81 |
public DerValue toDerValue() throws IOException { |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
82 |
// No need to cache the result since this method is |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
83 |
// only called once. |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
84 |
return new DerValue(DerValue.tag_GeneralString, |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
85 |
s.getBytes(MSNAME?"UTF8":"ASCII")); |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
86 |
} |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
diff
changeset
|
87 |
} |