Xbase++
Xbase++
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 Xbase++ Downloads
LOCAL nSuccess
LOCAL oSocket
LOCAL cPfxPassword
LOCAL oCert
LOCAL oMyCert
nSuccess := 0
oSocket := CreateObject("Chilkat.Socket")
// 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.
cPfxPassword := "myPfxPassword"
oCert := CreateObject("Chilkat.Cert")
nSuccess := oCert:LoadPfxFile("qa_data/server.pfx", cPfxPassword)
IF (nSuccess == 0)
? oCert:LastErrorText
oSocket:destroy()
oCert:destroy()
RETURN
ENDIF
nSuccess := oSocket:InitSslServer(oCert)
IF (nSuccess == 0)
? oSocket:LastErrorText
oSocket:destroy()
oCert:destroy()
RETURN
ENDIF
// Copy the TLS server certificate configured by InitSslServer, then inspect it.
oMyCert := CreateObject("Chilkat.Cert")
nSuccess := oSocket:GetMyServerCert(oMyCert)
IF (nSuccess == 0)
? oSocket:LastErrorText
oSocket:destroy()
oCert:destroy()
oMyCert:destroy()
RETURN
ENDIF
? "Server certificate subject: " + oMyCert:SubjectCN
oSocket:destroy()
oCert:destroy()
oMyCert:destroy()