Chilkat Online Tools

IssueCertificate TCL Example

AWS Private CA

load ./chilkat.dll

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

set rest [new_CkRest]

set authAws [new_CkAuthAws]

CkAuthAws_put_AccessKey $authAws "AWS_ACCESS_KEY"
CkAuthAws_put_SecretKey $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_put_Region $authAws "us-west-2"
CkAuthAws_put_ServiceName $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.
set success [CkRest_Connect $rest "acm-pca.us-west-2.amazonaws.com" 443 1 1]
if {$success != 1} then {
    puts "ConnectFailReason: [CkRest_get_ConnectFailReason $rest]"
    puts [CkRest_lastErrorText $rest]
    delete_CkRest $rest
    delete_CkAuthAws $authAws
    exit
}

# 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

set json [new_CkJsonObject]

CkJsonObject_UpdateString $json "ApiPassthrough.Extensions.CertificatePolicies[0].CertPolicyId" "string"
CkJsonObject_UpdateString $json "ApiPassthrough.Extensions.CertificatePolicies[0].PolicyQualifiers[0].PolicyQualifierId" "string"
CkJsonObject_UpdateString $json "ApiPassthrough.Extensions.CertificatePolicies[0].PolicyQualifiers[0].Qualifier.CpsUri" "string"
CkJsonObject_UpdateString $json "ApiPassthrough.Extensions.ExtendedKeyUsage[0].ExtendedKeyUsageObjectIdentifier" "string"
CkJsonObject_UpdateString $json "ApiPassthrough.Extensions.ExtendedKeyUsage[0].ExtendedKeyUsageType" "string"
CkJsonObject_UpdateInt $json "ApiPassthrough.Extensions.KeyUsage.CRLSign" 123
CkJsonObject_UpdateInt $json "ApiPassthrough.Extensions.KeyUsage.DataEncipherment" 123
CkJsonObject_UpdateInt $json "ApiPassthrough.Extensions.KeyUsage.DecipherOnly" 123
CkJsonObject_UpdateInt $json "ApiPassthrough.Extensions.KeyUsage.DigitalSignature" 123
CkJsonObject_UpdateInt $json "ApiPassthrough.Extensions.KeyUsage.EncipherOnly" 123
CkJsonObject_UpdateInt $json "ApiPassthrough.Extensions.KeyUsage.KeyAgreement" 123
CkJsonObject_UpdateInt $json "ApiPassthrough.Extensions.KeyUsage.KeyCertSign" 123
CkJsonObject_UpdateInt $json "ApiPassthrough.Extensions.KeyUsage.KeyEncipherment" 123
CkJsonObject_UpdateInt $json "ApiPassthrough.Extensions.KeyUsage.NonRepudiation" 123
CkJsonObject_UpdateString $json "ApiPassthrough.Extensions.SubjectAlternativeNames[0].DirectoryName.CommonName" "string"
CkJsonObject_UpdateString $json "ApiPassthrough.Extensions.SubjectAlternativeNames[0].DirectoryName.Country" "string"
CkJsonObject_UpdateString $json "ApiPassthrough.Extensions.SubjectAlternativeNames[0].DirectoryName.DistinguishedNameQualifier" "string"
CkJsonObject_UpdateString $json "ApiPassthrough.Extensions.SubjectAlternativeNames[0].DirectoryName.GenerationQualifier" "string"
CkJsonObject_UpdateString $json "ApiPassthrough.Extensions.SubjectAlternativeNames[0].DirectoryName.GivenName" "string"
CkJsonObject_UpdateString $json "ApiPassthrough.Extensions.SubjectAlternativeNames[0].DirectoryName.Initials" "string"
CkJsonObject_UpdateString $json "ApiPassthrough.Extensions.SubjectAlternativeNames[0].DirectoryName.Locality" "string"
CkJsonObject_UpdateString $json "ApiPassthrough.Extensions.SubjectAlternativeNames[0].DirectoryName.Organization" "string"
CkJsonObject_UpdateString $json "ApiPassthrough.Extensions.SubjectAlternativeNames[0].DirectoryName.OrganizationalUnit" "string"
CkJsonObject_UpdateString $json "ApiPassthrough.Extensions.SubjectAlternativeNames[0].DirectoryName.Pseudonym" "string"
CkJsonObject_UpdateString $json "ApiPassthrough.Extensions.SubjectAlternativeNames[0].DirectoryName.SerialNumber" "string"
CkJsonObject_UpdateString $json "ApiPassthrough.Extensions.SubjectAlternativeNames[0].DirectoryName.State" "string"
CkJsonObject_UpdateString $json "ApiPassthrough.Extensions.SubjectAlternativeNames[0].DirectoryName.Surname" "string"
CkJsonObject_UpdateString $json "ApiPassthrough.Extensions.SubjectAlternativeNames[0].DirectoryName.Title" "string"
CkJsonObject_UpdateString $json "ApiPassthrough.Extensions.SubjectAlternativeNames[0].DnsName" "string"
CkJsonObject_UpdateString $json "ApiPassthrough.Extensions.SubjectAlternativeNames[0].EdiPartyName.NameAssigner" "string"
CkJsonObject_UpdateString $json "ApiPassthrough.Extensions.SubjectAlternativeNames[0].EdiPartyName.PartyName" "string"
CkJsonObject_UpdateString $json "ApiPassthrough.Extensions.SubjectAlternativeNames[0].IpAddress" "string"
CkJsonObject_UpdateString $json "ApiPassthrough.Extensions.SubjectAlternativeNames[0].OtherName.TypeId" "string"
CkJsonObject_UpdateString $json "ApiPassthrough.Extensions.SubjectAlternativeNames[0].OtherName.Value" "string"
CkJsonObject_UpdateString $json "ApiPassthrough.Extensions.SubjectAlternativeNames[0].RegisteredId" "string"
CkJsonObject_UpdateString $json "ApiPassthrough.Extensions.SubjectAlternativeNames[0].Rfc822Name" "string"
CkJsonObject_UpdateString $json "ApiPassthrough.Extensions.SubjectAlternativeNames[0].UniformResourceIdentifier" "string"
CkJsonObject_UpdateString $json "ApiPassthrough.Subject.CommonName" "string"
CkJsonObject_UpdateString $json "ApiPassthrough.Subject.Country" "string"
CkJsonObject_UpdateString $json "ApiPassthrough.Subject.DistinguishedNameQualifier" "string"
CkJsonObject_UpdateString $json "ApiPassthrough.Subject.GenerationQualifier" "string"
CkJsonObject_UpdateString $json "ApiPassthrough.Subject.GivenName" "string"
CkJsonObject_UpdateString $json "ApiPassthrough.Subject.Initials" "string"
CkJsonObject_UpdateString $json "ApiPassthrough.Subject.Locality" "string"
CkJsonObject_UpdateString $json "ApiPassthrough.Subject.Organization" "string"
CkJsonObject_UpdateString $json "ApiPassthrough.Subject.OrganizationalUnit" "string"
CkJsonObject_UpdateString $json "ApiPassthrough.Subject.Pseudonym" "string"
CkJsonObject_UpdateString $json "ApiPassthrough.Subject.SerialNumber" "string"
CkJsonObject_UpdateString $json "ApiPassthrough.Subject.State" "string"
CkJsonObject_UpdateString $json "ApiPassthrough.Subject.Surname" "string"
CkJsonObject_UpdateString $json "ApiPassthrough.Subject.Title" "string"
CkJsonObject_UpdateString $json "CertificateAuthorityArn" "string"
CkJsonObject_UpdateInt $json "Csr" 123
CkJsonObject_UpdateString $json "IdempotencyToken" "string"
CkJsonObject_UpdateString $json "SigningAlgorithm" "string"
CkJsonObject_UpdateString $json "TemplateArn" "string"
CkJsonObject_UpdateString $json "Validity.Type" "string"
CkJsonObject_UpdateInt $json "Validity.Value" 123
CkJsonObject_UpdateString $json "ValidityNotBefore.Type" "string"
CkJsonObject_UpdateInt $json "ValidityNotBefore.Value" 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
#   }
# }

CkRest_AddHeader $rest "Content-Type" "application/x-amz-json-1.1"
CkRest_AddHeader $rest "X-Amz-Target" "ACMPrivateCA.IssueCertificate"

set sbRequestBody [new_CkStringBuilder]

CkJsonObject_EmitSb $json $sbRequestBody
set sbResponseBody [new_CkStringBuilder]

set success [CkRest_FullRequestSb $rest "POST" "/" $sbRequestBody $sbResponseBody]
if {$success != 1} then {
    puts [CkRest_lastErrorText $rest]
    delete_CkRest $rest
    delete_CkAuthAws $authAws
    delete_CkJsonObject $json
    delete_CkStringBuilder $sbRequestBody
    delete_CkStringBuilder $sbResponseBody
    exit
}

set respStatusCode [CkRest_get_ResponseStatusCode $rest]
puts "response status code = $respStatusCode"
if {$respStatusCode != 200} then {
    puts "Response Header:"
    puts [CkRest_responseHeader $rest]
    puts "Response Body:"
    puts [CkStringBuilder_getAsString $sbResponseBody]
    delete_CkRest $rest
    delete_CkAuthAws $authAws
    delete_CkJsonObject $json
    delete_CkStringBuilder $sbRequestBody
    delete_CkStringBuilder $sbResponseBody
    exit
}

set jResp [new_CkJsonObject]

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

set CertificateArn [CkJsonObject_stringOf $jResp "CertificateArn"]

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

# {
#   "CertificateArn": "string"
# }

delete_CkRest $rest
delete_CkAuthAws $authAws
delete_CkJsonObject $json
delete_CkStringBuilder $sbRequestBody
delete_CkStringBuilder $sbResponseBody
delete_CkJsonObject $jResp