From 8864bc3c1f52bfb1b47e1940d0d6e6a1942ea372 Mon Sep 17 00:00:00 2001 From: weijun Date: Fri, 2 Oct 2009 18:44:34 +0800 Subject: [PATCH] 6324292: keytool -help is unhelpful Reviewed-by: xuelei, mullan --- .../classes/sun/security/tools/KeyTool.java | 613 ++++++++---------- .../classes/sun/security/util/Resources.java | 271 ++++---- test/sun/security/tools/keytool/newhelp.sh | 53 ++ 3 files changed, 452 insertions(+), 485 deletions(-) create mode 100644 test/sun/security/tools/keytool/newhelp.sh diff --git a/src/share/classes/sun/security/tools/KeyTool.java b/src/share/classes/sun/security/tools/KeyTool.java index 8f9e86ee0..df686a732 100644 --- a/src/share/classes/sun/security/tools/KeyTool.java +++ b/src/share/classes/sun/security/tools/KeyTool.java @@ -76,6 +76,7 @@ import sun.security.util.DerValue; import sun.security.x509.*; import static java.security.KeyStore.*; +import static sun.security.tools.KeyTool.Command.*; /** * This tool manages keystores. @@ -92,7 +93,7 @@ import static java.security.KeyStore.*; public final class KeyTool { private boolean debug = false; - private int command = -1; + private Command command = null; private String sigAlgName = null; private String keyAlgName = null; private boolean verbose = false; @@ -146,24 +147,132 @@ public final class KeyTool { private List v3ext = new ArrayList (); - private static final int CERTREQ = 1; - private static final int CHANGEALIAS = 2; - private static final int DELETE = 3; - private static final int EXPORTCERT = 4; - private static final int GENKEYPAIR = 5; - private static final int GENSECKEY = 6; - // there is no HELP - private static final int IDENTITYDB = 7; - private static final int IMPORTCERT = 8; - private static final int IMPORTKEYSTORE = 9; - private static final int KEYCLONE = 10; - private static final int KEYPASSWD = 11; - private static final int LIST = 12; - private static final int PRINTCERT = 13; - private static final int SELFCERT = 14; - private static final int STOREPASSWD = 15; - private static final int GENCERT = 16; - private static final int PRINTCERTREQ = 17; + enum Command { + CERTREQ("Generates a certificate request", + "-alias", "-sigalg", "-file", "-keypass", "-keystore", + "-storepass", "-storetype", "-providername", "-providerclass", + "-providerarg", "-providerpath", "-v", "-protected"), + CHANGEALIAS("Changes an entry's alias", + "-alias", "-destalias", "-keypass", "-keystore", "-storepass", + "-storetype", "-providername", "-providerclass", "-providerarg", + "-providerpath", "-v", "-protected"), + DELETE("Deletes an entry", + "-alias", "-keystore", "-storepass", "-storetype", + "-providername", "-providerclass", "-providerarg", + "-providerpath", "-v", "-protected"), + EXPORTCERT("Exports certificate", + "-rfc", "-alias", "-file", "-keystore", "-storepass", + "-storetype", "-providername", "-providerclass", "-providerarg", + "-providerpath", "-v", "-protected"), + GENKEYPAIR("Generates a key pair", + "-alias", "-keyalg", "-keysize", "-sigalg", "-destalias", + "-startdate", "-ext", "-validity", "-keypass", "-keystore", + "-storepass", "-storetype", "-providername", "-providerclass", + "-providerarg", "-providerpath", "-v", "-protected"), + GENSECKEY("Generates a secret key", + "-alias", "-keypass", "-keyalg", "-keysize", "-keystore", + "-storepass", "-storetype", "-providername", "-providerclass", + "-providerarg", "-providerpath", "-v", "-protected"), + GENCERT("Generates certificate from a certificate request", + "-rfc", "-infile", "-outfile", "-alias", "-sigalg", + "-startdate", "-ext", "-validity", "-keypass", "-keystore", + "-storepass", "-storetype", "-providername", "-providerclass", + "-providerarg", "-providerpath", "-v", "-protected"), + IDENTITYDB("Imports entries from a JDK 1.1.x-style identity database", + "-file", "-storetype", "-keystore", "-storepass", "-providername", + "-providerclass", "-providerarg", "-providerpath", "-v"), + IMPORTCERT("Imports a certificate or a certificate chain", + "-noprompt", "-trustcacerts", "-protected", "-alias", "-file", + "-keypass", "-keystore", "-storepass", "-storetype", + "-providername", "-providerclass", "-providerarg", + "-providerpath", "-v"), + IMPORTKEYSTORE("Imports one or all entries from another keystore", + "-srckeystore", "-destkeystore", "-srcstoretype", + "-deststoretype", "-srcstorepass", "-deststorepass", + "-srcprotected", "-srcprovidername", "-destprovidername", + "-srcalias", "-destalias", "-srckeypass", "-destkeypass", + "-noprompt", "-providerclass", "-providerarg", "-providerpath", + "-v"), + KEYCLONE("Clones a key entry", + "-alias", "-destalias", "-keypass", "-new", "-storetype", + "-keystore", "-storepass", "-providername", "-providerclass", + "-providerarg", "-providerpath", "-v"), + KEYPASSWD("Changes the key password of an entry", + "-alias", "-keypass", "-new", "-keystore", "-storepass", + "-storetype", "-providername", "-providerclass", "-providerarg", + "-providerpath", "-v"), + LIST("Lists entries in a keystore", + "-rfc", "-alias", "-keystore", "-storepass", "-storetype", + "-providername", "-providerclass", "-providerarg", + "-providerpath", "-v", "-protected"), + PRINTCERT("Prints the content of a certificate", + "-rfc", "-file", "-sslserver", "-v"), + PRINTCERTREQ("Prints the content of a certificate request", + "-file", "-v"), + SELFCERT("Generates a self-signed certificate", + "-alias", "-sigalg", "-dname", "-startdate", "-validity", "-keypass", + "-storetype", "-keystore", "-storepass", "-providername", + "-providerclass", "-providerarg", "-providerpath", "-v"), + STOREPASSWD("Changes the store password of a keystore", + "-new", "-keystore", "-storepass", "-storetype", "-providername", + "-providerclass", "-providerarg", "-providerpath", "-v"); + + final String description; + final String[] options; + Command(String d, String... o) { + description = d; + options = o; + } + @Override + public String toString() { + return "-" + name().toLowerCase(Locale.ENGLISH); + } + }; + + private static String[][] options = { + // name, arg, description + {"-alias", "", "alias name of the entry to process"}, + {"-destalias", "", "destination alias"}, + {"-destkeypass", "", "destination key password"}, + {"-destkeystore", "", "destination keystore name"}, + {"-destprotected", null, "destination keystore password protected"}, + {"-destprovidername", "", "destination keystore provider name"}, + {"-deststorepass", "", "destination keystore password"}, + {"-deststoretype", "", "destination keystore type"}, + {"-dname", "", "distinguished name"}, + {"-ext", "", "X.509 extension"}, + {"-file", "", "output file name"}, + {"-file", "", "input file name"}, + {"-infile", "", "input file name"}, + {"-keyalg", "", "key algorithm name"}, + {"-keypass", "", "key password"}, + {"-keysize", "", "key bit size"}, + {"-keystore", "", "keystore name"}, + {"-new", "", "new password"}, + {"-noprompt", null, "do not prompt"}, + {"-outfile", "", "output file name"}, + {"-protected", null, "password through protected mechanism"}, + {"-providerarg", "", "provider argument"}, + {"-providerclass", "", "provider class name"}, + {"-providername", "", "provider name"}, + {"-providerpath", "", "provider classpath"}, + {"-rfc", null, "output in RFC style"}, + {"-sigalg", "", "signature algorithm name"}, + {"-srcalias", "", "source alias"}, + {"-srckeypass", "", "source keystore password"}, + {"-srckeystore", "", "source keystore name"}, + {"-srcprotected", null, "source keystore password protected"}, + {"-srcprovidername", "", "source keystore provider name"}, + {"-srcstorepass", "", "source keystore password"}, + {"-srcstoretype", "", "source keystore type"}, + {"-sslserver", "", "SSL server host and port"}, + {"-startdate", "", "certificate validity start date/time"}, + {"-storepass", "", "keystore password"}, + {"-storetype", "", "keystore type"}, + {"-trustcacerts", null, "trust certificates from cacerts"}, + {"-v", null, "verbose output"}, + {"-validity", "", "validity number of days"}, + }; private static final Class[] PARAM_STRING = { String.class }; @@ -192,7 +301,7 @@ public final class KeyTool { private void run(String[] args, PrintStream out) throws Exception { try { parseArgs(args); - if (command != -1) { + if (command != null) { doCommands(out); } } catch (Exception e) { @@ -224,59 +333,50 @@ public final class KeyTool { */ void parseArgs(String[] args) { - if (args.length == 0) { - usage(); - return; - } - int i=0; + boolean help = args.length == 0; for (i=0; (i < args.length) && args[i].startsWith("-"); i++) { String flags = args[i]; + + // Check if the last option needs an arg + if (i == args.length - 1) { + for (String[] option: options) { + // Only options with an arg need to be checked + if (collator.compare(flags, option[0]) == 0) { + if (option[1] != null) errorNeedArgument(flags); + break; + } + } + } + /* * command modes */ - if (collator.compare(flags, "-certreq") == 0) { - command = CERTREQ; - } else if (collator.compare(flags, "-delete") == 0) { - command = DELETE; - } else if (collator.compare(flags, "-export") == 0 || - collator.compare(flags, "-exportcert") == 0) { + boolean isCommand = false; + for (Command c: Command.values()) { + if (collator.compare(flags, c.toString()) == 0) { + command = c; + isCommand = true; + break; + } + } + + if (isCommand) { + // already recognized as a command + } else if (collator.compare(flags, "-export") == 0) { command = EXPORTCERT; - } else if (collator.compare(flags, "-genkey") == 0 || - collator.compare(flags, "-genkeypair") == 0) { + } else if (collator.compare(flags, "-genkey") == 0) { command = GENKEYPAIR; - } else if (collator.compare(flags, "-help") == 0) { - usage(); - return; - } else if (collator.compare(flags, "-identitydb") == 0) { // obsolete - command = IDENTITYDB; - } else if (collator.compare(flags, "-import") == 0 || - collator.compare(flags, "-importcert") == 0) { + } else if (collator.compare(flags, "-import") == 0) { command = IMPORTCERT; - } else if (collator.compare(flags, "-keyclone") == 0) { // obsolete - command = KEYCLONE; - } else if (collator.compare(flags, "-changealias") == 0) { - command = CHANGEALIAS; - } else if (collator.compare(flags, "-keypasswd") == 0) { - command = KEYPASSWD; - } else if (collator.compare(flags, "-list") == 0) { - command = LIST; - } else if (collator.compare(flags, "-printcert") == 0) { - command = PRINTCERT; - } else if (collator.compare(flags, "-selfcert") == 0) { // obsolete - command = SELFCERT; - } else if (collator.compare(flags, "-storepasswd") == 0) { - command = STOREPASSWD; - } else if (collator.compare(flags, "-importkeystore") == 0) { - command = IMPORTKEYSTORE; - } else if (collator.compare(flags, "-genseckey") == 0) { - command = GENSECKEY; - } else if (collator.compare(flags, "-gencert") == 0) { - command = GENCERT; - } else if (collator.compare(flags, "-printcertreq") == 0) { - command = PRINTCERTREQ; + } + /* + * Help + */ + else if (collator.compare(flags, "-help") == 0) { + help = true; } /* @@ -284,101 +384,74 @@ public final class KeyTool { */ else if (collator.compare(flags, "-keystore") == 0 || collator.compare(flags, "-destkeystore") == 0) { - if (++i == args.length) errorNeedArgument(flags); - ksfname = args[i]; + ksfname = args[++i]; } else if (collator.compare(flags, "-storepass") == 0 || collator.compare(flags, "-deststorepass") == 0) { - if (++i == args.length) errorNeedArgument(flags); - storePass = args[i].toCharArray(); + storePass = args[++i].toCharArray(); passwords.add(storePass); } else if (collator.compare(flags, "-storetype") == 0 || collator.compare(flags, "-deststoretype") == 0) { - if (++i == args.length) errorNeedArgument(flags); - storetype = args[i]; + storetype = args[++i]; } else if (collator.compare(flags, "-srcstorepass") == 0) { - if (++i == args.length) errorNeedArgument(flags); - srcstorePass = args[i].toCharArray(); + srcstorePass = args[++i].toCharArray(); passwords.add(srcstorePass); } else if (collator.compare(flags, "-srcstoretype") == 0) { - if (++i == args.length) errorNeedArgument(flags); - srcstoretype = args[i]; + srcstoretype = args[++i]; } else if (collator.compare(flags, "-srckeypass") == 0) { - if (++i == args.length) errorNeedArgument(flags); - srckeyPass = args[i].toCharArray(); + srckeyPass = args[++i].toCharArray(); passwords.add(srckeyPass); } else if (collator.compare(flags, "-srcprovidername") == 0) { - if (++i == args.length) errorNeedArgument(flags); - srcProviderName = args[i]; + srcProviderName = args[++i]; } else if (collator.compare(flags, "-providername") == 0 || collator.compare(flags, "-destprovidername") == 0) { - if (++i == args.length) errorNeedArgument(flags); - providerName = args[i]; + providerName = args[++i]; } else if (collator.compare(flags, "-providerpath") == 0) { - if (++i == args.length) errorNeedArgument(flags); - pathlist = args[i]; + pathlist = args[++i]; } else if (collator.compare(flags, "-keypass") == 0) { - if (++i == args.length) errorNeedArgument(flags); - keyPass = args[i].toCharArray(); + keyPass = args[++i].toCharArray(); passwords.add(keyPass); } else if (collator.compare(flags, "-new") == 0) { - if (++i == args.length) errorNeedArgument(flags); - newPass = args[i].toCharArray(); + newPass = args[++i].toCharArray(); passwords.add(newPass); } else if (collator.compare(flags, "-destkeypass") == 0) { - if (++i == args.length) errorNeedArgument(flags); - destKeyPass = args[i].toCharArray(); + destKeyPass = args[++i].toCharArray(); passwords.add(destKeyPass); } else if (collator.compare(flags, "-alias") == 0 || collator.compare(flags, "-srcalias") == 0) { - if (++i == args.length) errorNeedArgument(flags); - alias = args[i]; + alias = args[++i]; } else if (collator.compare(flags, "-dest") == 0 || collator.compare(flags, "-destalias") == 0) { - if (++i == args.length) errorNeedArgument(flags); - dest = args[i]; + dest = args[++i]; } else if (collator.compare(flags, "-dname") == 0) { - if (++i == args.length) errorNeedArgument(flags); - dname = args[i]; + dname = args[++i]; } else if (collator.compare(flags, "-keysize") == 0) { - if (++i == args.length) errorNeedArgument(flags); - keysize = Integer.parseInt(args[i]); + keysize = Integer.parseInt(args[++i]); } else if (collator.compare(flags, "-keyalg") == 0) { - if (++i == args.length) errorNeedArgument(flags); - keyAlgName = args[i]; + keyAlgName = args[++i]; } else if (collator.compare(flags, "-sigalg") == 0) { - if (++i == args.length) errorNeedArgument(flags); - sigAlgName = args[i]; + sigAlgName = args[++i]; } else if (collator.compare(flags, "-startdate") == 0) { - if (++i == args.length) errorNeedArgument(flags); - startDate = args[i]; + startDate = args[++i]; } else if (collator.compare(flags, "-validity") == 0) { - if (++i == args.length) errorNeedArgument(flags); - validity = Long.parseLong(args[i]); + validity = Long.parseLong(args[++i]); } else if (collator.compare(flags, "-ext") == 0) { - if (++i == args.length) errorNeedArgument(flags); - v3ext.add(args[i]); + v3ext.add(args[++i]); } else if (collator.compare(flags, "-file") == 0) { - if (++i == args.length) errorNeedArgument(flags); - filename = args[i]; + filename = args[++i]; } else if (collator.compare(flags, "-infile") == 0) { - if (++i == args.length) errorNeedArgument(flags); - infilename = args[i]; + infilename = args[++i]; } else if (collator.compare(flags, "-outfile") == 0) { - if (++i == args.length) errorNeedArgument(flags); - outfilename = args[i]; + outfilename = args[++i]; } else if (collator.compare(flags, "-sslserver") == 0) { - if (++i == args.length) errorNeedArgument(flags); - sslserver = args[i]; + sslserver = args[++i]; } else if (collator.compare(flags, "-srckeystore") == 0) { - if (++i == args.length) errorNeedArgument(flags); - srcksfname = args[i]; + srcksfname = args[++i]; } else if ((collator.compare(flags, "-provider") == 0) || (collator.compare(flags, "-providerclass") == 0)) { - if (++i == args.length) errorNeedArgument(flags); if (providers == null) { providers = new HashSet> (3); } - String providerClass = args[i]; + String providerClass = args[++i]; String providerArg = null; if (args.length > (i+1)) { @@ -418,19 +491,24 @@ public final class KeyTool { } if (i is not a legal command")); - Object[] source = {args[i]}; - throw new RuntimeException(form.format(source)); + System.err.println(rb.getString("Illegal option: ") + args[i]); + tinyHelp(); } - if (command == -1) { - System.err.println(rb.getString("Usage error: no command provided")); - tinyHelp(); + if (command == null) { + if (help) { + usage(); + } else { + System.err.println(rb.getString("Usage error: no command provided")); + tinyHelp(); + } + } else if (help) { + usage(); + command = null; } } - boolean isKeyStoreRelated(int cmd) { + boolean isKeyStoreRelated(Command cmd) { return cmd != PRINTCERT && cmd != PRINTCERTREQ; } @@ -2600,7 +2678,7 @@ public final class KeyTool { do { if (maxRetry-- < 0) { throw new RuntimeException(rb.getString( - "Too may retries, program terminated")); + "Too many retries, program terminated")); } commonName = inputString(in, rb.getString("What is your first and last name?"), @@ -3086,7 +3164,7 @@ public final class KeyTool { do { if (maxRetry-- < 0) { throw new RuntimeException(rb.getString( - "Too may retries, program terminated")); + "Too many retries, program terminated")); } System.err.print(prompt); System.err.flush(); @@ -3258,7 +3336,8 @@ public final class KeyTool { int nmatch = 0; for (int i = 0; i] [-sigalg ]")); - System.err.println(rb.getString - ("\t [-dname ]")); - System.err.println(rb.getString - ("\t [-file ] [-keypass ]")); - System.err.println(rb.getString - ("\t [-keystore ] [-storepass ]")); - System.err.println(rb.getString - ("\t [-storetype ] [-providername ]")); - System.err.println(rb.getString - ("\t [-providerclass [-providerarg ]] ...")); - System.err.println(rb.getString - ("\t [-providerpath ]")); - System.err.println(); - - System.err.println(rb.getString - ("-changealias [-v] [-protected] -alias -destalias ")); - System.err.println(rb.getString - ("\t [-keypass ]")); - System.err.println(rb.getString - ("\t [-keystore ] [-storepass ]")); - System.err.println(rb.getString - ("\t [-storetype ] [-providername ]")); - System.err.println(rb.getString - ("\t [-providerclass [-providerarg ]] ...")); - System.err.println(rb.getString - ("\t [-providerpath ]")); - System.err.println(); - - System.err.println(rb.getString - ("-delete [-v] [-protected] -alias ")); - System.err.println(rb.getString - ("\t [-keystore ] [-storepass ]")); - System.err.println(rb.getString - ("\t [-storetype ] [-providername ]")); - System.err.println(rb.getString - ("\t [-providerclass [-providerarg ]] ...")); - System.err.println(rb.getString - ("\t [-providerpath ]")); - System.err.println(); - - System.err.println(rb.getString - ("-exportcert [-v] [-rfc] [-protected]")); - System.err.println(rb.getString - ("\t [-alias ] [-file ]")); - System.err.println(rb.getString - ("\t [-keystore ] [-storepass ]")); - System.err.println(rb.getString - ("\t [-storetype ] [-providername ]")); - System.err.println(rb.getString - ("\t [-providerclass [-providerarg ]] ...")); - System.err.println(rb.getString - ("\t [-providerpath ]")); - System.err.println(); - - System.err.println(rb.getString - ("-genkeypair [-v] [-protected]")); - System.err.println(rb.getString - ("\t [-alias ]")); - System.err.println(rb.getString - ("\t [-keyalg ] [-keysize ]")); - System.err.println(rb.getString - ("\t [-sigalg ] [-dname ]")); - System.err.println(rb.getString - ("\t [-startdate ]")); - System.err.println(rb.getString - ("\t [-ext [:critical][=]]...")); - System.err.println(rb.getString - ("\t [-validity ] [-keypass ]")); - System.err.println(rb.getString - ("\t [-keystore ] [-storepass ]")); - System.err.println(rb.getString - ("\t [-storetype ] [-providername ]")); - System.err.println(rb.getString - ("\t [-providerclass [-providerarg ]] ...")); - System.err.println(rb.getString - ("\t [-providerpath ]")); - System.err.println(); - - System.err.println(rb.getString - ("-gencert [-v] [-rfc] [-protected]")); - System.err.println(rb.getString - ("\t [-infile ] [-outfile ]")); - System.err.println(rb.getString - ("\t [-alias ]")); - System.err.println(rb.getString - ("\t [-dname ]")); - System.err.println(rb.getString - ("\t [-sigalg ]")); - System.err.println(rb.getString - ("\t [-startdate ]")); - System.err.println(rb.getString - ("\t [-ext [:critical][=]]...")); - System.err.println(rb.getString - ("\t [-validity ] [-keypass ]")); - System.err.println(rb.getString - ("\t [-keystore ] [-storepass ]")); - System.err.println(rb.getString - ("\t [-storetype ] [-providername ]")); - System.err.println(rb.getString - ("\t [-providerclass [-providerarg ]] ...")); - System.err.println(rb.getString - ("\t [-providerpath ]")); - System.err.println(); - - System.err.println(rb.getString - ("-genseckey [-v] [-protected]")); - System.err.println(rb.getString - ("\t [-alias ] [-keypass ]")); - System.err.println(rb.getString - ("\t [-keyalg ] [-keysize ]")); - System.err.println(rb.getString - ("\t [-keystore ] [-storepass ]")); - System.err.println(rb.getString - ("\t [-storetype ] [-providername ]")); - System.err.println(rb.getString - ("\t [-providerclass [-providerarg ]] ...")); - System.err.println(rb.getString - ("\t [-providerpath ]")); - System.err.println(); - - System.err.println(rb.getString("-help")); - System.err.println(); - - System.err.println(rb.getString - ("-importcert [-v] [-noprompt] [-trustcacerts] [-protected]")); - System.err.println(rb.getString - ("\t [-alias ]")); - System.err.println(rb.getString - ("\t [-file ] [-keypass ]")); - System.err.println(rb.getString - ("\t [-keystore ] [-storepass ]")); - System.err.println(rb.getString - ("\t [-storetype ] [-providername ]")); - System.err.println(rb.getString - ("\t [-providerclass [-providerarg ]] ...")); - System.err.println(rb.getString - ("\t [-providerpath ]")); - System.err.println(); - - System.err.println(rb.getString - ("-importkeystore [-v] ")); - System.err.println(rb.getString - ("\t [-srckeystore ] [-destkeystore ]")); - System.err.println(rb.getString - ("\t [-srcstoretype ] [-deststoretype ]")); - System.err.println(rb.getString - ("\t [-srcstorepass ] [-deststorepass ]")); - System.err.println(rb.getString - ("\t [-srcprotected] [-destprotected]")); - System.err.println(rb.getString - ("\t [-srcprovidername ]\n\t [-destprovidername ]")); - System.err.println(rb.getString - ("\t [-srcalias [-destalias ]")); - System.err.println(rb.getString - ("\t [-srckeypass ] [-destkeypass ]]")); - System.err.println(rb.getString - ("\t [-noprompt]")); - System.err.println(rb.getString - ("\t [-providerclass [-providerarg ]] ...")); - System.err.println(rb.getString - ("\t [-providerpath ]")); - System.err.println(); - - System.err.println(rb.getString - ("-keypasswd [-v] [-alias ]")); - System.err.println(rb.getString - ("\t [-keypass ] [-new ]")); - System.err.println(rb.getString - ("\t [-keystore ] [-storepass ]")); - System.err.println(rb.getString - ("\t [-storetype ] [-providername ]")); - System.err.println(rb.getString - ("\t [-providerclass [-providerarg ]] ...")); - System.err.println(rb.getString - ("\t [-providerpath ]")); - System.err.println(); - - System.err.println(rb.getString - ("-list [-v | -rfc] [-protected]")); - System.err.println(rb.getString - ("\t [-alias ]")); - System.err.println(rb.getString - ("\t [-keystore ] [-storepass ]")); - System.err.println(rb.getString - ("\t [-storetype ] [-providername ]")); - System.err.println(rb.getString - ("\t [-providerclass [-providerarg ]] ...")); - System.err.println(rb.getString - ("\t [-providerpath ]")); - System.err.println(); - - System.err.println(rb.getString - ("-printcert [-v] [-rfc] [-file | -sslserver ]")); - System.err.println(); - - System.err.println(rb.getString - ("-printcertreq [-v] [-file ]")); - System.err.println(); + if (command != null) { + System.err.println("keytool " + command + + rb.getString(" [OPTION]...")); + System.err.println(); + System.err.println(rb.getString(command.description)); + System.err.println(); + System.err.println(rb.getString("Options:")); + System.err.println(); - System.err.println(rb.getString - ("-storepasswd [-v] [-new ]")); - System.err.println(rb.getString - ("\t [-keystore ] [-storepass ]")); - System.err.println(rb.getString - ("\t [-storetype ] [-providername ]")); - System.err.println(rb.getString - ("\t [-providerclass [-providerarg ]] ...")); - System.err.println(rb.getString - ("\t [-providerpath ]")); + // Left and right sides of the options list + String[] left = new String[command.options.length]; + String[] right = new String[command.options.length]; + + // Check if there's an unknown option + boolean found = false; + + // Length of left side of options list + int lenLeft = 0; + for (int j=0; j lenLeft) { + lenLeft = left[j].length(); + } + right[j] = rb.getString(opt[2]); + found = true; + break; + } + } + if (!found) { + throw new RuntimeException("ERROR: CANNOT FIND " + command.options[j]); + } + } + for (int j=0; j needs an argument.", "Command option {0} needs an argument."}, {"Warning: Different store and key passwords not supported for PKCS12 KeyStores. Ignoring user-specified value.", "Warning: Different store and key passwords not supported for PKCS12 KeyStores. Ignoring user-specified {0} value."}, {"-keystore must be NONE if -storetype is {0}", "-keystore must be NONE if -storetype is {0}"}, - {"Too may retries, program terminated", - "Too may retries, program terminated"}, + {"Too many retries, program terminated", + "Too many retries, program terminated"}, {"-storepasswd and -keypasswd commands not supported if -storetype is {0}", "-storepasswd and -keypasswd commands not supported if -storetype is {0}"}, {"-keypasswd commands not supported if -storetype is PKCS12", @@ -77,7 +204,6 @@ public class Resources extends java.util.ListResourceBundle { "Validity must be greater than zero"}, {"provName not a provider", "{0} not a provider"}, {"Usage error: no command provided", "Usage error: no command provided"}, - {"Usage error, is not a legal command", "Usage error, {0} is not a legal command"}, {"Source keystore file exists, but is empty: ", "Source keystore file exists, but is empty: "}, {"Please specify -srckeystore", "Please specify -srckeystore"}, {"Must not specify both -v and -rfc with 'list' command", @@ -279,7 +405,6 @@ public class Resources extends java.util.ListResourceBundle { "Secret Key not generated, alias <{0}> already exists"}, {"Please provide -keysize for secret key generation", "Please provide -keysize for secret key generation"}, - {"keytool usage:\n", "keytool usage:\n"}, {"Extensions: ", "Extensions: "}, {"(Empty value)", "(Empty value)"}, @@ -297,139 +422,6 @@ public class Resources extends java.util.ListResourceBundle { {"Odd number of hex digits found: ", "Odd number of hex digits found: "}, {"command {0} is ambiguous:", "command {0} is ambiguous:"}, - {"-certreq [-v] [-protected]", - "-certreq [-v] [-protected]"}, - {"\t [-alias ] [-sigalg ]", - "\t [-alias ] [-sigalg ]"}, - {"\t [-dname ]", "\t [-dname ]"}, - {"\t [-file ] [-keypass ]", - "\t [-file ] [-keypass ]"}, - {"\t [-keystore ] [-storepass ]", - "\t [-keystore ] [-storepass ]"}, - {"\t [-storetype ] [-providername ]", - "\t [-storetype ] [-providername ]"}, - {"\t [-providerclass [-providerarg ]] ...", - "\t [-providerclass [-providerarg ]] ..."}, - {"\t [-providerpath ]", - "\t [-providerpath ]"}, - {"-delete [-v] [-protected] -alias ", - "-delete [-v] [-protected] -alias "}, - /** rest is same as -certreq starting from -keystore **/ - - //{"-export [-v] [-rfc] [-protected]", - // "-export [-v] [-rfc] [-protected]"}, - {"-exportcert [-v] [-rfc] [-protected]", - "-exportcert [-v] [-rfc] [-protected]"}, - {"\t [-alias ] [-file ]", - "\t [-alias ] [-file ]"}, - /** rest is same as -certreq starting from -keystore **/ - - //{"-genkey [-v] [-protected]", - // "-genkey [-v] [-protected]"}, - {"-genkeypair [-v] [-protected]", - "-genkeypair [-v] [-protected]"}, - {"\t [-alias ]", "\t [-alias ]"}, - {"\t [-keyalg ] [-keysize ]", - "\t [-keyalg ] [-keysize ]"}, - {"\t [-sigalg ] [-dname ]", - "\t [-sigalg ] [-dname ]"}, - {"\t [-startdate ]", - "\t [-startdate ]"}, - {"\t [-validity ] [-keypass ]", - "\t [-validity ] [-keypass ]"}, - /** rest is same as -certreq starting from -keystore **/ - {"-gencert [-v] [-rfc] [-protected]", - "-gencert [-v] [-rfc] [-protected]"}, - {"\t [-infile ] [-outfile ]", - "\t [-infile ] [-outfile ]"}, - {"\t [-sigalg ]", - "\t [-sigalg ]"}, - {"\t [-ext [:critical][=]]...", - "\t [-ext [:critical][=]]..."}, - - {"-genseckey [-v] [-protected]", - "-genseckey [-v] [-protected]"}, - /** rest is same as -certreq starting from -keystore **/ - - {"-help", "-help"}, - //{"-identitydb [-v] [-protected]", - // "-identitydb [-v] [-protected]"}, - //{"\t [-file ]", "\t [-file ]"}, - /** rest is same as -certreq starting from -keystore **/ - - //{"-import [-v] [-noprompt] [-trustcacerts] [-protected]", - // "-import [-v] [-noprompt] [-trustcacerts] [-protected]"}, - {"-importcert [-v] [-noprompt] [-trustcacerts] [-protected]", - "-importcert [-v] [-noprompt] [-trustcacerts] [-protected]"}, - {"\t [-alias ]", "\t [-alias ]"}, - {"\t [-alias ] [-keypass ]", - "\t [-alias ] [-keypass ]"}, - {"\t [-file ] [-keypass ]", - "\t [-file ] [-keypass ]"}, - /** rest is same as -certreq starting from -keystore **/ - - {"-importkeystore [-v] ", - "-importkeystore [-v] "}, - {"\t [-srckeystore ] [-destkeystore ]", - "\t [-srckeystore ] [-destkeystore ]"}, - {"\t [-srcstoretype ] [-deststoretype ]", - "\t [-srcstoretype ] [-deststoretype ]"}, - {"\t [-srcprotected] [-destprotected]", - "\t [-srcprotected] [-destprotected]"}, - {"\t [-srcstorepass ] [-deststorepass ]", - "\t [-srcstorepass ] [-deststorepass ]"}, - {"\t [-srcprovidername ]\n\t [-destprovidername ]", // line too long, split to 2 - "\t [-srcprovidername ]\n\t [-destprovidername ]"}, - {"\t [-srcalias [-destalias ]", - "\t [-srcalias [-destalias ]"}, - {"\t [-srckeypass ] [-destkeypass ]]", - "\t [-srckeypass ] [-destkeypass ]]"}, - {"\t [-noprompt]", "\t [-noprompt]"}, - /** rest is same as -certreq starting from -keystore **/ - - {"-changealias [-v] [-protected] -alias -destalias ", - "-changealias [-v] [-protected] -alias -destalias "}, - {"\t [-keypass ]", "\t [-keypass ]"}, - - //{"-keyclone [-v] [-protected]", - // "-keyclone [-v] [-protected]"}, - //{"\t [-alias ] -dest ", - // "\t [-alias ] -dest "}, - //{"\t [-keypass ] [-new ]", - // "\t [-keypass ] [-new ]"}, - /** rest is same as -certreq starting from -keystore **/ - - {"-keypasswd [-v] [-alias ]", - "-keypasswd [-v] [-alias ]"}, - {"\t [-keypass ] [-new ]", - "\t [-keypass ] [-new ]"}, - /** rest is same as -certreq starting from -keystore **/ - - {"-list [-v | -rfc] [-protected]", - "-list [-v | -rfc] [-protected]"}, - {"\t [-alias ]", "\t [-alias ]"}, - /** rest is same as -certreq starting from -keystore **/ - - {"-printcert [-v] [-rfc] [-file | -sslserver ]", - "-printcert [-v] [-rfc] [-file | -sslserver ]"}, - {"-printcertreq [-v] [-file ]", - "-printcertreq [-v] [-file ]"}, - {"No certificate from the SSL server", - "No certificate from the SSL server"}, - - //{"-selfcert [-v] [-protected]", - // "-selfcert [-v] [-protected]"}, - {"\t [-alias ]", "\t [-alias ]"}, - //{"\t [-dname ] [-validity ]", - // "\t [-dname ] [-validity ]"}, - //{"\t [-keypass ] [-sigalg ]", - // "\t [-keypass ] [-sigalg ]"}, - /** rest is same as -certreq starting from -keystore **/ - - {"-storepasswd [-v] [-new ]", - "-storepasswd [-v] [-new ]"}, - /** rest is same as -certreq starting from -keystore **/ - // policytool {"Warning: A public key for alias 'signers[i]' does not exist. Make sure a KeyStore is properly configured.", "Warning: A public key for alias {0} does not exist. Make sure a KeyStore is properly configured."}, @@ -679,3 +671,4 @@ public class Resources extends java.util.ListResourceBundle { return contents; } } + diff --git a/test/sun/security/tools/keytool/newhelp.sh b/test/sun/security/tools/keytool/newhelp.sh new file mode 100644 index 000000000..08c7422e5 --- /dev/null +++ b/test/sun/security/tools/keytool/newhelp.sh @@ -0,0 +1,53 @@ +# +# Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# This code is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License version 2 only, as +# published by the Free Software Foundation. +# +# This code is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +# version 2 for more details (a copy is included in the LICENSE file that +# accompanied this code). +# +# You should have received a copy of the GNU General Public License version +# 2 along with this work; if not, write to the Free Software Foundation, +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. +# +# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, +# CA 95054 USA or visit www.sun.com if you need additional information or +# have any questions. +# + +# @test +# @bug 6324292 +# @summary keytool -help is unhelpful +# + +if [ "${TESTJAVA}" = "" ] ; then + JAVAC_CMD=`which javac` + TESTJAVA=`dirname $JAVAC_CMD`/.. +fi + +# set platform-dependent variables +OS=`uname -s` +case "$OS" in + Windows_* ) + FS="\\" + ;; + * ) + FS="/" + ;; +esac + +LANG=C +$TESTJAVA${FS}bin${FS}keytool -help 2> h1 || exit 1 +$TESTJAVA${FS}bin${FS}keytool -help -list 2> h2 || exit 2 + +grep Commands: h1 || exit 3 +grep Options: h2 || exit 4 + +exit 0 + -- GitLab