Commit 28f7d9d0 by Bryce McKinlay

decl.c (init_decl_processing): Add new class "protectionDomain" field.

gcc/java:

2001-04-25  Bryce McKinlay  <bryce@waitaki.otago.ac.nz>

	* decl.c (init_decl_processing): Add new class "protectionDomain"
	field.
	* class.c (make_class_data): Set initial value for "protectionDomain".

libjava:

2001-04-25  Bryce McKinlay  <bryce@albatross.co.nz>

	java.security merge and ClassLoader compliance fixes.

	* java/lang/Class.h (Class): Include ProtectionDomain.h.
	New protectionDomain field.
	(forName): Add initialize parameter. Fixes declaration to comply with
	JDK spec.
	* java/lang/natClass.cc (forName): Correct declaration of the three-arg
	variant. Honour	"initialize" flag.
	(getProtectionDomain0): New method.
	* java/lang/Class.java: Fix forName() declaration.
	(getPackage): New method based on Classpath implementation.
	(getProtectionDomain0): New native method decl.
	(getProtectionDomain): New method.
	* java/lang/ClassLoader.java (getParent): Now final.
	(definedPackages): New field.
	(getPackage): New.
	(defineClass): New variant with protectionDomain argument.
	(definePackage): New.
	(getPackages): New.
	(findSystemClass): Now final.
	(getSystemResourceAsStream): Remove redundant "final" modifier.
	(getSystemResource): Remove redundant "final" modifier.
	(getResources): Now final.
	(protectionDomainPermission): New static field.
	(unknownProtectionDomain): Ditto.
	(defaultProtectionDomain): Ditto.
	(getSystemClassLoader): Now non-native.
	* java/util/ResourceBundle.java (tryGetSomeBundle): Use the correct
	arguments for Class.forName().
	* java/lang/Package.java: New file.
	* gnu/gcj/runtime/VMClassLoader.java (getVMClassLoader): Removed.
	(instance): Static initialize singleton.
	(findClass): Override this, not findSystemClass.
	* java/lang/natClassLoader.cc (defineClass0): Set class's
	protectionDomain field as specified.
	(getSystemClassLoader): Removed.
	(findClass): Renamed from findSystemClass. Call the interpreter via
	URLClassLoader.findClass if loading class via dlopen fails.

	* java/security/*.java: java.security import/merge with Classpath.
	* java/security/acl/*.java: Likewise.
	* java/security/interfaces/*.java: Likewise.
	* java/security/spec/*.java: Likewise.
	* java/net/NetPermission.java: Likewise.
	* java/net/SocketPermission.java: Likewise.
	* gnu/java/security/provider/DefaultPolicy.java: Likewise.

	* Makefile.am: Add new classes.
	* Makefile.in: Rebuilt.
	* gcj/javaprims.h: CNI namespace rebuild.

From-SVN: r41543
parent 744cfa53
2001-04-25 Bryce McKinlay <bryce@waitaki.otago.ac.nz>
* decl.c (init_decl_processing): Add new class "protectionDomain"
field.
* class.c (make_class_data): Set initial value for "protectionDomain".
2001-04-22 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* jvspec.c (lang_specific_driver): Fix memory allocation
......
......@@ -1455,6 +1455,7 @@ make_class_data (type)
PUSH_FIELD_VALUE (cons, "ancestors", null_pointer_node);
PUSH_FIELD_VALUE (cons, "idt", null_pointer_node);
PUSH_FIELD_VALUE (cons, "arrayclass", null_pointer_node);
PUSH_FIELD_VALUE (cons, "protectionDomain", null_pointer_node);
FINISH_RECORD_CONSTRUCTOR (cons);
......
......@@ -647,6 +647,7 @@ init_decl_processing ()
PUSH_FIELD (class_type_node, field, "ancestors", ptr_type_node);
PUSH_FIELD (class_type_node, field, "idt", ptr_type_node);
PUSH_FIELD (class_type_node, field, "arrayclass", ptr_type_node);
PUSH_FIELD (class_type_node, field, "protectionDomain", ptr_type_node);
for (t = TYPE_FIELDS (class_type_node); t != NULL_TREE; t = TREE_CHAIN (t))
FIELD_PRIVATE (t) = 1;
push_super_field (class_type_node, object_type_node);
......
2001-04-25 Bryce McKinlay <bryce@albatross.co.nz>
java.security merge and ClassLoader compliance fixes.
* java/lang/Class.h (Class): Include ProtectionDomain.h.
New protectionDomain field.
(forName): Add initialize parameter. Fixes declaration to comply with
JDK spec.
* java/lang/natClass.cc (forName): Correct declaration of the three-arg
variant. Honour "initialize" flag.
(getProtectionDomain0): New method.
* java/lang/Class.java: Fix forName() declaration.
(getPackage): New method based on Classpath implementation.
(getProtectionDomain0): New native method decl.
(getProtectionDomain): New method.
* java/lang/ClassLoader.java (getParent): Now final.
(definedPackages): New field.
(getPackage): New.
(defineClass): New variant with protectionDomain argument.
(definePackage): New.
(getPackages): New.
(findSystemClass): Now final.
(getSystemResourceAsStream): Remove redundant "final" modifier.
(getSystemResource): Remove redundant "final" modifier.
(getResources): Now final.
(protectionDomainPermission): New static field.
(unknownProtectionDomain): Ditto.
(defaultProtectionDomain): Ditto.
(getSystemClassLoader): Now non-native.
* java/util/ResourceBundle.java (tryGetSomeBundle): Use the correct
arguments for Class.forName().
* java/lang/Package.java: New file.
* gnu/gcj/runtime/VMClassLoader.java (getVMClassLoader): Removed.
(instance): Static initialize singleton.
(findClass): Override this, not findSystemClass.
* java/lang/natClassLoader.cc (defineClass0): Set class's
protectionDomain field as specified.
(getSystemClassLoader): Removed.
(findClass): Renamed from findSystemClass. Call the interpreter via
URLClassLoader.findClass if loading class via dlopen fails.
* java/security/*.java: java.security import/merge with Classpath.
* java/security/acl/*.java: Likewise.
* java/security/interfaces/*.java: Likewise.
* java/security/spec/*.java: Likewise.
* java/net/NetPermission.java: Likewise.
* java/net/SocketPermission.java: Likewise.
* gnu/java/security/provider/DefaultPolicy.java: Likewise.
* Makefile.am: Add new classes.
* Makefile.in: Rebuilt.
* gcj/javaprims.h: CNI namespace rebuild.
2001-04-24 Alexandre Oliva <aoliva@redhat.com>
* configure.in (CPPFLAGS): Added builddir and srcdir to CPPFLAGS
......
......@@ -843,6 +843,7 @@ java/lang/NullPointerException.java \
java/lang/Number.java \
java/lang/NumberFormatException.java \
java/lang/OutOfMemoryError.java \
java/lang/Package.java \
java/lang/Process.java \
java/lang/Runnable.java \
java/lang/Runtime.java \
......@@ -1036,6 +1037,7 @@ gnu/java/locale/Calendar.java \
gnu/java/locale/Calendar_de.java \
gnu/java/locale/Calendar_en.java \
gnu/java/locale/Calendar_nl.java \
gnu/java/security/provider/DefaultPolicy.java \
gnu/java/security/provider/Gnu.java \
gnu/java/security/provider/SHA.java \
gnu/java/security/provider/SHA1PRNG.java \
......@@ -1068,6 +1070,7 @@ java/net/InetAddress.java \
java/net/JarURLConnection.java \
java/net/MalformedURLException.java \
java/net/MulticastSocket.java \
java/net/NetPermission.java \
java/net/NoRouteToHostException.java \
java/net/PlainDatagramSocketImpl.java \
java/net/PlainSocketImpl.java \
......@@ -1078,6 +1081,7 @@ java/net/SocketException.java \
java/net/SocketImpl.java \
java/net/SocketImplFactory.java \
java/net/SocketOptions.java \
java/net/SocketPermission.java \
java/net/URL.java \
java/net/URLClassLoader.java \
java/net/URLConnection.java \
......@@ -1087,34 +1091,80 @@ java/net/URLStreamHandler.java \
java/net/URLStreamHandlerFactory.java \
java/net/UnknownHostException.java \
java/net/UnknownServiceException.java \
java/security/AccessControlContext.java \
java/security/AccessControlException.java \
java/security/AccessController.java \
java/security/AlgorithmParameterGenerator.java \
java/security/AlgorithmParameters.java \
java/security/AlgorithmParameterGeneratorSpi.java \
java/security/AlgorithmParametersSpi.java \
java/security/AllPermission.java \
java/security/BasicPermission.java \
java/security/Certificate.java \
java/security/CodeSource.java \
java/security/DigestException.java \
java/security/DigestOutputStream.java \
java/security/DummyKeyPairGenerator.java \
java/security/DummySignature.java \
java/security/DigestInputStream.java \
java/security/DomainCombiner.java \
java/security/DummyMessageDigest.java \
java/security/GeneralSecurityException.java \
java/security/Guard.java \
java/security/GuardedObject.java \
java/security/Identity.java \
java/security/IdentityScope.java \
java/security/InvalidAlgorithmParameterException.java \
java/security/InvalidKeyException.java \
java/security/InvalidParameterException.java \
java/security/Key.java \
java/security/KeyException.java \
java/security/KeyPair.java \
java/security/KeyFactorySpi.java \
java/security/KeyPairGenerator.java \
java/security/KeyStoreException.java \
java/security/KeyException.java \
java/security/KeyManagementException.java \
java/security/KeyPairGeneratorSpi.java \
java/security/KeyStoreSpi.java \
java/security/KeyFactory.java \
java/security/KeyPair.java \
java/security/KeyStore.java \
java/security/MessageDigest.java \
java/security/MessageDigestSpi.java \
java/security/NoSuchAlgorithmException.java \
java/security/NoSuchProviderException.java \
java/security/Permission.java \
java/security/PermissionCollection.java \
java/security/Principal.java \
java/security/PrivilegedExceptionAction.java \
java/security/PublicKey.java \
java/security/PermissionCollection.java \
java/security/PrivateKey.java \
java/security/ProtectionDomain.java \
java/security/Permissions.java \
java/security/PrivilegedAction.java \
java/security/Provider.java \
java/security/PublicKey.java \
java/security/Policy.java \
java/security/PrivilegedActionException.java \
java/security/ProviderException.java \
java/security/SecureClassLoader.java \
java/security/SecureRandom.java \
java/security/SecureRandomSpi.java \
java/security/SecurityPermission.java \
java/security/SignatureException.java \
java/security/SignedObject.java \
java/security/SecureRandom.java \
java/security/Security.java \
java/security/Signature.java \
java/security/SignatureException.java \
java/security/SignatureSpi.java \
java/security/Signer.java \
java/security/UnrecoverableKeyException.java \
java/security/UnresolvedPermission.java \
java/security/acl/Acl.java \
java/security/acl/AclNotFoundException.java \
java/security/acl/LastOwnerException.java \
java/security/acl/Owner.java \
java/security/acl/AclEntry.java \
java/security/acl/Group.java \
java/security/acl/NotOwnerException.java \
java/security/acl/Permission.java \
java/security/cert/CRL.java \
java/security/cert/CRLException.java \
java/security/cert/Certificate.java \
......@@ -1130,19 +1180,28 @@ java/security/cert/X509CRLEntry.java \
java/security/cert/X509Certificate.java \
java/security/cert/X509Extension.java \
java/security/interfaces/DSAKey.java \
java/security/interfaces/DSAParams.java \
java/security/interfaces/DSAKeyPairGenerator.java \
java/security/interfaces/DSAParams.java \
java/security/interfaces/DSAPrivateKey.java \
java/security/interfaces/DSAPublicKey.java \
java/security/interfaces/RSAKey.java \
java/security/interfaces/RSAPrivateCrtKey.java \
java/security/interfaces/RSAPrivateKey.java \
java/security/interfaces/RSAPublicKey.java \
java/security/spec/AlgorithmParameterSpec.java \
java/security/spec/InvalidKeySpecException.java \
java/security/spec/DSAParameterSpec.java \
java/security/spec/DSAPrivateKeySpec.java \
java/security/spec/DSAPublicKeySpec.java \
java/security/spec/EncodedKeySpec.java \
java/security/spec/InvalidKeySpecException.java \
java/security/spec/InvalidParameterSpecException.java \
java/security/spec/KeySpec.java \
java/security/spec/KeySpec.java \
java/security/spec/PKCS8EncodedKeySpec.java \
java/security/spec/RSAKeyGenParameterSpec.java \
java/security/spec/RSAPrivateCrtKeySpec.java \
java/security/spec/RSAPrivateKeySpec.java \
java/security/spec/RSAPublicKeySpec.java \
java/security/spec/X509EncodedKeySpec.java \
java/sql/Array.java \
java/sql/BatchUpdateException.java \
java/sql/Blob.java \
......
......@@ -202,7 +202,7 @@ distdir: $(DISTFILES)
@for file in $(DISTFILES); do \
d=$(srcdir); \
if test -d $$d/$$file; then \
cp -pr $$/$$file $(distdir)/$$file; \
cp -pr $$d/$$file $(distdir)/$$file; \
else \
test -f $(distdir)/$$file \
|| ln $$d/$$file $(distdir)/$$file 2> /dev/null \
......
......@@ -39,7 +39,6 @@ extern "Java"
{
namespace io
{
class BlockDataException;
class BufferedInputStream;
class BufferedOutputStream;
class BufferedReader;
......@@ -176,6 +175,7 @@ extern "Java"
class NumberFormatException;
class Object;
class OutOfMemoryError;
class Package;
class Process;
class Runnable;
class Runtime;
......@@ -233,10 +233,12 @@ extern "Java"
class ArrayList;
class Arrays;
class Arrays$ListImpl;
class BasicMapEntry;
class BitSet;
class Calendar;
class Collection;
class Collections;
class Collections$ReverseComparator;
class Collections$SynchronizedCollection;
class Collections$SynchronizedIterator;
class Collections$SynchronizedList;
......@@ -302,6 +304,12 @@ extern "Java"
class Timer$TaskQueue;
class TimerTask;
class TooManyListenersException;
class TreeMap;
class TreeMap$Node;
class TreeMap$SubMap;
class TreeMap$TreeIterator;
class TreeMap$VerifyResult;
class TreeSet;
class Vector;
class WeakHashMap;
class WeakHashMap$Entry;
......
......@@ -65,18 +65,11 @@ final class VMClassLoader extends java.net.URLClassLoader
/** This is overridden to search the internal hash table, which
* will only search existing linked-in classes. This will make
* the default implementation of loadClass (in ClassLoader) work right.
* The implementation of this method is in java/lang/natClassLoader.cc.
*/
protected final native Class findSystemClass(String name)
throws java.lang.ClassNotFoundException, java.lang.LinkageError;
// Return the sole VMClassLoader.
private static synchronized VMClassLoader getVMClassLoader ()
{
if (redirect == null)
redirect = new VMClassLoader ();
return redirect;
}
protected native Class findClass(String name)
throws java.lang.ClassNotFoundException;
// The only VMClassLoader that can exist.
private static VMClassLoader redirect;
public static VMClassLoader instance = new VMClassLoader ();
}
/* DefaultPolicy.java
Copyright (C) 2001 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
package gnu.java.security.provider;
import java.security.*;
/**
* This is just a stub policy implementation which grants all permissions
* to any code source. FIXME: This should be replaced with a real
* implementation that reads the policy configuration from a file, like
* $JAVA_HOME/jre/lib/security/java.security.
*/
public class DefaultPolicy extends Policy
{
static Permissions allPermissions = new Permissions();
static
{
allPermissions.add(new AllPermission());
}
public PermissionCollection getPermissions(CodeSource codesource)
{
return allPermissions;
}
public void refresh()
{
// Nothing.
}
}
......@@ -19,6 +19,7 @@ details. */
#include <java/lang/String.h>
#include <java/net/URL.h>
#include <java/lang/reflect/Modifier.h>
#include <java/security/ProtectionDomain.h>
// We declare these here to avoid including gcj/cni.h.
extern "C" void _Jv_InitClass (jclass klass);
......@@ -105,7 +106,8 @@ struct _Jv_ifaces
class java::lang::Class : public java::lang::Object
{
public:
static jclass forName (jstring className, java::lang::ClassLoader *loader);
static jclass forName (jstring className, jboolean initialize,
java::lang::ClassLoader *loader);
static jclass forName (jstring className);
JArray<jclass> *getClasses (void);
......@@ -135,6 +137,7 @@ private:
jint offset);
java::lang::reflect::Field *getPrivateField (jstring);
java::lang::reflect::Method *getPrivateMethod (jstring, JArray<jclass> *);
java::security::ProtectionDomain *getProtectionDomain0 ();
public:
JArray<java::lang::reflect::Field *> *getFields (void);
......@@ -380,6 +383,8 @@ private:
_Jv_IDispatchTable *idt;
// Pointer to the class that represents an array of this class.
jclass arrayclass;
// Security Domain to which this class belongs (or null).
java::security::ProtectionDomain *protectionDomain;
};
#endif /* __JAVA_LANG_CLASS_H__ */
......@@ -12,6 +12,7 @@ package java.lang;
import java.io.Serializable;
import java.io.InputStream;
import java.lang.reflect.*;
import java.security.*;
/**
* @author Tom Tromey <tromey@cygnus.com>
......@@ -30,7 +31,9 @@ public final class Class implements Serializable
{
public static native Class forName (String className)
throws ClassNotFoundException;
public static native Class forName (String className, ClassLoader loader)
/** @since 1.2 */
public static native Class forName (String className, boolean initialize,
ClassLoader loader)
throws ClassNotFoundException;
public native Class[] getClasses ();
public native ClassLoader getClassLoader ();
......@@ -88,6 +91,30 @@ public final class Class implements Serializable
private native Field[] _getFields (Field[] result, int offset);
public native Field[] getFields () throws SecurityException;
/**
* Returns the <code>Package</code> in which this class is defined
* Returns null when this information is not available from the
* classloader of this class or when the classloader of this class
* is null.
*
* @since 1.2
*/
public Package getPackage()
{
ClassLoader cl = getClassLoader();
if (cl != null)
{
String name = getName();
String pkg = "";
int idx = name.lastIndexOf('.');
if (idx >= 0)
pkg = name.substring(0, idx);
return cl.getPackage(pkg);
}
else
return null;
}
public native Class[] getInterfaces ();
private final native void getSignature (StringBuffer buffer);
......@@ -154,6 +181,35 @@ public final class Class implements Serializable
public native Object newInstance ()
throws InstantiationException, IllegalAccessException;
// We need a native method to retrieve the protection domain, because we
// can't add fields to java.lang.Class that are accessible from Java.
private native ProtectionDomain getProtectionDomain0();
/**
* Returns the protection domain of this class. If the classloader
* did not record the protection domain when creating this class
* the unknown protection domain is returned which has a <code>null</code>
* code source and all permissions.
*
* @exception SecurityException if a security manager exists and the caller
* does not have <code>RuntimePermission("getProtectionDomain")</code>.
*
* @since 1.2
*/
public ProtectionDomain getProtectionDomain()
{
SecurityManager sm = System.getSecurityManager();
if (sm != null)
sm.checkPermission(ClassLoader.protectionDomainPermission);
ProtectionDomain protectionDomain = getProtectionDomain0();
if (protectionDomain == null)
return ClassLoader.unknownProtectionDomain;
else
return protectionDomain;
}
public String toString ()
{
if (isPrimitive ())
......
/* java.lang.Package - Everything you ever wanted to know about a package.
Copyright (C) 2000, 2001 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
package java.lang;
import java.net.URL;
import java.util.NoSuchElementException;
import java.util.StringTokenizer;
/**
* Everything you ever wanted to know about a package. This class makes it
* possible to attach specification and implementation information to a
* package as explained in the
* <a href="http://java.sun.com/products/jdk/1.3/docs/guide/versioning/spec/VersioningSpecification.html#PackageVersionSpecification">Package Versioning Specification</a>
* section of the
* <a href="http://java.sun.com/products/jdk/1.3/docs/guide/versioning/spec/VersioningSpecification.html">Product Versioning Specification</a>.
* It also allows packages to be sealed with respect to the originating URL.
* <p>
* The most usefull method is the <code>isCompatibleWith()</code> method that
* compares a desired version of a specification with the version of the
* specification as implemented by a package. A package is considered
* compatible with another version if the version of the specification is
* equal or higher then the requested version. Version numbers are represented
* as strings of positive numbers seperated by dots (e.g. "1.2.0").
* The first number is called the major number, the second the minor,
* the third the micro, etc. A version is considered higher then another
* version if it has a bigger major number then the another version or when
* the major numbers of the versions are equal if it has a bigger minor number
* then the other version, etc. (If a version has no minor, micro, etc numbers
* then they are considered the be 0.)
*
* @since 1.2
* @author Mark Wielaard (mark@klomp.org)
*/
public class Package
{
/** The name of the Package */
final private String name;
/** The name if the implementation */
final private String implTitle;
/** The vendor that wrote this implementation */
final private String implVendor;
/** The version of this implementation */
final private String implVersion;
/** The name of the specification */
final private String specTitle;
/** The name of the specification designer */
final private String specVendor;
/** The version of this specification */
final private String specVersion;
/** If sealed the origin of the package classes, otherwise null */
final private URL sealed;
/**
* A package local constructor for the Package class.
* All parameters except the <code>name</code> of the package may be
* <code>null</code>.
* There are no public constructors defined for Package this is a package
* local constructor that is used by java.lang.Classloader.definePackage().
*
* @param name The name of the Package
* @param specTitle The name of the specification
* @param specVendor The name of the specification designer
* @param specVersion The version of this specification
* @param implTitle The name of the implementation
* @param implVendor The vendor that wrote this implementation
* @param implVersion The version of this implementation
* @param sealed If sealed the origin of the package classes
*/
Package(String name,
String specTitle, String specVendor, String specVersion,
String implTitle, String implVendor, String implVersion, URL sealed)
{
if (name == null)
throw new IllegalArgumentException("null Package name");
this.name = name;
this.implTitle = implTitle;
this.implVendor = implVendor;
this.implVersion = implVersion;
this.specTitle = specTitle;
this.specVendor = specVendor;
this.specVersion = specVersion;
this.sealed = sealed;
}
/**
* Returns the Package name.
*/
public String getName()
{
return name;
}
/**
* Returns the name of the implementation or null if unknown.
*/
public String getImplementationTitle()
{
return implTitle;
}
/**
* Returns the vendor that wrote this implementation or null if unknown.
*/
public String getImplementationVendor()
{
return implVendor;
}
/**
* Returns the version of this implementation or null if unknown.
*/
public String getImplementationVersion()
{
return implVersion;
}
/**
* Returns the name of the specification or null if unknown.
*/
public String getSpecificationTitle()
{
return specTitle;
}
/**
* Returns the name of the specification designer or null if unknown.
*/
public String getSpecificationVendor()
{
return specVendor;
}
/**
* Returns the version of the specification or null if unknown.
*/
public String getSpecificationVersion()
{
return specVersion;
}
/**
* Returns true if this Package is sealed.
*/
public boolean isSealed()
{
return (sealed != null);
}
/**
* Returns true if this Package is sealed and the origin of the classes is
* the given URL.
*
* @param url
*/
public boolean isSealed(URL url)
{
return url.equals(sealed);
}
/**
* Checks if the version of the specification is higher or at least as high
* as the desired version.
* @param version the (minimal) desired version of the specification
* @exception NumberFormatException when either version or the
* specification version is not a correctly formatted version number
* @exception NullPointerException if the supplied version or the
* Package specification version is null.
*/
public boolean isCompatibleWith(String version) throws NumberFormatException
{
StringTokenizer versionTokens = new StringTokenizer(version, ".");
StringTokenizer specTokens = new StringTokenizer(specVersion, ".");
try
{
while (versionTokens.hasMoreElements())
{
int vers = Integer.parseInt(versionTokens.nextToken());
int spec = Integer.parseInt(specTokens.nextToken());
if (spec < vers)
return false;
else if (spec > vers)
return true;
// They must be equal, next Token please!
}
}
catch (NoSuchElementException e)
{
// this must have been thrown by spec.netToken() so return false
return false;
}
// They must have been exactly the same version.
// Or the specVersion has more subversions. That is also good.
return true;
}
/**
* Returns the named package if it is known by the callers class loader.
* It may return null if the package is unknown, when there is no
* information on that particular package available or when the callers
* classloader is null.
* @param name the name of the desired package
*/
public static Package getPackage(String name)
{
// Get the caller's classloader
SecurityManager sm = System.getSecurityManager();
Class c = sm.getClassContext()[1];
ClassLoader cl = c.getClassLoader();
if (cl != null)
return cl.getPackage(name);
else
return null;
}
/**
* Returns all the packages that are known to the callers class loader.
* It may return an empty array if the classloader of the caller is null.
*/
public static Package[] getPackages()
{
// Get the caller's classloader
SecurityManager sm = System.getSecurityManager();
Class c = sm.getClassContext()[1];
ClassLoader cl = c.getClassLoader();
if (cl != null)
return cl.getPackages();
else
return new Package[0];
}
/**
* Returns the hashCode of the name of this package.
*/
public int hashCode()
{
return name.hashCode();
}
/**
* Returns a string representation of this package name, specification,
* implementation and class origin if sealed.
*/
public String toString()
{
return "package: " + name +
" spec: " + specTitle +
" version: " + specVersion +
" vendor: " + specVendor +
" implementation: " + implTitle +
" version: " + implVersion +
" vendor: " + implVendor + " sealed: " + sealed;
}
}
......@@ -72,7 +72,8 @@ static _Jv_Utf8Const *finit_leg_name = _Jv_makeUtf8Const ("$finit$", 7);
jclass
java::lang::Class::forName (jstring className, java::lang::ClassLoader *loader)
java::lang::Class::forName (jstring className, jboolean initialize,
java::lang::ClassLoader *loader)
{
if (! className)
throw new java::lang::NullPointerException;
......@@ -90,11 +91,12 @@ java::lang::Class::forName (jstring className, java::lang::ClassLoader *loader)
? _Jv_FindClassFromSignature (name->data, loader)
: _Jv_FindClass (name, loader));
if (klass)
_Jv_InitClass (klass);
else
if (klass == NULL)
throw new java::lang::ClassNotFoundException (className);
if (initialize)
_Jv_InitClass (klass);
return klass;
}
......@@ -102,7 +104,7 @@ jclass
java::lang::Class::forName (jstring className)
{
// FIXME: should use class loader from calling method.
return forName (className, NULL);
return forName (className, true, NULL);
}
java::lang::reflect::Constructor *
......@@ -1415,3 +1417,10 @@ java::lang::Class::getPrivateMethod (jstring name, JArray<jclass> *param_types)
}
throw new java::lang::NoSuchMethodException;
}
// Private accessor method for Java code to retrieve the protection domain.
java::security::ProtectionDomain *
java::lang::Class::getProtectionDomain0 ()
{
return protectionDomain;
}
......@@ -48,20 +48,12 @@ details. */
/////////// java.lang.ClassLoader native methods ////////////
java::lang::ClassLoader *
java::lang::ClassLoader::getSystemClassLoader (void)
{
JvSynchronize sync (&ClassLoaderClass);
if (! system)
system = gnu::gcj::runtime::VMClassLoader::getVMClassLoader ();
return system;
}
java::lang::Class *
java::lang::ClassLoader::defineClass0 (jstring name,
jbyteArray data,
jint offset,
jint length)
jint length,
java::security::ProtectionDomain *pd)
{
#ifdef INTERPRETER
jclass klass;
......@@ -109,6 +101,8 @@ java::lang::ClassLoader::defineClass0 (jstring name,
throw ex;
}
klass->protectionDomain = pd;
// if everything proceeded sucessfully, we're loaded.
JvAssert (klass->state == JV_STATE_LOADED);
......@@ -180,10 +174,10 @@ java::lang::ClassLoader::markClassErrorState0 (java::lang::Class *klass)
}
/** this is the only native method in VMClassLoader, so
we define it here. */
// This is the findClass() implementation for the System classloader. It is
// the only native method in VMClassLoader, so we define it here.
jclass
gnu::gcj::runtime::VMClassLoader::findSystemClass (jstring name)
gnu::gcj::runtime::VMClassLoader::findClass (jstring name)
{
_Jv_Utf8Const *name_u = _Jv_makeUtf8Const (name);
jclass klass = _Jv_FindClassInCache (name_u, 0);
......@@ -213,6 +207,12 @@ gnu::gcj::runtime::VMClassLoader::findSystemClass (jstring name)
}
}
// Now try loading using the interpreter.
if (! klass)
{
klass = java::net::URLClassLoader::findClass (name);
}
return klass;
}
......
/* NetPermission.java -- A class for basic miscellaneous network permission
Copyright (C) 1998, 2000 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
package java.net;
import java.security.BasicPermission;
/**
* This class is used to model miscellaneous network permissions. It is
* a subclass of BasicPermission. This means that it models a "boolean"
* permission. One that you either have or do not have. Thus there is
* no permitted action list associated with this object.
*
* @author Aaron M. Renn (arenn@urbanophile.com)
*/
public final class NetPermission extends BasicPermission
implements java.io.Serializable
{
/**
* Initializes a new instance of <code>NetPermission</code> with the
* specified name.
*
* @param name The name of this permission.
*/
public NetPermission(String name)
{
super(name);
}
/**
* Initializes a new instance of <code>NetPermission</code> with the
* specified name and value. Note that the value field is irrelevant and is
* ignored. This constructor should never need to be used.
*
* @param name The name of this permission
* @param perms The permitted actions of this permission (ignored)
*/
public NetPermission(String name, String perms)
{
super(name);
}
}
/* AccessControlContext.java --- Access Control Context Class
Copyright (C) 1999 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
package java.security;
/**
AccessControlContext makes system resource access decsion
based on permission rights.
It is used for a specific context and has only one method
checkPermission. It is similar to AccessController except
that it makes decsions based on the current context instead
of the the current thread.
It is created by call AccessController.getContext method.
@author Mark Benvenuto
@since JDK 1.2
*/
public final class AccessControlContext
{
private ProtectionDomain protectionDomain[];
private DomainCombiner combiner;
/**
Construct a new AccessControlContext with the specified
ProtectionDomains. <code>context</code> must not be
null and duplicates will be removed.
@param context The ProtectionDomains to use
*/
public AccessControlContext(ProtectionDomain[]context)
{
int i, j, k, count = context.length, count2 = 0;
for (i = 0, j = 0; i < count; i++)
{
for (k = 0; k < i; k++)
if (context[k] == protectionDomain[i])
break;
if (k != i) //it means previous loop did not complete
continue;
count2++;
}
protectionDomain = new ProtectionDomain[count2];
for (i = 0, j = 0; i < count2; i++)
{
for (k = 0; k < i; k++)
if (context[k] == protectionDomain[i])
break;
if (k != i) //it means previous loop did not complete
continue;
protectionDomain[j++] = context[i];
}
}
/**
Construct a new AccessControlContext with the specified
ProtectionDomains and DomainCombiner
@param context The ProtectionDomains to use
@since JDK 1.3
*/
public AccessControlContext(AccessControlContext acc,
DomainCombiner combiner)
{
this(acc.protectionDomain);
this.combiner = combiner;
}
/**
Returns the Domain Combiner associated with the AccessControlContext
@returns the DomainCombiner
*/
public DomainCombiner getDomainCombiner()
{
return combiner;
}
/**
Determines whether or not the specific permission is granted
depending on the context it is within.
@param perm a permission to check
@throws AccessControlException if the permssion is not permitted
*/
public void checkPermission(Permission perm) throws AccessControlException
{
for (int i = 0; i < protectionDomain.length; i++)
if (protectionDomain[i].implies(perm) == true)
return;
throw new AccessControlException("Permission not granted");
}
/**
Checks if two AccessControlContexts are equal.
It first checks if obj is an AccessControlContext class, and
then checks if each ProtectionDomain matches.
@param obj The object to compare this class to
@return true if equal, false otherwise
*/
public boolean equals(Object obj)
{
if (obj instanceof AccessControlContext)
{
AccessControlContext acc = (AccessControlContext) obj;
if (acc.protectionDomain.length != protectionDomain.length)
return false;
for (int i = 0; i < protectionDomain.length; i++)
if (acc.protectionDomain[i] != protectionDomain[i])
return false;
return true;
}
return false;
}
/**
Computes a hash code of this class
@return a hash code representing this class
*/
public int hashCode()
{
int h = 0;
for (int i = 0; i < protectionDomain.length; i++)
h ^= protectionDomain[i].hashCode();
return h;
}
}
/* AccessControlException.java -- Permission is denied
Copyright (C) 1998 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
package java.security;
/**
* This exception is thrown when the <code>AccessController</code> denies
* an attempt to perform an operation.
*
* @version 0.0
*
* @author Aaron M. Renn (arenn@urbanophile.com)
*/
public class AccessControlException extends SecurityException
{
/**
* The <code>Permission</code> associated with this exception
*/
private Permission perm;
/**
* This method initializes a new instance of <code>AccessControlException</code>
* with a descriptive error message. There will be no <code>Permission</code>
* object associated with this exception.
*
* @param msg The descriptive error message
*/
public AccessControlException(String msg)
{
super(msg);
}
/**
* This method initializes a new instance of <code>AccessControlException</code>
* with a descriptive error message and an instance of <code>Permission</code>
* that is the permission that caused the exception to be thrown.
*
* @param msg The descriptive error message
* @param perm The <code>Permission</code> object that caused this exception.
*/
public AccessControlException(String msg, Permission perm)
{
super(msg);
this.perm = perm;
}
/**
* This method returns the <code>Permission</code> object that caused
* this exception to be thrown.
*
* @return The requested <code>Permission</code> object, or <code>null</code> if none is available.
*/
public Permission getPermission()
{
return (perm);
}
}
/* AccessController.java --- Access control context and permission checker
Copyright (C) 2001 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
package java.security;
/**
* Access control context and permission checker.
* Can check permissions in the access control context of the current thread
* through the <code>checkPermission()</code> method.
* Manipulates the access control context for code that needs to be executed
* the protection domain of the calling class (by explicitly ignoring the
* context of the calling code) in the <code>doPriviliged()</code> methods.
* And provides a <code>getContext()</code> method which gives the access
* control context of the current thread that can be used for checking
* permissions at a later time and/or in another thread.
* <p>
* XXX - Mostly a stub implementation at the moment. Needs native support
* from the VM to function correctly. XXX - Do not forget to think about
* how to handle <code>java.lang.reflect.Method.invoke()</code> on the
* <code>doPrivileged()</code> methods.
*
* @author Mark Wielaard (mark@klomp.org)
* @since 1.2
*/
public final class AccessController
{
/**
* This class only has static methods so there is no public contructor.
*/
private AccessController()
{
}
/**
* Checks wether the access control context of the current thread allows
* the given Permission. Throws an <code>AccessControlException</code>
* when the permission is not allowed in the current context. Otherwise
* returns silently without throwing an exception.
*
* @param perm the permission to be checked.
* @exception AccessControlException thrown if the current context does not
* allow the given permission.
*/
public static void checkPermission(Permission perm)
{
getContext().checkPermission(perm);
}
/**
* Calls the <code>run()</code> method of the given action with as
* (initial) access control context only the protection domain of the
* calling class. Calls to <code>checkPermission()</code> in the
* <code>run()</code> method ignore all earlier protection domains of
* classes in the call chain. Note that the protection domains of classes
* called by the code in the <code>run()</code> method are not ignored.
*
* @param action the <code>PrivilegedAction</code> whose <code>run()</code>
* should be be called.
* @returns the result of the <code>action.run()</code> method.
*/
public static Object doPrivileged(PrivilegedAction action)
{
return action.run();
}
/**
* Calls the <code>run()</code> method of the given action with as
* (initial) access control context the given context combined with the
* protection domain of the calling class. Calls to
* <code>checkPermission()</code> in the <code>run()</code> method ignore
* all earlier protection domains of classes in the call chain, but add
* checks for the protection domains given in the supplied context.
*
* @param action the <code>PrivilegedAction</code> whose <code>run()</code>
* should be be called.
* @param context the <code>AccessControlContext</code> whose protection
* domains should be added to the protection domain of the calling class.
* @returns the result of the <code>action.run()</code> method.
*/
public static Object doPrivileged(PrivilegedAction action,
AccessControlContext context)
{
return action.run();
}
/**
* Calls the <code>run()</code> method of the given action with as
* (initial) access control context only the protection domain of the
* calling class. Calls to <code>checkPermission()</code> in the
* <code>run()</code> method ignore all earlier protection domains of
* classes in the call chain. Note that the protection domains of classes
* called by the code in the <code>run()</code> method are not ignored.
* If the <code>run()</code> method throws an exception then this method
* will wrap that exception in an <code>PrivilegedActionException</code>.
*
* @param action the <code>PrivilegedExceptionAction</code> whose
* <code>run()</code> should be be called.
* @returns the result of the <code>action.run()</code> method.
* @exception PriviligedActionException wrapped around any exception that
* is thrown in the <code>run()</code> method.
*/
public static Object doPrivileged(PrivilegedExceptionAction action)
throws PrivilegedActionException
{
try
{
return action.run();
}
catch (Exception e)
{
throw new PrivilegedActionException(e);
}
}
/**
* Calls the <code>run()</code> method of the given action with as
* (initial) access control context the given context combined with the
* protection domain of the calling class. Calls to
* <code>checkPermission()</code> in the <code>run()</code> method ignore
* all earlier protection domains of classes in the call chain, but add
* checks for the protection domains given in the supplied context.
* If the <code>run()</code> method throws an exception then this method
* will wrap that exception in an <code>PrivilegedActionException</code>.
*
* @param action the <code>PrivilegedExceptionAction</code> whose
* <code>run()</code> should be be called.
* @param context the <code>AccessControlContext</code> whose protection
* domains should be added to the protection domain of the calling class.
* @returns the result of the <code>action.run()</code> method.
* @exception PriviligedActionException wrapped around any exception that
* is thrown in the <code>run()</code> method.
*/
public static Object doPrivileged(PrivilegedExceptionAction action,
AccessControlContext context)
throws PrivilegedActionException
{
try
{
return action.run();
}
catch (Exception e)
{
throw new PrivilegedActionException(e);
}
}
/**
* Returns the complete access control context of the current thread.
* <p>
* XXX - Should this include all the protection domains in the call chain
* or only the domains till the last <code>doPrivileged()</code> call?
* <p>
* XXX - needs native support. Currently returns an empty context.
*/
public static AccessControlContext getContext()
{
// For now just return an new empty context
return new AccessControlContext(new ProtectionDomain[0]);
}
}
/* AlgorithmParameterGenerator.java --- Algorithm Parameter Generator
Copyright (C) 1999 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
package java.security;
import java.security.spec.AlgorithmParameterSpec;
/**
AlgorithmParameterGenerator is used to generate
algorithm parameters for specified algorithms.
This class is used to generate the algorithm parameters
for a specific algorithm.
@since JDK 1.2
@author Mark Benvenuto
*/
public class AlgorithmParameterGenerator
{
private AlgorithmParameterGeneratorSpi paramGenSpi;
private Provider provider;
private String algorithm;
/**
Creates an instance of AlgorithmParameters
@param paramSpi A parameters engine to use
@param provider A provider to use
@param algorithm The algorithm
*/
protected AlgorithmParameterGenerator(AlgorithmParameterGeneratorSpi
paramGenSpi, Provider provider,
String algorithm)
{
this.paramGenSpi = paramGenSpi;
this.provider = provider;
this.algorithm = algorithm;
}
/**
Returns the name of the algorithm used
@return A string with the name of the algorithm
*/
public final String getAlgorithm()
{
return algorithm;
}
/**
Gets an instance of the AlgorithmParameterGenerator class
which generates algorithm parameters for the specified algorithm.
If the algorithm is not found then, it throws NoSuchAlgorithmException.
@param algorithm the name of algorithm to choose
@return a AlgorithmParameterGenerator repesenting the desired algorithm
@throws NoSuchAlgorithmException if the algorithm is not implemented by providers
*/
public static AlgorithmParameterGenerator getInstance(String algorithm)
throws NoSuchAlgorithmException
{
Provider[] p = Security.getProviders();
for (int i = 0; i < p.length; i++)
{
String classname =
p[i].getProperty("AlgorithmParameterGenerator." + algorithm);
if (classname != null)
return getInstance(classname, algorithm, p[i]);
}
throw new NoSuchAlgorithmException(algorithm);
}
/**
Gets an instance of the AlgorithmParameterGenerator class
which generates algorithm parameters for the specified algorithm.
If the algorithm is not found then, it throws NoSuchAlgorithmException.
@param algorithm the name of algorithm to choose
@param provider the name of the provider to find the algorithm in
@return a AlgorithmParameterGenerator repesenting the desired algorithm
@throws NoSuchAlgorithmException if the algorithm is not implemented by the provider
@throws NoSuchProviderException if the provider is not found
*/
public static AlgorithmParameterGenerator getInstance(String algorithm,
String provider)
throws NoSuchAlgorithmException, NoSuchProviderException
{
Provider p = Security.getProvider(provider);
if (p == null)
throw new NoSuchProviderException();
return getInstance(p.
getProperty("AlgorithmParameterGenerator." +
algorithm), algorithm, p);
}
private static AlgorithmParameterGenerator getInstance(String classname,
String algorithm,
Provider provider)
throws NoSuchAlgorithmException
{
try
{
return new
AlgorithmParameterGenerator((AlgorithmParameterGeneratorSpi) Class.
forName(classname).newInstance(),
provider, algorithm);
}
catch (ClassNotFoundException cnfe)
{
throw new NoSuchAlgorithmException("Class not found");
}
catch (InstantiationException ie)
{
throw new NoSuchAlgorithmException("Class instantiation failed");
}
catch (IllegalAccessException iae)
{
throw new NoSuchAlgorithmException("Illegal Access");
}
}
/**
Gets the provider that the class is from.
@return the provider of this class
*/
public final Provider getProvider()
{
return provider;
}
/**
Initializes the Algorithm Parameter Generator with the specified
size. (Since no source of randomness is supplied, a default
one is supplied).
@param size size (in bits) to use
*/
public final void init(int size)
{
init(size, new SecureRandom());
}
/**
Initializes the Algorithm Parameter Generator with the specified
size and source of randomness.
@param size size (in bits) to use
@param random source of randomness to use
*/
public final void init(int size, SecureRandom random)
{
paramGenSpi.engineInit(size, random);
}
/**
Initializes the Algorithm Parameter Generator with the specified
AlgorithmParameterSpec. (Since no source of randomness is supplied,
a default one is supplied).
@param genParamSpec the AlgorithmParameterSpec class to use
*/
public final void init(AlgorithmParameterSpec genParamSpec) throws
InvalidAlgorithmParameterException
{
init(genParamSpec, new SecureRandom());
}
/**
Initializes the Algorithm Parameter Generator with the specified
AlgorithmParameterSpec and source of randomness.
@param genParamSpec the AlgorithmParameterSpec class to use
@param random source of randomness to use
*/
public final void init(AlgorithmParameterSpec genParamSpec,
SecureRandom random) throws
InvalidAlgorithmParameterException
{
paramGenSpi.engineInit(genParamSpec, random);
}
/**
Generate a new set of AlgorithmParameters.
@returns a new set of algorithm parameters
*/
public final AlgorithmParameters generateParameters()
{
return paramGenSpi.engineGenerateParameters();
}
}
/* Copyright (C) 2000 Free Software Foundation
/* AlgorithmParameterGeneratorSpi.java --- Algorithm Parameter Generator SPI
Copyright (C) 1999 Free Software Foundation, Inc.
This file is part of libgcj.
This file is part of GNU Classpath.
This software is copyrighted work licensed under the terms of the
Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
details. */
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
package java.security;
import java.security.spec.AlgorithmParameterSpec;
/**
* @author Warren Levy <warrenl@cygnus.com>
* @date February 7, 2000.
*/
AlgorithmParameterGeneratorSpi is the Service Provider
Interface for the AlgorithmParameterGenerator class.
This class is used to generate the algorithm parameters
for a specific algorithm.
/**
* Written using on-line Java Platform 1.2 API Specification.
* Status: Stubbed.
@since JDK 1.2
@author Mark Benvenuto
*/
// JDK1.2
public abstract class AlgorithmParameterGeneratorSpi
{
// FIXME: Stubbed.
/**
Constructs a new AlgorithmParameterGeneratorSpi
*/
public AlgorithmParameterGeneratorSpi()
{
}
/**
Initializes the parameter generator with the specified size
and SecureRandom
@param size the size( in number of bits)
@param random the SecureRandom class to use for randomness
*/
protected abstract void engineInit(int size, SecureRandom random);
/**
Initializes the parameter generator with the specified
AlgorithmParameterSpec and SecureRandom classes.
If genParamSpec is an invalid AlgorithmParameterSpec for this
AlgorithmParameterGeneratorSpi then it throws
InvalidAlgorithmParameterException
@param genParamSpec the AlgorithmParameterSpec class to use
@param random the SecureRandom class to use for randomness
@throws InvalidAlgorithmParameterException genParamSpec is invalid
*/
protected abstract void engineInit(AlgorithmParameterSpec genParamSpec,
SecureRandom random) throws
InvalidAlgorithmParameterException;
/**
Generate a new set of AlgorithmParameters.
@returns a new set of algorithm parameters
*/
protected abstract AlgorithmParameters engineGenerateParameters();
}
/* AlgorithmParameters.java --- Algorithm Parameters Implementation Class
Copyright (C) 1999 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
package java.security;
import java.security.spec.InvalidParameterSpecException;
import java.security.spec.AlgorithmParameterSpec;
import java.io.IOException;
/**
AlgorithmParameters is the Algorithm Parameters class which
provides an interface through which to modify parameters for
classes. This class is used to manage the algorithm parameters.
@since JDK 1.2
@author Mark Benvenuto
*/
public class AlgorithmParameters
{
private AlgorithmParametersSpi paramSpi;
private Provider provider;
private String algorithm;
/**
Creates an instance of AlgorithmParameters
@param paramSpi A parameters engine to use
@param provider A provider to use
@param algorithm The algorithm
*/
protected AlgorithmParameters(AlgorithmParametersSpi paramSpi,
Provider provider, String algorithm)
{
this.paramSpi = paramSpi;
this.provider = provider;
this.algorithm = algorithm;
}
/**
Returns the name of the algorithm used
@return A string with the name of the algorithm
*/
public final String getAlgorithm()
{
return algorithm;
}
/**
Gets an instance of the AlgorithmParameters class representing
the specified algorithm parameters. If the algorithm is not
found then, it throws NoSuchAlgorithmException.
The returned AlgorithmParameters must still be intialized with
init().
@param algorithm the name of algorithm to choose
@return a AlgorithmParameters repesenting the desired algorithm
@throws NoSuchAlgorithmException if the algorithm is not implemented by providers
*/
public static AlgorithmParameters getInstance(String algorithm) throws
NoSuchAlgorithmException
{
Provider[] p = Security.getProviders();
for (int i = 0; i < p.length; i++)
{
String classname =
p[i].getProperty("AlgorithmParameters." + algorithm);
if (classname != null)
return getInstance(classname, algorithm, p[i]);
}
throw new NoSuchAlgorithmException(algorithm);
}
/**
Gets an instance of the AlgorithmParameters class representing
the specified algorithm parameters from the specified provider.
If the algorithm is not found then, it throws
NoSuchAlgorithmException. If the provider is not found, then
it throws NoSuchProviderException.
The returned AlgorithmParameters must still be intialized with
init().
@param algorithm the name of algorithm to choose
@param provider the name of the provider to find the algorithm in
@return a AlgorithmParameters repesenting the desired algorithm
@throws NoSuchAlgorithmException if the algorithm is not implemented by the provider
@throws NoSuchProviderException if the provider is not found
*/
public static AlgorithmParameters getInstance(String algorithm,
String provider) throws
NoSuchAlgorithmException, NoSuchProviderException
{
Provider p = Security.getProvider(provider);
if (p == null)
throw new NoSuchProviderException();
return getInstance(p.getProperty("AlgorithmParameters." + algorithm),
algorithm, p);
}
private static AlgorithmParameters getInstance(String classname,
String algorithm,
Provider provider)
throws NoSuchAlgorithmException
{
try
{
return new AlgorithmParameters((AlgorithmParametersSpi) Class.
forName(classname).newInstance(),
provider, algorithm);
}
catch (ClassNotFoundException cnfe)
{
throw new NoSuchAlgorithmException("Class not found");
}
catch (InstantiationException ie)
{
throw new NoSuchAlgorithmException("Class instantiation failed");
}
catch (IllegalAccessException iae)
{
throw new NoSuchAlgorithmException("Illegal Access");
}
}
/**
Gets the provider that the class is from.
@return the provider of this class
*/
public final Provider getProvider()
{
return provider;
}
/**
Initializes the engine with the specified
AlgorithmParameterSpec class.
@param paramSpec A AlgorithmParameterSpec to initialize with
@throws InvalidParameterSpecException For an inapporiate ParameterSpec class
*/
public final void init(AlgorithmParameterSpec paramSpec) throws
InvalidParameterSpecException
{
paramSpi.engineInit(paramSpec);
}
/**
Initializes the engine with the specified
parameters stored in the byte array and decodes them
according to the ASN.1 specification. If the ASN.1
specification exists then it succeeds or else it throws
IOException.
@param params Parameters to initialize with
@throws IOException Decoding Error
*/
public final void init(byte[]params) throws IOException
{
paramSpi.engineInit(params);
}
/**
Initializes the engine with the specified
parameters stored in the byte array and decodes them
according to the specified decoding specification.
If format is null, then it is decoded using the ASN.1
specification if it exists or else it throws
IOException.
@param params Parameters to initialize with
@param format Name of decoding format to use
@throws IOException Decoding Error
*/
public final void init(byte[]params, String format) throws IOException
{
paramSpi.engineInit(params, format);
}
/**
Returns a specification of this AlgorithmParameters object.
paramSpec identifies the class to return the AlgortihmParameters
in.
@param paramSpec Class to return AlgorithmParameters in
@return the parameter specification
@throws InvalidParameterSpecException if the paramSpec is an invalid parameter class
*/
public final AlgorithmParameterSpec getParameterSpec(Class paramSpec) throws
InvalidParameterSpecException
{
return paramSpi.engineGetParameterSpec(paramSpec);
}
/**
Returns the parameters in the default encoding format.
The primary encoding format is ASN.1 format if it exists
for the specified type.
@return byte array representing the parameters
*/
public final byte[] getEncoded() throws IOException
{
return paramSpi.engineGetEncoded();
}
/**
Returns the parameters in the specified encoding format.
If <code>format</code> is <code>null</code> then the
primary encoding format is used, the ASN.1 format,
if it exists for the specified type.
@return byte array representing the parameters
*/
public final byte[] getEncoded(String format) throws IOException
{
return paramSpi.engineGetEncoded(format);
}
/**
Returns a string representation of the encoding format
@return a string containing the string representation
*/
public final String toString()
{
return paramSpi.engineToString();
}
}
/* AlgorithmParametersSpi.java --- Algorithm Parameters SPI
Copyright (C) 1999 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
package java.security;
import java.security.spec.InvalidParameterSpecException;
import java.security.spec.AlgorithmParameterSpec;
import java.io.IOException;
/**
AlgorithmParametersSpi is the Service Provider Interface
for the Algorithm Parameters class. This class is used
to manage the algorithm parameters.
@since JDK 1.2
@author Mark Benvenuto
*/
public abstract class AlgorithmParametersSpi
{
/**
Creates a new instance of AlgorithmParametersSpi
*/
public AlgorithmParametersSpi()
{
}
/**
Initializes the engine with the specified
AlgorithmParameterSpec class.
@param paramSpec A AlgorithmParameterSpec to initialize with
@throws InvalidParameterSpecException For an inapporiate ParameterSpec class
*/
protected abstract void engineInit(AlgorithmParameterSpec paramSpec) throws
InvalidParameterSpecException;
/**
Initializes the engine with the specified
parameters stored in the byte array and decodes them
according to the ASN.1 specification. If the ASN.1
specification exists then it succeeds or else it throws
IOException.
@param params Parameters to initialize with
@throws IOException Decoding Error
*/
protected abstract void engineInit(byte[]params) throws IOException;
/**
Initializes the engine with the specified
parameters stored in the byte array and decodes them
according to the specified decoding specification.
If format is null, then it is decoded using the ASN.1
specification if it exists or else it throws
IOException.
@param params Parameters to initialize with
@param format Name of decoding format to use
@throws IOException Decoding Error
*/
protected abstract void engineInit(byte[]params,
String format) throws IOException;
/**
Returns a specification of this AlgorithmParameters object.
paramSpec identifies the class to return the AlgortihmParameters
in.
@param paramSpec Class to return AlgorithmParameters in
@return the parameter specification
@throws InvalidParameterSpecException if the paramSpec is an invalid parameter class
*/
protected abstract AlgorithmParameterSpec engineGetParameterSpec(Class
paramSpec)
throws InvalidParameterSpecException;
/**
Returns the parameters in the default encoding format.
The primary encoding format is ASN.1 format if it exists
for the specified type.
@return byte array representing the parameters
*/
protected abstract byte[] engineGetEncoded() throws IOException;
/**
Returns the parameters in the specified encoding format.
If <code>format</code> is <code>null</code> then the
primary encoding format is used, the ASN.1 format,
if it exists for the specified type.
@return byte array representing the parameters
*/
protected abstract byte[] engineGetEncoded(String format) throws
IOException;
/**
Returns a string describing the parameters in the
AlgorithmParametersSpi class.
@return A string representing the format of the parameters.
*/
protected abstract String engineToString();
}
/* AllPermission.java -- Permission to do anything
Copyright (C) 1998 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
package java.security;
/**
* This class is a permission that implies all other permissions. Granting
* this permission effectively grants all others. Extreme caution should
* be exercised in granting this permission.
*
* @version 0.0
*
* @author Aaron M. Renn (arenn@urbanophile.com)
*/
public class AllPermission extends Permission
{
/**
* This method initializes a new instance of <code>AllPermission</code>. It
* performs no actions.
*/
public AllPermission()
{
super("all");
}
/**
* This method initializes a new instance of <code>AllPermission</code>. The
* arguments passed to this method are used to set internal field for the
* permission name. However, these are not used in
* determining the actual permissions granted. This class always will
* return <code>true</code> in its implies method.
*
* @param name The name of this permission.
* @param actions The action list for this permission - ignored in this class.
*/
public AllPermission(String name, String actions)
{
super(name);
}
/**
* This method always returns <code>true</code> to indicate that this
* permission always implies that any other permission is also granted.
*
* @param perm The <code>Permission</code> to test against - ignored in this class.
*
* @return Always returns <code>true</code>
*/
public boolean implies(Permission perm)
{
return (true);
}
/**
* This method tests this class for equality against another <code>Object</code>.
* This will return <code>true</code> if and only if the specified
* <code>Object</code> is an instance of <code>AllPermission</code>.
*
* @param obj The <code>Object</code> to test for equality to this object
*/
public boolean equals(Object obj)
{
if (obj instanceof AllPermission)
return (true);
return (false);
}
/**
* This method returns a hash code for this object.
*
* @return A hash value for this object.
*/
public int hashCode()
{
return (System.identityHashCode(this));
}
/**
* This method returns the list of actions associated with this object.
* This will always be the empty string ("") for this class.
*
* @return The action list.
*/
public String getActions()
{
return ("");
}
/**
* This method returns a new instance of <code>PermissionCollection</code>
* suitable for holding instance of <code>AllPermission</code>.
*
* @return A new <code>PermissionCollection</code>.
*/
public PermissionCollection newPermissionCollection()
{
return (null);
}
}
......@@ -7,7 +7,7 @@ GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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
......@@ -24,7 +24,6 @@ resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
package java.security;
import java.io.Serializable;
......@@ -32,34 +31,28 @@ import java.util.Hashtable;
import java.util.Enumeration;
/**
* This class implements a simple model for named permissions without an
* associated action list. That is, either the named permission is granted
* or it is not.
* <p>
* It also supports trailing wildcards to allow the
* easy granting of permissions in a hierarchical fashion. (For example,
* the name "org.gnu.*" might grant all permissions under the "org.gnu"
* permissions hierarchy). The only valid wildcard character is a '*'
* which matches anything. It must be the rightmost element in the
* permission name and must follow a '.' or else the Permission name must
* consist of only a '*'. Any other occurrence of a '*' is not valid.
* <p>
* This class ignores the action list. Subclasses can choose to implement
* actions on top of this class if desired.
*
* @version 0.1
*
* @author Aaron M. Renn (arenn@urbanophile.com)
*/
public abstract class BasicPermission extends Permission implements Serializable
* This class implements a simple model for named permissions without an
* associated action list. That is, either the named permission is granted
* or it is not.
* <p>
* It also supports trailing wildcards to allow the
* easy granting of permissions in a hierarchical fashion. (For example,
* the name "org.gnu.*" might grant all permissions under the "org.gnu"
* permissions hierarchy). The only valid wildcard character is a '*'
* which matches anything. It must be the rightmost element in the
* permission name and must follow a '.' or else the Permission name must
* consist of only a '*'. Any other occurrence of a '*' is not valid.
* <p>
* This class ignores the action list. Subclasses can choose to implement
* actions on top of this class if desired.
*
* @version 0.1
*
* @author Aaron M. Renn (arenn@urbanophile.com)
*/
public abstract class BasicPermission extends Permission implements
Serializable
{
/*************************************************************************/
/*
* Constructors
*/
/**
* This method initializes a new instance of <code>BasicPermission</code>
* with the specified name. If the name contains an illegal wildcard
......@@ -70,23 +63,21 @@ public abstract class BasicPermission extends Permission implements Serializable
* @exception IllegalArgumentException If the name contains an invalid wildcard character
* @exception NullPointerException If the name is null
*/
public
BasicPermission(String name) throws IllegalArgumentException, NullPointerException
public BasicPermission(String name)
throws IllegalArgumentException, NullPointerException
{
super(name);
if (name.indexOf("*") != -1)
{
if (!name.endsWith(".*") && !name.equals("*"))
throw new IllegalArgumentException("Bad wildcard: " + name);
throw new IllegalArgumentException("Bad wildcard: " + name);
if (name.indexOf("*") != name.lastIndexOf("*"))
throw new IllegalArgumentException("Bad wildcard: " + name);
throw new IllegalArgumentException("Bad wildcard: " + name);
}
}
/*************************************************************************/
/**
* This method initializes a new instance of <code>BasicPermission</code>
* with the specified name. If the name contains an illegal wildcard
......@@ -99,15 +90,13 @@ public abstract class BasicPermission extends Permission implements Serializable
* @exception IllegalArgumentException If the name contains an invalid wildcard character
* @exception NullPointerException If the name is null
*/
public
BasicPermission(String name, String actions) throws IllegalArgumentException, NullPointerException
public BasicPermission(String name, String actions)
throws IllegalArgumentException, NullPointerException
{
// ignore actions
this(name);
}
/*************************************************************************/
/**
* This method tests to see if the specified permission is implied by
* this permission. This will be true if the following conditions are met:
......@@ -124,8 +113,7 @@ public abstract class BasicPermission extends Permission implements Serializable
*
* @return <code>true</code> if the specified permission is implied by this one or <code>false</code> otherwise.
*/
public boolean
implies(Permission perm)
public boolean implies(Permission perm)
{
if (!(perm instanceof BasicPermission))
return false;
......@@ -144,8 +132,6 @@ public abstract class BasicPermission extends Permission implements Serializable
return false;
}
/*************************************************************************/
/**
* This method tests to see if this object is equal to the specified
* <code>Object</code>. This will be true if and only if the specified
......@@ -160,20 +146,17 @@ public abstract class BasicPermission extends Permission implements Serializable
*
* @return <code>true</code> if the specified <code>Object</code> is equal to this object or <code>false</code> otherwise.
*/
public boolean
equals(Object obj)
public boolean equals(Object obj)
{
if (!(obj instanceof BasicPermission))
return(false);
return (false);
if (!getName().equals(((BasicPermission)obj).getName()))
return(false);
if (!getName().equals(((BasicPermission) obj).getName()))
return (false);
return(true);
return (true);
}
/*************************************************************************/
/**
* This method returns a hash code for this permission object. The hash
* code returned is the value returned by calling the <code>hashCode</code>
......@@ -181,14 +164,11 @@ public abstract class BasicPermission extends Permission implements Serializable
*
* @return A hash value for this object
*/
public int
hashCode()
public int hashCode()
{
return(getName().hashCode());
return (getName().hashCode());
}
/*************************************************************************/
/**
* This method returns a list of the actions associated with this
* permission. This method always returns the empty string ("") since
......@@ -196,14 +176,11 @@ public abstract class BasicPermission extends Permission implements Serializable
*
* @return The action list.
*/
public String
getActions()
public String getActions()
{
return("");
return ("");
}
/*************************************************************************/
/**
* This method returns an instance of <code>PermissionCollection</code>
* suitable for storing <code>BasicPermission</code> objects. This returns
......@@ -214,58 +191,58 @@ public abstract class BasicPermission extends Permission implements Serializable
*
* @return A new empty <code>PermissionCollection</code> object.
*/
public PermissionCollection
newPermissionCollection()
public PermissionCollection newPermissionCollection()
{
return new PermissionCollection()
return new PermissionCollection()
{
Hashtable permissions = new Hashtable();
boolean allAllowed = false;
public void add(Permission permission)
{
if (isReadOnly())
throw new IllegalStateException("readonly");
BasicPermission bp = (BasicPermission) permission;
String name = bp.getName();
if (name.equals("*"))
allAllowed = true;
permissions.put(name, bp);
}
public boolean implies(Permission permission)
{
Hashtable permissions = new Hashtable();
boolean allAllowed = false;
public void add(Permission permission)
{
if (isReadOnly())
throw new IllegalStateException("readonly");
if (!(permission instanceof BasicPermission))
return false;
BasicPermission bp = (BasicPermission) permission;
String name = bp.getName();
if (name.equals("*"))
allAllowed = true;
permissions.put(name, bp);
}
public boolean implies(Permission permission)
{
if (!(permission instanceof BasicPermission))
return false;
if (allAllowed)
return true;
if (allAllowed)
return true;
BasicPermission toImply = (BasicPermission) permission;
String name = toImply.getName();
if (name.equals("*"))
return false;
BasicPermission toImply = (BasicPermission) permission;
String name = toImply.getName();
if (name.equals("*"))
return false;
int prefixLength = name.length();
if (name.endsWith("*"))
prefixLength -= 2;
int prefixLength = name.length();
if (name.endsWith("*"))
prefixLength -= 2;
while (true) {
while (true)
{
if (permissions.get(name) != null)
return true;
prefixLength = name.lastIndexOf('.', prefixLength);
if (prefixLength < 0)
return false;
name = name.substring(0, prefixLength + 1) + '*';
}
}
public Enumeration elements()
{
return permissions.elements();
}
};
}
public Enumeration elements()
{
return permissions.elements();
}
};
}
} // class BasicPermission
}
/* Certificate.java -- Interface for modeling digital certificates
Copyright (C) 1998 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
package java.security;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;
/**
* This interface models a digital certificate which verifies the
* authenticity of a party. This class simply allows certificate
* information to be queried, it does not guarantee that the certificate
* is valid.
* <p>
* This class is deprecated in favor of the new java.security.cert package.
* It exists for backward compatibility only.
*
* @deprecated
*
* @version 0.0
*
* @author Aaron M. Renn (arenn@urbanophile.com)
*/
public interface Certificate
{
/**
* This method returns the <code>Principal</code> that is guaranteeing
* this certificate.
*
* @return The <code>Principal</code> guaranteeing the certificate
*/
public abstract Principal getGuarantor();
/**
* This method returns the <code>Principal</code> being guaranteed by
* this certificate.
*
* @return The <code>Principal</code> guaranteed by this certificate.
*/
public abstract Principal getPrincipal();
/**
* This method returns the public key for the <code>Principal</code> that
* is being guaranteed.
*
* @return The <code>PublicKey</code> of the <code>Principal</code> being guaranteed
*/
public abstract PublicKey getPublicKey();
/**
* This method returns the encoding format of the certificate (e.g., "PGP",
* "X.509"). This format is used by the <code>encode</code. and
* <code>decode</code> methods.
*
* @return The encoding format being used
*/
public abstract String getFormat();
/**
* This method writes the certificate to an <code>OutputStream</code> in
* a format that can be understood by the <code>decode</code> method.
*
* @param out The <code>OutputStream</code> to write to.
*
* @exception KeyException If there is a problem with the internals of this certificate
* @exception IOException If an error occurs writing to the stream.
*/
public abstract void
encode(OutputStream out) throws KeyException, IOException;
/**
* This method reads an encoded certificate from an <code>InputStream</code>.
*
* @param in The <code>InputStream</code> to read from.
*
* @param KeyException If there is a problem with the certificate data
* @param IOException If an error occurs reading from the stream.
*/
public abstract void
decode(InputStream in) throws KeyException, IOException;
/**
* This method returns a <code>String</code> representation of the contents
* of this certificate.
*
* @param detail <code>true</code> to provided detailed information about this certificate, <code>false</code> otherwise
*/
public abstract String toString(boolean detail);
}
/* CodeSource.java -- Code location and certifcates
Copyright (C) 1998 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
package java.security;
import java.io.Serializable;
import java.net.URL;
import java.net.SocketPermission;
/**
* This class represents a location from which code is loaded (as
* represented by a URL) and the list of certificates that are used to
* check the signatures of signed code loaded from this source.
*
* @version 0.0
*
* @author Aaron M. Renn (arenn@urbanophile.com)
*/
public class CodeSource implements Serializable
{
private static final String linesep = System.getProperty("line.separator");
/**
* This is the URL that represents the code base from which code will
* be loaded.
*/
private URL location;
/**
* This is the list of certificates for this code base
*/
// What is the serialized form of this?
private java.security.cert.Certificate[] certs;
/**
* This method initializes a new instance of <code>CodeSource</code> that
* loads code from the specified URL location and which uses the
* specified certificates for verifying signatures.
*
* @param location The location from which code will be loaded
* @param certs The list of certificates used for verifying signatures on code from this source
*/
public CodeSource(URL location, java.security.cert.Certificate[] certs)
{
this.location = location;
this.certs = certs;
}
/**
* This method returns the URL specifying the location from which code
* will be loaded under this <code>CodeSource</code>.
*
* @return The code location for this <code>CodeSource</code>.
*/
public final URL getLocation()
{
return location;
}
/**
* This method returns the list of digital certificates that can be used
* to verify the signatures of code loaded under this <code>CodeSource</code>.
*
* @return The certifcate list for this <code>CodeSource</code>.
*/
public final java.security.cert.Certificate[] getCertificates()
{
return certs;
}
/**
* This method tests to see if a specified <code>CodeSource</code> is
* implied by this object. Effectively, to meet this test, the specified
* object must have all the certifcates this object has (but may have
* more) and must have a location that is a subset of this object's. In order
* for this object to imply the specified object, the following must be
* true:
* <p>
* <ol>
* <li>The specified <code>CodeSource</code> must not be <code>null</code>.
* <li>If the specified <code>CodeSource</code> has a certificate list,
* all of that object's certificates must be present in the certificate
* list of this object.
* <li>If this object does not have a <code>null</code> location, then
* the following addtional tests must be passed.
* <ol>
* <li>The specified <code>CodeSource</code> must not have a <code>null</code> location.
* <li>The specified <code>CodeSource</code>'s location must be equal to
* this object's location, or<br>
* <ul>
* <li>The specifiec <code>CodeSource</code>'s location protocol, port,
* and ref (aka, anchor) must equal this objects, and
* <li>The specified <code>CodeSource</code>'s location host must imply this
* object's location host, as determined by contructing
* <code>SocketPermission</code> objects from each with no action list and
* using that classes's <code>implies</code> method. And,
* <li>If this object's location file ends with a '/', then the specified
* object's location file must start with this object's location file.
* Otherwise, the specified object's location file must start with this
* object's location file with the '/' character appended to it.
* </ul>
* </ol>
* </ol>
*
* @param cs The <code>CodeSource</code> to test against this object
*
* @return <code>true</code> if this specified <code>CodeSource</code> is specified by this object, <code>false</code> otherwise.
*/
public boolean implies(CodeSource cs)
{
if (cs == null)
return false;
// First check the certificate list
java.security.cert.Certificate[] their_certs = cs.getCertificates();
java.security.cert.Certificate[] our_certs = getCertificates();
if (our_certs != null)
{
if (their_certs == null)
return false;
for (int i = 0; i < our_certs.length; i++)
{
int j;
for (j = 0; j < their_certs.length; j++)
if (our_certs[i].equals(their_certs[j]))
break;
if (j == their_certs.length)
return false;
}
}
// Next check the location
URL their_loc = getLocation();
URL our_loc = getLocation();
if (our_loc == null)
return true;
else if (their_loc == null)
return false;
if (!our_loc.getProtocol().equals(their_loc.getProtocol()))
return false;
if (our_loc.getPort() != -1)
if (our_loc.getPort() != their_loc.getPort())
return false;
if (our_loc.getRef() != null)
if (!our_loc.getRef().equals(their_loc.getRef()))
return false;
// See javadoc comments for what we are doing here.
if (our_loc.getHost() != null)
{
String their_host = their_loc.getHost();
if (their_host == null)
return false;
SocketPermission our_sockperm =
new SocketPermission(our_loc.getHost(), "accept");
SocketPermission their_sockperm =
new SocketPermission(their_host, "accept");
if (!our_sockperm.implies(their_sockperm))
return false;
}
String our_file = our_loc.getFile();
if (our_file != null)
{
if (!our_file.endsWith("/"))
our_file = our_file + "/";
String their_file = their_loc.getFile();
if (their_file == null)
return false;
if (!their_file.startsWith(our_file))
return false;
}
return true;
}
/**
* This method tests the specified <code>Object</code> for equality with
* this object. This will be true if and only if:
* <p>
* <ul>
* <li>The specified object is not <code>null</code>.
* <li>The specified object is an instance of <code>CodeSource</code>.
* <li>The specified object's location is the same as this object's.
* <li>The specified object's certificate list contains the exact same
* entries as the object's. Note that the order of the certificate lists
* is not significant.
* </ul>
*
* @param obj The <code>Object</code> to test against.
*
* @return <code>true</code> if the specified object is equal to this one, <code>false</code> otherwise.
*/
public boolean equals(Object obj)
{
if (obj == null)
return false;
if (!(obj instanceof CodeSource))
return false;
CodeSource cs = (CodeSource) obj;
// First check the certificate list
java.security.cert.Certificate[] their_certs = cs.getCertificates();
java.security.cert.Certificate[] our_certs = getCertificates();
if ((our_certs == null) && (their_certs != null))
return false;
else if ((our_certs != null) && (their_certs == null))
return false;
if (our_certs != null)
{
if (our_certs.length != their_certs.length)
return false;
for (int i = 0; i < our_certs.length; i++)
{
int j;
for (j = 0; j < their_certs.length; j++)
if (our_certs[i].equals(their_certs[j]))
break;
if (j == their_certs.length)
return false;
}
}
// Now the location
URL their_loc = cs.getLocation();
URL our_loc = getLocation();
if ((our_loc == null) && (their_loc != null))
return false;
if (!our_loc.equals(their_loc))
return false;
return true;
}
/**
* This method returns a hash value for this object.
*
* @return A hash value for this object.
*/
public int hashCode()
{
URL location = getLocation();
if (location == null)
return System.identityHashCode(this);
return location.hashCode();
}
/**
* This method returns a <code>String</code> that represents this object.
* This <code>String</code> will contain the object's hash code, location,
* and certificate list.
*
* @return A <code>String</code> for this object
*/
public String toString()
{
StringBuffer sb = new StringBuffer("");
sb.append(super.toString() + " (" + linesep);
sb.append("Location: " + getLocation() + linesep);
java.security.cert.Certificate[] certs = getCertificates();
if (certs == null)
sb.append("<none>" + linesep);
else
for (int i = 0; i < certs.length; i++)
sb.append(certs[i] + linesep);
sb.append(")" + linesep);
return sb.toString();
}
}
/* Copyright (C) 2000 Free Software Foundation
/* DigestException.java -- A generic message digest exception
Copyright (C) 1998 Free Software Foundation, Inc.
This file is part of libgcj.
This file is part of GNU Classpath.
This software is copyrighted work licensed under the terms of the
Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
details. */
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
package java.security;
GNU Classpath 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 for more details.
/**
* @author Warren Levy <warrenl@cygnus.com>
* @date February 1, 2000.
*/
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
package java.security;
/**
* Written using on-line Java Platform 1.2 API Specification.
* Status: Believed complete and correct.
* This exception indicates that a generic message digest exception has
* occurred.
*
* @version 0.0
*
* @author Aaron M. Renn (arenn@urbanophile.com)
*/
public class DigestException extends GeneralSecurityException
{
/**
* This method initializes a new <code>DigestException</code> with no
* descriptive message.
*/
public DigestException()
{
super();
}
/**
* This method initializes a new instance of <code>DigestException</code>
* with a descriptive error message.
*
* @param msg The descriptive message
*/
public DigestException(String msg)
{
super(msg);
......
/* DigestInputStream.java --- An Input stream tied to a message digest
Copyright (C) 1999 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
package java.security;
//import java.security.MessageDigest;
import java.io.InputStream;
import java.io.FilterInputStream;
import java.io.IOException;
/**
DigestInputStream is a class that ties an InputStream with a
MessageDigest. The Message Digest is used by the class to
update it self as bytes are read from the InputStream.
The updating to the digest depends on the on flag which is set
to true by default to tell the class to update the data
in the message digest.
@version 0.0
@author Mark Benvenuto <ivymccough@worldnet.att.net>
*/
public class DigestInputStream extends FilterInputStream
{
/**
The message digest for the DigestInputStream
*/
protected MessageDigest digest;
//Manages the on flag
private boolean state = true;
/**
Constructs a new DigestInputStream.
It associates a MessageDigest with the stream to
compute the stream as data is written.
@param stream An InputStream to associate this stream with
@param digest A MessageDigest to hash the stream with
*/
public DigestInputStream(InputStream stream, MessageDigest digest)
{
super(stream);
//this.in = stream;
this.digest = digest;
}
/**
Returns the MessageDigest associated with this DigestInputStream
@return The MessageDigest used to hash this stream
*/
public MessageDigest getMessageDigest()
{
return digest;
}
/**
Sets the current MessageDigest to current parameter
@param digest A MessageDigest to associate with this stream
*/
public void setMessageDigest(MessageDigest digest)
{
this.digest = digest;
}
/**
Reads a byte from the input stream and updates the digest.
This method reads the underlying input stream and if the
on flag is true then updates the message digest.
@return Returns a byte from the input stream, -1 is returned to indicate that
the end of stream was reached before this read call
@throws IOException if an IO error occurs in the underlying input stream,
this error is thrown
*/
public int read() throws IOException
{
int temp = in.read();
if (state == true && temp != -1)
digest.update((byte) temp);
return temp;
}
/**
Reads bytes from the input stream and updates the digest.
This method reads the underlying input stream and if the
on flag is true then updates the message digest.
@param b a byte array to store the data from the input stream
@param off an offset to start at in the array
@param len length of data to read
@return Returns count of bytes read, -1 is returned to indicate that
the end of stream was reached before this read call
@throws IOException if an IO error occurs in the underlying input stream,
this error is thrown
*/
public int read(byte[]b, int off, int len) throws IOException
{
int temp = in.read(b, off, len);
if (state == true && temp != -1)
digest.update(b, off, len);
return temp;
}
/**
Sets the flag specifing if this DigestInputStream updates the
digest in the write() methods. The default is on;
@param on True means it digests stream, false means it does not
*/
public void on(boolean on)
{
state = on;
}
/**
Converts the input stream and underlying message digest to a string.
@return A string representing the input stream and message digest.
*/
public String toString()
{
return "[Digest Input Stream] " + digest.toString();
}
}
......@@ -7,7 +7,7 @@ GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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
......@@ -24,7 +24,6 @@ resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
package java.security;
import java.io.OutputStream;
......@@ -42,12 +41,12 @@ import java.io.IOException;
@version 0.0
@author Mark Benvenuto <ivymccough@worldnet.att.net>
*/
*/
public class DigestOutputStream extends FilterOutputStream
{
/**
The message digest for the DigestOutputStream
*/
*/
protected MessageDigest digest;
//Manages the on flag
......@@ -60,10 +59,10 @@ public class DigestOutputStream extends FilterOutputStream
@param stream An OutputStream to associate this stream with
@param digest A MessageDigest to hash the stream with
*/
public DigestOutputStream (OutputStream stream, MessageDigest digest)
*/
public DigestOutputStream(OutputStream stream, MessageDigest digest)
{
super (stream);
super(stream);
this.digest = digest;
}
......@@ -71,18 +70,18 @@ public class DigestOutputStream extends FilterOutputStream
Returns the MessageDigest associated with this DigestOutputStream
@return The MessageDigest used to hash this stream
*/
public MessageDigest getMessageDigest ()
*/
public MessageDigest getMessageDigest()
{
return digest;
}
/**
Sets the current MessageDigest to current parameter
@param digest A MessageDigest to associate with this stream
*/
public void setMessageDigest (MessageDigest digest)
*/
public void setMessageDigest(MessageDigest digest)
{
this.digest = digest;
}
......@@ -93,16 +92,16 @@ public class DigestOutputStream extends FilterOutputStream
the underlying output stream.
@param b A byte to write to the output stream
@exception IOException if the underlying output stream
cannot write the byte, this is thrown.
*/
public void write (int b) throws IOException
*/
public void write(int b) throws IOException
{
if (state)
digest.update ((byte)b);
super.write (b);
digest.update((byte) b);
super.write(b);
}
/**
......@@ -115,13 +114,13 @@ public class DigestOutputStream extends FilterOutputStream
@exception IOException if the underlying output stream
cannot write the bytes, this is thrown.
*/
public void write (byte[] b, int off, int len) throws IOException
*/
public void write(byte[]b, int off, int len) throws IOException
{
if (state)
digest.update (b, off, len);
digest.update(b, off, len);
super.write (b, off, len);
super.write(b, off, len);
}
/**
......@@ -129,8 +128,8 @@ public class DigestOutputStream extends FilterOutputStream
digest in the write() methods. The default is on;
@param on True means it digests stream, false means it does not
*/
public void on (boolean on)
*/
public void on(boolean on)
{
state = on;
}
......@@ -139,7 +138,7 @@ public class DigestOutputStream extends FilterOutputStream
Converts the output stream and underlying message digest to a string.
@return A string representing the output stream and message digest.
*/
*/
public String toString()
{
return "[Digest Output Stream] " + digest.toString();
......
/* DomainCombiner.java - Combines ProtectionDomains
Copyright (C) 1999 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
package java.security;
/**
A public interface used to combine two ProtectionDomains in a new
ProtectionDomain and update the current Protection Domains
associated with the current AccessControllerContext.
It can add, subtract, or update ProtectionDomains or possibly
remove duplicates or any possible complex action but just not add
ones that do not already exist in either array.
@since JDK 1.3
@author Mark Benvenuto
*/
public interface DomainCombiner
{
/**
Combines the current ProtectionDomains of the Thread with new
ProtectionDomains.
@param currentDomains - the ProtectionDomains for the current thread.
@param assignedDomains - ProtectionsDomains to add
@returns a new array of all the ProtectionDomains
*/
public ProtectionDomain[] combine(ProtectionDomain[]currentDomains,
ProtectionDomain[]assignedDomains);
}
/* DummyKeyPairGenerator.java
Copyright (C) 1999 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
package java.security;
final class DummyKeyPairGenerator extends KeyPairGenerator
{
private KeyPairGeneratorSpi kpgSpi = null;
public DummyKeyPairGenerator(KeyPairGeneratorSpi kpgSpi, String algorithm)
{
super(algorithm);
this.kpgSpi = kpgSpi;
}
public void initialize(int keysize, SecureRandom random)
{
kpgSpi.initialize(keysize, random);
}
public KeyPair generateKeyPair()
{
return kpgSpi.generateKeyPair();
}
}
/* DummyMessageDigest.java
Copyright (C) 1999 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
package java.security;
import java.security.MessageDigest;
import java.security.MessageDigestSpi;
import java.security.DigestException;
final class DummyMessageDigest extends MessageDigest
{
private MessageDigestSpi mdSpi = null;
public DummyMessageDigest(MessageDigestSpi mdSpi, String algorithm)
{
super(algorithm);
this.mdSpi = mdSpi;
}
protected void engineUpdate(byte input)
{
mdSpi.engineUpdate(input);
}
protected void engineUpdate(byte[]input, int offset, int len)
{
mdSpi.engineUpdate(input, offset, len);
}
protected byte[] engineDigest()
{
return mdSpi.engineDigest();
}
protected void engineReset()
{
mdSpi.engineReset();
}
}
/* DummySignature.java
Copyright (C) 1999 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
package java.security;
final class DummySignature extends Signature
{
private SignatureSpi sigSpi = null;
public DummySignature(SignatureSpi sigSpi, String algorithm)
{
super(algorithm);
this.sigSpi = sigSpi;
}
protected void engineInitVerify(PublicKey publicKey)
throws InvalidKeyException
{
sigSpi.engineInitVerify(publicKey);
}
protected void engineInitSign(PrivateKey privateKey)
throws InvalidKeyException
{
sigSpi.engineInitSign(privateKey);
}
protected void engineUpdate(byte b) throws SignatureException
{
sigSpi.engineUpdate(b);
}
protected void engineUpdate(byte[]b, int off, int len)
throws SignatureException
{
sigSpi.engineUpdate(b, off, len);
}
protected byte[] engineSign() throws SignatureException
{
return sigSpi.engineSign();
}
protected boolean engineVerify(byte[]sigBytes) throws SignatureException
{
return sigSpi.engineVerify(sigBytes);
}
protected void engineSetParameter(String param, Object value)
throws InvalidParameterException
{
sigSpi.engineSetParameter(param, value);
}
protected Object engineGetParameter(String param)
throws InvalidParameterException
{
return sigSpi.engineGetParameter(param);
}
}
/* Copyright (C) 2000 Free Software Foundation
/* GeneralSecurityException.java -- Common superclass of security exceptions
Copyright (C) 1998 Free Software Foundation, Inc.
This file is part of libgcj.
This file is part of GNU Classpath.
This software is copyrighted work licensed under the terms of the
Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
details. */
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
package java.security;
GNU Classpath 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 for more details.
/**
* @author Warren Levy <warrenl@cygnus.com>
* @date February 1, 2000.
*/
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
package java.security;
/**
* Written using on-line Java Platform 1.2 API Specification.
* Status: Believed complete and correct.
* This class is the common superclass of all security exceptions. All
* exceptions in java.security extend this class with the exception (no
* pun intended) of <code>AccessControlException</code> and
* <code>CertificateException</code> which extend <code>SecurityException</code>
* and <code>ProviderException</code> which extens <code>RuntimeException</code>.
* and <code>InvalidParamterException</code> which extends
* <code>IllegalArgumentException</code>.
*
* @version 0.0
*
* @author Aaron M. Renn (arenn@urbanophile.com)
*/
// JDK1.2
public class GeneralSecurityException extends Exception
{
/**
* This method initializes a new instance of <code>GeneralSecurityException</code>
* with no descriptive error message.
*/
public GeneralSecurityException()
{
super();
}
/**
* This method initializes a new instance of <code>GeneralSecurityException</code>
* with a descriptive error message.
*
* @param msg The descriptive error message.
*/
public GeneralSecurityException(String msg)
{
super(msg);
......
......@@ -7,7 +7,7 @@ GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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
......@@ -24,31 +24,27 @@ resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
package java.security;
/**
* This interface specifies a mechanism for querying whether or not
* access is allowed to a guarded object.
*
* @version 0.0
*
* @author Aaron M. Renn (arenn@urbanophile.com)
*/
* This interface specifies a mechanism for querying whether or not
* access is allowed to a guarded object.
*
* @version 0.0
*
* @author Aaron M. Renn (arenn@urbanophile.com)
*/
public interface Guard
{
/**
* This method tests whether or not access is allowed to the specified
* guarded object. Access is allowed if this method returns silently. If
* access is denied, an exception is generated.
*
* @param obj The <code>Object</code> to test
*
* @exception SecurityException If access to the object is denied.
*/
public abstract void
checkGuard(Object obj) throws SecurityException;
} // interface Guard
/**
* This method tests whether or not access is allowed to the specified
* guarded object. Access is allowed if this method returns silently. If
* access is denied, an exception is generated.
*
* @param obj The <code>Object</code> to test
*
* @exception SecurityException If access to the object is denied.
*/
public abstract void checkGuard(Object obj) throws SecurityException;
}
/* GuardedObject.java -- An object protected by a Guard
Copyright (C) 1998 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
package java.security;
import java.io.Serializable;
/**
* This class is an object that is guarded by a <code>Guard</code> object.
* The object that is being guarded is retrieved by a call to the only
* method in this class - <code>getObject</code>. That method returns the
* guarded <code>Object</code> after first checking with the
* <code>Guard</code>. If the <code>Guard</code> disallows access, an
* exception will be thrown.
*
* @version 0.0
*
* @author Aaron M. Renn (arenn@urbanophile.com)
*/
public class GuardedObject implements Serializable
{
/**
* This is the Guard that is protecting the object.
*/
private Guard guard;
/**
* This is the object that is being guarded.
*/
private Object object;
/**
* This method initializes a new instance of <code>GuardedObject</code>
* that protects the specified <code>Object</code> using the specified
* <code>Guard</code>
*
* @param object The <code>Object</code> to guard
* @param guard The <code>Guard</code> that is protecting the object.
*/
public GuardedObject(Object object, Guard guard)
{
this.object = object;
this.guard = guard;
}
/**
* This method first call the <code>checkGuard</code> method on the
* <code>Guard</code> object protecting the guarded object. If the
* <code>Guard</code> disallows access, an exception is thrown, otherwise
* the <code>Object</code> is returned.
*
* @return The object being guarded
*
* @exception SecurityException If the <code>Guard</code> disallows access to the object.
*/
public Object getObject() throws SecurityException
{
guard.checkGuard(object);
return (object);
}
}
/* IdentityScope.java --- IdentityScope Class
Copyright (C) 1999 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
package java.security;
import java.util.Enumeration;
/**
IdentityScope represents a scope of an identity. IdentityScope
is also an Identity and can have a name and scope along with
the other qualitites identities posses.
An IdentityScope contains other Identity objects. All Identity
objects are manipulated in the scope the same way. The scope
is suppose to apply different scope to different type of
Identities.
No identity within the same scope can have the same public key.
@since JDK 1.1
@deprecated Use java.security.KeyStore, the java.security.cert
package, and java.security.Principal.
@author Mark Benvenuto
*/
public abstract class IdentityScope extends Identity
{
private static IdentityScope systemScope = null;
/**
Creates a new instance of IdentityScope from Serialized Data
*/
protected IdentityScope()
{
super();
}
/**
Creates a new instance of IdentityScope with the specified name
and no scope.
@param name the name to use
*/
public IdentityScope(String name)
{
super(name);
}
/**
Creates a new instance of IdentityScope with the specified name
and IdentityScope.
@param name the name to use
@param scope the scope to use
@throws KeyManagementException if the identity scope is already
present
*/
public IdentityScope(String name, IdentityScope scope)
throws KeyManagementException
{
super(name, scope);
}
/**
Gets the system's Scope.
*/
public static IdentityScope getSystemScope()
{
if (systemScope == null)
{
//Load it
//systemScope;
}
return systemScope;
}
/**
Sets the scope of the system.
This class checks the security manager with the call
checkSecurityAccess with "setSystemScope".
@param scope the new sustem scope
@throws SecurityException - if the security manager denies
access to "setSystemScope"
*/
protected static void setSystemScope(IdentityScope scope)
{
SecurityManager sm = System.getSecurityManager();
if (sm != null)
sm.checkSecurityAccess("setSystemScope");
systemScope = scope;
}
/**
Gets the number of entries within this IdentityScope.
@returns the number of entries
*/
public abstract int size();
/**
Gets the specified Identity within this scope
by specified name.
@param name name of Identity to get
@returns an identity representing the name or null if it
cannot be found
*/
public abstract Identity getIdentity(String name);
/**
Gets the specified Identity within this scope
by the specified Principal.
@param principal The Principal of the Identity to get
@returns an identity representing the principal or null if it
cannot be found
*/
public Identity getIdentity(Principal principal)
{
return getIdentity(principal.getName());
}
/**
Gets the specified Identity within this scope
by the specified public key.
@param key the PublicKey of the Identity to get
@returns an identity representing the public key or null if it
cannot be found
*/
public abstract Identity getIdentity(PublicKey key);
/**
Adds an identity to his scope.
@param identity the identity to add
@throws KeyManagementException if it is an invalid identity,
an identity with the same key exists, or another error
occurs.
*/
public abstract void addIdentity(Identity identity)
throws KeyManagementException;
/**
Removes an identity to his scope.
@param identity the identity to remove
@throws KeyManagementException if it is a missing identity,
or another error occurs.
*/
public abstract void removeIdentity(Identity identity)
throws KeyManagementException;
/**
Returns an Enumeration of identities.
@returns an enumeration of the identities.
*/
public abstract Enumeration identities();
/**
Returns a string representing this IdentityScope.
It includes the name, the scope name, and number of identities.
@returns a string representing this IdentityScope.
*/
public String toString()
{
return (super.getName() + " " + super.getScope().getName()
+ " " + size());
}
}
/* Copyright (C) 2000 Free Software Foundation
/* InvalidAlgorithmParameterException.java
Copyright (C) 2000 Free Software Foundation, Inc.
This file is part of libgcj.
This file is part of GNU Classpath.
This software is copyrighted work licensed under the terms of the
Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
details. */
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
package java.security;
......
/* Copyright (C) 2000 Free Software Foundation
This file is part of libgcj.
This file is part of GNU Classpath.
This software is copyrighted work licensed under the terms of the
Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
details. */
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
package java.security;
......
/* Copyright (C) 2000 Free Software Foundation
This file is part of libgcj.
This file is part of GNU Classpath.
This software is copyrighted work licensed under the terms of the
Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
details. */
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
package java.security;
......
/* Copyright (C) 2000 Free Software Foundation
/* Key.java -- A abstract representation of a digital key
Copyright (C) 1998, 2000 Free Software Foundation, Inc.
This file is part of libgcj.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
This software is copyrighted work licensed under the terms of the
Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
details. */
package java.security;
import java.io.Serializable;
/**
* @author Warren Levy <warrenl@cygnus.com>
* @date February 1, 2000.
* This interfaces models the base characteristics that all keys must
* have. These are: a key algorithm, an encoded form, and a format used
* to encode the key. Specific key types inherit from this interface.
* <p>
* Note that since this interface extends <code>Serializable</code>, all
* keys may be serialized.
*
* @version 0.0
*
* @author Aaron M. Renn (arenn@urbanophile.com)
*/
/* Written using on-line Java Platform 1.2 API Specification.
* Status: Believed complete and correct.
*/
public interface Key extends Serializable
{
/**
* The verion identifier used for serialization.
*/
public static final long serialVersionUID = 6603384152749567654L;
public String getAlgorithm();
public String getFormat();
public byte[] getEncoded();
/**
* This method returns the name of the algorithm for this key. This is a
* <code>String</code> such as "RSA".
*
* @return The name of the algorithm in use
*/
public abstract String getAlgorithm();
/**
* This method returns the name of the encoding format for this key. This
* is the name of the ASN.1 data format used for this key, such as
* "X.509" or "PKCS#8". This method returns <code>null</code> if this key
* does not have an encoding format.
*
* @return The name of the encoding format for this key, or <code>null</code> if there is no such format.
*/
public abstract String getFormat();
/**
* This method returns the encoded form of the key. If this key does not
* support encoding, this method returns <code>null</code>
*
* @return The encoded form of the key, or <code>null</code> if no encoded form is available.
*/
public abstract byte[] getEncoded();
}
/* Copyright (C) 2000 Free Software Foundation
/* KeyException.java -- Thrown when there is a problem with a key
Copyright (C) 1998 Free Software Foundation, Inc.
This file is part of libgcj.
This file is part of GNU Classpath.
This software is copyrighted work licensed under the terms of the
Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
details. */
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
package java.security;
GNU Classpath 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 for more details.
/**
* @author Warren Levy <warrenl@cygnus.com>
* @date February 1, 2000.
*/
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
package java.security;
/**
* Written using on-line Java Platform 1.2 API Specification.
* Status: Believed complete and correct.
* This exception is thrown when there is a problem with a key.
*
* @version 0.0
*
* @author Aaron M. Renn (arenn@urbanophile.com)
*/
public class KeyException extends GeneralSecurityException
{
/**
* This method initializes a new instance of <code>KeyException</code>
* with no descriptive message.
*/
public KeyException()
{
super();
}
/**
* This method initializes a new instance of <code>KeyException</code>
* with a descriptive message.
*
* @param msg The descriptive message.
*/
public KeyException(String msg)
{
super(msg);
......
/* KeyFactory.java --- Key Factory Class
Copyright (C) 1999 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
package java.security;
import java.security.spec.KeySpec;
import java.security.spec.InvalidKeySpecException;
/**
Key factories are used to convert keys (opaque cryptographic
keys of type Key) into key specifications (transparent
representations of the underlying key material).
Key factories are bi-directional. They allow a key class
to be converted into a key specification (key material) and
back again.
For example DSA public keys can be specified as
DSAPublicKeySpec or X509EncodedKeySpec. The key factory
translate these key specifications.
@since JDK 1.2
@author Mark Benvenuto
*/
public class KeyFactory
{
private KeyFactorySpi keyFacSpi;
private Provider provider;
private String algorithm;
/**
Constructs a new keyFactory with the specified parameters.
@param keyFacSpi Key Factory SPI to use
@param provider the provider of the Key Factory SPI
@param algorithm the name of the key algorithm for this key factory
*/
protected KeyFactory(KeyFactorySpi keyFacSpi, Provider provider,
String algorithm)
{
this.keyFacSpi = keyFacSpi;
this.provider = provider;
this.algorithm = algorithm;
}
/**
Gets an instance of the KeyFactory class representing
the specified key factory. If the algorithm is not
found then, it throws NoSuchAlgorithmException.
@param algorithm the name of algorithm to choose
@return a KeyFactory repesenting the desired algorithm
@throws NoSuchAlgorithmException if the algorithm is not implemented by providers
*/
public static KeyFactory getInstance(String algorithm)
throws NoSuchAlgorithmException
{
Provider[] p = Security.getProviders();
for (int i = 0; i < p.length; i++)
{
String classname = p[i].getProperty("KeyFactory." + algorithm);
if (classname != null)
return getInstance(classname, algorithm, p[i]);
}
throw new NoSuchAlgorithmException(algorithm);
}
/**
Gets an instance of the KeyFactory class representing
the specified key factory from the specified provider.
If the algorithm is not found then, it throws
NoSuchAlgorithmException. If the provider is not found, then
it throws NoSuchProviderException.
@param algorithm the name of algorithm to choose
@param provider the name of the provider to find the algorithm in
@return a KeyFactory repesenting the desired algorithm
@throws NoSuchAlgorithmException if the algorithm is not implemented by the provider
@throws NoSuchProviderException if the provider is not found
*/
public static KeyFactory getInstance(String algorithm, String provider)
throws NoSuchAlgorithmException, NoSuchProviderException
{
Provider p = Security.getProvider(provider);
if (p == null)
throw new NoSuchProviderException();
return getInstance(p.getProperty("KeyFactory." + algorithm),
algorithm, p);
}
private static KeyFactory getInstance(String classname,
String algorithm,
Provider provider)
throws NoSuchAlgorithmException
{
try
{
return new KeyFactory((KeyFactorySpi) Class.forName(classname).
newInstance(), provider, algorithm);
}
catch (ClassNotFoundException cnfe)
{
throw new NoSuchAlgorithmException("Class not found");
}
catch (InstantiationException ie)
{
throw new NoSuchAlgorithmException("Class instantiation failed");
}
catch (IllegalAccessException iae)
{
throw new NoSuchAlgorithmException("Illegal Access");
}
}
/**
Gets the provider that the class is from.
@return the provider of this class
*/
public final Provider getProvider()
{
return provider;
}
/**
Returns the name of the algorithm used
@return A string with the name of the algorithm
*/
public final String getAlgorithm()
{
return algorithm;
}
/**
Generates a public key from the provided key specification.
@param keySpec key specification
@return the public key
@throws InvalidKeySpecException invalid key specification for
this key factory to produce a public key
*/
public final PublicKey generatePublic(KeySpec keySpec) throws
InvalidKeySpecException
{
return keyFacSpi.engineGeneratePublic(keySpec);
}
/**
Generates a private key from the provided key specification.
@param keySpec key specification
@return the private key
@throws InvalidKeySpecException invalid key specification for
this key factory to produce a private key
*/
public final PrivateKey generatePrivate(KeySpec keySpec) throws
InvalidKeySpecException
{
return keyFacSpi.engineGeneratePrivate(keySpec);
}
/**
Returns a key specification for the given key. keySpec
identifies the specification class to return the key
material in.
@param key the key
@param keySpec the specification class to return the
key material in.
@return the key specification in an instance of the requested
specification class
@throws InvalidKeySpecException the requested key specification
is inappropriate for this key or the key is
unrecognized.
*/
public final KeySpec getKeySpec(Key key, Class keySpec)
throws InvalidKeySpecException
{
return keyFacSpi.engineGetKeySpec(key, keySpec);
}
/**
Translates the key from an unknown or untrusted provider
into a key for this key factory.
@param the key from an unknown or untrusted provider
@return the translated key
@throws InvalidKeySpecException if the key cannot be
processed by this key factory
*/
public final Key translateKey(Key key) throws InvalidKeyException
{
return keyFacSpi.engineTranslateKey(key);
}
}
/* KeyFactorySpi.java --- Key Factory Service Provider Interface
Copyright (C) 1999 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
package java.security;
import java.security.spec.KeySpec;
import java.security.spec.InvalidKeySpecException;
/**
KeyFactorySpi is the Service Provider Interface (SPI) for the
KeyFactory class. This is the interface for providers to
supply to implement a key factory for an algorithm.
Key factories are used to convert keys (opaque cryptographic
keys of type Key) into key specifications (transparent
representations of the underlying key material).
Key factories are bi-directional. They allow a key class
to be converted into a key specification (key material) and
back again.
For example DSA public keys can be specified as
DSAPublicKeySpec or X509EncodedKeySpec. The key factory
translate these key specifications.
@since JDK 1.2
@author Mark Benvenuto
*/
public abstract class KeyFactorySpi
{
/**
Constucts a new KeyFactorySpi.
*/
public KeyFactorySpi()
{
}
/**
Generates a public key from the provided key specification.
@param keySpec key specification
@return the public key
@throws InvalidKeySpecException invalid key specification for
this key factory to produce a public key
*/
protected abstract PublicKey engineGeneratePublic(KeySpec keySpec)
throws InvalidKeySpecException;
/**
Generates a private key from the provided key specification.
@param keySpec key specification
@return the private key
@throws InvalidKeySpecException invalid key specification for
this key factory to produce a private key
*/
protected abstract PrivateKey engineGeneratePrivate(KeySpec keySpec)
throws InvalidKeySpecException;
/**
Returns a key specification for the given key. keySpec
identifies the specification class to return the key
material in.
@param key the key
@param keySpec the specification class to return the
key material in.
@return the key specification in an instance of the requested
specification class
@throws InvalidKeySpecException the requested key specification
is inappropriate for this key or the key is
unrecognized.
*/
protected abstract KeySpec engineGetKeySpec(Key key, Class keySpec)
throws InvalidKeySpecException;
/**
Translates the key from an unknown or untrusted provider
into a key for this key factory.
@param the key from an unknown or untrusted provider
@return the translated key
@throws InvalidKeySpecException if the key cannot be
processed by this key factory
*/
protected abstract Key engineTranslateKey(Key key)
throws InvalidKeyException;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment