Skip to content

Commit eea599c

Browse files
committed
Add support for non-bundled X.509 certificates to "Check Certificates" workflow
The digital certificates used for code signing are often stored in an archive file of the PKCS arduino#12 format, which allows multiple objects to be bundled in a single file. However, it also might occur that a single certificate is stored in X.509 format. Previously, the "Check Certificates" workflow only supported certificates in a PKCS arduino#12 archive. Support is hereby added to the workflow for validation of X.509 certificates in addition to PKCS arduino#12.
1 parent fda1203 commit eea599c

File tree

1 file changed

+39
-21
lines changed

1 file changed

+39
-21
lines changed

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

+39-21
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ jobs:
7676
- identifier: macOS signing certificate # Text used to identify certificate in notifications.
7777
certificate-secret: INSTALLER_CERT_MAC_P12 # Name of the secret that contains the certificate.
7878
password-secret: INSTALLER_CERT_MAC_PASSWORD # Name of the secret that contains the certificate password.
79+
type: pkcs12 # here you can use `x509` too in case you have a .cer file with a single certificate
7980

8081
steps:
8182
- name: Set certificate path environment variable
@@ -94,7 +95,7 @@ jobs:
9495
CERTIFICATE_PASSWORD: ${{ secrets[matrix.certificate.password-secret] }}
9596
run: |
9697
(
97-
openssl pkcs12 \
98+
openssl ${{ matrix.certificate.type }} \
9899
-in "${{ env.CERTIFICATE_PATH }}" \
99100
-legacy \
100101
-noout \
@@ -121,26 +122,43 @@ jobs:
121122
CERTIFICATE_PASSWORD: ${{ secrets[matrix.certificate.password-secret] }}
122123
id: get-days-before-expiration
123124
run: |
124-
EXPIRATION_DATE="$(
125-
(
126-
openssl pkcs12 \
127-
-in "${{ env.CERTIFICATE_PATH }}" \
128-
-clcerts \
129-
-legacy \
130-
-nodes \
131-
-passin env:CERTIFICATE_PASSWORD
132-
) | (
133-
openssl x509 \
134-
-noout \
135-
-enddate
136-
) | (
137-
grep \
138-
--max-count=1 \
139-
--only-matching \
140-
--perl-regexp \
141-
'notAfter=(\K.*)'
142-
)
143-
)"
125+
if [[ ${{ matrix.certificate.type }} == "pkcs12" ]]; then
126+
EXPIRATION_DATE="$(
127+
(
128+
openssl pkcs12 \
129+
-in ${{ env.CERTIFICATE_PATH }} \
130+
-clcerts \
131+
-legacy \
132+
-nodes \
133+
-passin env:CERTIFICATE_PASSWORD
134+
) | (
135+
openssl x509 \
136+
-noout \
137+
-enddate
138+
) | (
139+
grep \
140+
--max-count=1 \
141+
--only-matching \
142+
--perl-regexp \
143+
'notAfter=(\K.*)'
144+
)
145+
)"
146+
elif [[ ${{ matrix.certificate.type }} == "x509" ]]; then
147+
EXPIRATION_DATE="$(
148+
(
149+
openssl x509 \
150+
-in ${{ env.CERTIFICATE_PATH }} \
151+
-noout \
152+
-enddate
153+
) | (
154+
grep \
155+
--max-count=1 \
156+
--only-matching \
157+
--perl-regexp \
158+
'notAfter=(\K.*)'
159+
)
160+
)"
161+
fi
144162
145163
DAYS_BEFORE_EXPIRATION="$((($(date --utc --date="$EXPIRATION_DATE" +%s) - $(date --utc +%s)) / 60 / 60 / 24))"
146164

0 commit comments

Comments
 (0)