author | mbalao |
Wed, 17 Jul 2019 12:26:56 -0300 | |
changeset 57487 | 643978a35f6e |
parent 47216 | 71c04702a3d5 |
child 58611 | 53ddf218eddd |
permissions | -rw-r--r-- |
2 | 1 |
/* |
57487
643978a35f6e
8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents:
47216
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 |
package javax.security.auth.kerberos; |
|
27 |
||
28 |
import java.io.*; |
|
29 |
import java.util.Date; |
|
30 |
import java.util.Arrays; |
|
31 |
import java.net.InetAddress; |
|
32 |
import javax.crypto.SecretKey; |
|
33 |
import javax.security.auth.Refreshable; |
|
34 |
import javax.security.auth.Destroyable; |
|
35 |
import javax.security.auth.RefreshFailedException; |
|
36 |
import javax.security.auth.DestroyFailedException; |
|
34687
d302ed125dc9
8144995: Move sun.misc.HexDumpEncoder to sun.security.util
chegar
parents:
28059
diff
changeset
|
37 |
import sun.security.util.HexDumpEncoder; |
2 | 38 |
|
39 |
/** |
|
40 |
* This class encapsulates a Kerberos ticket and associated |
|
41 |
* information as viewed from the client's point of view. It captures all |
|
42 |
* information that the Key Distribution Center (KDC) sends to the client |
|
43 |
* in the reply message KDC-REP defined in the Kerberos Protocol |
|
44 |
* Specification (<a href=http://www.ietf.org/rfc/rfc4120.txt>RFC 4120</a>). |
|
45 |
* <p> |
|
46 |
* All Kerberos JAAS login modules that authenticate a user to a KDC should |
|
47 |
* use this class. Where available, the login module might even read this |
|
48 |
* information from a ticket cache in the operating system instead of |
|
49 |
* directly communicating with the KDC. During the commit phase of the JAAS |
|
50 |
* authentication process, the JAAS login module should instantiate this |
|
51 |
* class and store the instance in the private credential set of a |
|
52 |
* {@link javax.security.auth.Subject Subject}.<p> |
|
53 |
* |
|
54 |
* It might be necessary for the application to be granted a |
|
55 |
* {@link javax.security.auth.PrivateCredentialPermission |
|
27771
360714d431ab
8061253: Spec cleanup for some security-related classes
weijun
parents:
25859
diff
changeset
|
56 |
* PrivateCredentialPermission} if it needs to access a {@code KerberosTicket} |
360714d431ab
8061253: Spec cleanup for some security-related classes
weijun
parents:
25859
diff
changeset
|
57 |
* instance from a {@code Subject}. This permission is not needed when the |
2 | 58 |
* application depends on the default JGSS Kerberos mechanism to access the |
27771
360714d431ab
8061253: Spec cleanup for some security-related classes
weijun
parents:
25859
diff
changeset
|
59 |
* {@code KerberosTicket}. In that case, however, the application will need an |
2 | 60 |
* appropriate |
61 |
* {@link javax.security.auth.kerberos.ServicePermission ServicePermission}. |
|
62 |
* <p> |
|
63 |
* Note that this class is applicable to both ticket granting tickets and |
|
64 |
* other regular service tickets. A ticket granting ticket is just a |
|
65 |
* special case of a more generalized service ticket. |
|
66 |
* |
|
35999
b6bf26e04451
8147772: Update KerberosTicket to describe behavior if it has been destroyed and fix NullPointerExceptions
weijun
parents:
34687
diff
changeset
|
67 |
* @implNote The JAAS login module in the JDK reference implementation destroys |
b6bf26e04451
8147772: Update KerberosTicket to describe behavior if it has been destroyed and fix NullPointerExceptions
weijun
parents:
34687
diff
changeset
|
68 |
* all tickets after logout. |
b6bf26e04451
8147772: Update KerberosTicket to describe behavior if it has been destroyed and fix NullPointerExceptions
weijun
parents:
34687
diff
changeset
|
69 |
* |
2 | 70 |
* @see javax.security.auth.Subject |
71 |
* @see javax.security.auth.PrivateCredentialPermission |
|
72 |
* @see javax.security.auth.login.LoginContext |
|
73 |
* @see org.ietf.jgss.GSSCredential |
|
74 |
* @see org.ietf.jgss.GSSManager |
|
75 |
* |
|
76 |
* @author Mayank Upadhyay |
|
77 |
* @since 1.4 |
|
78 |
*/ |
|
79 |
public class KerberosTicket implements Destroyable, Refreshable, |
|
80 |
java.io.Serializable { |
|
81 |
||
82 |
private static final long serialVersionUID = 7395334370157380539L; |
|
83 |
||
84 |
// XXX Make these flag indices public |
|
85 |
private static final int FORWARDABLE_TICKET_FLAG = 1; |
|
86 |
private static final int FORWARDED_TICKET_FLAG = 2; |
|
87 |
private static final int PROXIABLE_TICKET_FLAG = 3; |
|
88 |
private static final int PROXY_TICKET_FLAG = 4; |
|
89 |
private static final int POSTDATED_TICKET_FLAG = 6; |
|
90 |
private static final int RENEWABLE_TICKET_FLAG = 8; |
|
91 |
private static final int INITIAL_TICKET_FLAG = 9; |
|
92 |
||
93 |
private static final int NUM_FLAGS = 32; |
|
94 |
||
95 |
/** |
|
96 |
* |
|
97 |
* ASN.1 DER Encoding of the Ticket as defined in the |
|
98 |
* Kerberos Protocol Specification RFC4120. |
|
99 |
* |
|
100 |
* @serial |
|
101 |
*/ |
|
102 |
||
103 |
private byte[] asn1Encoding; |
|
104 |
||
105 |
/** |
|
18830 | 106 |
*{@code KeyImpl} is serialized by writing out the ASN1 Encoded bytes |
2 | 107 |
* of the encryption key. The ASN1 encoding is defined in RFC4120 and as |
108 |
* follows: |
|
109 |
* <pre> |
|
110 |
* EncryptionKey ::= SEQUENCE { |
|
111 |
* keytype [0] Int32 -- actually encryption type --, |
|
112 |
* keyvalue [1] OCTET STRING |
|
113 |
* } |
|
114 |
* </pre> |
|
115 |
* |
|
116 |
* @serial |
|
117 |
*/ |
|
118 |
||
119 |
private KeyImpl sessionKey; |
|
120 |
||
121 |
/** |
|
122 |
* |
|
123 |
* Ticket Flags as defined in the Kerberos Protocol Specification RFC4120. |
|
124 |
* |
|
125 |
* @serial |
|
126 |
*/ |
|
127 |
||
128 |
private boolean[] flags; |
|
129 |
||
130 |
/** |
|
131 |
* |
|
132 |
* Time of initial authentication |
|
133 |
* |
|
134 |
* @serial |
|
135 |
*/ |
|
136 |
||
137 |
private Date authTime; |
|
138 |
||
139 |
/** |
|
140 |
* |
|
141 |
* Time after which the ticket is valid. |
|
142 |
* @serial |
|
143 |
*/ |
|
144 |
private Date startTime; |
|
145 |
||
146 |
/** |
|
147 |
* |
|
148 |
* Time after which the ticket will not be honored. (its expiration time). |
|
149 |
* |
|
150 |
* @serial |
|
151 |
*/ |
|
152 |
||
153 |
private Date endTime; |
|
154 |
||
155 |
/** |
|
156 |
* |
|
157 |
* For renewable Tickets it indicates the maximum endtime that may be |
|
158 |
* included in a renewal. It can be thought of as the absolute expiration |
|
159 |
* time for the ticket, including all renewals. This field may be null |
|
160 |
* for tickets that are not renewable. |
|
161 |
* |
|
162 |
* @serial |
|
163 |
*/ |
|
164 |
||
165 |
private Date renewTill; |
|
166 |
||
167 |
/** |
|
168 |
* |
|
169 |
* Client that owns the service ticket |
|
170 |
* |
|
171 |
* @serial |
|
172 |
*/ |
|
173 |
||
174 |
private KerberosPrincipal client; |
|
175 |
||
176 |
/** |
|
177 |
* |
|
178 |
* The service for which the ticket was issued. |
|
179 |
* |
|
180 |
* @serial |
|
181 |
*/ |
|
182 |
||
183 |
private KerberosPrincipal server; |
|
184 |
||
185 |
/** |
|
186 |
* |
|
187 |
* The addresses from where the ticket may be used by the client. |
|
188 |
* This field may be null when the ticket is usable from any address. |
|
189 |
* |
|
190 |
* @serial |
|
191 |
*/ |
|
192 |
||
193 |
||
194 |
private InetAddress[] clientAddresses; |
|
195 |
||
196 |
private transient boolean destroyed = false; |
|
197 |
||
57487
643978a35f6e
8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents:
47216
diff
changeset
|
198 |
transient KerberosPrincipal clientAlias = null; |
643978a35f6e
8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents:
47216
diff
changeset
|
199 |
|
643978a35f6e
8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents:
47216
diff
changeset
|
200 |
transient KerberosPrincipal serverAlias = null; |
643978a35f6e
8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents:
47216
diff
changeset
|
201 |
|
2 | 202 |
/** |
27771
360714d431ab
8061253: Spec cleanup for some security-related classes
weijun
parents:
25859
diff
changeset
|
203 |
* Constructs a {@code KerberosTicket} using credentials information that a |
2 | 204 |
* client either receives from a KDC or reads from a cache. |
205 |
* |
|
206 |
* @param asn1Encoding the ASN.1 encoding of the ticket as defined by |
|
207 |
* the Kerberos protocol specification. |
|
208 |
* @param client the client that owns this service |
|
209 |
* ticket |
|
210 |
* @param server the service that this ticket is for |
|
211 |
* @param sessionKey the raw bytes for the session key that must be |
|
212 |
* used to encrypt the authenticator that will be sent to the server |
|
213 |
* @param keyType the key type for the session key as defined by the |
|
214 |
* Kerberos protocol specification. |
|
215 |
* @param flags the ticket flags. Each element in this array indicates |
|
216 |
* the value for the corresponding bit in the ASN.1 BitString that |
|
217 |
* represents the ticket flags. If the number of elements in this array |
|
218 |
* is less than the number of flags used by the Kerberos protocol, |
|
219 |
* then the missing flags will be filled in with false. |
|
220 |
* @param authTime the time of initial authentication for the client |
|
221 |
* @param startTime the time after which the ticket will be valid. This |
|
222 |
* may be null in which case the value of authTime is treated as the |
|
223 |
* startTime. |
|
224 |
* @param endTime the time after which the ticket will no longer be |
|
225 |
* valid |
|
226 |
* @param renewTill an absolute expiration time for the ticket, |
|
227 |
* including all renewal that might be possible. This field may be null |
|
228 |
* for tickets that are not renewable. |
|
229 |
* @param clientAddresses the addresses from where the ticket may be |
|
230 |
* used by the client. This field may be null when the ticket is usable |
|
231 |
* from any address. |
|
232 |
*/ |
|
233 |
public KerberosTicket(byte[] asn1Encoding, |
|
234 |
KerberosPrincipal client, |
|
235 |
KerberosPrincipal server, |
|
236 |
byte[] sessionKey, |
|
237 |
int keyType, |
|
238 |
boolean[] flags, |
|
239 |
Date authTime, |
|
240 |
Date startTime, |
|
241 |
Date endTime, |
|
242 |
Date renewTill, |
|
243 |
InetAddress[] clientAddresses) { |
|
244 |
||
245 |
init(asn1Encoding, client, server, sessionKey, keyType, flags, |
|
246 |
authTime, startTime, endTime, renewTill, clientAddresses); |
|
247 |
} |
|
248 |
||
249 |
private void init(byte[] asn1Encoding, |
|
250 |
KerberosPrincipal client, |
|
251 |
KerberosPrincipal server, |
|
252 |
byte[] sessionKey, |
|
253 |
int keyType, |
|
254 |
boolean[] flags, |
|
255 |
Date authTime, |
|
256 |
Date startTime, |
|
257 |
Date endTime, |
|
258 |
Date renewTill, |
|
259 |
InetAddress[] clientAddresses) { |
|
25661
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
260 |
if (sessionKey == null) { |
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
261 |
throw new IllegalArgumentException("Session key for ticket" |
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
262 |
+ " cannot be null"); |
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
263 |
} |
488
5e84e13e8892
6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents:
51
diff
changeset
|
264 |
init(asn1Encoding, client, server, |
5e84e13e8892
6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents:
51
diff
changeset
|
265 |
new KeyImpl(sessionKey, keyType), flags, authTime, |
5e84e13e8892
6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents:
51
diff
changeset
|
266 |
startTime, endTime, renewTill, clientAddresses); |
5e84e13e8892
6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents:
51
diff
changeset
|
267 |
} |
2 | 268 |
|
488
5e84e13e8892
6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents:
51
diff
changeset
|
269 |
private void init(byte[] asn1Encoding, |
5e84e13e8892
6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents:
51
diff
changeset
|
270 |
KerberosPrincipal client, |
5e84e13e8892
6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents:
51
diff
changeset
|
271 |
KerberosPrincipal server, |
5e84e13e8892
6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents:
51
diff
changeset
|
272 |
KeyImpl sessionKey, |
5e84e13e8892
6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents:
51
diff
changeset
|
273 |
boolean[] flags, |
5e84e13e8892
6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents:
51
diff
changeset
|
274 |
Date authTime, |
5e84e13e8892
6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents:
51
diff
changeset
|
275 |
Date startTime, |
5e84e13e8892
6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents:
51
diff
changeset
|
276 |
Date endTime, |
5e84e13e8892
6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents:
51
diff
changeset
|
277 |
Date renewTill, |
5e84e13e8892
6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents:
51
diff
changeset
|
278 |
InetAddress[] clientAddresses) { |
25661
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
279 |
if (asn1Encoding == null) { |
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
280 |
throw new IllegalArgumentException("ASN.1 encoding of ticket" |
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
281 |
+ " cannot be null"); |
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
282 |
} |
2 | 283 |
this.asn1Encoding = asn1Encoding.clone(); |
284 |
||
25661
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
285 |
if (client == null) { |
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
286 |
throw new IllegalArgumentException("Client name in ticket" |
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
287 |
+ " cannot be null"); |
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
288 |
} |
2 | 289 |
this.client = client; |
290 |
||
25661
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
291 |
if (server == null) { |
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
292 |
throw new IllegalArgumentException("Server name in ticket" |
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
293 |
+ " cannot be null"); |
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
294 |
} |
2 | 295 |
this.server = server; |
296 |
||
488
5e84e13e8892
6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents:
51
diff
changeset
|
297 |
// Caller needs to make sure `sessionKey` will not be null |
5e84e13e8892
6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents:
51
diff
changeset
|
298 |
this.sessionKey = sessionKey; |
2 | 299 |
|
300 |
if (flags != null) { |
|
25661
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
301 |
if (flags.length >= NUM_FLAGS) { |
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
302 |
this.flags = flags.clone(); |
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
303 |
} else { |
2 | 304 |
this.flags = new boolean[NUM_FLAGS]; |
305 |
// Fill in whatever we have |
|
25661
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
306 |
for (int i = 0; i < flags.length; i++) { |
2 | 307 |
this.flags[i] = flags[i]; |
25661
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
308 |
} |
2 | 309 |
} |
25661
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
310 |
} else { |
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
311 |
this.flags = new boolean[NUM_FLAGS]; |
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
312 |
} |
2 | 313 |
|
47005
dbfaf076da58
8186576: KerberosTicket does not properly handle renewable tickets at the end of their lifetime
weijun
parents:
41586
diff
changeset
|
314 |
if (this.flags[RENEWABLE_TICKET_FLAG] && renewTill != null) { |
488
5e84e13e8892
6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents:
51
diff
changeset
|
315 |
this.renewTill = new Date(renewTill.getTime()); |
2 | 316 |
} |
317 |
||
488
5e84e13e8892
6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents:
51
diff
changeset
|
318 |
if (authTime != null) { |
5e84e13e8892
6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents:
51
diff
changeset
|
319 |
this.authTime = new Date(authTime.getTime()); |
5e84e13e8892
6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents:
51
diff
changeset
|
320 |
} |
5e84e13e8892
6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents:
51
diff
changeset
|
321 |
if (startTime != null) { |
5e84e13e8892
6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents:
51
diff
changeset
|
322 |
this.startTime = new Date(startTime.getTime()); |
5e84e13e8892
6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents:
51
diff
changeset
|
323 |
} else { |
5e84e13e8892
6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents:
51
diff
changeset
|
324 |
this.startTime = this.authTime; |
5e84e13e8892
6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents:
51
diff
changeset
|
325 |
} |
2 | 326 |
|
25661
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
327 |
if (endTime == null) { |
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
328 |
throw new IllegalArgumentException("End time for ticket validity" |
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
329 |
+ " cannot be null"); |
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
330 |
} |
488
5e84e13e8892
6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents:
51
diff
changeset
|
331 |
this.endTime = new Date(endTime.getTime()); |
2 | 332 |
|
25661
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
333 |
if (clientAddresses != null) { |
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
334 |
this.clientAddresses = clientAddresses.clone(); |
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
335 |
} |
2 | 336 |
} |
337 |
||
338 |
/** |
|
339 |
* Returns the client principal associated with this ticket. |
|
340 |
* |
|
35999
b6bf26e04451
8147772: Update KerberosTicket to describe behavior if it has been destroyed and fix NullPointerExceptions
weijun
parents:
34687
diff
changeset
|
341 |
* @return the client principal, or {@code null} if destroyed. |
2 | 342 |
*/ |
343 |
public final KerberosPrincipal getClient() { |
|
344 |
return client; |
|
345 |
} |
|
346 |
||
347 |
/** |
|
348 |
* Returns the service principal associated with this ticket. |
|
349 |
* |
|
35999
b6bf26e04451
8147772: Update KerberosTicket to describe behavior if it has been destroyed and fix NullPointerExceptions
weijun
parents:
34687
diff
changeset
|
350 |
* @return the service principal, or {@code null} if destroyed. |
2 | 351 |
*/ |
352 |
public final KerberosPrincipal getServer() { |
|
353 |
return server; |
|
354 |
} |
|
355 |
||
356 |
/** |
|
25661
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
357 |
* Returns the session key associated with this ticket. The return value |
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
358 |
* is always a {@link EncryptionKey} object. |
2 | 359 |
* |
360 |
* @return the session key. |
|
35999
b6bf26e04451
8147772: Update KerberosTicket to describe behavior if it has been destroyed and fix NullPointerExceptions
weijun
parents:
34687
diff
changeset
|
361 |
* @throws IllegalStateException if this ticket is destroyed |
2 | 362 |
*/ |
363 |
public final SecretKey getSessionKey() { |
|
25661
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
364 |
if (destroyed) { |
2 | 365 |
throw new IllegalStateException("This ticket is no longer valid"); |
25661
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
366 |
} |
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
367 |
return new EncryptionKey( |
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
368 |
sessionKey.getEncoded(), sessionKey.getKeyType()); |
2 | 369 |
} |
370 |
||
371 |
/** |
|
372 |
* Returns the key type of the session key associated with this |
|
373 |
* ticket as defined by the Kerberos Protocol Specification. |
|
374 |
* |
|
375 |
* @return the key type of the session key associated with this |
|
376 |
* ticket. |
|
35999
b6bf26e04451
8147772: Update KerberosTicket to describe behavior if it has been destroyed and fix NullPointerExceptions
weijun
parents:
34687
diff
changeset
|
377 |
* @throws IllegalStateException if this ticket is destroyed |
2 | 378 |
* |
379 |
* @see #getSessionKey() |
|
380 |
*/ |
|
381 |
public final int getSessionKeyType() { |
|
25661
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
382 |
if (destroyed) { |
2 | 383 |
throw new IllegalStateException("This ticket is no longer valid"); |
25661
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
384 |
} |
2 | 385 |
return sessionKey.getKeyType(); |
386 |
} |
|
387 |
||
388 |
/** |
|
389 |
* Determines if this ticket is forwardable. |
|
390 |
* |
|
35999
b6bf26e04451
8147772: Update KerberosTicket to describe behavior if it has been destroyed and fix NullPointerExceptions
weijun
parents:
34687
diff
changeset
|
391 |
* @return true if this ticket is forwardable, or false if not forwardable |
b6bf26e04451
8147772: Update KerberosTicket to describe behavior if it has been destroyed and fix NullPointerExceptions
weijun
parents:
34687
diff
changeset
|
392 |
* or destroyed. |
2 | 393 |
*/ |
394 |
public final boolean isForwardable() { |
|
35999
b6bf26e04451
8147772: Update KerberosTicket to describe behavior if it has been destroyed and fix NullPointerExceptions
weijun
parents:
34687
diff
changeset
|
395 |
return flags == null? false: flags[FORWARDABLE_TICKET_FLAG]; |
2 | 396 |
} |
397 |
||
398 |
/** |
|
399 |
* Determines if this ticket had been forwarded or was issued based on |
|
400 |
* authentication involving a forwarded ticket-granting ticket. |
|
401 |
* |
|
402 |
* @return true if this ticket had been forwarded or was issued based on |
|
403 |
* authentication involving a forwarded ticket-granting ticket, |
|
35999
b6bf26e04451
8147772: Update KerberosTicket to describe behavior if it has been destroyed and fix NullPointerExceptions
weijun
parents:
34687
diff
changeset
|
404 |
* or false otherwise or destroyed. |
2 | 405 |
*/ |
406 |
public final boolean isForwarded() { |
|
35999
b6bf26e04451
8147772: Update KerberosTicket to describe behavior if it has been destroyed and fix NullPointerExceptions
weijun
parents:
34687
diff
changeset
|
407 |
return flags == null? false: flags[FORWARDED_TICKET_FLAG]; |
2 | 408 |
} |
409 |
||
410 |
/** |
|
411 |
* Determines if this ticket is proxiable. |
|
412 |
* |
|
35999
b6bf26e04451
8147772: Update KerberosTicket to describe behavior if it has been destroyed and fix NullPointerExceptions
weijun
parents:
34687
diff
changeset
|
413 |
* @return true if this ticket is proxiable, or false if not proxiable |
b6bf26e04451
8147772: Update KerberosTicket to describe behavior if it has been destroyed and fix NullPointerExceptions
weijun
parents:
34687
diff
changeset
|
414 |
* or destroyed. |
2 | 415 |
*/ |
416 |
public final boolean isProxiable() { |
|
35999
b6bf26e04451
8147772: Update KerberosTicket to describe behavior if it has been destroyed and fix NullPointerExceptions
weijun
parents:
34687
diff
changeset
|
417 |
return flags == null? false: flags[PROXIABLE_TICKET_FLAG]; |
2 | 418 |
} |
419 |
||
420 |
/** |
|
421 |
* Determines is this ticket is a proxy-ticket. |
|
422 |
* |
|
35999
b6bf26e04451
8147772: Update KerberosTicket to describe behavior if it has been destroyed and fix NullPointerExceptions
weijun
parents:
34687
diff
changeset
|
423 |
* @return true if this ticket is a proxy-ticket, or false if not |
b6bf26e04451
8147772: Update KerberosTicket to describe behavior if it has been destroyed and fix NullPointerExceptions
weijun
parents:
34687
diff
changeset
|
424 |
* a proxy-ticket or destroyed. |
2 | 425 |
*/ |
426 |
public final boolean isProxy() { |
|
35999
b6bf26e04451
8147772: Update KerberosTicket to describe behavior if it has been destroyed and fix NullPointerExceptions
weijun
parents:
34687
diff
changeset
|
427 |
return flags == null? false: flags[PROXY_TICKET_FLAG]; |
2 | 428 |
} |
429 |
||
430 |
||
431 |
/** |
|
432 |
* Determines is this ticket is post-dated. |
|
433 |
* |
|
35999
b6bf26e04451
8147772: Update KerberosTicket to describe behavior if it has been destroyed and fix NullPointerExceptions
weijun
parents:
34687
diff
changeset
|
434 |
* @return true if this ticket is post-dated, or false if not post-dated |
b6bf26e04451
8147772: Update KerberosTicket to describe behavior if it has been destroyed and fix NullPointerExceptions
weijun
parents:
34687
diff
changeset
|
435 |
* or destroyed. |
2 | 436 |
*/ |
437 |
public final boolean isPostdated() { |
|
35999
b6bf26e04451
8147772: Update KerberosTicket to describe behavior if it has been destroyed and fix NullPointerExceptions
weijun
parents:
34687
diff
changeset
|
438 |
return flags == null? false: flags[POSTDATED_TICKET_FLAG]; |
2 | 439 |
} |
440 |
||
441 |
/** |
|
442 |
* Determines is this ticket is renewable. If so, the {@link #refresh() |
|
443 |
* refresh} method can be called, assuming the validity period for |
|
444 |
* renewing is not already over. |
|
445 |
* |
|
35999
b6bf26e04451
8147772: Update KerberosTicket to describe behavior if it has been destroyed and fix NullPointerExceptions
weijun
parents:
34687
diff
changeset
|
446 |
* @return true if this ticket is renewable, or false if not renewable |
b6bf26e04451
8147772: Update KerberosTicket to describe behavior if it has been destroyed and fix NullPointerExceptions
weijun
parents:
34687
diff
changeset
|
447 |
* or destroyed. |
2 | 448 |
*/ |
449 |
public final boolean isRenewable() { |
|
35999
b6bf26e04451
8147772: Update KerberosTicket to describe behavior if it has been destroyed and fix NullPointerExceptions
weijun
parents:
34687
diff
changeset
|
450 |
return flags == null? false: flags[RENEWABLE_TICKET_FLAG]; |
2 | 451 |
} |
452 |
||
453 |
/** |
|
454 |
* Determines if this ticket was issued using the Kerberos AS-Exchange |
|
455 |
* protocol, and not issued based on some ticket-granting ticket. |
|
456 |
* |
|
457 |
* @return true if this ticket was issued using the Kerberos AS-Exchange |
|
35999
b6bf26e04451
8147772: Update KerberosTicket to describe behavior if it has been destroyed and fix NullPointerExceptions
weijun
parents:
34687
diff
changeset
|
458 |
* protocol, or false if not issued this way or destroyed. |
2 | 459 |
*/ |
460 |
public final boolean isInitial() { |
|
35999
b6bf26e04451
8147772: Update KerberosTicket to describe behavior if it has been destroyed and fix NullPointerExceptions
weijun
parents:
34687
diff
changeset
|
461 |
return flags == null? false: flags[INITIAL_TICKET_FLAG]; |
2 | 462 |
} |
463 |
||
464 |
/** |
|
465 |
* Returns the flags associated with this ticket. Each element in the |
|
466 |
* returned array indicates the value for the corresponding bit in the |
|
467 |
* ASN.1 BitString that represents the ticket flags. |
|
468 |
* |
|
35999
b6bf26e04451
8147772: Update KerberosTicket to describe behavior if it has been destroyed and fix NullPointerExceptions
weijun
parents:
34687
diff
changeset
|
469 |
* @return the flags associated with this ticket, or {@code null} |
b6bf26e04451
8147772: Update KerberosTicket to describe behavior if it has been destroyed and fix NullPointerExceptions
weijun
parents:
34687
diff
changeset
|
470 |
* if destroyed. |
2 | 471 |
*/ |
472 |
public final boolean[] getFlags() { |
|
51 | 473 |
return (flags == null? null: flags.clone()); |
2 | 474 |
} |
475 |
||
476 |
/** |
|
477 |
* Returns the time that the client was authenticated. |
|
478 |
* |
|
479 |
* @return the time that the client was authenticated |
|
35999
b6bf26e04451
8147772: Update KerberosTicket to describe behavior if it has been destroyed and fix NullPointerExceptions
weijun
parents:
34687
diff
changeset
|
480 |
* or {@code null} if the field is not set or |
b6bf26e04451
8147772: Update KerberosTicket to describe behavior if it has been destroyed and fix NullPointerExceptions
weijun
parents:
34687
diff
changeset
|
481 |
* this ticket is destroyed. |
2 | 482 |
*/ |
483 |
public final java.util.Date getAuthTime() { |
|
488
5e84e13e8892
6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents:
51
diff
changeset
|
484 |
return (authTime == null) ? null : (Date)authTime.clone(); |
2 | 485 |
} |
486 |
||
487 |
/** |
|
488 |
* Returns the start time for this ticket's validity period. |
|
489 |
* |
|
490 |
* @return the start time for this ticket's validity period |
|
35999
b6bf26e04451
8147772: Update KerberosTicket to describe behavior if it has been destroyed and fix NullPointerExceptions
weijun
parents:
34687
diff
changeset
|
491 |
* or {@code null} if the field is not set or |
b6bf26e04451
8147772: Update KerberosTicket to describe behavior if it has been destroyed and fix NullPointerExceptions
weijun
parents:
34687
diff
changeset
|
492 |
* this ticket is destroyed. |
2 | 493 |
*/ |
494 |
public final java.util.Date getStartTime() { |
|
488
5e84e13e8892
6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents:
51
diff
changeset
|
495 |
return (startTime == null) ? null : (Date)startTime.clone(); |
2 | 496 |
} |
497 |
||
498 |
/** |
|
499 |
* Returns the expiration time for this ticket's validity period. |
|
500 |
* |
|
35999
b6bf26e04451
8147772: Update KerberosTicket to describe behavior if it has been destroyed and fix NullPointerExceptions
weijun
parents:
34687
diff
changeset
|
501 |
* @return the expiration time for this ticket's validity period, |
b6bf26e04451
8147772: Update KerberosTicket to describe behavior if it has been destroyed and fix NullPointerExceptions
weijun
parents:
34687
diff
changeset
|
502 |
* or {@code null} if destroyed. |
2 | 503 |
*/ |
504 |
public final java.util.Date getEndTime() { |
|
35999
b6bf26e04451
8147772: Update KerberosTicket to describe behavior if it has been destroyed and fix NullPointerExceptions
weijun
parents:
34687
diff
changeset
|
505 |
return (endTime == null) ? null : (Date) endTime.clone(); |
2 | 506 |
} |
507 |
||
508 |
/** |
|
509 |
* Returns the latest expiration time for this ticket, including all |
|
510 |
* renewals. This will return a null value for non-renewable tickets. |
|
511 |
* |
|
35999
b6bf26e04451
8147772: Update KerberosTicket to describe behavior if it has been destroyed and fix NullPointerExceptions
weijun
parents:
34687
diff
changeset
|
512 |
* @return the latest expiration time for this ticket, or {@code null} |
b6bf26e04451
8147772: Update KerberosTicket to describe behavior if it has been destroyed and fix NullPointerExceptions
weijun
parents:
34687
diff
changeset
|
513 |
* if destroyed. |
2 | 514 |
*/ |
515 |
public final java.util.Date getRenewTill() { |
|
488
5e84e13e8892
6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents:
51
diff
changeset
|
516 |
return (renewTill == null) ? null: (Date)renewTill.clone(); |
2 | 517 |
} |
518 |
||
519 |
/** |
|
520 |
* Returns a list of addresses from where the ticket can be used. |
|
521 |
* |
|
35999
b6bf26e04451
8147772: Update KerberosTicket to describe behavior if it has been destroyed and fix NullPointerExceptions
weijun
parents:
34687
diff
changeset
|
522 |
* @return the list of addresses, or {@code null} if the field was not |
b6bf26e04451
8147772: Update KerberosTicket to describe behavior if it has been destroyed and fix NullPointerExceptions
weijun
parents:
34687
diff
changeset
|
523 |
* provided or this ticket is destroyed. |
2 | 524 |
*/ |
525 |
public final java.net.InetAddress[] getClientAddresses() { |
|
51 | 526 |
return (clientAddresses == null) ? null: clientAddresses.clone(); |
2 | 527 |
} |
528 |
||
529 |
/** |
|
530 |
* Returns an ASN.1 encoding of the entire ticket. |
|
531 |
* |
|
35999
b6bf26e04451
8147772: Update KerberosTicket to describe behavior if it has been destroyed and fix NullPointerExceptions
weijun
parents:
34687
diff
changeset
|
532 |
* @return an ASN.1 encoding of the entire ticket. A new byte |
b6bf26e04451
8147772: Update KerberosTicket to describe behavior if it has been destroyed and fix NullPointerExceptions
weijun
parents:
34687
diff
changeset
|
533 |
* array is returned each time this method is called. |
b6bf26e04451
8147772: Update KerberosTicket to describe behavior if it has been destroyed and fix NullPointerExceptions
weijun
parents:
34687
diff
changeset
|
534 |
* @throws IllegalStateException if this ticket is destroyed |
2 | 535 |
*/ |
536 |
public final byte[] getEncoded() { |
|
25661
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
537 |
if (destroyed) { |
2 | 538 |
throw new IllegalStateException("This ticket is no longer valid"); |
25661
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
539 |
} |
51 | 540 |
return asn1Encoding.clone(); |
2 | 541 |
} |
542 |
||
35999
b6bf26e04451
8147772: Update KerberosTicket to describe behavior if it has been destroyed and fix NullPointerExceptions
weijun
parents:
34687
diff
changeset
|
543 |
/** |
b6bf26e04451
8147772: Update KerberosTicket to describe behavior if it has been destroyed and fix NullPointerExceptions
weijun
parents:
34687
diff
changeset
|
544 |
* Determines if this ticket is still current. |
b6bf26e04451
8147772: Update KerberosTicket to describe behavior if it has been destroyed and fix NullPointerExceptions
weijun
parents:
34687
diff
changeset
|
545 |
* |
b6bf26e04451
8147772: Update KerberosTicket to describe behavior if it has been destroyed and fix NullPointerExceptions
weijun
parents:
34687
diff
changeset
|
546 |
* @return true if this ticket is still current, or false if not current |
b6bf26e04451
8147772: Update KerberosTicket to describe behavior if it has been destroyed and fix NullPointerExceptions
weijun
parents:
34687
diff
changeset
|
547 |
* or destroyed. |
b6bf26e04451
8147772: Update KerberosTicket to describe behavior if it has been destroyed and fix NullPointerExceptions
weijun
parents:
34687
diff
changeset
|
548 |
*/ |
2 | 549 |
public boolean isCurrent() { |
35999
b6bf26e04451
8147772: Update KerberosTicket to describe behavior if it has been destroyed and fix NullPointerExceptions
weijun
parents:
34687
diff
changeset
|
550 |
return endTime == null? false: (System.currentTimeMillis() <= endTime.getTime()); |
2 | 551 |
} |
552 |
||
553 |
/** |
|
554 |
* Extends the validity period of this ticket. The ticket will contain |
|
555 |
* a new session key if the refresh operation succeeds. The refresh |
|
556 |
* operation will fail if the ticket is not renewable or the latest |
|
557 |
* allowable renew time has passed. Any other error returned by the |
|
558 |
* KDC will also cause this method to fail. |
|
559 |
* |
|
28059
e576535359cc
8067377: My hobby: caning, then then canning, the the can-can
martin
parents:
27771
diff
changeset
|
560 |
* Note: This method is not synchronized with the accessor |
2 | 561 |
* methods of this object. Hence callers need to be aware of multiple |
562 |
* threads that might access this and try to renew it at the same |
|
563 |
* time. |
|
564 |
* |
|
35999
b6bf26e04451
8147772: Update KerberosTicket to describe behavior if it has been destroyed and fix NullPointerExceptions
weijun
parents:
34687
diff
changeset
|
565 |
* @throws IllegalStateException if this ticket is destroyed |
2 | 566 |
* @throws RefreshFailedException if the ticket is not renewable, or |
567 |
* the latest allowable renew time has passed, or the KDC returns some |
|
568 |
* error. |
|
569 |
* |
|
570 |
* @see #isRenewable() |
|
571 |
* @see #getRenewTill() |
|
572 |
*/ |
|
573 |
public void refresh() throws RefreshFailedException { |
|
574 |
||
25661
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
575 |
if (destroyed) { |
2 | 576 |
throw new RefreshFailedException("A destroyed ticket " |
25661
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
577 |
+ "cannot be renewd."); |
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
578 |
} |
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
579 |
if (!isRenewable()) { |
2 | 580 |
throw new RefreshFailedException("This ticket is not renewable"); |
25661
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
581 |
} |
47005
dbfaf076da58
8186576: KerberosTicket does not properly handle renewable tickets at the end of their lifetime
weijun
parents:
41586
diff
changeset
|
582 |
|
dbfaf076da58
8186576: KerberosTicket does not properly handle renewable tickets at the end of their lifetime
weijun
parents:
41586
diff
changeset
|
583 |
if (getRenewTill() == null) { |
dbfaf076da58
8186576: KerberosTicket does not properly handle renewable tickets at the end of their lifetime
weijun
parents:
41586
diff
changeset
|
584 |
// Renewable ticket without renew-till. Illegal and ignored. |
dbfaf076da58
8186576: KerberosTicket does not properly handle renewable tickets at the end of their lifetime
weijun
parents:
41586
diff
changeset
|
585 |
return; |
dbfaf076da58
8186576: KerberosTicket does not properly handle renewable tickets at the end of their lifetime
weijun
parents:
41586
diff
changeset
|
586 |
} |
dbfaf076da58
8186576: KerberosTicket does not properly handle renewable tickets at the end of their lifetime
weijun
parents:
41586
diff
changeset
|
587 |
|
25661
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
588 |
if (System.currentTimeMillis() > getRenewTill().getTime()) { |
2 | 589 |
throw new RefreshFailedException("This ticket is past " |
25661
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
590 |
+ "its last renewal time."); |
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
591 |
} |
2 | 592 |
Throwable e = null; |
593 |
sun.security.krb5.Credentials krb5Creds = null; |
|
594 |
||
595 |
try { |
|
596 |
krb5Creds = new sun.security.krb5.Credentials(asn1Encoding, |
|
27771
360714d431ab
8061253: Spec cleanup for some security-related classes
weijun
parents:
25859
diff
changeset
|
597 |
client.getName(), |
57487
643978a35f6e
8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents:
47216
diff
changeset
|
598 |
(clientAlias != null ? |
643978a35f6e
8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents:
47216
diff
changeset
|
599 |
clientAlias.getName() : null), |
27771
360714d431ab
8061253: Spec cleanup for some security-related classes
weijun
parents:
25859
diff
changeset
|
600 |
server.getName(), |
57487
643978a35f6e
8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents:
47216
diff
changeset
|
601 |
(serverAlias != null ? |
643978a35f6e
8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents:
47216
diff
changeset
|
602 |
serverAlias.getName() : null), |
2 | 603 |
sessionKey.getEncoded(), |
604 |
sessionKey.getKeyType(), |
|
605 |
flags, |
|
606 |
authTime, |
|
607 |
startTime, |
|
608 |
endTime, |
|
609 |
renewTill, |
|
610 |
clientAddresses); |
|
611 |
krb5Creds = krb5Creds.renew(); |
|
612 |
} catch (sun.security.krb5.KrbException krbException) { |
|
613 |
e = krbException; |
|
614 |
} catch (java.io.IOException ioException) { |
|
615 |
e = ioException; |
|
616 |
} |
|
617 |
||
618 |
if (e != null) { |
|
619 |
RefreshFailedException rfException |
|
620 |
= new RefreshFailedException("Failed to renew Kerberos Ticket " |
|
621 |
+ "for client " + client |
|
622 |
+ " and server " + server |
|
623 |
+ " - " + e.getMessage()); |
|
624 |
rfException.initCause(e); |
|
625 |
throw rfException; |
|
626 |
} |
|
627 |
||
628 |
/* |
|
629 |
* In case multiple threads try to refresh it at the same time. |
|
630 |
*/ |
|
631 |
synchronized (this) { |
|
632 |
try { |
|
633 |
this.destroy(); |
|
634 |
} catch (DestroyFailedException dfException) { |
|
635 |
// Squelch it since we don't care about the old ticket. |
|
636 |
} |
|
637 |
init(krb5Creds.getEncoded(), |
|
638 |
new KerberosPrincipal(krb5Creds.getClient().getName()), |
|
639 |
new KerberosPrincipal(krb5Creds.getServer().getName(), |
|
640 |
KerberosPrincipal.KRB_NT_SRV_INST), |
|
641 |
krb5Creds.getSessionKey().getBytes(), |
|
642 |
krb5Creds.getSessionKey().getEType(), |
|
643 |
krb5Creds.getFlags(), |
|
644 |
krb5Creds.getAuthTime(), |
|
645 |
krb5Creds.getStartTime(), |
|
646 |
krb5Creds.getEndTime(), |
|
647 |
krb5Creds.getRenewTill(), |
|
648 |
krb5Creds.getClientAddresses()); |
|
649 |
destroyed = false; |
|
650 |
} |
|
651 |
} |
|
652 |
||
653 |
/** |
|
654 |
* Destroys the ticket and destroys any sensitive information stored in |
|
655 |
* it. |
|
656 |
*/ |
|
657 |
public void destroy() throws DestroyFailedException { |
|
658 |
if (!destroyed) { |
|
659 |
Arrays.fill(asn1Encoding, (byte) 0); |
|
660 |
client = null; |
|
661 |
server = null; |
|
662 |
sessionKey.destroy(); |
|
663 |
flags = null; |
|
664 |
authTime = null; |
|
665 |
startTime = null; |
|
666 |
endTime = null; |
|
667 |
renewTill = null; |
|
668 |
clientAddresses = null; |
|
669 |
destroyed = true; |
|
670 |
} |
|
671 |
} |
|
672 |
||
673 |
/** |
|
674 |
* Determines if this ticket has been destroyed. |
|
675 |
*/ |
|
676 |
public boolean isDestroyed() { |
|
677 |
return destroyed; |
|
678 |
} |
|
679 |
||
27771
360714d431ab
8061253: Spec cleanup for some security-related classes
weijun
parents:
25859
diff
changeset
|
680 |
/** |
360714d431ab
8061253: Spec cleanup for some security-related classes
weijun
parents:
25859
diff
changeset
|
681 |
* Returns an informative textual representation of this {@code KerberosTicket}. |
360714d431ab
8061253: Spec cleanup for some security-related classes
weijun
parents:
25859
diff
changeset
|
682 |
* |
360714d431ab
8061253: Spec cleanup for some security-related classes
weijun
parents:
25859
diff
changeset
|
683 |
* @return an informative textual representation of this {@code KerberosTicket}. |
360714d431ab
8061253: Spec cleanup for some security-related classes
weijun
parents:
25859
diff
changeset
|
684 |
*/ |
2 | 685 |
public String toString() { |
25661
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
686 |
if (destroyed) { |
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
687 |
return "Destroyed KerberosTicket"; |
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
688 |
} |
24969
afa6934dd8e8
8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents:
18830
diff
changeset
|
689 |
StringBuilder caddrString = new StringBuilder(); |
2 | 690 |
if (clientAddresses != null) { |
691 |
for (int i = 0; i < clientAddresses.length; i++) { |
|
24969
afa6934dd8e8
8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents:
18830
diff
changeset
|
692 |
caddrString.append("clientAddresses[" + i + "] = " + |
afa6934dd8e8
8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents:
18830
diff
changeset
|
693 |
clientAddresses[i].toString()); |
2 | 694 |
} |
695 |
} |
|
696 |
return ("Ticket (hex) = " + "\n" + |
|
697 |
(new HexDumpEncoder()).encodeBuffer(asn1Encoding) + "\n" + |
|
698 |
"Client Principal = " + client.toString() + "\n" + |
|
699 |
"Server Principal = " + server.toString() + "\n" + |
|
700 |
"Session Key = " + sessionKey.toString() + "\n" + |
|
701 |
"Forwardable Ticket " + flags[FORWARDABLE_TICKET_FLAG] + "\n" + |
|
702 |
"Forwarded Ticket " + flags[FORWARDED_TICKET_FLAG] + "\n" + |
|
703 |
"Proxiable Ticket " + flags[PROXIABLE_TICKET_FLAG] + "\n" + |
|
704 |
"Proxy Ticket " + flags[PROXY_TICKET_FLAG] + "\n" + |
|
705 |
"Postdated Ticket " + flags[POSTDATED_TICKET_FLAG] + "\n" + |
|
706 |
"Renewable Ticket " + flags[RENEWABLE_TICKET_FLAG] + "\n" + |
|
41586
d6f36cdf633c
8167647: Copy-and-paste bug in javax.security.auth.kerberos.KerberosTicket.toString()
weijun
parents:
35999
diff
changeset
|
707 |
"Initial Ticket " + flags[INITIAL_TICKET_FLAG] + "\n" + |
2 | 708 |
"Auth Time = " + String.valueOf(authTime) + "\n" + |
709 |
"Start Time = " + String.valueOf(startTime) + "\n" + |
|
710 |
"End Time = " + endTime.toString() + "\n" + |
|
711 |
"Renew Till = " + String.valueOf(renewTill) + "\n" + |
|
712 |
"Client Addresses " + |
|
24969
afa6934dd8e8
8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents:
18830
diff
changeset
|
713 |
(clientAddresses == null ? " Null " : caddrString.toString() + |
2 | 714 |
"\n")); |
715 |
} |
|
716 |
||
717 |
/** |
|
27771
360714d431ab
8061253: Spec cleanup for some security-related classes
weijun
parents:
25859
diff
changeset
|
718 |
* Returns a hash code for this {@code KerberosTicket}. |
2 | 719 |
* |
27771
360714d431ab
8061253: Spec cleanup for some security-related classes
weijun
parents:
25859
diff
changeset
|
720 |
* @return a hash code for this {@code KerberosTicket}. |
2 | 721 |
* @since 1.6 |
722 |
*/ |
|
723 |
public int hashCode() { |
|
724 |
int result = 17; |
|
725 |
if (isDestroyed()) { |
|
726 |
return result; |
|
727 |
} |
|
728 |
result = result * 37 + Arrays.hashCode(getEncoded()); |
|
729 |
result = result * 37 + endTime.hashCode(); |
|
730 |
result = result * 37 + client.hashCode(); |
|
731 |
result = result * 37 + server.hashCode(); |
|
732 |
result = result * 37 + sessionKey.hashCode(); |
|
733 |
||
734 |
// authTime may be null |
|
735 |
if (authTime != null) { |
|
736 |
result = result * 37 + authTime.hashCode(); |
|
737 |
} |
|
738 |
||
739 |
// startTime may be null |
|
740 |
if (startTime != null) { |
|
741 |
result = result * 37 + startTime.hashCode(); |
|
742 |
} |
|
743 |
||
744 |
// renewTill may be null |
|
745 |
if (renewTill != null) { |
|
746 |
result = result * 37 + renewTill.hashCode(); |
|
747 |
} |
|
748 |
||
749 |
// clientAddress may be null, the array's hashCode is 0 |
|
750 |
result = result * 37 + Arrays.hashCode(clientAddresses); |
|
751 |
return result * 37 + Arrays.hashCode(flags); |
|
752 |
} |
|
753 |
||
754 |
/** |
|
27771
360714d431ab
8061253: Spec cleanup for some security-related classes
weijun
parents:
25859
diff
changeset
|
755 |
* Compares the specified object with this {@code KerberosTicket} for equality. |
2 | 756 |
* Returns true if the given object is also a |
18830 | 757 |
* {@code KerberosTicket} and the two |
758 |
* {@code KerberosTicket} instances are equivalent. |
|
27771
360714d431ab
8061253: Spec cleanup for some security-related classes
weijun
parents:
25859
diff
changeset
|
759 |
* A destroyed {@code KerberosTicket} object is only equal to itself. |
2 | 760 |
* |
27771
360714d431ab
8061253: Spec cleanup for some security-related classes
weijun
parents:
25859
diff
changeset
|
761 |
* @param other the object to compare to |
360714d431ab
8061253: Spec cleanup for some security-related classes
weijun
parents:
25859
diff
changeset
|
762 |
* @return true if the specified object is equal to this {@code KerberosTicket}, |
360714d431ab
8061253: Spec cleanup for some security-related classes
weijun
parents:
25859
diff
changeset
|
763 |
* false otherwise. |
2 | 764 |
* @since 1.6 |
765 |
*/ |
|
766 |
public boolean equals(Object other) { |
|
767 |
||
25661
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
768 |
if (other == this) { |
2 | 769 |
return true; |
25661
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
770 |
} |
2 | 771 |
|
772 |
if (! (other instanceof KerberosTicket)) { |
|
773 |
return false; |
|
774 |
} |
|
775 |
||
776 |
KerberosTicket otherTicket = ((KerberosTicket) other); |
|
777 |
if (isDestroyed() || otherTicket.isDestroyed()) { |
|
778 |
return false; |
|
779 |
} |
|
780 |
||
781 |
if (!Arrays.equals(getEncoded(), otherTicket.getEncoded()) || |
|
782 |
!endTime.equals(otherTicket.getEndTime()) || |
|
783 |
!server.equals(otherTicket.getServer()) || |
|
784 |
!client.equals(otherTicket.getClient()) || |
|
25661
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
785 |
!sessionKey.equals(otherTicket.sessionKey) || |
2 | 786 |
!Arrays.equals(clientAddresses, otherTicket.getClientAddresses()) || |
787 |
!Arrays.equals(flags, otherTicket.getFlags())) { |
|
788 |
return false; |
|
789 |
} |
|
790 |
||
791 |
// authTime may be null |
|
792 |
if (authTime == null) { |
|
25661
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
793 |
if (otherTicket.getAuthTime() != null) { |
2 | 794 |
return false; |
25661
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
795 |
} |
2 | 796 |
} else { |
25661
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
797 |
if (!authTime.equals(otherTicket.getAuthTime())) { |
2 | 798 |
return false; |
25661
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
799 |
} |
2 | 800 |
} |
801 |
||
802 |
// startTime may be null |
|
803 |
if (startTime == null) { |
|
25661
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
804 |
if (otherTicket.getStartTime() != null) { |
2 | 805 |
return false; |
25661
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
806 |
} |
2 | 807 |
} else { |
25661
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
808 |
if (!startTime.equals(otherTicket.getStartTime())) { |
2 | 809 |
return false; |
25661
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
810 |
} |
2 | 811 |
} |
812 |
||
813 |
if (renewTill == null) { |
|
25661
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
814 |
if (otherTicket.getRenewTill() != null) { |
2 | 815 |
return false; |
25661
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
816 |
} |
2 | 817 |
} else { |
25661
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
818 |
if (!renewTill.equals(otherTicket.getRenewTill())) { |
2 | 819 |
return false; |
25661
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
820 |
} |
2 | 821 |
} |
822 |
||
823 |
return true; |
|
824 |
} |
|
488
5e84e13e8892
6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents:
51
diff
changeset
|
825 |
|
5e84e13e8892
6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents:
51
diff
changeset
|
826 |
private void readObject(ObjectInputStream s) |
25661
929c829a8400
8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
24969
diff
changeset
|
827 |
throws IOException, ClassNotFoundException { |
488
5e84e13e8892
6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents:
51
diff
changeset
|
828 |
s.defaultReadObject(); |
5e84e13e8892
6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents:
51
diff
changeset
|
829 |
if (sessionKey == null) { |
5e84e13e8892
6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents:
51
diff
changeset
|
830 |
throw new InvalidObjectException("Session key cannot be null"); |
5e84e13e8892
6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents:
51
diff
changeset
|
831 |
} |
5e84e13e8892
6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents:
51
diff
changeset
|
832 |
try { |
5e84e13e8892
6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents:
51
diff
changeset
|
833 |
init(asn1Encoding, client, server, sessionKey, |
5e84e13e8892
6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents:
51
diff
changeset
|
834 |
flags, authTime, startTime, endTime, |
5e84e13e8892
6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents:
51
diff
changeset
|
835 |
renewTill, clientAddresses); |
5e84e13e8892
6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents:
51
diff
changeset
|
836 |
} catch (IllegalArgumentException iae) { |
5e84e13e8892
6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents:
51
diff
changeset
|
837 |
throw (InvalidObjectException) |
5e84e13e8892
6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents:
51
diff
changeset
|
838 |
new InvalidObjectException(iae.getMessage()).initCause(iae); |
5e84e13e8892
6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents:
51
diff
changeset
|
839 |
} |
5e84e13e8892
6659990: KerberosTicket.getEndTime does not copy date (findbugs)
valeriep
parents:
51
diff
changeset
|
840 |
} |
2 | 841 |
} |