Sample code for 30+ languages & platforms
Visual FoxPro

Get the Server Certificate from a TLS Connection

See more Socket/SSL/TLS Examples

Demonstrates Socket.GetServerCert, which copies the certificate presented by the remote TLS server into a Cert object for inspection.

Background. The method returns false when the socket is not connected, is not using TLS, or no server certificate is available. Inspecting the certificate lets an application validate the server's identity.

Chilkat Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loSocket
LOCAL lnBTls
LOCAL lnMaxWaitMs
LOCAL loCert

lnSuccess = 0

loSocket = CreateObject('Chilkat.Socket')

*  Connect to the server using TLS.
lnBTls = 1
lnMaxWaitMs = 5000
lnSuccess = loSocket.Connect("example.com",5000,lnBTls,lnMaxWaitMs)
IF (lnSuccess = 0) THEN
    ? loSocket.LastErrorText
    RELEASE loSocket
    CANCEL
ENDIF

*  Copy the certificate presented by the remote TLS server, then inspect it.  This can be used to
*  validate the server's identity.
loCert = CreateObject('Chilkat.Cert')
lnSuccess = loSocket.GetServerCert(loCert)
IF (lnSuccess = 0) THEN
    ? loSocket.LastErrorText
    RELEASE loSocket
    RELEASE loCert
    CANCEL
ENDIF

? "Server certificate subject: " + loCert.SubjectCN
? "Issued by: " + loCert.IssuerCN

RELEASE loSocket
RELEASE loCert