Chilkat Examples

ChilkatHOMEAndroid™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi DLLGoJavaNode.jsObjective-CPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwiftTclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

DataFlex Examples
Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Box
CAdES
CSR
CSV
Cert Store
Certificates
Cloud Signature CSC
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text
HTTP
HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
Regular Expressions
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
Secrets
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
X
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(DataFlex) Get the Server Certificate, Certificate Chain, and Root CA Certificate

Demonstrates 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.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

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

 

© 2000-2025 Chilkat Software, Inc. All Rights Reserved.