DataFlex
DataFlex
Set a TLS Client Certificate from a Cert Object
See more Socket/SSL/TLS Examples
Demonstrates Socket.SetSslClientCert, which configures a certificate as the client certificate for subsequent TLS connections. The certificate must have access to its private key.
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. Configure the client certificate before connecting. Use client certificates only when the server requests or requires client-certificate authentication (mutual TLS).
Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoSocket
String sPfxPassword
Variant vCert
Handle hoCert
Boolean iBTls
Integer iMaxWaitMs
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/client.pfx" sPfxPassword To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoCert To sTemp1
Showln sTemp1
Procedure_Return
End
// Configure the client certificate before connecting. Use this only when the server requests or
// requires client-certificate authentication (mutual TLS).
Get pvComObject of hoCert to vCert
Get ComSetSslClientCert Of hoSocket vCert To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoSocket To sTemp1
Showln sTemp1
Procedure_Return
End
Move True To iBTls
Move 5000 To iMaxWaitMs
Get ComConnect Of hoSocket "example.com" 5000 iBTls iMaxWaitMs To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoSocket To sTemp1
Showln sTemp1
Procedure_Return
End
Showln "Connected with mutual TLS."
End_Procedure