Skip to content

Commit edb2aed

Browse files
authored
Merge pull request desktop#17648 from desktop/acs
Sign using ACS
2 parents f62e53a + 7467c72 commit edb2aed

File tree

2 files changed

+43
-11
lines changed

2 files changed

+43
-11
lines changed

.github/workflows/ci.yml

+19-9
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,21 @@ on:
2121
environment:
2222
type: string
2323
required: true
24+
sign:
25+
type: boolean
26+
default: true
27+
required: false
2428
secrets:
29+
AZURE_CODE_SIGNING_TENANT_ID:
30+
AZURE_CODE_SIGNING_CLIENT_ID:
31+
AZURE_CODE_SIGNING_CLIENT_SECRET:
2532
DESKTOP_OAUTH_CLIENT_ID:
2633
DESKTOP_OAUTH_CLIENT_SECRET:
2734
APPLE_ID:
2835
APPLE_ID_PASSWORD:
2936
APPLE_TEAM_ID:
3037
APPLE_APPLICATION_CERT:
3138
APPLE_APPLICATION_CERT_PASSWORD:
32-
WINDOWS_CERT_PFX:
33-
WINDOWS_CERT_PASSWORD:
3439

3540
jobs:
3641
lint:
@@ -123,17 +128,22 @@ jobs:
123128
- name: Run script tests
124129
if: matrix.arch == 'x64'
125130
run: yarn test:script
126-
- name: Install Windows code signing certificate
127-
if: ${{ runner.os == 'Windows' }}
128-
shell: bash
129-
env:
130-
CERT_CONTENTS: ${{ secrets.WINDOWS_CERT_PFX }}
131-
run: base64 -d <<<"$CERT_CONTENTS" > ./script/windows-certificate.pfx
131+
- name: Install Azure Code Signing Client
132+
if: ${{ runner.os == 'Windows' && inputs.sign }}
133+
run: |
134+
$acsZip = Join-Path $env:RUNNER_TEMP "acs.zip"
135+
$acsDir = Join-Path $env:RUNNER_TEMP "acs"
136+
Invoke-WebRequest -Uri https://www.nuget.org/api/v2/package/Azure.CodeSigning.Client/1.0.38 -OutFile $acsZip -Verbose
137+
Expand-Archive $acsZip -Destination $acsDir -Force -Verbose
138+
# Replace ancient signtool in electron-winstall with one that supports ACS
139+
Copy-Item -Path "C:\Program Files (x86)\Windows Kits\10\bin\10.0.22621.0\x64\*" -Include signtool.exe,signtool.exe.manifest,Microsoft.Windows.Build.Signing.mssign32.dll.manifest,mssign32.dll,Microsoft.Windows.Build.Signing.wintrust.dll.manifest,wintrust.dll,Microsoft.Windows.Build.Appx.AppxSip.dll.manifest,AppxSip.dll,Microsoft.Windows.Build.Appx.AppxPackaging.dll.manifest,AppxPackaging.dll,Microsoft.Windows.Build.Appx.OpcServices.dll.manifest,OpcServices.dll -Destination "node_modules\electron-winstaller\vendor" -Verbose
132140
- name: Package production app
133141
run: yarn package
134142
env:
135143
npm_config_arch: ${{ matrix.arch }}
136-
WINDOWS_CERT_PASSWORD: ${{ secrets.WINDOWS_CERT_PASSWORD }}
144+
AZURE_TENANT_ID: ${{ secrets.AZURE_CODE_SIGNING_TENANT_ID }}
145+
AZURE_CLIENT_ID: ${{ secrets.AZURE_CODE_SIGNING_CLIENT_ID }}
146+
AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CODE_SIGNING_CLIENT_SECRET }}
137147
- name: Upload artifacts
138148
uses: actions/upload-artifact@v3
139149
if: ${{ inputs.upload-artifacts }}

script/package.ts

+24-2
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,18 @@ import { existsSync, rmSync, writeFileSync } from 'fs'
2323
import { getVersion } from '../app/package-info'
2424
import { rename } from 'fs/promises'
2525
import { join } from 'path'
26+
import { assertNonNullable } from '../app/src/lib/fatal-error'
2627

2728
const distPath = getDistPath()
2829
const productName = getProductName()
2930
const outputDir = getDistRoot()
3031

32+
const assertExistsSync = (path: string) => {
33+
if (!existsSync(path)) {
34+
throw new Error(`Expected ${path} to exist`)
35+
}
36+
}
37+
3138
if (process.platform === 'darwin') {
3239
packageOSX()
3340
} else if (process.platform === 'win32') {
@@ -107,8 +114,23 @@ function packageWindows() {
107114
}
108115

109116
if (isGitHubActions() && isPublishable()) {
110-
const certificatePath = path.join(__dirname, 'windows-certificate.pfx')
111-
options.signWithParams = `/f ${certificatePath} /p ${process.env.WINDOWS_CERT_PASSWORD} /tr http://timestamp.digicert.com /td sha256 /fd sha256`
117+
assertNonNullable(process.env.RUNNER_TEMP, 'Missing RUNNER_TEMP env var')
118+
119+
const acsPath = join(process.env.RUNNER_TEMP, 'acs')
120+
const dlibPath = join(acsPath, 'bin', 'x64', 'Azure.CodeSigning.Dlib.dll')
121+
122+
assertExistsSync(dlibPath)
123+
124+
const metadataPath = join(acsPath, 'metadata.json')
125+
const acsMetadata = {
126+
Endpoint: 'https://eus.codesigning.azure.net/',
127+
CodeSigningAccountName: 'github-desktop',
128+
CertificateProfileName: 'desktop',
129+
CorrelationId: `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`,
130+
}
131+
writeFileSync(metadataPath, JSON.stringify(acsMetadata))
132+
133+
options.signWithParams = `/v /fd SHA256 /tr "http://timestamp.acs.microsoft.com" /td SHA256 /dlib "${dlibPath}" /dmdf "${metadataPath}"`
112134
}
113135

114136
console.log('Packaging for Windows…')

0 commit comments

Comments
 (0)