Sample code for 30+ languages & platforms
Tcl

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 Tcl Downloads

Tcl

load ./chilkat.dll

set success 0

set socket [new_CkSocket]

#  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.
set pfxPassword "myPfxPassword"
set cert [new_CkCert]

set success [CkCert_LoadPfxFile $cert "qa_data/server.pfx" $pfxPassword]
if {$success == 0} then {
    puts [CkCert_lastErrorText $cert]
    delete_CkSocket $socket
    delete_CkCert $cert
    exit
}

set success [CkSocket_InitSslServer $socket $cert]
if {$success == 0} then {
    puts [CkSocket_lastErrorText $socket]
    delete_CkSocket $socket
    delete_CkCert $cert
    exit
}

#  Copy the TLS server certificate configured by InitSslServer, then inspect it.
set myCert [new_CkCert]

set success [CkSocket_GetMyServerCert $socket $myCert]
if {$success == 0} then {
    puts [CkSocket_lastErrorText $socket]
    delete_CkSocket $socket
    delete_CkCert $cert
    delete_CkCert $myCert
    exit
}

puts "Server certificate subject: [CkCert_subjectCN $myCert]"

delete_CkSocket $socket
delete_CkCert $cert
delete_CkCert $myCert