Chilkat Online Tools

DescribeCertificateAuthority Java Example

AWS Private CA

import com.chilkatsoft.*;

public class ChilkatExample {

  static {
    try {
        System.loadLibrary("chilkat");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }

  public static void main(String argv[])
  {
    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    CkRest rest = new CkRest();
    boolean success;

    CkAuthAws authAws = new CkAuthAws();
    authAws.put_AccessKey("AWS_ACCESS_KEY");
    authAws.put_SecretKey("AWS_SECRET_KEY");

    // Don't forget to change the region to your particular region. (Also make the same change in the call to Connect below.)
    authAws.put_Region("us-west-2");
    authAws.put_ServiceName("acm-pca");
    // SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
    rest.SetAuthAws(authAws);

    // URL: https://acm-pca.us-west-2.amazonaws.com/
    // Use the same region as specified above.
    success = rest.Connect("acm-pca.us-west-2.amazonaws.com",443,true,true);
    if (success != true) {
        System.out.println("ConnectFailReason: " + rest.get_ConnectFailReason());
        System.out.println(rest.lastErrorText());
        return;
        }

    // The following code creates the JSON request body.
    // The JSON created by this code is shown below.

    // Use this online tool to generate code from sample JSON:
    // Generate Code to Create JSON

    CkJsonObject json = new CkJsonObject();
    json.UpdateString("CertificateAuthorityArn","string");

    // The JSON request body created by the above code:

    // {
    //   "CertificateAuthorityArn": "string"
    // }

    rest.AddHeader("Content-Type","application/x-amz-json-1.1");
    rest.AddHeader("X-Amz-Target","ACMPrivateCA.DescribeCertificateAuthority");

    CkStringBuilder sbRequestBody = new CkStringBuilder();
    json.EmitSb(sbRequestBody);
    CkStringBuilder sbResponseBody = new CkStringBuilder();
    success = rest.FullRequestSb("POST","/",sbRequestBody,sbResponseBody);
    if (success != true) {
        System.out.println(rest.lastErrorText());
        return;
        }

    int respStatusCode = rest.get_ResponseStatusCode();
    System.out.println("response status code = " + respStatusCode);
    if (respStatusCode != 200) {
        System.out.println("Response Header:");
        System.out.println(rest.responseHeader());
        System.out.println("Response Body:");
        System.out.println(sbResponseBody.getAsString());
        return;
        }

    CkJsonObject jResp = new CkJsonObject();
    jResp.LoadSb(sbResponseBody);

    // The following code parses the JSON response.
    // A sample JSON response is shown below the sample code.

    // Use this online tool to generate parsing code from sample JSON:
    // Generate Parsing Code from JSON

    String DirectoryNameCommonName;
    String DirectoryNameCountry;
    String DirectoryNameDistinguishedNameQualifier;
    String DirectoryNameGenerationQualifier;
    String DirectoryNameGivenName;
    String DirectoryNameInitials;
    String DirectoryNameLocality;
    String DirectoryNameOrganization;
    String DirectoryNameOrganizationalUnit;
    String DirectoryNamePseudonym;
    String DirectoryNameSerialNumber;
    String DirectoryNameState;
    String DirectoryNameSurname;
    String DirectoryNameTitle;
    String DnsName;
    String NameAssigner;
    String PartyName;
    String IpAddress;
    String TypeId;
    String Value;
    String RegisteredId;
    String Rfc822Name;
    String UniformResourceIdentifier;
    String AccessMethodType;
    String CustomObjectIdentifier;

    String Arn = jResp.stringOf("CertificateAuthority.Arn");
    int CRLSign = jResp.IntOf("CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.CRLSign");
    int DataEncipherment = jResp.IntOf("CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.DataEncipherment");
    int DecipherOnly = jResp.IntOf("CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.DecipherOnly");
    int DigitalSignature = jResp.IntOf("CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.DigitalSignature");
    int EncipherOnly = jResp.IntOf("CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.EncipherOnly");
    int KeyAgreement = jResp.IntOf("CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.KeyAgreement");
    int KeyCertSign = jResp.IntOf("CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.KeyCertSign");
    int KeyEncipherment = jResp.IntOf("CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.KeyEncipherment");
    int NonRepudiation = jResp.IntOf("CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.NonRepudiation");
    String KeyAlgorithm = jResp.stringOf("CertificateAuthority.CertificateAuthorityConfiguration.KeyAlgorithm");
    String SigningAlgorithm = jResp.stringOf("CertificateAuthority.CertificateAuthorityConfiguration.SigningAlgorithm");
    String CommonName = jResp.stringOf("CertificateAuthority.CertificateAuthorityConfiguration.Subject.CommonName");
    String Country = jResp.stringOf("CertificateAuthority.CertificateAuthorityConfiguration.Subject.Country");
    String DistinguishedNameQualifier = jResp.stringOf("CertificateAuthority.CertificateAuthorityConfiguration.Subject.DistinguishedNameQualifier");
    String GenerationQualifier = jResp.stringOf("CertificateAuthority.CertificateAuthorityConfiguration.Subject.GenerationQualifier");
    String GivenName = jResp.stringOf("CertificateAuthority.CertificateAuthorityConfiguration.Subject.GivenName");
    String Initials = jResp.stringOf("CertificateAuthority.CertificateAuthorityConfiguration.Subject.Initials");
    String Locality = jResp.stringOf("CertificateAuthority.CertificateAuthorityConfiguration.Subject.Locality");
    String Organization = jResp.stringOf("CertificateAuthority.CertificateAuthorityConfiguration.Subject.Organization");
    String OrganizationalUnit = jResp.stringOf("CertificateAuthority.CertificateAuthorityConfiguration.Subject.OrganizationalUnit");
    String Pseudonym = jResp.stringOf("CertificateAuthority.CertificateAuthorityConfiguration.Subject.Pseudonym");
    String SerialNumber = jResp.stringOf("CertificateAuthority.CertificateAuthorityConfiguration.Subject.SerialNumber");
    String State = jResp.stringOf("CertificateAuthority.CertificateAuthorityConfiguration.Subject.State");
    String Surname = jResp.stringOf("CertificateAuthority.CertificateAuthorityConfiguration.Subject.Surname");
    String Title = jResp.stringOf("CertificateAuthority.CertificateAuthorityConfiguration.Subject.Title");
    int CreatedAt = jResp.IntOf("CertificateAuthority.CreatedAt");
    String FailureReason = jResp.stringOf("CertificateAuthority.FailureReason");
    String KeyStorageSecurityStandard = jResp.stringOf("CertificateAuthority.KeyStorageSecurityStandard");
    int LastStateChangeAt = jResp.IntOf("CertificateAuthority.LastStateChangeAt");
    int NotAfter = jResp.IntOf("CertificateAuthority.NotAfter");
    int NotBefore = jResp.IntOf("CertificateAuthority.NotBefore");
    String OwnerAccount = jResp.stringOf("CertificateAuthority.OwnerAccount");
    int RestorableUntil = jResp.IntOf("CertificateAuthority.RestorableUntil");
    String CustomCname = jResp.stringOf("CertificateAuthority.RevocationConfiguration.CrlConfiguration.CustomCname");
    int Enabled = jResp.IntOf("CertificateAuthority.RevocationConfiguration.CrlConfiguration.Enabled");
    int ExpirationInDays = jResp.IntOf("CertificateAuthority.RevocationConfiguration.CrlConfiguration.ExpirationInDays");
    String S3BucketName = jResp.stringOf("CertificateAuthority.RevocationConfiguration.CrlConfiguration.S3BucketName");
    String S3ObjectAcl = jResp.stringOf("CertificateAuthority.RevocationConfiguration.CrlConfiguration.S3ObjectAcl");
    int OcspConfigurationEnabled = jResp.IntOf("CertificateAuthority.RevocationConfiguration.OcspConfiguration.Enabled");
    String OcspCustomCname = jResp.stringOf("CertificateAuthority.RevocationConfiguration.OcspConfiguration.OcspCustomCname");
    String Serial = jResp.stringOf("CertificateAuthority.Serial");
    String Status = jResp.stringOf("CertificateAuthority.Status");
    String v_Type = jResp.stringOf("CertificateAuthority.Type");
    int i = 0;
    int count_i = jResp.SizeOfArray("CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess");
    while (i < count_i) {
        jResp.put_I(i);
        DirectoryNameCommonName = jResp.stringOf("CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[i].AccessLocation.DirectoryName.CommonName");
        DirectoryNameCountry = jResp.stringOf("CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[i].AccessLocation.DirectoryName.Country");
        DirectoryNameDistinguishedNameQualifier = jResp.stringOf("CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[i].AccessLocation.DirectoryName.DistinguishedNameQualifier");
        DirectoryNameGenerationQualifier = jResp.stringOf("CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[i].AccessLocation.DirectoryName.GenerationQualifier");
        DirectoryNameGivenName = jResp.stringOf("CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[i].AccessLocation.DirectoryName.GivenName");
        DirectoryNameInitials = jResp.stringOf("CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[i].AccessLocation.DirectoryName.Initials");
        DirectoryNameLocality = jResp.stringOf("CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[i].AccessLocation.DirectoryName.Locality");
        DirectoryNameOrganization = jResp.stringOf("CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[i].AccessLocation.DirectoryName.Organization");
        DirectoryNameOrganizationalUnit = jResp.stringOf("CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[i].AccessLocation.DirectoryName.OrganizationalUnit");
        DirectoryNamePseudonym = jResp.stringOf("CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[i].AccessLocation.DirectoryName.Pseudonym");
        DirectoryNameSerialNumber = jResp.stringOf("CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[i].AccessLocation.DirectoryName.SerialNumber");
        DirectoryNameState = jResp.stringOf("CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[i].AccessLocation.DirectoryName.State");
        DirectoryNameSurname = jResp.stringOf("CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[i].AccessLocation.DirectoryName.Surname");
        DirectoryNameTitle = jResp.stringOf("CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[i].AccessLocation.DirectoryName.Title");
        DnsName = jResp.stringOf("CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[i].AccessLocation.DnsName");
        NameAssigner = jResp.stringOf("CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[i].AccessLocation.EdiPartyName.NameAssigner");
        PartyName = jResp.stringOf("CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[i].AccessLocation.EdiPartyName.PartyName");
        IpAddress = jResp.stringOf("CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[i].AccessLocation.IpAddress");
        TypeId = jResp.stringOf("CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[i].AccessLocation.OtherName.TypeId");
        Value = jResp.stringOf("CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[i].AccessLocation.OtherName.Value");
        RegisteredId = jResp.stringOf("CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[i].AccessLocation.RegisteredId");
        Rfc822Name = jResp.stringOf("CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[i].AccessLocation.Rfc822Name");
        UniformResourceIdentifier = jResp.stringOf("CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[i].AccessLocation.UniformResourceIdentifier");
        AccessMethodType = jResp.stringOf("CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[i].AccessMethod.AccessMethodType");
        CustomObjectIdentifier = jResp.stringOf("CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[i].AccessMethod.CustomObjectIdentifier");
        i = i+1;
        }

    // A sample JSON response body parsed by the above code:

    // {
    //   "CertificateAuthority": {
    //     "Arn": "string",
    //     "CertificateAuthorityConfiguration": {
    //       "CsrExtensions": {
    //         "KeyUsage": {
    //           "CRLSign": boolean,
    //           "DataEncipherment": boolean,
    //           "DecipherOnly": boolean,
    //           "DigitalSignature": boolean,
    //           "EncipherOnly": boolean,
    //           "KeyAgreement": boolean,
    //           "KeyCertSign": boolean,
    //           "KeyEncipherment": boolean,
    //           "NonRepudiation": boolean
    //         },
    //         "SubjectInformationAccess": [
    //           {
    //             "AccessLocation": {
    //               "DirectoryName": {
    //                 "CommonName": "string",
    //                 "Country": "string",
    //                 "DistinguishedNameQualifier": "string",
    //                 "GenerationQualifier": "string",
    //                 "GivenName": "string",
    //                 "Initials": "string",
    //                 "Locality": "string",
    //                 "Organization": "string",
    //                 "OrganizationalUnit": "string",
    //                 "Pseudonym": "string",
    //                 "SerialNumber": "string",
    //                 "State": "string",
    //                 "Surname": "string",
    //                 "Title": "string"
    //               },
    //               "DnsName": "string",
    //               "EdiPartyName": {
    //                 "NameAssigner": "string",
    //                 "PartyName": "string"
    //               },
    //               "IpAddress": "string",
    //               "OtherName": {
    //                 "TypeId": "string",
    //                 "Value": "string"
    //               },
    //               "RegisteredId": "string",
    //               "Rfc822Name": "string",
    //               "UniformResourceIdentifier": "string"
    //             },
    //             "AccessMethod": {
    //               "AccessMethodType": "string",
    //               "CustomObjectIdentifier": "string"
    //             }
    //           }
    //         ]
    //       },
    //       "KeyAlgorithm": "string",
    //       "SigningAlgorithm": "string",
    //       "Subject": {
    //         "CommonName": "string",
    //         "Country": "string",
    //         "DistinguishedNameQualifier": "string",
    //         "GenerationQualifier": "string",
    //         "GivenName": "string",
    //         "Initials": "string",
    //         "Locality": "string",
    //         "Organization": "string",
    //         "OrganizationalUnit": "string",
    //         "Pseudonym": "string",
    //         "SerialNumber": "string",
    //         "State": "string",
    //         "Surname": "string",
    //         "Title": "string"
    //       }
    //     },
    //     "CreatedAt": number,
    //     "FailureReason": "string",
    //     "KeyStorageSecurityStandard": "string",
    //     "LastStateChangeAt": number,
    //     "NotAfter": number,
    //     "NotBefore": number,
    //     "OwnerAccount": "string",
    //     "RestorableUntil": number,
    //     "RevocationConfiguration": {
    //       "CrlConfiguration": {
    //         "CustomCname": "string",
    //         "Enabled": boolean,
    //         "ExpirationInDays": number,
    //         "S3BucketName": "string",
    //         "S3ObjectAcl": "string"
    //       },
    //       "OcspConfiguration": {
    //         "Enabled": boolean,
    //         "OcspCustomCname": "string"
    //       }
    //     },
    //     "Serial": "string",
    //     "Status": "string",
    //     "Type": "string"
    //   }
    // }
  }
}