>From e2f0c909c444ba85a73c39cde2f1c97e6b0a81f0 Mon Sep 17 00:00:00 2001
From: Abhishek Koneru <akoneru@redhat.com>
Date: Fri, 2 May 2014 19:16:03 -0400
Subject: [PATCH] Removed requestID parameter usage in [un]revoke request.

There seems to be no use of the requestID parameter in both revoke
and unrevoke request. Removed requestID attribute in CertRevokeRequest
remove the class CertUnrevokeRequest.

Also made changes in RevocationProcesor to use the requestID of the
request created in it.

The setRequestID() is being called in the DoRevoke and DoUnRevoke servlets.
Removed the call and a function auditRequesterId in both the classes.

The auditRequestorId method tries to get a "requestID" stored as a INPUT field
in the reasonToRequest page. The ReasonToRevoke class which generates
this page does not set the value.
---
 .../webapps/ca/ee/ca/reasonToRevoke.template       |   4 -
 .../org/dogtagpki/server/ca/rest/CertService.java  |   9 +-
 .../src/com/netscape/certsrv/cert/CertClient.java  |   4 +-
 .../com/netscape/certsrv/cert/CertResource.java    |   2 +-
 .../netscape/certsrv/cert/CertRevokeRequest.java   |  21 ----
 .../netscape/certsrv/cert/CertUnrevokeRequest.java | 124 ---------------------
 .../netscape/cmstools/cert/CertReleaseHoldCLI.java |   5 +-
 .../com/netscape/cms/servlet/cert/DoRevoke.java    |  21 ----
 .../com/netscape/cms/servlet/cert/DoUnrevoke.java  |  22 ----
 .../cms/servlet/cert/RevocationProcessor.java      |   2 +
 10 files changed, 8 insertions(+), 206 deletions(-)
 delete mode 100644 base/common/src/com/netscape/certsrv/cert/CertUnrevokeRequest.java

diff --git a/base/ca/shared/webapps/ca/ee/ca/reasonToRevoke.template b/base/ca/shared/webapps/ca/ee/ca/reasonToRevoke.template
index 7edfe7e29db58d2190f738d2c9dc6f4ac021284a..2a608438b1f46b7695a8692ed857ce7de6e07d42 100644
--- a/base/ca/shared/webapps/ca/ee/ca/reasonToRevoke.template
+++ b/base/ca/shared/webapps/ca/ee/ca/reasonToRevoke.template
@@ -457,10 +457,6 @@ function revokeCert(serialNumber)
         document.writeln("<INPUT TYPE=hidden name=verifiedRecordCount value=\"" +
                          result.header.verifiedRecordCount +"\">");
         document.writeln("<INPUT TYPE=hidden name=invalidityDate value=\"0\">");
-        if (result.header.request != null) {
-            document.writeln("<INPUT TYPE=hidden name=requestId value=\"" +
-                             result.header.request +"\">");
-        }
         if (result.header.b64eCertificate != null) {
             document.writeln("<INPUT TYPE=hidden name=b64eCertificate value=\"" +
                              result.header.b64eCertificate +"\">");
diff --git a/base/ca/src/org/dogtagpki/server/ca/rest/CertService.java b/base/ca/src/org/dogtagpki/server/ca/rest/CertService.java
index 1b7120b376d09596efb853d188e218d008b64f61..e9e1e0da02f279fccb5c787a2005dc806a84b1d2 100644
--- a/base/ca/src/org/dogtagpki/server/ca/rest/CertService.java
+++ b/base/ca/src/org/dogtagpki/server/ca/rest/CertService.java
@@ -67,7 +67,6 @@ import com.netscape.certsrv.cert.CertResource;
 import com.netscape.certsrv.cert.CertRetrievalRequest;
 import com.netscape.certsrv.cert.CertRevokeRequest;
 import com.netscape.certsrv.cert.CertSearchRequest;
-import com.netscape.certsrv.cert.CertUnrevokeRequest;
 import com.netscape.certsrv.dbs.EDBRecordNotFoundException;
 import com.netscape.certsrv.dbs.certdb.CertId;
 import com.netscape.certsrv.dbs.certdb.ICertRecord;
@@ -182,9 +181,7 @@ public class CertService extends PKIService implements CertResource {
 
         RevocationReason revReason = request.getReason();
         if (revReason == RevocationReason.REMOVE_FROM_CRL) {
-            CertUnrevokeRequest unrevRequest = new CertUnrevokeRequest();
-            unrevRequest.setRequestID(request.getRequestID());
-            return unrevokeCert(id, unrevRequest);
+            return unrevokeCert(id);
         }
 
         RevocationProcessor processor;
@@ -196,7 +193,6 @@ public class CertService extends PKIService implements CertResource {
             processor.setInitiative(AuditFormat.FROMAGENT);
 
             processor.setSerialNumber(id);
-            processor.setRequestID(request.getRequestID());
 
             processor.setRevocationReason(revReason);
             processor.setRequestType(revReason == RevocationReason.CERTIFICATE_HOLD
@@ -302,7 +298,7 @@ public class CertService extends PKIService implements CertResource {
     }
 
     @Override
-    public Response unrevokeCert(CertId id, CertUnrevokeRequest request) {
+    public Response unrevokeCert(CertId id) {
         if (id == null) {
             CMS.debug("unrevokeCert: id is null");
             throw new BadRequestException("Unable to unrevoke cert: invalid id");
@@ -325,7 +321,6 @@ public class CertService extends PKIService implements CertResource {
             processor.setInitiative(AuditFormat.FROMAGENT);
 
             processor.setSerialNumber(id);
-            processor.setRequestID(request.getRequestID());
             processor.setRevocationReason(RevocationReason.CERTIFICATE_HOLD);
             processor.setAuthority(authority);
 
diff --git a/base/common/src/com/netscape/certsrv/cert/CertClient.java b/base/common/src/com/netscape/certsrv/cert/CertClient.java
index 3af93269f284ab826901e6cfc4424f023850f31b..86e5e15374d23563faac987b40e9d5c33a38cc25 100644
--- a/base/common/src/com/netscape/certsrv/cert/CertClient.java
+++ b/base/common/src/com/netscape/certsrv/cert/CertClient.java
@@ -75,8 +75,8 @@ public class CertClient extends Client {
         return client.getEntity(response, CertRequestInfo.class);
     }
 
-    public CertRequestInfo unrevokeCert(CertId id, CertUnrevokeRequest request) {
-        Response response = certClient.unrevokeCert(id, request);
+    public CertRequestInfo unrevokeCert(CertId id) {
+        Response response = certClient.unrevokeCert(id);
         return client.getEntity(response, CertRequestInfo.class);
     }
 
diff --git a/base/common/src/com/netscape/certsrv/cert/CertResource.java b/base/common/src/com/netscape/certsrv/cert/CertResource.java
index c5a5823ea90af354b20007d5a2b91762853b795f..9d6a7c89bc43e9337b09de7c31a2167b3898431d 100644
--- a/base/common/src/com/netscape/certsrv/cert/CertResource.java
+++ b/base/common/src/com/netscape/certsrv/cert/CertResource.java
@@ -65,5 +65,5 @@ public interface CertResource {
     @ClientResponseType(entityType=CertRequestInfo.class)
     @ACLMapping("certs")
     @AuthMethodMapping("certs")
-    public Response unrevokeCert(@PathParam("id") CertId id, CertUnrevokeRequest request);
+    public Response unrevokeCert(@PathParam("id") CertId id);
 }
diff --git a/base/common/src/com/netscape/certsrv/cert/CertRevokeRequest.java b/base/common/src/com/netscape/certsrv/cert/CertRevokeRequest.java
index 0fe0c4696e6104506a34989d1a21b07280e4ed9c..a89c95a3e82971cd059fe76ee10b954fa0aebb43 100644
--- a/base/common/src/com/netscape/certsrv/cert/CertRevokeRequest.java
+++ b/base/common/src/com/netscape/certsrv/cert/CertRevokeRequest.java
@@ -34,8 +34,6 @@ import netscape.security.x509.RevocationReason;
 import netscape.security.x509.RevocationReasonAdapter;
 
 import com.netscape.certsrv.request.IRequest;
-import com.netscape.certsrv.request.RequestId;
-import com.netscape.certsrv.request.RequestIdAdapter;
 import com.netscape.certsrv.util.DateAdapter;
 
 /**
@@ -58,7 +56,6 @@ public class CertRevokeRequest {
         }
     }
 
-    RequestId requestID;
     RevocationReason reason;
     Date invalidityDate;
     String comments;
@@ -66,17 +63,6 @@ public class CertRevokeRequest {
     Long nonce;
 
 
-    @XmlElement(name="RequestID")
-    @FormParam("requestId")
-    @XmlJavaTypeAdapter(RequestIdAdapter.class)
-    public RequestId getRequestID() {
-        return requestID;
-    }
-
-    public void setRequestID(RequestId requestID) {
-        this.requestID = requestID;
-    }
-
     @XmlElement(name="Reason")
     @FormParam("revocationReason")
     @XmlJavaTypeAdapter(RevocationReasonAdapter.class)
@@ -138,7 +124,6 @@ public class CertRevokeRequest {
         result = prime * result + ((invalidityDate == null) ? 0 : invalidityDate.hashCode());
         result = prime * result + ((nonce == null) ? 0 : nonce.hashCode());
         result = prime * result + ((reason == null) ? 0 : reason.hashCode());
-        result = prime * result + ((requestID == null) ? 0 : requestID.hashCode());
         return result;
     }
 
@@ -176,11 +161,6 @@ public class CertRevokeRequest {
                 return false;
         } else if (!reason.equals(other.reason))
             return false;
-        if (requestID == null) {
-            if (other.requestID != null)
-                return false;
-        } else if (!requestID.equals(other.requestID))
-            return false;
         return true;
     }
 
@@ -206,7 +186,6 @@ public class CertRevokeRequest {
     public static void main(String args[]) throws Exception {
 
         CertRevokeRequest before = new CertRevokeRequest();
-        before.setRequestID(new RequestId("42323234"));
         before.setReason(RevocationReason.CERTIFICATE_HOLD);
         before.setInvalidityDate(new Date());
         before.setComments("test");
diff --git a/base/common/src/com/netscape/certsrv/cert/CertUnrevokeRequest.java b/base/common/src/com/netscape/certsrv/cert/CertUnrevokeRequest.java
deleted file mode 100644
index 7885482be0a4afa734fbf82abe3102675f620de9..0000000000000000000000000000000000000000
--- a/base/common/src/com/netscape/certsrv/cert/CertUnrevokeRequest.java
+++ /dev/null
@@ -1,124 +0,0 @@
-// --- BEGIN COPYRIGHT BLOCK ---
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; version 2 of the License.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License along
-// with this program; if not, write to the Free Software Foundation, Inc.,
-// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-//
-// (C) 2012 Red Hat, Inc.
-// All rights reserved.
-// --- END COPYRIGHT BLOCK ---
-
-package com.netscape.certsrv.cert;
-
-import java.io.StringReader;
-import java.io.StringWriter;
-
-import javax.ws.rs.FormParam;
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.Marshaller;
-import javax.xml.bind.Unmarshaller;
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlRootElement;
-import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
-
-import com.netscape.certsrv.request.RequestId;
-import com.netscape.certsrv.request.RequestIdAdapter;
-
-/**
- * @author Endi S. Dewata
- */
-@XmlRootElement(name="CertUnrevokeRequest")
-public class CertUnrevokeRequest {
-
-    public static Marshaller marshaller;
-    public static Unmarshaller unmarshaller;
-
-    static {
-        try {
-            JAXBContext context = JAXBContext.newInstance(CertUnrevokeRequest.class);
-            marshaller = context.createMarshaller();
-            marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
-            unmarshaller = context.createUnmarshaller();
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-    }
-
-    RequestId requestID;
-
-    @XmlElement(name="requestID")
-    @FormParam("requestId")
-    @XmlJavaTypeAdapter(RequestIdAdapter.class)
-    public RequestId getRequestID() {
-        return requestID;
-    }
-
-    public void setRequestID(RequestId requestID) {
-        this.requestID = requestID;
-    }
-
-    @Override
-    public int hashCode() {
-        final int prime = 31;
-        int result = 1;
-        result = prime * result + ((requestID == null) ? 0 : requestID.hashCode());
-        return result;
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        if (this == obj)
-            return true;
-        if (obj == null)
-            return false;
-        if (getClass() != obj.getClass())
-            return false;
-        CertUnrevokeRequest other = (CertUnrevokeRequest) obj;
-        if (requestID == null) {
-            if (other.requestID != null)
-                return false;
-        } else if (!requestID.equals(other.requestID))
-            return false;
-        return true;
-    }
-
-    public String toString() {
-        try {
-            StringWriter sw = new StringWriter();
-            marshaller.marshal(this, sw);
-            return sw.toString();
-
-        } catch (Exception e) {
-            return super.toString();
-        }
-    }
-
-    public static CertUnrevokeRequest valueOf(String string) throws Exception {
-        try {
-            return (CertUnrevokeRequest)unmarshaller.unmarshal(new StringReader(string));
-        } catch (Exception e) {
-            return null;
-        }
-    }
-
-    public static void main(String args[]) throws Exception {
-
-        CertUnrevokeRequest before = new CertUnrevokeRequest();
-        before.setRequestID(new RequestId("42323234"));
-
-        String string = before.toString();
-        System.out.println(string);
-
-        CertUnrevokeRequest after = CertUnrevokeRequest.valueOf(string);
-
-        System.out.println(before.equals(after));
-    }
-}
diff --git a/base/java-tools/src/com/netscape/cmstools/cert/CertReleaseHoldCLI.java b/base/java-tools/src/com/netscape/cmstools/cert/CertReleaseHoldCLI.java
index 42a8ae9ca9d57e700022e4dc293b4ae1cc99e706..78beb12d084d29b701944720fd92905c9a4cd068 100644
--- a/base/java-tools/src/com/netscape/cmstools/cert/CertReleaseHoldCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/cert/CertReleaseHoldCLI.java
@@ -26,7 +26,6 @@ import org.apache.commons.cli.CommandLine;
 
 import com.netscape.certsrv.cert.CertData;
 import com.netscape.certsrv.cert.CertRequestInfo;
-import com.netscape.certsrv.cert.CertUnrevokeRequest;
 import com.netscape.certsrv.dbs.certdb.CertId;
 import com.netscape.certsrv.request.RequestStatus;
 import com.netscape.cmstools.cli.CLI;
@@ -101,9 +100,7 @@ public class CertReleaseHoldCLI extends CLI {
             }
         }
 
-        CertUnrevokeRequest request = new CertUnrevokeRequest();
-
-        CertRequestInfo certRequestInfo = certCLI.certClient.unrevokeCert(certID, request);
+        CertRequestInfo certRequestInfo = certCLI.certClient.unrevokeCert(certID);
 
         if (verbose) {
             CertCLI.printCertRequestInfo(certRequestInfo);
diff --git a/base/server/cms/src/com/netscape/cms/servlet/cert/DoRevoke.java b/base/server/cms/src/com/netscape/cms/servlet/cert/DoRevoke.java
index 8a7bc556e27359c54de55dcbf0e6659f2c1918ef..1788be3039d12280d573dc9209ae2dbff3b9efd1 100644
--- a/base/server/cms/src/com/netscape/cms/servlet/cert/DoRevoke.java
+++ b/base/server/cms/src/com/netscape/cms/servlet/cert/DoRevoke.java
@@ -381,7 +381,6 @@ public class DoRevoke extends CMSServlet {
         processor.setStartTime(startTime);
         processor.setInitiative(initiative);
         processor.setSerialNumber(eeSerialNumber == null ? null : new CertId(eeSerialNumber));
-        processor.setRequestID(auditRequesterID(req));
 
         RevocationReason revReason = RevocationReason.fromInt(reason);
         processor.setRevocationReason(revReason);
@@ -753,26 +752,6 @@ public class DoRevoke extends CMSServlet {
     }
 
     /**
-     * Signed Audit Log Requester ID
-     *
-     * This method is called to obtain the "RequesterID" for
-     * a signed audit log message.
-     * <P>
-     *
-     * @param req HTTP request
-     * @return id string containing the signed audit log message RequesterID
-     */
-    private RequestId auditRequesterID(HttpServletRequest req) {
-        String requesterID = req.getParameter("requestId");
-
-        if (requesterID != null) {
-            return new RequestId(requesterID.trim());
-        } else {
-            return null;
-        }
-    }
-
-    /**
      * This method parses a String serial number into BigInteger.
      *
      * @param serialNumber a String containing the un-normalized serial number
diff --git a/base/server/cms/src/com/netscape/cms/servlet/cert/DoUnrevoke.java b/base/server/cms/src/com/netscape/cms/servlet/cert/DoUnrevoke.java
index 723651eb6fa3c2f3a80b39eecc5695b3826aad08..e111e8ad872081a2fa6085ff8aa0e0cc9d146837 100644
--- a/base/server/cms/src/com/netscape/cms/servlet/cert/DoUnrevoke.java
+++ b/base/server/cms/src/com/netscape/cms/servlet/cert/DoUnrevoke.java
@@ -49,7 +49,6 @@ import com.netscape.certsrv.logging.AuditFormat;
 import com.netscape.certsrv.logging.ILogger;
 import com.netscape.certsrv.publish.IPublisherProcessor;
 import com.netscape.certsrv.request.IRequest;
-import com.netscape.certsrv.request.RequestId;
 import com.netscape.certsrv.request.RequestStatus;
 import com.netscape.cms.servlet.base.CMSServlet;
 import com.netscape.cms.servlet.common.CMSRequest;
@@ -242,7 +241,6 @@ public class DoUnrevoke extends CMSServlet {
 
         processor.setInitiative(initiative);
         processor.setSerialNumber(auditSerialNumber(serialNumbers[0].toString()));
-        processor.setRequestID(auditRequesterID(req));
 
         processor.setRevocationReason(RevocationReason.CERTIFICATE_HOLD);
         processor.setRequestType(RevocationProcessor.OFF_HOLD);
@@ -461,26 +459,6 @@ public class DoUnrevoke extends CMSServlet {
     }
 
     /**
-     * Signed Audit Log Requester ID
-     *
-     * This method is called to obtain the "RequesterID" for
-     * a signed audit log message.
-     * <P>
-     *
-     * @param req HTTP request
-     * @return id string containing the signed audit log message RequesterID
-     */
-    private RequestId auditRequesterID(HttpServletRequest req) {
-        String requesterID = req.getParameter("requestId");
-
-        if (requesterID != null) {
-            return new RequestId(requesterID.trim());
-        } else {
-            return null;
-        }
-    }
-
-    /**
      * Signed Audit Log Serial Number
      *
      * This method is called to obtain the serial number of the certificate
diff --git a/base/server/cms/src/com/netscape/cms/servlet/cert/RevocationProcessor.java b/base/server/cms/src/com/netscape/cms/servlet/cert/RevocationProcessor.java
index 93b7531c810ac7992db94c09e227c33cd6a542a5..e03fc2cfd851ddbb4cd7f557e6878051d5ecaba5 100644
--- a/base/server/cms/src/com/netscape/cms/servlet/cert/RevocationProcessor.java
+++ b/base/server/cms/src/com/netscape/cms/servlet/cert/RevocationProcessor.java
@@ -296,6 +296,7 @@ public class RevocationProcessor extends CertProcessor {
     public void createRevocationRequest() throws EBaseException {
 
         request = requestQueue.newRequest(IRequest.REVOCATION_REQUEST);
+        setRequestID(request.getRequestId());
 
         request.setExtData(IRequest.REQ_TYPE, IRequest.REVOCATION_REQUEST);
 
@@ -376,6 +377,7 @@ public class RevocationProcessor extends CertProcessor {
     public void createUnrevocationRequest() throws EBaseException {
 
         request = requestQueue.newRequest(IRequest.UNREVOCATION_REQUEST);
+        setRequestID(request.getRequestId());
 
         request.setExtData(IRequest.REQ_TYPE, IRequest.UNREVOCATION_REQUEST);
 
-- 
1.8.5.3

