IssueCertificate Objective-C Example
#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: @"ApiPassthrough.Extensions.CertificatePolicies[0].CertPolicyId" value: @"string"];
[json UpdateString: @"ApiPassthrough.Extensions.CertificatePolicies[0].PolicyQualifiers[0].PolicyQualifierId" value: @"string"];
[json UpdateString: @"ApiPassthrough.Extensions.CertificatePolicies[0].PolicyQualifiers[0].Qualifier.CpsUri" value: @"string"];
[json UpdateString: @"ApiPassthrough.Extensions.ExtendedKeyUsage[0].ExtendedKeyUsageObjectIdentifier" value: @"string"];
[json UpdateString: @"ApiPassthrough.Extensions.ExtendedKeyUsage[0].ExtendedKeyUsageType" value: @"string"];
[json UpdateInt: @"ApiPassthrough.Extensions.KeyUsage.CRLSign" value: [NSNumber numberWithInt: 123]];
[json UpdateInt: @"ApiPassthrough.Extensions.KeyUsage.DataEncipherment" value: [NSNumber numberWithInt: 123]];
[json UpdateInt: @"ApiPassthrough.Extensions.KeyUsage.DecipherOnly" value: [NSNumber numberWithInt: 123]];
[json UpdateInt: @"ApiPassthrough.Extensions.KeyUsage.DigitalSignature" value: [NSNumber numberWithInt: 123]];
[json UpdateInt: @"ApiPassthrough.Extensions.KeyUsage.EncipherOnly" value: [NSNumber numberWithInt: 123]];
[json UpdateInt: @"ApiPassthrough.Extensions.KeyUsage.KeyAgreement" value: [NSNumber numberWithInt: 123]];
[json UpdateInt: @"ApiPassthrough.Extensions.KeyUsage.KeyCertSign" value: [NSNumber numberWithInt: 123]];
[json UpdateInt: @"ApiPassthrough.Extensions.KeyUsage.KeyEncipherment" value: [NSNumber numberWithInt: 123]];
[json UpdateInt: @"ApiPassthrough.Extensions.KeyUsage.NonRepudiation" value: [NSNumber numberWithInt: 123]];
[json UpdateString: @"ApiPassthrough.Extensions.SubjectAlternativeNames[0].DirectoryName.CommonName" value: @"string"];
[json UpdateString: @"ApiPassthrough.Extensions.SubjectAlternativeNames[0].DirectoryName.Country" value: @"string"];
[json UpdateString: @"ApiPassthrough.Extensions.SubjectAlternativeNames[0].DirectoryName.DistinguishedNameQualifier" value: @"string"];
[json UpdateString: @"ApiPassthrough.Extensions.SubjectAlternativeNames[0].DirectoryName.GenerationQualifier" value: @"string"];
[json UpdateString: @"ApiPassthrough.Extensions.SubjectAlternativeNames[0].DirectoryName.GivenName" value: @"string"];
[json UpdateString: @"ApiPassthrough.Extensions.SubjectAlternativeNames[0].DirectoryName.Initials" value: @"string"];
[json UpdateString: @"ApiPassthrough.Extensions.SubjectAlternativeNames[0].DirectoryName.Locality" value: @"string"];
[json UpdateString: @"ApiPassthrough.Extensions.SubjectAlternativeNames[0].DirectoryName.Organization" value: @"string"];
[json UpdateString: @"ApiPassthrough.Extensions.SubjectAlternativeNames[0].DirectoryName.OrganizationalUnit" value: @"string"];
[json UpdateString: @"ApiPassthrough.Extensions.SubjectAlternativeNames[0].DirectoryName.Pseudonym" value: @"string"];
[json UpdateString: @"ApiPassthrough.Extensions.SubjectAlternativeNames[0].DirectoryName.SerialNumber" value: @"string"];
[json UpdateString: @"ApiPassthrough.Extensions.SubjectAlternativeNames[0].DirectoryName.State" value: @"string"];
[json UpdateString: @"ApiPassthrough.Extensions.SubjectAlternativeNames[0].DirectoryName.Surname" value: @"string"];
[json UpdateString: @"ApiPassthrough.Extensions.SubjectAlternativeNames[0].DirectoryName.Title" value: @"string"];
[json UpdateString: @"ApiPassthrough.Extensions.SubjectAlternativeNames[0].DnsName" value: @"string"];
[json UpdateString: @"ApiPassthrough.Extensions.SubjectAlternativeNames[0].EdiPartyName.NameAssigner" value: @"string"];
[json UpdateString: @"ApiPassthrough.Extensions.SubjectAlternativeNames[0].EdiPartyName.PartyName" value: @"string"];
[json UpdateString: @"ApiPassthrough.Extensions.SubjectAlternativeNames[0].IpAddress" value: @"string"];
[json UpdateString: @"ApiPassthrough.Extensions.SubjectAlternativeNames[0].OtherName.TypeId" value: @"string"];
[json UpdateString: @"ApiPassthrough.Extensions.SubjectAlternativeNames[0].OtherName.Value" value: @"string"];
[json UpdateString: @"ApiPassthrough.Extensions.SubjectAlternativeNames[0].RegisteredId" value: @"string"];
[json UpdateString: @"ApiPassthrough.Extensions.SubjectAlternativeNames[0].Rfc822Name" value: @"string"];
[json UpdateString: @"ApiPassthrough.Extensions.SubjectAlternativeNames[0].UniformResourceIdentifier" value: @"string"];
[json UpdateString: @"ApiPassthrough.Subject.CommonName" value: @"string"];
[json UpdateString: @"ApiPassthrough.Subject.Country" value: @"string"];
[json UpdateString: @"ApiPassthrough.Subject.DistinguishedNameQualifier" value: @"string"];
[json UpdateString: @"ApiPassthrough.Subject.GenerationQualifier" value: @"string"];
[json UpdateString: @"ApiPassthrough.Subject.GivenName" value: @"string"];
[json UpdateString: @"ApiPassthrough.Subject.Initials" value: @"string"];
[json UpdateString: @"ApiPassthrough.Subject.Locality" value: @"string"];
[json UpdateString: @"ApiPassthrough.Subject.Organization" value: @"string"];
[json UpdateString: @"ApiPassthrough.Subject.OrganizationalUnit" value: @"string"];
[json UpdateString: @"ApiPassthrough.Subject.Pseudonym" value: @"string"];
[json UpdateString: @"ApiPassthrough.Subject.SerialNumber" value: @"string"];
[json UpdateString: @"ApiPassthrough.Subject.State" value: @"string"];
[json UpdateString: @"ApiPassthrough.Subject.Surname" value: @"string"];
[json UpdateString: @"ApiPassthrough.Subject.Title" value: @"string"];
[json UpdateString: @"CertificateAuthorityArn" value: @"string"];
[json UpdateInt: @"Csr" value: [NSNumber numberWithInt: 123]];
[json UpdateString: @"IdempotencyToken" value: @"string"];
[json UpdateString: @"SigningAlgorithm" value: @"string"];
[json UpdateString: @"TemplateArn" value: @"string"];
[json UpdateString: @"Validity.Type" value: @"string"];
[json UpdateInt: @"Validity.Value" value: [NSNumber numberWithInt: 123]];
[json UpdateString: @"ValidityNotBefore.Type" value: @"string"];
[json UpdateInt: @"ValidityNotBefore.Value" value: [NSNumber numberWithInt: 123]];
// The JSON request body created by the above code:
// {
// "ApiPassthrough": {
// "Extensions": {
// "CertificatePolicies": [
// {
// "CertPolicyId": "string",
// "PolicyQualifiers": [
// {
// "PolicyQualifierId": "string",
// "Qualifier": {
// "CpsUri": "string"
// }
// }
// ]
// }
// ],
// "ExtendedKeyUsage": [
// {
// "ExtendedKeyUsageObjectIdentifier": "string",
// "ExtendedKeyUsageType": "string"
// }
// ],
// "KeyUsage": {
// "CRLSign": boolean,
// "DataEncipherment": boolean,
// "DecipherOnly": boolean,
// "DigitalSignature": boolean,
// "EncipherOnly": boolean,
// "KeyAgreement": boolean,
// "KeyCertSign": boolean,
// "KeyEncipherment": boolean,
// "NonRepudiation": boolean
// },
// "SubjectAlternativeNames": [
// {
// "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"
// }
// ]
// },
// "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"
// }
// },
// "CertificateAuthorityArn": "string",
// "Csr": blob,
// "IdempotencyToken": "string",
// "SigningAlgorithm": "string",
// "TemplateArn": "string",
// "Validity": {
// "Type": "string",
// "Value": number
// },
// "ValidityNotBefore": {
// "Type": "string",
// "Value": number
// }
// }
[rest AddHeader: @"Content-Type" value: @"application/x-amz-json-1.1"];
[rest AddHeader: @"X-Amz-Target" value: @"ACMPrivateCA.IssueCertificate"];
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 *CertificateArn = [jResp StringOf: @"CertificateArn"];
// A sample JSON response body parsed by the above code:
// {
// "CertificateArn": "string"
// }