Search in sources :

Example 1 with RestCaClient

use of org.xipki.litecaclient.RestCaClient in project xipki by xipki.

the class RestCaClientExample method main.

public static void main(String[] args) {
    // System.setProperty("javax.net.debug", "all");
    try {
        RestCaClient client = new RestCaClient(CA_URL, USER, PASSWORD);
        client.init();
        // retrieve CA certificate
        printCert("===== CA Certificate (REST) =====", client.getCaCert());
        // Enroll certificate - RSA
        MyKeypair kp = generateRsaKeypair();
        CertificationRequest csr = genCsr(kp, getSubject());
        X509Certificate cert = client.requestCert(CERT_PROFILE, csr);
        printCert("===== RSA (REST) =====", cert);
        // Enroll certificate - EC
        kp = generateEcKeypair();
        csr = genCsr(kp, getSubject());
        cert = client.requestCert(CERT_PROFILE, csr);
        printCert("===== EC (REST) =====", cert);
        // Enroll certificate - DSA
        kp = generateDsaKeypair();
        csr = genCsr(kp, getSubject());
        cert = client.requestCert(CERT_PROFILE, csr);
        printCert("===== DSA =====", cert);
        BigInteger serialNumber = cert.getSerialNumber();
        // Suspend certificate
        boolean flag = client.revokeCert(serialNumber, CRLReason.lookup(CRLReason.certificateHold));
        if (flag) {
            System.out.println("(REST) suspended certificate");
        } else {
            System.err.println("(REST) suspending certificate failed");
        }
        // Unsuspend certificate
        flag = client.revokeCert(serialNumber, CRLReason.lookup(CRLReason.removeFromCRL));
        if (flag) {
            System.out.println("(REST) unsuspended certificate");
        } else {
            System.err.println("(REST) unsuspending certificate failed");
        }
        // Revoke certificate
        flag = client.revokeCert(serialNumber, CRLReason.lookup(CRLReason.keyCompromise));
        if (flag) {
            System.out.println("(REST) revoked certificate");
        } else {
            System.err.println("(REST) revoking certificate failed");
        }
        client.shutdown();
    } catch (Exception ex) {
        ex.printStackTrace();
        System.exit(-1);
    }
}
Also used : RestCaClient(org.xipki.litecaclient.RestCaClient) BigInteger(java.math.BigInteger) CertificationRequest(org.bouncycastle.asn1.pkcs.CertificationRequest) X509Certificate(java.security.cert.X509Certificate)

Aggregations

BigInteger (java.math.BigInteger)1 X509Certificate (java.security.cert.X509Certificate)1 CertificationRequest (org.bouncycastle.asn1.pkcs.CertificationRequest)1 RestCaClient (org.xipki.litecaclient.RestCaClient)1