author | ohair |
Tue, 25 May 2010 15:58:33 -0700 | |
changeset 5506 | 202f599c92aa |
parent 3949 | 00603a93b589 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
5506 | 2 |
* Copyright (c) 2005, 2009, Oracle and/or its affiliates. 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
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. |
|
2 | 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:
715
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-INFO2-ENTRY ::= SEQUENCE { |
|
37 |
* etype [0] Int32, |
|
38 |
* salt [1] KerberosString OPTIONAL, |
|
39 |
* s2kparams [2] OCTET STRING OPTIONAL |
|
40 |
* } |
|
41 |
* |
|
42 |
* @author Seema Malkani |
|
43 |
*/ |
|
44 |
||
45 |
public class ETypeInfo2 { |
|
46 |
||
47 |
private int etype; |
|
48 |
private String saltStr = null; |
|
49 |
private byte[] s2kparams = null; |
|
50 |
||
51 |
private static final byte TAG_TYPE = 0; |
|
52 |
private static final byte TAG_VALUE1 = 1; |
|
53 |
private static final byte TAG_VALUE2 = 2; |
|
54 |
||
55 |
private ETypeInfo2() { |
|
56 |
} |
|
57 |
||
3949
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
715
diff
changeset
|
58 |
public ETypeInfo2(int etype, String salt, byte[] s2kparams) { |
2 | 59 |
this.etype = etype; |
3949
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
715
diff
changeset
|
60 |
this.saltStr = salt; |
2 | 61 |
if (s2kparams != null) { |
62 |
this.s2kparams = s2kparams.clone(); |
|
63 |
} |
|
64 |
} |
|
65 |
||
66 |
public Object clone() { |
|
67 |
ETypeInfo2 etypeInfo2 = new ETypeInfo2(); |
|
68 |
etypeInfo2.etype = etype; |
|
69 |
etypeInfo2.saltStr = saltStr; |
|
70 |
if (s2kparams != null) { |
|
71 |
etypeInfo2.s2kparams = new byte[s2kparams.length]; |
|
72 |
System.arraycopy(s2kparams, 0, etypeInfo2.s2kparams, |
|
73 |
0, s2kparams.length); |
|
74 |
} |
|
75 |
return etypeInfo2; |
|
76 |
} |
|
77 |
||
78 |
/** |
|
79 |
* Constructs a ETypeInfo2 object. |
|
80 |
* @param encoding a DER-encoded data. |
|
81 |
* @exception Asn1Exception if an error occurs while decoding an |
|
82 |
* ASN1 encoded data. |
|
83 |
* @exception IOException if an I/O error occurs while reading encoded data. |
|
84 |
*/ |
|
85 |
public ETypeInfo2(DerValue encoding) throws Asn1Exception, IOException { |
|
86 |
DerValue der = null; |
|
87 |
||
88 |
if (encoding.getTag() != DerValue.tag_Sequence) { |
|
89 |
throw new Asn1Exception(Krb5.ASN1_BAD_ID); |
|
90 |
} |
|
91 |
||
92 |
// etype |
|
93 |
der = encoding.getData().getDerValue(); |
|
94 |
if ((der.getTag() & 0x1F) == 0x00) { |
|
95 |
this.etype = der.getData().getBigInteger().intValue(); |
|
96 |
} |
|
97 |
else |
|
98 |
throw new Asn1Exception(Krb5.ASN1_BAD_ID); |
|
99 |
||
100 |
// salt |
|
101 |
if (encoding.getData().available() > 0) { |
|
75 | 102 |
if ((encoding.getData().peekByte() & 0x1F) == 0x01) { |
103 |
der = encoding.getData().getDerValue(); |
|
3949
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
715
diff
changeset
|
104 |
this.saltStr = new KerberosString( |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
715
diff
changeset
|
105 |
der.getData().getDerValue()).toString(); |
2 | 106 |
} |
107 |
} |
|
108 |
||
109 |
// s2kparams |
|
110 |
if (encoding.getData().available() > 0) { |
|
75 | 111 |
if ((encoding.getData().peekByte() & 0x1F) == 0x02) { |
112 |
der = encoding.getData().getDerValue(); |
|
2 | 113 |
this.s2kparams = der.getData().getOctetString(); |
114 |
} |
|
115 |
} |
|
116 |
||
117 |
if (encoding.getData().available() > 0) |
|
118 |
throw new Asn1Exception(Krb5.ASN1_BAD_ID); |
|
119 |
} |
|
120 |
||
121 |
/** |
|
122 |
* Encodes this object to an OutputStream. |
|
123 |
* |
|
124 |
* @return byte array of the encoded data. |
|
125 |
* @exception IOException if an I/O error occurs while reading encoded data. |
|
126 |
* @exception Asn1Exception on encoding errors. |
|
127 |
*/ |
|
128 |
public byte[] asn1Encode() throws Asn1Exception, IOException { |
|
129 |
||
130 |
DerOutputStream bytes = new DerOutputStream(); |
|
131 |
DerOutputStream temp = new DerOutputStream(); |
|
132 |
||
133 |
temp.putInteger(etype); |
|
134 |
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, |
|
135 |
TAG_TYPE), temp); |
|
136 |
||
137 |
if (saltStr != null) { |
|
138 |
temp = new DerOutputStream(); |
|
3949
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
715
diff
changeset
|
139 |
temp.putDerValue(new KerberosString(saltStr).toDerValue()); |
2 | 140 |
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, |
141 |
TAG_VALUE1), temp); |
|
142 |
} |
|
143 |
if (s2kparams != null) { |
|
144 |
temp = new DerOutputStream(); |
|
145 |
temp.putOctetString(s2kparams); |
|
146 |
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, |
|
147 |
TAG_VALUE2), temp); |
|
148 |
} |
|
149 |
||
150 |
temp = new DerOutputStream(); |
|
151 |
temp.write(DerValue.tag_Sequence, bytes); |
|
152 |
return temp.toByteArray(); |
|
153 |
} |
|
154 |
||
155 |
// accessor methods |
|
156 |
public int getEType() { |
|
157 |
return etype; |
|
158 |
} |
|
159 |
||
3949
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
715
diff
changeset
|
160 |
public String getSalt() { |
00603a93b589
6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents:
715
diff
changeset
|
161 |
return saltStr; |
2 | 162 |
} |
163 |
||
164 |
public byte[] getParams() { |
|
165 |
return ((s2kparams == null) ? null : s2kparams.clone()); |
|
166 |
} |
|
167 |
||
168 |
} |