Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/test/jdk/sun/security/krb5/auto/IgnoreChannelBinding.java
66646 views
1
/*
2
* Copyright (c) 2009, 2021, 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 6851973 8194486 8279520
27
* @summary ignore incoming channel binding if acceptor does not set one
28
* @library /test/lib
29
* @run main jdk.test.lib.FileInstaller TestHosts TestHosts
30
* @run main/othervm -Djdk.net.hosts.file=TestHosts IgnoreChannelBinding
31
*/
32
33
import java.net.InetAddress;
34
import org.ietf.jgss.ChannelBinding;
35
import org.ietf.jgss.GSSException;
36
import org.ietf.jgss.Oid;
37
import sun.security.jgss.GSSUtil;
38
39
public class IgnoreChannelBinding {
40
41
public static void main(String[] args)
42
throws Exception {
43
44
new OneKDC(null).writeJAASConf();
45
test(GSSUtil.GSS_KRB5_MECH_OID);
46
test(GSSUtil.GSS_SPNEGO_MECH_OID);
47
}
48
49
static void test(Oid mech) throws Exception {
50
51
Context c = Context.fromJAAS("client");
52
Context s = Context.fromJAAS("server");
53
54
// All silent
55
c.startAsClient(OneKDC.SERVER, mech);
56
s.startAsServer(mech);
57
Context.handshake(c, s);
58
59
// Initiator req, acceptor ignore
60
c.startAsClient(OneKDC.SERVER, mech);
61
c.x().setChannelBinding(new ChannelBinding(
62
InetAddress.getByName("client.rabbit.hole"),
63
InetAddress.getByName("host.rabbit.hole"),
64
new byte[0]
65
));
66
s.startAsServer(mech);
67
Context.handshake(c, s);
68
69
// Both req, and match
70
c.startAsClient(OneKDC.SERVER, mech);
71
c.x().setChannelBinding(new ChannelBinding(
72
InetAddress.getByName("client.rabbit.hole"),
73
InetAddress.getByName("host.rabbit.hole"),
74
new byte[0]
75
));
76
s.startAsServer(mech);
77
s.x().setChannelBinding(new ChannelBinding(
78
InetAddress.getByName("client.rabbit.hole"),
79
InetAddress.getByName("host.rabbit.hole"),
80
new byte[0]
81
));
82
Context.handshake(c, s);
83
84
// Both req, NOT match
85
c.startAsClient(OneKDC.SERVER, mech);
86
c.x().setChannelBinding(new ChannelBinding(
87
InetAddress.getByName("client.rabbit.hole"),
88
InetAddress.getByName("host.rabbit.hole"),
89
new byte[0]
90
));
91
s.startAsServer(mech);
92
s.x().setChannelBinding(new ChannelBinding(
93
InetAddress.getByName("client.rabbit.hole"),
94
InetAddress.getByName("host.rabbit.hole"),
95
new byte[1] // 0 -> 1
96
));
97
try {
98
Context.handshake(c, s);
99
throw new Exception("Acceptor should reject initiator");
100
} catch (GSSException ge) {
101
// Expected bahavior
102
}
103
104
// Acceptor req, reject
105
c.startAsClient(OneKDC.SERVER, mech);
106
s.startAsServer(mech);
107
s.x().setChannelBinding(new ChannelBinding(
108
InetAddress.getByName("client.rabbit.hole"),
109
InetAddress.getByName("host.rabbit.hole"),
110
new byte[0]
111
));
112
try {
113
Context.handshake(c, s);
114
throw new Exception("Acceptor should reject initiator");
115
} catch (GSSException ge) {
116
// Expected bahavior
117
if (ge.getMajor() != GSSException.BAD_BINDINGS) {
118
throw ge;
119
}
120
}
121
}
122
}
123
124