Tcl
Tcl
Find a Certificate by it's SHA-1 Thumbprint
See more Cert Store Examples
Finds a certificate by it's SHA-1 hex thumbprint.Note: This example requires Chilkat v10.1.2 or later.
Chilkat Tcl Downloads
load ./chilkat.dll
set success 0
set certStore [new_CkCertStore]
set thumbprint "12c1dd8015f3f03f7b1fa619dc24e2493ca8b4b2"
# This opens the Current User certificate store on Windows,
# On MacOS and iOS it opens the default Keychain.
set bReadOnly 1
set success [CkCertStore_OpenCurrentUserStore $certStore $bReadOnly]
if {$success == 0} then {
puts [CkCertStore_lastErrorText $certStore]
delete_CkCertStore $certStore
exit
}
# Find the certificate having a specific SHA1 thumbprint.
set json [new_CkJsonObject]
CkJsonObject_UpdateString $json "thumbprint" $thumbprint
set cert [new_CkCert]
set success [CkCertStore_FindCert $certStore $json $cert]
if {$success == 0} then {
puts "Failed to find the certificate."
delete_CkCertStore $certStore
delete_CkJsonObject $json
delete_CkCert $cert
exit
}
puts "Found: [CkCert_subjectCN $cert]"
# -------------------------------------------------------------------------------------
# Alternatively, one could load a certificate store object with certs from a PEM file,
# and do the same thing..
set certStorePem [new_CkCertStore]
set success [CkCertStore_LoadPemFile $certStorePem "pemFiles/certificates.pem"]
if {$success == 0} then {
puts [CkCertStore_lastErrorText $certStorePem]
delete_CkCertStore $certStore
delete_CkJsonObject $json
delete_CkCert $cert
delete_CkCertStore $certStorePem
exit
}
set success [CkCertStore_FindCert $certStore $json $cert]
if {$success == 0} then {
puts "Failed to find the certificate."
delete_CkCertStore $certStore
delete_CkJsonObject $json
delete_CkCert $cert
delete_CkCertStore $certStorePem
exit
}
puts "Found: [CkCert_subjectCN $cert]"
delete_CkCertStore $certStore
delete_CkJsonObject $json
delete_CkCert $cert
delete_CkCertStore $certStorePem