Search in sources :

Example 1 with Client

use of org.jscep.client.Client in project xipki by xipki.

the class GetCrlCmd method execute0.

@Override
protected Object execute0() throws Exception {
    X509Certificate cert = X509Util.parseCert(new File(certFile));
    Client client = getScepClient();
    X509CRL crl = client.getRevocationList(getIdentityCert(), getIdentityKey(), cert.getIssuerX500Principal(), cert.getSerialNumber());
    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) Client(org.jscep.client.Client) File(java.io.File) X509Certificate(java.security.cert.X509Certificate)

Example 2 with Client

use of org.jscep.client.Client in project xipki by xipki.

the class CertPollCmd method execute0.

@Override
protected Object execute0() throws Exception {
    PKCS10CertificationRequest csr = new PKCS10CertificationRequest(IoUtil.read(csrFile));
    Client client = getScepClient();
    TransactionId transId = TransactionId.createTransactionId(CertificationRequestUtils.getPublicKey(csr), "SHA-1");
    EnrollmentResponse resp = client.poll(getIdentityCert(), getIdentityKey(), new X500Principal(csr.getSubject().getEncoded()), transId);
    if (resp.isFailure()) {
        throw new CmdFailure("server returned 'failure'");
    }
    if (resp.isPending()) {
        throw new CmdFailure("server returned 'pending'");
    }
    X509Certificate cert = extractEeCerts(resp.getCertStore());
    if (cert == null) {
        throw new Exception("received no certificate");
    }
    saveVerbose("saved polled certificate to file", new File(outputFile), cert.getEncoded());
    return null;
}
Also used : PKCS10CertificationRequest(org.bouncycastle.pkcs.PKCS10CertificationRequest) CmdFailure(org.xipki.console.karaf.CmdFailure) X500Principal(javax.security.auth.x500.X500Principal) EnrollmentResponse(org.jscep.client.EnrollmentResponse) Client(org.jscep.client.Client) File(java.io.File) X509Certificate(java.security.cert.X509Certificate) TransactionId(org.jscep.transaction.TransactionId)

Example 3 with Client

use of org.jscep.client.Client in project xipki by xipki.

the class EnrollCertAction method execute0.

@Override
protected Object execute0() throws Exception {
    Client client = getScepClient();
    PKCS10CertificationRequest csr = new PKCS10CertificationRequest(IoUtil.read(csrFile));
    EnrollmentResponse resp = requestCertificate(client, csr, getIdentityKey(), getIdentityCert());
    if (resp.isFailure()) {
        throw new CmdFailure("server returned 'failure'");
    }
    if (resp.isPending()) {
        throw new CmdFailure("server returned 'pending'");
    }
    X509Certificate cert = extractEeCerts(resp.getCertStore());
    if (cert == null) {
        throw new Exception("received no certificate");
    }
    saveVerbose("saved enrolled certificate to file", new File(outputFile), cert.getEncoded());
    return null;
}
Also used : PKCS10CertificationRequest(org.bouncycastle.pkcs.PKCS10CertificationRequest) CmdFailure(org.xipki.console.karaf.CmdFailure) EnrollmentResponse(org.jscep.client.EnrollmentResponse) Client(org.jscep.client.Client) File(java.io.File) X509Certificate(java.security.cert.X509Certificate) TransactionException(org.jscep.transaction.TransactionException) ClientException(org.jscep.client.ClientException)

Example 4 with Client

use of org.jscep.client.Client in project xipki by xipki.

the class ClientAction method getScepClient.

protected Client getScepClient() throws CertificateException, IOException {
    if (scepClient == null) {
        X509Certificate caCert = X509Util.parseCert(caCertFile);
        URL tmpUrl = new URL(url);
        scepClient = new Client(tmpUrl, new PreProvisionedCertificateVerifier(caCert));
    }
    return scepClient;
}
Also used : Client(org.jscep.client.Client) X509Certificate(java.security.cert.X509Certificate) URL(java.net.URL) PreProvisionedCertificateVerifier(org.jscep.client.verification.PreProvisionedCertificateVerifier)

Example 5 with Client

use of org.jscep.client.Client in project xipki by xipki.

the class GetCertCmd method execute0.

@Override
protected Object execute0() throws Exception {
    Client client = getScepClient();
    BigInteger serial = toBigInt(serialNumber);
    CertStore certs = client.getCertificate(getIdentityCert(), getIdentityKey(), serial, null);
    X509Certificate cert = extractEeCerts(certs);
    if (cert == null) {
        throw new CmdFailure("received no certificate from server");
    }
    saveVerbose("saved returned certificate to file", new File(outputFile), cert.getEncoded());
    return null;
}
Also used : CmdFailure(org.xipki.console.karaf.CmdFailure) BigInteger(java.math.BigInteger) Client(org.jscep.client.Client) CertStore(java.security.cert.CertStore) File(java.io.File) X509Certificate(java.security.cert.X509Certificate)

Aggregations

X509Certificate (java.security.cert.X509Certificate)5 Client (org.jscep.client.Client)5 File (java.io.File)4 CmdFailure (org.xipki.console.karaf.CmdFailure)4 PKCS10CertificationRequest (org.bouncycastle.pkcs.PKCS10CertificationRequest)2 EnrollmentResponse (org.jscep.client.EnrollmentResponse)2 BigInteger (java.math.BigInteger)1 URL (java.net.URL)1 CertStore (java.security.cert.CertStore)1 X509CRL (java.security.cert.X509CRL)1 X500Principal (javax.security.auth.x500.X500Principal)1 ClientException (org.jscep.client.ClientException)1 PreProvisionedCertificateVerifier (org.jscep.client.verification.PreProvisionedCertificateVerifier)1 TransactionException (org.jscep.transaction.TransactionException)1 TransactionId (org.jscep.transaction.TransactionId)1