-
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathSignFile.ps1
More file actions
53 lines (48 loc) · 1.43 KB
/
SignFile.ps1
File metadata and controls
53 lines (48 loc) · 1.43 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
# winget install --exact --id Microsoft.AzureCLI
# winget install -e --id Microsoft.Azure.TrustedSigningClientTools
param(
[string]$file = "",
[string]$file1 = "",
[string]$file2 = "",
[string]$file3 = "",
[string]$file4 = "",
[string]$file5 = "",
[string]$file6 = "",
[string]$file7 = "",
[boolean]$login = $false
)
if (-not $file) {
Write-Host "Usage: SignFile.ps1 -file <path to file to sign>"
exit 1
}
# if (-not (az account show --only-show-errors | Out-Null 2>&1)) {
# Write-Host "Already logged in."
# } else {
if ($login) {
az config set core.enable_broker_on_windows=false
az login
az account set --subscription "Pay-As-You-Go"
}
$args = @(
"sign", "/v", "/debug", "/fd", "SHA256",
"/tr", "http://timestamp.acs.microsoft.com",
"/td", "SHA256",
"/dlib", "$env:LOCALAPPDATA\Microsoft\MicrosoftTrustedSigningClientTools\Azure.CodeSigning.Dlib.dll",
"/dmdf", ".\SignfileMetadata.json"
)
# Add non-empty file arguments
foreach ($f in @($file, $file1, $file2, $file3, $file4, $file5, $file6, $file7)) {
if (![string]::IsNullOrWhiteSpace($f)) {
$args += $f
}
}
# Run signtool and capture the exit code
.\signtool.exe $args
$exitCode = $LASTEXITCODE
if ($exitCode -eq 0) {
Write-Host "File(s) signed successfully." -ForegroundColor Green
exit 0
} else {
Write-Host "Signing failed with exit code: $exitCode" -ForegroundColor Red
exit $exitCode
}