PowerBuilder
PowerBuilder
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 PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Socket
string ls_PfxPassword
oleobject loo_Cert
oleobject loo_MyCert
li_Success = 0
loo_Socket = create oleobject
li_rc = loo_Socket.ConnectToNewObject("Chilkat.Socket")
if li_rc < 0 then
destroy loo_Socket
MessageBox("Error","Connecting to COM object failed")
return
end if
// 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.
ls_PfxPassword = "myPfxPassword"
loo_Cert = create oleobject
li_rc = loo_Cert.ConnectToNewObject("Chilkat.Cert")
li_Success = loo_Cert.LoadPfxFile("qa_data/server.pfx",ls_PfxPassword)
if li_Success = 0 then
Write-Debug loo_Cert.LastErrorText
destroy loo_Socket
destroy loo_Cert
return
end if
li_Success = loo_Socket.InitSslServer(loo_Cert)
if li_Success = 0 then
Write-Debug loo_Socket.LastErrorText
destroy loo_Socket
destroy loo_Cert
return
end if
// Copy the TLS server certificate configured by InitSslServer, then inspect it.
loo_MyCert = create oleobject
li_rc = loo_MyCert.ConnectToNewObject("Chilkat.Cert")
li_Success = loo_Socket.GetMyServerCert(loo_MyCert)
if li_Success = 0 then
Write-Debug loo_Socket.LastErrorText
destroy loo_Socket
destroy loo_Cert
destroy loo_MyCert
return
end if
Write-Debug "Server certificate subject: " + loo_MyCert.SubjectCN
destroy loo_Socket
destroy loo_Cert
destroy loo_MyCert