Sample code for 30+ languages & platforms
PowerBuilder

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 PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Http
oleobject loo_SslCert
oleobject loo_CertChain
oleobject loo_Cert
integer i
integer li_NumCerts
oleobject loo_CaCert

li_Success = 0

// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
    destroy loo_Http
    MessageBox("Error","Connecting to COM object failed")
    return
end if

// We're getting the SSL/TLS certificate, so make sure to connect to the SSL/TLS port (443).
loo_SslCert = create oleobject
li_rc = loo_SslCert.ConnectToNewObject("Chilkat.Cert")

li_Success = loo_Http.GetServerCert("apple.com",443,loo_SslCert)
if li_Success = 0 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_SslCert
    return
end if

loo_CertChain = create oleobject
li_rc = loo_CertChain.ConnectToNewObject("Chilkat.CertChain")

li_Success = loo_SslCert.BuildCertChain(loo_CertChain)
if li_Success = 0 then
    Write-Debug loo_SslCert.LastErrorText
    destroy loo_Http
    destroy loo_SslCert
    destroy loo_CertChain
    return
end if

loo_Cert = create oleobject
li_rc = loo_Cert.ConnectToNewObject("Chilkat.Cert")

i = 0
li_NumCerts = loo_CertChain.NumCerts
do while i < li_NumCerts
    loo_CertChain.CertAt(i,loo_Cert)
    Write-Debug "SubjectDN " + string(i) + ": " + loo_Cert.SubjectDN
    Write-Debug "IssuerDN " + string(i) + ": " + loo_Cert.IssuerDN
    i = i + 1
loop

// If the certificate chain reaches the root CA cert, then the last cert in the chain
// is the root CA cert.
if loo_CertChain.ReachesRoot = 1 then
    loo_CaCert = create oleobject
    li_rc = loo_CaCert.ConnectToNewObject("Chilkat.Cert")

    loo_CertChain.CertAt(li_NumCerts - 1,loo_CaCert)
    Write-Debug "CA Root Cert: " + loo_CaCert.SubjectDN
end if



destroy loo_Http
destroy loo_SslCert
destroy loo_CertChain
destroy loo_Cert
destroy loo_CaCert