![]() |
Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(PureBasic) 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. Note: This example requires Chilkat v11.0.0 or greater.
IncludeFile "CkCert.pb" IncludeFile "CkHttp.pb" IncludeFile "CkCertChain.pb" Procedure ChilkatExample() success.i = 0 ; This example assumes the Chilkat API to have been previously unlocked. ; See Global Unlock Sample for sample code. http.i = CkHttp::ckCreate() If http.i = 0 Debug "Failed to create object." ProcedureReturn EndIf ; We're getting the SSL/TLS certificate, so make sure to connect to the SSL/TLS port (443). sslCert.i = CkCert::ckCreate() If sslCert.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success = CkHttp::ckGetServerCert(http,"apple.com",443,sslCert) If success = 0 Debug CkHttp::ckLastErrorText(http) CkHttp::ckDispose(http) CkCert::ckDispose(sslCert) ProcedureReturn EndIf certChain.i = CkCertChain::ckCreate() If certChain.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success = CkCert::ckBuildCertChain(sslCert,certChain) If success = 0 Debug CkCert::ckLastErrorText(sslCert) CkHttp::ckDispose(http) CkCert::ckDispose(sslCert) CkCertChain::ckDispose(certChain) ProcedureReturn EndIf cert.i = CkCert::ckCreate() If cert.i = 0 Debug "Failed to create object." ProcedureReturn EndIf i.i = 0 numCerts.i = CkCertChain::ckNumCerts(certChain) While i < numCerts CkCertChain::ckCertAt(certChain,i,cert) Debug "SubjectDN " + Str(i) + ": " + CkCert::ckSubjectDN(cert) Debug "IssuerDN " + Str(i) + ": " + CkCert::ckIssuerDN(cert) i = i + 1 Wend ; If the certificate chain reaches the root CA cert, then the last cert in the chain ; is the root CA cert. If CkCertChain::ckReachesRoot(certChain) = 1 caCert.i = CkCert::ckCreate() If caCert.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkCertChain::ckCertAt(certChain,numCerts - 1,caCert) Debug "CA Root Cert: " + CkCert::ckSubjectDN(caCert) EndIf CkHttp::ckDispose(http) CkCert::ckDispose(sslCert) CkCertChain::ckDispose(certChain) CkCert::ckDispose(cert) CkCert::ckDispose(caCert) ProcedureReturn EndProcedure |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.