Visual FoxPro
Visual FoxPro
SSL Client Certificate
See more Socket/SSL/TLS Examples
Demonstrates how to connect to an SSL server using a client-side certificate, send a simple message, receive a simple response, and disconnect.Chilkat Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loSocket
LOCAL loCertStore
LOCAL loJsonCN
LOCAL loCert
LOCAL lnSsl
LOCAL lnMaxWaitMillisec
LOCAL lcSslServerHost
LOCAL lnSslServerPort
LOCAL lcReceivedMsg
lnSuccess = 0
* This example requires the Chilkat API to have been previously unlocked.
* See Global Unlock Sample for sample code.
loSocket = CreateObject('Chilkat.Socket')
* Create an instance of a certificate store object, load a PFX file,
* locate the certificate we need, and use it for signing.
* (a PFX file may contain more than one certificate.)
loCertStore = CreateObject('Chilkat.CertStore')
* The 1st argument is the filename, the 2nd arg is the
* PFX file's password:
lnSuccess = loCertStore.LoadPfxFile("chilkat_secret.pfx","secret")
IF (lnSuccess <> 1) THEN
? loCertStore.LastErrorText
RELEASE loSocket
RELEASE loCertStore
CANCEL
ENDIF
* Find the certificate by the subject common name:
loJsonCN = CreateObject('Chilkat.JsonObject')
loJsonCN.UpdateString("CN","cert common name")
loCert = CreateObject('Chilkat.Cert')
lnSuccess = loCertStore.FindCert(loJsonCN,loCert)
IF (lnSuccess = 0) THEN
? loCertStore.LastErrorText
RELEASE loSocket
RELEASE loCertStore
RELEASE loJsonCN
RELEASE loCert
CANCEL
ENDIF
lnSuccess = loSocket.SetSslClientCert(loCert)
lnSsl = 1
lnMaxWaitMillisec = 20000
* The SSL server hostname may be an IP address, a domain name,
* or "localhost". You'll need to change this:
lcSslServerHost = "123.123.88.88"
lnSslServerPort = 8123
* Connect to the SSL server:
lnSuccess = loSocket.Connect(lcSslServerHost,lnSslServerPort,lnSsl,lnMaxWaitMillisec)
IF (lnSuccess <> 1) THEN
? loSocket.LastErrorText
RELEASE loSocket
RELEASE loCertStore
RELEASE loJsonCN
RELEASE loCert
CANCEL
ENDIF
* Set maximum timeouts for reading an writing (in millisec)
loSocket.MaxReadIdleMs = 20000
loSocket.MaxSendIdleMs = 20000
* Send a "Hello Server! -EOM-" message:
lnSuccess = loSocket.SendString("Hello Server! -EOM-")
IF (lnSuccess <> 1) THEN
? loSocket.LastErrorText
RELEASE loSocket
RELEASE loCertStore
RELEASE loJsonCN
RELEASE loCert
CANCEL
ENDIF
* The server (in this example) is going to send a "Hello Client! -EOM-"
* message. Read it:
lcReceivedMsg = loSocket.ReceiveUntilMatch("-EOM-")
IF (loSocket.LastMethodSuccess <> 1) THEN
? loSocket.LastErrorText
RELEASE loSocket
RELEASE loCertStore
RELEASE loJsonCN
RELEASE loCert
CANCEL
ENDIF
* Close the connection with the server
* Wait a max of 20 seconds (20000 millsec)
lnSuccess = loSocket.Close(20000)
? lcReceivedMsg
RELEASE loSocket
RELEASE loCertStore
RELEASE loJsonCN
RELEASE loCert