Chilkat Online Tools

DescribeCertificate Objective-C Example

AWS Certificate Manager

#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";
// SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
[rest SetAuthAws: authAws];

// URL: https://acm.us-west-2.amazonaws.com/
// Use the same region as specified above.
success = [rest Connect: @"acm.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: @"CertificateArn" value: @"string"];

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

// {
//   "CertificateArn": "string"
// }

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

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 *Name = 0;
NSString *ResourceRecordType = 0;
NSString *Value = 0;
NSString *ValidationDomain = 0;
NSString *ValidationMethod = 0;
NSString *ValidationStatus = 0;
int j;
int count_j;
NSString *strVal = 0;
NSString *OID = 0;
NSString *ResourceRecordName = 0;
NSString *ResourceRecordValue = 0;

NSString *CertificateArn = [jResp StringOf: @"Certificate.CertificateArn"];
NSString *CertificateAuthorityArn = [jResp StringOf: @"Certificate.CertificateAuthorityArn"];
int CreatedAt = [[jResp IntOf: @"Certificate.CreatedAt"] intValue];
NSString *DomainName = [jResp StringOf: @"Certificate.DomainName"];
NSString *FailureReason = [jResp StringOf: @"Certificate.FailureReason"];
int ImportedAt = [[jResp IntOf: @"Certificate.ImportedAt"] intValue];
int IssuedAt = [[jResp IntOf: @"Certificate.IssuedAt"] intValue];
NSString *Issuer = [jResp StringOf: @"Certificate.Issuer"];
NSString *KeyAlgorithm = [jResp StringOf: @"Certificate.KeyAlgorithm"];
int NotAfter = [[jResp IntOf: @"Certificate.NotAfter"] intValue];
int NotBefore = [[jResp IntOf: @"Certificate.NotBefore"] intValue];
NSString *CertificateTransparencyLoggingPreference = [jResp StringOf: @"Certificate.Options.CertificateTransparencyLoggingPreference"];
NSString *RenewalEligibility = [jResp StringOf: @"Certificate.RenewalEligibility"];
NSString *RenewalStatus = [jResp StringOf: @"Certificate.RenewalSummary.RenewalStatus"];
NSString *RenewalStatusReason = [jResp StringOf: @"Certificate.RenewalSummary.RenewalStatusReason"];
int UpdatedAt = [[jResp IntOf: @"Certificate.RenewalSummary.UpdatedAt"] intValue];
NSString *RevocationReason = [jResp StringOf: @"Certificate.RevocationReason"];
int RevokedAt = [[jResp IntOf: @"Certificate.RevokedAt"] intValue];
NSString *Serial = [jResp StringOf: @"Certificate.Serial"];
NSString *SignatureAlgorithm = [jResp StringOf: @"Certificate.SignatureAlgorithm"];
NSString *Status = [jResp StringOf: @"Certificate.Status"];
NSString *Subject = [jResp StringOf: @"Certificate.Subject"];
NSString *v_Type = [jResp StringOf: @"Certificate.Type"];
int i = 0;
int count_i = [[jResp SizeOfArray: @"Certificate.DomainValidationOptions"] intValue];
while (i < count_i) {
    jResp.I = [NSNumber numberWithInt: i];
    DomainName = [jResp StringOf: @"Certificate.DomainValidationOptions[i].DomainName"];
    Name = [jResp StringOf: @"Certificate.DomainValidationOptions[i].ResourceRecord.Name"];
    ResourceRecordType = [jResp StringOf: @"Certificate.DomainValidationOptions[i].ResourceRecord.Type"];
    Value = [jResp StringOf: @"Certificate.DomainValidationOptions[i].ResourceRecord.Value"];
    ValidationDomain = [jResp StringOf: @"Certificate.DomainValidationOptions[i].ValidationDomain"];
    ValidationMethod = [jResp StringOf: @"Certificate.DomainValidationOptions[i].ValidationMethod"];
    ValidationStatus = [jResp StringOf: @"Certificate.DomainValidationOptions[i].ValidationStatus"];
    j = 0;
    count_j = [[jResp SizeOfArray: @"Certificate.DomainValidationOptions[i].ValidationEmails"] intValue];
    while (j < count_j) {
        jResp.J = [NSNumber numberWithInt: j];
        strVal = [jResp StringOf: @"Certificate.DomainValidationOptions[i].ValidationEmails[j]"];
        j = j + 1;
    }

    i = i + 1;
}

i = 0;
count_i = [[jResp SizeOfArray: @"Certificate.ExtendedKeyUsages"] intValue];
while (i < count_i) {
    jResp.I = [NSNumber numberWithInt: i];
    Name = [jResp StringOf: @"Certificate.ExtendedKeyUsages[i].Name"];
    OID = [jResp StringOf: @"Certificate.ExtendedKeyUsages[i].OID"];
    i = i + 1;
}

i = 0;
count_i = [[jResp SizeOfArray: @"Certificate.InUseBy"] intValue];
while (i < count_i) {
    jResp.I = [NSNumber numberWithInt: i];
    strVal = [jResp StringOf: @"Certificate.InUseBy[i]"];
    i = i + 1;
}

i = 0;
count_i = [[jResp SizeOfArray: @"Certificate.KeyUsages"] intValue];
while (i < count_i) {
    jResp.I = [NSNumber numberWithInt: i];
    Name = [jResp StringOf: @"Certificate.KeyUsages[i].Name"];
    i = i + 1;
}

i = 0;
count_i = [[jResp SizeOfArray: @"Certificate.RenewalSummary.DomainValidationOptions"] intValue];
while (i < count_i) {
    jResp.I = [NSNumber numberWithInt: i];
    DomainName = [jResp StringOf: @"Certificate.RenewalSummary.DomainValidationOptions[i].DomainName"];
    ResourceRecordName = [jResp StringOf: @"Certificate.RenewalSummary.DomainValidationOptions[i].ResourceRecord.Name"];
    ResourceRecordType = [jResp StringOf: @"Certificate.RenewalSummary.DomainValidationOptions[i].ResourceRecord.Type"];
    ResourceRecordValue = [jResp StringOf: @"Certificate.RenewalSummary.DomainValidationOptions[i].ResourceRecord.Value"];
    ValidationDomain = [jResp StringOf: @"Certificate.RenewalSummary.DomainValidationOptions[i].ValidationDomain"];
    ValidationMethod = [jResp StringOf: @"Certificate.RenewalSummary.DomainValidationOptions[i].ValidationMethod"];
    ValidationStatus = [jResp StringOf: @"Certificate.RenewalSummary.DomainValidationOptions[i].ValidationStatus"];
    j = 0;
    count_j = [[jResp SizeOfArray: @"Certificate.RenewalSummary.DomainValidationOptions[i].ValidationEmails"] intValue];
    while (j < count_j) {
        jResp.J = [NSNumber numberWithInt: j];
        strVal = [jResp StringOf: @"Certificate.RenewalSummary.DomainValidationOptions[i].ValidationEmails[j]"];
        j = j + 1;
    }

    i = i + 1;
}

i = 0;
count_i = [[jResp SizeOfArray: @"Certificate.SubjectAlternativeNames"] intValue];
while (i < count_i) {
    jResp.I = [NSNumber numberWithInt: i];
    strVal = [jResp StringOf: @"Certificate.SubjectAlternativeNames[i]"];
    i = i + 1;
}

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

// {
//   "Certificate": {
//     "CertificateArn": "string",
//     "CertificateAuthorityArn": "string",
//     "CreatedAt": number,
//     "DomainName": "string",
//     "DomainValidationOptions": [
//       {
//         "DomainName": "string",
//         "ResourceRecord": {
//           "Name": "string",
//           "Type": "string",
//           "Value": "string"
//         },
//         "ValidationDomain": "string",
//         "ValidationEmails": [
//           "string"
//         ],
//         "ValidationMethod": "string",
//         "ValidationStatus": "string"
//       }
//     ],
//     "ExtendedKeyUsages": [
//       {
//         "Name": "string",
//         "OID": "string"
//       }
//     ],
//     "FailureReason": "string",
//     "ImportedAt": number,
//     "InUseBy": [
//       "string"
//     ],
//     "IssuedAt": number,
//     "Issuer": "string",
//     "KeyAlgorithm": "string",
//     "KeyUsages": [
//       {
//         "Name": "string"
//       }
//     ],
//     "NotAfter": number,
//     "NotBefore": number,
//     "Options": {
//       "CertificateTransparencyLoggingPreference": "string"
//     },
//     "RenewalEligibility": "string",
//     "RenewalSummary": {
//       "DomainValidationOptions": [
//         {
//           "DomainName": "string",
//           "ResourceRecord": {
//             "Name": "string",
//             "Type": "string",
//             "Value": "string"
//           },
//           "ValidationDomain": "string",
//           "ValidationEmails": [
//             "string"
//           ],
//           "ValidationMethod": "string",
//           "ValidationStatus": "string"
//         }
//       ],
//       "RenewalStatus": "string",
//       "RenewalStatusReason": "string",
//       "UpdatedAt": number
//     },
//     "RevocationReason": "string",
//     "RevokedAt": number,
//     "Serial": "string",
//     "SignatureAlgorithm": "string",
//     "Status": "string",
//     "Subject": "string",
//     "SubjectAlternativeNames": [
//       "string"
//     ],
//     "Type": "string"
//   }
// }