GSSContextEx
# HG changeset patch
# User weijun
# Date 1235699013 -28800
# Node ID 46b5bab64c25ee6417083078271e9e8b18b35103
# Parent c6c88cfd6860f76d8263e937cd560a8218b56b1b
9999999: Implement gss_inquire_sec_context_by_oid
Reviewed-by: nobody
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/com/sun/security/jgss/GSSContextEx.java Fri Feb 27 09:43:33 2009 +0800
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package com.sun.security.jgss;
+
+import org.ietf.jgss.GSSException;
+import org.ietf.jgss.Oid;
+
+/**
+ * Extra GSSContext interface methods defined by vendor.
+ */
+public interface GSSContextEx {
+ /**
+ * Retrieve property of the context using an OID as a key.
+ * @param oid the type of the property requested
+ * @return the property
+ * @throws org.ietf.jgss.GSSException
+ */
+ public Object inquireSecContextByOid(Oid oid)
+ throws GSSException;
+}
--- a/src/share/classes/sun/security/jgss/GSSContextImpl.java Sat Feb 21 11:39:57 2009 -0800
+++ b/src/share/classes/sun/security/jgss/GSSContextImpl.java Fri Feb 27 09:43:33 2009 +0800
@@ -34,7 +34,8 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
-
+import com.sun.security.jgss.GSSContextEx;
+import sun.security.jgss.krb5.Krb5Context;
/**
* This class represents the JGSS security context and its associated
@@ -88,7 +89,7 @@
* per-message operations are returned in an instance of the MessageProp
* class, which is used as an argument in these calls.</dl>
*/
-class GSSContextImpl implements GSSContext {
+class GSSContextImpl implements GSSContext, GSSContextEx {
private GSSManagerImpl gssManager = null;
@@ -630,4 +631,11 @@
srcName = null;
targName = null;
}
+
+ public Object inquireSecContextByOid(Oid oid) throws GSSException {
+ if (mechCtxt == null) {
+ throw new GSSException(GSSException.NO_CONTEXT);
+ }
+ return mechCtxt.inquireSecContextByOid(oid);
+ }
}
--- a/src/share/classes/sun/security/jgss/krb5/Krb5Context.java Sat Feb 21 11:39:57 2009 -0800
+++ b/src/share/classes/sun/security/jgss/krb5/Krb5Context.java Fri Feb 27 09:43:33 2009 +0800
@@ -37,8 +37,7 @@
import java.security.Provider;
import java.security.AccessController;
import java.security.AccessControlContext;
-import java.security.GeneralSecurityException;
-import java.security.PrivilegedAction;
+import java.security.Key;
import java.security.PrivilegedExceptionAction;
import java.security.PrivilegedActionException;
import javax.crypto.Cipher;
@@ -53,7 +52,7 @@
* @author Ram Marti
* @since 1.4
*/
-class Krb5Context implements GSSContextSpi {
+public class Krb5Context implements GSSContextSpi {
/*
* The different states that this context can be in.
@@ -1284,4 +1283,31 @@
// Currently used by InitialToken only
return caller;
}
+
+ static class KerberosSessionKey implements Key {
+ private EncryptionKey key;
+
+ KerberosSessionKey(EncryptionKey key) {
+ this.key = key;
+ }
+ @Override
+ public String getAlgorithm() {
+ return "1.2.840.113554.1.2.2.4." + key.getEType();
+ }
+
+ @Override
+ public String getFormat() {
+ return "RAW";
+ }
+
+ @Override
+ public byte[] getEncoded() {
+ return key.getBytes().clone();
+ }
+ }
+ public Object inquireSecContextByOid(Oid oid)
+ throws GSSException {
+ // Check... TODO
+ return new KerberosSessionKey(key);
+ }
}
--- a/src/share/classes/sun/security/jgss/spi/GSSContextSpi.java Sat Feb 21 11:39:57 2009 -0800
+++ b/src/share/classes/sun/security/jgss/spi/GSSContextSpi.java Fri Feb 27 09:43:33 2009 +0800
@@ -403,4 +403,7 @@
* @exception GSSException may be thrown
*/
public void dispose() throws GSSException;
+
+ public Object inquireSecContextByOid(Oid oid)
+ throws GSSException;
}
--- a/src/share/classes/sun/security/jgss/spnego/SpNegoContext.java Sat Feb 21 11:39:57 2009 -0800
+++ b/src/share/classes/sun/security/jgss/spnego/SpNegoContext.java Fri Feb 27 09:43:33 2009 +0800
@@ -27,12 +27,11 @@
import java.io.*;
import java.security.Provider;
-import java.util.List;
-import java.util.ArrayList;
import org.ietf.jgss.*;
import sun.security.jgss.*;
import sun.security.jgss.spi.*;
import sun.security.util.*;
+import com.sun.security.jgss.GSSContextEx;
/**
* Implements the mechanism specific context class for SPNEGO
@@ -1200,4 +1199,17 @@
return ("Unknown state " + state);
}
}
+
+ public Object inquireSecContextByOid(Oid oid)
+ throws GSSException {
+ if (mechContext == null) {
+ throw new GSSException(GSSException.NO_CONTEXT);
+ }
+ if (mechContext instanceof GSSContextEx) {
+ return ((GSSContextEx)mechContext).inquireSecContextByOid(oid);
+ } else {
+ throw new GSSException(GSSException.UNAVAILABLE);
+ }
+ }
+
}
--- a/src/share/classes/sun/security/jgss/wrapper/NativeGSSContext.java Sat Feb 21 11:39:57 2009 -0800
+++ b/src/share/classes/sun/security/jgss/wrapper/NativeGSSContext.java Fri Feb 27 09:43:33 2009 +0800
@@ -615,4 +615,9 @@
protected void finalize() throws Throwable {
dispose();
}
+
+ public Object inquireSecContextByOid(Oid oid)
+ throws GSSException {
+ throw new GSSException(GSSException.UNAVAILABLE);
+ }
}
--- a/test/sun/security/krb5/auto/Context.java Sat Feb 21 11:39:57 2009 -0800
+++ b/test/sun/security/krb5/auto/Context.java Fri Feb 27 09:43:33 2009 +0800
@@ -38,6 +38,7 @@
import org.ietf.jgss.GSSName;
import org.ietf.jgss.MessageProp;
import org.ietf.jgss.Oid;
+import com.sun.security.jgss.GSSContextEx;
/**
* Context of a JGSS subject, encapsulating Subject and GSSContext.
@@ -276,6 +277,15 @@
}
}
}
+ if (x != null && x instanceof GSSContextEx) {
+ try {
+ GSSContextEx ex = (GSSContextEx)x;
+ System.out.println("Session key is: " +
+ ex.inquireSecContextByOid(new Oid("1.2.840.113554.1.2.2.5.5")));
+ } catch (GSSException gse) {
+ System.out.println("Session key not available yet");
+ }
+ }
}
/**