Search in sources :

Example 1 with RevokeCertificateRequest

use of com.google.cloud.security.privateca.v1.RevokeCertificateRequest in project java-security-private-ca by googleapis.

the class RevokeCertificate method revokeCertificate.

// Revoke an issued certificate. Once revoked, the certificate will become invalid and will expire
// post its lifetime.
public static void revokeCertificate(String project, String location, String pool_Id, String certificateName) throws IOException, ExecutionException, InterruptedException {
    // clean up any remaining background resources.
    try (CertificateAuthorityServiceClient certificateAuthorityServiceClient = CertificateAuthorityServiceClient.create()) {
        // Create Certificate Name.
        CertificateName certificateNameParent = CertificateName.newBuilder().setProject(project).setLocation(location).setCaPool(pool_Id).setCertificate(certificateName).build();
        // Create Revoke Certificate Request and specify the appropriate revocation reason.
        RevokeCertificateRequest revokeCertificateRequest = RevokeCertificateRequest.newBuilder().setName(certificateNameParent.toString()).setReason(RevocationReason.PRIVILEGE_WITHDRAWN).build();
        // Revoke certificate.
        ApiFuture<Certificate> response = certificateAuthorityServiceClient.revokeCertificateCallable().futureCall(revokeCertificateRequest);
        Certificate certificateResponse = response.get();
        System.out.println("Certificate Revoked: " + certificateResponse.getName());
    }
}
Also used : CertificateAuthorityServiceClient(com.google.cloud.security.privateca.v1.CertificateAuthorityServiceClient) RevokeCertificateRequest(com.google.cloud.security.privateca.v1.RevokeCertificateRequest) CertificateName(com.google.cloud.security.privateca.v1.CertificateName) Certificate(com.google.cloud.security.privateca.v1.Certificate)

Aggregations

Certificate (com.google.cloud.security.privateca.v1.Certificate)1 CertificateAuthorityServiceClient (com.google.cloud.security.privateca.v1.CertificateAuthorityServiceClient)1 CertificateName (com.google.cloud.security.privateca.v1.CertificateName)1 RevokeCertificateRequest (com.google.cloud.security.privateca.v1.RevokeCertificateRequest)1