001: /*
002: * Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package sun.security.jgss.wrapper;
027:
028: import java.util.Hashtable;
029: import org.ietf.jgss.Oid;
030: import org.ietf.jgss.GSSName;
031: import org.ietf.jgss.ChannelBinding;
032: import org.ietf.jgss.MessageProp;
033: import org.ietf.jgss.GSSException;
034: import sun.security.jgss.GSSUtil;
035:
036: /**
037: * This class is essentially a JNI calling stub for all wrapper classes.
038: *
039: * @author Valerie Peng
040: * @version 1.13, 05/05/07
041: * @since 1.6
042: */
043:
044: class GSSLibStub {
045:
046: private Oid mech;
047: private long pMech;
048:
049: /**
050: * Initialization routine to dynamically load function pointers.
051: *
052: * @param library name to dlopen
053: * @return true if succeeded, false otherwise.
054: */
055: static native boolean init(String lib);
056:
057: private static native long getMechPtr(byte[] oidDerEncoding);
058:
059: // Miscellaneous routines
060: static native Oid[] indicateMechs();
061:
062: native Oid[] inquireNamesForMech() throws GSSException;
063:
064: // Name related routines
065: native void releaseName(long pName);
066:
067: native long importName(byte[] name, Oid type);
068:
069: native boolean compareName(long pName1, long pName2);
070:
071: native long canonicalizeName(long pName);
072:
073: native byte[] exportName(long pName) throws GSSException;
074:
075: native Object[] displayName(long pName) throws GSSException;
076:
077: // Credential related routines
078: native long acquireCred(long pName, int lifetime, int usage)
079: throws GSSException;
080:
081: native long releaseCred(long pCred);
082:
083: native long getCredName(long pCred);
084:
085: native int getCredTime(long pCred);
086:
087: native int getCredUsage(long pCred);
088:
089: // Context related routines
090: native NativeGSSContext importContext(byte[] interProcToken);
091:
092: native byte[] initContext(long pCred, long targetName,
093: ChannelBinding cb, byte[] inToken, NativeGSSContext context);
094:
095: native byte[] acceptContext(long pCred, ChannelBinding cb,
096: byte[] inToken, NativeGSSContext context);
097:
098: native long[] inquireContext(long pContext);
099:
100: native Oid getContextMech(long pContext);
101:
102: native long getContextName(long pContext, boolean isSrc);
103:
104: native int getContextTime(long pContext);
105:
106: native long deleteContext(long pContext);
107:
108: native int wrapSizeLimit(long pContext, int flags, int qop,
109: int outSize);
110:
111: native byte[] exportContext(long pContext);
112:
113: native byte[] getMic(long pContext, int qop, byte[] msg);
114:
115: native void verifyMic(long pContext, byte[] token, byte[] msg,
116: MessageProp prop);
117:
118: native byte[] wrap(long pContext, byte[] msg, MessageProp prop);
119:
120: native byte[] unwrap(long pContext, byte[] msgToken,
121: MessageProp prop);
122:
123: private static Hashtable<Oid, GSSLibStub> table = new Hashtable<Oid, GSSLibStub>(
124: 5);
125:
126: static GSSLibStub getInstance(Oid mech) throws GSSException {
127: GSSLibStub s = table.get(mech);
128: if (s == null) {
129: s = new GSSLibStub(mech);
130: table.put(mech, s);
131: }
132: return s;
133: }
134:
135: private GSSLibStub(Oid mech) throws GSSException {
136: SunNativeProvider.debug("Created GSSLibStub for mech " + mech);
137: this .mech = mech;
138: this .pMech = getMechPtr(mech.getDER());
139: }
140:
141: public boolean equals(Object obj) {
142: if (obj == this )
143: return true;
144: if (!(obj instanceof GSSLibStub)) {
145: return false;
146: }
147: return (mech.equals(((GSSLibStub) obj).getMech()));
148: }
149:
150: public int hashCode() {
151: return mech.hashCode();
152: }
153:
154: Oid getMech() {
155: return mech;
156: }
157: }
|