>From e855d529609fd88e0a2961c23caa88ec6752b9d3 Mon Sep 17 00:00:00 2001
From: Ade Lee <alee@redhat.com>
Date: Wed, 5 Feb 2014 13:03:46 -0500
Subject: [PATCH 192/192] Change the return type for KeyRequest creation
 operations

We will likely want to extend the REST API to allow the immediate return
of a generated key, and perhaps of a recovered key in a single step.
This change allows us to do that.
---
 .../src/com/netscape/certsrv/key/KeyClient.java    |  4 +-
 .../netscape/certsrv/key/KeyRequestResource.java   |  4 +-
 .../netscape/certsrv/key/KeyRequestResponse.java   | 46 +++++++++++++++
 .../src/com/netscape/certsrv/kra/KRAClient.java    | 18 +++---
 .../src/com/netscape/cms/servlet/test/DRMTest.java | 65 +++++++++++-----------
 .../netscape/cms/servlet/key/KeyRequestDAO.java    | 31 +++++++++--
 .../cms/servlet/request/KeyRequestService.java     | 41 +++++++-------
 7 files changed, 141 insertions(+), 68 deletions(-)
 create mode 100644 base/common/src/com/netscape/certsrv/key/KeyRequestResponse.java

diff --git a/base/common/src/com/netscape/certsrv/key/KeyClient.java b/base/common/src/com/netscape/certsrv/key/KeyClient.java
index 280b10c498c6ad2fe1e0dfb2532ebf27a667c97f..1a5dd50aa988f9267bd1537fed2edbffa523f42b 100644
--- a/base/common/src/com/netscape/certsrv/key/KeyClient.java
+++ b/base/common/src/com/netscape/certsrv/key/KeyClient.java
@@ -71,9 +71,9 @@ public class KeyClient extends Client {
                 maxTime);
     }
 
-    public KeyRequestInfo createRequest(ResourceMessage data) {
+    public KeyRequestResponse createRequest(ResourceMessage data) {
         @SuppressWarnings("unchecked")
-        ClientResponse<KeyRequestInfo> response = (ClientResponse<KeyRequestInfo>) keyRequestClient.createRequest(data);
+        ClientResponse<KeyRequestResponse> response = (ClientResponse<KeyRequestResponse>) keyRequestClient.createRequest(data);
         return response.getEntity();
     }
 
diff --git a/base/common/src/com/netscape/certsrv/key/KeyRequestResource.java b/base/common/src/com/netscape/certsrv/key/KeyRequestResource.java
index 81cca7b41622b788c1998df9eef458fc8aca8051..e6e6c2e70d7001b32adda41eca01724565e40504 100644
--- a/base/common/src/com/netscape/certsrv/key/KeyRequestResource.java
+++ b/base/common/src/com/netscape/certsrv/key/KeyRequestResource.java
@@ -50,13 +50,13 @@ public interface KeyRequestResource {
                                             @QueryParam("maxTime") Integer maxTime);
 
     @POST
-    @ClientResponseType(entityType=KeyRequestInfo.class)
+    @ClientResponseType(entityType=KeyRequestResponse.class)
     @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
     @Consumes({ MediaType.APPLICATION_FORM_URLENCODED})
     public Response createRequest(MultivaluedMap<String, String> form);
 
     @POST
-    @ClientResponseType(entityType=KeyRequestInfo.class)
+    @ClientResponseType(entityType=KeyRequestResponse.class)
     @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
     @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
     public Response createRequest(ResourceMessage data);
diff --git a/base/common/src/com/netscape/certsrv/key/KeyRequestResponse.java b/base/common/src/com/netscape/certsrv/key/KeyRequestResponse.java
new file mode 100644
index 0000000000000000000000000000000000000000..1d21b4cec090a6cf07dce67ee273733ec1730660
--- /dev/null
+++ b/base/common/src/com/netscape/certsrv/key/KeyRequestResponse.java
@@ -0,0 +1,46 @@
+// --- BEGIN COPYRIGHT BLOCK ---
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program 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 for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+// (C) 2014 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+
+package com.netscape.certsrv.key;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement(name = "KeyRequestResponse")
+public class KeyRequestResponse {
+    KeyRequestInfo requestInfo;
+    KeyData keyData;
+
+    @XmlElement(name="RequestInfo")
+    public KeyRequestInfo getRequestInfo() {
+        return requestInfo;
+    }
+
+    public void setRequestInfo(KeyRequestInfo requestInfo) {
+        this.requestInfo = requestInfo;
+    }
+
+    @XmlElement(name="KeyData")
+    public KeyData getKeyData() {
+        return keyData;
+    }
+
+    public void setKeyData(KeyData keyData) {
+        this.keyData = keyData;
+    }
+}
diff --git a/base/common/src/com/netscape/certsrv/kra/KRAClient.java b/base/common/src/com/netscape/certsrv/kra/KRAClient.java
index 76e321ac87c9ac53b784e0c303c78de33587eb5c..5473b9c73b0a009f7b5b5a91dfdb149987e3bf2e 100644
--- a/base/common/src/com/netscape/certsrv/kra/KRAClient.java
+++ b/base/common/src/com/netscape/certsrv/kra/KRAClient.java
@@ -20,6 +20,7 @@ import com.netscape.certsrv.key.KeyRecoveryRequest;
 import com.netscape.certsrv.key.KeyRequestInfo;
 import com.netscape.certsrv.key.KeyRequestInfoCollection;
 import com.netscape.certsrv.key.KeyRequestResource;
+import com.netscape.certsrv.key.KeyRequestResponse;
 import com.netscape.certsrv.key.KeyResource;
 import com.netscape.certsrv.key.SymKeyGenerationRequest;
 import com.netscape.certsrv.logging.AuditClient;
@@ -69,7 +70,7 @@ public class KRAClient extends SubsystemClient {
         return list;
     }
 
-    public KeyRequestInfo archiveSecurityData(byte[] encoded, String clientId, String dataType, String algorithm, int strength) {
+    public KeyRequestResponse archiveSecurityData(byte[] encoded, String clientId, String dataType, String algorithm, int strength) {
         // create archival request
         KeyArchivalRequest data = new KeyArchivalRequest();
         String req1 = Utils.base64encode(encoded);
@@ -80,7 +81,7 @@ public class KRAClient extends SubsystemClient {
         data.setKeyStrength(strength);
 
         @SuppressWarnings("unchecked")
-        ClientResponse<KeyRequestInfo> response = (ClientResponse<KeyRequestInfo>)
+        ClientResponse<KeyRequestResponse> response = (ClientResponse<KeyRequestResponse>)
                 keyRequestClient.createRequest(data);
         return client.getEntity(response);
     }
@@ -100,7 +101,7 @@ public class KRAClient extends SubsystemClient {
         return null;
     }
 
-    public KeyRequestInfo requestRecovery(KeyId keyId, byte[] rpwd, byte[] rkey, byte[] nonceData) {
+    public KeyRequestResponse requestRecovery(KeyId keyId, byte[] rpwd, byte[] rkey, byte[] nonceData) {
         // create recovery request
         KeyRecoveryRequest data = new KeyRecoveryRequest();
         data.setKeyId(keyId);
@@ -116,7 +117,7 @@ public class KRAClient extends SubsystemClient {
         }
 
         @SuppressWarnings("unchecked")
-        ClientResponse<KeyRequestInfo> response = (ClientResponse<KeyRequestInfo>)
+        ClientResponse<KeyRequestResponse> response = (ClientResponse<KeyRequestResponse>)
                 keyRequestClient.createRequest(data);
         return client.getEntity(response);
     }
@@ -149,14 +150,14 @@ public class KRAClient extends SubsystemClient {
         return keyRequestClient.getRequestInfo(id);
     }
 
-    public KeyRequestInfo requestKeyRecovery(String keyId, String b64Certificate) {
+    public KeyRequestResponse requestKeyRecovery(String keyId, String b64Certificate) {
         // create key recovery request
         KeyRecoveryRequest data = new KeyRecoveryRequest();
         data.setKeyId(new KeyId(keyId));
         data.setCertificate(b64Certificate);
 
         @SuppressWarnings("unchecked")
-        ClientResponse<KeyRequestInfo> response = (ClientResponse<KeyRequestInfo>)
+        ClientResponse<KeyRequestResponse> response = (ClientResponse<KeyRequestResponse>)
                 keyRequestClient.createRequest(data);
         return client.getEntity(response);
     }
@@ -171,7 +172,7 @@ public class KRAClient extends SubsystemClient {
         return key;
     }
 
-    public KeyRequestInfo generateKey(String clientId, String keyAlgorithm, int keySize, List<String> usages) {
+    public KeyRequestResponse generateKey(String clientId, String keyAlgorithm, int keySize, List<String> usages) {
         SymKeyGenerationRequest data = new SymKeyGenerationRequest();
         data.setClientId(clientId);
         data.setKeyAlgorithm(keyAlgorithm);
@@ -179,7 +180,8 @@ public class KRAClient extends SubsystemClient {
         data.setUsages(usages);
 
         @SuppressWarnings("unchecked")
-        ClientResponse<KeyRequestInfo> response = (ClientResponse<KeyRequestInfo>) keyRequestClient.createRequest(data);
+        ClientResponse<KeyRequestResponse> response = (ClientResponse<KeyRequestResponse>)
+                keyRequestClient.createRequest(data);
         return response.getEntity();
     }
 }
diff --git a/base/kra/functional/src/com/netscape/cms/servlet/test/DRMTest.java b/base/kra/functional/src/com/netscape/cms/servlet/test/DRMTest.java
index 42ab77c906af6cc48347f49a947794cb20e5b9c9..ce6a8fbf79538f332d5a4195f9f15340c8062469 100644
--- a/base/kra/functional/src/com/netscape/cms/servlet/test/DRMTest.java
+++ b/base/kra/functional/src/com/netscape/cms/servlet/test/DRMTest.java
@@ -47,6 +47,7 @@ import com.netscape.certsrv.key.KeyData;
 import com.netscape.certsrv.key.KeyInfo;
 import com.netscape.certsrv.key.KeyRequestInfo;
 import com.netscape.certsrv.key.KeyRequestResource;
+import com.netscape.certsrv.key.KeyRequestResponse;
 import com.netscape.certsrv.key.SymKeyGenerationRequest;
 import com.netscape.certsrv.kra.KRAClient;
 import com.netscape.certsrv.request.IRequest;
@@ -167,7 +168,7 @@ public class DRMTest {
         RequestId recoveryRequestId = null;
 
         // Variables for data structures from calls
-        KeyRequestInfo requestInfo = null;
+        KeyRequestResponse requestResponse = null;
         KeyData keyData = null;
         KeyInfo keyInfo = null;
 
@@ -255,11 +256,11 @@ public class DRMTest {
             byte[] encoded = CryptoUtil.createPKIArchiveOptions(manager, token, transportCert, vek, null,
                     KeyGenAlgorithm.DES3, ivps);
 
-            KeyRequestInfo info = client.archiveSecurityData(encoded, clientId,
+            KeyRequestResponse info = client.archiveSecurityData(encoded, clientId,
                     KeyRequestResource.SYMMETRIC_KEY_TYPE, KeyRequestResource.DES3_ALGORITHM, 0);
             log("Archival Results:");
-            printRequestInfo(info);
-            keyId = info.getKeyId();
+            printRequestInfo(info.getRequestInfo());
+            keyId = info.getRequestInfo().getKeyId();
         } catch (Exception e) {
             log("Exception in archiving symmetric key:" + e.getMessage());
             e.printStackTrace();
@@ -288,8 +289,9 @@ public class DRMTest {
         try {
             recoveryKey = CryptoUtil.generateKey(token, KeyGenAlgorithm.DES3);
             wrappedRecoveryKey = CryptoUtil.wrapSymmetricKey(manager, token, transportCert, recoveryKey);
-            KeyRequestInfo info = client.requestRecovery(keyId, null, wrappedRecoveryKey, ivps.getIV());
-            recoveryRequestId = info.getRequestId();
+            KeyRequestResponse info = client.requestRecovery(keyId, null, wrappedRecoveryKey,
+                    ivps.getIV());
+            recoveryRequestId = info.getRequestInfo().getRequestId();
         } catch (Exception e) {
             log("Exception in recovering symmetric key using session key: " + e.getMessage());
         }
@@ -330,8 +332,8 @@ public class DRMTest {
                     EncryptionAlgorithm.DES3_CBC_PAD);
             wrappedRecoveryKey = CryptoUtil.wrapSymmetricKey(manager, token, transportCert, recoveryKey);
 
-            requestInfo = client.requestRecovery(keyId, wrappedRecoveryPassphrase, wrappedRecoveryKey, ivps.getIV());
-            recoveryRequestId = requestInfo.getRequestId();
+            requestResponse = client.requestRecovery(keyId, wrappedRecoveryPassphrase, wrappedRecoveryKey, ivps.getIV());
+            recoveryRequestId = requestResponse.getRequestInfo().getRequestId();
         } catch (Exception e) {
             log("Exception in recovering symmetric key using passphrase" + e.toString());
             e.printStackTrace();
@@ -366,11 +368,11 @@ public class DRMTest {
         try {
             byte[] encoded = CryptoUtil.createPKIArchiveOptions(manager, token, transportCert, null, passphrase,
                     KeyGenAlgorithm.DES3, ivps);
-            requestInfo = client.archiveSecurityData(encoded, clientId,
+            requestResponse = client.archiveSecurityData(encoded, clientId,
                     KeyRequestResource.PASS_PHRASE_TYPE, null, 0);
             log("Archival Results:");
-            printRequestInfo(requestInfo);
-            keyId = requestInfo.getKeyId();
+            printRequestInfo(requestResponse.getRequestInfo());
+            keyId = requestResponse.getRequestInfo().getKeyId();
         } catch (Exception e) {
             log("Exception in archiving symmetric key:" + e.toString());
             e.printStackTrace();
@@ -403,8 +405,8 @@ public class DRMTest {
             wrappedRecoveryKey = CryptoUtil.wrapSymmetricKey(manager, token, transportCert, recoveryKey);
             wrappedRecoveryPassphrase = CryptoUtil.wrapPassphrase(token, recoveryPassphrase, ivps, recoveryKey,
                     EncryptionAlgorithm.DES3_CBC_PAD);
-            requestInfo = client.requestRecovery(keyId, null, wrappedRecoveryKey, ivps.getIV());
-            recoveryRequestId = requestInfo.getRequestId();
+            requestResponse = client.requestRecovery(keyId, null, wrappedRecoveryKey, ivps.getIV());
+            recoveryRequestId = requestResponse.getRequestInfo().getRequestId();
         } catch (Exception e) {
             log("Exception in recovering passphrase using session key: " + e.getMessage());
         }
@@ -437,8 +439,8 @@ public class DRMTest {
 
         // Test 17: Submit a recovery request for the passphrase using a passphrase
         log("Submitting a recovery request for the passphrase using a passphrase");
-        requestInfo = client.requestRecovery(keyId, wrappedRecoveryPassphrase, wrappedRecoveryKey, ivps.getIV());
-        recoveryRequestId = requestInfo.getRequestId();
+        requestResponse = client.requestRecovery(keyId, wrappedRecoveryPassphrase, wrappedRecoveryKey, ivps.getIV());
+        recoveryRequestId = requestResponse.getRequestInfo().getRequestId();
 
         //Test 18: Approve recovery
         log("Approving recovery request: " + recoveryRequestId);
@@ -466,8 +468,8 @@ public class DRMTest {
         //Wait until retrieving key before sending input data.
 
         log("Submitting a recovery request for the passphrase using a passphrase, wait till end to provide recovery data.");
-        requestInfo = client.requestRecovery(keyId, null, null, null);
-        recoveryRequestId = requestInfo.getRequestId();
+        requestResponse = client.requestRecovery(keyId, null, null, null);
+        recoveryRequestId = requestResponse.getRequestInfo().getRequestId();
 
         //Test 21: Approve recovery
         log("Approving recovery request: " + recoveryRequestId);
@@ -523,7 +525,8 @@ public class DRMTest {
                                 "greWr3xTsy6gF2yphUEkGHh4v22XvK+FLx9Jb6zloMWA2GG9gpUpvMnl1fH4";
 
         log("Requesting X509 key recovery.");
-        recoveryRequestId = client.requestKeyRecovery(keyID, b64Certificate).getRequestId();
+        recoveryRequestId = client.requestKeyRecovery(keyID,
+                b64Certificate).getRequestInfo().getRequestId();
         log("Requesting X509 key recovery request: " + recoveryRequestId);
 
         // Test 25: Approve x509 key recovery
@@ -565,11 +568,11 @@ public class DRMTest {
         List<String> usages = new ArrayList<String>();
         usages.add(SymKeyGenerationRequest.DECRYPT_USAGE);
         usages.add(SymKeyGenerationRequest.ENCRYPT_USAGE);
-        KeyRequestInfo genKeyInfo = client.generateKey(clientId,
+        KeyRequestResponse genKeyResponse = client.generateKey(clientId,
                 KeyRequestResource.AES_ALGORITHM,
                 128, usages);
-        printRequestInfo(genKeyInfo);
-        keyId = genKeyInfo.getKeyId();
+        printRequestInfo(genKeyResponse.getRequestInfo());
+        keyId = genKeyResponse.getRequestInfo().getKeyId();
 
         // test 29: Get keyId for active key with client ID
         log("Getting key ID for symmetric key");
@@ -593,8 +596,8 @@ public class DRMTest {
         try {
             recoveryKey = CryptoUtil.generateKey(token, KeyGenAlgorithm.DES3);
             wrappedRecoveryKey = CryptoUtil.wrapSymmetricKey(manager, token, transportCert, recoveryKey);
-            KeyRequestInfo info = client.requestRecovery(keyId, null, wrappedRecoveryKey, ivps.getIV());
-            recoveryRequestId = info.getRequestId();
+            KeyRequestResponse response = client.requestRecovery(keyId, null, wrappedRecoveryKey, ivps.getIV());
+            recoveryRequestId = response.getRequestInfo().getRequestId();
         } catch (Exception e) {
             log("Exception in recovering symmetric key using session key: " + e.getMessage());
         }
@@ -621,21 +624,21 @@ public class DRMTest {
 
         // test 33: Generate symmetric key - invalid algorithm
         try {
-            genKeyInfo = client.generateKey("Symmetric Key #1235", "AFS", 128, usages);
+            genKeyResponse = client.generateKey("Symmetric Key #1235", "AFS", 128, usages);
         } catch (Exception e) {
             log("Exception: " + e);
         }
 
         // test 34: Generate symmetric key - invalid key size
         try {
-            genKeyInfo = client.generateKey("Symmetric Key #1236", "AES", 135, usages);
+            genKeyResponse = client.generateKey("Symmetric Key #1236", "AES", 135, usages);
         } catch (Exception e) {
             log("Exception: " + e);
         }
 
         // test 35: Generate symmetric key - usages not defined
         try {
-            genKeyInfo = client.generateKey("Symmetric Key #1236", "DES", 56, usages);
+            genKeyResponse = client.generateKey("Symmetric Key #1236", "DES", 56, usages);
         } catch (Exception e) {
             log("Exception: " + e);
         }
@@ -651,11 +654,11 @@ public class DRMTest {
             byte[] encoded = CryptoUtil.createPKIArchiveOptions(manager, token, transportCert, vek, null,
                     KeyGenAlgorithm.DES3, ivps);
 
-            KeyRequestInfo info = client.archiveSecurityData(encoded, clientId,
+            KeyRequestResponse response = client.archiveSecurityData(encoded, clientId,
                     KeyRequestResource.SYMMETRIC_KEY_TYPE, KeyRequestResource.AES_ALGORITHM, 128);
             log("Archival Results:");
-            printRequestInfo(info);
-            keyId = info.getKeyId();
+            printRequestInfo(response.getRequestInfo());
+            keyId = response.getRequestInfo().getKeyId();
         } catch (Exception e) {
             log("Exception in archiving symmetric key:" + e.getMessage());
             e.printStackTrace();
@@ -683,8 +686,8 @@ public class DRMTest {
         try {
             recoveryKey = CryptoUtil.generateKey(token, KeyGenAlgorithm.DES3);
             wrappedRecoveryKey = CryptoUtil.wrapSymmetricKey(manager, token, transportCert, recoveryKey);
-            KeyRequestInfo info = client.requestRecovery(keyId, null, wrappedRecoveryKey, ivps.getIV());
-            recoveryRequestId = info.getRequestId();
+            KeyRequestResponse response = client.requestRecovery(keyId, null, wrappedRecoveryKey, ivps.getIV());
+            recoveryRequestId = response.getRequestInfo().getRequestId();
         } catch (Exception e) {
             log("Exception in recovering symmetric key using session key: " + e.getMessage());
         }
diff --git a/base/server/cms/src/com/netscape/cms/servlet/key/KeyRequestDAO.java b/base/server/cms/src/com/netscape/cms/servlet/key/KeyRequestDAO.java
index ac728d5931eab4ce1529ac8a595c3bebedfaa61c..7a63b113df3b35e657050664c11a5e7dc0b0474e 100644
--- a/base/server/cms/src/com/netscape/cms/servlet/key/KeyRequestDAO.java
+++ b/base/server/cms/src/com/netscape/cms/servlet/key/KeyRequestDAO.java
@@ -36,10 +36,12 @@ import com.netscape.certsrv.dbs.keydb.IKeyRecord;
 import com.netscape.certsrv.dbs.keydb.IKeyRepository;
 import com.netscape.certsrv.dbs.keydb.KeyId;
 import com.netscape.certsrv.key.KeyArchivalRequest;
+import com.netscape.certsrv.key.KeyData;
 import com.netscape.certsrv.key.KeyRecoveryRequest;
 import com.netscape.certsrv.key.KeyRequestInfo;
 import com.netscape.certsrv.key.KeyRequestInfoCollection;
 import com.netscape.certsrv.key.KeyRequestResource;
+import com.netscape.certsrv.key.KeyRequestResponse;
 import com.netscape.certsrv.key.KeyResource;
 import com.netscape.certsrv.key.SymKeyGenerationRequest;
 import com.netscape.certsrv.kra.IKeyRecoveryAuthority;
@@ -133,7 +135,7 @@ public class KeyRequestDAO extends CMSRequestDAO {
      * @return info for the request submitted.
      * @throws EBaseException
      */
-    public KeyRequestInfo submitRequest(KeyArchivalRequest data, UriInfo uriInfo) throws EBaseException {
+    public KeyRequestResponse submitRequest(KeyArchivalRequest data, UriInfo uriInfo) throws EBaseException {
         String clientId = data.getClientId();
         String wrappedSecurityData = data.getWrappedPrivateData();
         String dataType = data.getDataType();
@@ -162,7 +164,7 @@ public class KeyRequestDAO extends CMSRequestDAO {
 
         queue.markAsServiced(request);
 
-        return createKeyRequestInfo(request, uriInfo);
+        return createKeyRequestResponse(request, uriInfo);
     }
 
     /**
@@ -172,7 +174,7 @@ public class KeyRequestDAO extends CMSRequestDAO {
      * @return info on the recovery request created
      * @throws EBaseException
      */
-    public KeyRequestInfo submitRequest(KeyRecoveryRequest data, UriInfo uriInfo) throws EBaseException {
+    public KeyRequestResponse submitRequest(KeyRecoveryRequest data, UriInfo uriInfo) throws EBaseException {
         // set data using request.setExtData(field, data)
 
         String wrappedSessionKeyStr = data.getTransWrappedSessionKey();
@@ -209,10 +211,10 @@ public class KeyRequestDAO extends CMSRequestDAO {
 
         queue.processRequest(request);
 
-        return createKeyRequestInfo(request, uriInfo);
+        return createKeyRequestResponse(request, uriInfo);
     }
 
-    public KeyRequestInfo submitRequest(SymKeyGenerationRequest data, UriInfo uriInfo) throws EBaseException {
+    public KeyRequestResponse submitRequest(SymKeyGenerationRequest data, UriInfo uriInfo) throws EBaseException {
         String clientId = data.getClientId();
         String algName = data.getKeyAlgorithm();
         int size = data.getKeySize();
@@ -258,7 +260,7 @@ public class KeyRequestDAO extends CMSRequestDAO {
         queue.processRequest(request);
         queue.markAsServiced(request);
 
-        return createKeyRequestInfo(request, uriInfo);
+        return createKeyRequestResponse(request, uriInfo);
     }
 
     public void approveRequest(RequestId id) throws EBaseException {
@@ -302,11 +304,28 @@ public class KeyRequestDAO extends CMSRequestDAO {
         return ret;
     }
 
+    private KeyData createKeyData(IRequest request, UriInfo uriInfo) {
+        // TODO - to be implemented when we enable one-shot generation and recovery
+        // with retrieval
+        return null;
+    }
+
+    private KeyRequestResponse createKeyRequestResponse(IRequest request, UriInfo uriInfo) {
+        KeyRequestResponse response = new KeyRequestResponse();
+        response.setRequestInfo(createKeyRequestInfo(request, uriInfo));
+        response.setKeyData(createKeyData(request, uriInfo));
+        return response;
+    }
+
     @Override
     public KeyRequestInfo createCMSRequestInfo(IRequest request, UriInfo uriInfo) {
         return createKeyRequestInfo(request, uriInfo);
     }
 
+    public KeyRequestResponse createCMSRequestResponse(IRequest request, UriInfo uriInfo) {
+        return createKeyRequestResponse(request, uriInfo);
+    }
+
     //We only care if the key exists or not
     private boolean doesKeyExist(String clientId, String keyStatus, UriInfo uriInfo) {
         String state = "active";
diff --git a/base/server/cms/src/com/netscape/cms/servlet/request/KeyRequestService.java b/base/server/cms/src/com/netscape/cms/servlet/request/KeyRequestService.java
index 19f053d0e394308b599dc0bd3191a1370f6d17d5..c919f10ea0cad7ee7fc63f6be914966558649415 100644
--- a/base/server/cms/src/com/netscape/cms/servlet/request/KeyRequestService.java
+++ b/base/server/cms/src/com/netscape/cms/servlet/request/KeyRequestService.java
@@ -51,6 +51,7 @@ import com.netscape.certsrv.key.KeyRecoveryRequest;
 import com.netscape.certsrv.key.KeyRequestInfo;
 import com.netscape.certsrv.key.KeyRequestInfoCollection;
 import com.netscape.certsrv.key.KeyRequestResource;
+import com.netscape.certsrv.key.KeyRequestResponse;
 import com.netscape.certsrv.key.SymKeyGenerationRequest;
 import com.netscape.certsrv.kra.IKeyRecoveryAuthority;
 import com.netscape.certsrv.kra.IKeyService;
@@ -176,14 +177,14 @@ public class KeyRequestService extends PKIService implements KeyRequestResource
         }
 
         KeyRequestDAO dao = new KeyRequestDAO();
-        KeyRequestInfo info;
+        KeyRequestResponse response;
         try {
-            info = dao.submitRequest(data, uriInfo);
-            auditArchivalRequestMade(info.getRequestId(), ILogger.SUCCESS, data.getClientId());
+            response = dao.submitRequest(data, uriInfo);
+            auditArchivalRequestMade(response.getRequestInfo().getRequestId(), ILogger.SUCCESS, data.getClientId());
 
             return Response
-                    .created(new URI(info.getRequestURL()))
-                    .entity(info)
+                    .created(new URI(response.getRequestInfo().getRequestURL()))
+                    .entity(response)
                     .type(MediaType.APPLICATION_XML)
                     .build();
         } catch (EBaseException | URISyntaxException e) {
@@ -210,15 +211,16 @@ public class KeyRequestService extends PKIService implements KeyRequestResource
             throw new BadRequestException("No wrapped session key.");
         }
         KeyRequestDAO dao = new KeyRequestDAO();
-        KeyRequestInfo info;
+        KeyRequestResponse response;
         try {
-            info = (data.getCertificate() != null)?
+            response = (data.getCertificate() != null)?
                     requestKeyRecovery(data): dao.submitRequest(data, uriInfo);
-            auditRecoveryRequestMade(info.getRequestId(), ILogger.SUCCESS, data.getKeyId());
+            auditRecoveryRequestMade(response.getRequestInfo().getRequestId(),
+                    ILogger.SUCCESS, data.getKeyId());
 
             return Response
-                    .created(new URI(info.getRequestURL()))
-                    .entity(info)
+                    .created(new URI(response.getRequestInfo().getRequestURL()))
+                    .entity(response)
                     .type(MediaType.APPLICATION_XML)
                     .build();
         } catch (EBaseException | URISyntaxException e) {
@@ -228,8 +230,8 @@ public class KeyRequestService extends PKIService implements KeyRequestResource
         }
     }
 
-    private KeyRequestInfo requestKeyRecovery(KeyRecoveryRequest data) {
-        KeyRequestInfo info = null;
+    private KeyRequestResponse requestKeyRecovery(KeyRecoveryRequest data) {
+        KeyRequestResponse response = null;
         if (data == null) {
             throw new BadRequestException("Invalid request.");
         }
@@ -250,9 +252,9 @@ public class KeyRequestService extends PKIService implements KeyRequestResource
         } catch (EBaseException e) {
         }
         KeyRequestDAO dao = new KeyRequestDAO();
-        info = dao.createCMSRequestInfo(request, uriInfo);
+        response = dao.createCMSRequestResponse(request, uriInfo);
 
-        return info;
+        return response;
     }
 
     @Override
@@ -447,14 +449,15 @@ public class KeyRequestService extends PKIService implements KeyRequestResource
         }
 
         KeyRequestDAO dao = new KeyRequestDAO();
-        KeyRequestInfo info;
+        KeyRequestResponse response;
         try {
-            info = dao.submitRequest(data, uriInfo);
-            auditSymKeyGenRequestMade(info.getRequestId(), ILogger.SUCCESS, data.getClientId());
+            response = dao.submitRequest(data, uriInfo);
+            auditSymKeyGenRequestMade(response.getRequestInfo().getRequestId(), ILogger.SUCCESS,
+                    data.getClientId());
 
             return Response
-                    .created(new URI(info.getRequestURL()))
-                    .entity(info)
+                    .created(new URI(response.getRequestInfo().getRequestURL()))
+                    .entity(response)
                     .type(MediaType.APPLICATION_XML)
                     .build();
         } catch (EBaseException | URISyntaxException e) {
-- 
1.8.4.2

