Path: blob/master/test/jdk/sun/security/krb5/auto/IgnoreChannelBinding.java
41152 views
/*1* Copyright (c) 2009, 2018, 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 819448626* @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 sun.security.jgss.GSSUtil;3637public class IgnoreChannelBinding {3839public static void main(String[] args)40throws Exception {4142new OneKDC(null).writeJAASConf();4344Context c = Context.fromJAAS("client");45Context s = Context.fromJAAS("server");4647// All silent48c.startAsClient(OneKDC.SERVER, GSSUtil.GSS_KRB5_MECH_OID);49s.startAsServer(GSSUtil.GSS_KRB5_MECH_OID);50Context.handshake(c, s);5152// Initiator req, acceptor ignore53c.startAsClient(OneKDC.SERVER, GSSUtil.GSS_KRB5_MECH_OID);54c.x().setChannelBinding(new ChannelBinding(55InetAddress.getByName("client.rabbit.hole"),56InetAddress.getByName("host.rabbit.hole"),57new byte[0]58));59s.startAsServer(GSSUtil.GSS_KRB5_MECH_OID);60Context.handshake(c, s);6162// Both req, and match63c.startAsClient(OneKDC.SERVER, GSSUtil.GSS_KRB5_MECH_OID);64c.x().setChannelBinding(new ChannelBinding(65InetAddress.getByName("client.rabbit.hole"),66InetAddress.getByName("host.rabbit.hole"),67new byte[0]68));69s.startAsServer(GSSUtil.GSS_KRB5_MECH_OID);70s.x().setChannelBinding(new ChannelBinding(71InetAddress.getByName("client.rabbit.hole"),72InetAddress.getByName("host.rabbit.hole"),73new byte[0]74));75Context.handshake(c, s);7677// Both req, NOT match78c.startAsClient(OneKDC.SERVER, GSSUtil.GSS_KRB5_MECH_OID);79c.x().setChannelBinding(new ChannelBinding(80InetAddress.getByName("client.rabbit.hole"),81InetAddress.getByName("host.rabbit.hole"),82new byte[0]83));84s.startAsServer(GSSUtil.GSS_KRB5_MECH_OID);85s.x().setChannelBinding(new ChannelBinding(86InetAddress.getByName("client.rabbit.hole"),87InetAddress.getByName("host.rabbit.hole"),88new byte[1] // 0 -> 189));90try {91Context.handshake(c, s);92throw new Exception("Acceptor should reject initiator");93} catch (GSSException ge) {94// Expected bahavior95}9697// Acceptor req, reject98c.startAsClient(OneKDC.SERVER, GSSUtil.GSS_KRB5_MECH_OID);99s.startAsServer(GSSUtil.GSS_KRB5_MECH_OID);100s.x().setChannelBinding(new ChannelBinding(101InetAddress.getByName("client.rabbit.hole"),102InetAddress.getByName("host.rabbit.hole"),103new byte[0]104));105try {106Context.handshake(c, s);107throw new Exception("Acceptor should reject initiator");108} catch (GSSException ge) {109// Expected bahavior110if (ge.getMajor() != GSSException.BAD_BINDINGS) {111throw ge;112}113}114}115}116117118