author | weijun |
Wed, 09 Nov 2011 09:30:13 +0800 | |
changeset 11011 | d14a696e3ab5 |
parent 5506 | 202f599c92aa |
child 11020 | a17d4ff7bae3 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
3 |
* |
|
4 |
* This code is free software; you can redistribute it and/or modify it |
|
5 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 6 |
* published by the Free Software Foundation. Oracle designates this |
2 | 7 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 8 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 9 |
* |
10 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
11 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
12 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
13 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
14 |
* accompanied this code). |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License version |
|
17 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
18 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
19 |
* |
|
5506 | 20 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
21 |
* or visit www.oracle.com if you need additional information or have any |
|
22 |
* questions. |
|
2 | 23 |
*/ |
24 |
||
25 |
/* |
|
26 |
* |
|
27 |
* (C) Copyright IBM Corp. 1999 All Rights Reserved. |
|
28 |
* Copyright 1997 The Open Group Research Institute. All rights reserved. |
|
29 |
*/ |
|
30 |
||
31 |
package sun.security.krb5.internal.ccache; |
|
32 |
||
33 |
import sun.security.krb5.*; |
|
34 |
import sun.security.krb5.internal.*; |
|
35 |
||
36 |
public class Credentials { |
|
73 | 37 |
|
38 |
PrincipalName cname; |
|
39 |
Realm crealm; |
|
2 | 40 |
PrincipalName sname; |
73 | 41 |
Realm srealm; |
42 |
EncryptionKey key; |
|
43 |
KerberosTime authtime; |
|
44 |
KerberosTime starttime;//optional |
|
45 |
KerberosTime endtime; |
|
46 |
KerberosTime renewTill; //optional |
|
47 |
HostAddresses caddr; //optional; for proxied tickets only |
|
2 | 48 |
AuthorizationData authorizationData; //optional, not being actually used |
49 |
public boolean isEncInSKey; // true if ticket is encrypted in another ticket's skey |
|
73 | 50 |
TicketFlags flags; |
2 | 51 |
Ticket ticket; |
73 | 52 |
Ticket secondTicket; //optional |
53 |
private boolean DEBUG = Krb5.DEBUG; |
|
2 | 54 |
|
73 | 55 |
public Credentials( |
56 |
PrincipalName new_cname, |
|
57 |
PrincipalName new_sname, |
|
58 |
EncryptionKey new_key, |
|
59 |
KerberosTime new_authtime, |
|
60 |
KerberosTime new_starttime, |
|
61 |
KerberosTime new_endtime, |
|
62 |
KerberosTime new_renewTill, |
|
63 |
boolean new_isEncInSKey, |
|
64 |
TicketFlags new_flags, |
|
65 |
HostAddresses new_caddr, |
|
66 |
AuthorizationData new_authData, |
|
67 |
Ticket new_ticket, |
|
68 |
Ticket new_secondTicket) { |
|
69 |
cname = (PrincipalName) new_cname.clone(); |
|
70 |
if (new_cname.getRealm() != null) { |
|
71 |
crealm = (Realm) new_cname.getRealm().clone(); |
|
72 |
} |
|
2 | 73 |
|
73 | 74 |
sname = (PrincipalName) new_sname.clone(); |
75 |
if (new_sname.getRealm() != null) { |
|
76 |
srealm = (Realm) new_sname.getRealm().clone(); |
|
77 |
} |
|
78 |
||
79 |
key = (EncryptionKey) new_key.clone(); |
|
2 | 80 |
|
73 | 81 |
authtime = (KerberosTime) new_authtime.clone(); |
76 | 82 |
if (new_starttime != null) { |
83 |
starttime = (KerberosTime) new_starttime.clone(); |
|
84 |
} |
|
73 | 85 |
endtime = (KerberosTime) new_endtime.clone(); |
76 | 86 |
if (new_renewTill != null) { |
87 |
renewTill = (KerberosTime) new_renewTill.clone(); |
|
88 |
} |
|
73 | 89 |
if (new_caddr != null) { |
90 |
caddr = (HostAddresses) new_caddr.clone(); |
|
91 |
} |
|
92 |
if (new_authData != null) { |
|
93 |
authorizationData = (AuthorizationData) new_authData.clone(); |
|
2 | 94 |
} |
95 |
||
73 | 96 |
isEncInSKey = new_isEncInSKey; |
97 |
flags = (TicketFlags) new_flags.clone(); |
|
98 |
ticket = (Ticket) (new_ticket.clone()); |
|
99 |
if (new_secondTicket != null) { |
|
100 |
secondTicket = (Ticket) new_secondTicket.clone(); |
|
101 |
} |
|
102 |
} |
|
2 | 103 |
|
73 | 104 |
public Credentials( |
105 |
KDCRep kdcRep, |
|
106 |
Ticket new_secondTicket, |
|
107 |
AuthorizationData new_authorizationData, |
|
108 |
boolean new_isEncInSKey) { |
|
109 |
if (kdcRep.encKDCRepPart == null) //can't store while encrypted |
|
110 |
{ |
|
111 |
return; |
|
2 | 112 |
} |
73 | 113 |
crealm = (Realm) kdcRep.crealm.clone(); |
114 |
cname = (PrincipalName) kdcRep.cname.clone(); |
|
115 |
ticket = (Ticket) kdcRep.ticket.clone(); |
|
116 |
key = (EncryptionKey) kdcRep.encKDCRepPart.key.clone(); |
|
117 |
flags = (TicketFlags) kdcRep.encKDCRepPart.flags.clone(); |
|
118 |
authtime = (KerberosTime) kdcRep.encKDCRepPart.authtime.clone(); |
|
76 | 119 |
if (kdcRep.encKDCRepPart.starttime != null) { |
120 |
starttime = (KerberosTime) kdcRep.encKDCRepPart.starttime.clone(); |
|
121 |
} |
|
73 | 122 |
endtime = (KerberosTime) kdcRep.encKDCRepPart.endtime.clone(); |
76 | 123 |
if (kdcRep.encKDCRepPart.renewTill != null) { |
124 |
renewTill = (KerberosTime) kdcRep.encKDCRepPart.renewTill.clone(); |
|
125 |
} |
|
73 | 126 |
srealm = (Realm) kdcRep.encKDCRepPart.srealm.clone(); |
127 |
sname = (PrincipalName) kdcRep.encKDCRepPart.sname.clone(); |
|
128 |
caddr = (HostAddresses) kdcRep.encKDCRepPart.caddr.clone(); |
|
129 |
secondTicket = (Ticket) new_secondTicket.clone(); |
|
130 |
authorizationData = |
|
131 |
(AuthorizationData) new_authorizationData.clone(); |
|
132 |
isEncInSKey = new_isEncInSKey; |
|
133 |
} |
|
2 | 134 |
|
73 | 135 |
public Credentials(KDCRep kdcRep) { |
136 |
this(kdcRep, null); |
|
137 |
} |
|
2 | 138 |
|
73 | 139 |
public Credentials(KDCRep kdcRep, Ticket new_ticket) { |
140 |
sname = (PrincipalName) kdcRep.encKDCRepPart.sname.clone(); |
|
141 |
srealm = (Realm) kdcRep.encKDCRepPart.srealm.clone(); |
|
142 |
try { |
|
143 |
sname.setRealm(srealm); |
|
144 |
} catch (RealmException e) { |
|
145 |
} |
|
146 |
cname = (PrincipalName) kdcRep.cname.clone(); |
|
147 |
crealm = (Realm) kdcRep.crealm.clone(); |
|
148 |
try { |
|
149 |
cname.setRealm(crealm); |
|
150 |
} catch (RealmException e) { |
|
151 |
} |
|
152 |
key = (EncryptionKey) kdcRep.encKDCRepPart.key.clone(); |
|
153 |
authtime = (KerberosTime) kdcRep.encKDCRepPart.authtime.clone(); |
|
154 |
if (kdcRep.encKDCRepPart.starttime != null) { |
|
155 |
starttime = (KerberosTime) kdcRep.encKDCRepPart.starttime.clone(); |
|
156 |
} else { |
|
157 |
starttime = null; |
|
158 |
} |
|
159 |
endtime = (KerberosTime) kdcRep.encKDCRepPart.endtime.clone(); |
|
160 |
if (kdcRep.encKDCRepPart.renewTill != null) { |
|
161 |
renewTill = (KerberosTime) kdcRep.encKDCRepPart.renewTill.clone(); |
|
162 |
} else { |
|
163 |
renewTill = null; |
|
164 |
} |
|
165 |
// if (kdcRep.msgType == Krb5.KRB_AS_REP) { |
|
166 |
// isEncInSKey = false; |
|
167 |
// secondTicket = null; |
|
168 |
// } |
|
169 |
flags = kdcRep.encKDCRepPart.flags; |
|
170 |
if (kdcRep.encKDCRepPart.caddr != null) { |
|
171 |
caddr = (HostAddresses) kdcRep.encKDCRepPart.caddr.clone(); |
|
172 |
} else { |
|
173 |
caddr = null; |
|
2 | 174 |
} |
73 | 175 |
ticket = (Ticket) kdcRep.ticket.clone(); |
176 |
if (new_ticket != null) { |
|
177 |
secondTicket = (Ticket) new_ticket.clone(); |
|
178 |
isEncInSKey = true; |
|
179 |
} else { |
|
180 |
secondTicket = null; |
|
181 |
isEncInSKey = false; |
|
182 |
} |
|
183 |
} |
|
2 | 184 |
|
73 | 185 |
/** |
186 |
* Checks if this credential is expired |
|
187 |
*/ |
|
188 |
public boolean isValid() { |
|
189 |
boolean valid = true; |
|
190 |
if (endtime.getTime() < System.currentTimeMillis()) { |
|
191 |
valid = false; |
|
76 | 192 |
} else if (starttime != null) { |
193 |
if (starttime.getTime() > System.currentTimeMillis()) { |
|
194 |
valid = false; |
|
195 |
} |
|
196 |
} else { |
|
197 |
if (authtime.getTime() > System.currentTimeMillis()) { |
|
198 |
valid = false; |
|
199 |
} |
|
2 | 200 |
} |
73 | 201 |
return valid; |
202 |
} |
|
2 | 203 |
|
73 | 204 |
public PrincipalName getServicePrincipal() throws RealmException { |
205 |
if (sname.getRealm() == null) { |
|
206 |
sname.setRealm(srealm); |
|
2 | 207 |
} |
73 | 208 |
return sname; |
209 |
} |
|
2 | 210 |
|
73 | 211 |
public sun.security.krb5.Credentials setKrbCreds() { |
11011
d14a696e3ab5
7107019: sun.security.krb5.internal.ccache.CCacheInputStream.readCred does not use auth data
weijun
parents:
5506
diff
changeset
|
212 |
// Note: We will not pass authorizationData to s.s.k.Credentials. The |
d14a696e3ab5
7107019: sun.security.krb5.internal.ccache.CCacheInputStream.readCred does not use auth data
weijun
parents:
5506
diff
changeset
|
213 |
// field in that class will be passed to Krb5Context as the return |
d14a696e3ab5
7107019: sun.security.krb5.internal.ccache.CCacheInputStream.readCred does not use auth data
weijun
parents:
5506
diff
changeset
|
214 |
// value of ExtendedGSSContext.inquireSecContext(KRB5_GET_AUTHZ_DATA), |
d14a696e3ab5
7107019: sun.security.krb5.internal.ccache.CCacheInputStream.readCred does not use auth data
weijun
parents:
5506
diff
changeset
|
215 |
// which is documented as the authData in the service ticket. That |
d14a696e3ab5
7107019: sun.security.krb5.internal.ccache.CCacheInputStream.readCred does not use auth data
weijun
parents:
5506
diff
changeset
|
216 |
// is on the acceptor side. |
d14a696e3ab5
7107019: sun.security.krb5.internal.ccache.CCacheInputStream.readCred does not use auth data
weijun
parents:
5506
diff
changeset
|
217 |
// |
d14a696e3ab5
7107019: sun.security.krb5.internal.ccache.CCacheInputStream.readCred does not use auth data
weijun
parents:
5506
diff
changeset
|
218 |
// This class is for the initiator side. Also, authdata inside a ccache |
d14a696e3ab5
7107019: sun.security.krb5.internal.ccache.CCacheInputStream.readCred does not use auth data
weijun
parents:
5506
diff
changeset
|
219 |
// is most likely to be the one in Authenticator in PA-TGS-REQ encoded |
d14a696e3ab5
7107019: sun.security.krb5.internal.ccache.CCacheInputStream.readCred does not use auth data
weijun
parents:
5506
diff
changeset
|
220 |
// in TGS-REQ, therefore only stored with a service ticket. Currently |
d14a696e3ab5
7107019: sun.security.krb5.internal.ccache.CCacheInputStream.readCred does not use auth data
weijun
parents:
5506
diff
changeset
|
221 |
// in Java, we only reads TGTs. |
73 | 222 |
return new sun.security.krb5.Credentials(ticket, |
223 |
cname, sname, key, flags, authtime, starttime, endtime, renewTill, caddr); |
|
224 |
} |
|
2 | 225 |
|
226 |
public KerberosTime getAuthTime() { |
|
227 |
return authtime; |
|
228 |
} |
|
229 |
||
230 |
public KerberosTime getEndTime() { |
|
231 |
return endtime; |
|
232 |
} |
|
233 |
||
234 |
public TicketFlags getTicketFlags() { |
|
235 |
return flags; |
|
236 |
} |
|
237 |
||
238 |
public int getEType() { |
|
239 |
return key.getEType(); |
|
240 |
} |
|
241 |
} |