Path: blob/master/src/java.security.jgss/share/classes/sun/security/jgss/wrapper/GSSLibStub.java
41161 views
/*1* Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.security.jgss.wrapper;2627import java.util.Hashtable;28import org.ietf.jgss.Oid;29import org.ietf.jgss.GSSName;30import org.ietf.jgss.ChannelBinding;31import org.ietf.jgss.MessageProp;32import org.ietf.jgss.GSSException;33import sun.security.jgss.GSSUtil;3435/**36* This class is essentially a JNI calling stub for all wrapper classes.37*38* @author Valerie Peng39* @since 1.640*/4142class GSSLibStub {4344private Oid mech;45private long pMech; // Warning: used by NativeUtil.c4647/**48* Initialization routine to dynamically load function pointers.49*50* @param lib library name to dlopen51* @param debug set to true for reporting native debugging info52* @return true if succeeded, false otherwise.53*/54static native boolean init(String lib, boolean debug);55private static native long getMechPtr(byte[] oidDerEncoding);5657// Miscellaneous routines58static native Oid[] indicateMechs();59native Oid[] inquireNamesForMech() throws GSSException;6061// Name related routines62native void releaseName(long pName);63native long importName(byte[] name, Oid type);64native boolean compareName(long pName1, long pName2);65native long canonicalizeName(long pName);66native byte[] exportName(long pName) throws GSSException;67native Object[] displayName(long pName) throws GSSException;6869// Credential related routines70native long acquireCred(long pName, int lifetime, int usage)71throws GSSException;72native long releaseCred(long pCred);73native long getCredName(long pCred);74native int getCredTime(long pCred);75native int getCredUsage(long pCred);7677// Context related routines78native NativeGSSContext importContext(byte[] interProcToken);79native byte[] initContext(long pCred, long targetName, ChannelBinding cb,80byte[] inToken, NativeGSSContext context);81native byte[] acceptContext(long pCred, ChannelBinding cb,82byte[] inToken, NativeGSSContext context);83native long[] inquireContext(long pContext);84native Oid getContextMech(long pContext);85native long getContextName(long pContext, boolean isSrc);86native int getContextTime(long pContext);87native long deleteContext(long pContext);88native int wrapSizeLimit(long pContext, int flags, int qop, int outSize);89native byte[] exportContext(long pContext);90native byte[] getMic(long pContext, int qop, byte[] msg);91native void verifyMic(long pContext, byte[] token, byte[] msg,92MessageProp prop) ;93native byte[] wrap(long pContext, byte[] msg, MessageProp prop);94native byte[] unwrap(long pContext, byte[] msgToken, MessageProp prop);9596private static Hashtable<Oid, GSSLibStub>97table = new Hashtable<Oid, GSSLibStub>(5);9899static GSSLibStub getInstance(Oid mech) throws GSSException {100GSSLibStub s = table.get(mech);101if (s == null) {102s = new GSSLibStub(mech);103table.put(mech, s);104}105return s;106}107private GSSLibStub(Oid mech) throws GSSException {108SunNativeProvider.debug("Created GSSLibStub for mech " + mech);109this.mech = mech;110this.pMech = getMechPtr(mech.getDER());111}112public boolean equals(Object obj) {113if (obj == this) return true;114if (!(obj instanceof GSSLibStub)) {115return false;116}117return (mech.equals(((GSSLibStub) obj).getMech()));118}119public int hashCode() {120return mech.hashCode();121}122Oid getMech() {123return mech;124}125}126127128