diff options
author | Raif S. Naffah <raif@swiftdsl.com.au> | 2006-07-16 05:55:59 +0000 |
---|---|---|
committer | Raif S. Naffah <raif@swiftdsl.com.au> | 2006-07-16 05:55:59 +0000 |
commit | 04d6abbcf08cdaded5b0adf78f171eb42971c3bf (patch) | |
tree | 74d3091b62912fea948e9807466df438fb6ca1ca /tools | |
parent | 26b0a9e8dab07147f24fad086f77f928b4bebfbd (diff) | |
download | classpath-04d6abbcf08cdaded5b0adf78f171eb42971c3bf.tar.gz |
2006-07-16 Raif S. Naffah <raif@swiftdsl.com.au>
PR Classpath/28391
* tools/gnu/classpath/tools/keytool/Command.java (setKeyStoreParams(5)):
New method.
(setKeyStoreParams(4)): Call the above method with false as its 1st arg.
(setProviderClassNameParam): Made private.
(setKeystoreTypeParam): Likewise.
(setKeyPasswordParam): Likewise
(setKeystorePasswordParam): Likewise.
(setKeystoreURLParam): Now accepts 2 more arguments; the first a boolean to
create or not the keystore if it's not there, and the second is the store's
password to process before loading the keystore. Amended the code
accordingly.
* tools/gnu/classpath/tools/keytool/GenKeyCmd.java (setup): Call super's
setKeyStoreParams(5) with true as its first argument.
* tools/gnu/classpath/tools/keytool/IdentityDBCmd.java (setup): Likewise.
* tools/gnu/classpath/tools/keytool/ImportCmd.java (setup): Likewise.
Diffstat (limited to 'tools')
4 files changed, 49 insertions, 13 deletions
diff --git a/tools/gnu/classpath/tools/keytool/Command.java b/tools/gnu/classpath/tools/keytool/Command.java index da9293116..00547766b 100644 --- a/tools/gnu/classpath/tools/keytool/Command.java +++ b/tools/gnu/classpath/tools/keytool/Command.java @@ -374,6 +374,11 @@ abstract class Command /** * Convenience method to setup the key store given its type, its password, its * location and portentially a specialized security provider. + * <p> + * Calls the method with the same name and 5 arguments passing + * <code>false</code> to the first argument implying that no attempt to + * create the keystore will be made if one was not found at the designated + * location. * * @param className the potentially null fully qualified class name of a * security provider to add at runtime, if no installed provider is @@ -388,10 +393,31 @@ abstract class Command throws IOException, UnsupportedCallbackException, KeyStoreException, NoSuchAlgorithmException, CertificateException { + setKeyStoreParams(false, className, type, password, url); + } + + /** + * Convenience method to setup the key store given its type, its password, its + * location and portentially a specialized security provider. + * + * @param createIfNotFound if <code>true</code> then create the keystore if + * it was not found; otherwise do not. + * @param className the potentially null fully qualified class name of a + * security provider to add at runtime, if no installed provider is + * able to provide a key store implementation of the desired type. + * @param type the potentially null type of the key store to request from the + * key store factory. + * @param password the potentially null password protecting the key store. + * @param url the URL of the key store. + */ + protected void setKeyStoreParams(boolean createIfNotFound, String className, + String type, String password, String url) + throws IOException, UnsupportedCallbackException, KeyStoreException, + NoSuchAlgorithmException, CertificateException + { setProviderClassNameParam(className); setKeystoreTypeParam(type); - setKeystorePasswordParam(password); - setKeystoreURLParam(url); + setKeystoreURLParam(createIfNotFound, url, password); } /** @@ -402,7 +428,7 @@ abstract class Command * security provider to add, if it is not already installed, to the * set of available providers. */ - protected void setProviderClassNameParam(String className) + private void setProviderClassNameParam(String className) { if (Configuration.DEBUG) log.fine("setProviderClassNameParam(" + className + ")"); //$NON-NLS-1$ //$NON-NLS-2$ @@ -430,7 +456,7 @@ abstract class Command * For GNU Classpath this is <i>gkr</i> which stands for the "Gnu * KeyRing" specifications. */ - protected void setKeystoreTypeParam(String type) + private void setKeystoreTypeParam(String type) { if (Configuration.DEBUG) log.fine("setKeystoreTypeParam(" + type + ")"); //$NON-NLS-1$ //$NON-NLS-2$ @@ -491,7 +517,7 @@ abstract class Command * @throws SecurityException if no password is available, even after prompting * the user. */ - protected void setKeyPasswordParam() throws IOException, + private void setKeyPasswordParam() throws IOException, UnsupportedCallbackException { String prompt = Messages.getFormattedString("Command.21", alias); //$NON-NLS-1$ @@ -503,7 +529,7 @@ abstract class Command throw new SecurityException(Messages.getString("Command.23")); //$NON-NLS-1$ } - protected void setKeystorePasswordParam(String password) throws IOException, + private void setKeystorePasswordParam(String password) throws IOException, UnsupportedCallbackException { if (password != null) @@ -521,14 +547,20 @@ abstract class Command /** * Set the key store URL to use. * - * @param url + * @param createIfNotFound when <code>true</code> an attempt to create a + * keystore at the designated location will be made. If + * <code>false</code> then no file creation is carried out, which + * may cause an exception to be thrown later. + * @param url the full, or partial, URL to the keystore location. + * @param password an eventually null string to use when loading the keystore. * @throws IOException * @throws KeyStoreException * @throws UnsupportedCallbackException * @throws NoSuchAlgorithmException * @throws CertificateException */ - protected void setKeystoreURLParam(String url) throws IOException, + private void setKeystoreURLParam(boolean createIfNotFound, String url, + String password) throws IOException, KeyStoreException, UnsupportedCallbackException, NoSuchAlgorithmException, CertificateException { @@ -549,8 +581,10 @@ abstract class Command { url = url.trim(); if (url.indexOf(":") == -1) // if it does not exist create it //$NON-NLS-1$ - new File(url).createNewFile(); - + { + if (createIfNotFound) + new File(url).createNewFile(); + } url = "file:" + url; //$NON-NLS-1$ } @@ -590,6 +624,8 @@ abstract class Command store = KeyStore.getInstance(storeType, provider); } + setKeystorePasswordParam(password); + // now we have a KeyStore instance. load it // KeyStore public API claims: "...In order to create an empty keystore, // you pass null as the InputStream argument to the load method. diff --git a/tools/gnu/classpath/tools/keytool/GenKeyCmd.java b/tools/gnu/classpath/tools/keytool/GenKeyCmd.java index e9034eac2..03a1555a8 100644 --- a/tools/gnu/classpath/tools/keytool/GenKeyCmd.java +++ b/tools/gnu/classpath/tools/keytool/GenKeyCmd.java @@ -303,7 +303,7 @@ class GenKeyCmd extends Command void setup() throws Exception { - setKeyStoreParams(_providerClassName, _ksType, _ksPassword, _ksURL); + setKeyStoreParams(true, _providerClassName, _ksType, _ksPassword, _ksURL); setAliasParam(_alias); setKeyPasswordParam(_password); setAlgorithmParams(_keyAlgorithm, _sigAlgorithm); diff --git a/tools/gnu/classpath/tools/keytool/IdentityDBCmd.java b/tools/gnu/classpath/tools/keytool/IdentityDBCmd.java index 94234c5b9..d0de589d9 100644 --- a/tools/gnu/classpath/tools/keytool/IdentityDBCmd.java +++ b/tools/gnu/classpath/tools/keytool/IdentityDBCmd.java @@ -149,7 +149,7 @@ class IdentityDBCmd extends Command void setup() throws Exception { setInputStreamParam(_idbFileName); - setKeyStoreParams(_providerClassName, _ksType, _ksPassword, _ksURL); + setKeyStoreParams(true, _providerClassName, _ksType, _ksPassword, _ksURL); if (Configuration.DEBUG) { log.fine("-identitydb handler will use the following options:"); //$NON-NLS-1$ diff --git a/tools/gnu/classpath/tools/keytool/ImportCmd.java b/tools/gnu/classpath/tools/keytool/ImportCmd.java index e733ad4c1..3a6ed872b 100644 --- a/tools/gnu/classpath/tools/keytool/ImportCmd.java +++ b/tools/gnu/classpath/tools/keytool/ImportCmd.java @@ -292,7 +292,7 @@ class ImportCmd extends Command void setup() throws Exception { setInputStreamParam(_certFileName); - setKeyStoreParams(_providerClassName, _ksType, _ksPassword, _ksURL); + setKeyStoreParams(true, _providerClassName, _ksType, _ksPassword, _ksURL); setAliasParam(_alias); setKeyPasswordNoPrompt(_password); if (Configuration.DEBUG) |