use of org.xipki.audit.AuditEvent in project xipki by xipki.
the class X509Ca method revokeSuspendedCert.
// method revokeCertificate0
private X509CertWithRevocationInfo revokeSuspendedCert(BigInteger serialNumber, CrlReason reason, String msgId) throws OperationException {
AuditEvent event = newPerfAuditEvent(CaAuditConstants.TYPE_revoke_suspendedCert, msgId);
boolean successful = false;
try {
X509CertWithRevocationInfo ret = revokeSuspendedCert0(serialNumber, reason, event);
successful = (ret != null);
return ret;
} finally {
finish(event, successful);
}
}
use of org.xipki.audit.AuditEvent in project xipki by xipki.
the class HttpRestServlet method service0.
private void service0(HttpServletRequest req, HttpServletResponse resp, boolean viaPost) throws IOException {
AuditServiceRegister auditServiceRegister = ServletHelper.getAuditServiceRegister();
if (auditServiceRegister == null) {
LOG.error("ServletHelper.auditServiceRegister not configured");
sendError(resp, HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return;
}
ResponderManager responderManager = ServletHelper.getResponderManager();
if (responderManager == null) {
LOG.error("ServletHelper.responderManager not configured");
sendError(resp, HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return;
}
AuditService auditService = auditServiceRegister.getAuditService();
AuditEvent event = new AuditEvent(new Date());
try {
Rest rest = responderManager.getRest();
String path = StringUtil.getRelativeRequestUri(req.getServletPath(), req.getRequestURI());
HttpRequestMetadataRetriever httpRetriever = new HttpRequestMetadataRetrieverImpl(req);
byte[] requestBytes = IoUtil.read(req.getInputStream());
RestResponse response = rest.service(path, event, requestBytes, httpRetriever);
resp.setStatus(response.getStatusCode());
if (resp.getContentType() != null) {
resp.setContentType(resp.getContentType());
}
for (String headerName : response.getHeaders().keySet()) {
resp.setHeader(headerName, response.getHeaders().get(headerName));
}
byte[] respBody = response.getBody();
if (respBody == null) {
resp.setContentLength(0);
} else {
resp.setContentLength(respBody.length);
resp.getOutputStream().write(respBody);
}
} finally {
event.finish();
auditService.logEvent(event);
}
}
use of org.xipki.audit.AuditEvent in project xipki by xipki.
the class OcspCertPublisher method logAndAudit.
private void logAndAudit(String issuer, X509Cert cert, Exception ex, String messagePrefix) {
String subjectText = cert.getSubject();
String serialText = LogUtil.formatCsn(cert.getCert().getSerialNumber());
LOG.error("{} (issuser='{}': subject='{}', serialNumber={}). Message: {}", messagePrefix, issuer, subjectText, serialText, ex.getMessage());
LOG.debug("error", ex);
AuditEvent event = new AuditEvent(new Date());
event.setApplicationName("CAPublisher");
event.setName("SYSTEM");
event.setLevel(AuditLevel.ERROR);
event.setStatus(AuditStatus.FAILED);
if (cert instanceof X509CertWithDbId) {
Long certId = ((X509CertWithDbId) cert).getCertId();
if (certId != null) {
event.addEventData(CaAuditConstants.NAME_id, certId);
}
}
event.addEventData(CaAuditConstants.NAME_issuer, issuer);
event.addEventData(CaAuditConstants.NAME_subject, subjectText);
event.addEventData(CaAuditConstants.NAME_serial, serialText);
event.addEventData(CaAuditConstants.NAME_message, messagePrefix);
auditServiceRegister.getAuditService().logEvent(event);
}
use of org.xipki.audit.AuditEvent in project xipki by xipki.
the class CaManagerImpl method generateCertificate.
// method removeCertificate
@Override
public X509Certificate generateCertificate(String caName, String profileName, byte[] encodedCsr, Date notBefore, Date notAfter) throws CaMgmtException {
caName = ParamUtil.requireNonBlank("caName", caName).toLowerCase();
profileName = ParamUtil.requireNonBlank("profileName", profileName).toLowerCase();
ParamUtil.requireNonNull("encodedCsr", encodedCsr);
AuditEvent event = new AuditEvent(new Date());
event.setApplicationName(CaAuditConstants.APPNAME);
event.setName(CaAuditConstants.NAME_PERF);
event.addEventType("CAMGMT_CRL_GEN_ONDEMAND");
X509Ca ca = getX509Ca(caName);
CertificationRequest csr;
try {
csr = CertificationRequest.getInstance(encodedCsr);
} catch (Exception ex) {
throw new CaMgmtException(concat("invalid CSR request. ERROR: ", ex.getMessage()));
}
CmpControl cmpControl = getCmpControlObject(ca.getCaInfo().getCmpControlName());
if (!securityFactory.verifyPopo(csr, cmpControl.getPopoAlgoValidator())) {
throw new CaMgmtException("could not validate POP for the CSR");
}
CertificationRequestInfo certTemp = csr.getCertificationRequestInfo();
Extensions extensions = null;
ASN1Set attrs = certTemp.getAttributes();
for (int i = 0; i < attrs.size(); i++) {
Attribute attr = Attribute.getInstance(attrs.getObjectAt(i));
if (PKCSObjectIdentifiers.pkcs_9_at_extensionRequest.equals(attr.getAttrType())) {
extensions = Extensions.getInstance(attr.getAttributeValues()[0]);
}
}
X500Name subject = certTemp.getSubject();
SubjectPublicKeyInfo publicKeyInfo = certTemp.getSubjectPublicKeyInfo();
CertTemplateData certTemplateData = new CertTemplateData(subject, publicKeyInfo, notBefore, notAfter, extensions, profileName);
X509CertificateInfo certInfo;
try {
certInfo = ca.generateCertificate(certTemplateData, byCaRequestor, RequestType.CA, (byte[]) null, CaAuditConstants.MSGID_ca_mgmt);
} catch (OperationException ex) {
throw new CaMgmtException(ex.getMessage(), ex);
}
if (ca.getCaInfo().isSaveRequest()) {
try {
long dbId = ca.addRequest(encodedCsr);
ca.addRequestCert(dbId, certInfo.getCert().getCertId());
} catch (OperationException ex) {
LogUtil.warn(LOG, ex, "could not save request");
}
}
return certInfo.getCert().getCert();
}
use of org.xipki.audit.AuditEvent in project xipki by xipki.
the class X509Ca method cleanupCrls.
private void cleanupCrls(String msgId) throws OperationException {
int numCrls = caInfo.getNumCrls();
LOG.info(" START cleanupCrls: ca={}, numCrls={}", caIdent, numCrls);
boolean successful = false;
AuditEvent event = newPerfAuditEvent(CaAuditConstants.TYPE_cleanup_crl, msgId);
try {
int num = (numCrls <= 0) ? 0 : certstore.cleanupCrls(caIdent, caInfo.getNumCrls());
successful = true;
event.addEventData(CaAuditConstants.NAME_num, num);
LOG.info("SUCCESSFUL cleanupCrls: ca={}, num={}", caIdent, num);
} catch (RuntimeException ex) {
throw new OperationException(ErrorCode.SYSTEM_FAILURE, ex);
} finally {
if (!successful) {
LOG.info(" FAILED cleanupCrls: ca={}", caIdent);
}
finish(event, successful);
}
}
Aggregations