Chilkat Online Tools

DescribeCertificateAuthority unicodeC Example

AWS Private CA

#include <C_CkRestW.h>
#include <C_CkAuthAwsW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkStringBuilderW.h>

void ChilkatSample(void)
    {
    HCkRestW rest;
    BOOL success;
    HCkAuthAwsW authAws;
    HCkJsonObjectW json;
    HCkStringBuilderW sbRequestBody;
    HCkStringBuilderW sbResponseBody;
    int respStatusCode;
    HCkJsonObjectW jResp;
    const wchar_t *DirectoryNameCommonName;
    const wchar_t *DirectoryNameCountry;
    const wchar_t *DirectoryNameDistinguishedNameQualifier;
    const wchar_t *DirectoryNameGenerationQualifier;
    const wchar_t *DirectoryNameGivenName;
    const wchar_t *DirectoryNameInitials;
    const wchar_t *DirectoryNameLocality;
    const wchar_t *DirectoryNameOrganization;
    const wchar_t *DirectoryNameOrganizationalUnit;
    const wchar_t *DirectoryNamePseudonym;
    const wchar_t *DirectoryNameSerialNumber;
    const wchar_t *DirectoryNameState;
    const wchar_t *DirectoryNameSurname;
    const wchar_t *DirectoryNameTitle;
    const wchar_t *DnsName;
    const wchar_t *NameAssigner;
    const wchar_t *PartyName;
    const wchar_t *IpAddress;
    const wchar_t *TypeId;
    const wchar_t *Value;
    const wchar_t *RegisteredId;
    const wchar_t *Rfc822Name;
    const wchar_t *UniformResourceIdentifier;
    const wchar_t *AccessMethodType;
    const wchar_t *CustomObjectIdentifier;
    const wchar_t *Arn;
    int CRLSign;
    int DataEncipherment;
    int DecipherOnly;
    int DigitalSignature;
    int EncipherOnly;
    int KeyAgreement;
    int KeyCertSign;
    int KeyEncipherment;
    int NonRepudiation;
    const wchar_t *KeyAlgorithm;
    const wchar_t *SigningAlgorithm;
    const wchar_t *CommonName;
    const wchar_t *Country;
    const wchar_t *DistinguishedNameQualifier;
    const wchar_t *GenerationQualifier;
    const wchar_t *GivenName;
    const wchar_t *Initials;
    const wchar_t *Locality;
    const wchar_t *Organization;
    const wchar_t *OrganizationalUnit;
    const wchar_t *Pseudonym;
    const wchar_t *SerialNumber;
    const wchar_t *State;
    const wchar_t *Surname;
    const wchar_t *Title;
    int CreatedAt;
    const wchar_t *FailureReason;
    const wchar_t *KeyStorageSecurityStandard;
    int LastStateChangeAt;
    int NotAfter;
    int NotBefore;
    const wchar_t *OwnerAccount;
    int RestorableUntil;
    const wchar_t *CustomCname;
    int Enabled;
    int ExpirationInDays;
    const wchar_t *S3BucketName;
    const wchar_t *S3ObjectAcl;
    int OcspConfigurationEnabled;
    const wchar_t *OcspCustomCname;
    const wchar_t *Serial;
    const wchar_t *Status;
    const wchar_t *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 = CkRestW_Create();

    authAws = CkAuthAwsW_Create();
    CkAuthAwsW_putAccessKey(authAws,L"AWS_ACCESS_KEY");
    CkAuthAwsW_putSecretKey(authAws,L"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.)
    CkAuthAwsW_putRegion(authAws,L"us-west-2");
    CkAuthAwsW_putServiceName(authAws,L"acm-pca");
    // SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
    CkRestW_SetAuthAws(rest,authAws);

    // URL: https://acm-pca.us-west-2.amazonaws.com/
    // Use the same region as specified above.
    success = CkRestW_Connect(rest,L"acm-pca.us-west-2.amazonaws.com",443,TRUE,TRUE);
    if (success != TRUE) {
        wprintf(L"ConnectFailReason: %d\n",CkRestW_getConnectFailReason(rest));
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkRestW_Dispose(rest);
        CkAuthAwsW_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 = CkJsonObjectW_Create();
    CkJsonObjectW_UpdateString(json,L"CertificateAuthorityArn",L"string");

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

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

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

    sbRequestBody = CkStringBuilderW_Create();
    CkJsonObjectW_EmitSb(json,sbRequestBody);
    sbResponseBody = CkStringBuilderW_Create();
    success = CkRestW_FullRequestSb(rest,L"POST",L"/",sbRequestBody,sbResponseBody);
    if (success != TRUE) {
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkRestW_Dispose(rest);
        CkAuthAwsW_Dispose(authAws);
        CkJsonObjectW_Dispose(json);
        CkStringBuilderW_Dispose(sbRequestBody);
        CkStringBuilderW_Dispose(sbResponseBody);
        return;
    }

    respStatusCode = CkRestW_getResponseStatusCode(rest);
    wprintf(L"response status code = %d\n",respStatusCode);
    if (respStatusCode != 200) {
        wprintf(L"Response Header:\n");
        wprintf(L"%s\n",CkRestW_responseHeader(rest));
        wprintf(L"Response Body:\n");
        wprintf(L"%s\n",CkStringBuilderW_getAsString(sbResponseBody));
        CkRestW_Dispose(rest);
        CkAuthAwsW_Dispose(authAws);
        CkJsonObjectW_Dispose(json);
        CkStringBuilderW_Dispose(sbRequestBody);
        CkStringBuilderW_Dispose(sbResponseBody);
        return;
    }

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


    CkRestW_Dispose(rest);
    CkAuthAwsW_Dispose(authAws);
    CkJsonObjectW_Dispose(json);
    CkStringBuilderW_Dispose(sbRequestBody);
    CkStringBuilderW_Dispose(sbResponseBody);
    CkJsonObjectW_Dispose(jResp);

    }