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