@@ -458,14 +458,18 @@ function VM-Install-From-Zip {
458458 if ($verifySignature ) {
459459 # Check signature of all executable files individually
460460 Get-ChildItem - Path " $toolDir \*.exe" | ForEach-Object {
461+ $file = $_
461462 try {
462463 # Check signature for each file
463- VM- Assert-Signature $_ .FullName
464+ VM- Assert-Signature $file .FullName
464465 } catch {
465- # Remove the file with invalid signature
466- Write-Warning " Removing file '$ ( $_.FullName ) ' due to invalid signature"
467- Remove-Item $_.FullName - Force - ea 0 | Out-Null
468466 VM- Write-Log - Exception $_
467+ if ($_.Exception.Message -like " INVALID SIGNATURE*" )
468+ {
469+ # Remove the file with invalid signature
470+ VM- Write-Log " ERROR" " Removing file '$ ( $file.FullName ) ' due to invalid signature"
471+ Remove-Item $file.FullName - Force - ea 0 | Out-Null
472+ }
469473 }
470474 }
471475 }
@@ -738,6 +742,8 @@ function VM-Install-With-Installer {
738742 [Parameter (Mandatory = $false )]
739743 [bool ] $consoleApp = $false ,
740744 [Parameter (Mandatory = $false )]
745+ [switch ] $verifySignature ,
746+ [Parameter (Mandatory = $false )]
741747 [string ] $arguments = " " ,
742748 [Parameter (Mandatory = $false )]
743749 [string ] $iconLocation
@@ -753,9 +759,15 @@ function VM-Install-With-Installer {
753759 $packageArgs = @ {
754760 packageName = ${Env: ChocolateyPackageName}
755761 url = $url
756- checksum = $sha256
757- checksumType = " sha256"
758762 }
763+
764+ # Add checksum details only if signature verification is not requested
765+ if (-not $verifySignature )
766+ {
767+ $packageArgs.checksum = $sha256
768+ $packageArgs.checksumType = ' sha256'
769+ }
770+
759771 if ($ext -in @ (" zip" , " 7z" )) {
760772 VM- Remove-PreviousZipPackage ${Env: chocolateyPackageFolder}
761773 $unzippedDir = Join-Path $toolDir " $ ( $toolName ) _installer"
@@ -781,6 +793,25 @@ function VM-Install-With-Installer {
781793 VM- Assert-Path $installerPath
782794 }
783795
796+ if ($verifySignature ) {
797+ # Check signature of all executable files individually
798+ Get-ChildItem - path $toolDir - include * .msi, * .exe - recurse - File - ea 0 | ForEach-Object {
799+ $file = $_
800+ try {
801+ # Check signature for each file
802+ VM- Assert-Signature $file.FullName
803+ } catch {
804+ VM- Write-Log - Exception $_
805+ if ($_.Exception.Message -like " INVALID SIGNATURE*" )
806+ {
807+ # Remove the file with invalid signature
808+ VM- Write-Log " ERROR" " Removing file '$ ( $file.FullName ) ' due to invalid signature"
809+ Remove-Item $file.FullName - Force - ea 0 | Out-Null
810+ }
811+ }
812+ }
813+ }
814+
784815 # Install tool via native installer
785816 $packageArgs = @ {
786817 packageName = ${Env: ChocolateyPackageName}
0 commit comments