author | xuelei |
Sat, 24 Jul 2010 22:59:41 +0800 | |
changeset 6122 | 16fa7ed7ff1b |
parent 5975 | 076cd013e5e4 |
child 13247 | 74902cfeb9c6 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
5975
076cd013e5e4
6946669: SSL/Krb5 should not call EncryptedData.reset(data, false)
weijun
parents:
5506
diff
changeset
|
2 |
* Copyright (c) 2000, 2010, 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 |
/* |
|
27 |
* |
|
28 |
* (C) Copyright IBM Corp. 1999 All Rights Reserved. |
|
29 |
* Copyright 1997 The Open Group Research Institute. All rights reserved. |
|
30 |
*/ |
|
31 |
||
32 |
package sun.security.krb5; |
|
33 |
||
34 |
import sun.security.krb5.internal.*; |
|
35 |
import sun.security.krb5.internal.crypto.*; |
|
36 |
import sun.security.util.*; |
|
37 |
import java.io.IOException; |
|
38 |
||
39 |
/** XXX This class does not appear to be used. **/ |
|
40 |
||
41 |
class KrbPriv extends KrbAppMessage { |
|
42 |
private byte[] obuf; |
|
43 |
private byte[] userData; |
|
44 |
||
45 |
private KrbPriv(byte[] userData, |
|
46 |
Credentials creds, |
|
47 |
EncryptionKey subKey, |
|
48 |
KerberosTime timestamp, |
|
49 |
SeqNumber seqNumber, |
|
50 |
HostAddress saddr, |
|
51 |
HostAddress raddr |
|
52 |
) throws KrbException, IOException { |
|
53 |
EncryptionKey reqKey = null; |
|
54 |
if (subKey != null) |
|
55 |
reqKey = subKey; |
|
56 |
else |
|
57 |
reqKey = creds.key; |
|
58 |
||
59 |
obuf = mk_priv( |
|
60 |
userData, |
|
61 |
reqKey, |
|
62 |
timestamp, |
|
63 |
seqNumber, |
|
64 |
saddr, |
|
65 |
raddr |
|
66 |
); |
|
67 |
} |
|
68 |
||
69 |
private KrbPriv(byte[] msg, |
|
70 |
Credentials creds, |
|
71 |
EncryptionKey subKey, |
|
72 |
SeqNumber seqNumber, |
|
73 |
HostAddress saddr, |
|
74 |
HostAddress raddr, |
|
75 |
boolean timestampRequired, |
|
76 |
boolean seqNumberRequired |
|
77 |
) throws KrbException, IOException { |
|
78 |
||
79 |
KRBPriv krb_priv = new KRBPriv(msg); |
|
80 |
EncryptionKey reqKey = null; |
|
81 |
if (subKey != null) |
|
82 |
reqKey = subKey; |
|
83 |
else |
|
84 |
reqKey = creds.key; |
|
85 |
userData = rd_priv(krb_priv, |
|
86 |
reqKey, |
|
87 |
seqNumber, |
|
88 |
saddr, |
|
89 |
raddr, |
|
90 |
timestampRequired, |
|
91 |
seqNumberRequired, |
|
92 |
creds.client, |
|
93 |
creds.client.getRealm() |
|
94 |
); |
|
95 |
} |
|
96 |
||
97 |
public byte[] getMessage() throws KrbException { |
|
98 |
return obuf; |
|
99 |
} |
|
100 |
||
101 |
public byte[] getData() { |
|
102 |
return userData; |
|
103 |
} |
|
104 |
||
105 |
private byte[] mk_priv(byte[] userData, |
|
106 |
EncryptionKey key, |
|
107 |
KerberosTime timestamp, |
|
108 |
SeqNumber seqNumber, |
|
109 |
HostAddress sAddress, |
|
110 |
HostAddress rAddress |
|
111 |
) throws Asn1Exception, IOException, |
|
112 |
KdcErrException, KrbCryptoException { |
|
113 |
||
114 |
Integer usec = null; |
|
115 |
Integer seqno = null; |
|
116 |
||
117 |
if (timestamp != null) |
|
118 |
usec = new Integer(timestamp.getMicroSeconds()); |
|
119 |
||
120 |
if (seqNumber != null) { |
|
121 |
seqno = new Integer(seqNumber.current()); |
|
122 |
seqNumber.step(); |
|
123 |
} |
|
124 |
||
125 |
EncKrbPrivPart unenc_encKrbPrivPart = |
|
126 |
new EncKrbPrivPart(userData, |
|
127 |
timestamp, |
|
128 |
usec, |
|
129 |
seqno, |
|
130 |
sAddress, |
|
131 |
rAddress |
|
132 |
); |
|
133 |
||
134 |
byte[] temp = unenc_encKrbPrivPart.asn1Encode(); |
|
135 |
||
136 |
EncryptedData encKrbPrivPart = |
|
137 |
new EncryptedData(key, temp, |
|
138 |
KeyUsage.KU_ENC_KRB_PRIV_PART); |
|
139 |
||
140 |
KRBPriv krb_priv = new KRBPriv(encKrbPrivPart); |
|
141 |
||
142 |
temp = krb_priv.asn1Encode(); |
|
143 |
||
144 |
return krb_priv.asn1Encode(); |
|
145 |
} |
|
146 |
||
147 |
private byte[] rd_priv(KRBPriv krb_priv, |
|
148 |
EncryptionKey key, |
|
149 |
SeqNumber seqNumber, |
|
150 |
HostAddress sAddress, |
|
151 |
HostAddress rAddress, |
|
152 |
boolean timestampRequired, |
|
153 |
boolean seqNumberRequired, |
|
154 |
PrincipalName cname, |
|
155 |
Realm crealm |
|
156 |
) throws Asn1Exception, KdcErrException, |
|
157 |
KrbApErrException, IOException, KrbCryptoException { |
|
158 |
||
159 |
byte[] bytes = krb_priv.encPart.decrypt(key, |
|
160 |
KeyUsage.KU_ENC_KRB_PRIV_PART); |
|
5975
076cd013e5e4
6946669: SSL/Krb5 should not call EncryptedData.reset(data, false)
weijun
parents:
5506
diff
changeset
|
161 |
byte[] temp = krb_priv.encPart.reset(bytes); |
2 | 162 |
DerValue ref = new DerValue(temp); |
163 |
EncKrbPrivPart enc_part = new EncKrbPrivPart(ref); |
|
164 |
||
165 |
check(enc_part.timestamp, |
|
166 |
enc_part.usec, |
|
167 |
enc_part.seqNumber, |
|
168 |
enc_part.sAddress, |
|
169 |
enc_part.rAddress, |
|
170 |
seqNumber, |
|
171 |
sAddress, |
|
172 |
rAddress, |
|
173 |
timestampRequired, |
|
174 |
seqNumberRequired, |
|
175 |
cname, |
|
176 |
crealm |
|
177 |
); |
|
178 |
||
179 |
return enc_part.userData; |
|
180 |
} |
|
181 |
} |