Skip to content
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

PICARD-2760: Timestamp the Windows binaries when codesigning #2321

Merged
merged 2 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions .github/workflows/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,10 @@ jobs:
- name: Build Windows 10 signed app package
if: matrix.type == 'signed-app' && env.CODESIGN == '1'
run: |
$CertPassword = ConvertTo-SecureString -String $Env:CODESIGN_P12_PASSWORD -Force -AsPlainText
& .\scripts\package\win-package-appx.ps1 -BuildNumber $Env:BUILD_NUMBER -CertificateFile .\codesign.pfx -CertificatePassword $CertPassword
$CertificateFile = ".\codesign.pfx"
$CertificatePassword = ConvertTo-SecureString -String $Env:CODESIGN_P12_PASSWORD -Force -AsPlainText
& .\scripts\package\win-package-appx.ps1 -BuildNumber $Env:BUILD_NUMBER `
-CertificateFile $CertificateFile -CertificatePassword $CertificatePassword
Move-Item .\dist\*.msix .\artifacts
env:
CODESIGN_P12_PASSWORD: ${{ secrets.CODESIGN_P12_PASSWORD }}
Expand All @@ -198,12 +200,14 @@ jobs:
run: |
# choco install nsis
If ($Env:CODESIGN -eq "1") {
$CertPassword = ConvertTo-SecureString -String $Env:CODESIGN_P12_PASSWORD -Force -AsPlainText
$Certificate = Get-PfxCertificate -FilePath .\codesign.pfx -Password $CertPassword
$CertificateFile = ".\codesign.pfx"
$CertificatePassword = ConvertTo-SecureString -String $Env:CODESIGN_P12_PASSWORD -Force -AsPlainText
} Else {
$Certificate = $null
$CertificateFile = $null
$CertificatePassword = $null
}
& .\scripts\package\win-package-installer.ps1 -BuildNumber $Env:BUILD_NUMBER -Certificate $Certificate
& .\scripts\package\win-package-installer.ps1 -BuildNumber $Env:BUILD_NUMBER `
-CertificateFile $CertificateFile -CertificatePassword $CertificatePassword
Move-Item .\installer\*.exe .\artifacts
dist\picard\fpcalc -version
env:
Expand All @@ -212,12 +216,14 @@ jobs:
if: matrix.type == 'portable'
run: |
If ($Env:CODESIGN -eq "1") {
$CertPassword = ConvertTo-SecureString -String $Env:CODESIGN_P12_PASSWORD -Force -AsPlainText
$Certificate = Get-PfxCertificate -FilePath .\codesign.pfx -Password $CertPassword
$CertificateFile = ".\codesign.pfx"
$CertificatePassword = ConvertTo-SecureString -String $Env:CODESIGN_P12_PASSWORD -Force -AsPlainText
} Else {
$Certificate = $null
$CertificateFile = $null
$CertificatePassword = $null
}
& .\scripts\package\win-package-portable.ps1 -BuildNumber $Env:BUILD_NUMBER -Certificate $Certificate
& .\scripts\package\win-package-portable.ps1 -BuildNumber $Env:BUILD_NUMBER `
-CertificateFile $CertificateFile -CertificatePassword $CertificatePassword
Move-Item .\dist\*.exe .\artifacts
env:
CODESIGN_P12_PASSWORD: ${{ secrets.CODESIGN_P12_PASSWORD }}
Expand Down
18 changes: 13 additions & 5 deletions scripts/package/win-common.ps1
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
# Common functions for Windows packaging scripts

Param(
[System.Security.Cryptography.X509Certificates.X509Certificate]
$Certificate
[ValidateScript({ (Test-Path $_ -PathType Leaf) -or (-not $_) })]
[String]
$CertificateFile,
[SecureString]
$CertificatePassword
)

# RFC 3161 timestamp server for code signing
$TimeStampServer = 'http://ts.ssl.com'

Function CodeSignBinary {
Param(
[ValidateScript({Test-Path $_ -PathType Leaf})]
[String]
$BinaryPath
)
If ($Certificate) {
Set-AuthenticodeSignature -FilePath $BinaryPath -Certificate $Certificate `
-ErrorAction Stop
If ($CertificateFile) {
SignTool sign /v /fd SHA256 /tr "$TimeStampServer" /td sha256 `
/f "$CertificateFile" /p (ConvertFrom-SecureString -AsPlainText $CertificatePassword) `
$BinaryPath
ThrowOnExeError "SignTool failed"
} Else {
Write-Output "Skip signing $BinaryPath"
}
Expand Down
15 changes: 3 additions & 12 deletions scripts/package/win-package-appx.ps1
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# Build a MSIX app package for Windows 10

Param(
[System.Security.Cryptography.X509Certificates.X509Certificate]
$Certificate,
[ValidateScript({Test-Path $_ -PathType Leaf})]
[ValidateScript({ (Test-Path $_ -PathType Leaf) -or (-not $_) })]
[String]
$CertificateFile,
[SecureString]
Expand All @@ -25,7 +23,7 @@ If (-Not $Certificate -And $CertificateFile) {
}

$ScriptDirectory = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent
. $ScriptDirectory\win-common.ps1 -Certificate $Certificate
. $ScriptDirectory\win-common.ps1 -CertificateFile $CertificateFile -CertificatePassword $CertificatePassword

Write-Output "Building Windows 10 app package..."

Expand Down Expand Up @@ -70,11 +68,4 @@ If ($CertificateFile -or $Certificate) {
MakeAppx pack /o /h SHA256 /d $PackageDir /p $PackageFile
ThrowOnExeError "MakeAppx failed"

# Sign package
If ($CertificateFile) {
SignTool sign /fd SHA256 /f "$CertificateFile" /p (ConvertFrom-SecureString -AsPlainText $CertificatePassword) $PackageFile
ThrowOnExeError "SignTool failed"
} ElseIf ($Certificate) {
SignTool sign /fd SHA256 /sha1 $Certificate.Thumbprint $PackageFile
ThrowOnExeError "SignTool failed"
}
CodeSignBinary $PackageFile
9 changes: 6 additions & 3 deletions scripts/package/win-package-installer.ps1
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# Build a Windows installer

Param(
[System.Security.Cryptography.X509Certificates.X509Certificate]
$Certificate,
[ValidateScript({ (Test-Path $_ -PathType Leaf) -or (-not $_) })]
[String]
$CertificateFile,
[SecureString]
$CertificatePassword,
[Int]
$BuildNumber
)
Expand All @@ -16,7 +19,7 @@ If (-Not $BuildNumber) {
}

$ScriptDirectory = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent
. $ScriptDirectory\win-common.ps1 -Certificate $Certificate
. $ScriptDirectory\win-common.ps1 -CertificateFile $CertificateFile -CertificatePassword $CertificatePassword

Write-Output "Building Windows installer..."

Expand Down
9 changes: 6 additions & 3 deletions scripts/package/win-package-portable.ps1
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# Build a portable app

Param(
[System.Security.Cryptography.X509Certificates.X509Certificate]
$Certificate,
[ValidateScript({ (Test-Path $_ -PathType Leaf) -or (-not $_) })]
[String]
$CertificateFile,
[SecureString]
$CertificatePassword,
[Int]
$BuildNumber
)
Expand All @@ -16,7 +19,7 @@ If (-Not $BuildNumber) {
}

$ScriptDirectory = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent
. $ScriptDirectory\win-common.ps1 -Certificate $Certificate
. $ScriptDirectory\win-common.ps1 -CertificateFile $CertificateFile -CertificatePassword $CertificatePassword

Write-Output "Building portable exe..."

Expand Down
Loading