Sample code for 30+ languages & platforms
Tcl Requires Chilkat v11.7.0+

Verify the Authenticode Signature of an MSI, PowerShell, or VBScript File

See more Code Signing Examples

Demonstrates how to verify the Authenticode signature of a Windows Installer package (.msi), a PowerShell file (.ps1, .psm1, .psd1), or a VBScript file (.vbs), and how to get the certificate of the signer. Verifying these file types requires Chilkat v11.7.0 or later.

Chilkat Tcl Downloads

Tcl

load ./chilkat.dll

set success 0

#  This example requires the Chilkat API to have been previously unlocked.
#  See Global Unlock Sample for sample code.

#  Starting in Chilkat v11.7.0, VerifySignature can verify the Authenticode signature of
#    - Windows Installer packages (.msi)
#    - PowerShell scripts, modules, and data files (.ps1, .psm1, .psd1)
#    - VBScript files (.vbs)
#  in addition to EXE and DLL files.

#  This example verifies a signed PowerShell script.
#  To verify an .msi or a .vbs, pass the path of that file instead.
set path "C:/someDir/Deploy.ps1"

set codeSign [new_CkCodeSign]

set sigInfo [new_CkJsonObject]

#  VerifySignature returns true if the file has a valid Authenticode signature.
#  It returns false if the file is not signed, if the file was changed after it was signed,
#  or if the signing certificate is not trusted.
set valid [CkCodeSign_VerifySignature $codeSign $path $sigInfo]
if {$valid == 0} then {
    #  The LastErrorText explains why the verification failed.
    puts [CkCodeSign_lastErrorText $codeSign]
    delete_CkCodeSign $codeSign
    delete_CkJsonObject $sigInfo
    exit
}

puts "The Authenticode signature is valid."

#  The details of the signature are returned in the JSON, in the same layout as for an EXE or DLL.
#  See Verify Authenticode Signature of EXE or DLL for a sample of the JSON and code that parses it.
puts "signing algorithm: [CkJsonObject_stringOf $sigInfo {pkcs7.verify.signerInfo[0].signingAlgName}]"
puts "hash algorithm: [CkJsonObject_stringOf $sigInfo {pkcs7.verify.signerInfo[0].cert.digestAlgName}]"

#  Get the certificate of the signer.
#  The signer certificate is available only after a call to VerifySignature that returned true.
#  It is the public certificate only.  It does not include the signer's private key.
set signerCert [new_CkCert]

set success [CkCodeSign_GetSignerCert $codeSign $signerCert]
if {$success == 0} then {
    puts [CkCodeSign_lastErrorText $codeSign]
    delete_CkCodeSign $codeSign
    delete_CkJsonObject $sigInfo
    delete_CkCert $signerCert
    exit
}

puts "signed by: [CkCert_subjectCN $signerCert]"
puts "certificate issued by: [CkCert_issuerCN $signerCert]"
puts "certificate serial number: [CkCert_serialNumber $signerCert]"
puts "certificate valid until: [CkCert_validToStr $signerCert]"

delete_CkCodeSign $codeSign
delete_CkJsonObject $sigInfo
delete_CkCert $signerCert