DataFlex
DataFlex
Get the Server Certificate, Certificate Chain, and Root CA Certificate
See more HTTP Examples
Demonstrates how to get the HTTP server certificate, its certificate chain, and the root CA certificate.Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoHttp
Variant vSslCert
Handle hoSslCert
Variant vCert
Chain Handle hoCertChain
Variant vCert
Handle hoCert
Integer i
Integer iNumCerts
Variant vCaCert
Handle hoCaCert
String sTemp1
Boolean bTemp1
Move False To iSuccess
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Get Create (RefClass(cComChilkatHttp)) To hoHttp
If (Not(IsComObjectCreated(hoHttp))) Begin
Send CreateComObject of hoHttp
End
// We're getting the SSL/TLS certificate, so make sure to connect to the SSL/TLS port (443).
Get Create (RefClass(cComChilkatCert)) To hoSslCert
If (Not(IsComObjectCreated(hoSslCert))) Begin
Send CreateComObject of hoSslCert
End
Get pvComObject of hoSslCert to vSslCert
Get ComGetServerCert Of hoHttp "apple.com" 443 vSslCert To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoHttp To sTemp1
Showln sTemp1
Procedure_Return
End
Get Create (RefClass(cComChilkatCertChain)) To hoCertChain
If (Not(IsComObjectCreated(hoCertChain))) Begin
Send CreateComObject of hoCertChain
End
Get pvComObject of hoCertChain to vCertChain
Get ComBuildCertChain Of hoSslCert vCertChain To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoSslCert To sTemp1
Showln sTemp1
Procedure_Return
End
Get Create (RefClass(cComChilkatCert)) To hoCert
If (Not(IsComObjectCreated(hoCert))) Begin
Send CreateComObject of hoCert
End
Move 0 To i
Get ComNumCerts Of hoCertChain To iNumCerts
While (i < iNumCerts)
Get pvComObject of hoCert to vCert
Get ComCertAt Of hoCertChain i vCert To iSuccess
Get ComSubjectDN Of hoCert To sTemp1
Showln "SubjectDN " i ": " sTemp1
Get ComIssuerDN Of hoCert To sTemp1
Showln "IssuerDN " i ": " sTemp1
Move (i + 1) To i
Loop
// If the certificate chain reaches the root CA cert, then the last cert in the chain
// is the root CA cert.
Get ComReachesRoot Of hoCertChain To bTemp1
If (bTemp1 = True) Begin
Get Create (RefClass(cComChilkatCert)) To hoCaCert
If (Not(IsComObjectCreated(hoCaCert))) Begin
Send CreateComObject of hoCaCert
End
Get pvComObject of hoCaCert to vCaCert
Get ComCertAt Of hoCertChain (iNumCerts - 1) vCaCert To iSuccess
Get ComSubjectDN Of hoCaCert To sTemp1
Showln "CA Root Cert: " sTemp1
End
End_Procedure