From 6de5b60438f0edeb3d18f715d90a94191bd05cc8 Mon Sep 17 00:00:00 2001 From: Abhishek Koneru Date: Wed, 9 Apr 2014 13:59:26 -0400 Subject: Fixes for comments on patches 87 and 89 --- .../com/netscape/cmstools/key/KeyArchiveCLI.java | 8 +- .../src/com/netscape/cmstools/key/KeyCLI.java | 6 +- .../com/netscape/cmstools/key/KeyGenerateCLI.java | 36 +++-- .../com/netscape/cmstools/key/KeyModifyCLI.java | 9 +- .../com/netscape/cmstools/key/KeyRecoverCLI.java | 12 +- .../netscape/cmstools/key/KeyRequestReviewCLI.java | 4 +- .../netscape/cmstools/key/KeyRequestShowCLI.java | 2 +- .../cmstools/key/KeyRequestTemplateFindCLI.java | 43 ------ .../cmstools/key/KeyRequestTemplateShowCLI.java | 154 --------------------- .../com/netscape/cmstools/key/KeyRetrieveCLI.java | 51 +++++-- .../src/com/netscape/cmstools/key/KeyShowCLI.java | 2 +- .../netscape/cmstools/key/KeyTemplateFindCLI.java | 66 +++++++++ .../netscape/cmstools/key/KeyTemplateShowCLI.java | 93 +++++++++++++ 13 files changed, 237 insertions(+), 249 deletions(-) delete mode 100644 base/java-tools/src/com/netscape/cmstools/key/KeyRequestTemplateFindCLI.java delete mode 100644 base/java-tools/src/com/netscape/cmstools/key/KeyRequestTemplateShowCLI.java create mode 100644 base/java-tools/src/com/netscape/cmstools/key/KeyTemplateFindCLI.java create mode 100644 base/java-tools/src/com/netscape/cmstools/key/KeyTemplateShowCLI.java (limited to 'base/java-tools/src/com') diff --git a/base/java-tools/src/com/netscape/cmstools/key/KeyArchiveCLI.java b/base/java-tools/src/com/netscape/cmstools/key/KeyArchiveCLI.java index ced51ad74..209231c2c 100644 --- a/base/java-tools/src/com/netscape/cmstools/key/KeyArchiveCLI.java +++ b/base/java-tools/src/com/netscape/cmstools/key/KeyArchiveCLI.java @@ -21,7 +21,7 @@ public class KeyArchiveCLI extends CLI { public KeyCLI keyCLI; public KeyArchiveCLI(KeyCLI keyCLI) { - super("archive", "Archive a secret at the DRM.", keyCLI); + super("archive", "Archive a secret in the DRM.", keyCLI); this.keyCLI = keyCLI; } @@ -31,7 +31,7 @@ public class KeyArchiveCLI extends CLI { public void execute(String[] args) { - Option option = new Option(null, "clientKeyId", true, "Unique client key identifier."); + Option option = new Option(null, "clientKeyID", true, "Unique client key identifier."); option.setArgName("Client Key Identifier"); options.addOption(option); @@ -58,7 +58,7 @@ public class KeyArchiveCLI extends CLI { KeyRequestResponse response = null; - if ((requestFile != null) && (requestFile.trim().length() != 0)) { + if (requestFile != null) { // Case where the request template file is used. For pre-encrypted data. try { JAXBContext context = JAXBContext.newInstance(KeyArchivalRequest.class); @@ -91,7 +91,7 @@ public class KeyArchiveCLI extends CLI { } else { // Simple case for archiving a passphrase - String clientKeyId = cmd.getOptionValue("clientKeyId"); + String clientKeyId = cmd.getOptionValue("clientKeyID"); String passphrase = cmd.getOptionValue("passphrase"); if (clientKeyId == null) { System.err.println("Error: Client Key Id is not specified."); diff --git a/base/java-tools/src/com/netscape/cmstools/key/KeyCLI.java b/base/java-tools/src/com/netscape/cmstools/key/KeyCLI.java index f64b8d762..1b8ae64b5 100644 --- a/base/java-tools/src/com/netscape/cmstools/key/KeyCLI.java +++ b/base/java-tools/src/com/netscape/cmstools/key/KeyCLI.java @@ -43,8 +43,8 @@ public class KeyCLI extends CLI { addModule(new KeyShowCLI(this)); addModule(new KeyRequestShowCLI(this)); addModule(new KeyModifyCLI(this)); - addModule(new KeyRequestTemplateFindCLI(this)); - addModule(new KeyRequestTemplateShowCLI(this)); + addModule(new KeyTemplateFindCLI(this)); + addModule(new KeyTemplateShowCLI(this)); addModule(new KeyArchiveCLI(this)); addModule(new KeyRetrieveCLI(this)); addModule(new KeyGenerateCLI(this)); @@ -72,7 +72,7 @@ public class KeyCLI extends CLI { // create new key client keyClient = new KeyClient(client, subsystem); - if ((client.getConfig().getCertDatabase() != null) && (client.getConfig().getCertPassword() != null)) { + if (client.getConfig().getCertDatabase() != null && client.getConfig().getCertPassword() != null) { keyClient.setCrypto(new NSSCryptoProvider(client.getConfig())); // Set the transport cert for crypto operations diff --git a/base/java-tools/src/com/netscape/cmstools/key/KeyGenerateCLI.java b/base/java-tools/src/com/netscape/cmstools/key/KeyGenerateCLI.java index 5edf9489c..0a07ebabd 100644 --- a/base/java-tools/src/com/netscape/cmstools/key/KeyGenerateCLI.java +++ b/base/java-tools/src/com/netscape/cmstools/key/KeyGenerateCLI.java @@ -1,6 +1,5 @@ package com.netscape.cmstools.key; -import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -27,21 +26,23 @@ public class KeyGenerateCLI extends CLI { public void execute(String[] args) { Option option = new Option(null, "key-algorithm", true, - "Algorithm to be used to create a key.\n Supported types [AES,DES,DES3,RC2,RC4,DESede]"); - option.setArgName("Key algorithm"); + "Algorithm to be used to create a key.\nValid values: AES, DES, DES3, RC2, RC4, DESede."); + option.setArgName("algorithm"); option.setRequired(true); options.addOption(option); - option = new Option(null, "key-size", true, - "Size of the key to be generated. Required for all algorithms AES and RC2.\n" - + "Valid size values:\n AES - 128, 192. 256.\n RC2 - >=8, <=128"); - option.setArgName("Key size"); + option = new Option( + null, + "key-size", + true, + "Size of the key to be generated.\nThis is required for AES, RC2 and RC4.\n" + + "Valid values for AES: 128, 192. 256.\nValid values for RC2: 8-128.\n Valid values for RC4: Any positive integer."); + option.setArgName("size"); options.addOption(option); - option = new Option(null, "usages", true, "Comma seperated list of usages." - + "\n Usage1,Usage2,Usage3.. .\n " - + "Valid usages: [wrap, unwrap, sign, verify, encrypt, decrypt]."); - option.setArgName("Usages"); + option = new Option(null, "usages", true, "Comma separated list of usages." + + "\nValid values: wrap, unwrap, sign, verify, encrypt, decrypt."); + option.setArgName("list of usages"); options.addOption(option); CommandLine cmd = null; @@ -75,8 +76,6 @@ public class KeyGenerateCLI extends CLI { keySize = "56"; break; case KeyRequestResource.RC4_ALGORITHM: - keySize = "0"; - break; case KeyRequestResource.AES_ALGORITHM: case KeyRequestResource.RC2_ALGORITHM: System.err.println("Error: Key size must be specified for the algorithm used."); @@ -88,15 +87,14 @@ public class KeyGenerateCLI extends CLI { System.exit(1); } } - List usagesList = null; - if (cmd.getOptionValue("usages") != null) { - String[] usages = cmd.getOptionValue("usages").split(","); - usagesList = new ArrayList(Arrays.asList(usages)); + List usages = null; + String givenUsages = cmd.getOptionValue("usages"); + if (givenUsages != null) { + usages = Arrays.asList(givenUsages.split(",")); } - KeyRequestResponse response = keyCLI.keyClient.generateSymmetricKey(clientKeyId, keyAlgorithm, Integer.parseInt(keySize), - usagesList, null); + usages, null); MainCLI.printMessage("Key generation request info"); KeyCLI.printKeyRequestInfo(response.getRequestInfo()); diff --git a/base/java-tools/src/com/netscape/cmstools/key/KeyModifyCLI.java b/base/java-tools/src/com/netscape/cmstools/key/KeyModifyCLI.java index e5da6e792..6ae49ce5d 100644 --- a/base/java-tools/src/com/netscape/cmstools/key/KeyModifyCLI.java +++ b/base/java-tools/src/com/netscape/cmstools/key/KeyModifyCLI.java @@ -40,7 +40,7 @@ public class KeyModifyCLI extends CLI { public void execute(String[] args) { - Option option = new Option(null, "status", true, "Status of the key.\n Valid values:[active,inactive]"); + Option option = new Option(null, "status", true, "Status of the key.\nValid values: active, inactive"); option.setRequired(true); option.setArgName("status"); options.addOption(option); @@ -72,11 +72,6 @@ public class KeyModifyCLI extends CLI { keyCLI.keyClient.modifyKeyStatus(keyId, status); KeyInfo keyInfo = keyCLI.keyClient.getKeyInfo(keyId); - if (keyInfo.getStatus().equalsIgnoreCase(status)) { - System.out.println("Success!"); - KeyCLI.printKeyInfo(keyInfo); - } else { - System.out.println("Failure! Key status not modified."); - } + KeyCLI.printKeyInfo(keyInfo); } } diff --git a/base/java-tools/src/com/netscape/cmstools/key/KeyRecoverCLI.java b/base/java-tools/src/com/netscape/cmstools/key/KeyRecoverCLI.java index 9e226cf65..baed8a8df 100644 --- a/base/java-tools/src/com/netscape/cmstools/key/KeyRecoverCLI.java +++ b/base/java-tools/src/com/netscape/cmstools/key/KeyRecoverCLI.java @@ -22,17 +22,17 @@ public class KeyRecoverCLI extends CLI { public KeyCLI keyCLI; public KeyRecoverCLI(KeyCLI keyCLI) { - super("recover", "Recover key", keyCLI); + super("recover", "Create a key recovery request", keyCLI); this.keyCLI = keyCLI; } public void printHelp() { - formatter.printHelp(getFullName() + " [OPTIONS]", options); + formatter.printHelp(getFullName() + " [OPTIONS]", options); } public void execute(String[] args) { - Option option = new Option(null, "keyId", true, "Key Identifier for the secret to be recovered."); + Option option = new Option(null, "keyID", true, "Key Identifier for the secret to be recovered."); option.setArgName("Key Identifier"); options.addOption(option); @@ -54,7 +54,7 @@ public class KeyRecoverCLI extends CLI { KeyRequestResponse response = null; - if ((requestFile != null) && (requestFile.trim().length() != 0)) { + if (requestFile != null) { try { JAXBContext context = JAXBContext.newInstance(KeyRecoveryRequest.class); Unmarshaller unmarshaller = context.createUnmarshaller(); @@ -77,11 +77,11 @@ public class KeyRecoverCLI extends CLI { } } else { - String keyId = cmd.getOptionValue("keyId"); + String keyId = cmd.getOptionValue("keyID"); response = keyCLI.keyClient.recoverKey(new KeyId(keyId), null, null, null, null); } - MainCLI.printMessage("Recovered Key Information"); + MainCLI.printMessage("Key Recovery Request Information"); KeyCLI.printKeyRequestInfo(response.getRequestInfo()); } diff --git a/base/java-tools/src/com/netscape/cmstools/key/KeyRequestReviewCLI.java b/base/java-tools/src/com/netscape/cmstools/key/KeyRequestReviewCLI.java index 9f60fff8b..ef4e6c823 100644 --- a/base/java-tools/src/com/netscape/cmstools/key/KeyRequestReviewCLI.java +++ b/base/java-tools/src/com/netscape/cmstools/key/KeyRequestReviewCLI.java @@ -23,7 +23,7 @@ public class KeyRequestReviewCLI extends CLI { public void execute(String[] args) { Option option = new Option(null, "action", true, - "Action to be performed on the request.\n Available actions - [approve|reject|cancel]."); + "Action to be performed on the request.\nValid values: approve, reject, cancel."); option.setArgName("Action to perform"); option.setRequired(true); options.addOption(option); @@ -40,7 +40,7 @@ public class KeyRequestReviewCLI extends CLI { String[] cmdArgs = cmd.getArgs(); if (cmdArgs.length != 1) { - System.err.println("Error: Invalid arguements provided."); + System.err.println("Error: Invalid arguments provided."); printHelp(); System.exit(1); } diff --git a/base/java-tools/src/com/netscape/cmstools/key/KeyRequestShowCLI.java b/base/java-tools/src/com/netscape/cmstools/key/KeyRequestShowCLI.java index 412748f87..f360d86f3 100644 --- a/base/java-tools/src/com/netscape/cmstools/key/KeyRequestShowCLI.java +++ b/base/java-tools/src/com/netscape/cmstools/key/KeyRequestShowCLI.java @@ -32,7 +32,7 @@ public class KeyRequestShowCLI extends CLI { } public void printHelp() { - formatter.printHelp(getFullName() + " ", options); + formatter.printHelp(getFullName() + " ", options); } public void execute(String[] args) { diff --git a/base/java-tools/src/com/netscape/cmstools/key/KeyRequestTemplateFindCLI.java b/base/java-tools/src/com/netscape/cmstools/key/KeyRequestTemplateFindCLI.java deleted file mode 100644 index 375cb61b8..000000000 --- a/base/java-tools/src/com/netscape/cmstools/key/KeyRequestTemplateFindCLI.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.netscape.cmstools.key; - -import java.util.ArrayList; - -import com.netscape.certsrv.key.Template; -import com.netscape.cmstools.cli.CLI; -import com.netscape.cmstools.cli.MainCLI; - -public class KeyRequestTemplateFindCLI extends CLI { - public KeyCLI keyCLI; - - public ArrayList