Chilkat Online Tools

DescribeCertificateAuthority C Example

AWS Private CA

#include <C_CkRest.h>
#include <C_CkAuthAws.h>
#include <C_CkJsonObject.h>
#include <C_CkStringBuilder.h>

void ChilkatSample(void)
    {
    HCkRest rest;
    BOOL success;
    HCkAuthAws authAws;
    HCkJsonObject json;
    HCkStringBuilder sbRequestBody;
    HCkStringBuilder sbResponseBody;
    int respStatusCode;
    HCkJsonObject jResp;
    const char *DirectoryNameCommonName;
    const char *DirectoryNameCountry;
    const char *DirectoryNameDistinguishedNameQualifier;
    const char *DirectoryNameGenerationQualifier;
    const char *DirectoryNameGivenName;
    const char *DirectoryNameInitials;
    const char *DirectoryNameLocality;
    const char *DirectoryNameOrganization;
    const char *DirectoryNameOrganizationalUnit;
    const char *DirectoryNamePseudonym;
    const char *DirectoryNameSerialNumber;
    const char *DirectoryNameState;
    const char *DirectoryNameSurname;
    const char *DirectoryNameTitle;
    const char *DnsName;
    const char *NameAssigner;
    const char *PartyName;
    const char *IpAddress;
    const char *TypeId;
    const char *Value;
    const char *RegisteredId;
    const char *Rfc822Name;
    const char *UniformResourceIdentifier;
    const char *AccessMethodType;
    const char *CustomObjectIdentifier;
    const char *Arn;
    int CRLSign;
    int DataEncipherment;
    int DecipherOnly;
    int DigitalSignature;
    int EncipherOnly;
    int KeyAgreement;
    int KeyCertSign;
    int KeyEncipherment;
    int NonRepudiation;
    const char *KeyAlgorithm;
    const char *SigningAlgorithm;
    const char *CommonName;
    const char *Country;
    const char *DistinguishedNameQualifier;
    const char *GenerationQualifier;
    const char *GivenName;
    const char *Initials;
    const char *Locality;
    const char *Organization;
    const char *OrganizationalUnit;
    const char *Pseudonym;
    const char *SerialNumber;
    const char *State;
    const char *Surname;
    const char *Title;
    int CreatedAt;
    const char *FailureReason;
    const char *KeyStorageSecurityStandard;
    int LastStateChangeAt;
    int NotAfter;
    int NotBefore;
    const char *OwnerAccount;
    int RestorableUntil;
    const char *CustomCname;
    int Enabled;
    int ExpirationInDays;
    const char *S3BucketName;
    const char *S3ObjectAcl;
    int OcspConfigurationEnabled;
    const char *OcspCustomCname;
    const char *Serial;
    const char *Status;
    const char *v_Type;
    int i;
    int count_i;

    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    rest = CkRest_Create();

    authAws = CkAuthAws_Create();
    CkAuthAws_putAccessKey(authAws,"AWS_ACCESS_KEY");
    CkAuthAws_putSecretKey(authAws,"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.)
    CkAuthAws_putRegion(authAws,"us-west-2");
    CkAuthAws_putServiceName(authAws,"acm-pca");
    // SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
    CkRest_SetAuthAws(rest,authAws);

    // URL: https://acm-pca.us-west-2.amazonaws.com/
    // Use the same region as specified above.
    success = CkRest_Connect(rest,"acm-pca.us-west-2.amazonaws.com",443,TRUE,TRUE);
    if (success != TRUE) {
        printf("ConnectFailReason: %d\n",CkRest_getConnectFailReason(rest));
        printf("%s\n",CkRest_lastErrorText(rest));
        CkRest_Dispose(rest);
        CkAuthAws_Dispose(authAws);
        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

    json = CkJsonObject_Create();
    CkJsonObject_UpdateString(json,"CertificateAuthorityArn","string");

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

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

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

    sbRequestBody = CkStringBuilder_Create();
    CkJsonObject_EmitSb(json,sbRequestBody);
    sbResponseBody = CkStringBuilder_Create();
    success = CkRest_FullRequestSb(rest,"POST","/",sbRequestBody,sbResponseBody);
    if (success != TRUE) {
        printf("%s\n",CkRest_lastErrorText(rest));
        CkRest_Dispose(rest);
        CkAuthAws_Dispose(authAws);
        CkJsonObject_Dispose(json);
        CkStringBuilder_Dispose(sbRequestBody);
        CkStringBuilder_Dispose(sbResponseBody);
        return;
    }

    respStatusCode = CkRest_getResponseStatusCode(rest);
    printf("response status code = %d\n",respStatusCode);
    if (respStatusCode != 200) {
        printf("Response Header:\n");
        printf("%s\n",CkRest_responseHeader(rest));
        printf("Response Body:\n");
        printf("%s\n",CkStringBuilder_getAsString(sbResponseBody));
        CkRest_Dispose(rest);
        CkAuthAws_Dispose(authAws);
        CkJsonObject_Dispose(json);
        CkStringBuilder_Dispose(sbRequestBody);
        CkStringBuilder_Dispose(sbResponseBody);
        return;
    }

    jResp = CkJsonObject_Create();
    CkJsonObject_LoadSb(jResp,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

    // Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.
    // See this example explaining how this memory should be used: const char * functions.

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


    CkRest_Dispose(rest);
    CkAuthAws_Dispose(authAws);
    CkJsonObject_Dispose(json);
    CkStringBuilder_Dispose(sbRequestBody);
    CkStringBuilder_Dispose(sbResponseBody);
    CkJsonObject_Dispose(jResp);

    }