blob: af1d32c306eb1c43962f74300de70a29a47310a6 [file] [log] [blame]
Minos Galanakis6aab5b72024-07-25 14:24:37 +01001# components.sh
2#
3# Copyright The Mbed TLS Contributors
4# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
5
6# This file contains the test components that are executed by all.sh
7
8# The functions below are named as follows:
9# * component_XXX: independent components. They can be run in any order.
10# * component_check_XXX: quick tests that aren't worth parallelizing.
11# * component_build_XXX: build things but don't run them.
12# * component_test_XXX: build and test.
13# * component_release_XXX: tests that the CI should skip during PR testing.
14# * support_XXX: if support_XXX exists and returns false then
15# component_XXX is not run by default.
16
17# Each component must start by invoking `msg` with a short informative message.
18#
19# Warning: due to the way bash detects errors, the failure of a command
20# inside 'if' or '!' is not detected. Use the 'not' function instead of '!'.
21#
22# Each component is executed in a separate shell process. The component
23# fails if any command in it returns a non-zero status.
24#
25# The framework in all.sh performs some cleanup tasks after each component.
26# This means that components can assume that the working directory is in a
27# cleaned-up state, and don't need to perform the cleanup themselves.
28# * Run `make clean`.
29# * Restore `include/mbedtls/mbedtls_config.h` from a backup made before running
30# the component.
31# * Check out `Makefile`, `library/Makefile`, `programs/Makefile`,
32# `tests/Makefile` and `programs/fuzz/Makefile` from git.
33# This cleans up after an in-tree use of CMake.
34#
35# The tests are roughly in order from fastest to slowest. This doesn't
36# have to be exact, but in general you should add slower tests towards
37# the end and fast checks near the beginning.
38
39
40################################################################
41#### Build and test many configurations and targets
42################################################################
Minos Galanakisada21b02024-07-26 12:34:19 +010043
44# Helper function for controlling (start & stop) the psasim server.
45helper_psasim_server() {
46 OPERATION=$1
47 if [ "$OPERATION" == "start" ]; then
48 (
49 cd tests
50 msg "start server in tests"
51 psa-client-server/psasim/test/start_server.sh
52 msg "start server in tf-psa-crypto/tests"
53 cd ../tf-psa-crypto/tests
54 ../../tests/psa-client-server/psasim/test/start_server.sh
55 )
56 else
57 (
58 msg "terminate servers and cleanup"
59 tests/psa-client-server/psasim//test/kill_servers.sh
60
61 # Remove temporary files and logs
62 cd tests
63 rm -f psa_notify_*
64 rm -f psa_service_*
65 rm -f psa_server.log
66
67 cd ../tf-psa-crypto/tests
68 rm -f psa_notify_*
69 rm -f psa_service_*
70 rm -f psa_server.log
71 )
72 fi
73}
74
75################################################################
Minos Galanakisada21b02024-07-26 12:34:19 +010076#### Build and test many configurations and targets
77################################################################
78
79component_test_default_out_of_box () {
80 msg "build: make, default config (out-of-box)" # ~1min
81 make
82 # Disable fancy stuff
83 unset MBEDTLS_TEST_OUTCOME_FILE
84
85 msg "test: main suites make, default config (out-of-box)" # ~10s
86 make test
87
88 msg "selftest: make, default config (out-of-box)" # ~10s
89 programs/test/selftest
90
91 msg "program demos: make, default config (out-of-box)" # ~10s
92 tests/scripts/run_demos.py
93}
94
95component_test_default_cmake_gcc_asan () {
96 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
97 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
98 make
99
100 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
101 make test
102
103 msg "program demos (ASan build)" # ~10s
104 tests/scripts/run_demos.py
105
106 msg "test: selftest (ASan build)" # ~ 10s
107 programs/test/selftest
108
109 msg "test: metatests (GCC, ASan build)"
110 tests/scripts/run-metatests.sh any asan poison
111
112 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
113 tests/ssl-opt.sh
114
115 msg "test: compat.sh (ASan build)" # ~ 6 min
116 tests/compat.sh
117
118 msg "test: context-info.sh (ASan build)" # ~ 15 sec
119 tests/context-info.sh
120}
121
122component_test_default_cmake_gcc_asan_new_bignum () {
123 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
124 scripts/config.py set MBEDTLS_ECP_WITH_MPI_UINT
125 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
126 make
127
128 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
129 make test
130
131 msg "test: selftest (ASan build)" # ~ 10s
132 programs/test/selftest
133
134 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
135 tests/ssl-opt.sh
136
137 msg "test: compat.sh (ASan build)" # ~ 6 min
138 tests/compat.sh
139
140 msg "test: context-info.sh (ASan build)" # ~ 15 sec
141 tests/context-info.sh
142}
143
144component_test_full_cmake_gcc_asan () {
145 msg "build: full config, cmake, gcc, ASan"
146 scripts/config.py full
147 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
148 make
149
150 msg "test: main suites (inc. selftests) (full config, ASan build)"
151 make test
152
153 msg "test: selftest (full config, ASan build)" # ~ 10s
154 programs/test/selftest
155
156 msg "test: ssl-opt.sh (full config, ASan build)"
157 tests/ssl-opt.sh
158
159 # Note: the next two invocations cover all compat.sh test cases.
160 # We should use the same here and in basic-build-test.sh.
161 msg "test: compat.sh: default version (full config, ASan build)"
162 tests/compat.sh -e 'ARIA\|CHACHA'
163
164 msg "test: compat.sh: next: ARIA, Chacha (full config, ASan build)"
165 env OPENSSL="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
166
167 msg "test: context-info.sh (full config, ASan build)" # ~ 15 sec
168 tests/context-info.sh
169}
170
171
172component_test_full_cmake_gcc_asan_new_bignum () {
173 msg "build: full config, cmake, gcc, ASan"
174 scripts/config.py full
175 scripts/config.py set MBEDTLS_ECP_WITH_MPI_UINT
176 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
177 make
178
179 msg "test: main suites (inc. selftests) (full config, new bignum, ASan)"
180 make test
181
182 msg "test: selftest (full config, new bignum, ASan)" # ~ 10s
183 programs/test/selftest
184
185 msg "test: ssl-opt.sh (full config, new bignum, ASan)"
186 tests/ssl-opt.sh
187
188 # Note: the next two invocations cover all compat.sh test cases.
189 # We should use the same here and in basic-build-test.sh.
190 msg "test: compat.sh: default version (full config, new bignum, ASan)"
191 tests/compat.sh -e 'ARIA\|CHACHA'
192
193 msg "test: compat.sh: next: ARIA, Chacha (full config, new bignum, ASan)"
194 env OPENSSL="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
195
196 msg "test: context-info.sh (full config, new bignum, ASan)" # ~ 15 sec
197 tests/context-info.sh
198}
199
Minos Galanakisada21b02024-07-26 12:34:19 +0100200component_test_no_rsa_key_pair_generation() {
201 msg "build: default config minus PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE"
202 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
203 scripts/config.py unset MBEDTLS_GENPRIME
204 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE
205 make
206
207 msg "test: default config minus PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE"
208 make test
209}
210
211component_test_ref_configs () {
212 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
213 # test-ref-configs works by overwriting mbedtls_config.h; this makes cmake
214 # want to re-generate generated files that depend on it, quite correctly.
215 # However this doesn't work as the generation script expects a specific
216 # format for mbedtls_config.h, which the other files don't follow. Also,
217 # cmake can't know this, but re-generation is actually not necessary as
218 # the generated files only depend on the list of available options, not
219 # whether they're on or off. So, disable cmake's (over-sensitive here)
220 # dependency resolution for generated files and just rely on them being
221 # present (thanks to pre_generate_files) by turning GEN_FILES off.
222 CC=$ASAN_CC cmake -D GEN_FILES=Off -D CMAKE_BUILD_TYPE:String=Asan .
223 tests/scripts/test-ref-configs.pl config-tfm.h
224}
225
226component_test_no_renegotiation () {
227 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
228 scripts/config.py unset MBEDTLS_SSL_RENEGOTIATION
229 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
230 make
231
232 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
233 make test
234
235 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
236 tests/ssl-opt.sh
237}
238
239component_test_no_pem_no_fs () {
240 msg "build: Default + !MBEDTLS_PEM_PARSE_C + !MBEDTLS_FS_IO (ASan build)"
241 scripts/config.py unset MBEDTLS_PEM_PARSE_C
242 scripts/config.py unset MBEDTLS_FS_IO
243 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C # requires a filesystem
244 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA ITS
245 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
246 make
247
248 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - main suites (inc. selftests) (ASan build)" # ~ 50s
249 make test
250
251 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - ssl-opt.sh (ASan build)" # ~ 6 min
252 tests/ssl-opt.sh
253}
254
255component_test_rsa_no_crt () {
256 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
257 scripts/config.py set MBEDTLS_RSA_NO_CRT
258 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
259 make
260
261 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
262 make test
263
264 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
265 tests/ssl-opt.sh -f RSA
266
267 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
268 tests/compat.sh -t RSA
269
270 msg "test: RSA_NO_CRT - RSA-related part of context-info.sh (ASan build)" # ~ 15 sec
271 tests/context-info.sh
272}
273
274component_test_no_ctr_drbg_classic () {
275 msg "build: Full minus CTR_DRBG, classic crypto in TLS"
276 scripts/config.py full
277 scripts/config.py unset MBEDTLS_CTR_DRBG_C
278 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
279 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
280
281 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
282 make
283
284 msg "test: Full minus CTR_DRBG, classic crypto - main suites"
285 make test
286
287 # In this configuration, the TLS test programs use HMAC_DRBG.
288 # The SSL tests are slow, so run a small subset, just enough to get
289 # confidence that the SSL code copes with HMAC_DRBG.
290 msg "test: Full minus CTR_DRBG, classic crypto - ssl-opt.sh (subset)"
291 tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
292
293 msg "test: Full minus CTR_DRBG, classic crypto - compat.sh (subset)"
294 tests/compat.sh -m tls12 -t 'ECDSA PSK' -V NO -p OpenSSL
295}
296
297component_test_no_ctr_drbg_use_psa () {
298 msg "build: Full minus CTR_DRBG, PSA crypto in TLS"
299 scripts/config.py full
300 scripts/config.py unset MBEDTLS_CTR_DRBG_C
301 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
302
303 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
304 make
305
306 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - main suites"
307 make test
308
309 # In this configuration, the TLS test programs use HMAC_DRBG.
310 # The SSL tests are slow, so run a small subset, just enough to get
311 # confidence that the SSL code copes with HMAC_DRBG.
312 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
313 tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
314
315 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - compat.sh (subset)"
316 tests/compat.sh -m tls12 -t 'ECDSA PSK' -V NO -p OpenSSL
317}
318
319component_test_no_hmac_drbg_classic () {
320 msg "build: Full minus HMAC_DRBG, classic crypto in TLS"
321 scripts/config.py full
322 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
323 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
324 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
325 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
326
327 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
328 make
329
330 msg "test: Full minus HMAC_DRBG, classic crypto - main suites"
331 make test
332
333 # Normally our ECDSA implementation uses deterministic ECDSA. But since
334 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
335 # instead.
336 # Test SSL with non-deterministic ECDSA. Only test features that
337 # might be affected by how ECDSA signature is performed.
338 msg "test: Full minus HMAC_DRBG, classic crypto - ssl-opt.sh (subset)"
339 tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
340
341 # To save time, only test one protocol version, since this part of
342 # the protocol is identical in (D)TLS up to 1.2.
343 msg "test: Full minus HMAC_DRBG, classic crypto - compat.sh (ECDSA)"
344 tests/compat.sh -m tls12 -t 'ECDSA'
345}
346
347component_test_no_hmac_drbg_use_psa () {
348 msg "build: Full minus HMAC_DRBG, PSA crypto in TLS"
349 scripts/config.py full
350 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
351 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
352 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
353
354 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
355 make
356
357 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - main suites"
358 make test
359
360 # Normally our ECDSA implementation uses deterministic ECDSA. But since
361 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
362 # instead.
363 # Test SSL with non-deterministic ECDSA. Only test features that
364 # might be affected by how ECDSA signature is performed.
365 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
366 tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
367
368 # To save time, only test one protocol version, since this part of
369 # the protocol is identical in (D)TLS up to 1.2.
370 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - compat.sh (ECDSA)"
371 tests/compat.sh -m tls12 -t 'ECDSA'
372}
373
374component_test_psa_external_rng_no_drbg_classic () {
375 msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto in TLS"
376 scripts/config.py full
377 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
378 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
379 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
380 scripts/config.py unset MBEDTLS_ENTROPY_C
381 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
382 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
383 scripts/config.py unset MBEDTLS_CTR_DRBG_C
384 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
385 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
386 # When MBEDTLS_USE_PSA_CRYPTO is disabled and there is no DRBG,
387 # the SSL test programs don't have an RNG and can't work. Explicitly
388 # make them use the PSA RNG with -DMBEDTLS_TEST_USE_PSA_CRYPTO_RNG.
389 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DMBEDTLS_TEST_USE_PSA_CRYPTO_RNG" LDFLAGS="$ASAN_CFLAGS"
390
391 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto - main suites"
392 make test
393
394 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto - ssl-opt.sh (subset)"
395 tests/ssl-opt.sh -f 'Default'
396}
397
398component_test_psa_external_rng_no_drbg_use_psa () {
399 msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto in TLS"
400 scripts/config.py full
401 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
402 scripts/config.py unset MBEDTLS_ENTROPY_C
403 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
404 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
405 scripts/config.py unset MBEDTLS_CTR_DRBG_C
406 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
407 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
408 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
409
410 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - main suites"
411 make test
412
413 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - ssl-opt.sh (subset)"
414 tests/ssl-opt.sh -f 'Default\|opaque'
415}
416
Minos Galanakisada21b02024-07-26 12:34:19 +0100417component_test_sw_inet_pton () {
418 msg "build: default plus MBEDTLS_TEST_SW_INET_PTON"
419
420 # MBEDTLS_TEST_HOOKS required for x509_crt_parse_cn_inet_pton
421 scripts/config.py set MBEDTLS_TEST_HOOKS
422 make CFLAGS="-DMBEDTLS_TEST_SW_INET_PTON"
423
424 msg "test: default plus MBEDTLS_TEST_SW_INET_PTON"
425 make test
426}
427
Minos Galanakisada21b02024-07-26 12:34:19 +0100428component_test_full_no_cipher () {
429 msg "build: full no CIPHER"
430
431 scripts/config.py full
432 scripts/config.py unset MBEDTLS_CIPHER_C
433
434 # The built-in implementation of the following algs/key-types depends
435 # on CIPHER_C so we disable them.
436 # This does not hold for KEY_TYPE_CHACHA20 and ALG_CHACHA20_POLY1305
437 # so we keep them enabled.
438 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CCM_STAR_NO_TAG
439 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CMAC
440 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CBC_NO_PADDING
441 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CBC_PKCS7
442 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CFB
443 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CTR
444 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_ECB_NO_PADDING
445 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_OFB
446 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128
447 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_STREAM_CIPHER
448 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_KEY_TYPE_DES
449
450 # The following modules directly depends on CIPHER_C
451 scripts/config.py unset MBEDTLS_CMAC_C
452 scripts/config.py unset MBEDTLS_NIST_KW_C
453
454 make
455
456 # Ensure that CIPHER_C was not re-enabled
457 not grep mbedtls_cipher_init ${BUILTIN_SRC_PATH}/cipher.o
458
459 msg "test: full no CIPHER"
460 make test
461}
462
Minos Galanakisada21b02024-07-26 12:34:19 +0100463component_test_tls1_2_default_stream_cipher_only () {
464 msg "build: default with only stream cipher use psa"
465
466 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
467 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
468 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
469 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CCM
470 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CCM_STAR_NO_TAG
471 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_GCM
472 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CHACHA20_POLY1305
473 # Note: The three unsets below are to be removed for Mbed TLS 4.0
474 scripts/config.py unset MBEDTLS_GCM_C
475 scripts/config.py unset MBEDTLS_CCM_C
476 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
477 #Disable TLS 1.3 (as no AEAD)
478 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
479 # Disable CBC. Note: When implemented, PSA_WANT_ALG_CBC_MAC will also need to be unset here to fully disable CBC
480 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CBC_NO_PADDING
481 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CBC_PKCS7
482 # Disable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
483 # Note: The unset below is to be removed for 4.0
484 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
485 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
486 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
487 # Enable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
488 scripts/config.py set MBEDTLS_CIPHER_NULL_CIPHER
489 # Modules that depend on AEAD
490 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
491 scripts/config.py unset MBEDTLS_SSL_TICKET_C
492
493 make
494
495 msg "test: default with only stream cipher use psa"
496 make test
497
498 # Not running ssl-opt.sh because most tests require a non-NULL ciphersuite.
499}
500
501component_test_tls1_2_default_cbc_legacy_cipher_only () {
502 msg "build: default with only CBC-legacy cipher use psa"
503
504 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
505 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
506 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
507 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CCM
508 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CCM_STAR_NO_TAG
509 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_GCM
510 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CHACHA20_POLY1305
511 # Note: The three unsets below are to be removed for Mbed TLS 4.0
512 scripts/config.py unset MBEDTLS_GCM_C
513 scripts/config.py unset MBEDTLS_CCM_C
514 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
515 #Disable TLS 1.3 (as no AEAD)
516 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
517 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
518 scripts/config.py -f $CRYPTO_CONFIG_H set PSA_WANT_ALG_CBC_NO_PADDING
519 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
520 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
521 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
522 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
523 # Modules that depend on AEAD
524 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
525 scripts/config.py unset MBEDTLS_SSL_TICKET_C
526
527 make
528
529 msg "test: default with only CBC-legacy cipher use psa"
530 make test
531
532 msg "test: default with only CBC-legacy cipher use psa - ssl-opt.sh (subset)"
533 tests/ssl-opt.sh -f "TLS 1.2"
534}
535
536component_test_tls1_2_default_cbc_legacy_cbc_etm_cipher_only () {
537 msg "build: default with only CBC-legacy and CBC-EtM ciphers use psa"
538
539 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
540 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
541 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
542 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CCM
543 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CCM_STAR_NO_TAG
544 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_GCM
545 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CHACHA20_POLY1305
546 # Note: The three unsets below are to be removed for Mbed TLS 4.0
547 scripts/config.py unset MBEDTLS_GCM_C
548 scripts/config.py unset MBEDTLS_CCM_C
549 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
550 #Disable TLS 1.3 (as no AEAD)
551 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
552 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
553 scripts/config.py -f $CRYPTO_CONFIG_H set PSA_WANT_ALG_CBC_NO_PADDING
554 # Enable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
555 scripts/config.py set MBEDTLS_SSL_ENCRYPT_THEN_MAC
556 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
557 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
558 # Modules that depend on AEAD
559 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
560 scripts/config.py unset MBEDTLS_SSL_TICKET_C
561
562 make
563
564 msg "test: default with only CBC-legacy and CBC-EtM ciphers use psa"
565 make test
566
567 msg "test: default with only CBC-legacy and CBC-EtM ciphers use psa - ssl-opt.sh (subset)"
568 tests/ssl-opt.sh -f "TLS 1.2"
569}
570
571# We're not aware of any other (open source) implementation of EC J-PAKE in TLS
572# that we could use for interop testing. However, we now have sort of two
573# implementations ourselves: one using PSA, the other not. At least test that
574# these two interoperate with each other.
575component_test_tls1_2_ecjpake_compatibility() {
576 msg "build: TLS1.2 server+client w/ EC-JPAKE w/o USE_PSA"
577 scripts/config.py set MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
578 # Explicitly make lib first to avoid a race condition:
579 # https://github.com/Mbed-TLS/mbedtls/issues/8229
580 make lib
581 make -C programs ssl/ssl_server2 ssl/ssl_client2
582 cp programs/ssl/ssl_server2 s2_no_use_psa
583 cp programs/ssl/ssl_client2 c2_no_use_psa
584
585 msg "build: TLS1.2 server+client w/ EC-JPAKE w/ USE_PSA"
586 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
587 make clean
588 make lib
589 make -C programs ssl/ssl_server2 ssl/ssl_client2
590 make -C programs test/udp_proxy test/query_compile_time_config
591
592 msg "test: server w/o USE_PSA - client w/ USE_PSA, text password"
593 P_SRV=../s2_no_use_psa tests/ssl-opt.sh -f "ECJPAKE: working, TLS"
594 msg "test: server w/o USE_PSA - client w/ USE_PSA, opaque password"
595 P_SRV=../s2_no_use_psa tests/ssl-opt.sh -f "ECJPAKE: opaque password client only, working, TLS"
596 msg "test: client w/o USE_PSA - server w/ USE_PSA, text password"
597 P_CLI=../c2_no_use_psa tests/ssl-opt.sh -f "ECJPAKE: working, TLS"
598 msg "test: client w/o USE_PSA - server w/ USE_PSA, opaque password"
599 P_CLI=../c2_no_use_psa tests/ssl-opt.sh -f "ECJPAKE: opaque password server only, working, TLS"
600
601 rm s2_no_use_psa c2_no_use_psa
602}
603
604component_test_everest () {
605 msg "build: Everest ECDH context (ASan build)" # ~ 6 min
606 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
607 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Asan .
608 make
609
610 msg "test: Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
611 make test
612
613 msg "test: metatests (clang, ASan)"
614 tests/scripts/run-metatests.sh any asan poison
615
616 msg "test: Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
617 tests/ssl-opt.sh -f ECDH
618
619 msg "test: Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
620 # Exclude some symmetric ciphers that are redundant here to gain time.
621 tests/compat.sh -f ECDH -V NO -e 'ARIA\|CAMELLIA\|CHACHA'
622}
623
624component_test_everest_curve25519_only () {
625 msg "build: Everest ECDH context, only Curve25519" # ~ 6 min
626 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
627 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
628 scripts/config.py unset MBEDTLS_ECDSA_C
629 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_DETERMINISTIC_ECDSA
630 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_ECDSA
631 scripts/config.py -f $CRYPTO_CONFIG_H set PSA_WANT_ALG_ECDH
632 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
633 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
634 scripts/config.py unset MBEDTLS_ECJPAKE_C
635 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_JPAKE
636
637 # Disable all curves
638 scripts/config.py unset-all "MBEDTLS_ECP_DP_[0-9A-Z_a-z]*_ENABLED"
639 scripts/config.py -f $CRYPTO_CONFIG_H unset-all "PSA_WANT_ECC_[0-9A-Z_a-z]*$"
640 scripts/config.py -f $CRYPTO_CONFIG_H set PSA_WANT_ECC_MONTGOMERY_255
641
642 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
643
644 msg "test: Everest ECDH context, only Curve25519" # ~ 50s
645 make test
646}
647
648component_test_small_ssl_out_content_len () {
649 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
650 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
651 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
652 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
653 make
654
655 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
656 tests/ssl-opt.sh -f "Max fragment\|Large packet"
657}
658
659component_test_small_ssl_in_content_len () {
660 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
661 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 4096
662 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
663 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
664 make
665
666 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
667 tests/ssl-opt.sh -f "Max fragment"
668}
669
670component_test_small_ssl_dtls_max_buffering () {
671 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
672 scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
673 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
674 make
675
676 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
677 tests/ssl-opt.sh -f "DTLS reordering: Buffer out-of-order hs msg before reassembling next, free buffered msg"
678}
679
680component_test_small_mbedtls_ssl_dtls_max_buffering () {
681 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
682 scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 190
683 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
684 make
685
686 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
687 tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
688}
689
Minos Galanakisada21b02024-07-26 12:34:19 +0100690component_test_full_cmake_clang () {
691 msg "build: cmake, full config, clang" # ~ 50s
692 scripts/config.py full
693 CC=clang CXX=clang cmake -D CMAKE_BUILD_TYPE:String=Release -D ENABLE_TESTING=On -D TEST_CPP=1 .
694 make
695
696 msg "test: main suites (full config, clang)" # ~ 5s
697 make test
698
699 msg "test: cpp_dummy_build (full config, clang)" # ~ 1s
700 programs/test/cpp_dummy_build
701
702 msg "test: metatests (clang)"
703 tests/scripts/run-metatests.sh any pthread
704
705 msg "program demos (full config, clang)" # ~10s
706 tests/scripts/run_demos.py
707
708 msg "test: psa_constant_names (full config, clang)" # ~ 1s
709 tests/scripts/test_psa_constant_names.py
710
711 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
712 tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
713}
714
715skip_suites_without_constant_flow () {
716 # Skip the test suites that don't have any constant-flow annotations.
717 # This will need to be adjusted if we ever start declaring things as
718 # secret from macros or functions inside tests/include or tests/src.
719 SKIP_TEST_SUITES=$(
720 git -C tests/suites grep -L TEST_CF_ 'test_suite_*.function' |
721 sed 's/test_suite_//; s/\.function$//' |
722 tr '\n' ,),$(
723 git -C tf-psa-crypto/tests/suites grep -L TEST_CF_ 'test_suite_*.function' |
724 sed 's/test_suite_//; s/\.function$//' |
725 tr '\n' ,)
726 export SKIP_TEST_SUITES
727}
728
729skip_all_except_given_suite () {
730 # Skip all but the given test suite
731 SKIP_TEST_SUITES=$(
732 ls -1 tests/suites/test_suite_*.function |
733 grep -v $1.function |
734 sed 's/tests.suites.test_suite_//; s/\.function$//' |
735 tr '\n' ,),$(
736 ls -1 tf-psa-crypto/tests/suites/test_suite_*.function |
737 grep -v $1.function |
738 sed 's/tf-psa-crypto.tests.suites.test_suite_//; s/\.function$//' |
739 tr '\n' ,)
740 export SKIP_TEST_SUITES
741}
742
743component_test_memsan_constant_flow () {
744 # This tests both (1) accesses to undefined memory, and (2) branches or
745 # memory access depending on secret values. To distinguish between those:
746 # - unset MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN - does the failure persist?
747 # - or alternatively, change the build type to MemSanDbg, which enables
748 # origin tracking and nicer stack traces (which are useful for debugging
749 # anyway), and check if the origin was TEST_CF_SECRET() or something else.
750 msg "build: cmake MSan (clang), full config minus MBEDTLS_USE_PSA_CRYPTO with constant flow testing"
751 scripts/config.py full
752 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN
753 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
754 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
755 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
756 make
757
758 msg "test: main suites (full minus MBEDTLS_USE_PSA_CRYPTO, Msan + constant flow)"
759 make test
760}
761
762component_test_memsan_constant_flow_psa () {
763 # This tests both (1) accesses to undefined memory, and (2) branches or
764 # memory access depending on secret values. To distinguish between those:
765 # - unset MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN - does the failure persist?
766 # - or alternatively, change the build type to MemSanDbg, which enables
767 # origin tracking and nicer stack traces (which are useful for debugging
768 # anyway), and check if the origin was TEST_CF_SECRET() or something else.
769 msg "build: cmake MSan (clang), full config with constant flow testing"
770 scripts/config.py full
771 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN
772 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
773 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
774 make
775
776 msg "test: main suites (Msan + constant flow)"
777 make test
778}
779
780component_release_test_valgrind_constant_flow () {
781 # This tests both (1) everything that valgrind's memcheck usually checks
782 # (heap buffer overflows, use of uninitialized memory, use-after-free,
783 # etc.) and (2) branches or memory access depending on secret values,
784 # which will be reported as uninitialized memory. To distinguish between
785 # secret and actually uninitialized:
786 # - unset MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND - does the failure persist?
787 # - or alternatively, build with debug info and manually run the offending
788 # test suite with valgrind --track-origins=yes, then check if the origin
789 # was TEST_CF_SECRET() or something else.
790 msg "build: cmake release GCC, full config minus MBEDTLS_USE_PSA_CRYPTO with constant flow testing"
791 scripts/config.py full
792 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND
793 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
794 skip_suites_without_constant_flow
795 cmake -D CMAKE_BUILD_TYPE:String=Release .
796 make
797
798 # this only shows a summary of the results (how many of each type)
799 # details are left in Testing/<date>/DynamicAnalysis.xml
800 msg "test: some suites (full minus MBEDTLS_USE_PSA_CRYPTO, valgrind + constant flow)"
801 make memcheck
802
803 # Test asm path in constant time module - by default, it will test the plain C
804 # path under Valgrind or Memsan. Running only the constant_time tests is fast (<1s)
805 msg "test: valgrind asm constant_time"
806 scripts/config.py --force set MBEDTLS_TEST_CONSTANT_FLOW_ASM
807 skip_all_except_given_suite test_suite_constant_time
808 cmake -D CMAKE_BUILD_TYPE:String=Release .
809 make clean
810 make
811 make memcheck
812}
813
814component_release_test_valgrind_constant_flow_psa () {
815 # This tests both (1) everything that valgrind's memcheck usually checks
816 # (heap buffer overflows, use of uninitialized memory, use-after-free,
817 # etc.) and (2) branches or memory access depending on secret values,
818 # which will be reported as uninitialized memory. To distinguish between
819 # secret and actually uninitialized:
820 # - unset MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND - does the failure persist?
821 # - or alternatively, build with debug info and manually run the offending
822 # test suite with valgrind --track-origins=yes, then check if the origin
823 # was TEST_CF_SECRET() or something else.
824 msg "build: cmake release GCC, full config with constant flow testing"
825 scripts/config.py full
826 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND
827 skip_suites_without_constant_flow
828 cmake -D CMAKE_BUILD_TYPE:String=Release .
829 make
830
831 # this only shows a summary of the results (how many of each type)
832 # details are left in Testing/<date>/DynamicAnalysis.xml
833 msg "test: some suites (valgrind + constant flow)"
834 make memcheck
835}
836
837component_test_tsan () {
838 msg "build: TSan (clang)"
839 scripts/config.py full
840 scripts/config.py set MBEDTLS_THREADING_C
841 scripts/config.py set MBEDTLS_THREADING_PTHREAD
842 # Self-tests do not currently use multiple threads.
843 scripts/config.py unset MBEDTLS_SELF_TEST
844
845 # The deprecated MBEDTLS_PSA_CRYPTO_SE_C interface is not thread safe.
846 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
847
848 CC=clang cmake -D CMAKE_BUILD_TYPE:String=TSan .
849 make
850
851 msg "test: main suites (TSan)"
852 make test
853}
854
855component_test_default_no_deprecated () {
856 # Test that removing the deprecated features from the default
857 # configuration leaves something consistent.
858 msg "build: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 30s
859 scripts/config.py set MBEDTLS_DEPRECATED_REMOVED
860 make CFLAGS='-O -Werror -Wall -Wextra'
861
862 msg "test: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 5s
863 make test
864}
865
866component_test_full_no_deprecated () {
867 msg "build: make, full_no_deprecated config" # ~ 30s
868 scripts/config.py full_no_deprecated
869 make CFLAGS='-O -Werror -Wall -Wextra'
870
871 msg "test: make, full_no_deprecated config" # ~ 5s
872 make test
873
874 msg "test: ensure that X509 has no direct dependency on BIGNUM_C"
875 not grep mbedtls_mpi library/libmbedx509.a
876}
877
878component_test_full_no_deprecated_deprecated_warning () {
879 # Test that there is nothing deprecated in "full_no_deprecated".
880 # A deprecated feature would trigger a warning (made fatal) from
881 # MBEDTLS_DEPRECATED_WARNING.
882 msg "build: make, full_no_deprecated config, MBEDTLS_DEPRECATED_WARNING" # ~ 30s
883 scripts/config.py full_no_deprecated
884 scripts/config.py unset MBEDTLS_DEPRECATED_REMOVED
885 scripts/config.py set MBEDTLS_DEPRECATED_WARNING
886 make CFLAGS='-O -Werror -Wall -Wextra'
887
888 msg "test: make, full_no_deprecated config, MBEDTLS_DEPRECATED_WARNING" # ~ 5s
889 make test
890}
891
892component_test_full_deprecated_warning () {
893 # Test that when MBEDTLS_DEPRECATED_WARNING is enabled, the build passes
894 # with only certain whitelisted types of warnings.
895 msg "build: make, full config + MBEDTLS_DEPRECATED_WARNING, expect warnings" # ~ 30s
896 scripts/config.py full
897 scripts/config.py set MBEDTLS_DEPRECATED_WARNING
898 # Expect warnings from '#warning' directives in check_config.h.
899 # Note that gcc is required to allow the use of -Wno-error=cpp, which allows us to
900 # display #warning messages without them being treated as errors.
901 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-error=cpp' lib programs
902
903 msg "build: make tests, full config + MBEDTLS_DEPRECATED_WARNING, expect warnings" # ~ 30s
904 # Set MBEDTLS_TEST_DEPRECATED to enable tests for deprecated features.
905 # By default those are disabled when MBEDTLS_DEPRECATED_WARNING is set.
906 # Expect warnings from '#warning' directives in check_config.h and
907 # from the use of deprecated functions in test suites.
908 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-error=deprecated-declarations -Wno-error=cpp -DMBEDTLS_TEST_DEPRECATED' tests
909
910 msg "test: full config + MBEDTLS_TEST_DEPRECATED" # ~ 30s
911 make test
912
913 msg "program demos: full config + MBEDTLS_TEST_DEPRECATED" # ~10s
914 tests/scripts/run_demos.py
915}
916
Minos Galanakisada21b02024-07-26 12:34:19 +0100917component_build_baremetal () {
918 msg "build: make, baremetal config"
919 scripts/config.py baremetal
920 make CFLAGS="-O1 -Werror -I$PWD/tests/include/baremetal-override/"
921}
922support_build_baremetal () {
923 # Older Glibc versions include time.h from other headers such as stdlib.h,
924 # which makes the no-time.h-in-baremetal check fail. Ubuntu 16.04 has this
925 # problem, Ubuntu 18.04 is ok.
926 ! grep -q -F time.h /usr/include/x86_64-linux-gnu/sys/types.h
927}
928
Minos Galanakisada21b02024-07-26 12:34:19 +0100929component_test_no_psa_crypto_full_cmake_asan() {
930 # full minus MBEDTLS_PSA_CRYPTO_C: run the same set of tests as basic-build-test.sh
931 msg "build: cmake, full config minus PSA crypto, ASan"
932 scripts/config.py full
933 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
934 scripts/config.py unset MBEDTLS_PSA_CRYPTO_CLIENT
935 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
936 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
937 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
938 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
939 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
940 scripts/config.py unset MBEDTLS_LMS_C
941 scripts/config.py unset MBEDTLS_LMS_PRIVATE
942 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
943 make
944
945 msg "test: main suites (full minus PSA crypto)"
946 make test
947
948 # Note: ssl-opt.sh has some test cases that depend on
949 # MBEDTLS_ECP_RESTARTABLE && !MBEDTLS_USE_PSA_CRYPTO
950 # This is the only component where those tests are not skipped.
951 msg "test: ssl-opt.sh (full minus PSA crypto)"
952 tests/ssl-opt.sh
953
954 # Note: the next two invocations cover all compat.sh test cases.
955 # We should use the same here and in basic-build-test.sh.
956 msg "test: compat.sh: default version (full minus PSA crypto)"
957 tests/compat.sh -e 'ARIA\|CHACHA'
958
959 msg "test: compat.sh: next: ARIA, Chacha (full minus PSA crypto)"
960 env OPENSSL="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
961}
962
Minos Galanakisada21b02024-07-26 12:34:19 +0100963# Common helper for component_full_without_ecdhe_ecdsa() and
964# component_full_without_ecdhe_ecdsa_and_tls13() which:
965# - starts from the "full" configuration minus the list of symbols passed in
966# as 1st parameter
967# - build
968# - test only TLS (i.e. test_suite_tls and ssl-opt)
969build_full_minus_something_and_test_tls () {
970 symbols_to_disable="$1"
971
972 msg "build: full minus something, test TLS"
973
974 scripts/config.py full
975 for sym in $symbols_to_disable; do
976 echo "Disabling $sym"
977 scripts/config.py unset $sym
978 done
979
980 make
981
982 msg "test: full minus something, test TLS"
983 ( cd tests; ./test_suite_ssl )
984
985 msg "ssl-opt: full minus something, test TLS"
986 tests/ssl-opt.sh
987}
988
989component_full_without_ecdhe_ecdsa () {
990 build_full_minus_something_and_test_tls "MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED"
991}
992
993component_full_without_ecdhe_ecdsa_and_tls13 () {
994 build_full_minus_something_and_test_tls "MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
995 MBEDTLS_SSL_PROTO_TLS1_3"
996}
997
Minos Galanakisada21b02024-07-26 12:34:19 +0100998component_build_tfm() {
999 # Check that the TF-M configuration can build cleanly with various
1000 # warning flags enabled. We don't build or run tests, since the
1001 # TF-M configuration needs a TF-M platform. A tweaked version of
1002 # the configuration that works on mainstream platforms is in
1003 # configs/config-tfm.h, tested via test-ref-configs.pl.
1004 cp configs/config-tfm.h "$CONFIG_H"
1005
1006 msg "build: TF-M config, clang, armv7-m thumb2"
1007 make lib CC="clang" CFLAGS="--target=arm-linux-gnueabihf -march=armv7-m -mthumb -Os -std=c99 -Werror -Wall -Wextra -Wwrite-strings -Wpointer-arith -Wimplicit-fallthrough -Wshadow -Wvla -Wformat=2 -Wno-format-nonliteral -Wshadow -Wasm-operand-widths -Wunused -I../tests/include/spe"
1008
1009 msg "build: TF-M config, gcc native build"
1010 make clean
1011 make lib CC="gcc" CFLAGS="-Os -std=c99 -Werror -Wall -Wextra -Wwrite-strings -Wpointer-arith -Wshadow -Wvla -Wformat=2 -Wno-format-nonliteral -Wshadow -Wformat-signedness -Wlogical-op -I../tests/include/spe"
1012}
1013
Minos Galanakisada21b02024-07-26 12:34:19 +01001014component_test_no_platform () {
1015 # Full configuration build, without platform support, file IO and net sockets.
1016 # This should catch missing mbedtls_printf definitions, and by disabling file
1017 # IO, it should catch missing '#include <stdio.h>'
1018 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
1019 scripts/config.py full_no_platform
1020 scripts/config.py unset MBEDTLS_PLATFORM_C
1021 scripts/config.py unset MBEDTLS_NET_C
1022 scripts/config.py unset MBEDTLS_FS_IO
1023 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
1024 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
1025 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
1026 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1027 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
1028 # to re-enable platform integration features otherwise disabled in C99 builds
1029 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -Os -D_DEFAULT_SOURCE' lib programs
1030 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os' test
1031}
1032
Minos Galanakisada21b02024-07-26 12:34:19 +01001033component_build_no_ssl_srv () {
1034 msg "build: full config except SSL server, make, gcc" # ~ 30s
1035 scripts/config.py full
1036 scripts/config.py unset MBEDTLS_SSL_SRV_C
1037 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
1038}
1039
1040component_build_no_ssl_cli () {
1041 msg "build: full config except SSL client, make, gcc" # ~ 30s
1042 scripts/config.py full
1043 scripts/config.py unset MBEDTLS_SSL_CLI_C
1044 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
1045}
1046
Minos Galanakisada21b02024-07-26 12:34:19 +01001047component_test_memory_buffer_allocator_backtrace () {
1048 msg "build: default config with memory buffer allocator and backtrace enabled"
1049 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
1050 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
1051 scripts/config.py set MBEDTLS_MEMORY_BACKTRACE
1052 scripts/config.py set MBEDTLS_MEMORY_DEBUG
1053 cmake -DCMAKE_BUILD_TYPE:String=Release .
1054 make
1055
1056 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C and MBEDTLS_MEMORY_BACKTRACE"
1057 make test
1058}
1059
1060component_test_memory_buffer_allocator () {
1061 msg "build: default config with memory buffer allocator"
1062 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
1063 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
1064 cmake -DCMAKE_BUILD_TYPE:String=Release .
1065 make
1066
1067 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C"
1068 make test
1069
1070 msg "test: ssl-opt.sh, MBEDTLS_MEMORY_BUFFER_ALLOC_C"
1071 # MBEDTLS_MEMORY_BUFFER_ALLOC is slow. Skip tests that tend to time out.
1072 tests/ssl-opt.sh -e '^DTLS proxy'
1073}
1074
1075component_test_no_max_fragment_length () {
1076 # Run max fragment length tests with MFL disabled
1077 msg "build: default config except MFL extension (ASan build)" # ~ 30s
1078 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
1079 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
1080 make
1081
1082 msg "test: ssl-opt.sh, MFL-related tests"
1083 tests/ssl-opt.sh -f "Max fragment length"
1084}
1085
1086component_test_asan_remove_peer_certificate () {
1087 msg "build: default config with MBEDTLS_SSL_KEEP_PEER_CERTIFICATE disabled (ASan build)"
1088 scripts/config.py unset MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
1089 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
1090 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
1091 make
1092
1093 msg "test: !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
1094 make test
1095
1096 msg "test: ssl-opt.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
1097 tests/ssl-opt.sh
1098
1099 msg "test: compat.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
1100 tests/compat.sh
1101
1102 msg "test: context-info.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
1103 tests/context-info.sh
1104}
1105
1106component_test_no_max_fragment_length_small_ssl_out_content_len () {
1107 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
1108 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
1109 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
1110 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
1111 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
1112 make
1113
1114 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
1115 tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
1116
1117 msg "test: context-info.sh (disabled MFL extension case)"
1118 tests/context-info.sh
1119}
1120
1121component_test_variable_ssl_in_out_buffer_len () {
1122 msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled (ASan build)"
1123 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
1124 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
1125 make
1126
1127 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
1128 make test
1129
1130 msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
1131 tests/ssl-opt.sh
1132
1133 msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
1134 tests/compat.sh
1135}
1136
1137component_test_dtls_cid_legacy () {
1138 msg "build: MBEDTLS_SSL_DTLS_CONNECTION_ID (legacy) enabled (ASan build)"
1139 scripts/config.py set MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT 1
1140
1141 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
1142 make
1143
1144 msg "test: MBEDTLS_SSL_DTLS_CONNECTION_ID (legacy)"
1145 make test
1146
1147 msg "test: ssl-opt.sh, MBEDTLS_SSL_DTLS_CONNECTION_ID (legacy) enabled"
1148 tests/ssl-opt.sh
1149
1150 msg "test: compat.sh, MBEDTLS_SSL_DTLS_CONNECTION_ID (legacy) enabled"
1151 tests/compat.sh
1152}
1153
1154component_test_ssl_alloc_buffer_and_mfl () {
1155 msg "build: default config with memory buffer allocator and MFL extension"
1156 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
1157 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
1158 scripts/config.py set MBEDTLS_MEMORY_DEBUG
1159 scripts/config.py set MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
1160 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
1161 cmake -DCMAKE_BUILD_TYPE:String=Release .
1162 make
1163
1164 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH, MBEDTLS_MEMORY_BUFFER_ALLOC_C, MBEDTLS_MEMORY_DEBUG and MBEDTLS_SSL_MAX_FRAGMENT_LENGTH"
1165 make test
1166
1167 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH, MBEDTLS_MEMORY_BUFFER_ALLOC_C, MBEDTLS_MEMORY_DEBUG and MBEDTLS_SSL_MAX_FRAGMENT_LENGTH"
1168 tests/ssl-opt.sh -f "Handshake memory usage"
1169}
1170
1171component_test_when_no_ciphersuites_have_mac () {
1172 msg "build: when no ciphersuites have MAC"
1173 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1174 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_NO_PADDING
1175 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_PKCS7
1176 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CMAC
1177 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128
1178
1179 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
1180 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
1181 scripts/config.py unset MBEDTLS_CMAC_C
1182
1183 make
1184
1185 msg "test: !MBEDTLS_SSL_SOME_SUITES_USE_MAC"
1186 make test
1187
1188 msg "test ssl-opt.sh: !MBEDTLS_SSL_SOME_SUITES_USE_MAC"
1189 tests/ssl-opt.sh -f 'Default\|EtM' -e 'without EtM'
1190}
1191
Minos Galanakisada21b02024-07-26 12:34:19 +01001192component_test_malloc_0_null () {
1193 msg "build: malloc(0) returns NULL (ASan+UBSan build)"
1194 scripts/config.py full
1195 make CC=$ASAN_CC CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"$PWD/tests/configs/user-config-malloc-0-null.h\"' $ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
1196
1197 msg "test: malloc(0) returns NULL (ASan+UBSan build)"
1198 make test
1199
1200 msg "selftest: malloc(0) returns NULL (ASan+UBSan build)"
1201 # Just the calloc selftest. "make test" ran the others as part of the
1202 # test suites.
1203 programs/test/selftest calloc
1204
1205 msg "test ssl-opt.sh: malloc(0) returns NULL (ASan+UBSan build)"
1206 # Run a subset of the tests. The choice is a balance between coverage
1207 # and time (including time indirectly wasted due to flaky tests).
1208 # The current choice is to skip tests whose description includes
1209 # "proxy", which is an approximation of skipping tests that use the
1210 # UDP proxy, which tend to be slower and flakier.
1211 tests/ssl-opt.sh -e 'proxy'
1212}
1213
Minos Galanakisada21b02024-07-26 12:34:19 +01001214component_build_mbedtls_config_file () {
1215 msg "build: make with MBEDTLS_CONFIG_FILE" # ~40s
1216 scripts/config.py -w full_config.h full
1217 echo '#error "MBEDTLS_CONFIG_FILE is not working"' >"$CONFIG_H"
1218 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"'"
1219 # Make sure this feature is enabled. We'll disable it in the next phase.
1220 programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
1221 make clean
1222
1223 msg "build: make with MBEDTLS_CONFIG_FILE + MBEDTLS_USER_CONFIG_FILE"
1224 # In the user config, disable one feature (for simplicity, pick a feature
1225 # that nothing else depends on).
1226 echo '#undef MBEDTLS_NIST_KW_C' >user_config.h
1227 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"' -DMBEDTLS_USER_CONFIG_FILE='\"user_config.h\"'"
1228 not programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
1229
1230 rm -f user_config.h full_config.h
1231}
1232
Minos Galanakisada21b02024-07-26 12:34:19 +01001233
Minos Galanakisada21b02024-07-26 12:34:19 +01001234
Minos Galanakisada21b02024-07-26 12:34:19 +01001235
Minos Galanakisada21b02024-07-26 12:34:19 +01001236
1237component_test_m32_no_asm () {
1238 # Build without assembly, so as to use portable C code (in a 32-bit
1239 # build) and not the i386-specific inline assembly.
1240 #
1241 # Note that we require gcc, because clang Asan builds fail to link for
1242 # this target (cannot find libclang_rt.lsan-i386.a - this is a known clang issue).
1243 msg "build: i386, make, gcc, no asm (ASan build)" # ~ 30s
1244 scripts/config.py full
1245 scripts/config.py unset MBEDTLS_HAVE_ASM
1246 scripts/config.py unset MBEDTLS_AESNI_C # AESNI for 32-bit is tested in test_aesni_m32
1247 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32" LDFLAGS="-m32 $ASAN_CFLAGS"
1248
1249 msg "test: i386, make, gcc, no asm (ASan build)"
1250 make test
1251}
1252support_test_m32_no_asm () {
1253 case $(uname -m) in
1254 amd64|x86_64) true;;
1255 *) false;;
1256 esac
1257}
1258
1259component_test_m32_o2 () {
1260 # Build with optimization, to use the i386 specific inline assembly
1261 # and go faster for tests.
1262 msg "build: i386, make, gcc -O2 (ASan build)" # ~ 30s
1263 scripts/config.py full
1264 scripts/config.py unset MBEDTLS_AESNI_C # AESNI for 32-bit is tested in test_aesni_m32
1265 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32" LDFLAGS="-m32 $ASAN_CFLAGS"
1266
1267 msg "test: i386, make, gcc -O2 (ASan build)"
1268 make test
1269
1270 msg "test ssl-opt.sh, i386, make, gcc-O2"
1271 tests/ssl-opt.sh
1272}
1273support_test_m32_o2 () {
1274 support_test_m32_no_asm "$@"
1275}
1276
1277component_test_m32_everest () {
1278 msg "build: i386, Everest ECDH context (ASan build)" # ~ 6 min
1279 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
1280 scripts/config.py unset MBEDTLS_AESNI_C # AESNI for 32-bit is tested in test_aesni_m32
1281 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32" LDFLAGS="-m32 $ASAN_CFLAGS"
1282
1283 msg "test: i386, Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
1284 make test
1285
1286 msg "test: i386, Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
1287 tests/ssl-opt.sh -f ECDH
1288
1289 msg "test: i386, Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
1290 # Exclude some symmetric ciphers that are redundant here to gain time.
1291 tests/compat.sh -f ECDH -V NO -e 'ARIA\|CAMELLIA\|CHACHA'
1292}
1293support_test_m32_everest () {
1294 support_test_m32_no_asm "$@"
1295}
1296
1297component_test_mx32 () {
1298 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
1299 scripts/config.py full
1300 make CC=gcc CFLAGS='-O2 -Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
1301
1302 msg "test: 64-bit ILP32, make, gcc"
1303 make test
1304}
1305support_test_mx32 () {
1306 case $(uname -m) in
1307 amd64|x86_64) true;;
1308 *) false;;
1309 esac
1310}
1311
Minos Galanakisada21b02024-07-26 12:34:19 +01001312component_test_no_x509_info () {
1313 msg "build: full + MBEDTLS_X509_REMOVE_INFO" # ~ 10s
1314 scripts/config.pl full
1315 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
1316 scripts/config.pl set MBEDTLS_X509_REMOVE_INFO
1317 make CFLAGS='-Werror -O2'
1318
1319 msg "test: full + MBEDTLS_X509_REMOVE_INFO" # ~ 10s
1320 make test
1321
1322 msg "test: ssl-opt.sh, full + MBEDTLS_X509_REMOVE_INFO" # ~ 1 min
1323 tests/ssl-opt.sh
1324}
1325
Minos Galanakisada21b02024-07-26 12:34:19 +01001326component_test_tls12_only () {
1327 msg "build: default config without MBEDTLS_SSL_PROTO_TLS1_3, cmake, gcc, ASan"
1328 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
1329 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1330 make
1331
1332 msg "test: main suites (inc. selftests) (ASan build)"
1333 make test
1334
1335 msg "test: ssl-opt.sh (ASan build)"
1336 tests/ssl-opt.sh
1337
1338 msg "test: compat.sh (ASan build)"
1339 tests/compat.sh
1340}
1341
1342component_test_tls13_only () {
1343 msg "build: default config without MBEDTLS_SSL_PROTO_TLS1_2"
1344 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
1345 scripts/config.py set MBEDTLS_SSL_RECORD_SIZE_LIMIT
1346 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
1347
1348 msg "test: TLS 1.3 only, all key exchange modes enabled"
1349 make test
1350
1351 msg "ssl-opt.sh: TLS 1.3 only, all key exchange modes enabled"
1352 tests/ssl-opt.sh
1353}
1354
1355component_test_tls13_only_psk () {
1356 msg "build: TLS 1.3 only from default, only PSK key exchange mode"
1357 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
1358 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
1359 scripts/config.py unset MBEDTLS_ECDH_C
1360 scripts/config.py unset MBEDTLS_DHM_C
1361 scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
1362 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
1363 scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
1364 scripts/config.py unset MBEDTLS_ECDSA_C
1365 scripts/config.py unset MBEDTLS_PKCS1_V21
1366 scripts/config.py unset MBEDTLS_PKCS7_C
1367 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
1368 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
1369
1370 msg "test_suite_ssl: TLS 1.3 only, only PSK key exchange mode enabled"
1371 cd tests; ./test_suite_ssl; cd ..
1372
1373 msg "ssl-opt.sh: TLS 1.3 only, only PSK key exchange mode enabled"
1374 tests/ssl-opt.sh
1375}
1376
1377component_test_tls13_only_ephemeral () {
1378 msg "build: TLS 1.3 only from default, only ephemeral key exchange mode"
1379 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
1380 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
1381 scripts/config.py unset MBEDTLS_SSL_EARLY_DATA
1382 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
1383
1384 msg "test_suite_ssl: TLS 1.3 only, only ephemeral key exchange mode"
1385 cd tests; ./test_suite_ssl; cd ..
1386
1387 msg "ssl-opt.sh: TLS 1.3 only, only ephemeral key exchange mode"
1388 tests/ssl-opt.sh
1389}
1390
1391component_test_tls13_only_ephemeral_ffdh () {
1392 msg "build: TLS 1.3 only from default, only ephemeral ffdh key exchange mode"
1393 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
1394 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
1395 scripts/config.py unset MBEDTLS_SSL_EARLY_DATA
1396 scripts/config.py unset MBEDTLS_ECDH_C
1397
1398 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
1399
1400 msg "test_suite_ssl: TLS 1.3 only, only ephemeral ffdh key exchange mode"
1401 cd tests; ./test_suite_ssl; cd ..
1402
1403 msg "ssl-opt.sh: TLS 1.3 only, only ephemeral ffdh key exchange mode"
1404 tests/ssl-opt.sh
1405}
1406
1407component_test_tls13_only_psk_ephemeral () {
1408 msg "build: TLS 1.3 only from default, only PSK ephemeral key exchange mode"
1409 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
1410 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
1411 scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
1412 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
1413 scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
1414 scripts/config.py unset MBEDTLS_ECDSA_C
1415 scripts/config.py unset MBEDTLS_PKCS1_V21
1416 scripts/config.py unset MBEDTLS_PKCS7_C
1417 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
1418 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
1419
1420 msg "test_suite_ssl: TLS 1.3 only, only PSK ephemeral key exchange mode"
1421 cd tests; ./test_suite_ssl; cd ..
1422
1423 msg "ssl-opt.sh: TLS 1.3 only, only PSK ephemeral key exchange mode"
1424 tests/ssl-opt.sh
1425}
1426
1427component_test_tls13_only_psk_ephemeral_ffdh () {
1428 msg "build: TLS 1.3 only from default, only PSK ephemeral ffdh key exchange mode"
1429 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
1430 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
1431 scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
1432 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
1433 scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
1434 scripts/config.py unset MBEDTLS_ECDSA_C
1435 scripts/config.py unset MBEDTLS_PKCS1_V21
1436 scripts/config.py unset MBEDTLS_PKCS7_C
1437 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
1438 scripts/config.py unset MBEDTLS_ECDH_C
1439 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
1440
1441 msg "test_suite_ssl: TLS 1.3 only, only PSK ephemeral ffdh key exchange mode"
1442 cd tests; ./test_suite_ssl; cd ..
1443
1444 msg "ssl-opt.sh: TLS 1.3 only, only PSK ephemeral ffdh key exchange mode"
1445 tests/ssl-opt.sh
1446}
1447
1448component_test_tls13_only_psk_all () {
1449 msg "build: TLS 1.3 only from default, without ephemeral key exchange mode"
1450 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
1451 scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
1452 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
1453 scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
1454 scripts/config.py unset MBEDTLS_ECDSA_C
1455 scripts/config.py unset MBEDTLS_PKCS1_V21
1456 scripts/config.py unset MBEDTLS_PKCS7_C
1457 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
1458 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
1459
1460 msg "test_suite_ssl: TLS 1.3 only, PSK and PSK ephemeral key exchange modes"
1461 cd tests; ./test_suite_ssl; cd ..
1462
1463 msg "ssl-opt.sh: TLS 1.3 only, PSK and PSK ephemeral key exchange modes"
1464 tests/ssl-opt.sh
1465}
1466
1467component_test_tls13_only_ephemeral_all () {
1468 msg "build: TLS 1.3 only from default, without PSK key exchange mode"
1469 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
1470 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
1471 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
1472
1473 msg "test_suite_ssl: TLS 1.3 only, ephemeral and PSK ephemeral key exchange modes"
1474 cd tests; ./test_suite_ssl; cd ..
1475
1476 msg "ssl-opt.sh: TLS 1.3 only, ephemeral and PSK ephemeral key exchange modes"
1477 tests/ssl-opt.sh
1478}
1479
1480component_test_tls13_no_padding () {
1481 msg "build: default config plus early data minus padding"
1482 scripts/config.py set MBEDTLS_SSL_CID_TLS1_3_PADDING_GRANULARITY 1
1483 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
1484 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
1485 make
1486 msg "test: default config plus early data minus padding"
1487 make test
1488 msg "ssl-opt.sh (TLS 1.3 no padding)"
1489 tests/ssl-opt.sh
1490}
1491
1492component_test_tls13_no_compatibility_mode () {
1493 msg "build: default config plus early data minus middlebox compatibility mode"
1494 scripts/config.py unset MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
1495 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
1496 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
1497 make
1498 msg "test: default config plus early data minus middlebox compatibility mode"
1499 make test
1500 msg "ssl-opt.sh (TLS 1.3 no compatibility mode)"
1501 tests/ssl-opt.sh
1502}
1503
1504component_test_full_minus_session_tickets() {
1505 msg "build: full config without session tickets"
1506 scripts/config.py full
1507 scripts/config.py unset MBEDTLS_SSL_SESSION_TICKETS
1508 scripts/config.py unset MBEDTLS_SSL_EARLY_DATA
1509 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1510 make
1511 msg "test: full config without session tickets"
1512 make test
1513 msg "ssl-opt.sh (full config without session tickets)"
1514 tests/ssl-opt.sh
1515}
1516
Minos Galanakisada21b02024-07-26 12:34:19 +01001517component_test_memsan () {
1518 msg "build: MSan (clang)" # ~ 1 min 20s
1519 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1520 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1521 make
1522
1523 msg "test: main suites (MSan)" # ~ 10s
1524 make test
1525
1526 msg "test: metatests (MSan)"
1527 tests/scripts/run-metatests.sh any msan
1528
1529 msg "program demos (MSan)" # ~20s
1530 tests/scripts/run_demos.py
1531
1532 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
1533 tests/ssl-opt.sh
1534
1535 # Optional part(s)
1536
1537 if [ "$MEMORY" -gt 0 ]; then
1538 msg "test: compat.sh (MSan)" # ~ 6 min 20s
1539 tests/compat.sh
1540 fi
1541}
1542
1543component_release_test_valgrind () {
1544 msg "build: Release (clang)"
1545 # default config, in particular without MBEDTLS_USE_PSA_CRYPTO
1546 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
1547 make
1548
1549 msg "test: main suites, Valgrind (default config)"
1550 make memcheck
1551
1552 # Optional parts (slow; currently broken on OS X because programs don't
1553 # seem to receive signals under valgrind on OS X).
1554 # These optional parts don't run on the CI.
1555 if [ "$MEMORY" -gt 0 ]; then
1556 msg "test: ssl-opt.sh --memcheck (default config)"
1557 tests/ssl-opt.sh --memcheck
1558 fi
1559
1560 if [ "$MEMORY" -gt 1 ]; then
1561 msg "test: compat.sh --memcheck (default config)"
1562 tests/compat.sh --memcheck
1563 fi
1564
1565 if [ "$MEMORY" -gt 0 ]; then
1566 msg "test: context-info.sh --memcheck (default config)"
1567 tests/context-info.sh --memcheck
1568 fi
1569}
1570
1571component_release_test_valgrind_psa () {
1572 msg "build: Release, full (clang)"
1573 # full config, in particular with MBEDTLS_USE_PSA_CRYPTO
1574 scripts/config.py full
1575 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
1576 make
1577
1578 msg "test: main suites, Valgrind (full config)"
1579 make memcheck
1580}
1581
Minos Galanakisada21b02024-07-26 12:34:19 +01001582component_build_zeroize_checks () {
1583 msg "build: check for obviously wrong calls to mbedtls_platform_zeroize()"
1584
1585 scripts/config.py full
1586
1587 # Only compile - we're looking for sizeof-pointer-memaccess warnings
1588 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-zeroize-memset.h\"' -DMBEDTLS_TEST_DEFINES_ZEROIZE -Werror -Wsizeof-pointer-memaccess"
1589}
1590
Minos Galanakisdb7b1bb2024-07-26 13:39:09 +01001591component_test_psasim () {
Minos Galanakisada21b02024-07-26 12:34:19 +01001592 msg "build server library and application"
1593 scripts/config.py crypto
1594 helper_psasim_config server
1595 helper_psasim_build server
1596
1597 helper_psasim_cleanup_before_client
1598
1599 msg "build library for client"
1600 helper_psasim_config client
1601 helper_psasim_build client
1602
1603 msg "build basic psasim client"
1604 make -C tests/psa-client-server/psasim CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS" test/psa_client_base
1605 msg "test basic psasim client"
1606 tests/psa-client-server/psasim/test/run_test.sh psa_client_base
1607
1608 msg "build full psasim client"
1609 make -C tests/psa-client-server/psasim CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS" test/psa_client_full
1610 msg "test full psasim client"
1611 tests/psa-client-server/psasim/test/run_test.sh psa_client_full
1612
1613 make -C tests/psa-client-server/psasim clean
1614}
1615
Minos Galanakisdb7b1bb2024-07-26 13:39:09 +01001616component_test_suite_with_psasim () {
Minos Galanakisada21b02024-07-26 12:34:19 +01001617 msg "build server library and application"
1618 helper_psasim_config server
1619 # Modify server's library configuration here (if needed)
1620 helper_psasim_build server
1621
1622 helper_psasim_cleanup_before_client
1623
1624 msg "build client library"
1625 helper_psasim_config client
1626 # PAKE functions are still unsupported from PSASIM
1627 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_JPAKE
1628 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
1629 helper_psasim_build client
1630
1631 msg "build test suites"
1632 make PSASIM=1 CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS" tests
1633
1634 helper_psasim_server kill
1635 helper_psasim_server start
1636
1637 # psasim takes an extremely long execution time on some test suites so we
1638 # exclude them from the list.
1639 SKIP_TEST_SUITES="constant_time_hmac,lmots,lms"
1640 export SKIP_TEST_SUITES
1641
1642 msg "run test suites"
1643 make PSASIM=1 test
1644
1645 helper_psasim_server kill
Minos Galanakis85c78f52024-07-26 14:11:08 +01001646}