Path: blob/master/test/jdk/sun/security/krb5/auto/MSOID2.java
41152 views
/*1* Copyright (c) 2015, 2020, 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 8078439 819448626* @summary SPNEGO auth fails if client proposes MS krb5 OID27* @library /test/lib28* @compile -XDignore.symbol.file MSOID2.java29* @run main jdk.test.lib.FileInstaller TestHosts TestHosts30* @run main/othervm -Djdk.net.hosts.file=TestHosts MSOID231*/3233import sun.security.jgss.GSSUtil;34import jdk.test.lib.hexdump.HexPrinter;3536// The basic krb5 test skeleton you can copy from37public class MSOID2 {3839public static void main(String[] args) throws Exception {4041new OneKDC(null).writeJAASConf();4243Context c, s;44c = Context.fromJAAS("client");45s = Context.fromJAAS("server");4647c.startAsClient(OneKDC.SERVER, GSSUtil.GSS_SPNEGO_MECH_OID);48s.startAsServer(GSSUtil.GSS_SPNEGO_MECH_OID);4950byte[] t = new byte[0];51boolean first = true;52while (true) {53if (t != null || !c.x().isEstablished()) t = c.take(t);54if (first) {55// Tweak the packet to append an extra OID56int len = t.length;57byte[] nt = new byte[len + 11];58System.arraycopy(t, 0, nt, 0, 0x23);59System.arraycopy(t, 0x18, nt, 0x23, 11); // dup the OID60System.arraycopy(t, 0x23, nt, 0x2e, len-0x23);61nt[0x1d] = (byte)0x82; // change the 1st to MS OID62// Length bytes to be tweaked63for (int pos: new int[] {3, 0xf, 0x13, 0x15, 0x17}) {64int newLen = (nt[pos]&0xff) + 11;65// The length byte at nt[pos] might overflow. It's66// unlikely for nt[pos-1] to overflow, which means the size67// of token is bigger than 65535.68if (newLen >= 256) {69nt[pos-1] = (byte)(nt[pos-1] + 1);70}71nt[pos] = (byte)newLen;72}73t = nt;74HexPrinter.simple().format(t);75}76if (t != null || !s.x().isEstablished()) t = s.take(t);77if (c.x().isEstablished() && s.x().isEstablished()) break;78first = false;79}8081Context.transmit("i say high --", c, s);82Context.transmit(" you say low", s, c);8384s.dispose();85c.dispose();86}87}888990