VBScript
VBScript
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 VBScript Downloads
Dim fso, outFile
Set fso = CreateObject("Scripting.FileSystemObject")
'Create a Unicode (utf-16) output text file.
Set outFile = fso.CreateTextFile("output.txt", True, True)
success = 0
set socket = CreateObject("Chilkat.Socket")
' Connect to the server using TLS.
bTls = 1
maxWaitMs = 5000
success = socket.Connect("example.com",5000,bTls,maxWaitMs)
If (success = 0) Then
outFile.WriteLine(socket.LastErrorText)
WScript.Quit
End If
' Copy the certificate presented by the remote TLS server, then inspect it. This can be used to
' validate the server's identity.
set cert = CreateObject("Chilkat.Cert")
success = socket.GetServerCert(cert)
If (success = 0) Then
outFile.WriteLine(socket.LastErrorText)
WScript.Quit
End If
outFile.WriteLine("Server certificate subject: " & cert.SubjectCN)
outFile.WriteLine("Issued by: " & cert.IssuerCN)
outFile.Close