final String certserno = args[2];
final BigInteger serno;
try {
serno = new BigInteger(certserno, 16);
} catch (NumberFormatException e) {
throw new ErrorAdminCommandException("Invalid hexadecimal certificate serial number string: "+certserno);
}
int reason = Integer.parseInt(args[3]);
if ((reason == 7) || (reason < 0) || (reason > 10)) {
getLogger().error("Reason must be an integer between 0 and 10 except 7.");
} else {
Certificate cert = ejb.getCertStoreSession().findCertificateByIssuerAndSerno(getAdmin(), issuerDN, serno);
if (cert != null) {
getLogger().info("Found certificate:");
getLogger().info("Subject DN=" + CertTools.getSubjectDN(cert));
// We need the user this cert is connected with
// Revoke or unrevoke, will throw appropriate exceptions if parameters are wrong, such as trying to unrevoke a certificate
// that was permanently revoked
try {
ejb.getUserAdminSession().revokeCert(getAdmin(), serno, issuerDN, reason);
getLogger().info( (reason == 8 ? "Unrevoked":"Revoked") + " certificate with issuerDN '"+issuerDN+"' and serialNumber "+certserno+". Revocation reason="+reason);
} catch (AlreadyRevokedException e) {
if (reason == 8) {
getLogger().info("Certificate with issuerDN '"+issuerDN+"' and serialNumber "+certserno+" is not revoked, nothing was done.");
} else {
getLogger().info("Certificate with issuerDN '"+issuerDN+"' and serialNumber "+certserno+" is already revoked, nothing was done.");
}
getLogger().info(e.getMessage());
}
} else {
getLogger().info("No certificate found with issuerDN '"+issuerDN+"' and serialNumber "+certserno);
}
}
} catch (Exception e) {
throw new ErrorAdminCommandException(e);
}
}