blob: ebc12e47acbc31fb8fae22d1d14704ae015fa460 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26package sun.security.jgss.wrapper;
27
28import java.util.Hashtable;
29import org.ietf.jgss.Oid;
30import org.ietf.jgss.GSSName;
31import org.ietf.jgss.ChannelBinding;
32import org.ietf.jgss.MessageProp;
33import org.ietf.jgss.GSSException;
34import sun.security.jgss.GSSUtil;
35
36/**
37 * This class is essentially a JNI calling stub for all wrapper classes.
38 *
39 * @author Valerie Peng
40 * @since 1.6
41 */
42
43class GSSLibStub {
44
45 private Oid mech;
46 private long pMech;
47
48 /**
49 * Initialization routine to dynamically load function pointers.
50 *
51 * @param library name to dlopen
52 * @return true if succeeded, false otherwise.
53 */
54 static native boolean init(String lib);
55 private static native long getMechPtr(byte[] oidDerEncoding);
56
57 // Miscellaneous routines
58 static native Oid[] indicateMechs();
59 native Oid[] inquireNamesForMech() throws GSSException;
60
61 // Name related routines
62 native void releaseName(long pName);
63 native long importName(byte[] name, Oid type);
64 native boolean compareName(long pName1, long pName2);
65 native long canonicalizeName(long pName);
66 native byte[] exportName(long pName) throws GSSException;
67 native Object[] displayName(long pName) throws GSSException;
68
69 // Credential related routines
70 native long acquireCred(long pName, int lifetime, int usage)
71 throws GSSException;
72 native long releaseCred(long pCred);
73 native long getCredName(long pCred);
74 native int getCredTime(long pCred);
75 native int getCredUsage(long pCred);
76
77 // Context related routines
78 native NativeGSSContext importContext(byte[] interProcToken);
79 native byte[] initContext(long pCred, long targetName, ChannelBinding cb,
80 byte[] inToken, NativeGSSContext context);
81 native byte[] acceptContext(long pCred, ChannelBinding cb,
82 byte[] inToken, NativeGSSContext context);
83 native long[] inquireContext(long pContext);
84 native Oid getContextMech(long pContext);
85 native long getContextName(long pContext, boolean isSrc);
86 native int getContextTime(long pContext);
87 native long deleteContext(long pContext);
88 native int wrapSizeLimit(long pContext, int flags, int qop, int outSize);
89 native byte[] exportContext(long pContext);
90 native byte[] getMic(long pContext, int qop, byte[] msg);
91 native void verifyMic(long pContext, byte[] token, byte[] msg,
92 MessageProp prop) ;
93 native byte[] wrap(long pContext, byte[] msg, MessageProp prop);
94 native byte[] unwrap(long pContext, byte[] msgToken, MessageProp prop);
95
96 private static Hashtable<Oid, GSSLibStub>
97 table = new Hashtable<Oid, GSSLibStub>(5);
98
99 static GSSLibStub getInstance(Oid mech) throws GSSException {
100 GSSLibStub s = table.get(mech);
101 if (s == null) {
102 s = new GSSLibStub(mech);
103 table.put(mech, s);
104 }
105 return s;
106 }
107 private GSSLibStub(Oid mech) throws GSSException {
108 SunNativeProvider.debug("Created GSSLibStub for mech " + mech);
109 this.mech = mech;
110 this.pMech = getMechPtr(mech.getDER());
111 }
112 public boolean equals(Object obj) {
113 if (obj == this) return true;
114 if (!(obj instanceof GSSLibStub)) {
115 return false;
116 }
117 return (mech.equals(((GSSLibStub) obj).getMech()));
118 }
119 public int hashCode() {
120 return mech.hashCode();
121 }
122 Oid getMech() {
123 return mech;
124 }
125}