From e3d47aabee97773832d2f8ac7ff138314b44f646 Mon Sep 17 00:00:00 2001
From: Ade Lee <alee@redhat.com>
Date: Thu, 19 May 2016 11:56:26 -0400
Subject: [PATCH 306/306] Add revocation information to pki CLI output.

The date on which the certificate is revoked and the agent that
revoked it is displayed now in cert-find and cert-show output.

Ticket 1055
---
 .../org/dogtagpki/server/ca/rest/CertService.java  | 24 +++++++++------
 .../src/com/netscape/certsrv/cert/CertData.java    | 36 ++++++++++++++++++++++
 .../com/netscape/certsrv/cert/CertDataInfo.java    | 33 ++++++++++++++++++++
 .../src/com/netscape/cmstools/cert/CertCLI.java    | 21 +++++++++++++
 4 files changed, 105 insertions(+), 9 deletions(-)

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 2c5fa52b8e13f8c9bc033b9bc9a850e6220cef33..54a349e2a60c6fd7571c2cb43a0504d96050c11a 100644
--- a/base/ca/src/org/dogtagpki/server/ca/rest/CertService.java
+++ b/base/ca/src/org/dogtagpki/server/ca/rest/CertService.java
@@ -41,15 +41,6 @@ import javax.ws.rs.core.Request;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
 
-import netscape.security.pkcs.ContentInfo;
-import netscape.security.pkcs.PKCS7;
-import netscape.security.pkcs.SignerInfo;
-import netscape.security.provider.RSAPublicKey;
-import netscape.security.x509.AlgorithmId;
-import netscape.security.x509.RevocationReason;
-import netscape.security.x509.X509CertImpl;
-import netscape.security.x509.X509Key;
-
 import org.apache.catalina.realm.GenericPrincipal;
 import org.jboss.resteasy.plugins.providers.atom.Link;
 
@@ -84,6 +75,15 @@ import com.netscape.cms.servlet.processors.CAProcessor;
 import com.netscape.cmsutil.ldap.LDAPUtil;
 import com.netscape.cmsutil.util.Utils;
 
+import netscape.security.pkcs.ContentInfo;
+import netscape.security.pkcs.PKCS7;
+import netscape.security.pkcs.SignerInfo;
+import netscape.security.provider.RSAPublicKey;
+import netscape.security.x509.AlgorithmId;
+import netscape.security.x509.RevocationReason;
+import netscape.security.x509.X509CertImpl;
+import netscape.security.x509.X509Key;
+
 /**
  * @author alee
  *
@@ -527,6 +527,9 @@ public class CertService extends PKIService implements CertResource {
         Date notAfter = cert.getNotAfter();
         if (notAfter != null) certData.setNotAfter(notAfter.toString());
 
+        certData.setRevokedOn(record.getRevokedOn());
+        certData.setRevokedBy(record.getRevokedBy());
+
         certData.setStatus(record.getStatus());
 
         if (authority.noncesEnabled() && generateNonce) {
@@ -575,6 +578,9 @@ public class CertService extends PKIService implements CertResource {
         info.setIssuedOn(record.getCreateTime());
         info.setIssuedBy(record.getIssuedBy());
 
+        info.setRevokedOn(record.getRevokedOn());
+        info.setRevokedBy(record.getRevokedBy());
+
         URI uri = uriInfo.getBaseUriBuilder().path(CertResource.class, "getCert").build(id.toHexString());
         info.setLink(new Link("self", uri));
 
diff --git a/base/common/src/com/netscape/certsrv/cert/CertData.java b/base/common/src/com/netscape/certsrv/cert/CertData.java
index c0233dd66975db954144c6ac286c0ffd6a036e10..bb6d4c07cec27ad2f63d77c55d01f02102cd223f 100644
--- a/base/common/src/com/netscape/certsrv/cert/CertData.java
+++ b/base/common/src/com/netscape/certsrv/cert/CertData.java
@@ -20,6 +20,7 @@ package com.netscape.certsrv.cert;
 import java.io.PrintWriter;
 import java.io.StringReader;
 import java.io.StringWriter;
+import java.util.Date;
 
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.Marshaller;
@@ -33,6 +34,7 @@ import org.jboss.resteasy.plugins.providers.atom.Link;
 
 import com.netscape.certsrv.dbs.certdb.CertId;
 import com.netscape.certsrv.dbs.certdb.CertIdAdapter;
+import com.netscape.certsrv.util.DateAdapter;
 
 /**
  * @author alee
@@ -67,6 +69,9 @@ public class CertData {
     String notBefore;
     String notAfter;
     String status;
+    Date revokedOn;
+    String revokedBy;
+
     Long nonce;
 
     Link link;
@@ -162,6 +167,25 @@ public class CertData {
         this.nonce = nonce;
     }
 
+    @XmlElement(name="RevokedOn")
+    @XmlJavaTypeAdapter(DateAdapter.class)
+    public Date getRevokedOn() {
+        return revokedOn;
+    }
+
+    public void setRevokedOn(Date revokedOn) {
+        this.revokedOn = revokedOn;
+    }
+
+    @XmlElement(name="RevokedBy")
+    public String getRevokedBy() {
+        return revokedBy;
+    }
+
+    public void setRevokedBy(String revokedBy) {
+        this.revokedBy = revokedBy;
+    }
+
     @XmlElement(name="Link")
     public Link getLink() {
         return link;
@@ -185,6 +209,8 @@ public class CertData {
         result = prime * result + ((serialNumber == null) ? 0 : serialNumber.hashCode());
         result = prime * result + ((status == null) ? 0 : status.hashCode());
         result = prime * result + ((subjectDN == null) ? 0 : subjectDN.hashCode());
+        result = prime * result + ((revokedOn == null) ? 0 : revokedOn.hashCode());
+        result = prime * result + ((revokedBy == null) ? 0 : revokedBy.hashCode());
         return result;
     }
 
@@ -247,6 +273,16 @@ public class CertData {
                 return false;
         } else if (!subjectDN.equals(other.subjectDN))
             return false;
+        if (revokedOn == null) {
+            if (other.revokedOn != null)
+                return false;
+        } else if (!revokedOn.equals(other.revokedOn))
+            return false;
+        if (revokedBy == null) {
+            if (other.revokedBy != null)
+                return false;
+        } else if (!revokedBy.equals(other.revokedBy))
+            return false;
         return true;
     }
 
diff --git a/base/common/src/com/netscape/certsrv/cert/CertDataInfo.java b/base/common/src/com/netscape/certsrv/cert/CertDataInfo.java
index a73cb5e3acec6a7398aa94c1ce8369d190199dc8..656f264f7744298aebc687f3eabf852786c43b40 100644
--- a/base/common/src/com/netscape/certsrv/cert/CertDataInfo.java
+++ b/base/common/src/com/netscape/certsrv/cert/CertDataInfo.java
@@ -71,6 +71,8 @@ public class CertDataInfo {
     Date notValidAfter;
     Date issuedOn;
     String issuedBy;
+    Date revokedOn;
+    String revokedBy;
 
     Link link;
 
@@ -186,6 +188,25 @@ public class CertDataInfo {
         this.issuedBy = issuedBy;
     }
 
+    @XmlElement(name="RevokedOn")
+    @XmlJavaTypeAdapter(DateAdapter.class)
+    public Date getRevokedOn() {
+        return revokedOn;
+    }
+
+    public void setRevokedOn(Date revokedOn) {
+        this.revokedOn = revokedOn;
+    }
+
+    @XmlElement(name="RevokedBy")
+    public String getRevokedBy() {
+        return revokedBy;
+    }
+
+    public void setRevokedBy(String revokedBy) {
+        this.revokedBy = revokedBy;
+    }
+
     @XmlElement(name="Link")
     public Link getLink() {
         return link;
@@ -212,6 +233,8 @@ public class CertDataInfo {
         result = prime * result + ((issuerDN == null) ? 0 : issuerDN.hashCode());
         result = prime * result + ((type == null) ? 0 : type.hashCode());
         result = prime * result + ((version == null) ? 0 : version.hashCode());
+        result = prime * result + ((revokedOn == null) ? 0 : revokedOn.hashCode());
+        result = prime * result + ((revokedBy == null) ? 0 : revokedBy.hashCode());
         return result;
     }
 
@@ -289,6 +312,16 @@ public class CertDataInfo {
                 return false;
         } else if (!version.equals(other.version))
             return false;
+        if (revokedOn == null) {
+            if (other.revokedOn != null)
+                return false;
+        } else if (!revokedOn.equals(other.revokedOn))
+            return false;
+        if (revokedBy == null) {
+            if (other.revokedBy != null)
+                return false;
+        } else if (!revokedBy.equals(other.revokedBy))
+            return false;
         return true;
     }
 
diff --git a/base/java-tools/src/com/netscape/cmstools/cert/CertCLI.java b/base/java-tools/src/com/netscape/cmstools/cert/CertCLI.java
index e0924d3538a5a747daf30687ee3f852013631564..14e4a53d6d604e21f06cdf791e27b0bf34a10955 100644
--- a/base/java-tools/src/com/netscape/cmstools/cert/CertCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/cert/CertCLI.java
@@ -19,6 +19,7 @@
 package com.netscape.cmstools.cert;
 
 import java.text.SimpleDateFormat;
+import java.util.Date;
 
 import org.jboss.resteasy.plugins.providers.atom.Link;
 
@@ -128,6 +129,16 @@ public class CertCLI extends CLI {
         System.out.println("  Issued On: "+info.getIssuedOn());
         System.out.println("  Issued By: "+info.getIssuedBy());
 
+        Date revokedOn = info.getRevokedOn();
+        if (revokedOn != null) {
+            System.out.println("  Revoked On: " + revokedOn);
+        }
+
+        String revokedBy = info.getRevokedBy();
+        if (revokedBy != null) {
+            System.out.println("  Revoked By: " + revokedBy);
+        }
+
         Link link = info.getLink();
         if (verbose && link != null) {
             System.out.println("  Link: " + link.getHref());
@@ -146,6 +157,16 @@ public class CertCLI extends CLI {
         System.out.println("  Not Before: " + certData.getNotBefore());
         System.out.println("  Not After: " + certData.getNotAfter());
 
+        Date revokedOn = certData.getRevokedOn();
+        if (revokedOn != null) {
+            System.out.println("  Revoked On: " + revokedOn);
+        }
+
+        String revokedBy = certData.getRevokedBy();
+        if (revokedBy != null) {
+            System.out.println("  Revoked By: " + revokedBy);
+        }
+
         Link link = certData.getLink();
         if (verbose && link != null) {
             System.out.println("  Link: " + link.getHref());
-- 
2.7.3

