diff options
author | Endi S. Dewata <edewata@redhat.com> | 2017-04-19 23:23:39 +0200 |
---|---|---|
committer | Endi S. Dewata <edewata@redhat.com> | 2017-04-25 21:44:49 +0200 |
commit | 36a606e4b51de17c56da0f9ee4daab062ec4acf3 (patch) | |
tree | a63f303c90c768330e5223586b5f339cc88b013f /base/common/src | |
parent | 993a55fb4c883b3ca7ea0e64e24f4501909a571c (diff) | |
download | pki-36a606e4b51de17c56da0f9ee4daab062ec4acf3.tar.gz pki-36a606e4b51de17c56da0f9ee4daab062ec4acf3.tar.xz pki-36a606e4b51de17c56da0f9ee4daab062ec4acf3.zip |
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
Diffstat (limited to 'base/common/src')
-rw-r--r-- | base/common/src/com/netscape/certsrv/logging/event/CertRequestProcessedEvent.java | 71 |
1 files changed, 71 insertions, 0 deletions
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. + * <P> + * + * @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; + } + } } |