Skip to content

Commit fc0a137

Browse files
authored
use eToken for signing (#950)
* fix typo * use eToken for signing, create a dedicated step for signing * update workflow, we have a certificate and no longer a container for win * env var $GITHUB_REF not expanded in step input causing workflow to fail * bump runner, so that we get an updated version of openssl OpenSSL 1.1.1f-1ubuntu2.22 in Ubuntu 20.04 https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2004-Readme.md OpenSSL 3.0.2-0ubuntu1.15 in Ubuntu 22.04 https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2204-Readme.md * add flag to correctly recognize the algorithm see openssl/openssl#23089 * remove double quotes, they cause errors with new version of openssl: `Could not read certificate from <stdin>`
1 parent 2fa738f commit fc0a137

File tree

2 files changed

+92
-36
lines changed

2 files changed

+92
-36
lines changed

Diff for: .github/workflows/check-certificates.yml

+45-24
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
if: >
2727
(github.event_name != 'pull_request' && github.repository == 'arduino/arduino-create-agent') ||
2828
(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == 'arduino/arduino-create-agent')
29-
runs-on: ubuntu-20.04
29+
runs-on: ubuntu-22.04
3030

3131
strategy:
3232
fail-fast: false
@@ -37,9 +37,11 @@ jobs:
3737
- identifier: macOS signing certificate # Text used to identify certificate in notifications.
3838
certificate-secret: INSTALLER_CERT_MAC_P12 # Name of the secret that contains the certificate.
3939
password-secret: INSTALLER_CERT_MAC_PASSWORD # Name of the secret that contains the certificate password.
40+
type: pkcs12
4041
- identifier: Windows signing certificate
41-
certificate-secret: INSTALLER_CERT_WINDOWS_PFX
42-
password-secret: INSTALLER_CERT_WINDOWS_PASSWORD
42+
certificate-secret: INSTALLER_CERT_WINDOWS_CER
43+
# The password for the Windows certificate is not needed, because its not a container, but a single certificate.
44+
type: x509
4345

4446
steps:
4547
- name: Set certificate path environment variable
@@ -58,9 +60,10 @@ jobs:
5860
CERTIFICATE_PASSWORD: ${{ secrets[matrix.certificate.password-secret] }}
5961
run: |
6062
(
61-
openssl pkcs12 \
63+
openssl ${{ matrix.certificate.type }} \
6264
-in "${{ env.CERTIFICATE_PATH }}" \
63-
-noout -passin env:CERTIFICATE_PASSWORD
65+
-noout -passin env:CERTIFICATE_PASSWORD \
66+
-legacy
6467
) || (
6568
echo "::error::Verification of ${{ matrix.certificate.identifier }} failed!!!"
6669
exit 1
@@ -83,25 +86,43 @@ jobs:
8386
CERTIFICATE_PASSWORD: ${{ secrets[matrix.certificate.password-secret] }}
8487
id: get-days-before-expiration
8588
run: |
86-
EXPIRATION_DATE="$(
87-
(
88-
openssl pkcs12 \
89-
-in "${{ env.CERTIFICATE_PATH }}" \
90-
-clcerts \
91-
-nodes \
92-
-passin env:CERTIFICATE_PASSWORD
93-
) | (
94-
openssl x509 \
95-
-noout \
96-
-enddate
97-
) | (
98-
grep \
99-
--max-count=1 \
100-
--only-matching \
101-
--perl-regexp \
102-
'notAfter=(\K.*)'
103-
)
104-
)"
89+
if [[ ${{ matrix.certificate.type }} == "pkcs12" ]]; then
90+
EXPIRATION_DATE="$(
91+
(
92+
openssl pkcs12 \
93+
-in ${{ env.CERTIFICATE_PATH }} \
94+
-clcerts \
95+
-nodes \
96+
-passin env:CERTIFICATE_PASSWORD \
97+
-legacy
98+
) | (
99+
openssl x509 \
100+
-noout \
101+
-enddate
102+
) | (
103+
grep \
104+
--max-count=1 \
105+
--only-matching \
106+
--perl-regexp \
107+
'notAfter=(\K.*)'
108+
)
109+
)"
110+
elif [[ ${{ matrix.certificate.type }} == "x509" ]]; then
111+
EXPIRATION_DATE="$(
112+
(
113+
openssl x509 \
114+
-in ${{ env.CERTIFICATE_PATH }} \
115+
-noout \
116+
-enddate
117+
) | (
118+
grep \
119+
--max-count=1 \
120+
--only-matching \
121+
--perl-regexp \
122+
'notAfter=(\K.*)'
123+
)
124+
)"
125+
fi
105126
106127
DAYS_BEFORE_EXPIRATION="$((($(date --utc --date="$EXPIRATION_DATE" +%s) - $(date --utc +%s)) / 60 / 60 / 24))"
107128

Diff for: .github/workflows/release.yml

+47-12
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
run:
4646
shell: bash
4747

48-
# by default disable CGO, it's not needed (except on macos)
48+
# by default disable CGO, it's not needed (except on macos)
4949
env:
5050
CGO_ENABLED: 0
5151

@@ -157,7 +157,7 @@ jobs:
157157
create-macos-bundle:
158158
needs: build
159159

160-
# for not they are exaclty the same
160+
# for now they are exaclty the same
161161
strategy:
162162
matrix:
163163
arch: [amd64, arm64]
@@ -371,9 +371,6 @@ jobs:
371371
# vars used by installbuilder
372372
INSTALLBUILDER_PATH: "/opt/installbuilder-23.11.0/bin/builder"
373373
INSTALLER_VARS: "project.outputDirectory=$PWD project.version=${GITHUB_REF##*/} workspace=$PWD realname=Arduino_Create_Agent"
374-
# installbuilder will read this vars automatically (defined in installer.xml):
375-
INSTALLER_CERT_WINDOWS_PASSWORD: ${{ secrets.INSTALLER_CERT_WINDOWS_PASSWORD }}
376-
INSTALLER_CERT_WINDOWS_PFX: "/tmp/ArduinoCerts2020.pfx"
377374

378375
strategy:
379376
fail-fast: false # if one os is failing continue nonetheless
@@ -424,11 +421,6 @@ jobs:
424421
- name: Save InstallBuilder license to file
425422
run: echo "${{ secrets.INSTALLER_LICENSE }}" > /tmp/license.xml
426423

427-
- name: Save Win signing certificate to file
428-
run: echo "${{ secrets.INSTALLER_CERT_WINDOWS_PFX }}" | base64 --decode > ${{ env.INSTALLER_CERT_WINDOWS_PFX}}
429-
if: matrix.os == 'windows-2019'
430-
431-
# installbuilder reads the env vars with certs paths and use it to sign the installer.
432424
- name: Launch Bitrock installbuilder
433425
run: ${{ env.INSTALLBUILDER_PATH }} build installer.xml ${{ matrix.installbuilder-name }} --verbose --license /tmp/license.xml --setvars ${{ env.INSTALLER_VARS }} architecture=${{ matrix.arch }}
434426

@@ -443,6 +435,49 @@ jobs:
443435
path: ArduinoCreateAgent*
444436
if-no-files-found: error
445437

438+
# This job will sign the Windows installer
439+
sign-windows:
440+
runs-on: [self-hosted, windows-sign-pc]
441+
needs: package
442+
443+
defaults:
444+
run:
445+
shell: bash
446+
447+
env:
448+
INSTALLER_CERT_WINDOWS_CER: "/tmp/cert.cer"
449+
# We are hardcoding the path for signtool because is not present on the windows PATH env var by default.
450+
# Keep in mind that this path could change when upgrading to a new runner version
451+
SIGNTOOL_PATH: "C:/Program Files (x86)/Windows Kits/10/bin/10.0.19041.0/x86/signtool.exe"
452+
453+
strategy:
454+
matrix:
455+
arch: [amd64, 386]
456+
457+
steps:
458+
- name: Download artifact
459+
uses: actions/download-artifact@v3
460+
with:
461+
name: ArduinoCreateAgent-windows-${{ matrix.arch }}
462+
463+
- name: Save Win signing certificate to file
464+
run: echo "${{ secrets.INSTALLER_CERT_WINDOWS_CER }}" | base64 --decode > ${{ env.INSTALLER_CERT_WINDOWS_CER}}
465+
466+
- name: Sign EXE
467+
env:
468+
CERT_PASSWORD: ${{ secrets.INSTALLER_CERT_WINDOWS_PASSWORD }}
469+
CONTAINER_NAME: ${{ secrets.INSTALLER_CERT_WINDOWS_CONTAINER }}
470+
# https://stackoverflow.com/questions/17927895/automate-extended-validation-ev-code-signing-with-safenet-etoken
471+
run: |
472+
"${{ env.SIGNTOOL_PATH }}" sign -d "Arduino Create Agent" -f ${{ env.INSTALLER_CERT_WINDOWS_CER}} -csp "eToken Base Cryptographic Provider" -k "[{{${{ env.CERT_PASSWORD }}}}]=${{ env.CONTAINER_NAME }}" -fd sha256 -tr http://timestamp.digicert.com -td SHA256 -v "ArduinoCreateAgent-${GITHUB_REF##*/}-windows-${{ matrix.arch }}-installer.exe"
473+
474+
- name: Upload artifacts
475+
uses: actions/upload-artifact@v3
476+
with:
477+
if-no-files-found: error
478+
name: ArduinoCreateAgent-windows-${{ matrix.arch }}-signed
479+
path: ArduinoCreateAgent-*-windows-${{ matrix.arch }}-installer.exe
480+
446481
# This job will generate a dmg mac installer, sign/notarize it.
447482
generate-sign-dmg:
448483
needs: notarize-macos
@@ -544,7 +579,7 @@ jobs:
544579
create-release:
545580
runs-on: ubuntu-20.04
546581
environment: production
547-
needs: [build, package, generate-sign-dmg]
582+
needs: [build, generate-sign-dmg, sign-windows]
548583

549584
steps:
550585
- name: Checkout
@@ -563,7 +598,7 @@ jobs:
563598
mv -v ArduinoCreateAgent-linux-amd64/* release/
564599
cat ArduinoCreateAgent-osx-amd64/*.tar | tar -xvf - -i -C release/
565600
rm -v release/._ArduinoCreateAgent*.dmg
566-
mv -v ArduinoCreateAgent-windows*/* release/
601+
mv -v ArduinoCreateAgent-windows*-signed/* release/
567602
568603
- name: VirusTotal Scan
569604
id: virustotal_step

0 commit comments

Comments
 (0)