summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew John Hughes <gnu_andrew@member.fsf.org>2015-02-02 15:28:40 +0000
committerAndrew John Hughes <gnu_andrew@member.fsf.org>2015-02-02 15:28:40 +0000
commit55c5097f9ce57cb5ebdbec6383c6c89ad4933348 (patch)
treee70deaabb74a1793da3f94d6d3c51feccd85cc0e
parent92f6e5177fbd0c8bfdbecce4b5704d981f4988bb (diff)
downloadclasspath-55c5097f9ce57cb5ebdbec6383c6c89ad4933348.tar.gz
PR64881: KeyPairGenerator.genKeyPair() ends up calling the default generateKeyPair method which returns a DSA generator
2015-01-30 Andrew John Hughes <gnu_andrew@member.fsf.org> PR classpath/64881 * NEWS: Updated. * java/security/KeyPairGenerator.java: (genKeyPair()): Document properly. Call original method, generateKeyPair(). (generateKeyPair()): Document properly. Use provider and algorithm values if set rather than just defaulting to GNU and DSA. Signed-off-by: Andrew John Hughes <gnu_andrew@member.fsf.org>
-rw-r--r--ChangeLog11
-rw-r--r--NEWS1
-rw-r--r--java/security/KeyPairGenerator.java65
3 files changed, 59 insertions, 18 deletions
diff --git a/ChangeLog b/ChangeLog
index 0abf14e4e..2a34c27b1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2015-01-30 Andrew John Hughes <gnu_andrew@member.fsf.org>
+
+ PR classpath/64881
+ * NEWS: Updated.
+ * java/security/KeyPairGenerator.java:
+ (genKeyPair()): Document properly. Call original
+ method, generateKeyPair().
+ (generateKeyPair()): Document properly. Use provider
+ and algorithm values if set rather than just defaulting
+ to GNU and DSA.
+
2015-01-06 Andrew John Hughes <gnu_andrew@member.fsf.org>
* NEWS: Updated.
diff --git a/NEWS b/NEWS
index 9f5149a92..67566c251 100644
--- a/NEWS
+++ b/NEWS
@@ -31,6 +31,7 @@ New in release 0.99.1 (XXX XX, 2012)
- PR58688: gnu.java.security.x509.PolicyNodeImpl#addAllPolicyQualifiers does not work
- PR64109: Missing symbol in libjavautil.so
- PR64176: Week of year field during end of year transition is incorrect
+ - PR64881: KeyPairGenerator.genKeyPair() ends up calling the default generateKeyPair method which returns a DSA generator
New in release 0.99 (Feb 15, 2012)
diff --git a/java/security/KeyPairGenerator.java b/java/security/KeyPairGenerator.java
index 19724da6f..457c5a531 100644
--- a/java/security/KeyPairGenerator.java
+++ b/java/security/KeyPairGenerator.java
@@ -1,5 +1,5 @@
/* KeyPairGenerator.java --- Key Pair Generator Class
- Copyright (C) 1999, 2002, 2003, 2004, 2005, 2014 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2002, 2003, 2004, 2005, 2014, 2015 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -278,9 +278,17 @@ public abstract class KeyPairGenerator extends KeyPairGeneratorSpi
}
/**
- * Generates a new "DSA" {@link KeyPair} from the "GNU" security provider.
- *
- * <p>This method generates a unique key-pair each time it is called.</p>
+ * <p>
+ * Generates a new key pair. If a provider hasn't been selected,
+ * it defaults to generating a "DSA" {@link KeyPair} using the "GNU"
+ * security provider. If the provider hasn't been initialised, then
+ * the provider-specified default key size and other parameters are
+ * used.
+ * </p>
+ * <p>
+ * A new key pair is generated on each call to this method. It
+ * is functionally equivalent to {@link #genKeyPair()}.
+ * </p>
*
* @return a new unique {@link KeyPair}.
* @see #generateKeyPair()
@@ -288,28 +296,49 @@ public abstract class KeyPairGenerator extends KeyPairGeneratorSpi
*/
public final KeyPair genKeyPair()
{
- try
- {
- return getInstance("DSA", "GNU").generateKeyPair();
- }
- catch (Exception e)
- {
- System.err.println("genKeyPair failed: " + e);
- e.printStackTrace();
- return null;
- }
+ return generateKeyPair();
}
/**
- * Generates a new "DSA" {@link KeyPair} from the "GNU" security provider.
- *
- * <p>This method generates a unique key pair each time it is called.</p>
+ * <p>
+ * Generates a new key pair. If a provider hasn't been selected,
+ * it defaults to generating a "DSA" {@link KeyPair} using the "GNU"
+ * security provider. If the provider hasn't been initialised, then
+ * the provider-specified default key size and other parameters are
+ * used.
+ * </p>
+ * <p>
+ * A new key pair is generated on each call to this method. It
+ * is functionally equivalent to {@link #generateKeyPair()}.
+ * </p>
*
* @return a new unique {@link KeyPair}.
* @see #genKeyPair()
*/
public KeyPair generateKeyPair()
{
- return genKeyPair();
+ try
+ {
+ Provider providerToUse = null;
+ String algToUse = null;
+
+ if (provider == null)
+ providerToUse = Security.getProvider("GNU");
+ else
+ providerToUse = provider;
+
+ if (algorithm == null)
+ algToUse = "DSA";
+ else
+ algToUse = algorithm;
+
+ return getInstance(algToUse, providerToUse).generateKeyPair();
+ }
+ catch (Exception e)
+ {
+ System.err.println("genKeyPair failed: " + e);
+ e.printStackTrace();
+ return null;
+ }
}
}