Lua Requires Chilkat v11.0.0+
Lua
Verify SSL Server Certificate
See more Socket/SSL/TLS Examples
Demonstrates how to connect to an SSL server and verify its SSL certificate.Chilkat Lua Downloads
local chilkat = require("chilkat")
-- This example requires the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
local socket = chilkat.Socket.new()
local ssl = true
local maxWaitMillisec = 20000
-- The SSL server hostname may be an IP address, a domain name,
-- or "localhost".
local sslServerHost = "www.paypal.com"
local sslServerPort = 443
-- Connect to the SSL server:
local success = socket:connect(sslServerHost, sslServerPort, ssl, maxWaitMillisec)
if not success then
print(socket.last_error_text)
return
end
local cert = chilkat.Cert.new()
local bExpired = false
local bRevoked = false
local bSignatureVerified = false
local bTrustedRoot = false
success = socket:get_server_cert(cert)
if success then
print("Server Certificate:")
print("Distinguished Name: " .. cert.subject_dn)
print("Common Name: " .. cert.subject_cn)
print("Issuer Distinguished Name: " .. cert.issuer_dn)
print("Issuer Common Name: " .. cert.issuer_cn)
bExpired = cert.expired
bRevoked = cert.revoked
bSignatureVerified = cert.signature_verified
bTrustedRoot = cert.trusted_root
print("Expired: " .. tostring(bExpired))
print("Revoked: " .. tostring(bRevoked))
print("Signature Verified: " .. tostring(bSignatureVerified))
print("Trusted Root: " .. tostring(bTrustedRoot))
end
-- Close the connection with the server
-- Wait a max of 20 seconds (20000 millsec)
success = socket:close(20000)