CreateCertificateAuthority SQL Server Example
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @iTmp0 int
DECLARE @sTmp0 nvarchar(max)
-- This example requires the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
DECLARE @rest int
EXEC @hr = sp_OACreate 'Chilkat_9_5_0.Rest', @rest OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
DECLARE @success int
DECLARE @authAws int
EXEC @hr = sp_OACreate 'Chilkat_9_5_0.AuthAws', @authAws OUT
EXEC sp_OASetProperty @authAws, 'AccessKey', 'AWS_ACCESS_KEY'
EXEC sp_OASetProperty @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.)
EXEC sp_OASetProperty @authAws, 'Region', 'us-west-2'
EXEC sp_OASetProperty @authAws, 'ServiceName', 'acm-pca'
-- SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
EXEC sp_OAMethod @rest, 'SetAuthAws', @success OUT, @authAws
-- URL: https://acm-pca.us-west-2.amazonaws.com/
-- Use the same region as specified above.
EXEC sp_OAMethod @rest, 'Connect', @success OUT, 'acm-pca.us-west-2.amazonaws.com', 443, 1, 1
IF @success <> 1
BEGIN
EXEC sp_OAGetProperty @rest, 'ConnectFailReason', @iTmp0 OUT
PRINT 'ConnectFailReason: ' + @iTmp0
EXEC sp_OAGetProperty @rest, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @rest
EXEC @hr = sp_OADestroy @authAws
RETURN
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
DECLARE @json int
EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @json OUT
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.CRLSign', 123
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.DataEncipherment', 123
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.DecipherOnly', 123
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.DigitalSignature', 123
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.EncipherOnly', 123
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.KeyAgreement', 123
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.KeyCertSign', 123
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.KeyEncipherment', 123
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.NonRepudiation', 123
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.DirectoryName.CommonName', 'string'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.DirectoryName.Country', 'string'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.DirectoryName.DistinguishedNameQualifier', 'string'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.DirectoryName.GenerationQualifier', 'string'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.DirectoryName.GivenName', 'string'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.DirectoryName.Initials', 'string'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.DirectoryName.Locality', 'string'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.DirectoryName.Organization', 'string'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.DirectoryName.OrganizationalUnit', 'string'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.DirectoryName.Pseudonym', 'string'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.DirectoryName.SerialNumber', 'string'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.DirectoryName.State', 'string'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.DirectoryName.Surname', 'string'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.DirectoryName.Title', 'string'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.DnsName', 'string'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.EdiPartyName.NameAssigner', 'string'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.EdiPartyName.PartyName', 'string'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.IpAddress', 'string'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.OtherName.TypeId', 'string'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.OtherName.Value', 'string'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.RegisteredId', 'string'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.Rfc822Name', 'string'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessLocation.UniformResourceIdentifier', 'string'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessMethod.AccessMethodType', 'string'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[0].AccessMethod.CustomObjectIdentifier', 'string'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'CertificateAuthorityConfiguration.KeyAlgorithm', 'string'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'CertificateAuthorityConfiguration.SigningAlgorithm', 'string'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'CertificateAuthorityConfiguration.Subject.CommonName', 'string'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'CertificateAuthorityConfiguration.Subject.Country', 'string'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'CertificateAuthorityConfiguration.Subject.DistinguishedNameQualifier', 'string'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'CertificateAuthorityConfiguration.Subject.GenerationQualifier', 'string'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'CertificateAuthorityConfiguration.Subject.GivenName', 'string'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'CertificateAuthorityConfiguration.Subject.Initials', 'string'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'CertificateAuthorityConfiguration.Subject.Locality', 'string'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'CertificateAuthorityConfiguration.Subject.Organization', 'string'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'CertificateAuthorityConfiguration.Subject.OrganizationalUnit', 'string'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'CertificateAuthorityConfiguration.Subject.Pseudonym', 'string'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'CertificateAuthorityConfiguration.Subject.SerialNumber', 'string'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'CertificateAuthorityConfiguration.Subject.State', 'string'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'CertificateAuthorityConfiguration.Subject.Surname', 'string'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'CertificateAuthorityConfiguration.Subject.Title', 'string'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'CertificateAuthorityType', 'string'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'IdempotencyToken', 'string'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'KeyStorageSecurityStandard', 'string'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'RevocationConfiguration.CrlConfiguration.CustomCname', 'string'
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'RevocationConfiguration.CrlConfiguration.Enabled', 123
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'RevocationConfiguration.CrlConfiguration.ExpirationInDays', 123
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'RevocationConfiguration.CrlConfiguration.S3BucketName', 'string'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'RevocationConfiguration.CrlConfiguration.S3ObjectAcl', 'string'
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'RevocationConfiguration.OcspConfiguration.Enabled', 123
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'RevocationConfiguration.OcspConfiguration.OcspCustomCname', 'string'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'Tags[0].Key', 'string'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, '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"
-- }
-- ]
-- }
EXEC sp_OAMethod @rest, 'AddHeader', @success OUT, 'Content-Type', 'application/x-amz-json-1.1'
EXEC sp_OAMethod @rest, 'AddHeader', @success OUT, 'X-Amz-Target', 'ACMPrivateCA.CreateCertificateAuthority'
DECLARE @sbRequestBody int
EXEC @hr = sp_OACreate 'Chilkat_9_5_0.StringBuilder', @sbRequestBody OUT
EXEC sp_OAMethod @json, 'EmitSb', @success OUT, @sbRequestBody
DECLARE @sbResponseBody int
EXEC @hr = sp_OACreate 'Chilkat_9_5_0.StringBuilder', @sbResponseBody OUT
EXEC sp_OAMethod @rest, 'FullRequestSb', @success OUT, 'POST', '/', @sbRequestBody, @sbResponseBody
IF @success <> 1
BEGIN
EXEC sp_OAGetProperty @rest, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @rest
EXEC @hr = sp_OADestroy @authAws
EXEC @hr = sp_OADestroy @json
EXEC @hr = sp_OADestroy @sbRequestBody
EXEC @hr = sp_OADestroy @sbResponseBody
RETURN
END
DECLARE @respStatusCode int
EXEC sp_OAGetProperty @rest, 'ResponseStatusCode', @respStatusCode OUT
PRINT 'response status code = ' + @respStatusCode
IF @respStatusCode <> 200
BEGIN
PRINT 'Response Header:'
EXEC sp_OAGetProperty @rest, 'ResponseHeader', @sTmp0 OUT
PRINT @sTmp0
PRINT 'Response Body:'
EXEC sp_OAMethod @sbResponseBody, 'GetAsString', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @rest
EXEC @hr = sp_OADestroy @authAws
EXEC @hr = sp_OADestroy @json
EXEC @hr = sp_OADestroy @sbRequestBody
EXEC @hr = sp_OADestroy @sbResponseBody
RETURN
END
DECLARE @jResp int
EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @jResp OUT
EXEC sp_OAMethod @jResp, 'LoadSb', @success OUT, @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
DECLARE @CertificateAuthorityArn nvarchar(max)
EXEC sp_OAMethod @jResp, 'StringOf', @CertificateAuthorityArn OUT, 'CertificateAuthorityArn'
-- A sample JSON response body parsed by the above code:
-- {
-- "CertificateAuthorityArn": "string"
-- }
EXEC @hr = sp_OADestroy @rest
EXEC @hr = sp_OADestroy @authAws
EXEC @hr = sp_OADestroy @json
EXEC @hr = sp_OADestroy @sbRequestBody
EXEC @hr = sp_OADestroy @sbResponseBody
EXEC @hr = sp_OADestroy @jResp
END
GO