PKIBody body = pkimsg.getBody();
RevReqContent rr = body.getRr();
RevDetails rd = rr.getRevDetails(0);
CertTemplate ct = rd.getCertDetails();
DERInteger serno = ct.getSerialNumber();
X509Name issuer = ct.getIssuer();
// Get the revocation reason.
// For CMPv1 this can be a simple DERBitString or it can be a requested CRL Entry Extension
// If there exists CRL Entry Extensions we will use that, because it's the only thing allowed in CMPv2
int reason = RevokedCertInfo.REVOCATION_REASON_UNSPECIFIED;
DERBitString reasonbits = rd.getRevocationReason();
if (reasonbits != null) {
reason = CertTools.bitStringToRevokedCertInfo(reasonbits);
LOG.debug("CMPv1 revocation reason: "+reason);
} else {
LOG.debug("CMPv1 revocation reason is null");
}
X509Extensions crlExt = rd.getCrlEntryDetails();
if (crlExt != null) {
X509Extension ext = crlExt.getExtension(X509Extensions.ReasonCode);
if (ext != null) {
try {
ASN1InputStream ai = new ASN1InputStream(ext.getValue().getOctets());
DERObject obj = ai.readObject();
DEREnumerated crlreason = DEREnumerated.getInstance(obj);
// RevokedCertInfo.REVOCATION_REASON_AACOMPROMISE are the same integer values as the CRL reason extension code
reason = crlreason.getValue().intValue();
LOG.debug("CRLReason extension: "+reason);
} catch (IOException e) {
LOG.info("Exception parsin CRL reason extension: ", e);
}
} else {
LOG.debug("No CRL reason code extension present.");
}
} else {
LOG.debug("No CRL entry extensions present");
}
if ( (serno != null) && (issuer != null) ) {
String iMsg = INTRES.getLocalizedMessage("cmp.receivedrevreq", issuer.toString(), serno.getValue().toString(16));
LOG.info(iMsg);
try {
userAdminSession.revokeCert(admin, serno.getValue(), issuer.toString(), reason);
status = ResponseStatus.SUCCESS;
} catch (AuthorizationDeniedException e) {
failInfo = FailInfo.NOT_AUTHORIZED;
String errMsg = INTRES.getLocalizedMessage("cmp.errornotauthrevoke", issuer.toString(), serno.getValue().toString(16));
failText = errMsg;
LOG.error(failText);
} catch (FinderException e) {
failInfo = FailInfo.BAD_CERTIFICATE_ID;
String errMsg = INTRES.getLocalizedMessage("cmp.errorcertnofound", issuer.toString(), serno.getValue().toString(16));
failText = errMsg;
LOG.error(failText);
} catch (WaitingForApprovalException e) {
status = ResponseStatus.GRANTED_WITH_MODS;
} catch (ApprovalException e) {
failInfo = FailInfo.BAD_REQUEST;
String errMsg = INTRES.getLocalizedMessage("cmp.erroralreadyrequested");
failText = errMsg;
LOG.error(failText);
} catch (AlreadyRevokedException e) {
failInfo = FailInfo.BAD_REQUEST;
String errMsg = INTRES.getLocalizedMessage("cmp.erroralreadyrevoked");
failText = errMsg;
LOG.error(failText);
}
} else {
failInfo = FailInfo.BAD_CERTIFICATE_ID;
String errMsg = INTRES.getLocalizedMessage("cmp.errormissingissuerrevoke", issuer.toString(), serno.getValue().toString(16));
failText = errMsg;
LOG.error(failText);
}
} else {
String errMsg = INTRES.getLocalizedMessage("cmp.errorauthmessage");