Visual FoxPro
Visual FoxPro
Get a Received Client Certificate (Server Side)
See more Socket/SSL/TLS Examples
Demonstrates Socket.GetRcvdClientCert, which copies a client certificate presented during the TLS handshake of an accepted server-side connection into a Cert object.
The file path is relative to the application's current working directory. An absolute path may also be used. Supply the path appropriate to your own environment.
Background. Use
NumReceivedClientCerts to determine the valid index range. Client certificates are supplied only when the server requests them for mutual TLS.Chilkat Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loSocket
LOCAL lcPfxPassword
LOCAL loCert
LOCAL loConnectedSock
LOCAL lnNumClientCerts
LOCAL loClientCert
LOCAL i
lnSuccess = 0
loSocket = CreateObject('Chilkat.Socket')
* The file path is relative to the application's current working directory. An absolute path
* may also be used. Supply the path appropriate to your own environment.
* The PFX password should come from a secure source rather than being hard-coded.
lcPfxPassword = "myPfxPassword"
loCert = CreateObject('Chilkat.Cert')
lnSuccess = loCert.LoadPfxFile("qa_data/server.pfx",lcPfxPassword)
IF (lnSuccess = 0) THEN
? loCert.LastErrorText
RELEASE loSocket
RELEASE loCert
CANCEL
ENDIF
lnSuccess = loSocket.InitSslServer(loCert)
IF (lnSuccess = 0) THEN
? loSocket.LastErrorText
RELEASE loSocket
RELEASE loCert
CANCEL
ENDIF
lnSuccess = loSocket.BindAndListen(5000,25)
IF (lnSuccess = 0) THEN
? loSocket.LastErrorText
RELEASE loSocket
RELEASE loCert
CANCEL
ENDIF
* Accept a client connection. The accepted connection carries any client certificate presented
* during the TLS handshake.
loConnectedSock = CreateObject('Chilkat.Socket')
lnSuccess = loSocket.AcceptNext(20000,loConnectedSock)
IF (lnSuccess = 0) THEN
? loSocket.LastErrorText
RELEASE loSocket
RELEASE loCert
RELEASE loConnectedSock
CANCEL
ENDIF
* Copy each received client certificate and inspect it.
lnNumClientCerts = loConnectedSock.NumReceivedClientCerts
loClientCert = CreateObject('Chilkat.Cert')
FOR i = 0 TO lnNumClientCerts - 1
lnSuccess = loConnectedSock.GetRcvdClientCert(i,loClientCert)
IF (lnSuccess = 0) THEN
? loConnectedSock.LastErrorText
RELEASE loSocket
RELEASE loCert
RELEASE loConnectedSock
RELEASE loClientCert
CANCEL
ENDIF
? "Client certificate subject: " + loClientCert.SubjectCN
NEXT
RELEASE loSocket
RELEASE loCert
RELEASE loConnectedSock
RELEASE loClientCert