Search in sources :

Example 81 with CmdFailure

use of org.xipki.console.karaf.CmdFailure in project xipki by xipki.

the class CaRevokeCmd method execute0.

@Override
protected Object execute0() throws Exception {
    CrlReason crlReason = CrlReason.forNameOrText(reason);
    if (!PERMITTED_REASONS.contains(crlReason)) {
        throw new IllegalCmdParamException("reason " + reason + " is not permitted");
    }
    if (!caManager.getCaNames().contains(caName)) {
        throw new IllegalCmdParamException("invalid CA name " + caName);
    }
    Date revocationDate = null;
    revocationDate = isNotBlank(revocationDateS) ? DateUtil.parseUtcTimeyyyyMMddhhmmss(revocationDateS) : new Date();
    Date invalidityDate = null;
    if (isNotBlank(invalidityDateS)) {
        invalidityDate = DateUtil.parseUtcTimeyyyyMMddhhmmss(invalidityDateS);
    }
    CertRevocationInfo revInfo = new CertRevocationInfo(crlReason, revocationDate, invalidityDate);
    String msg = "CA " + caName;
    try {
        caManager.revokeCa(caName, revInfo);
        println("revoked " + msg);
        return null;
    } catch (CaMgmtException ex) {
        throw new CmdFailure("could not revoke " + msg + ", error: " + ex.getMessage(), ex);
    }
}
Also used : CertRevocationInfo(org.xipki.security.CertRevocationInfo) CaMgmtException(org.xipki.ca.server.mgmt.api.CaMgmtException) CmdFailure(org.xipki.console.karaf.CmdFailure) IllegalCmdParamException(org.xipki.console.karaf.IllegalCmdParamException) CrlReason(org.xipki.security.CrlReason) Date(java.util.Date)

Example 82 with CmdFailure

use of org.xipki.console.karaf.CmdFailure in project xipki by xipki.

the class CaSystemRestartCmd method execute0.

@Override
protected Object execute0() throws Exception {
    try {
        caManager.restartCaSystem();
    } catch (CaMgmtException ex) {
        throw new CmdFailure("could not restart CA system, error: " + ex.getMessage(), ex);
    }
    StringBuilder sb = new StringBuilder("restarted CA system\n");
    sb.append("  successful CAs:\n");
    String prefix = "    ";
    printCaNames(sb, caManager.getSuccessfulCaNames(), prefix);
    sb.append("  failed CAs:\n");
    printCaNames(sb, caManager.getFailedCaNames(), prefix);
    sb.append("  inactive CAs:\n");
    printCaNames(sb, caManager.getInactiveCaNames(), prefix);
    println(sb.toString());
    return null;
}
Also used : CaMgmtException(org.xipki.ca.server.mgmt.api.CaMgmtException) CmdFailure(org.xipki.console.karaf.CmdFailure)

Example 83 with CmdFailure

use of org.xipki.console.karaf.CmdFailure in project xipki by xipki.

the class RequestorUpdateCmd method execute0.

@Override
protected Object execute0() throws Exception {
    // check if the certificate is valid
    byte[] certBytes = IoUtil.read(certFile);
    X509Util.parseCert(new ByteArrayInputStream(certBytes));
    String msg = "CMP requestor " + name;
    try {
        caManager.changeRequestor(name, Base64.encodeToString(certBytes));
        println("updated " + msg);
        return null;
    } catch (CaMgmtException ex) {
        throw new CmdFailure("could not update " + msg + ", error: " + ex.getMessage(), ex);
    }
}
Also used : CaMgmtException(org.xipki.ca.server.mgmt.api.CaMgmtException) ByteArrayInputStream(java.io.ByteArrayInputStream) CmdFailure(org.xipki.console.karaf.CmdFailure)

Example 84 with CmdFailure

use of org.xipki.console.karaf.CmdFailure in project xipki by xipki.

the class ResponderInfoCmd method execute0.

@Override
protected Object execute0() throws Exception {
    StringBuilder sb = new StringBuilder();
    if (name == null) {
        Set<String> names = caManager.getResponderNames();
        int size = names.size();
        if (size == 0 || size == 1) {
            sb.append((size == 0) ? "no" : "1").append(" responder is configured\n");
        } else {
            sb.append(size).append(" responders are configured:\n");
        }
        List<String> sorted = new ArrayList<>(names);
        Collections.sort(sorted);
        for (String entry : sorted) {
            sb.append("\t").append(entry).append("\n");
        }
    } else {
        ResponderEntry entry = caManager.getResponder(name);
        if (entry == null) {
            throw new CmdFailure("could not find CMP responder '" + name + "'");
        } else {
            sb.append(entry.toString(verbose));
        }
    }
    println(sb.toString());
    return null;
}
Also used : CmdFailure(org.xipki.console.karaf.CmdFailure) ArrayList(java.util.ArrayList) ResponderEntry(org.xipki.ca.server.mgmt.api.ResponderEntry)

Example 85 with CmdFailure

use of org.xipki.console.karaf.CmdFailure in project xipki by xipki.

the class ScepUpdateCmd 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;
    }
    ChangeScepEntry entry = new ChangeScepEntry(name);
    if (realActive != null) {
        entry.setActive(realActive);
    }
    if (caName != null) {
        entry.setCa(new NameId(null, caName));
    }
    if (responderName != null) {
        entry.setResponderName(responderName);
    }
    if (CollectionUtil.isNonEmpty(profiles)) {
        if (profiles.contains("NONE")) {
            profiles.clear();
        }
    }
    if (control != null) {
        entry.setControl(control);
    }
    String msg = "SCEP responder " + name;
    try {
        caManager.changeScep(entry);
        println("updated " + msg);
        return null;
    } catch (CaMgmtException ex) {
        throw new CmdFailure("could not update " + msg + ", error: " + ex.getMessage(), ex);
    }
}
Also used : ChangeScepEntry(org.xipki.ca.server.mgmt.api.x509.ChangeScepEntry) CaMgmtException(org.xipki.ca.server.mgmt.api.CaMgmtException) NameId(org.xipki.ca.api.NameId) CmdFailure(org.xipki.console.karaf.CmdFailure) IllegalCmdParamException(org.xipki.console.karaf.IllegalCmdParamException)

Aggregations

CmdFailure (org.xipki.console.karaf.CmdFailure)99 CaMgmtException (org.xipki.ca.server.mgmt.api.CaMgmtException)52 File (java.io.File)20 X509Certificate (java.security.cert.X509Certificate)20 IllegalCmdParamException (org.xipki.console.karaf.IllegalCmdParamException)15 BigInteger (java.math.BigInteger)9 NameId (org.xipki.ca.api.NameId)9 X509CRL (java.security.cert.X509CRL)7 ArrayList (java.util.ArrayList)6 Date (java.util.Date)6 CaEntry (org.xipki.ca.server.mgmt.api.CaEntry)6 RequestResponseDebug (org.xipki.common.RequestResponseDebug)6 PublisherEntry (org.xipki.ca.server.mgmt.api.PublisherEntry)5 ScepClient (org.xipki.scep.client.ScepClient)4 DEROctetString (org.bouncycastle.asn1.DEROctetString)3 CertificationRequest (org.bouncycastle.asn1.pkcs.CertificationRequest)3 X500Name (org.bouncycastle.asn1.x500.X500Name)3 Client (org.jscep.client.Client)3 CertprofileEntry (org.xipki.ca.server.mgmt.api.CertprofileEntry)3 X509CrlSignerEntry (org.xipki.ca.server.mgmt.api.x509.X509CrlSignerEntry)3