Tcl
Tcl
Get the IMAP Server's TLS Certificate
See more IMAP Examples
Demonstrates the Chilkat Imap.GetServerCert method, which retrieves the certificate the IMAP server presented on the current (or most recent) TLS connection. The only argument is a Cert object that receives the certificate. This example prints the subject and issuer common names.
Background: Chilkat already validates the server certificate as part of the TLS handshake, but this method lets an application inspect it directly — to log the issuer, display connection details, implement certificate pinning, or apply an application-specific trust policy. The
Cert object exposes the full certificate, including subject, issuer, validity dates, and the public key.Chilkat Tcl Downloads
load ./chilkat.dll
set success 0
# Demonstrates the Imap.GetServerCert method, which retrieves the certificate presented by the
# IMAP server on the current TLS connection. The only argument is a Cert object that receives
# the certificate.
set imap [new_CkImap]
CkImap_put_Ssl $imap 1
CkImap_put_Port $imap 993
set success [CkImap_Connect $imap "imap.example.com"]
if {$success == 0} then {
puts [CkImap_lastErrorText $imap]
delete_CkImap $imap
exit
}
set success [CkImap_Login $imap "user@example.com" "myPassword"]
if {$success == 0} then {
puts [CkImap_lastErrorText $imap]
delete_CkImap $imap
exit
}
# Get the server's TLS certificate for inspection or diagnostics.
set cert [new_CkCert]
set success [CkImap_GetServerCert $imap $cert]
if {$success == 0} then {
puts [CkImap_lastErrorText $imap]
delete_CkImap $imap
delete_CkCert $cert
exit
}
puts "Server certificate subject: [CkCert_subjectCN $cert]"
puts "Issued by: [CkCert_issuerCN $cert]"
set success [CkImap_Disconnect $imap]
if {$success == 0} then {
puts [CkImap_lastErrorText $imap]
delete_CkImap $imap
delete_CkCert $cert
exit
}
delete_CkImap $imap
delete_CkCert $cert