PowerBuilder
PowerBuilder
Configure a Socket for Server-Side TLS
See more Socket/SSL/TLS Examples
Demonstrates Socket.InitSslServer, which configures the object for server-side TLS using a server certificate that has access to its private key, then listens for and accepts a TLS connection.
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. A TLS listener presents the configured server certificate during the handshake. When client certificates are required, acceptable CA distinguished names are added before InitSslServer.
Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Socket
string ls_PfxPassword
oleobject loo_Cert
oleobject loo_ConnectedSock
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
// Configure this object for server-side TLS using the certificate. The certificate must have
// access to its corresponding private key.
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
// Listen for connections. Accepted connections will use TLS.
li_Success = loo_Socket.BindAndListen(5000,25)
if li_Success = 0 then
Write-Debug loo_Socket.LastErrorText
destroy loo_Socket
destroy loo_Cert
return
end if
loo_ConnectedSock = create oleobject
li_rc = loo_ConnectedSock.ConnectToNewObject("Chilkat.Socket")
li_Success = loo_Socket.AcceptNext(20000,loo_ConnectedSock)
if li_Success = 0 then
Write-Debug loo_Socket.LastErrorText
destroy loo_Socket
destroy loo_Cert
destroy loo_ConnectedSock
return
end if
Write-Debug "Accepted a TLS client connection."
destroy loo_Socket
destroy loo_Cert
destroy loo_ConnectedSock