2
0

sign-windows.ps1 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. param(
  2. [Parameter(ValueFromRemainingArguments = $true)]
  3. [string[]] $Path
  4. )
  5. $ErrorActionPreference = "Stop"
  6. if (-not $Path -or $Path.Count -eq 0) {
  7. throw "At least one path is required"
  8. }
  9. if ($env:GITHUB_ACTIONS -ne "true") {
  10. Write-Host "Skipping Windows signing because this is not running on GitHub Actions"
  11. exit 0
  12. }
  13. $vars = @{
  14. endpoint = $env:AZURE_TRUSTED_SIGNING_ENDPOINT
  15. account = $env:AZURE_TRUSTED_SIGNING_ACCOUNT_NAME
  16. profile = $env:AZURE_TRUSTED_SIGNING_CERTIFICATE_PROFILE
  17. }
  18. if ($vars.Values | Where-Object { -not $_ }) {
  19. Write-Host "Skipping Windows signing because Azure Artifact Signing is not configured"
  20. exit 0
  21. }
  22. $moduleVersion = "0.5.8"
  23. $module = Get-Module -ListAvailable -Name TrustedSigning | Where-Object { $_.Version -eq [version] $moduleVersion }
  24. if (-not $module) {
  25. try {
  26. Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force -Scope CurrentUser | Out-Null
  27. }
  28. catch {
  29. Write-Host "NuGet package provider install skipped: $($_.Exception.Message)"
  30. }
  31. Install-Module -Name TrustedSigning -RequiredVersion $moduleVersion -Force -Repository PSGallery -Scope CurrentUser
  32. }
  33. Import-Module TrustedSigning -RequiredVersion $moduleVersion -Force
  34. $files = @($Path | ForEach-Object { Resolve-Path $_ -ErrorAction SilentlyContinue } | Select-Object -ExpandProperty Path -Unique)
  35. if (-not $files -or $files.Count -eq 0) {
  36. throw "No files matched the requested paths"
  37. }
  38. $params = @{
  39. Endpoint = $vars.endpoint
  40. CodeSigningAccountName = $vars.account
  41. CertificateProfileName = $vars.profile
  42. Files = ($files -join ",")
  43. FileDigest = "SHA256"
  44. TimestampDigest = "SHA256"
  45. TimestampRfc3161 = "http://timestamp.acs.microsoft.com"
  46. ExcludeEnvironmentCredential = $true
  47. ExcludeWorkloadIdentityCredential = $true
  48. ExcludeManagedIdentityCredential = $true
  49. ExcludeSharedTokenCacheCredential = $true
  50. ExcludeVisualStudioCredential = $true
  51. ExcludeVisualStudioCodeCredential = $true
  52. ExcludeAzureCliCredential = $false
  53. ExcludeAzurePowerShellCredential = $true
  54. ExcludeAzureDeveloperCliCredential = $true
  55. ExcludeInteractiveBrowserCredential = $true
  56. }
  57. Invoke-TrustedSigning @params