Chilkat Online Tools

DescribeCertificateAuthority Objective-C Example

AWS Private CA

#import <CkoRest.h>
#import <CkoAuthAws.h>
#import <CkoJsonObject.h>
#import <CkoStringBuilder.h>
#import <NSString.h>

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

CkoRest *rest = [[CkoRest alloc] init];
BOOL success;

CkoAuthAws *authAws = [[CkoAuthAws alloc] init];
authAws.AccessKey = @"AWS_ACCESS_KEY";
authAws.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.Region = @"us-west-2";
authAws.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" port: [NSNumber numberWithInt: 443] tls: YES autoReconnect: YES];
if (success != YES) {
    NSLog(@"%@%d",@"ConnectFailReason: ",[rest.ConnectFailReason intValue]);
    NSLog(@"%@",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

CkoJsonObject *json = [[CkoJsonObject alloc] init];
[json UpdateString: @"CertificateAuthorityArn" value: @"string"];

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

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

[rest AddHeader: @"Content-Type" value: @"application/x-amz-json-1.1"];
[rest AddHeader: @"X-Amz-Target" value: @"ACMPrivateCA.DescribeCertificateAuthority"];

CkoStringBuilder *sbRequestBody = [[CkoStringBuilder alloc] init];
[json EmitSb: sbRequestBody];
CkoStringBuilder *sbResponseBody = [[CkoStringBuilder alloc] init];
success = [rest FullRequestSb: @"POST" uriPath: @"/" requestBody: sbRequestBody responseBody: sbResponseBody];
if (success != YES) {
    NSLog(@"%@",rest.LastErrorText);
    return;
}

int respStatusCode = [rest.ResponseStatusCode intValue];
NSLog(@"%@%d",@"response status code = ",respStatusCode);
if (respStatusCode != 200) {
    NSLog(@"%@",@"Response Header:");
    NSLog(@"%@",rest.ResponseHeader);
    NSLog(@"%@",@"Response Body:");
    NSLog(@"%@",[sbResponseBody GetAsString]);
    return;
}

CkoJsonObject *jResp = [[CkoJsonObject alloc] init];
[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

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

NSString *Arn = [jResp StringOf: @"CertificateAuthority.Arn"];
int CRLSign = [[jResp IntOf: @"CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.CRLSign"] intValue];
int DataEncipherment = [[jResp IntOf: @"CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.DataEncipherment"] intValue];
int DecipherOnly = [[jResp IntOf: @"CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.DecipherOnly"] intValue];
int DigitalSignature = [[jResp IntOf: @"CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.DigitalSignature"] intValue];
int EncipherOnly = [[jResp IntOf: @"CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.EncipherOnly"] intValue];
int KeyAgreement = [[jResp IntOf: @"CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.KeyAgreement"] intValue];
int KeyCertSign = [[jResp IntOf: @"CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.KeyCertSign"] intValue];
int KeyEncipherment = [[jResp IntOf: @"CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.KeyEncipherment"] intValue];
int NonRepudiation = [[jResp IntOf: @"CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.NonRepudiation"] intValue];
NSString *KeyAlgorithm = [jResp StringOf: @"CertificateAuthority.CertificateAuthorityConfiguration.KeyAlgorithm"];
NSString *SigningAlgorithm = [jResp StringOf: @"CertificateAuthority.CertificateAuthorityConfiguration.SigningAlgorithm"];
NSString *CommonName = [jResp StringOf: @"CertificateAuthority.CertificateAuthorityConfiguration.Subject.CommonName"];
NSString *Country = [jResp StringOf: @"CertificateAuthority.CertificateAuthorityConfiguration.Subject.Country"];
NSString *DistinguishedNameQualifier = [jResp StringOf: @"CertificateAuthority.CertificateAuthorityConfiguration.Subject.DistinguishedNameQualifier"];
NSString *GenerationQualifier = [jResp StringOf: @"CertificateAuthority.CertificateAuthorityConfiguration.Subject.GenerationQualifier"];
NSString *GivenName = [jResp StringOf: @"CertificateAuthority.CertificateAuthorityConfiguration.Subject.GivenName"];
NSString *Initials = [jResp StringOf: @"CertificateAuthority.CertificateAuthorityConfiguration.Subject.Initials"];
NSString *Locality = [jResp StringOf: @"CertificateAuthority.CertificateAuthorityConfiguration.Subject.Locality"];
NSString *Organization = [jResp StringOf: @"CertificateAuthority.CertificateAuthorityConfiguration.Subject.Organization"];
NSString *OrganizationalUnit = [jResp StringOf: @"CertificateAuthority.CertificateAuthorityConfiguration.Subject.OrganizationalUnit"];
NSString *Pseudonym = [jResp StringOf: @"CertificateAuthority.CertificateAuthorityConfiguration.Subject.Pseudonym"];
NSString *SerialNumber = [jResp StringOf: @"CertificateAuthority.CertificateAuthorityConfiguration.Subject.SerialNumber"];
NSString *State = [jResp StringOf: @"CertificateAuthority.CertificateAuthorityConfiguration.Subject.State"];
NSString *Surname = [jResp StringOf: @"CertificateAuthority.CertificateAuthorityConfiguration.Subject.Surname"];
NSString *Title = [jResp StringOf: @"CertificateAuthority.CertificateAuthorityConfiguration.Subject.Title"];
int CreatedAt = [[jResp IntOf: @"CertificateAuthority.CreatedAt"] intValue];
NSString *FailureReason = [jResp StringOf: @"CertificateAuthority.FailureReason"];
NSString *KeyStorageSecurityStandard = [jResp StringOf: @"CertificateAuthority.KeyStorageSecurityStandard"];
int LastStateChangeAt = [[jResp IntOf: @"CertificateAuthority.LastStateChangeAt"] intValue];
int NotAfter = [[jResp IntOf: @"CertificateAuthority.NotAfter"] intValue];
int NotBefore = [[jResp IntOf: @"CertificateAuthority.NotBefore"] intValue];
NSString *OwnerAccount = [jResp StringOf: @"CertificateAuthority.OwnerAccount"];
int RestorableUntil = [[jResp IntOf: @"CertificateAuthority.RestorableUntil"] intValue];
NSString *CustomCname = [jResp StringOf: @"CertificateAuthority.RevocationConfiguration.CrlConfiguration.CustomCname"];
int Enabled = [[jResp IntOf: @"CertificateAuthority.RevocationConfiguration.CrlConfiguration.Enabled"] intValue];
int ExpirationInDays = [[jResp IntOf: @"CertificateAuthority.RevocationConfiguration.CrlConfiguration.ExpirationInDays"] intValue];
NSString *S3BucketName = [jResp StringOf: @"CertificateAuthority.RevocationConfiguration.CrlConfiguration.S3BucketName"];
NSString *S3ObjectAcl = [jResp StringOf: @"CertificateAuthority.RevocationConfiguration.CrlConfiguration.S3ObjectAcl"];
int OcspConfigurationEnabled = [[jResp IntOf: @"CertificateAuthority.RevocationConfiguration.OcspConfiguration.Enabled"] intValue];
NSString *OcspCustomCname = [jResp StringOf: @"CertificateAuthority.RevocationConfiguration.OcspConfiguration.OcspCustomCname"];
NSString *Serial = [jResp StringOf: @"CertificateAuthority.Serial"];
NSString *Status = [jResp StringOf: @"CertificateAuthority.Status"];
NSString *v_Type = [jResp StringOf: @"CertificateAuthority.Type"];
int i = 0;
int count_i = [[jResp SizeOfArray: @"CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess"] intValue];
while (i < count_i) {
    jResp.I = [NSNumber numberWithInt: 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"
//   }
// }