Chilkat Online Tools

DescribeCertificateAuthority Swift3 Example

AWS Private CA

func chilkatTest() {
    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    let rest = CkoRest()!
    var success: Bool

    let authAws = CkoAuthAws()!
    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: 443, tls: true, autoReconnect: true)
    if success != true {
        print("ConnectFailReason: \(rest.connectFailReason.intValue)")
        print("\(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

    let json = CkoJsonObject()!
    json.update("CertificateAuthorityArn", value: "string")

    // The JSON request body created by the above code:

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

    rest.addHeader("Content-Type", value: "application/x-amz-json-1.1")
    rest.addHeader("X-Amz-Target", value: "ACMPrivateCA.DescribeCertificateAuthority")

    let sbRequestBody = CkoStringBuilder()!
    json.emitSb(sbRequestBody)
    let sbResponseBody = CkoStringBuilder()!
    success = rest.fullRequestSb("POST", uriPath: "/", requestBody: sbRequestBody, responseBody: sbResponseBody)
    if success != true {
        print("\(rest.lastErrorText!)")
        return
    }

    var respStatusCode: Int = rest.responseStatusCode.intValue
    print("response status code = \(respStatusCode)")
    if respStatusCode != 200 {
        print("Response Header:")
        print("\(rest.responseHeader!)")
        print("Response Body:")
        print("\(sbResponseBody.getAsString()!)")
        return
    }

    let jResp = CkoJsonObject()!
    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

    var DirectoryNameCommonName: String?
    var DirectoryNameCountry: String?
    var DirectoryNameDistinguishedNameQualifier: String?
    var DirectoryNameGenerationQualifier: String?
    var DirectoryNameGivenName: String?
    var DirectoryNameInitials: String?
    var DirectoryNameLocality: String?
    var DirectoryNameOrganization: String?
    var DirectoryNameOrganizationalUnit: String?
    var DirectoryNamePseudonym: String?
    var DirectoryNameSerialNumber: String?
    var DirectoryNameState: String?
    var DirectoryNameSurname: String?
    var DirectoryNameTitle: String?
    var DnsName: String?
    var NameAssigner: String?
    var PartyName: String?
    var IpAddress: String?
    var TypeId: String?
    var Value: String?
    var RegisteredId: String?
    var Rfc822Name: String?
    var UniformResourceIdentifier: String?
    var AccessMethodType: String?
    var CustomObjectIdentifier: String?

    var Arn: String? = jResp.string(of: "CertificateAuthority.Arn")
    var CRLSign: Int = jResp.int(of: "CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.CRLSign").intValue
    var DataEncipherment: Int = jResp.int(of: "CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.DataEncipherment").intValue
    var DecipherOnly: Int = jResp.int(of: "CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.DecipherOnly").intValue
    var DigitalSignature: Int = jResp.int(of: "CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.DigitalSignature").intValue
    var EncipherOnly: Int = jResp.int(of: "CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.EncipherOnly").intValue
    var KeyAgreement: Int = jResp.int(of: "CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.KeyAgreement").intValue
    var KeyCertSign: Int = jResp.int(of: "CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.KeyCertSign").intValue
    var KeyEncipherment: Int = jResp.int(of: "CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.KeyEncipherment").intValue
    var NonRepudiation: Int = jResp.int(of: "CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.NonRepudiation").intValue
    var KeyAlgorithm: String? = jResp.string(of: "CertificateAuthority.CertificateAuthorityConfiguration.KeyAlgorithm")
    var SigningAlgorithm: String? = jResp.string(of: "CertificateAuthority.CertificateAuthorityConfiguration.SigningAlgorithm")
    var CommonName: String? = jResp.string(of: "CertificateAuthority.CertificateAuthorityConfiguration.Subject.CommonName")
    var Country: String? = jResp.string(of: "CertificateAuthority.CertificateAuthorityConfiguration.Subject.Country")
    var DistinguishedNameQualifier: String? = jResp.string(of: "CertificateAuthority.CertificateAuthorityConfiguration.Subject.DistinguishedNameQualifier")
    var GenerationQualifier: String? = jResp.string(of: "CertificateAuthority.CertificateAuthorityConfiguration.Subject.GenerationQualifier")
    var GivenName: String? = jResp.string(of: "CertificateAuthority.CertificateAuthorityConfiguration.Subject.GivenName")
    var Initials: String? = jResp.string(of: "CertificateAuthority.CertificateAuthorityConfiguration.Subject.Initials")
    var Locality: String? = jResp.string(of: "CertificateAuthority.CertificateAuthorityConfiguration.Subject.Locality")
    var Organization: String? = jResp.string(of: "CertificateAuthority.CertificateAuthorityConfiguration.Subject.Organization")
    var OrganizationalUnit: String? = jResp.string(of: "CertificateAuthority.CertificateAuthorityConfiguration.Subject.OrganizationalUnit")
    var Pseudonym: String? = jResp.string(of: "CertificateAuthority.CertificateAuthorityConfiguration.Subject.Pseudonym")
    var SerialNumber: String? = jResp.string(of: "CertificateAuthority.CertificateAuthorityConfiguration.Subject.SerialNumber")
    var State: String? = jResp.string(of: "CertificateAuthority.CertificateAuthorityConfiguration.Subject.State")
    var Surname: String? = jResp.string(of: "CertificateAuthority.CertificateAuthorityConfiguration.Subject.Surname")
    var Title: String? = jResp.string(of: "CertificateAuthority.CertificateAuthorityConfiguration.Subject.Title")
    var CreatedAt: Int = jResp.int(of: "CertificateAuthority.CreatedAt").intValue
    var FailureReason: String? = jResp.string(of: "CertificateAuthority.FailureReason")
    var KeyStorageSecurityStandard: String? = jResp.string(of: "CertificateAuthority.KeyStorageSecurityStandard")
    var LastStateChangeAt: Int = jResp.int(of: "CertificateAuthority.LastStateChangeAt").intValue
    var NotAfter: Int = jResp.int(of: "CertificateAuthority.NotAfter").intValue
    var NotBefore: Int = jResp.int(of: "CertificateAuthority.NotBefore").intValue
    var OwnerAccount: String? = jResp.string(of: "CertificateAuthority.OwnerAccount")
    var RestorableUntil: Int = jResp.int(of: "CertificateAuthority.RestorableUntil").intValue
    var CustomCname: String? = jResp.string(of: "CertificateAuthority.RevocationConfiguration.CrlConfiguration.CustomCname")
    var Enabled: Int = jResp.int(of: "CertificateAuthority.RevocationConfiguration.CrlConfiguration.Enabled").intValue
    var ExpirationInDays: Int = jResp.int(of: "CertificateAuthority.RevocationConfiguration.CrlConfiguration.ExpirationInDays").intValue
    var S3BucketName: String? = jResp.string(of: "CertificateAuthority.RevocationConfiguration.CrlConfiguration.S3BucketName")
    var S3ObjectAcl: String? = jResp.string(of: "CertificateAuthority.RevocationConfiguration.CrlConfiguration.S3ObjectAcl")
    var OcspConfigurationEnabled: Int = jResp.int(of: "CertificateAuthority.RevocationConfiguration.OcspConfiguration.Enabled").intValue
    var OcspCustomCname: String? = jResp.string(of: "CertificateAuthority.RevocationConfiguration.OcspConfiguration.OcspCustomCname")
    var Serial: String? = jResp.string(of: "CertificateAuthority.Serial")
    var Status: String? = jResp.string(of: "CertificateAuthority.Status")
    var v_Type: String? = jResp.string(of: "CertificateAuthority.Type")
    var i: Int = 0
    var count_i: Int = jResp.size(ofArray: "CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess").intValue
    while i < count_i {
        jResp.i = i
        DirectoryNameCommonName = jResp.string(of: "CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[i].AccessLocation.DirectoryName.CommonName")
        DirectoryNameCountry = jResp.string(of: "CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[i].AccessLocation.DirectoryName.Country")
        DirectoryNameDistinguishedNameQualifier = jResp.string(of: "CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[i].AccessLocation.DirectoryName.DistinguishedNameQualifier")
        DirectoryNameGenerationQualifier = jResp.string(of: "CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[i].AccessLocation.DirectoryName.GenerationQualifier")
        DirectoryNameGivenName = jResp.string(of: "CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[i].AccessLocation.DirectoryName.GivenName")
        DirectoryNameInitials = jResp.string(of: "CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[i].AccessLocation.DirectoryName.Initials")
        DirectoryNameLocality = jResp.string(of: "CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[i].AccessLocation.DirectoryName.Locality")
        DirectoryNameOrganization = jResp.string(of: "CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[i].AccessLocation.DirectoryName.Organization")
        DirectoryNameOrganizationalUnit = jResp.string(of: "CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[i].AccessLocation.DirectoryName.OrganizationalUnit")
        DirectoryNamePseudonym = jResp.string(of: "CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[i].AccessLocation.DirectoryName.Pseudonym")
        DirectoryNameSerialNumber = jResp.string(of: "CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[i].AccessLocation.DirectoryName.SerialNumber")
        DirectoryNameState = jResp.string(of: "CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[i].AccessLocation.DirectoryName.State")
        DirectoryNameSurname = jResp.string(of: "CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[i].AccessLocation.DirectoryName.Surname")
        DirectoryNameTitle = jResp.string(of: "CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[i].AccessLocation.DirectoryName.Title")
        DnsName = jResp.string(of: "CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[i].AccessLocation.DnsName")
        NameAssigner = jResp.string(of: "CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[i].AccessLocation.EdiPartyName.NameAssigner")
        PartyName = jResp.string(of: "CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[i].AccessLocation.EdiPartyName.PartyName")
        IpAddress = jResp.string(of: "CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[i].AccessLocation.IpAddress")
        TypeId = jResp.string(of: "CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[i].AccessLocation.OtherName.TypeId")
        Value = jResp.string(of: "CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[i].AccessLocation.OtherName.Value")
        RegisteredId = jResp.string(of: "CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[i].AccessLocation.RegisteredId")
        Rfc822Name = jResp.string(of: "CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[i].AccessLocation.Rfc822Name")
        UniformResourceIdentifier = jResp.string(of: "CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[i].AccessLocation.UniformResourceIdentifier")
        AccessMethodType = jResp.string(of: "CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[i].AccessMethod.AccessMethodType")
        CustomObjectIdentifier = jResp.string(of: "CertificateAuthority.CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[i].AccessMethod.CustomObjectIdentifier")
        i = i + 1
    }

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

    // {
    //   "CertificateAuthority": {
    //     "Arn": "string",
    //     "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"
    //       }
    //     },
    //     "CreatedAt": number,
    //     "FailureReason": "string",
    //     "KeyStorageSecurityStandard": "string",
    //     "LastStateChangeAt": number,
    //     "NotAfter": number,
    //     "NotBefore": number,
    //     "OwnerAccount": "string",
    //     "RestorableUntil": number,
    //     "RevocationConfiguration": {
    //       "CrlConfiguration": {
    //         "CustomCname": "string",
    //         "Enabled": boolean,
    //         "ExpirationInDays": number,
    //         "S3BucketName": "string",
    //         "S3ObjectAcl": "string"
    //       },
    //       "OcspConfiguration": {
    //         "Enabled": boolean,
    //         "OcspCustomCname": "string"
    //       }
    //     },
    //     "Serial": "string",
    //     "Status": "string",
    //     "Type": "string"
    //   }
    // }

}