/** * 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); } }
/** * 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); } }
/** * 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); } }
/** * 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); } }
/** * 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); } }
@Test public void testTransientProviderOnlyConfig() throws Exception { final String[] args1 = {"create", "key1"}; int rc = 0; KeyShell ks = new KeyShell(); Configuration config = new Configuration(); config.set(KeyProviderFactory.KEY_PROVIDER_PATH, "user:///"); ks.setConf(config); rc = ks.run(args1); assertEquals(1, rc); assertTrue(outContent.toString().contains("There are no valid " + "KeyProviders configured.")); }
@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.")); }
@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.")); }
@Test public void testTransientProviderOnlyConfig() throws Exception { final String[] args1 = {"create", "key1"}; int rc = 0; KeyShell ks = new KeyShell(); Configuration config = new Configuration(); config.set(KeyProviderFactory.KEY_PROVIDER_PATH, "user:///"); ks.setConf(config); rc = ks.run(args1); assertEquals(1, rc); assertTrue(outContent.toString().contains("There are no valid " + "KeyProviders configured.")); }
@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.")); }
@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.")); }
@Test public void testInvalidProvider() throws Exception { final String[] args1 = {"create", "key1", "-cipher", "AES", "-provider", "sdff://file/tmp/keystore.jceks"}; int rc = 0; KeyShell ks = new KeyShell(); ks.setConf(new Configuration()); rc = ks.run(args1); assertEquals(1, rc); assertTrue(outContent.toString().contains("There are no valid " + "KeyProviders configured.")); }
@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.")); }
@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.")); }
@Test public void testInvalidProvider() throws Exception { final String[] args1 = {"create", "key1", "-cipher", "AES", "-provider", "sdff://file/tmp/keystore.jceks"}; int rc = 0; KeyShell ks = new KeyShell(); ks.setConf(new Configuration()); rc = ks.run(args1); assertEquals(1, rc); assertTrue(outContent.toString().contains("There are no valid " + "KeyProviders configured.")); }
@Test public void testFullCipher() throws Exception { final String keyName = "key1"; final String[] args1 = {"create", keyName, "-cipher", "AES/CBC/pkcs5Padding", "-provider", jceksProvider}; int rc = 0; KeyShell ks = new KeyShell(); ks.setConf(new Configuration()); rc = ks.run(args1); assertEquals(0, rc); assertTrue(outContent.toString().contains(keyName + " has been " + "successfully created")); deleteKey(ks, keyName); }
@Test public void testKeySuccessfulCreationWithDescription() throws Exception { outContent.reset(); final String[] args1 = {"create", "key1", "-provider", jceksProvider, "-description", "someDescription"}; int rc = 0; KeyShell ks = new KeyShell(); ks.setConf(new Configuration()); rc = ks.run(args1); assertEquals(0, rc); assertTrue(outContent.toString().contains("key1 has been successfully " + "created")); String listOut = listKeys(ks, true); assertTrue(listOut.contains("description")); assertTrue(listOut.contains("someDescription")); }
@Test public void testKeySuccessfulCreationWithDescription() throws Exception { outContent.reset(); final String[] args1 = {"create", "key1", "-provider", jceksProvider, "-description", "someDescription"}; int rc = 0; KeyShell ks = new KeyShell(); ks.setConf(new Configuration()); rc = ks.run(args1); assertEquals(0, rc); assertTrue(outContent.toString().contains("key1 has been successfully " + "created")); String listOut = listKeys(ks, true); assertTrue(listOut.contains("description")); assertTrue(listOut.contains("someDescription")); }
@Test public void testFullCipher() throws Exception { final String keyName = "key1"; final String[] args1 = {"create", keyName, "-cipher", "AES/CBC/pkcs5Padding", "-provider", jceksProvider}; int rc = 0; KeyShell ks = new KeyShell(); ks.setConf(new Configuration()); rc = ks.run(args1); assertEquals(0, rc); assertTrue(outContent.toString().contains(keyName + " has been " + "successfully created")); deleteKey(ks, keyName); }
@Test public void testKeySuccessfulKeyLifecycle() throws Exception { int rc = 0; String keyName = "key1"; KeyShell ks = new KeyShell(); ks.setConf(new Configuration()); outContent.reset(); final String[] args1 = {"create", keyName, "-provider", jceksProvider}; rc = ks.run(args1); assertEquals(0, rc); assertTrue(outContent.toString().contains(keyName + " has been " + "successfully created")); String listOut = listKeys(ks, false); assertTrue(listOut.contains(keyName)); listOut = listKeys(ks, true); assertTrue(listOut.contains(keyName)); assertTrue(listOut.contains("description")); assertTrue(listOut.contains("created")); outContent.reset(); final String[] args2 = {"roll", keyName, "-provider", jceksProvider}; rc = ks.run(args2); assertEquals(0, rc); assertTrue(outContent.toString().contains("key1 has been successfully " + "rolled.")); deleteKey(ks, keyName); listOut = listKeys(ks, false); assertFalse(listOut, listOut.contains(keyName)); }