>From d37e8b607d0646001c8c60bd0db23700a813cc30 Mon Sep 17 00:00:00 2001
From: Abhishek Koneru <akoneru@redhat.com>
Date: Mon, 25 Aug 2014 23:50:33 -0400
Subject: [PATCH] Fixes for tickets 1087, 1089, 1090, 1091.

Addresses upstream issues in the pki key-* CLI commands.
Updates the man page in all the required cases.
---
 base/common/src/com/netscape/certsrv/key/KeyTemplate.java    |  2 +-
 base/java-tools/man/man1/pki-key.1                           | 12 ++++++------
 base/java-tools/src/com/netscape/cmstools/key/KeyCLI.java    |  2 +-
 .../java-tools/src/com/netscape/cmstools/key/KeyFindCLI.java |  6 +++---
 .../src/com/netscape/cmstools/key/KeyRecoverCLI.java         |  9 +++++++--
 .../src/com/netscape/cmstools/key/KeyTemplateFindCLI.java    |  3 ++-
 .../src/com/netscape/cmstools/key/KeyTemplateShowCLI.java    | 11 ++++++-----
 7 files changed, 26 insertions(+), 19 deletions(-)

diff --git a/base/common/src/com/netscape/certsrv/key/KeyTemplate.java b/base/common/src/com/netscape/certsrv/key/KeyTemplate.java
index 25d0d30ff6b5941ba81188883507b133e189f793..6023b4f2c35a187e0d72abccacb7cf6b377d8e43 100644
--- a/base/common/src/com/netscape/certsrv/key/KeyTemplate.java
+++ b/base/common/src/com/netscape/certsrv/key/KeyTemplate.java
@@ -13,6 +13,6 @@ public class KeyTemplate {
     public void printTemplateInfo() {
         System.out.println();
         System.out.println("  Template ID: " + id);
-        System.out.println("  Template Description: " + description);
+        System.out.println("  Description: " + description);
     }
 }
\ No newline at end of file
diff --git a/base/java-tools/man/man1/pki-key.1 b/base/java-tools/man/man1/pki-key.1
index 171d21e66f574e001f8ed387b3894dbbc6668327..4953bcb8f6e5320733943c490a0144251d326ce6 100644
--- a/base/java-tools/man/man1/pki-key.1
+++ b/base/java-tools/man/man1/pki-key.1
@@ -121,7 +121,7 @@ To view the keys stored in DRM:
 
 To view all active keys for a specific client key ID:
 
-.B pki <agent authentication> key-find --client <Client ID> --status active
+.B pki <agent authentication> key-find --clientKeyID <Client Key ID> --status active
 
 To view details of a specific key:
 
@@ -131,7 +131,7 @@ To view details of a specific key:
 
 To archive a passphrase in the DRM:
 
-.B pki <agent authentication> key-archive --clientKeyID <Client ID> --passphrase <Passphrase>
+.B pki <agent authentication> key-archive --clientKeyID <Client Key ID> --passphrase <Passphrase>
 
 A symmetric key can be archived using the "archiveKey" request template.
 
@@ -274,7 +274,7 @@ All the templates can be listed by executing:
 
 To fetch the template for key archival:
 
-.B pki key-template-show archiveKey --output-file <File_Path_to_store_the_template>
+.B pki key-template-show archiveKey --output <File_Path_to_store_the_template>
 
 This command gets the template for a key archival request and stores it in an output file.
 
@@ -298,7 +298,7 @@ To create an archival request using the template file:
 
 To fetch the template for key retrieval:
 
-.B pki key-template-show retrieveKey --output-file <File_Path_to_store_the_template>
+.B pki key-template-show retrieveKey --output <File_Path_to_store_the_template>
 
 This command gets the template for a key retrieval request and stores it in an output file.
 
@@ -319,8 +319,8 @@ To create a retrieval request using the template file:
 .SS Creating a symmetric key generation request
 
 To fetch the template for symmetric key generation:
-:q!:
-.B pki key-template-show generateKey --output-file <File_Path_to_store_the_template>
+
+.B pki key-template-show generateKey --output <File_Path_to_store_the_template>
 
 This command gets the template for a symmetric key generation request and stores it in an output file.
 
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 82235d278236a30485325bab766e33e6ca2a309d..5696c34cdd316bfd76d4f87f3ceba1256adcae44 100644
--- a/base/java-tools/src/com/netscape/cmstools/key/KeyCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/key/KeyCLI.java
@@ -88,7 +88,7 @@ public class KeyCLI extends CLI {
 
     public static void printKeyInfo(KeyInfo info) {
         System.out.println("  Key ID: "+info.getKeyId().toHexString());
-        if (info.getClientKeyID() != null) System.out.println("  Client ID: "+info.getClientKeyID());
+        if (info.getClientKeyID() != null) System.out.println("  Client Key Id: "+info.getClientKeyID());
         if (info.getStatus() != null) System.out.println("  Status: "+info.getStatus());
         if (info.getAlgorithm() != null) System.out.println("  Algorithm: "+info.getAlgorithm());
         if (info.getSize() != null) System.out.println("  Size: "+info.getSize());
diff --git a/base/java-tools/src/com/netscape/cmstools/key/KeyFindCLI.java b/base/java-tools/src/com/netscape/cmstools/key/KeyFindCLI.java
index 73bad6b58aaa9cf9613a9f1ea9f39c76a0969ea5..cac0fc8757d340ff3bf09ecfc1f168a8c1d4d175 100644
--- a/base/java-tools/src/com/netscape/cmstools/key/KeyFindCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/key/KeyFindCLI.java
@@ -49,8 +49,8 @@ public class KeyFindCLI extends CLI {
     }
 
     public void createOptions() {
-        Option option = new Option(null, "client", true, "Client ID");
-        option.setArgName("client ID");
+        Option option = new Option(null, "clientKeyID", true, "Unique client key identifier");
+        option.setArgName("Client Key Identifier");
         options.addOption(option);
 
         option = new Option(null, "status", true, "Status");
@@ -101,7 +101,7 @@ public class KeyFindCLI extends CLI {
             System.exit(-1);
         }
 
-        String clientKeyID = cmd.getOptionValue("client");
+        String clientKeyID = cmd.getOptionValue("clientKeyID");
         String status = cmd.getOptionValue("status");
 
         String s = cmd.getOptionValue("maxResults");
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 5077330fac5ba639cc29baf6e30cfecfb6680e02..b23577f53a636414410d199ae6391f1f07565d51 100644
--- a/base/java-tools/src/com/netscape/cmstools/key/KeyRecoverCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/key/KeyRecoverCLI.java
@@ -38,7 +38,7 @@ public class KeyRecoverCLI extends CLI {
         option.setArgName("Key Identifier");
         options.addOption(option);
 
-        option = new Option(null, "input", true, "Location of the request template file.");
+        option = new Option(null, "input", true, "Location of the request file.");
         option.setArgName("Input file path");
         options.addOption(option);
     }
@@ -71,6 +71,7 @@ public class KeyRecoverCLI extends CLI {
         }
 
         String requestFile = cmd.getOptionValue("input");
+        String keyID = cmd.getOptionValue("keyID");
 
         KeyRequestResponse response = null;
 
@@ -96,9 +97,13 @@ public class KeyRecoverCLI extends CLI {
                 System.exit(-1);
             }
 
-        } else {
+        } else if (keyID != null) {
             String keyId = cmd.getOptionValue("keyID");
             response = keyCLI.keyClient.recoverKey(new KeyId(keyId), null, null, null, null);
+        } else {
+            System.err.println("Error: Neither a key ID nor a request file's path is specified.");
+            printHelp();
+            System.exit(-1);
         }
 
         MainCLI.printMessage("Key Recovery Request Information");
diff --git a/base/java-tools/src/com/netscape/cmstools/key/KeyTemplateFindCLI.java b/base/java-tools/src/com/netscape/cmstools/key/KeyTemplateFindCLI.java
index 0e76d4f1d709e2927a0430da4d831ad2e85c868a..3303560a69f449b92ba25d0ac568e8a2bca6626b 100644
--- a/base/java-tools/src/com/netscape/cmstools/key/KeyTemplateFindCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/key/KeyTemplateFindCLI.java
@@ -65,11 +65,12 @@ public class KeyTemplateFindCLI extends CLI {
                 e.printStackTrace();
             System.exit(-1);
         }
-        MainCLI.printMessage("List of templates");
+        MainCLI.printMessage(templates.size() + " entries matched");
         for (KeyTemplate template : templates) {
             template.printTemplateInfo();
         }
         System.out.println();
+        MainCLI.printMessage("Number of entries returned " + templates.size());
     }
 
     public void createTemplateList() throws FileNotFoundException, JAXBException {
diff --git a/base/java-tools/src/com/netscape/cmstools/key/KeyTemplateShowCLI.java b/base/java-tools/src/com/netscape/cmstools/key/KeyTemplateShowCLI.java
index 77d0680b4af3321ec01b74b89b24fa600b2f1a3c..32248134772089a68092cbf980180c37f652dd23 100644
--- a/base/java-tools/src/com/netscape/cmstools/key/KeyTemplateShowCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/key/KeyTemplateShowCLI.java
@@ -31,7 +31,7 @@ public class KeyTemplateShowCLI extends CLI {
     }
 
     public void createOptions() {
-        Option option = new Option(null, "output-file", true, "Location where the template has to be stored.");
+        Option option = new Option(null, "output", true, "Location where the template has to be stored.");
         option.setArgName("File to write the template to.");
         options.addOption(option);
     }
@@ -63,7 +63,7 @@ public class KeyTemplateShowCLI extends CLI {
         }
 
         String templateId = cmdArgs[0];
-        String writeToFile = cmd.getOptionValue("output-file");
+        String writeToFile = cmd.getOptionValue("output");
         String templateDir = "/usr/share/pki/key/templates/";
         String templatePath = templateDir + templateId + ".xml";
         ResourceMessage data = null;
@@ -71,10 +71,11 @@ public class KeyTemplateShowCLI extends CLI {
             data = ResourceMessage.unmarshall(KeyArchivalRequest.class, templatePath);
         } catch (FileNotFoundException | JAXBException e2) {
             System.err.println("Error: " + e2.getMessage());
-            if(verbose)
-            e2.printStackTrace();
+            if (verbose)
+                e2.printStackTrace();
             System.exit(-1);
-        };
+        }
+        ;
 
         if (writeToFile != null) {
             try (FileOutputStream fOS = new FileOutputStream(writeToFile)) {
-- 
1.8.5.3

