From 361c689098daecb3f0c080b35aa75a1a0f260411 Mon Sep 17 00:00:00 2001
From: Endi Sukma Dewata <edewata@redhat.com>
Date: Tue, 28 Feb 2012 00:05:53 -0600
Subject: [PATCH] Fixed DRM REST interface to use BigInteger.

The DRM REST interface previously uses strings for key ID and request ID.
It has been modified to use KeyId and RequestId classes which can accept
decimal or hex numbers and internally store it as BigInteger.

Ticket #94
---
 pki/base/common/src/CMakeLists.txt                 |    3 +
 .../src/com/netscape/certsrv/dbs/keydb/KeyId.java  |  121 ++++++++++++++++++++
 .../netscape/certsrv/dbs/keydb/KeyIdAdapter.java   |   37 ++++++
 .../com/netscape/certsrv/request/RequestId.java    |   88 +++++++++++----
 .../netscape/certsrv/request/RequestIdAdapter.java |   37 ++++++
 .../cms/servlet/key/KeyResourceService.java        |   12 +-
 .../com/netscape/cms/servlet/key/KeysResource.java |    8 +-
 .../com/netscape/cms/servlet/key/model/KeyDAO.java |   14 +-
 .../cms/servlet/key/model/KeyDataInfo.java         |   10 ++
 .../cms/servlet/request/KeyRequestResource.java    |   10 +-
 .../servlet/request/KeyRequestResourceService.java |   16 ++--
 .../cms/servlet/request/KeyRequestsResource.java   |   18 ++--
 .../request/KeyRequestsResourceService.java        |   21 +---
 .../cms/servlet/request/ProcessCertReq.java        |    4 +-
 .../netscape/cms/servlet/request/ProcessReq.java   |    2 +-
 .../com/netscape/cms/servlet/request/QueryReq.java |    2 +-
 .../cms/servlet/request/model/KeyRequestDAO.java   |   32 +++---
 .../cms/servlet/request/model/KeyRequestInfo.java  |   19 +++
 .../servlet/request/model/RecoveryRequestData.java |   28 ++++--
 .../netscape/cmscore/cert/PrettyPrintFormat.java   |    3 +
 .../com/netscape/cmscore/request/RequestQueue.java |    4 +-
 .../cmscore/request/RequestRecordTest.java         |    2 +-
 .../com/netscape/cmscore/request/RequestTest.java  |    2 +-
 pki/base/kra/functional/drmclient.py               |    1 +
 .../netscape/cms/servlet/test/DRMRestClient.java   |   13 ++-
 .../src/com/netscape/cms/servlet/test/DRMTest.java |   28 ++---
 .../util/src/netscape/security/util/BigInt.java    |    4 +-
 27 files changed, 412 insertions(+), 127 deletions(-)
 create mode 100644 pki/base/common/src/com/netscape/certsrv/dbs/keydb/KeyId.java
 create mode 100644 pki/base/common/src/com/netscape/certsrv/dbs/keydb/KeyIdAdapter.java
 create mode 100644 pki/base/common/src/com/netscape/certsrv/request/RequestIdAdapter.java

diff --git a/pki/base/common/src/CMakeLists.txt b/pki/base/common/src/CMakeLists.txt
index 62d30740df830353f4a6d1ae795793d0d6a3b9b1..ed83bb68e88a550c298fa6c3ab302f1f0cdb71f0 100644
--- a/pki/base/common/src/CMakeLists.txt
+++ b/pki/base/common/src/CMakeLists.txt
@@ -200,6 +200,8 @@ set(pki-certsrv_java_SRCS
     com/netscape/certsrv/dbs/Modification.java
     com/netscape/certsrv/dbs/EDBNotAvailException.java
     com/netscape/certsrv/dbs/IDBVirtualList.java
+    com/netscape/certsrv/dbs/keydb/KeyId.java
+    com/netscape/certsrv/dbs/keydb/KeyIdAdapter.java
     com/netscape/certsrv/dbs/keydb/KeyState.java
     com/netscape/certsrv/dbs/keydb/IKeyRecord.java
     com/netscape/certsrv/dbs/keydb/IKeyRecordList.java
@@ -301,6 +303,7 @@ set(pki-certsrv_java_SRCS
     com/netscape/certsrv/request/AgentApprovals.java
     com/netscape/certsrv/request/IRequestRecord.java
     com/netscape/certsrv/request/RequestId.java
+    com/netscape/certsrv/request/RequestIdAdapter.java
     com/netscape/certsrv/request/IService.java
     com/netscape/certsrv/request/IRequestListener.java
     com/netscape/certsrv/request/AgentApproval.java
diff --git a/pki/base/common/src/com/netscape/certsrv/dbs/keydb/KeyId.java b/pki/base/common/src/com/netscape/certsrv/dbs/keydb/KeyId.java
new file mode 100644
index 0000000000000000000000000000000000000000..82502df641b8581a5089e21d10ff8622de7c1b7a
--- /dev/null
+++ b/pki/base/common/src/com/netscape/certsrv/dbs/keydb/KeyId.java
@@ -0,0 +1,121 @@
+// --- 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) 2007 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+package com.netscape.certsrv.dbs.keydb;
+
+import java.math.BigInteger;
+
+/**
+ * The KeyId class represents the identifier for a particular
+ * key record. This identifier may be used to retrieve the key record
+ * from the database.
+ * <p>
+ *
+ * @author Endi S. Dewata
+ * @version $Revision$ $Date$
+ */
+public class KeyId {
+
+    protected BigInteger value;
+
+    /**
+     * Creates a new KeyId from its string representation.
+     * <p>
+     *
+     * @param id
+     *            a string containing the decimal or hex value for the identifier.
+     */
+    public KeyId(String id) {
+        id = id.trim();
+        if (id.startsWith("0x")) { // hex
+            value = new BigInteger(id.substring(2), 16);
+        } else { // decimal
+            value = new BigInteger(id);
+        }
+    }
+
+    /**
+     * Creates a new KeyId from its BigInteger representation.
+     * <p>
+     *
+     * @param id
+     *            a BigInteger containing the identifier.
+     */
+    public KeyId(BigInteger id) {
+        if (id == null) throw new NullPointerException();
+        value = id;
+    }
+
+    /**
+     * Creates a new KeyId from its integer representation.
+     * <p>
+     *
+     * @param id
+     *            an integer containing the identifier.
+     */
+    public KeyId(int id) {
+        value = BigInteger.valueOf(id);
+    }
+
+    /**
+     * Converts the KeyId into its BigInteger representation.
+     * <p>
+     *
+     * @return
+     *         a BigInteger containing the identifier.
+     */
+    public BigInteger toBigInteger() {
+        return value;
+    }
+
+    /**
+     * Converts the KeyId into its string representation. The string
+     * form can be stored in a database (such as the LDAP directory)
+     * <p>
+     *
+     * @return
+     *         a string containing the decimal (base 10) value for the identifier.
+     */
+    public String toString() {
+        return value.toString();
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((value == null) ? 0 : value.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        KeyId other = (KeyId) obj;
+        if (value == null) {
+            if (other.value != null)
+                return false;
+        } else if (!value.equals(other.value))
+            return false;
+        return true;
+    }
+}
diff --git a/pki/base/common/src/com/netscape/certsrv/dbs/keydb/KeyIdAdapter.java b/pki/base/common/src/com/netscape/certsrv/dbs/keydb/KeyIdAdapter.java
new file mode 100644
index 0000000000000000000000000000000000000000..1d1593e57c73d67b84d542c8fd3324f38df4b479
--- /dev/null
+++ b/pki/base/common/src/com/netscape/certsrv/dbs/keydb/KeyIdAdapter.java
@@ -0,0 +1,37 @@
+// --- 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) 2007 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+package com.netscape.certsrv.dbs.keydb;
+
+import javax.xml.bind.annotation.adapters.XmlAdapter;
+
+/**
+ * The KeyIdAdapter class provides custom marshaling for KeyId.
+ *
+ * @author Endi S. Dewata
+ * @version $Revision$ $Date$
+ */
+public class KeyIdAdapter extends XmlAdapter<String, KeyId> {
+
+    public KeyId unmarshal(String value) throws Exception {
+        return new KeyId(value);
+    }
+
+    public String marshal(KeyId value) throws Exception {
+        return value.toString();
+    }
+}
diff --git a/pki/base/common/src/com/netscape/certsrv/request/RequestId.java b/pki/base/common/src/com/netscape/certsrv/request/RequestId.java
index 31681675ba9b33b57e495280fd4651d63ff1fb5d..fee52acf54d89308d7f14c41322f087b80fbe5e1 100644
--- a/pki/base/common/src/com/netscape/certsrv/request/RequestId.java
+++ b/pki/base/common/src/com/netscape/certsrv/request/RequestId.java
@@ -17,6 +17,8 @@
 // --- END COPYRIGHT BLOCK ---
 package com.netscape.certsrv.request;
 
+import java.math.BigInteger;
+
 /**
  * The RequestId class represents the identifier for a particular
  * request within a request queue. This identifier may be used to
@@ -25,17 +27,58 @@ package com.netscape.certsrv.request;
  * 
  * @version $Revision$ $Date$
  */
-public final class RequestId {
+public class RequestId {
+
+    protected BigInteger value;
 
     /**
      * Creates a new RequestId from its string representation.
      * <p>
      * 
      * @param id
-     *            a string containing the decimal (base 10) value for the identifier.
+     *            a string containing the decimal or hex value for the identifier.
      */
     public RequestId(String id) {
-        mString = id;
+        id = id.trim();
+        if (id.startsWith("0x")) { // hex
+            value = new BigInteger(id.substring(2), 16);
+        } else { // decimal
+            value = new BigInteger(id);
+        }
+    }
+
+    /**
+     * Creates a new RequestId from its BigInteger representation.
+     * <p>
+     *
+     * @param id
+     *            a BigInteger containing the identifier.
+     */
+    public RequestId(BigInteger id) {
+        if (id == null) throw new NullPointerException();
+        value = id;
+    }
+
+    /**
+     * Creates a new RequestId from its integer representation.
+     * <p>
+     *
+     * @param id
+     *            an integer containing the identifier.
+     */
+    public RequestId(int id) {
+        value = BigInteger.valueOf(id);
+    }
+
+    /**
+     * Converts the RequestId into its BigInteger representation.
+     * <p>
+     *
+     * @return
+     *         a BigInteger containing the identifier.
+     */
+    public BigInteger toBigInteger() {
+        return value;
     }
 
     /**
@@ -47,30 +90,31 @@ public final class RequestId {
      *         a string containing the decimal (base 10) value for the identifier.
      */
     public String toString() {
-        return mString;
+        return value.toString();
     }
 
-    /**
-     * Implements Object.hashCode.
-     * <p>
-     * 
-     * @return hash code of the object
-     */
+    @Override
     public int hashCode() {
-        return mString.hashCode();
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((value == null) ? 0 : value.hashCode());
+        return result;
     }
 
-    /**
-     * Implements Object.equals.
-     * <p>
-     * 
-     * @param obj object to compare
-     * @return true if objects are equal
-     */
+    @Override
     public boolean equals(Object obj) {
-        return mString.equals(obj);
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        RequestId other = (RequestId) obj;
+        if (value == null) {
+            if (other.value != null)
+                return false;
+        } else if (!value.equals(other.value))
+            return false;
+        return true;
     }
-
-    // instance variables
-    private final String mString;
 }
diff --git a/pki/base/common/src/com/netscape/certsrv/request/RequestIdAdapter.java b/pki/base/common/src/com/netscape/certsrv/request/RequestIdAdapter.java
new file mode 100644
index 0000000000000000000000000000000000000000..b46732236e9c211de27e60c99f2ec28a7aae238f
--- /dev/null
+++ b/pki/base/common/src/com/netscape/certsrv/request/RequestIdAdapter.java
@@ -0,0 +1,37 @@
+// --- 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) 2007 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+package com.netscape.certsrv.request;
+
+import javax.xml.bind.annotation.adapters.XmlAdapter;
+
+/**
+ * The RequestIdAdapter class provides custom marshaling for RequestId.
+ *
+ * @author Endi S. Dewata
+ * @version $Revision$ $Date$
+ */
+public class RequestIdAdapter extends XmlAdapter<String, RequestId> {
+
+    public RequestId unmarshal(String value) throws Exception {
+        return new RequestId(value);
+    }
+
+    public String marshal(RequestId value) throws Exception {
+        return value.toString();
+    }
+}
\ No newline at end of file
diff --git a/pki/base/common/src/com/netscape/cms/servlet/key/KeyResourceService.java b/pki/base/common/src/com/netscape/cms/servlet/key/KeyResourceService.java
index 4888d609f6feb63d39c6d1ad3f26a9fb811d9d4d..79e6ccfdb4e45cb1715835b6cac7d3ce4ff77f1c 100644
--- a/pki/base/common/src/com/netscape/cms/servlet/key/KeyResourceService.java
+++ b/pki/base/common/src/com/netscape/cms/servlet/key/KeyResourceService.java
@@ -32,8 +32,11 @@ import com.netscape.cms.servlet.request.model.KeyRequestDAO;
 import com.netscape.cms.servlet.request.model.KeyRequestInfo;
 import com.netscape.cms.servlet.request.model.RecoveryRequestData;
 import com.netscape.certsrv.request.IRequest;
+import com.netscape.certsrv.request.RequestId;
 import com.netscape.certsrv.request.RequestStatus;
 import com.netscape.certsrv.base.EBaseException;
+import com.netscape.certsrv.dbs.keydb.KeyId;
+
 /**
  * @author alee
  * 
@@ -50,7 +53,7 @@ public class KeyResourceService extends CMSResourceService implements KeyResourc
      */
     public KeyData retrieveKey(RecoveryRequestData data) {
         // auth and authz
-        String keyId = validateRequest(data);
+        KeyId keyId = validateRequest(data);
         KeyDAO dao = new KeyDAO();
         KeyData keyData;
         try {
@@ -73,10 +76,10 @@ public class KeyResourceService extends CMSResourceService implements KeyResourc
         return retrieveKey(data);
     }
     
-    private String validateRequest(RecoveryRequestData data) {
+    private KeyId validateRequest(RecoveryRequestData data) {
         
         // confirm request exists
-        String reqId = data.getRequestId();
+        RequestId reqId = data.getRequestId();
         if (reqId == null) {
             // log error
             throw new WebApplicationException(Response.Status.BAD_REQUEST);
@@ -120,8 +123,7 @@ public class KeyResourceService extends CMSResourceService implements KeyResourc
             throw new WebApplicationException(Response.Status.UNAUTHORIZED);
         }
         
-        String keyURL = reqInfo.getKeyURL();
-        return keyURL.substring(keyURL.lastIndexOf("/") + 1);
+        return reqInfo.getKeyId();
     }
 
 }
diff --git a/pki/base/common/src/com/netscape/cms/servlet/key/KeysResource.java b/pki/base/common/src/com/netscape/cms/servlet/key/KeysResource.java
index 35cd5ccbe45ab0b78e550c20837de6b8de0e91e1..c93ffa4c913c84958d4b59adcaa70d805caf6359 100644
--- a/pki/base/common/src/com/netscape/cms/servlet/key/KeysResource.java
+++ b/pki/base/common/src/com/netscape/cms/servlet/key/KeysResource.java
@@ -10,14 +10,14 @@ import com.netscape.cms.servlet.key.model.KeyDataInfos;
  
 @Path("/keys")
 public interface KeysResource {
-    public static final String DEFAULT_MAXTIME = "10";
-    public static final String DEFAULT_MAXRESULTS = "100";
+    public static final int DEFAULT_MAXTIME = 10;
+    public static final int DEFAULT_MAXRESULTS = 100;
     
     @GET
     @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.TEXT_XML })
     public KeyDataInfos listKeys(@QueryParam("clientID") String clientID,
                                  @QueryParam("status") String status,
-                                 @DefaultValue(DEFAULT_MAXRESULTS) @QueryParam("maxResults") int maxResults,
-                                 @DefaultValue(DEFAULT_MAXTIME) @QueryParam("maxTime") int maxTime);
+                                 @DefaultValue(""+DEFAULT_MAXRESULTS) @QueryParam("maxResults") int maxResults,
+                                 @DefaultValue(""+DEFAULT_MAXTIME) @QueryParam("maxTime") int maxTime);
     
 }
diff --git a/pki/base/common/src/com/netscape/cms/servlet/key/model/KeyDAO.java b/pki/base/common/src/com/netscape/cms/servlet/key/model/KeyDAO.java
index f2ee46c66857a726142163dc449f11201e592de2..f479c6f0d3b4a5bd34b95d315ea0c4f9170f711d 100644
--- a/pki/base/common/src/com/netscape/cms/servlet/key/model/KeyDAO.java
+++ b/pki/base/common/src/com/netscape/cms/servlet/key/model/KeyDAO.java
@@ -30,6 +30,7 @@ import com.netscape.certsrv.apps.CMS;
 import com.netscape.certsrv.base.EBaseException;
 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.kra.IKeyRecoveryAuthority;
 import com.netscape.certsrv.request.IRequest;
 import com.netscape.certsrv.request.IRequestQueue;
@@ -87,23 +88,22 @@ public class KeyDAO {
         return ret;
     }
     
-    public KeyData getKey(String keyId, RecoveryRequestData data) throws EBaseException {
+    public KeyData getKey(KeyId keyId, RecoveryRequestData data) throws EBaseException {
         KeyData keyData;
-        BigInteger serial = new BigInteger(keyId);
-        
-        String rId = data.getRequestId();
+
+        RequestId rId = data.getRequestId();
 
         String transWrappedSessionKey;
         String sessionWrappedPassphrase;
 
-        IRequest  request = queue.findRequest(new RequestId(rId));
+        IRequest request = queue.findRequest(rId);
 
         if (request == null) {
             return null;
         }
 
      // get wrapped key
-        IKeyRecord rec = repo.readKeyRecord(serial);
+        IKeyRecord rec = repo.readKeyRecord(keyId.toBigInteger());
         if (rec == null) {
             return null;  
         }
@@ -133,7 +133,7 @@ public class KeyDAO {
             sessionWrappedPassphrase = data.getSessionWrappedPassphrase();
             nonceData = data.getNonceData();
 
-            if(transWrappedSessionKey == null) {
+            if (transWrappedSessionKey == null) {
                  //There must be at least a transWrappedSessionKey input provided.
                  //The command AND the request have provided insufficient data, end of the line.
                  throw new EBaseException("Can't retrieve key, insufficient input data!");
diff --git a/pki/base/common/src/com/netscape/cms/servlet/key/model/KeyDataInfo.java b/pki/base/common/src/com/netscape/cms/servlet/key/model/KeyDataInfo.java
index 46843ba9061fd398fc86fcf36915c1d5e57d6ae8..88b31b4d1ccf32fbacab61944c4d6909af2d1425 100644
--- a/pki/base/common/src/com/netscape/cms/servlet/key/model/KeyDataInfo.java
+++ b/pki/base/common/src/com/netscape/cms/servlet/key/model/KeyDataInfo.java
@@ -26,6 +26,8 @@ import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.XmlAccessorType;
 
+import com.netscape.certsrv.dbs.keydb.KeyId;
+
 /**
  * @author alee
  *
@@ -59,6 +61,14 @@ public class KeyDataInfo {
     }
 
     /**
+     * @return the key ID in the keyURL
+     */
+    public KeyId getKeyId() {
+        String id = keyURL.substring(keyURL.lastIndexOf("/") + 1);
+        return new KeyId(id);
+    }
+
+    /**
      * @return the clientID
      */
     public String getClientID() {
diff --git a/pki/base/common/src/com/netscape/cms/servlet/request/KeyRequestResource.java b/pki/base/common/src/com/netscape/cms/servlet/request/KeyRequestResource.java
index 656768f02eb904231336b5646d856c215b0fc19e..cd08f46bbbdd6d8d6615bed1cdafa151b99c283c 100644
--- a/pki/base/common/src/com/netscape/cms/servlet/request/KeyRequestResource.java
+++ b/pki/base/common/src/com/netscape/cms/servlet/request/KeyRequestResource.java
@@ -8,6 +8,8 @@ import javax.ws.rs.Produces;
 import javax.ws.rs.Consumes;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
+
+import com.netscape.certsrv.request.RequestId;
 import com.netscape.cms.servlet.request.model.ArchivalRequestData;
 import com.netscape.cms.servlet.request.model.KeyRequestInfo;
 import com.netscape.cms.servlet.request.model.RecoveryRequestData;
@@ -24,7 +26,7 @@ public interface KeyRequestResource {
     @GET
     @Path("{id}")
     @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.TEXT_XML })
-    public KeyRequestInfo getRequestInfo(@PathParam("id") String id);
+    public KeyRequestInfo getRequestInfo(@PathParam("id") RequestId id);
 
     // Archiving - used to test integration with a browser
     @POST
@@ -54,14 +56,14 @@ public interface KeyRequestResource {
 
     @POST
     @Path("approve/{id}")
-    public void approveRequest(@PathParam("id") String id);
+    public void approveRequest(@PathParam("id") RequestId id);
 
     @POST
     @Path("reject/{id}")
-    public void rejectRequest(@PathParam("id") String id);
+    public void rejectRequest(@PathParam("id") RequestId id);
 
     @POST
     @Path("cancel/{id}")
-    public void cancelRequest(@PathParam("id") String id);
+    public void cancelRequest(@PathParam("id") RequestId id);
 
 }
diff --git a/pki/base/common/src/com/netscape/cms/servlet/request/KeyRequestResourceService.java b/pki/base/common/src/com/netscape/cms/servlet/request/KeyRequestResourceService.java
index e18407727f78a4e4e87a8c488d11dd0f70b452e5..43e58bbdc604beb6e92eb0042f2e06784afb5e3f 100644
--- a/pki/base/common/src/com/netscape/cms/servlet/request/KeyRequestResourceService.java
+++ b/pki/base/common/src/com/netscape/cms/servlet/request/KeyRequestResourceService.java
@@ -18,13 +18,13 @@
 
 package com.netscape.cms.servlet.request;
 
-import javax.ws.rs.PathParam;
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
 import com.netscape.certsrv.base.EBaseException;
+import com.netscape.certsrv.request.RequestId;
 import com.netscape.cms.servlet.base.CMSResourceService;
 import com.netscape.cms.servlet.request.model.ArchivalRequestData;
 import com.netscape.cms.servlet.request.model.KeyRequestDAO;
@@ -43,7 +43,7 @@ public class KeyRequestResourceService extends CMSResourceService implements Key
     /**
      * Used to retrieve key request info for a specific request
      */
-    public KeyRequestInfo getRequestInfo(String id) {
+    public KeyRequestInfo getRequestInfo(RequestId id) {
         // auth and authz
         KeyRequestDAO dao = new KeyRequestDAO();
         KeyRequestInfo info;
@@ -118,8 +118,8 @@ public class KeyRequestResourceService extends CMSResourceService implements Key
         return info;
     }
     
-    public void approveRequest(@PathParam("id") String id) {
-        if ( id == null) {
+    public void approveRequest(RequestId id) {
+        if (id == null) {
             throw new WebApplicationException(Response.Status.BAD_REQUEST);
         }
         // auth and authz
@@ -133,8 +133,8 @@ public class KeyRequestResourceService extends CMSResourceService implements Key
         }
     }
     
-    public void rejectRequest(@PathParam("id") String id) {
-        if ( id == null) {
+    public void rejectRequest(RequestId id) {
+        if (id == null) {
             throw new WebApplicationException(Response.Status.BAD_REQUEST);
         }
         // auth and authz
@@ -148,8 +148,8 @@ public class KeyRequestResourceService extends CMSResourceService implements Key
         }
     }
          
-    public void cancelRequest(@PathParam("id") String id) {
-        if ( id == null) {
+    public void cancelRequest(RequestId id) {
+        if (id == null) {
             throw new WebApplicationException(Response.Status.BAD_REQUEST);
         }
         // auth and authz
diff --git a/pki/base/common/src/com/netscape/cms/servlet/request/KeyRequestsResource.java b/pki/base/common/src/com/netscape/cms/servlet/request/KeyRequestsResource.java
index 0f8fbc78fd664ecb69d2fa407b0217fff5694227..fd6bc4c27011b1fd9027d60d43f195adde7812ed 100644
--- a/pki/base/common/src/com/netscape/cms/servlet/request/KeyRequestsResource.java
+++ b/pki/base/common/src/com/netscape/cms/servlet/request/KeyRequestsResource.java
@@ -6,15 +6,17 @@ import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
 import javax.ws.rs.QueryParam;
 import javax.ws.rs.core.MediaType;
+
+import com.netscape.certsrv.request.RequestId;
 import com.netscape.cms.servlet.request.model.KeyRequestInfos;
 
 @Path("/keyrequests")
 public interface KeyRequestsResource {
 
-    public static final String DEFAULT_START = "0";
-    public static final String DEFAULT_PAGESIZE = "20";
-    public static final String DEFAULT_MAXRESULTS = "100";
-    public static final String DEFAULT_MAXTIME = "10";
+    public static final int DEFAULT_START = 0;
+    public static final int DEFAULT_PAGESIZE = 20;
+    public static final int DEFAULT_MAXRESULTS = 100;
+    public static final int DEFAULT_MAXTIME = 10;
 
     /**
      * Used to generate list of key requests based on the search parameters
@@ -24,9 +26,9 @@ public interface KeyRequestsResource {
     public KeyRequestInfos listRequests(@QueryParam("requestState") String requestState,
                                             @QueryParam("requestType") String requestType,
                                             @QueryParam("clientID") String clientID,
-                                            @DefaultValue(DEFAULT_START) @QueryParam("start") String start_s,
-                                            @DefaultValue(DEFAULT_PAGESIZE) @QueryParam("pageSize") int pageSize,
-                                            @DefaultValue(DEFAULT_MAXRESULTS) @QueryParam("maxResults") int maxResults,
-                                            @DefaultValue(DEFAULT_MAXTIME) @QueryParam("maxTime") int maxTime);
+                                            @DefaultValue(""+DEFAULT_START) @QueryParam("start") RequestId start,
+                                            @DefaultValue(""+DEFAULT_PAGESIZE) @QueryParam("pageSize") int pageSize,
+                                            @DefaultValue(""+DEFAULT_MAXRESULTS) @QueryParam("maxResults") int maxResults,
+                                            @DefaultValue(""+DEFAULT_MAXTIME) @QueryParam("maxTime") int maxTime);
 
 }
diff --git a/pki/base/common/src/com/netscape/cms/servlet/request/KeyRequestsResourceService.java b/pki/base/common/src/com/netscape/cms/servlet/request/KeyRequestsResourceService.java
index 290868ab5574bafbcdcad6fc7d5f38d3d04085e1..9b11a96d606f248de483d4d5b319ec196ef66460 100644
--- a/pki/base/common/src/com/netscape/cms/servlet/request/KeyRequestsResourceService.java
+++ b/pki/base/common/src/com/netscape/cms/servlet/request/KeyRequestsResourceService.java
@@ -25,10 +25,11 @@ import javax.ws.rs.core.UriInfo;
 
 import com.netscape.certsrv.apps.CMS;
 import com.netscape.certsrv.base.EBaseException;
+import com.netscape.certsrv.request.RequestId;
 import com.netscape.cms.servlet.base.CMSResourceService;
 import com.netscape.cms.servlet.request.model.KeyRequestDAO;
 import com.netscape.cms.servlet.request.model.KeyRequestInfos;
- 
+
 /**
  * @author alee
  *
@@ -42,28 +43,16 @@ public class KeyRequestsResourceService extends CMSResourceService implements Ke
      * Used to generate list of key requests based on the search parameters
      */
     public KeyRequestInfos listRequests(String requestState, String requestType, String clientID,
-                                        String start_s, int pageSize, int maxResults,
-                                        int maxTime) {
+            RequestId start, int pageSize, int maxResults, int maxTime) {
         // auth and authz
         
         // get ldap filter
         String filter = createSearchFilter(requestState, requestType, clientID);
         CMS.debug("listRequests: filter is " + filter);
        
-        
         // get start marker
-        int start = Integer.parseInt(KeyRequestsResource.DEFAULT_START);
-        if (start_s != null) {
-            try {
-                if (start_s.trim().startsWith("0x")) {
-                    start = Integer.parseInt(start_s.trim().substring(2), 16);
-                } else {
-                    start = Integer.parseInt(start_s.trim());
-                }
-            } catch (NumberFormatException e) {
-                CMS.debug("listRequests: NumberformatException: Invalid value for start " + start_s);
-                throw new WebApplicationException(Response.Status.NOT_FOUND);
-            }
+        if (start == null) {
+            start = new RequestId(KeyRequestsResource.DEFAULT_START);
         }
         
         KeyRequestDAO reqDAO = new KeyRequestDAO();
diff --git a/pki/base/common/src/com/netscape/cms/servlet/request/ProcessCertReq.java b/pki/base/common/src/com/netscape/cms/servlet/request/ProcessCertReq.java
index 68328a73cbc27eec437a084d175f952464214359..ee5581a6d6d042273d37dc81fb947f12b093ad5e 100644
--- a/pki/base/common/src/com/netscape/cms/servlet/request/ProcessCertReq.java
+++ b/pki/base/common/src/com/netscape/cms/servlet/request/ProcessCertReq.java
@@ -314,7 +314,7 @@ public class ProcessCertReq extends CMSServlet {
             IRequest r = null;
 
             if (seqNum.compareTo(BigInteger.ONE.negate()) > 0) {
-                r = mQueue.findRequest(new RequestId(seqNum.toString()));
+                r = mQueue.findRequest(new RequestId(seqNum));
             }
 
             if (seqNum.compareTo(BigInteger.ONE.negate()) > 0 && r != null) {
@@ -424,7 +424,7 @@ public class ProcessCertReq extends CMSServlet {
         }
 
         try {
-            IRequest r = mQueue.findRequest(new RequestId(seqNum.toString()));
+            IRequest r = mQueue.findRequest(new RequestId(seqNum));
 
             if (r != null) {
                 // overwrite "auditRequesterID" if and only if "id" != null
diff --git a/pki/base/common/src/com/netscape/cms/servlet/request/ProcessReq.java b/pki/base/common/src/com/netscape/cms/servlet/request/ProcessReq.java
index 93457a2816832b4698e78caf3bf8f06ad7e39680..a4eb68b1946b66a33d202a7507fa64b4c40e94d6 100644
--- a/pki/base/common/src/com/netscape/cms/servlet/request/ProcessReq.java
+++ b/pki/base/common/src/com/netscape/cms/servlet/request/ProcessReq.java
@@ -245,7 +245,7 @@ public class ProcessReq extends CMSServlet {
 
         header.addBigIntegerValue("seqNum", seqNum, 10);
 
-        IRequest r = mQueue.findRequest(new RequestId(seqNum.toString()));
+        IRequest r = mQueue.findRequest(new RequestId(seqNum));
 
         if (r != null) {
             if (doAssign != null) {
diff --git a/pki/base/common/src/com/netscape/cms/servlet/request/QueryReq.java b/pki/base/common/src/com/netscape/cms/servlet/request/QueryReq.java
index e580cc9a453b40a93655fa48e0c16be239067c83..181f9f906d11f19fdb21ea536da716d03c16f67e 100644
--- a/pki/base/common/src/com/netscape/cms/servlet/request/QueryReq.java
+++ b/pki/base/common/src/com/netscape/cms/servlet/request/QueryReq.java
@@ -414,7 +414,7 @@ public class QueryReq extends CMSServlet {
                 jumptoend = true; // override  to '99' during search 
             }
 
-            RequestId id = new RequestId(marker.toString());
+            RequestId id = new RequestId(marker);
             IRequestVirtualList list = mQueue.getPagedRequestsByFilter(
                     id,
                     jumptoend,
diff --git a/pki/base/common/src/com/netscape/cms/servlet/request/model/KeyRequestDAO.java b/pki/base/common/src/com/netscape/cms/servlet/request/model/KeyRequestDAO.java
index 4da4af6d5ce0cba5f1752c464f3952c3b797719e..9b1c0ce54b531964d1ca201f5e3cd0a738b63bcb 100644
--- a/pki/base/common/src/com/netscape/cms/servlet/request/model/KeyRequestDAO.java
+++ b/pki/base/common/src/com/netscape/cms/servlet/request/model/KeyRequestDAO.java
@@ -29,6 +29,7 @@ import javax.ws.rs.core.UriInfo;
 
 import com.netscape.certsrv.apps.CMS;
 import com.netscape.certsrv.base.EBaseException;
+import com.netscape.certsrv.dbs.keydb.KeyId;
 import com.netscape.certsrv.kra.IKeyRecoveryAuthority;
 import com.netscape.certsrv.request.IRequest;
 import com.netscape.certsrv.request.IRequestList;
@@ -89,7 +90,7 @@ public class KeyRequestDAO {
      * @return collection of key request info
      * @throws EBaseException
      */
-    public KeyRequestInfos listRequests(String filter, int start, int pageSize, int maxResults, int maxTime, 
+    public KeyRequestInfos listRequests(String filter, RequestId start, int pageSize, int maxResults, int maxTime,
             UriInfo uriInfo) throws EBaseException {
         List <KeyRequestInfo> list = new ArrayList<KeyRequestInfo>();
         List <Link> links = new ArrayList<Link>();
@@ -97,8 +98,7 @@ public class KeyRequestDAO {
         int current = 0;
         
         if (isVLVSearch(filter)) {
-            RequestId id = new RequestId(Integer.toString(start));
-            IRequestVirtualList vlvlist = queue.getPagedRequestsByFilter(id, false, filter, 
+            IRequestVirtualList vlvlist = queue.getPagedRequestsByFilter(start, false, filter,
                                                                          pageSize +1 , "requestId");
             totalSize = vlvlist.getSize();
             current = vlvlist.getCurrentIndex();
@@ -120,7 +120,7 @@ public class KeyRequestDAO {
                 return null;
             }
             while (requests.hasMoreElements()) {
-                RequestId rid = (RequestId) requests.nextElement();
+                RequestId rid = requests.nextElement();
                 IRequest request = queue.findRequest(rid);
                 if (request != null) {
                     list.add(createKeyRequestInfo(request, uriInfo));
@@ -168,8 +168,8 @@ public class KeyRequestDAO {
      * @return info for specific request
      * @throws EBaseException 
      */
-    public KeyRequestInfo getRequest(String id, UriInfo uriInfo) throws EBaseException {
-        IRequest request = queue.findRequest(new RequestId(id));
+    public KeyRequestInfo getRequest(RequestId id, UriInfo uriInfo) throws EBaseException {
+        IRequest request = queue.findRequest(id);
         if (request == null) {
             return null;
         }
@@ -189,7 +189,7 @@ public class KeyRequestDAO {
 
         boolean keyExists = doesKeyExist(clientId, "active", uriInfo);
 
-        if(keyExists == true) {
+        if (keyExists == true) {
             throw new EBaseException("Can not archive already active existing key!");
         }
 
@@ -221,7 +221,7 @@ public class KeyRequestDAO {
 
         IRequest request = queue.newRequest(IRequest.SECURITY_DATA_RECOVERY_REQUEST);
 
-        String keyId = data.getKeyId();
+        KeyId keyId = data.getKeyId();
 
         Hashtable<String, Object> requestParams;
         requestParams = kra.createVolatileRequest(request.getRequestId());
@@ -244,27 +244,27 @@ public class KeyRequestDAO {
             requestParams.put(IRequest.SECURITY_DATA_IV_STRING_IN, nonceDataStr);
         }
 
-        request.setExtData(ATTR_SERIALNO,keyId);
+        request.setExtData(ATTR_SERIALNO, keyId.toString());
 
         queue.processRequest(request);
 
         return createKeyRequestInfo(request, uriInfo);
     }
 
-    public void approveRequest(String id) throws EBaseException {
-        IRequest request = queue.findRequest(new RequestId(id));
+    public void approveRequest(RequestId id) throws EBaseException {
+        IRequest request = queue.findRequest(id);
         request.setRequestStatus(RequestStatus.APPROVED);
         queue.updateRequest(request);
     }
     
-    public void rejectRequest(String id) throws EBaseException {
-        IRequest request = queue.findRequest(new RequestId(id));
+    public void rejectRequest(RequestId id) throws EBaseException {
+        IRequest request = queue.findRequest(id);
         request.setRequestStatus(RequestStatus.CANCELED);
         queue.updateRequest(request);
     }
     
-    public void cancelRequest(String id) throws EBaseException {
-        IRequest request = queue.findRequest(new RequestId(id));
+    public void cancelRequest(RequestId id) throws EBaseException {
+        IRequest request = queue.findRequest(id);
         request.setRequestStatus(RequestStatus.REJECTED);
         queue.updateRequest(request);
     }
@@ -276,7 +276,7 @@ public class KeyRequestDAO {
         ret.setRequestStatus(request.getRequestStatus().toString());
         
         Path keyRequestPath = KeyRequestResource.class.getAnnotation(Path.class);
-        String rid = request.getRequestId().toString();
+        RequestId rid = request.getRequestId();
 
         UriBuilder reqBuilder = uriInfo.getBaseUriBuilder();
         reqBuilder.path(keyRequestPath.value() + "/" + rid);
diff --git a/pki/base/common/src/com/netscape/cms/servlet/request/model/KeyRequestInfo.java b/pki/base/common/src/com/netscape/cms/servlet/request/model/KeyRequestInfo.java
index d768e2ba98e9dda41909f872630b3bf986257618..f07c302dde5b21db7c71d237c0b4d9332bf6c31d 100644
--- a/pki/base/common/src/com/netscape/cms/servlet/request/model/KeyRequestInfo.java
+++ b/pki/base/common/src/com/netscape/cms/servlet/request/model/KeyRequestInfo.java
@@ -23,6 +23,9 @@ import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlElement;
 
+import com.netscape.certsrv.dbs.keydb.KeyId;
+import com.netscape.certsrv.request.RequestId;
+
 @XmlRootElement(name="SecurityDataRequestInfo")
 @XmlAccessorType(XmlAccessType.FIELD)
 public class KeyRequestInfo {
@@ -79,6 +82,14 @@ public class KeyRequestInfo {
     }
 
     /**
+     * @return the request ID in the requestURL
+     */
+    public RequestId getRequestId() {
+        String id = requestURL.substring(requestURL.lastIndexOf("/") + 1);
+        return new RequestId(id);
+    }
+
+    /**
      * @param requestURL the requestURL to set
      */
     public void setRequestURL(String requestURL) {
@@ -93,6 +104,14 @@ public class KeyRequestInfo {
     }
 
     /**
+     * @return the key ID in the keyURL
+     */
+    public KeyId getKeyId() {
+        String id = keyURL.substring(keyURL.lastIndexOf("/") + 1);
+        return new KeyId(id);
+    }
+
+    /**
      * @param keyURL the keyURL to set
      */
     public void setKeyURL(String keyURL) {
diff --git a/pki/base/common/src/com/netscape/cms/servlet/request/model/RecoveryRequestData.java b/pki/base/common/src/com/netscape/cms/servlet/request/model/RecoveryRequestData.java
index ae84175424d8a8bad6cda578b39888d6ae96e24e..80ec6d127fa53ceedfb4d62ace34791cec83db47 100644
--- a/pki/base/common/src/com/netscape/cms/servlet/request/model/RecoveryRequestData.java
+++ b/pki/base/common/src/com/netscape/cms/servlet/request/model/RecoveryRequestData.java
@@ -26,6 +26,12 @@ import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
+
+import com.netscape.certsrv.dbs.keydb.KeyId;
+import com.netscape.certsrv.dbs.keydb.KeyIdAdapter;
+import com.netscape.certsrv.request.RequestId;
+import com.netscape.certsrv.request.RequestIdAdapter;
 
 /**
  * @author alee
@@ -42,10 +48,12 @@ public class RecoveryRequestData {
     private static final String NONCE_DATA = "nonceData";
 
     @XmlElement
-    protected String keyId;
+    @XmlJavaTypeAdapter(KeyIdAdapter.class)
+    protected KeyId keyId;
     
     @XmlElement
-    protected String requestId;
+    @XmlJavaTypeAdapter(RequestIdAdapter.class)
+    protected RequestId requestId;
     
     @XmlElement
     protected String transWrappedSessionKey;
@@ -61,8 +69,12 @@ public class RecoveryRequestData {
     }
     
     public RecoveryRequestData(MultivaluedMap<String, String> form) {
-        keyId = form.getFirst(KEY_ID);
-        requestId = form.getFirst(REQUEST_ID);
+        if (form.containsKey(KEY_ID)) {
+            keyId = new KeyId(form.getFirst(KEY_ID));
+        }
+        if (form.containsKey(REQUEST_ID)) {
+            requestId = new RequestId(form.getFirst(REQUEST_ID));
+        }
         transWrappedSessionKey = form.getFirst(TRANS_WRAPPED_SESSION_KEY);
         sessionWrappedPassphrase = form.getFirst(SESSION_WRAPPED_PASSPHRASE);
         nonceData = form.getFirst(NONCE_DATA);
@@ -71,28 +83,28 @@ public class RecoveryRequestData {
     /**
      * @return the keyId
      */
-    public String getKeyId() {
+    public KeyId getKeyId() {
         return keyId;
     }
 
     /**
      * @param keyId the keyId to set
      */
-    public void setKeyId(String keyId) {
+    public void setKeyId(KeyId keyId) {
         this.keyId = keyId;
     }
 
     /**
      * @return the requestId
      */
-    public String getRequestId() {
+    public RequestId getRequestId() {
         return requestId;
     }
 
     /**
      * @param requestId the requestId to set
      */
-    public void setRequestId(String requestId) {
+    public void setRequestId(RequestId requestId) {
         this.requestId = requestId;
     }
 
diff --git a/pki/base/common/src/com/netscape/cmscore/cert/PrettyPrintFormat.java b/pki/base/common/src/com/netscape/cmscore/cert/PrettyPrintFormat.java
index fb97a5ccb2a62c8244cd2d2fa161461950ac8d9b..6692005752516270e74bfadf7ac313d54b7515e5 100644
--- a/pki/base/common/src/com/netscape/cmscore/cert/PrettyPrintFormat.java
+++ b/pki/base/common/src/com/netscape/cmscore/cert/PrettyPrintFormat.java
@@ -104,6 +104,9 @@ public class PrettyPrintFormat implements IPrettyPrintFormat {
 
     public String toHexString(byte[] in, int indentSize,
             int lineLen, String separator) {
+
+        if (in == null) return "";
+
         StringBuffer sb = new StringBuffer();
         int hexCount = 0;
         char c[];
diff --git a/pki/base/common/src/com/netscape/cmscore/request/RequestQueue.java b/pki/base/common/src/com/netscape/cmscore/request/RequestQueue.java
index b23e6fff4205ac2ab48678fff339ca9d57bc10ba..ef13d3c293c62faa528f0037a662a3d3e8c0e1f0 100644
--- a/pki/base/common/src/com/netscape/cmscore/request/RequestQueue.java
+++ b/pki/base/common/src/com/netscape/cmscore/request/RequestQueue.java
@@ -52,7 +52,7 @@ public class RequestQueue
         // get the next request Id
         BigInteger next = mRepository.getNextSerialNumber();
 
-        RequestId rid = new RequestId(next.toString());
+        RequestId rid = new RequestId(next);
 
         return rid;
     }
@@ -241,7 +241,7 @@ public class RequestQueue
 
         String filter = "(" + "requeststate" + "=*" + ")";
 
-        RequestId fromId = new RequestId(reqId_upper_bound.toString(10));
+        RequestId fromId = new RequestId(reqId_upper_bound);
 
         CMS.debug("RequestQueue: getLastRequestId: filter " + filter + " fromId " + fromId);
         ListEnumeration recList = (ListEnumeration) getPagedRequestsByFilter(fromId, filter, 5 * -1, "requestId");
diff --git a/pki/base/common/test/com/netscape/cmscore/request/RequestRecordTest.java b/pki/base/common/test/com/netscape/cmscore/request/RequestRecordTest.java
index 06a4725716cdc35cc6bde14418e796fb0395f30e..0ebf3beabd1a85cba4250e7c57c583832deb0210 100644
--- a/pki/base/common/test/com/netscape/cmscore/request/RequestRecordTest.java
+++ b/pki/base/common/test/com/netscape/cmscore/request/RequestRecordTest.java
@@ -29,7 +29,7 @@ public class RequestRecordTest extends CMSBaseTestCase {
 
     public void cmsTestSetUp() {
         requestRecord = new RequestRecord();
-        request = new Request(new RequestId("testid"));
+        request = new Request(new RequestId("0xabcdef"));
     }
 
     public void cmsTestTearDown() {
diff --git a/pki/base/common/test/com/netscape/cmscore/request/RequestTest.java b/pki/base/common/test/com/netscape/cmscore/request/RequestTest.java
index 3ca589280ef79452ad649c3277fac8e50d720c3f..b396c2d3572a0363e9fbd767affab88ffef455a4 100644
--- a/pki/base/common/test/com/netscape/cmscore/request/RequestTest.java
+++ b/pki/base/common/test/com/netscape/cmscore/request/RequestTest.java
@@ -42,7 +42,7 @@ public class RequestTest extends CMSBaseTestCase {
         cmsStub = new CMSMemoryStub();
         CMS.setCMSEngine(cmsStub);
 
-        request = new Request(new RequestId("testid"));
+        request = new Request(new RequestId("0xabcdef"));
     }
 
     public void cmsTestTearDown() {
diff --git a/pki/base/kra/functional/drmclient.py b/pki/base/kra/functional/drmclient.py
index 95ce04207bb3474d5dcbb5c5cd9f6bfaa2f265df..531e2f450247145a0ac263bc88d9b50fd36a1b85 100644
--- a/pki/base/kra/functional/drmclient.py
+++ b/pki/base/kra/functional/drmclient.py
@@ -976,6 +976,7 @@ print response
 
 #create recovery request
 key_id = response.keys()[0]
+print key_id
 response = test_kra.submit_recovery_request(key_id)
 print response
 
diff --git a/pki/base/kra/functional/src/com/netscape/cms/servlet/test/DRMRestClient.java b/pki/base/kra/functional/src/com/netscape/cms/servlet/test/DRMRestClient.java
index eaf6b98dd1283fc50ddce30443ff5f24e269b89b..51cead47b029a6ba914dfc1411dbaf6bb5d51435 100644
--- a/pki/base/kra/functional/src/com/netscape/cms/servlet/test/DRMRestClient.java
+++ b/pki/base/kra/functional/src/com/netscape/cms/servlet/test/DRMRestClient.java
@@ -5,6 +5,9 @@ import java.util.Iterator;
 
 import org.jboss.resteasy.client.ClientResponse;
 import org.jboss.resteasy.client.ProxyFactory;
+
+import com.netscape.certsrv.dbs.keydb.KeyId;
+import com.netscape.certsrv.request.RequestId;
 import com.netscape.cms.servlet.admin.SystemCertificateResource;
 import com.netscape.cms.servlet.cert.model.CertificateData;
 import com.netscape.cms.servlet.key.KeyResource;
@@ -45,7 +48,9 @@ public class DRMRestClient {
     }
     
     public Collection<KeyRequestInfo> listRequests(String requestState, String requestType) {
-        KeyRequestInfos infos = keyRequestsClient.listRequests(requestState, requestType, null, "0", 100, 100, 10);
+        KeyRequestInfos infos = keyRequestsClient.listRequests(
+                requestState, requestType, null, new RequestId(0), 100, 100, 10
+        );
         Collection<KeyRequestInfo> list = infos.getRequests();
         return list;
     }
@@ -77,7 +82,7 @@ public class DRMRestClient {
         return null;
     }
     
-    public KeyRequestInfo requestRecovery(String keyId, byte[] rpwd, byte[] rkey, byte[] nonceData) {
+    public KeyRequestInfo requestRecovery(KeyId keyId, byte[] rpwd, byte[] rkey, byte[] nonceData) {
         // create recovery request
         RecoveryRequestData data = new RecoveryRequestData();
         data.setKeyId(keyId);
@@ -96,11 +101,11 @@ public class DRMRestClient {
         return info;
     }
     
-    public void approveRecovery(String recoveryId) {
+    public void approveRecovery(RequestId recoveryId) {
         keyRequestClient.approveRequest(recoveryId);
     }
     
-    public KeyData retrieveKey(String keyId, String requestId, byte[] rpwd, byte[] rkey, byte[] nonceData) {
+    public KeyData retrieveKey(KeyId keyId, RequestId requestId, byte[] rpwd, byte[] rkey, byte[] nonceData) {
         // create recovery request
         RecoveryRequestData data = new RecoveryRequestData();
         data.setKeyId(keyId);
diff --git a/pki/base/kra/functional/src/com/netscape/cms/servlet/test/DRMTest.java b/pki/base/kra/functional/src/com/netscape/cms/servlet/test/DRMTest.java
index 368cb72822b0bd453cbb6d6abc0ef3618901f7f9..8020ec2cab7542aeab55fbf699c12d713e3cb83a 100644
--- a/pki/base/kra/functional/src/com/netscape/cms/servlet/test/DRMTest.java
+++ b/pki/base/kra/functional/src/com/netscape/cms/servlet/test/DRMTest.java
@@ -38,6 +38,8 @@ import org.apache.commons.cli.Options;
 import org.apache.commons.cli.ParseException;
 import org.apache.commons.cli.PosixParser;
 
+import com.netscape.certsrv.dbs.keydb.KeyId;
+import com.netscape.certsrv.request.RequestId;
 import com.netscape.cms.servlet.base.CMSResourceService;
 import com.netscape.cms.servlet.key.model.KeyData;
 import com.netscape.cms.servlet.key.model.KeyDataInfo;
@@ -134,9 +136,9 @@ public class DRMTest {
         String recoveredKey = null;
 
         // various ids used in recovery/archival operations
-        String keyId = null;
+        KeyId keyId = null;
         String clientId = null;
-        String recoveryRequestId = null;
+        RequestId recoveryRequestId = null;
 
         // Variables for data structures from calls
         KeyRequestInfo requestInfo = null;
@@ -218,7 +220,7 @@ public class DRMTest {
             KeyRequestInfo info = client.archiveSecurityData(encoded, clientId, KeyRequestResource.SYMMETRIC_KEY_TYPE);
             log("Archival Results:");
             printRequestInfo(info);
-            keyId = getId(info.getKeyURL());
+            keyId = info.getKeyId();
         } catch (Exception e) {
             log("Exception in archiving symmetric key:" + e.getMessage());
             e.printStackTrace();
@@ -228,7 +230,7 @@ public class DRMTest {
 
         log("Getting key ID for symmetric key");
         keyInfo = client.getKeyData(clientId, "active");
-        String keyId2 = getId(keyInfo.getKeyURL());
+        KeyId keyId2 = keyInfo.getKeyId();
         if (keyId2 == null) {
             log("No archived key found");
         } else {
@@ -247,7 +249,7 @@ public class DRMTest {
             recoveryKey = CryptoUtil.generateKey(token, KeyGenAlgorithm.DES3);
             wrappedRecoveryKey = CryptoUtil.wrapSymmetricKey(manager, token, transportCert, recoveryKey);
             KeyRequestInfo info = client.requestRecovery(keyId, null, wrappedRecoveryKey, ivps.getIV());
-            recoveryRequestId = getId(info.getRequestURL());
+            recoveryRequestId = info.getRequestId();
         } catch (Exception e) {
             log("Exception in recovering symmetric key using session key: " + e.getMessage());
         }
@@ -289,7 +291,7 @@ public class DRMTest {
             wrappedRecoveryKey = CryptoUtil.wrapSymmetricKey(manager, token, transportCert, recoveryKey);
 
             requestInfo = client.requestRecovery(keyId, wrappedRecoveryPassphrase, wrappedRecoveryKey, ivps.getIV());
-            recoveryRequestId = getId(requestInfo.getRequestURL());
+            recoveryRequestId = requestInfo.getRequestId();
         } catch (Exception e) {
             log("Exception in recovering symmetric key using passphrase" + e.toString());
             e.printStackTrace();
@@ -327,7 +329,7 @@ public class DRMTest {
             requestInfo = client.archiveSecurityData(encoded, clientId, KeyRequestResource.PASS_PHRASE_TYPE);
             log("Archival Results:");
             printRequestInfo(requestInfo);
-            keyId = getId(requestInfo.getKeyURL());
+            keyId = requestInfo.getKeyId();
         } catch (Exception e) {
             log("Exception in archiving symmetric key:" + e.toString());
             e.printStackTrace();
@@ -336,7 +338,7 @@ public class DRMTest {
         //Test 13: Get keyId for active passphrase with client ID
         log("Getting key ID for passphrase");
         keyInfo = client.getKeyData(clientId, "active");
-        keyId2 = getId(keyInfo.getKeyURL());
+        keyId2 = keyInfo.getKeyId();
         if (keyId2 == null) {
             log("No archived key found");
         } else {
@@ -360,7 +362,7 @@ public class DRMTest {
             wrappedRecoveryPassphrase = CryptoUtil.wrapPassphrase(token, recoveryPassphrase, ivps, recoveryKey,
                     EncryptionAlgorithm.DES3_CBC_PAD);
             requestInfo = client.requestRecovery(keyId, null, wrappedRecoveryKey, ivps.getIV());
-            recoveryRequestId = getId(requestInfo.getRequestURL());
+            recoveryRequestId = requestInfo.getRequestId();
         } catch (Exception e) {
             log("Exception in recovering passphrase using session key: " + e.getMessage());
         }
@@ -394,7 +396,7 @@ 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 = getId(requestInfo.getRequestURL());
+        recoveryRequestId = requestInfo.getRequestId();
 
         //Test 18: Approve recovery
         log("Approving recovery request: " + recoveryRequestId);
@@ -423,7 +425,7 @@ public class DRMTest {
 
         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 = getId(requestInfo.getRequestURL());
+        recoveryRequestId = requestInfo.getRequestId();
 
         //Test 21: Approve recovery
         log("Approving recovery request: " + recoveryRequestId);
@@ -453,10 +455,6 @@ public class DRMTest {
         System.out.println(string);
     }
 
-    private static String getId(String link) {
-        return link.substring(link.lastIndexOf("/") + 1);
-    }
-
     private static void printRequestInfo(KeyRequestInfo info) {
         log("KeyRequestURL: " + info.getRequestURL());
         log("Key URL:       " + info.getKeyURL());
diff --git a/pki/base/util/src/netscape/security/util/BigInt.java b/pki/base/util/src/netscape/security/util/BigInt.java
index 8f7b0b872ec0036c74cfd77625385ea4bc164956..9210648f124baee90e0e2aaa0a0357b97233552b 100644
--- a/pki/base/util/src/netscape/security/util/BigInt.java
+++ b/pki/base/util/src/netscape/security/util/BigInt.java
@@ -47,7 +47,7 @@ public final class BigInt {
      *            first. CONSUMED.
      */
     public BigInt(byte[] data) {
-        places = (byte[]) data.clone();
+        places = data.clone();
     }
 
     /**
@@ -154,7 +154,7 @@ public final class BigInt {
             zero[0] = (byte) 0;
             return zero;
         } else {
-            return (byte[]) places.clone();
+            return places.clone();
         }
     }
 
-- 
1.7.7.4

