Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/security/krb5/auto/NoAddresses.java
38854 views
/*1* Copyright (c) 2011, 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 703235426* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock NoAddresses 127* @run main/othervm -Dsun.net.spi.nameservice.provider.1=ns,mock NoAddresses 228* @run main/othervm/fail -Dsun.net.spi.nameservice.provider.1=ns,mock NoAddresses 329* @summary no-addresses should not be used on acceptor side30*/3132import java.net.InetAddress;33import org.ietf.jgss.ChannelBinding;34import sun.security.jgss.GSSUtil;35import sun.security.krb5.Config;3637public class NoAddresses {3839public static void main(String[] args)40throws Exception {4142OneKDC kdc = new OneKDC(null);43kdc.writeJAASConf();44KDC.saveConfig(OneKDC.KRB5_CONF, kdc,45"noaddresses = false",46"default_keytab_name = " + OneKDC.KTAB);47Config.refresh();4849Context c = Context.fromJAAS("client");50Context s = Context.fromJAAS("server");5152c.startAsClient(OneKDC.SERVER, GSSUtil.GSS_KRB5_MECH_OID);53s.startAsServer(GSSUtil.GSS_KRB5_MECH_OID);5455InetAddress initiator = InetAddress.getLocalHost();56InetAddress acceptor = InetAddress.getLocalHost();57switch (args[0]) {58case "1":59// no initiator host address available, should be OK60break;61case "2":62// correct initiator host address, still fine63c.x().setChannelBinding(64new ChannelBinding(initiator, acceptor, null));65s.x().setChannelBinding(66new ChannelBinding(initiator, acceptor, null));67break;68case "3":69// incorrect initiator host address, fail70initiator = InetAddress.getByAddress(new byte[]{1,1,1,1});71c.x().setChannelBinding(72new ChannelBinding(initiator, acceptor, null));73s.x().setChannelBinding(74new ChannelBinding(initiator, acceptor, null));75break;76}7778Context.handshake(c, s);79}80}818283