Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode 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
Bounced Email
Box
CAdES
CSR
CSV
Certificates
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
MS Storage Providers
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
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl

 

 

 

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

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

Use ChilkatAx-9.5.0-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.