test/jdk/sun/security/krb5/auto/NewInquireTypes.java
author ssahoo
Thu, 25 Jan 2018 05:57:22 -0800
changeset 48668 2da4a52715d8
parent 47216 71c04702a3d5
permissions -rw-r--r--
8194486: Several krb5 tests failed in Mac. Summary: Several tests failed due to improper host service Reviewed-by: weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
25661
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
diff changeset
     1
/*
48668
2da4a52715d8 8194486: Several krb5 tests failed in Mac.
ssahoo
parents: 47216
diff changeset
     2
 * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
25661
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
diff changeset
     4
 *
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
diff changeset
     7
 * published by the Free Software Foundation.
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
diff changeset
     8
 *
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
diff changeset
    13
 * accompanied this code).
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
diff changeset
    14
 *
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
diff changeset
    18
 *
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
diff changeset
    21
 * questions.
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
diff changeset
    22
 */
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
diff changeset
    23
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
diff changeset
    24
/*
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
diff changeset
    25
 * @test
48668
2da4a52715d8 8194486: Several krb5 tests failed in Mac.
ssahoo
parents: 47216
diff changeset
    26
 * @bug 8043071 8194486
25661
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
diff changeset
    27
 * @summary Expose session key and KRB_CRED through extended GSS-API
48668
2da4a52715d8 8194486: Several krb5 tests failed in Mac.
ssahoo
parents: 47216
diff changeset
    28
 * @library /test/lib
25661
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
diff changeset
    29
 * @compile -XDignore.symbol.file NewInquireTypes.java
48668
2da4a52715d8 8194486: Several krb5 tests failed in Mac.
ssahoo
parents: 47216
diff changeset
    30
 * @run main jdk.test.lib.FileInstaller TestHosts TestHosts
2da4a52715d8 8194486: Several krb5 tests failed in Mac.
ssahoo
parents: 47216
diff changeset
    31
 * @run main/othervm -Djdk.net.hosts.file=TestHosts NewInquireTypes
25661
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
diff changeset
    32
 */
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
diff changeset
    33
26629
3b9ed8175488 8042900: Allow com.sun.security.jgss to be in different module than org.ietf.jgss
weijun
parents: 25661
diff changeset
    34
import com.sun.security.jgss.ExtendedGSSContext;
25661
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
diff changeset
    35
import com.sun.security.jgss.InquireType;
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
diff changeset
    36
import sun.security.jgss.GSSUtil;
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
diff changeset
    37
import sun.security.krb5.internal.KRBCred;
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
diff changeset
    38
import sun.security.krb5.internal.crypto.KeyUsage;
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
diff changeset
    39
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
diff changeset
    40
import javax.security.auth.kerberos.KerberosCredMessage;
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
diff changeset
    41
import javax.security.auth.kerberos.EncryptionKey;
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
diff changeset
    42
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
diff changeset
    43
public class NewInquireTypes {
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
diff changeset
    44
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
diff changeset
    45
    public static void main(String[] args) throws Exception {
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
diff changeset
    46
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
diff changeset
    47
        new OneKDC(null).writeJAASConf();
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
diff changeset
    48
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
diff changeset
    49
        Context c, s;
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
diff changeset
    50
        c = Context.fromJAAS("client");
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
diff changeset
    51
        s = Context.fromJAAS("server");
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
diff changeset
    52
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
diff changeset
    53
        c.startAsClient(OneKDC.SERVER, GSSUtil.GSS_KRB5_MECH_OID);
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
diff changeset
    54
        s.startAsServer(GSSUtil.GSS_KRB5_MECH_OID);
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
diff changeset
    55
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
diff changeset
    56
        Context.handshake(c, s);
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
diff changeset
    57
26629
3b9ed8175488 8042900: Allow com.sun.security.jgss to be in different module than org.ietf.jgss
weijun
parents: 25661
diff changeset
    58
        ExtendedGSSContext ctxt = (ExtendedGSSContext)c.x();
25661
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
diff changeset
    59
        EncryptionKey key = (EncryptionKey)
26629
3b9ed8175488 8042900: Allow com.sun.security.jgss to be in different module than org.ietf.jgss
weijun
parents: 25661
diff changeset
    60
                ctxt.inquireSecContext(InquireType.KRB5_GET_SESSION_KEY_EX);
25661
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
diff changeset
    61
        KerberosCredMessage cred = (KerberosCredMessage)
26629
3b9ed8175488 8042900: Allow com.sun.security.jgss to be in different module than org.ietf.jgss
weijun
parents: 25661
diff changeset
    62
                ctxt.inquireSecContext(InquireType.KRB5_GET_KRB_CRED);
3b9ed8175488 8042900: Allow com.sun.security.jgss to be in different module than org.ietf.jgss
weijun
parents: 25661
diff changeset
    63
        c.status();
25661
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
diff changeset
    64
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
diff changeset
    65
        // Confirm the KRB_CRED message is encrypted with the session key.
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
diff changeset
    66
        new KRBCred(cred.getEncoded()).encPart.decrypt(
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
diff changeset
    67
                new sun.security.krb5.EncryptionKey(key.getKeyType(), key.getEncoded()),
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
diff changeset
    68
                KeyUsage.KU_ENC_KRB_CRED_PART);
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
diff changeset
    69
    }
929c829a8400 8043071: Expose session key and KRB_CRED through extended GSS-API
weijun
parents:
diff changeset
    70
}