4413N/A/*
4413N/A * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
4413N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4413N/A *
4413N/A * This code is free software; you can redistribute it and/or modify it
4413N/A * under the terms of the GNU General Public License version 2 only, as
4413N/A * published by the Free Software Foundation.
4413N/A *
4413N/A * This code is distributed in the hope that it will be useful, but WITHOUT
4413N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4413N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4413N/A * version 2 for more details (a copy is included in the LICENSE file that
4413N/A * accompanied this code).
4413N/A *
4413N/A * You should have received a copy of the GNU General Public License version
4413N/A * 2 along with this work; if not, write to the Free Software Foundation,
4413N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4413N/A *
4413N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4413N/A * or visit www.oracle.com if you need additional information or have any
4413N/A * questions.
4413N/A */
4413N/A
4413N/A/*
4413N/A * @test
4413N/A * @bug 7077640
4413N/A * @summary gss wrap for cfx doesn't handle rrc != 0
4413N/A * @compile -XDignore.symbol.file RRC.java
4413N/A * @run main/othervm RRC
4413N/A */
4413N/A
4413N/Aimport java.util.Arrays;
4413N/Aimport sun.security.jgss.GSSUtil;
4413N/A
4413N/A// The basic krb5 test skeleton you can copy from
4413N/Apublic class RRC {
4413N/A
4413N/A public static void main(String[] args) throws Exception {
4413N/A
4413N/A new OneKDC(null).writeJAASConf();
4413N/A
4413N/A Context c, s;
4413N/A c = Context.fromJAAS("client");
4413N/A s = Context.fromJAAS("server");
4413N/A
4413N/A c.startAsClient(OneKDC.SERVER, GSSUtil.GSS_SPNEGO_MECH_OID);
4413N/A s.startAsServer(GSSUtil.GSS_SPNEGO_MECH_OID);
4413N/A
4413N/A Context.handshake(c, s);
4413N/A
4413N/A byte[] msg = "i say high --".getBytes();
4413N/A byte[] wrapped = c.wrap(msg, false);
4413N/A
4413N/A // Simulate RRC equals to EC
4413N/A int rrc = wrapped[5];
4413N/A byte[] rotated = new byte[wrapped.length];
4413N/A System.arraycopy(wrapped, 0, rotated, 0, 16);
4413N/A System.arraycopy(wrapped, wrapped.length-rrc, rotated, 16, rrc);
4413N/A System.arraycopy(wrapped, 16, rotated, 16+rrc, wrapped.length-16-rrc);
4413N/A rotated[7] = (byte)rrc;
4413N/A
4413N/A byte[] unwrapped = s.unwrap(rotated, false);
4413N/A if (!Arrays.equals(msg, unwrapped)) {
4413N/A throw new Exception("Failure");
4413N/A }
4413N/A
4413N/A s.dispose();
4413N/A c.dispose();
4413N/A }
4413N/A}