jdk/test/sun/security/krb5/auto/Context.java
author weijun
Wed, 20 Apr 2011 18:41:32 +0800
changeset 9499 f3115698a012
parent 9035 1255eb81cc2f
child 10696 3811a12690ce
permissions -rw-r--r--
6894072: always refresh keytab Reviewed-by: valeriep
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
     1
/*
9035
1255eb81cc2f 7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents: 7977
diff changeset
     2
 * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
     4
 *
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
     7
 * published by the Free Software Foundation.
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
     8
 *
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    13
 * accompanied this code).
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    14
 *
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4336
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4336
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4336
diff changeset
    21
 * questions.
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    22
 */
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    23
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    24
import com.sun.security.auth.module.Krb5LoginModule;
3482
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents: 1575
diff changeset
    25
import java.security.Key;
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    26
import java.security.PrivilegedActionException;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    27
import java.security.PrivilegedExceptionAction;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    28
import java.util.Arrays;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    29
import java.util.HashMap;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    30
import java.util.Map;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    31
import javax.security.auth.Subject;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    32
import javax.security.auth.kerberos.KerberosKey;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    33
import javax.security.auth.kerberos.KerberosTicket;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    34
import javax.security.auth.login.LoginContext;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    35
import org.ietf.jgss.GSSContext;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    36
import org.ietf.jgss.GSSCredential;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    37
import org.ietf.jgss.GSSException;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    38
import org.ietf.jgss.GSSManager;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    39
import org.ietf.jgss.GSSName;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    40
import org.ietf.jgss.MessageProp;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    41
import org.ietf.jgss.Oid;
3482
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents: 1575
diff changeset
    42
import com.sun.security.jgss.ExtendedGSSContext;
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents: 1575
diff changeset
    43
import com.sun.security.jgss.InquireType;
3483
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 3482
diff changeset
    44
import com.sun.security.jgss.AuthorizationDataEntry;
7801
814c8359b104 6975866: api/org_ietf/jgss/GSSContext/index.html#wrapUnwrapIOTest started to fail since jdk7 b102
weijun
parents: 5774
diff changeset
    45
import java.io.ByteArrayInputStream;
814c8359b104 6975866: api/org_ietf/jgss/GSSContext/index.html#wrapUnwrapIOTest started to fail since jdk7 b102
weijun
parents: 5774
diff changeset
    46
import java.io.ByteArrayOutputStream;
9499
f3115698a012 6894072: always refresh keytab
weijun
parents: 9035
diff changeset
    47
import javax.security.auth.kerberos.KeyTab;
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    48
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    49
/**
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    50
 * Context of a JGSS subject, encapsulating Subject and GSSContext.
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    51
 *
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    52
 * Three "constructors", which acquire the (private) credentials and fill
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    53
 * it into the Subject:
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    54
 *
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    55
 * 1. static fromJAAS(): Creates a Context using a JAAS login config entry
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    56
 * 2. static fromUserPass(): Creates a Context using a username and a password
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    57
 * 3. delegated(): A new context which uses the delegated credentials from a
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    58
 *    previously established acceptor Context
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    59
 *
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    60
 * Two context initiators, which create the GSSContext object inside:
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    61
 *
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    62
 * 1. startAsClient()
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    63
 * 2. startAsServer()
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    64
 *
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    65
 * Privileged action:
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    66
 *    doAs(): Performs an action in the name of the Subject
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    67
 *
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    68
 * Handshake process:
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    69
 *    static handShake(initiator, acceptor)
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    70
 *
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    71
 * A four-phase typical data communication which includes all four GSS
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    72
 * actions (wrap, unwrap, getMic and veryfyMiC):
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    73
 *    static transmit(message, from, to)
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    74
 */
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    75
public class Context {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    76
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    77
    private Subject s;
4336
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3483
diff changeset
    78
    private ExtendedGSSContext x;
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    79
    private boolean f;      // context established?
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    80
    private String name;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    81
    private GSSCredential cred;     // see static method delegated().
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    82
7801
814c8359b104 6975866: api/org_ietf/jgss/GSSContext/index.html#wrapUnwrapIOTest started to fail since jdk7 b102
weijun
parents: 5774
diff changeset
    83
    static boolean usingStream = false;
814c8359b104 6975866: api/org_ietf/jgss/GSSContext/index.html#wrapUnwrapIOTest started to fail since jdk7 b102
weijun
parents: 5774
diff changeset
    84
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    85
    private Context() {}
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    86
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    87
    /**
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    88
     * Using the delegated credentials from a previous acceptor
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    89
     * @param c
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    90
     */
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    91
    public Context delegated() throws Exception {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    92
        Context out = new Context();
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    93
        out.s = s;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    94
        out.cred = x.getDelegCred();
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    95
        out.name = name + " as " + out.cred.getName().toString();
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    96
        return out;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    97
    }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    98
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    99
    /**
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   100
     * Logins with a JAAS login config entry name
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   101
     */
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   102
    public static Context fromJAAS(final String name) throws Exception {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   103
        Context out = new Context();
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   104
        out.name = name;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   105
        LoginContext lc = new LoginContext(name);
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   106
        lc.login();
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   107
        out.s = lc.getSubject();
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   108
        return out;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   109
    }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   110
9499
f3115698a012 6894072: always refresh keytab
weijun
parents: 9035
diff changeset
   111
    public static Context fromUserPass(
f3115698a012 6894072: always refresh keytab
weijun
parents: 9035
diff changeset
   112
            String user, char[] pass, boolean storeKey) throws Exception {
f3115698a012 6894072: always refresh keytab
weijun
parents: 9035
diff changeset
   113
        return fromUserPass(null, user, pass, storeKey);
f3115698a012 6894072: always refresh keytab
weijun
parents: 9035
diff changeset
   114
    }
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   115
    /**
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   116
     * Logins with a username and a password, using Krb5LoginModule directly
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   117
     * @param storeKey true if key should be saved, used on acceptor side
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   118
     */
9499
f3115698a012 6894072: always refresh keytab
weijun
parents: 9035
diff changeset
   119
    public static Context fromUserPass(Subject s,
f3115698a012 6894072: always refresh keytab
weijun
parents: 9035
diff changeset
   120
            String user, char[] pass, boolean storeKey) throws Exception {
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   121
        Context out = new Context();
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   122
        out.name = user;
9499
f3115698a012 6894072: always refresh keytab
weijun
parents: 9035
diff changeset
   123
        out.s = s == null ? new Subject() : s;
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   124
        Krb5LoginModule krb5 = new Krb5LoginModule();
7977
f47f211cd627 7008713: diamond conversion of kerberos5 and security tools
smarks
parents: 7816
diff changeset
   125
        Map<String, String> map = new HashMap<>();
f47f211cd627 7008713: diamond conversion of kerberos5 and security tools
smarks
parents: 7816
diff changeset
   126
        Map<String, Object> shared = new HashMap<>();
1575
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents: 1574
diff changeset
   127
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents: 1574
diff changeset
   128
        if (pass != null) {
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents: 1574
diff changeset
   129
            map.put("useFirstPass", "true");
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents: 1574
diff changeset
   130
            shared.put("javax.security.auth.login.name", user);
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents: 1574
diff changeset
   131
            shared.put("javax.security.auth.login.password", pass);
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents: 1574
diff changeset
   132
        } else {
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents: 1574
diff changeset
   133
            map.put("doNotPrompt", "true");
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents: 1574
diff changeset
   134
            map.put("useTicketCache", "true");
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents: 1574
diff changeset
   135
            if (user != null) {
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents: 1574
diff changeset
   136
                map.put("principal", user);
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents: 1574
diff changeset
   137
            }
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents: 1574
diff changeset
   138
        }
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   139
        if (storeKey) {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   140
            map.put("storeKey", "true");
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   141
        }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   142
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   143
        krb5.initialize(out.s, null, shared, map);
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   144
        krb5.login();
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   145
        krb5.commit();
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   146
        return out;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   147
    }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   148
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   149
    /**
5774
4b9857e483c1 6951366: kerberos login failure on win2008 with AD set to win2000 compat mode
weijun
parents: 5506
diff changeset
   150
     * Logins with a username and a keytab, using Krb5LoginModule directly
4b9857e483c1 6951366: kerberos login failure on win2008 with AD set to win2000 compat mode
weijun
parents: 5506
diff changeset
   151
     * @param storeKey true if key should be saved, used on acceptor side
4b9857e483c1 6951366: kerberos login failure on win2008 with AD set to win2000 compat mode
weijun
parents: 5506
diff changeset
   152
     */
4b9857e483c1 6951366: kerberos login failure on win2008 with AD set to win2000 compat mode
weijun
parents: 5506
diff changeset
   153
    public static Context fromUserKtab(String user, String ktab, boolean storeKey)
4b9857e483c1 6951366: kerberos login failure on win2008 with AD set to win2000 compat mode
weijun
parents: 5506
diff changeset
   154
            throws Exception {
4b9857e483c1 6951366: kerberos login failure on win2008 with AD set to win2000 compat mode
weijun
parents: 5506
diff changeset
   155
        Context out = new Context();
4b9857e483c1 6951366: kerberos login failure on win2008 with AD set to win2000 compat mode
weijun
parents: 5506
diff changeset
   156
        out.name = user;
4b9857e483c1 6951366: kerberos login failure on win2008 with AD set to win2000 compat mode
weijun
parents: 5506
diff changeset
   157
        out.s = new Subject();
4b9857e483c1 6951366: kerberos login failure on win2008 with AD set to win2000 compat mode
weijun
parents: 5506
diff changeset
   158
        Krb5LoginModule krb5 = new Krb5LoginModule();
7977
f47f211cd627 7008713: diamond conversion of kerberos5 and security tools
smarks
parents: 7816
diff changeset
   159
        Map<String, String> map = new HashMap<>();
5774
4b9857e483c1 6951366: kerberos login failure on win2008 with AD set to win2000 compat mode
weijun
parents: 5506
diff changeset
   160
4b9857e483c1 6951366: kerberos login failure on win2008 with AD set to win2000 compat mode
weijun
parents: 5506
diff changeset
   161
        map.put("doNotPrompt", "true");
4b9857e483c1 6951366: kerberos login failure on win2008 with AD set to win2000 compat mode
weijun
parents: 5506
diff changeset
   162
        map.put("useTicketCache", "false");
4b9857e483c1 6951366: kerberos login failure on win2008 with AD set to win2000 compat mode
weijun
parents: 5506
diff changeset
   163
        map.put("useKeyTab", "true");
4b9857e483c1 6951366: kerberos login failure on win2008 with AD set to win2000 compat mode
weijun
parents: 5506
diff changeset
   164
        map.put("keyTab", ktab);
4b9857e483c1 6951366: kerberos login failure on win2008 with AD set to win2000 compat mode
weijun
parents: 5506
diff changeset
   165
        map.put("principal", user);
4b9857e483c1 6951366: kerberos login failure on win2008 with AD set to win2000 compat mode
weijun
parents: 5506
diff changeset
   166
        if (storeKey) {
4b9857e483c1 6951366: kerberos login failure on win2008 with AD set to win2000 compat mode
weijun
parents: 5506
diff changeset
   167
            map.put("storeKey", "true");
4b9857e483c1 6951366: kerberos login failure on win2008 with AD set to win2000 compat mode
weijun
parents: 5506
diff changeset
   168
        }
4b9857e483c1 6951366: kerberos login failure on win2008 with AD set to win2000 compat mode
weijun
parents: 5506
diff changeset
   169
4b9857e483c1 6951366: kerberos login failure on win2008 with AD set to win2000 compat mode
weijun
parents: 5506
diff changeset
   170
        krb5.initialize(out.s, null, null, map);
4b9857e483c1 6951366: kerberos login failure on win2008 with AD set to win2000 compat mode
weijun
parents: 5506
diff changeset
   171
        krb5.login();
4b9857e483c1 6951366: kerberos login failure on win2008 with AD set to win2000 compat mode
weijun
parents: 5506
diff changeset
   172
        krb5.commit();
4b9857e483c1 6951366: kerberos login failure on win2008 with AD set to win2000 compat mode
weijun
parents: 5506
diff changeset
   173
        return out;
4b9857e483c1 6951366: kerberos login failure on win2008 with AD set to win2000 compat mode
weijun
parents: 5506
diff changeset
   174
    }
4b9857e483c1 6951366: kerberos login failure on win2008 with AD set to win2000 compat mode
weijun
parents: 5506
diff changeset
   175
4b9857e483c1 6951366: kerberos login failure on win2008 with AD set to win2000 compat mode
weijun
parents: 5506
diff changeset
   176
    /**
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   177
     * Starts as a client
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   178
     * @param target communication peer
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   179
     * @param mech GSS mech
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   180
     * @throws java.lang.Exception
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   181
     */
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   182
    public void startAsClient(final String target, final Oid mech) throws Exception {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   183
        doAs(new Action() {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   184
            @Override
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   185
            public byte[] run(Context me, byte[] dummy) throws Exception {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   186
                GSSManager m = GSSManager.getInstance();
4336
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3483
diff changeset
   187
                me.x = (ExtendedGSSContext)m.createContext(
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3483
diff changeset
   188
                          target.indexOf('@') < 0 ?
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   189
                            m.createName(target, null) :
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   190
                            m.createName(target, GSSName.NT_HOSTBASED_SERVICE),
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   191
                        mech,
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   192
                        cred,
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   193
                        GSSContext.DEFAULT_LIFETIME);
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   194
                return null;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   195
            }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   196
        }, null);
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   197
        f = false;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   198
    }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   199
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   200
    /**
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   201
     * Starts as a server
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   202
     * @param mech GSS mech
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   203
     * @throws java.lang.Exception
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   204
     */
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   205
    public void startAsServer(final Oid mech) throws Exception {
9499
f3115698a012 6894072: always refresh keytab
weijun
parents: 9035
diff changeset
   206
        startAsServer(null, mech);
f3115698a012 6894072: always refresh keytab
weijun
parents: 9035
diff changeset
   207
    }
f3115698a012 6894072: always refresh keytab
weijun
parents: 9035
diff changeset
   208
f3115698a012 6894072: always refresh keytab
weijun
parents: 9035
diff changeset
   209
    /**
f3115698a012 6894072: always refresh keytab
weijun
parents: 9035
diff changeset
   210
     * Starts as a server with the specified service name
f3115698a012 6894072: always refresh keytab
weijun
parents: 9035
diff changeset
   211
     * @param name the service name
f3115698a012 6894072: always refresh keytab
weijun
parents: 9035
diff changeset
   212
     * @param mech GSS mech
f3115698a012 6894072: always refresh keytab
weijun
parents: 9035
diff changeset
   213
     * @throws java.lang.Exception
f3115698a012 6894072: always refresh keytab
weijun
parents: 9035
diff changeset
   214
     */
f3115698a012 6894072: always refresh keytab
weijun
parents: 9035
diff changeset
   215
    public void startAsServer(final String name, final Oid mech) throws Exception {
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   216
        doAs(new Action() {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   217
            @Override
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   218
            public byte[] run(Context me, byte[] dummy) throws Exception {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   219
                GSSManager m = GSSManager.getInstance();
4336
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3483
diff changeset
   220
                me.x = (ExtendedGSSContext)m.createContext(m.createCredential(
9499
f3115698a012 6894072: always refresh keytab
weijun
parents: 9035
diff changeset
   221
                        name == null ? null :
f3115698a012 6894072: always refresh keytab
weijun
parents: 9035
diff changeset
   222
                          (name.indexOf('@') < 0 ?
f3115698a012 6894072: always refresh keytab
weijun
parents: 9035
diff changeset
   223
                            m.createName(name, null) :
f3115698a012 6894072: always refresh keytab
weijun
parents: 9035
diff changeset
   224
                            m.createName(name, GSSName.NT_HOSTBASED_SERVICE)),
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   225
                        GSSCredential.INDEFINITE_LIFETIME,
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   226
                        mech,
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   227
                        GSSCredential.ACCEPT_ONLY));
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   228
                return null;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   229
            }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   230
        }, null);
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   231
        f = false;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   232
    }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   233
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   234
    /**
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   235
     * Accesses the internal GSSContext object. Currently it's used for --
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   236
     *
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   237
     * 1. calling requestXXX() before handshake
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   238
     * 2. accessing source name
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   239
     *
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   240
     * Note: If the application needs to do any privileged call on this
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   241
     * object, please use doAs(). Otherwise, it can be done directly. The
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   242
     * methods listed above are all non-privileged calls.
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   243
     *
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   244
     * @return the GSSContext object
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   245
     */
4336
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3483
diff changeset
   246
    public ExtendedGSSContext x() {
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   247
        return x;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   248
    }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   249
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   250
    /**
9499
f3115698a012 6894072: always refresh keytab
weijun
parents: 9035
diff changeset
   251
     * Accesses the internal subject.
f3115698a012 6894072: always refresh keytab
weijun
parents: 9035
diff changeset
   252
     * @return the subject
f3115698a012 6894072: always refresh keytab
weijun
parents: 9035
diff changeset
   253
     */
f3115698a012 6894072: always refresh keytab
weijun
parents: 9035
diff changeset
   254
    public Subject s() {
f3115698a012 6894072: always refresh keytab
weijun
parents: 9035
diff changeset
   255
        return s;
f3115698a012 6894072: always refresh keytab
weijun
parents: 9035
diff changeset
   256
    }
f3115698a012 6894072: always refresh keytab
weijun
parents: 9035
diff changeset
   257
f3115698a012 6894072: always refresh keytab
weijun
parents: 9035
diff changeset
   258
    /**
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   259
     * Disposes the GSSContext within
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   260
     * @throws org.ietf.jgss.GSSException
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   261
     */
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   262
    public void dispose() throws GSSException {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   263
        x.dispose();
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   264
    }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   265
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   266
    /**
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   267
     * Does something using the Subject inside
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   268
     * @param action the action
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   269
     * @param in the input byte
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   270
     * @return the output byte
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   271
     * @throws java.lang.Exception
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   272
     */
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   273
    public byte[] doAs(final Action action, final byte[] in) throws Exception {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   274
        try {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   275
            return Subject.doAs(s, new PrivilegedExceptionAction<byte[]>() {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   276
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   277
                @Override
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   278
                public byte[] run() throws Exception {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   279
                    return action.run(Context.this, in);
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   280
                }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   281
            });
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   282
        } catch (PrivilegedActionException pae) {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   283
            throw pae.getException();
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   284
        }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   285
    }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   286
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   287
    /**
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   288
     * Prints status of GSSContext and Subject
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   289
     * @throws java.lang.Exception
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   290
     */
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   291
    public void status() throws Exception {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   292
        System.out.println("STATUS OF " + name.toUpperCase());
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   293
        try {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   294
            StringBuffer sb = new StringBuffer();
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   295
            if (x.getAnonymityState()) {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   296
                sb.append("anon, ");
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   297
            }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   298
            if (x.getConfState()) {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   299
                sb.append("conf, ");
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   300
            }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   301
            if (x.getCredDelegState()) {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   302
                sb.append("deleg, ");
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   303
            }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   304
            if (x.getIntegState()) {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   305
                sb.append("integ, ");
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   306
            }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   307
            if (x.getMutualAuthState()) {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   308
                sb.append("mutual, ");
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   309
            }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   310
            if (x.getReplayDetState()) {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   311
                sb.append("rep det, ");
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   312
            }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   313
            if (x.getSequenceDetState()) {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   314
                sb.append("seq det, ");
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   315
            }
4336
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3483
diff changeset
   316
            if (x instanceof ExtendedGSSContext) {
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3483
diff changeset
   317
                if (((ExtendedGSSContext)x).getDelegPolicyState()) {
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3483
diff changeset
   318
                    sb.append("deleg policy, ");
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3483
diff changeset
   319
                }
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3483
diff changeset
   320
            }
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   321
            System.out.println("Context status of " + name + ": " + sb.toString());
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   322
            System.out.println(x.getSrcName() + " -> " + x.getTargName());
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   323
        } catch (Exception e) {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   324
            ;// Don't care
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   325
        }
9499
f3115698a012 6894072: always refresh keytab
weijun
parents: 9035
diff changeset
   326
        System.out.println("====== Private Credentials Set ======");
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   327
        for (Object o : s.getPrivateCredentials()) {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   328
            System.out.println("    " + o.getClass());
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   329
            if (o instanceof KerberosTicket) {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   330
                KerberosTicket kt = (KerberosTicket) o;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   331
                System.out.println("        " + kt.getServer() + " for " + kt.getClient());
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   332
            } else if (o instanceof KerberosKey) {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   333
                KerberosKey kk = (KerberosKey) o;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   334
                System.out.print("        " + kk.getKeyType() + " " + kk.getVersionNumber() + " " + kk.getAlgorithm() + " ");
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   335
                for (byte b : kk.getEncoded()) {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   336
                    System.out.printf("%02X", b & 0xff);
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   337
                }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   338
                System.out.println();
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   339
            } else if (o instanceof Map) {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   340
                Map map = (Map) o;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   341
                for (Object k : map.keySet()) {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   342
                    System.out.println("        " + k + ": " + map.get(k));
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   343
                }
9499
f3115698a012 6894072: always refresh keytab
weijun
parents: 9035
diff changeset
   344
            } else {
f3115698a012 6894072: always refresh keytab
weijun
parents: 9035
diff changeset
   345
                System.out.println("        " + o);
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   346
            }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   347
        }
3482
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents: 1575
diff changeset
   348
        if (x != null && x instanceof ExtendedGSSContext) {
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents: 1575
diff changeset
   349
            if (x.isEstablished()) {
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents: 1575
diff changeset
   350
                ExtendedGSSContext ex = (ExtendedGSSContext)x;
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents: 1575
diff changeset
   351
                Key k = (Key)ex.inquireSecContext(
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents: 1575
diff changeset
   352
                        InquireType.KRB5_GET_SESSION_KEY);
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents: 1575
diff changeset
   353
                if (k == null) {
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents: 1575
diff changeset
   354
                    throw new Exception("Session key cannot be null");
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents: 1575
diff changeset
   355
                }
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents: 1575
diff changeset
   356
                System.out.println("Session key is: " + k);
3483
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 3482
diff changeset
   357
                boolean[] flags = (boolean[])ex.inquireSecContext(
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 3482
diff changeset
   358
                        InquireType.KRB5_GET_TKT_FLAGS);
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 3482
diff changeset
   359
                if (flags == null) {
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 3482
diff changeset
   360
                    throw new Exception("Ticket flags cannot be null");
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 3482
diff changeset
   361
                }
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 3482
diff changeset
   362
                System.out.println("Ticket flags is: " + Arrays.toString(flags));
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 3482
diff changeset
   363
                String authTime = (String)ex.inquireSecContext(
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 3482
diff changeset
   364
                        InquireType.KRB5_GET_AUTHTIME);
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 3482
diff changeset
   365
                if (authTime == null) {
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 3482
diff changeset
   366
                    throw new Exception("Auth time cannot be null");
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 3482
diff changeset
   367
                }
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 3482
diff changeset
   368
                System.out.println("AuthTime is: " + authTime);
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 3482
diff changeset
   369
                if (!x.isInitiator()) {
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 3482
diff changeset
   370
                    AuthorizationDataEntry[] ad = (AuthorizationDataEntry[])ex.inquireSecContext(
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 3482
diff changeset
   371
                            InquireType.KRB5_GET_AUTHZ_DATA);
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 3482
diff changeset
   372
                    System.out.println("AuthzData is: " + Arrays.toString(ad));
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 3482
diff changeset
   373
                }
3482
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents: 1575
diff changeset
   374
            }
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents: 1575
diff changeset
   375
        }
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   376
    }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   377
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   378
    /**
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   379
     * Transmits a message from one Context to another. The sender wraps the
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   380
     * message and sends it to the receiver. The receiver unwraps it, creates
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   381
     * a MIC of the clear text and sends it back to the sender. The sender
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   382
     * verifies the MIC against the message sent earlier.
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   383
     * @param message the message
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   384
     * @param s1 the sender
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   385
     * @param s2 the receiver
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   386
     * @throws java.lang.Exception If anything goes wrong
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   387
     */
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   388
    static public void transmit(final String message, final Context s1,
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   389
            final Context s2) throws Exception {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   390
        final byte[] messageBytes = message.getBytes();
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   391
        System.out.printf("-------------------- TRANSMIT from %s to %s------------------------\n",
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   392
                s1.name, s2.name);
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   393
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   394
        byte[] t = s1.doAs(new Action() {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   395
            @Override
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   396
            public byte[] run(Context me, byte[] dummy) throws Exception {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   397
                System.out.println("wrap");
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   398
                MessageProp p1 = new MessageProp(0, true);
7801
814c8359b104 6975866: api/org_ietf/jgss/GSSContext/index.html#wrapUnwrapIOTest started to fail since jdk7 b102
weijun
parents: 5774
diff changeset
   399
                byte[] out;
814c8359b104 6975866: api/org_ietf/jgss/GSSContext/index.html#wrapUnwrapIOTest started to fail since jdk7 b102
weijun
parents: 5774
diff changeset
   400
                if (usingStream) {
814c8359b104 6975866: api/org_ietf/jgss/GSSContext/index.html#wrapUnwrapIOTest started to fail since jdk7 b102
weijun
parents: 5774
diff changeset
   401
                    ByteArrayOutputStream os = new ByteArrayOutputStream();
814c8359b104 6975866: api/org_ietf/jgss/GSSContext/index.html#wrapUnwrapIOTest started to fail since jdk7 b102
weijun
parents: 5774
diff changeset
   402
                    me.x.wrap(new ByteArrayInputStream(messageBytes), os, p1);
814c8359b104 6975866: api/org_ietf/jgss/GSSContext/index.html#wrapUnwrapIOTest started to fail since jdk7 b102
weijun
parents: 5774
diff changeset
   403
                    out = os.toByteArray();
814c8359b104 6975866: api/org_ietf/jgss/GSSContext/index.html#wrapUnwrapIOTest started to fail since jdk7 b102
weijun
parents: 5774
diff changeset
   404
                } else {
814c8359b104 6975866: api/org_ietf/jgss/GSSContext/index.html#wrapUnwrapIOTest started to fail since jdk7 b102
weijun
parents: 5774
diff changeset
   405
                    out = me.x.wrap(messageBytes, 0, messageBytes.length, p1);
814c8359b104 6975866: api/org_ietf/jgss/GSSContext/index.html#wrapUnwrapIOTest started to fail since jdk7 b102
weijun
parents: 5774
diff changeset
   406
                }
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   407
                System.out.println(printProp(p1));
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   408
                return out;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   409
            }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   410
        }, null);
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   411
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   412
        t = s2.doAs(new Action() {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   413
            @Override
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   414
            public byte[] run(Context me, byte[] input) throws Exception {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   415
                MessageProp p1 = new MessageProp(0, true);
7801
814c8359b104 6975866: api/org_ietf/jgss/GSSContext/index.html#wrapUnwrapIOTest started to fail since jdk7 b102
weijun
parents: 5774
diff changeset
   416
                byte[] bytes;
814c8359b104 6975866: api/org_ietf/jgss/GSSContext/index.html#wrapUnwrapIOTest started to fail since jdk7 b102
weijun
parents: 5774
diff changeset
   417
                if (usingStream) {
814c8359b104 6975866: api/org_ietf/jgss/GSSContext/index.html#wrapUnwrapIOTest started to fail since jdk7 b102
weijun
parents: 5774
diff changeset
   418
                    ByteArrayOutputStream os = new ByteArrayOutputStream();
814c8359b104 6975866: api/org_ietf/jgss/GSSContext/index.html#wrapUnwrapIOTest started to fail since jdk7 b102
weijun
parents: 5774
diff changeset
   419
                    me.x.unwrap(new ByteArrayInputStream(input), os, p1);
814c8359b104 6975866: api/org_ietf/jgss/GSSContext/index.html#wrapUnwrapIOTest started to fail since jdk7 b102
weijun
parents: 5774
diff changeset
   420
                    bytes = os.toByteArray();
814c8359b104 6975866: api/org_ietf/jgss/GSSContext/index.html#wrapUnwrapIOTest started to fail since jdk7 b102
weijun
parents: 5774
diff changeset
   421
                } else {
814c8359b104 6975866: api/org_ietf/jgss/GSSContext/index.html#wrapUnwrapIOTest started to fail since jdk7 b102
weijun
parents: 5774
diff changeset
   422
                    bytes = me.x.unwrap(input, 0, input.length, p1);
814c8359b104 6975866: api/org_ietf/jgss/GSSContext/index.html#wrapUnwrapIOTest started to fail since jdk7 b102
weijun
parents: 5774
diff changeset
   423
                }
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   424
                if (!Arrays.equals(messageBytes, bytes))
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   425
                    throw new Exception("wrap/unwrap mismatch");
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   426
                System.out.println("unwrap");
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   427
                System.out.println(printProp(p1));
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   428
                p1 = new MessageProp(0, true);
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   429
                System.out.println("getMIC");
7801
814c8359b104 6975866: api/org_ietf/jgss/GSSContext/index.html#wrapUnwrapIOTest started to fail since jdk7 b102
weijun
parents: 5774
diff changeset
   430
                if (usingStream) {
814c8359b104 6975866: api/org_ietf/jgss/GSSContext/index.html#wrapUnwrapIOTest started to fail since jdk7 b102
weijun
parents: 5774
diff changeset
   431
                    ByteArrayOutputStream os = new ByteArrayOutputStream();
814c8359b104 6975866: api/org_ietf/jgss/GSSContext/index.html#wrapUnwrapIOTest started to fail since jdk7 b102
weijun
parents: 5774
diff changeset
   432
                    me.x.getMIC(new ByteArrayInputStream(messageBytes), os, p1);
814c8359b104 6975866: api/org_ietf/jgss/GSSContext/index.html#wrapUnwrapIOTest started to fail since jdk7 b102
weijun
parents: 5774
diff changeset
   433
                    bytes = os.toByteArray();
814c8359b104 6975866: api/org_ietf/jgss/GSSContext/index.html#wrapUnwrapIOTest started to fail since jdk7 b102
weijun
parents: 5774
diff changeset
   434
                } else {
814c8359b104 6975866: api/org_ietf/jgss/GSSContext/index.html#wrapUnwrapIOTest started to fail since jdk7 b102
weijun
parents: 5774
diff changeset
   435
                    bytes = me.x.getMIC(messageBytes, 0, messageBytes.length, p1);
814c8359b104 6975866: api/org_ietf/jgss/GSSContext/index.html#wrapUnwrapIOTest started to fail since jdk7 b102
weijun
parents: 5774
diff changeset
   436
                }
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   437
                System.out.println(printProp(p1));
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   438
                return bytes;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   439
            }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   440
        }, t);
7801
814c8359b104 6975866: api/org_ietf/jgss/GSSContext/index.html#wrapUnwrapIOTest started to fail since jdk7 b102
weijun
parents: 5774
diff changeset
   441
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   442
        // Re-unwrap should make p2.isDuplicateToken() returns true
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   443
        s1.doAs(new Action() {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   444
            @Override
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   445
            public byte[] run(Context me, byte[] input) throws Exception {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   446
                MessageProp p1 = new MessageProp(0, true);
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   447
                System.out.println("verifyMIC");
7801
814c8359b104 6975866: api/org_ietf/jgss/GSSContext/index.html#wrapUnwrapIOTest started to fail since jdk7 b102
weijun
parents: 5774
diff changeset
   448
                if (usingStream) {
814c8359b104 6975866: api/org_ietf/jgss/GSSContext/index.html#wrapUnwrapIOTest started to fail since jdk7 b102
weijun
parents: 5774
diff changeset
   449
                    me.x.verifyMIC(new ByteArrayInputStream(input),
814c8359b104 6975866: api/org_ietf/jgss/GSSContext/index.html#wrapUnwrapIOTest started to fail since jdk7 b102
weijun
parents: 5774
diff changeset
   450
                            new ByteArrayInputStream(messageBytes), p1);
814c8359b104 6975866: api/org_ietf/jgss/GSSContext/index.html#wrapUnwrapIOTest started to fail since jdk7 b102
weijun
parents: 5774
diff changeset
   451
                } else {
814c8359b104 6975866: api/org_ietf/jgss/GSSContext/index.html#wrapUnwrapIOTest started to fail since jdk7 b102
weijun
parents: 5774
diff changeset
   452
                    me.x.verifyMIC(input, 0, input.length,
814c8359b104 6975866: api/org_ietf/jgss/GSSContext/index.html#wrapUnwrapIOTest started to fail since jdk7 b102
weijun
parents: 5774
diff changeset
   453
                            messageBytes, 0, messageBytes.length,
814c8359b104 6975866: api/org_ietf/jgss/GSSContext/index.html#wrapUnwrapIOTest started to fail since jdk7 b102
weijun
parents: 5774
diff changeset
   454
                            p1);
814c8359b104 6975866: api/org_ietf/jgss/GSSContext/index.html#wrapUnwrapIOTest started to fail since jdk7 b102
weijun
parents: 5774
diff changeset
   455
                }
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   456
                System.out.println(printProp(p1));
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   457
                return null;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   458
            }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   459
        }, t);
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   460
    }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   461
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   462
    /**
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   463
     * Returns a string description of a MessageProp object
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   464
     * @param prop the object
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   465
     * @return the description
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   466
     */
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   467
    static public String printProp(MessageProp prop) {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   468
        StringBuffer sb = new StringBuffer();
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   469
        sb.append("MessagePop: ");
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   470
        sb.append("QOP="+ prop.getQOP() + ", ");
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   471
        sb.append(prop.getPrivacy()?"privacy, ":"");
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   472
        sb.append(prop.isDuplicateToken()?"dup, ":"");
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   473
        sb.append(prop.isGapToken()?"gap, ":"");
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   474
        sb.append(prop.isOldToken()?"old, ":"");
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   475
        sb.append(prop.isUnseqToken()?"unseq, ":"");
7801
814c8359b104 6975866: api/org_ietf/jgss/GSSContext/index.html#wrapUnwrapIOTest started to fail since jdk7 b102
weijun
parents: 5774
diff changeset
   476
        if (prop.getMinorStatus() != 0) {
814c8359b104 6975866: api/org_ietf/jgss/GSSContext/index.html#wrapUnwrapIOTest started to fail since jdk7 b102
weijun
parents: 5774
diff changeset
   477
            sb.append(prop.getMinorString()+ "(" + prop.getMinorStatus()+")");
814c8359b104 6975866: api/org_ietf/jgss/GSSContext/index.html#wrapUnwrapIOTest started to fail since jdk7 b102
weijun
parents: 5774
diff changeset
   478
        }
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   479
        return sb.toString();
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   480
    }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   481
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   482
    /**
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   483
     * Handshake (security context establishment process) between two Contexts
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   484
     * @param c the initiator
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   485
     * @param s the acceptor
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   486
     * @throws java.lang.Exception
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   487
     */
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   488
    static public void handshake(final Context c, final Context s) throws Exception {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   489
        byte[] t = new byte[0];
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   490
        while (!c.f || !s.f) {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   491
            t = c.doAs(new Action() {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   492
                @Override
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   493
                public byte[] run(Context me, byte[] input) throws Exception {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   494
                    if (me.x.isEstablished()) {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   495
                        me.f = true;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   496
                        System.out.println(c.name + " side established");
1574
7aad9fe14378 6733095: Failure when SPNEGO request non-Mutual
weijun
parents: 1454
diff changeset
   497
                        if (input != null) {
7aad9fe14378 6733095: Failure when SPNEGO request non-Mutual
weijun
parents: 1454
diff changeset
   498
                            throw new Exception("Context established but " +
7aad9fe14378 6733095: Failure when SPNEGO request non-Mutual
weijun
parents: 1454
diff changeset
   499
                                    "still receive token at " + c.name);
7aad9fe14378 6733095: Failure when SPNEGO request non-Mutual
weijun
parents: 1454
diff changeset
   500
                        }
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   501
                        return null;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   502
                    } else {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   503
                        System.out.println(c.name + " call initSecContext");
7801
814c8359b104 6975866: api/org_ietf/jgss/GSSContext/index.html#wrapUnwrapIOTest started to fail since jdk7 b102
weijun
parents: 5774
diff changeset
   504
                        if (usingStream) {
814c8359b104 6975866: api/org_ietf/jgss/GSSContext/index.html#wrapUnwrapIOTest started to fail since jdk7 b102
weijun
parents: 5774
diff changeset
   505
                            ByteArrayOutputStream os = new ByteArrayOutputStream();
814c8359b104 6975866: api/org_ietf/jgss/GSSContext/index.html#wrapUnwrapIOTest started to fail since jdk7 b102
weijun
parents: 5774
diff changeset
   506
                            me.x.initSecContext(new ByteArrayInputStream(input), os);
814c8359b104 6975866: api/org_ietf/jgss/GSSContext/index.html#wrapUnwrapIOTest started to fail since jdk7 b102
weijun
parents: 5774
diff changeset
   507
                            return os.size() == 0 ? null : os.toByteArray();
814c8359b104 6975866: api/org_ietf/jgss/GSSContext/index.html#wrapUnwrapIOTest started to fail since jdk7 b102
weijun
parents: 5774
diff changeset
   508
                        } else {
814c8359b104 6975866: api/org_ietf/jgss/GSSContext/index.html#wrapUnwrapIOTest started to fail since jdk7 b102
weijun
parents: 5774
diff changeset
   509
                            return me.x.initSecContext(input, 0, input.length);
814c8359b104 6975866: api/org_ietf/jgss/GSSContext/index.html#wrapUnwrapIOTest started to fail since jdk7 b102
weijun
parents: 5774
diff changeset
   510
                        }
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   511
                    }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   512
                }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   513
            }, t);
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   514
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   515
            t = s.doAs(new Action() {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   516
                @Override
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   517
                public byte[] run(Context me, byte[] input) throws Exception {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   518
                    if (me.x.isEstablished()) {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   519
                        me.f = true;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   520
                        System.out.println(s.name + " side established");
1574
7aad9fe14378 6733095: Failure when SPNEGO request non-Mutual
weijun
parents: 1454
diff changeset
   521
                        if (input != null) {
7aad9fe14378 6733095: Failure when SPNEGO request non-Mutual
weijun
parents: 1454
diff changeset
   522
                            throw new Exception("Context established but " +
7aad9fe14378 6733095: Failure when SPNEGO request non-Mutual
weijun
parents: 1454
diff changeset
   523
                                    "still receive token at " + s.name);
7aad9fe14378 6733095: Failure when SPNEGO request non-Mutual
weijun
parents: 1454
diff changeset
   524
                        }
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   525
                        return null;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   526
                    } else {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   527
                        System.out.println(s.name + " called acceptSecContext");
7801
814c8359b104 6975866: api/org_ietf/jgss/GSSContext/index.html#wrapUnwrapIOTest started to fail since jdk7 b102
weijun
parents: 5774
diff changeset
   528
                        if (usingStream) {
814c8359b104 6975866: api/org_ietf/jgss/GSSContext/index.html#wrapUnwrapIOTest started to fail since jdk7 b102
weijun
parents: 5774
diff changeset
   529
                            ByteArrayOutputStream os = new ByteArrayOutputStream();
814c8359b104 6975866: api/org_ietf/jgss/GSSContext/index.html#wrapUnwrapIOTest started to fail since jdk7 b102
weijun
parents: 5774
diff changeset
   530
                            me.x.acceptSecContext(new ByteArrayInputStream(input), os);
814c8359b104 6975866: api/org_ietf/jgss/GSSContext/index.html#wrapUnwrapIOTest started to fail since jdk7 b102
weijun
parents: 5774
diff changeset
   531
                            return os.size() == 0 ? null : os.toByteArray();
814c8359b104 6975866: api/org_ietf/jgss/GSSContext/index.html#wrapUnwrapIOTest started to fail since jdk7 b102
weijun
parents: 5774
diff changeset
   532
                        } else {
814c8359b104 6975866: api/org_ietf/jgss/GSSContext/index.html#wrapUnwrapIOTest started to fail since jdk7 b102
weijun
parents: 5774
diff changeset
   533
                            return me.x.acceptSecContext(input, 0, input.length);
814c8359b104 6975866: api/org_ietf/jgss/GSSContext/index.html#wrapUnwrapIOTest started to fail since jdk7 b102
weijun
parents: 5774
diff changeset
   534
                        }
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   535
                    }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   536
                }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   537
            }, t);
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   538
        }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   539
    }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   540
}