Chilkat Online Tools

CreateCertificateAuthority delphiDll Example

AWS Private CA

var
rest: HCkRest;
success: Boolean;
authAws: HCkAuthAws;
json: HCkJsonObject;
sbRequestBody: HCkStringBuilder;
sbResponseBody: HCkStringBuilder;
respStatusCode: Integer;
jResp: HCkJsonObject;
CertificateAuthorityArn: PWideChar;

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

rest := CkRest_Create();

authAws := CkAuthAws_Create();
CkAuthAws_putAccessKey(authAws,'AWS_ACCESS_KEY');
CkAuthAws_putSecretKey(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_putRegion(authAws,'us-west-2');
CkAuthAws_putServiceName(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.
success := CkRest_Connect(rest,'acm-pca.us-west-2.amazonaws.com',443,True,True);
if (success <> True) then
  begin
    Memo1.Lines.Add('ConnectFailReason: ' + IntToStr(CkRest_getConnectFailReason(rest)));
    Memo1.Lines.Add(CkRest__lastErrorText(rest));
    Exit;
  end;

// 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 := CkJsonObject_Create();
CkJsonObject_UpdateInt(json,'CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.CRLSign',123);
CkJsonObject_UpdateInt(json,'CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.DataEncipherment',123);
CkJsonObject_UpdateInt(json,'CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.DecipherOnly',123);
CkJsonObject_UpdateInt(json,'CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.DigitalSignature',123);
CkJsonObject_UpdateInt(json,'CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.EncipherOnly',123);
CkJsonObject_UpdateInt(json,'CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.KeyAgreement',123);
CkJsonObject_UpdateInt(json,'CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.KeyCertSign',123);
CkJsonObject_UpdateInt(json,'CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.KeyEncipherment',123);
CkJsonObject_UpdateInt(json,'CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.NonRepudiation',123);
CkJsonObject_UpdateString(json,'CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.DirectoryName.CommonName','string');
CkJsonObject_UpdateString(json,'CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.DirectoryName.Country','string');
CkJsonObject_UpdateString(json,'CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.DirectoryName.DistinguishedNameQualifier','string');
CkJsonObject_UpdateString(json,'CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.DirectoryName.GenerationQualifier','string');
CkJsonObject_UpdateString(json,'CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.DirectoryName.GivenName','string');
CkJsonObject_UpdateString(json,'CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.DirectoryName.Initials','string');
CkJsonObject_UpdateString(json,'CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.DirectoryName.Locality','string');
CkJsonObject_UpdateString(json,'CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.DirectoryName.Organization','string');
CkJsonObject_UpdateString(json,'CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.DirectoryName.OrganizationalUnit','string');
CkJsonObject_UpdateString(json,'CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.DirectoryName.Pseudonym','string');
CkJsonObject_UpdateString(json,'CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.DirectoryName.SerialNumber','string');
CkJsonObject_UpdateString(json,'CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.DirectoryName.State','string');
CkJsonObject_UpdateString(json,'CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.DirectoryName.Surname','string');
CkJsonObject_UpdateString(json,'CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.DirectoryName.Title','string');
CkJsonObject_UpdateString(json,'CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.DnsName','string');
CkJsonObject_UpdateString(json,'CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.EdiPartyName.NameAssigner','string');
CkJsonObject_UpdateString(json,'CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.EdiPartyName.PartyName','string');
CkJsonObject_UpdateString(json,'CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.IpAddress','string');
CkJsonObject_UpdateString(json,'CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.OtherName.TypeId','string');
CkJsonObject_UpdateString(json,'CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.OtherName.Value','string');
CkJsonObject_UpdateString(json,'CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.RegisteredId','string');
CkJsonObject_UpdateString(json,'CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.Rfc822Name','string');
CkJsonObject_UpdateString(json,'CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.UniformResourceIdentifier','string');
CkJsonObject_UpdateString(json,'CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessMethod.AccessMethodType','string');
CkJsonObject_UpdateString(json,'CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessMethod.CustomObjectIdentifier','string');
CkJsonObject_UpdateString(json,'CertificateAuthorityConfiguration.KeyAlgorithm','string');
CkJsonObject_UpdateString(json,'CertificateAuthorityConfiguration.SigningAlgorithm','string');
CkJsonObject_UpdateString(json,'CertificateAuthorityConfiguration.Subject.CommonName','string');
CkJsonObject_UpdateString(json,'CertificateAuthorityConfiguration.Subject.Country','string');
CkJsonObject_UpdateString(json,'CertificateAuthorityConfiguration.Subject.DistinguishedNameQualifier','string');
CkJsonObject_UpdateString(json,'CertificateAuthorityConfiguration.Subject.GenerationQualifier','string');
CkJsonObject_UpdateString(json,'CertificateAuthorityConfiguration.Subject.GivenName','string');
CkJsonObject_UpdateString(json,'CertificateAuthorityConfiguration.Subject.Initials','string');
CkJsonObject_UpdateString(json,'CertificateAuthorityConfiguration.Subject.Locality','string');
CkJsonObject_UpdateString(json,'CertificateAuthorityConfiguration.Subject.Organization','string');
CkJsonObject_UpdateString(json,'CertificateAuthorityConfiguration.Subject.OrganizationalUnit','string');
CkJsonObject_UpdateString(json,'CertificateAuthorityConfiguration.Subject.Pseudonym','string');
CkJsonObject_UpdateString(json,'CertificateAuthorityConfiguration.Subject.SerialNumber','string');
CkJsonObject_UpdateString(json,'CertificateAuthorityConfiguration.Subject.State','string');
CkJsonObject_UpdateString(json,'CertificateAuthorityConfiguration.Subject.Surname','string');
CkJsonObject_UpdateString(json,'CertificateAuthorityConfiguration.Subject.Title','string');
CkJsonObject_UpdateString(json,'CertificateAuthorityType','string');
CkJsonObject_UpdateString(json,'IdempotencyToken','string');
CkJsonObject_UpdateString(json,'KeyStorageSecurityStandard','string');
CkJsonObject_UpdateString(json,'RevocationConfiguration.CrlConfiguration.CustomCname','string');
CkJsonObject_UpdateInt(json,'RevocationConfiguration.CrlConfiguration.Enabled',123);
CkJsonObject_UpdateInt(json,'RevocationConfiguration.CrlConfiguration.ExpirationInDays',123);
CkJsonObject_UpdateString(json,'RevocationConfiguration.CrlConfiguration.S3BucketName','string');
CkJsonObject_UpdateString(json,'RevocationConfiguration.CrlConfiguration.S3ObjectAcl','string');
CkJsonObject_UpdateInt(json,'RevocationConfiguration.OcspConfiguration.Enabled',123);
CkJsonObject_UpdateString(json,'RevocationConfiguration.OcspConfiguration.OcspCustomCname','string');
CkJsonObject_UpdateString(json,'Tags[0].Key','string');
CkJsonObject_UpdateString(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_AddHeader(rest,'Content-Type','application/x-amz-json-1.1');
CkRest_AddHeader(rest,'X-Amz-Target','ACMPrivateCA.CreateCertificateAuthority');

sbRequestBody := CkStringBuilder_Create();
CkJsonObject_EmitSb(json,sbRequestBody);
sbResponseBody := CkStringBuilder_Create();
success := CkRest_FullRequestSb(rest,'POST','/',sbRequestBody,sbResponseBody);
if (success <> True) then
  begin
    Memo1.Lines.Add(CkRest__lastErrorText(rest));
    Exit;
  end;
respStatusCode := CkRest_getResponseStatusCode(rest);
Memo1.Lines.Add('response status code = ' + IntToStr(respStatusCode));
if (respStatusCode <> 200) then
  begin
    Memo1.Lines.Add('Response Header:');
    Memo1.Lines.Add(CkRest__responseHeader(rest));
    Memo1.Lines.Add('Response Body:');
    Memo1.Lines.Add(CkStringBuilder__getAsString(sbResponseBody));
    Exit;
  end;

jResp := CkJsonObject_Create();
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

CertificateAuthorityArn := CkJsonObject__stringOf(jResp,'CertificateAuthorityArn');

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

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

CkRest_Dispose(rest);
CkAuthAws_Dispose(authAws);
CkJsonObject_Dispose(json);
CkStringBuilder_Dispose(sbRequestBody);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);