author | weijun |
Fri, 19 Apr 2019 10:22:20 +0800 | |
changeset 58611 | 53ddf218eddd |
parent 58331 | e4ce29f6094e |
child 58679 | 9c3209ff7550 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
57487
643978a35f6e
8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents:
51398
diff
changeset
|
2 |
* Copyright (c) 2000, 2019, 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 |
||
51398
3c389a284345
8209416: Refactoring GetPropertyAction calls in security libs
weijun
parents:
47216
diff
changeset
|
34 |
import sun.security.action.GetPropertyAction; |
2 | 35 |
import sun.security.krb5.internal.*; |
36 |
import sun.security.krb5.internal.ccache.CredentialsCache; |
|
37 |
import sun.security.krb5.internal.crypto.EType; |
|
38 |
import java.io.IOException; |
|
39 |
import java.util.Date; |
|
6122
16fa7ed7ff1b
6867345: Turkish regional options cause NPE in sun.security.x509.AlgorithmId.algOID
xuelei
parents:
5974
diff
changeset
|
40 |
import java.util.Locale; |
2 | 41 |
import java.net.InetAddress; |
42 |
||
43 |
/** |
|
44 |
* This class encapsulates the concept of a Kerberos service |
|
45 |
* credential. That includes a Kerberos ticket and an associated |
|
46 |
* session key. |
|
47 |
*/ |
|
48 |
public class Credentials { |
|
49 |
||
50 |
Ticket ticket; |
|
51 |
PrincipalName client; |
|
57487
643978a35f6e
8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents:
51398
diff
changeset
|
52 |
PrincipalName clientAlias; |
2 | 53 |
PrincipalName server; |
57487
643978a35f6e
8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents:
51398
diff
changeset
|
54 |
PrincipalName serverAlias; |
2 | 55 |
EncryptionKey key; |
56 |
TicketFlags flags; |
|
57 |
KerberosTime authTime; |
|
58 |
KerberosTime startTime; |
|
59 |
KerberosTime endTime; |
|
60 |
KerberosTime renewTill; |
|
61 |
HostAddresses cAddr; |
|
3483
a16fce1820ef
6821190: more InquireType values for ExtendedGSSContext
weijun
parents:
2
diff
changeset
|
62 |
AuthorizationData authzData; |
2 | 63 |
private static boolean DEBUG = Krb5.DEBUG; |
64 |
private static CredentialsCache cache; |
|
65 |
static boolean alreadyLoaded = false; |
|
66 |
private static boolean alreadyTried = false; |
|
19373
4bb12c72a46f
8016594: Native Windows ccache still reads DES tickets
weijun
parents:
14413
diff
changeset
|
67 |
|
58611 | 68 |
private Credentials proxy = null; |
69 |
||
70 |
public Credentials getProxy() { |
|
71 |
return proxy; |
|
72 |
} |
|
73 |
||
74 |
public Credentials setProxy(Credentials proxy) { |
|
75 |
this.proxy = proxy; |
|
76 |
return this; |
|
77 |
} |
|
78 |
||
19373
4bb12c72a46f
8016594: Native Windows ccache still reads DES tickets
weijun
parents:
14413
diff
changeset
|
79 |
// Read native ticket with session key type in the given list |
4bb12c72a46f
8016594: Native Windows ccache still reads DES tickets
weijun
parents:
14413
diff
changeset
|
80 |
private static native Credentials acquireDefaultNativeCreds(int[] eTypes); |
2 | 81 |
|
82 |
public Credentials(Ticket new_ticket, |
|
83 |
PrincipalName new_client, |
|
57487
643978a35f6e
8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents:
51398
diff
changeset
|
84 |
PrincipalName new_client_alias, |
2 | 85 |
PrincipalName new_server, |
57487
643978a35f6e
8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents:
51398
diff
changeset
|
86 |
PrincipalName new_server_alias, |
2 | 87 |
EncryptionKey new_key, |
88 |
TicketFlags new_flags, |
|
89 |
KerberosTime authTime, |
|
90 |
KerberosTime new_startTime, |
|
91 |
KerberosTime new_endTime, |
|
92 |
KerberosTime renewTill, |
|
3483
a16fce1820ef
6821190: more InquireType values for ExtendedGSSContext
weijun
parents:
2
diff
changeset
|
93 |
HostAddresses cAddr, |
a16fce1820ef
6821190: more InquireType values for ExtendedGSSContext
weijun
parents:
2
diff
changeset
|
94 |
AuthorizationData authzData) { |
57487
643978a35f6e
8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents:
51398
diff
changeset
|
95 |
this(new_ticket, new_client, new_client_alias, new_server, |
643978a35f6e
8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents:
51398
diff
changeset
|
96 |
new_server_alias, new_key, new_flags, authTime, |
643978a35f6e
8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents:
51398
diff
changeset
|
97 |
new_startTime, new_endTime, renewTill, cAddr); |
3483
a16fce1820ef
6821190: more InquireType values for ExtendedGSSContext
weijun
parents:
2
diff
changeset
|
98 |
this.authzData = authzData; |
a16fce1820ef
6821190: more InquireType values for ExtendedGSSContext
weijun
parents:
2
diff
changeset
|
99 |
} |
a16fce1820ef
6821190: more InquireType values for ExtendedGSSContext
weijun
parents:
2
diff
changeset
|
100 |
|
58331
e4ce29f6094e
8228659: Record which Java methods are called by native codes in JGSS and JAAS
weijun
parents:
57487
diff
changeset
|
101 |
// Warning: called by NativeCreds.c and nativeccache.c |
3483
a16fce1820ef
6821190: more InquireType values for ExtendedGSSContext
weijun
parents:
2
diff
changeset
|
102 |
public Credentials(Ticket new_ticket, |
a16fce1820ef
6821190: more InquireType values for ExtendedGSSContext
weijun
parents:
2
diff
changeset
|
103 |
PrincipalName new_client, |
57487
643978a35f6e
8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents:
51398
diff
changeset
|
104 |
PrincipalName new_client_alias, |
3483
a16fce1820ef
6821190: more InquireType values for ExtendedGSSContext
weijun
parents:
2
diff
changeset
|
105 |
PrincipalName new_server, |
57487
643978a35f6e
8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents:
51398
diff
changeset
|
106 |
PrincipalName new_server_alias, |
3483
a16fce1820ef
6821190: more InquireType values for ExtendedGSSContext
weijun
parents:
2
diff
changeset
|
107 |
EncryptionKey new_key, |
a16fce1820ef
6821190: more InquireType values for ExtendedGSSContext
weijun
parents:
2
diff
changeset
|
108 |
TicketFlags new_flags, |
a16fce1820ef
6821190: more InquireType values for ExtendedGSSContext
weijun
parents:
2
diff
changeset
|
109 |
KerberosTime authTime, |
a16fce1820ef
6821190: more InquireType values for ExtendedGSSContext
weijun
parents:
2
diff
changeset
|
110 |
KerberosTime new_startTime, |
a16fce1820ef
6821190: more InquireType values for ExtendedGSSContext
weijun
parents:
2
diff
changeset
|
111 |
KerberosTime new_endTime, |
a16fce1820ef
6821190: more InquireType values for ExtendedGSSContext
weijun
parents:
2
diff
changeset
|
112 |
KerberosTime renewTill, |
2 | 113 |
HostAddresses cAddr) { |
114 |
ticket = new_ticket; |
|
115 |
client = new_client; |
|
57487
643978a35f6e
8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents:
51398
diff
changeset
|
116 |
clientAlias = new_client_alias; |
2 | 117 |
server = new_server; |
57487
643978a35f6e
8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents:
51398
diff
changeset
|
118 |
serverAlias = new_server_alias; |
2 | 119 |
key = new_key; |
120 |
flags = new_flags; |
|
121 |
this.authTime = authTime; |
|
122 |
startTime = new_startTime; |
|
123 |
endTime = new_endTime; |
|
124 |
this.renewTill = renewTill; |
|
125 |
this.cAddr = cAddr; |
|
126 |
} |
|
127 |
||
128 |
public Credentials(byte[] encoding, |
|
129 |
String client, |
|
57487
643978a35f6e
8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents:
51398
diff
changeset
|
130 |
String clientAlias, |
2 | 131 |
String server, |
57487
643978a35f6e
8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents:
51398
diff
changeset
|
132 |
String serverAlias, |
2 | 133 |
byte[] keyBytes, |
134 |
int keyType, |
|
135 |
boolean[] flags, |
|
136 |
Date authTime, |
|
137 |
Date startTime, |
|
138 |
Date endTime, |
|
139 |
Date renewTill, |
|
140 |
InetAddress[] cAddrs) throws KrbException, IOException { |
|
141 |
this(new Ticket(encoding), |
|
142 |
new PrincipalName(client, PrincipalName.KRB_NT_PRINCIPAL), |
|
57487
643978a35f6e
8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents:
51398
diff
changeset
|
143 |
(clientAlias == null? null : new PrincipalName(clientAlias, |
643978a35f6e
8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents:
51398
diff
changeset
|
144 |
PrincipalName.KRB_NT_PRINCIPAL)), |
2 | 145 |
new PrincipalName(server, PrincipalName.KRB_NT_SRV_INST), |
57487
643978a35f6e
8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents:
51398
diff
changeset
|
146 |
(serverAlias == null? null : new PrincipalName(serverAlias, |
643978a35f6e
8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents:
51398
diff
changeset
|
147 |
PrincipalName.KRB_NT_SRV_INST)), |
2 | 148 |
new EncryptionKey(keyType, keyBytes), |
149 |
(flags == null? null: new TicketFlags(flags)), |
|
150 |
(authTime == null? null: new KerberosTime(authTime)), |
|
151 |
(startTime == null? null: new KerberosTime(startTime)), |
|
152 |
(endTime == null? null: new KerberosTime(endTime)), |
|
153 |
(renewTill == null? null: new KerberosTime(renewTill)), |
|
154 |
null); // caddrs are in the encoding at this point |
|
155 |
} |
|
156 |
||
157 |
/** |
|
158 |
* Acquires a service ticket for the specified service |
|
159 |
* principal. If the service ticket is not already available, it |
|
160 |
* obtains a new one from the KDC. |
|
161 |
*/ |
|
162 |
/* |
|
163 |
public Credentials(Credentials tgt, PrincipalName service) |
|
164 |
throws KrbException { |
|
165 |
} |
|
166 |
*/ |
|
167 |
||
168 |
public final PrincipalName getClient() { |
|
169 |
return client; |
|
170 |
} |
|
171 |
||
57487
643978a35f6e
8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents:
51398
diff
changeset
|
172 |
public final PrincipalName getClientAlias() { |
643978a35f6e
8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents:
51398
diff
changeset
|
173 |
return clientAlias; |
643978a35f6e
8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents:
51398
diff
changeset
|
174 |
} |
643978a35f6e
8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents:
51398
diff
changeset
|
175 |
|
2 | 176 |
public final PrincipalName getServer() { |
177 |
return server; |
|
178 |
} |
|
179 |
||
57487
643978a35f6e
8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents:
51398
diff
changeset
|
180 |
public final PrincipalName getServerAlias() { |
643978a35f6e
8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents:
51398
diff
changeset
|
181 |
return serverAlias; |
643978a35f6e
8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents:
51398
diff
changeset
|
182 |
} |
643978a35f6e
8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents:
51398
diff
changeset
|
183 |
|
2 | 184 |
public final EncryptionKey getSessionKey() { |
185 |
return key; |
|
186 |
} |
|
187 |
||
188 |
public final Date getAuthTime() { |
|
189 |
if (authTime != null) { |
|
190 |
return authTime.toDate(); |
|
191 |
} else { |
|
192 |
return null; |
|
193 |
} |
|
194 |
} |
|
195 |
||
196 |
public final Date getStartTime() { |
|
197 |
if (startTime != null) |
|
198 |
{ |
|
199 |
return startTime.toDate(); |
|
200 |
} |
|
201 |
return null; |
|
202 |
} |
|
203 |
||
204 |
public final Date getEndTime() { |
|
205 |
if (endTime != null) |
|
206 |
{ |
|
207 |
return endTime.toDate(); |
|
208 |
} |
|
209 |
return null; |
|
210 |
} |
|
211 |
||
212 |
public final Date getRenewTill() { |
|
213 |
if (renewTill != null) |
|
214 |
{ |
|
215 |
return renewTill.toDate(); |
|
216 |
} |
|
217 |
return null; |
|
218 |
} |
|
219 |
||
220 |
public final boolean[] getFlags() { |
|
221 |
if (flags == null) // Can be in a KRB-CRED |
|
222 |
return null; |
|
223 |
return flags.toBooleanArray(); |
|
224 |
} |
|
225 |
||
226 |
public final InetAddress[] getClientAddresses() { |
|
227 |
||
228 |
if (cAddr == null) |
|
229 |
return null; |
|
230 |
||
231 |
return cAddr.getInetAddresses(); |
|
232 |
} |
|
233 |
||
234 |
public final byte[] getEncoded() { |
|
235 |
byte[] retVal = null; |
|
236 |
try { |
|
237 |
retVal = ticket.asn1Encode(); |
|
238 |
} catch (Asn1Exception e) { |
|
239 |
if (DEBUG) |
|
240 |
System.out.println(e); |
|
241 |
} catch (IOException ioe) { |
|
242 |
if (DEBUG) |
|
243 |
System.out.println(ioe); |
|
244 |
} |
|
245 |
return retVal; |
|
246 |
} |
|
247 |
||
248 |
public boolean isForwardable() { |
|
249 |
return flags.get(Krb5.TKT_OPTS_FORWARDABLE); |
|
250 |
} |
|
251 |
||
252 |
public boolean isRenewable() { |
|
253 |
return flags.get(Krb5.TKT_OPTS_RENEWABLE); |
|
254 |
} |
|
255 |
||
256 |
public Ticket getTicket() { |
|
257 |
return ticket; |
|
258 |
} |
|
259 |
||
260 |
public TicketFlags getTicketFlags() { |
|
261 |
return flags; |
|
262 |
} |
|
263 |
||
3483
a16fce1820ef
6821190: more InquireType values for ExtendedGSSContext
weijun
parents:
2
diff
changeset
|
264 |
public AuthorizationData getAuthzData() { |
a16fce1820ef
6821190: more InquireType values for ExtendedGSSContext
weijun
parents:
2
diff
changeset
|
265 |
return authzData; |
a16fce1820ef
6821190: more InquireType values for ExtendedGSSContext
weijun
parents:
2
diff
changeset
|
266 |
} |
2 | 267 |
/** |
268 |
* Checks if the service ticket returned by the KDC has the OK-AS-DELEGATE |
|
269 |
* flag set |
|
270 |
* @return true if OK-AS_DELEGATE flag is set, otherwise, return false. |
|
271 |
*/ |
|
272 |
public boolean checkDelegate() { |
|
4336 | 273 |
return flags.get(Krb5.TKT_OPTS_DELEGATE); |
274 |
} |
|
275 |
||
276 |
/** |
|
277 |
* Reset TKT_OPTS_DELEGATE to false, called at credentials acquirement |
|
278 |
* when one of the cross-realm TGTs does not have the OK-AS-DELEGATE |
|
279 |
* flag set. This info must be preservable and restorable through |
|
280 |
* the Krb5Util.credsToTicket/ticketToCreds() methods so that even if |
|
281 |
* the service ticket is cached it still remembers the cross-realm |
|
282 |
* authentication result. |
|
283 |
*/ |
|
284 |
public void resetDelegate() { |
|
285 |
flags.set(Krb5.TKT_OPTS_DELEGATE, false); |
|
2 | 286 |
} |
287 |
||
288 |
public Credentials renew() throws KrbException, IOException { |
|
289 |
KDCOptions options = new KDCOptions(); |
|
290 |
options.set(KDCOptions.RENEW, true); |
|
291 |
/* |
|
292 |
* Added here to pass KrbKdcRep.check:73 |
|
293 |
*/ |
|
294 |
options.set(KDCOptions.RENEWABLE, true); |
|
295 |
||
296 |
return new KrbTgsReq(options, |
|
297 |
this, |
|
298 |
server, |
|
57487
643978a35f6e
8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents:
51398
diff
changeset
|
299 |
serverAlias, |
2 | 300 |
null, // from |
301 |
null, // till |
|
302 |
null, // rtime |
|
303 |
null, // eTypes |
|
304 |
cAddr, |
|
305 |
null, |
|
306 |
null, |
|
307 |
null).sendAndGetCreds(); |
|
308 |
} |
|
309 |
||
310 |
/** |
|
311 |
* Returns a TGT for the given client principal from a ticket cache. |
|
312 |
* |
|
313 |
* @param princ the client principal. A value of null means that the |
|
314 |
* default principal name in the credentials cache will be used. |
|
315 |
* @param ticketCache the path to the tickets file. A value |
|
316 |
* of null will be accepted to indicate that the default |
|
317 |
* path should be searched |
|
32003 | 318 |
* @return the TGT credentials or null if none were found. If the tgt |
2 | 319 |
* expired, it is the responsibility of the caller to determine this. |
320 |
*/ |
|
321 |
public static Credentials acquireTGTFromCache(PrincipalName princ, |
|
322 |
String ticketCache) |
|
323 |
throws KrbException, IOException { |
|
324 |
||
325 |
if (ticketCache == null) { |
|
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
7183
diff
changeset
|
326 |
// The default ticket cache on Windows and Mac is not a file. |
51398
3c389a284345
8209416: Refactoring GetPropertyAction calls in security libs
weijun
parents:
47216
diff
changeset
|
327 |
String os = GetPropertyAction.privilegedGetProperty("os.name"); |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
7183
diff
changeset
|
328 |
if (os.toUpperCase(Locale.ENGLISH).startsWith("WINDOWS") || |
12538
211d6e82fe51
7130404: [macosx] "os.arch" value should be "x86_64" for compatibility with Apple JDK6
jmelvin
parents:
12423
diff
changeset
|
329 |
os.toUpperCase(Locale.ENGLISH).contains("OS X")) { |
2 | 330 |
Credentials creds = acquireDefaultCreds(); |
331 |
if (creds == null) { |
|
332 |
if (DEBUG) { |
|
333 |
System.out.println(">>> Found no TGT's in LSA"); |
|
334 |
} |
|
335 |
return null; |
|
336 |
} |
|
337 |
if (princ != null) { |
|
338 |
if (creds.getClient().equals(princ)) { |
|
339 |
if (DEBUG) { |
|
340 |
System.out.println(">>> Obtained TGT from LSA: " |
|
341 |
+ creds); |
|
342 |
} |
|
343 |
return creds; |
|
344 |
} else { |
|
345 |
if (DEBUG) { |
|
346 |
System.out.println(">>> LSA contains TGT for " |
|
347 |
+ creds.getClient() |
|
348 |
+ " not " |
|
349 |
+ princ); |
|
350 |
} |
|
351 |
return null; |
|
352 |
} |
|
353 |
} else { |
|
354 |
if (DEBUG) { |
|
355 |
System.out.println(">>> Obtained TGT from LSA: " |
|
356 |
+ creds); |
|
357 |
} |
|
358 |
return creds; |
|
359 |
} |
|
360 |
} |
|
361 |
} |
|
362 |
||
363 |
/* |
|
364 |
* Returns the appropriate cache. If ticketCache is null, it is the |
|
365 |
* default cache otherwise it is the cache filename contained in it. |
|
366 |
*/ |
|
367 |
CredentialsCache ccache = |
|
368 |
CredentialsCache.getInstance(princ, ticketCache); |
|
369 |
||
12423
a69d7fadb9f8
7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents:
12047
diff
changeset
|
370 |
if (ccache == null) { |
2 | 371 |
return null; |
12423
a69d7fadb9f8
7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents:
12047
diff
changeset
|
372 |
} |
2 | 373 |
|
58611 | 374 |
Credentials tgtCred = ccache.getInitialCreds(); |
2 | 375 |
|
12423
a69d7fadb9f8
7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents:
12047
diff
changeset
|
376 |
if (tgtCred == null) { |
a69d7fadb9f8
7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents:
12047
diff
changeset
|
377 |
return null; |
a69d7fadb9f8
7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents:
12047
diff
changeset
|
378 |
} |
a69d7fadb9f8
7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents:
12047
diff
changeset
|
379 |
|
58611 | 380 |
if (EType.isSupported(tgtCred.key.getEType())) { |
381 |
return tgtCred; |
|
2 | 382 |
} else { |
383 |
if (DEBUG) { |
|
384 |
System.out.println( |
|
385 |
">>> unsupported key type found the default TGT: " + |
|
58611 | 386 |
tgtCred.key.getEType()); |
2 | 387 |
} |
388 |
return null; |
|
389 |
} |
|
390 |
} |
|
391 |
||
392 |
/** |
|
393 |
* Acquires default credentials. |
|
394 |
* <br>The possible locations for default credentials cache is searched in |
|
395 |
* the following order: |
|
396 |
* <ol> |
|
397 |
* <li> The directory and cache file name specified by "KRB5CCNAME" system. |
|
398 |
* property. |
|
399 |
* <li> The directory and cache file name specified by "KRB5CCNAME" |
|
400 |
* environment variable. |
|
401 |
* <li> A cache file named krb5cc_{user.name} at {user.home} directory. |
|
402 |
* </ol> |
|
403 |
* @return a <code>KrbCreds</code> object if the credential is found, |
|
404 |
* otherwise return null. |
|
405 |
*/ |
|
406 |
||
407 |
// this method is intentionally changed to not check if the caller's |
|
408 |
// principal name matches cache file's principal name. |
|
409 |
// It assumes that the GSS call has |
|
410 |
// the privilege to access the default cache file. |
|
411 |
||
19373
4bb12c72a46f
8016594: Native Windows ccache still reads DES tickets
weijun
parents:
14413
diff
changeset
|
412 |
// This method is only called on Windows and Mac OS X, the native |
4bb12c72a46f
8016594: Native Windows ccache still reads DES tickets
weijun
parents:
14413
diff
changeset
|
413 |
// acquireDefaultNativeCreds is also available on these platforms. |
2 | 414 |
public static synchronized Credentials acquireDefaultCreds() { |
415 |
Credentials result = null; |
|
416 |
||
417 |
if (cache == null) { |
|
418 |
cache = CredentialsCache.getInstance(); |
|
419 |
} |
|
420 |
if (cache != null) { |
|
58611 | 421 |
Credentials temp = cache.getInitialCreds(); |
12423
a69d7fadb9f8
7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents:
12047
diff
changeset
|
422 |
if (temp != null) { |
2 | 423 |
if (DEBUG) { |
12423
a69d7fadb9f8
7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents:
12047
diff
changeset
|
424 |
System.out.println(">>> KrbCreds found the default ticket" |
a69d7fadb9f8
7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents:
12047
diff
changeset
|
425 |
+ " granting ticket in credential cache."); |
a69d7fadb9f8
7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents:
12047
diff
changeset
|
426 |
} |
58611 | 427 |
if (EType.isSupported(temp.key.getEType())) { |
428 |
result = temp; |
|
12423
a69d7fadb9f8
7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents:
12047
diff
changeset
|
429 |
} else { |
a69d7fadb9f8
7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents:
12047
diff
changeset
|
430 |
if (DEBUG) { |
a69d7fadb9f8
7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents:
12047
diff
changeset
|
431 |
System.out.println( |
a69d7fadb9f8
7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents:
12047
diff
changeset
|
432 |
">>> unsupported key type found the default TGT: " + |
58611 | 433 |
temp.key.getEType()); |
12423
a69d7fadb9f8
7158329: NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
weijun
parents:
12047
diff
changeset
|
434 |
} |
2 | 435 |
} |
436 |
} |
|
437 |
} |
|
438 |
if (result == null) { |
|
439 |
// Doesn't seem to be a default cache on this system or |
|
440 |
// TGT has unsupported encryption type |
|
441 |
||
442 |
if (!alreadyTried) { |
|
443 |
// See if there's any native code to load |
|
444 |
try { |
|
445 |
ensureLoaded(); |
|
446 |
} catch (Exception e) { |
|
447 |
if (DEBUG) { |
|
448 |
System.out.println("Can not load credentials cache"); |
|
449 |
e.printStackTrace(); |
|
450 |
} |
|
451 |
alreadyTried = true; |
|
452 |
} |
|
453 |
} |
|
454 |
if (alreadyLoaded) { |
|
455 |
// There is some native code |
|
19373
4bb12c72a46f
8016594: Native Windows ccache still reads DES tickets
weijun
parents:
14413
diff
changeset
|
456 |
if (DEBUG) { |
4bb12c72a46f
8016594: Native Windows ccache still reads DES tickets
weijun
parents:
14413
diff
changeset
|
457 |
System.out.println(">> Acquire default native Credentials"); |
4bb12c72a46f
8016594: Native Windows ccache still reads DES tickets
weijun
parents:
14413
diff
changeset
|
458 |
} |
4bb12c72a46f
8016594: Native Windows ccache still reads DES tickets
weijun
parents:
14413
diff
changeset
|
459 |
try { |
4bb12c72a46f
8016594: Native Windows ccache still reads DES tickets
weijun
parents:
14413
diff
changeset
|
460 |
result = acquireDefaultNativeCreds( |
4bb12c72a46f
8016594: Native Windows ccache still reads DES tickets
weijun
parents:
14413
diff
changeset
|
461 |
EType.getDefaults("default_tkt_enctypes")); |
4bb12c72a46f
8016594: Native Windows ccache still reads DES tickets
weijun
parents:
14413
diff
changeset
|
462 |
} catch (KrbException ke) { |
4bb12c72a46f
8016594: Native Windows ccache still reads DES tickets
weijun
parents:
14413
diff
changeset
|
463 |
// when there is no default_tkt_enctypes. |
4bb12c72a46f
8016594: Native Windows ccache still reads DES tickets
weijun
parents:
14413
diff
changeset
|
464 |
} |
2 | 465 |
} |
466 |
} |
|
467 |
return result; |
|
468 |
} |
|
469 |
||
470 |
/** |
|
471 |
* Acquires credentials for a specified service using initial credential. |
|
472 |
* When the service has a different realm |
|
473 |
* from the initial credential, we do cross-realm authentication |
|
474 |
* - first, we use the current credential to get |
|
475 |
* a cross-realm credential from the local KDC, then use that |
|
476 |
* cross-realm credential to request service credential |
|
477 |
* from the foreigh KDC. |
|
478 |
* |
|
479 |
* @param service the name of service principal using format |
|
480 |
* components@realm |
|
481 |
* @param ccreds client's initial credential. |
|
482 |
* @exception IOException if an error occurs in reading the credentials |
|
483 |
* cache |
|
484 |
* @exception KrbException if an error occurs specific to Kerberos |
|
485 |
* @return a <code>Credentials</code> object. |
|
486 |
*/ |
|
487 |
||
488 |
public static Credentials acquireServiceCreds(String service, |
|
489 |
Credentials ccreds) |
|
490 |
throws KrbException, IOException { |
|
491 |
return CredentialsUtil.acquireServiceCreds(service, ccreds); |
|
492 |
} |
|
493 |
||
14413
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
13247
diff
changeset
|
494 |
public static Credentials acquireS4U2selfCreds(PrincipalName user, |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
13247
diff
changeset
|
495 |
Credentials ccreds) throws KrbException, IOException { |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
13247
diff
changeset
|
496 |
return CredentialsUtil.acquireS4U2selfCreds(user, ccreds); |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
13247
diff
changeset
|
497 |
} |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
13247
diff
changeset
|
498 |
|
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
13247
diff
changeset
|
499 |
public static Credentials acquireS4U2proxyCreds(String service, |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
13247
diff
changeset
|
500 |
Ticket second, PrincipalName client, Credentials ccreds) |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
13247
diff
changeset
|
501 |
throws KrbException, IOException { |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
13247
diff
changeset
|
502 |
return CredentialsUtil.acquireS4U2proxyCreds( |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
13247
diff
changeset
|
503 |
service, second, client, ccreds); |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
13247
diff
changeset
|
504 |
} |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
13247
diff
changeset
|
505 |
|
2 | 506 |
public CredentialsCache getCache() { |
507 |
return cache; |
|
508 |
} |
|
509 |
||
510 |
/* |
|
511 |
* Prints out debug info. |
|
512 |
*/ |
|
513 |
public static void printDebug(Credentials c) { |
|
514 |
System.out.println(">>> DEBUG: ----Credentials----"); |
|
515 |
System.out.println("\tclient: " + c.client.toString()); |
|
57487
643978a35f6e
8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents:
51398
diff
changeset
|
516 |
if (c.clientAlias != null) |
643978a35f6e
8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents:
51398
diff
changeset
|
517 |
System.out.println("\tclient alias: " + c.clientAlias.toString()); |
2 | 518 |
System.out.println("\tserver: " + c.server.toString()); |
57487
643978a35f6e
8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents:
51398
diff
changeset
|
519 |
if (c.serverAlias != null) |
643978a35f6e
8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents:
51398
diff
changeset
|
520 |
System.out.println("\tserver alias: " + c.serverAlias.toString()); |
13247 | 521 |
System.out.println("\tticket: sname: " + c.ticket.sname.toString()); |
2 | 522 |
if (c.startTime != null) { |
523 |
System.out.println("\tstartTime: " + c.startTime.getTime()); |
|
524 |
} |
|
525 |
System.out.println("\tendTime: " + c.endTime.getTime()); |
|
526 |
System.out.println(" ----Credentials end----"); |
|
527 |
} |
|
528 |
||
529 |
||
530 |
static void ensureLoaded() { |
|
531 |
java.security.AccessController.doPrivileged( |
|
532 |
new java.security.PrivilegedAction<Void> () { |
|
533 |
public Void run() { |
|
12538
211d6e82fe51
7130404: [macosx] "os.arch" value should be "x86_64" for compatibility with Apple JDK6
jmelvin
parents:
12423
diff
changeset
|
534 |
if (System.getProperty("os.name").contains("OS X")) { |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
7183
diff
changeset
|
535 |
System.loadLibrary("osxkrb5"); |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
7183
diff
changeset
|
536 |
} else { |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
7183
diff
changeset
|
537 |
System.loadLibrary("w2k_lsa_auth"); |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
7183
diff
changeset
|
538 |
} |
2 | 539 |
return null; |
540 |
} |
|
541 |
}); |
|
542 |
alreadyLoaded = true; |
|
543 |
} |
|
544 |
||
545 |
public String toString() { |
|
24969
afa6934dd8e8
8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents:
23010
diff
changeset
|
546 |
StringBuilder sb = new StringBuilder("Credentials:"); |
afa6934dd8e8
8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents:
23010
diff
changeset
|
547 |
sb.append( "\n client=").append(client); |
57487
643978a35f6e
8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents:
51398
diff
changeset
|
548 |
if (clientAlias != null) |
643978a35f6e
8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents:
51398
diff
changeset
|
549 |
sb.append( "\n clientAlias=").append(clientAlias); |
24969
afa6934dd8e8
8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents:
23010
diff
changeset
|
550 |
sb.append( "\n server=").append(server); |
57487
643978a35f6e
8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents:
51398
diff
changeset
|
551 |
if (serverAlias != null) |
643978a35f6e
8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents:
51398
diff
changeset
|
552 |
sb.append( "\n serverAlias=").append(serverAlias); |
2 | 553 |
if (authTime != null) { |
24969
afa6934dd8e8
8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents:
23010
diff
changeset
|
554 |
sb.append("\n authTime=").append(authTime); |
2 | 555 |
} |
556 |
if (startTime != null) { |
|
24969
afa6934dd8e8
8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents:
23010
diff
changeset
|
557 |
sb.append("\n startTime=").append(startTime); |
2 | 558 |
} |
24969
afa6934dd8e8
8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents:
23010
diff
changeset
|
559 |
sb.append( "\n endTime=").append(endTime); |
afa6934dd8e8
8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents:
23010
diff
changeset
|
560 |
sb.append( "\n renewTill=").append(renewTill); |
afa6934dd8e8
8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents:
23010
diff
changeset
|
561 |
sb.append( "\n flags=").append(flags); |
afa6934dd8e8
8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents:
23010
diff
changeset
|
562 |
sb.append( "\nEType (skey)=").append(key.getEType()); |
afa6934dd8e8
8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents:
23010
diff
changeset
|
563 |
sb.append( "\n (tkt key)=").append(ticket.encPart.eType); |
afa6934dd8e8
8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents:
23010
diff
changeset
|
564 |
return sb.toString(); |
2 | 565 |
} |
566 |
||
27946
9f99b93cbbb2
8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents:
25859
diff
changeset
|
567 |
public sun.security.krb5.internal.ccache.Credentials toCCacheCreds() { |
9f99b93cbbb2
8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents:
25859
diff
changeset
|
568 |
return new sun.security.krb5.internal.ccache.Credentials( |
9f99b93cbbb2
8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents:
25859
diff
changeset
|
569 |
getClient(), getServer(), |
9f99b93cbbb2
8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents:
25859
diff
changeset
|
570 |
getSessionKey(), |
9f99b93cbbb2
8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents:
25859
diff
changeset
|
571 |
date2kt(getAuthTime()), |
9f99b93cbbb2
8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents:
25859
diff
changeset
|
572 |
date2kt(getStartTime()), |
9f99b93cbbb2
8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents:
25859
diff
changeset
|
573 |
date2kt(getEndTime()), |
9f99b93cbbb2
8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents:
25859
diff
changeset
|
574 |
date2kt(getRenewTill()), |
9f99b93cbbb2
8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents:
25859
diff
changeset
|
575 |
false, |
9f99b93cbbb2
8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents:
25859
diff
changeset
|
576 |
flags, |
9f99b93cbbb2
8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents:
25859
diff
changeset
|
577 |
new HostAddresses(getClientAddresses()), |
9f99b93cbbb2
8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents:
25859
diff
changeset
|
578 |
getAuthzData(), |
9f99b93cbbb2
8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents:
25859
diff
changeset
|
579 |
getTicket(), |
9f99b93cbbb2
8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents:
25859
diff
changeset
|
580 |
null); |
9f99b93cbbb2
8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents:
25859
diff
changeset
|
581 |
} |
9f99b93cbbb2
8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents:
25859
diff
changeset
|
582 |
|
9f99b93cbbb2
8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents:
25859
diff
changeset
|
583 |
private static KerberosTime date2kt(Date d) { |
9f99b93cbbb2
8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents:
25859
diff
changeset
|
584 |
return d == null ? null : new KerberosTime(d); |
9f99b93cbbb2
8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents:
25859
diff
changeset
|
585 |
} |
2 | 586 |
} |