Path: blob/master/test/jdk/sun/security/krb5/auto/IgnoreChannelBinding.java
66646 views
/*1* Copyright (c) 2009, 2021, Oracle and/or its affiliates. All rights reserved.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 it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 6851973 8194486 827952026* @summary ignore incoming channel binding if acceptor does not set one27* @library /test/lib28* @run main jdk.test.lib.FileInstaller TestHosts TestHosts29* @run main/othervm -Djdk.net.hosts.file=TestHosts IgnoreChannelBinding30*/3132import java.net.InetAddress;33import org.ietf.jgss.ChannelBinding;34import org.ietf.jgss.GSSException;35import org.ietf.jgss.Oid;36import sun.security.jgss.GSSUtil;3738public class IgnoreChannelBinding {3940public static void main(String[] args)41throws Exception {4243new OneKDC(null).writeJAASConf();44test(GSSUtil.GSS_KRB5_MECH_OID);45test(GSSUtil.GSS_SPNEGO_MECH_OID);46}4748static void test(Oid mech) throws Exception {4950Context c = Context.fromJAAS("client");51Context s = Context.fromJAAS("server");5253// All silent54c.startAsClient(OneKDC.SERVER, mech);55s.startAsServer(mech);56Context.handshake(c, s);5758// Initiator req, acceptor ignore59c.startAsClient(OneKDC.SERVER, mech);60c.x().setChannelBinding(new ChannelBinding(61InetAddress.getByName("client.rabbit.hole"),62InetAddress.getByName("host.rabbit.hole"),63new byte[0]64));65s.startAsServer(mech);66Context.handshake(c, s);6768// Both req, and match69c.startAsClient(OneKDC.SERVER, mech);70c.x().setChannelBinding(new ChannelBinding(71InetAddress.getByName("client.rabbit.hole"),72InetAddress.getByName("host.rabbit.hole"),73new byte[0]74));75s.startAsServer(mech);76s.x().setChannelBinding(new ChannelBinding(77InetAddress.getByName("client.rabbit.hole"),78InetAddress.getByName("host.rabbit.hole"),79new byte[0]80));81Context.handshake(c, s);8283// Both req, NOT match84c.startAsClient(OneKDC.SERVER, mech);85c.x().setChannelBinding(new ChannelBinding(86InetAddress.getByName("client.rabbit.hole"),87InetAddress.getByName("host.rabbit.hole"),88new byte[0]89));90s.startAsServer(mech);91s.x().setChannelBinding(new ChannelBinding(92InetAddress.getByName("client.rabbit.hole"),93InetAddress.getByName("host.rabbit.hole"),94new byte[1] // 0 -> 195));96try {97Context.handshake(c, s);98throw new Exception("Acceptor should reject initiator");99} catch (GSSException ge) {100// Expected bahavior101}102103// Acceptor req, reject104c.startAsClient(OneKDC.SERVER, mech);105s.startAsServer(mech);106s.x().setChannelBinding(new ChannelBinding(107InetAddress.getByName("client.rabbit.hole"),108InetAddress.getByName("host.rabbit.hole"),109new byte[0]110));111try {112Context.handshake(c, s);113throw new Exception("Acceptor should reject initiator");114} catch (GSSException ge) {115// Expected bahavior116if (ge.getMajor() != GSSException.BAD_BINDINGS) {117throw ge;118}119}120}121}122123124