Steve Dower | 0cd6391 | 2018-12-10 18:52:57 -0800 | [diff] [blame] | 1 | function Find-Tool { |
| 2 | param([string]$toolname) |
| 3 | |
| 4 | $kitroot = (gp 'HKLM:\SOFTWARE\Microsoft\Windows Kits\Installed Roots\').KitsRoot10 |
| 5 | $tool = (gci -r "$kitroot\Bin\*\x64\$toolname" | sort FullName -Desc | select -First 1) |
| 6 | if (-not $tool) { |
| 7 | throw "$toolname is not available" |
| 8 | } |
| 9 | Write-Host "Found $toolname at $($tool.FullName)" |
| 10 | return $tool.FullName |
| 11 | } |
| 12 | |
| 13 | Set-Alias SignTool (Find-Tool "signtool.exe") -Scope Script |
| 14 | |
| 15 | function Sign-File { |
| 16 | param([string]$certname, [string]$certsha1, [string]$certfile, [string]$description, [string[]]$files) |
| 17 | |
| 18 | if (-not $description) { |
| 19 | $description = $env:SigningDescription; |
| 20 | if (-not $description) { |
| 21 | $description = "Python"; |
| 22 | } |
| 23 | } |
Steve Dower | d3bbc52 | 2018-12-21 13:48:18 -0800 | [diff] [blame] | 24 | if (-not $certsha1) { |
| 25 | $certsha1 = $env:SigningCertificateSha1; |
| 26 | } |
Steve Dower | 0cd6391 | 2018-12-10 18:52:57 -0800 | [diff] [blame] | 27 | if (-not $certname) { |
| 28 | $certname = $env:SigningCertificate; |
| 29 | } |
| 30 | if (-not $certfile) { |
| 31 | $certfile = $env:SigningCertificateFile; |
| 32 | } |
| 33 | |
Steve Dower | 606c66a | 2019-04-12 11:24:15 -0700 | [diff] [blame] | 34 | if (-not ($certsha1 -or $certname -or $certfile)) { |
| 35 | throw "No signing certificate specified" |
| 36 | } |
| 37 | |
Steve Dower | 0cd6391 | 2018-12-10 18:52:57 -0800 | [diff] [blame] | 38 | foreach ($a in $files) { |
| 39 | if ($certsha1) { |
| 40 | SignTool sign /sha1 $certsha1 /fd sha256 /t http://timestamp.verisign.com/scripts/timestamp.dll /d $description $a |
| 41 | } elseif ($certname) { |
Steve Dower | d3bbc52 | 2018-12-21 13:48:18 -0800 | [diff] [blame] | 42 | SignTool sign /a /n $certname /fd sha256 /t http://timestamp.verisign.com/scripts/timestamp.dll /d $description $a |
Steve Dower | 0cd6391 | 2018-12-10 18:52:57 -0800 | [diff] [blame] | 43 | } elseif ($certfile) { |
| 44 | SignTool sign /f $certfile /fd sha256 /t http://timestamp.verisign.com/scripts/timestamp.dll /d $description $a |
Steve Dower | 0cd6391 | 2018-12-10 18:52:57 -0800 | [diff] [blame] | 45 | } |
| 46 | } |
| 47 | } |
| 48 | |