DataFlex
DataFlex
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 DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoSocket
String sPfxPassword
Variant vCert
Handle hoCert
Variant vConnectedSock
Handle hoConnectedSock
String sTemp1
Move False To iSuccess
Get Create (RefClass(cComChilkatSocket)) To hoSocket
If (Not(IsComObjectCreated(hoSocket))) Begin
Send CreateComObject of hoSocket
End
// 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.
Move "myPfxPassword" To sPfxPassword
Get Create (RefClass(cComChilkatCert)) To hoCert
If (Not(IsComObjectCreated(hoCert))) Begin
Send CreateComObject of hoCert
End
Get ComLoadPfxFile Of hoCert "qa_data/server.pfx" sPfxPassword To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoCert To sTemp1
Showln sTemp1
Procedure_Return
End
// Configure this object for server-side TLS using the certificate. The certificate must have
// access to its corresponding private key.
Get pvComObject of hoCert to vCert
Get ComInitSslServer Of hoSocket vCert To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoSocket To sTemp1
Showln sTemp1
Procedure_Return
End
// Listen for connections. Accepted connections will use TLS.
Get ComBindAndListen Of hoSocket 5000 25 To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoSocket To sTemp1
Showln sTemp1
Procedure_Return
End
Get Create (RefClass(cComChilkatSocket)) To hoConnectedSock
If (Not(IsComObjectCreated(hoConnectedSock))) Begin
Send CreateComObject of hoConnectedSock
End
Get pvComObject of hoConnectedSock to vConnectedSock
Get ComAcceptNext Of hoSocket 20000 vConnectedSock To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoSocket To sTemp1
Showln sTemp1
Procedure_Return
End
Showln "Accepted a TLS client connection."
End_Procedure