CreateCertificateAuthority PureBasic Example
IncludeFile "CkJsonObject.pb"
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkRest.pb"
IncludeFile "CkAuthAws.pb"
Procedure ChilkatExample()
; This example requires the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
rest.i = CkRest::ckCreate()
If rest.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success.i
authAws.i = CkAuthAws::ckCreate()
If authAws.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkAuthAws::setCkAccessKey(authAws, "AWS_ACCESS_KEY")
CkAuthAws::setCkSecretKey(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::setCkRegion(authAws, "us-west-2")
CkAuthAws::setCkServiceName(authAws, "acm-pca")
; SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
CkRest::ckSetAuthAws(rest,authAws)
; URL: https://acm-pca.us-west-2.amazonaws.com/
; Use the same region as specified above.
success = CkRest::ckConnect(rest,"acm-pca.us-west-2.amazonaws.com",443,1,1)
If success <> 1
Debug "ConnectFailReason: " + Str(CkRest::ckConnectFailReason(rest))
Debug CkRest::ckLastErrorText(rest)
CkRest::ckDispose(rest)
CkAuthAws::ckDispose(authAws)
ProcedureReturn
EndIf
; 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.i = CkJsonObject::ckCreate()
If json.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkJsonObject::ckUpdateInt(json,"CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.CRLSign",123)
CkJsonObject::ckUpdateInt(json,"CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.DataEncipherment",123)
CkJsonObject::ckUpdateInt(json,"CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.DecipherOnly",123)
CkJsonObject::ckUpdateInt(json,"CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.DigitalSignature",123)
CkJsonObject::ckUpdateInt(json,"CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.EncipherOnly",123)
CkJsonObject::ckUpdateInt(json,"CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.KeyAgreement",123)
CkJsonObject::ckUpdateInt(json,"CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.KeyCertSign",123)
CkJsonObject::ckUpdateInt(json,"CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.KeyEncipherment",123)
CkJsonObject::ckUpdateInt(json,"CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.NonRepudiation",123)
CkJsonObject::ckUpdateString(json,"CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.DirectoryName.CommonName","string")
CkJsonObject::ckUpdateString(json,"CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.DirectoryName.Country","string")
CkJsonObject::ckUpdateString(json,"CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.DirectoryName.DistinguishedNameQualifier","string")
CkJsonObject::ckUpdateString(json,"CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.DirectoryName.GenerationQualifier","string")
CkJsonObject::ckUpdateString(json,"CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.DirectoryName.GivenName","string")
CkJsonObject::ckUpdateString(json,"CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.DirectoryName.Initials","string")
CkJsonObject::ckUpdateString(json,"CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.DirectoryName.Locality","string")
CkJsonObject::ckUpdateString(json,"CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.DirectoryName.Organization","string")
CkJsonObject::ckUpdateString(json,"CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.DirectoryName.OrganizationalUnit","string")
CkJsonObject::ckUpdateString(json,"CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.DirectoryName.Pseudonym","string")
CkJsonObject::ckUpdateString(json,"CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.DirectoryName.SerialNumber","string")
CkJsonObject::ckUpdateString(json,"CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.DirectoryName.State","string")
CkJsonObject::ckUpdateString(json,"CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.DirectoryName.Surname","string")
CkJsonObject::ckUpdateString(json,"CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.DirectoryName.Title","string")
CkJsonObject::ckUpdateString(json,"CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.DnsName","string")
CkJsonObject::ckUpdateString(json,"CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.EdiPartyName.NameAssigner","string")
CkJsonObject::ckUpdateString(json,"CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.EdiPartyName.PartyName","string")
CkJsonObject::ckUpdateString(json,"CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.IpAddress","string")
CkJsonObject::ckUpdateString(json,"CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.OtherName.TypeId","string")
CkJsonObject::ckUpdateString(json,"CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.OtherName.Value","string")
CkJsonObject::ckUpdateString(json,"CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.RegisteredId","string")
CkJsonObject::ckUpdateString(json,"CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.Rfc822Name","string")
CkJsonObject::ckUpdateString(json,"CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.UniformResourceIdentifier","string")
CkJsonObject::ckUpdateString(json,"CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessMethod.AccessMethodType","string")
CkJsonObject::ckUpdateString(json,"CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessMethod.CustomObjectIdentifier","string")
CkJsonObject::ckUpdateString(json,"CertificateAuthorityConfiguration.KeyAlgorithm","string")
CkJsonObject::ckUpdateString(json,"CertificateAuthorityConfiguration.SigningAlgorithm","string")
CkJsonObject::ckUpdateString(json,"CertificateAuthorityConfiguration.Subject.CommonName","string")
CkJsonObject::ckUpdateString(json,"CertificateAuthorityConfiguration.Subject.Country","string")
CkJsonObject::ckUpdateString(json,"CertificateAuthorityConfiguration.Subject.DistinguishedNameQualifier","string")
CkJsonObject::ckUpdateString(json,"CertificateAuthorityConfiguration.Subject.GenerationQualifier","string")
CkJsonObject::ckUpdateString(json,"CertificateAuthorityConfiguration.Subject.GivenName","string")
CkJsonObject::ckUpdateString(json,"CertificateAuthorityConfiguration.Subject.Initials","string")
CkJsonObject::ckUpdateString(json,"CertificateAuthorityConfiguration.Subject.Locality","string")
CkJsonObject::ckUpdateString(json,"CertificateAuthorityConfiguration.Subject.Organization","string")
CkJsonObject::ckUpdateString(json,"CertificateAuthorityConfiguration.Subject.OrganizationalUnit","string")
CkJsonObject::ckUpdateString(json,"CertificateAuthorityConfiguration.Subject.Pseudonym","string")
CkJsonObject::ckUpdateString(json,"CertificateAuthorityConfiguration.Subject.SerialNumber","string")
CkJsonObject::ckUpdateString(json,"CertificateAuthorityConfiguration.Subject.State","string")
CkJsonObject::ckUpdateString(json,"CertificateAuthorityConfiguration.Subject.Surname","string")
CkJsonObject::ckUpdateString(json,"CertificateAuthorityConfiguration.Subject.Title","string")
CkJsonObject::ckUpdateString(json,"CertificateAuthorityType","string")
CkJsonObject::ckUpdateString(json,"IdempotencyToken","string")
CkJsonObject::ckUpdateString(json,"KeyStorageSecurityStandard","string")
CkJsonObject::ckUpdateString(json,"RevocationConfiguration.CrlConfiguration.CustomCname","string")
CkJsonObject::ckUpdateInt(json,"RevocationConfiguration.CrlConfiguration.Enabled",123)
CkJsonObject::ckUpdateInt(json,"RevocationConfiguration.CrlConfiguration.ExpirationInDays",123)
CkJsonObject::ckUpdateString(json,"RevocationConfiguration.CrlConfiguration.S3BucketName","string")
CkJsonObject::ckUpdateString(json,"RevocationConfiguration.CrlConfiguration.S3ObjectAcl","string")
CkJsonObject::ckUpdateInt(json,"RevocationConfiguration.OcspConfiguration.Enabled",123)
CkJsonObject::ckUpdateString(json,"RevocationConfiguration.OcspConfiguration.OcspCustomCname","string")
CkJsonObject::ckUpdateString(json,"Tags[0].Key","string")
CkJsonObject::ckUpdateString(json,"Tags[0].Value","string")
; The JSON request body created by the above code:
; {
; "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"
; }
; },
; "CertificateAuthorityType": "string",
; "IdempotencyToken": "string",
; "KeyStorageSecurityStandard": "string",
; "RevocationConfiguration": {
; "CrlConfiguration": {
; "CustomCname": "string",
; "Enabled": boolean,
; "ExpirationInDays": number,
; "S3BucketName": "string",
; "S3ObjectAcl": "string"
; },
; "OcspConfiguration": {
; "Enabled": boolean,
; "OcspCustomCname": "string"
; }
; },
; "Tags": [
; {
; "Key": "string",
; "Value": "string"
; }
; ]
; }
CkRest::ckAddHeader(rest,"Content-Type","application/x-amz-json-1.1")
CkRest::ckAddHeader(rest,"X-Amz-Target","ACMPrivateCA.CreateCertificateAuthority")
sbRequestBody.i = CkStringBuilder::ckCreate()
If sbRequestBody.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkJsonObject::ckEmitSb(json,sbRequestBody)
sbResponseBody.i = CkStringBuilder::ckCreate()
If sbResponseBody.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success = CkRest::ckFullRequestSb(rest,"POST","/",sbRequestBody,sbResponseBody)
If success <> 1
Debug CkRest::ckLastErrorText(rest)
CkRest::ckDispose(rest)
CkAuthAws::ckDispose(authAws)
CkJsonObject::ckDispose(json)
CkStringBuilder::ckDispose(sbRequestBody)
CkStringBuilder::ckDispose(sbResponseBody)
ProcedureReturn
EndIf
respStatusCode.i = CkRest::ckResponseStatusCode(rest)
Debug "response status code = " + Str(respStatusCode)
If respStatusCode <> 200
Debug "Response Header:"
Debug CkRest::ckResponseHeader(rest)
Debug "Response Body:"
Debug CkStringBuilder::ckGetAsString(sbResponseBody)
CkRest::ckDispose(rest)
CkAuthAws::ckDispose(authAws)
CkJsonObject::ckDispose(json)
CkStringBuilder::ckDispose(sbRequestBody)
CkStringBuilder::ckDispose(sbResponseBody)
ProcedureReturn
EndIf
jResp.i = CkJsonObject::ckCreate()
If jResp.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkJsonObject::ckLoadSb(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
CertificateAuthorityArn.s = CkJsonObject::ckStringOf(jResp,"CertificateAuthorityArn")
; A sample JSON response body parsed by the above code:
; {
; "CertificateAuthorityArn": "string"
; }
CkRest::ckDispose(rest)
CkAuthAws::ckDispose(authAws)
CkJsonObject::ckDispose(json)
CkStringBuilder::ckDispose(sbRequestBody)
CkStringBuilder::ckDispose(sbResponseBody)
CkJsonObject::ckDispose(jResp)
ProcedureReturn
EndProcedure