Skip to content

Commit 267a523

Browse files
committed
Update Windows code signing to use KeyLocker
1 parent 922de46 commit 267a523

File tree

3 files changed

+37
-34
lines changed

3 files changed

+37
-34
lines changed

.github/workflows/cd.yml

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,10 @@ jobs:
9595
deploy-windows-bundle:
9696
needs: deploy
9797
env:
98-
B2_WINDOWS_CODE_SIGNING_CERTIFICATE: ${{ secrets.B2_WINDOWS_CODE_SIGNING_CERTIFICATE }}
99-
B2_WINDOWS_CODE_SIGNING_CERTIFICATE_PASSWORD: ${{ secrets.B2_WINDOWS_CODE_SIGNING_CERTIFICATE_PASSWORD }}
98+
SM_HOST: ${{ secrets.SM_HOST }}
99+
SM_API_KEY: ${{ secrets.SM_API_KEY }}
100+
SM_CLIENT_CERT_FILE_B64: ${{ secrets.SM_CLIENT_CERT_FILE_B64 }}
101+
SM_CLIENT_CERT_PASSWORD: ${{ secrets. SM_CLIENT_CERT_PASSWORD }}
100102
runs-on: windows-2019
101103
steps:
102104
- uses: actions/checkout@v4
@@ -112,18 +114,19 @@ jobs:
112114
id: bundle
113115
shell: bash
114116
run: nox -vs bundle
115-
- name: Import certificate
116-
id: windows_import_cert
117-
if: ${{ env.B2_WINDOWS_CODE_SIGNING_CERTIFICATE != '' }}
118-
uses: timheuer/base64-to-file@v1
119-
with:
120-
fileName: 'cert.pfx'
121-
encodedString: ${{ secrets.B2_WINDOWS_CODE_SIGNING_CERTIFICATE }}
122-
- name: Sign the bundle
123-
if: ${{ env.B2_WINDOWS_CODE_SIGNING_CERTIFICATE != '' }}
124-
id: sign
117+
- name: Install client for code signing with Software Trust Manager
118+
uses: digicert/[email protected]
119+
env:
120+
FORCE_DOWNLOAD_TOOLS: 'true'
121+
- name: Set up client authentication certificate
122+
id: client_cert
123+
run: |
124+
echo "${{ env.SM_CLIENT_CERT_FILE_B64 }}" | base64 --decode > /d/Certificate_pkcs12.p12
125+
echo "SM_CLIENT_CERT_FILE=D:\\Certificate_pkcs12.p12" >> "$GITHUB_ENV"
125126
shell: bash
126-
run: nox -vs sign -- '${{ steps.windows_import_cert.outputs.filePath }}' '${{ env.B2_WINDOWS_CODE_SIGNING_CERTIFICATE_PASSWORD }}'
127+
- name: Sign the bundle using a keypair alais
128+
id: sign
129+
run: nox -vs sign -- '${{ secrets.SM_KEYPAIR_ALIAS }}' '${{ secrets.SM_CERT_FINGERPRINT }}'
127130
- name: Generate hashes
128131
id: hashes
129132
run: nox -vs make_dist_digest
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Switched to cloud-based signing using DigiCert KeyLocker

noxfile.py

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -365,42 +365,41 @@ def bundle(session: nox.Session):
365365
def sign(session):
366366
"""Sign the bundled distribution (macOS and Windows only)."""
367367

368-
def sign_windows(cert_file, cert_password):
369-
session.run('certutil', '-f', '-p', cert_password, '-importpfx', cert_file)
368+
def sign_windows(keypair_alias, cert_fingerprint):
370369
for binary_name in ['b2'] + get_versions():
370+
binary_path = f'dist/{binary_name}.exe'
371+
372+
# Sign the binary
371373
session.run(
372-
WINDOWS_SIGNTOOL_PATH,
374+
'smctl',
373375
'sign',
374-
'/f',
375-
cert_file,
376-
'/p',
377-
cert_password,
378-
'/tr',
379-
WINDOWS_TIMESTAMP_SERVER,
380-
'/td',
381-
'sha256',
382-
'/fd',
383-
'sha256',
384-
f'dist/{binary_name}.exe',
376+
'--keypair-alias',
377+
keypair_alias,
378+
'--input',
379+
binary_path,
385380
external=True,
386381
)
382+
383+
# Verify the signature
387384
session.run(
388-
WINDOWS_SIGNTOOL_PATH,
385+
'smctl',
386+
'sign',
389387
'verify',
390-
'/pa',
391-
'/all',
392-
f'dist/{binary_name}.exe',
388+
'--fingerprint',
389+
cert_fingerprint,
390+
'--input',
391+
binary_path,
393392
external=True,
394393
)
395394

396395
if SYSTEM == 'windows':
397396
try:
398-
certificate_file, certificate_password = session.posargs
397+
sm_keypair_alias, sm_cert_fingerprint = session.posargs
399398
except ValueError:
400-
session.error('pass the certificate file and the password as positional arguments')
399+
session.error('pass the keypair alias and the cert fingerprint as positional arguments')
401400
return
402401

403-
sign_windows(certificate_file, certificate_password)
402+
sign_windows(sm_keypair_alias, sm_cert_fingerprint)
404403
elif SYSTEM == 'linux':
405404
session.log('signing is not supported for Linux')
406405
else:

0 commit comments

Comments
 (0)