Sample code for 30+ languages & platforms
Xbase++ Requires Chilkat v11.0.0+

Verify SSL Server Certificate

See more Socket/SSL/TLS Examples

Demonstrates how to connect to an SSL server and verify its SSL certificate.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oSocket
LOCAL nSsl
LOCAL nMaxWaitMillisec
LOCAL cSslServerHost
LOCAL nSslServerPort
LOCAL oCert
LOCAL nBExpired
LOCAL nBRevoked
LOCAL nBSignatureVerified
LOCAL nBTrustedRoot

nSuccess := 0

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

oSocket := CreateObject("Chilkat.Socket")

nSsl := 1
nMaxWaitMillisec := 20000

//  The SSL server hostname may be an IP address, a domain name,
//  or "localhost". 

cSslServerHost := "www.paypal.com"
nSslServerPort := 443

//  Connect to the SSL server:
nSuccess := oSocket:Connect(cSslServerHost, nSslServerPort, nSsl, nMaxWaitMillisec)
IF (nSuccess == 0)
    ? oSocket:LastErrorText
    oSocket:destroy()
    RETURN
ENDIF

oCert := CreateObject("Chilkat.Cert")

nSuccess := oSocket:GetServerCert(oCert)
IF (nSuccess != 0)

    ? "Server Certificate:"
    ? "Distinguished Name: " + oCert:SubjectDN
    ? "Common Name: " + oCert:SubjectCN
    ? "Issuer Distinguished Name: " + oCert:IssuerDN
    ? "Issuer Common Name: " + oCert:IssuerCN

    nBExpired := oCert:Expired
    nBRevoked := oCert:Revoked
    nBSignatureVerified := oCert:SignatureVerified
    nBTrustedRoot := oCert:TrustedRoot

    ? "Expired: " + Str(nBExpired)
    ? "Revoked: " + Str(nBRevoked)
    ? "Signature Verified: " + Str(nBSignatureVerified)
    ? "Trusted Root: " + Str(nBTrustedRoot)

ENDIF

//  Close the connection with the server
//  Wait a max of 20 seconds (20000 millsec)
nSuccess := oSocket:Close(20000)

oSocket:destroy()
oCert:destroy()