Search in sources :

Example 66 with CmdFailure

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

the class GetCaCertCmd method execute0.

@Override
protected Object execute0() throws Exception {
    CaIdentifier tmpCaId = new CaIdentifier(url, caId);
    CaCertValidator caCertValidator = new CaCertValidator() {

        @Override
        public boolean isTrusted(X509Certificate cert) {
            return true;
        }
    };
    ScepClient client = new ScepClient(tmpCaId, caCertValidator);
    client.init();
    X509Certificate caCert = client.getCaCert();
    if (caCert == null) {
        throw new CmdFailure("received no CA certficate from server");
    }
    saveVerbose("saved certificate to file", new File(outFile), caCert.getEncoded());
    return null;
}
Also used : CaCertValidator(org.xipki.scep.client.CaCertValidator) CmdFailure(org.xipki.console.karaf.CmdFailure) CaIdentifier(org.xipki.scep.client.CaIdentifier) ScepClient(org.xipki.scep.client.ScepClient) File(java.io.File) X509Certificate(java.security.cert.X509Certificate)

Example 67 with CmdFailure

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

the class GetCrlCmd method execute0.

@Override
protected Object execute0() throws Exception {
    Certificate cert = Certificate.getInstance(IoUtil.read(certFile));
    ScepClient client = getScepClient();
    X509CRL crl = client.scepGetCrl(getIdentityKey(), getIdentityCert(), cert.getIssuer(), cert.getSerialNumber().getPositiveValue());
    if (crl == null) {
        throw new CmdFailure("received no CRL from server");
    }
    saveVerbose("saved CRL to file", new File(outputFile), crl.getEncoded());
    return null;
}
Also used : X509CRL(java.security.cert.X509CRL) CmdFailure(org.xipki.console.karaf.CmdFailure) ScepClient(org.xipki.scep.client.ScepClient) File(java.io.File) Certificate(org.bouncycastle.asn1.x509.Certificate)

Example 68 with CmdFailure

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

the class CaRequestorCheckCmd method execute0.

@Override
protected Object execute0() throws Exception {
    println("checking CA requestor CA='" + caName + "', requestor='" + requestorName + "'");
    if (caManager.getCa(caName) == null) {
        throw new UnexpectedException("could not find CA '" + caName + "'");
    }
    Set<CaHasRequestorEntry> entries = caManager.getRequestorsForCa(caName);
    CaHasRequestorEntry entry = null;
    String upRequestorName = requestorName.toLowerCase();
    for (CaHasRequestorEntry m : entries) {
        if (m.getRequestorIdent().getName().equals(upRequestorName)) {
            entry = m;
            break;
        }
    }
    if (entry == null) {
        throw new CmdFailure("CA is not associated with requestor '" + requestorName + "'");
    }
    boolean ra = isEnabled(raS, false, "ra");
    boolean bo = entry.isRa();
    if (ra != bo) {
        throw new CmdFailure("ra: is '" + bo + "', expected '" + ra + "'");
    }
    if (permissions != null) {
        int intPermission = ShellUtil.getPermission(permissions);
        if (intPermission != entry.getPermission()) {
            throw new CmdFailure("permissions: is '" + entry.getPermission() + "', but expected '" + intPermission + "'");
        }
    }
    if (profiles != null) {
        if (profiles.size() == 1) {
            if (CaManager.NULL.equalsIgnoreCase(profiles.iterator().next())) {
                profiles = Collections.emptySet();
            }
        }
        if (!profiles.equals(entry.getProfiles())) {
            throw new CmdFailure("profiles: is '" + entry.getProfiles() + "', but expected '" + profiles + "'");
        }
    }
    println(" checked CA requestor CA='" + caName + "', requestor='" + requestorName + "'");
    return null;
}
Also used : UnexpectedException(java.rmi.UnexpectedException) CmdFailure(org.xipki.console.karaf.CmdFailure) CaHasRequestorEntry(org.xipki.ca.server.mgmt.api.CaHasRequestorEntry)

Example 69 with CmdFailure

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

the class CertPollCmd method execute0.

@Override
protected Object execute0() throws Exception {
    CertificationRequest csr = CertificationRequest.getInstance(IoUtil.read(csrFile));
    ScepClient client = getScepClient();
    X509Certificate caCert = client.getAuthorityCertStore().getCaCert();
    X500Name caSubject = X500Name.getInstance(caCert.getSubjectX500Principal().getEncoded());
    EnrolmentResponse resp = client.scepCertPoll(getIdentityKey(), getIdentityCert(), csr, caSubject);
    if (resp.isFailure()) {
        throw new CmdFailure("server returned 'failure'");
    }
    if (resp.isPending()) {
        throw new CmdFailure("server returned 'pending'");
    }
    List<X509Certificate> certs = resp.getCertificates();
    if (certs == null || certs.isEmpty()) {
        throw new CmdFailure("received no certficate from server");
    }
    saveVerbose("saved certificate to file", new File(outputFile), certs.get(0).getEncoded());
    return null;
}
Also used : CmdFailure(org.xipki.console.karaf.CmdFailure) ScepClient(org.xipki.scep.client.ScepClient) EnrolmentResponse(org.xipki.scep.client.EnrolmentResponse) X500Name(org.bouncycastle.asn1.x500.X500Name) File(java.io.File) CertificationRequest(org.bouncycastle.asn1.pkcs.CertificationRequest) X509Certificate(java.security.cert.X509Certificate)

Example 70 with CmdFailure

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

the class GetCertCmd method execute0.

@Override
protected Object execute0() throws Exception {
    ScepClient client = getScepClient();
    BigInteger serial = toBigInt(serialNumber);
    X509Certificate caCert = client.getAuthorityCertStore().getCaCert();
    X500Name caSubject = X500Name.getInstance(caCert.getSubjectX500Principal().getEncoded());
    List<X509Certificate> certs = client.scepGetCert(getIdentityKey(), getIdentityCert(), caSubject, serial);
    if (certs == null || certs.isEmpty()) {
        throw new CmdFailure("received no certficate from server");
    }
    saveVerbose("saved certificate to file", new File(outputFile), certs.get(0).getEncoded());
    return null;
}
Also used : CmdFailure(org.xipki.console.karaf.CmdFailure) ScepClient(org.xipki.scep.client.ScepClient) BigInteger(java.math.BigInteger) X500Name(org.bouncycastle.asn1.x500.X500Name) File(java.io.File) X509Certificate(java.security.cert.X509Certificate)

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