From 36a606e4b51de17c56da0f9ee4daab062ec4acf3 Mon Sep 17 00:00:00 2001 From: "Endi S. Dewata" Date: Wed, 19 Apr 2017 23:23:39 +0200 Subject: Added CertRequestProcessedEvent constructor for X509CertImpl. A new CertRequestProcessedEvent constructor has been added to encapsulate CERT_REQUEST_PROCESSED events that take an X509CertImpl object. Copies of auditInfoCertValue() method in various classes have been combined and moved into CertRequestProcessedEvent. https://pagure.io/dogtagpki/issue/2636 Change-Id: Ie234bdb9f1b52399dad4bd1e20f57dcb99d86091 --- .../logging/event/CertRequestProcessedEvent.java | 71 ++++++++++++++++++++++ 1 file changed, 71 insertions(+) (limited to 'base/common/src') diff --git a/base/common/src/com/netscape/certsrv/logging/event/CertRequestProcessedEvent.java b/base/common/src/com/netscape/certsrv/logging/event/CertRequestProcessedEvent.java index 1703f65ff..3e5041ddf 100644 --- a/base/common/src/com/netscape/certsrv/logging/event/CertRequestProcessedEvent.java +++ b/base/common/src/com/netscape/certsrv/logging/event/CertRequestProcessedEvent.java @@ -17,7 +17,13 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.certsrv.logging.event; +import java.security.cert.CertificateEncodingException; + import com.netscape.certsrv.logging.AuditEvent; +import com.netscape.certsrv.logging.ILogger; +import com.netscape.cmsutil.util.Utils; + +import netscape.security.x509.X509CertImpl; public class CertRequestProcessedEvent extends AuditEvent { @@ -40,4 +46,69 @@ public class CertRequestProcessedEvent extends AuditEvent { infoValue }); } + + public CertRequestProcessedEvent( + String subjectID, + String outcome, + String requesterID, + String infoName, + X509CertImpl x509cert) { + + super(CERT_REQUEST_PROCESSED); + + setParameters(new Object[] { + subjectID, + outcome, + requesterID, + infoName, + auditInfoCertValue(x509cert) + }); + } + + /** + * Signed Audit Log Info Certificate Value + * + * This method is called to obtain the certificate from the passed in + * "X509CertImpl" for a signed audit log message. + *

+ * + * @param x509cert an X509CertImpl + * @return cert string containing the certificate + */ + public static String auditInfoCertValue(X509CertImpl x509cert) { + + if (x509cert == null) { + return ILogger.SIGNED_AUDIT_EMPTY_VALUE; + } + + byte rawData[] = null; + + try { + rawData = x509cert.getEncoded(); + } catch (CertificateEncodingException e) { + return ILogger.SIGNED_AUDIT_EMPTY_VALUE; + } + + String cert = null; + + // convert "rawData" into "base64Data" + if (rawData != null) { + String base64Data = Utils.base64encode(rawData).trim(); + + // concatenate lines + cert = base64Data.replace("\r", "").replace("\n", ""); + } + + if (cert != null) { + cert = cert.trim(); + + if (cert.equals("")) { + return ILogger.SIGNED_AUDIT_EMPTY_VALUE; + } else { + return cert; + } + } else { + return ILogger.SIGNED_AUDIT_EMPTY_VALUE; + } + } } -- cgit