Skip to content
This repository was archived by the owner on Aug 27, 2022. It is now read-only.
/ lanai Public archive

Commit c4681a9

Browse files
committedFeb 15, 2020
8160818: GssKrb5Client violates RFC 4752
Reviewed-by: xuelei
1 parent 71ed4f2 commit c4681a9

File tree

2 files changed

+120
-4
lines changed

2 files changed

+120
-4
lines changed
 

‎src/jdk.security.jgss/share/classes/com/sun/security/sasl/gsskerb/GssKrb5Client.java

+12-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,7 +25,6 @@
2525

2626
package com.sun.security.sasl.gsskerb;
2727

28-
import java.io.IOException;
2928
import java.util.Map;
3029
import java.util.logging.Level;
3130
import javax.security.sasl.*;
@@ -85,7 +84,6 @@ final class GssKrb5Client extends GssKrb5Base implements SaslClient {
8584
private static final String MY_CLASS_NAME = GssKrb5Client.class.getName();
8685

8786
private boolean finalHandshake = false;
88-
private boolean mutual = false; // default false
8987
private byte[] authzID;
9088

9189
/**
@@ -132,7 +130,17 @@ final class GssKrb5Client extends GssKrb5Base implements SaslClient {
132130
secCtx.requestCredDeleg(true);
133131
}
134132

135-
// Parse properties to set desired context options
133+
// mutual is by default true if there is a security layer
134+
boolean mutual;
135+
if ((allQop & INTEGRITY_ONLY_PROTECTION) != 0
136+
|| (allQop & PRIVACY_PROTECTION) != 0) {
137+
mutual = true;
138+
secCtx.requestSequenceDet(true);
139+
} else {
140+
mutual = false;
141+
}
142+
143+
// User can override default mutual flag
136144
if (props != null) {
137145
// Mutual authentication
138146
String prop = (String)props.get(Sasl.SERVER_AUTH);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*
2+
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
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
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/*
25+
* @test
26+
* @bug 8160818
27+
* @summary GssKrb5Client violates RFC 4752
28+
* @library /test/lib
29+
* @compile -XDignore.symbol.file SaslMutual.java
30+
* @run main jdk.test.lib.FileInstaller TestHosts TestHosts
31+
* @run main/othervm -Djdk.net.hosts.file=TestHosts SaslMutual
32+
*/
33+
import jdk.test.lib.Asserts;
34+
35+
import java.util.Map;
36+
import javax.security.auth.callback.Callback;
37+
import javax.security.sasl.*;
38+
39+
public class SaslMutual {
40+
41+
public static void main(String[] args) throws Exception {
42+
43+
String name = "host." + OneKDC.REALM_LOWER_CASE;
44+
45+
new OneKDC(null).writeJAASConf();
46+
System.setProperty("javax.security.auth.useSubjectCredsOnly", "false");
47+
48+
SaslClient sc;
49+
50+
sc = Sasl.createSaslClient(
51+
new String[]{"GSSAPI"}, null, "server",
52+
name,
53+
Map.of(),
54+
null);
55+
Asserts.assertEQ(round(sc, server()), 2);
56+
57+
sc = Sasl.createSaslClient(
58+
new String[]{"GSSAPI"}, null, "server",
59+
name,
60+
Map.of(Sasl.SERVER_AUTH, "true"),
61+
null);
62+
Asserts.assertEQ(round(sc, server()), 3);
63+
64+
sc = Sasl.createSaslClient(
65+
new String[]{"GSSAPI"}, null, "server",
66+
name,
67+
Map.of(Sasl.QOP, "auth-int"),
68+
null);
69+
Asserts.assertEQ(round(sc, server()), 3);
70+
71+
sc = Sasl.createSaslClient(
72+
new String[]{"GSSAPI"}, null, "server",
73+
name,
74+
Map.of(Sasl.QOP, "auth-conf"),
75+
null);
76+
Asserts.assertEQ(round(sc, server()), 3);
77+
}
78+
79+
static SaslServer server() throws Exception {
80+
return Sasl.createSaslServer("GSSAPI", "server",
81+
null,
82+
Map.of(Sasl.QOP, "auth,auth-int,auth-conf"),
83+
callbacks -> {
84+
for (Callback cb : callbacks) {
85+
if (cb instanceof RealmCallback) {
86+
((RealmCallback) cb).setText(OneKDC.REALM);
87+
} else if (cb instanceof AuthorizeCallback) {
88+
((AuthorizeCallback) cb).setAuthorized(true);
89+
}
90+
}
91+
});
92+
}
93+
94+
static int round(SaslClient sc, SaslServer ss) throws Exception {
95+
int round = 0;
96+
byte[] token = new byte[0];
97+
while (!sc.isComplete() || !ss.isComplete()) {
98+
if (!sc.isComplete()) {
99+
token = sc.evaluateChallenge(token);
100+
}
101+
if (!ss.isComplete()) {
102+
token = ss.evaluateResponse(token);
103+
}
104+
round++;
105+
}
106+
return round;
107+
}
108+
}

0 commit comments

Comments
 (0)
This repository has been archived.