author | weijun |
Wed, 03 Jul 2019 11:43:01 +0800 | |
changeset 55570 | 1e95931e7d8f |
parent 55258 | d65d3c37232c |
child 58679 | 9c3209ff7550 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
3 |
* |
|
4 |
* This code is free software; you can redistribute it and/or modify it |
|
5 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 6 |
* published by the Free Software Foundation. Oracle designates this |
2 | 7 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 8 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 9 |
* |
10 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
11 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
12 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
13 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
14 |
* accompanied this code). |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License version |
|
17 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
18 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
19 |
* |
|
5506 | 20 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
21 |
* or visit www.oracle.com if you need additional information or have any |
|
22 |
* questions. |
|
2 | 23 |
*/ |
24 |
||
25 |
/* |
|
26 |
* |
|
27 |
* (C) Copyright IBM Corp. 1999 All Rights Reserved. |
|
28 |
* Copyright 1997 The Open Group Research Institute. All rights reserved. |
|
29 |
*/ |
|
30 |
||
31 |
package sun.security.krb5; |
|
32 |
||
33 |
import sun.security.krb5.internal.*; |
|
55258
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
34 |
import sun.security.krb5.internal.crypto.KeyUsage; |
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
35 |
import sun.security.util.DerInputStream; |
2 | 36 |
|
37 |
abstract class KrbKdcRep { |
|
38 |
||
39 |
static void check( |
|
13247 | 40 |
boolean isAsReq, |
2 | 41 |
KDCReq req, |
55258
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
42 |
KDCRep rep, |
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
43 |
EncryptionKey replyKey |
2 | 44 |
) throws KrbApErrException { |
45 |
||
55258
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
46 |
// cname change in AS-REP is allowed only if the client |
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
47 |
// sent CANONICALIZE and the server supports RFC 6806 - Section 11 |
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
48 |
// FAST scheme (ENC-PA-REP flag). |
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
49 |
if (isAsReq && !req.reqBody.cname.equals(rep.cname) && |
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
50 |
(!req.reqBody.kdcOptions.get(KDCOptions.CANONICALIZE) || |
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
51 |
!rep.encKDCRepPart.flags.get(Krb5.TKT_OPTS_ENC_PA_REP))) { |
2 | 52 |
rep.encKDCRepPart.key.destroy(); |
53 |
throw new KrbApErrException(Krb5.KRB_AP_ERR_MODIFIED); |
|
54 |
} |
|
55 |
||
55258
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
56 |
// sname change in TGS-REP is allowed only if client |
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
57 |
// sent CANONICALIZE and new sname is a referral of |
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
58 |
// the form krbtgt/TO-REALM.COM@FROM-REALM.COM. |
13247 | 59 |
if (!req.reqBody.sname.equals(rep.encKDCRepPart.sname)) { |
55258
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
60 |
String[] snameStrings = rep.encKDCRepPart.sname.getNameStrings(); |
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
61 |
if (isAsReq || !req.reqBody.kdcOptions.get(KDCOptions.CANONICALIZE) || |
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
62 |
snameStrings == null || snameStrings.length != 2 || |
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
63 |
!snameStrings[0].equals(PrincipalName.TGS_DEFAULT_SRV_NAME) || |
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
64 |
!rep.encKDCRepPart.sname.getRealmString().equals( |
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
65 |
req.reqBody.sname.getRealmString())) { |
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
66 |
rep.encKDCRepPart.key.destroy(); |
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
67 |
throw new KrbApErrException(Krb5.KRB_AP_ERR_MODIFIED); |
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
68 |
} |
2 | 69 |
} |
70 |
||
71 |
if (req.reqBody.getNonce() != rep.encKDCRepPart.nonce) { |
|
72 |
rep.encKDCRepPart.key.destroy(); |
|
73 |
throw new KrbApErrException(Krb5.KRB_AP_ERR_MODIFIED); |
|
74 |
} |
|
75 |
||
76 |
if ( |
|
77 |
((req.reqBody.addresses != null && rep.encKDCRepPart.caddr != null) && |
|
78 |
!req.reqBody.addresses.equals(rep.encKDCRepPart.caddr))) { |
|
79 |
rep.encKDCRepPart.key.destroy(); |
|
80 |
throw new KrbApErrException(Krb5.KRB_AP_ERR_MODIFIED); |
|
81 |
} |
|
82 |
||
28670
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
27946
diff
changeset
|
83 |
// We allow KDC to return a non-forwardable ticket if request has -f |
bb9afe681988
8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents:
27946
diff
changeset
|
84 |
for (int i = 2; i < 6; i++) { |
2 | 85 |
if (req.reqBody.kdcOptions.get(i) != |
14413
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
13247
diff
changeset
|
86 |
rep.encKDCRepPart.flags.get(i)) { |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
13247
diff
changeset
|
87 |
if (Krb5.DEBUG) { |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
13247
diff
changeset
|
88 |
System.out.println("> KrbKdcRep.check: at #" + i |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
13247
diff
changeset
|
89 |
+ ". request for " + req.reqBody.kdcOptions.get(i) |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
13247
diff
changeset
|
90 |
+ ", received " + rep.encKDCRepPart.flags.get(i)); |
e954df027393
6355584: Introduce constrained Kerberos delegation
weijun
parents:
13247
diff
changeset
|
91 |
} |
2 | 92 |
throw new KrbApErrException(Krb5.KRB_AP_ERR_MODIFIED); |
93 |
} |
|
94 |
} |
|
95 |
||
31817
1cd8bae1ef0c
8131051: KDC might issue a renewable ticket even if not requested
weijun
parents:
28670
diff
changeset
|
96 |
// Reply to a renewable request should be renewable, but if request does |
1cd8bae1ef0c
8131051: KDC might issue a renewable ticket even if not requested
weijun
parents:
28670
diff
changeset
|
97 |
// not contain renewable, KDC is free to issue a renewable ticket (for |
1cd8bae1ef0c
8131051: KDC might issue a renewable ticket even if not requested
weijun
parents:
28670
diff
changeset
|
98 |
// example, if ticket_lifetime is too big). |
1cd8bae1ef0c
8131051: KDC might issue a renewable ticket even if not requested
weijun
parents:
28670
diff
changeset
|
99 |
if (req.reqBody.kdcOptions.get(KDCOptions.RENEWABLE) && |
1cd8bae1ef0c
8131051: KDC might issue a renewable ticket even if not requested
weijun
parents:
28670
diff
changeset
|
100 |
!rep.encKDCRepPart.flags.get(KDCOptions.RENEWABLE)) { |
2 | 101 |
throw new KrbApErrException(Krb5.KRB_AP_ERR_MODIFIED); |
102 |
} |
|
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
|
103 |
|
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
|
104 |
if ((req.reqBody.from == null) || req.reqBody.from.isZero()) { |
2 | 105 |
// verify this is allowed |
106 |
if ((rep.encKDCRepPart.starttime != null) && |
|
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
|
107 |
!rep.encKDCRepPart.starttime.inClockSkew()) { |
2 | 108 |
rep.encKDCRepPart.key.destroy(); |
109 |
throw new KrbApErrException(Krb5.KRB_AP_ERR_SKEW); |
|
110 |
} |
|
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
|
111 |
} |
2 | 112 |
|
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
|
113 |
if ((req.reqBody.from != null) && !req.reqBody.from.isZero()) { |
2 | 114 |
// verify this is allowed |
115 |
if ((rep.encKDCRepPart.starttime != null) && |
|
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
|
116 |
!req.reqBody.from.equals(rep.encKDCRepPart.starttime)) { |
2 | 117 |
rep.encKDCRepPart.key.destroy(); |
118 |
throw new KrbApErrException(Krb5.KRB_AP_ERR_MODIFIED); |
|
119 |
} |
|
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
|
120 |
} |
2 | 121 |
|
122 |
if (!req.reqBody.till.isZero() && |
|
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
|
123 |
rep.encKDCRepPart.endtime.greaterThan(req.reqBody.till)) { |
2 | 124 |
rep.encKDCRepPart.key.destroy(); |
125 |
throw new KrbApErrException(Krb5.KRB_AP_ERR_MODIFIED); |
|
126 |
} |
|
127 |
||
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
|
128 |
if (req.reqBody.kdcOptions.get(KDCOptions.RENEWABLE)) { |
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
|
129 |
if (req.reqBody.rtime != null && !req.reqBody.rtime.isZero()) { |
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
|
130 |
// verify this is required |
2 | 131 |
if ((rep.encKDCRepPart.renewTill == null) || |
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
|
132 |
rep.encKDCRepPart.renewTill.greaterThan(req.reqBody.rtime) |
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
|
133 |
) { |
2 | 134 |
rep.encKDCRepPart.key.destroy(); |
135 |
throw new KrbApErrException(Krb5.KRB_AP_ERR_MODIFIED); |
|
136 |
} |
|
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
|
137 |
} |
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
|
138 |
} |
55258
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
139 |
|
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
140 |
// RFC 6806 - Section 11 mechanism check |
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
141 |
if (rep.encKDCRepPart.flags.get(Krb5.TKT_OPTS_ENC_PA_REP) && |
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
142 |
req.reqBody.kdcOptions.get(KDCOptions.CANONICALIZE)) { |
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
143 |
boolean reqPaReqEncPaRep = false; |
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
144 |
boolean repPaReqEncPaRepValid = false; |
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
145 |
|
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
146 |
// PA_REQ_ENC_PA_REP only required for AS requests |
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
147 |
for (PAData pa : req.pAData) { |
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
148 |
if (pa.getType() == Krb5.PA_REQ_ENC_PA_REP) { |
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
149 |
reqPaReqEncPaRep = true; |
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
150 |
break; |
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
151 |
} |
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
152 |
} |
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
153 |
|
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
154 |
if (rep.encKDCRepPart.pAData != null) { |
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
155 |
for (PAData pa : rep.encKDCRepPart.pAData) { |
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
156 |
if (pa.getType() == Krb5.PA_REQ_ENC_PA_REP) { |
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
157 |
try { |
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
158 |
Checksum repCksum = new Checksum( |
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
159 |
new DerInputStream( |
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
160 |
pa.getValue()).getDerValue()); |
55570
1e95931e7d8f
8226719: Kerberos login to Windows 2000 failed with "Inappropriate type of checksum in message"
weijun
parents:
55258
diff
changeset
|
161 |
// The checksum is inside encKDCRepPart so we don't |
1e95931e7d8f
8226719: Kerberos login to Windows 2000 failed with "Inappropriate type of checksum in message"
weijun
parents:
55258
diff
changeset
|
162 |
// care if it's keyed or not. |
55258
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
163 |
repPaReqEncPaRepValid = |
55570
1e95931e7d8f
8226719: Kerberos login to Windows 2000 failed with "Inappropriate type of checksum in message"
weijun
parents:
55258
diff
changeset
|
164 |
repCksum.verifyAnyChecksum( |
55258
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
165 |
req.asn1Encode(), replyKey, |
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
166 |
KeyUsage.KU_AS_REQ); |
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
167 |
} catch (Exception e) { |
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
168 |
if (Krb5.DEBUG) { |
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
169 |
e.printStackTrace(); |
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
170 |
} |
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
171 |
} |
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
172 |
break; |
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
173 |
} |
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
174 |
} |
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
175 |
} |
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
176 |
|
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
177 |
if (reqPaReqEncPaRep && !repPaReqEncPaRepValid) { |
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
178 |
throw new KrbApErrException(Krb5.KRB_AP_ERR_MODIFIED); |
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
179 |
} |
d65d3c37232c
8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents:
47216
diff
changeset
|
180 |
} |
2 | 181 |
} |
182 |
} |