@trillboards/edge-sdk 0.2.25 → 0.2.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -57,6 +57,12 @@
57
57
  signed (by Azure Trusted Signing) and are proved
58
58
  as-is, with the unsigned control derived by stripping
59
59
  the signature block from a copy.
60
+ .PARAMETER RetainSelfSignedFixturePath
61
+ In hermetic mode, retain the exact proven root until
62
+ a downstream proof cleans it and write only its
63
+ subject/thumbprint metadata to this path. The owning
64
+ harness emits this directly; callers must not scan
65
+ the certificate provider after the proof.
60
66
 
61
67
  .NOTES
62
68
  .cmd/.bat have no Authenticode SIP and cmd.exe has no execution policy, so a
@@ -71,7 +77,8 @@ param(
71
77
  [string]$CanaryPs1 = "",
72
78
  [string]$CanaryVbs = "",
73
79
  [switch]$SelfSign,
74
- [switch]$AlreadySigned
80
+ [switch]$AlreadySigned,
81
+ [string]$RetainSelfSignedFixturePath = ""
75
82
  )
76
83
 
77
84
  $ErrorActionPreference = 'Stop'
@@ -81,12 +88,17 @@ if (-not ($SelfSign -xor $AlreadySigned)) {
81
88
  Write-Error 'Choose exactly one of -SelfSign or -AlreadySigned.'
82
89
  exit 2
83
90
  }
91
+ if ($RetainSelfSignedFixturePath -and -not $SelfSign) {
92
+ Write-Error '-RetainSelfSignedFixturePath is valid only with -SelfSign.'
93
+ exit 2
94
+ }
84
95
 
85
96
  $PolicyKey = 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\PowerShell'
86
97
  $WshKey = 'HKLM:\SOFTWARE\Microsoft\Windows Script Host\Settings'
87
98
  $Work = Join-Path ([IO.Path]::GetTempPath()) ("tb-allsigned-" + [Guid]::NewGuid().ToString('N').Substring(0, 8))
88
99
  $failures = New-Object System.Collections.Generic.List[string]
89
100
  $addedThumbprints = New-Object System.Collections.Generic.List[string]
101
+ $retainedRootThumbprint = $null
90
102
 
91
103
  function Say($m) { Write-Host "[allsigned] $m" }
92
104
  function Fail($m) { $script:failures.Add($m); Write-Host "[allsigned] FAIL: $m" -ForegroundColor Red }
@@ -288,6 +300,7 @@ try {
288
300
  # reason.
289
301
  Add-CertToStore -Cert $pub -StoreName 'Root'
290
302
  $addedThumbprints.Add('Root|' + $pub.Thumbprint)
303
+ if ($RetainSelfSignedFixturePath) { $retainedRootThumbprint = $pub.Thumbprint }
291
304
  foreach ($f in @(Get-ChildItem -LiteralPath $signedDir -File)) {
292
305
  $r = Set-AuthenticodeSignature -FilePath $f.FullName -Certificate $cert -HashAlgorithm SHA256
293
306
  if ($r.Status -ne 'Valid') { throw "self-signing produced $($r.Status) for $($f.Name)" }
@@ -589,6 +602,7 @@ try {
589
602
  elseif (Test-Path $WshKey) { Remove-ItemProperty -Path $WshKey -Name 'UseWINSAFER' -ErrorAction SilentlyContinue }
590
603
  foreach ($entry in $addedThumbprints) {
591
604
  $parts = $entry.Split('|')
605
+ if ($retainedRootThumbprint -and $parts[0] -eq 'Root' -and $parts[1] -eq $retainedRootThumbprint) { continue }
592
606
  Remove-CertFromStore -Thumbprint $parts[1] -StoreName $parts[0]
593
607
  }
594
608
  } catch {
@@ -604,5 +618,14 @@ if ($failures.Count -gt 0) {
604
618
  exit 1
605
619
  }
606
620
 
621
+ if ($RetainSelfSignedFixturePath) {
622
+ if (-not $cert -or -not $cert.HasPrivateKey -or $cert.Thumbprint -ne $retainedRootThumbprint) {
623
+ Write-Error 'the retained self-signed fixture is not the exact proven certificate'
624
+ exit 1
625
+ }
626
+ @([pscustomobject]@{ subject = $cert.Subject; thumbprint = $cert.Thumbprint }) |
627
+ ConvertTo-Json -Depth 3 | Set-Content -LiteralPath $RetainSelfSignedFixturePath -Encoding UTF8
628
+ }
629
+
607
630
  Say 'PASSED - unsigned is blocked, untrusted-publisher is blocked, tampered is blocked, and every shipped script is admitted.'
608
631
  exit 0