Skip to content

Commit d96e7da

Browse files
committed
add script for signed nupkg bulk validation
1 parent dae6e8f commit d96e7da

File tree

2 files changed

+66
-2
lines changed

2 files changed

+66
-2
lines changed

tools/Validate-SignedNupkg.ps1

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<#
2+
.SYNOPSIS
3+
Validates signed files. Use this code for manual validation of a folder of nupkg files.
4+
.DESCRIPTION
5+
Recursively validates folder for signed files.
6+
.NOTES
7+
Use this script to check files for valid signatures before release.
8+
.EXAMPLE
9+
.\Validate-SignedNupkg.ps1 -NupkgsPath "C:\MyNupkgs" -ExtractionPath "C:\MyNupkgs\Extracted"
10+
#>
11+
12+
param
13+
(
14+
[Parameter(Mandatory=$true)]
15+
# $NupkgsPath is the path to the folder of .nupkg files.
16+
[string] $NupkgsPath,
17+
[Parameter(Mandatory=$false)]
18+
# $ExtractionPath is the path to extract each nupkg folders separately to. Extracts to $NupkgsPath by default.
19+
[string] $ExtractionPath=[System.IO.Path]::Combine($PSScriptRoot, "extracted")
20+
)
21+
22+
###########
23+
# EXTRACT
24+
###########
25+
$nupkgs = Get-ChildItem -Path $nupkgPath -Filter *.nupkg
26+
$nupkgs | Out-String
27+
28+
New-Item -Path $extractionPath -ItemType Directory -Force
29+
30+
$nupkgs | ForEach-Object {Expand-Archive -Path $_.FullName -DestinationPath $([System.IO.Path]::Combine($extractionPath,$_.BaseName)) -Force}
31+
Write-Host -Message "Extracted nupkg modules to ${extractionPath}."
32+
33+
###########
34+
# VALIDATE
35+
###########
36+
37+
# Add string of file name to $exclude hashtable to exclude specific files.
38+
$exclude = @()
39+
$fileInfos = Get-ChildItem -Path $extractionPath -File -Recurse `
40+
| Where-Object { $_.Name -notin $exclude } `
41+
| Where-Object { $_.Extension -in @('.dll','.exe','.msi','.cab','.ps1','.psm1','.psd1','.pssc','.ps1xml') }
42+
43+
$filePaths = $fileInfos | ForEach-Object {$_.FullName}
44+
Write-Host "Scanning files:`n"
45+
$filePaths | Out-String
46+
47+
$authenticodeStatuses = $filePaths | Get-AuthenticodeSignature
48+
Write-Host "Statuses of files in the folder ${extractionPath}:`n"
49+
$authenticodeStatuses | Select-Object -Property Status, Path | Out-String -width 4096
50+
51+
$unsignedFiles = $authenticodeStatuses | Where-Object {$_.Status -eq [System.Management.Automation.SignatureStatus]::NotSigned}
52+
$unsignedFilesFormatted = $unsignedFiles | Select-Object -Property Status, Path | Out-String
53+
54+
if ($unsignedFiles)
55+
{
56+
Write-Host "ERROR: These files in ${extractionPath} are unsigned:"
57+
$unsignedFilesFormatted | Out-String -width 4096
58+
throw "ERROR: The module contains unsigned files."
59+
}

tools/validate-signing.ps1

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<#
22
.SYNOPSIS
3-
Validates signed files.
3+
Validates signed files, mainly used for the signing pipeline with multiplier for each module (i.e., runs within the directory of each module folder).
44
.DESCRIPTION
55
Recursively validates folder for signed files.
66
.NOTES
@@ -50,7 +50,7 @@ $exclude = @()
5050
if (Test-Path -Path $pathToValidate -PathType Container)
5151
{
5252
$fileInfos = Get-ChildItem -Path $pathToValidate -File -Recurse `
53-
| Where-Object { $_.Name -notin $exclude }
53+
| Where-Object { $_.Name -notin $exclude } `
5454
| Where-Object { $_.Extension -in @('.dll','.exe','.msi','.cab','.ps1','.psm1','.psd1','.pssc','.ps1xml') } `
5555
| Where-Object { $_.FullName -notlike $(Join-Path -Path "*${moduleName}" -ChildPath "test*") }
5656
}
@@ -63,6 +63,11 @@ else
6363
Write-Error -Message "Invalid path: ${pathToValidate}" -Category InvalidArgument
6464
}
6565

66+
if (!$fileInfos)
67+
{
68+
throw "ERROR: The path ${pathToValidate} contains no valid files to validate according to the filter in this code."
69+
}
70+
6671
$filePaths = $fileInfos | ForEach-Object {$_.FullName}
6772
$output = $filePaths | Out-String
6873
Write-Verbose -Message "Files to be checked: `n${output}" -Verbose

0 commit comments

Comments
 (0)