-
Notifications
You must be signed in to change notification settings - Fork 54
471 lines (420 loc) · 16.8 KB
/
build_and_test.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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
name: Build and Test
on: [push, pull_request]
jobs:
build_debian_derivatives:
strategy:
fail-fast: false
matrix:
include:
- environment: "ubuntu:24.04"
cc: "gcc"
upload_for_test: "false"
- environment: "ubuntu:24.04"
cc: "clang"
upload_for_test: "false"
- environment: "ubuntu:23.10"
cc: "gcc"
upload_for_test: "false"
- environment: "ubuntu:23.10"
cc: "clang"
upload_for_test: "false"
- environment: "ubuntu:22.04"
cc: "gcc"
upload_for_test: "false"
- environment: "ubuntu:22.04"
cc: "clang"
upload_for_test: "true"
- environment: "ubuntu:20.04"
cc: "gcc"
upload_for_test: "false"
- environment: "ubuntu:20.04"
cc: "clang"
upload_for_test: "false"
# - environment: "ubuntu:18.04"
# cc: "gcc"
# upload_for_test: "false"
# - environment: "ubuntu:16.04"
# cc: "gcc"
# upload_for_test: "false"
# - environment: "ubuntu:14.04"
# cc: "gcc"
# upload_for_test: "false"
- environment: "debian:12"
cc: "gcc"
upload_for_test: "false"
- environment: "debian:12"
cc: "clang"
upload_for_test: "false"
- environment: "debian:11"
cc: "gcc"
upload_for_test: "false"
- environment: "debian:11"
cc: "clang"
upload_for_test: "false"
name: build on ${{ matrix.environment }} (${{ matrix.cc }},${{ matrix.upload_for_test}})
runs-on: ubuntu-latest
container: ${{ matrix.environment }}
steps:
- name: install dependencies from package management
env:
CC: ${{ matrix.cc }}
DEBIAN_FRONTEND: noninteractive
run: |
apt update
apt install -q -y build-essential \
cmake pkg-config \
gengetopt \
help2man \
libcurl4-openssl-dev \
libedit-dev \
libpcsclite-dev \
libusb-1.0-0-dev \
libssl-dev \
file \
curl \
jq
if [ "$CC" = "clang" ]; then
apt install -q -y clang llvm lld
fi
- name: clone the Yubico/yubihsm-shell repository
uses: actions/checkout@v4
with:
path: yubihsm-shell
- name: apply environment specific changes to CMakeLists.txt
working-directory: yubihsm-shell
if: ${{ matrix.environment == 'ubuntu:14.04' }}
run: |
# ubuntu 14.04 comes with cmake version 2.8, but the project requires 3.5
# we downgrade that requirement for the ubuntu 14.04 build
sed -i 's/cmake_minimum_required (VERSION 3.5)/cmake_minimum_required (VERSION 2.8)/' CMakeLists.txt
# we also remove the following policies which are not supported in the older cmake version
sed -i 's/cmake_policy(SET CMP0025 NEW)/#cmake_policy(SET CMP0025 NEW)/' CMakeLists.txt
sed -i 's/cmake_policy(SET CMP0042 NEW)/#cmake_policy(SET CMP0042 NEW)/' CMakeLists.txt
sed -i 's/cmake_policy(SET CMP0054 NEW)/#cmake_policy(SET CMP0054 NEW)/' CMakeLists.txt
# append the following flags: -Wno-missing-braces -Wno-missing-field-initializers -Wno-implicit-function-declaration
sed -i 's/-Wall -Wextra -Werror/-Wall -Wextra -Werror -Wno-missing-braces -Wno-missing-field-initializers -Wno-implicit-function-declaration/' cmake/SecurityFlags.cmake
- name: do build
working-directory: yubihsm-shell
env:
CC: ${{ matrix.cc }}
VERBOSE: 1
run: |
mkdir build
cd build
if [ "$CC" = "gcc" ]; then
cmake -DRELEASE_BUILD=1 -DWITHOUT_YKYH=1 ..
else
cmake -DRELEASE_BUILD=1 -DWITHOUT_YKYH=1 \
-DCMAKE_AR=/usr/bin/llvm-ar \
-DCMAKE_RANLIB=/usr/bin/llvm-ranlib \
-DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=lld" \
..
fi
cmake --build .
- name: do static build
working-directory: yubihsm-shell
env:
CC: ${{ matrix.cc }}
VERBOSE: 1
BUILD_ENVIRONMENT: ${{ matrix.environment }}
run: |
mkdir build-static
cd build-static
if [ "$CC" = "gcc" ]; then
cmake -DENABLE_STATIC=ON -DCMAKE_BUILD_TYPE=Release ..
else
cmake -DENABLE_STATIC=ON -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_AR=/usr/bin/llvm-ar \
-DCMAKE_RANLIB=/usr/bin/llvm-ranlib \
-DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=lld" \
..
fi
cmake --build .
- name: prepare name for upload-artifact action
env:
DOCKER_IMAGE: ${{ matrix.environment }}
CC: ${{ matrix.cc }}
run: |
ESCAPED_IMAGE=$(echo -n "$DOCKER_IMAGE" | sed -E 's/[^a-zA-Z0-9]//g')
echo "ARTIFACT_NAME=yubihsm-shell_${ESCAPED_IMAGE}_${CC}" >> $GITHUB_ENV
- name: create compressed tar file
if: ${{ matrix.upload_for_test == 'true' }}
run: tar cfz yubihsm-shell.tar.gz yubihsm-shell
- name: upload artifacts for the test job
if: ${{ matrix.upload_for_test == 'true' }}
uses: actions/upload-artifact@v3
with:
name: "${{ env.ARTIFACT_NAME }}"
path: yubihsm-shell.tar.gz
build_centos_fedora:
strategy:
fail-fast: false
matrix:
include:
# we do not perform clang builds for all environments, only fedora
- environment: "fedora:40"
cc: "gcc"
upload_for_test: "true"
- environment: "fedora:40"
cc: "clang"
upload_for_test: "false"
- environment: "fedora:39"
cc: "gcc"
upload_for_test: "false"
- environment: "fedora:39"
cc: "clang"
upload_for_test: "false"
name: build on ${{ matrix.environment }} (${{ matrix.cc }}, ${{ matrix.upload_for_test }})
runs-on: ubuntu-latest
container: ${{ matrix.environment }}
steps:
- name: clone the Yubico/yubihsm-shell repository
uses: actions/checkout@v3
with:
path: yubihsm-shell
- name: extract platform name
env:
DOCKER_IMAGE: ${{ matrix.environment }}
run: |
# Remove everything from DOCKER_IMAGE that is not a letter or a number
PLATFORM=$(echo -n "$DOCKER_IMAGE" | sed -E 's/[^a-zA-Z0-9]//g')
echo "PLATFORM=$PLATFORM" >> $GITHUB_ENV
- name: install dependencies from package management
env:
CC: ${{ matrix.cc }}
PLATFORM: ${{ env.PLATFORM }}
run: |
cd yubihsm-shell/resources/release/linux
./install_redhat_dependencies.sh $PLATFORM
if [ "$CC" = "clang" ]; then
yum install -y clang llvm lld
fi
- name: apply environment specific changes to CMakeLists.txt
working-directory: yubihsm-shell
if: ${{ matrix.environment == 'centos:7' }}
run: |
# centos 7 comes with cmake version 2.8, but the project requires 3.5
# we downgrade that requirement for the centos 7 build
sed -i 's/cmake_minimum_required (VERSION 3.5)/cmake_minimum_required (VERSION 2.8)/' CMakeLists.txt
# we also remove the following policies which are not supported in the older cmake version
sed -i 's/cmake_policy(SET CMP0025 NEW)/#cmake_policy(SET CMP0025 NEW)/' CMakeLists.txt
sed -i 's/cmake_policy(SET CMP0042 NEW)/#cmake_policy(SET CMP0042 NEW)/' CMakeLists.txt
sed -i 's/cmake_policy(SET CMP0054 NEW)/#cmake_policy(SET CMP0054 NEW)/' CMakeLists.txt
# append the following flags: -Wno-missing-braces -Wno-missing-field-initializers -Wno-implicit-function-declaration
sed -i 's/-Wall -Wextra -Werror/-Wall -Wextra -Werror -Wno-missing-braces -Wno-missing-field-initializers/' cmake/SecurityFlags.cmake
- name: do build
working-directory: yubihsm-shell
env:
CC: ${{ matrix.cc }}
VERBOSE: 1
run: |
mkdir build
cd build
if [ "$CC" = "gcc" ]; then
cmake -DCMAKE_BUILD_TYPE=Release ..
else
cmake -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_AR=/usr/bin/llvm-ar \
-DCMAKE_RANLIB=/usr/bin/llvm-ranlib \
-DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=lld" \
..
fi
cmake --build .
- name: do static build
working-directory: yubihsm-shell
env:
CC: ${{ matrix.cc }}
VERBOSE: 1
PLATFORM: ${{ env.PLATFORM }}
run: |
mkdir build-static
cd build-static
if [ "$CC" = "gcc" ]; then
# lto breaks static builds on centos 7 so we disable it
if [ $PLATFORM = "centos7" ]; then
cmake -DENABLE_STATIC=ON -DCMAKE_BUILD_TYPE=Release -DDISABLE_LTO=ON ..
else
cmake -DENABLE_STATIC=ON -DCMAKE_BUILD_TYPE=Release ..
fi
else
cmake -DENABLE_STATIC=ON -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_AR=/usr/bin/llvm-ar \
-DCMAKE_RANLIB=/usr/bin/llvm-ranlib \
-DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=lld" \
..
fi
cmake --build .
- name: prepare name for upload-artifact action
env:
PLATFORM: ${{ env.PLATFORM }}
CC: ${{ matrix.cc }}
run: |
echo "ARTIFACT_NAME=yubihsm-shell_${PLATFORM}_${CC}" >> $GITHUB_ENV
- name: create compressed tar file
if: ${{ matrix.upload_for_test == 'true' }}
run: tar cfz yubihsm-shell.tar.gz yubihsm-shell
- name: upload artifacts for the test job
if: ${{ matrix.upload_for_test == 'true' }}
uses: actions/upload-artifact@v3
with:
name: "${{ env.ARTIFACT_NAME }}"
path: yubihsm-shell.tar.gz
build_macos:
name: build on macos
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: macos-latest
- os: macos-latest-xlarge
steps:
- name: install dependencies using brew
run: brew install gengetopt help2man libedit opensc
- name: clone the Yubico/yubihsm-shell repository
uses: actions/checkout@v4
with:
path: yubihsm-shell
- name: do build
working-directory: yubihsm-shell
env:
VERBOSE: 1
run: |
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
cmake --build .
- name: Test loading PKCS11 module
working-directory: yubihsm-shell
run: |
echo connector=http://127.0.0.1:12345 > yubihsm_pkcs11.conf
export YUBIHSM_PKCS11_CONF=$GITHUB_WORKSPACE/yubihsm-shell/yubihsm_pkcs11.conf
pkcs11-tool --module build/pkcs11/yubihsm_pkcs11.dylib --show-info | grep Yubico
- name: do static build
working-directory: yubihsm-shell
env:
VERBOSE: 1
run: |
mkdir build-static
cd build-static
cmake -DENABLE_STATIC=ON -DCMAKE_BUILD_TYPE=Release ..
cmake --build .
- name: check binaries for hardening
working-directory: yubihsm-shell
run: |
./resources/release/macos/check_hardening.sh "build/src/yubihsm-shell"
test:
strategy:
fail-fast: false
matrix:
include:
- environment: "ubuntu:22.04"
cc: "clang"
- environment: "fedora:40"
cc: "gcc"
name: run unit tests
runs-on: ubuntu-latest
container: ${{ matrix.environment }}
needs: [build_debian_derivatives, build_centos_fedora]
steps:
- name: install dependencies from package management (debian based)
env:
DEBIAN_FRONTEND: noninteractive
if: ${{ matrix.environment == 'ubuntu:22.04' }}
run: |
apt update
apt install -q -y build-essential cmake python3 python3-pip python3-setuptools curl libedit2 libpcsclite1 libengine-pkcs11-openssl opensc swig openjdk-11-jdk-headless libssl3
- name: install dependencies from package management (rpm based)
if: ${{ matrix.environment == 'fedora:40' }}
run: |
yum install -y gcc gcc-c++ cmake python3-devel python3-pip python3-setuptools curl libedit gengetopt openssl libcurl pcsc-lite swig java-11-openjdk-headless which
- name: prepare name for download-artifact action
env:
DOCKER_IMAGE: ${{ matrix.environment }}
CC: ${{ matrix.cc }}
run: |
ESCAPED_IMAGE=$(echo -n "$DOCKER_IMAGE" | sed -E 's/[^a-zA-Z0-9]//g')
echo "ARTIFACT_NAME=yubihsm-shell_${ESCAPED_IMAGE}_${CC}" >> $GITHUB_ENV
- name: download artifacts from the build job
uses: actions/download-artifact@v3
with:
name: "${{ env.ARTIFACT_NAME }}"
- name: decompress yubihsm-shell.tar.gz
run: tar xfz yubihsm-shell.tar.gz
- name: prepare ghostunnel
env:
TLSPWD: ${{ secrets.TLSKEY }}
# GODEBUG required for ghostunnel to temporarily enable Common Name matching
GODEBUG: x509ignoreCN=0
run: |
curl -o /tmp/ghostunnel -L https://github.com/ghostunnel/ghostunnel/releases/download/v1.6.0/ghostunnel-v1.6.0-linux-amd64
chmod +x /tmp/ghostunnel
openssl aes-256-cbc \
-k "$TLSPWD" \
-md sha256 \
-in yubihsm-shell/.ci/client-combined.pem.enc \
-out yubihsm-shell/.ci/client-combined.pem \
-d
/tmp/ghostunnel client \
--listen localhost:12345 \
--target hsm-connector01.sthlm.in.yubico.org:8443 \
--keystore yubihsm-shell/.ci/client-combined.pem \
--cacert yubihsm-shell/.ci/server-crt.pem > /dev/null 2>&1 &
sleep 3
DEFAULT_CONNECTOR_URL=$(curl -s http://localhost:12345/dispatcher/request)
test -n "$DEFAULT_CONNECTOR_URL" || (echo "Unable to obtain a connector URL, aborting"; exit 1)
echo "DEFAULT_CONNECTOR_URL=$DEFAULT_CONNECTOR_URL" >> $GITHUB_ENV
- name: clone the YubicoLabs/pkcs11test repository
uses: actions/checkout@v3
with:
repository: YubicoLabs/pkcs11test
path: pkcs11test
- name: build the pkcs11test binary
working-directory: pkcs11test
run: |
make
echo "PKCS11TEST_PATH=`pwd`" >> $GITHUB_ENV
- name: reset the hsm
working-directory: yubihsm-shell/build/src
run: |
./yubihsm-shell --connector "$DEFAULT_CONNECTOR_URL" -p password -a reset
sleep 3
- name: run tests with ctest
working-directory: yubihsm-shell/build
env:
DOCKER_IMAGE: ${{ matrix.environment }}
run: |
if [ $DOCKER_IMAGE = "debian:11" ]; then
# we skip the engine tests (for now) since it ships with a broken curl version
ctest --output-on-failure -E engine
elif [ $DOCKER_IMAGE = "centos:7" ]; then
# we skip the ecdh_derive tests (for now) since there is an issue with generating secp224r1 keys
ctest --output-on-failure -E ecdh_derive\|aes\|ecdh_sp800
else
ctest --output-on-failure
fi
- name: clone the YubicoLabs/python-pkcs11tester repository
uses: actions/checkout@v3
with:
repository: YubicoLabs/python-pkcs11tester
path: python-pkcs11tester
- name: run python-pkcs11tester
env:
DOCKER_IMAGE: ${{ matrix.environment }}
run: |
if [ $DOCKER_IMAGE = "centos:7" ]; then
# the pypi cryptography package requires an up-to-date version of pip
# https://github.com/pyca/cryptography/issues/5753
pip3 install --upgrade pip
fi
export YUBIHSM_PKCS11_MODULE=`pwd`/yubihsm-shell/build/pkcs11/yubihsm_pkcs11.so
cd python-pkcs11tester
echo "connector=$DEFAULT_CONNECTOR_URL" > yubihsm_pkcs11.conf
python3 -m pip install 'pykcs11' 'cryptography>=1.4.0'
python3 setup.py test
- name: cleanup
if: ${{ always() }}
run: |
if [ -n "$DEFAULT_CONNECTOR_URL" ]; then
curl -s http://localhost:12345/dispatcher/release?connector=$DEFAULT_CONNECTOR_URL
fi