/
action.yml
282 lines (260 loc) · 11.1 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
name: "Code Sign Action"
description: "A GitHub Action for code signing files. Particularly those generated with vercel/pkg."
branding:
color: purple
icon: lock
inputs:
# Required
file:
description: "The file to sign"
required: true
certificate-data:
description: "A `base64` encoded string of your `p12` or `pfx` cert contents. Note: if you use KeyLocker, this will be the base64 encoded client certificate (`SM_CLIENT_CERT_FILE`)"
required: true
certificate-password:
description: "The password to unlock the certificate-data"
required: true
# Optional
apple-notary-password:
description: "The Apple Developer account password to use in notarization"
required: false
apple-notary-user:
description: "The Apple Developer account email to use in notarization"
required: false
apple-notary-tool:
description: "The xcrun tool to use to notarize."
required: false
default: notarytool
apple-product-id:
description: "The unique product ID to use for notarization"
required: false
apple-team-id:
description: "The Apple Developer account Team ID"
required: false
keylocker-api-key:
description: "The API key to use for KeyLocker"
required: false
keylocker-cert-sha1-hash:
description: "The SHA1 hash of the certificate to use for KeyLocker"
required: false
keylocker-host:
description: "The host to use for KeyLocker"
required: false
keylocker-keypair-alias:
description: "The alias of the keypair to use for KeyLocker"
required: false
options:
description: "Extra options to pass to the codesigning tool"
required: false
outputs:
file:
description: "The path to the signed binary."
value: ${{ steps.code-sign-action.outputs.file }}
runs:
using: composite
steps:
- name: Validate required inputs
shell: bash
run: |
echo "::group::Ensure file is set"
if [ "${{ inputs.file }}" == "" ]; then
echo "::error title=File is not set!::You must specify a file to sign!"
exit 1
fi
echo "::endgroup::"
echo "::group::Ensure cert data is set"
if [ "${{ inputs.certificate-data }}" == "" ]; then
echo "::error title=Cert data is not set!::You must specify the cert you want to sign with!"
exit 2
fi
echo "::endgroup::"
echo "::group::Ensure certificate password is set"
if [ "${{ inputs.certificate-password }}" == "" ]; then
echo "::error title=Cert password is not set!::You must specify the password to unlock the cert with!"
exit 2
fi
echo "::endgroup::"
- name: Validate macos specific inputs
shell: bash
if: runner.os == 'macOS'
run: |
echo "::group::Ensure Apple Team ID is set"
if [ "${{ inputs.apple-team-id }}" == "" ]; then
echo "::error title=File is not set!::You must specify a file to sign!"
exit 1
fi
echo "::endgroup::"
- name: Sign
shell: bash
if: runner.os == 'Linux' && !inputs.keylocker-host
run: |
echo "::warning:: Currently not supported on Linux!"
- name: Sign
shell: bash
if: runner.os == 'macOS'
env:
FILE: ${{ inputs.file }}
OPTIONS: ${{ inputs.options }}
APPLE_CERT_DATA: ${{ inputs.certificate-data }}
APPLE_CERT_PASSWORD: ${{ inputs.certificate-password }}
APPLE_TEAM_ID: ${{ inputs.apple-team-id }}
run: |
# Setup
SIGNFILE="$(pwd)/$FILE"
# Throw error if file does not exist
if [ ! -f "$SIGNFILE" ]; then
echo "$SIGNFILE does not exist!"
exit 5
fi
# Export certs
echo "$APPLE_CERT_DATA" | base64 --decode > /tmp/certs.p12
# Create keychain
security create-keychain -p actions macos-build.keychain
security default-keychain -s macos-build.keychain
security unlock-keychain -p actions macos-build.keychain
security set-keychain-settings -t 3600 -u macos-build.keychain
# Import certs to keychain
security import /tmp/certs.p12 -k ~/Library/Keychains/macos-build.keychain -P "$APPLE_CERT_PASSWORD" -T /usr/bin/codesign -T /usr/bin/productsign
# Key signing
security set-key-partition-list -S apple-tool:,apple: -s -k actions macos-build.keychain
# Verify keychain things
security find-identity -v macos-build.keychain | grep "$APPLE_TEAM_ID" | grep "Developer ID Application"
security find-identity -v macos-build.keychain | grep "$APPLE_TEAM_ID" | grep "Developer ID Installer"
# Force the codesignature
codesign --force $OPTIONS -s "$APPLE_TEAM_ID" "$SIGNFILE"
# Verify the code signature
codesign -v "$SIGNFILE" --verbose
- name: Setup Certificate Windows
run: |
echo "${{ inputs.certificate-data }}" | base64 --decode > /d/cognite_code_signing_github_actions.p12
if: runner.os == 'Windows' && inputs.keylocker-host
shell: bash
- name: Setup Certificate Linux
run: |
echo "${{ inputs.certificate-data }}" | base64 --decode | sudo install -D /dev/stdin /d/cognite_code_signing_github_actions.p12
if: runner.os == 'Linux' && inputs.keylocker-host
shell: bash
- name: Set KeyLocker Variables
id: variables
run: |
echo "SM_HOST=${{ inputs.keylocker-host }}" >> "$GITHUB_ENV"
echo "SM_API_KEY=${{ inputs.keylocker-api-key }}" >> "$GITHUB_ENV"
echo "SM_CLIENT_CERT_PASSWORD=${{ inputs.certificate-password }}" >> "$GITHUB_ENV"
echo "SM_CODE_SIGNING_CERT_SHA1_HASH=${{ inputs.keylocker-cert-sha1-hash }}" >> "$GITHUB_ENV"
if [ "${{ runner.os }}" == "Windows" ]
then
echo "SM_CLIENT_CERT_FILE=D:\\cognite_code_signing_github_actions.p12" >> "$GITHUB_ENV"
elif [ "${{ runner.os }}" == "Linux" ]
then
echo "SM_CLIENT_CERT_FILE=/d/cognite_code_signing_github_actions.p12" >> "$GITHUB_ENV"
echo "PKCS11_CONFIG=/tmp/DigiCert One Signing Manager Tools/smtools-linux-x64/pkcs11properties.cfg" >> "$GITHUB_ENV"
echo "/tmp/DigiCert One Signing Manager Tools/smtools-linux-x64" >> $GITHUB_PATH
fi
if: inputs.keylocker-host
shell: bash
- name: Configure Digicert Secure Software Manager
uses: digicert/ssm-code-signing@v0.0.2
env:
SM_API_KEY: ${{ env.SM_API_KEY }}
SM_CLIENT_CERT_PASSWORD: ${{ env.SM_CLIENT_CERT_PASSWORD }}
SM_CLIENT_CERT_FILE: ${{ env.SM_CLIENT_CERT_FILE }}
if: inputs.keylocker-host
- name: Sign with smctl Windows
env:
GITHUB_WORKSPACE: ${{ github.workspace }}
run: |
smctl windows certsync --keypair-alias="${{ inputs.keylocker-keypair-alias }}"
$file_path = "${{ env.GITHUB_WORKSPACE }}\${{ inputs.file }}"
$files_to_sign = @()
if (Test-Path -Path $file_path -PathType Leaf) {
$files_to_sign = @([PSCustomObject]@{FullName = $file_path})
}
else {
Get-ChildItem -Path $file_path -File -Recurse
$files_to_sign = @(Get-ChildItem -Path $file_path -File -Recurse)
}
foreach ( $f in $files_to_sign )
{
smctl sign --fingerprint ${{ env.SM_CODE_SIGNING_CERT_SHA1_HASH }} --input $f.FullName
smctl sign verify --input $f.FullName
}
if: runner.os == 'Windows' && inputs.keylocker-host
shell: powershell
- name: Sign Linux with KeyLocker
run: |
curl -fSslL https://github.com/ebourg/jsign/releases/download/3.1/jsign_3.1_all.deb -o jsign_3.1_all.deb
sudo dpkg --install jsign_3.1_all.deb
file_path="${{ env.GITHUB_WORKSPACE }}/${{ inputs.file }}"
for f in $(find $file_path -type f); do
smctl sign -v --keypair-alias="${{ inputs.keylocker-keypair-alias }}" --config-file="/tmp/DigiCert One Signing Manager Tools/smtools-linux-x64/pkcs11properties.cfg" --fingerprint "${{ env.SM_CODE_SIGNING_CERT_SHA1_HASH }}" --input "$f"
smctl sign verify --input $f
done
if: runner.os == 'Linux' && inputs.keylocker-host
shell: bash
- name: Sign
shell: powershell
if: runner.os == 'Windows' && !inputs.keylocker-host
env:
FILE: ${{ inputs.file }}
OPTIONS: ${{ inputs.options }}
WINDOZE_CERT_DATA: ${{ inputs.certificate-data }}
WINDOZE_CERT_PASSWORD: ${{ inputs.certificate-password }}
run: |
$ErrorActionPreference = "Stop"
# Get some things for cert opts
$file = -join($pwd, "/", $env:FILE);
$temp_dir = $env:TMP
$cert_data = $env:WINDOZE_CERT_DATA
$cert_path = "$temp_dir\lando.windoze.p12"
$cert_password = $env:WINDOZE_CERT_PASSWORD
$cert_secure_password = $null
$signtool = "${env:ProgramFiles(x86)}\Windows Kits\10\bin\x64\signtool.exe"
$signtool2022 = "${env:ProgramFiles(x86)}\Windows Kits\10\bin\10.0.17763.0\x86\signtool.exe"
# Throw error if file does not exist
if (!(Test-Path "$file"))
{
throw "$file does not exist"
}
# Decode and dump to temp file
If (!(Test-Path $cert_path)) {
Write-Output "Dumping cert to $cert_path..."
$bytes = [Convert]::FromBase64String($cert_data)
[IO.File]::WriteAllBytes($cert_path, $bytes)
}
# Use more recent signtool if we can
If (Test-Path $signtool2022) {
$signtool = "$signtool2022"
}
# Verify the cert and password are good
Write-Output "Verifying cert is good to go..."
$cert_secure_password = ConvertTo-SecureString $cert_password -AsPlainText -Force
Import-PfxCertificate -FilePath "$cert_path" -Password $cert_secure_password -CertStoreLocation "Cert:\LocalMachine\My"
# If we get this far we should be good!
Write-Output "We can sign!"
# Sign and verify
Write-Output "Trying to sign $file with $signtool..."
& $signtool sign -f "$cert_path" -p "$cert_password" -fd sha256 -tr "http://timestamp.comodoca.com/?td=sha256" -td sha256 $env:OPTIONS -as -v "$file"
Write-Output "Verifying $file has been signed with the signtool..."
& $signtool verify -pa -v "$file"
- name: Notarize
if: runner.os == 'macOS' && inputs.apple-notary-user && inputs.apple-notary-password && inputs.apple-product-id
uses: lando/notarize-action@v2
with:
appstore-connect-username: ${{ inputs.apple-notary-user }}
appstore-connect-password: ${{ inputs.apple-notary-password }}
appstore-connect-team-id: ${{ inputs.apple-team-id }}
primary-bundle-id: ${{ inputs.apple-product-id }}
product-path: ${{ inputs.file }}
tool: ${{ inputs.apple-notary-tool }}
verbose: true
- name: Verify Notarization
if: runner.os == 'macOS' && inputs.apple-notary-user && inputs.apple-notary-password && inputs.apple-product-id
shell: bash
run: codesign -vvvv -R="notarized" --check-notarization ${{ inputs.file }}
- name: Set outputs
shell: bash
id: code-sign-action
run: |
echo "::group::Setting outputs"
echo "file=$(pwd)/${{ inputs.file }}" >> $GITHUB_OUTPUT
echo "::endgroup::"