[kaffe] CVS kaffe (robilad): Resynced with GNU Classpath: cleanups in java.security
Kaffe CVS
cvs-commits at kaffe.org
Sat Oct 23 03:11:19 PDT 2004
PatchSet 5330
Date: 2004/10/23 10:07:16
Author: robilad
Branch: HEAD
Tag: (none)
Log:
Resynced with GNU Classpath: cleanups in java.security
2004-10-23 Dalibor Topic <robilad at kaffe.org>
* libraries/javalib/java/security/Identity.java:
Replaced by implementation from GNU Classpath.
* libraries/javalib/java/security/AlgorithmParameterGenerator.java,
libraries/javalib/java/security/AlgorithmParameters.java,
libraries/javalib/java/security/DigestInputStream.java,
libraries/javalib/java/security/KeyFactory.java,
libraries/javalib/java/security/KeyPairGenerator.java,
libraries/javalib/java/security/KeyStore.java,
libraries/javalib/java/security/MessageDigest.java,
libraries/javalib/java/security/MessageDigestSpi.java,
libraries/javalib/java/security/Policy.java,
libraries/javalib/java/security/SecureRandom.java,
libraries/javalib/java/security/Security.java,
libraries/javalib/java/security/Signature.java,
libraries/javalib/java/security/SignatureSpi.java,
libraries/javalib/java/security/cert/CertPathBuilder.java,
libraries/javalib/java/security/cert/CertPathValidator.java,
libraries/javalib/java/security/cert/CertStore.java,
libraries/javalib/java/security/cert/Certificate.java,
libraries/javalib/java/security/cert/CertificateFactory.java,
libraries/javalib/java/security/cert/PolicyQualifierInfo.java,
libraries/javalib/java/security/cert/TrustAnchor.java,
libraries/javalib/java/security/cert/X509CRL.java,
libraries/javalib/java/security/cert/X509CRLEntry.java,
libraries/javalib/java/security/cert/X509Certificate.java,
libraries/javalib/java/security/spec/RSAMultiPrimePrivateCrtKeySpec.java:
Resynced with GNU Classpath.
2004-10-20 Michael Koch <konqueror at gmx.de>
* java/security/AlgorithmParameterGenerator.java,
java/security/AlgorithmParameters.java,
java/security/DigestInputStream.java,
java/security/Identity.java,
java/security/KeyFactory.java,
java/security/KeyPairGenerator.java,
java/security/KeyStore.java,
java/security/MessageDigest.java,
java/security/MessageDigestSpi.java,
java/security/Policy.java,
java/security/SecureRandom.java,
java/security/Security.java,
java/security/Signature.java,
java/security/SignatureSpi.java,
java/security/cert/CertPathBuilder.java,
java/security/cert/CertPathValidator.java,
java/security/cert/CertStore.java,
java/security/cert/Certificate.java,
java/security/cert/CertificateFactory.java,
java/security/cert/PolicyQualifierInfo.java,
java/security/cert/TrustAnchor.java,
java/security/cert/X509CRL.java,
java/security/cert/X509CRLEntry.java,
java/security/cert/X509Certificate.java,
java/security/spec/RSAMultiPrimePrivateCrtKeySpec.java:
Import statements reorganized, some little formatting issues,
used java-style array declarations, added comments in empty catch
blocks.
Members:
ChangeLog:1.2882->1.2883
libraries/javalib/java/security/AlgorithmParameterGenerator.java:1.3->1.4
libraries/javalib/java/security/AlgorithmParameters.java:1.4->1.5
libraries/javalib/java/security/DigestInputStream.java:1.3->1.4
libraries/javalib/java/security/Identity.java:1.1->1.2
libraries/javalib/java/security/KeyFactory.java:1.4->1.5
libraries/javalib/java/security/KeyPairGenerator.java:1.4->1.5
libraries/javalib/java/security/KeyStore.java:1.4->1.5
libraries/javalib/java/security/MessageDigest.java:1.7->1.8
libraries/javalib/java/security/MessageDigestSpi.java:1.3->1.4
libraries/javalib/java/security/Policy.java:1.3->1.4
libraries/javalib/java/security/SecureRandom.java:1.6->1.7
libraries/javalib/java/security/Security.java:1.16->1.17
libraries/javalib/java/security/Signature.java:1.6->1.7
libraries/javalib/java/security/SignatureSpi.java:1.4->1.5
libraries/javalib/java/security/cert/CertPathBuilder.java:1.3->1.4
libraries/javalib/java/security/cert/CertPathValidator.java:1.3->1.4
libraries/javalib/java/security/cert/CertStore.java:1.4->1.5
libraries/javalib/java/security/cert/Certificate.java:1.3->1.4
libraries/javalib/java/security/cert/CertificateFactory.java:1.4->1.5
libraries/javalib/java/security/cert/PolicyQualifierInfo.java:1.3->1.4
libraries/javalib/java/security/cert/TrustAnchor.java:1.3->1.4
libraries/javalib/java/security/cert/X509CRL.java:1.3->1.4
libraries/javalib/java/security/cert/X509CRLEntry.java:1.3->1.4
libraries/javalib/java/security/cert/X509Certificate.java:1.4->1.5
libraries/javalib/java/security/spec/RSAMultiPrimePrivateCrtKeySpec.java:1.3->1.4
Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.2882 kaffe/ChangeLog:1.2883
--- kaffe/ChangeLog:1.2882 Fri Oct 22 23:41:05 2004
+++ kaffe/ChangeLog Sat Oct 23 10:07:16 2004
@@ -1,3 +1,65 @@
+2004-10-23 Dalibor Topic <robilad at kaffe.org>
+
+ * libraries/javalib/java/security/Identity.java:
+ Replaced by implementation from GNU Classpath.
+
+ * libraries/javalib/java/security/AlgorithmParameterGenerator.java,
+ libraries/javalib/java/security/AlgorithmParameters.java,
+ libraries/javalib/java/security/DigestInputStream.java,
+ libraries/javalib/java/security/KeyFactory.java,
+ libraries/javalib/java/security/KeyPairGenerator.java,
+ libraries/javalib/java/security/KeyStore.java,
+ libraries/javalib/java/security/MessageDigest.java,
+ libraries/javalib/java/security/MessageDigestSpi.java,
+ libraries/javalib/java/security/Policy.java,
+ libraries/javalib/java/security/SecureRandom.java,
+ libraries/javalib/java/security/Security.java,
+ libraries/javalib/java/security/Signature.java,
+ libraries/javalib/java/security/SignatureSpi.java,
+ libraries/javalib/java/security/cert/CertPathBuilder.java,
+ libraries/javalib/java/security/cert/CertPathValidator.java,
+ libraries/javalib/java/security/cert/CertStore.java,
+ libraries/javalib/java/security/cert/Certificate.java,
+ libraries/javalib/java/security/cert/CertificateFactory.java,
+ libraries/javalib/java/security/cert/PolicyQualifierInfo.java,
+ libraries/javalib/java/security/cert/TrustAnchor.java,
+ libraries/javalib/java/security/cert/X509CRL.java,
+ libraries/javalib/java/security/cert/X509CRLEntry.java,
+ libraries/javalib/java/security/cert/X509Certificate.java,
+ libraries/javalib/java/security/spec/RSAMultiPrimePrivateCrtKeySpec.java:
+ Resynced with GNU Classpath.
+
+ 2004-10-20 Michael Koch <konqueror at gmx.de>
+
+ * java/security/AlgorithmParameterGenerator.java,
+ java/security/AlgorithmParameters.java,
+ java/security/DigestInputStream.java,
+ java/security/Identity.java,
+ java/security/KeyFactory.java,
+ java/security/KeyPairGenerator.java,
+ java/security/KeyStore.java,
+ java/security/MessageDigest.java,
+ java/security/MessageDigestSpi.java,
+ java/security/Policy.java,
+ java/security/SecureRandom.java,
+ java/security/Security.java,
+ java/security/Signature.java,
+ java/security/SignatureSpi.java,
+ java/security/cert/CertPathBuilder.java,
+ java/security/cert/CertPathValidator.java,
+ java/security/cert/CertStore.java,
+ java/security/cert/Certificate.java,
+ java/security/cert/CertificateFactory.java,
+ java/security/cert/PolicyQualifierInfo.java,
+ java/security/cert/TrustAnchor.java,
+ java/security/cert/X509CRL.java,
+ java/security/cert/X509CRLEntry.java,
+ java/security/cert/X509Certificate.java,
+ java/security/spec/RSAMultiPrimePrivateCrtKeySpec.java:
+ Import statements reorganized, some little formatting issues,
+ used java-style array declarations, added comments in empty catch
+ blocks.
+
2004-10-22 Eric Anholt <eta at lclark.edu>
* config/alpha/threads.h,
Index: kaffe/libraries/javalib/java/security/AlgorithmParameterGenerator.java
diff -u kaffe/libraries/javalib/java/security/AlgorithmParameterGenerator.java:1.3 kaffe/libraries/javalib/java/security/AlgorithmParameterGenerator.java:1.4
--- kaffe/libraries/javalib/java/security/AlgorithmParameterGenerator.java:1.3 Fri Sep 24 19:06:44 2004
+++ kaffe/libraries/javalib/java/security/AlgorithmParameterGenerator.java Sat Oct 23 10:07:18 2004
@@ -1,5 +1,5 @@
/* AlgorithmParameterGenerator.java --- Algorithm Parameter Generator
- Copyright (C) 1999, 2003 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2003, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -35,12 +35,13 @@
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
-package java.security;
-import java.security.spec.AlgorithmParameterSpec;
+package java.security;
import gnu.java.security.Engine;
+import java.security.spec.AlgorithmParameterSpec;
+
/**
* <p>The <code>AlgorithmParameterGenerator</code> class is used to generate a
* set of parameters to be used with a certain algorithm. Parameter generators
@@ -140,7 +141,10 @@
{
return getInstance(algorithm, p[i]);
}
- catch (NoSuchAlgorithmException ignored) {}
+ catch (NoSuchAlgorithmException e)
+ {
+ // Ignore.
+ }
throw new NoSuchAlgorithmException(algorithm);
}
Index: kaffe/libraries/javalib/java/security/AlgorithmParameters.java
diff -u kaffe/libraries/javalib/java/security/AlgorithmParameters.java:1.4 kaffe/libraries/javalib/java/security/AlgorithmParameters.java:1.5
--- kaffe/libraries/javalib/java/security/AlgorithmParameters.java:1.4 Fri Sep 24 18:49:11 2004
+++ kaffe/libraries/javalib/java/security/AlgorithmParameters.java Sat Oct 23 10:07:18 2004
@@ -1,5 +1,5 @@
/* AlgorithmParameters.java --- Algorithm Parameters Implementation Class
- Copyright (C) 1999, 2003 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2003, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -35,14 +35,15 @@
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
-package java.security;
-import java.security.spec.InvalidParameterSpecException;
-import java.security.spec.AlgorithmParameterSpec;
-import java.io.IOException;
+package java.security;
import gnu.java.security.Engine;
+import java.io.IOException;
+import java.security.spec.AlgorithmParameterSpec;
+import java.security.spec.InvalidParameterSpecException;
+
/**
* <p>This class is used as an opaque representation of cryptographic
* parameters.</p>
@@ -136,12 +137,16 @@
throws NoSuchAlgorithmException
{
Provider[] p = Security.getProviders();
+
for (int i = 0; i < p.length; i++)
try
{
return getInstance(algorithm, p[i]);
}
- catch (NoSuchAlgorithmException ignored) {}
+ catch (NoSuchAlgorithmException e)
+ {
+ // Ignore this.
+ }
throw new NoSuchAlgorithmException(algorithm);
}
Index: kaffe/libraries/javalib/java/security/DigestInputStream.java
diff -u kaffe/libraries/javalib/java/security/DigestInputStream.java:1.3 kaffe/libraries/javalib/java/security/DigestInputStream.java:1.4
--- kaffe/libraries/javalib/java/security/DigestInputStream.java:1.3 Tue Sep 21 23:50:50 2004
+++ kaffe/libraries/javalib/java/security/DigestInputStream.java Sat Oct 23 10:07:18 2004
@@ -1,5 +1,5 @@
/* DigestInputStream.java --- An Input stream tied to a message digest
- Copyright (C) 1999, 2003 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2003, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -35,28 +35,29 @@
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
+
package java.security;
-//import java.security.MessageDigest;
-import java.io.InputStream;
+
import java.io.FilterInputStream;
import java.io.IOException;
+import java.io.InputStream;
/**
- 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 at worldnet.att.net>
+ * 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 at worldnet.att.net>
*/
public class DigestInputStream extends FilterInputStream
{
/**
- The message digest for the DigestInputStream
+ * The message digest for the DigestInputStream
*/
protected MessageDigest digest;
@@ -64,12 +65,12 @@
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
+ * 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)
{
@@ -79,9 +80,9 @@
}
/**
- Returns the MessageDigest associated with this DigestInputStream
-
- @return The MessageDigest used to hash this stream
+ * Returns the MessageDigest associated with this DigestInputStream
+ *
+ * @return The MessageDigest used to hash this stream
*/
public MessageDigest getMessageDigest()
{
@@ -89,9 +90,9 @@
}
/**
- Sets the current MessageDigest to current parameter
-
- @param digest A MessageDigest to associate with this stream
+ * Sets the current MessageDigest to current parameter
+ *
+ * @param digest A MessageDigest to associate with this stream
*/
public void setMessageDigest(MessageDigest digest)
{
@@ -99,15 +100,15 @@
}
/**
- 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
+ * 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
{
@@ -120,18 +121,18 @@
}
/**
- 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
+ * 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
{
@@ -144,10 +145,10 @@
}
/**
- 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
+ * 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)
{
@@ -155,9 +156,9 @@
}
/**
- Converts the input stream and underlying message digest to a string.
-
- @return A string representing the input stream and message digest.
+ * Converts the input stream and underlying message digest to a string.
+ *
+ * @return A string representing the input stream and message digest.
*/
public String toString()
{
Index: kaffe/libraries/javalib/java/security/Identity.java
diff -u kaffe/libraries/javalib/java/security/Identity.java:1.1 kaffe/libraries/javalib/java/security/Identity.java:1.2
--- kaffe/libraries/javalib/java/security/Identity.java:1.1 Wed Jul 3 23:57:50 2002
+++ kaffe/libraries/javalib/java/security/Identity.java Sat Oct 23 10:07:18 2004
@@ -1,140 +1,407 @@
-/*
- * Java core library component.
- *
- * Copyright (c) 2002
- * Dalibor Topic. All rights reserved.
- *
- * See the file "license.terms" for information on usage and redistribution
- * of this file.
- *
- * Author: Dalibor Topic <robilad at yahoo.com>
- */
+/* Identity.java --- Identity Class
+ Copyright (C) 1999, 2003, 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.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
package java.security;
import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Collection;
+import java.util.Vector;
+
+/**
+ * <p>This class represents identities: real-world objects such as people,
+ * companies or organizations whose identities can be authenticated using their
+ * public keys. Identities may also be more abstract (or concrete) constructs,
+ * such as daemon threads or smart cards.</p>
+ *
+ * <p>All Identity objects have a <i>name</i> and a <i>public key</i>. Names
+ * are immutable. <i>Identities</i> may also be <b>scoped</b>. That is, if an
+ * <i>Identity</i> is specified to have a particular <i>scope</i>, then the
+ * <i>name</i> and <i>public key</i> of the <i>Identity</i> are unique within
+ * that <i>scope</i>.</p>
+ *
+ * <p>An <i>Identity</i> also has a <i>set of certificates</i> (all certifying
+ * its own <i>public key</i>). The <i>Principal</i> names specified in these
+ * certificates need not be the same, only the key.</p>
+ *
+ * <p>An <i>Identity</i> can be subclassed, to include postal and email
+ * addresses, telephone numbers, images of faces and logos, and so on.</p>
+ *
+ * @author Mark Benvenuto
+ * @see IdentityScope
+ * @see Signer
+ * @see Principal
+ * @deprecated This class is no longer used. Its functionality has been replaced
+ * by <code>java.security.KeyStore</code>, the <code>java.security.cert</code>
+ * package, and <code>java.security.Principal</code>.
+ */
+public abstract class Identity implements Principal, Serializable
+{
+ private static final long serialVersionUID = 3609922007826600659L;
+
+ private String name;
+ private IdentityScope scope;
+ private PublicKey publicKey;
+ private String info;
+ private Vector certificates;
+
+ /** Constructor for serialization only. */
+ protected Identity()
+ {
+ }
+
+ /**
+ * Constructs an identity with the specified name and scope.
+ *
+ * @param name the identity name.
+ * @param scope the scope of the identity.
+ * @throws KeyManagementException if there is already an identity with the
+ * same name in the scope.
+ */
+ public Identity(String name, IdentityScope scope)
+ throws KeyManagementException
+ {
+ this.name = name;
+ this.scope = scope;
+ }
+
+ /**
+ * Constructs an identity with the specified name and no scope.
+ *
+ * @param name the identity name.
+ */
+ public Identity(String name)
+ {
+ this.name = name;
+ this.scope = null;
+ }
+
+ /**
+ * Returns this identity's name.
+ *
+ * @return the name of this identity.
+ */
+ public final String getName()
+ {
+ return name;
+ }
+
+ /**
+ * Returns this identity's scope.
+ *
+ * @return the scope of this identity.
+ */
+ public final IdentityScope getScope()
+ {
+ return scope;
+ }
+
+ /**
+ * Returns this identity's public key.
+ *
+ * @return the public key for this identity.
+ * @see #setPublicKey(java.security.PublicKey)
+ */
+ public PublicKey getPublicKey()
+ {
+ return publicKey;
+ }
+
+ /**
+ * <p>Sets this identity's public key. The old key and all of this identity's
+ * certificates are removed by this operation.</p>
+ *
+ * <p>First, if there is a security manager, its <code>checkSecurityAccess()
+ * </code> method is called with <code>"setIdentityPublicKey"</code> as its
+ * argument to see if it's ok to set the public key.</p>
+ *
+ * @param key the public key for this identity.
+ * @throws KeyManagementException if another identity in the identity's scope
+ * has the same public key, or if another exception occurs.
+ * @throws SecurityException if a security manager exists and its
+ * <code>checkSecurityAccess()</code> method doesn't allow setting the public
+ * key.
+ * @see #getPublicKey()
+ * @see SecurityManager#checkSecurityAccess(String)
+ */
+ public void setPublicKey(PublicKey key) throws KeyManagementException
+ {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null)
+ sm.checkSecurityAccess("setIdentityPublicKey");
+
+ this.publicKey = key;
+ }
+
+ /**
+ * <p>Specifies a general information string for this identity.</p>
+ *
+ * <p>First, if there is a security manager, its <code>checkSecurityAccess()
+ * </code> method is called with <code>"setIdentityInfo"</code> as its
+ * argument to see if it's ok to specify the information string.</p>
+ *
+ * @param info the information string.
+ * @throws SecurityException if a security manager exists and its
+ * <code>checkSecurityAccess()</code> method doesn't allow setting the
+ * information string.
+ * @see #getInfo()
+ * @see SecurityManager#checkSecurityAccess(String)
+ */
+ public void setInfo(String info)
+ {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null)
+ sm.checkSecurityAccess("setIdentityInfo");
+
+ this.info = info;
+ }
+
+ /**
+ * Returns general information previously specified for this identity.
+ *
+ * @return general information about this identity.
+ * @see #setInfo(String)
+ */
+ public String getInfo()
+ {
+ return info;
+ }
+
+ /**
+ * <p>Adds a certificate for this identity. If the identity has a public key,
+ * the public key in the certificate must be the same, and if the identity
+ * does not have a public key, the identity's public key is set to be that
+ * specified in the certificate.</p>
+ *
+ * <p>First, if there is a security manager, its <code>checkSecurityAccess()
+ * </code> method is called with <code>"addIdentityCertificate"</code> as its
+ * argument to see if it's ok to add a certificate.</p>
+ *
+ * @param certificate the certificate to be added.
+ * @throws KeyManagementException if the certificate is not valid, if the
+ * public key in the certificate being added conflicts with this identity's
+ * public key, or if another exception occurs.
+ * @throws SecurityException if a security manager exists and its
+ * <code>checkSecurityAccess()</code> method doesn't allow adding a
+ * certificate.
+ * @see SecurityManager#checkSecurityAccess(String)
+ */
+ public void addCertificate(Certificate certificate)
+ throws KeyManagementException
+ {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null)
+ sm.checkSecurityAccess("addIdentityCertificate");
+
+ // Check public key of this certificate against the first one in the vector
+ if (certificates.size() > 0)
+ {
+ if (((Certificate) certificates.firstElement()).getPublicKey() != publicKey)
+ throw new KeyManagementException("Public key does not match");
+ }
+ certificates.addElement(certificate);
+ }
+
+ /**
+ * <p>Removes a certificate from this identity.</p>
+ *
+ * <p>First, if there is a security manager, its <code>checkSecurityAccess()
+ * </code> method is called with <code>"removeIdentityCertificate"</code> as
+ * its argument to see if it's ok to remove a certificate.</p>
+ *
+ * @param certificate the certificate to be removed.
+ * @throws KeyManagementException if the certificate is missing, or if
+ * another exception occurs.
+ * @throws SecurityException if a security manager exists and its
+ * <code>checkSecurityAccess()</code> method doesn't allow removing a
+ * certificate.
+ * @see SecurityManager#checkSecurityAccess(String)
+ */
+ public void removeCertificate(Certificate certificate)
+ throws KeyManagementException
+ {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null)
+ sm.checkSecurityAccess("removeIdentityCertificate");
+
+ if (certificates.contains(certificate) == false)
+ throw new KeyManagementException("Certificate not found");
+
+ certificates.removeElement(certificate);
+ }
+
+ /**
+ * Returns a copy of all the certificates for this identity.
+ *
+ * @return a copy of all the certificates for this identity.
+ */
+ public Certificate[] certificates()
+ {
+ Certificate[] certs = new Certificate[certificates.size()];
+ int max = certificates.size();
+ for (int i = 0; i < max; i++)
+ certs[i] = (Certificate) certificates.elementAt(i);
+
+ return certs;
+ }
+
+ /**
+ * Tests for equality between the specified object and this identity. This
+ * first tests to see if the entities actually refer to the same object, in
+ * which case it returns <code>true</code>. Next, it checks to see if the
+ * entities have the same <i>name</i> and the same <i>scope</i>. If they do,
+ * the method returns <code>true</code>. Otherwise, it calls
+ * <code>identityEquals()</code>, which subclasses should override.
+ *
+ * @param identity the object to test for equality with this identity.
+ * @return <code>true</code> if the objects are considered equal, <code>false
+ * </code>otherwise.
+ * @see #identityEquals(Identity)
+ */
+ public final boolean equals(Object identity)
+ {
+ if (identity instanceof Identity)
+ {
+ if (identity == this)
+ return true;
+
+ if ((((Identity) identity).getName() == this.name) &&
+ (((Identity) identity).getScope() == this.scope))
+ return true;
+
+ return identityEquals((Identity) identity);
+ }
+ return false;
+ }
+
+ /**
+ * Tests for equality between the specified <code>identity</code> and this
+ * <i>identity</i>. This method should be overriden by subclasses to test for
+ * equality. The default behavior is to return <code>true</code> if the names
+ * and public keys are equal.
+ *
+ * @param identity the identity to test for equality with this identity.
+ * @return <code>true</code> if the identities are considered equal,
+ * <code>false</code> otherwise.
+ * @see #equals(Object)
+ */
+ protected boolean identityEquals(Identity identity)
+ {
+ return ((identity.getName() == this.name) &&
+ (identity.getPublicKey() == this.publicKey));
+ }
+
+ /**
+ * <p>Returns a short string describing this identity, telling its name and
+ * its scope (if any).</p>
+ *
+ * <p>First, if there is a security manager, its <code>checkSecurityAccess()
+ * </code> method is called with <code>"printIdentity"</code> as its argument
+ * to see if it's ok to return the string.</p>
+ *
+ * @return information about this identity, such as its name and the name of
+ * its scope (if any).
+ * @throws SecurityException if a security manager exists and its
+ * <code>checkSecurityAccess()</code> method doesn't allow returning a string
+ * describing this identity.
+ * @see SecurityManager#checkSecurityAccess(String)
+ */
+ public String toString()
+ {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null)
+ sm.checkSecurityAccess("printIdentity");
+
+ /* TODO: Insert proper format here */
+ return (name + ":@" + scope + " Public Key: " + publicKey);
+ }
+
+ /**
+ * <p>Returns a string representation of this identity, with optionally more
+ * details than that provided by the <code>toString()</code> method without
+ * any arguments.</p>
+ *
+ * <p>First, if there is a security manager, its <code>checkSecurityAccess()
+ * </code> method is called with <code>"printIdentity"</code> as its argument
+ * to see if it's ok to return the string.</p>
+ *
+ * @param detailed whether or not to provide detailed information.
+ * @return information about this identity. If detailed is <code>true</code>,
+ * then this method returns more information than that provided by the
+ * <code>toString()</code> method without any arguments.
+ * @throws SecurityException if a security manager exists and its
+ * <code>checkSecurityAccess()</code> method doesn't allow returning a string
+ * describing this identity.
+ * @see #toString()
+ * @see SecurityManager#checkSecurityAccess(String)
+ */
+ public String toString(boolean detailed)
+ {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null)
+ sm.checkSecurityAccess("printIdentity");
+
+ if (detailed)
+ {
+ /* TODO: Insert proper detailed format here */
+ return (name + ":@" + scope + " Public Key: " + publicKey);
+ }
+ else
+ {
+ /* TODO: Insert proper format here */
+ return (name + ":@" + scope + " Public Key: " + publicKey);
+ }
+ }
+
+ /**
+ * Returns a hashcode for this identity.
+ *
+ * @return a hashcode for this identity.
+ */
+ public int hashCode()
+ {
+ int ret = name.hashCode();
+ if (publicKey != null)
+ ret |= publicKey.hashCode();
+ if (scope != null)
+ ret |= scope.hashCode();
+ if (info != null)
+ ret |= info.hashCode();
+ if (certificates != null)
+ ret |= certificates.hashCode();
-public abstract class Identity implements Principal, Serializable {
- private String name;
- private IdentityScope scope;
- private Collection certs = new ArrayList();
- private String info;
- private PublicKey key;
-
- private static final Certificate [] CERTIFICATE_ARRAY_DUMMY = new Certificate [0];
-
- public Identity() {
- }
-
- public Identity(String name) {
- this.name = name;
- }
-
- public Identity(String name, IdentityScope scope) throws KeyManagementException {
- if (scope.getIdentity(name) != null) {
- throw new KeyManagementException("There is already an identity " + name + " in identity scope " + scope);
- }
-
- this.name = name;
- this.scope = scope;
- }
-
- public void addCertificate(Certificate certificate) throws KeyManagementException {
- if (getPublicKey() != null) {
- if (getPublicKey() != certificate.getPublicKey()) {
- throw new KeyManagementException("Public key in the certificate being added conflicts with identity's public key");
- }
- }
- else {
- setPublicKey(certificate.getPublicKey());
- }
-
- certs.add(certificate);
- }
-
- public Certificate[] certificates() {
- return (Certificate []) certs.toArray(CERTIFICATE_ARRAY_DUMMY);
- }
-
- public final boolean equals(Object identity) {
- if (this == identity) {
- return true;
- }
-
- if (identity instanceof Identity) {
- Identity other = (Identity) identity;
- if (other.getName() == getName()
- && other.getScope() == getScope()) {
- return true;
- }
- else {
- return identityEquals(other);
- }
- }
-
- return false;
- }
-
- public String getInfo() {
- return info;
- }
-
- public final String getName() {
- return name;
- }
-
- public PublicKey getPublicKey() {
- return key;
- }
-
- public final IdentityScope getScope() {
- return scope;
- }
-
- public int hashCode() {
- /* how the hash code is computed
- * is not specified in the spec.
- */
- return (name == null ? 0 : getName().hashCode())
- + (scope == null ? 0 : getScope().hashCode());
- }
-
- protected boolean identityEquals(Identity identity) {
- return getName() == identity.getName()
- && getPublicKey() == identity.getPublicKey();
- }
-
- public void removeCertificate(Certificate certificate) throws KeyManagementException {
- if (certs.remove(certificate) == false) {
- throw new KeyManagementException("Certificate " + certificate + " is missing, so it can not be removed");
- }
- }
-
- public void setInfo(String info) {
- this.info = info;
- }
-
- public void setPublicKey(PublicKey key) throws KeyManagementException {
- if (getScope() != null && getScope().getIdentity(key) != null) {
- throw new KeyManagementException("There is already an identity in identity scope " + scope + " with public key " + key);
- }
-
- this.key = key;
- this.certs = new ArrayList();
- }
-
- public String toString() {
- return "java.security.Identity[name=" + name + ",scope=" + scope + ']';
- }
-
- public String toString(boolean detailed) {
- if (detailed) {
- return "java.security.Identity[name=" + name + ",scope=" + scope + ",info=" + info + ",key=" + key + ",certificates=" + certs + ']';
- }
- else {
- return toString();
- }
- }
+ return ret;
+ }
}
Index: kaffe/libraries/javalib/java/security/KeyFactory.java
diff -u kaffe/libraries/javalib/java/security/KeyFactory.java:1.4 kaffe/libraries/javalib/java/security/KeyFactory.java:1.5
--- kaffe/libraries/javalib/java/security/KeyFactory.java:1.4 Fri Sep 24 18:39:19 2004
+++ kaffe/libraries/javalib/java/security/KeyFactory.java Sat Oct 23 10:07:18 2004
@@ -1,5 +1,5 @@
/* KeyFactory.java --- Key Factory Class
- Copyright (C) 1999, 2003 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2003, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -35,14 +35,14 @@
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
*** Patch too long, truncated ***
More information about the kaffe
mailing list