>From aaea2c23e5abc288d46217be01e39668a82ff2b0 Mon Sep 17 00:00:00 2001
From: Andrew Wnuk <awnuk@redhat.com>
Date: Fri, 13 Jan 2012 12:18:44 -0800
Subject: [PATCH] Big numbers fix for CA and DRM.

This patch resolves multiple issues related to use of big numbers on CA and DRM
It also provides a fix for incomplete recovery requests causing null pointer exception.

Bugs: 756133, 758505.
---
 .../com/netscape/cms/servlet/cert/DoRevoke.java    |  206 +++++-----
 .../com/netscape/cms/servlet/cert/DoRevokeTPS.java |  131 +++----
 .../com/netscape/cms/servlet/cert/DoUnrevoke.java  |   64 ++--
 .../netscape/cms/servlet/cert/DoUnrevokeTPS.java   |   64 ++--
 .../cms/servlet/cert/GetCertFromRequest.java       |   11 +-
 .../cms/servlet/key/ConfirmRecoverBySerial.java    |   12 +-
 .../netscape/cms/servlet/key/DisplayBySerial.java  |   12 +-
 .../servlet/key/DisplayBySerialForRecovery.java    |   12 +-
 .../netscape/cms/servlet/key/KeyRecordParser.java  |    5 +-
 .../netscape/cms/servlet/key/RecoverBySerial.java  |   12 +-
 .../cms/servlet/request/CertReqParser.java         |    2 +-
 .../netscape/cms/servlet/request/CheckRequest.java |   23 +-
 .../cms/servlet/request/ProcessCertReq.java        |  407 ++++++++++----------
 .../netscape/cms/servlet/request/ProcessReq.java   |   28 +-
 .../com/netscape/cms/servlet/request/QueryReq.java |   70 ++--
 .../netscape/cms/servlet/request/ReqParser.java    |    5 +-
 16 files changed, 532 insertions(+), 532 deletions(-)

diff --git a/pki/base/common/src/com/netscape/cms/servlet/cert/DoRevoke.java b/pki/base/common/src/com/netscape/cms/servlet/cert/DoRevoke.java
index 4c11d477d1b558a68516d08dc853195d4e5bf9a1..9e36d8b816159d1ff024183e61c0e4837b64bb8b 100644
--- a/pki/base/common/src/com/netscape/cms/servlet/cert/DoRevoke.java
+++ b/pki/base/common/src/com/netscape/cms/servlet/cert/DoRevoke.java
@@ -24,6 +24,7 @@ import java.util.Date;
 import java.util.Enumeration;
 import java.util.Locale;
 import java.util.Vector;
+import java.math.BigInteger;
 
 import javax.servlet.ServletConfig;
 import javax.servlet.ServletException;
@@ -195,20 +196,20 @@ public class DoRevoke extends CMSServlet {
         try {
             if (req.getParameter("revocationReason") != null) {
                 reason = Integer.parseInt(req.getParameter(
-                                "revocationReason"));
+                        "revocationReason"));
             }
             if (req.getParameter("totalRecordCount") != null) {
                 totalRecordCount = Integer.parseInt(req.getParameter(
-                                "totalRecordCount"));
+                        "totalRecordCount"));
             }
             if (req.getParameter("verifiedRecordCount") != null) {
                 verifiedRecordCount = Integer.parseInt(
-                            req.getParameter(
-                                    "verifiedRecordCount"));
+                        req.getParameter(
+                                "verifiedRecordCount"));
             }
             if (req.getParameter("invalidityDate") != null) {
                 long l = Long.parseLong(req.getParameter(
-                            "invalidityDate"));
+                        "invalidityDate"));
 
                 if (l > 0) {
                     invalidityDate = new Date(l);
@@ -229,7 +230,7 @@ public class DoRevoke extends CMSServlet {
                         user = (IUser) mUL.locateUser(new Certificates(certChain));
                     } catch (Exception e) {
                         CMS.debug("DoRevoke:  Failed to map certificate '" +
-                                   cert2.getSubjectDN().getName() + "' to user.");
+                                cert2.getSubjectDN().getName() + "' to user.");
                     }
                     if (mUG.isMemberOf(user, "Subsystem Group")) {
                         skipNonceVerification = true;
@@ -272,7 +273,7 @@ public class DoRevoke extends CMSServlet {
 
             try {
                 authzToken = authorize(mAclMethod, authToken,
-                            mAuthzResourceName, "revoke");
+                        mAuthzResourceName, "revoke");
             } catch (EAuthzAccessDenied e) {
                 log(ILogger.LL_FAILURE,
                         CMS.getLogMessage("ADMIN_SRVLT_AUTH_FAILURE", e.toString()));
@@ -495,12 +496,12 @@ public class DoRevoke extends CMSServlet {
 
                             // store a message in the signed audit log file
                             auditMessage = CMS.getLogMessage(
-                                        LOGGING_SIGNED_AUDIT_CERT_STATUS_CHANGE_REQUEST,
-                                        auditSubjectID,
-                                        ILogger.FAILURE,
-                                        auditRequesterID,
-                                        auditSerialNumber,
-                                        auditRequestType);
+                                    LOGGING_SIGNED_AUDIT_CERT_STATUS_CHANGE_REQUEST,
+                                    auditSubjectID,
+                                    ILogger.FAILURE,
+                                    auditRequesterID,
+                                    auditSerialNumber,
+                                    auditRequestType);
 
                             audit(auditMessage);
 
@@ -534,8 +535,8 @@ public class DoRevoke extends CMSServlet {
                 Vector serialNumbers = new Vector();
 
                 if (revokeAll != null && revokeAll.length() > 0) {
-                    for (int i = revokeAll.indexOf('='); i < revokeAll.length() && i > -1; 
-                            i = revokeAll.indexOf('=', i)) {
+                    for (int i = revokeAll.indexOf('='); i < revokeAll.length() && i > -1; i = revokeAll
+                            .indexOf('=', i)) {
                         if (i > -1) {
                             i++;
                             while (i < revokeAll.length() && revokeAll.charAt(i) == ' ') {
@@ -597,12 +598,12 @@ public class DoRevoke extends CMSServlet {
 
                         // store a message in the signed audit log file
                         auditMessage = CMS.getLogMessage(
-                                    LOGGING_SIGNED_AUDIT_CERT_STATUS_CHANGE_REQUEST,
-                                    auditSubjectID,
-                                    ILogger.FAILURE,
-                                    auditRequesterID,
-                                    auditSerialNumber,
-                                    auditRequestType);
+                                LOGGING_SIGNED_AUDIT_CERT_STATUS_CHANGE_REQUEST,
+                                auditSubjectID,
+                                ILogger.FAILURE,
+                                auditRequesterID,
+                                auditSerialNumber,
+                                auditRequestType);
 
                         audit(auditMessage);
 
@@ -638,12 +639,12 @@ public class DoRevoke extends CMSServlet {
 
                 // store a message in the signed audit log file
                 auditMessage = CMS.getLogMessage(
-                            LOGGING_SIGNED_AUDIT_CERT_STATUS_CHANGE_REQUEST,
-                            auditSubjectID,
-                            ILogger.FAILURE,
-                            auditRequesterID,
-                            auditSerialNumber,
-                            auditRequestType);
+                        LOGGING_SIGNED_AUDIT_CERT_STATUS_CHANGE_REQUEST,
+                        auditSubjectID,
+                        ILogger.FAILURE,
+                        auditRequesterID,
+                        auditSerialNumber,
+                        auditRequestType);
 
                 audit(auditMessage);
 
@@ -666,12 +667,12 @@ public class DoRevoke extends CMSServlet {
 
             // store a message in the signed audit log file
             auditMessage = CMS.getLogMessage(
-                        LOGGING_SIGNED_AUDIT_CERT_STATUS_CHANGE_REQUEST,
-                        auditSubjectID,
-                        ILogger.SUCCESS,
-                        auditRequesterID,
-                        auditSerialNumber,
-                        auditRequestType);
+                    LOGGING_SIGNED_AUDIT_CERT_STATUS_CHANGE_REQUEST,
+                    auditSubjectID,
+                    ILogger.SUCCESS,
+                    auditRequesterID,
+                    auditSerialNumber,
+                    auditRequestType);
 
             audit(auditMessage);
 
@@ -748,20 +749,20 @@ public class DoRevoke extends CMSServlet {
                     // if and only if "auditApprovalStatus" is
                     // "complete", "revoked", or "canceled"
                     if ((auditApprovalStatus.equals(
-                                RequestStatus.COMPLETE_STRING)) ||
+                            RequestStatus.COMPLETE_STRING)) ||
                             (auditApprovalStatus.equals(
                                     RequestStatus.REJECTED_STRING)) ||
                             (auditApprovalStatus.equals(
                                     RequestStatus.CANCELED_STRING))) {
                         auditMessage = CMS.getLogMessage(
-                                    LOGGING_SIGNED_AUDIT_CERT_STATUS_CHANGE_REQUEST_PROCESSED,
-                                    auditSubjectID,
-                                    ILogger.FAILURE,
-                                    auditRequesterID,
-                                    auditSerialNumber,
-                                    auditRequestType,
-                                    auditReasonNum,
-                                    auditApprovalStatus);
+                                LOGGING_SIGNED_AUDIT_CERT_STATUS_CHANGE_REQUEST_PROCESSED,
+                                auditSubjectID,
+                                ILogger.FAILURE,
+                                auditRequesterID,
+                                auditSerialNumber,
+                                auditRequestType,
+                                auditReasonNum,
+                                auditApprovalStatus);
 
                         audit(auditMessage);
                     }
@@ -968,14 +969,14 @@ public class DoRevoke extends CMSServlet {
                     || (auditApprovalStatus.equals(RequestStatus.REJECTED_STRING))
                     || (auditApprovalStatus.equals(RequestStatus.CANCELED_STRING))) {
                 auditMessage = CMS.getLogMessage(
-                            LOGGING_SIGNED_AUDIT_CERT_STATUS_CHANGE_REQUEST_PROCESSED,
-                            auditSubjectID,
-                            ILogger.SUCCESS,
-                            auditRequesterID,
-                            auditSerialNumber,
-                            auditRequestType,
-                            auditReasonNum,
-                            auditApprovalStatus);
+                        LOGGING_SIGNED_AUDIT_CERT_STATUS_CHANGE_REQUEST_PROCESSED,
+                        auditSubjectID,
+                        ILogger.SUCCESS,
+                        auditRequesterID,
+                        auditSerialNumber,
+                        auditRequestType,
+                        auditReasonNum,
+                        auditApprovalStatus);
 
                 audit(auditMessage);
             }
@@ -985,12 +986,12 @@ public class DoRevoke extends CMSServlet {
                 // store a "CERT_STATUS_CHANGE_REQUEST" failure
                 // message in the signed audit log file
                 auditMessage = CMS.getLogMessage(
-                            LOGGING_SIGNED_AUDIT_CERT_STATUS_CHANGE_REQUEST,
-                            auditSubjectID,
-                            ILogger.FAILURE,
-                            auditRequesterID,
-                            auditSerialNumber,
-                            auditRequestType);
+                        LOGGING_SIGNED_AUDIT_CERT_STATUS_CHANGE_REQUEST,
+                        auditSubjectID,
+                        ILogger.FAILURE,
+                        auditRequesterID,
+                        auditSerialNumber,
+                        auditRequestType);
 
                 audit(auditMessage);
             } else {
@@ -999,20 +1000,20 @@ public class DoRevoke extends CMSServlet {
                 // if and only if "auditApprovalStatus" is
                 // "complete", "revoked", or "canceled"
                 if ((auditApprovalStatus.equals(
-                            RequestStatus.COMPLETE_STRING)) ||
+                        RequestStatus.COMPLETE_STRING)) ||
                         (auditApprovalStatus.equals(
                                 RequestStatus.REJECTED_STRING)) ||
                         (auditApprovalStatus.equals(
                                 RequestStatus.CANCELED_STRING))) {
                     auditMessage = CMS.getLogMessage(
-                                LOGGING_SIGNED_AUDIT_CERT_STATUS_CHANGE_REQUEST_PROCESSED,
-                                auditSubjectID,
-                                ILogger.FAILURE,
-                                auditRequesterID,
-                                auditSerialNumber,
-                                auditRequestType,
-                                auditReasonNum,
-                                auditApprovalStatus);
+                            LOGGING_SIGNED_AUDIT_CERT_STATUS_CHANGE_REQUEST_PROCESSED,
+                            auditSubjectID,
+                            ILogger.FAILURE,
+                            auditRequesterID,
+                            auditSerialNumber,
+                            auditRequestType,
+                            auditReasonNum,
+                            auditApprovalStatus);
 
                     audit(auditMessage);
                 }
@@ -1026,12 +1027,12 @@ public class DoRevoke extends CMSServlet {
                 // store a "CERT_STATUS_CHANGE_REQUEST" failure
                 // message in the signed audit log file
                 auditMessage = CMS.getLogMessage(
-                            LOGGING_SIGNED_AUDIT_CERT_STATUS_CHANGE_REQUEST,
-                            auditSubjectID,
-                            ILogger.FAILURE,
-                            auditRequesterID,
-                            auditSerialNumber,
-                            auditRequestType);
+                        LOGGING_SIGNED_AUDIT_CERT_STATUS_CHANGE_REQUEST,
+                        auditSubjectID,
+                        ILogger.FAILURE,
+                        auditRequesterID,
+                        auditSerialNumber,
+                        auditRequestType);
 
                 audit(auditMessage);
             } else {
@@ -1040,20 +1041,20 @@ public class DoRevoke extends CMSServlet {
                 // if and only if "auditApprovalStatus" is
                 // "complete", "revoked", or "canceled"
                 if ((auditApprovalStatus.equals(
-                            RequestStatus.COMPLETE_STRING)) ||
+                        RequestStatus.COMPLETE_STRING)) ||
                         (auditApprovalStatus.equals(
                                 RequestStatus.REJECTED_STRING)) ||
                         (auditApprovalStatus.equals(
                                 RequestStatus.CANCELED_STRING))) {
                     auditMessage = CMS.getLogMessage(
-                                LOGGING_SIGNED_AUDIT_CERT_STATUS_CHANGE_REQUEST_PROCESSED,
-                                auditSubjectID,
-                                ILogger.FAILURE,
-                                auditRequesterID,
-                                auditSerialNumber,
-                                auditRequestType,
-                                auditReasonNum,
-                                auditApprovalStatus);
+                            LOGGING_SIGNED_AUDIT_CERT_STATUS_CHANGE_REQUEST_PROCESSED,
+                            auditSubjectID,
+                            ILogger.FAILURE,
+                            auditRequesterID,
+                            auditSerialNumber,
+                            auditRequestType,
+                            auditReasonNum,
+                            auditApprovalStatus);
 
                     audit(auditMessage);
                 }
@@ -1068,12 +1069,12 @@ public class DoRevoke extends CMSServlet {
                 // store a "CERT_STATUS_CHANGE_REQUEST" failure
                 // message in the signed audit log file
                 auditMessage = CMS.getLogMessage(
-                            LOGGING_SIGNED_AUDIT_CERT_STATUS_CHANGE_REQUEST,
-                            auditSubjectID,
-                            ILogger.FAILURE,
-                            auditRequesterID,
-                            auditSerialNumber,
-                            auditRequestType);
+                        LOGGING_SIGNED_AUDIT_CERT_STATUS_CHANGE_REQUEST,
+                        auditSubjectID,
+                        ILogger.FAILURE,
+                        auditRequesterID,
+                        auditSerialNumber,
+                        auditRequestType);
 
                 audit(auditMessage);
             } else {
@@ -1082,20 +1083,20 @@ public class DoRevoke extends CMSServlet {
                 // if and only if "auditApprovalStatus" is
                 // "complete", "revoked", or "canceled"
                 if ((auditApprovalStatus.equals(
-                            RequestStatus.COMPLETE_STRING)) ||
+                        RequestStatus.COMPLETE_STRING)) ||
                         (auditApprovalStatus.equals(
                                 RequestStatus.REJECTED_STRING)) ||
                         (auditApprovalStatus.equals(
                                 RequestStatus.CANCELED_STRING))) {
                     auditMessage = CMS.getLogMessage(
-                                LOGGING_SIGNED_AUDIT_CERT_STATUS_CHANGE_REQUEST_PROCESSED,
-                                auditSubjectID,
-                                ILogger.FAILURE,
-                                auditRequesterID,
-                                auditSerialNumber,
-                                auditRequestType,
-                                auditReasonNum,
-                                auditApprovalStatus);
+                            LOGGING_SIGNED_AUDIT_CERT_STATUS_CHANGE_REQUEST_PROCESSED,
+                            auditSubjectID,
+                            ILogger.FAILURE,
+                            auditRequesterID,
+                            auditSerialNumber,
+                            auditRequestType,
+                            auditReasonNum,
+                            auditApprovalStatus);
 
                     audit(auditMessage);
                 }
@@ -1161,31 +1162,28 @@ public class DoRevoke extends CMSServlet {
 
             // find out if the value is hex or decimal
 
-            int value = -1;
+            BigInteger value = BigInteger.ONE.negate();
 
             //try int 
             try {
-                value = Integer.parseInt(serialNumber, 10);
+                value = new BigInteger(serialNumber, 10);
             } catch (NumberFormatException e) {
             }
 
             //try hex
-            if (value == -1) {
+            if (value.compareTo(BigInteger.ONE.negate()) == 0) {
                 try {
-                    value = Integer.parseInt(serialNumber, 16);
-
+                    value = new BigInteger(serialNumber, 16);
                 } catch (NumberFormatException e) {
                 }
             }
             // give up if it isn't hex or dec
-            if (value == -1) {
+            if (value.compareTo(BigInteger.ONE.negate()) == 0) {
                 throw new NumberFormatException();
             }
 
             // convert it to hexadecimal
-            serialNumber = "0x"
-                    + Integer.toHexString(
-                            value);
+            serialNumber = "0x" + value.toString(16);
         } else {
             serialNumber = ILogger.SIGNED_AUDIT_EMPTY_VALUE;
         }
diff --git a/pki/base/common/src/com/netscape/cms/servlet/cert/DoRevokeTPS.java b/pki/base/common/src/com/netscape/cms/servlet/cert/DoRevokeTPS.java
index f17e576d657d824f2eadae33c29e67eaee88127a..4b118d1af60fb1450b7509009c7bc71f1db766dc 100644
--- a/pki/base/common/src/com/netscape/cms/servlet/cert/DoRevokeTPS.java
+++ b/pki/base/common/src/com/netscape/cms/servlet/cert/DoRevokeTPS.java
@@ -23,6 +23,7 @@ import java.util.Date;
 import java.util.Enumeration;
 import java.util.Locale;
 import java.util.Vector;
+import java.math.BigInteger;
 
 import javax.servlet.ServletConfig;
 import javax.servlet.ServletException;
@@ -186,15 +187,15 @@ public class DoRevokeTPS extends CMSServlet {
         try {
             if (req.getParameter("revocationReason") != null) {
                 reason = Integer.parseInt(req.getParameter(
-                                "revocationReason"));
+                        "revocationReason"));
             }
             if (req.getParameter("totalRecordCount") != null) {
                 totalRecordCount = Integer.parseInt(req.getParameter(
-                                "totalRecordCount"));
+                        "totalRecordCount"));
             }
             if (req.getParameter("invalidityDate") != null) {
                 long l = Long.parseLong(req.getParameter(
-                            "invalidityDate"));
+                        "invalidityDate"));
 
                 if (l > 0) {
                     invalidityDate = new Date(l);
@@ -212,7 +213,7 @@ public class DoRevokeTPS extends CMSServlet {
 
             try {
                 authzToken = authorize(mAclMethod, authToken,
-                            mAuthzResourceName, "revoke");
+                        mAuthzResourceName, "revoke");
             } catch (EAuthzAccessDenied e) {
                 log(ILogger.LL_FAILURE,
                         CMS.getLogMessage("ADMIN_SRVLT_AUTH_FAILURE", e.toString()));
@@ -446,12 +447,12 @@ public class DoRevokeTPS extends CMSServlet {
 
                 // store a message in the signed audit log file
                 auditMessage = CMS.getLogMessage(
-                            LOGGING_SIGNED_AUDIT_CERT_STATUS_CHANGE_REQUEST,
-                            auditSubjectID,
-                            ILogger.FAILURE,
-                            auditRequesterID,
-                            auditSerialNumber,
-                            auditRequestType);
+                        LOGGING_SIGNED_AUDIT_CERT_STATUS_CHANGE_REQUEST,
+                        auditSubjectID,
+                        ILogger.FAILURE,
+                        auditRequesterID,
+                        auditSerialNumber,
+                        auditRequestType);
 
                 audit(auditMessage);
 
@@ -471,12 +472,12 @@ public class DoRevokeTPS extends CMSServlet {
 
             // store a message in the signed audit log file
             auditMessage = CMS.getLogMessage(
-                        LOGGING_SIGNED_AUDIT_CERT_STATUS_CHANGE_REQUEST,
-                        auditSubjectID,
-                        ILogger.SUCCESS,
-                        auditRequesterID,
-                        auditSerialNumber,
-                        auditRequestType);
+                    LOGGING_SIGNED_AUDIT_CERT_STATUS_CHANGE_REQUEST,
+                    auditSubjectID,
+                    ILogger.SUCCESS,
+                    auditRequesterID,
+                    auditSerialNumber,
+                    auditRequestType);
 
             audit(auditMessage);
 
@@ -554,20 +555,20 @@ public class DoRevokeTPS extends CMSServlet {
                     // if and only if "auditApprovalStatus" is
                     // "complete", "revoked", or "canceled"
                     if ((auditApprovalStatus.equals(
-                                RequestStatus.COMPLETE_STRING)) ||
+                            RequestStatus.COMPLETE_STRING)) ||
                             (auditApprovalStatus.equals(
                                     RequestStatus.REJECTED_STRING)) ||
                             (auditApprovalStatus.equals(
                                     RequestStatus.CANCELED_STRING))) {
                         auditMessage = CMS.getLogMessage(
-                                    LOGGING_SIGNED_AUDIT_CERT_STATUS_CHANGE_REQUEST_PROCESSED,
-                                    auditSubjectID,
-                                    ILogger.FAILURE,
-                                    auditRequesterID,
-                                    auditSerialNumber,
-                                    auditRequestType,
-                                    auditReasonNum,
-                                    auditApprovalStatus);
+                                LOGGING_SIGNED_AUDIT_CERT_STATUS_CHANGE_REQUEST_PROCESSED,
+                                auditSubjectID,
+                                ILogger.FAILURE,
+                                auditRequesterID,
+                                auditSerialNumber,
+                                auditRequestType,
+                                auditReasonNum,
+                                auditApprovalStatus);
 
                         audit(auditMessage);
                     }
@@ -765,14 +766,14 @@ public class DoRevokeTPS extends CMSServlet {
                     || (auditApprovalStatus.equals(RequestStatus.REJECTED_STRING))
                     || (auditApprovalStatus.equals(RequestStatus.CANCELED_STRING))) {
                 auditMessage = CMS.getLogMessage(
-                            LOGGING_SIGNED_AUDIT_CERT_STATUS_CHANGE_REQUEST_PROCESSED,
-                            auditSubjectID,
-                            ILogger.SUCCESS,
-                            auditRequesterID,
-                            auditSerialNumber,
-                            auditRequestType,
-                            auditReasonNum,
-                            auditApprovalStatus);
+                        LOGGING_SIGNED_AUDIT_CERT_STATUS_CHANGE_REQUEST_PROCESSED,
+                        auditSubjectID,
+                        ILogger.SUCCESS,
+                        auditRequesterID,
+                        auditSerialNumber,
+                        auditRequestType,
+                        auditReasonNum,
+                        auditApprovalStatus);
 
                 audit(auditMessage);
             }
@@ -783,12 +784,12 @@ public class DoRevokeTPS extends CMSServlet {
                 // store a "CERT_STATUS_CHANGE_REQUEST" failure
                 // message in the signed audit log file
                 auditMessage = CMS.getLogMessage(
-                            LOGGING_SIGNED_AUDIT_CERT_STATUS_CHANGE_REQUEST,
-                            auditSubjectID,
-                            ILogger.FAILURE,
-                            auditRequesterID,
-                            auditSerialNumber,
-                            auditRequestType);
+                        LOGGING_SIGNED_AUDIT_CERT_STATUS_CHANGE_REQUEST,
+                        auditSubjectID,
+                        ILogger.FAILURE,
+                        auditRequesterID,
+                        auditSerialNumber,
+                        auditRequestType);
 
                 audit(auditMessage);
             } else {
@@ -797,20 +798,20 @@ public class DoRevokeTPS extends CMSServlet {
                 // if and only if "auditApprovalStatus" is
                 // "complete", "revoked", or "canceled"
                 if ((auditApprovalStatus.equals(
-                            RequestStatus.COMPLETE_STRING)) ||
+                        RequestStatus.COMPLETE_STRING)) ||
                         (auditApprovalStatus.equals(
                                 RequestStatus.REJECTED_STRING)) ||
                         (auditApprovalStatus.equals(
                                 RequestStatus.CANCELED_STRING))) {
                     auditMessage = CMS.getLogMessage(
-                                LOGGING_SIGNED_AUDIT_CERT_STATUS_CHANGE_REQUEST_PROCESSED,
-                                auditSubjectID,
-                                ILogger.FAILURE,
-                                auditRequesterID,
-                                auditSerialNumber,
-                                auditRequestType,
-                                auditReasonNum,
-                                auditApprovalStatus);
+                            LOGGING_SIGNED_AUDIT_CERT_STATUS_CHANGE_REQUEST_PROCESSED,
+                            auditSubjectID,
+                            ILogger.FAILURE,
+                            auditRequesterID,
+                            auditSerialNumber,
+                            auditRequestType,
+                            auditReasonNum,
+                            auditApprovalStatus);
 
                     audit(auditMessage);
                 }
@@ -825,12 +826,12 @@ public class DoRevokeTPS extends CMSServlet {
                 // store a "CERT_STATUS_CHANGE_REQUEST" failure
                 // message in the signed audit log file
                 auditMessage = CMS.getLogMessage(
-                            LOGGING_SIGNED_AUDIT_CERT_STATUS_CHANGE_REQUEST,
-                            auditSubjectID,
-                            ILogger.FAILURE,
-                            auditRequesterID,
-                            auditSerialNumber,
-                            auditRequestType);
+                        LOGGING_SIGNED_AUDIT_CERT_STATUS_CHANGE_REQUEST,
+                        auditSubjectID,
+                        ILogger.FAILURE,
+                        auditRequesterID,
+                        auditSerialNumber,
+                        auditRequestType);
 
                 audit(auditMessage);
             } else {
@@ -839,20 +840,20 @@ public class DoRevokeTPS extends CMSServlet {
                 // if and only if "auditApprovalStatus" is
                 // "complete", "revoked", or "canceled"
                 if ((auditApprovalStatus.equals(
-                            RequestStatus.COMPLETE_STRING)) ||
+                        RequestStatus.COMPLETE_STRING)) ||
                         (auditApprovalStatus.equals(
                                 RequestStatus.REJECTED_STRING)) ||
                         (auditApprovalStatus.equals(
                                 RequestStatus.CANCELED_STRING))) {
                     auditMessage = CMS.getLogMessage(
-                                LOGGING_SIGNED_AUDIT_CERT_STATUS_CHANGE_REQUEST_PROCESSED,
-                                auditSubjectID,
-                                ILogger.FAILURE,
-                                auditRequesterID,
-                                auditSerialNumber,
-                                auditRequestType,
-                                auditReasonNum,
-                                auditApprovalStatus);
+                            LOGGING_SIGNED_AUDIT_CERT_STATUS_CHANGE_REQUEST_PROCESSED,
+                            auditSubjectID,
+                            ILogger.FAILURE,
+                            auditRequesterID,
+                            auditSerialNumber,
+                            auditRequestType,
+                            auditReasonNum,
+                            auditApprovalStatus);
 
                     audit(auditMessage);
                 }
@@ -917,9 +918,7 @@ public class DoRevokeTPS extends CMSServlet {
             serialNumber = eeSerialNumber.trim();
 
             // convert it to hexadecimal
-            serialNumber = "0x"
-                    + Integer.toHexString(
-                            Integer.valueOf(serialNumber).intValue());
+            serialNumber = "0x" + (new BigInteger(serialNumber)).toString(16);
         } else {
             serialNumber = ILogger.SIGNED_AUDIT_EMPTY_VALUE;
         }
diff --git a/pki/base/common/src/com/netscape/cms/servlet/cert/DoUnrevoke.java b/pki/base/common/src/com/netscape/cms/servlet/cert/DoUnrevoke.java
index 656d36f858441a189b44f2e8d39d395393a2e8ba..aadbffad5da7f74dd7940c36ae551e99d38728c8 100644
--- a/pki/base/common/src/com/netscape/cms/servlet/cert/DoUnrevoke.java
+++ b/pki/base/common/src/com/netscape/cms/servlet/cert/DoUnrevoke.java
@@ -164,7 +164,7 @@ public class DoUnrevoke extends CMSServlet {
 
             try {
                 authzToken = authorize(mAclMethod, authToken,
-                            mAuthzResourceName, "unrevoke");
+                        mAuthzResourceName, "unrevoke");
             } catch (EAuthzAccessDenied e) {
                 log(ILogger.LL_FAILURE,
                         CMS.getLogMessage("ADMIN_SRVLT_AUTH_FAILURE", e.toString()));
@@ -270,12 +270,12 @@ public class DoUnrevoke extends CMSServlet {
 
             // store a message in the signed audit log file
             auditMessage = CMS.getLogMessage(
-                        LOGGING_SIGNED_AUDIT_CERT_STATUS_CHANGE_REQUEST,
-                        auditSubjectID,
-                        ILogger.SUCCESS,
-                        auditRequesterID,
-                        auditSerialNumber,
-                        auditRequestType);
+                    LOGGING_SIGNED_AUDIT_CERT_STATUS_CHANGE_REQUEST,
+                    auditSubjectID,
+                    ILogger.SUCCESS,
+                    auditRequesterID,
+                    auditSerialNumber,
+                    auditRequestType);
 
             audit(auditMessage);
 
@@ -519,14 +519,14 @@ public class DoUnrevoke extends CMSServlet {
                     || (auditApprovalStatus.equals(RequestStatus.REJECTED_STRING))
                     || (auditApprovalStatus.equals(RequestStatus.CANCELED_STRING))) {
                 auditMessage = CMS.getLogMessage(
-                            LOGGING_SIGNED_AUDIT_CERT_STATUS_CHANGE_REQUEST_PROCESSED,
-                            auditSubjectID,
-                            ILogger.SUCCESS,
-                            auditRequesterID,
-                            auditSerialNumber,
-                            auditRequestType,
-                            auditReasonNum,
-                            auditApprovalStatus);
+                        LOGGING_SIGNED_AUDIT_CERT_STATUS_CHANGE_REQUEST_PROCESSED,
+                        auditSubjectID,
+                        ILogger.SUCCESS,
+                        auditRequesterID,
+                        auditSerialNumber,
+                        auditRequestType,
+                        auditReasonNum,
+                        auditApprovalStatus);
 
                 audit(auditMessage);
             }
@@ -536,12 +536,12 @@ public class DoUnrevoke extends CMSServlet {
                 // store a "CERT_STATUS_CHANGE_REQUEST" failure
                 // message in the signed audit log file
                 auditMessage = CMS.getLogMessage(
-                            LOGGING_SIGNED_AUDIT_CERT_STATUS_CHANGE_REQUEST,
-                            auditSubjectID,
-                            ILogger.FAILURE,
-                            auditRequesterID,
-                            auditSerialNumber,
-                            auditRequestType);
+                        LOGGING_SIGNED_AUDIT_CERT_STATUS_CHANGE_REQUEST,
+                        auditSubjectID,
+                        ILogger.FAILURE,
+                        auditRequesterID,
+                        auditSerialNumber,
+                        auditRequestType);
 
                 audit(auditMessage);
             } else {
@@ -550,20 +550,20 @@ public class DoUnrevoke extends CMSServlet {
                 // if and only if "auditApprovalStatus" is
                 // "complete", "revoked", or "canceled"
                 if ((auditApprovalStatus.equals(
-                            RequestStatus.COMPLETE_STRING)) ||
+                        RequestStatus.COMPLETE_STRING)) ||
                         (auditApprovalStatus.equals(
                                 RequestStatus.REJECTED_STRING)) ||
                         (auditApprovalStatus.equals(
                                 RequestStatus.CANCELED_STRING))) {
                     auditMessage = CMS.getLogMessage(
-                                LOGGING_SIGNED_AUDIT_CERT_STATUS_CHANGE_REQUEST_PROCESSED,
-                                auditSubjectID,
-                                ILogger.FAILURE,
-                                auditRequesterID,
-                                auditSerialNumber,
-                                auditRequestType,
-                                auditReasonNum,
-                                auditApprovalStatus);
+                            LOGGING_SIGNED_AUDIT_CERT_STATUS_CHANGE_REQUEST_PROCESSED,
+                            auditSubjectID,
+                            ILogger.FAILURE,
+                            auditRequesterID,
+                            auditSerialNumber,
+                            auditRequestType,
+                            auditReasonNum,
+                            auditApprovalStatus);
 
                     audit(auditMessage);
                 }
@@ -662,9 +662,7 @@ public class DoUnrevoke extends CMSServlet {
             serialNumber = eeSerialNumber.trim();
 
             // convert it to hexadecimal
-            serialNumber = "0x"
-                    + Integer.toHexString(
-                            Integer.valueOf(serialNumber).intValue());
+            serialNumber = "0x" + (new BigInteger(serialNumber)).toString(16);
         } else {
             serialNumber = ILogger.SIGNED_AUDIT_EMPTY_VALUE;
         }
diff --git a/pki/base/common/src/com/netscape/cms/servlet/cert/DoUnrevokeTPS.java b/pki/base/common/src/com/netscape/cms/servlet/cert/DoUnrevokeTPS.java
index 3af743a95c927c9894216b7e0e5e57e726031020..7310d2e6c38a02958b8122514b9227101991abb3 100644
--- a/pki/base/common/src/com/netscape/cms/servlet/cert/DoUnrevokeTPS.java
+++ b/pki/base/common/src/com/netscape/cms/servlet/cert/DoUnrevokeTPS.java
@@ -162,7 +162,7 @@ public class DoUnrevokeTPS extends CMSServlet {
 
             try {
                 authzToken = authorize(mAclMethod, authToken,
-                            mAuthzResourceName, "unrevoke");
+                        mAuthzResourceName, "unrevoke");
             } catch (EAuthzAccessDenied e) {
                 log(ILogger.LL_FAILURE,
                         CMS.getLogMessage("ADMIN_SRVLT_AUTH_FAILURE", e.toString()));
@@ -274,12 +274,12 @@ public class DoUnrevokeTPS extends CMSServlet {
 
             // store a message in the signed audit log file
             auditMessage = CMS.getLogMessage(
-                        LOGGING_SIGNED_AUDIT_CERT_STATUS_CHANGE_REQUEST,
-                        auditSubjectID,
-                        ILogger.SUCCESS,
-                        auditRequesterID,
-                        auditSerialNumber,
-                        auditRequestType);
+                    LOGGING_SIGNED_AUDIT_CERT_STATUS_CHANGE_REQUEST,
+                    auditSubjectID,
+                    ILogger.SUCCESS,
+                    auditRequesterID,
+                    auditSerialNumber,
+                    auditRequestType);
 
             audit(auditMessage);
 
@@ -472,14 +472,14 @@ public class DoUnrevokeTPS extends CMSServlet {
                     || (auditApprovalStatus.equals(RequestStatus.REJECTED_STRING))
                     || (auditApprovalStatus.equals(RequestStatus.CANCELED_STRING))) {
                 auditMessage = CMS.getLogMessage(
-                            LOGGING_SIGNED_AUDIT_CERT_STATUS_CHANGE_REQUEST_PROCESSED,
-                            auditSubjectID,
-                            ILogger.SUCCESS,
-                            auditRequesterID,
-                            auditSerialNumber,
-                            auditRequestType,
-                            auditReasonNum,
-                            auditApprovalStatus);
+                        LOGGING_SIGNED_AUDIT_CERT_STATUS_CHANGE_REQUEST_PROCESSED,
+                        auditSubjectID,
+                        ILogger.SUCCESS,
+                        auditRequesterID,
+                        auditSerialNumber,
+                        auditRequestType,
+                        auditReasonNum,
+                        auditApprovalStatus);
 
                 audit(auditMessage);
             }
@@ -489,12 +489,12 @@ public class DoUnrevokeTPS extends CMSServlet {
                 // store a "CERT_STATUS_CHANGE_REQUEST" failure
                 // message in the signed audit log file
                 auditMessage = CMS.getLogMessage(
-                            LOGGING_SIGNED_AUDIT_CERT_STATUS_CHANGE_REQUEST,
-                            auditSubjectID,
-                            ILogger.FAILURE,
-                            auditRequesterID,
-                            auditSerialNumber,
-                            auditRequestType);
+                        LOGGING_SIGNED_AUDIT_CERT_STATUS_CHANGE_REQUEST,
+                        auditSubjectID,
+                        ILogger.FAILURE,
+                        auditRequesterID,
+                        auditSerialNumber,
+                        auditRequestType);
 
                 audit(auditMessage);
             } else {
@@ -503,20 +503,20 @@ public class DoUnrevokeTPS extends CMSServlet {
                 // if and only if "auditApprovalStatus" is
                 // "complete", "revoked", or "canceled"
                 if ((auditApprovalStatus.equals(
-                            RequestStatus.COMPLETE_STRING)) ||
+                        RequestStatus.COMPLETE_STRING)) ||
                         (auditApprovalStatus.equals(
                                 RequestStatus.REJECTED_STRING)) ||
                         (auditApprovalStatus.equals(
                                 RequestStatus.CANCELED_STRING))) {
                     auditMessage = CMS.getLogMessage(
-                                LOGGING_SIGNED_AUDIT_CERT_STATUS_CHANGE_REQUEST_PROCESSED,
-                                auditSubjectID,
-                                ILogger.FAILURE,
-                                auditRequesterID,
-                                auditSerialNumber,
-                                auditRequestType,
-                                auditReasonNum,
-                                auditApprovalStatus);
+                            LOGGING_SIGNED_AUDIT_CERT_STATUS_CHANGE_REQUEST_PROCESSED,
+                            auditSubjectID,
+                            ILogger.FAILURE,
+                            auditRequesterID,
+                            auditSerialNumber,
+                            auditRequestType,
+                            auditReasonNum,
+                            auditApprovalStatus);
 
                     audit(auditMessage);
                 }
@@ -615,9 +615,7 @@ public class DoUnrevokeTPS extends CMSServlet {
             serialNumber = eeSerialNumber.trim();
 
             // convert it to hexadecimal
-            serialNumber = "0x"
-                    + Integer.toHexString(
-                            Integer.valueOf(serialNumber).intValue());
+            serialNumber = "0x" + (new BigInteger(serialNumber)).toString(16);
         } else {
             serialNumber = ILogger.SIGNED_AUDIT_EMPTY_VALUE;
         }
diff --git a/pki/base/common/src/com/netscape/cms/servlet/cert/GetCertFromRequest.java b/pki/base/common/src/com/netscape/cms/servlet/cert/GetCertFromRequest.java
index 67481e7df5a356e98ab01bc1efda6d93e5635b43..c8e3b1dfb708e9b9b7b5782cd87a2102760fb82e 100644
--- a/pki/base/common/src/com/netscape/cms/servlet/cert/GetCertFromRequest.java
+++ b/pki/base/common/src/com/netscape/cms/servlet/cert/GetCertFromRequest.java
@@ -19,6 +19,7 @@ package com.netscape.cms.servlet.cert;
 
 import java.io.IOException;
 import java.util.Locale;
+import java.math.BigInteger;
 
 import javax.servlet.ServletConfig;
 import javax.servlet.ServletException;
@@ -106,7 +107,7 @@ public class GetCertFromRequest extends CMSServlet {
             else
                 defTemplate = "/ca/" + defTemplate;
             mCertFrReqSuccessTemplate = sc.getInitParameter(
-                        PROP_SUCCESS_TEMPLATE);
+                    PROP_SUCCESS_TEMPLATE);
             if (mCertFrReqSuccessTemplate == null)
                 mCertFrReqSuccessTemplate = defTemplate;
             String fillername =
@@ -147,7 +148,7 @@ public class GetCertFromRequest extends CMSServlet {
 
         try {
             authzToken = authorize(mAclMethod, authToken,
-                        mAuthzResourceName, "read");
+                    mAuthzResourceName, "read");
         } catch (EAuthzAccessDenied e) {
             log(ILogger.LL_FAILURE,
                     CMS.getLogMessage("ADMIN_SRVLT_AUTH_FAILURE", e.toString()));
@@ -169,7 +170,7 @@ public class GetCertFromRequest extends CMSServlet {
         }
         // check if request Id is valid.
         try {
-            Integer.parseInt(requestId);
+            new BigInteger(requestId);
         } catch (NumberFormatException e) {
             log(ILogger.LL_FAILURE, CMS.getLogMessage("CMSGW_INVALID_REQ_ID_FORMAT", requestId));
             throw new EBaseException(
@@ -205,8 +206,8 @@ public class GetCertFromRequest extends CMSServlet {
             }
         }
 
-        if (!((r.getRequestType().equals(IRequest.ENROLLMENT_REQUEST)) || 
-                (r.getRequestType().equals(IRequest.RENEWAL_REQUEST)))) {
+        if (!((r.getRequestType().equals(IRequest.ENROLLMENT_REQUEST)) || (r.getRequestType()
+                .equals(IRequest.RENEWAL_REQUEST)))) {
             log(ILogger.LL_FAILURE,
                     CMS.getLogMessage("CMSGW_REQUEST_NOT_ENROLLMENT_1", requestId));
             throw new ECMSGWException(
diff --git a/pki/base/common/src/com/netscape/cms/servlet/key/ConfirmRecoverBySerial.java b/pki/base/common/src/com/netscape/cms/servlet/key/ConfirmRecoverBySerial.java
index d7c3ffaefeaf2dc38baa47f57c71421f0358c4f3..15e73179e94f171cfd14047649ab482d83145727 100644
--- a/pki/base/common/src/com/netscape/cms/servlet/key/ConfirmRecoverBySerial.java
+++ b/pki/base/common/src/com/netscape/cms/servlet/key/ConfirmRecoverBySerial.java
@@ -130,12 +130,11 @@ public class ConfirmRecoverBySerial extends CMSServlet {
         IArgBlock fixed = CMS.createArgBlock();
         CMSTemplateParams argSet = new CMSTemplateParams(header, fixed);
 
-        int seqNum = -1;
+        BigInteger seqNum = BigInteger.ZERO;
 
         try {
             if (req.getParameter(IN_SERIALNO) != null) {
-                seqNum = Integer.parseInt(
-                            req.getParameter(IN_SERIALNO));
+                seqNum = new BigInteger(req.getParameter(IN_SERIALNO));
             }
 
             // make sure this page, which contains password
@@ -167,11 +166,11 @@ public class ConfirmRecoverBySerial extends CMSServlet {
      * Requests for a list of agent passwords.
      */
     private void process(CMSTemplateParams argSet,
-            IArgBlock header, int seq,
+            IArgBlock header, BigInteger seq,
             HttpServletRequest req, HttpServletResponse resp,
             Locale locale) {
         try {
-            header.addIntegerValue(OUT_SERIALNO, seq);
+            header.addBigIntegerValue(OUT_SERIALNO, seq, 10);
             header.addIntegerValue(OUT_M,
                     mRecoveryService.getNoOfRequiredAgents());
             header.addStringValue(OUT_OP,
@@ -179,8 +178,7 @@ public class ConfirmRecoverBySerial extends CMSServlet {
             header.addStringValue(OUT_SERVICE_URL,
                     req.getRequestURI());
 
-            IKeyRecord rec = (IKeyRecord) mKeyDB.readKeyRecord(new BigInteger(
-                        Integer.toString(seq)));
+            IKeyRecord rec = (IKeyRecord) mKeyDB.readKeyRecord(seq);
 
             KeyRecordParser.fillRecordIntoArg(rec, header);
         } catch (EBaseException e) {
diff --git a/pki/base/common/src/com/netscape/cms/servlet/key/DisplayBySerial.java b/pki/base/common/src/com/netscape/cms/servlet/key/DisplayBySerial.java
index a3490d893ac1a01b47d292e1847f323cdda13b5c..a25ab1441f32d2147a91a20a18314823def4d00f 100644
--- a/pki/base/common/src/com/netscape/cms/servlet/key/DisplayBySerial.java
+++ b/pki/base/common/src/com/netscape/cms/servlet/key/DisplayBySerial.java
@@ -114,7 +114,7 @@ public class DisplayBySerial extends CMSServlet {
 
         try {
             authzToken = authorize(mAclMethod, authToken,
-                        mAuthzResourceName, "read");
+                    mAuthzResourceName, "read");
         } catch (EAuthzAccessDenied e) {
             log(ILogger.LL_FAILURE,
                     CMS.getLogMessage("ADMIN_SRVLT_AUTH_FAILURE", e.toString()));
@@ -147,12 +147,11 @@ public class DisplayBySerial extends CMSServlet {
         IArgBlock header = CMS.createArgBlock();
         IArgBlock fixed = CMS.createArgBlock();
         CMSTemplateParams argSet = new CMSTemplateParams(header, fixed);
-        int seqNum = -1;
+        BigInteger seqNum = BigInteger.ZERO;
 
         try {
             if (req.getParameter(IN_SERIALNO) != null) {
-                seqNum = Integer.parseInt(
-                            req.getParameter(IN_SERIALNO));
+                seqNum = new BigInteger(req.getParameter(IN_SERIALNO));
             }
             process(argSet, header, seqNum, req, resp, locale[0]);
         } catch (NumberFormatException e) {
@@ -177,7 +176,7 @@ public class DisplayBySerial extends CMSServlet {
      * Display information about a particular key.
      */
     private void process(CMSTemplateParams argSet,
-            IArgBlock header, int seq,
+            IArgBlock header, BigInteger seq,
             HttpServletRequest req, HttpServletResponse resp,
             Locale locale) {
         try {
@@ -185,8 +184,7 @@ public class DisplayBySerial extends CMSServlet {
                     req.getParameter(OUT_OP));
             header.addStringValue(OUT_SERVICE_URL,
                     req.getRequestURI());
-            IKeyRecord rec = (IKeyRecord) mKeyDB.readKeyRecord(new
-                    BigInteger(Integer.toString(seq)));
+            IKeyRecord rec = (IKeyRecord) mKeyDB.readKeyRecord(seq);
 
             KeyRecordParser.fillRecordIntoArg(rec, header);
         } catch (EBaseException e) {
diff --git a/pki/base/common/src/com/netscape/cms/servlet/key/DisplayBySerialForRecovery.java b/pki/base/common/src/com/netscape/cms/servlet/key/DisplayBySerialForRecovery.java
index 1ef0ba40b7bfe8db3f7a40a5b91201524f3b7b16..72294cd4c765d29ac54c536b25aa11deb61bc101 100644
--- a/pki/base/common/src/com/netscape/cms/servlet/key/DisplayBySerialForRecovery.java
+++ b/pki/base/common/src/com/netscape/cms/servlet/key/DisplayBySerialForRecovery.java
@@ -116,7 +116,7 @@ public class DisplayBySerialForRecovery extends CMSServlet {
 
         try {
             authzToken = authorize(mAclMethod, authToken,
-                        mAuthzResourceName, "read");
+                    mAuthzResourceName, "read");
         } catch (EAuthzAccessDenied e) {
             log(ILogger.LL_FAILURE,
                     CMS.getLogMessage("ADMIN_SRVLT_AUTH_FAILURE", e.toString()));
@@ -150,12 +150,11 @@ public class DisplayBySerialForRecovery extends CMSServlet {
         IArgBlock fixed = CMS.createArgBlock();
         CMSTemplateParams argSet = new CMSTemplateParams(header, fixed);
 
-        int seqNum = -1;
+        BigInteger seqNum = BigInteger.ZERO;
 
         try {
             if (req.getParameter(IN_SERIALNO) != null) {
-                seqNum = Integer.parseInt(
-                            req.getParameter(IN_SERIALNO));
+                seqNum = new BigInteger(req.getParameter(IN_SERIALNO));
             }
             process(argSet, header,
                     req.getParameter("publicKeyData"),
@@ -185,7 +184,7 @@ public class DisplayBySerialForRecovery extends CMSServlet {
      * Display information about a particular key.
      */
     private synchronized void process(CMSTemplateParams argSet,
-            IArgBlock header, String publicKeyData, int seq,
+            IArgBlock header, String publicKeyData, BigInteger seq,
             HttpServletRequest req, HttpServletResponse resp,
             Locale locale) {
         try {
@@ -201,8 +200,7 @@ public class DisplayBySerialForRecovery extends CMSServlet {
                 header.addStringValue("publicKeyData",
                         publicKeyData);
             }
-            IKeyRecord rec = (IKeyRecord) mKeyDB.readKeyRecord(new
-                    BigInteger(Integer.toString(seq)));
+            IKeyRecord rec = (IKeyRecord) mKeyDB.readKeyRecord(seq);
 
             KeyRecordParser.fillRecordIntoArg(rec, header);
 
diff --git a/pki/base/common/src/com/netscape/cms/servlet/key/KeyRecordParser.java b/pki/base/common/src/com/netscape/cms/servlet/key/KeyRecordParser.java
index 1171236b8e3dc5cd71e52593717d341f4e32a013..d6bc57fcf0233232e4d7e4e2ec1c4b94fc5c53a7 100644
--- a/pki/base/common/src/com/netscape/cms/servlet/key/KeyRecordParser.java
+++ b/pki/base/common/src/com/netscape/cms/servlet/key/KeyRecordParser.java
@@ -17,6 +17,7 @@
 // --- END COPYRIGHT BLOCK ---
 package com.netscape.cms.servlet.key;
 
+import java.math.BigInteger;
 import java.util.Date;
 
 import com.netscape.certsrv.apps.CMS;
@@ -54,8 +55,8 @@ public class KeyRecordParser {
                 rec.getState().toString());
         rarg.addStringValue(OUT_OWNER_NAME,
                 rec.getOwnerName());
-        rarg.addIntegerValue(OUT_SERIALNO,
-                rec.getSerialNumber().intValue());
+        rarg.addBigIntegerValue(OUT_SERIALNO,
+                rec.getSerialNumber(), 10);
         rarg.addStringValue(OUT_KEY_ALGORITHM,
                 rec.getAlgorithm());
         // Possible Enhancement: sun's BASE64Encode is not 
diff --git a/pki/base/common/src/com/netscape/cms/servlet/key/RecoverBySerial.java b/pki/base/common/src/com/netscape/cms/servlet/key/RecoverBySerial.java
index 8abafa155dd17a27be61690d473d93ee7bd08ec8..ce4bc990083a9105266027e8007ea211de1252c2 100644
--- a/pki/base/common/src/com/netscape/cms/servlet/key/RecoverBySerial.java
+++ b/pki/base/common/src/com/netscape/cms/servlet/key/RecoverBySerial.java
@@ -134,7 +134,7 @@ public class RecoverBySerial extends CMSServlet {
 
         try {
             authzToken = authorize(mAclMethod, authToken,
-                        mAuthzResourceName, "recover");
+                    mAuthzResourceName, "recover");
         } catch (EAuthzAccessDenied e) {
             log(ILogger.LL_FAILURE,
                     CMS.getLogMessage("ADMIN_SRVLT_AUTH_FAILURE", e.toString()));
@@ -271,7 +271,7 @@ public class RecoverBySerial extends CMSServlet {
         }
         X509CertImpl x509cert = null;
 
-        if (cert == null) {
+        if (cert == null || cert.trim().length() == 0) {
             header.addStringValue(OUT_ERROR, "certificate not found");
             return;
         } else {
@@ -291,7 +291,7 @@ public class RecoverBySerial extends CMSServlet {
         try {
             String reqID = mService.initAsyncKeyRecovery(
                     new BigInteger(seq), x509cert,
-                      (String) sContext.get(SessionContext.USER_ID));
+                    (String) sContext.get(SessionContext.USER_ID));
             header.addStringValue(OUT_SERIALNO, req.getParameter(IN_SERIALNO));
             header.addStringValue("requestID", reqID);
         } catch (EBaseException e) {
@@ -335,7 +335,7 @@ public class RecoverBySerial extends CMSServlet {
         }
         X509CertImpl x509cert = null;
 
-        if (cert == null) {
+        if (cert == null || cert.trim().length() == 0) {
             // perform recovery
             header.addStringValue(OUT_ERROR, "certificate not found");
             return null;
@@ -407,8 +407,8 @@ public class RecoverBySerial extends CMSServlet {
 
                 header.addStringValue(OUT_OP,
                         req.getParameter(OUT_OP));
-                header.addIntegerValue(OUT_SERIALNO,
-                        Integer.parseInt(seq));
+                header.addBigIntegerValue(OUT_SERIALNO,
+                        new BigInteger(seq), 10);
                 header.addStringValue(OUT_SERVICE_URL,
                         req.getRequestURI());
                 byte pkcs12[] = mService.doKeyRecovery(
diff --git a/pki/base/common/src/com/netscape/cms/servlet/request/CertReqParser.java b/pki/base/common/src/com/netscape/cms/servlet/request/CertReqParser.java
index 7fc353a0f0b711204f962c8444e937b293c69e3f..4cc7af4fcdf2a23ae082c8e50896ca9c2bba94b1 100644
--- a/pki/base/common/src/com/netscape/cms/servlet/request/CertReqParser.java
+++ b/pki/base/common/src/com/netscape/cms/servlet/request/CertReqParser.java
@@ -444,7 +444,7 @@ public class CertReqParser extends ReqParser {
                                     (CertificateValidity)
                                     certInfo[0].get(X509CertInfo.VALIDITY);
                             if (validity != null) {
-                                long validityLength = (((Date) validity.get(CertificateValidity.NOT_AFTER)).getTime() - 
+                                long validityLength = (((Date) validity.get(CertificateValidity.NOT_AFTER)).getTime() -
                                         ((Date) validity.get(CertificateValidity.NOT_BEFORE)).getTime()) / 1000;
                                 arg.addLongValue("validityLength", validityLength);
                             }
diff --git a/pki/base/common/src/com/netscape/cms/servlet/request/CheckRequest.java b/pki/base/common/src/com/netscape/cms/servlet/request/CheckRequest.java
index b53413dcf1cd4c22e4328c3a46c410ef1a04f57c..db3e9088d586475e5f23e3b1787bc4cd8e1cc0d4 100644
--- a/pki/base/common/src/com/netscape/cms/servlet/request/CheckRequest.java
+++ b/pki/base/common/src/com/netscape/cms/servlet/request/CheckRequest.java
@@ -27,6 +27,7 @@ import java.security.NoSuchAlgorithmException;
 import java.security.cert.X509Certificate;
 import java.util.Locale;
 import java.util.StringTokenizer;
+import java.math.BigInteger;
 
 import javax.servlet.ServletConfig;
 import javax.servlet.ServletException;
@@ -160,7 +161,7 @@ public class CheckRequest extends CMSServlet {
 
         try {
             authzToken = authorize(mAclMethod, authToken,
-                        mAuthzResourceName, "read");
+                    mAuthzResourceName, "read");
         } catch (EAuthzAccessDenied e) {
             log(ILogger.LL_FAILURE,
                     CMS.getLogMessage("ADMIN_SRVLT_AUTH_FAILURE", e.toString()));
@@ -279,7 +280,7 @@ public class CheckRequest extends CMSServlet {
             throw new ECMSGWException(CMS.getUserMessage("CMS_GW_NO_REQUEST_ID_PROVIDED"));
         }
         try {
-            Integer.parseInt(requestId);
+            new BigInteger(requestId);
         } catch (NumberFormatException e) {
             log(ILogger.LL_FAILURE, CMS.getLogMessage("BASE_INVALID_NUMBER_FORMAT_1", requestId));
             throw new EBaseException(
@@ -446,17 +447,17 @@ public class CheckRequest extends CMSServlet {
                                         // create recipientNonce
                                         if (transIds != null) {
                                             ta = new TaggedAttribute(new
-                                                        INTEGER(bpid++),
-                                                        OBJECT_IDENTIFIER.id_cmc_transactionId,
-                                                        transIds);
+                                                    INTEGER(bpid++),
+                                                    OBJECT_IDENTIFIER.id_cmc_transactionId,
+                                                    transIds);
                                             controlSeq.addElement(ta);
                                         }
 
                                         if (sNonces != null) {
                                             ta = new TaggedAttribute(new
-                                                        INTEGER(bpid++),
-                                                        OBJECT_IDENTIFIER.id_cmc_recipientNonce,
-                                                        sNonces);
+                                                    INTEGER(bpid++),
+                                                    OBJECT_IDENTIFIER.id_cmc_recipientNonce,
+                                                    sNonces);
                                             controlSeq.addElement(ta);
                                         }
 
@@ -474,9 +475,9 @@ public class CheckRequest extends CMSServlet {
                                         String[] newNonce = { b64E };
 
                                         ta = new TaggedAttribute(new
-                                                    INTEGER(bpid++),
-                                                    OBJECT_IDENTIFIER.id_cmc_senderNonce,
-                                                    new OCTET_STRING(newNonce[0].getBytes()));
+                                                INTEGER(bpid++),
+                                                OBJECT_IDENTIFIER.id_cmc_senderNonce,
+                                                new OCTET_STRING(newNonce[0].getBytes()));
                                         controlSeq.addElement(ta);
 
                                         ResponseBody rb = new ResponseBody(controlSeq, new
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 6e782f5ab147607009fe2c6c43760bc4a6b786cf..063528367a88e8d9835833b804655829e5de0786 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
@@ -18,6 +18,7 @@
 package com.netscape.cms.servlet.request;
 
 import java.io.IOException;
+import java.math.BigInteger;
 import java.security.NoSuchAlgorithmException;
 import java.security.cert.Certificate;
 import java.security.cert.CertificateEncodingException;
@@ -122,56 +123,56 @@ public class ProcessCertReq extends CMSServlet {
     private final static byte EOL[] = { Character.LINE_SEPARATOR };
     private final static String[] SIGNED_AUDIT_MANUAL_CANCELLATION_REASON = new String[] {
 
-    /* 0 */"manual non-profile cert request cancellation:  "
-            + "request cannot be processed due to an "
-            + "authorization failure",
+            /* 0 */"manual non-profile cert request cancellation:  "
+                    + "request cannot be processed due to an "
+                    + "authorization failure",
 
-    /* 1 */"manual non-profile cert request cancellation:  "
-            + "no reason has been given for cancelling this "
-            + "cert request",
+            /* 1 */"manual non-profile cert request cancellation:  "
+                    + "no reason has been given for cancelling this "
+                    + "cert request",
 
-    /* 2 */"manual non-profile cert request cancellation:  "
-            + "indeterminate reason for inability to process "
-            + "cert request due to an EBaseException",
+            /* 2 */"manual non-profile cert request cancellation:  "
+                    + "indeterminate reason for inability to process "
+                    + "cert request due to an EBaseException",
 
-    /* 3 */"manual non-profile cert request cancellation:  "
-            + "indeterminate reason for inability to process "
-            + "cert request due to an IOException",
+            /* 3 */"manual non-profile cert request cancellation:  "
+                    + "indeterminate reason for inability to process "
+                    + "cert request due to an IOException",
 
-    /* 4 */"manual non-profile cert request cancellation:  "
-            + "indeterminate reason for inability to process "
-            + "cert request due to a CertificateException",
+            /* 4 */"manual non-profile cert request cancellation:  "
+                    + "indeterminate reason for inability to process "
+                    + "cert request due to a CertificateException",
 
-    /* 5 */"manual non-profile cert request cancellation:  "
-            + "indeterminate reason for inability to process "
-            + "cert request due to a NoSuchAlgorithmException"
-        };
+            /* 5 */"manual non-profile cert request cancellation:  "
+                    + "indeterminate reason for inability to process "
+                    + "cert request due to a NoSuchAlgorithmException"
+    };
     private final static String[] SIGNED_AUDIT_MANUAL_REJECTION_REASON = new String[] {
 
-    /* 0 */"manual non-profile cert request rejection:  "
-            + "request cannot be processed due to an "
-            + "authorization failure",
+            /* 0 */"manual non-profile cert request rejection:  "
+                    + "request cannot be processed due to an "
+                    + "authorization failure",
 
-    /* 1 */"manual non-profile cert request rejection:  "
-            + "no reason has been given for rejecting this "
-            + "cert request",
+            /* 1 */"manual non-profile cert request rejection:  "
+                    + "no reason has been given for rejecting this "
+                    + "cert request",
 
-    /* 2 */"manual non-profile cert request rejection:  "
-            + "indeterminate reason for inability to process "
-            + "cert request due to an EBaseException",
+            /* 2 */"manual non-profile cert request rejection:  "
+                    + "indeterminate reason for inability to process "
+                    + "cert request due to an EBaseException",
 
-    /* 3 */"manual non-profile cert request rejection:  "
-            + "indeterminate reason for inability to process "
-            + "cert request due to an IOException",
+            /* 3 */"manual non-profile cert request rejection:  "
+                    + "indeterminate reason for inability to process "
+                    + "cert request due to an IOException",
 
-    /* 4 */"manual non-profile cert request rejection:  "
-            + "indeterminate reason for inability to process "
-            + "cert request due to a CertificateException",
+            /* 4 */"manual non-profile cert request rejection:  "
+                    + "indeterminate reason for inability to process "
+                    + "cert request due to a CertificateException",
 
-    /* 5 */"manual non-profile cert request rejection:  "
-            + "indeterminate reason for inability to process "
-            + "cert request due to a NoSuchAlgorithmException"
-        };
+            /* 5 */"manual non-profile cert request rejection:  "
+                    + "indeterminate reason for inability to process "
+                    + "cert request due to a NoSuchAlgorithmException"
+    };
     private final static String LOGGING_SIGNED_AUDIT_NON_PROFILE_CERT_REQUEST =
             "LOGGING_SIGNED_AUDIT_NON_PROFILE_CERT_REQUEST_5";
     private final static String LOGGING_SIGNED_AUDIT_CERT_REQUEST_PROCESSED =
@@ -200,7 +201,7 @@ public class ProcessCertReq extends CMSServlet {
 
             if (id != null) {
                 if (!(auditServiceID.equals(
-                            AGENT_CA_CLONE_ENROLLMENT_SERVLET))
+                        AGENT_CA_CLONE_ENROLLMENT_SERVLET))
                         && !(auditServiceID.equals(
                                 AGENT_RA_CLONE_ENROLLMENT_SERVLET))) {
                     auditServiceID = ILogger.UNIDENTIFIED;
@@ -223,7 +224,7 @@ public class ProcessCertReq extends CMSServlet {
 
             try {
                 mReqCompletedTemplate = sc.getInitParameter(
-                            PROP_REQ_COMPLETED_TEMPLATE);
+                        PROP_REQ_COMPLETED_TEMPLATE);
                 if (mReqCompletedTemplate == null)
                     mReqCompletedTemplate = REQ_COMPLETED_TEMPLATE;
                 String tmp = sc.getInitParameter(PROP_EXTRA_AGENT_PARAMS);
@@ -263,7 +264,7 @@ public class ProcessCertReq extends CMSServlet {
         String signatureAlgorithm = null;
         long notValidBefore = 0;
         long notValidAfter = 0;
-        int seqNum = -1;
+        BigInteger seqNum = BigInteger.ONE.negate();
         EBaseException error = null;
 
         HttpServletRequest req = cmsReq.getHttpReq();
@@ -289,7 +290,7 @@ public class ProcessCertReq extends CMSServlet {
             if (req.getParameter(SEQNUM) != null) {
                 CMS.debug(
                         "ProcessCertReq: parameter seqNum " + req.getParameter(SEQNUM));
-                seqNum = Integer.parseInt(req.getParameter(SEQNUM));
+                seqNum = new BigInteger(req.getParameter(SEQNUM));
             }
             String notValidBeforeStr = req.getParameter("notValidBefore");
 
@@ -311,20 +312,19 @@ public class ProcessCertReq extends CMSServlet {
 
             IRequest r = null;
 
-            if (seqNum > -1) {
-                r = mQueue.findRequest(new RequestId(
-                            Integer.toString(seqNum)));
+            if (seqNum.compareTo(BigInteger.ONE.negate()) > 0) {
+                r = mQueue.findRequest(new RequestId(seqNum.toString()));
             }
 
-            if (seqNum > -1 && r != null) {
+            if (seqNum.compareTo(BigInteger.ONE.negate()) > 0 && r != null) {
                 processX509(cmsReq, argSet, header, seqNum, req, resp,
                         toDo, signatureAlgorithm, subject,
                         notValidBefore, notValidAfter, locale[0], startTime);
             } else {
-                log(ILogger.LL_FAILURE, CMS.getLogMessage("CMSGW_INVALID_REQUEST_ID_1", String.valueOf(seqNum)));
+                log(ILogger.LL_FAILURE, CMS.getLogMessage("CMSGW_INVALID_REQUEST_ID_1", seqNum.toString()));
                 error = new ECMSGWException(
                         CMS.getUserMessage("CMS_GW_INVALID_REQUEST_ID",
-                                String.valueOf(seqNum)));
+                                seqNum.toString()));
             }
         } catch (EBaseException e) {
             error = e;
@@ -399,7 +399,7 @@ public class ProcessCertReq extends CMSServlet {
      */
     private void processX509(CMSRequest cmsReq,
             CMSTemplateParams argSet, IArgBlock header,
-            int seqNum, HttpServletRequest req,
+            BigInteger seqNum, HttpServletRequest req,
             HttpServletResponse resp,
             String toDo, String signatureAlgorithm,
             String subject,
@@ -423,8 +423,7 @@ public class ProcessCertReq extends CMSServlet {
         }
 
         try {
-            IRequest r = mQueue.findRequest(new RequestId(
-                        Integer.toString(seqNum)));
+            IRequest r = mQueue.findRequest(new RequestId(seqNum.toString()));
 
             if (r != null) {
                 // overwrite "auditRequesterID" if and only if "id" != null
@@ -444,7 +443,7 @@ public class ProcessCertReq extends CMSServlet {
 
                 try {
                     authzToken = authorize(mAclMethod, authToken,
-                                mAuthzResourceName, "execute");
+                            mAuthzResourceName, "execute");
                 } catch (EAuthzAccessDenied e) {
                     log(ILogger.LL_FAILURE,
                             CMS.getLogMessage("ADMIN_SRVLT_AUTH_FAILURE",
@@ -462,45 +461,45 @@ public class ProcessCertReq extends CMSServlet {
                     if (toDo.equals(SIGNED_AUDIT_CLONING)) {
                         // ("agent" cert request for "cloning")
                         auditMessage = CMS.getLogMessage(
-                                    LOGGING_SIGNED_AUDIT_NON_PROFILE_CERT_REQUEST,
-                                    auditSubjectID,
-                                    ILogger.FAILURE,
-                                    auditRequesterID,
-                                    auditServiceID,
-                                    auditCertificateSubjectName);
+                                LOGGING_SIGNED_AUDIT_NON_PROFILE_CERT_REQUEST,
+                                auditSubjectID,
+                                ILogger.FAILURE,
+                                auditRequesterID,
+                                auditServiceID,
+                                auditCertificateSubjectName);
 
                         audit(auditMessage);
                     } else if (toDo.equals(SIGNED_AUDIT_ACCEPTANCE)) {
                         // (manual "agent" cert request processed - "accepted")
                         auditMessage = CMS.getLogMessage(
-                                    LOGGING_SIGNED_AUDIT_CERT_REQUEST_PROCESSED,
-                                    auditSubjectID,
-                                    ILogger.FAILURE,
-                                    auditRequesterID,
-                                    auditInfoName,
-                                    ILogger.SIGNED_AUDIT_EMPTY_VALUE);
+                                LOGGING_SIGNED_AUDIT_CERT_REQUEST_PROCESSED,
+                                auditSubjectID,
+                                ILogger.FAILURE,
+                                auditRequesterID,
+                                auditInfoName,
+                                ILogger.SIGNED_AUDIT_EMPTY_VALUE);
 
                         audit(auditMessage);
                     } else if (toDo.equals(SIGNED_AUDIT_CANCELLATION)) {
                         // (manual "agent" cert request processed - "cancelled")
                         auditMessage = CMS.getLogMessage(
-                                    LOGGING_SIGNED_AUDIT_CERT_REQUEST_PROCESSED,
-                                    auditSubjectID,
-                                    ILogger.FAILURE,
-                                    auditRequesterID,
-                                    auditInfoName,
-                                    SIGNED_AUDIT_MANUAL_CANCELLATION_REASON[0]);
+                                LOGGING_SIGNED_AUDIT_CERT_REQUEST_PROCESSED,
+                                auditSubjectID,
+                                ILogger.FAILURE,
+                                auditRequesterID,
+                                auditInfoName,
+                                SIGNED_AUDIT_MANUAL_CANCELLATION_REASON[0]);
 
                         audit(auditMessage);
                     } else if (toDo.equals(SIGNED_AUDIT_REJECTION)) {
                         // (manual "agent" cert request processed - "rejected")
                         auditMessage = CMS.getLogMessage(
-                                    LOGGING_SIGNED_AUDIT_CERT_REQUEST_PROCESSED,
-                                    auditSubjectID,
-                                    ILogger.FAILURE,
-                                    auditRequesterID,
-                                    auditInfoName,
-                                    SIGNED_AUDIT_MANUAL_REJECTION_REASON[0]);
+                                LOGGING_SIGNED_AUDIT_CERT_REQUEST_PROCESSED,
+                                auditSubjectID,
+                                ILogger.FAILURE,
+                                auditRequesterID,
+                                auditInfoName,
+                                SIGNED_AUDIT_MANUAL_REJECTION_REASON[0]);
 
                         audit(auditMessage);
                     }
@@ -943,12 +942,12 @@ public class ProcessCertReq extends CMSServlet {
                                 // (one for each manual "agent"
                                 //  cert request processed - "accepted")
                                 auditMessage = CMS.getLogMessage(
-                                            LOGGING_SIGNED_AUDIT_CERT_REQUEST_PROCESSED,
-                                            auditSubjectID,
-                                            ILogger.SUCCESS,
-                                            auditRequesterID,
-                                            auditInfoName,
-                                            auditInfoCertValue(issuedCerts[i]));
+                                        LOGGING_SIGNED_AUDIT_CERT_REQUEST_PROCESSED,
+                                        auditSubjectID,
+                                        ILogger.SUCCESS,
+                                        auditRequesterID,
+                                        auditInfoName,
+                                        auditInfoCertValue(issuedCerts[i]));
 
                                 audit(auditMessage);
                             }
@@ -987,12 +986,12 @@ public class ProcessCertReq extends CMSServlet {
                             // (manual "agent" cert request processed
                             //  - "accepted")
                             auditMessage = CMS.getLogMessage(
-                                        LOGGING_SIGNED_AUDIT_CERT_REQUEST_PROCESSED,
-                                        auditSubjectID,
-                                        ILogger.SUCCESS,
-                                        auditRequesterID,
-                                        auditInfoName,
-                                        ILogger.SIGNED_AUDIT_EMPTY_VALUE);
+                                    LOGGING_SIGNED_AUDIT_CERT_REQUEST_PROCESSED,
+                                    auditSubjectID,
+                                    ILogger.SUCCESS,
+                                    auditRequesterID,
+                                    auditInfoName,
+                                    ILogger.SIGNED_AUDIT_EMPTY_VALUE);
 
                             audit(auditMessage);
                         }
@@ -1116,12 +1115,12 @@ public class ProcessCertReq extends CMSServlet {
                     // store a message in the signed audit log file
                     // (manual "agent" cert request processed - "rejected")
                     auditMessage = CMS.getLogMessage(
-                                LOGGING_SIGNED_AUDIT_CERT_REQUEST_PROCESSED,
-                                auditSubjectID,
-                                ILogger.SUCCESS,
-                                auditRequesterID,
-                                auditInfoName,
-                                SIGNED_AUDIT_MANUAL_REJECTION_REASON[1]);
+                            LOGGING_SIGNED_AUDIT_CERT_REQUEST_PROCESSED,
+                            auditSubjectID,
+                            ILogger.SUCCESS,
+                            auditRequesterID,
+                            auditInfoName,
+                            SIGNED_AUDIT_MANUAL_REJECTION_REASON[1]);
 
                     audit(auditMessage);
 
@@ -1178,12 +1177,12 @@ public class ProcessCertReq extends CMSServlet {
                     // store a message in the signed audit log file
                     // (manual "agent" cert request processed - "cancelled")
                     auditMessage = CMS.getLogMessage(
-                                LOGGING_SIGNED_AUDIT_CERT_REQUEST_PROCESSED,
-                                auditSubjectID,
-                                ILogger.SUCCESS,
-                                auditRequesterID,
-                                auditInfoName,
-                                SIGNED_AUDIT_MANUAL_CANCELLATION_REASON[1]);
+                            LOGGING_SIGNED_AUDIT_CERT_REQUEST_PROCESSED,
+                            auditSubjectID,
+                            ILogger.SUCCESS,
+                            auditRequesterID,
+                            auditInfoName,
+                            SIGNED_AUDIT_MANUAL_CANCELLATION_REASON[1]);
 
                     audit(auditMessage);
 
@@ -1245,12 +1244,12 @@ public class ProcessCertReq extends CMSServlet {
                     // store a message in the signed audit log file
                     // ("agent" cert request for "cloning")
                     auditMessage = CMS.getLogMessage(
-                                LOGGING_SIGNED_AUDIT_NON_PROFILE_CERT_REQUEST,
-                                auditSubjectID,
-                                ILogger.SUCCESS,
-                                auditRequesterID,
-                                auditServiceID,
-                                auditCertificateSubjectName);
+                            LOGGING_SIGNED_AUDIT_NON_PROFILE_CERT_REQUEST,
+                            auditSubjectID,
+                            ILogger.SUCCESS,
+                            auditRequesterID,
+                            auditServiceID,
+                            auditCertificateSubjectName);
 
                     audit(auditMessage);
                 }
@@ -1264,7 +1263,7 @@ public class ProcessCertReq extends CMSServlet {
             if (CMS.getSubsystem("ra") != null)
                 header.addStringValue("localra", "yes");
 
-            header.addIntegerValue("seqNum", seqNum);
+            header.addBigIntegerValue("seqNum", seqNum, 10);
             mParser.fillRequestIntoArg(locale, r, argSet, header);
             String rid = r.getExtDataInString(IRequest.REMOTE_REQID);
 
@@ -1278,45 +1277,45 @@ public class ProcessCertReq extends CMSServlet {
                 if (toDo.equals(SIGNED_AUDIT_CLONING)) {
                     // ("agent" cert request for "cloning")
                     auditMessage = CMS.getLogMessage(
-                                LOGGING_SIGNED_AUDIT_NON_PROFILE_CERT_REQUEST,
-                                auditSubjectID,
-                                ILogger.FAILURE,
-                                auditRequesterID,
-                                auditServiceID,
-                                auditCertificateSubjectName);
+                            LOGGING_SIGNED_AUDIT_NON_PROFILE_CERT_REQUEST,
+                            auditSubjectID,
+                            ILogger.FAILURE,
+                            auditRequesterID,
+                            auditServiceID,
+                            auditCertificateSubjectName);
 
                     audit(auditMessage);
                 } else if (toDo.equals(SIGNED_AUDIT_ACCEPTANCE)) {
                     // (manual "agent" cert request processed - "accepted")
                     auditMessage = CMS.getLogMessage(
-                                LOGGING_SIGNED_AUDIT_CERT_REQUEST_PROCESSED,
-                                auditSubjectID,
-                                ILogger.FAILURE,
-                                auditRequesterID,
-                                auditInfoName,
-                                ILogger.SIGNED_AUDIT_EMPTY_VALUE);
+                            LOGGING_SIGNED_AUDIT_CERT_REQUEST_PROCESSED,
+                            auditSubjectID,
+                            ILogger.FAILURE,
+                            auditRequesterID,
+                            auditInfoName,
+                            ILogger.SIGNED_AUDIT_EMPTY_VALUE);
 
                     audit(auditMessage);
                 } else if (toDo.equals(SIGNED_AUDIT_CANCELLATION)) {
                     // (manual "agent" cert request processed - "cancelled")
                     auditMessage = CMS.getLogMessage(
-                                LOGGING_SIGNED_AUDIT_CERT_REQUEST_PROCESSED,
-                                auditSubjectID,
-                                ILogger.FAILURE,
-                                auditRequesterID,
-                                auditInfoName,
-                                SIGNED_AUDIT_MANUAL_CANCELLATION_REASON[2]);
+                            LOGGING_SIGNED_AUDIT_CERT_REQUEST_PROCESSED,
+                            auditSubjectID,
+                            ILogger.FAILURE,
+                            auditRequesterID,
+                            auditInfoName,
+                            SIGNED_AUDIT_MANUAL_CANCELLATION_REASON[2]);
 
                     audit(auditMessage);
                 } else if (toDo.equals(SIGNED_AUDIT_REJECTION)) {
                     // (manual "agent" cert request processed - "rejected")
                     auditMessage = CMS.getLogMessage(
-                                LOGGING_SIGNED_AUDIT_CERT_REQUEST_PROCESSED,
-                                auditSubjectID,
-                                ILogger.FAILURE,
-                                auditRequesterID,
-                                auditInfoName,
-                                SIGNED_AUDIT_MANUAL_REJECTION_REASON[2]);
+                            LOGGING_SIGNED_AUDIT_CERT_REQUEST_PROCESSED,
+                            auditSubjectID,
+                            ILogger.FAILURE,
+                            auditRequesterID,
+                            auditInfoName,
+                            SIGNED_AUDIT_MANUAL_REJECTION_REASON[2]);
 
                     audit(auditMessage);
                 }
@@ -1331,45 +1330,45 @@ public class ProcessCertReq extends CMSServlet {
                 if (toDo.equals(SIGNED_AUDIT_CLONING)) {
                     // ("agent" cert request for "cloning")
                     auditMessage = CMS.getLogMessage(
-                                LOGGING_SIGNED_AUDIT_NON_PROFILE_CERT_REQUEST,
-                                auditSubjectID,
-                                ILogger.FAILURE,
-                                auditRequesterID,
-                                auditServiceID,
-                                auditCertificateSubjectName);
+                            LOGGING_SIGNED_AUDIT_NON_PROFILE_CERT_REQUEST,
+                            auditSubjectID,
+                            ILogger.FAILURE,
+                            auditRequesterID,
+                            auditServiceID,
+                            auditCertificateSubjectName);
 
                     audit(auditMessage);
                 } else if (toDo.equals(SIGNED_AUDIT_ACCEPTANCE)) {
                     // (manual "agent" cert request processed - "accepted")
                     auditMessage = CMS.getLogMessage(
-                                LOGGING_SIGNED_AUDIT_CERT_REQUEST_PROCESSED,
-                                auditSubjectID,
-                                ILogger.FAILURE,
-                                auditRequesterID,
-                                auditInfoName,
-                                ILogger.SIGNED_AUDIT_EMPTY_VALUE);
+                            LOGGING_SIGNED_AUDIT_CERT_REQUEST_PROCESSED,
+                            auditSubjectID,
+                            ILogger.FAILURE,
+                            auditRequesterID,
+                            auditInfoName,
+                            ILogger.SIGNED_AUDIT_EMPTY_VALUE);
 
                     audit(auditMessage);
                 } else if (toDo.equals(SIGNED_AUDIT_CANCELLATION)) {
                     // (manual "agent" cert request processed - "cancelled")
                     auditMessage = CMS.getLogMessage(
-                                LOGGING_SIGNED_AUDIT_CERT_REQUEST_PROCESSED,
-                                auditSubjectID,
-                                ILogger.FAILURE,
-                                auditRequesterID,
-                                auditInfoName,
-                                SIGNED_AUDIT_MANUAL_CANCELLATION_REASON[3]);
+                            LOGGING_SIGNED_AUDIT_CERT_REQUEST_PROCESSED,
+                            auditSubjectID,
+                            ILogger.FAILURE,
+                            auditRequesterID,
+                            auditInfoName,
+                            SIGNED_AUDIT_MANUAL_CANCELLATION_REASON[3]);
 
                     audit(auditMessage);
                 } else if (toDo.equals(SIGNED_AUDIT_REJECTION)) {
                     // (manual "agent" cert request processed - "rejected")
                     auditMessage = CMS.getLogMessage(
-                                LOGGING_SIGNED_AUDIT_CERT_REQUEST_PROCESSED,
-                                auditSubjectID,
-                                ILogger.FAILURE,
-                                auditRequesterID,
-                                auditInfoName,
-                                SIGNED_AUDIT_MANUAL_REJECTION_REASON[3]);
+                            LOGGING_SIGNED_AUDIT_CERT_REQUEST_PROCESSED,
+                            auditSubjectID,
+                            ILogger.FAILURE,
+                            auditRequesterID,
+                            auditInfoName,
+                            SIGNED_AUDIT_MANUAL_REJECTION_REASON[3]);
 
                     audit(auditMessage);
                 }
@@ -1385,45 +1384,45 @@ public class ProcessCertReq extends CMSServlet {
                 if (toDo.equals(SIGNED_AUDIT_CLONING)) {
                     // ("agent" cert request for "cloning")
                     auditMessage = CMS.getLogMessage(
-                                LOGGING_SIGNED_AUDIT_NON_PROFILE_CERT_REQUEST,
-                                auditSubjectID,
-                                ILogger.FAILURE,
-                                auditRequesterID,
-                                auditServiceID,
-                                auditCertificateSubjectName);
+                            LOGGING_SIGNED_AUDIT_NON_PROFILE_CERT_REQUEST,
+                            auditSubjectID,
+                            ILogger.FAILURE,
+                            auditRequesterID,
+                            auditServiceID,
+                            auditCertificateSubjectName);
 
                     audit(auditMessage);
                 } else if (toDo.equals(SIGNED_AUDIT_ACCEPTANCE)) {
                     // (manual "agent" cert request processed - "accepted")
                     auditMessage = CMS.getLogMessage(
-                                LOGGING_SIGNED_AUDIT_CERT_REQUEST_PROCESSED,
-                                auditSubjectID,
-                                ILogger.FAILURE,
-                                auditRequesterID,
-                                auditInfoName,
-                                ILogger.SIGNED_AUDIT_EMPTY_VALUE);
+                            LOGGING_SIGNED_AUDIT_CERT_REQUEST_PROCESSED,
+                            auditSubjectID,
+                            ILogger.FAILURE,
+                            auditRequesterID,
+                            auditInfoName,
+                            ILogger.SIGNED_AUDIT_EMPTY_VALUE);
 
                     audit(auditMessage);
                 } else if (toDo.equals(SIGNED_AUDIT_CANCELLATION)) {
                     // (manual "agent" cert request processed - "cancelled")
                     auditMessage = CMS.getLogMessage(
-                                LOGGING_SIGNED_AUDIT_CERT_REQUEST_PROCESSED,
-                                auditSubjectID,
-                                ILogger.FAILURE,
-                                auditRequesterID,
-                                auditInfoName,
-                                SIGNED_AUDIT_MANUAL_CANCELLATION_REASON[4]);
+                            LOGGING_SIGNED_AUDIT_CERT_REQUEST_PROCESSED,
+                            auditSubjectID,
+                            ILogger.FAILURE,
+                            auditRequesterID,
+                            auditInfoName,
+                            SIGNED_AUDIT_MANUAL_CANCELLATION_REASON[4]);
 
                     audit(auditMessage);
                 } else if (toDo.equals(SIGNED_AUDIT_REJECTION)) {
                     // (manual "agent" cert request processed - "rejected")
                     auditMessage = CMS.getLogMessage(
-                                LOGGING_SIGNED_AUDIT_CERT_REQUEST_PROCESSED,
-                                auditSubjectID,
-                                ILogger.FAILURE,
-                                auditRequesterID,
-                                auditInfoName,
-                                SIGNED_AUDIT_MANUAL_REJECTION_REASON[4]);
+                            LOGGING_SIGNED_AUDIT_CERT_REQUEST_PROCESSED,
+                            auditSubjectID,
+                            ILogger.FAILURE,
+                            auditRequesterID,
+                            auditInfoName,
+                            SIGNED_AUDIT_MANUAL_REJECTION_REASON[4]);
 
                     audit(auditMessage);
                 }
@@ -1439,45 +1438,45 @@ public class ProcessCertReq extends CMSServlet {
                 if (toDo.equals(SIGNED_AUDIT_CLONING)) {
                     // ("agent" cert request for "cloning")
                     auditMessage = CMS.getLogMessage(
-                                LOGGING_SIGNED_AUDIT_NON_PROFILE_CERT_REQUEST,
-                                auditSubjectID,
-                                ILogger.FAILURE,
-                                auditRequesterID,
-                                auditServiceID,
-                                auditCertificateSubjectName);
+                            LOGGING_SIGNED_AUDIT_NON_PROFILE_CERT_REQUEST,
+                            auditSubjectID,
+                            ILogger.FAILURE,
+                            auditRequesterID,
+                            auditServiceID,
+                            auditCertificateSubjectName);
 
                     audit(auditMessage);
                 } else if (toDo.equals(SIGNED_AUDIT_ACCEPTANCE)) {
                     // (manual "agent" cert request processed - "accepted")
                     auditMessage = CMS.getLogMessage(
-                                LOGGING_SIGNED_AUDIT_CERT_REQUEST_PROCESSED,
-                                auditSubjectID,
-                                ILogger.FAILURE,
-                                auditRequesterID,
-                                auditInfoName,
-                                ILogger.SIGNED_AUDIT_EMPTY_VALUE);
+                            LOGGING_SIGNED_AUDIT_CERT_REQUEST_PROCESSED,
+                            auditSubjectID,
+                            ILogger.FAILURE,
+                            auditRequesterID,
+                            auditInfoName,
+                            ILogger.SIGNED_AUDIT_EMPTY_VALUE);
 
                     audit(auditMessage);
                 } else if (toDo.equals(SIGNED_AUDIT_CANCELLATION)) {
                     // (manual "agent" cert request processed - "cancelled")
                     auditMessage = CMS.getLogMessage(
-                                LOGGING_SIGNED_AUDIT_CERT_REQUEST_PROCESSED,
-                                auditSubjectID,
-                                ILogger.FAILURE,
-                                auditRequesterID,
-                                auditInfoName,
-                                SIGNED_AUDIT_MANUAL_CANCELLATION_REASON[5]);
+                            LOGGING_SIGNED_AUDIT_CERT_REQUEST_PROCESSED,
+                            auditSubjectID,
+                            ILogger.FAILURE,
+                            auditRequesterID,
+                            auditInfoName,
+                            SIGNED_AUDIT_MANUAL_CANCELLATION_REASON[5]);
 
                     audit(auditMessage);
                 } else if (toDo.equals(SIGNED_AUDIT_REJECTION)) {
                     // (manual "agent" cert request processed - "rejected")
                     auditMessage = CMS.getLogMessage(
-                                LOGGING_SIGNED_AUDIT_CERT_REQUEST_PROCESSED,
-                                auditSubjectID,
-                                ILogger.FAILURE,
-                                auditRequesterID,
-                                auditInfoName,
-                                SIGNED_AUDIT_MANUAL_REJECTION_REASON[5]);
+                            LOGGING_SIGNED_AUDIT_CERT_REQUEST_PROCESSED,
+                            auditSubjectID,
+                            ILogger.FAILURE,
+                            auditRequesterID,
+                            auditInfoName,
+                            SIGNED_AUDIT_MANUAL_REJECTION_REASON[5]);
 
                     audit(auditMessage);
                 }
@@ -1642,7 +1641,7 @@ public class ProcessCertReq extends CMSServlet {
 
             try {
                 authzToken = authorize(mAclMethod, authToken,
-                            resourceName, "add");
+                        resourceName, "add");
             } catch (Exception e) {
                 // do nothing for now
             }
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 78f047d2cd45c027680f0e482a40d99a98f240b9..d33250b5df67e57a4ca3ea1f01230fd068d854c6 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
@@ -19,6 +19,7 @@ package com.netscape.cms.servlet.request;
 
 import java.io.IOException;
 import java.util.Locale;
+import java.math.BigInteger;
 
 import javax.servlet.ServletConfig;
 import javax.servlet.ServletException;
@@ -73,7 +74,7 @@ public class ProcessReq extends CMSServlet {
     private String[] mSigningAlgorithms = null;
 
     private static String[] DEF_SIGNING_ALGORITHMS = new String[]
-        { "SHA1withRSA", "SHA256withRSA", "SHA512withRSA", "SHA1withDSA", "MD5withRSA", "MD2withRSA" };
+    { "SHA1withRSA", "SHA256withRSA", "SHA512withRSA", "SHA1withDSA", "MD5withRSA", "MD2withRSA" };
 
     /**
      * Process request.
@@ -130,7 +131,7 @@ public class ProcessReq extends CMSServlet {
      * @param cmsReq the object holding the request and response information
      */
     public void process(CMSRequest cmsReq) throws EBaseException {
-        int seqNum = -1;
+        BigInteger seqNum = BigInteger.ONE.negate();
 
         HttpServletRequest req = cmsReq.getHttpReq();
         HttpServletResponse resp = cmsReq.getHttpResp();
@@ -158,25 +159,25 @@ public class ProcessReq extends CMSServlet {
 
         try {
             if (req.getParameter(SEQNUM) != null) {
-                seqNum = Integer.parseInt(req.getParameter(SEQNUM));
+                seqNum = new BigInteger(req.getParameter(SEQNUM));
             }
             doAssign = req.getParameter(DO_ASSIGN);
 
-            if (seqNum > -1) {
+            if (seqNum.compareTo(BigInteger.ONE.negate()) > 0) {
                 // start authorization
                 AuthzToken authzToken = null;
 
                 try {
                     if (doAssign == null) {
                         authzToken = authorize(mAclMethod, authToken,
-                                    mAuthzResourceName, "read");
+                                mAuthzResourceName, "read");
                     } else if (doAssign.equals("toMe") ||
                             doAssign.equals("reassignToMe")) {
                         authzToken = authorize(mAclMethod, authToken,
-                                    mAuthzResourceName, "assign");
+                                mAuthzResourceName, "assign");
                     } else if (doAssign.equals("reassignToNobody")) {
                         authzToken = authorize(mAclMethod, authToken,
-                                    mAuthzResourceName, "unassign");
+                                mAuthzResourceName, "unassign");
                     }
                 } catch (EAuthzAccessDenied e) {
                     log(ILogger.LL_FAILURE,
@@ -237,15 +238,14 @@ public class ProcessReq extends CMSServlet {
      * returns whether there was an error or not.
      */
     private void process(CMSTemplateParams argSet, IArgBlock header,
-            int seqNum, HttpServletRequest req,
+            BigInteger seqNum, HttpServletRequest req,
             HttpServletResponse resp,
             String doAssign, Locale locale)
             throws EBaseException {
 
-        header.addIntegerValue("seqNum", seqNum);
+        header.addBigIntegerValue("seqNum", seqNum, 10);
 
-        IRequest r =
-                mQueue.findRequest(new RequestId(Integer.toString(seqNum)));
+        IRequest r = mQueue.findRequest(new RequestId(seqNum.toString()));
 
         if (r != null) {
             if (doAssign != null) {
@@ -280,7 +280,7 @@ public class ProcessReq extends CMSServlet {
 
                 if (allAlgorithms == null) {
                     allAlgorithms = mSigningAlgorithms =
-                                    ((ICertAuthority) mAuthority).getCASigningAlgorithms();
+                            ((ICertAuthority) mAuthority).getCASigningAlgorithms();
                     if (allAlgorithms == null) {
                         CMS.debug(
                                 "ProcessReq: signing algorithms set to All algorithms");
@@ -324,10 +324,10 @@ public class ProcessReq extends CMSServlet {
 
             mParser.fillRequestIntoArg(locale, r, argSet, header);
         } else {
-            log(ILogger.LL_FAILURE, "Invalid sequence number " + seqNum);
+            log(ILogger.LL_FAILURE, "Invalid sequence number " + seqNum.toString());
             throw new ECMSGWException(
                     CMS.getUserMessage("CMS_GW_INVALID_REQUEST_ID",
-                            String.valueOf(seqNum)));
+                            seqNum.toString()));
         }
 
         return;
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 3cb2704666b11967815c9de748ba9ea4ddddd498..8ec82d0a42c0faa19ef551b4a9b172c57a4db6e8 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
@@ -21,6 +21,7 @@ import java.io.IOException;
 import java.util.Enumeration;
 import java.util.Locale;
 import java.util.Vector;
+import java.math.BigInteger;
 
 import javax.servlet.ServletConfig;
 import javax.servlet.ServletException;
@@ -291,7 +292,8 @@ public class QueryReq extends CMSServlet {
             direction = req.getParameter("direction").trim();
         }
 
-        int top = 0, bottom = 0;
+        BigInteger top = BigInteger.ZERO;
+        BigInteger bottom = BigInteger.ZERO;
 
         try {
             String top_s = req.getParameter(OUT_FIRST_ENTRY_ON_PAGE);
@@ -303,14 +305,14 @@ public class QueryReq extends CMSServlet {
                 bottom_s = "0";
 
             if (top_s.trim().startsWith("0x")) {
-                top = Integer.parseInt(top_s.trim().substring(2), 16);
+                top = new BigInteger(top_s.trim().substring(2), 16);
             } else {
-                top = Integer.parseInt(top_s.trim());
+                top = new BigInteger(top_s.trim());
             }
             if (bottom_s.trim().startsWith("0x")) {
-                bottom = Integer.parseInt(bottom_s.trim().substring(2), 16);
+                bottom = new BigInteger(bottom_s.trim().substring(2), 16);
             } else {
-                bottom = Integer.parseInt(bottom_s.trim());
+                bottom = new BigInteger(bottom_s.trim());
             }
 
         } catch (NumberFormatException e) {
@@ -362,18 +364,19 @@ public class QueryReq extends CMSServlet {
      */
 
     private CMSTemplateParams doSearch(Locale l, String filter,
-            int count, String direction, int top, int bottom) {
+            int count, String direction, BigInteger top, BigInteger bottom) {
         CMSTemplateParams ctp = null;
         if (direction.equals("previous")) {
-            ctp = doSearch(l, filter, -count, top - 1);
+            ctp = doSearch(l, filter, -count, top);
         } else if (direction.equals("next")) {
-            ctp = doSearch(l, filter, count, bottom + 1);
+            bottom = bottom.add(BigInteger.ONE);
+            ctp = doSearch(l, filter, count, bottom);
         } else if (direction.equals("begin")) {
-            ctp = doSearch(l, filter, count, 0);
+            ctp = doSearch(l, filter, count, BigInteger.ZERO);
         } else if (direction.equals("first")) {
             ctp = doSearch(l, filter, count, bottom);
         } else { // if 'direction is 'end', default here
-            ctp = doSearch(l, filter, -count, -1);
+            ctp = doSearch(l, filter, -count, BigInteger.ONE.negate());
         }
         return ctp;
     }
@@ -391,7 +394,7 @@ public class QueryReq extends CMSServlet {
             Locale locale,
             String filter,
             int count,
-            int marker) {
+            BigInteger marker) {
 
         IArgBlock header = CMS.createArgBlock();
         IArgBlock context = CMS.createArgBlock();
@@ -406,32 +409,41 @@ public class QueryReq extends CMSServlet {
             header.addStringValue(OUT_REQUESTING_USER, "admin");
 
             boolean jumptoend = false;
-            if (marker == -1) {
-                marker = 0; // I think this is inconsequential
+            if (marker.toString().equals("-1")) {
+                marker = BigInteger.ZERO; // I think this is inconsequential
                 jumptoend = true; // override  to '99' during search 
             }
 
-            RequestId id = new RequestId(Integer.toString(marker));
+            RequestId id = new RequestId(marker.toString());
             IRequestVirtualList list = mQueue.getPagedRequestsByFilter(
                     id,
                     jumptoend,
                     filter,
-                    count + 1,
+                    ((count < 0) ? count - 1 : count + 1),
                     "requestId");
 
-            int totalCount = list.getSize() - list.getCurrentIndex();
+            int maxCount = 0;
+            if (count < 0 && jumptoend) {
+                maxCount = -count;
+            } else if (count < 0) {
+                maxCount = -count + 1;
+            } else {
+                maxCount = count;
+            }
+            int totalCount = (jumptoend) ? maxCount :
+                    (list.getSize() - list.getCurrentIndex());
             header.addIntegerValue(OUT_TOTALCOUNT, totalCount);
             header.addIntegerValue(OUT_CURRENTCOUNT, list.getSize());
 
             int numEntries = list.getSize() - list.getCurrentIndex();
 
-            Vector v = fetchRecords(list, Math.abs(count));
+            Vector v = fetchRecords(list, maxCount);
             v = normalizeOrder(v);
             trim(v, id);
 
             int currentCount = 0;
-            int curNum = 0;
-            int firstNum = -1;
+            BigInteger curNum = BigInteger.ZERO;
+            BigInteger firstNum = BigInteger.ONE.negate();
             Enumeration requests = v.elements();
 
             while (requests.hasMoreElements()) {
@@ -447,10 +459,9 @@ public class QueryReq extends CMSServlet {
                     continue;
                 }
 
-                curNum = Integer.parseInt(
-                        request.getRequestId().toString());
+                curNum = new BigInteger(request.getRequestId().toString());
 
-                if (firstNum == -1) {
+                if (firstNum.equals(BigInteger.ONE.negate())) {
                     firstNum = curNum;
                 }
 
@@ -466,15 +477,14 @@ public class QueryReq extends CMSServlet {
 
             header.addIntegerValue(OUT_CURRENTCOUNT, currentCount);
             header.addStringValue("time", Long.toString(endTime - startTime));
-            header.addIntegerValue(OUT_FIRST_ENTRY_ON_PAGE, firstNum);
-            header.addIntegerValue(OUT_LAST_ENTRY_ON_PAGE, curNum);
+            header.addBigIntegerValue(OUT_FIRST_ENTRY_ON_PAGE, firstNum, 10);
+            header.addBigIntegerValue(OUT_LAST_ENTRY_ON_PAGE, curNum, 10);
 
         } catch (EBaseException e) {
             header.addStringValue(OUT_ERROR, e.toString(locale));
         } catch (Exception e) {
         }
         return argset;
-
     }
 
     /**
@@ -485,10 +495,10 @@ public class QueryReq extends CMSServlet {
      */
     private void trim(Vector v, RequestId marker) {
         int i = v.size() - 1;
-        if (((IRequest) v.elementAt(i)).getRequestId().equals(marker)) {
+        if (((IRequest) v.elementAt(i)).getRequestId().toString().equals(
+                marker.toString())) {
             v.remove(i);
         }
-
     }
 
     /**
@@ -525,12 +535,12 @@ public class QueryReq extends CMSServlet {
      */
     private Vector normalizeOrder(Vector list) {
 
-        int firstrequestnum = Integer.parseInt(((IRequest) list.elementAt(0))
+        BigInteger firstrequestnum = new BigInteger(((IRequest) list.elementAt(0))
                 .getRequestId().toString());
-        int lastrequestnum = Integer.parseInt(((IRequest) list.elementAt(list
+        BigInteger lastrequestnum = new BigInteger(((IRequest) list.elementAt(list
                 .size() - 1)).getRequestId().toString());
         boolean reverse = false;
-        if (firstrequestnum > lastrequestnum) {
+        if (firstrequestnum.compareTo(lastrequestnum) > 0) {
             reverse = true; // if the order is backwards, place items at the beginning
         }
         Vector v = new Vector();
diff --git a/pki/base/common/src/com/netscape/cms/servlet/request/ReqParser.java b/pki/base/common/src/com/netscape/cms/servlet/request/ReqParser.java
index 00f95ec2dddc2aa28a307d0e8c37aaf9ccb9e145..230ddb43382997b151e979408dbedeb48a9a81bd 100644
--- a/pki/base/common/src/com/netscape/cms/servlet/request/ReqParser.java
+++ b/pki/base/common/src/com/netscape/cms/servlet/request/ReqParser.java
@@ -18,6 +18,7 @@
 package com.netscape.cms.servlet.request;
 
 import java.util.Locale;
+import java.math.BigInteger;
 
 import com.netscape.certsrv.base.EBaseException;
 import com.netscape.certsrv.base.IArgBlock;
@@ -51,8 +52,8 @@ public class ReqParser implements IReqParser {
     public void fillRequestIntoArg(Locale l, IRequest req, CMSTemplateParams argSet, IArgBlock arg)
             throws EBaseException {
         arg.addStringValue(TYPE, req.getRequestType());
-        arg.addLongValue("seqNum",
-                Long.parseLong(req.getRequestId().toString()));
+        arg.addBigIntegerValue("seqNum",
+                new BigInteger(req.getRequestId().toString()), 10);
         arg.addStringValue(STATUS,
                 req.getRequestStatus().toString());
         arg.addLongValue(CREATE_ON,
-- 
1.7.7.5

