DataFlex
DataFlex
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 DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoSocket
String sPfxPassword
Variant vCert
Handle hoCert
Variant vMyCert
Handle hoMyCert
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
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
// Copy the TLS server certificate configured by InitSslServer, then inspect it.
Get Create (RefClass(cComChilkatCert)) To hoMyCert
If (Not(IsComObjectCreated(hoMyCert))) Begin
Send CreateComObject of hoMyCert
End
Get pvComObject of hoMyCert to vMyCert
Get ComGetMyServerCert Of hoSocket vMyCert To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoSocket To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComSubjectCN Of hoMyCert To sTemp1
Showln "Server certificate subject: " sTemp1
End_Procedure