Sample code for 30+ languages & platforms
Lianja

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 Lianja Downloads

Lianja
llSuccess = .F.

loSocket = createobject("CkSocket")

//  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.
lcPfxPassword = "myPfxPassword"
loCert = createobject("CkCert")
llSuccess = loCert.LoadPfxFile("qa_data/server.pfx",lcPfxPassword)
if (llSuccess = .F.) then
    ? loCert.LastErrorText
    release loSocket
    release loCert
    return
endif

llSuccess = loSocket.InitSslServer(loCert)
if (llSuccess = .F.) then
    ? loSocket.LastErrorText
    release loSocket
    release loCert
    return
endif

//  Copy the TLS server certificate configured by InitSslServer, then inspect it.
loMyCert = createobject("CkCert")
llSuccess = loSocket.GetMyServerCert(loMyCert)
if (llSuccess = .F.) then
    ? loSocket.LastErrorText
    release loSocket
    release loCert
    release loMyCert
    return
endif

? "Server certificate subject: " + loMyCert.SubjectCN


release loSocket
release loCert
release loMyCert