DataFlex
DataFlex
Set a TLS Client Certificate from a PEM
See more Socket/SSL/TLS Examples
Demonstrates Socket.SetSslClientCertPem, which loads and configures a TLS client certificate and private key from PEM data or a PEM file.
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. Supply the PEM password when the private key is encrypted, and configure the client certificate before connecting. Use client certificates only for mutual TLS.
Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoSocket
String sPemPassword
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 PEM password should come from a secure source rather than being hard-coded.
Move "myPemPassword" To sPemPassword
// Load and configure the TLS client certificate and private key from a PEM file. Configure the
// client certificate before connecting.
Get ComSetSslClientCertPem Of hoSocket "qa_data/client.pem" sPemPassword 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