src/java.security.jgss/share/classes/sun/security/jgss/wrapper/GSSLibStub.java
author weijun
Wed, 25 Sep 2019 17:54:21 +0800
changeset 58331 e4ce29f6094e
parent 47216 71c04702a3d5
permissions -rw-r--r--
8228659: Record which Java methods are called by native codes in JGSS and JAAS Reviewed-by: mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
58331
e4ce29f6094e 8228659: Record which Java methods are called by native codes in JGSS and JAAS
weijun
parents: 47216
diff changeset
     2
 * Copyright (c) 2005, 2019, Oracle and/or its affiliates. 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
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
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
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
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.wrapper;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.Hashtable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import org.ietf.jgss.Oid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import org.ietf.jgss.GSSName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import org.ietf.jgss.ChannelBinding;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import org.ietf.jgss.MessageProp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import org.ietf.jgss.GSSException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import sun.security.jgss.GSSUtil;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * This class is essentially a JNI calling stub for all wrapper classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * @author Valerie Peng
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
class GSSLibStub {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    private Oid mech;
58331
e4ce29f6094e 8228659: Record which Java methods are called by native codes in JGSS and JAAS
weijun
parents: 47216
diff changeset
    46
    private long pMech; // Warning: used by NativeUtil.c
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     * Initialization routine to dynamically load function pointers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     *
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 5506
diff changeset
    51
     * @param lib library name to dlopen
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 5506
diff changeset
    52
     * @param debug set to true for reporting native debugging info
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     * @return true if succeeded, false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     */
23585
e4412d1b53d3 8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents: 5506
diff changeset
    55
    static native boolean init(String lib, boolean debug);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private static native long getMechPtr(byte[] oidDerEncoding);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    // Miscellaneous routines
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    static native Oid[] indicateMechs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    native Oid[] inquireNamesForMech() throws GSSException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    // Name related routines
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    native void releaseName(long pName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    native long importName(byte[] name, Oid type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    native boolean compareName(long pName1, long pName2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    native long canonicalizeName(long pName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    native byte[] exportName(long pName) throws GSSException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    native Object[] displayName(long pName) throws GSSException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    // Credential related routines
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    native long acquireCred(long pName, int lifetime, int usage)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                                        throws GSSException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    native long releaseCred(long pCred);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    native long getCredName(long pCred);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    native int getCredTime(long pCred);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    native int getCredUsage(long pCred);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    // Context related routines
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    native NativeGSSContext importContext(byte[] interProcToken);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    native byte[] initContext(long pCred, long targetName, ChannelBinding cb,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                              byte[] inToken, NativeGSSContext context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    native byte[] acceptContext(long pCred, ChannelBinding cb,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                                byte[] inToken, NativeGSSContext context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    native long[] inquireContext(long pContext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    native Oid getContextMech(long pContext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    native long getContextName(long pContext, boolean isSrc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    native int getContextTime(long pContext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    native long deleteContext(long pContext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    native int wrapSizeLimit(long pContext, int flags, int qop, int outSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    native byte[] exportContext(long pContext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    native byte[] getMic(long pContext, int qop, byte[] msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    native void verifyMic(long pContext, byte[] token, byte[] msg,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                          MessageProp prop) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    native byte[] wrap(long pContext, byte[] msg, MessageProp prop);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    native byte[] unwrap(long pContext, byte[] msgToken, MessageProp prop);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    private static Hashtable<Oid, GSSLibStub>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        table = new Hashtable<Oid, GSSLibStub>(5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    static GSSLibStub getInstance(Oid mech) throws GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        GSSLibStub s = table.get(mech);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        if (s == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            s = new GSSLibStub(mech);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            table.put(mech, s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        return s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    private GSSLibStub(Oid mech) throws GSSException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        SunNativeProvider.debug("Created GSSLibStub for mech " + mech);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        this.mech = mech;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        this.pMech = getMechPtr(mech.getDER());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        if (obj == this) return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        if (!(obj instanceof GSSLibStub)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        return (mech.equals(((GSSLibStub) obj).getMech()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        return mech.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    Oid getMech() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        return mech;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
}