0N/A/*
2362N/A * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage sun.security.jgss.wrapper;
0N/A
0N/Aimport java.util.Hashtable;
0N/Aimport org.ietf.jgss.Oid;
0N/Aimport org.ietf.jgss.GSSName;
0N/Aimport org.ietf.jgss.ChannelBinding;
0N/Aimport org.ietf.jgss.MessageProp;
0N/Aimport org.ietf.jgss.GSSException;
0N/Aimport sun.security.jgss.GSSUtil;
0N/A
0N/A/**
0N/A * This class is essentially a JNI calling stub for all wrapper classes.
0N/A *
0N/A * @author Valerie Peng
0N/A * @since 1.6
0N/A */
0N/A
0N/Aclass GSSLibStub {
0N/A
0N/A private Oid mech;
0N/A private long pMech;
0N/A
0N/A /**
0N/A * Initialization routine to dynamically load function pointers.
0N/A *
0N/A * @param library name to dlopen
0N/A * @return true if succeeded, false otherwise.
0N/A */
0N/A static native boolean init(String lib);
0N/A private static native long getMechPtr(byte[] oidDerEncoding);
0N/A
0N/A // Miscellaneous routines
0N/A static native Oid[] indicateMechs();
0N/A native Oid[] inquireNamesForMech() throws GSSException;
0N/A
0N/A // Name related routines
0N/A native void releaseName(long pName);
0N/A native long importName(byte[] name, Oid type);
0N/A native boolean compareName(long pName1, long pName2);
0N/A native long canonicalizeName(long pName);
0N/A native byte[] exportName(long pName) throws GSSException;
0N/A native Object[] displayName(long pName) throws GSSException;
0N/A
0N/A // Credential related routines
0N/A native long acquireCred(long pName, int lifetime, int usage)
0N/A throws GSSException;
0N/A native long releaseCred(long pCred);
0N/A native long getCredName(long pCred);
0N/A native int getCredTime(long pCred);
0N/A native int getCredUsage(long pCred);
0N/A
0N/A // Context related routines
0N/A native NativeGSSContext importContext(byte[] interProcToken);
0N/A native byte[] initContext(long pCred, long targetName, ChannelBinding cb,
0N/A byte[] inToken, NativeGSSContext context);
0N/A native byte[] acceptContext(long pCred, ChannelBinding cb,
0N/A byte[] inToken, NativeGSSContext context);
0N/A native long[] inquireContext(long pContext);
0N/A native Oid getContextMech(long pContext);
0N/A native long getContextName(long pContext, boolean isSrc);
0N/A native int getContextTime(long pContext);
0N/A native long deleteContext(long pContext);
0N/A native int wrapSizeLimit(long pContext, int flags, int qop, int outSize);
0N/A native byte[] exportContext(long pContext);
0N/A native byte[] getMic(long pContext, int qop, byte[] msg);
0N/A native void verifyMic(long pContext, byte[] token, byte[] msg,
0N/A MessageProp prop) ;
0N/A native byte[] wrap(long pContext, byte[] msg, MessageProp prop);
0N/A native byte[] unwrap(long pContext, byte[] msgToken, MessageProp prop);
0N/A
0N/A private static Hashtable<Oid, GSSLibStub>
0N/A table = new Hashtable<Oid, GSSLibStub>(5);
0N/A
0N/A static GSSLibStub getInstance(Oid mech) throws GSSException {
0N/A GSSLibStub s = table.get(mech);
0N/A if (s == null) {
0N/A s = new GSSLibStub(mech);
0N/A table.put(mech, s);
0N/A }
0N/A return s;
0N/A }
0N/A private GSSLibStub(Oid mech) throws GSSException {
0N/A SunNativeProvider.debug("Created GSSLibStub for mech " + mech);
0N/A this.mech = mech;
0N/A this.pMech = getMechPtr(mech.getDER());
0N/A }
0N/A public boolean equals(Object obj) {
0N/A if (obj == this) return true;
0N/A if (!(obj instanceof GSSLibStub)) {
0N/A return false;
0N/A }
0N/A return (mech.equals(((GSSLibStub) obj).getMech()));
0N/A }
0N/A public int hashCode() {
0N/A return mech.hashCode();
0N/A }
0N/A Oid getMech() {
0N/A return mech;
0N/A }
0N/A}