use of org.xipki.console.karaf.CmdFailure in project xipki by xipki.
the class CrlSignerCheckCmd method execute0.
@Override
protected Object execute0() throws Exception {
X509ChangeCrlSignerEntry ey = getCrlSignerChangeEntry();
String name = ey.getName();
println("checking CRL signer " + name);
X509CrlSignerEntry cs = caManager.getCrlSigner(name);
if (cs == null) {
throw new CmdFailure("CRL signer named '" + name + "' is not configured");
}
if (ey.getSignerType() != null) {
MgmtQaShellUtil.assertEquals("signer type", ey.getSignerType(), cs.getType());
}
if (ey.getSignerConf() != null) {
MgmtQaShellUtil.assertEquals("signer conf", ey.getSignerConf(), cs.getConf());
}
if (ey.getCrlControl() != null) {
CrlControl ex = new CrlControl(ey.getCrlControl());
CrlControl is = new CrlControl(cs.crlControl());
if (!ex.equals(is)) {
throw new CmdFailure("CRL control: is '" + is.getConf() + "', but expected '" + ex.getConf() + "'");
}
}
if (ey.getBase64Cert() != null) {
MgmtQaShellUtil.assertEquals("certificate", ey.getBase64Cert(), cs.getBase64Cert());
}
println(" checked CRL signer " + name);
return null;
}
use of org.xipki.console.karaf.CmdFailure in project xipki by xipki.
the class P12CertExportCmd method execute0.
@Override
protected Object execute0() throws Exception {
KeyStore ks = getKeyStore();
String keyname = null;
Enumeration<String> aliases = ks.aliases();
while (aliases.hasMoreElements()) {
String alias = aliases.nextElement();
if (ks.isKeyEntry(alias)) {
keyname = alias;
break;
}
}
if (keyname == null) {
throw new CmdFailure("could not find private key");
}
X509Certificate cert = (X509Certificate) ks.getCertificate(keyname);
saveVerbose("saved certificate to file", new File(outFile), cert.getEncoded());
return null;
}
use of org.xipki.console.karaf.CmdFailure in project xipki by xipki.
the class UserUpdateCmd method execute0.
@Override
protected Object execute0() throws Exception {
Boolean realActive;
if (active != null) {
if (inactive != null) {
throw new IllegalCmdParamException("maximal one of --active and --inactive can be set");
}
realActive = Boolean.TRUE;
} else if (inactive != null) {
realActive = Boolean.FALSE;
} else {
realActive = null;
}
ChangeUserEntry entry = new ChangeUserEntry(new NameId(null, name));
if (realActive != null) {
entry.setActive(realActive);
}
if ("CONSOLE".equalsIgnoreCase(password)) {
password = new String(readPassword());
}
if (password != null) {
entry.setPassword(password);
}
String msg = "user " + name;
try {
caManager.changeUser(entry);
println("changed " + msg);
return null;
} catch (CaMgmtException ex) {
throw new CmdFailure("could not change " + msg + ", error: " + ex.getMessage(), ex);
}
}
use of org.xipki.console.karaf.CmdFailure in project xipki by xipki.
the class GetCrlCmd method execute0.
@Override
protected Object execute0() throws Exception {
CaEntry ca = caManager.getCa(caName);
if (ca == null) {
throw new CmdFailure("CA " + caName + " not available");
}
X509CRL crl = null;
try {
crl = retrieveCrl();
} catch (Exception ex) {
throw new CmdFailure("received no CRL from server: " + ex.getMessage());
}
if (crl == null) {
throw new CmdFailure("received no CRL from server");
}
saveVerbose("saved CRL to file", new File(outFile), crl.getEncoded());
if (withBaseCrl.booleanValue()) {
byte[] octetString = crl.getExtensionValue(Extension.deltaCRLIndicator.getId());
if (octetString != null) {
if (baseCrlOut == null) {
baseCrlOut = outFile + "-baseCRL";
}
byte[] extnValue = DEROctetString.getInstance(octetString).getOctets();
BigInteger baseCrlNumber = ASN1Integer.getInstance(extnValue).getPositiveValue();
try {
crl = caManager.getCrl(caName, baseCrlNumber);
} catch (Exception ex) {
throw new CmdFailure("received no baseCRL from server: " + ex.getMessage());
}
if (crl == null) {
throw new CmdFailure("received no baseCRL from server");
} else {
saveVerbose("saved baseCRL to file", new File(baseCrlOut), crl.getEncoded());
}
}
}
return null;
}
use of org.xipki.console.karaf.CmdFailure in project xipki by xipki.
the class RevokeCertCmd method execute0.
@Override
protected Object execute0() throws Exception {
CrlReason crlReason = CrlReason.forNameOrText(reason);
if (!CrlReason.PERMITTED_CLIENT_CRLREASONS.contains(crlReason)) {
throw new InvalidConfException("reason " + reason + " is not permitted");
}
Date invalidityDate = null;
if (isNotBlank(invalidityDateS)) {
invalidityDate = DateUtil.parseUtcTimeyyyyMMddhhmmss(invalidityDateS);
}
BigInteger serialNo = getSerialNumber();
String msg = "certificate (serial number = 0x" + serialNo.toString(16) + ")";
try {
caManager.revokeCertificate(caName, serialNo, crlReason, invalidityDate);
println("revoked " + msg);
return null;
} catch (CaMgmtException ex) {
throw new CmdFailure("could not revoke " + msg + ", error: " + ex.getMessage(), ex);
}
}
Aggregations