| Manuel Pégourié-Gonnard | 72e51ee | 2014-08-31 10:22:11 +0200 | [diff] [blame] | 1 | #!/bin/sh | 
| Paul Bakker | accd4eb | 2013-07-19 13:41:51 +0200 | [diff] [blame] | 2 |  | 
| Simon Butcher | ac22d11 | 2016-09-04 22:31:09 +0100 | [diff] [blame] | 3 | # compat.sh | 
|  | 4 | # | 
| Bence Szépkúti | 1e14827 | 2020-08-07 13:07:28 +0200 | [diff] [blame] | 5 | # Copyright The Mbed TLS Contributors | 
| Dave Rodgman | 16799db | 2023-11-02 19:47:20 +0000 | [diff] [blame] | 6 | # SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later | 
| Bence Szépkúti | c7da1fe | 2020-05-26 01:54:15 +0200 | [diff] [blame] | 7 | # | 
| Simon Butcher | ac22d11 | 2016-09-04 22:31:09 +0100 | [diff] [blame] | 8 | # Purpose | 
|  | 9 | # | 
|  | 10 | # Test interoperbility with OpenSSL, GnuTLS as well as itself. | 
| Manuel Pégourié-Gonnard | 12b8472 | 2014-03-25 19:07:28 +0100 | [diff] [blame] | 11 | # | 
|  | 12 | # Check each common ciphersuite, with each version, both ways (client/server), | 
|  | 13 | # with and without client authentication. | 
| Manuel Pégourié-Gonnard | eaadc50 | 2014-02-20 11:01:30 +0100 | [diff] [blame] | 14 |  | 
| Manuel Pégourié-Gonnard | 913030c | 2014-03-28 10:12:38 +0100 | [diff] [blame] | 15 | set -u | 
|  | 16 |  | 
| Jaeden Amero | 6e70eb2 | 2019-07-03 13:51:04 +0100 | [diff] [blame] | 17 | # Limit the size of each log to 10 GiB, in case of failures with this script | 
|  | 18 | # where it may output seemingly unlimited length error logs. | 
|  | 19 | ulimit -f 20971520 | 
|  | 20 |  | 
| Yanray Wang | ad47063 | 2023-02-20 14:58:03 +0800 | [diff] [blame] | 21 | ORIGINAL_PWD=$PWD | 
|  | 22 | if ! cd "$(dirname "$0")"; then | 
|  | 23 | exit 125 | 
|  | 24 | fi | 
|  | 25 |  | 
| Manuel Pégourié-Gonnard | a1a9f9a | 2014-03-25 18:04:59 +0100 | [diff] [blame] | 26 | # initialise counters | 
| Manuel Pégourié-Gonnard | 72e51ee | 2014-08-31 10:22:11 +0200 | [diff] [blame] | 27 | TESTS=0 | 
|  | 28 | FAILED=0 | 
|  | 29 | SKIPPED=0 | 
|  | 30 | SRVMEM=0 | 
| Manuel Pégourié-Gonnard | 70064fd | 2013-08-27 22:00:47 +0200 | [diff] [blame] | 31 |  | 
| Antonin Décimo | 36e89b5 | 2019-01-23 15:24:37 +0100 | [diff] [blame] | 32 | # default commands, can be overridden by the environment | 
| Simon Butcher | ac22d11 | 2016-09-04 22:31:09 +0100 | [diff] [blame] | 33 | : ${M_SRV:=../programs/ssl/ssl_server2} | 
|  | 34 | : ${M_CLI:=../programs/ssl/ssl_client2} | 
| Manuel Pégourié-Gonnard | 6e666c2 | 2023-01-10 09:38:58 +0100 | [diff] [blame] | 35 | : ${OPENSSL:=openssl} | 
| Manuel Pégourié-Gonnard | 74faf3c | 2014-03-13 18:47:44 +0100 | [diff] [blame] | 36 | : ${GNUTLS_CLI:=gnutls-cli} | 
|  | 37 | : ${GNUTLS_SERV:=gnutls-serv} | 
| Manuel Pégourié-Gonnard | f7a2690 | 2014-02-27 12:25:54 +0100 | [diff] [blame] | 38 |  | 
| Manuel Pégourié-Gonnard | c572246 | 2022-12-19 11:42:12 +0100 | [diff] [blame] | 39 | # The OPENSSL variable used to be OPENSSL_CMD for historical reasons. | 
|  | 40 | # To help the migration, error out if the old variable is set, | 
|  | 41 | # but only if it has a different value than the new one. | 
|  | 42 | if [ "${OPENSSL_CMD+set}" = set ]; then | 
|  | 43 | # the variable is set, we can now check its value | 
|  | 44 | if [ "$OPENSSL_CMD" != "$OPENSSL" ]; then | 
|  | 45 | echo "Please use OPENSSL instead of OPENSSL_CMD." >&2 | 
|  | 46 | exit 125 | 
|  | 47 | fi | 
|  | 48 | fi | 
|  | 49 |  | 
| Manuel Pégourié-Gonnard | 1287f11 | 2014-08-31 16:20:58 +0200 | [diff] [blame] | 50 | # do we have a recent enough GnuTLS? | 
| Manuel Pégourié-Gonnard | 03db6b0 | 2015-06-26 15:45:30 +0200 | [diff] [blame] | 51 | if ( which $GNUTLS_CLI && which $GNUTLS_SERV ) >/dev/null 2>&1; then | 
| Manuel Pégourié-Gonnard | dd45927 | 2014-10-24 12:57:37 +0200 | [diff] [blame] | 52 | G_VER="$( $GNUTLS_CLI --version | head -n1 )" | 
|  | 53 | if echo "$G_VER" | grep '@VERSION@' > /dev/null; then # git version | 
| Manuel Pégourié-Gonnard | 1287f11 | 2014-08-31 16:20:58 +0200 | [diff] [blame] | 54 | PEER_GNUTLS=" GnuTLS" | 
| Manuel Pégourié-Gonnard | dd45927 | 2014-10-24 12:57:37 +0200 | [diff] [blame] | 55 | else | 
|  | 56 | eval $( echo $G_VER | sed 's/.* \([0-9]*\)\.\([0-9]\)*\.\([0-9]*\)$/MAJOR="\1" MINOR="\2" PATCH="\3"/' ) | 
|  | 57 | if [ $MAJOR -lt 3 -o \ | 
|  | 58 | \( $MAJOR -eq 3 -a $MINOR -lt 2 \) -o \ | 
|  | 59 | \( $MAJOR -eq 3 -a $MINOR -eq 2 -a $PATCH -lt 15 \) ] | 
|  | 60 | then | 
|  | 61 | PEER_GNUTLS="" | 
|  | 62 | else | 
|  | 63 | PEER_GNUTLS=" GnuTLS" | 
| Manuel Pégourié-Gonnard | c36b432 | 2018-06-14 13:14:29 +0200 | [diff] [blame] | 64 | if [ $MINOR -lt 4 ]; then | 
|  | 65 | GNUTLS_MINOR_LT_FOUR='x' | 
|  | 66 | fi | 
| Manuel Pégourié-Gonnard | dd45927 | 2014-10-24 12:57:37 +0200 | [diff] [blame] | 67 | fi | 
| Manuel Pégourié-Gonnard | 1287f11 | 2014-08-31 16:20:58 +0200 | [diff] [blame] | 68 | fi | 
|  | 69 | else | 
|  | 70 | PEER_GNUTLS="" | 
|  | 71 | fi | 
|  | 72 |  | 
| Yanray Wang | ad47063 | 2023-02-20 14:58:03 +0800 | [diff] [blame] | 73 | guess_config_name() { | 
|  | 74 | if git diff --quiet ../include/mbedtls/mbedtls_config.h 2>/dev/null; then | 
|  | 75 | echo "default" | 
|  | 76 | else | 
|  | 77 | echo "unknown" | 
|  | 78 | fi | 
|  | 79 | } | 
|  | 80 | : ${MBEDTLS_TEST_OUTCOME_FILE=} | 
|  | 81 | : ${MBEDTLS_TEST_CONFIGURATION:="$(guess_config_name)"} | 
|  | 82 | : ${MBEDTLS_TEST_PLATFORM:="$(uname -s | tr -c \\n0-9A-Za-z _)-$(uname -m | tr -c \\n0-9A-Za-z _)"} | 
|  | 83 |  | 
| Manuel Pégourié-Gonnard | a1a9f9a | 2014-03-25 18:04:59 +0100 | [diff] [blame] | 84 | # default values for options | 
| Manuel Pégourié-Gonnard | 636b5f1 | 2022-04-14 09:21:56 +0200 | [diff] [blame] | 85 | # /!\ keep this synchronised with: | 
|  | 86 | # - basic-build-test.sh | 
|  | 87 | # - all.sh (multiple components) | 
| Xiaofei Bai | 8b5c382 | 2021-12-02 08:43:35 +0000 | [diff] [blame] | 88 | MODES="tls12 dtls12" | 
| Paul Bakker | 1eeceae | 2012-11-23 14:25:34 +0100 | [diff] [blame] | 89 | VERIFIES="NO YES" | 
| Manuel Pégourié-Gonnard | 7ebaf37 | 2013-08-27 21:03:33 +0200 | [diff] [blame] | 90 | TYPES="ECDSA RSA PSK" | 
| Paul Bakker | accd4eb | 2013-07-19 13:41:51 +0200 | [diff] [blame] | 91 | FILTER="" | 
| Manuel Pégourié-Gonnard | 636b5f1 | 2022-04-14 09:21:56 +0200 | [diff] [blame] | 92 | # By default, exclude: | 
|  | 93 | # - NULL: excluded from our default config + requires OpenSSL legacy | 
| Manuel Pégourié-Gonnard | 4111b73 | 2022-04-06 13:21:59 +0200 | [diff] [blame] | 94 | # - ARIA: requires OpenSSL >= 1.1.1 | 
| Manuel Pégourié-Gonnard | 9fece7e | 2018-06-18 11:38:22 +0200 | [diff] [blame] | 95 | # - ChachaPoly: requires OpenSSL >= 1.1.0 | 
| Yanray Wang | 20fa2ae | 2023-01-13 18:00:10 +0800 | [diff] [blame] | 96 | EXCLUDE='NULL\|ARIA\|CHACHA20_POLY1305' | 
| Paul Bakker | accd4eb | 2013-07-19 13:41:51 +0200 | [diff] [blame] | 97 | VERBOSE="" | 
| Manuel Pégourié-Gonnard | 3eec604 | 2014-02-27 15:37:24 +0100 | [diff] [blame] | 98 | MEMCHECK=0 | 
| Gilles Peskine | 39c5207 | 2024-05-17 11:55:15 +0200 | [diff] [blame] | 99 | MIN_TESTS=1 | 
| Gilles Peskine | 1783870 | 2023-08-28 17:36:22 +0200 | [diff] [blame] | 100 | PRESERVE_LOGS=0 | 
| Manuel Pégourié-Gonnard | e4f6edc | 2015-01-22 16:43:54 +0000 | [diff] [blame] | 101 | PEERS="OpenSSL$PEER_GNUTLS mbedTLS" | 
| Paul Bakker | accd4eb | 2013-07-19 13:41:51 +0200 | [diff] [blame] | 102 |  | 
| Manuel Pégourié-Gonnard | 39e2ca9 | 2015-08-04 16:43:37 +0200 | [diff] [blame] | 103 | # hidden option: skip DTLS with OpenSSL | 
|  | 104 | # (travis CI has a version that doesn't work for us) | 
|  | 105 | : ${OSSL_NO_DTLS:=0} | 
|  | 106 |  | 
| Manuel Pégourié-Gonnard | 9dea8bd | 2014-02-26 18:21:02 +0100 | [diff] [blame] | 107 | print_usage() { | 
|  | 108 | echo "Usage: $0" | 
| Manuel Pégourié-Gonnard | f46f128 | 2014-12-11 11:51:28 +0100 | [diff] [blame] | 109 | printf "  -h|--help\tPrint this help.\n" | 
| Gilles Peskine | 231befa | 2020-08-26 20:05:11 +0200 | [diff] [blame] | 110 | printf "  -f|--filter\tOnly matching ciphersuites are tested (Default: '%s')\n" "$FILTER" | 
|  | 111 | printf "  -e|--exclude\tMatching ciphersuites are excluded (Default: '%s')\n" "$EXCLUDE" | 
|  | 112 | printf "  -m|--modes\tWhich modes to perform (Default: '%s')\n" "$MODES" | 
|  | 113 | printf "  -t|--types\tWhich key exchange type to perform (Default: '%s')\n" "$TYPES" | 
|  | 114 | printf "  -V|--verify\tWhich verification modes to perform (Default: '%s')\n" "$VERIFIES" | 
|  | 115 | printf "  -p|--peers\tWhich peers to use (Default: '%s')\n" "$PEERS" | 
| Manuel Pégourié-Gonnard | f46f128 | 2014-12-11 11:51:28 +0100 | [diff] [blame] | 116 | printf "            \tAlso available: GnuTLS (needs v3.2.15 or higher)\n" | 
|  | 117 | printf "  -M|--memcheck\tCheck memory leaks and errors.\n" | 
|  | 118 | printf "  -v|--verbose\tSet verbose output.\n" | 
| Tomás González | 12787c9 | 2023-09-04 10:26:00 +0100 | [diff] [blame] | 119 | printf "     --list-test-cases\tList all potential test cases (No Execution)\n" | 
| Gilles Peskine | 39c5207 | 2024-05-17 11:55:15 +0200 | [diff] [blame] | 120 | printf "     --min      \tMinimum number of non-skipped tests (default 1)\n" | 
| Yanray Wang | ad47063 | 2023-02-20 14:58:03 +0800 | [diff] [blame] | 121 | printf "     --outcome-file\tFile where test outcomes are written\n" | 
|  | 122 | printf "                   \t(default: \$MBEDTLS_TEST_OUTCOME_FILE, none if empty)\n" | 
| Gilles Peskine | 1783870 | 2023-08-28 17:36:22 +0200 | [diff] [blame] | 123 | printf "     --preserve-logs\tPreserve logs of successful tests as well\n" | 
| Yanray Wang | d893837 | 2023-02-23 10:04:58 +0800 | [diff] [blame] | 124 | } | 
|  | 125 |  | 
| Yanray Wang | fb784b2 | 2023-03-02 11:55:55 +0800 | [diff] [blame] | 126 | # print_test_case <CLIENT> <SERVER> <STANDARD_CIPHER_SUITE> | 
|  | 127 | print_test_case() { | 
|  | 128 | for i in $3; do | 
|  | 129 | uniform_title $1 $2 $i | 
| Pengyu Lv | 3c170d3 | 2023-11-29 13:53:34 +0800 | [diff] [blame] | 130 | echo "compat;$TITLE" | 
| Yanray Wang | fb784b2 | 2023-03-02 11:55:55 +0800 | [diff] [blame] | 131 | done | 
|  | 132 | } | 
|  | 133 |  | 
| Tomás González | 4fc5824 | 2023-09-20 22:14:06 +0100 | [diff] [blame] | 134 | # list_test_cases lists all potential test cases in compat.sh without execution | 
|  | 135 | list_test_cases() { | 
| Yanray Wang | d893837 | 2023-02-23 10:04:58 +0800 | [diff] [blame] | 136 | for TYPE in $TYPES; do | 
| Pengyu Lv | d36bc98 | 2023-12-01 14:23:27 +0800 | [diff] [blame] | 137 | reset_ciphersuites | 
| Yanray Wang | d893837 | 2023-02-23 10:04:58 +0800 | [diff] [blame] | 138 | add_common_ciphersuites | 
|  | 139 | add_openssl_ciphersuites | 
|  | 140 | add_gnutls_ciphersuites | 
|  | 141 | add_mbedtls_ciphersuites | 
| Yanray Wang | d893837 | 2023-02-23 10:04:58 +0800 | [diff] [blame] | 142 |  | 
| Pengyu Lv | d36bc98 | 2023-12-01 14:23:27 +0800 | [diff] [blame] | 143 | # PSK cipher suites do not allow client certificate verification. | 
|  | 144 | SUB_VERIFIES=$VERIFIES | 
|  | 145 | if [ "$TYPE" = "PSK" ]; then | 
|  | 146 | SUB_VERIFIES="NO" | 
|  | 147 | fi | 
|  | 148 |  | 
|  | 149 | for VERIFY in $SUB_VERIFIES; do | 
|  | 150 | VERIF=$(echo $VERIFY | tr '[:upper:]' '[:lower:]') | 
|  | 151 | for MODE in $MODES; do | 
| Pengyu Lv | d36bc98 | 2023-12-01 14:23:27 +0800 | [diff] [blame] | 152 | print_test_case m O "$O_CIPHERS" | 
|  | 153 | print_test_case O m "$O_CIPHERS" | 
|  | 154 | print_test_case m G "$G_CIPHERS" | 
| Pengyu Lv | a8342a7 | 2023-12-01 14:25:40 +0800 | [diff] [blame] | 155 | print_test_case G m "$G_CIPHERS" | 
| Pengyu Lv | d36bc98 | 2023-12-01 14:23:27 +0800 | [diff] [blame] | 156 | print_test_case m m "$M_CIPHERS" | 
|  | 157 | done | 
| Yanray Wang | d893837 | 2023-02-23 10:04:58 +0800 | [diff] [blame] | 158 | done | 
|  | 159 | done | 
| Manuel Pégourié-Gonnard | 9dea8bd | 2014-02-26 18:21:02 +0100 | [diff] [blame] | 160 | } | 
|  | 161 |  | 
|  | 162 | get_options() { | 
|  | 163 | while [ $# -gt 0 ]; do | 
|  | 164 | case "$1" in | 
|  | 165 | -f|--filter) | 
|  | 166 | shift; FILTER=$1 | 
|  | 167 | ;; | 
| Manuel Pégourié-Gonnard | 9edba77 | 2014-03-13 17:45:35 +0100 | [diff] [blame] | 168 | -e|--exclude) | 
|  | 169 | shift; EXCLUDE=$1 | 
|  | 170 | ;; | 
| Manuel Pégourié-Gonnard | 9dea8bd | 2014-02-26 18:21:02 +0100 | [diff] [blame] | 171 | -m|--modes) | 
|  | 172 | shift; MODES=$1 | 
|  | 173 | ;; | 
|  | 174 | -t|--types) | 
|  | 175 | shift; TYPES=$1 | 
|  | 176 | ;; | 
|  | 177 | -V|--verify) | 
|  | 178 | shift; VERIFIES=$1 | 
|  | 179 | ;; | 
| Manuel Pégourié-Gonnard | 9edba77 | 2014-03-13 17:45:35 +0100 | [diff] [blame] | 180 | -p|--peers) | 
|  | 181 | shift; PEERS=$1 | 
|  | 182 | ;; | 
| Manuel Pégourié-Gonnard | 9dea8bd | 2014-02-26 18:21:02 +0100 | [diff] [blame] | 183 | -v|--verbose) | 
|  | 184 | VERBOSE=1 | 
|  | 185 | ;; | 
| Manuel Pégourié-Gonnard | 3eec604 | 2014-02-27 15:37:24 +0100 | [diff] [blame] | 186 | -M|--memcheck) | 
|  | 187 | MEMCHECK=1 | 
|  | 188 | ;; | 
| Yanray Wang | cdc0708 | 2023-03-03 17:12:29 +0800 | [diff] [blame] | 189 | # Please check scripts/check_test_cases.py correspondingly | 
| Tomás González | 4a86da2 | 2023-09-01 17:41:16 +0100 | [diff] [blame] | 190 | # if you have to modify option, --list-test-cases | 
|  | 191 | --list-test-cases) | 
| Tomás González | 4fc5824 | 2023-09-20 22:14:06 +0100 | [diff] [blame] | 192 | list_test_cases | 
| Yanray Wang | 14e052f | 2023-03-06 19:37:07 +0800 | [diff] [blame] | 193 | exit $? | 
| Yanray Wang | d893837 | 2023-02-23 10:04:58 +0800 | [diff] [blame] | 194 | ;; | 
| Gilles Peskine | 39c5207 | 2024-05-17 11:55:15 +0200 | [diff] [blame] | 195 | --min) | 
|  | 196 | shift; MIN_TESTS=$1 | 
|  | 197 | ;; | 
| Yanray Wang | ad47063 | 2023-02-20 14:58:03 +0800 | [diff] [blame] | 198 | --outcome-file) | 
|  | 199 | shift; MBEDTLS_TEST_OUTCOME_FILE=$1 | 
|  | 200 | ;; | 
| Gilles Peskine | 1783870 | 2023-08-28 17:36:22 +0200 | [diff] [blame] | 201 | --preserve-logs) | 
|  | 202 | PRESERVE_LOGS=1 | 
|  | 203 | ;; | 
| Manuel Pégourié-Gonnard | 9dea8bd | 2014-02-26 18:21:02 +0100 | [diff] [blame] | 204 | -h|--help) | 
|  | 205 | print_usage | 
|  | 206 | exit 0 | 
|  | 207 | ;; | 
|  | 208 | *) | 
|  | 209 | echo "Unknown argument: '$1'" | 
|  | 210 | print_usage | 
|  | 211 | exit 1 | 
|  | 212 | ;; | 
|  | 213 | esac | 
|  | 214 | shift | 
|  | 215 | done | 
| Manuel Pégourié-Gonnard | 85a4178 | 2014-10-24 12:47:26 +0200 | [diff] [blame] | 216 |  | 
|  | 217 | # sanitize some options (modes checked later) | 
|  | 218 | VERIFIES="$( echo $VERIFIES | tr [a-z] [A-Z] )" | 
|  | 219 | TYPES="$( echo $TYPES | tr [a-z] [A-Z] )" | 
| Manuel Pégourié-Gonnard | 9dea8bd | 2014-02-26 18:21:02 +0100 | [diff] [blame] | 220 | } | 
| Paul Bakker | accd4eb | 2013-07-19 13:41:51 +0200 | [diff] [blame] | 221 |  | 
| Manuel Pégourié-Gonnard | 9595771 | 2014-02-19 15:29:38 +0100 | [diff] [blame] | 222 | log() { | 
| Paul Bakker | accd4eb | 2013-07-19 13:41:51 +0200 | [diff] [blame] | 223 | if [ "X" != "X$VERBOSE" ]; then | 
| Manuel Pégourié-Gonnard | 3025b6c | 2014-03-26 15:30:16 +0100 | [diff] [blame] | 224 | echo "" | 
| Paul Bakker | accd4eb | 2013-07-19 13:41:51 +0200 | [diff] [blame] | 225 | echo "$@" | 
|  | 226 | fi | 
|  | 227 | } | 
| Paul Bakker | 10cd225 | 2012-04-12 21:26:34 +0000 | [diff] [blame] | 228 |  | 
| Manuel Pégourié-Gonnard | 3025b6c | 2014-03-26 15:30:16 +0100 | [diff] [blame] | 229 | # is_dtls <mode> | 
|  | 230 | is_dtls() | 
|  | 231 | { | 
| Xiaofei Bai | 8b5c382 | 2021-12-02 08:43:35 +0000 | [diff] [blame] | 232 | test "$1" = "dtls12" | 
| Manuel Pégourié-Gonnard | 3025b6c | 2014-03-26 15:30:16 +0100 | [diff] [blame] | 233 | } | 
|  | 234 |  | 
|  | 235 | # minor_ver <mode> | 
|  | 236 | minor_ver() | 
|  | 237 | { | 
|  | 238 | case "$1" in | 
| Xiaofei Bai | 8b5c382 | 2021-12-02 08:43:35 +0000 | [diff] [blame] | 239 | tls12|dtls12) | 
| Manuel Pégourié-Gonnard | 3025b6c | 2014-03-26 15:30:16 +0100 | [diff] [blame] | 240 | echo 3 | 
|  | 241 | ;; | 
|  | 242 | *) | 
|  | 243 | echo "error: invalid mode: $MODE" >&2 | 
|  | 244 | # exiting is no good here, typically called in a subshell | 
|  | 245 | echo -1 | 
|  | 246 | esac | 
|  | 247 | } | 
|  | 248 |  | 
| Manuel Pégourié-Gonnard | dfc8d5a | 2013-08-27 20:48:40 +0200 | [diff] [blame] | 249 | filter() | 
|  | 250 | { | 
| Manuel Pégourié-Gonnard | 9edba77 | 2014-03-13 17:45:35 +0100 | [diff] [blame] | 251 | LIST="$1" | 
| Manuel Pégourié-Gonnard | dfc8d5a | 2013-08-27 20:48:40 +0200 | [diff] [blame] | 252 | NEW_LIST="" | 
|  | 253 |  | 
| Mateusz Starzyk | 5224e29 | 2021-02-22 14:36:29 +0100 | [diff] [blame] | 254 | EXCLMODE="$EXCLUDE" | 
| Manuel Pégourié-Gonnard | 3025b6c | 2014-03-26 15:30:16 +0100 | [diff] [blame] | 255 |  | 
| Manuel Pégourié-Gonnard | dfc8d5a | 2013-08-27 20:48:40 +0200 | [diff] [blame] | 256 | for i in $LIST; | 
|  | 257 | do | 
| Manuel Pégourié-Gonnard | 3025b6c | 2014-03-26 15:30:16 +0100 | [diff] [blame] | 258 | NEW_LIST="$NEW_LIST $( echo "$i" | grep "$FILTER" | grep -v "$EXCLMODE" )" | 
| Manuel Pégourié-Gonnard | dfc8d5a | 2013-08-27 20:48:40 +0200 | [diff] [blame] | 259 | done | 
|  | 260 |  | 
| Manuel Pégourié-Gonnard | 911622d | 2014-02-27 11:50:40 +0100 | [diff] [blame] | 261 | # normalize whitespace | 
| Manuel Pégourié-Gonnard | f46f128 | 2014-12-11 11:51:28 +0100 | [diff] [blame] | 262 | echo "$NEW_LIST" | sed -e 's/[[:space:]][[:space:]]*/ /g' -e 's/^ //' -e 's/ $//' | 
| Manuel Pégourié-Gonnard | dfc8d5a | 2013-08-27 20:48:40 +0200 | [diff] [blame] | 263 | } | 
|  | 264 |  | 
| Manuel Pégourié-Gonnard | 5b2d776 | 2014-02-28 12:42:57 +0100 | [diff] [blame] | 265 | filter_ciphersuites() | 
|  | 266 | { | 
| Manuel Pégourié-Gonnard | 9edba77 | 2014-03-13 17:45:35 +0100 | [diff] [blame] | 267 | if [ "X" != "X$FILTER" -o "X" != "X$EXCLUDE" ]; | 
| Manuel Pégourié-Gonnard | 5b2d776 | 2014-02-28 12:42:57 +0100 | [diff] [blame] | 268 | then | 
| Gilles Peskine | e820c0a | 2023-08-03 17:45:20 +0200 | [diff] [blame] | 269 | # Ciphersuite for Mbed TLS | 
| Simon Butcher | ac22d11 | 2016-09-04 22:31:09 +0100 | [diff] [blame] | 270 | M_CIPHERS=$( filter "$M_CIPHERS" ) | 
|  | 271 |  | 
|  | 272 | # Ciphersuite for OpenSSL | 
| Manuel Pégourié-Gonnard | 9edba77 | 2014-03-13 17:45:35 +0100 | [diff] [blame] | 273 | O_CIPHERS=$( filter "$O_CIPHERS" ) | 
| Simon Butcher | ac22d11 | 2016-09-04 22:31:09 +0100 | [diff] [blame] | 274 |  | 
|  | 275 | # Ciphersuite for GnuTLS | 
| Manuel Pégourié-Gonnard | 9edba77 | 2014-03-13 17:45:35 +0100 | [diff] [blame] | 276 | G_CIPHERS=$( filter "$G_CIPHERS" ) | 
| Manuel Pégourié-Gonnard | 5b2d776 | 2014-02-28 12:42:57 +0100 | [diff] [blame] | 277 | fi | 
|  | 278 | } | 
|  | 279 |  | 
|  | 280 | reset_ciphersuites() | 
| Manuel Pégourié-Gonnard | 48f196c | 2014-02-19 13:51:58 +0100 | [diff] [blame] | 281 | { | 
| Simon Butcher | ac22d11 | 2016-09-04 22:31:09 +0100 | [diff] [blame] | 282 | M_CIPHERS="" | 
| Manuel Pégourié-Gonnard | 48f196c | 2014-02-19 13:51:58 +0100 | [diff] [blame] | 283 | O_CIPHERS="" | 
| Manuel Pégourié-Gonnard | 5b2d776 | 2014-02-28 12:42:57 +0100 | [diff] [blame] | 284 | G_CIPHERS="" | 
|  | 285 | } | 
| Manuel Pégourié-Gonnard | 48f196c | 2014-02-19 13:51:58 +0100 | [diff] [blame] | 286 |  | 
| Gilles Peskine | 47aab85 | 2023-01-26 21:16:34 +0100 | [diff] [blame] | 287 | # translate_ciphers {g|m|o} {STANDARD_CIPHER_SUITE_NAME...} | 
|  | 288 | # Set $ciphers to the cipher suite name translations for the specified | 
|  | 289 | # program (gnutls, mbedtls or openssl). $ciphers is a space-separated | 
|  | 290 | # list of entries of the form "STANDARD_NAME=PROGRAM_NAME". | 
|  | 291 | translate_ciphers() | 
| Joe Subbiani | c3610ba | 2021-07-29 11:35:59 +0100 | [diff] [blame] | 292 | { | 
| Elena Uziunaite | 9669eea | 2024-10-08 16:41:15 +0100 | [diff] [blame] | 293 | ciphers=$(../framework/scripts/translate_ciphers.py "$@") | 
| Gilles Peskine | 47aab85 | 2023-01-26 21:16:34 +0100 | [diff] [blame] | 294 | if [ $? -ne 0 ]; then | 
| Joe Subbiani | 439a696 | 2021-07-29 12:51:09 +0100 | [diff] [blame] | 295 | echo "translate_ciphers.py failed with exit code $1" >&2 | 
|  | 296 | echo "$2" >&2 | 
| Joe Subbiani | c3610ba | 2021-07-29 11:35:59 +0100 | [diff] [blame] | 297 | exit 1 | 
|  | 298 | fi | 
|  | 299 | } | 
|  | 300 |  | 
| Manuel Pégourié-Gonnard | 7299dfd | 2018-02-15 11:43:55 +0100 | [diff] [blame] | 301 | # Ciphersuites that can be used with all peers. | 
|  | 302 | # Since we currently have three possible peers, each ciphersuite should appear | 
|  | 303 | # three times: in each peer's list (with the name that this peer uses). | 
| Manuel Pégourié-Gonnard | 12b8472 | 2014-03-25 19:07:28 +0100 | [diff] [blame] | 304 | add_common_ciphersuites() | 
| Manuel Pégourié-Gonnard | 5b2d776 | 2014-02-28 12:42:57 +0100 | [diff] [blame] | 305 | { | 
| Joe Subbiani | 34d6262 | 2021-07-27 14:55:56 +0100 | [diff] [blame] | 306 | CIPHERS="" | 
| Manuel Pégourié-Gonnard | 48f196c | 2014-02-19 13:51:58 +0100 | [diff] [blame] | 307 | case $TYPE in | 
|  | 308 |  | 
|  | 309 | "ECDSA") | 
| Joe Subbiani | 9f84761 | 2021-08-10 10:41:13 +0100 | [diff] [blame] | 310 | CIPHERS="$CIPHERS                           \ | 
| Yanray Wang | d5f99e4 | 2023-01-11 10:11:23 +0800 | [diff] [blame] | 311 | TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA    \ | 
|  | 312 | TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 \ | 
|  | 313 | TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 \ | 
|  | 314 | TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA    \ | 
|  | 315 | TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 \ | 
|  | 316 | TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 \ | 
|  | 317 | TLS_ECDHE_ECDSA_WITH_NULL_SHA           \ | 
| Joe Subbiani | 9f84761 | 2021-08-10 10:41:13 +0100 | [diff] [blame] | 318 | " | 
| Manuel Pégourié-Gonnard | 48f196c | 2014-02-19 13:51:58 +0100 | [diff] [blame] | 319 | ;; | 
|  | 320 |  | 
|  | 321 | "RSA") | 
| Joe Subbiani | 34d6262 | 2021-07-27 14:55:56 +0100 | [diff] [blame] | 322 | CIPHERS="$CIPHERS                           \ | 
| Yanray Wang | d5f99e4 | 2023-01-11 10:11:23 +0800 | [diff] [blame] | 323 | TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA      \ | 
|  | 324 | TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256   \ | 
|  | 325 | TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256   \ | 
|  | 326 | TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA      \ | 
|  | 327 | TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384   \ | 
|  | 328 | TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384   \ | 
|  | 329 | TLS_ECDHE_RSA_WITH_NULL_SHA             \ | 
| Manuel Pégourié-Gonnard | 12b8472 | 2014-03-25 19:07:28 +0100 | [diff] [blame] | 330 | " | 
| Manuel Pégourié-Gonnard | 48f196c | 2014-02-19 13:51:58 +0100 | [diff] [blame] | 331 | ;; | 
|  | 332 |  | 
|  | 333 | "PSK") | 
| Joe Subbiani | 34d6262 | 2021-07-27 14:55:56 +0100 | [diff] [blame] | 334 | CIPHERS="$CIPHERS                           \ | 
| Yanray Wang | d5f99e4 | 2023-01-11 10:11:23 +0800 | [diff] [blame] | 335 | TLS_PSK_WITH_AES_128_CBC_SHA            \ | 
|  | 336 | TLS_PSK_WITH_AES_256_CBC_SHA            \ | 
| Manuel Pégourié-Gonnard | 48f196c | 2014-02-19 13:51:58 +0100 | [diff] [blame] | 337 | " | 
| Manuel Pégourié-Gonnard | 48f196c | 2014-02-19 13:51:58 +0100 | [diff] [blame] | 338 | ;; | 
|  | 339 | esac | 
| Joe Subbiani | 34d6262 | 2021-07-27 14:55:56 +0100 | [diff] [blame] | 340 |  | 
| Yanray Wang | 20fa2ae | 2023-01-13 18:00:10 +0800 | [diff] [blame] | 341 | O_CIPHERS="$O_CIPHERS $CIPHERS" | 
|  | 342 | G_CIPHERS="$G_CIPHERS $CIPHERS" | 
| Joe Subbiani | 34d6262 | 2021-07-27 14:55:56 +0100 | [diff] [blame] | 343 | M_CIPHERS="$M_CIPHERS $CIPHERS" | 
| Manuel Pégourié-Gonnard | 48f196c | 2014-02-19 13:51:58 +0100 | [diff] [blame] | 344 | } | 
|  | 345 |  | 
| Manuel Pégourié-Gonnard | 7299dfd | 2018-02-15 11:43:55 +0100 | [diff] [blame] | 346 | # Ciphersuites usable only with Mbed TLS and OpenSSL | 
| Yanray Wang | 20fa2ae | 2023-01-13 18:00:10 +0800 | [diff] [blame] | 347 | # A list of ciphersuites in the standard naming convention is appended | 
|  | 348 | # to the list of Mbed TLS ciphersuites $M_CIPHERS and | 
|  | 349 | # to the list of OpenSSL ciphersuites $O_CIPHERS respectively. | 
|  | 350 | # Based on client's naming convention, all ciphersuite names will be | 
|  | 351 | # translated into another naming format before sent to the client. | 
| Manuel Pégourié-Gonnard | 7299dfd | 2018-02-15 11:43:55 +0100 | [diff] [blame] | 352 | # | 
| Manuel Pégourié-Gonnard | 9fece7e | 2018-06-18 11:38:22 +0200 | [diff] [blame] | 353 | # ChachaPoly suites are here rather than in "common", as they were added in | 
|  | 354 | # GnuTLS in 3.5.0 and the CI only has 3.4.x so far. | 
| Manuel Pégourié-Gonnard | 12b8472 | 2014-03-25 19:07:28 +0100 | [diff] [blame] | 355 | add_openssl_ciphersuites() | 
|  | 356 | { | 
| Joe Subbiani | 34d6262 | 2021-07-27 14:55:56 +0100 | [diff] [blame] | 357 | CIPHERS="" | 
| Manuel Pégourié-Gonnard | 12b8472 | 2014-03-25 19:07:28 +0100 | [diff] [blame] | 358 | case $TYPE in | 
|  | 359 |  | 
|  | 360 | "ECDSA") | 
| Joe Subbiani | 32df145 | 2021-08-13 13:30:36 +0100 | [diff] [blame] | 361 | CIPHERS="$CIPHERS                                   \ | 
| Yanray Wang | d5f99e4 | 2023-01-11 10:11:23 +0800 | [diff] [blame] | 362 | TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA             \ | 
|  | 363 | TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256          \ | 
|  | 364 | TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256          \ | 
|  | 365 | TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA             \ | 
|  | 366 | TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384          \ | 
|  | 367 | TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384          \ | 
|  | 368 | TLS_ECDH_ECDSA_WITH_NULL_SHA                    \ | 
|  | 369 | TLS_ECDHE_ECDSA_WITH_ARIA_128_GCM_SHA256        \ | 
|  | 370 | TLS_ECDHE_ECDSA_WITH_ARIA_256_GCM_SHA384        \ | 
|  | 371 | TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256   \ | 
| Joe Subbiani | 9f84761 | 2021-08-10 10:41:13 +0100 | [diff] [blame] | 372 | " | 
| Manuel Pégourié-Gonnard | 12b8472 | 2014-03-25 19:07:28 +0100 | [diff] [blame] | 373 | ;; | 
|  | 374 |  | 
|  | 375 | "RSA") | 
| Joe Subbiani | 32df145 | 2021-08-13 13:30:36 +0100 | [diff] [blame] | 376 | CIPHERS="$CIPHERS                                   \ | 
| Yanray Wang | d5f99e4 | 2023-01-11 10:11:23 +0800 | [diff] [blame] | 377 | TLS_ECDHE_RSA_WITH_ARIA_128_GCM_SHA256          \ | 
|  | 378 | TLS_ECDHE_RSA_WITH_ARIA_256_GCM_SHA384          \ | 
|  | 379 | TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256     \ | 
| Manuel Pégourié-Gonnard | 12b8472 | 2014-03-25 19:07:28 +0100 | [diff] [blame] | 380 | " | 
| Manuel Pégourié-Gonnard | 12b8472 | 2014-03-25 19:07:28 +0100 | [diff] [blame] | 381 | ;; | 
|  | 382 |  | 
|  | 383 | "PSK") | 
| Joe Subbiani | 9f84761 | 2021-08-10 10:41:13 +0100 | [diff] [blame] | 384 | CIPHERS="$CIPHERS                                   \ | 
| Yanray Wang | d5f99e4 | 2023-01-11 10:11:23 +0800 | [diff] [blame] | 385 | TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256     \ | 
|  | 386 | TLS_PSK_WITH_ARIA_128_GCM_SHA256                \ | 
|  | 387 | TLS_PSK_WITH_ARIA_256_GCM_SHA384                \ | 
|  | 388 | TLS_PSK_WITH_CHACHA20_POLY1305_SHA256           \ | 
| Joe Subbiani | 9f84761 | 2021-08-10 10:41:13 +0100 | [diff] [blame] | 389 | " | 
| Manuel Pégourié-Gonnard | 12b8472 | 2014-03-25 19:07:28 +0100 | [diff] [blame] | 390 | ;; | 
|  | 391 | esac | 
| Joe Subbiani | 34d6262 | 2021-07-27 14:55:56 +0100 | [diff] [blame] | 392 |  | 
| Yanray Wang | 20fa2ae | 2023-01-13 18:00:10 +0800 | [diff] [blame] | 393 | O_CIPHERS="$O_CIPHERS $CIPHERS" | 
| Joe Subbiani | 34d6262 | 2021-07-27 14:55:56 +0100 | [diff] [blame] | 394 | M_CIPHERS="$M_CIPHERS $CIPHERS" | 
| Manuel Pégourié-Gonnard | 12b8472 | 2014-03-25 19:07:28 +0100 | [diff] [blame] | 395 | } | 
|  | 396 |  | 
| Manuel Pégourié-Gonnard | 7299dfd | 2018-02-15 11:43:55 +0100 | [diff] [blame] | 397 | # Ciphersuites usable only with Mbed TLS and GnuTLS | 
| Yanray Wang | 20fa2ae | 2023-01-13 18:00:10 +0800 | [diff] [blame] | 398 | # A list of ciphersuites in the standard naming convention is appended | 
|  | 399 | # to the list of Mbed TLS ciphersuites $M_CIPHERS and | 
|  | 400 | # to the list of GnuTLS ciphersuites $G_CIPHERS respectively. | 
|  | 401 | # Based on client's naming convention, all ciphersuite names will be | 
|  | 402 | # translated into another naming format before sent to the client. | 
| Manuel Pégourié-Gonnard | 5b2d776 | 2014-02-28 12:42:57 +0100 | [diff] [blame] | 403 | add_gnutls_ciphersuites() | 
| Manuel Pégourié-Gonnard | 48f196c | 2014-02-19 13:51:58 +0100 | [diff] [blame] | 404 | { | 
| Joe Subbiani | 34d6262 | 2021-07-27 14:55:56 +0100 | [diff] [blame] | 405 | CIPHERS="" | 
| Manuel Pégourié-Gonnard | 48f196c | 2014-02-19 13:51:58 +0100 | [diff] [blame] | 406 | case $TYPE in | 
|  | 407 |  | 
|  | 408 | "ECDSA") | 
| Joe Subbiani | 9f84761 | 2021-08-10 10:41:13 +0100 | [diff] [blame] | 409 | CIPHERS="$CIPHERS                                       \ | 
| Yanray Wang | d5f99e4 | 2023-01-11 10:11:23 +0800 | [diff] [blame] | 410 | TLS_ECDHE_ECDSA_WITH_AES_128_CCM                    \ | 
|  | 411 | TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8                  \ | 
|  | 412 | TLS_ECDHE_ECDSA_WITH_AES_256_CCM                    \ | 
|  | 413 | TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8                  \ | 
|  | 414 | TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256        \ | 
|  | 415 | TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_GCM_SHA256        \ | 
|  | 416 | TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384        \ | 
|  | 417 | TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_GCM_SHA384        \ | 
| Joe Subbiani | 9f84761 | 2021-08-10 10:41:13 +0100 | [diff] [blame] | 418 | " | 
| Manuel Pégourié-Gonnard | 48f196c | 2014-02-19 13:51:58 +0100 | [diff] [blame] | 419 | ;; | 
|  | 420 |  | 
|  | 421 | "RSA") | 
| Joe Subbiani | 9f84761 | 2021-08-10 10:41:13 +0100 | [diff] [blame] | 422 | CIPHERS="$CIPHERS                               \ | 
| Yanray Wang | d5f99e4 | 2023-01-11 10:11:23 +0800 | [diff] [blame] | 423 | TLS_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256  \ | 
|  | 424 | TLS_ECDHE_RSA_WITH_CAMELLIA_128_GCM_SHA256  \ | 
|  | 425 | TLS_ECDHE_RSA_WITH_CAMELLIA_256_CBC_SHA384  \ | 
|  | 426 | TLS_ECDHE_RSA_WITH_CAMELLIA_256_GCM_SHA384  \ | 
| Joe Subbiani | 9f84761 | 2021-08-10 10:41:13 +0100 | [diff] [blame] | 427 | " | 
| Manuel Pégourié-Gonnard | 48f196c | 2014-02-19 13:51:58 +0100 | [diff] [blame] | 428 | ;; | 
|  | 429 |  | 
|  | 430 | "PSK") | 
| Joe Subbiani | 9f84761 | 2021-08-10 10:41:13 +0100 | [diff] [blame] | 431 | CIPHERS="$CIPHERS                               \ | 
| Yanray Wang | d5f99e4 | 2023-01-11 10:11:23 +0800 | [diff] [blame] | 432 | TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA          \ | 
|  | 433 | TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256       \ | 
|  | 434 | TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA          \ | 
|  | 435 | TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384       \ | 
|  | 436 | TLS_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256  \ | 
|  | 437 | TLS_ECDHE_PSK_WITH_CAMELLIA_256_CBC_SHA384  \ | 
|  | 438 | TLS_ECDHE_PSK_WITH_NULL_SHA256              \ | 
|  | 439 | TLS_ECDHE_PSK_WITH_NULL_SHA384              \ | 
|  | 440 | TLS_PSK_WITH_AES_128_CBC_SHA256             \ | 
|  | 441 | TLS_PSK_WITH_AES_128_CCM                    \ | 
|  | 442 | TLS_PSK_WITH_AES_128_CCM_8                  \ | 
|  | 443 | TLS_PSK_WITH_AES_128_GCM_SHA256             \ | 
|  | 444 | TLS_PSK_WITH_AES_256_CBC_SHA384             \ | 
|  | 445 | TLS_PSK_WITH_AES_256_CCM                    \ | 
|  | 446 | TLS_PSK_WITH_AES_256_CCM_8                  \ | 
|  | 447 | TLS_PSK_WITH_AES_256_GCM_SHA384             \ | 
|  | 448 | TLS_PSK_WITH_CAMELLIA_128_CBC_SHA256        \ | 
|  | 449 | TLS_PSK_WITH_CAMELLIA_128_GCM_SHA256        \ | 
|  | 450 | TLS_PSK_WITH_CAMELLIA_256_CBC_SHA384        \ | 
|  | 451 | TLS_PSK_WITH_CAMELLIA_256_GCM_SHA384        \ | 
|  | 452 | TLS_PSK_WITH_NULL_SHA256                    \ | 
|  | 453 | TLS_PSK_WITH_NULL_SHA384                    \ | 
| Manuel Pégourié-Gonnard | e46aa5e | 2014-07-13 15:44:19 +0200 | [diff] [blame] | 454 | " | 
| Manuel Pégourié-Gonnard | 48f196c | 2014-02-19 13:51:58 +0100 | [diff] [blame] | 455 | ;; | 
|  | 456 | esac | 
| Joe Subbiani | 43592bd | 2021-07-27 16:32:21 +0100 | [diff] [blame] | 457 |  | 
| Yanray Wang | 20fa2ae | 2023-01-13 18:00:10 +0800 | [diff] [blame] | 458 | G_CIPHERS="$G_CIPHERS $CIPHERS" | 
| Joe Subbiani | 34d6262 | 2021-07-27 14:55:56 +0100 | [diff] [blame] | 459 | M_CIPHERS="$M_CIPHERS $CIPHERS" | 
| Manuel Pégourié-Gonnard | 5b2d776 | 2014-02-28 12:42:57 +0100 | [diff] [blame] | 460 | } | 
| Manuel Pégourié-Gonnard | 48f196c | 2014-02-19 13:51:58 +0100 | [diff] [blame] | 461 |  | 
| Manuel Pégourié-Gonnard | 7299dfd | 2018-02-15 11:43:55 +0100 | [diff] [blame] | 462 | # Ciphersuites usable only with Mbed TLS (not currently supported by another | 
| Yanray Wang | 20fa2ae | 2023-01-13 18:00:10 +0800 | [diff] [blame] | 463 | # peer usable in this script). This provides only very rudimentaty testing, as | 
| Manuel Pégourié-Gonnard | 7299dfd | 2018-02-15 11:43:55 +0100 | [diff] [blame] | 464 | # this is not interop testing, but it's better than nothing. | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 465 | add_mbedtls_ciphersuites() | 
| Manuel Pégourié-Gonnard | 5b2d776 | 2014-02-28 12:42:57 +0100 | [diff] [blame] | 466 | { | 
|  | 467 | case $TYPE in | 
|  | 468 |  | 
|  | 469 | "ECDSA") | 
| Joe Subbiani | 9f84761 | 2021-08-10 10:41:13 +0100 | [diff] [blame] | 470 | M_CIPHERS="$M_CIPHERS                               \ | 
| Yanray Wang | d5f99e4 | 2023-01-11 10:11:23 +0800 | [diff] [blame] | 471 | TLS_ECDH_ECDSA_WITH_ARIA_128_CBC_SHA256         \ | 
|  | 472 | TLS_ECDH_ECDSA_WITH_ARIA_128_GCM_SHA256         \ | 
|  | 473 | TLS_ECDH_ECDSA_WITH_ARIA_256_CBC_SHA384         \ | 
|  | 474 | TLS_ECDH_ECDSA_WITH_ARIA_256_GCM_SHA384         \ | 
|  | 475 | TLS_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256     \ | 
|  | 476 | TLS_ECDH_ECDSA_WITH_CAMELLIA_128_GCM_SHA256     \ | 
|  | 477 | TLS_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384     \ | 
|  | 478 | TLS_ECDH_ECDSA_WITH_CAMELLIA_256_GCM_SHA384     \ | 
|  | 479 | TLS_ECDHE_ECDSA_WITH_ARIA_128_CBC_SHA256        \ | 
|  | 480 | TLS_ECDHE_ECDSA_WITH_ARIA_256_CBC_SHA384        \ | 
| Joe Subbiani | 9f84761 | 2021-08-10 10:41:13 +0100 | [diff] [blame] | 481 | " | 
| Manuel Pégourié-Gonnard | 5b2d776 | 2014-02-28 12:42:57 +0100 | [diff] [blame] | 482 | ;; | 
|  | 483 |  | 
|  | 484 | "RSA") | 
| Joe Subbiani | 9f84761 | 2021-08-10 10:41:13 +0100 | [diff] [blame] | 485 | M_CIPHERS="$M_CIPHERS                               \ | 
| Yanray Wang | d5f99e4 | 2023-01-11 10:11:23 +0800 | [diff] [blame] | 486 | TLS_ECDHE_RSA_WITH_ARIA_128_CBC_SHA256          \ | 
|  | 487 | TLS_ECDHE_RSA_WITH_ARIA_256_CBC_SHA384          \ | 
| Joe Subbiani | 9f84761 | 2021-08-10 10:41:13 +0100 | [diff] [blame] | 488 | " | 
| Manuel Pégourié-Gonnard | 5b2d776 | 2014-02-28 12:42:57 +0100 | [diff] [blame] | 489 | ;; | 
|  | 490 |  | 
|  | 491 | "PSK") | 
| Yanray Wang | d5f99e4 | 2023-01-11 10:11:23 +0800 | [diff] [blame] | 492 | # *PSK_NULL_SHA suites supported by GnuTLS 3.3.5 but not 3.2.15 | 
| Joe Subbiani | 9f84761 | 2021-08-10 10:41:13 +0100 | [diff] [blame] | 493 | M_CIPHERS="$M_CIPHERS                               \ | 
| Yanray Wang | d5f99e4 | 2023-01-11 10:11:23 +0800 | [diff] [blame] | 494 | TLS_ECDHE_PSK_WITH_ARIA_128_CBC_SHA256          \ | 
|  | 495 | TLS_ECDHE_PSK_WITH_ARIA_256_CBC_SHA384          \ | 
|  | 496 | TLS_ECDHE_PSK_WITH_NULL_SHA                     \ | 
|  | 497 | TLS_PSK_WITH_ARIA_128_CBC_SHA256                \ | 
|  | 498 | TLS_PSK_WITH_ARIA_256_CBC_SHA384                \ | 
|  | 499 | TLS_PSK_WITH_NULL_SHA                           \ | 
| Manuel Pégourié-Gonnard | 5b2d776 | 2014-02-28 12:42:57 +0100 | [diff] [blame] | 500 | " | 
| Manuel Pégourié-Gonnard | 5b2d776 | 2014-02-28 12:42:57 +0100 | [diff] [blame] | 501 | ;; | 
|  | 502 | esac | 
| Manuel Pégourié-Gonnard | 48f196c | 2014-02-19 13:51:58 +0100 | [diff] [blame] | 503 | } | 
|  | 504 |  | 
| Pengyu Lv | 1c0e4c0 | 2023-02-20 18:05:21 +0800 | [diff] [blame] | 505 | # o_check_ciphersuite STANDARD_CIPHER_SUITE | 
|  | 506 | o_check_ciphersuite() | 
|  | 507 | { | 
| Manuel Pégourié-Gonnard | 0dd6ca41 | 2024-04-10 12:26:24 +0200 | [diff] [blame] | 508 | # skip DTLS when lack of support was declared | 
|  | 509 | if test "$OSSL_NO_DTLS" -gt 0 && is_dtls "$MODE"; then | 
|  | 510 | SKIP_NEXT_="YES" | 
|  | 511 | fi | 
|  | 512 |  | 
| Manuel Pégourié-Gonnard | cb42409 | 2024-04-10 22:11:20 +0200 | [diff] [blame] | 513 | # skip DTLS 1.2 is support was not detected | 
|  | 514 | if [ "$O_SUPPORT_DTLS12" = "NO" -a "$MODE" = "dtls12" ]; then | 
|  | 515 | SKIP_NEXT="YES" | 
| Manuel Pégourié-Gonnard | 0dd6ca41 | 2024-04-10 12:26:24 +0200 | [diff] [blame] | 516 | fi | 
|  | 517 |  | 
|  | 518 | # skip static ECDH when OpenSSL doesn't support it | 
|  | 519 | if [ "${O_SUPPORT_STATIC_ECDH}" = "NO" ]; then | 
| Pengyu Lv | a64c277 | 2023-02-22 09:30:20 +0800 | [diff] [blame] | 520 | case "$1" in | 
|  | 521 | *ECDH_*) SKIP_NEXT="YES" | 
|  | 522 | esac | 
| Pengyu Lv | 1c0e4c0 | 2023-02-20 18:05:21 +0800 | [diff] [blame] | 523 | fi | 
|  | 524 | } | 
|  | 525 |  | 
| Manuel Pégourié-Gonnard | d941a79 | 2014-02-19 13:35:52 +0100 | [diff] [blame] | 526 | setup_arguments() | 
|  | 527 | { | 
| David Horstmann | d178031 | 2024-07-01 16:52:57 +0100 | [diff] [blame] | 528 | DATA_FILES_PATH="../framework/data_files" | 
|  | 529 |  | 
| Ronald Cron | 2c74ff6 | 2022-03-11 17:15:23 +0100 | [diff] [blame] | 530 | O_MODE="" | 
| Manuel Pégourié-Gonnard | 3025b6c | 2014-03-26 15:30:16 +0100 | [diff] [blame] | 531 | G_MODE="" | 
|  | 532 | case "$MODE" in | 
| Xiaofei Bai | 8b5c382 | 2021-12-02 08:43:35 +0000 | [diff] [blame] | 533 | "tls12") | 
| Ronald Cron | 2c74ff6 | 2022-03-11 17:15:23 +0100 | [diff] [blame] | 534 | O_MODE="tls1_2" | 
| Manuel Pégourié-Gonnard | 5b2d776 | 2014-02-28 12:42:57 +0100 | [diff] [blame] | 535 | G_PRIO_MODE="+VERS-TLS1.2" | 
| Manuel Pégourié-Gonnard | 9ada01a | 2014-02-19 14:24:24 +0100 | [diff] [blame] | 536 | ;; | 
| Xiaofei Bai | 8b5c382 | 2021-12-02 08:43:35 +0000 | [diff] [blame] | 537 | "dtls12") | 
| Ronald Cron | 2c74ff6 | 2022-03-11 17:15:23 +0100 | [diff] [blame] | 538 | O_MODE="dtls1_2" | 
| Manuel Pégourié-Gonnard | 3025b6c | 2014-03-26 15:30:16 +0100 | [diff] [blame] | 539 | G_PRIO_MODE="+VERS-DTLS1.2" | 
| Manuel Pégourié-Gonnard | 3679519 | 2014-09-26 16:33:45 +0200 | [diff] [blame] | 540 | G_MODE="-u" | 
| Manuel Pégourié-Gonnard | 3025b6c | 2014-03-26 15:30:16 +0100 | [diff] [blame] | 541 | ;; | 
| Manuel Pégourié-Gonnard | 9ada01a | 2014-02-19 14:24:24 +0100 | [diff] [blame] | 542 | *) | 
|  | 543 | echo "error: invalid mode: $MODE" >&2 | 
|  | 544 | exit 1; | 
|  | 545 | esac | 
|  | 546 |  | 
| Manuel Pégourié-Gonnard | c36b432 | 2018-06-14 13:14:29 +0200 | [diff] [blame] | 547 | # GnuTLS < 3.4 will choke if we try to allow CCM-8 | 
|  | 548 | if [ -z "${GNUTLS_MINOR_LT_FOUR-}" ]; then | 
|  | 549 | G_PRIO_CCM="+AES-256-CCM-8:+AES-128-CCM-8:" | 
|  | 550 | else | 
|  | 551 | G_PRIO_CCM="" | 
|  | 552 | fi | 
|  | 553 |  | 
| Mateusz Starzyk | 5224e29 | 2021-02-22 14:36:29 +0100 | [diff] [blame] | 554 | M_SERVER_ARGS="server_port=$PORT server_addr=0.0.0.0 force_version=$MODE" | 
| Gilles Peskine | 5f5e388 | 2023-08-27 21:32:36 +0200 | [diff] [blame] | 555 | O_SERVER_ARGS="-accept $PORT -cipher ALL,COMPLEMENTOFALL -$O_MODE" | 
| Manuel Pégourié-Gonnard | 3025b6c | 2014-03-26 15:30:16 +0100 | [diff] [blame] | 556 | G_SERVER_ARGS="-p $PORT --http $G_MODE" | 
| Valerio Setti | 9a9c9a5 | 2025-01-14 17:04:09 +0100 | [diff] [blame] | 557 | G_SERVER_PRIO="NORMAL:${G_PRIO_CCM}+NULL:+MD5:+PSK:+ECDHE-PSK:+SHA256:+SHA384:-VERS-TLS-ALL:$G_PRIO_MODE" | 
| Manuel Pégourié-Gonnard | 5b2d776 | 2014-02-28 12:42:57 +0100 | [diff] [blame] | 558 |  | 
| Gilles Peskine | 96f5bae | 2021-04-01 14:00:11 +0200 | [diff] [blame] | 559 | # The default prime for `openssl s_server` depends on the version: | 
|  | 560 | # * OpenSSL <= 1.0.2a: 512-bit | 
|  | 561 | # * OpenSSL 1.0.2b to 1.1.1b: 1024-bit | 
|  | 562 | # * OpenSSL >= 1.1.1c: 2048-bit | 
|  | 563 | # Mbed TLS wants >=1024, so force that for older versions. Don't force | 
|  | 564 | # it for newer versions, which reject a 1024-bit prime. Indifferently | 
|  | 565 | # force it or not for intermediate versions. | 
| Manuel Pégourié-Gonnard | c572246 | 2022-12-19 11:42:12 +0100 | [diff] [blame] | 566 | case $($OPENSSL version) in | 
| Gilles Peskine | 96f5bae | 2021-04-01 14:00:11 +0200 | [diff] [blame] | 567 | "OpenSSL 1.0"*) | 
| David Horstmann | d178031 | 2024-07-01 16:52:57 +0100 | [diff] [blame] | 568 | O_SERVER_ARGS="$O_SERVER_ARGS -dhparam $DATA_FILES_PATH/dhparams.pem" | 
| Gilles Peskine | 96f5bae | 2021-04-01 14:00:11 +0200 | [diff] [blame] | 569 | ;; | 
|  | 570 | esac | 
|  | 571 |  | 
| Manuel Pégourié-Gonnard | d1af102 | 2014-07-11 17:01:06 +0200 | [diff] [blame] | 572 | # with OpenSSL 1.0.1h, -www, -WWW and -HTTP break DTLS handshakes | 
|  | 573 | if is_dtls "$MODE"; then | 
| Manuel Pégourié-Gonnard | 3679519 | 2014-09-26 16:33:45 +0200 | [diff] [blame] | 574 | O_SERVER_ARGS="$O_SERVER_ARGS" | 
| Manuel Pégourié-Gonnard | d1af102 | 2014-07-11 17:01:06 +0200 | [diff] [blame] | 575 | else | 
|  | 576 | O_SERVER_ARGS="$O_SERVER_ARGS -www" | 
|  | 577 | fi | 
|  | 578 |  | 
| Simon Butcher | ac22d11 | 2016-09-04 22:31:09 +0100 | [diff] [blame] | 579 | M_CLIENT_ARGS="server_port=$PORT server_addr=127.0.0.1 force_version=$MODE" | 
| Ronald Cron | 2c74ff6 | 2022-03-11 17:15:23 +0100 | [diff] [blame] | 580 | O_CLIENT_ARGS="-connect localhost:$PORT -$O_MODE" | 
| Manuel Pégourié-Gonnard | 3025b6c | 2014-03-26 15:30:16 +0100 | [diff] [blame] | 581 | G_CLIENT_ARGS="-p $PORT --debug 3 $G_MODE" | 
| Manuel Pégourié-Gonnard | 9ada01a | 2014-02-19 14:24:24 +0100 | [diff] [blame] | 582 |  | 
| Gilles Peskine | 4bdb9fb | 2022-11-24 22:21:15 +0100 | [diff] [blame] | 583 | # Newer versions of OpenSSL have a syntax to enable all "ciphers", even | 
|  | 584 | # low-security ones. This covers not just cipher suites but also protocol | 
|  | 585 | # versions. It is necessary, for example, to use (D)TLS 1.0/1.1 on | 
|  | 586 | # OpenSSL 1.1.1f from Ubuntu 20.04. The syntax was only introduced in | 
|  | 587 | # OpenSSL 1.1.0 (21e0c1d23afff48601eb93135defddae51f7e2e3) and I can't find | 
|  | 588 | # a way to discover it from -help, so check the openssl version. | 
| Manuel Pégourié-Gonnard | c572246 | 2022-12-19 11:42:12 +0100 | [diff] [blame] | 589 | case $($OPENSSL version) in | 
| Gilles Peskine | 4bdb9fb | 2022-11-24 22:21:15 +0100 | [diff] [blame] | 590 | "OpenSSL 0"*|"OpenSSL 1.0"*) :;; | 
|  | 591 | *) | 
|  | 592 | O_CLIENT_ARGS="$O_CLIENT_ARGS -cipher ALL@SECLEVEL=0" | 
|  | 593 | O_SERVER_ARGS="$O_SERVER_ARGS -cipher ALL@SECLEVEL=0" | 
|  | 594 | ;; | 
|  | 595 | esac | 
|  | 596 |  | 
| Pengyu Lv | 1c0e4c0 | 2023-02-20 18:05:21 +0800 | [diff] [blame] | 597 | case $($OPENSSL ciphers ALL) in | 
| Manuel Pégourié-Gonnard | 0dd6ca41 | 2024-04-10 12:26:24 +0200 | [diff] [blame] | 598 | *ECDH-ECDSA*|*ECDH-RSA*) O_SUPPORT_STATIC_ECDH="YES";; | 
|  | 599 | *) O_SUPPORT_STATIC_ECDH="NO";; | 
| Pengyu Lv | 1c0e4c0 | 2023-02-20 18:05:21 +0800 | [diff] [blame] | 600 | esac | 
|  | 601 |  | 
| Manuel Pégourié-Gonnard | cb42409 | 2024-04-10 22:11:20 +0200 | [diff] [blame] | 602 | # OpenSSL <1.0.2 doesn't support DTLS 1.2. Check if OpenSSL | 
|  | 603 | # supports -dtls1_2 from the s_server help. (The s_client | 
|  | 604 | # help isn't accurate as of 1.0.2g: it supports DTLS 1.2 | 
|  | 605 | # but doesn't list it. But the s_server help seems to be | 
|  | 606 | # accurate.) | 
|  | 607 | O_SUPPORT_DTLS12="NO" | 
|  | 608 | if $OPENSSL s_server -help 2>&1 | grep -q "^ *-dtls1_2 "; then | 
|  | 609 | O_SUPPORT_DTLS12="YES" | 
|  | 610 | fi | 
|  | 611 |  | 
| Yanray Wang | 3038297 | 2023-02-08 12:38:31 +0800 | [diff] [blame] | 612 | if [ "X$VERIFY" = "XYES" ]; | 
| Manuel Pégourié-Gonnard | d941a79 | 2014-02-19 13:35:52 +0100 | [diff] [blame] | 613 | then | 
| David Horstmann | d178031 | 2024-07-01 16:52:57 +0100 | [diff] [blame] | 614 | M_SERVER_ARGS="$M_SERVER_ARGS ca_file=$DATA_FILES_PATH/test-ca_cat12.crt auth_mode=required" | 
|  | 615 | O_SERVER_ARGS="$O_SERVER_ARGS -CAfile $DATA_FILES_PATH/test-ca_cat12.crt -Verify 10" | 
|  | 616 | G_SERVER_ARGS="$G_SERVER_ARGS --x509cafile $DATA_FILES_PATH/test-ca_cat12.crt --require-client-cert" | 
| Manuel Pégourié-Gonnard | 5b2d776 | 2014-02-28 12:42:57 +0100 | [diff] [blame] | 617 |  | 
| David Horstmann | d178031 | 2024-07-01 16:52:57 +0100 | [diff] [blame] | 618 | M_CLIENT_ARGS="$M_CLIENT_ARGS ca_file=$DATA_FILES_PATH/test-ca_cat12.crt auth_mode=required" | 
|  | 619 | O_CLIENT_ARGS="$O_CLIENT_ARGS -CAfile $DATA_FILES_PATH/test-ca_cat12.crt -verify 10" | 
|  | 620 | G_CLIENT_ARGS="$G_CLIENT_ARGS --x509cafile $DATA_FILES_PATH/test-ca_cat12.crt" | 
| Manuel Pégourié-Gonnard | da782c9 | 2014-02-21 10:10:20 +0100 | [diff] [blame] | 621 | else | 
| Manuel Pégourié-Gonnard | 5b2d776 | 2014-02-28 12:42:57 +0100 | [diff] [blame] | 622 | # don't request a client cert at all | 
| Simon Butcher | ac22d11 | 2016-09-04 22:31:09 +0100 | [diff] [blame] | 623 | M_SERVER_ARGS="$M_SERVER_ARGS ca_file=none auth_mode=none" | 
| Manuel Pégourié-Gonnard | 5b2d776 | 2014-02-28 12:42:57 +0100 | [diff] [blame] | 624 | G_SERVER_ARGS="$G_SERVER_ARGS --disable-client-cert" | 
|  | 625 |  | 
| Simon Butcher | ac22d11 | 2016-09-04 22:31:09 +0100 | [diff] [blame] | 626 | M_CLIENT_ARGS="$M_CLIENT_ARGS ca_file=none auth_mode=none" | 
| Manuel Pégourié-Gonnard | 5de31ec | 2014-03-19 17:34:52 +0100 | [diff] [blame] | 627 | O_CLIENT_ARGS="$O_CLIENT_ARGS" | 
|  | 628 | G_CLIENT_ARGS="$G_CLIENT_ARGS --insecure" | 
| Manuel Pégourié-Gonnard | d941a79 | 2014-02-19 13:35:52 +0100 | [diff] [blame] | 629 | fi | 
|  | 630 |  | 
|  | 631 | case $TYPE in | 
|  | 632 | "ECDSA") | 
| David Horstmann | d178031 | 2024-07-01 16:52:57 +0100 | [diff] [blame] | 633 | M_SERVER_ARGS="$M_SERVER_ARGS crt_file=$DATA_FILES_PATH/server5.crt key_file=$DATA_FILES_PATH/server5.key" | 
|  | 634 | O_SERVER_ARGS="$O_SERVER_ARGS -cert $DATA_FILES_PATH/server5.crt -key $DATA_FILES_PATH/server5.key" | 
|  | 635 | G_SERVER_ARGS="$G_SERVER_ARGS --x509certfile $DATA_FILES_PATH/server5.crt --x509keyfile $DATA_FILES_PATH/server5.key" | 
| Manuel Pégourié-Gonnard | 5b2d776 | 2014-02-28 12:42:57 +0100 | [diff] [blame] | 636 |  | 
| Manuel Pégourié-Gonnard | 1b149ef | 2014-02-27 14:38:29 +0100 | [diff] [blame] | 637 | if [ "X$VERIFY" = "XYES" ]; then | 
| David Horstmann | d178031 | 2024-07-01 16:52:57 +0100 | [diff] [blame] | 638 | M_CLIENT_ARGS="$M_CLIENT_ARGS crt_file=$DATA_FILES_PATH/server6.crt key_file=$DATA_FILES_PATH/server6.key" | 
|  | 639 | O_CLIENT_ARGS="$O_CLIENT_ARGS -cert $DATA_FILES_PATH/server6.crt -key $DATA_FILES_PATH/server6.key" | 
|  | 640 | G_CLIENT_ARGS="$G_CLIENT_ARGS --x509certfile $DATA_FILES_PATH/server6.crt --x509keyfile $DATA_FILES_PATH/server6.key" | 
| Manuel Pégourié-Gonnard | 1b149ef | 2014-02-27 14:38:29 +0100 | [diff] [blame] | 641 | else | 
| Simon Butcher | ac22d11 | 2016-09-04 22:31:09 +0100 | [diff] [blame] | 642 | M_CLIENT_ARGS="$M_CLIENT_ARGS crt_file=none key_file=none" | 
| Manuel Pégourié-Gonnard | 1b149ef | 2014-02-27 14:38:29 +0100 | [diff] [blame] | 643 | fi | 
| Manuel Pégourié-Gonnard | d941a79 | 2014-02-19 13:35:52 +0100 | [diff] [blame] | 644 | ;; | 
|  | 645 |  | 
|  | 646 | "RSA") | 
| David Horstmann | d178031 | 2024-07-01 16:52:57 +0100 | [diff] [blame] | 647 | M_SERVER_ARGS="$M_SERVER_ARGS crt_file=$DATA_FILES_PATH/server2-sha256.crt key_file=$DATA_FILES_PATH/server2.key" | 
|  | 648 | O_SERVER_ARGS="$O_SERVER_ARGS -cert $DATA_FILES_PATH/server2-sha256.crt -key $DATA_FILES_PATH/server2.key" | 
|  | 649 | G_SERVER_ARGS="$G_SERVER_ARGS --x509certfile $DATA_FILES_PATH/server2-sha256.crt --x509keyfile $DATA_FILES_PATH/server2.key" | 
| Manuel Pégourié-Gonnard | 5b2d776 | 2014-02-28 12:42:57 +0100 | [diff] [blame] | 650 |  | 
| Manuel Pégourié-Gonnard | 1b149ef | 2014-02-27 14:38:29 +0100 | [diff] [blame] | 651 | if [ "X$VERIFY" = "XYES" ]; then | 
| David Horstmann | d178031 | 2024-07-01 16:52:57 +0100 | [diff] [blame] | 652 | M_CLIENT_ARGS="$M_CLIENT_ARGS crt_file=$DATA_FILES_PATH/cert_sha256.crt key_file=$DATA_FILES_PATH/server1.key" | 
|  | 653 | O_CLIENT_ARGS="$O_CLIENT_ARGS -cert $DATA_FILES_PATH/cert_sha256.crt -key $DATA_FILES_PATH/server1.key" | 
|  | 654 | G_CLIENT_ARGS="$G_CLIENT_ARGS --x509certfile $DATA_FILES_PATH/cert_sha256.crt --x509keyfile $DATA_FILES_PATH/server1.key" | 
| Manuel Pégourié-Gonnard | 1b149ef | 2014-02-27 14:38:29 +0100 | [diff] [blame] | 655 | else | 
| Simon Butcher | ac22d11 | 2016-09-04 22:31:09 +0100 | [diff] [blame] | 656 | M_CLIENT_ARGS="$M_CLIENT_ARGS crt_file=none key_file=none" | 
| Manuel Pégourié-Gonnard | 1b149ef | 2014-02-27 14:38:29 +0100 | [diff] [blame] | 657 | fi | 
| Manuel Pégourié-Gonnard | d941a79 | 2014-02-19 13:35:52 +0100 | [diff] [blame] | 658 | ;; | 
|  | 659 |  | 
|  | 660 | "PSK") | 
| Gilles Peskine | fdf7db0 | 2024-09-20 18:25:09 +0200 | [diff] [blame] | 661 | M_SERVER_ARGS="$M_SERVER_ARGS psk=6162636465666768696a6b6c6d6e6f70 ca_file=none" | 
| Manuel Pégourié-Gonnard | 1b149ef | 2014-02-27 14:38:29 +0100 | [diff] [blame] | 662 | O_SERVER_ARGS="$O_SERVER_ARGS -psk 6162636465666768696a6b6c6d6e6f70 -nocert" | 
| Gilles Peskine | fdf7db0 | 2024-09-20 18:25:09 +0200 | [diff] [blame] | 663 | G_SERVER_ARGS="$G_SERVER_ARGS --pskpasswd $DATA_FILES_PATH/passwd.psk" | 
| Manuel Pégourié-Gonnard | 5b2d776 | 2014-02-28 12:42:57 +0100 | [diff] [blame] | 664 |  | 
| Simon Butcher | ac22d11 | 2016-09-04 22:31:09 +0100 | [diff] [blame] | 665 | M_CLIENT_ARGS="$M_CLIENT_ARGS psk=6162636465666768696a6b6c6d6e6f70 crt_file=none key_file=none" | 
| Manuel Pégourié-Gonnard | 9ada01a | 2014-02-19 14:24:24 +0100 | [diff] [blame] | 666 | O_CLIENT_ARGS="$O_CLIENT_ARGS -psk 6162636465666768696a6b6c6d6e6f70" | 
| Manuel Pégourié-Gonnard | a437144 | 2014-03-13 16:21:59 +0100 | [diff] [blame] | 667 | G_CLIENT_ARGS="$G_CLIENT_ARGS --pskusername Client_identity --pskkey=6162636465666768696a6b6c6d6e6f70" | 
| Manuel Pégourié-Gonnard | d941a79 | 2014-02-19 13:35:52 +0100 | [diff] [blame] | 668 | ;; | 
|  | 669 | esac | 
|  | 670 | } | 
|  | 671 |  | 
| Simon Butcher | ac22d11 | 2016-09-04 22:31:09 +0100 | [diff] [blame] | 672 | # is_mbedtls <cmd_line> | 
|  | 673 | is_mbedtls() { | 
| Gilles Peskine | b20028b | 2023-01-26 21:34:01 +0100 | [diff] [blame] | 674 | case $1 in | 
|  | 675 | *ssl_client2*) true;; | 
|  | 676 | *ssl_server2*) true;; | 
|  | 677 | *) false;; | 
|  | 678 | esac | 
| Manuel Pégourié-Gonnard | 3eec604 | 2014-02-27 15:37:24 +0100 | [diff] [blame] | 679 | } | 
|  | 680 |  | 
|  | 681 | # has_mem_err <log_file_name> | 
|  | 682 | has_mem_err() { | 
|  | 683 | if ( grep -F 'All heap blocks were freed -- no leaks are possible' "$1" && | 
|  | 684 | grep -F 'ERROR SUMMARY: 0 errors from 0 contexts' "$1" ) > /dev/null | 
|  | 685 | then | 
|  | 686 | return 1 # false: does not have errors | 
|  | 687 | else | 
|  | 688 | return 0 # true: has errors | 
|  | 689 | fi | 
|  | 690 | } | 
|  | 691 |  | 
| Gilles Peskine | 12c49c7 | 2017-12-14 19:02:00 +0100 | [diff] [blame] | 692 | # Wait for process $2 to be listening on port $1 | 
|  | 693 | if type lsof >/dev/null 2>/dev/null; then | 
|  | 694 | wait_server_start() { | 
|  | 695 | START_TIME=$(date +%s) | 
|  | 696 | if is_dtls "$MODE"; then | 
|  | 697 | proto=UDP | 
|  | 698 | else | 
|  | 699 | proto=TCP | 
|  | 700 | fi | 
|  | 701 | while ! lsof -a -n -b -i "$proto:$1" -p "$2" >/dev/null 2>/dev/null; do | 
|  | 702 | if [ $(( $(date +%s) - $START_TIME )) -gt $DOG_DELAY ]; then | 
|  | 703 | echo "SERVERSTART TIMEOUT" | 
|  | 704 | echo "SERVERSTART TIMEOUT" >> $SRV_OUT | 
|  | 705 | break | 
|  | 706 | fi | 
|  | 707 | # Linux and *BSD support decimal arguments to sleep. On other | 
|  | 708 | # OSes this may be a tight loop. | 
|  | 709 | sleep 0.1 2>/dev/null || true | 
|  | 710 | done | 
|  | 711 | } | 
|  | 712 | else | 
| Gilles Peskine | 3c9e2b5 | 2018-01-08 12:38:15 +0100 | [diff] [blame] | 713 | echo "Warning: lsof not available, wait_server_start = sleep" | 
| Gilles Peskine | 12c49c7 | 2017-12-14 19:02:00 +0100 | [diff] [blame] | 714 | wait_server_start() { | 
| Manuel Pégourié-Gonnard | 0d225da | 2018-01-22 10:22:09 +0100 | [diff] [blame] | 715 | sleep 2 | 
| Gilles Peskine | 12c49c7 | 2017-12-14 19:02:00 +0100 | [diff] [blame] | 716 | } | 
|  | 717 | fi | 
|  | 718 |  | 
|  | 719 |  | 
| Manuel Pégourié-Gonnard | 304beef | 2014-02-19 14:45:00 +0100 | [diff] [blame] | 720 | # start_server <name> | 
|  | 721 | # also saves name and command | 
|  | 722 | start_server() { | 
| Manuel Pégourié-Gonnard | 304beef | 2014-02-19 14:45:00 +0100 | [diff] [blame] | 723 | case $1 in | 
|  | 724 | [Oo]pen*) | 
| Manuel Pégourié-Gonnard | c572246 | 2022-12-19 11:42:12 +0100 | [diff] [blame] | 725 | SERVER_CMD="$OPENSSL s_server $O_SERVER_ARGS" | 
| Manuel Pégourié-Gonnard | 304beef | 2014-02-19 14:45:00 +0100 | [diff] [blame] | 726 | ;; | 
| Manuel Pégourié-Gonnard | 5b2d776 | 2014-02-28 12:42:57 +0100 | [diff] [blame] | 727 | [Gg]nu*) | 
| Manuel Pégourié-Gonnard | 74faf3c | 2014-03-13 18:47:44 +0100 | [diff] [blame] | 728 | SERVER_CMD="$GNUTLS_SERV $G_SERVER_ARGS --priority $G_SERVER_PRIO" | 
| Manuel Pégourié-Gonnard | 5b2d776 | 2014-02-28 12:42:57 +0100 | [diff] [blame] | 729 | ;; | 
| Manuel Pégourié-Gonnard | a8f3b75 | 2015-01-22 17:05:05 +0000 | [diff] [blame] | 730 | mbed*) | 
| Simon Butcher | ac22d11 | 2016-09-04 22:31:09 +0100 | [diff] [blame] | 731 | SERVER_CMD="$M_SRV $M_SERVER_ARGS" | 
| Manuel Pégourié-Gonnard | 3eec604 | 2014-02-27 15:37:24 +0100 | [diff] [blame] | 732 | if [ "$MEMCHECK" -gt 0 ]; then | 
|  | 733 | SERVER_CMD="valgrind --leak-check=full $SERVER_CMD" | 
|  | 734 | fi | 
| Manuel Pégourié-Gonnard | 304beef | 2014-02-19 14:45:00 +0100 | [diff] [blame] | 735 | ;; | 
|  | 736 | *) | 
|  | 737 | echo "error: invalid server name: $1" >&2 | 
|  | 738 | exit 1 | 
|  | 739 | ;; | 
|  | 740 | esac | 
|  | 741 | SERVER_NAME=$1 | 
|  | 742 |  | 
|  | 743 | log "$SERVER_CMD" | 
| Manuel Pégourié-Gonnard | bc3b16c | 2014-05-28 23:06:50 +0200 | [diff] [blame] | 744 | echo "$SERVER_CMD" > $SRV_OUT | 
| Manuel Pégourié-Gonnard | d1af102 | 2014-07-11 17:01:06 +0200 | [diff] [blame] | 745 | # for servers without -www or equivalent | 
| Manuel Pégourié-Gonnard | 82cf0a1 | 2015-02-09 13:05:54 +0000 | [diff] [blame] | 746 | while :; do echo bla; sleep 1; done | $SERVER_CMD >> $SRV_OUT 2>&1 & | 
| Yanray Wang | 1288597 | 2023-01-13 11:42:11 +0800 | [diff] [blame] | 747 | SRV_PID=$! | 
| Manuel Pégourié-Gonnard | 304beef | 2014-02-19 14:45:00 +0100 | [diff] [blame] | 748 |  | 
| Yanray Wang | 1288597 | 2023-01-13 11:42:11 +0800 | [diff] [blame] | 749 | wait_server_start "$PORT" "$SRV_PID" | 
| Manuel Pégourié-Gonnard | 304beef | 2014-02-19 14:45:00 +0100 | [diff] [blame] | 750 | } | 
|  | 751 |  | 
| Manuel Pégourié-Gonnard | 1649449 | 2014-08-31 10:37:14 +0200 | [diff] [blame] | 752 | # terminate the running server | 
| Manuel Pégourié-Gonnard | 9595771 | 2014-02-19 15:29:38 +0100 | [diff] [blame] | 753 | stop_server() { | 
| Yanray Wang | 1288597 | 2023-01-13 11:42:11 +0800 | [diff] [blame] | 754 | # For Ubuntu 22.04, `Terminated` message is outputed by wait command. | 
|  | 755 | # To remove it from stdout, redirect stdout/stderr to SRV_OUT | 
|  | 756 | kill $SRV_PID >/dev/null 2>&1 | 
|  | 757 | wait $SRV_PID >> $SRV_OUT 2>&1 | 
| Manuel Pégourié-Gonnard | 3eec604 | 2014-02-27 15:37:24 +0100 | [diff] [blame] | 758 |  | 
|  | 759 | if [ "$MEMCHECK" -gt 0 ]; then | 
| Simon Butcher | ac22d11 | 2016-09-04 22:31:09 +0100 | [diff] [blame] | 760 | if is_mbedtls "$SERVER_CMD" && has_mem_err $SRV_OUT; then | 
| Manuel Pégourié-Gonnard | 3eec604 | 2014-02-27 15:37:24 +0100 | [diff] [blame] | 761 | echo "  ! Server had memory errors" | 
| Manuel Pégourié-Gonnard | 72e51ee | 2014-08-31 10:22:11 +0200 | [diff] [blame] | 762 | SRVMEM=$(( $SRVMEM + 1 )) | 
| Manuel Pégourié-Gonnard | 3eec604 | 2014-02-27 15:37:24 +0100 | [diff] [blame] | 763 | return | 
|  | 764 | fi | 
|  | 765 | fi | 
|  | 766 |  | 
| Manuel Pégourié-Gonnard | bc3b16c | 2014-05-28 23:06:50 +0200 | [diff] [blame] | 767 | rm -f $SRV_OUT | 
| Manuel Pégourié-Gonnard | 9595771 | 2014-02-19 15:29:38 +0100 | [diff] [blame] | 768 | } | 
|  | 769 |  | 
| Manuel Pégourié-Gonnard | a9062e9 | 2014-02-25 16:21:22 +0100 | [diff] [blame] | 770 | # kill the running server (used when killed by signal) | 
|  | 771 | cleanup() { | 
| Manuel Pégourié-Gonnard | bc3b16c | 2014-05-28 23:06:50 +0200 | [diff] [blame] | 772 | rm -f $SRV_OUT $CLI_OUT | 
| Yanray Wang | 1288597 | 2023-01-13 11:42:11 +0800 | [diff] [blame] | 773 | kill $SRV_PID >/dev/null 2>&1 | 
| Manuel Pégourié-Gonnard | 1649449 | 2014-08-31 10:37:14 +0200 | [diff] [blame] | 774 | kill $WATCHDOG_PID >/dev/null 2>&1 | 
| Manuel Pégourié-Gonnard | a9062e9 | 2014-02-25 16:21:22 +0100 | [diff] [blame] | 775 | exit 1 | 
|  | 776 | } | 
|  | 777 |  | 
| Manuel Pégourié-Gonnard | c0f6a69 | 2014-08-30 22:41:47 +0200 | [diff] [blame] | 778 | # wait for client to terminate and set EXIT | 
|  | 779 | # must be called right after starting the client | 
|  | 780 | wait_client_done() { | 
|  | 781 | CLI_PID=$! | 
|  | 782 |  | 
|  | 783 | ( sleep "$DOG_DELAY"; echo "TIMEOUT" >> $CLI_OUT; kill $CLI_PID ) & | 
|  | 784 | WATCHDOG_PID=$! | 
|  | 785 |  | 
| Yanray Wang | 05f940b | 2023-01-13 10:52:41 +0800 | [diff] [blame] | 786 | # For Ubuntu 22.04, `Terminated` message is outputed by wait command. | 
|  | 787 | # To remove it from stdout, redirect stdout/stderr to CLI_OUT | 
|  | 788 | wait $CLI_PID >> $CLI_OUT 2>&1 | 
| Manuel Pégourié-Gonnard | c0f6a69 | 2014-08-30 22:41:47 +0200 | [diff] [blame] | 789 | EXIT=$? | 
|  | 790 |  | 
| Yanray Wang | 05f940b | 2023-01-13 10:52:41 +0800 | [diff] [blame] | 791 | kill $WATCHDOG_PID >/dev/null 2>&1 | 
|  | 792 | wait $WATCHDOG_PID >> $CLI_OUT 2>&1 | 
| Manuel Pégourié-Gonnard | c0f6a69 | 2014-08-30 22:41:47 +0200 | [diff] [blame] | 793 |  | 
|  | 794 | echo "EXIT: $EXIT" >> $CLI_OUT | 
|  | 795 | } | 
|  | 796 |  | 
| Yanray Wang | fb784b2 | 2023-03-02 11:55:55 +0800 | [diff] [blame] | 797 | # uniform_title <CLIENT> <SERVER> <STANDARD_CIPHER_SUITE> | 
| Tomás González | 4a86da2 | 2023-09-01 17:41:16 +0100 | [diff] [blame] | 798 | # $TITLE is considered as test case description for both --list-test-cases and | 
| Yanray Wang | fb784b2 | 2023-03-02 11:55:55 +0800 | [diff] [blame] | 799 | # MBEDTLS_TEST_OUTCOME_FILE. This function aims to control the format of | 
|  | 800 | # each test case description. | 
|  | 801 | uniform_title() { | 
|  | 802 | TITLE="$1->$2 $MODE,$VERIF $3" | 
| Yanray Wang | 3fcd3a7 | 2023-02-24 17:07:47 +0800 | [diff] [blame] | 803 | } | 
|  | 804 |  | 
| Yanray Wang | ad47063 | 2023-02-20 14:58:03 +0800 | [diff] [blame] | 805 | # record_outcome <outcome> [<failure-reason>] | 
|  | 806 | record_outcome() { | 
|  | 807 | echo "$1" | 
|  | 808 | if [ -n "$MBEDTLS_TEST_OUTCOME_FILE" ]; then | 
|  | 809 | # The test outcome file has the format (in single line): | 
|  | 810 | # platform;configuration; | 
|  | 811 | # test suite name;test case description; | 
|  | 812 | # PASS/FAIL/SKIP;[failure cause] | 
|  | 813 | printf '%s;%s;%s;%s;%s;%s\n'                                    \ | 
|  | 814 | "$MBEDTLS_TEST_PLATFORM" "$MBEDTLS_TEST_CONFIGURATION"      \ | 
|  | 815 | "compat" "$TITLE"                                           \ | 
|  | 816 | "$1" "${2-}"                                                \ | 
|  | 817 | >> "$MBEDTLS_TEST_OUTCOME_FILE" | 
|  | 818 | fi | 
|  | 819 | } | 
|  | 820 |  | 
| Gilles Peskine | 1783870 | 2023-08-28 17:36:22 +0200 | [diff] [blame] | 821 | save_logs() { | 
|  | 822 | cp $SRV_OUT c-srv-${TESTS}.log | 
|  | 823 | cp $CLI_OUT c-cli-${TESTS}.log | 
|  | 824 | } | 
|  | 825 |  | 
| Yanray Wang | f45a8ea | 2023-02-20 15:49:10 +0800 | [diff] [blame] | 826 | # display additional information if test case fails | 
|  | 827 | report_fail() { | 
| Yanray Wang | ad47063 | 2023-02-20 14:58:03 +0800 | [diff] [blame] | 828 | FAIL_PROMPT="outputs saved to c-srv-${TESTS}.log, c-cli-${TESTS}.log" | 
|  | 829 | record_outcome "FAIL" "$FAIL_PROMPT" | 
| Gilles Peskine | 1783870 | 2023-08-28 17:36:22 +0200 | [diff] [blame] | 830 | save_logs | 
| Yanray Wang | ad47063 | 2023-02-20 14:58:03 +0800 | [diff] [blame] | 831 | echo "  ! $FAIL_PROMPT" | 
| Yanray Wang | f45a8ea | 2023-02-20 15:49:10 +0800 | [diff] [blame] | 832 |  | 
|  | 833 | if [ "${LOG_FAILURE_ON_STDOUT:-0}" != 0 ]; then | 
|  | 834 | echo "  ! server output:" | 
|  | 835 | cat c-srv-${TESTS}.log | 
|  | 836 | echo "  ! ===================================================" | 
|  | 837 | echo "  ! client output:" | 
|  | 838 | cat c-cli-${TESTS}.log | 
|  | 839 | fi | 
|  | 840 | } | 
|  | 841 |  | 
| Gilles Peskine | 47aab85 | 2023-01-26 21:16:34 +0100 | [diff] [blame] | 842 | # run_client PROGRAM_NAME STANDARD_CIPHER_SUITE PROGRAM_CIPHER_SUITE | 
| Manuel Pégourié-Gonnard | 330e411 | 2014-02-19 15:23:21 +0100 | [diff] [blame] | 843 | run_client() { | 
| Manuel Pégourié-Gonnard | 87ae303 | 2014-02-27 11:12:30 +0100 | [diff] [blame] | 844 | # announce what we're going to do | 
| Manuel Pégourié-Gonnard | 72e51ee | 2014-08-31 10:22:11 +0200 | [diff] [blame] | 845 | TESTS=$(( $TESTS + 1 )) | 
| Yanray Wang | fb784b2 | 2023-03-02 11:55:55 +0800 | [diff] [blame] | 846 | uniform_title "${1%"${1#?}"}" "${SERVER_NAME%"${SERVER_NAME#?}"}" $2 | 
|  | 847 | DOTS72="........................................................................" | 
|  | 848 | printf "%s %.*s " "$TITLE" "$((71 - ${#TITLE}))" "$DOTS72" | 
| Manuel Pégourié-Gonnard | 87ae303 | 2014-02-27 11:12:30 +0100 | [diff] [blame] | 849 |  | 
| Manuel Pégourié-Gonnard | 53aef81 | 2014-07-11 17:41:24 +0200 | [diff] [blame] | 850 | # should we skip? | 
|  | 851 | if [ "X$SKIP_NEXT" = "XYES" ]; then | 
|  | 852 | SKIP_NEXT="NO" | 
| Yanray Wang | ad47063 | 2023-02-20 14:58:03 +0800 | [diff] [blame] | 853 | record_outcome "SKIP" | 
| Manuel Pégourié-Gonnard | 53aef81 | 2014-07-11 17:41:24 +0200 | [diff] [blame] | 854 | SKIPPED=$(( $SKIPPED + 1 )) | 
|  | 855 | return | 
|  | 856 | fi | 
|  | 857 |  | 
| Manuel Pégourié-Gonnard | 330e411 | 2014-02-19 15:23:21 +0100 | [diff] [blame] | 858 | # run the command and interpret result | 
|  | 859 | case $1 in | 
|  | 860 | [Oo]pen*) | 
| Gilles Peskine | 47aab85 | 2023-01-26 21:16:34 +0100 | [diff] [blame] | 861 | CLIENT_CMD="$OPENSSL s_client $O_CLIENT_ARGS -cipher $3" | 
| Manuel Pégourié-Gonnard | 330e411 | 2014-02-19 15:23:21 +0100 | [diff] [blame] | 862 | log "$CLIENT_CMD" | 
| Manuel Pégourié-Gonnard | bc3b16c | 2014-05-28 23:06:50 +0200 | [diff] [blame] | 863 | echo "$CLIENT_CMD" > $CLI_OUT | 
| Manuel Pégourié-Gonnard | 9afdc83 | 2015-08-04 17:15:13 +0200 | [diff] [blame] | 864 | printf 'GET HTTP/1.0\r\n\r\n' | $CLIENT_CMD >> $CLI_OUT 2>&1 & | 
| Manuel Pégourié-Gonnard | c0f6a69 | 2014-08-30 22:41:47 +0200 | [diff] [blame] | 865 | wait_client_done | 
| Manuel Pégourié-Gonnard | 330e411 | 2014-02-19 15:23:21 +0100 | [diff] [blame] | 866 |  | 
| Manuel Pégourié-Gonnard | 72e51ee | 2014-08-31 10:22:11 +0200 | [diff] [blame] | 867 | if [ $EXIT -eq 0 ]; then | 
| Manuel Pégourié-Gonnard | 330e411 | 2014-02-19 15:23:21 +0100 | [diff] [blame] | 868 | RESULT=0 | 
|  | 869 | else | 
| Pengyu Lv | 9e7bb2a | 2023-02-23 15:24:47 +0800 | [diff] [blame] | 870 | # If it is NULL cipher ... | 
| Manuel Pégourié-Gonnard | bc3b16c | 2014-05-28 23:06:50 +0200 | [diff] [blame] | 871 | if grep 'Cipher is (NONE)' $CLI_OUT >/dev/null; then | 
| Manuel Pégourié-Gonnard | 330e411 | 2014-02-19 15:23:21 +0100 | [diff] [blame] | 872 | RESULT=1 | 
|  | 873 | else | 
|  | 874 | RESULT=2 | 
|  | 875 | fi | 
|  | 876 | fi | 
|  | 877 | ;; | 
|  | 878 |  | 
| Manuel Pégourié-Gonnard | a437144 | 2014-03-13 16:21:59 +0100 | [diff] [blame] | 879 | [Gg]nu*) | 
| Pengyu Lv | a8342a7 | 2023-12-01 14:25:40 +0800 | [diff] [blame] | 880 | CLIENT_CMD="$GNUTLS_CLI $G_CLIENT_ARGS --priority $G_PRIO_MODE:$3 localhost" | 
| Manuel Pégourié-Gonnard | a437144 | 2014-03-13 16:21:59 +0100 | [diff] [blame] | 881 | log "$CLIENT_CMD" | 
| Manuel Pégourié-Gonnard | bc3b16c | 2014-05-28 23:06:50 +0200 | [diff] [blame] | 882 | echo "$CLIENT_CMD" > $CLI_OUT | 
| Manuel Pégourié-Gonnard | 9afdc83 | 2015-08-04 17:15:13 +0200 | [diff] [blame] | 883 | printf 'GET HTTP/1.0\r\n\r\n' | $CLIENT_CMD >> $CLI_OUT 2>&1 & | 
| Manuel Pégourié-Gonnard | c0f6a69 | 2014-08-30 22:41:47 +0200 | [diff] [blame] | 884 | wait_client_done | 
| Manuel Pégourié-Gonnard | a437144 | 2014-03-13 16:21:59 +0100 | [diff] [blame] | 885 |  | 
| Manuel Pégourié-Gonnard | 72e51ee | 2014-08-31 10:22:11 +0200 | [diff] [blame] | 886 | if [ $EXIT -eq 0 ]; then | 
| Manuel Pégourié-Gonnard | a437144 | 2014-03-13 16:21:59 +0100 | [diff] [blame] | 887 | RESULT=0 | 
|  | 888 | else | 
| Manuel Pégourié-Gonnard | 9edba77 | 2014-03-13 17:45:35 +0100 | [diff] [blame] | 889 | RESULT=2 | 
|  | 890 | # interpret early failure, with a handshake_failure alert | 
|  | 891 | # before the server hello, as "no ciphersuite in common" | 
| Manuel Pégourié-Gonnard | bc3b16c | 2014-05-28 23:06:50 +0200 | [diff] [blame] | 892 | if grep -F 'Received alert [40]: Handshake failed' $CLI_OUT; then | 
|  | 893 | if grep -i 'SERVER HELLO .* was received' $CLI_OUT; then : | 
| Manuel Pégourié-Gonnard | 9edba77 | 2014-03-13 17:45:35 +0100 | [diff] [blame] | 894 | else | 
|  | 895 | RESULT=1 | 
|  | 896 | fi | 
|  | 897 | fi >/dev/null | 
| Manuel Pégourié-Gonnard | a437144 | 2014-03-13 16:21:59 +0100 | [diff] [blame] | 898 | fi | 
|  | 899 | ;; | 
|  | 900 |  | 
| Manuel Pégourié-Gonnard | a8f3b75 | 2015-01-22 17:05:05 +0000 | [diff] [blame] | 901 | mbed*) | 
| Gilles Peskine | 47aab85 | 2023-01-26 21:16:34 +0100 | [diff] [blame] | 902 | CLIENT_CMD="$M_CLI $M_CLIENT_ARGS force_ciphersuite=$3" | 
| Manuel Pégourié-Gonnard | 3eec604 | 2014-02-27 15:37:24 +0100 | [diff] [blame] | 903 | if [ "$MEMCHECK" -gt 0 ]; then | 
|  | 904 | CLIENT_CMD="valgrind --leak-check=full $CLIENT_CMD" | 
|  | 905 | fi | 
| Manuel Pégourié-Gonnard | 330e411 | 2014-02-19 15:23:21 +0100 | [diff] [blame] | 906 | log "$CLIENT_CMD" | 
| Manuel Pégourié-Gonnard | bc3b16c | 2014-05-28 23:06:50 +0200 | [diff] [blame] | 907 | echo "$CLIENT_CMD" > $CLI_OUT | 
| Manuel Pégourié-Gonnard | c0f6a69 | 2014-08-30 22:41:47 +0200 | [diff] [blame] | 908 | $CLIENT_CMD >> $CLI_OUT 2>&1 & | 
|  | 909 | wait_client_done | 
| Manuel Pégourié-Gonnard | 330e411 | 2014-02-19 15:23:21 +0100 | [diff] [blame] | 910 |  | 
|  | 911 | case $EXIT in | 
| Simon Butcher | ac22d11 | 2016-09-04 22:31:09 +0100 | [diff] [blame] | 912 | # Success | 
| Manuel Pégourié-Gonnard | 330e411 | 2014-02-19 15:23:21 +0100 | [diff] [blame] | 913 | "0")    RESULT=0    ;; | 
| Simon Butcher | ac22d11 | 2016-09-04 22:31:09 +0100 | [diff] [blame] | 914 |  | 
|  | 915 | # Ciphersuite not supported | 
| Manuel Pégourié-Gonnard | 330e411 | 2014-02-19 15:23:21 +0100 | [diff] [blame] | 916 | "2")    RESULT=1    ;; | 
| Simon Butcher | ac22d11 | 2016-09-04 22:31:09 +0100 | [diff] [blame] | 917 |  | 
|  | 918 | # Error | 
| Manuel Pégourié-Gonnard | 330e411 | 2014-02-19 15:23:21 +0100 | [diff] [blame] | 919 | *)      RESULT=2    ;; | 
|  | 920 | esac | 
| Manuel Pégourié-Gonnard | 3eec604 | 2014-02-27 15:37:24 +0100 | [diff] [blame] | 921 |  | 
|  | 922 | if [ "$MEMCHECK" -gt 0 ]; then | 
| Simon Butcher | ac22d11 | 2016-09-04 22:31:09 +0100 | [diff] [blame] | 923 | if is_mbedtls "$CLIENT_CMD" && has_mem_err $CLI_OUT; then | 
| Manuel Pégourié-Gonnard | 3eec604 | 2014-02-27 15:37:24 +0100 | [diff] [blame] | 924 | RESULT=2 | 
|  | 925 | fi | 
|  | 926 | fi | 
|  | 927 |  | 
| Manuel Pégourié-Gonnard | 330e411 | 2014-02-19 15:23:21 +0100 | [diff] [blame] | 928 | ;; | 
|  | 929 |  | 
|  | 930 | *) | 
|  | 931 | echo "error: invalid client name: $1" >&2 | 
|  | 932 | exit 1 | 
|  | 933 | ;; | 
|  | 934 | esac | 
|  | 935 |  | 
| Manuel Pégourié-Gonnard | bc3b16c | 2014-05-28 23:06:50 +0200 | [diff] [blame] | 936 | echo "EXIT: $EXIT" >> $CLI_OUT | 
| Manuel Pégourié-Gonnard | e01af4c | 2014-03-25 14:16:44 +0100 | [diff] [blame] | 937 |  | 
| Manuel Pégourié-Gonnard | 330e411 | 2014-02-19 15:23:21 +0100 | [diff] [blame] | 938 | # report and count result | 
| Manuel Pégourié-Gonnard | 330e411 | 2014-02-19 15:23:21 +0100 | [diff] [blame] | 939 | case $RESULT in | 
|  | 940 | "0") | 
| Yanray Wang | ad47063 | 2023-02-20 14:58:03 +0800 | [diff] [blame] | 941 | record_outcome "PASS" | 
| Gilles Peskine | 1783870 | 2023-08-28 17:36:22 +0200 | [diff] [blame] | 942 | if [ "$PRESERVE_LOGS" -gt 0 ]; then | 
|  | 943 | save_logs | 
|  | 944 | fi | 
| Manuel Pégourié-Gonnard | 330e411 | 2014-02-19 15:23:21 +0100 | [diff] [blame] | 945 | ;; | 
|  | 946 | "1") | 
| Yanray Wang | ad47063 | 2023-02-20 14:58:03 +0800 | [diff] [blame] | 947 | record_outcome "SKIP" | 
| Manuel Pégourié-Gonnard | 72e51ee | 2014-08-31 10:22:11 +0200 | [diff] [blame] | 948 | SKIPPED=$(( $SKIPPED + 1 )) | 
| Manuel Pégourié-Gonnard | 330e411 | 2014-02-19 15:23:21 +0100 | [diff] [blame] | 949 | ;; | 
|  | 950 | "2") | 
| Yanray Wang | f45a8ea | 2023-02-20 15:49:10 +0800 | [diff] [blame] | 951 | report_fail | 
| Manuel Pégourié-Gonnard | 72e51ee | 2014-08-31 10:22:11 +0200 | [diff] [blame] | 952 | FAILED=$(( $FAILED + 1 )) | 
| Manuel Pégourié-Gonnard | 330e411 | 2014-02-19 15:23:21 +0100 | [diff] [blame] | 953 | ;; | 
|  | 954 | esac | 
| Manuel Pégourié-Gonnard | 87ae303 | 2014-02-27 11:12:30 +0100 | [diff] [blame] | 955 |  | 
| Manuel Pégourié-Gonnard | bc3b16c | 2014-05-28 23:06:50 +0200 | [diff] [blame] | 956 | rm -f $CLI_OUT | 
| Manuel Pégourié-Gonnard | 330e411 | 2014-02-19 15:23:21 +0100 | [diff] [blame] | 957 | } | 
|  | 958 |  | 
| Manuel Pégourié-Gonnard | 9dea8bd | 2014-02-26 18:21:02 +0100 | [diff] [blame] | 959 | # | 
|  | 960 | # MAIN | 
|  | 961 | # | 
|  | 962 |  | 
| Manuel Pégourié-Gonnard | 3947d04 | 2014-03-14 18:13:53 +0100 | [diff] [blame] | 963 | get_options "$@" | 
|  | 964 |  | 
| Yanray Wang | ad47063 | 2023-02-20 14:58:03 +0800 | [diff] [blame] | 965 | # Make the outcome file path relative to the original directory, not | 
|  | 966 | # to .../tests | 
|  | 967 | case "$MBEDTLS_TEST_OUTCOME_FILE" in | 
|  | 968 | [!/]*) | 
|  | 969 | MBEDTLS_TEST_OUTCOME_FILE="$ORIGINAL_PWD/$MBEDTLS_TEST_OUTCOME_FILE" | 
|  | 970 | ;; | 
|  | 971 | esac | 
|  | 972 |  | 
| Manuel Pégourié-Gonnard | f7a2690 | 2014-02-27 12:25:54 +0100 | [diff] [blame] | 973 | # sanity checks, avoid an avalanche of errors | 
| Simon Butcher | ac22d11 | 2016-09-04 22:31:09 +0100 | [diff] [blame] | 974 | if [ ! -x "$M_SRV" ]; then | 
|  | 975 | echo "Command '$M_SRV' is not an executable file" >&2 | 
| Manuel Pégourié-Gonnard | f7a2690 | 2014-02-27 12:25:54 +0100 | [diff] [blame] | 976 | exit 1 | 
|  | 977 | fi | 
| Simon Butcher | ac22d11 | 2016-09-04 22:31:09 +0100 | [diff] [blame] | 978 | if [ ! -x "$M_CLI" ]; then | 
|  | 979 | echo "Command '$M_CLI' is not an executable file" >&2 | 
| Manuel Pégourié-Gonnard | f7a2690 | 2014-02-27 12:25:54 +0100 | [diff] [blame] | 980 | exit 1 | 
|  | 981 | fi | 
| Manuel Pégourié-Gonnard | 3947d04 | 2014-03-14 18:13:53 +0100 | [diff] [blame] | 982 |  | 
|  | 983 | if echo "$PEERS" | grep -i openssl > /dev/null; then | 
| Manuel Pégourié-Gonnard | c572246 | 2022-12-19 11:42:12 +0100 | [diff] [blame] | 984 | if which "$OPENSSL" >/dev/null 2>&1; then :; else | 
|  | 985 | echo "Command '$OPENSSL' not found" >&2 | 
| Manuel Pégourié-Gonnard | 74faf3c | 2014-03-13 18:47:44 +0100 | [diff] [blame] | 986 | exit 1 | 
|  | 987 | fi | 
| Manuel Pégourié-Gonnard | 3947d04 | 2014-03-14 18:13:53 +0100 | [diff] [blame] | 988 | fi | 
| Manuel Pégourié-Gonnard | f7a2690 | 2014-02-27 12:25:54 +0100 | [diff] [blame] | 989 |  | 
| Manuel Pégourié-Gonnard | 3947d04 | 2014-03-14 18:13:53 +0100 | [diff] [blame] | 990 | if echo "$PEERS" | grep -i gnutls > /dev/null; then | 
|  | 991 | for CMD in "$GNUTLS_CLI" "$GNUTLS_SERV"; do | 
|  | 992 | if which "$CMD" >/dev/null 2>&1; then :; else | 
|  | 993 | echo "Command '$CMD' not found" >&2 | 
|  | 994 | exit 1 | 
|  | 995 | fi | 
|  | 996 | done | 
|  | 997 | fi | 
|  | 998 |  | 
|  | 999 | for PEER in $PEERS; do | 
|  | 1000 | case "$PEER" in | 
| Manuel Pégourié-Gonnard | a8f3b75 | 2015-01-22 17:05:05 +0000 | [diff] [blame] | 1001 | mbed*|[Oo]pen*|[Gg]nu*) | 
| Manuel Pégourié-Gonnard | 3947d04 | 2014-03-14 18:13:53 +0100 | [diff] [blame] | 1002 | ;; | 
|  | 1003 | *) | 
|  | 1004 | echo "Unknown peers: $PEER" >&2 | 
|  | 1005 | exit 1 | 
|  | 1006 | esac | 
|  | 1007 | done | 
| Manuel Pégourié-Gonnard | 9dea8bd | 2014-02-26 18:21:02 +0100 | [diff] [blame] | 1008 |  | 
| Manuel Pégourié-Gonnard | 8066b81 | 2014-05-28 22:59:30 +0200 | [diff] [blame] | 1009 | # Pick a "unique" port in the range 10000-19999. | 
|  | 1010 | PORT="0000$$" | 
| Manuel Pégourié-Gonnard | fab2a3c | 2014-06-16 16:54:36 +0200 | [diff] [blame] | 1011 | PORT="1$(echo $PORT | tail -c 5)" | 
| Manuel Pégourié-Gonnard | 8066b81 | 2014-05-28 22:59:30 +0200 | [diff] [blame] | 1012 |  | 
| Manuel Pégourié-Gonnard | bc3b16c | 2014-05-28 23:06:50 +0200 | [diff] [blame] | 1013 | # Also pick a unique name for intermediate files | 
|  | 1014 | SRV_OUT="srv_out.$$" | 
|  | 1015 | CLI_OUT="cli_out.$$" | 
|  | 1016 |  | 
| Manuel Pégourié-Gonnard | c0f6a69 | 2014-08-30 22:41:47 +0200 | [diff] [blame] | 1017 | # client timeout delay: be more patient with valgrind | 
|  | 1018 | if [ "$MEMCHECK" -gt 0 ]; then | 
|  | 1019 | DOG_DELAY=30 | 
|  | 1020 | else | 
|  | 1021 | DOG_DELAY=10 | 
|  | 1022 | fi | 
|  | 1023 |  | 
| Manuel Pégourié-Gonnard | 53aef81 | 2014-07-11 17:41:24 +0200 | [diff] [blame] | 1024 | SKIP_NEXT="NO" | 
|  | 1025 |  | 
| Manuel Pégourié-Gonnard | a9062e9 | 2014-02-25 16:21:22 +0100 | [diff] [blame] | 1026 | trap cleanup INT TERM HUP | 
|  | 1027 |  | 
| Yanray Wang | 35c0ead | 2023-02-07 10:41:04 +0800 | [diff] [blame] | 1028 | for MODE in $MODES; do | 
| Yanray Wang | 3038297 | 2023-02-08 12:38:31 +0800 | [diff] [blame] | 1029 | for TYPE in $TYPES; do | 
| Yanray Wang | 35c0ead | 2023-02-07 10:41:04 +0800 | [diff] [blame] | 1030 |  | 
| Yanray Wang | 3038297 | 2023-02-08 12:38:31 +0800 | [diff] [blame] | 1031 | # PSK cipher suites do not allow client certificate verification. | 
|  | 1032 | # This means PSK test cases with VERIFY=YES should be replaced by | 
|  | 1033 | # VERIFY=NO or be ignored. SUB_VERIFIES variable is used to constrain | 
|  | 1034 | # verification option for PSK test cases. | 
|  | 1035 | SUB_VERIFIES=$VERIFIES | 
|  | 1036 | if [ "$TYPE" = "PSK" ]; then | 
|  | 1037 | SUB_VERIFIES="NO" | 
|  | 1038 | fi | 
| Yanray Wang | 35c0ead | 2023-02-07 10:41:04 +0800 | [diff] [blame] | 1039 |  | 
| Yanray Wang | 3038297 | 2023-02-08 12:38:31 +0800 | [diff] [blame] | 1040 | for VERIFY in $SUB_VERIFIES; do | 
|  | 1041 | VERIF=$(echo $VERIFY | tr '[:upper:]' '[:lower:]') | 
| Manuel Pégourié-Gonnard | 9edba77 | 2014-03-13 17:45:35 +0100 | [diff] [blame] | 1042 | for PEER in $PEERS; do | 
| Paul Bakker | 7e5e7ca | 2013-04-17 19:27:58 +0200 | [diff] [blame] | 1043 |  | 
| Manuel Pégourié-Gonnard | 9595771 | 2014-02-19 15:29:38 +0100 | [diff] [blame] | 1044 | setup_arguments | 
| Manuel Pégourié-Gonnard | 5b2d776 | 2014-02-28 12:42:57 +0100 | [diff] [blame] | 1045 |  | 
| Manuel Pégourié-Gonnard | 9edba77 | 2014-03-13 17:45:35 +0100 | [diff] [blame] | 1046 | case "$PEER" in | 
| Manuel Pégourié-Gonnard | d331319 | 2013-09-13 19:20:37 +0200 | [diff] [blame] | 1047 |  | 
| Manuel Pégourié-Gonnard | 9edba77 | 2014-03-13 17:45:35 +0100 | [diff] [blame] | 1048 | [Oo]pen*) | 
| Paul Bakker | 398cb51 | 2012-04-10 08:22:31 +0000 | [diff] [blame] | 1049 |  | 
| Manuel Pégourié-Gonnard | 9edba77 | 2014-03-13 17:45:35 +0100 | [diff] [blame] | 1050 | reset_ciphersuites | 
| Manuel Pégourié-Gonnard | 12b8472 | 2014-03-25 19:07:28 +0100 | [diff] [blame] | 1051 | add_common_ciphersuites | 
| Manuel Pégourié-Gonnard | 9edba77 | 2014-03-13 17:45:35 +0100 | [diff] [blame] | 1052 | add_openssl_ciphersuites | 
|  | 1053 | filter_ciphersuites | 
| Manuel Pégourié-Gonnard | 330e411 | 2014-02-19 15:23:21 +0100 | [diff] [blame] | 1054 |  | 
| Simon Butcher | ac22d11 | 2016-09-04 22:31:09 +0100 | [diff] [blame] | 1055 | if [ "X" != "X$M_CIPHERS" ]; then | 
| Manuel Pégourié-Gonnard | 9edba77 | 2014-03-13 17:45:35 +0100 | [diff] [blame] | 1056 | start_server "OpenSSL" | 
| Gilles Peskine | 47aab85 | 2023-01-26 21:16:34 +0100 | [diff] [blame] | 1057 | translate_ciphers m $M_CIPHERS | 
|  | 1058 | for i in $ciphers; do | 
| Pengyu Lv | 5e780df | 2023-02-21 14:19:27 +0800 | [diff] [blame] | 1059 | o_check_ciphersuite "${i%%=*}" | 
| Gilles Peskine | 47aab85 | 2023-01-26 21:16:34 +0100 | [diff] [blame] | 1060 | run_client mbedTLS ${i%%=*} ${i#*=} | 
| Manuel Pégourié-Gonnard | 9edba77 | 2014-03-13 17:45:35 +0100 | [diff] [blame] | 1061 | done | 
|  | 1062 | stop_server | 
|  | 1063 | fi | 
| Manuel Pégourié-Gonnard | 5b2d776 | 2014-02-28 12:42:57 +0100 | [diff] [blame] | 1064 |  | 
| Manuel Pégourié-Gonnard | 9edba77 | 2014-03-13 17:45:35 +0100 | [diff] [blame] | 1065 | if [ "X" != "X$O_CIPHERS" ]; then | 
| Manuel Pégourié-Gonnard | e4f6edc | 2015-01-22 16:43:54 +0000 | [diff] [blame] | 1066 | start_server "mbedTLS" | 
| Gilles Peskine | 47aab85 | 2023-01-26 21:16:34 +0100 | [diff] [blame] | 1067 | translate_ciphers o $O_CIPHERS | 
|  | 1068 | for i in $ciphers; do | 
| Pengyu Lv | 07d5085 | 2023-02-22 12:17:26 +0800 | [diff] [blame] | 1069 | o_check_ciphersuite "${i%%=*}" | 
| Gilles Peskine | 47aab85 | 2023-01-26 21:16:34 +0100 | [diff] [blame] | 1070 | run_client OpenSSL ${i%%=*} ${i#*=} | 
| Manuel Pégourié-Gonnard | 9edba77 | 2014-03-13 17:45:35 +0100 | [diff] [blame] | 1071 | done | 
|  | 1072 | stop_server | 
|  | 1073 | fi | 
| Manuel Pégourié-Gonnard | 5b2d776 | 2014-02-28 12:42:57 +0100 | [diff] [blame] | 1074 |  | 
| Manuel Pégourié-Gonnard | 9edba77 | 2014-03-13 17:45:35 +0100 | [diff] [blame] | 1075 | ;; | 
| Manuel Pégourié-Gonnard | 5b2d776 | 2014-02-28 12:42:57 +0100 | [diff] [blame] | 1076 |  | 
| Manuel Pégourié-Gonnard | 9edba77 | 2014-03-13 17:45:35 +0100 | [diff] [blame] | 1077 | [Gg]nu*) | 
| Paul Bakker | fab5c82 | 2012-02-06 16:45:10 +0000 | [diff] [blame] | 1078 |  | 
| Manuel Pégourié-Gonnard | 9edba77 | 2014-03-13 17:45:35 +0100 | [diff] [blame] | 1079 | reset_ciphersuites | 
| Manuel Pégourié-Gonnard | 12b8472 | 2014-03-25 19:07:28 +0100 | [diff] [blame] | 1080 | add_common_ciphersuites | 
| Manuel Pégourié-Gonnard | 9edba77 | 2014-03-13 17:45:35 +0100 | [diff] [blame] | 1081 | add_gnutls_ciphersuites | 
|  | 1082 | filter_ciphersuites | 
| Paul Bakker | fab5c82 | 2012-02-06 16:45:10 +0000 | [diff] [blame] | 1083 |  | 
| Simon Butcher | ac22d11 | 2016-09-04 22:31:09 +0100 | [diff] [blame] | 1084 | if [ "X" != "X$M_CIPHERS" ]; then | 
| Manuel Pégourié-Gonnard | 9edba77 | 2014-03-13 17:45:35 +0100 | [diff] [blame] | 1085 | start_server "GnuTLS" | 
| Gilles Peskine | 47aab85 | 2023-01-26 21:16:34 +0100 | [diff] [blame] | 1086 | translate_ciphers m $M_CIPHERS | 
|  | 1087 | for i in $ciphers; do | 
|  | 1088 | run_client mbedTLS ${i%%=*} ${i#*=} | 
| Manuel Pégourié-Gonnard | 9edba77 | 2014-03-13 17:45:35 +0100 | [diff] [blame] | 1089 | done | 
|  | 1090 | stop_server | 
|  | 1091 | fi | 
|  | 1092 |  | 
|  | 1093 | if [ "X" != "X$G_CIPHERS" ]; then | 
| Manuel Pégourié-Gonnard | e4f6edc | 2015-01-22 16:43:54 +0000 | [diff] [blame] | 1094 | start_server "mbedTLS" | 
| Gilles Peskine | 47aab85 | 2023-01-26 21:16:34 +0100 | [diff] [blame] | 1095 | translate_ciphers g $G_CIPHERS | 
|  | 1096 | for i in $ciphers; do | 
|  | 1097 | run_client GnuTLS ${i%%=*} ${i#*=} | 
| Manuel Pégourié-Gonnard | 9edba77 | 2014-03-13 17:45:35 +0100 | [diff] [blame] | 1098 | done | 
|  | 1099 | stop_server | 
|  | 1100 | fi | 
|  | 1101 |  | 
|  | 1102 | ;; | 
|  | 1103 |  | 
| Manuel Pégourié-Gonnard | a8f3b75 | 2015-01-22 17:05:05 +0000 | [diff] [blame] | 1104 | mbed*) | 
| Manuel Pégourié-Gonnard | 9edba77 | 2014-03-13 17:45:35 +0100 | [diff] [blame] | 1105 |  | 
|  | 1106 | reset_ciphersuites | 
| Manuel Pégourié-Gonnard | 12b8472 | 2014-03-25 19:07:28 +0100 | [diff] [blame] | 1107 | add_common_ciphersuites | 
| Manuel Pégourié-Gonnard | 9edba77 | 2014-03-13 17:45:35 +0100 | [diff] [blame] | 1108 | add_openssl_ciphersuites | 
|  | 1109 | add_gnutls_ciphersuites | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1110 | add_mbedtls_ciphersuites | 
| Manuel Pégourié-Gonnard | 9edba77 | 2014-03-13 17:45:35 +0100 | [diff] [blame] | 1111 | filter_ciphersuites | 
|  | 1112 |  | 
| Simon Butcher | ac22d11 | 2016-09-04 22:31:09 +0100 | [diff] [blame] | 1113 | if [ "X" != "X$M_CIPHERS" ]; then | 
| Manuel Pégourié-Gonnard | e4f6edc | 2015-01-22 16:43:54 +0000 | [diff] [blame] | 1114 | start_server "mbedTLS" | 
| Gilles Peskine | 47aab85 | 2023-01-26 21:16:34 +0100 | [diff] [blame] | 1115 | translate_ciphers m $M_CIPHERS | 
|  | 1116 | for i in $ciphers; do | 
|  | 1117 | run_client mbedTLS ${i%%=*} ${i#*=} | 
| Manuel Pégourié-Gonnard | 9edba77 | 2014-03-13 17:45:35 +0100 | [diff] [blame] | 1118 | done | 
|  | 1119 | stop_server | 
|  | 1120 | fi | 
|  | 1121 |  | 
|  | 1122 | ;; | 
|  | 1123 |  | 
| Manuel Pégourié-Gonnard | a1a9f9a | 2014-03-25 18:04:59 +0100 | [diff] [blame] | 1124 | *) | 
| Paul Bakker | 1ebc0c5 | 2014-05-22 15:47:58 +0200 | [diff] [blame] | 1125 | echo "Unknown peer: $PEER" >&2 | 
| Manuel Pégourié-Gonnard | a1a9f9a | 2014-03-25 18:04:59 +0100 | [diff] [blame] | 1126 | exit 1 | 
|  | 1127 | ;; | 
|  | 1128 |  | 
| Manuel Pégourié-Gonnard | 9edba77 | 2014-03-13 17:45:35 +0100 | [diff] [blame] | 1129 | esac | 
|  | 1130 |  | 
|  | 1131 | done | 
| Manuel Pégourié-Gonnard | 9595771 | 2014-02-19 15:29:38 +0100 | [diff] [blame] | 1132 | done | 
|  | 1133 | done | 
| Manuel Pégourié-Gonnard | 9791a40 | 2013-08-27 19:57:15 +0200 | [diff] [blame] | 1134 | done | 
| Manuel Pégourié-Gonnard | 70064fd | 2013-08-27 22:00:47 +0200 | [diff] [blame] | 1135 |  | 
| Manuel Pégourié-Gonnard | 4145b89 | 2014-02-24 13:20:14 +0100 | [diff] [blame] | 1136 | echo "------------------------------------------------------------------------" | 
| Manuel Pégourié-Gonnard | 70064fd | 2013-08-27 22:00:47 +0200 | [diff] [blame] | 1137 |  | 
| Tom Cosgrove | fc0e79e | 2023-01-13 12:13:41 +0000 | [diff] [blame] | 1138 | if [ $FAILED -ne 0 -o $SRVMEM -ne 0 ]; then | 
| Manuel Pégourié-Gonnard | f46f128 | 2014-12-11 11:51:28 +0100 | [diff] [blame] | 1139 | printf "FAILED" | 
| Manuel Pégourié-Gonnard | 70064fd | 2013-08-27 22:00:47 +0200 | [diff] [blame] | 1140 | else | 
| Manuel Pégourié-Gonnard | f46f128 | 2014-12-11 11:51:28 +0100 | [diff] [blame] | 1141 | printf "PASSED" | 
| Manuel Pégourié-Gonnard | 70064fd | 2013-08-27 22:00:47 +0200 | [diff] [blame] | 1142 | fi | 
|  | 1143 |  | 
| Manuel Pégourié-Gonnard | ba0b844 | 2014-03-13 17:57:45 +0100 | [diff] [blame] | 1144 | if [ "$MEMCHECK" -gt 0 ]; then | 
| Manuel Pégourié-Gonnard | 72e51ee | 2014-08-31 10:22:11 +0200 | [diff] [blame] | 1145 | MEMREPORT=", $SRVMEM server memory errors" | 
| Manuel Pégourié-Gonnard | ba0b844 | 2014-03-13 17:57:45 +0100 | [diff] [blame] | 1146 | else | 
|  | 1147 | MEMREPORT="" | 
|  | 1148 | fi | 
|  | 1149 |  | 
| Manuel Pégourié-Gonnard | 72e51ee | 2014-08-31 10:22:11 +0200 | [diff] [blame] | 1150 | PASSED=$(( $TESTS - $FAILED )) | 
|  | 1151 | echo " ($PASSED / $TESTS tests ($SKIPPED skipped$MEMREPORT))" | 
| Manuel Pégourié-Gonnard | 70064fd | 2013-08-27 22:00:47 +0200 | [diff] [blame] | 1152 |  | 
| Gilles Peskine | 39c5207 | 2024-05-17 11:55:15 +0200 | [diff] [blame] | 1153 | if [ $((TESTS - SKIPPED)) -lt $MIN_TESTS ]; then | 
|  | 1154 | cat <<EOF | 
|  | 1155 | Error: Expected to run at least $MIN_TESTS, but only ran $((TESTS - SKIPPED)). | 
|  | 1156 | Maybe a bad filter ('$FILTER' excluding '$EXCLUDE') or a bad configuration? | 
|  | 1157 | EOF | 
|  | 1158 | if [ $FAILED -eq 0 ]; then | 
|  | 1159 | FAILED=1 | 
|  | 1160 | fi | 
|  | 1161 | fi | 
|  | 1162 |  | 
| Manuel Pégourié-Gonnard | 72e51ee | 2014-08-31 10:22:11 +0200 | [diff] [blame] | 1163 | FAILED=$(( $FAILED + $SRVMEM )) | 
| Tom Cosgrove | fc0e79e | 2023-01-13 12:13:41 +0000 | [diff] [blame] | 1164 | if [ $FAILED -gt 255 ]; then | 
|  | 1165 | # Clamp at 255 as caller gets exit code & 0xFF | 
|  | 1166 | # (so 256 would be 0, or success, etc) | 
|  | 1167 | FAILED=255 | 
|  | 1168 | fi | 
| Manuel Pégourié-Gonnard | 72e51ee | 2014-08-31 10:22:11 +0200 | [diff] [blame] | 1169 | exit $FAILED |