Swift
Swift
Get the Configured Server-Side TLS Certificate
See more Socket/SSL/TLS Examples
Demonstrates Socket.GetMyServerCert, which copies the TLS server certificate configured by InitSslServer into a Cert object.
The file path is relative to the application's current working directory. An absolute path may also be used. Supply the path appropriate to your own environment.
Background. This is intended for a socket acting as a TLS server and returns false when no server certificate has been configured.
Chilkat Swift Downloads
func chilkatTest() {
var success: Bool = false
let socket = CkoSocket()!
// The file path is relative to the application's current working directory. An absolute path
// may also be used. Supply the path appropriate to your own environment.
// The PFX password should come from a secure source rather than being hard-coded.
var pfxPassword: String? = "myPfxPassword"
let cert = CkoCert()!
success = cert.loadPfxFile(path: "qa_data/server.pfx", password: pfxPassword)
if success == false {
print("\(cert.lastErrorText!)")
return
}
success = socket.initSslServer(cert: cert)
if success == false {
print("\(socket.lastErrorText!)")
return
}
// Copy the TLS server certificate configured by InitSslServer, then inspect it.
let myCert = CkoCert()!
success = socket.getMyServerCert(cert: myCert)
if success == false {
print("\(socket.lastErrorText!)")
return
}
print("Server certificate subject: \(myCert.subjectCN!)")
}