From ffde862e033a0825e1e9972a89c0f1f80b261a8e Mon Sep 17 00:00:00 2001
From: mark
Date: Mon, 14 Aug 2006 23:12:35 +0000
Subject: 2006-08-14 Mark Wielaard
Imported GNU Classpath 0.92
* HACKING: Add more importing hints. Update automake version
requirement.
* configure.ac (gconf-peer): New enable AC argument.
Add --disable-gconf-peer and --enable-default-preferences-peer
to classpath configure when gconf is disabled.
* scripts/makemake.tcl: Set gnu/java/util/prefs/gconf and
gnu/java/awt/dnd/peer/gtk to bc. Classify
gnu/java/security/Configuration.java as generated source file.
* gnu/java/lang/management/VMGarbageCollectorMXBeanImpl.java,
gnu/java/lang/management/VMMemoryPoolMXBeanImpl.java,
gnu/java/lang/management/VMClassLoadingMXBeanImpl.java,
gnu/java/lang/management/VMRuntimeMXBeanImpl.java,
gnu/java/lang/management/VMMemoryManagerMXBeanImpl.java,
gnu/java/lang/management/VMThreadMXBeanImpl.java,
gnu/java/lang/management/VMMemoryMXBeanImpl.java,
gnu/java/lang/management/VMCompilationMXBeanImpl.java: New VM stub
classes.
* java/lang/management/VMManagementFactory.java: Likewise.
* java/net/VMURLConnection.java: Likewise.
* gnu/java/nio/VMChannel.java: Likewise.
* java/lang/Thread.java (getState): Add stub implementation.
* java/lang/Class.java (isEnum): Likewise.
* java/lang/Class.h (isEnum): Likewise.
* gnu/awt/xlib/XToolkit.java (getClasspathTextLayoutPeer): Removed.
* javax/naming/spi/NamingManager.java: New override for StackWalker
functionality.
* configure, sources.am, Makefile.in, gcj/Makefile.in,
include/Makefile.in, testsuite/Makefile.in: Regenerated.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@116139 138bc75d-0d04-0410-961f-82ee72b054a4
---
.../javax/crypto/keyring/AuthenticatedEntry.java | 108 +++-----
.../gnu/javax/crypto/keyring/BaseKeyring.java | 78 ++----
.../gnu/javax/crypto/keyring/BinaryDataEntry.java | 39 +--
.../gnu/javax/crypto/keyring/CertPathEntry.java | 31 +--
.../gnu/javax/crypto/keyring/CertificateEntry.java | 42 +---
.../gnu/javax/crypto/keyring/CompressedEntry.java | 34 +--
.../gnu/javax/crypto/keyring/EncryptedEntry.java | 90 ++-----
.../classpath/gnu/javax/crypto/keyring/Entry.java | 81 +++---
.../gnu/javax/crypto/keyring/EnvelopeEntry.java | 275 ++++++++++++---------
.../javax/crypto/keyring/GnuPrivateKeyring.java | 185 +++++++-------
.../gnu/javax/crypto/keyring/GnuPublicKeyring.java | 69 +++---
.../gnu/javax/crypto/keyring/IKeyring.java | 102 ++++----
.../gnu/javax/crypto/keyring/IPrivateKeyring.java | 76 +++---
.../gnu/javax/crypto/keyring/IPublicKeyring.java | 35 +--
.../crypto/keyring/MalformedKeyringException.java | 7 +-
.../crypto/keyring/MaskableEnvelopeEntry.java | 57 ++---
.../javax/crypto/keyring/MeteredInputStream.java | 18 +-
.../crypto/keyring/PasswordAuthenticatedEntry.java | 203 +++++++--------
.../crypto/keyring/PasswordEncryptedEntry.java | 174 +++++++------
.../crypto/keyring/PasswordProtectedEntry.java | 15 +-
.../gnu/javax/crypto/keyring/PrimitiveEntry.java | 41 +--
.../gnu/javax/crypto/keyring/PrivateKeyEntry.java | 79 ++----
.../gnu/javax/crypto/keyring/Properties.java | 68 ++---
.../gnu/javax/crypto/keyring/PublicKeyEntry.java | 62 ++---
24 files changed, 821 insertions(+), 1148 deletions(-)
(limited to 'libjava/classpath/gnu/javax/crypto/keyring')
diff --git a/libjava/classpath/gnu/javax/crypto/keyring/AuthenticatedEntry.java b/libjava/classpath/gnu/javax/crypto/keyring/AuthenticatedEntry.java
index 22b42b3ea0b..cd2e5868db9 100644
--- a/libjava/classpath/gnu/javax/crypto/keyring/AuthenticatedEntry.java
+++ b/libjava/classpath/gnu/javax/crypto/keyring/AuthenticatedEntry.java
@@ -38,46 +38,32 @@ exception statement from your version. */
package gnu.javax.crypto.keyring;
+import gnu.java.security.Registry;
+import gnu.javax.crypto.mac.IMac;
+import gnu.javax.crypto.mac.MacFactory;
+import gnu.javax.crypto.mac.MacOutputStream;
+
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
-
import java.security.InvalidKeyException;
-
import java.util.Arrays;
-import java.util.Date;
-import java.util.Iterator;
import java.util.HashMap;
-import java.util.List;
-
-import gnu.java.security.Registry;
-import gnu.javax.crypto.mac.IMac;
-import gnu.javax.crypto.mac.MacFactory;
-import gnu.javax.crypto.mac.MacInputStream;
-import gnu.javax.crypto.mac.MacOutputStream;
+import java.util.Iterator;
-public final class AuthenticatedEntry extends MaskableEnvelopeEntry implements
- Registry
+public final class AuthenticatedEntry
+ extends MaskableEnvelopeEntry
+ implements Registry
{
-
- // Constants and fields.
- // ------------------------------------------------------------------------
-
public static final int TYPE = 2;
- // Constructor.
- // ------------------------------------------------------------------------
-
public AuthenticatedEntry(String mac, int macLen, Properties properties)
{
super(TYPE, properties);
-
if (macLen <= 0)
- {
- throw new IllegalArgumentException("invalid mac length");
- }
+ throw new IllegalArgumentException("invalid mac length");
this.properties.put("mac", mac);
this.properties.put("maclen", String.valueOf(macLen));
setMasked(false);
@@ -89,32 +75,22 @@ public final class AuthenticatedEntry extends MaskableEnvelopeEntry implements
setMasked(true);
}
- // Class methods.
- // ------------------------------------------------------------------------
-
public static AuthenticatedEntry decode(DataInputStream in)
throws IOException
{
AuthenticatedEntry entry = new AuthenticatedEntry();
entry.properties.decode(in);
- if (!entry.properties.containsKey("mac"))
- {
- throw new MalformedKeyringException("no mac specified");
- }
- if (!entry.properties.containsKey("maclen"))
- {
- throw new MalformedKeyringException("no mac length specified");
- }
+ if (! entry.properties.containsKey("mac"))
+ throw new MalformedKeyringException("no mac specified");
+ if (! entry.properties.containsKey("maclen"))
+ throw new MalformedKeyringException("no mac length specified");
return entry;
}
- // Instance methods.
- // ------------------------------------------------------------------------
-
/**
* Computes the mac over this envelope's data. This method must be
* called before this entry in encoded.
- *
+ *
* @param key The key to authenticate with.
* @throws IOException If encoding fails.
* @throws InvalidKeyException If the supplied key is bad.
@@ -122,11 +98,8 @@ public final class AuthenticatedEntry extends MaskableEnvelopeEntry implements
public void authenticate(byte[] key) throws IOException, InvalidKeyException
{
if (isMasked())
- {
- throw new IllegalStateException("entry is masked");
- }
+ throw new IllegalStateException("entry is masked");
IMac m = getMac(key);
-
ByteArrayOutputStream bout = new ByteArrayOutputStream(1024);
MacOutputStream macout = new MacOutputStream(bout, m);
DataOutputStream out2 = new DataOutputStream(macout);
@@ -140,36 +113,28 @@ public final class AuthenticatedEntry extends MaskableEnvelopeEntry implements
}
/**
- * Verifies this entry's payload. This method will unmask this entry,
- * thus it must be called before accessing its contents.
- *
+ * Verifies this entry's payload. This method will unmask this entry, thus it
+ * must be called before accessing its contents.
+ *
* @param key The key to use to authenticate.
* @throws InvalidKeyException If the given key is improper.
*/
public void verify(byte[] key) throws InvalidKeyException
{
- if (!isMasked() || payload == null)
- {
- return;
- }
+ if (! isMasked() || payload == null)
+ return;
IMac m = getMac(key);
-
m.update(payload, 0, payload.length - m.macSize());
byte[] macValue = new byte[m.macSize()];
System.arraycopy(payload, payload.length - macValue.length, macValue, 0,
macValue.length);
- if (!Arrays.equals(macValue, m.digest()))
- {
- throw new IllegalArgumentException("MAC verification failed");
- }
+ if (! Arrays.equals(macValue, m.digest()))
+ throw new IllegalArgumentException("MAC verification failed");
try
{
- DataInputStream in = new DataInputStream(
- new ByteArrayInputStream(
- payload,
- 0,
- payload.length
- - m.macSize()));
+ int len = payload.length - m.macSize();
+ ByteArrayInputStream bais = new ByteArrayInputStream(payload, 0, len);
+ DataInputStream in = new DataInputStream(bais);
decodeEnvelope(in);
}
catch (IOException ioe)
@@ -183,27 +148,17 @@ public final class AuthenticatedEntry extends MaskableEnvelopeEntry implements
protected void encodePayload() throws IOException
{
if (payload == null)
- {
- throw new IllegalStateException("not authenticated");
- }
+ throw new IllegalStateException("not authenticated");
}
- // Own methods.
- // ------------------------------------------------------------------------
-
private IMac getMac(byte[] key) throws InvalidKeyException
{
IMac mac = MacFactory.getInstance(properties.get("mac"));
if (mac == null)
- {
- throw new IllegalArgumentException("no such mac: "
- + properties.get("mac"));
- }
+ throw new IllegalArgumentException("no such mac: " + properties.get("mac"));
int maclen = 0;
- if (!properties.containsKey("maclen"))
- {
- throw new IllegalArgumentException("no MAC length");
- }
+ if (! properties.containsKey("maclen"))
+ throw new IllegalArgumentException("no MAC length");
try
{
maclen = Integer.parseInt(properties.get("maclen"));
@@ -212,10 +167,9 @@ public final class AuthenticatedEntry extends MaskableEnvelopeEntry implements
{
throw new IllegalArgumentException("bad MAC length");
}
-
HashMap macAttr = new HashMap();
macAttr.put(IMac.MAC_KEY_MATERIAL, key);
- macAttr.put(IMac.TRUNCATED_SIZE, new Integer(maclen));
+ macAttr.put(IMac.TRUNCATED_SIZE, Integer.valueOf(maclen));
mac.init(macAttr);
return mac;
}
diff --git a/libjava/classpath/gnu/javax/crypto/keyring/BaseKeyring.java b/libjava/classpath/gnu/javax/crypto/keyring/BaseKeyring.java
index 5fe7dbf4deb..369507d4c73 100644
--- a/libjava/classpath/gnu/javax/crypto/keyring/BaseKeyring.java
+++ b/libjava/classpath/gnu/javax/crypto/keyring/BaseKeyring.java
@@ -38,86 +38,58 @@ exception statement from your version. */
package gnu.javax.crypto.keyring;
-import java.io.InputStream;
+import gnu.java.security.Registry;
+
import java.io.IOException;
+import java.io.InputStream;
import java.io.OutputStream;
-
import java.util.Enumeration;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
-import gnu.java.security.Registry;
-
-public abstract class BaseKeyring implements IKeyring
+public abstract class BaseKeyring
+ implements IKeyring
{
-
- // Fields.
- // ------------------------------------------------------------------------
-
- /**
- * The top-level keyring data.
- */
+ /** The top-level keyring data. */
protected PasswordAuthenticatedEntry keyring;
-
protected CompressedEntry keyring2;
- // Constructors.
- // ------------------------------------------------------------------------
-
public BaseKeyring()
{
}
- // Instance methods.
- // ------------------------------------------------------------------------
-
public void load(Map attributes) throws IOException
{
InputStream in = (InputStream) attributes.get(KEYRING_DATA_IN);
if (in == null)
- {
- throw new IllegalArgumentException("no input stream");
- }
+ throw new IllegalArgumentException("no input stream");
char[] password = (char[]) attributes.get(KEYRING_PASSWORD);
if (password == null)
- {
- password = new char[0];
- }
+ password = new char[0];
if (in.read() != Registry.GKR_MAGIC[0]
|| in.read() != Registry.GKR_MAGIC[1]
|| in.read() != Registry.GKR_MAGIC[2]
|| in.read() != Registry.GKR_MAGIC[3])
- {
- throw new MalformedKeyringException("magic");
- }
+ throw new MalformedKeyringException("magic");
load(in, password);
-
List l = keyring.getEntries();
if (l.size() == 1 && (l.get(0) instanceof CompressedEntry))
- {
- keyring2 = (CompressedEntry) l.get(0);
- }
+ keyring2 = (CompressedEntry) l.get(0);
}
public void store(Map attributes) throws IOException
{
OutputStream out = (OutputStream) attributes.get(KEYRING_DATA_OUT);
if (out == null)
- {
- throw new IllegalArgumentException("no output stream");
- }
+ throw new IllegalArgumentException("no output stream");
char[] password = (char[]) attributes.get(KEYRING_PASSWORD);
if (password == null)
- {
- password = new char[0];
- }
+ password = new char[0];
if (keyring == null)
- {
- throw new IllegalStateException("empty keyring");
- }
+ throw new IllegalStateException("empty keyring");
out.write(Registry.GKR_MAGIC);
store(out, password);
@@ -131,45 +103,35 @@ public abstract class BaseKeyring implements IKeyring
public int size()
{
if (keyring == null)
- {
- throw new IllegalStateException ("keyring not loaded");
- }
+ throw new IllegalStateException("keyring not loaded");
return ((StringTokenizer) aliases()).countTokens();
}
public Enumeration aliases()
{
if (keyring == null)
- {
- throw new IllegalStateException ("keyring not loaded");
- }
+ throw new IllegalStateException("keyring not loaded");
return new StringTokenizer(keyring.getAliasList(), ";");
}
public boolean containsAlias(String alias)
{
if (keyring == null)
- {
- throw new IllegalStateException("keyring not loaded");
- }
+ throw new IllegalStateException("keyring not loaded");
return keyring.containsAlias(alias);
}
public List get(String alias)
{
if (keyring == null)
- {
- throw new IllegalStateException("keyring not loaded");
- }
+ throw new IllegalStateException("keyring not loaded");
return keyring.get(alias);
}
public void add(Entry entry)
{
if (keyring == null)
- {
- throw new IllegalStateException("keyring not loaded");
- }
+ throw new IllegalStateException("keyring not loaded");
if (keyring2 != null)
keyring2.add(entry);
else
@@ -179,9 +141,7 @@ public abstract class BaseKeyring implements IKeyring
public void remove(String alias)
{
if (keyring == null)
- {
- throw new IllegalStateException("keyring not loaded");
- }
+ throw new IllegalStateException("keyring not loaded");
keyring.remove(alias);
}
diff --git a/libjava/classpath/gnu/javax/crypto/keyring/BinaryDataEntry.java b/libjava/classpath/gnu/javax/crypto/keyring/BinaryDataEntry.java
index 2dcd5454fb6..e694487e141 100644
--- a/libjava/classpath/gnu/javax/crypto/keyring/BinaryDataEntry.java
+++ b/libjava/classpath/gnu/javax/crypto/keyring/BinaryDataEntry.java
@@ -40,29 +40,22 @@ package gnu.javax.crypto.keyring;
import java.io.DataInputStream;
import java.io.IOException;
-
import java.util.Date;
/**
- * A binary data entry is a primitive entry that simply contains some amount
- * of arbitrary binary data and an optional content type.
+ * A binary data entry is a primitive entry that simply contains some amount of
+ * arbitrary binary data and an optional content type.
*/
-public class BinaryDataEntry extends PrimitiveEntry
+public class BinaryDataEntry
+ extends PrimitiveEntry
{
-
- // Fields.
- // ------------------------------------------------------------------------
-
public static final int TYPE = 9;
- // Constructors.
- // ------------------------------------------------------------------------
-
/**
* Creates a new binary data entry.
- *
- * @param contentType The content type of this entry. This parameter can
- * be An immutable class representing a trusted certificate entry. . The top-level interface to a keyring: a file that is used to
- * store and protect public and private cryptographic keys. A keyring is modelled as a mapping of one alias to one or
- * more entries (optionally of different types). See also the sub-interfaces {@link IPublicKeyring} and
- * {@link IPrivateKeyring} for special types of keyrings --the difference
- * being in the type of entries they contain.
+ * A keyring is modelled as a mapping of one alias to one or
+ * more entries (optionally of different types).
+ *
+ * See also the sub-interfaces {@link IPublicKeyring} and
+ * {@link IPrivateKeyring} for special types of keyrings --the
+ * difference being in the type of entries they contain.
*/
public interface IKeyring
{
-
/**
- * Property name for the source of data to load the keyring from. The
- * value mapped must be a {@link java.io.InputStream}. Property name for the data sink to store the keyring to. The value
- * mapped must be a {@link java.io.OutputStream}. Property name for the keyring's top-level password, used to
- * authenticate and/or transform the store itself. The mapped value must be a
- * char array. Loads a keyring into memory. What happens to the current contents of this keyring? are the new ones
- * merged with the current ones or do they simply replace them?
+ * What happens to the current contents of this keyring? are the new ones
+ * merged with the current ones or do they simply replace them?
+ *
* @param attributes The attributes that designate the source where the store
- * is to be loaded from. What happens
+ * is to be loaded from. What happens
* @throws IllegalArgumentException If the attributes are inappropriate.
* @throws IOException If the keyring file cannot be read.
* @throws SecurityException If the given password is incorrect, or if the
- * top-level authentication or decryption fails.
+ * top-level authentication or decryption fails.
*/
void load(Map attributes) throws IOException;
/**
- * Stores the contents of this keyring to persistent storage as specified
- * by the designated Resets this keyring, clearing all sensitive data. This method always
- * suceeds. Returns the number of entries in this keyring. Returns an {@link Enumeration} of all aliases (instances of
- * {@link String}) in this keyring. Returns a {@link List} of entries (instances of {@link Entry}) for the
+ * Returns a {@link List} of entries (instances of {@link Entry}) for the
* given Adds a designated {@link Entry} to this keyring. What happens if there is already an entry with the same alias?
+ * What happens if there is already an entry with the same alias?
+ *
* @param entry The entry to put in this keyring.
*/
void add(Entry entry);
/**
- * Removes an entry with the designated What happens if there are more than one?
+ * What happens if there are more than one?
+ *
* @param alias The alias of the entry to remove.
*/
void remove(String alias);
diff --git a/libjava/classpath/gnu/javax/crypto/keyring/IPrivateKeyring.java b/libjava/classpath/gnu/javax/crypto/keyring/IPrivateKeyring.java
index 66bbd84f568..9e2ceab9b95 100644
--- a/libjava/classpath/gnu/javax/crypto/keyring/IPrivateKeyring.java
+++ b/libjava/classpath/gnu/javax/crypto/keyring/IPrivateKeyring.java
@@ -44,41 +44,41 @@ import java.security.UnrecoverableKeyException;
import java.security.cert.Certificate;
/**
- * An interface to private, or "personal", keyrings, which contain private
+ * An interface to private, or "personal", keyrings, which contain private
* credentials. The contract is that each such entry is known by a unique
- * alias. What about public keys? and certificate-path?
+ * What about public keys? and certificate-path?
*/
-public interface IPrivateKeyring extends IKeyring
+public interface IPrivateKeyring
+ extends IKeyring
{
-
/**
- * Tests if this keyring contains a private key entry with the given
- * null if no content type is needed.
+ *
+ * @param contentType The content type of this entry. This parameter can be
+ * null if no content type is needed.
* @param data The data.
* @param creationDate The creation date.
* @param properties This entry's properties.
@@ -72,14 +65,10 @@ public class BinaryDataEntry extends PrimitiveEntry
{
super(TYPE, creationDate, properties);
if (data == null)
- {
- throw new IllegalArgumentException("no data");
- }
+ throw new IllegalArgumentException("no data");
payload = (byte[]) data.clone();
if (contentType != null)
- {
- this.properties.put("content-type", contentType);
- }
+ this.properties.put("content-type", contentType);
}
private BinaryDataEntry()
@@ -87,9 +76,6 @@ public class BinaryDataEntry extends PrimitiveEntry
super(TYPE);
}
- // Class methods.
- // ------------------------------------------------------------------------
-
public static BinaryDataEntry decode(DataInputStream in) throws IOException
{
BinaryDataEntry entry = new BinaryDataEntry();
@@ -97,13 +83,10 @@ public class BinaryDataEntry extends PrimitiveEntry
return entry;
}
- // Instance methods.
- // ------------------------------------------------------------------------
-
/**
* Returns the content type of this entry, or null if this
* property is not set.
- *
+ *
* @return The content type.
*/
public String getContentType()
@@ -113,7 +96,7 @@ public class BinaryDataEntry extends PrimitiveEntry
/**
* Returns this object's data field.
- *
+ *
* @return The data.
*/
public byte[] getData()
diff --git a/libjava/classpath/gnu/javax/crypto/keyring/CertPathEntry.java b/libjava/classpath/gnu/javax/crypto/keyring/CertPathEntry.java
index ef62347ec9d..32b86084f31 100644
--- a/libjava/classpath/gnu/javax/crypto/keyring/CertPathEntry.java
+++ b/libjava/classpath/gnu/javax/crypto/keyring/CertPathEntry.java
@@ -40,40 +40,28 @@ package gnu.javax.crypto.keyring;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
-import java.io.DataOutputStream;
import java.io.IOException;
-
import java.security.cert.Certificate;
import java.security.cert.CertificateEncodingException;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
-
import java.util.Date;
/**
* A primitive entry that contains a path of X.509 certificates.
*/
-public final class CertPathEntry extends PrimitiveEntry
+public final class CertPathEntry
+ extends PrimitiveEntry
{
-
- // Constants and fields.
- // ------------------------------------------------------------------------
-
public static final int TYPE = 8;
-
private Certificate[] path;
- // Constructor.
- // ------------------------------------------------------------------------
-
public CertPathEntry(Certificate[] path, Date creationDate,
Properties properties)
{
super(TYPE, creationDate, properties);
if (path == null || path.length == 0)
- {
- throw new IllegalArgumentException("no certificate path");
- }
+ throw new IllegalArgumentException("no certificate path");
this.path = (Certificate[]) path.clone();
}
@@ -82,9 +70,6 @@ public final class CertPathEntry extends PrimitiveEntry
super(TYPE);
}
- // Class method.
- // ------------------------------------------------------------------------
-
public static CertPathEntry decode(DataInputStream in) throws IOException
{
CertPathEntry entry = new CertPathEntry();
@@ -95,8 +80,7 @@ public final class CertPathEntry extends PrimitiveEntry
try
{
CertificateFactory fact = CertificateFactory.getInstance("X.509");
- entry.path = (Certificate[]) fact.generateCertificates(in2).toArray(
- new Certificate[0]);
+ entry.path = (Certificate[]) fact.generateCertificates(in2).toArray(new Certificate[0]);
}
catch (CertificateException ce)
{
@@ -105,9 +89,6 @@ public final class CertPathEntry extends PrimitiveEntry
return entry;
}
- // Instance methods.
- // ------------------------------------------------------------------------
-
public Certificate[] getCertPath()
{
return path;
@@ -120,9 +101,7 @@ public final class CertPathEntry extends PrimitiveEntry
try
{
for (int i = 0; i < path.length; i++)
- {
- bout.write(path[i].getEncoded());
- }
+ bout.write(path[i].getEncoded());
}
catch (CertificateEncodingException cee)
{
diff --git a/libjava/classpath/gnu/javax/crypto/keyring/CertificateEntry.java b/libjava/classpath/gnu/javax/crypto/keyring/CertificateEntry.java
index 95a708ac53f..661758442cc 100644
--- a/libjava/classpath/gnu/javax/crypto/keyring/CertificateEntry.java
+++ b/libjava/classpath/gnu/javax/crypto/keyring/CertificateEntry.java
@@ -39,50 +39,38 @@ exception statement from your version. */
package gnu.javax.crypto.keyring;
import java.io.DataInputStream;
-import java.io.DataOutputStream;
import java.io.IOException;
import java.security.cert.Certificate;
import java.security.cert.CertificateEncodingException;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
-import java.security.cert.X509Certificate;
import java.util.Date;
/**
- * true if alias was present and was
+ * successfully trmoved. Returns false if
+ * alias was not present in the list of aliases in this
+ * envelope.
*/
- public void remove(String alias)
+ public boolean remove(String alias)
{
+ if (Configuration.DEBUG)
+ log.entering(this.getClass().getName(), "remove", alias);
+ boolean result = false;
for (Iterator it = entries.iterator(); it.hasNext();)
{
Entry e = (Entry) it.next();
if (e instanceof EnvelopeEntry)
{
- ((EnvelopeEntry) e).remove(alias);
+ EnvelopeEntry ee = (EnvelopeEntry) e;
+ result = ee.remove(alias) || result;
}
else if (e instanceof PrimitiveEntry)
{
- if (((PrimitiveEntry) e).getAlias().equals(alias))
+ PrimitiveEntry pe = (PrimitiveEntry) e;
+ if (pe.getAlias().equals(alias))
{
it.remove();
+ result = true;
}
}
}
- payload = null;
- makeAliasList();
+ if (result)
+ {
+ if (Configuration.DEBUG)
+ log.fine("State before: " + this);
+ payload = null;
+ makeAliasList();
+ if (Configuration.DEBUG)
+ log.fine("State after: " + this);
+ }
+ if (Configuration.DEBUG)
+ log.exiting(this.getClass().getName(), "remove", Boolean.valueOf(result));
+ return result;
+ }
+
+ public String toString()
+ {
+ return new StringBuilder("Envelope{")
+ .append(super.toString())
+ .append(", entries=").append(entries)
+ .append("}")
+ .toString();
}
// Protected methods.
@@ -308,22 +341,19 @@ public abstract class EnvelopeEntry extends Entry
ByteArrayOutputStream bout = new ByteArrayOutputStream(1024);
DataOutputStream out = new DataOutputStream(bout);
for (Iterator it = entries.iterator(); it.hasNext();)
- {
- ((Entry) it.next()).encode(out);
- }
+ ((Entry) it.next()).encode(out);
}
protected void setContainingEnvelope(EnvelopeEntry e)
{
if (containingEnvelope != null)
- {
- throw new IllegalArgumentException("envelopes may not be shared");
- }
+ throw new IllegalArgumentException("envelopes may not be shared");
containingEnvelope = e;
}
protected void decodeEnvelope(DataInputStream in) throws IOException
{
+ this.entries.clear();
while (true)
{
int type = in.read();
@@ -367,32 +397,43 @@ public abstract class EnvelopeEntry extends Entry
}
}
- // Own methods.
- // ------------------------------------------------------------------------
-
private void makeAliasList()
{
- if (entries.isEmpty())
- return;
- StringBuffer buf = new StringBuffer();
- for (Iterator it = entries.iterator(); it.hasNext();)
+ if (Configuration.DEBUG)
+ log.entering(this.getClass().getName(), "makeAliasList");
+ if (! entries.isEmpty())
{
- Entry entry = (Entry) it.next();
- if (entry instanceof EnvelopeEntry)
- {
- buf.append(((EnvelopeEntry) entry).getAliasList());
- }
- else if (entry instanceof PrimitiveEntry)
+ StringBuilder buf = new StringBuilder();
+ String aliasOrList;
+ for (Iterator it = entries.iterator(); it.hasNext();)
{
- buf.append(((PrimitiveEntry) entry).getAlias());
+ Entry entry = (Entry) it.next();
+ aliasOrList = null;
+ if (entry instanceof EnvelopeEntry)
+ aliasOrList = ((EnvelopeEntry) entry).getAliasList();
+ else if (entry instanceof PrimitiveEntry)
+ aliasOrList = ((PrimitiveEntry) entry).getAlias();
+ else if (Configuration.DEBUG)
+ log.fine("Entry with no Alias. Ignored: " + entry);
+ if (aliasOrList != null)
+ {
+ aliasOrList = aliasOrList.trim();
+ if (aliasOrList.trim().length() > 0)
+ {
+ buf.append(aliasOrList);
+ if (it.hasNext())
+ buf.append(';');
+ }
+ }
}
- if (it.hasNext())
- buf.append(';');
- }
- properties.put("alias-list", buf.toString());
- if (containingEnvelope != null)
- {
- containingEnvelope.makeAliasList();
+ String aliasList = buf.toString();
+ properties.put("alias-list", aliasList);
+ if (Configuration.DEBUG)
+ log.fine("alias-list=[" + aliasList + "]");
+ if (containingEnvelope != null)
+ containingEnvelope.makeAliasList();
}
+ if (Configuration.DEBUG)
+ log.exiting(this.getClass().getName(), "makeAliasList");
}
}
diff --git a/libjava/classpath/gnu/javax/crypto/keyring/GnuPrivateKeyring.java b/libjava/classpath/gnu/javax/crypto/keyring/GnuPrivateKeyring.java
index c1fe30e677b..2ccdad6b3e3 100644
--- a/libjava/classpath/gnu/javax/crypto/keyring/GnuPrivateKeyring.java
+++ b/libjava/classpath/gnu/javax/crypto/keyring/GnuPrivateKeyring.java
@@ -38,6 +38,7 @@ exception statement from your version. */
package gnu.javax.crypto.keyring;
+import gnu.java.security.Configuration;
import gnu.java.security.Registry;
import java.io.DataInputStream;
@@ -55,30 +56,21 @@ import java.util.logging.Level;
import java.util.logging.Logger;
/**
- * attributes.attributes.
+ *
* @param attributes the attributes that define where the contents of this
- * keyring will be stored.
+ * keyring will be stored.
* @throws IOException if an exception occurs during the process.
*/
void store(Map attributes) throws IOException;
/**
- * alias, or null if there no such entry
- * exists.alias, or null if no one {@link Entry} can
- * be found with the designated alias.
+ * given alias, or null if no one
+ * {@link Entry} can be found with the designated alias.
*/
List get(String alias);
/**
- * alias from this
- * keyring. Does nothing if there was no such entry.alias from this
+ * keyring. Does nothing if there was no such entry.
+ * alias.alias.
+ *
* @param alias The alias to check.
* @return true if this keyring contains a private key with the
- * given alias; false otherwise.
alias; false otherwise.
*/
boolean containsPrivateKey(String alias);
/**
- * Returns the private key with the given alias.
alias.
+ *
* @param alias The alias of the private key to find.
* @param password The password of the private key.
* @return The private, or secret, key if one is found; null if
- * none were found.
+ * none were found.
* @throws UnrecoverableKeyException If the private key could not be
- * recovered, possibly due to a bad password.
+ * recovered, possibly due to a bad password.
*/
Key getPrivateKey(String alias, char[] password)
throws UnrecoverableKeyException;
/**
- * Adds a private key to this keyring.
- * + * Adds a private key to this keyring. + * * @param alias The alias of the private key. * @param key The private key. * @param password The password used to protect this private key. @@ -86,55 +86,57 @@ public interface IPrivateKeyring extends IKeyring void putPrivateKey(String alias, Key key, char[] password); /** - *Checks if this keyring contains a public key with the given
- * alias.
alias.
+ *
* @param alias The alias to test.
- * @return true if this keyring contains a public key entry with
- * the given alias; false otherwise.
+ * @return true if this keyring contains a public key entry
+ * with the given alias; false
+ * otherwise.
*/
boolean containsPublicKey(String alias);
/**
- * Returns the public key with the given alias, or
- * null if there is no such entry.
alias, or
+ * null if there is no such entry.
+ *
* @param alias The alias of the public key to find.
* @return The public key; or null if none were found.
*/
PublicKey getPublicKey(String alias);
/**
- * Sets a public key entry.
- * + * Sets a public key entry. + * * @param alias The alias for this public key. * @param key The public key. */ void putPublicKey(String alias, PublicKey key); /** - *Checks if this keyring contains a certificate path with the given
- * alias.
alias.
+ *
* @param alias The alias to check.
- * @return true if this keyring contains a certificate path with
- * the given alias; false otherwise.
+ * @return true if this keyring contains a certificate path
+ * with the given alias; false
+ * otherwise.
*/
boolean containsCertPath(String alias);
/**
- * Returns the certificate path with the given alias, or
- * null if there is no such entry.
alias, or
+ * null if there is no such entry.
+ *
* @param alias The alias of the certificate path to find.
* @return The certificate path for the designated alias; or
- * null if none were found.
+ * null if none were found.
*/
Certificate[] getCertPath(String alias);
/**
- * Sets a certificate path entry.
- * + * Sets a certificate path entry. + * * @param alias The alias for this certificate path. * @param path The certificate path. */ diff --git a/libjava/classpath/gnu/javax/crypto/keyring/IPublicKeyring.java b/libjava/classpath/gnu/javax/crypto/keyring/IPublicKeyring.java index ccf9ca73b55..efe568f185b 100644 --- a/libjava/classpath/gnu/javax/crypto/keyring/IPublicKeyring.java +++ b/libjava/classpath/gnu/javax/crypto/keyring/IPublicKeyring.java @@ -41,39 +41,40 @@ package gnu.javax.crypto.keyring; import java.security.cert.Certificate; /** - *An interface for keyrings that contain trusted (by the owner) public - * credentials (incl. certificates).
- * + * An interface for keyrings that contain trusted (by the owner) public + * credentials (incl. certificates). + * * @see IKeyring */ -public interface IPublicKeyring extends IKeyring +public interface IPublicKeyring + extends IKeyring { - /** - *Tests if this keyring contains a certificate entry with the specified
- * alias.
alias.
+ *
* @param alias The alias of the certificate to check.
* @return true if this keyring contains a certificate entry
- * that has the given alias; false otherwise.
+ * that has the given alias; false
+ * otherwise.
*/
boolean containsCertificate(String alias);
/**
- * Returns a certificate that has the given alias, or
- * null if this keyring has no such entry.
alias, or
+ * null if this keyring has no such entry.
+ *
* @param alias The alias of the certificate to find.
* @return The certificate with the designated alias, or
- * null if none found.
+ * null if none found.
*/
Certificate getCertificate(String alias);
/**
- * Adds a certificate in this keyring, with the given alias.
What happens if there is already a certificate entry with this alias?
- * + * Adds a certificate in this keyring, with the givenalias.
+ * + * What happens if there is already a certificate entry with this alias? + * * @param alias The alias of this certificate entry. * @param cert The certificate. */ diff --git a/libjava/classpath/gnu/javax/crypto/keyring/MalformedKeyringException.java b/libjava/classpath/gnu/javax/crypto/keyring/MalformedKeyringException.java index 44c953946d4..0dab3a764c6 100644 --- a/libjava/classpath/gnu/javax/crypto/keyring/MalformedKeyringException.java +++ b/libjava/classpath/gnu/javax/crypto/keyring/MalformedKeyringException.java @@ -40,12 +40,9 @@ package gnu.javax.crypto.keyring; import java.io.IOException; -public class MalformedKeyringException extends IOException +public class MalformedKeyringException + extends IOException { - - // Constructors. - // ------------------------------------------------------------------------ - public MalformedKeyringException() { super(); diff --git a/libjava/classpath/gnu/javax/crypto/keyring/MaskableEnvelopeEntry.java b/libjava/classpath/gnu/javax/crypto/keyring/MaskableEnvelopeEntry.java index 7fed7c40c15..5206a5e071e 100644 --- a/libjava/classpath/gnu/javax/crypto/keyring/MaskableEnvelopeEntry.java +++ b/libjava/classpath/gnu/javax/crypto/keyring/MaskableEnvelopeEntry.java @@ -43,21 +43,15 @@ import java.util.List; /** * An envelope entry that can be "masked" -- placed in a state where the - * envelope's contents cannot be accessed, due to the envelope not being - * fully decoded, for example. + * envelope's contents cannot be accessed, due to the envelope not being fully + * decoded, for example. */ -public abstract class MaskableEnvelopeEntry extends EnvelopeEntry +public abstract class MaskableEnvelopeEntry + extends EnvelopeEntry { - - // Fields. - // ------------------------------------------------------------------------ - /** The masked state. */ protected boolean masked; - // Constructors. - // ------------------------------------------------------------------------ - public MaskableEnvelopeEntry(int type, Properties properties) { super(type, properties); @@ -68,12 +62,9 @@ public abstract class MaskableEnvelopeEntry extends EnvelopeEntry super(type); } - // Instance methods. - // ------------------------------------------------------------------------ - /** * Sets the masked state to the specified value. - * + * * @param masked The new masked state. */ protected final void setMasked(boolean masked) @@ -84,7 +75,7 @@ public abstract class MaskableEnvelopeEntry extends EnvelopeEntry /** * Gets the masked state of this object. Certain operations on this object * will fail if it is masked. - * + * * @return The current masked state. */ public boolean isMasked() @@ -95,54 +86,50 @@ public abstract class MaskableEnvelopeEntry extends EnvelopeEntry public void add(Entry entry) { if (isMasked()) - { - throw new IllegalStateException("masked envelope"); - } + throw new IllegalStateException("masked envelope"); super.add(entry); } public boolean containsEntry(Entry entry) { if (isMasked()) - { - throw new IllegalStateException("masked envelope"); - } + throw new IllegalStateException("masked envelope"); return super.containsEntry(entry); } public List getEntries() { if (isMasked()) - { - throw new IllegalStateException("masked envelope"); - } + throw new IllegalStateException("masked envelope"); return new ArrayList(entries); } public List get(String alias) { if (isMasked()) - { - throw new IllegalStateException("masked envelope"); - } + throw new IllegalStateException("masked envelope"); return super.get(alias); } public boolean remove(Entry entry) { if (isMasked()) - { - throw new IllegalStateException("masked envelope"); - } + throw new IllegalStateException("masked envelope"); return super.remove(entry); } - public void remove(String alias) + public boolean remove(String alias) { if (isMasked()) - { - throw new IllegalStateException("masked envelope"); - } - super.remove(alias); + throw new IllegalStateException("masked envelope"); + return super.remove(alias); + } + + public String toString() + { + return new StringBuilder("MaskableEnvelope{") + .append(super.toString()) + .append(", masked=").append(masked) + .append("}").toString(); } } diff --git a/libjava/classpath/gnu/javax/crypto/keyring/MeteredInputStream.java b/libjava/classpath/gnu/javax/crypto/keyring/MeteredInputStream.java index fcf2be746c9..330e4b20fb5 100644 --- a/libjava/classpath/gnu/javax/crypto/keyring/MeteredInputStream.java +++ b/libjava/classpath/gnu/javax/crypto/keyring/MeteredInputStream.java @@ -39,22 +39,15 @@ exception statement from your version. */ package gnu.javax.crypto.keyring; import java.io.FilterInputStream; -import java.io.InputStream; import java.io.IOException; +import java.io.InputStream; -final class MeteredInputStream extends FilterInputStream +final class MeteredInputStream + extends FilterInputStream { - - // Fields. - // ------------------------------------------------------------------------ - private int count; - private final int limit; - // Constructor. - // ------------------------------------------------------------------------ - MeteredInputStream(InputStream in, int limit) { super(in); @@ -64,12 +57,9 @@ final class MeteredInputStream extends FilterInputStream count = 0; } - // Instance methods. - // ------------------------------------------------------------------------ - /** * Tests if the number of bytes read has reached the limit. - * + * * @return True if the limit has been reached. */ public boolean limitReached() diff --git a/libjava/classpath/gnu/javax/crypto/keyring/PasswordAuthenticatedEntry.java b/libjava/classpath/gnu/javax/crypto/keyring/PasswordAuthenticatedEntry.java index 2e3a0d145c8..be10029c8bc 100644 --- a/libjava/classpath/gnu/javax/crypto/keyring/PasswordAuthenticatedEntry.java +++ b/libjava/classpath/gnu/javax/crypto/keyring/PasswordAuthenticatedEntry.java @@ -38,9 +38,11 @@ exception statement from your version. */ package gnu.javax.crypto.keyring; +import gnu.java.security.Configuration; import gnu.java.security.Registry; import gnu.java.security.prng.IRandom; import gnu.java.security.prng.LimitReachedException; +import gnu.java.security.util.PRNG; import gnu.java.security.util.Util; import gnu.javax.crypto.mac.IMac; import gnu.javax.crypto.mac.MacFactory; @@ -55,35 +57,27 @@ import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; import java.security.InvalidKeyException; -import java.security.SecureRandom; import java.util.Arrays; -import java.util.Iterator; import java.util.HashMap; +import java.util.Iterator; +import java.util.logging.Logger; /** - *
An entry authenticated with a password-based MAC.
+ * An entry authenticated with a password-based MAC. */ -public final class PasswordAuthenticatedEntry extends MaskableEnvelopeEntry +public final class PasswordAuthenticatedEntry + extends MaskableEnvelopeEntry implements PasswordProtectedEntry, Registry { - - // Constants and variables - // ------------------------------------------------------------------------- - + private static final Logger log = Logger.getLogger(PasswordAuthenticatedEntry.class.getName()); public static final int TYPE = 3; - // Constructor(s) - // ------------------------------------------------------------------------- - public PasswordAuthenticatedEntry(String mac, int maclen, Properties properties) { super(TYPE, properties); - if (mac == null || mac.length() == 0) - { - throw new IllegalArgumentException("no MAC specified"); - } + throw new IllegalArgumentException("no MAC specified"); this.properties.put("mac", mac); this.properties.put("maclen", String.valueOf(maclen)); setMasked(false); @@ -95,9 +89,6 @@ public final class PasswordAuthenticatedEntry extends MaskableEnvelopeEntry setMasked(true); } - // Class methods - // ------------------------------------------------------------------------- - public static PasswordAuthenticatedEntry decode(DataInputStream in, char[] password) throws IOException @@ -113,10 +104,8 @@ public final class PasswordAuthenticatedEntry extends MaskableEnvelopeEntry entry.decodeEnvelope(in2); byte[] macValue = new byte[mac.macSize()]; in.readFully(macValue); - if (!Arrays.equals(macValue, mac.digest())) - { - throw new MalformedKeyringException("MAC verification failed"); - } + if (! Arrays.equals(macValue, mac.digest())) + throw new MalformedKeyringException("MAC verification failed"); return entry; } @@ -125,74 +114,76 @@ public final class PasswordAuthenticatedEntry extends MaskableEnvelopeEntry { PasswordAuthenticatedEntry entry = new PasswordAuthenticatedEntry(); entry.defaultDecode(in); - if (!entry.properties.containsKey("mac")) - { - throw new MalformedKeyringException("no MAC"); - } - if (!entry.properties.containsKey("maclen")) - { - throw new MalformedKeyringException("no MAC length"); - } - if (!entry.properties.containsKey("salt")) - { - throw new MalformedKeyringException("no salt"); - } + if (! entry.properties.containsKey("mac")) + throw new MalformedKeyringException("no MAC"); + if (! entry.properties.containsKey("maclen")) + throw new MalformedKeyringException("no MAC length"); + if (! entry.properties.containsKey("salt")) + throw new MalformedKeyringException("no salt"); return entry; } - // Instance methods - // ------------------------------------------------------------------------- - public void verify(char[] password) { - if (!isMasked() || payload == null) - { - return; - } - IMac m = null; - try - { - m = getMac(password); - } - catch (Exception x) + if (Configuration.DEBUG) + log.entering(this.getClass().getName(), "verify"); + if (isMasked() && payload != null) { - throw new IllegalArgumentException(x.toString()); + if (Configuration.DEBUG) + log.fine("payload to verify: " + Util.dumpString(payload)); + long tt = -System.currentTimeMillis(); + IMac m = null; + try + { + m = getMac(password); + } + catch (Exception x) + { + throw new IllegalArgumentException(x.toString(), x); + } + int limit = payload.length - m.macSize(); + m.update(payload, 0, limit); + byte[] macValue = new byte[m.macSize()]; + System.arraycopy(payload, payload.length - macValue.length, macValue, + 0, macValue.length); + if (! Arrays.equals(macValue, m.digest())) + throw new IllegalArgumentException("MAC verification failed"); + setMasked(false); + ByteArrayInputStream bais; + try + { + bais = new ByteArrayInputStream(payload, 0, limit); + DataInputStream in = new DataInputStream(bais); + decodeEnvelope(in); + } + catch (IOException ioe) + { + throw new IllegalArgumentException("malformed keyring fragment"); + } + tt += System.currentTimeMillis(); + if (Configuration.DEBUG) + log.fine("Verified in " + tt + "ms."); } - - m.update(payload, 0, payload.length - m.macSize()); - byte[] macValue = new byte[m.macSize()]; - System.arraycopy(payload, payload.length - macValue.length, macValue, 0, - macValue.length); - if (!Arrays.equals(macValue, m.digest())) - { - throw new IllegalArgumentException("MAC verification failed"); - } - try - { - DataInputStream in = new DataInputStream( - new ByteArrayInputStream( - payload, - 0, - payload.length - - m.macSize())); - decodeEnvelope(in); - } - catch (IOException ioe) - { - throw new IllegalArgumentException("malformed keyring fragment"); - } - setMasked(false); - payload = null; + else if (Configuration.DEBUG) + log.fine("Skip verification; " + + (isMasked() ? "null payload" : "unmasked")); + if (Configuration.DEBUG) + log.exiting(this.getClass().getName(), "verify"); } public void authenticate(char[] password) throws IOException { + if (Configuration.DEBUG) + log.entering(this.getClass().getName(), "authenticate"); + long tt = -System.currentTimeMillis(); + long t1 = -System.currentTimeMillis(); if (isMasked()) - { - throw new IllegalStateException("entry is masked"); - } + throw new IllegalStateException("entry is masked"); byte[] salt = new byte[8]; - new SecureRandom ().nextBytes (salt); + PRNG.getInstance().nextBytes(salt); + t1 += System.currentTimeMillis(); + if (Configuration.DEBUG) + log.fine("-- Generated salt in " + t1 + "ms."); properties.put("salt", Util.toString(salt)); IMac m = getMac(password); ByteArrayOutputStream bout = new ByteArrayOutputStream(1024); @@ -201,10 +192,25 @@ public final class PasswordAuthenticatedEntry extends MaskableEnvelopeEntry for (Iterator it = entries.iterator(); it.hasNext();) { Entry entry = (Entry) it.next(); + if (Configuration.DEBUG) + log.fine("-- About to authenticate one " + entry); + t1 = -System.currentTimeMillis(); entry.encode(out2); + t1 += System.currentTimeMillis(); + if (Configuration.DEBUG) + log.fine("-- Authenticated an Entry in " + t1 + "ms."); } bout.write(m.digest()); payload = bout.toByteArray(); + if (Configuration.DEBUG) + log.fine("authenticated payload: " + Util.dumpString(payload)); + setMasked(true); + tt += System.currentTimeMillis(); + if (Configuration.DEBUG) + { + log.fine("Authenticated in " + tt + "ms."); + log.exiting(this.getClass().getName(), "authenticate"); + } } public void encode(DataOutputStream out, char[] password) throws IOException @@ -217,48 +223,42 @@ public final class PasswordAuthenticatedEntry extends MaskableEnvelopeEntry { if (payload == null) { + log.fine("Null payload: " + this); throw new IllegalStateException("mac not computed"); } } - // Own methods. - // ------------------------------------------------------------------------ - private IMac getMac(char[] password) throws MalformedKeyringException { - if (!properties.containsKey("salt")) - { - throw new MalformedKeyringException("no salt"); - } - byte[] salt = Util.toBytesFromString(properties.get("salt")); - IMac mac = MacFactory.getInstance(properties.get("mac")); + if (Configuration.DEBUG) + log.entering(this.getClass().getName(), "getMac"); + String saltString = properties.get("salt"); + if (saltString == null) + throw new MalformedKeyringException("no salt"); + byte[] salt = Util.toBytesFromString(saltString); + String macAlgorithm = properties.get("mac"); + IMac mac = MacFactory.getInstance(macAlgorithm); if (mac == null) - { - throw new MalformedKeyringException("no such mac: " - + properties.get("mac")); - } - int keylen = mac.macSize(); - int maclen = 0; - if (!properties.containsKey("maclen")) - { - throw new MalformedKeyringException("no MAC length"); - } + throw new MalformedKeyringException("no such mac: " + macAlgorithm); + String macLenString = properties.get("maclen"); + if (macLenString == null) + throw new MalformedKeyringException("no MAC length"); + int maclen; try { - maclen = Integer.parseInt(properties.get("maclen")); + maclen = Integer.parseInt(macLenString); } catch (NumberFormatException nfe) { throw new MalformedKeyringException("bad MAC length"); } - HashMap pbAttr = new HashMap(); pbAttr.put(IPBE.PASSWORD, password); pbAttr.put(IPBE.SALT, salt); pbAttr.put(IPBE.ITERATION_COUNT, ITERATION_COUNT); IRandom kdf = PRNGFactory.getInstance("PBKDF2-HMAC-SHA"); kdf.init(pbAttr); - + int keylen = mac.macSize(); byte[] dk = new byte[keylen]; try { @@ -268,10 +268,9 @@ public final class PasswordAuthenticatedEntry extends MaskableEnvelopeEntry { throw new Error(shouldNotHappen.toString()); } - HashMap macAttr = new HashMap(); macAttr.put(IMac.MAC_KEY_MATERIAL, dk); - macAttr.put(IMac.TRUNCATED_SIZE, new Integer(maclen)); + macAttr.put(IMac.TRUNCATED_SIZE, Integer.valueOf(maclen)); try { mac.init(macAttr); @@ -280,6 +279,8 @@ public final class PasswordAuthenticatedEntry extends MaskableEnvelopeEntry { throw new Error(shouldNotHappen.toString()); } + if (Configuration.DEBUG) + log.exiting(this.getClass().getName(), "getMac"); return mac; } } diff --git a/libjava/classpath/gnu/javax/crypto/keyring/PasswordEncryptedEntry.java b/libjava/classpath/gnu/javax/crypto/keyring/PasswordEncryptedEntry.java index 26b4032bdfb..00031cbf1bb 100644 --- a/libjava/classpath/gnu/javax/crypto/keyring/PasswordEncryptedEntry.java +++ b/libjava/classpath/gnu/javax/crypto/keyring/PasswordEncryptedEntry.java @@ -38,11 +38,12 @@ exception statement from your version. */ package gnu.javax.crypto.keyring; +import gnu.java.security.Configuration; import gnu.java.security.Registry; import gnu.java.security.prng.IRandom; import gnu.java.security.prng.LimitReachedException; +import gnu.java.security.util.PRNG; import gnu.java.security.util.Util; - import gnu.javax.crypto.cipher.CipherFactory; import gnu.javax.crypto.cipher.IBlockCipher; import gnu.javax.crypto.mode.IMode; @@ -58,41 +59,28 @@ import java.io.ByteArrayOutputStream; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; - import java.security.InvalidKeyException; -import java.security.SecureRandom; - -import java.util.Arrays; -import java.util.Collections; -import java.util.Date; -import java.util.Iterator; import java.util.HashMap; -import java.util.List; +import java.util.Iterator; +import java.util.logging.Logger; /** * An envelope that is encrypted with a password-derived key. */ -public class PasswordEncryptedEntry extends MaskableEnvelopeEntry implements - PasswordProtectedEntry, Registry +public class PasswordEncryptedEntry + extends MaskableEnvelopeEntry + implements PasswordProtectedEntry, Registry { - - // Constants and fields. - // ------------------------------------------------------------------------ - + private static final Logger log = Logger.getLogger(PasswordEncryptedEntry.class.getName()); public static final int TYPE = 1; - // Constructors. - // ------------------------------------------------------------------------ - public PasswordEncryptedEntry(String cipher, String mode, int keylen, Properties properties) { super(TYPE, properties); if ((cipher == null || cipher.length() == 0) || (mode == null || mode.length() == 0)) - { - throw new IllegalArgumentException("cipher nor mode can be empty"); - } + throw new IllegalArgumentException("cipher nor mode can be empty"); this.properties.put("cipher", cipher); this.properties.put("mode", mode); this.properties.put("keylen", String.valueOf(keylen)); @@ -105,9 +93,6 @@ public class PasswordEncryptedEntry extends MaskableEnvelopeEntry implements setMasked(true); } - // Class methods. - // ------------------------------------------------------------------------ - public static PasswordEncryptedEntry decode(DataInputStream in, char[] password) throws IOException @@ -132,49 +117,57 @@ public class PasswordEncryptedEntry extends MaskableEnvelopeEntry implements return entry; } - // Instance methods. - // ------------------------------------------------------------------------ - public void decrypt(char[] password) throws IllegalArgumentException, WrongPaddingException { - if (!isMasked() || payload == null) + if (Configuration.DEBUG) + log.entering(this.getClass().getName(), "decrypt"); + if (isMasked() && payload != null) { - return; - } - IMode mode = getMode(password, IMode.DECRYPTION); - IPad padding = PadFactory.getInstance("PKCS7"); - padding.init(mode.currentBlockSize()); - byte[] buf = new byte[payload.length]; - int count = 0; - for (int i = 0; i < payload.length; i++) - { - mode.update(payload, count, buf, count); - count += mode.currentBlockSize(); - } - int padlen = padding.unpad(buf, 0, buf.length); - DataInputStream in = new DataInputStream( - new ByteArrayInputStream( - buf, - 0, - buf.length - - padlen)); - try - { - decodeEnvelope(in); - } - catch (IOException ioe) - { - throw new IllegalArgumentException("decryption failed"); + long tt = -System.currentTimeMillis(); + IMode mode = getMode(password, IMode.DECRYPTION); + IPad padding = PadFactory.getInstance("PKCS7"); + padding.init(mode.currentBlockSize()); + byte[] buf = new byte[payload.length]; + int count = 0; + while (count + mode.currentBlockSize() <= payload.length) + { + mode.update(payload, count, buf, count); + count += mode.currentBlockSize(); + } + int padlen = padding.unpad(buf, 0, buf.length); + setMasked(false); + int len = buf.length - padlen; + ByteArrayInputStream baos = new ByteArrayInputStream(buf, 0, len); + DataInputStream in = new DataInputStream(baos); + try + { + decodeEnvelope(in); + } + catch (IOException ioe) + { + throw new IllegalArgumentException("decryption failed"); + } + tt += System.currentTimeMillis(); + log.fine("Decrypted in " + tt + "ms."); } - setMasked(false); - payload = null; + else if (Configuration.DEBUG) + log.fine("Skip decryption; " + (isMasked() ? "null payload" : "unmasked")); + if (Configuration.DEBUG) + log.exiting(this.getClass().getName(), "decrypt"); } public void encrypt(char[] password) throws IOException { + if (Configuration.DEBUG) + log.entering(this.getClass().getName(), "encrypt", String.valueOf(password)); + long tt = -System.currentTimeMillis(); + long t1 = -System.currentTimeMillis(); byte[] salt = new byte[8]; - new SecureRandom ().nextBytes (salt); + PRNG.getInstance().nextBytes(salt); + t1 += System.currentTimeMillis(); + if (Configuration.DEBUG) + log.fine("-- Generated salt in " + t1 + "ms."); properties.put("salt", Util.toString(salt)); IMode mode = getMode(password, IMode.ENCRYPTION); IPad pad = PadFactory.getInstance("PKCS7"); @@ -184,7 +177,13 @@ public class PasswordEncryptedEntry extends MaskableEnvelopeEntry implements for (Iterator it = entries.iterator(); it.hasNext();) { Entry entry = (Entry) it.next(); + if (Configuration.DEBUG) + log.fine("-- About to encode one " + entry); + t1 = -System.currentTimeMillis(); entry.encode(out2); + t1 += System.currentTimeMillis(); + if (Configuration.DEBUG) + log.fine("-- Encoded an Entry in " + t1 + "ms."); } byte[] plaintext = bout.toByteArray(); byte[] padding = pad.pad(plaintext, 0, plaintext.length); @@ -200,6 +199,13 @@ public class PasswordEncryptedEntry extends MaskableEnvelopeEntry implements count += mode.currentBlockSize(); } mode.update(lastBlock, 0, payload, count); + setMasked(true); + tt += System.currentTimeMillis(); + if (Configuration.DEBUG) + { + log.fine("Encrypted in " + tt + "ms."); + log.exiting(this.getClass().getName(), "encrypt"); + } } public void encode(DataOutputStream out, char[] password) throws IOException @@ -212,60 +218,46 @@ public class PasswordEncryptedEntry extends MaskableEnvelopeEntry implements { if (payload == null) { + if (Configuration.DEBUG) + log.fine("Null payload: " + this); throw new IllegalStateException("not encrypted"); } } - // Own methods. - // ------------------------------------------------------------------------ - private IMode getMode(char[] password, int state) { String s = properties.get("salt"); if (s == null) - { - throw new IllegalArgumentException("no salt"); - } + throw new IllegalArgumentException("no salt"); byte[] salt = Util.toBytesFromString(s); IBlockCipher cipher = CipherFactory.getInstance(properties.get("cipher")); if (cipher == null) - { - throw new IllegalArgumentException("no such cipher: " - + properties.get("cipher")); - } + throw new IllegalArgumentException("no such cipher: " + + properties.get("cipher")); int blockSize = cipher.defaultBlockSize(); if (properties.containsKey("block-size")) - { - try - { - blockSize = Integer.parseInt(properties.get("block-size")); - } - catch (NumberFormatException nfe) - { - throw new IllegalArgumentException("bad block size: " - + nfe.getMessage()); - } - } - IMode mode = ModeFactory.getInstance(properties.get("mode"), cipher, - blockSize); + try + { + blockSize = Integer.parseInt(properties.get("block-size")); + } + catch (NumberFormatException nfe) + { + throw new IllegalArgumentException("bad block size: " + + nfe.getMessage()); + } + String modeName = properties.get("mode"); + IMode mode = ModeFactory.getInstance(modeName, cipher, blockSize); if (mode == null) - { - throw new IllegalArgumentException("no such mode: " - + properties.get("mode")); - } - + throw new IllegalArgumentException("no such mode: " + modeName); HashMap pbAttr = new HashMap(); pbAttr.put(IPBE.PASSWORD, password); pbAttr.put(IPBE.SALT, salt); pbAttr.put(IPBE.ITERATION_COUNT, ITERATION_COUNT); IRandom kdf = PRNGFactory.getInstance("PBKDF2-HMAC-SHA"); kdf.init(pbAttr); - int keylen = 0; - if (!properties.containsKey("keylen")) - { - throw new IllegalArgumentException("no key length"); - } + if (! properties.containsKey("keylen")) + throw new IllegalArgumentException("no key length"); try { keylen = Integer.parseInt(properties.get("keylen")); @@ -286,7 +278,7 @@ public class PasswordEncryptedEntry extends MaskableEnvelopeEntry implements } HashMap modeAttr = new HashMap(); modeAttr.put(IMode.KEY_MATERIAL, dk); - modeAttr.put(IMode.STATE, new Integer(state)); + modeAttr.put(IMode.STATE, Integer.valueOf(state)); modeAttr.put(IMode.IV, iv); try { diff --git a/libjava/classpath/gnu/javax/crypto/keyring/PasswordProtectedEntry.java b/libjava/classpath/gnu/javax/crypto/keyring/PasswordProtectedEntry.java index 0dcf73eb8d2..5eff637927a 100644 --- a/libjava/classpath/gnu/javax/crypto/keyring/PasswordProtectedEntry.java +++ b/libjava/classpath/gnu/javax/crypto/keyring/PasswordProtectedEntry.java @@ -43,21 +43,12 @@ import java.io.IOException; public interface PasswordProtectedEntry { - - // Constant. - // ------------------------------------------------------------------------ - - /** - * The iteration count for password-based KDFs. - */ - Integer ITERATION_COUNT = new Integer(1000); - - // Method. - // ------------------------------------------------------------------------ + /** The iteration count for password-based KDFs. */ + Integer ITERATION_COUNT = Integer.valueOf(1000); /** * Encodes this entry, protected by a password. - * + * * @param out The output stream to encode to. * @param password The password. * @throws IOException If an I/O error occurs. diff --git a/libjava/classpath/gnu/javax/crypto/keyring/PrimitiveEntry.java b/libjava/classpath/gnu/javax/crypto/keyring/PrimitiveEntry.java index 4c9ff0ff1d9..194fe9eeec1 100644 --- a/libjava/classpath/gnu/javax/crypto/keyring/PrimitiveEntry.java +++ b/libjava/classpath/gnu/javax/crypto/keyring/PrimitiveEntry.java @@ -43,36 +43,24 @@ import java.util.Date; /** * A primitive entry is an entry that contains a single cryptographic entity. */ -public abstract class PrimitiveEntry extends Entry +public abstract class PrimitiveEntry + extends Entry { - - // Fields. - // ------------------------------------------------------------------------ - /** The creation date. */ protected Date creationDate; - // Constructor. - // ------------------------------------------------------------------------ - protected PrimitiveEntry(int type, Date creationDate, Properties properties) { super(type, properties); if (creationDate == null) - { - this.creationDate = new Date(); - } + this.creationDate = new Date(); else - { - this.creationDate = (Date) creationDate.clone(); - } - if (!this.properties.containsKey("alias") + this.creationDate = (Date) creationDate.clone(); + if (! this.properties.containsKey("alias") || this.properties.get("alias").length() == 0) - { - throw new IllegalArgumentException( - "primitive entries MUST have an alias"); - } - this.properties.put("creation-date", String.valueOf(creationDate.getTime())); + throw new IllegalArgumentException("primitive entries MUST have an alias"); + this.properties.put("creation-date", + String.valueOf(this.creationDate.getTime())); } protected PrimitiveEntry(int type) @@ -80,12 +68,9 @@ public abstract class PrimitiveEntry extends Entry super(type); } - // Instance method. - // ------------------------------------------------------------------------ - /** * Returns the alias of this primitive entry. - * + * * @return The alias. */ public String getAlias() @@ -95,7 +80,7 @@ public abstract class PrimitiveEntry extends Entry /** * Returns the creation date of this primitive entry. - * + * * @return The creation date. */ public Date getCreationDate() @@ -105,7 +90,7 @@ public abstract class PrimitiveEntry extends Entry public boolean equals(Object object) { - if (!getClass().equals(object.getClass())) + if (! getClass().equals(object.getClass())) return false; return getAlias().equals(((PrimitiveEntry) object).getAlias()); } @@ -114,9 +99,7 @@ public abstract class PrimitiveEntry extends Entry { String s = properties.get("creation-date"); if (s == null) - { - throw new MalformedKeyringException("no creation date"); - } + throw new MalformedKeyringException("no creation date"); try { creationDate = new Date(Long.parseLong(s)); diff --git a/libjava/classpath/gnu/javax/crypto/keyring/PrivateKeyEntry.java b/libjava/classpath/gnu/javax/crypto/keyring/PrivateKeyEntry.java index 88249563341..23244afee8d 100644 --- a/libjava/classpath/gnu/javax/crypto/keyring/PrivateKeyEntry.java +++ b/libjava/classpath/gnu/javax/crypto/keyring/PrivateKeyEntry.java @@ -42,12 +42,10 @@ import gnu.java.security.key.IKeyPairCodec; import gnu.java.security.key.KeyPairCodecFactory; import gnu.java.security.key.dss.DSSPrivateKey; import gnu.java.security.key.rsa.GnuRSAPrivateKey; - import gnu.javax.crypto.key.GnuSecretKey; import gnu.javax.crypto.key.dh.GnuDHPrivateKey; import java.io.DataInputStream; -import java.io.DataOutputStream; import java.io.IOException; import java.security.Key; import java.security.KeyFactory; @@ -56,25 +54,18 @@ import java.security.spec.PKCS8EncodedKeySpec; import java.util.Date; /** - *An immutable class representing a private or secret key entry.
+ * An immutable class representing a private or secret key entry. */ -public final class PrivateKeyEntry extends PrimitiveEntry +public final class PrivateKeyEntry + extends PrimitiveEntry { - - // Constants and variables - // ------------------------------------------------------------------------- - public static final int TYPE = 7; - /** The key. */ private Key key; - // Constructor(s) - // ------------------------------------------------------------------------- - /** - *Creates a new key entry.
- * + * Creates a new key entry. + * * @param key The key. * @param creationDate The entry creation date. * @param properties The entry properties. @@ -83,15 +74,10 @@ public final class PrivateKeyEntry extends PrimitiveEntry public PrivateKeyEntry(Key key, Date creationDate, Properties properties) { super(TYPE, creationDate, properties); - if (key == null) - { - throw new IllegalArgumentException("no private key"); - } - if (!(key instanceof PrivateKey) && !(key instanceof GnuSecretKey)) - { - throw new IllegalArgumentException("not a private or secret key"); - } + throw new IllegalArgumentException("no private key"); + if (! (key instanceof PrivateKey) && ! (key instanceof GnuSecretKey)) + throw new IllegalArgumentException("not a private or secret key"); this.key = key; } @@ -100,18 +86,13 @@ public final class PrivateKeyEntry extends PrimitiveEntry super(TYPE); } - // Class methods - // ------------------------------------------------------------------------- - public static PrivateKeyEntry decode(DataInputStream in) throws IOException { PrivateKeyEntry entry = new PrivateKeyEntry(); entry.defaultDecode(in); String type = entry.properties.get("type"); if (type == null) - { - throw new MalformedKeyringException("no key type"); - } + throw new MalformedKeyringException("no key type"); if (type.equalsIgnoreCase("RAW-DSS")) { IKeyPairCodec coder = KeyPairCodecFactory.getInstance("dss"); @@ -128,18 +109,16 @@ public final class PrivateKeyEntry extends PrimitiveEntry entry.key = coder.decodePrivateKey(entry.payload); } else if (type.equalsIgnoreCase("RAW")) - { - entry.key = new GnuSecretKey(entry.payload, null); - } + entry.key = new GnuSecretKey(entry.payload, null); else if (type.equalsIgnoreCase("PKCS8")) { try { KeyFactory kf = KeyFactory.getInstance("RSA"); - entry.key = kf.generatePrivate(new PKCS8EncodedKeySpec( - entry.payload)); + PKCS8EncodedKeySpec ks = new PKCS8EncodedKeySpec(entry.payload); + entry.key = kf.generatePrivate(ks); } - catch (Exception x) + catch (Exception ignored) { } if (entry.key == null) @@ -147,32 +126,24 @@ public final class PrivateKeyEntry extends PrimitiveEntry try { KeyFactory kf = KeyFactory.getInstance("DSA"); - entry.key = kf.generatePrivate(new PKCS8EncodedKeySpec( - entry.payload)); + PKCS8EncodedKeySpec ks = new PKCS8EncodedKeySpec(entry.payload); + entry.key = kf.generatePrivate(ks); } - catch (Exception x) + catch (Exception ignored) { } if (entry.key == null) - { - throw new MalformedKeyringException( - "could not decode PKCS#8 key"); - } + throw new MalformedKeyringException("could not decode PKCS#8 key"); } } else - { - throw new MalformedKeyringException("unsupported key type " + type); - } + throw new MalformedKeyringException("unsupported key type " + type); return entry; } - // Instance methods - // ------------------------------------------------------------------------- - /** - *Returns this entry's key.
- * + * Returns this entry's key. + * * @return The key. */ public Key getKey() @@ -212,8 +183,12 @@ public final class PrivateKeyEntry extends PrimitiveEntry payload = key.getEncoded(); } else - { - throw new IllegalArgumentException("unsupported private key"); - } + throw new IllegalArgumentException("unsupported private key"); + } + + public String toString() + { + return "PrivateKeyEntry{key=" + + (key == null ? "-" : key.getClass().getName()) + "}"; } } diff --git a/libjava/classpath/gnu/javax/crypto/keyring/Properties.java b/libjava/classpath/gnu/javax/crypto/keyring/Properties.java index 646b5711df2..b833a74aeab 100644 --- a/libjava/classpath/gnu/javax/crypto/keyring/Properties.java +++ b/libjava/classpath/gnu/javax/crypto/keyring/Properties.java @@ -42,27 +42,20 @@ import java.io.ByteArrayOutputStream; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; - import java.util.HashMap; import java.util.Iterator; import java.util.Map; /** * A set of(name => value) pairs used in keyring entries.
- * Keys and values are simple strings, with the key never being empty and
- * always treated case-insensitively.
+ * Keys and values are simple strings, with the key never being empty and always
+ * treated case-insensitively.
*/
-public class Properties implements Cloneable
+public class Properties
+ implements Cloneable
{
-
- // Field.
- // ------------------------------------------------------------------------
-
private HashMap props;
- // Constructor.
- // ------------------------------------------------------------------------
-
/**
* Creates a new properties object.
*/
@@ -71,9 +64,6 @@ public class Properties implements Cloneable
props = new HashMap();
}
- // Instance methods.
- // ------------------------------------------------------------------------
-
/**
* Removes all properties from this object.
*/
@@ -84,7 +74,7 @@ public class Properties implements Cloneable
/**
* Creates a copy of this properties object.
- *
+ *
* @return The copy.
*/
public Object clone()
@@ -96,86 +86,75 @@ public class Properties implements Cloneable
/**
* Tests if this object contains a given property name.
- *
+ *
* @param key The key to test.
* @return True if this object contains the given key.
*/
public boolean containsKey(String key)
{
if (key == null || key.length() == 0)
- {
- return false;
- }
+ return false;
return props.containsKey(canonicalize(key));
}
/**
* Tests if this object contains a given property value.
- *
+ *
* @param value The value to test.
* @return True if this object contains the given value.
*/
public boolean containsValue(String value)
{
if (value == null)
- {
- return false;
- }
+ return false;
return props.containsValue(value);
}
/**
* Adds a new property to this object.
- *
+ *
* @param key The key, which can neither be null nor empty.
* @param value The value, which cannot be null.
* @return The old value mapped by the key, if any.
- * @throws IllegalArgumentException If either the key or value parameter
-
- * is null, or if the key is empty.
+ * @throws IllegalArgumentException If either the key or value parameter is
+ * null, or if the key is empty.
*/
public String put(String key, String value)
{
if (key == null || value == null || key.length() == 0)
- {
- throw new IllegalArgumentException("key nor value can be null");
- }
+ throw new IllegalArgumentException("key nor value can be null");
return (String) props.put(canonicalize(key), value);
}
/**
- * Returns the value mapped by the given key, or null if there is no
- * such mapping.
- *
+ * Returns the value mapped by the given key, or null if there is no such
+ * mapping.
+ *
* @param key
*/
public String get(String key)
{
if (key == null || key.length() == 0)
- {
- return null;
- }
+ return null;
return (String) props.get(canonicalize(key));
}
/**
* Removes a key and its value from this object.
- *
+ *
* @param key The key of the property to remove.
* @return The old value mapped by the key, if any.
*/
public String remove(String key)
{
if (key == null || key.length() == 0)
- {
- return null;
- }
+ return null;
return (String) props.remove(canonicalize(key));
}
/**
* Decodes a set of properties from the given input stream.
- *
+ *
* @param in The input stream.
* @throws IOException If an I/O error occurs.
*/
@@ -184,7 +163,7 @@ public class Properties implements Cloneable
int len = in.readInt();
MeteredInputStream min = new MeteredInputStream(in, len);
DataInputStream in2 = new DataInputStream(min);
- while (!min.limitReached())
+ while (! min.limitReached())
{
String name = in2.readUTF();
String value = in2.readUTF();
@@ -194,7 +173,7 @@ public class Properties implements Cloneable
/**
* Encodes this set of properties to the given output stream.
- *
+ *
* @param out The output stream to encode to.
* @throws IOException If an I/O error occurs.
*/
@@ -217,9 +196,6 @@ public class Properties implements Cloneable
return props.toString();
}
- // Own methods.
- // ------------------------------------------------------------------------
-
private String canonicalize(String key)
{
return key.toLowerCase();
diff --git a/libjava/classpath/gnu/javax/crypto/keyring/PublicKeyEntry.java b/libjava/classpath/gnu/javax/crypto/keyring/PublicKeyEntry.java
index 528e70cc648..3e7f54d3e20 100644
--- a/libjava/classpath/gnu/javax/crypto/keyring/PublicKeyEntry.java
+++ b/libjava/classpath/gnu/javax/crypto/keyring/PublicKeyEntry.java
@@ -38,43 +38,30 @@ exception statement from your version. */
package gnu.javax.crypto.keyring;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-
-import java.security.PublicKey;
-import java.security.KeyFactory;
-import java.security.spec.X509EncodedKeySpec;
-
-import java.util.Date;
-
import gnu.java.security.key.IKeyPairCodec;
import gnu.java.security.key.KeyPairCodecFactory;
import gnu.java.security.key.dss.DSSPublicKey;
import gnu.java.security.key.rsa.GnuRSAPublicKey;
import gnu.javax.crypto.key.dh.GnuDHPublicKey;
-public final class PublicKeyEntry extends PrimitiveEntry
-{
-
- // Constants and fields.
- // ------------------------------------------------------------------------
+import java.io.DataInputStream;
+import java.io.IOException;
+import java.security.KeyFactory;
+import java.security.PublicKey;
+import java.security.spec.X509EncodedKeySpec;
+import java.util.Date;
+public final class PublicKeyEntry
+ extends PrimitiveEntry
+{
public static final int TYPE = 6;
-
private PublicKey key;
- // Constructor.
- // ------------------------------------------------------------------------
-
public PublicKeyEntry(PublicKey key, Date creationDate, Properties properties)
{
super(TYPE, creationDate, properties);
-
if (key == null)
- {
- throw new IllegalArgumentException("no key specified");
- }
+ throw new IllegalArgumentException("no key specified");
this.key = key;
}
@@ -83,18 +70,13 @@ public final class PublicKeyEntry extends PrimitiveEntry
super(TYPE);
}
- // Class method.
- // ------------------------------------------------------------------------
-
public static PublicKeyEntry decode(DataInputStream in) throws IOException
{
PublicKeyEntry entry = new PublicKeyEntry();
entry.defaultDecode(in);
String type = entry.properties.get("type");
if (type == null)
- {
- throw new MalformedKeyringException("no key type");
- }
+ throw new MalformedKeyringException("no key type");
if (type.equalsIgnoreCase("RAW-DSS"))
{
IKeyPairCodec coder = KeyPairCodecFactory.getInstance("dss");
@@ -125,33 +107,23 @@ public final class PublicKeyEntry extends PrimitiveEntry
try
{
KeyFactory kf = KeyFactory.getInstance("DSA");
- entry.key = kf.generatePublic(new X509EncodedKeySpec(
- entry.payload));
+ entry.key = kf.generatePublic(new X509EncodedKeySpec(entry.payload));
}
catch (Exception x)
{
}
if (entry.key == null)
- {
- throw new MalformedKeyringException(
- "could not decode X.509 key");
- }
+ throw new MalformedKeyringException("could not decode X.509 key");
}
}
else
- {
- throw new MalformedKeyringException("unsupported public key type: "
- + type);
- }
+ throw new MalformedKeyringException("unsupported public key type: " + type);
return entry;
}
- // Instance methods.
- // ------------------------------------------------------------------------
-
/**
* Returns the public key.
- *
+ *
* @return The public key.
*/
public PublicKey getKey()
@@ -185,8 +157,6 @@ public final class PublicKeyEntry extends PrimitiveEntry
payload = key.getEncoded();
}
else
- {
- throw new IllegalArgumentException("cannot encode public key");
- }
+ throw new IllegalArgumentException("cannot encode public key");
}
}
--
cgit v1.2.3