Search in sources :

Example 1 with ActivateCertificateAuthorityRequest

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

the class ActivateSubordinateCa method activateSubordinateCA.

// Activate a subordinate CA.
// *Prerequisite*: Get the CSR of the subordinate CA signed by another CA. Pass in the signed
// certificate and (issuer CA's name or the issuer CA's Certificate chain).
// *Post*: After activating the subordinate CA, it should be enabled before issuing certificates.
public static void activateSubordinateCA(String project, String location, String pool_Id, String certificateAuthorityName, String subordinateCaName, String pemCACertificate) throws ExecutionException, InterruptedException, IOException {
    // clean up any remaining background resources.
    try (CertificateAuthorityServiceClient certificateAuthorityServiceClient = CertificateAuthorityServiceClient.create()) {
        // Subordinate CA parent.
        String subordinateCaParent = CertificateAuthorityName.of(project, location, pool_Id, subordinateCaName).toString();
        // Construct the "Activate CA Request".
        ActivateCertificateAuthorityRequest activateCertificateAuthorityRequest = ActivateCertificateAuthorityRequest.newBuilder().setName(subordinateCaParent).setPemCaCertificate(pemCACertificate).setSubordinateConfig(SubordinateConfig.newBuilder().setCertificateAuthority(CertificateAuthorityName.of(project, location, pool_Id, certificateAuthorityName).toString()).build()).build();
        // Activate the CA.
        ApiFuture<Operation> futureCall = certificateAuthorityServiceClient.activateCertificateAuthorityCallable().futureCall(activateCertificateAuthorityRequest);
        Operation response = futureCall.get();
        if (response.hasError()) {
            System.out.println("Error while activating the subordinate CA! " + response.getError());
            return;
        }
        System.out.println("Subordinate Certificate Authority activated successfully ! !" + subordinateCaName);
        TimeUnit.SECONDS.sleep(3);
        // The current state will be STAGED.
        // The Subordinate CA has to be ENABLED before issuing certificates.
        System.out.println("Current State: " + certificateAuthorityServiceClient.getCertificateAuthority(subordinateCaParent).getState());
    }
}
Also used : CertificateAuthorityServiceClient(com.google.cloud.security.privateca.v1.CertificateAuthorityServiceClient) Operation(com.google.longrunning.Operation) ActivateCertificateAuthorityRequest(com.google.cloud.security.privateca.v1.ActivateCertificateAuthorityRequest)

Aggregations

ActivateCertificateAuthorityRequest (com.google.cloud.security.privateca.v1.ActivateCertificateAuthorityRequest)1 CertificateAuthorityServiceClient (com.google.cloud.security.privateca.v1.CertificateAuthorityServiceClient)1 Operation (com.google.longrunning.Operation)1