Search in sources :

Example 1 with GenerateCRLException

use of org.hyperledger.fabric_ca.sdk.exception.GenerateCRLException in project fabric-sdk-java by hyperledger.

the class HFCAClient method generateCRL.

/**
 * Generate certificate revocation list.
 *
 * @param registrar     admin user configured in CA-server
 * @param revokedBefore Restrict certificates returned to revoked before this date if not null.
 * @param revokedAfter  Restrict certificates returned to revoked after this date if not null.
 * @param expireBefore  Restrict certificates returned to expired before this date if not null.
 * @param expireAfter   Restrict certificates returned to expired after this date if not null.
 * @throws InvalidArgumentException
 */
public String generateCRL(User registrar, Date revokedBefore, Date revokedAfter, Date expireBefore, Date expireAfter) throws InvalidArgumentException, GenerateCRLException {
    if (cryptoSuite == null) {
        throw new InvalidArgumentException("Crypto primitives not set.");
    }
    if (registrar == null) {
        throw new InvalidArgumentException("registrar is not set");
    }
    try {
        setUpSSL();
        // ---------------------------------------
        JsonObjectBuilder factory = Json.createObjectBuilder();
        if (revokedBefore != null) {
            factory.add("revokedBefore", toJson(revokedBefore));
        }
        if (revokedAfter != null) {
            factory.add("revokedAfter", toJson(revokedAfter));
        }
        if (expireBefore != null) {
            factory.add("expireBefore", toJson(expireBefore));
        }
        if (expireAfter != null) {
            factory.add("expireAfter", toJson(expireAfter));
        }
        if (caName != null) {
            factory.add(HFCAClient.FABRIC_CA_REQPROP, caName);
        }
        JsonObject jsonObject = factory.build();
        StringWriter stringWriter = new StringWriter();
        JsonWriter jsonWriter = Json.createWriter(new PrintWriter(stringWriter));
        jsonWriter.writeObject(jsonObject);
        jsonWriter.close();
        String body = stringWriter.toString();
        // ---------------------------------------
        // send revoke request
        JsonObject ret = httpPost(url + HFCA_GENCRL, body, registrar);
        return ret.getString("CRL");
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        throw new GenerateCRLException(e.getMessage(), e);
    }
}
Also used : GenerateCRLException(org.hyperledger.fabric_ca.sdk.exception.GenerateCRLException) InvalidArgumentException(org.hyperledger.fabric_ca.sdk.exception.InvalidArgumentException) StringWriter(java.io.StringWriter) JsonObject(javax.json.JsonObject) ASN1OctetString(org.bouncycastle.asn1.ASN1OctetString) JsonObjectBuilder(javax.json.JsonObjectBuilder) JsonWriter(javax.json.JsonWriter) InvalidArgumentException(org.hyperledger.fabric_ca.sdk.exception.InvalidArgumentException) URISyntaxException(java.net.URISyntaxException) RegistrationException(org.hyperledger.fabric_ca.sdk.exception.RegistrationException) KeyStoreException(java.security.KeyStoreException) AffiliationException(org.hyperledger.fabric_ca.sdk.exception.AffiliationException) GenerateCRLException(org.hyperledger.fabric_ca.sdk.exception.GenerateCRLException) KeyManagementException(java.security.KeyManagementException) IdentityException(org.hyperledger.fabric_ca.sdk.exception.IdentityException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) EnrollmentException(org.hyperledger.fabric_ca.sdk.exception.EnrollmentException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) RevocationException(org.hyperledger.fabric_ca.sdk.exception.RevocationException) ParseException(org.apache.http.ParseException) MalformedURLException(java.net.MalformedURLException) InfoException(org.hyperledger.fabric_ca.sdk.exception.InfoException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) HTTPException(org.hyperledger.fabric_ca.sdk.exception.HTTPException) PrintWriter(java.io.PrintWriter)

Aggregations

IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 KeyManagementException (java.security.KeyManagementException)1 KeyStoreException (java.security.KeyStoreException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 UnrecoverableKeyException (java.security.UnrecoverableKeyException)1 CertificateException (java.security.cert.CertificateException)1 JsonObject (javax.json.JsonObject)1 JsonObjectBuilder (javax.json.JsonObjectBuilder)1 JsonWriter (javax.json.JsonWriter)1 ParseException (org.apache.http.ParseException)1 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)1 AffiliationException (org.hyperledger.fabric_ca.sdk.exception.AffiliationException)1 EnrollmentException (org.hyperledger.fabric_ca.sdk.exception.EnrollmentException)1 GenerateCRLException (org.hyperledger.fabric_ca.sdk.exception.GenerateCRLException)1 HTTPException (org.hyperledger.fabric_ca.sdk.exception.HTTPException)1 IdentityException (org.hyperledger.fabric_ca.sdk.exception.IdentityException)1