diff options
Diffstat (limited to 'gnu/javax/crypto/keyring/GnuPrivateKeyring.java')
-rw-r--r-- | gnu/javax/crypto/keyring/GnuPrivateKeyring.java | 123 |
1 files changed, 75 insertions, 48 deletions
diff --git a/gnu/javax/crypto/keyring/GnuPrivateKeyring.java b/gnu/javax/crypto/keyring/GnuPrivateKeyring.java index bd5a96227..5b6829e7b 100644 --- a/gnu/javax/crypto/keyring/GnuPrivateKeyring.java +++ b/gnu/javax/crypto/keyring/GnuPrivateKeyring.java @@ -38,6 +38,7 @@ exception statement from your version. */ package gnu.javax.crypto.keyring; +import gnu.classpath.Configuration; import gnu.java.security.Registry; import java.io.DataInputStream; @@ -105,7 +106,8 @@ public class GnuPrivateKeyring extends BaseKeyring implements IPrivateKeyring public boolean containsPrivateKey(String alias) { - log.entering(this.getClass().getName(), "containsPrivateKey", alias); + if (Configuration.DEBUG) + log.entering(this.getClass().getName(), "containsPrivateKey", alias); boolean result = false; if (containsAlias(alias)) for (Iterator it = get(alias).iterator(); it.hasNext();) @@ -114,15 +116,17 @@ public class GnuPrivateKeyring extends BaseKeyring implements IPrivateKeyring result = true; break; } - log.exiting(this.getClass().getName(), "containsPrivateKey", - Boolean.valueOf(result)); + if (Configuration.DEBUG) + log.exiting(this.getClass().getName(), "containsPrivateKey", + Boolean.valueOf(result)); return result; } public Key getPrivateKey(String alias, char[] password) throws UnrecoverableKeyException { - log.entering(this.getClass().getName(), "getPrivateKey", alias); + if (Configuration.DEBUG) + log.entering(this.getClass().getName(), "getPrivateKey", alias); Key result = null; if (containsAlias(alias)) { @@ -130,15 +134,16 @@ public class GnuPrivateKeyring extends BaseKeyring implements IPrivateKeyring for (Iterator it = get(alias).iterator(); it.hasNext();) { Entry e = (Entry) it.next(); - log.finest("Entry: " + e); + if (Configuration.DEBUG) + log.finest("Entry: " + e); if (e instanceof PasswordAuthenticatedEntry) { e1 = (PasswordAuthenticatedEntry) e; break; } } - - log.finest("e1 = " + e1); + if (Configuration.DEBUG) + log.fine("e1 = " + e1); if (e1 != null) { try @@ -147,7 +152,8 @@ public class GnuPrivateKeyring extends BaseKeyring implements IPrivateKeyring } catch (Exception e) { - log.throwing(this.getClass().getName(), "getPrivateKey", e); + if (Configuration.DEBUG) + log.throwing(this.getClass().getName(), "getPrivateKey", e); throw new UnrecoverableKeyException("authentication failed"); } @@ -186,23 +192,25 @@ public class GnuPrivateKeyring extends BaseKeyring implements IPrivateKeyring } } } - log.exiting(this.getClass().getName(), "getPrivateKey", - result == null ? "null" : result.getClass().getName()); + if (Configuration.DEBUG) + log.exiting(this.getClass().getName(), "getPrivateKey", + result == null ? "null" : result.getClass().getName()); return result; } public void putPrivateKey(String alias, Key key, char[] password) { - log.entering(this.getClass().getName(), "putPrivateKey", - new Object[] { alias, key.getClass().getName() }); + if (Configuration.DEBUG) + log.entering(this.getClass().getName(), "putPrivateKey", + new Object[] { alias, key.getClass().getName() }); if (! containsPrivateKey(alias)) { alias = fixAlias(alias); Properties p = new Properties(); p.put("alias", alias); PrivateKeyEntry pke = new PrivateKeyEntry(key, new Date(), p); - - log.finest("About to encrypt the key..."); + if (Configuration.DEBUG) + log.fine("About to encrypt the key..."); PasswordEncryptedEntry enc; enc = new PasswordEncryptedEntry(cipher, mode, keylen, new Properties()); enc.add(pke); @@ -212,12 +220,13 @@ public class GnuPrivateKeyring extends BaseKeyring implements IPrivateKeyring } catch (IOException x) { - log.log(Level.FINER, "Exception while encrypting the key. " - + "Rethrow as IllegalArgumentException", x); + if (Configuration.DEBUG) + log.log(Level.FINE, "Exception while encrypting the key. " + + "Rethrow as IllegalArgumentException", x); throw new IllegalArgumentException(x.toString()); } - - log.finest("About to authenticate the encrypted key..."); + if (Configuration.DEBUG) + log.fine("About to authenticate the encrypted key..."); PasswordAuthenticatedEntry auth; auth = new PasswordAuthenticatedEntry(mac, maclen, new Properties()); auth.add(enc); @@ -227,22 +236,25 @@ public class GnuPrivateKeyring extends BaseKeyring implements IPrivateKeyring } catch (IOException x) { - log.log(Level.FINER, "Exception while authenticating the encrypted " - + "key. Rethrow as IllegalArgumentException", x); + if (Configuration.DEBUG) + log.log(Level.FINE, "Exception while authenticating the encrypted " + + "key. Rethrow as IllegalArgumentException", x); throw new IllegalArgumentException(x.toString()); } keyring.add(auth); } - else - log.finer("Keyring already contains alias: " + alias); + else if (Configuration.DEBUG) + log.fine("Keyring already contains alias: " + alias); - log.exiting(this.getClass().getName(), "putPrivateKey"); + if (Configuration.DEBUG) + log.exiting(this.getClass().getName(), "putPrivateKey"); } public boolean containsPublicKey(String alias) { - log.entering(this.getClass().getName(), "containsPublicKey", alias); + if (Configuration.DEBUG) + log.entering(this.getClass().getName(), "containsPublicKey", alias); boolean result = false; if (containsAlias(alias)) for (Iterator it = get(alias).iterator(); it.hasNext();) @@ -251,14 +263,16 @@ public class GnuPrivateKeyring extends BaseKeyring implements IPrivateKeyring result = true; break; } - log.exiting(this.getClass().getName(), "containsPublicKey", - Boolean.valueOf(result)); + if (Configuration.DEBUG) + log.exiting(this.getClass().getName(), "containsPublicKey", + Boolean.valueOf(result)); return result; } public PublicKey getPublicKey(String alias) { - log.entering(this.getClass().getName(), "getPublicKey", alias); + if (Configuration.DEBUG) + log.entering(this.getClass().getName(), "getPublicKey", alias); PublicKey result = null; if (containsAlias(alias)) for (Iterator it = get(alias).iterator(); it.hasNext();) @@ -270,30 +284,34 @@ public class GnuPrivateKeyring extends BaseKeyring implements IPrivateKeyring break; } } - log.exiting(this.getClass().getName(), "getPublicKey", - result == null ? "null" : result.getClass().getName()); + if (Configuration.DEBUG) + log.exiting(this.getClass().getName(), "getPublicKey", + result == null ? "null" : result.getClass().getName()); return result; } public void putPublicKey(String alias, PublicKey key) { - log.entering(this.getClass().getName(), "putPublicKey", - new Object[] { alias, key.getClass().getName() }); + if (Configuration.DEBUG) + log.entering(this.getClass().getName(), "putPublicKey", + new Object[] { alias, key.getClass().getName() }); if (! containsPublicKey(alias)) { Properties p = new Properties(); p.put("alias", fixAlias(alias)); add(new PublicKeyEntry(key, new Date(), p)); } - else - log.finer("Keyring already contains alias: " + alias); + else if (Configuration.DEBUG) + log.fine("Keyring already contains alias: " + alias); - log.exiting(this.getClass().getName(), "putPublicKey"); + if (Configuration.DEBUG) + log.exiting(this.getClass().getName(), "putPublicKey"); } public boolean containsCertPath(String alias) { - log.entering(this.getClass().getName(), "containsCertPath", alias); + if (Configuration.DEBUG) + log.entering(this.getClass().getName(), "containsCertPath", alias); boolean result = false; if (containsAlias(alias)) for (Iterator it = get(alias).iterator(); it.hasNext();) @@ -302,14 +320,16 @@ public class GnuPrivateKeyring extends BaseKeyring implements IPrivateKeyring result = true; break; } - log.exiting(this.getClass().getName(), "containsCertPath", - Boolean.valueOf(result)); + if (Configuration.DEBUG) + log.exiting(this.getClass().getName(), "containsCertPath", + Boolean.valueOf(result)); return result; } public Certificate[] getCertPath(String alias) { - log.entering(this.getClass().getName(), "getCertPath", alias); + if (Configuration.DEBUG) + log.entering(this.getClass().getName(), "getCertPath", alias); Certificate[] result = null; if (containsAlias(alias)) for (Iterator it = get(alias).iterator(); it.hasNext();) @@ -321,29 +341,33 @@ public class GnuPrivateKeyring extends BaseKeyring implements IPrivateKeyring break; } } - log.exiting(this.getClass().getName(), "getCertPath", result); + if (Configuration.DEBUG) + log.exiting(this.getClass().getName(), "getCertPath", result); return result; } public void putCertPath(String alias, Certificate[] path) { - log.entering(this.getClass().getName(), "putCertPath", - new Object[] { alias, path }); + if (Configuration.DEBUG) + log.entering(this.getClass().getName(), "putCertPath", + new Object[] { alias, path }); if (! containsCertPath(alias)) { Properties p = new Properties(); p.put("alias", fixAlias(alias)); add(new CertPathEntry(path, new Date(), p)); } - else - log.finer("Keyring already contains alias: " + alias); + else if (Configuration.DEBUG) + log.fine("Keyring already contains alias: " + alias); - log.exiting(this.getClass().getName(), "putCertPath"); + if (Configuration.DEBUG) + log.exiting(this.getClass().getName(), "putCertPath"); } protected void load(InputStream in, char[] password) throws IOException { - log.entering(this.getClass().getName(), "load"); + if (Configuration.DEBUG) + log.entering(this.getClass().getName(), "load"); if (in.read() != USAGE) throw new MalformedKeyringException("incompatible keyring usage"); @@ -352,14 +376,17 @@ public class GnuPrivateKeyring extends BaseKeyring implements IPrivateKeyring keyring = PasswordAuthenticatedEntry.decode(new DataInputStream(in), password); - log.exiting(this.getClass().getName(), "load"); + if (Configuration.DEBUG) + log.exiting(this.getClass().getName(), "load"); } protected void store(OutputStream out, char[] password) throws IOException { - log.entering(this.getClass().getName(), "store"); + if (Configuration.DEBUG) + log.entering(this.getClass().getName(), "store"); out.write(USAGE); keyring.encode(new DataOutputStream(out), password); - log.exiting(this.getClass().getName(), "store"); + if (Configuration.DEBUG) + log.exiting(this.getClass().getName(), "store"); } } |