Sample code for 30+ languages & platforms
Swift

Enumerate Server-Advertised Acceptable Client CAs

See more Socket/SSL/TLS Examples

Demonstrates Socket.GetSslAcceptableClientCaDn, which returns a certificate-authority distinguished name advertised by a TLS server when it requests a client certificate.

Background. Valid indexes range from 0 through NumSslAcceptableClientCAs minus one. A client can use these names to select an appropriate client certificate.

Chilkat Swift Downloads

Swift

func chilkatTest() {
    var success: Bool = false

    let socket = CkoSocket()!

    //  Connect to the server using TLS.
    var bTls: Bool = true
    var maxWaitMs: Int = 5000
    success = socket.connect(hostname: "example.com", port: 5000, ssl: bTls, maxWaitMs: maxWaitMs)
    if success == false {
        print("\(socket.lastErrorText!)")
        return
    }

    //  After connecting to a server that requests a client certificate, enumerate the certificate-
    //  authority distinguished names the server advertised as acceptable.
    var numCAs: Int = socket.numSslAcceptableClientCAs.intValue
    var i: Int
    for i = 0; i <= numCAs - 1; i++ {
        var caDn: String? = socket.getSslAcceptableClientCaDn(index: i)
        if socket.lastMethodSuccess == false {
            print("\(socket.lastErrorText!)")
            return
        }

        print("\(caDn!)")
    }


}