jdk/src/share/classes/sun/security/jgss/spnego/SpNegoContext.java
author weijun
Fri, 27 Nov 2009 08:51:42 +0800
changeset 4337 2a6d13ebbbed
parent 4336 4c792c19266e
child 5506 202f599c92aa
permissions -rw-r--r--
6901085: SPNEGO does not works with native program Reviewed-by: valeriep
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
2279
e5639c0d8552 6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents: 1574
diff changeset
     2
 * Copyright 2005-2009 Sun Microsystems, Inc.  All Rights Reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.security.jgss.spnego;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
3482
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents: 2279
diff changeset
    28
import com.sun.security.jgss.ExtendedGSSContext;
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents: 2279
diff changeset
    29
import com.sun.security.jgss.InquireType;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.security.Provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import org.ietf.jgss.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import sun.security.jgss.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import sun.security.jgss.spi.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import sun.security.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * Implements the mechanism specific context class for SPNEGO
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * GSS-API mechanism
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * @author Seema Malkani
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
public class SpNegoContext implements GSSContextSpi {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     * The different states that this context can be in.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    private static final int STATE_NEW = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    private static final int STATE_IN_PROCESS = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private static final int STATE_DONE = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    private static final int STATE_DELETED = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    private int state = STATE_NEW;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * Optional features that the application can set and their default
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private boolean credDelegState = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private boolean mutualAuthState = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private boolean replayDetState = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    private boolean sequenceDetState = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    private boolean confState = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    private boolean integState = true;
4336
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3482
diff changeset
    66
    private boolean delegPolicyState = false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    private GSSNameSpi peerName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    private GSSNameSpi myName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    private SpNegoCredElement myCred = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    private GSSContext mechContext = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    private byte[] DER_mechTypes = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    private int lifetime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    private ChannelBinding channelBinding;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    private boolean initiator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    // the underlying negotiated mechanism
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    private Oid internal_mech = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    // the SpNegoMechFactory that creates this context
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    final private SpNegoMechFactory factory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    // debug property
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    static final boolean DEBUG =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        java.security.AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            new sun.security.action.GetBooleanAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            ("sun.security.spnego.debug")).booleanValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * Constructor for SpNegoContext to be called on the context initiator's
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * side.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    public SpNegoContext(SpNegoMechFactory factory, GSSNameSpi peerName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                        GSSCredentialSpi myCred,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                        int lifetime) throws GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        if (peerName == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            throw new IllegalArgumentException("Cannot have null peer name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        if ((myCred != null) && !(myCred instanceof SpNegoCredElement)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            throw new IllegalArgumentException("Wrong cred element type");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        this.peerName = peerName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        this.myCred = (SpNegoCredElement) myCred;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        this.lifetime = lifetime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        this.initiator = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        this.factory = factory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * Constructor for SpNegoContext to be called on the context acceptor's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * side.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    public SpNegoContext(SpNegoMechFactory factory, GSSCredentialSpi myCred)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            throws GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        if ((myCred != null) && !(myCred instanceof SpNegoCredElement)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            throw new IllegalArgumentException("Wrong cred element type");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        this.myCred = (SpNegoCredElement) myCred;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        this.initiator = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        this.factory = factory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * Constructor for SpNegoContext to import a previously exported context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    public SpNegoContext(SpNegoMechFactory factory, byte [] interProcessToken)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        throws GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        throw new GSSException(GSSException.UNAVAILABLE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                               -1, "GSS Import Context not available");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * Requests that confidentiality be available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    public final void requestConf(boolean value) throws GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        if (state == STATE_NEW && isInitiator())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            confState  = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * Is confidentiality available?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    public final boolean getConfState() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        return confState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * Requests that integrity be available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    public final void requestInteg(boolean value) throws GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        if (state == STATE_NEW && isInitiator())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            integState  = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    /**
4336
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3482
diff changeset
   158
     * Requests that deleg policy be respected.
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3482
diff changeset
   159
     */
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3482
diff changeset
   160
    public final void requestDelegPolicy(boolean value) throws GSSException {
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3482
diff changeset
   161
        if (state == STATE_NEW && isInitiator())
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3482
diff changeset
   162
            delegPolicyState = value;
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3482
diff changeset
   163
    }
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3482
diff changeset
   164
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3482
diff changeset
   165
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * Is integrity available?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    public final boolean getIntegState() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        return integState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    /**
4336
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3482
diff changeset
   173
     * Is deleg policy respected?
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3482
diff changeset
   174
     */
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3482
diff changeset
   175
    public final boolean getDelegPolicyState() {
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3482
diff changeset
   176
        if (isInitiator() && mechContext != null &&
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3482
diff changeset
   177
                mechContext instanceof ExtendedGSSContext &&
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3482
diff changeset
   178
                (state == STATE_IN_PROCESS || state == STATE_DONE)) {
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3482
diff changeset
   179
            return ((ExtendedGSSContext)mechContext).getDelegPolicyState();
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3482
diff changeset
   180
        } else {
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3482
diff changeset
   181
            return delegPolicyState;
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3482
diff changeset
   182
        }
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3482
diff changeset
   183
    }
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3482
diff changeset
   184
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3482
diff changeset
   185
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * Requests that credential delegation be done during context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * establishment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    public final void requestCredDeleg(boolean value) throws GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        if (state == STATE_NEW && isInitiator())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            credDelegState  = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * Is credential delegation enabled?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    public final boolean getCredDelegState() {
4336
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3482
diff changeset
   198
        if (isInitiator() && mechContext != null &&
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                (state == STATE_IN_PROCESS || state == STATE_DONE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            return mechContext.getCredDelegState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            return credDelegState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * Requests that mutual authentication be done during context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * establishment. Since this is fromm the client's perspective, it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * essentially requests that the server be authenticated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    public final void requestMutualAuth(boolean value) throws GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        if (state == STATE_NEW && isInitiator()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            mutualAuthState  = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * Is mutual authentication enabled? Since this is from the client's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * perspective, it essentially meas that the server is being
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * authenticated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    public final boolean getMutualAuthState() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        return mutualAuthState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * Returns the mechanism oid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * @return the Oid of this context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    public final Oid getMech() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        if (isEstablished()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            return getNegotiatedMech();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        return (SpNegoMechFactory.GSS_SPNEGO_MECH_OID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    public final Oid getNegotiatedMech() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        return (internal_mech);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    public final Provider getProvider() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        return SpNegoMechFactory.PROVIDER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    public final void dispose() throws GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        mechContext = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        state = STATE_DELETED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * Tests if this is the initiator side of the context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * @return boolean indicating if this is initiator (true)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     *  or target (false)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    public final boolean isInitiator() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        return initiator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * Tests if the context can be used for per-message service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * Context may allow the calls to the per-message service
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * functions before being fully established.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * @return boolean indicating if per-message methods can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     *  be called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    public final boolean isProtReady() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        return (state == STATE_DONE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * Initiator context establishment call. This method may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * required to be called several times. A CONTINUE_NEEDED return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * call indicates that more calls are needed after the next token
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * is received from the peer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * @param is contains the token received from the peer. On the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     *        first call it will be ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * @return any token required to be sent to the peer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * It is responsibility of the caller to send the token
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * to its peer for processing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * @exception GSSException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    public final byte[] initSecContext(InputStream is, int mechTokenSize)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        throws GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        byte[] retVal = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        NegTokenInit initToken = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        byte[] mechToken = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        int errorCode = GSSException.FAILURE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            System.out.println("Entered SpNego.initSecContext with " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                                "state=" + printState(state));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        if (!isInitiator()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            throw new GSSException(GSSException.FAILURE, -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                "initSecContext on an acceptor GSSContext");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            if (state == STATE_NEW) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                state = STATE_IN_PROCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                errorCode = GSSException.NO_CRED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                // determine available mech set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                Oid[] mechList = getAvailableMechs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                DER_mechTypes = getEncodedMechs(mechList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                // pull out first mechanism
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                internal_mech = mechList[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                // get the token for first mechanism
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                mechToken = GSS_initSecContext(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                errorCode = GSSException.DEFECTIVE_TOKEN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                // generate SPNEGO token
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                initToken = new NegTokenInit(DER_mechTypes, getContextFlags(),
4337
2a6d13ebbbed 6901085: SPNEGO does not works with native program
weijun
parents: 4336
diff changeset
   322
                                        mechToken, null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                    System.out.println("SpNegoContext.initSecContext: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                                "sending token of type = " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                                SpNegoToken.getTokenName(initToken.getType()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                // get the encoded token
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                retVal = initToken.getEncoded();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            } else if (state == STATE_IN_PROCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                errorCode = GSSException.FAILURE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                if (is == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                    throw new GSSException(errorCode, -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                                "No token received from peer!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                errorCode = GSSException.DEFECTIVE_TOKEN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                byte[] server_token = new byte[is.available()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                SpNegoToken.readFully(is, server_token);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                    System.out.println("SpNegoContext.initSecContext: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                                        "process received token = " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                                        SpNegoToken.getHexBytes(server_token));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                // read the SPNEGO token
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                // token will be validated when parsing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                NegTokenTarg targToken = new NegTokenTarg(server_token);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                    System.out.println("SpNegoContext.initSecContext: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                                "received token of type = " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                                SpNegoToken.getTokenName(targToken.getType()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                // pull out mechanism
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                internal_mech = targToken.getSupportedMech();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                if (internal_mech == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                    // return wth failure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                    throw new GSSException(errorCode, -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                                "supported mechansim from server is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                // get the negotiated result
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                SpNegoToken.NegoResult negoResult = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                int result = targToken.getNegotiatedResult();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                switch (result) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                    case 0:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                        negoResult = SpNegoToken.NegoResult.ACCEPT_COMPLETE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                        state = STATE_DONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                    case 1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                        negoResult = SpNegoToken.NegoResult.ACCEPT_INCOMPLETE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                        state = STATE_IN_PROCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                    case 2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                        negoResult = SpNegoToken.NegoResult.REJECT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                        state = STATE_DELETED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                    default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                        state = STATE_DONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                errorCode = GSSException.BAD_MECH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                if (negoResult == SpNegoToken.NegoResult.REJECT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                    throw new GSSException(errorCode, -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                                        internal_mech.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                errorCode = GSSException.DEFECTIVE_TOKEN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                if ((negoResult == SpNegoToken.NegoResult.ACCEPT_COMPLETE) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                    (negoResult == SpNegoToken.NegoResult.ACCEPT_INCOMPLETE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                    // pull out the mechanism token
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                    byte[] accept_token = targToken.getResponseToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                    if (accept_token == null) {
1574
7aad9fe14378 6733095: Failure when SPNEGO request non-Mutual
weijun
parents: 2
diff changeset
   402
                        if (!isMechContextEstablished()) {
7aad9fe14378 6733095: Failure when SPNEGO request non-Mutual
weijun
parents: 2
diff changeset
   403
                            // return with failure
7aad9fe14378 6733095: Failure when SPNEGO request non-Mutual
weijun
parents: 2
diff changeset
   404
                            throw new GSSException(errorCode, -1,
7aad9fe14378 6733095: Failure when SPNEGO request non-Mutual
weijun
parents: 2
diff changeset
   405
                                    "mechanism token from server is null");
7aad9fe14378 6733095: Failure when SPNEGO request non-Mutual
weijun
parents: 2
diff changeset
   406
                        }
7aad9fe14378 6733095: Failure when SPNEGO request non-Mutual
weijun
parents: 2
diff changeset
   407
                    } else {
7aad9fe14378 6733095: Failure when SPNEGO request non-Mutual
weijun
parents: 2
diff changeset
   408
                        mechToken = GSS_initSecContext(accept_token);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                    // verify MIC
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                    if (!GSSUtil.useMSInterop()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                        byte[] micToken = targToken.getMechListMIC();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                        if (!verifyMechListMIC(DER_mechTypes, micToken)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                            throw new GSSException(errorCode, -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                                "verification of MIC on MechList Failed!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                    if (isMechContextEstablished()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                        state = STATE_DONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                        retVal = mechToken;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                        if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                            System.out.println("SPNEGO Negotiated Mechanism = "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                                + internal_mech + " " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                                GSSUtil.getMechStr(internal_mech));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                        // generate SPNEGO token
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                        initToken = new NegTokenInit(null, null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                                                mechToken, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                        if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                            System.out.println("SpNegoContext.initSecContext:" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                                " continue sending token of type = " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                                SpNegoToken.getTokenName(initToken.getType()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                        // get the encoded token
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                        retVal = initToken.getEncoded();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                // XXX Use logging API
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                    System.out.println(state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                if (retVal != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                    System.out.println("SNegoContext.initSecContext: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                        "sending token = " + SpNegoToken.getHexBytes(retVal));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        } catch (GSSException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            GSSException gssException =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                        new GSSException(errorCode, -1, e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
            gssException.initCause(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
            throw gssException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
            GSSException gssException =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                new GSSException(GSSException.FAILURE, -1, e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
            gssException.initCause(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            throw gssException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        return retVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     * Acceptor's context establishment call. This method may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * required to be called several times. A CONTINUE_NEEDED return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * call indicates that more calls are needed after the next token
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     * is received from the peer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     * @param is contains the token received from the peer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     * @return any token required to be sent to the peer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     * It is responsibility of the caller to send the token
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     * to its peer for processing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     * @exception GSSException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    public final byte[] acceptSecContext(InputStream is, int mechTokenSize)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        throws GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        byte[] retVal = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        SpNegoToken.NegoResult negoResult;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        boolean valid = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            System.out.println("Entered SpNegoContext.acceptSecContext with " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                               "state=" +  printState(state));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        if (isInitiator()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            throw new GSSException(GSSException.FAILURE, -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                                   "acceptSecContext on an initiator " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                                   "GSSContext");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
            if (state == STATE_NEW) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                state = STATE_IN_PROCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                // read data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
                byte[] token = new byte[is.available()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
                SpNegoToken.readFully(is, token);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
                if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
                    System.out.println("SpNegoContext.acceptSecContext: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                                        "receiving token = " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
                                        SpNegoToken.getHexBytes(token));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                // read the SPNEGO token
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                // token will be validated when parsing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                NegTokenInit initToken = new NegTokenInit(token);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                    System.out.println("SpNegoContext.acceptSecContext: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                                "received token of type = " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                                SpNegoToken.getTokenName(initToken.getType()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                Oid[] mechList = initToken.getMechTypeList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                DER_mechTypes = initToken.getMechTypes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                if (DER_mechTypes == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                    valid = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                // get the mechanism token
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                byte[] mechToken = initToken.getMechToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                 * Select the best match between the list of mechs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                 * that the initiator requested and the list that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                 * the acceptor will support.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                Oid[] supported_mechSet = getAvailableMechs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                Oid mech_wanted =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                        negotiate_mech_type(supported_mechSet, mechList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
                if (mech_wanted == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                    valid = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                // save the desired mechansim
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                internal_mech = mech_wanted;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                // get the token for mechanism
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                byte[] accept_token = GSS_acceptSecContext(mechToken);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                // verify MIC
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                if (!GSSUtil.useMSInterop() && valid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                    valid = verifyMechListMIC(DER_mechTypes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                                                initToken.getMechListMIC());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                // determine negotiated result status
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                if (valid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                    if (isMechContextEstablished()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                        negoResult = SpNegoToken.NegoResult.ACCEPT_COMPLETE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                        state = STATE_DONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                        // now set the context flags for acceptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                        setContextFlags();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                        // print the negotiated mech info
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                        if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                            System.out.println("SPNEGO Negotiated Mechanism = "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                                + internal_mech + " " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                                GSSUtil.getMechStr(internal_mech));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                        negoResult = SpNegoToken.NegoResult.ACCEPT_INCOMPLETE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                        state = STATE_IN_PROCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                    negoResult = SpNegoToken.NegoResult.REJECT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
                    state = STATE_DONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                    System.out.println("SpNegoContext.acceptSecContext: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                                "mechanism wanted = " + mech_wanted);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                    System.out.println("SpNegoContext.acceptSecContext: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                                "negotiated result = " + negoResult);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
                // generate SPNEGO token
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                NegTokenTarg targToken = new NegTokenTarg(negoResult.ordinal(),
4337
2a6d13ebbbed 6901085: SPNEGO does not works with native program
weijun
parents: 4336
diff changeset
   583
                                mech_wanted, accept_token, null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                    System.out.println("SpNegoContext.acceptSecContext: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                                "sending token of type = " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                                SpNegoToken.getTokenName(targToken.getType()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                // get the encoded token
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                retVal = targToken.getEncoded();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
            } else if (state == STATE_IN_PROCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                // read the token
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                byte[] client_token = new byte[is.available()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
                SpNegoToken.readFully(is, client_token);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
                byte[] accept_token = GSS_acceptSecContext(client_token);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                if (accept_token == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
                    valid = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
                // determine negotiated result status
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
                if (valid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
                    if (isMechContextEstablished()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                        negoResult = SpNegoToken.NegoResult.ACCEPT_COMPLETE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                        state = STATE_DONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                        negoResult = SpNegoToken.NegoResult.ACCEPT_INCOMPLETE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                        state = STATE_IN_PROCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                    negoResult = SpNegoToken.NegoResult.REJECT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                    state = STATE_DONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                // generate SPNEGO token
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
                NegTokenTarg targToken = new NegTokenTarg(negoResult.ordinal(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
                                null, accept_token, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
                if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
                    System.out.println("SpNegoContext.acceptSecContext: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
                                "sending token of type = " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
                                SpNegoToken.getTokenName(targToken.getType()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
                // get the encoded token
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
                retVal = targToken.getEncoded();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
                // XXX Use logging API
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
                if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
                    System.out.println("AcceptSecContext: state = " + state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
            if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
                    System.out.println("SpNegoContext.acceptSecContext: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
                        "sending token = " + SpNegoToken.getHexBytes(retVal));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
            GSSException gssException =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
                new GSSException(GSSException.FAILURE, -1, e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
            gssException.initCause(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
            throw gssException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
4336
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3482
diff changeset
   643
        if (state == STATE_DONE) {
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3482
diff changeset
   644
            // now set the context flags for acceptor
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3482
diff changeset
   645
            setContextFlags();
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3482
diff changeset
   646
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        return retVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     * obtain the available mechanisms
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
    private Oid[] getAvailableMechs() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        if (myCred != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
            Oid[] mechs = new Oid[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
            mechs[0] = myCred.getInternalMech();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
            return mechs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
            return factory.availableMechs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
     * get ther DER encoded MechList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
    private byte[] getEncodedMechs(Oid[] mechSet)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
        throws IOException, GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
        DerOutputStream mech = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
        for (int i = 0; i < mechSet.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
            byte[] mechType = mechSet[i].getDER();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
            mech.write(mechType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        // insert in SEQUENCE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        DerOutputStream mechTypeList = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
        mechTypeList.write(DerValue.tag_Sequence, mech);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        byte[] encoded = mechTypeList.toByteArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
        return encoded;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     * get the context flags
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     */
2279
e5639c0d8552 6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents: 1574
diff changeset
   684
    private BitArray getContextFlags() {
e5639c0d8552 6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents: 1574
diff changeset
   685
        BitArray out = new BitArray(7);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
2279
e5639c0d8552 6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents: 1574
diff changeset
   687
        if (getCredDelegState()) out.set(0, true);
e5639c0d8552 6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents: 1574
diff changeset
   688
        if (getMutualAuthState()) out.set(1, true);
e5639c0d8552 6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents: 1574
diff changeset
   689
        if (getReplayDetState()) out.set(2, true);
e5639c0d8552 6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents: 1574
diff changeset
   690
        if (getSequenceDetState()) out.set(3, true);
e5639c0d8552 6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents: 1574
diff changeset
   691
        if (getConfState()) out.set(5, true);
e5639c0d8552 6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents: 1574
diff changeset
   692
        if (getIntegState()) out.set(6, true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
2279
e5639c0d8552 6815182: GSSAPI/SPNEGO does not work with server using MIT Kerberos library
weijun
parents: 1574
diff changeset
   694
        return out;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
4336
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3482
diff changeset
   697
    // Only called on acceptor side. On the initiator side, most flags
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3482
diff changeset
   698
    // are already set at request. For those that might get chanegd,
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3482
diff changeset
   699
    // state from mech below is used.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
    private void setContextFlags() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        if (mechContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
            // default for cred delegation is false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
            if (mechContext.getCredDelegState()) {
4336
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3482
diff changeset
   705
                credDelegState = true;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
            // default for the following are true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
            if (!mechContext.getMutualAuthState()) {
4336
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3482
diff changeset
   709
                mutualAuthState = false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
            if (!mechContext.getReplayDetState()) {
4336
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3482
diff changeset
   712
                replayDetState = false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
            if (!mechContext.getSequenceDetState()) {
4336
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3482
diff changeset
   715
                sequenceDetState = false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
            if (!mechContext.getIntegState()) {
4336
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3482
diff changeset
   718
                integState = false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
            if (!mechContext.getConfState()) {
4336
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3482
diff changeset
   721
                confState = false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
    /**
4337
2a6d13ebbbed 6901085: SPNEGO does not works with native program
weijun
parents: 4336
diff changeset
   727
     * generate MIC on mechList. Not used at the moment.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
     */
4337
2a6d13ebbbed 6901085: SPNEGO does not works with native program
weijun
parents: 4336
diff changeset
   729
    /*private byte[] generateMechListMIC(byte[] mechTypes)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
        throws GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        // sanity check the required input
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
        if (mechTypes == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
            if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
                System.out.println("SpNegoContext: no MIC token included");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
        // check if mechansim supports integrity
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        if (!mechContext.getIntegState()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
            if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
                System.out.println("SpNegoContext: no MIC token included" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
                        " - mechanism does not support integrity");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
        // compute MIC on DER encoded mechanism list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
        byte[] mic = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
            MessageProp prop = new MessageProp(0, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
            mic = getMIC(mechTypes, 0, mechTypes.length, prop);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
            if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
                System.out.println("SpNegoContext: getMIC = " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
                                        SpNegoToken.getHexBytes(mic));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
        } catch (GSSException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
            mic = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
            if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
                System.out.println("SpNegoContext: no MIC token included" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
                        " - getMIC failed : " + e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
        return mic;
4337
2a6d13ebbbed 6901085: SPNEGO does not works with native program
weijun
parents: 4336
diff changeset
   766
    }*/
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
     * verify MIC on MechList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
    private boolean verifyMechListMIC(byte[] mechTypes, byte[] token)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
        throws GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
        // sanity check the input
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
        if (token == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
            if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
                System.out.println("SpNegoContext: no MIC token validation");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
        // check if mechansim supports integrity
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
        if (!mechContext.getIntegState()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
            if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
                System.out.println("SpNegoContext: no MIC token validation" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
                        " - mechanism does not support integrity");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
        // now verify the token
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
        boolean valid = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
            MessageProp prop = new MessageProp(0, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
            verifyMIC(token, 0, token.length, mechTypes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
                        0, mechTypes.length, prop);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
            valid = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
        } catch (GSSException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
            valid = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
            if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
                System.out.println("SpNegoContext: MIC validation failed! " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
                                        e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        return valid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
     * call gss_init_sec_context for the corresponding underlying mechanism
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
    private byte[] GSS_initSecContext(byte[] token) throws GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
        byte[] tok = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
        if (mechContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
            // initialize mech context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
            GSSName serverName =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
                factory.manager.createName(peerName.toString(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
                    peerName.getStringNameType(), internal_mech);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
            GSSCredential cred = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
            if (myCred != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
                // create context with provided credential
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
                cred = new GSSCredentialImpl(factory.manager,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
                    myCred.getInternalCred());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
            mechContext =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
                factory.manager.createContext(serverName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
                    internal_mech, cred, GSSContext.DEFAULT_LIFETIME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
            mechContext.requestConf(confState);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
            mechContext.requestInteg(integState);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
            mechContext.requestCredDeleg(credDelegState);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
            mechContext.requestMutualAuth(mutualAuthState);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
            mechContext.requestReplayDet(replayDetState);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
            mechContext.requestSequenceDet(sequenceDetState);
4336
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3482
diff changeset
   834
            if (mechContext instanceof ExtendedGSSContext) {
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3482
diff changeset
   835
                ((ExtendedGSSContext)mechContext).requestDelegPolicy(
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3482
diff changeset
   836
                        delegPolicyState);
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3482
diff changeset
   837
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
        // pass token
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
        if (token != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
            tok = token;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
            tok = new byte[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
        // pass token to mechanism initSecContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
        byte[] init_token = mechContext.initSecContext(tok, 0, tok.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
        return init_token;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
     * call gss_accept_sec_context for the corresponding underlying mechanism
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
    private byte[] GSS_acceptSecContext(byte[] token) throws GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
        if (mechContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
            // initialize mech context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
            GSSCredential cred = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
            if (myCred != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
                // create context with provided credential
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
                cred = new GSSCredentialImpl(factory.manager,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
                myCred.getInternalCred());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
            mechContext =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
                factory.manager.createContext(cred);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
        // pass token to mechanism acceptSecContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
        byte[] accept_token =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
                mechContext.acceptSecContext(token, 0, token.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
        return accept_token;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
     * This routine compares the recieved mechset to the mechset that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
     * this server can support. It looks sequentially through the mechset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
     * and the first one that matches what the server can support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
     * chosen as the negotiated mechanism. If one is found, negResult
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
     * is set to ACCEPT_COMPLETE, otherwise we return NULL and negResult
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
     * is set to REJECT.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
    private static Oid negotiate_mech_type(Oid[] supported_mechSet,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
                                        Oid[] mechSet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
        for (int i = 0; i < supported_mechSet.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
            for (int j = 0; j < mechSet.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
                if (mechSet[j].equals(supported_mechSet[i])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
                    if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
                        System.out.println("SpNegoContext: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
                                "negotiated mechanism = " + mechSet[j]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
                    return (mechSet[j]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
    public final boolean isEstablished() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
        return (state == STATE_DONE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
    public final boolean isMechContextEstablished() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
        if (mechContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
            return mechContext.isEstablished();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
            if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
                System.out.println("The underlying mechansim context has " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
                                        "not been initialized");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
    public final byte [] export() throws GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
        throw new GSSException(GSSException.UNAVAILABLE, -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
                               "GSS Export Context not available");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
     * Sets the channel bindings to be used during context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
     * establishment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
    public final void setChannelBinding(ChannelBinding channelBinding)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
        throws GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
        this.channelBinding = channelBinding;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
    final ChannelBinding getChannelBinding() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
        return channelBinding;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
     * Anonymity is a little different in that after an application
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
     * requests anonymity it will want to know whether the mechanism
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
     * can support it or not, prior to sending any tokens across for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
     * context establishment. Since this is from the initiator's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
     * perspective, it essentially requests that the initiator be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
     * anonymous.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
    public final void requestAnonymity(boolean value) throws GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
        // Ignore silently. Application will check back with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
        // getAnonymityState.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
    // RFC 2853 actually calls for this to be called after context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
    // establishment to get the right answer, but that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
    // incorrect. The application may not want to send over any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
    // tokens if anonymity is not available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
    public final boolean getAnonymityState() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
     * Requests the desired lifetime. Can only be used on the context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
     * initiator's side.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
    public void requestLifetime(int lifetime) throws GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
        if (state == STATE_NEW && isInitiator())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
            this.lifetime = lifetime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
     * The lifetime remaining for this context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
    public final int getLifetime() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
        if (mechContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
            return mechContext.getLifetime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
            return GSSContext.INDEFINITE_LIFETIME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
    public final boolean isTransferable() throws GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
     * Requests that sequence checking be done on the GSS wrap and MIC
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
     * tokens.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
    public final void requestSequenceDet(boolean value) throws GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
        if (state == STATE_NEW && isInitiator())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
            sequenceDetState  = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
     * Is sequence checking enabled on the GSS Wrap and MIC tokens?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
     * We enable sequence checking if replay detection is enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
    public final boolean getSequenceDetState() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
        return sequenceDetState || replayDetState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
     * Requests that replay detection be done on the GSS wrap and MIC
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
     * tokens.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
    public final void requestReplayDet(boolean value) throws GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
        if (state == STATE_NEW && isInitiator())
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
            replayDetState  = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
     * Is replay detection enabled on the GSS wrap and MIC tokens?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
     * We enable replay detection if sequence checking is enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
    public final boolean getReplayDetState() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
        return replayDetState || sequenceDetState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
    public final GSSNameSpi getTargName() throws GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
        // fill-in the GSSName
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
        // get the peer name for the mechanism
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
        if (mechContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
            GSSNameImpl targName = (GSSNameImpl)mechContext.getTargName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
            peerName = (GSSNameSpi) targName.getElement(internal_mech);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
            return peerName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
            if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
                System.out.println("The underlying mechansim context has " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
                                        "not been initialized");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
    public final GSSNameSpi getSrcName() throws GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
        // fill-in the GSSName
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
        // get the src name for the mechanism
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
        if (mechContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
            GSSNameImpl srcName = (GSSNameImpl)mechContext.getSrcName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
            myName = (GSSNameSpi) srcName.getElement(internal_mech);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
            return myName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
            if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
                System.out.println("The underlying mechansim context has " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
                                        "not been initialized");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
     * Returns the delegated credential for the context. This
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
     * is an optional feature of contexts which not all
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
     * mechanisms will support. A context can be requested to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
     * support credential delegation by using the <b>CRED_DELEG</b>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
     * This is only valid on the acceptor side of the context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
     * @return GSSCredentialSpi object for the delegated credential
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
     * @exception GSSException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
     * @see GSSContext#getDelegCredState
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
    public final GSSCredentialSpi getDelegCred() throws GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
        if (state != STATE_IN_PROCESS && state != STATE_DONE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
            throw new GSSException(GSSException.NO_CONTEXT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
        if (mechContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
            GSSCredentialImpl delegCred =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
                        (GSSCredentialImpl)mechContext.getDelegCred();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
            // determine delegated cred element usage
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
            boolean initiate = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
            if (delegCred.getUsage() == GSSCredential.INITIATE_ONLY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
                initiate = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
            GSSCredentialSpi mechCred = (GSSCredentialSpi)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
                                delegCred.getElement(internal_mech, initiate);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
            SpNegoCredElement cred = new SpNegoCredElement(mechCred);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
            return cred.getInternalCred();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
            throw new GSSException(GSSException.NO_CONTEXT, -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
                                "getDelegCred called in invalid state!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
    public final int getWrapSizeLimit(int qop, boolean confReq,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
                                       int maxTokSize) throws GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
        if (mechContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
            return mechContext.getWrapSizeLimit(qop, confReq, maxTokSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
            throw new GSSException(GSSException.NO_CONTEXT, -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
                                "getWrapSizeLimit called in invalid state!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
    public final byte[] wrap(byte inBuf[], int offset, int len,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
                             MessageProp msgProp) throws GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
        if (mechContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
            return mechContext.wrap(inBuf, offset, len, msgProp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
            throw new GSSException(GSSException.NO_CONTEXT, -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
                                "Wrap called in invalid state!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
    public final void wrap(InputStream is, OutputStream os,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
                            MessageProp msgProp) throws GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
        if (mechContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
            mechContext.wrap(is, os, msgProp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
            throw new GSSException(GSSException.NO_CONTEXT, -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
                                "Wrap called in invalid state!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
    public final byte[] unwrap(byte inBuf[], int offset, int len,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
                               MessageProp msgProp)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
        throws GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
        if (mechContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
            return mechContext.unwrap(inBuf, offset, len, msgProp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
            throw new GSSException(GSSException.NO_CONTEXT, -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
                                "UnWrap called in invalid state!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
    public final void unwrap(InputStream is, OutputStream os,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
                             MessageProp msgProp) throws GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
        if (mechContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
            mechContext.unwrap(is, os, msgProp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
            throw new GSSException(GSSException.NO_CONTEXT, -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
                                "UnWrap called in invalid state!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
    public final byte[] getMIC(byte []inMsg, int offset, int len,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
                               MessageProp msgProp)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
        throws GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
        if (mechContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
            return mechContext.getMIC(inMsg, offset, len, msgProp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
            throw new GSSException(GSSException.NO_CONTEXT, -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
                                "getMIC called in invalid state!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
    public final void getMIC(InputStream is, OutputStream os,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
                              MessageProp msgProp) throws GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
        if (mechContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
            mechContext.getMIC(is, os, msgProp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
            throw new GSSException(GSSException.NO_CONTEXT, -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
                                "getMIC called in invalid state!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
    public final void verifyMIC(byte []inTok, int tokOffset, int tokLen,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
                                byte[] inMsg, int msgOffset, int msgLen,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
                                MessageProp msgProp)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
        throws GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
        if (mechContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
            mechContext.verifyMIC(inTok, tokOffset, tokLen, inMsg, msgOffset,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
                                msgLen,  msgProp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
            throw new GSSException(GSSException.NO_CONTEXT, -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
                                "verifyMIC called in invalid state!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
    public final void verifyMIC(InputStream is, InputStream msgStr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
                                 MessageProp msgProp) throws GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
        if (mechContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
            mechContext.verifyMIC(is, msgStr, msgProp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
            throw new GSSException(GSSException.NO_CONTEXT, -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
                                "verifyMIC called in invalid state!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
    private static String printState(int state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
        switch (state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
          case STATE_NEW:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
                return ("STATE_NEW");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
          case STATE_IN_PROCESS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
                return ("STATE_IN_PROCESS");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
          case STATE_DONE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
                return ("STATE_DONE");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
          case STATE_DELETED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
                return ("STATE_DELETED");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
          default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
                return ("Unknown state " + state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
    }
3482
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents: 2279
diff changeset
  1186
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents: 2279
diff changeset
  1187
    /**
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents: 2279
diff changeset
  1188
     * Retrieve attribute of the context for {@code type}.
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents: 2279
diff changeset
  1189
     */
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents: 2279
diff changeset
  1190
    public Object inquireSecContext(InquireType type)
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents: 2279
diff changeset
  1191
            throws GSSException {
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents: 2279
diff changeset
  1192
        if (mechContext == null) {
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents: 2279
diff changeset
  1193
            throw new GSSException(GSSException.NO_CONTEXT, -1,
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents: 2279
diff changeset
  1194
                    "Underlying mech not established.");
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents: 2279
diff changeset
  1195
        }
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents: 2279
diff changeset
  1196
        if (mechContext instanceof ExtendedGSSContext) {
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents: 2279
diff changeset
  1197
            return ((ExtendedGSSContext)mechContext).inquireSecContext(type);
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents: 2279
diff changeset
  1198
        } else {
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents: 2279
diff changeset
  1199
            throw new GSSException(GSSException.BAD_MECH, -1,
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents: 2279
diff changeset
  1200
                    "inquireSecContext not supported by underlying mech.");
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents: 2279
diff changeset
  1201
        }
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents: 2279
diff changeset
  1202
    }
4336
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 3482
diff changeset
  1203
}
3482
4aaa66ce712d 6710360: export Kerberos session key to applications
weijun
parents: 2279
diff changeset
  1204