-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Add catalog signing for .js files and direct signing for .cab files #127242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jesuszarate
wants to merge
1
commit into
dotnet:main
Choose a base branch
from
jesuszarate:dev/jezarat/sign-mono-cab-js
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+124
−2
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| <# | ||
| .SYNOPSIS | ||
| Generates a catalog definition file (.cdf) and catalog file (.cat) for all .js files | ||
| in the specified root directory. Used for VS signing compliance - the .js files are | ||
| customer-modifiable and cannot be directly Authenticode-signed. | ||
|
|
||
| .PARAMETER RootPath | ||
| Root directory to search for .js files recursively. | ||
|
|
||
| .PARAMETER CatOutputPath | ||
| Full path for the output .cat file. | ||
| #> | ||
| param( | ||
| [Parameter(Mandatory)][string]$RootPath, | ||
| [Parameter(Mandatory)][string]$CatOutputPath, | ||
| [string]$WindowsSdkDir = '', | ||
| [switch]$ErrorIfMakecatNotFound | ||
| ) | ||
|
|
||
| $ErrorActionPreference = 'Stop' | ||
|
|
||
| $cdfPath = [System.IO.Path]::ChangeExtension($CatOutputPath, '.cdf') | ||
|
|
||
| $files = Get-ChildItem -Path $RootPath -Recurse -Filter '*.js' -File | ||
| if ($files.Count -eq 0) { | ||
| Write-Warning "No .js files found under $RootPath - skipping catalog generation." | ||
| exit 0 | ||
| } | ||
|
|
||
| $cdf = @() | ||
| $cdf += '[CatalogHeader]' | ||
| $cdf += "Name=$CatOutputPath" | ||
| $cdf += 'CatalogVersion=2' | ||
| $cdf += 'HashAlgorithms=SHA256' | ||
| $cdf += '' | ||
| $cdf += '[CatalogFiles]' | ||
|
|
||
| $i = 0 | ||
| foreach ($f in $files) { | ||
| $label = "js_${i}_" + ($f.Name -replace '[^\w\.-]', '_') | ||
| $cdf += "<hash>$label=$($f.FullName)" | ||
| $i++ | ||
| } | ||
|
|
||
| $cdf | Set-Content -Path $cdfPath -Encoding ASCII | ||
| Write-Host "Generated CDF with $($files.Count) .js files at $cdfPath" | ||
|
|
||
| $catDir = [System.IO.Path]::GetDirectoryName($CatOutputPath) | ||
| if (-not (Test-Path $catDir)) { | ||
| New-Item -ItemType Directory -Path $catDir -Force | Out-Null | ||
| } | ||
|
|
||
| # Find makecat.exe - it ships with the Windows SDK and may not be on PATH. | ||
| $makecat = $null | ||
| if ($WindowsSdkDir -and (Test-Path $WindowsSdkDir)) { | ||
| $makecat = Get-ChildItem -Path (Join-Path $WindowsSdkDir 'bin') -Recurse -Filter 'makecat.exe' -File | | ||
| Where-Object { $_.DirectoryName -match 'x64' } | | ||
| Sort-Object DirectoryName -Descending | | ||
| Select-Object -First 1 | ||
| } | ||
|
|
||
| if (-not $makecat) { | ||
| $makecat = Get-Command makecat.exe -ErrorAction SilentlyContinue | ||
| } | ||
|
|
||
| if (-not $makecat) { | ||
| # Fallback: search common Windows SDK locations | ||
| $sdkRoot = "${env:ProgramFiles(x86)}\Windows Kits\10\bin" | ||
| if (Test-Path $sdkRoot) { | ||
| $makecat = Get-ChildItem -Path $sdkRoot -Recurse -Filter 'makecat.exe' -File | | ||
| Where-Object { $_.DirectoryName -match 'x64' } | | ||
| Sort-Object DirectoryName -Descending | | ||
| Select-Object -First 1 | ||
| } | ||
| } | ||
|
|
||
| if (-not $makecat) { | ||
| if ($ErrorIfMakecatNotFound) { | ||
| throw "makecat.exe not found. Catalog signing requires the Windows SDK which must be available in CI builds." | ||
| } | ||
| Write-Warning "makecat.exe not found - skipping catalog generation. Catalog signing requires the Windows SDK." | ||
| exit 0 | ||
| } | ||
|
|
||
| $makecatPath = if ($makecat -is [System.Management.Automation.CommandInfo]) { $makecat.Source } else { $makecat.FullName } | ||
| Write-Host "Using makecat.exe at: $makecatPath" | ||
|
|
||
| & $makecatPath $cdfPath | ||
| if ($LASTEXITCODE -ne 0) { | ||
| throw "makecat.exe failed with exit code $LASTEXITCODE" | ||
| } | ||
|
|
||
| Write-Host "Generated catalog file: $CatOutputPath" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is for correctness, can we instead add this in dotnet/arcade? Then everyone that builds MSIs will get it (SDK as well).