-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSign.ps1
More file actions
89 lines (73 loc) · 2.98 KB
/
Copy pathSign.ps1
File metadata and controls
89 lines (73 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<#
.SYNOPSIS
Digital Signature Tool
.DESCRIPTION
A utility designed to simplify the code-signing process using SignTool.exe.
1. Prompts for target MSI/EXE and PFX Certificate via Windows File Picker.
2. Captures the PFX password via CLI.
3. Signs the file using SHA256
4. Automatically copies the verified signed file to 'C:\Signed Installer'.
5. Applies an RFC 3161 compliant SHA256 timestamp to ensure long-term signature validity.
.NOTES
Author: Aftab Khan
Version: 1.0
Date: 2026-05-18
RequirementS: Requires signtool.exe and its binaries located in "C:\SignTool\" requires a PFX file with Password and obviously an installer
#>
## <# 1. Select the Installer #>
Write-Host "`n[STEP 1] Pick the MSI or EXE you want to sign..." -ForegroundColor Yellow
Add-Type -AssemblyName System.Windows.Forms
$MSIPicker = New-Object System.Windows.Forms.OpenFileDialog
$MSIPicker.Title = "Select Installer"
$MSIPicker.Filter = "Installers (*.msi;*.exe)|*.msi;*.exe"
$MSIPicker.InitialDirectory = "C:\Installers"
if ($MSIPicker.ShowDialog() -ne "OK") {
Write-Host "No file selected. Exiting." -ForegroundColor Red
Read-Host "Press Enter to close..."
exit
}
$TargetFile = $MSIPicker.FileName
Write-Host "Selected: $TargetFile" -ForegroundColor Cyan
## <# 2. Select the Certificate #>
Write-Host "`n[STEP 2] Pick your PFX Certificate file..." -ForegroundColor Yellow
$PFXPicker = New-Object System.Windows.Forms.OpenFileDialog
$PFXPicker.Title = "Select PFX Certificate"
$PFXPicker.Filter = "Certificate (*.pfx)|*.pfx"
$PFXPicker.InitialDirectory = "C:\Installers"
if ($PFXPicker.ShowDialog() -ne "OK") {
Write-Host "No certificate selected. Exiting." -ForegroundColor Red
Read-Host "Press Enter to close..."
exit
}
$CertPath = $PFXPicker.FileName
Write-Host "Selected: $CertPath" -ForegroundColor Cyan
## <# 3. Enter Password #>
Write-Host "`n[STEP 3] Enter the PFX Password below..." -ForegroundColor Yellow
$Password = Read-Host -AsSecureString "Password"
$PlainTextPassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Password))
## <# 4. Sign the App #>
$SignTool = "C:\SignTool\signtool.exe"
Write-Host "`n--- Starting Digital Signature ---" -ForegroundColor Cyan
$Params = @(
"sign",
"/f", "`"$CertPath`"",
"/p", "`"$PlainTextPassword`"",
"/fd", "sha256",
"/td", "sha256",
"/tr", "http://timestamp.digicert.com",
"/v",
"`"$TargetFile`""
)
& $SignTool $Params
## <# 5. Copy to Signed Folder #>
$OutputDir = "C:\Signed Installer"
if (!(Test-Path $OutputDir)) { New-Item -Path $OutputDir -ItemType Directory | Out-Null }
try {
Copy-Item -Path $TargetFile -Destination $OutputDir -Force
Write-Host "`nSuccess! Signed file copied to: $OutputDir" -ForegroundColor Green
}
catch {
Write-Host "`nError copying file: $($_.Exception.Message)" -ForegroundColor Red
}
Write-Host "`nProcess Complete. Press Enter to exit..." -ForegroundColor Green
Read-Host