Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(DataFlex) Get the Server Certificate, Certificate Chain, and Root CA CertificateDemonstrates how to get the HTTP server certificate, its certificate chain, and the root CA certificate.
Use ChilkatAx-win32.pkg Procedure Test Handle hoHttp Variant vSslCert Handle hoSslCert Variant vCertChain Handle hoCertChain Integer i Integer iNumCerts Variant vCert Handle hoCert Variant vCaCert Handle hoCaCert String sTemp1 Boolean bTemp1 // 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 ComGetServerSslCert Of hoHttp "nationalgeographic.com" 443 To vSslCert If (IsComObject(vSslCert)) Begin Get Create (RefClass(cComChilkatCert)) To hoSslCert Set pvComObject Of hoSslCert To vSslCert End Get ComLastMethodSuccess Of hoHttp To bTemp1 If (bTemp1 = False) Begin Get ComLastErrorText Of hoHttp To sTemp1 Showln sTemp1 Procedure_Return End // Note: Prior to v9.5.0.50, this method would fail if the certificate chain could not // be completed to the root. Starting in v9.5.0.50, the incomplete certificate chain // will be returned. The certificate chain's ReachesRoot property can be examined to // see if the chain was completed to the root. Get ComGetCertChain Of hoSslCert To vCertChain If (IsComObject(vCertChain)) Begin Get Create (RefClass(cComChilkatCertChain)) To hoCertChain Set pvComObject Of hoCertChain To vCertChain End Get ComLastMethodSuccess Of hoSslCert To bTemp1 If (bTemp1 = False) Begin Get ComLastErrorText Of hoSslCert To sTemp1 Showln sTemp1 Send Destroy of hoSslCert Procedure_Return End Move 0 To i Get ComNumCerts Of hoCertChain To iNumCerts While (i < iNumCerts) Get ComGetCert Of hoCertChain i To vCert If (IsComObject(vCert)) Begin Get Create (RefClass(cComChilkatCert)) To hoCert Set pvComObject Of hoCert To vCert End Get ComSubjectDN Of hoCert To sTemp1 Showln "SubjectDN " i ": " sTemp1 Get ComIssuerDN Of hoCert To sTemp1 Showln "IssuerDN " i ": " sTemp1 Send Destroy of hoCert 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 ComGetCert Of hoCertChain (iNumCerts - 1) To vCaCert If (IsComObject(vCaCert)) Begin Get Create (RefClass(cComChilkatCert)) To hoCaCert Set pvComObject Of hoCaCert To vCaCert End Get ComSubjectDN Of hoCaCert To sTemp1 Showln "CA Root Cert: " sTemp1 Send Destroy of hoCaCert End Send Destroy of hoSslCert Send Destroy of hoCertChain End_Procedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.