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