author | weijun |
Fri, 02 Oct 2009 18:47:34 +0800 | |
changeset 3949 | 00603a93b589 |
parent 2 | 90ce3da70b43 |
child 5506 | 202f599c92aa |
permissions | -rw-r--r-- |
2 | 1 |
/* |
3949
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
2
diff
changeset
|
2 |
* Copyright 2005-2009 Sun Microsystems, Inc. All Rights Reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Sun designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Sun in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 |
* have any questions. |
|
24 |
*/ |
|
25 |
||
26 |
package sun.security.krb5.internal; |
|
27 |
||
28 |
import sun.security.util.*; |
|
29 |
import sun.security.krb5.Asn1Exception; |
|
30 |
import java.io.IOException; |
|
3949
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
2
diff
changeset
|
31 |
import sun.security.krb5.internal.util.KerberosString; |
2 | 32 |
|
33 |
/** |
|
34 |
* Implements the ASN.1 ETYPE-INFO-ENTRY type. |
|
35 |
* |
|
36 |
* ETYPE-INFO-ENTRY ::= SEQUENCE { |
|
37 |
* etype [0] Int32, |
|
38 |
* salt [1] OCTET STRING OPTIONAL |
|
39 |
* } |
|
40 |
* |
|
41 |
* @author Seema Malkani |
|
42 |
*/ |
|
43 |
||
44 |
public class ETypeInfo { |
|
45 |
||
46 |
private int etype; |
|
3949
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
2
diff
changeset
|
47 |
private String salt = null; |
2 | 48 |
|
49 |
private static final byte TAG_TYPE = 0; |
|
50 |
private static final byte TAG_VALUE = 1; |
|
51 |
||
52 |
private ETypeInfo() { |
|
53 |
} |
|
54 |
||
3949
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
2
diff
changeset
|
55 |
public ETypeInfo(int etype, String salt) { |
2 | 56 |
this.etype = etype; |
3949
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
2
diff
changeset
|
57 |
this.salt = salt; |
2 | 58 |
} |
59 |
||
60 |
public Object clone() { |
|
3949
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
2
diff
changeset
|
61 |
return new ETypeInfo(etype, salt); |
2 | 62 |
} |
63 |
||
64 |
/** |
|
65 |
* Constructs a ETypeInfo object. |
|
66 |
* @param encoding a DER-encoded data. |
|
67 |
* @exception Asn1Exception if an error occurs while decoding an |
|
68 |
* ASN1 encoded data. |
|
69 |
* @exception IOException if an I/O error occurs while reading encoded data. |
|
70 |
*/ |
|
71 |
public ETypeInfo(DerValue encoding) throws Asn1Exception, IOException { |
|
72 |
DerValue der = null; |
|
73 |
||
74 |
if (encoding.getTag() != DerValue.tag_Sequence) { |
|
75 |
throw new Asn1Exception(Krb5.ASN1_BAD_ID); |
|
76 |
} |
|
77 |
||
78 |
// etype |
|
79 |
der = encoding.getData().getDerValue(); |
|
80 |
if ((der.getTag() & 0x1F) == 0x00) { |
|
81 |
this.etype = der.getData().getBigInteger().intValue(); |
|
82 |
} |
|
83 |
else |
|
84 |
throw new Asn1Exception(Krb5.ASN1_BAD_ID); |
|
85 |
||
86 |
// salt |
|
87 |
if (encoding.getData().available() > 0) { |
|
88 |
der = encoding.getData().getDerValue(); |
|
89 |
if ((der.getTag() & 0x1F) == 0x01) { |
|
3949
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
2
diff
changeset
|
90 |
byte[] saltBytes = der.getData().getOctetString(); |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
2
diff
changeset
|
91 |
|
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
2
diff
changeset
|
92 |
// Although salt is defined as an OCTET STRING, it's the |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
2
diff
changeset
|
93 |
// encoding from of a string. As RFC 4120 says: |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
2
diff
changeset
|
94 |
// |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
2
diff
changeset
|
95 |
// "The salt, ..., is also completely unspecified with respect |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
2
diff
changeset
|
96 |
// to character set and is probably locale-specific". |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
2
diff
changeset
|
97 |
// |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
2
diff
changeset
|
98 |
// It's known that this field is using the same encoding as |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
2
diff
changeset
|
99 |
// KerberosString in most implementations. |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
2
diff
changeset
|
100 |
|
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
2
diff
changeset
|
101 |
if (KerberosString.MSNAME) { |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
2
diff
changeset
|
102 |
this.salt = new String(saltBytes, "UTF8"); |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
2
diff
changeset
|
103 |
} else { |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
2
diff
changeset
|
104 |
this.salt = new String(saltBytes); |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
2
diff
changeset
|
105 |
} |
2 | 106 |
} |
107 |
} |
|
108 |
||
109 |
if (encoding.getData().available() > 0) |
|
110 |
throw new Asn1Exception(Krb5.ASN1_BAD_ID); |
|
111 |
} |
|
112 |
||
113 |
/** |
|
114 |
* Encodes this object to an OutputStream. |
|
115 |
* |
|
116 |
* @return byte array of the encoded data. |
|
117 |
* @exception IOException if an I/O error occurs while reading encoded data. |
|
118 |
* @exception Asn1Exception on encoding errors. |
|
119 |
*/ |
|
120 |
public byte[] asn1Encode() throws Asn1Exception, IOException { |
|
121 |
||
122 |
DerOutputStream bytes = new DerOutputStream(); |
|
123 |
DerOutputStream temp = new DerOutputStream(); |
|
124 |
||
125 |
temp.putInteger(etype); |
|
126 |
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, |
|
127 |
TAG_TYPE), temp); |
|
128 |
||
129 |
if (salt != null) { |
|
130 |
temp = new DerOutputStream(); |
|
3949
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
2
diff
changeset
|
131 |
if (KerberosString.MSNAME) { |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
2
diff
changeset
|
132 |
temp.putOctetString(salt.getBytes("UTF8")); |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
2
diff
changeset
|
133 |
} else { |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
2
diff
changeset
|
134 |
temp.putOctetString(salt.getBytes()); |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
2
diff
changeset
|
135 |
} |
2 | 136 |
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, |
137 |
TAG_VALUE), temp); |
|
138 |
} |
|
139 |
||
140 |
temp = new DerOutputStream(); |
|
141 |
temp.write(DerValue.tag_Sequence, bytes); |
|
142 |
return temp.toByteArray(); |
|
143 |
} |
|
144 |
||
145 |
// accessor methods |
|
146 |
public int getEType() { |
|
147 |
return etype; |
|
148 |
} |
|
149 |
||
3949
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
2
diff
changeset
|
150 |
public String getSalt() { |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
2
diff
changeset
|
151 |
return salt; |
2 | 152 |
} |
153 |
||
154 |
} |