diff options
author | Raif S. Naffah <raif@swiftdsl.com.au> | 2006-05-14 08:20:18 +0000 |
---|---|---|
committer | Raif S. Naffah <raif@swiftdsl.com.au> | 2006-05-14 08:20:18 +0000 |
commit | 0d0e1fb922cd2e5aa0937e22551c39e24a06b6a2 (patch) | |
tree | 544134c0582f0b734d00f0c24b66a71132f0b5a6 /tools | |
parent | 5b3050d33f02aec5a71155f136833e8bfe6c4829 (diff) | |
download | classpath-0d0e1fb922cd2e5aa0937e22551c39e24a06b6a2.tar.gz |
2006-05-14 Raif S. Naffah <raif@swiftdsl.com.au>
* tools/gnu/classpath/tools/keytool/keytool.txt: Removed
* tools/gnu/classpath/tools/keytool/StorePasswdCmd.java:
Increased visibility of fields used by parser anonymous classes.
(processArgs): Removed.
(getParser): New method.
* tools/gnu/classpath/tools/keytool/SelfCertCmd.java: Likewise.
(setup): Mark (Eclipse) strings that need not be externalised.
(start): Likewise.
* tools/gnu/classpath/tools/keytool/PrintCertCmd.java: Likewise.
* tools/gnu/classpath/tools/keytool/Main.java: Amended to use getopt
command line option parsing.
* tools/gnu/classpath/tools/keytool/ListCmd.java:
Increased visibility of fields used by parser anonymous classes.
(processArgs): Removed.
(setup): set 'all' local field.
(getParser): New method.
* tools/gnu/classpath/tools/keytool/KeyPasswdCmd.java:
Increased visibility of fields used by parser anonymous classes.
(processArgs): Removed.
(getParser): New method.
* tools/gnu/classpath/tools/keytool/KeyCloneCmd.java: Likewise.
(setNewKeyPassword): Fixed comments.
* tools/gnu/classpath/tools/keytool/ImportCmd.java:
Increased visibility of fields used by parser anonymous classes.
(processArgs): Removed.
(getParser): New method.
(findTrustInCACerts): Mark (Eclipse) strings that need not be
externalised.
* tools/gnu/classpath/tools/keytool/GenKeyCmd.java:
Increased visibility of fields used by parser anonymous classes.
(processArgs): Removed.
(setup): Mark (Eclipse) strings that need not be externalised.
(getParser): New method.
* tools/gnu/classpath/tools/keytool/IdentityDBCmd.java: Likewise.
* tools/gnu/classpath/tools/keytool/DeleteCmd.java:
Increased visibility of fields used by parser anonymous classes.
(processArgs): Removed.
(getParser): New method.
* tools/gnu/classpath/tools/keytool/CertReqCmd.java: Likewise.
(ATTRIBUTES_OPT): New constant.
* tools/gnu/classpath/tools/keytool/ExportCmd.java:
Increased visibility of fields used by parser anonymous classes.
(processArgs): Removed.
(setup): Mark (Eclipse) strings that need not be externalised.
(start): Likewise.
Reduced logging level.
(getParser): New method.
* tools/gnu/classpath/tools/keytool/Command.java
(processArgs): Made it concrete.
(getParser): New abstract method.
* tools/Makefile.am (KEYTOOL_HELPS): Removed.
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/Makefile.am | 4 | ||||
-rw-r--r-- | tools/gnu/classpath/tools/keytool/CertReqCmd.java | 164 | ||||
-rw-r--r-- | tools/gnu/classpath/tools/keytool/Command.java | 22 | ||||
-rw-r--r-- | tools/gnu/classpath/tools/keytool/DeleteCmd.java | 113 | ||||
-rw-r--r-- | tools/gnu/classpath/tools/keytool/ExportCmd.java | 169 | ||||
-rw-r--r-- | tools/gnu/classpath/tools/keytool/GenKeyCmd.java | 195 | ||||
-rw-r--r-- | tools/gnu/classpath/tools/keytool/IdentityDBCmd.java | 127 | ||||
-rw-r--r-- | tools/gnu/classpath/tools/keytool/ImportCmd.java | 164 | ||||
-rw-r--r-- | tools/gnu/classpath/tools/keytool/KeyCloneCmd.java | 156 | ||||
-rw-r--r-- | tools/gnu/classpath/tools/keytool/KeyPasswdCmd.java | 138 | ||||
-rw-r--r-- | tools/gnu/classpath/tools/keytool/ListCmd.java | 125 | ||||
-rw-r--r-- | tools/gnu/classpath/tools/keytool/Main.java | 231 | ||||
-rw-r--r-- | tools/gnu/classpath/tools/keytool/PrintCertCmd.java | 73 | ||||
-rw-r--r-- | tools/gnu/classpath/tools/keytool/SelfCertCmd.java | 192 | ||||
-rw-r--r-- | tools/gnu/classpath/tools/keytool/StorePasswdCmd.java | 112 | ||||
-rw-r--r-- | tools/gnu/classpath/tools/keytool/keytool.txt | 616 |
16 files changed, 1377 insertions, 1224 deletions
diff --git a/tools/Makefile.am b/tools/Makefile.am index d17c9d221..bc7bee4b1 100755 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -43,9 +43,8 @@ TOOLS_TEMPLATES = $(GRMIC_TEMPLATES) $(RMIC_TEMPLATES) # This covers the built-in help texts, both for giop and rmic subpackages. GIOP_HELPS = $(srcdir)/gnu/classpath/tools/giop/*.txt RMI_HELPS = $(srcdir)/gnu/classpath/tools/rmi/*.txt -KEYTOOL_HELPS = $(srcdir)/gnu/classpath/tools/keytool/*.txt -TOOLS_HELPS = $(GIOP_HELPS) $(RMI_HELPS) $(KEYTOOL_HELPS) +TOOLS_HELPS = $(GIOP_HELPS) $(RMI_HELPS) # The tool specific README files. READMES = $(srcdir)/gnu/classpath/tools/giop/README @@ -87,7 +86,6 @@ $(TOOLS_ZIP): $(TOOLS_JAVA_FILES) cp $(GRMIC_TEMPLATES) classes/gnu/classpath/tools/giop/grmic/templates cp $(RMI_HELPS) classes/gnu/classpath/tools/rmi/ cp $(GIOP_HELPS) classes/gnu/classpath/tools/giop/ - cp $(KEYTOOL_HELPS) classes/gnu/classpath/tools/keytool/ $(JCOMPILER) -d classes $(TOOLS_JAVA_FILES) (cd classes; \ if test "$(ZIP)" != ""; then $(ZIP) -r ../$(TOOLS_ZIP) .; fi; \ diff --git a/tools/gnu/classpath/tools/keytool/CertReqCmd.java b/tools/gnu/classpath/tools/keytool/CertReqCmd.java index 0c64246e8..533d54cae 100644 --- a/tools/gnu/classpath/tools/keytool/CertReqCmd.java +++ b/tools/gnu/classpath/tools/keytool/CertReqCmd.java @@ -38,6 +38,11 @@ exception statement from your version. */ package gnu.classpath.tools.keytool; +import gnu.classpath.tools.getopt.ClasspathToolParser; +import gnu.classpath.tools.getopt.Option; +import gnu.classpath.tools.getopt.OptionException; +import gnu.classpath.tools.getopt.OptionGroup; +import gnu.classpath.tools.getopt.Parser; import gnu.java.security.OID; import gnu.java.security.der.BitString; import gnu.java.security.der.DER; @@ -170,15 +175,16 @@ import javax.security.auth.x500.X500Principal; class CertReqCmd extends Command { private static final Logger log = Logger.getLogger(CertReqCmd.class.getName()); - private String _alias; - private String _sigAlgorithm; - private String _certReqFileName; - private String _password; - private String _ksType; - private String _ksURL; - private String _ksPassword; - private String _providerClassName; - private boolean nullAttributes; + private static final String ATTRIBUTES_OPT = "attributes"; //$NON-NLS-1$ + protected String _alias; + protected String _sigAlgorithm; + protected String _certReqFileName; + protected String _password; + protected String _ksType; + protected String _ksURL; + protected String _ksPassword; + protected String _providerClassName; + protected boolean nullAttributes; // default 0-arguments constructor @@ -246,44 +252,6 @@ class CertReqCmd extends Command // life-cycle methods ------------------------------------------------------- - int processArgs(String[] args, int i) - { - int limit = args.length; - String opt; - while (++i < limit) - { - opt = args[i]; - log.finest("args[" + i + "]=" + opt); //$NON-NLS-1$ //$NON-NLS-2$ - if (opt == null || opt.length() == 0) - continue; - - if ("-alias".equals(opt)) // -alias ALIAS //$NON-NLS-1$ - _alias = args[++i]; - else if ("-sigalg".equals(opt)) // -sigalg ALGORITHM //$NON-NLS-1$ - _sigAlgorithm = args[++i]; - else if ("-file".equals(opt)) // -file FILE_NAME //$NON-NLS-1$ - _certReqFileName = args[++i]; - else if ("-keypass".equals(opt)) // -keypass PASSWORD //$NON-NLS-1$ - _password = args[++i]; - else if ("-storetype".equals(opt)) // -storetype STORE_TYPE //$NON-NLS-1$ - _ksType = args[++i]; - else if ("-keystore".equals(opt)) // -keystore URL //$NON-NLS-1$ - _ksURL = args[++i]; - else if ("-storepass".equals(opt)) // -storepass PASSWORD //$NON-NLS-1$ - _ksPassword = args[++i]; - else if ("-provider".equals(opt)) // -provider PROVIDER_CLASS_NAME //$NON-NLS-1$ - _providerClassName = args[++i]; - else if ("-v".equals(opt)) //$NON-NLS-1$ - verbose = true; - else if ("-attributes".equals(opt)) //$NON-NLS-1$ - nullAttributes = true; - else - break; - } - - return i; - } - void setup() throws Exception { setOutputStreamParam(_certReqFileName); @@ -346,6 +314,108 @@ class CertReqCmd extends Command // own methods -------------------------------------------------------------- + Parser getParser() + { + log.entering(this.getClass().getName(), "getParser"); //$NON-NLS-1$ + + Parser result = new ClasspathToolParser(Main.CERTREQ_CMD, true); + result.setHeader(Messages.getString("CertReqCmd.25")); //$NON-NLS-1$ + result.setFooter(Messages.getString("CertReqCmd.24")); //$NON-NLS-1$ + OptionGroup options = new OptionGroup(Messages.getString("CertReqCmd.23")); //$NON-NLS-1$ + options.add(new Option(Main.ALIAS_OPT, + Messages.getString("CertReqCmd.22"), //$NON-NLS-1$ + Messages.getString("CertReqCmd.21")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _alias = argument; + } + }); + options.add(new Option(Main.SIGALG_OPT, + Messages.getString("CertReqCmd.20"), //$NON-NLS-1$ + Messages.getString("CertReqCmd.19")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _sigAlgorithm = argument; + } + }); + options.add(new Option(Main.FILE_OPT, + Messages.getString("CertReqCmd.18"), //$NON-NLS-1$ + Messages.getString("CertReqCmd.17")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _certReqFileName = argument; + } + }); + options.add(new Option(Main.KEYPASS_OPT, + Messages.getString("CertReqCmd.16"), //$NON-NLS-1$ + Messages.getString("CertReqCmd.9")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _password = argument; + } + }); + options.add(new Option(Main.STORETYPE_OPT, + Messages.getString("CertReqCmd.14"), //$NON-NLS-1$ + Messages.getString("CertReqCmd.13")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _ksType = argument; + } + }); + options.add(new Option(Main.KEYSTORE_OPT, + Messages.getString("CertReqCmd.12"), //$NON-NLS-1$ + Messages.getString("CertReqCmd.11")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _ksURL = argument; + } + }); + options.add(new Option(Main.STOREPASS_OPT, + Messages.getString("CertReqCmd.10"), //$NON-NLS-1$ + Messages.getString("CertReqCmd.9")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _ksPassword = argument; + } + }); + options.add(new Option(Main.PROVIDER_OPT, + Messages.getString("CertReqCmd.8"), //$NON-NLS-1$ + Messages.getString("CertReqCmd.7")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _providerClassName = argument; + } + }); + options.add(new Option(Main.VERBOSE_OPT, + Messages.getString("CertReqCmd.6")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + verbose = true; + } + }); + options.add(new Option(ATTRIBUTES_OPT, + Messages.getString("CertReqCmd.5")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + nullAttributes = true; + } + }); + result.add(options); + + log.exiting(this.getClass().getName(), "getParser", result); //$NON-NLS-1$ + return result; + } + /** * @param aliasName * @param publicKey diff --git a/tools/gnu/classpath/tools/keytool/Command.java b/tools/gnu/classpath/tools/keytool/Command.java index a59614644..f1f79d5e4 100644 --- a/tools/gnu/classpath/tools/keytool/Command.java +++ b/tools/gnu/classpath/tools/keytool/Command.java @@ -42,6 +42,7 @@ import gnu.classpath.SystemProperties; import gnu.classpath.tools.common.CallbackUtil; import gnu.classpath.tools.common.ProviderUtil; import gnu.classpath.tools.common.SecurityProviderInfo; +import gnu.classpath.tools.getopt.Parser; import gnu.java.security.OID; import gnu.java.security.Registry; import gnu.java.security.der.BitString; @@ -228,11 +229,18 @@ abstract class Command * * @param args an array of options for this handler and possibly other * commands and their options. - * @param startIndex the index of the first argument in <code>args</code> to - * process. - * @return the index of the first unprocessed argument in <code>args</code>. + * @return the remaining un-processed <code>args</code>. */ - abstract int processArgs(String[] args, int startIndex); + String[] processArgs(String[] args) + { + log.entering(this.getClass().getName(), "processArgs", args); //$NON-NLS-1$ + + Parser cmdOptionsParser = getParser(); + String[] result = cmdOptionsParser.parse(args); + + log.exiting(this.getClass().getName(), "processArgs", result); //$NON-NLS-1$ + return result; + } /** * Initialize this concrete command handler for later invocation of the @@ -346,6 +354,12 @@ abstract class Command // parameter setup and validation methods ----------------------------------- /** + * @return a {@link Parser} that knows how to parse the concrete command's + * options. + */ + abstract Parser getParser(); + + /** * Convenience method to setup the key store given its type, its password, its * location and portentially a specialized security provider. * diff --git a/tools/gnu/classpath/tools/keytool/DeleteCmd.java b/tools/gnu/classpath/tools/keytool/DeleteCmd.java index 968af50f8..8b07b3dcc 100644 --- a/tools/gnu/classpath/tools/keytool/DeleteCmd.java +++ b/tools/gnu/classpath/tools/keytool/DeleteCmd.java @@ -38,6 +38,12 @@ exception statement from your version. */ package gnu.classpath.tools.keytool; +import gnu.classpath.tools.getopt.ClasspathToolParser; +import gnu.classpath.tools.getopt.Option; +import gnu.classpath.tools.getopt.OptionException; +import gnu.classpath.tools.getopt.OptionGroup; +import gnu.classpath.tools.getopt.Parser; + import java.io.IOException; import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; @@ -106,11 +112,11 @@ import javax.security.auth.callback.UnsupportedCallbackException; class DeleteCmd extends Command { private static final Logger log = Logger.getLogger(DeleteCmd.class.getName()); - private String _alias; - private String _ksType; - private String _ksURL; - private String _ksPassword; - private String _providerClassName; + protected String _alias; + protected String _ksType; + protected String _ksURL; + protected String _ksPassword; + protected String _providerClassName; // default 0-arguments constructor @@ -148,36 +154,6 @@ class DeleteCmd extends Command // life-cycle methods ------------------------------------------------------- - int processArgs(String[] args, int i) - { - int limit = args.length; - String opt; - while (++i < limit) - { - opt = args[i]; - log.finest("args[" + i + "]=" + opt); //$NON-NLS-1$ //$NON-NLS-2$ - if (opt == null || opt.length() == 0) - continue; - - if ("-alias".equals(opt)) // -alias ALIAS //$NON-NLS-1$ - _alias = args[++i]; - else if ("-storetype".equals(opt)) // -storetype STORE_TYPE //$NON-NLS-1$ - _ksType = args[++i]; - else if ("-keystore".equals(opt)) // -keystore URL //$NON-NLS-1$ - _ksURL = args[++i]; - else if ("-storepass".equals(opt)) // -storepass PASSWORD //$NON-NLS-1$ - _ksPassword = args[++i]; - else if ("-provider".equals(opt)) // -provider PROVIDER_CLASS_NAME //$NON-NLS-1$ - _providerClassName = args[++i]; - else if ("-v".equals(opt)) //$NON-NLS-1$ - verbose = true; - else - break; - } - - return i; - } - void setup() throws Exception { setKeyStoreParams(_providerClassName, _ksType, _ksPassword, _ksURL); @@ -206,6 +182,73 @@ class DeleteCmd extends Command // own methods -------------------------------------------------------------- + Parser getParser() + { + log.entering(this.getClass().getName(), "getParser"); //$NON-NLS-1$ + + Parser result = new ClasspathToolParser(Main.DELETE_CMD, true); + result.setHeader(Messages.getString("DeleteCmd.18")); //$NON-NLS-1$ + result.setFooter(Messages.getString("DeleteCmd.17")); //$NON-NLS-1$ + OptionGroup options = new OptionGroup(Messages.getString("DeleteCmd.16")); //$NON-NLS-1$ + options.add(new Option(Main.ALIAS_OPT, + Messages.getString("DeleteCmd.15"), //$NON-NLS-1$ + Messages.getString("DeleteCmd.14")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _alias = argument; + } + }); + options.add(new Option(Main.STORETYPE_OPT, + Messages.getString("DeleteCmd.13"), //$NON-NLS-1$ + Messages.getString("DeleteCmd.12")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _ksType = argument; + } + }); + options.add(new Option(Main.KEYSTORE_OPT, + Messages.getString("DeleteCmd.11"), //$NON-NLS-1$ + Messages.getString("DeleteCmd.10")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _ksURL = argument; + } + }); + options.add(new Option(Main.STOREPASS_OPT, + Messages.getString("DeleteCmd.9"), //$NON-NLS-1$ + Messages.getString("DeleteCmd.8")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _ksPassword = argument; + } + }); + options.add(new Option(Main.PROVIDER_OPT, + Messages.getString("DeleteCmd.7"), //$NON-NLS-1$ + Messages.getString("DeleteCmd.6")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _providerClassName = argument; + } + }); + options.add(new Option(Main.VERBOSE_OPT, + Messages.getString("DeleteCmd.5")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + verbose = true; + } + }); + result.add(options); + + log.exiting(this.getClass().getName(), "getParser", result); //$NON-NLS-1$ + return result; + } + /** * Set the alias to delete from the key store. * <p> diff --git a/tools/gnu/classpath/tools/keytool/ExportCmd.java b/tools/gnu/classpath/tools/keytool/ExportCmd.java index c1c0d4f83..1cb2e2e05 100644 --- a/tools/gnu/classpath/tools/keytool/ExportCmd.java +++ b/tools/gnu/classpath/tools/keytool/ExportCmd.java @@ -38,6 +38,11 @@ exception statement from your version. */ package gnu.classpath.tools.keytool; +import gnu.classpath.tools.getopt.ClasspathToolParser; +import gnu.classpath.tools.getopt.Option; +import gnu.classpath.tools.getopt.OptionException; +import gnu.classpath.tools.getopt.OptionGroup; +import gnu.classpath.tools.getopt.Parser; import gnu.java.security.util.Base64; import java.io.IOException; @@ -119,13 +124,13 @@ import java.util.logging.Logger; class ExportCmd extends Command { private static final Logger log = Logger.getLogger(ExportCmd.class.getName()); - private String _alias; - private String _certFileName; - private String _ksType; - private String _ksURL; - private String _ksPassword; - private String _providerClassName; - private boolean rfc; + protected String _alias; + protected String _certFileName; + protected String _ksType; + protected String _ksURL; + protected String _ksPassword; + protected String _providerClassName; + protected boolean rfc; // default 0-arguments constructor @@ -178,72 +183,38 @@ class ExportCmd extends Command // life-cycle methods ------------------------------------------------------- - int processArgs(String[] args, int i) - { - int limit = args.length; - String opt; - while (++i < limit) - { - opt = args[i]; - log.finest("args[" + i + "]=" + opt); - if (opt == null || opt.length() == 0) - continue; - - if ("-alias".equals(opt)) // -alias ALIAS - _alias = args[++i]; - else if ("-file".equals(opt)) // -file FILE_NAME - _certFileName = args[++i]; - else if ("-storetype".equals(opt)) // -storetype STORE_TYPE - _ksType = args[++i]; - else if ("-keystore".equals(opt)) // -keystore URL - _ksURL = args[++i]; - else if ("-storepass".equals(opt)) // -storepass PASSWORD - _ksPassword = args[++i]; - else if ("-provider".equals(opt)) // -provider PROVIDER_CLASS_NAME - _providerClassName = args[++i]; - else if ("-rfc".equals(opt)) - rfc = true; - else if ("-v".equals(opt)) - verbose = true; - else - break; - } - - return i; - } - void setup() throws Exception { setOutputStreamParam(_certFileName); setKeyStoreParams(_providerClassName, _ksType, _ksPassword, _ksURL); setAliasParam(_alias); - log.finer("-export handler will use the following options:"); - log.finer(" -alias=" + alias); - log.finer(" -file=" + _certFileName); - log.finer(" -storetype=" + storeType); - log.finer(" -keystore=" + storeURL); - log.finer(" -storepass=" + String.valueOf(storePasswordChars)); - log.finer(" -provider=" + provider); - log.finer(" -rfc=" + rfc); - log.finer(" -v=" + verbose); + log.finer("-export handler will use the following options:"); //$NON-NLS-1$ + log.finer(" -alias=" + alias); //$NON-NLS-1$ + log.finer(" -file=" + _certFileName); //$NON-NLS-1$ + log.finer(" -storetype=" + storeType); //$NON-NLS-1$ + log.finer(" -keystore=" + storeURL); //$NON-NLS-1$ + log.finer(" -storepass=" + String.valueOf(storePasswordChars)); //$NON-NLS-1$ + log.finer(" -provider=" + provider); //$NON-NLS-1$ + log.finer(" -rfc=" + rfc); //$NON-NLS-1$ + log.finer(" -v=" + verbose); //$NON-NLS-1$ } void start() throws KeyStoreException, CertificateEncodingException, IOException { - log.entering(this.getClass().getName(), "start"); + log.entering(this.getClass().getName(), "start"); //$NON-NLS-1$ ensureStoreContainsAlias(); Certificate certificate; if (store.isCertificateEntry(alias)) { - log.fine("Alias [" + alias + "] is a trusted certificate"); + log.finer("Alias [" + alias + "] is a trusted certificate"); //$NON-NLS-1$ //$NON-NLS-2$ certificate = store.getCertificate(alias); } else { - log.fine("Alias [" + alias + "] is a key entry"); + log.finer("Alias [" + alias + "] is a key entry"); //$NON-NLS-1$ //$NON-NLS-2$ Certificate[] chain = store.getCertificateChain(alias); certificate = chain[0]; } @@ -253,14 +224,100 @@ class ExportCmd extends Command { String encoded = Base64.encode(derBytes, 0, derBytes.length, true); PrintWriter pw = new PrintWriter(outStream, true); - pw.println("-----BEGIN CERTIFICATE-----"); + pw.println("-----BEGIN CERTIFICATE-----"); //$NON-NLS-1$ pw.println(encoded); - pw.println("-----END CERTIFICATE-----"); + pw.println("-----END CERTIFICATE-----"); //$NON-NLS-1$ } else outStream.write(derBytes); // stream is closed in Command.teardown() - log.exiting(this.getClass().getName(), "start"); + log.exiting(this.getClass().getName(), "start"); //$NON-NLS-1$ + } + + // own methods -------------------------------------------------------------- + + Parser getParser() + { + log.entering(this.getClass().getName(), "getParser"); //$NON-NLS-1$ + + Parser result = new ClasspathToolParser(Main.EXPORT_CMD, true); + result.setHeader(Messages.getString("ExportCmd.17")); //$NON-NLS-1$ + result.setFooter(Messages.getString("ExportCmd.18")); //$NON-NLS-1$ + OptionGroup options = new OptionGroup(Messages.getString("ExportCmd.19")); //$NON-NLS-1$ + options.add(new Option(Main.ALIAS_OPT, + Messages.getString("ExportCmd.20"), //$NON-NLS-1$ + Messages.getString("ExportCmd.21")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _alias = argument; + } + }); + options.add(new Option(Main.FILE_OPT, + Messages.getString("ExportCmd.22"), //$NON-NLS-1$ + Messages.getString("ExportCmd.23")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _certFileName = argument; + } + }); + options.add(new Option(Main.STORETYPE_OPT, + Messages.getString("ExportCmd.24"), //$NON-NLS-1$ + Messages.getString("ExportCmd.25")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _ksType = argument; + } + }); + options.add(new Option(Main.KEYSTORE_OPT, + Messages.getString("ExportCmd.26"), //$NON-NLS-1$ + Messages.getString("ExportCmd.27")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _ksURL = argument; + } + }); + options.add(new Option(Main.STOREPASS_OPT, + Messages.getString("ExportCmd.28"), //$NON-NLS-1$ + Messages.getString("ExportCmd.29")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _ksPassword = argument; + } + }); + options.add(new Option(Main.PROVIDER_OPT, + Messages.getString("ExportCmd.30"), //$NON-NLS-1$ + Messages.getString("ExportCmd.31")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _providerClassName = argument; + } + }); + options.add(new Option(Main.RFC_OPT, + Messages.getString("ExportCmd.32")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + rfc = true; + } + }); + options.add(new Option(Main.VERBOSE_OPT, + Messages.getString("ExportCmd.33")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + verbose = true; + } + }); + result.add(options); + + log.exiting(this.getClass().getName(), "getParser", result); //$NON-NLS-1$ + return result; } } diff --git a/tools/gnu/classpath/tools/keytool/GenKeyCmd.java b/tools/gnu/classpath/tools/keytool/GenKeyCmd.java index 2d92134c2..7d0eebe5d 100644 --- a/tools/gnu/classpath/tools/keytool/GenKeyCmd.java +++ b/tools/gnu/classpath/tools/keytool/GenKeyCmd.java @@ -38,6 +38,11 @@ exception statement from your version. */ package gnu.classpath.tools.keytool; +import gnu.classpath.tools.getopt.ClasspathToolParser; +import gnu.classpath.tools.getopt.Option; +import gnu.classpath.tools.getopt.OptionException; +import gnu.classpath.tools.getopt.OptionGroup; +import gnu.classpath.tools.getopt.Parser; import gnu.java.security.util.Util; import gnu.java.security.x509.X500DistinguishedName; @@ -198,19 +203,20 @@ class GenKeyCmd extends Command /** Default key size in bits. */ private static final int DEFAULT_KEY_SIZE = 1024; - private String _alias; - private String _keyAlgorithm; - private String _keySizeStr; - private String _sigAlgorithm; - private String _dName; - private String _password; - private String _validityStr; - private String _ksType; - private String _ksURL; - private String _ksPassword; - private String _providerClassName; + protected String _alias; + protected String _keyAlgorithm; + protected String _keySizeStr; + protected String _sigAlgorithm; + protected String _dName; + protected String _password; + protected String _validityStr; + protected String _ksType; + protected String _ksURL; + protected String _ksPassword; + protected String _providerClassName; private int keySize; private X500DistinguishedName distinguishedName; + private Parser cmdOptionsParser; // default 0-arguments constructor @@ -294,48 +300,6 @@ class GenKeyCmd extends Command // life-cycle methods ------------------------------------------------------- - int processArgs(String[] args, int i) - { - int limit = args.length; - String opt; - while (++i < limit) - { - opt = args[i]; - log.finest("args[" + i + "]=" + opt); //$NON-NLS-1$ //$NON-NLS-2$ - if (opt == null || opt.length() == 0) - continue; - - if ("-alias".equals(opt)) // -alias ALIAS //$NON-NLS-1$ - _alias = args[++i]; - else if ("-keyalg".equals(opt)) // -keyalg ALGORITHM //$NON-NLS-1$ - _keyAlgorithm = args[++i]; - else if ("-keysize".equals(opt)) // -keysize KEY_SIZE //$NON-NLS-1$ - _keySizeStr = args[++i]; - else if ("-sigalg".equals(opt)) // -sigalg ALGORITHM //$NON-NLS-1$ - _sigAlgorithm = args[++i]; - else if ("-dname".equals(opt)) // -dname NAME //$NON-NLS-1$ - _dName = args[++i]; - else if ("-keypass".equals(opt)) // -keypass PASSWORD //$NON-NLS-1$ - _password = args[++i]; - else if ("-validity".equals(opt)) // -validity DAY_COUNT //$NON-NLS-1$ - _validityStr = args[++i]; - else if ("-storetype".equals(opt)) // -storetype STORE_TYPE //$NON-NLS-1$ - _ksType = args[++i]; - else if ("-keystore".equals(opt)) // -keystore URL //$NON-NLS-1$ - _ksURL = args[++i]; - else if ("-storepass".equals(opt)) // -storepass PASSWORD //$NON-NLS-1$ - _ksPassword = args[++i]; - else if ("-provider".equals(opt)) // -provider PROVIDER_CLASS_NAME //$NON-NLS-1$ - _providerClassName = args[++i]; - else if ("-v".equals(opt)) //$NON-NLS-1$ - verbose = true; - else - break; - } - - return i; - } - void setup() throws Exception { setKeyStoreParams(_providerClassName, _ksType, _ksPassword, _ksURL); @@ -368,14 +332,14 @@ class GenKeyCmd extends Command log.entering(this.getClass().getName(), "start"); //$NON-NLS-1$ // 1. generate a new key-pair - log.fine("About to generate key-pair..."); + log.finer("About to generate key-pair..."); //$NON-NLS-1$ keyPairGenerator.initialize(keySize); KeyPair kp = keyPairGenerator.generateKeyPair(); PublicKey publicKey = kp.getPublic(); PrivateKey privateKey = kp.getPrivate(); // 2. generate a self-signed certificate - log.fine("About to generate a self-signed certificate..."); + log.finer("About to generate a self-signed certificate..."); //$NON-NLS-1$ byte[] derBytes = getSelfSignedCertificate(distinguishedName, publicKey, privateKey); @@ -398,6 +362,127 @@ class GenKeyCmd extends Command // own methods -------------------------------------------------------------- + Parser getParser() + { + log.entering(this.getClass().getName(), "getParser"); //$NON-NLS-1$ + + Parser result = new ClasspathToolParser(Main.GENKEY_CMD, true); + result.setHeader(Messages.getString("GenKeyCmd.57")); //$NON-NLS-1$ + result.setFooter(Messages.getString("GenKeyCmd.58")); //$NON-NLS-1$ + OptionGroup options = new OptionGroup(Messages.getString("GenKeyCmd.59")); //$NON-NLS-1$ + options.add(new Option(Main.ALIAS_OPT, + Messages.getString("GenKeyCmd.60"), //$NON-NLS-1$ + Messages.getString("GenKeyCmd.61")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _alias = argument; + } + }); + options.add(new Option(Main.KEYALG_OPT, + Messages.getString("GenKeyCmd.62"), //$NON-NLS-1$ + Messages.getString("GenKeyCmd.63")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _keyAlgorithm = argument; + } + }); + options.add(new Option(Main.KEYSIZE_OPT, + Messages.getString("GenKeyCmd.64"), //$NON-NLS-1$ + Messages.getString("GenKeyCmd.65")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _keySizeStr = argument; + } + }); + options.add(new Option(Main.SIGALG_OPT, + Messages.getString("GenKeyCmd.66"), //$NON-NLS-1$ + Messages.getString("GenKeyCmd.63")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _sigAlgorithm = argument; + } + }); + options.add(new Option(Main.DNAME_OPT, + Messages.getString("GenKeyCmd.68"), //$NON-NLS-1$ + Messages.getString("GenKeyCmd.69")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _dName = argument; + } + }); + options.add(new Option(Main.KEYPASS_OPT, + Messages.getString("GenKeyCmd.70"), //$NON-NLS-1$ + Messages.getString("GenKeyCmd.71")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _password = argument; + } + }); + options.add(new Option(Main.VALIDITY_OPT, + Messages.getString("GenKeyCmd.72"), //$NON-NLS-1$ + Messages.getString("GenKeyCmd.73")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _validityStr = argument; + } + }); + options.add(new Option(Main.STORETYPE_OPT, + Messages.getString("GenKeyCmd.74"), //$NON-NLS-1$ + Messages.getString("GenKeyCmd.75")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _ksType = argument; + } + }); + options.add(new Option(Main.KEYSTORE_OPT, + Messages.getString("GenKeyCmd.76"), //$NON-NLS-1$ + Messages.getString("GenKeyCmd.77")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _ksURL = argument; + } + }); + options.add(new Option(Main.STOREPASS_OPT, + Messages.getString("GenKeyCmd.78"), //$NON-NLS-1$ + Messages.getString("GenKeyCmd.71")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _ksPassword = argument; + } + }); + options.add(new Option(Main.PROVIDER_OPT, + Messages.getString("GenKeyCmd.80"), //$NON-NLS-1$ + Messages.getString("GenKeyCmd.81")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _providerClassName = argument; + } + }); + options.add(new Option(Main.VERBOSE_OPT, + Messages.getString("GenKeyCmd.82")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + verbose = true; + } + }); + result.add(options); + + log.exiting(this.getClass().getName(), "getParser", result); //$NON-NLS-1$ + return result; + } + /** * @param size the desired key size as a string. * @throws NumberFormatException if the string does not represent a valid diff --git a/tools/gnu/classpath/tools/keytool/IdentityDBCmd.java b/tools/gnu/classpath/tools/keytool/IdentityDBCmd.java index cb6b6dac2..b584e06db 100644 --- a/tools/gnu/classpath/tools/keytool/IdentityDBCmd.java +++ b/tools/gnu/classpath/tools/keytool/IdentityDBCmd.java @@ -38,6 +38,12 @@ exception statement from your version. */ package gnu.classpath.tools.keytool; +import gnu.classpath.tools.getopt.ClasspathToolParser; +import gnu.classpath.tools.getopt.Option; +import gnu.classpath.tools.getopt.OptionException; +import gnu.classpath.tools.getopt.OptionGroup; +import gnu.classpath.tools.getopt.Parser; + import java.util.logging.Logger; /** @@ -97,11 +103,11 @@ import java.util.logging.Logger; class IdentityDBCmd extends Command { private static final Logger log = Logger.getLogger(IdentityDBCmd.class.getName()); - private String _idbFileName; - private String _ksType; - private String _ksURL; - private String _ksPassword; - private String _providerClassName; + protected String _idbFileName; + protected String _ksType; + protected String _ksURL; + protected String _ksPassword; + protected String _providerClassName; // default 0-arguments constructor @@ -139,47 +145,86 @@ class IdentityDBCmd extends Command // life-cycle methods ------------------------------------------------------- - int processArgs(String[] args, int i) + void setup() throws Exception { - int limit = args.length; - String opt; - while (++i < limit) - { - opt = args[i]; - log.finest("args[" + i + "]=" + opt); - if (opt == null || opt.length() == 0) - continue; - - if ("-file".equals(opt)) // -file FILE_NAME - _idbFileName = args[++i]; - else if ("-storetype".equals(opt)) // -storetype STORE_TYPE - _ksType = args[++i]; - else if ("-keystore".equals(opt)) // -keystore URL - _ksURL = args[++i]; - else if ("-storepass".equals(opt)) // -storepass PASSWORD - _ksPassword = args[++i]; - else if ("-provider".equals(opt)) // -provider PROVIDER_CLASS_NAME - _providerClassName = args[++i]; - else if ("-v".equals(opt)) - verbose = true; - else - break; - } + setInputStreamParam(_idbFileName); + setKeyStoreParams(_providerClassName, _ksType, _ksPassword, _ksURL); - return i; + log.finer("-identitydb handler will use the following options:"); //$NON-NLS-1$ + log.finer(" -file=" + _idbFileName); //$NON-NLS-1$ + log.finer(" -storetype=" + storeType); //$NON-NLS-1$ + log.finer(" -keystore=" + storeURL); //$NON-NLS-1$ + log.finer(" -storepass=" + new String(storePasswordChars)); //$NON-NLS-1$ + log.finer(" -provider=" + provider); //$NON-NLS-1$ + log.finer(" -v=" + verbose); //$NON-NLS-1$ } - void setup() throws Exception + // own methods -------------------------------------------------------------- + + Parser getParser() { - setInputStreamParam(_idbFileName); - setKeyStoreParams(_providerClassName, _ksType, _ksPassword, _ksURL); + log.entering(this.getClass().getName(), "getParser"); //$NON-NLS-1$ + + Parser result = new ClasspathToolParser(Main.IDENTITYDB_CMD, true); + result.setHeader(Messages.getString("IdentityDBCmd.7")); //$NON-NLS-1$ + result.setFooter(Messages.getString("IdentityDBCmd.8")); //$NON-NLS-1$ + OptionGroup options = new OptionGroup(Messages.getString("IdentityDBCmd.9")); //$NON-NLS-1$ + options.add(new Option(Main.FILE_OPT, + Messages.getString("IdentityDBCmd.10"), //$NON-NLS-1$ + Messages.getString("IdentityDBCmd.11")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _idbFileName = argument; + } + }); + options.add(new Option(Main.STORETYPE_OPT, + Messages.getString("IdentityDBCmd.12"), //$NON-NLS-1$ + Messages.getString("IdentityDBCmd.13")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _ksType = argument; + } + }); + options.add(new Option(Main.KEYSTORE_OPT, + Messages.getString("IdentityDBCmd.14"), //$NON-NLS-1$ + Messages.getString("IdentityDBCmd.15")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _ksURL = argument; + } + }); + options.add(new Option(Main.STOREPASS_OPT, + Messages.getString("IdentityDBCmd.16"), //$NON-NLS-1$ + Messages.getString("IdentityDBCmd.17")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _ksPassword = argument; + } + }); + options.add(new Option(Main.PROVIDER_OPT, + Messages.getString("IdentityDBCmd.18"), //$NON-NLS-1$ + Messages.getString("IdentityDBCmd.19")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _providerClassName = argument; + } + }); + options.add(new Option(Main.VERBOSE_OPT, + Messages.getString("IdentityDBCmd.20")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + verbose = true; + } + }); + result.add(options); - log.finer("-identitydb handler will use the following options:"); - log.finer(" -file=" + _idbFileName); - log.finer(" -storetype=" + storeType); - log.finer(" -keystore=" + storeURL); - log.finer(" -storepass=" + new String(storePasswordChars)); - log.finer(" -provider=" + provider); - log.finer(" -v=" + verbose); + log.exiting(this.getClass().getName(), "getParser", result); //$NON-NLS-1$ + return result; } } diff --git a/tools/gnu/classpath/tools/keytool/ImportCmd.java b/tools/gnu/classpath/tools/keytool/ImportCmd.java index b5058b581..70bf49f01 100644 --- a/tools/gnu/classpath/tools/keytool/ImportCmd.java +++ b/tools/gnu/classpath/tools/keytool/ImportCmd.java @@ -39,6 +39,11 @@ exception statement from your version. */ package gnu.classpath.tools.keytool; import gnu.classpath.SystemProperties; +import gnu.classpath.tools.getopt.ClasspathToolParser; +import gnu.classpath.tools.getopt.Option; +import gnu.classpath.tools.getopt.OptionException; +import gnu.classpath.tools.getopt.OptionGroup; +import gnu.classpath.tools.getopt.Parser; import gnu.java.security.x509.X509CertPath; import java.io.FileInputStream; @@ -181,15 +186,15 @@ import javax.security.auth.callback.UnsupportedCallbackException; class ImportCmd extends Command { private static final Logger log = Logger.getLogger(ImportCmd.class.getName()); - private String _alias; - private String _certFileName; - private String _password; - private boolean noPrompt; - private boolean trustCACerts; - private String _ksType; - private String _ksURL; - private String _ksPassword; - private String _providerClassName; + protected String _alias; + protected String _certFileName; + protected String _password; + protected boolean noPrompt; + protected boolean trustCACerts; + protected String _ksType; + protected String _ksURL; + protected String _ksPassword; + protected String _providerClassName; private CertificateFactory x509Factory; private boolean imported; @@ -259,44 +264,6 @@ class ImportCmd extends Command // life-cycle methods ------------------------------------------------------- - int processArgs(String[] args, int i) - { - int limit = args.length; - String opt; - while (++i < limit) - { - opt = args[i]; - log.finest("args[" + i + "]=" + opt); //$NON-NLS-1$ //$NON-NLS-2$ - if (opt == null || opt.length() == 0) - continue; - - if ("-alias".equals(opt)) // -alias ALIAS //$NON-NLS-1$ - _alias = args[++i]; - else if ("-file".equals(opt)) // -file FILE_NAME //$NON-NLS-1$ - _certFileName = args[++i]; - else if ("-keypass".equals(opt)) // -keypass PASSWORD //$NON-NLS-1$ - _password = args[++i]; - else if ("-noprompt".equals(opt)) //$NON-NLS-1$ - noPrompt = true; - else if ("-trustcacerts".equals(opt)) //$NON-NLS-1$ - trustCACerts = true; - else if ("-storetype".equals(opt)) // -storetype STORE_TYPE //$NON-NLS-1$ - _ksType = args[++i]; - else if ("-keystore".equals(opt)) // -keystore URL //$NON-NLS-1$ - _ksURL = args[++i]; - else if ("-storepass".equals(opt)) // -storepass PASSWORD //$NON-NLS-1$ - _ksPassword = args[++i]; - else if ("-provider".equals(opt)) // -provider PROVIDER_CLASS_NAME //$NON-NLS-1$ - _providerClassName = args[++i]; - else if ("-v".equals(opt)) //$NON-NLS-1$ - verbose = true; - else - break; - } - - return i; - } - void setup() throws Exception { setInputStreamParam(_certFileName); @@ -339,6 +306,107 @@ class ImportCmd extends Command // own methods -------------------------------------------------------------- + Parser getParser() + { + log.entering(this.getClass().getName(), "getParser"); //$NON-NLS-1$ + + Parser result = new ClasspathToolParser(Main.IMPORT_CMD, true); + result.setHeader(Messages.getString("ImportCmd.27")); //$NON-NLS-1$ + result.setFooter(Messages.getString("ImportCmd.26")); //$NON-NLS-1$ + OptionGroup options = new OptionGroup(Messages.getString("ImportCmd.25")); //$NON-NLS-1$ + options.add(new Option(Main.ALIAS_OPT, + Messages.getString("ImportCmd.24"), //$NON-NLS-1$ + Messages.getString("ImportCmd.23")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _alias = argument; + } + }); + options.add(new Option(Main.FILE_OPT, + Messages.getString("ImportCmd.22"), //$NON-NLS-1$ + Messages.getString("ImportCmd.21")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _certFileName = argument; + } + }); + options.add(new Option(Main.KEYPASS_OPT, + Messages.getString("ImportCmd.20"), //$NON-NLS-1$ + Messages.getString("ImportCmd.19")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _password = argument; + } + }); + options.add(new Option("noprompt", //$NON-NLS-1$ + Messages.getString("ImportCmd.18")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + noPrompt = true; + } + }); + options.add(new Option("trustcacerts", //$NON-NLS-1$ + Messages.getString("ImportCmd.17")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + trustCACerts = true; + } + }); + options.add(new Option(Main.STORETYPE_OPT, + Messages.getString("ImportCmd.16"), //$NON-NLS-1$ + Messages.getString("ImportCmd.15")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _ksType = argument; + } + }); + options.add(new Option(Main.KEYSTORE_OPT, + Messages.getString("ImportCmd.14"), //$NON-NLS-1$ + Messages.getString("ImportCmd.13")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _ksURL = argument; + } + }); + options.add(new Option(Main.STOREPASS_OPT, + Messages.getString("ImportCmd.12"), //$NON-NLS-1$ + Messages.getString("ImportCmd.11")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _ksPassword = argument; + } + }); + options.add(new Option(Main.PROVIDER_OPT, + Messages.getString("ImportCmd.10"), //$NON-NLS-1$ + Messages.getString("ImportCmd.9")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _providerClassName = argument; + } + }); + options.add(new Option(Main.VERBOSE_OPT, + Messages.getString("ImportCmd.8")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + verbose = true; + } + }); + result.add(options); + + log.exiting(this.getClass().getName(), "getParser", result); //$NON-NLS-1$ + return result; + } + /** * When importing a new trusted certificate, <i>alias</i> MUST NOT yet exist * in the key store. @@ -715,7 +783,7 @@ class ImportCmd extends Command try { KeyStore cacerts = KeyStore.getInstance("jks"); //$NON-NLS-1$ - String cacertsPath = SystemProperties.getProperty("java.home"); + String cacertsPath = SystemProperties.getProperty("java.home"); //$NON-NLS-1$ String fs = SystemProperties.getProperty("file.separator"); //$NON-NLS-1$ cacertsPath = new StringBuilder(cacertsPath).append(fs) .append("lib").append(fs) //$NON-NLS-1$ diff --git a/tools/gnu/classpath/tools/keytool/KeyCloneCmd.java b/tools/gnu/classpath/tools/keytool/KeyCloneCmd.java index 5936719f7..924cbcf3c 100644 --- a/tools/gnu/classpath/tools/keytool/KeyCloneCmd.java +++ b/tools/gnu/classpath/tools/keytool/KeyCloneCmd.java @@ -38,6 +38,12 @@ exception statement from your version. */ package gnu.classpath.tools.keytool; +import gnu.classpath.tools.getopt.ClasspathToolParser; +import gnu.classpath.tools.getopt.Option; +import gnu.classpath.tools.getopt.OptionException; +import gnu.classpath.tools.getopt.OptionGroup; +import gnu.classpath.tools.getopt.Parser; + import java.io.IOException; import java.security.Key; import java.security.KeyStoreException; @@ -132,14 +138,14 @@ import javax.security.auth.callback.UnsupportedCallbackException; class KeyCloneCmd extends Command { private static final Logger log = Logger.getLogger(KeyCloneCmd.class.getName()); - private String _alias; - private String _destAlias; - private String _password; - private String _newPassword; - private String _ksType; - private String _ksURL; - private String _ksPassword; - private String _providerClassName; + protected String _alias; + protected String _destAlias; + protected String _password; + protected String _newPassword; + protected String _ksType; + protected String _ksURL; + protected String _ksPassword; + protected String _providerClassName; private String destinationAlias; private char[] newKeyPasswordChars; @@ -197,42 +203,6 @@ class KeyCloneCmd extends Command // life-cycle methods ------------------------------------------------------- - int processArgs(String[] args, int i) - { - int limit = args.length; - String opt; - while (++i < limit) - { - opt = args[i]; - log.finest("args[" + i + "]=" + opt); //$NON-NLS-1$ //$NON-NLS-2$ - if (opt == null || opt.length() == 0) - continue; - - if ("-alias".equals(opt)) // -alias ALIAS //$NON-NLS-1$ - _alias = args[++i]; - else if ("-dest".equals(opt)) // -dest ALIAS //$NON-NLS-1$ - _destAlias = args[++i]; - else if ("-keypass".equals(opt)) // -keypass PASSWORD //$NON-NLS-1$ - _password = args[++i]; - else if ("-new".equals(opt)) // -new PASSWORD //$NON-NLS-1$ - _newPassword = args[++i]; - else if ("-storetype".equals(opt)) // -storetype STORE_TYPE //$NON-NLS-1$ - _ksType = args[++i]; - else if ("-keystore".equals(opt)) // -keystore URL //$NON-NLS-1$ - _ksURL = args[++i]; - else if ("-storepass".equals(opt)) // -storepass PASSWORD //$NON-NLS-1$ - _ksPassword = args[++i]; - else if ("-provider".equals(opt)) // -provider PROVIDER_CLASS_NAME //$NON-NLS-1$ - _providerClassName = args[++i]; - else if ("-v".equals(opt)) //$NON-NLS-1$ - verbose = true; - else - break; - } - - return i; - } - void setup() throws Exception { setKeyStoreParams(_providerClassName, _ksType, _ksPassword, _ksURL); @@ -276,6 +246,100 @@ class KeyCloneCmd extends Command // own methods -------------------------------------------------------------- + Parser getParser() + { + log.entering(this.getClass().getName(), "getParser"); //$NON-NLS-1$ + + Parser result = new ClasspathToolParser(Main.KEYCLONE_CMD, true); + result.setHeader(Messages.getString("KeyCloneCmd.22")); //$NON-NLS-1$ + result.setFooter(Messages.getString("KeyCloneCmd.21")); //$NON-NLS-1$ + OptionGroup options = new OptionGroup(Messages.getString("KeyCloneCmd.20")); //$NON-NLS-1$ + options.add(new Option(Main.ALIAS_OPT, + Messages.getString("KeyCloneCmd.19"), //$NON-NLS-1$ + Messages.getString("KeyCloneCmd.16")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _alias = argument; + } + }); + options.add(new Option(Main.DEST_OPT, + Messages.getString("KeyCloneCmd.17"), //$NON-NLS-1$ + Messages.getString("KeyCloneCmd.16")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _destAlias = argument; + } + }); + options.add(new Option(Main.KEYPASS_OPT, + Messages.getString("KeyCloneCmd.15"), //$NON-NLS-1$ + Messages.getString("KeyCloneCmd.6")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _password = argument; + } + }); + options.add(new Option(Main.NEW_OPT, + Messages.getString("KeyCloneCmd.13"), //$NON-NLS-1$ + Messages.getString("KeyCloneCmd.6")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _newPassword = argument; + } + }); + options.add(new Option(Main.STORETYPE_OPT, + Messages.getString("KeyCloneCmd.11"), //$NON-NLS-1$ + Messages.getString("KeyCloneCmd.10")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _ksType = argument; + } + }); + options.add(new Option(Main.KEYSTORE_OPT, + Messages.getString("KeyCloneCmd.9"), //$NON-NLS-1$ + Messages.getString("KeyCloneCmd.8")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _ksURL = argument; + } + }); + options.add(new Option(Main.STOREPASS_OPT, + Messages.getString("KeyCloneCmd.7"), //$NON-NLS-1$ + Messages.getString("KeyCloneCmd.6")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _ksPassword = argument; + } + }); + options.add(new Option(Main.PROVIDER_OPT, + Messages.getString("KeyCloneCmd.5"), //$NON-NLS-1$ + Messages.getString("KeyCloneCmd.4")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _providerClassName = argument; + } + }); + options.add(new Option(Main.VERBOSE_OPT, + Messages.getString("KeyCloneCmd.3")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + verbose = true; + } + }); + result.add(options); + + log.exiting(this.getClass().getName(), "getParser", result); //$NON-NLS-1$ + return result; + } + private void setDestinationAlias(String name) throws IOException, UnsupportedCallbackException { @@ -294,9 +358,9 @@ class KeyCloneCmd extends Command private void setNewKeyPassword(String password) throws IOException, UnsupportedCallbackException { - if (password != null) // ask user to provide one + if (password != null) newKeyPasswordChars = password.toCharArray(); - else + else // ask user to provide one { boolean ok = false; Callback[] prompts = new Callback[1]; diff --git a/tools/gnu/classpath/tools/keytool/KeyPasswdCmd.java b/tools/gnu/classpath/tools/keytool/KeyPasswdCmd.java index 9dc7b8164..58197a3ab 100644 --- a/tools/gnu/classpath/tools/keytool/KeyPasswdCmd.java +++ b/tools/gnu/classpath/tools/keytool/KeyPasswdCmd.java @@ -39,6 +39,11 @@ exception statement from your version. */ package gnu.classpath.tools.keytool; import gnu.classpath.SystemProperties; +import gnu.classpath.tools.getopt.ClasspathToolParser; +import gnu.classpath.tools.getopt.Option; +import gnu.classpath.tools.getopt.OptionException; +import gnu.classpath.tools.getopt.OptionGroup; +import gnu.classpath.tools.getopt.Parser; import java.io.IOException; import java.security.Key; @@ -128,13 +133,13 @@ import javax.security.auth.callback.UnsupportedCallbackException; class KeyPasswdCmd extends Command { private static final Logger log = Logger.getLogger(KeyPasswdCmd.class.getName()); - private String _alias; - private String _password; - private String _newPassword; - private String _ksType; - private String _ksURL; - private String _ksPassword; - private String _providerClassName; + protected String _alias; + protected String _password; + protected String _newPassword; + protected String _ksType; + protected String _ksURL; + protected String _ksPassword; + protected String _providerClassName; private char[] newPasswordChars; // default 0-arguments constructor @@ -185,40 +190,6 @@ class KeyPasswdCmd extends Command // life-cycle methods ------------------------------------------------------- - int processArgs(String[] args, int i) - { - int limit = args.length; - String opt; - while (++i < limit) - { - opt = args[i]; - log.finest("args[" + i + "]=" + opt); //$NON-NLS-1$ //$NON-NLS-2$ - if (opt == null || opt.length() == 0) - continue; - - if ("-alias".equals(opt)) // -alias ALIAS //$NON-NLS-1$ - _alias = args[++i]; - else if ("-keypass".equals(opt)) // -keypass PASSWORD //$NON-NLS-1$ - _password = args[++i]; - else if ("-new".equals(opt)) // -new PASSWORD //$NON-NLS-1$ - _newPassword = args[++i]; - else if ("-storetype".equals(opt)) // -storetype STORE_TYPE //$NON-NLS-1$ - _ksType = args[++i]; - else if ("-keystore".equals(opt)) // -keystore URL //$NON-NLS-1$ - _ksURL = args[++i]; - else if ("-storepass".equals(opt)) // -storepass PASSWORD //$NON-NLS-1$ - _ksPassword = args[++i]; - else if ("-provider".equals(opt)) // -provider PROVIDER_CLASS_NAME //$NON-NLS-1$ - _providerClassName = args[++i]; - else if ("-v".equals(opt)) //$NON-NLS-1$ - verbose = true; - else - break; - } - - return i; - } - void setup() throws Exception { setKeyStoreParams(_providerClassName, _ksType, _ksPassword, _ksURL); @@ -259,6 +230,91 @@ class KeyPasswdCmd extends Command // own methods -------------------------------------------------------------- + Parser getParser() + { + log.entering(this.getClass().getName(), "getParser"); //$NON-NLS-1$ + + Parser result = new ClasspathToolParser(Main.KEYPASSWD_CMD, true); + result.setHeader(Messages.getString("KeyPasswdCmd.23")); //$NON-NLS-1$ + result.setFooter(Messages.getString("KeyPasswdCmd.22")); //$NON-NLS-1$ + OptionGroup options = new OptionGroup(Messages.getString("KeyPasswdCmd.21")); //$NON-NLS-1$ + options.add(new Option(Main.ALIAS_OPT, + Messages.getString("KeyPasswdCmd.20"), //$NON-NLS-1$ + Messages.getString("KeyPasswdCmd.19")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _alias = argument; + } + }); + options.add(new Option(Main.KEYPASS_OPT, + Messages.getString("KeyPasswdCmd.18"), //$NON-NLS-1$ + Messages.getString("KeyPasswdCmd.9")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _password = argument; + } + }); + options.add(new Option(Main.NEW_OPT, + Messages.getString("KeyPasswdCmd.16"), //$NON-NLS-1$ + Messages.getString("KeyPasswdCmd.9")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _newPassword = argument; + } + }); + options.add(new Option(Main.STORETYPE_OPT, + Messages.getString("KeyPasswdCmd.14"), //$NON-NLS-1$ + Messages.getString("KeyPasswdCmd.13")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _ksType = argument; + } + }); + options.add(new Option(Main.KEYSTORE_OPT, + Messages.getString("KeyPasswdCmd.12"), //$NON-NLS-1$ + Messages.getString("KeyPasswdCmd.11")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _ksURL = argument; + } + }); + options.add(new Option(Main.STOREPASS_OPT, + Messages.getString("KeyPasswdCmd.10"), //$NON-NLS-1$ + Messages.getString("KeyPasswdCmd.9")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _ksPassword = argument; + } + }); + options.add(new Option(Main.PROVIDER_OPT, + Messages.getString("KeyPasswdCmd.8"), //$NON-NLS-1$ + Messages.getString("KeyPasswdCmd.7")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _providerClassName = argument; + } + }); + options.add(new Option(Main.VERBOSE_OPT, + Messages.getString("KeyPasswdCmd.6")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + verbose = true; + } + }); + result.add(options); + + log.exiting(this.getClass().getName(), "getParser", result); //$NON-NLS-1$ + return result; + } + /** * Set the new password to use for protecting Alias's private key. * diff --git a/tools/gnu/classpath/tools/keytool/ListCmd.java b/tools/gnu/classpath/tools/keytool/ListCmd.java index 655242785..4f6f47185 100644 --- a/tools/gnu/classpath/tools/keytool/ListCmd.java +++ b/tools/gnu/classpath/tools/keytool/ListCmd.java @@ -38,6 +38,11 @@ exception statement from your version. */ package gnu.classpath.tools.keytool; +import gnu.classpath.tools.getopt.ClasspathToolParser; +import gnu.classpath.tools.getopt.Option; +import gnu.classpath.tools.getopt.OptionException; +import gnu.classpath.tools.getopt.OptionGroup; +import gnu.classpath.tools.getopt.Parser; import gnu.java.security.util.Base64; import java.io.IOException; @@ -113,11 +118,11 @@ import java.util.logging.Logger; class ListCmd extends Command { private static final Logger log = Logger.getLogger(ListCmd.class.getName()); - private String _alias; - private String _ksType; - private String _ksURL; - private String _ksPassword; - private String _providerClassName; + protected String _alias; + protected String _ksType; + protected String _ksURL; + protected String _ksPassword; + protected String _providerClassName; private boolean rfc; private boolean all; @@ -166,44 +171,11 @@ class ListCmd extends Command // life-cycle methods ------------------------------------------------------- - int processArgs(String[] args, int i) - { - int limit = args.length; - String opt; - while (++i < limit) - { - opt = args[i]; - log.finest("args[" + i + "]=" + opt); //$NON-NLS-1$ //$NON-NLS-2$ - if (opt == null || opt.length() == 0) - continue; - - if ("-alias".equals(opt)) // -alias ALIAS //$NON-NLS-1$ - _alias = args[++i]; - else if ("-storetype".equals(opt)) // -storetype STORE_TYPE //$NON-NLS-1$ - _ksType = args[++i]; - else if ("-keystore".equals(opt)) // -keystore URL //$NON-NLS-1$ - _ksURL = args[++i]; - else if ("-storepass".equals(opt)) // -storepass PASSWORD //$NON-NLS-1$ - _ksPassword = args[++i]; - else if ("-provider".equals(opt)) // -provider PROVIDER_CLASS_NAME //$NON-NLS-1$ - _providerClassName = args[++i]; - else if ("-v".equals(opt)) //$NON-NLS-1$ - verbose = true; - else if ("-rfc".equals(opt)) //$NON-NLS-1$ - rfc = true; - else - break; - } - - all = _alias == null; - - return i; - } - void setup() throws Exception { setOutputStreamParam(null); // use stdout setKeyStoreParams(_providerClassName, _ksType, _ksPassword, _ksURL); + all = _alias == null; if (! all) setAliasParam(_alias); @@ -254,6 +226,81 @@ class ListCmd extends Command // own methods -------------------------------------------------------------- + Parser getParser() + { + log.entering(this.getClass().getName(), "getParser"); //$NON-NLS-1$ + + Parser result = new ClasspathToolParser(Main.LIST_CMD, true); + result.setHeader(Messages.getString("ListCmd.20")); //$NON-NLS-1$ + result.setFooter(Messages.getString("ListCmd.19")); //$NON-NLS-1$ + OptionGroup options = new OptionGroup(Messages.getString("ListCmd.18")); //$NON-NLS-1$ + options.add(new Option(Main.ALIAS_OPT, + Messages.getString("ListCmd.17"), //$NON-NLS-1$ + Messages.getString("ListCmd.16")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _alias = argument; + } + }); + options.add(new Option(Main.STORETYPE_OPT, + Messages.getString("ListCmd.15"), //$NON-NLS-1$ + Messages.getString("ListCmd.14")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _ksType = argument; + } + }); + options.add(new Option(Main.KEYSTORE_OPT, + Messages.getString("ListCmd.13"), //$NON-NLS-1$ + Messages.getString("ListCmd.12")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _ksURL = argument; + } + }); + options.add(new Option(Main.STOREPASS_OPT, + Messages.getString("ListCmd.11"), //$NON-NLS-1$ + Messages.getString("ListCmd.10")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _ksPassword = argument; + } + }); + options.add(new Option(Main.PROVIDER_OPT, + Messages.getString("ListCmd.9"), //$NON-NLS-1$ + Messages.getString("ListCmd.8")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _providerClassName = argument; + } + }); + options.add(new Option(Main.VERBOSE_OPT, + Messages.getString("ListCmd.7")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + verbose = true; + } + }); + options.add(new Option(Main.RFC_OPT, + Messages.getString("ListCmd.6")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + verbose = true; + } + }); + result.add(options); + + log.exiting(this.getClass().getName(), "getParser", result); //$NON-NLS-1$ + return result; + } + /** * Prints the certificate(s) associated with the designated alias. * diff --git a/tools/gnu/classpath/tools/keytool/Main.java b/tools/gnu/classpath/tools/keytool/Main.java index fb7aa4509..582aba082 100644 --- a/tools/gnu/classpath/tools/keytool/Main.java +++ b/tools/gnu/classpath/tools/keytool/Main.java @@ -38,8 +38,12 @@ exception statement from your version. */ package gnu.classpath.tools.keytool; -import gnu.classpath.tools.HelpPrinter; import gnu.classpath.tools.common.ProviderUtil; +import gnu.classpath.tools.getopt.ClasspathToolParser; +import gnu.classpath.tools.getopt.Option; +import gnu.classpath.tools.getopt.OptionException; +import gnu.classpath.tools.getopt.OptionGroup; +import gnu.classpath.tools.getopt.Parser; import gnu.java.security.Registry; import gnu.javax.crypto.jce.GnuCrypto; import gnu.javax.security.auth.callback.GnuCallbacks; @@ -57,8 +61,51 @@ import java.util.logging.Logger; public class Main { private static final Logger log = Logger.getLogger(Main.class.getName()); - /** The relative file path to the command tool's help text. */ - private static final String HELP_PATH = "keytool/keytool.txt"; //$NON-NLS-1$ + static final String KEYTOOL_TOOL = "keytool"; //$NON-NLS-1$ + static final String GENKEY_CMD = "genkey"; //$NON-NLS-1$ + static final String IMPORT_CMD = "import"; //$NON-NLS-1$ + static final String SELFCERT_CMD = "selfcert"; //$NON-NLS-1$ + static final String IDENTITYDB_CMD = "identitydb"; //$NON-NLS-1$ + static final String CERTREQ_CMD = "certreq"; //$NON-NLS-1$ + static final String EXPORT_CMD = "export"; //$NON-NLS-1$ + static final String LIST_CMD = "list"; //$NON-NLS-1$ + static final String PRINTCERT_CMD = "printcert"; //$NON-NLS-1$ + static final String KEYCLONE_CMD = "keyclone"; //$NON-NLS-1$ + static final String STOREPASSWD_CMD = "storepasswd"; //$NON-NLS-1$ + static final String KEYPASSWD_CMD = "keypasswd"; //$NON-NLS-1$ + static final String DELETE_CMD = "delete"; //$NON-NLS-1$ + + static final String _GENKEY = "-" + GENKEY_CMD; //$NON-NLS-1$ + static final String _IMPORT = "-" + IMPORT_CMD; //$NON-NLS-1$ + static final String _SELFCERT = "-" + SELFCERT_CMD; //$NON-NLS-1$ + static final String _IDENTITYDB = "-" + IDENTITYDB_CMD; //$NON-NLS-1$ + static final String _CERTREQ = "-" + CERTREQ_CMD; //$NON-NLS-1$ + static final String _EXPORT = "-" + EXPORT_CMD; //$NON-NLS-1$ + static final String _LIST = "-" + LIST_CMD; //$NON-NLS-1$ + static final String _PRINTCERT = "-" + PRINTCERT_CMD; //$NON-NLS-1$ + static final String _KEYCLONE = "-" + KEYCLONE_CMD; //$NON-NLS-1$ + static final String _STOREPASSWD = "-" + STOREPASSWD_CMD; //$NON-NLS-1$ + static final String _KEYPASSWD = "-" + KEYPASSWD_CMD; //$NON-NLS-1$ + static final String _DELETE = "-" + DELETE_CMD; //$NON-NLS-1$ + static final String _HELP = "-help"; //$NON-NLS-1$ + + static final String ALIAS_OPT = "alias"; //$NON-NLS-1$ + static final String SIGALG_OPT = "sigalg"; //$NON-NLS-1$ + static final String KEYALG_OPT = "keyalg"; //$NON-NLS-1$ + static final String KEYSIZE_OPT = "keysize"; //$NON-NLS-1$ + static final String KEYPASS_OPT = "keypass"; //$NON-NLS-1$ + static final String VALIDITY_OPT = "validity"; //$NON-NLS-1$ + static final String STORETYPE_OPT = "storetype"; //$NON-NLS-1$ + static final String STOREPASS_OPT = "storepass"; //$NON-NLS-1$ + static final String KEYSTORE_OPT = "keystore"; //$NON-NLS-1$ + static final String PROVIDER_OPT = "provider"; //$NON-NLS-1$ + static final String FILE_OPT = "file"; //$NON-NLS-1$ + static final String VERBOSE_OPT = "v"; //$NON-NLS-1$ + static final String DEST_OPT = "dest"; //$NON-NLS-1$ + static final String NEW_OPT = "new"; //$NON-NLS-1$ + static final String RFC_OPT = "rfc"; //$NON-NLS-1$ + static final String DNAME_OPT = "dname"; //$NON-NLS-1$ + /** The Preferences key name for the last issued certificate serial nbr. */ static final String LAST_SERIAL_NUMBER = "lastSerialNumber"; //$NON-NLS-1$ /** Constant denoting the X.509 certificate type. */ @@ -70,6 +117,8 @@ public class Main private int gnuCryptoProviderNdx = -2; /** The new position of GNU Callbacks provider if it is not already installed. */ private int gnuCallbacksNdx = -2; + /** The command line parser. */ + private Parser cmdLineParser; private Main() { @@ -81,117 +130,140 @@ public class Main log.entering(Main.class.getName(), "main", args); //$NON-NLS-1$ Main tool = new Main(); + int result = 1; try { tool.setup(); tool.start(args); + result = 0; + } + catch (OptionException x) + { + System.err.println(x.getMessage()); + if (tool.cmdLineParser != null) + tool.cmdLineParser.printHelp(); } catch (SecurityException x) { log.throwing(Main.class.getName(), "main", x); //$NON-NLS-1$ - System.err.println(Messages.getString("Main.6") + x.getMessage()); //$NON-NLS-1$ + System.err.println(Messages.getFormattedString("Main.6", //$NON-NLS-1$ + x.getMessage())); } catch (Exception x) { log.throwing(Main.class.getName(), "main", x); //$NON-NLS-1$ - System.err.println(Messages.getString("Main.8") + x); //$NON-NLS-1$ + System.err.println(Messages.getFormattedString("Main.8", x)); //$NON-NLS-1$ } finally - { - tool.teardown(); - } + { + tool.teardown(); + } - log.exiting(Main.class.getName(), "main"); //$NON-NLS-1$ - // System.exit(0); + log.exiting(Main.class.getName(), "main", Integer.valueOf(result)); //$NON-NLS-1$ + System.exit(result); } // helper methods ----------------------------------------------------------- + private void setup() + { + log.entering(this.getClass().getName(), "setup"); //$NON-NLS-1$ + + cmdLineParser = getParser(); + gnuCryptoProviderNdx = ProviderUtil.addProvider(new GnuCrypto()); + gnuCallbacksNdx = ProviderUtil.addProvider(new GnuCallbacks()); + + log.exiting(this.getClass().getName(), "setup"); //$NON-NLS-1$ + } + private void start(String[] args) throws Exception { - log.entering(this.getClass().getName(), "start", args); //$NON-NLS-1$ + log.entering(this.getClass().getName(), "start"); //$NON-NLS-1$ - if (args == null) - args = new String[0]; + if (args == null || args.length == 0) + throw new OptionException(""); //$NON-NLS-1$ - int limit = args.length; - log.finest("args.length=" + limit); //$NON-NLS-1$ - int i = 0; String opt; Command cmd; - while (i < limit) + while (args.length > 0) { - opt = args[i]; - log.finest("args[" + i + "]=" + opt); //$NON-NLS-1$ //$NON-NLS-2$ - if (opt == null || opt.length() == 0) - continue; - + opt = args[0]; cmd = null; - if ("-genkey".equals(opt)) //$NON-NLS-1$ + if (_GENKEY.equals(opt)) cmd = new GenKeyCmd(); - else if ("-import".equals(opt)) //$NON-NLS-1$ + else if (_IMPORT.equals(opt)) cmd = new ImportCmd(); - else if ("-selfcert".equals(opt)) //$NON-NLS-1$ + else if (_SELFCERT.equals(opt)) cmd = new SelfCertCmd(); - else if ("-identitydb".equals(opt)) //$NON-NLS-1$ + else if (_IDENTITYDB.equals(opt)) cmd = new IdentityDBCmd(); - else if ("-certreq".equals(opt)) //$NON-NLS-1$ + else if (_CERTREQ.equals(opt)) cmd = new CertReqCmd(); - else if ("-export".equals(opt)) //$NON-NLS-1$ + else if (_EXPORT.equals(opt)) cmd = new ExportCmd(); - else if ("-list".equals(opt)) //$NON-NLS-1$ + else if (_LIST.equals(opt)) cmd = new ListCmd(); - else if ("-printcert".equals(opt)) //$NON-NLS-1$ + else if (_PRINTCERT.equals(opt)) cmd = new PrintCertCmd(); - else if ("-keyclone".equals(opt)) //$NON-NLS-1$ + else if (_KEYCLONE.equals(opt)) cmd = new KeyCloneCmd(); - else if ("-storepasswd".equals(opt)) //$NON-NLS-1$ + else if (_STOREPASSWD.equals(opt)) cmd = new StorePasswdCmd(); - else if ("-keypasswd".equals(opt)) //$NON-NLS-1$ + else if (_KEYPASSWD.equals(opt)) cmd = new KeyPasswdCmd(); - else if ("-delete".equals(opt)) //$NON-NLS-1$ + else if (_DELETE.equals(opt)) cmd = new DeleteCmd(); - else if ("-help".equals(opt)) //$NON-NLS-1$ - { - printHelp(); - i++; - } + else if (_HELP.equals(opt)) + throw new OptionException(""); //$NON-NLS-1$ else - { - log.fine("Unknown command [" + opt + "] at index #" + i //$NON-NLS-1$ //$NON-NLS-2$ - + ". Arguments from that token onward will be ignored"); //$NON-NLS-1$ - break; - } - - if (cmd != null) - { - i = cmd.processArgs(args, i); - cmd.doCommand(); - } - } - - // the -help command is the default; i.e. - // keytool - // is equivalent to: - // keytool -help - if (i == 0) - printHelp(); + throw new OptionException(Messages.getFormattedString("Main.18", //$NON-NLS-1$ + opt)); - if (i < limit) // more options than needed - log.fine("Last recognized argument is assumed at index #" + (i - 1) //$NON-NLS-1$ - + ". Remaining arguments (" + args[i] + "...) will be ignored"); //$NON-NLS-1$ //$NON-NLS-2$ + String[] cmdArgs = new String[args.length - 1]; + System.arraycopy(args, 1, cmdArgs, 0, cmdArgs.length); + args = cmd.processArgs(cmdArgs); + cmd.doCommand(); + } log.exiting(this.getClass().getName(), "start"); //$NON-NLS-1$ } - private void setup() + private Parser getParser() { - log.entering(this.getClass().getName(), "setup"); //$NON-NLS-1$ - - gnuCryptoProviderNdx = ProviderUtil.addProvider(new GnuCrypto()); - gnuCallbacksNdx = ProviderUtil.addProvider(new GnuCallbacks()); - - log.exiting(this.getClass().getName(), "setup"); //$NON-NLS-1$ + log.entering(this.getClass().getName(), "getParser"); //$NON-NLS-1$ + + Parser result = new ClasspathToolParser(KEYTOOL_TOOL, true); + result.setHeader(Messages.getString("Main.19")); //$NON-NLS-1$ + result.setFooter(Messages.getString("Main.20")); //$NON-NLS-1$ + OptionGroup cmdGroup = new OptionGroup(Messages.getString("Main.21")); //$NON-NLS-1$ + cmdGroup.add(new NoParseOption(GENKEY_CMD, + Messages.getString("Main.22"))); //$NON-NLS-1$ + cmdGroup.add(new NoParseOption(IMPORT_CMD, + Messages.getString("Main.23"))); //$NON-NLS-1$ + cmdGroup.add(new NoParseOption(SELFCERT_CMD, + Messages.getString("Main.24"))); //$NON-NLS-1$ + cmdGroup.add(new NoParseOption(IDENTITYDB_CMD, + Messages.getString("Main.25"))); //$NON-NLS-1$ + cmdGroup.add(new NoParseOption(CERTREQ_CMD, + Messages.getString("Main.26"))); //$NON-NLS-1$ + cmdGroup.add(new NoParseOption(EXPORT_CMD, + Messages.getString("Main.27"))); //$NON-NLS-1$ + cmdGroup.add(new NoParseOption(LIST_CMD, + Messages.getString("Main.28"))); //$NON-NLS-1$ + cmdGroup.add(new NoParseOption(PRINTCERT_CMD, + Messages.getString("Main.29"))); //$NON-NLS-1$ + cmdGroup.add(new NoParseOption(KEYCLONE_CMD, + Messages.getString("Main.30"))); //$NON-NLS-1$ + cmdGroup.add(new NoParseOption(STOREPASSWD_CMD, + Messages.getString("Main.31"))); //$NON-NLS-1$ + cmdGroup.add(new NoParseOption(KEYPASSWD_CMD, + Messages.getString("Main.32"))); //$NON-NLS-1$ + cmdGroup.add(new NoParseOption(DELETE_CMD, + Messages.getString("Main.33"))); //$NON-NLS-1$ + result.add(cmdGroup); + + log.exiting(this.getClass().getName(), "getParser", result); //$NON-NLS-1$ + return result; } private void teardown() @@ -213,7 +285,28 @@ public class Main if (helpPrinted) return; - HelpPrinter.printHelp(HELP_PATH); helpPrinted = true; } + + // Inner class(es) + // ========================================================================== + + private class NoParseOption + extends Option + { + public NoParseOption(String name, String description) + { + super(name, description); + } + + public NoParseOption(String name, String description, String param) + { + super(name, description, param); + } + + public void parsed(String argument) throws OptionException + { + // do nothing + } + } } diff --git a/tools/gnu/classpath/tools/keytool/PrintCertCmd.java b/tools/gnu/classpath/tools/keytool/PrintCertCmd.java index 9ba1d5970..d259258e7 100644 --- a/tools/gnu/classpath/tools/keytool/PrintCertCmd.java +++ b/tools/gnu/classpath/tools/keytool/PrintCertCmd.java @@ -38,6 +38,12 @@ exception statement from your version. */ package gnu.classpath.tools.keytool; +import gnu.classpath.tools.getopt.ClasspathToolParser; +import gnu.classpath.tools.getopt.Option; +import gnu.classpath.tools.getopt.OptionException; +import gnu.classpath.tools.getopt.OptionGroup; +import gnu.classpath.tools.getopt.Parser; + import java.io.PrintWriter; import java.security.cert.Certificate; import java.security.cert.CertificateException; @@ -63,7 +69,7 @@ import java.util.logging.Logger; class PrintCertCmd extends Command { private static final Logger log = Logger.getLogger(PrintCertCmd.class.getName()); - private String _certFileName; + protected String _certFileName; // default 0-arguments constructor @@ -77,40 +83,18 @@ class PrintCertCmd extends Command // life-cycle methods ------------------------------------------------------- - int processArgs(String[] args, int i) - { - int limit = args.length; - String opt; - while (++i < limit) - { - opt = args[i]; - log.finest("args[" + i + "]=" + opt); - if (opt == null || opt.length() == 0) - continue; - - if ("-file".equals(opt)) // -file FILE_NAME - _certFileName = args[++i]; - else if ("-v".equals(opt)) - verbose = true; - else - break; - } - - return i; - } - void setup() throws Exception { setInputStreamParam(_certFileName); - log.finer("-printcert handler will use the following options:"); - log.finer(" -file=" + _certFileName); - log.finer(" -v=" + verbose); + log.finer("-printcert handler will use the following options:"); //$NON-NLS-1$ + log.finer(" -file=" + _certFileName); //$NON-NLS-1$ + log.finer(" -v=" + verbose); //$NON-NLS-1$ } void start() throws CertificateException { - log.entering(getClass().getName(), "start"); + log.entering(getClass().getName(), "start"); //$NON-NLS-1$ CertificateFactory x509Factory = CertificateFactory.getInstance(Main.X_509); Certificate certificate = x509Factory.generateCertificate(inStream); @@ -118,6 +102,39 @@ class PrintCertCmd extends Command writer.println(); printVerbose(certificate, writer); - log.exiting(getClass().getName(), "start"); + log.exiting(getClass().getName(), "start"); //$NON-NLS-1$ + } + + // own methods -------------------------------------------------------------- + + Parser getParser() + { + log.entering(this.getClass().getName(), "getParser"); //$NON-NLS-1$ + + Parser result = new ClasspathToolParser(Main.PRINTCERT_CMD, true); + result.setHeader(Messages.getString("PrintCertCmd.5")); //$NON-NLS-1$ + result.setFooter(Messages.getString("PrintCertCmd.6")); //$NON-NLS-1$ + OptionGroup options = new OptionGroup(Messages.getString("PrintCertCmd.7")); //$NON-NLS-1$ + options.add(new Option(Main.FILE_OPT, + Messages.getString("PrintCertCmd.8"), //$NON-NLS-1$ + Messages.getString("PrintCertCmd.9")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _certFileName = argument; + } + }); + options.add(new Option(Main.VERBOSE_OPT, + Messages.getString("PrintCertCmd.10")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + verbose = true; + } + }); + result.add(options); + + log.exiting(this.getClass().getName(), "getParser", result); //$NON-NLS-1$ + return result; } } diff --git a/tools/gnu/classpath/tools/keytool/SelfCertCmd.java b/tools/gnu/classpath/tools/keytool/SelfCertCmd.java index db7d45994..13a63d817 100644 --- a/tools/gnu/classpath/tools/keytool/SelfCertCmd.java +++ b/tools/gnu/classpath/tools/keytool/SelfCertCmd.java @@ -38,6 +38,11 @@ exception statement from your version. */ package gnu.classpath.tools.keytool; +import gnu.classpath.tools.getopt.ClasspathToolParser; +import gnu.classpath.tools.getopt.Option; +import gnu.classpath.tools.getopt.OptionException; +import gnu.classpath.tools.getopt.OptionGroup; +import gnu.classpath.tools.getopt.Parser; import gnu.java.security.x509.X500DistinguishedName; import java.io.ByteArrayInputStream; @@ -171,15 +176,15 @@ import javax.security.auth.x500.X500Principal; class SelfCertCmd extends Command { private static final Logger log = Logger.getLogger(SelfCertCmd.class.getName()); - private String _alias; - private String _sigAlgorithm; - private String _dName; - private String _password; - private String _validityStr; - private String _ksType; - private String _ksURL; - private String _ksPassword; - private String _providerClassName; + protected String _alias; + protected String _sigAlgorithm; + protected String _dName; + protected String _password; + protected String _validityStr; + protected String _ksType; + protected String _ksURL; + protected String _ksPassword; + protected String _providerClassName; private X500DistinguishedName distinguishedName; private int validityInDays; @@ -253,44 +258,6 @@ class SelfCertCmd extends Command // life-cycle methods ------------------------------------------------------- - int processArgs(String[] args, int i) - { - int limit = args.length; - String opt; - while (++i < limit) - { - opt = args[i]; - log.finest("args[" + i + "]=" + opt); - if (opt == null || opt.length() == 0) - continue; - - if ("-alias".equals(opt)) // -alias ALIAS - _alias = args[++i]; - else if ("-sigalg".equals(opt)) // -sigalg ALGORITHM - _sigAlgorithm = args[++i]; - else if ("-dname".equals(opt)) // -dname NAME - _dName = args[++i]; - else if ("-keypass".equals(opt)) // -keypass PASSWORD - _password = args[++i]; - else if ("-validity".equals(opt)) // -validity DAY_COUNT - _validityStr = args[++i]; - else if ("-storetype".equals(opt)) // -storetype STORE_TYPE - _ksType = args[++i]; - else if ("-keystore".equals(opt)) // -keystore URL - _ksURL = args[++i]; - else if ("-storepass".equals(opt)) // -storepass PASSWORD - _ksPassword = args[++i]; - else if ("-provider".equals(opt)) // -provider PROVIDER_CLASS_NAME - _providerClassName = args[++i]; - else if ("-v".equals(opt)) - verbose = true; - else - break; - } - - return i; - } - void setup() throws Exception { setKeyStoreParams(_providerClassName, _ksType, _ksPassword, _ksURL); @@ -300,24 +267,24 @@ class SelfCertCmd extends Command setValidityParam(_validityStr); // setSignatureAlgorithm(_sigAlgorithm); - log.finer("-selfcert handler will use the following options:"); - log.finer(" -alias=" + alias); - log.finer(" -sigalg=" + _sigAlgorithm); - log.finer(" -dname=" + _dName); - log.finer(" -keypass=" + _password); - log.finer(" -validity=" + validityInDays); - log.finer(" -storetype=" + storeType); - log.finer(" -keystore=" + storeURL); - log.finer(" -storepass=" + String.valueOf(storePasswordChars)); - log.finer(" -provider=" + provider); - log.finer(" -v=" + verbose); + log.finer("-selfcert handler will use the following options:"); //$NON-NLS-1$ + log.finer(" -alias=" + alias); //$NON-NLS-1$ + log.finer(" -sigalg=" + _sigAlgorithm); //$NON-NLS-1$ + log.finer(" -dname=" + _dName); //$NON-NLS-1$ + log.finer(" -keypass=" + _password); //$NON-NLS-1$ + log.finer(" -validity=" + validityInDays); //$NON-NLS-1$ + log.finer(" -storetype=" + storeType); //$NON-NLS-1$ + log.finer(" -keystore=" + storeURL); //$NON-NLS-1$ + log.finer(" -storepass=" + String.valueOf(storePasswordChars)); //$NON-NLS-1$ + log.finer(" -provider=" + provider); //$NON-NLS-1$ + log.finer(" -v=" + verbose); //$NON-NLS-1$ } void start() throws KeyStoreException, NoSuchAlgorithmException, UnrecoverableKeyException, IOException, UnsupportedCallbackException, InvalidKeyException, SignatureException, CertificateException { - log.entering(getClass().getName(), "start"); + log.entering(getClass().getName(), "start"); //$NON-NLS-1$ // 1. get the key entry and certificate chain associated to alias Key privateKey = getAliasPrivateKey(); @@ -337,7 +304,7 @@ class SelfCertCmd extends Command byte[] derBytes = getSelfSignedCertificate(distinguishedName, publicKey, (PrivateKey) privateKey); - CertificateFactory x509Factory = CertificateFactory.getInstance("X.509"); + CertificateFactory x509Factory = CertificateFactory.getInstance("X.509"); //$NON-NLS-1$ ByteArrayInputStream bais = new ByteArrayInputStream(derBytes); Certificate certificate = x509Factory.generateCertificate(bais); @@ -348,11 +315,114 @@ class SelfCertCmd extends Command // 7. persist the key store saveKeyStore(); - log.exiting(getClass().getName(), "start"); + log.exiting(getClass().getName(), "start"); //$NON-NLS-1$ } // own methods -------------------------------------------------------------- + Parser getParser() + { + log.entering(this.getClass().getName(), "getParser"); //$NON-NLS-1$ + + Parser result = new ClasspathToolParser(Main.SELFCERT_CMD, true); + result.setHeader(Messages.getString("SelfCertCmd.14")); //$NON-NLS-1$ + result.setFooter(Messages.getString("SelfCertCmd.15")); //$NON-NLS-1$ + OptionGroup options = new OptionGroup(Messages.getString("SelfCertCmd.16")); //$NON-NLS-1$ + options.add(new Option(Main.ALIAS_OPT, + Messages.getString("SelfCertCmd.17"), //$NON-NLS-1$ + Messages.getString("SelfCertCmd.18")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _alias = argument; + } + }); + options.add(new Option(Main.SIGALG_OPT, + Messages.getString("SelfCertCmd.19"), //$NON-NLS-1$ + Messages.getString("SelfCertCmd.20")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _sigAlgorithm = argument; + } + }); + options.add(new Option(Main.DNAME_OPT, + Messages.getString("SelfCertCmd.21"), //$NON-NLS-1$ + Messages.getString("SelfCertCmd.22")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _dName = argument; + } + }); + options.add(new Option(Main.KEYPASS_OPT, + Messages.getString("SelfCertCmd.23"), //$NON-NLS-1$ + Messages.getString("SelfCertCmd.24")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _password = argument; + } + }); + options.add(new Option(Main.VALIDITY_OPT, + Messages.getString("SelfCertCmd.25"), //$NON-NLS-1$ + Messages.getString("SelfCertCmd.26")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _validityStr = argument; + } + }); + options.add(new Option(Main.STORETYPE_OPT, + Messages.getString("SelfCertCmd.27"), //$NON-NLS-1$ + Messages.getString("SelfCertCmd.28")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _ksType = argument; + } + }); + options.add(new Option(Main.KEYSTORE_OPT, + Messages.getString("SelfCertCmd.29"), //$NON-NLS-1$ + Messages.getString("SelfCertCmd.30")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _ksURL = argument; + } + }); + options.add(new Option(Main.STOREPASS_OPT, + Messages.getString("SelfCertCmd.31"), //$NON-NLS-1$ + Messages.getString("SelfCertCmd.32")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _ksPassword = argument; + } + }); + options.add(new Option(Main.PROVIDER_OPT, + Messages.getString("SelfCertCmd.33"), //$NON-NLS-1$ + Messages.getString("SelfCertCmd.34")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _providerClassName = argument; + } + }); + options.add(new Option(Main.VERBOSE_OPT, + Messages.getString("SelfCertCmd.35")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + verbose = true; + } + }); + result.add(options); + + log.exiting(this.getClass().getName(), "getParser", result); //$NON-NLS-1$ + return result; + } + private void setDName(String name, X500Principal defaultName) { if (name != null && name.trim().length() > 0) diff --git a/tools/gnu/classpath/tools/keytool/StorePasswdCmd.java b/tools/gnu/classpath/tools/keytool/StorePasswdCmd.java index 1eb053c1c..988c1636a 100644 --- a/tools/gnu/classpath/tools/keytool/StorePasswdCmd.java +++ b/tools/gnu/classpath/tools/keytool/StorePasswdCmd.java @@ -39,6 +39,11 @@ exception statement from your version. */ package gnu.classpath.tools.keytool; import gnu.classpath.SystemProperties; +import gnu.classpath.tools.getopt.ClasspathToolParser; +import gnu.classpath.tools.getopt.Option; +import gnu.classpath.tools.getopt.OptionException; +import gnu.classpath.tools.getopt.OptionGroup; +import gnu.classpath.tools.getopt.Parser; import java.io.IOException; import java.security.KeyStoreException; @@ -107,11 +112,11 @@ import javax.security.auth.callback.UnsupportedCallbackException; class StorePasswdCmd extends Command { private static final Logger log = Logger.getLogger(StorePasswdCmd.class.getName()); - private String _newPassword; - private String _ksType; - private String _ksURL; - private String _ksPassword; - private String _providerClassName; + protected String _newPassword; + protected String _ksType; + protected String _ksURL; + protected String _ksPassword; + protected String _providerClassName; private char[] newStorePasswordChars; // default 0-arguments constructor @@ -150,36 +155,6 @@ class StorePasswdCmd extends Command // life-cycle methods ------------------------------------------------------- - int processArgs(String[] args, int i) - { - int limit = args.length; - String opt; - while (++i < limit) - { - opt = args[i]; - log.finest("args[" + i + "]=" + opt); //$NON-NLS-1$ //$NON-NLS-2$ - if (opt == null || opt.length() == 0) - continue; - - if ("-new".equals(opt)) // -new PASSWORD //$NON-NLS-1$ - _newPassword = args[++i]; - else if ("-storetype".equals(opt)) // -storetype STORE_TYPE //$NON-NLS-1$ - _ksType = args[++i]; - else if ("-keystore".equals(opt)) // -keystore URL //$NON-NLS-1$ - _ksURL = args[++i]; - else if ("-storepass".equals(opt)) // -storepass PASSWORD //$NON-NLS-1$ - _ksPassword = args[++i]; - else if ("-provider".equals(opt)) // -provider PROVIDER_CLASS_NAME //$NON-NLS-1$ - _providerClassName = args[++i]; - else if ("-v".equals(opt)) //$NON-NLS-1$ - verbose = true; - else - break; - } - - return i; - } - void setup() throws Exception { setKeyStoreParams(_providerClassName, _ksType, _ksPassword, _ksURL); @@ -206,6 +181,73 @@ class StorePasswdCmd extends Command // own methods -------------------------------------------------------------- + Parser getParser() + { + log.entering(this.getClass().getName(), "getParser"); //$NON-NLS-1$ + + Parser result = new ClasspathToolParser(Main.STOREPASSWD_CMD, true); + result.setHeader(Messages.getString("StorePasswdCmd.18")); //$NON-NLS-1$ + result.setFooter(Messages.getString("StorePasswdCmd.17")); //$NON-NLS-1$ + OptionGroup options = new OptionGroup(Messages.getString("StorePasswdCmd.16")); //$NON-NLS-1$ + options.add(new Option(Main.NEW_OPT, + Messages.getString("StorePasswdCmd.15"), //$NON-NLS-1$ + Messages.getString("StorePasswdCmd.8")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _newPassword = argument; + } + }); + options.add(new Option(Main.STORETYPE_OPT, + Messages.getString("StorePasswdCmd.13"), //$NON-NLS-1$ + Messages.getString("StorePasswdCmd.12")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _ksType = argument; + } + }); + options.add(new Option(Main.KEYSTORE_OPT, + Messages.getString("StorePasswdCmd.11"), //$NON-NLS-1$ + Messages.getString("StorePasswdCmd.10")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _ksURL = argument; + } + }); + options.add(new Option(Main.STOREPASS_OPT, + Messages.getString("StorePasswdCmd.9"), //$NON-NLS-1$ + Messages.getString("StorePasswdCmd.8")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _ksPassword = argument; + } + }); + options.add(new Option(Main.PROVIDER_OPT, + Messages.getString("StorePasswdCmd.7"), //$NON-NLS-1$ + Messages.getString("StorePasswdCmd.6")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + _providerClassName = argument; + } + }); + options.add(new Option(Main.VERBOSE_OPT, + Messages.getString("StorePasswdCmd.5")) //$NON-NLS-1$ + { + public void parsed(String argument) throws OptionException + { + verbose = true; + } + }); + result.add(options); + + log.exiting(this.getClass().getName(), "getParser", result); //$NON-NLS-1$ + return result; + } + protected void setNewKeystorePassword(String password) throws IOException, UnsupportedCallbackException { diff --git a/tools/gnu/classpath/tools/keytool/keytool.txt b/tools/gnu/classpath/tools/keytool/keytool.txt deleted file mode 100644 index 15f9b96f9..000000000 --- a/tools/gnu/classpath/tools/keytool/keytool.txt +++ /dev/null @@ -1,616 +0,0 @@ -NAME - keytool - manage private keys and public certificates - -SYNOPSIS - keytool [COMMAND]... - -DESCRIPTION - A Java-based tool for managing both Key Entries as well as Trusted - Certificates. - - Multiple COMMANDs may be specified at once, each complete with its own - options. keytool will parse all the arguments, before processing, and - executing, each COMMAND. If an exception occurs while executing one - COMMAND keytool will abort. - - A COMMAND can be one of the followings: - - -genkey [OPTION]... - Generate a new Key Entry, eventually creating a new key store. - - -import [OPTION]... - Add, to a key store, Key Entries (private keys and certificate - chains authenticating the public keys) and Trusted Certificates - (3rd party certificates which can be used as Trust anchors when - building chains-of-trust). - - -selfcert [OPTION]... - Generate a new self-signed Trusted Certificate. - - -identitydb [OPTION]... - NOT IMPLEMENTED YET. - Import a JDK 1.1 style Identity Database. - - -certreq [OPTION]... - Issue a Certificate Signing Request (CSR) which can be then sent - to a Certification Authority (CA) to issue a certificate signed - (by the CA) and authenticating the Subject of the request. - - -export [OPTION]... - Export a Certificate from a key store. - - -list [OPTION]... - Print one or all Certificates in a key store to STDOUT. - - -printcert [OPTION]... - Print a human-readable form of a Certificate in a designated - file to STDOUT. - - -keyclone [OPTION]... - Clone a Key Entry in a key store. - - -storepasswd [OPTION]... - Change the password protecting a key store. - - -keypasswd [OPTION]... - Change the password protecting a Key Entry in a key store. - - -delete [OPTION]... - Delete a Key Entry or a Trusted Certificate from a key store. - - -help Display this text. - -OPTIONS COMMON TO MORE THAN ONE COMMAND - The following OPTIONs are used in more than one COMMAND. They are - described here to reduce redundancy. - - -alias ALIAS - Every entry, be it a Key Entry or a Trusted Certificate, in a - key store is uniquely identified by a user-defined Alias string. - Use this option to specify the Alias to use when referring to an - entry in the key store. Unless specified otherwise, a default - value of "mykey" (all lower case, without the enclosing quotes) - shall be used when this option is omitted from the command line. - - -keyalg ALGORITHM - Use this option to specify the canonical name of the key-pair - generation algorithm. The default value for this option is - "DSS" (a synonym for the Digital Signature Algorithm also known - as DSA). - - -keysize SIZE - Use this option to specify the number of bits of the shared - modulus (for both the public and private keys) to use when - generating new keys. A default value of 1024 will be used if - this option is omitted from the command line. - - -validity DAY_COUNT - Use this option to specify the number of days a newly generated - certificate will be valid for. The default value is 90 (days) - if this option is omitted from the command line. - - -storetype STORE_TYPE - Use this option to specify the type of the key store to use. - The default value, if this option is omitted, is that of the - property "keystore.type" in the security properties file, which - is obtained by invoking the static method call getDefaultType() - in java.security.KeyStore. - - -storepass PASSWORD - Use this option to specify the password protecting the key - store. If this option is omitted from the command line, you - will be prompted to provide a password. - - -keystore URL - Use this option to specify the location of the key store to use. - The default value is a file URL referencing the file named - ".keystore" (all lower case and without the enclosing quotes) - located in the path returned by the call to - java.lang.System#getProperty(String) using "user.home" as - argument. - - If a URL was specified, but was found to be malformed --e.g. - missing protocol element-- the tool will attempt to use the URL - value as a file-name (with absolute or relative path-name) of a - key store --as if the protocol was "file:". - - -provider PROVIDER_CLASS_NAME - A fully qualified class name of a Security Provider to add to - the current list of Security Providers already installed in the - JVM in-use. If a provider class is specified with this option, - and was successfully added to the runtime --i.e. it was not - already installed-- then the tool will attempt to remove this - Security Provider before exiting. - - -file FILE_NAME - Use this option to designate a file to use with a command. When - specified with this option, the value is expected to be the - fully qualified path of a file accessible by the File System. - Depending on the command, the file may be used as input or as - output. When this option is omitted from the command line, - STDIN will be used instead, as the source of input, and STDOUT - will be used instead as the output destination. - - -v Unless specified otherwise, use this option to enable more - verbose output. - -X.500 DISTINGUISHED NAME - A Distinguished Name (or DN) MUST be supplied with some of the COMMANDs - using a -dname option. The syntax of a valid value for this option MUST - follow RFC-2253 specifications. Namely the following components (with - their accepted meaning) will be recognized. Note that the component - name is case-insensitive: - - CN The Common Name; e.g. "host.domain.com" - OU The Organizational Unit; e.g. "IT Department" - O The Organization Name; e.g. "The Sample Company" - L The Locality Name; e.g. "Sydney" - ST The State Name; e.g. "New South Wales" - C The 2-letter Country identifier; e.g. "AU" - - When specified with a -dname option, each pair of component/value will - be separated from the other with a comma. Each component and value pair - MUST be separated by an equal sign. For example, the following is - a valid DN value: - - CN=host.domain.com, O=The Sample Company, L=Sydney, ST=NSW, C=AU - - If the Distinguished Name is required, and no valid default value can be - used, the tool will prompt you to enter the information through the - console. - --genkey COMMAND - Generate a new key-pair (both private and public keys), and save these - credentials in the key store as a Key Entry, associated with the - designated (if was specified in the -alias option) or default (if the - -alias option is omitted) Alias. - - The private key material will be protected with a user-defined password - (see -keypass option). The public key on the other hand will be part - of a self-signed X.509 certificate, which will form a 1-element chain - and will be saved in the key store. - - -alias ALIAS - (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - - -keyalg ALGORITHM - (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - - -keysize KEY_SIZE - (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - - -sigalg ALGORITHM - The canonical name of the digital signature algorithm to use for - signing certificates. If this option is omitted, a default - value will be chosen based on the type of the key-pair; i.e. the - algorithm that ends up being used by the -keyalg option. If the - key-pair generation algorithm is "DSA", the value for the - signature algorithm will be "SHA1withDSA". If on the other hand - the key-pair generation algorithm is "RSA", then the tool will - use "MD5withRSA" as the signature algorithm. - - -dname NAME - This a mandatory value for the command. If no value is - specified --i.e. the -dname option is omitted-- the tool will - prompt you to enter a Distinguished Name to use as both the - Owner and Issuer of the generated self-signed certificate. - - (see X.500 DISTINGUISHED NAME) - - -keypass PASSWORD - Use this option to specify the password which the tool will use - to protect the newly created Key Entry. - - If this option is omitted, you will be prompted to provide a - password. - - -validity DAY_COUNT - (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - - -storetype STORE_TYPE - (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - - -keystore URL - (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - - -storepass PASSWORD - (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - - -provider PROVIDER_CLASS_NAME - (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - - -v (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - --import COMMAND - Read an X.509 certificate, or a PKCS#7 Certificate Reply from a - designated input source and incorporate the certificates into the key - store. - - If the Alias does not already exist in the key store, the tool treats - the certificate read from the input source as a new Trusted Certificate. - It then attempts to discover a chain-of-trust, starting from that - certificate and ending at another Trusted Certificate, already stored in - the key store. If the -trustcacerts option is present, an additional - key store, of type "JKS" named "cacerts", and assumed to be present in - ${JAVA_HOME}/lib/security will also be consulted if found --${JAVA_HOME} - refers to the location of an installed Java Runtime Environment (JRE). - If no chain-of-trust can be established, and unless the -noprompt option - has been specified, the certificate is printed to STDOUT and the user is - prompted for a confirmation. - - If Alias exists in the key store, the tool will treat the certificate(s) - read from the input source as a Certificate Reply, which can be a chain - of certificates, that eventually would replace the chain of certificates - associated with the Key Entry of that Alias. The substitution of the - certificates only occurs if a chain-of-trust can be established between - the bottom certificate of the chain read from the input file and the - Trusted Certificates already present in the key store. Again, if the - -trustcacerts option is specified, additional Trusted Certificates in - the same "cacerts" key store will be considered. If no chain-of-trust - can be established, the operation will abort. - - -alias ALIAS - (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - - -file FILE_NAME - (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - - -keypass PASSWORD - Use this option to specify the password which the tool will use - to protect the Key Entry associated with the designated Alias, - when replacing this Alias' chain of certificates with that found - in the certificate reply. - - If this option is omitted, and the chain-of-trust for the - certificate reply has been established, the tool will first - attempt to unlock the Key Entry using the same password - protecting the key store. If this fails, you will then be - prompted to provide a password. - - -noprompt - Use this option to prevent the tool from prompting the user. - - -trustcacerts - Use this option to indicate to the tool that a key store, of - type "JKS", named "cacerts", and usually located in lib/security - in an installed Java Runtime Environment should be considered - when trying to establish chain-of-trusts. - - -storetype STORE_TYPE - (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - - -keystore URL - (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - - -storepass PASSWORD - (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - - -provider PROVIDER_CLASS_NAME - (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - - -v (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - --selfcert COMMAND - Generate a self-signed X.509 version 1 certificate. The newly generated - certificate will form a chain of one element which will replace the - previous chain associated with the designated Alias (if -alias option - was specified), or the default Alias (if -alias option was omitted). - - -alias ALIAS - (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - - -sigalg ALGORITHM - The canonical name of the digital signature algorithm to use for - signing the certificate. If this option is omitted, a default - value will be chosen based on the type of the private key - associated with the designated Alias. If the private key is a - "DSA" one, the value for the signature algorithm will be - "SHA1withDSA". If on the other hand the private key is an "RSA" - one, then the tool will use "MD5withRSA" as the signature - algorithm. - - -dname NAME - Use this option to specify the Distinguished Name of the newly - generated self-signed certificate. If this option is omitted, - the existing Distinguished Name of the base certificate in the - chain associated with the designated Alias will be used instead. - - (see X.500 DISTINGUISHED NAME) - - -validity DAY_COUNT - (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - - -keypass PASSWORD - Use this option to specify the password which the tool will use - to unlock the Key Entry associated with the designated Alias. - - If this option is omitted, the tool will first attempt to unlock - the Key Entry using the same password protecting the key store. - If this fails, you will then be prompted to provide a password. - - -storetype STORE_TYPE - (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - - -keystore URL - (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - - -storepass PASSWORD - (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - - -provider PROVIDER_CLASS_NAME - (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - - -v (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - --identitydb COMMAND - NOT IMPLEMENTED YET. - - Import a JDK 1.1 style Identity Database. - - -file FILE_NAME - (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - - -storetype STORE_TYPE - (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - - -keystore URL - (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - - -storepass PASSWORD - (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - - -provider PROVIDER_CLASS_NAME - (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - - -v (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - --certreq COMMAND - Generate a PKCS#10 Certificate Signing Request (CSR) and writes it to - a designated output destination. The contents of the destination - should look something like the following: - - -----BEGIN NEW CERTIFICATE REQUEST----- - MIICYTCCAiECAQAwXzEUMBIGA1UEAwwLcnNuQGdudS5vcmcxGzAZBgNVBAoMElUg - Q29tcGFueTEPMA0GA1UEBwwGU3lkbmV5MQwwCgYDVQQIDANOU1cxCzAJBgNVBACC - ... - FCTlKlok8KwGuIVwNVOfQLRX+O5kAhQ/a4RTZme2L8PnpvgRwrf7Eg8D6w== - -----END NEW CERTIFICATE REQUEST----- - - IMPORTANT: Some documentation (e.g. RSA examples) claims that the - Attributes field, in the CSR is OPTIONAL while RFC-2986 implies the - opposite. This implementation considers this field, by default, as - OPTIONAL, unless the option -attributes is specified on the command - line. - - -alias ALIAS - (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - - -sigalg ALGORITHM - The canonical name of the digital signature algorithm to use for - signing the certificate. If this option is omitted, a default - value will be chosen based on the type of the private key - associated with the designated Alias. If the private key is a - "DSA" one, the value for the signature algorithm will be - "SHA1withDSA". If on the other hand the private key is an "RSA" - one, then the tool will use "MD5withRSA" as the signature - algorithm. - - -file FILE_NAME - (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - - -keypass PASSWORD - Use this option to specify the password which the tool will use - to unlock the Key Entry associated with the designated Alias. - - If this option is omitted, the tool will first attempt to unlock - the Key Entry using the same password protecting the key store. - If this fails, you will then be prompted to provide a password. - - -storetype STORE_TYPE - (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - - -keystore URL - (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - - -storepass PASSWORD - (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - - -provider PROVIDER_CLASS_NAME - (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - - -v (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - - -attributes - Use this option to force the tool to encode a NULL DER value in - the CSR as the value of the Attributes field. - --export COMMAND - Export a certificate stored in the key store to a designated output - destination, either in binary format (if the -v option is specified), - or in RFC-1421 compliant encoding (if the -rfc option is specified - instead). - - -alias ALIAS - (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - - -file FILE_NAME - (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - - -storetype STORE_TYPE - (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - - -keystore URL - (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - - -storepass PASSWORD - (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - - -provider PROVIDER_CLASS_NAME - (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - - -rfc Use RFC-1421 specifications when encoding the output. - - -v Output the certificate in binary DER encoding. This is the - default output format of the command if neither -rfc nor -v - options were detected on the command line. If both this option - and the -rfc option are detected on the command line, the tool - will opt for the RFC-1421 style encoding. - --list COMMAND - Print one or all of the key store entries to STDOUT. Usually this - command will only print a fingerprint of the certificate, unless either - the -rfc or the -v option is specified. - - -alias ALIAS - If this option is omitted, the tool will print ALL the entries - found in the key store. - - (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - - -storetype STORE_TYPE - (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - - -keystore URL - (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - - -storepass PASSWORD - (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - - -provider PROVIDER_CLASS_NAME - (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - - -rfc Use RFC-1421 specifications when encoding the output. - - -v Output the certificate in human-readable format. If both this - option and the -rfc option are detected on the command line, - the tool will opt for the human-readable form and will not - abort the command. - --printcert COMMAND - Read a certificate from a designated input source and print it to STDOUT - in a human-readable form. - - -file FILE_NAME - (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - - -v (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - --keyclone COMMAND - Clone an existing Key Entry and store it under a new (different) Alias - protecting, its private key material with possibly a new password. - - -alias ALIAS - (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - - -dest ALIAS - Use this option to specify the new Alias which will be used to - identify the cloned copy of the Key Entry. - - -keypass PASSWORD - Use this option to specify the password which the tool will use - to unlock the Key Entry associated with the designated Alias. - - If this option is omitted, the tool will first attempt to unlock - the Key Entry using the same password protecting the key store. - If this fails, you will then be prompted to provide a password. - - -new PASSWORD - Use this option to specify the password protecting the private - key material of the newly cloned copy of the Key Entry. - - -storetype STORE_TYPE - (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - - -keystore URL - (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - - -storepass PASSWORD - (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - - -provider PROVIDER_CLASS_NAME - (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - - -v (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - --storepasswd COMMAND - Change the password protecting a key store. - - -new PASSWORD - The new, and different, password which will be used to protect - the designated key store. - - -storetype STORE_TYPE - (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - - -keystore URL - (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - - -storepass PASSWORD - (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - - -provider PROVIDER_CLASS_NAME - (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - - -v (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - --keypasswd COMMAND - Change the password protecting the private key material of a designated - Key Entry. - - -alias ALIAS - (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - - -keypass PASSWORD - Use this option to specify the password which the tool will use - to unlock the Key Entry associated with the designated Alias. - - If this option is omitted, the tool will first attempt to unlock - the Key Entry using the same password protecting the key store. - If this fails, you will then be prompted to provide a password. - - -new PASSWORD - The new, and different, password which will be used to protect - the private key material of the designated Key Entry. - - -storetype STORE_TYPE - (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - - -keystore URL - (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - - -storepass PASSWORD - (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - - -provider PROVIDER_CLASS_NAME - (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - - -v (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - --delete COMMAND - Delete a designated key store entry. - - -alias ALIAS - (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - - -storetype STORE_TYPE - (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - - -keystore URL - (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - - -storepass PASSWORD - (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - - -provider PROVIDER_CLASS_NAME - (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - - -v (see OPTIONS COMMON TO MORE THAN ONE COMMAND) - -REPORTING BUGS - Please report bugs at http://www.gnu.org/software/classpath/bugs.html - -COPYRIGHT - Copyright (C) 2006 Free Software Foundation, Inc. - This is free software; see the source for copying conditions. There is - NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. |