Lianja
Lianja
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 Lianja Downloads
llSuccess = .F.
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loHttp = createobject("CkHttp")
// We're getting the SSL/TLS certificate, so make sure to connect to the SSL/TLS port (443).
loSslCert = createobject("CkCert")
llSuccess = loHttp.GetServerCert("apple.com",443,loSslCert)
if (llSuccess = .F.) then
? loHttp.LastErrorText
release loHttp
release loSslCert
return
endif
loCertChain = createobject("CkCertChain")
llSuccess = loSslCert.BuildCertChain(loCertChain)
if (llSuccess = .F.) then
? loSslCert.LastErrorText
release loHttp
release loSslCert
release loCertChain
return
endif
loCert = createobject("CkCert")
i = 0
lnNumCerts = loCertChain.NumCerts
do while i < lnNumCerts
loCertChain.CertAt(i,loCert)
? "SubjectDN " + str(i) + ": " + loCert.SubjectDN
? "IssuerDN " + str(i) + ": " + loCert.IssuerDN
i = i + 1
enddo
// If the certificate chain reaches the root CA cert, then the last cert in the chain
// is the root CA cert.
if (loCertChain.ReachesRoot = .T.) then
loCaCert = createobject("CkCert")
loCertChain.CertAt(lnNumCerts - 1,loCaCert)
? "CA Root Cert: " + loCaCert.SubjectDN
endif
release loHttp
release loSslCert
release loCertChain
release loCert
release loCaCert