Sample code for 30+ languages & platforms
Lua

Get the Configured Server-Side TLS Certificate

See more Socket/SSL/TLS Examples

Demonstrates Socket.GetMyServerCert, which copies the TLS server certificate configured by InitSslServer 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. This is intended for a socket acting as a TLS server and returns false when no server certificate has been configured.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

local socket = chilkat.Socket.new()

-- 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.
local pfxPassword = "myPfxPassword"
local cert = chilkat.Cert.new()
local success = cert:load_pfx_file("qa_data/server.pfx", pfxPassword)
if not success then
    print(cert.last_error_text)
    return
end

success = socket:init_ssl_server(cert)
if not success then
    print(socket.last_error_text)
    return
end

-- Copy the TLS server certificate configured by InitSslServer, then inspect it.
local myCert = chilkat.Cert.new()
success = socket:get_my_server_cert(myCert)
if not success then
    print(socket.last_error_text)
    return
end

print("Server certificate subject: " .. myCert.subject_cn)