/** * main() entry point for the KeyShell. While strictly speaking the * return is void, it will System.exit() with a return code: 0 is for * success and 1 for failure. * * @param args Command line arguments. * @throws Exception */ public static void main(String[] args) throws Exception { int res = ToolRunner.run(new Configuration(), new KeyShell(), args); System.exit(res); } }
public boolean validate() { boolean rc = true; provider = getKeyProvider(); if (provider == null) { rc = false; } metadata = getConf().getBoolean(LIST_METADATA, false); return rc; }
protected KeyProvider getKeyProvider() { KeyProvider prov = null; List<KeyProvider> providers; try { providers = KeyProviderFactory.getProviders(getConf()); if (userSuppliedProvider) { prov = providers.get(0); } else { for (KeyProvider p : providers) { if (!p.isTransient()) { prov = p; break; } } } } catch (IOException e) { e.printStackTrace(getErr()); } if (prov == null) { getOut().println(NO_VALID_PROVIDERS); } return prov; }
final Options options = KeyProvider.options(getConf()); final Map<String, String> attributes = new HashMap<String, String>(); setSubCommand(new CreateCommand(keyName, options)); if ("-help".equals(keyName)) { return 1; setSubCommand(new DeleteCommand(keyName)); if ("-help".equals(keyName)) { return 1; setSubCommand(new RollCommand(keyName)); if ("-help".equals(keyName)) { return 1; setSubCommand(new ListCommand()); } else if ("invalidateCache".equals(args[i])) { String keyName = "-help"; setSubCommand(new InvalidateCacheCommand(keyName)); if ("-help".equals(keyName)) { return 1; final String val = attrval[1].trim(); if (attr.isEmpty() || val.isEmpty()) { getOut().println("\nAttributes must be in attribute=value form, " + "or quoted\nlike \"attribute = value\"\n"); return 1;
@Test public void testInvalidKeySize() throws Exception { final String[] args1 = {"create", "key1", "-size", "56", "-provider", jceksProvider}; int rc = 0; KeyShell ks = new KeyShell(); ks.setConf(new Configuration()); rc = ks.run(args1); assertEquals(1, rc); assertTrue(outContent.toString().contains("key1 has not been created.")); }
final Options options = KeyProvider.options(getConf()); final Map<String, String> attributes = new HashMap<String, String>(); printKeyShellUsage(); return 1; printKeyShellUsage(); return 1; printKeyShellUsage(); return 1; out.println("\nAttributes must be in attribute=value form, " + "or quoted\nlike \"attribute = value\"\n"); printKeyShellUsage(); return 1; out.println("\nEach attribute must correspond to only one value:\n" + "atttribute \"" + attr + "\" was repeated\n" ); printKeyShellUsage(); return 1; } else if ("-provider".equals(args[i]) && moreTokens) { userSuppliedProvider = true; getConf().set(KeyProviderFactory.KEY_PROVIDER_PATH, args[++i]); } else if ("-metadata".equals(args[i])) { getConf().setBoolean(LIST_METADATA, true); } else if ("-f".equals(args[i]) || ("-force".equals(args[i]))) { interactive = false;
/** * Primary entry point for the KeyShell; called via main(). * * @param args Command line arguments. * @return 0 on success and 1 on failure. This value is passed back to * the unix shell, so we must follow shell return code conventions: * the return code is an unsigned character, and 0 means success, and * small positive integers mean failure. * @throws Exception */ @Override public int run(String[] args) throws Exception { int exitCode = 0; try { exitCode = init(args); if (exitCode != 0) { return exitCode; } if (command.validate()) { command.execute(); } else { exitCode = 1; } } catch (Exception e) { e.printStackTrace(err); return 1; } return exitCode; }
/** * Lists the keys in the jceksProvider * @param ks The KeyShell instance * @param wantMetadata True if you want metadata returned with the keys * @return The output from the "list" call * @throws Exception */ private String listKeys(KeyShell ks, boolean wantMetadata) throws Exception { int rc; outContent.reset(); final String[] listArgs = {"list", "-provider", jceksProvider }; final String[] listArgsM = {"list", "-metadata", "-provider", jceksProvider }; rc = ks.run(wantMetadata ? listArgsM : listArgs); assertEquals(0, rc); return outContent.toString(); }
@Test public void testInvalidCipher() throws Exception { final String[] args1 = {"create", "key1", "-cipher", "LJM", "-provider", jceksProvider}; int rc = 0; KeyShell ks = new KeyShell(); ks.setConf(new Configuration()); rc = ks.run(args1); assertEquals(1, rc); assertTrue(outContent.toString().contains("key1 has not been created.")); }
final Options options = KeyProvider.options(getConf()); final Map<String, String> attributes = new HashMap<String, String>(); printKeyShellUsage(); return 1; printKeyShellUsage(); return 1; printKeyShellUsage(); return 1; out.println("\nAttributes must be in attribute=value form, " + "or quoted\nlike \"attribute = value\"\n"); printKeyShellUsage(); return 1; out.println("\nEach attribute must correspond to only one value:\n" + "atttribute \"" + attr + "\" was repeated\n" ); printKeyShellUsage(); return 1; } else if ("-provider".equals(args[i]) && moreTokens) { userSuppliedProvider = true; getConf().set(KeyProviderFactory.KEY_PROVIDER_PATH, args[++i]); } else if ("-metadata".equals(args[i])) { getConf().setBoolean(LIST_METADATA, true); } else if ("-f".equals(args[i]) || ("-force".equals(args[i]))) { interactive = false;
/** * Primary entry point for the KeyShell; called via main(). * * @param args Command line arguments. * @return 0 on success and 1 on failure. This value is passed back to * the unix shell, so we must follow shell return code conventions: * the return code is an unsigned character, and 0 means success, and * small positive integers mean failure. * @throws Exception */ @Override public int run(String[] args) throws Exception { int exitCode = 0; try { exitCode = init(args); if (exitCode != 0) { return exitCode; } if (command.validate()) { command.execute(); } else { exitCode = 1; } } catch (Exception e) { e.printStackTrace(err); return 1; } return exitCode; }
/** * Lists the keys in the jceksProvider * @param ks The KeyShell instance * @param wantMetadata True if you want metadata returned with the keys * @return The output from the "list" call * @throws Exception */ private String listKeys(KeyShell ks, boolean wantMetadata) throws Exception { int rc; outContent.reset(); final String[] listArgs = {"list", "-provider", jceksProvider }; final String[] listArgsM = {"list", "-metadata", "-provider", jceksProvider }; rc = ks.run(wantMetadata ? listArgsM : listArgs); assertEquals(0, rc); return outContent.toString(); }
@Test public void testInvalidCipher() throws Exception { final String[] args1 = {"create", "key1", "-cipher", "LJM", "-provider", jceksProvider}; int rc = 0; KeyShell ks = new KeyShell(); ks.setConf(new Configuration()); rc = ks.run(args1); assertEquals(1, rc); assertTrue(outContent.toString().contains("key1 has not been created.")); }
final Options options = KeyProvider.options(getConf()); final Map<String, String> attributes = new HashMap<String, String>(); printKeyShellUsage(); return 1; printKeyShellUsage(); return 1; printKeyShellUsage(); return 1; out.println("\nAttributes must be in attribute=value form, " + "or quoted\nlike \"attribute = value\"\n"); printKeyShellUsage(); return 1; out.println("\nEach attribute must correspond to only one value:\n" + "atttribute \"" + attr + "\" was repeated\n" ); printKeyShellUsage(); return 1; } else if ("-provider".equals(args[i]) && moreTokens) { userSuppliedProvider = true; getConf().set(KeyProviderFactory.KEY_PROVIDER_PATH, args[++i]); } else if ("-metadata".equals(args[i])) { getConf().setBoolean(LIST_METADATA, true); } else if ("-f".equals(args[i]) || ("-force".equals(args[i]))) { interactive = false;
/** * main() entry point for the KeyShell. While strictly speaking the * return is void, it will System.exit() with a return code: 0 is for * success and 1 for failure. * * @param args Command line arguments. * @throws Exception */ public static void main(String[] args) throws Exception { int res = ToolRunner.run(new Configuration(), new KeyShell(), args); System.exit(res); } }
public boolean validate() { boolean rc = true; provider = getKeyProvider(); if (provider == null) { out.println("There are no non-transient KeyProviders configured.\n" + "Use the -provider option to specify a provider. If you\n" + "want to list a transient provider then you must use the\n" + "-provider argument."); rc = false; } metadata = getConf().getBoolean(LIST_METADATA, false); return rc; }
/** * Primary entry point for the KeyShell; called via main(). * * @param args Command line arguments. * @return 0 on success and 1 on failure. This value is passed back to * the unix shell, so we must follow shell return code conventions: * the return code is an unsigned character, and 0 means success, and * small positive integers mean failure. * @throws Exception */ @Override public int run(String[] args) throws Exception { int exitCode = 0; try { exitCode = init(args); if (exitCode != 0) { return exitCode; } if (command.validate()) { command.execute(); } else { exitCode = 1; } } catch (Exception e) { e.printStackTrace(err); return 1; } return exitCode; }
/** * Delete a key from the default jceksProvider * @param ks The KeyShell instance * @param keyName The key to delete * @throws Exception */ private void deleteKey(KeyShell ks, String keyName) throws Exception { int rc; outContent.reset(); final String[] delArgs = {"delete", keyName, "-f", "-provider", jceksProvider}; rc = ks.run(delArgs); assertEquals(0, rc); assertTrue(outContent.toString().contains(keyName + " has been " + "successfully deleted.")); }
@Test public void testTransientProviderWarning() throws Exception { final String[] args1 = {"create", "key1", "-cipher", "AES", "-provider", "user:///"}; int rc = 0; KeyShell ks = new KeyShell(); ks.setConf(new Configuration()); rc = ks.run(args1); assertEquals(0, rc); assertTrue(outContent.toString().contains("WARNING: you are modifying a " + "transient provider.")); }
final Options options = KeyProvider.options(getConf()); final Map<String, String> attributes = new HashMap<String, String>(); printKeyShellUsage(); return 1; printKeyShellUsage(); return 1; printKeyShellUsage(); return 1; out.println("\nAttributes must be in attribute=value form, " + "or quoted\nlike \"attribute = value\"\n"); printKeyShellUsage(); return 1; out.println("\nEach attribute must correspond to only one value:\n" + "atttribute \"" + attr + "\" was repeated\n" ); printKeyShellUsage(); return 1; } else if ("-provider".equals(args[i]) && moreTokens) { userSuppliedProvider = true; getConf().set(KeyProviderFactory.KEY_PROVIDER_PATH, args[++i]); } else if ("-metadata".equals(args[i])) { getConf().setBoolean(LIST_METADATA, true); } else if ("-f".equals(args[i]) || ("-force".equals(args[i]))) { interactive = false;