compat.sh 38.7 KB
Newer Older
1 2
#!/bin/bash

3 4 5 6
# Test interop with OpenSSL and GnuTLS (and self-op while at it).
#
# Check each common ciphersuite, with each version, both ways (client/server),
# with and without client authentication.
7

8 9 10 11 12 13 14 15
# test if those two are set in the environment before assigning defaults
if [ -n "$GNUTLS_CLI" -a -n "$GNUTLS_SERV" ]; then
    GNUTLS_AVAILABLE=1
else
    GNUTLS_AVAILABLE=0
fi

# catch undefined variables from now on
16 17
set -u

18
# initialise counters
19 20 21
let "tests = 0"
let "failed = 0"
let "skipped = 0"
22
let "srvmem = 0"
23

24
# default commands, can be overriden by the environment
25 26
: ${P_SRV:=../programs/ssl/ssl_server2}
: ${P_CLI:=../programs/ssl/ssl_client2}
27 28 29
: ${OPENSSL_CMD:=openssl} # OPENSSL would conflict with the build system
: ${GNUTLS_CLI:=gnutls-cli}
: ${GNUTLS_SERV:=gnutls-serv}
30

31
# default values for options
32
MODES="ssl3 tls1 tls1_1 tls1_2"
Paul Bakker's avatar
Paul Bakker committed
33
VERIFIES="NO YES"
34
TYPES="ECDSA RSA PSK"
35
FILTER=""
36
EXCLUDE='NULL\|DES-CBC-' # avoid plain DES but keep 3DES-EDE-CBC (PolarSSL), DES-CBC3 (OpenSSL)
37
VERBOSE=""
38
MEMCHECK=0
39 40 41 42 43 44
# GnuTLS not enabled by default, 3.2.4 might not be available everywhere
if [ "$GNUTLS_AVAILABLE" -gt 0 ]; then
    PEERS="OpenSSL PolarSSL GnuTLS"
else
    PEERS="OpenSSL PolarSSL"
fi
45

46 47
print_usage() {
    echo "Usage: $0"
48 49 50 51 52 53 54 55 56 57
    echo -e "  -h|--help\tPrint this help."
    echo -e "  -f|--filter\tOnly matching ciphersuites are tested (Default: '$FILTER')"
    echo -e "  -e|--exclude\tMatching ciphersuites are excluded (Default: '$EXCLUDE')"
    echo -e "  -m|--modes\tWhich modes to perform (Default: '$MODES')"
    echo -e "  -t|--types\tWhich key exchange type to perform (Default: '$TYPES')"
    echo -e "  -V|--verify\tWhich verification modes to perform (Default: '$VERIFIES')"
    echo -e "  -p|--peers\tWhich peers to use (Default: '$PEERS')"
    echo -e "            \tAlso available: GnuTLS (needs v3.2.4 or higher)"
    echo -e "  -M|--memcheck\tCheck memory leaks and errors."
    echo -e "  -v|--verbose\tSet verbose output."
58 59 60 61 62 63 64 65
}

get_options() {
    while [ $# -gt 0 ]; do
        case "$1" in
            -f|--filter)
                shift; FILTER=$1
                ;;
66 67 68
            -e|--exclude)
                shift; EXCLUDE=$1
                ;;
69 70 71 72 73 74 75 76 77
            -m|--modes)
                shift; MODES=$1
                ;;
            -t|--types)
                shift; TYPES=$1
                ;;
            -V|--verify)
                shift; VERIFIES=$1
                ;;
78 79 80
            -p|--peers)
                shift; PEERS=$1
                ;;
81 82 83
            -v|--verbose)
                VERBOSE=1
                ;;
84 85 86
            -M|--memcheck)
                MEMCHECK=1
                ;;
87 88 89 90 91 92 93 94 95 96 97 98 99
            -h|--help)
                print_usage
                exit 0
                ;;
            *)
                echo "Unknown argument: '$1'"
                print_usage
                exit 1
                ;;
        esac
        shift
    done
}
100

101
log() {
102 103 104 105
  if [ "X" != "X$VERBOSE" ]; then
    echo "$@"
  fi
}
106

107 108
filter()
{
109
  LIST="$1"
110 111 112 113
  NEW_LIST=""

  for i in $LIST;
  do
114
    NEW_LIST="$NEW_LIST $( echo "$i" | grep "$FILTER" | grep -v "$EXCLUDE" )"
115 116
  done

117 118
  # normalize whitespace
  echo "$NEW_LIST" | sed -e 's/[[:space:]]\+/ /g' -e 's/^ //' -e 's/ $//'
119 120
}

121 122
filter_ciphersuites()
{
123
    if [ "X" != "X$FILTER" -o "X" != "X$EXCLUDE" ];
124
    then
125 126 127
        P_CIPHERS=$( filter "$P_CIPHERS" )
        O_CIPHERS=$( filter "$O_CIPHERS" )
        G_CIPHERS=$( filter "$G_CIPHERS" )
128 129 130 131
    fi
}

reset_ciphersuites()
132 133 134
{
    P_CIPHERS=""
    O_CIPHERS=""
135 136
    G_CIPHERS=""
}
137

138
add_common_ciphersuites()
139
{
140 141 142 143 144 145 146 147 148 149 150
    case $TYPE in

        "ECDSA")
            if [ "$MODE" != "ssl3" ];
            then
                P_CIPHERS="$P_CIPHERS                       \
                    TLS-ECDHE-ECDSA-WITH-NULL-SHA           \
                    TLS-ECDHE-ECDSA-WITH-RC4-128-SHA        \
                    TLS-ECDHE-ECDSA-WITH-3DES-EDE-CBC-SHA   \
                    TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA    \
                    TLS-ECDHE-ECDSA-WITH-AES-256-CBC-SHA    \
151 152 153 154 155 156 157
                    "
                G_CIPHERS="$G_CIPHERS                       \
                    +ECDHE-ECDSA:+NULL:+SHA1                \
                    +ECDHE-ECDSA:+ARCFOUR-128:+SHA1         \
                    +ECDHE-ECDSA:+3DES-CBC:+SHA1            \
                    +ECDHE-ECDSA:+AES-128-CBC:+SHA1         \
                    +ECDHE-ECDSA:+AES-256-CBC:+SHA1         \
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
                    "
                O_CIPHERS="$O_CIPHERS               \
                    ECDHE-ECDSA-NULL-SHA            \
                    ECDHE-ECDSA-RC4-SHA             \
                    ECDHE-ECDSA-DES-CBC3-SHA        \
                    ECDHE-ECDSA-AES128-SHA          \
                    ECDHE-ECDSA-AES256-SHA          \
                    "
            fi
            if [ "$MODE" = "tls1_2" ];
            then
                P_CIPHERS="$P_CIPHERS                               \
                    TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256         \
                    TLS-ECDHE-ECDSA-WITH-AES-256-CBC-SHA384         \
                    TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256         \
                    TLS-ECDHE-ECDSA-WITH-AES-256-GCM-SHA384         \
174 175 176 177 178 179
                    "
                G_CIPHERS="$G_CIPHERS                               \
                    +ECDHE-ECDSA:+AES-128-CBC:+SHA256               \
                    +ECDHE-ECDSA:+AES-256-CBC:+SHA384               \
                    +ECDHE-ECDSA:+AES-128-GCM:+AEAD                 \
                    +ECDHE-ECDSA:+AES-256-GCM:+AEAD                 \
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
                    "
                O_CIPHERS="$O_CIPHERS               \
                    ECDHE-ECDSA-AES128-SHA256       \
                    ECDHE-ECDSA-AES256-SHA384       \
                    ECDHE-ECDSA-AES128-GCM-SHA256   \
                    ECDHE-ECDSA-AES256-GCM-SHA384   \
                    "
            fi
            ;;

        "RSA")
            P_CIPHERS="$P_CIPHERS                       \
                TLS-DHE-RSA-WITH-AES-128-CBC-SHA        \
                TLS-DHE-RSA-WITH-AES-256-CBC-SHA        \
                TLS-DHE-RSA-WITH-CAMELLIA-128-CBC-SHA   \
                TLS-DHE-RSA-WITH-CAMELLIA-256-CBC-SHA   \
                TLS-DHE-RSA-WITH-3DES-EDE-CBC-SHA       \
                TLS-RSA-WITH-AES-256-CBC-SHA            \
                TLS-RSA-WITH-CAMELLIA-256-CBC-SHA       \
                TLS-RSA-WITH-AES-128-CBC-SHA            \
                TLS-RSA-WITH-CAMELLIA-128-CBC-SHA       \
                TLS-RSA-WITH-3DES-EDE-CBC-SHA           \
                TLS-RSA-WITH-RC4-128-SHA                \
                TLS-RSA-WITH-RC4-128-MD5                \
                TLS-RSA-WITH-NULL-MD5                   \
                TLS-RSA-WITH-NULL-SHA                   \
206
                TLS-RSA-WITH-NULL-SHA256                \
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
                "
            G_CIPHERS="$G_CIPHERS                       \
                +DHE-RSA:+AES-128-CBC:+SHA1             \
                +DHE-RSA:+AES-256-CBC:+SHA1             \
                +DHE-RSA:+CAMELLIA-128-CBC:+SHA1        \
                +DHE-RSA:+CAMELLIA-256-CBC:+SHA1        \
                +DHE-RSA:+3DES-CBC:+SHA1                \
                +RSA:+AES-256-CBC:+SHA1                 \
                +RSA:+CAMELLIA-256-CBC:+SHA1            \
                +RSA:+AES-128-CBC:+SHA1                 \
                +RSA:+CAMELLIA-128-CBC:+SHA1            \
                +RSA:+3DES-CBC:+SHA1                    \
                +RSA:+ARCFOUR-128:+SHA1                 \
                +RSA:+ARCFOUR-128:+MD5                  \
                +RSA:+NULL:+MD5                         \
                +RSA:+NULL:+SHA1                        \
223
                +RSA:+NULL:+SHA256                      \
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
                "
            O_CIPHERS="$O_CIPHERS               \
                DHE-RSA-AES128-SHA              \
                DHE-RSA-AES256-SHA              \
                DHE-RSA-CAMELLIA128-SHA         \
                DHE-RSA-CAMELLIA256-SHA         \
                EDH-RSA-DES-CBC3-SHA            \
                AES256-SHA                      \
                CAMELLIA256-SHA                 \
                AES128-SHA                      \
                CAMELLIA128-SHA                 \
                DES-CBC3-SHA                    \
                RC4-SHA                         \
                RC4-MD5                         \
                NULL-MD5                        \
                NULL-SHA                        \
                "
            if [ "$MODE" != "ssl3" ];
            then
                P_CIPHERS="$P_CIPHERS                       \
                    TLS-ECDHE-RSA-WITH-AES-128-CBC-SHA      \
                    TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA      \
                    TLS-ECDHE-RSA-WITH-3DES-EDE-CBC-SHA     \
                    TLS-ECDHE-RSA-WITH-RC4-128-SHA          \
                    TLS-ECDHE-RSA-WITH-NULL-SHA             \
                    "
250 251 252 253 254 255 256
                G_CIPHERS="$G_CIPHERS                       \
                    +ECDHE-RSA:+AES-128-CBC:+SHA1           \
                    +ECDHE-RSA:+AES-256-CBC:+SHA1           \
                    +ECDHE-RSA:+3DES-CBC:+SHA1              \
                    +ECDHE-RSA:+ARCFOUR-128:+SHA1           \
                    +ECDHE-RSA:+NULL:+SHA1                  \
                    "
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
                O_CIPHERS="$O_CIPHERS               \
                    ECDHE-RSA-AES256-SHA            \
                    ECDHE-RSA-AES128-SHA            \
                    ECDHE-RSA-DES-CBC3-SHA          \
                    ECDHE-RSA-RC4-SHA               \
                    ECDHE-RSA-NULL-SHA              \
                    "
            fi
            if [ "$MODE" = "tls1_2" ];
            then
                P_CIPHERS="$P_CIPHERS                       \
                    TLS-RSA-WITH-AES-128-CBC-SHA256         \
                    TLS-DHE-RSA-WITH-AES-128-CBC-SHA256     \
                    TLS-RSA-WITH-AES-256-CBC-SHA256         \
                    TLS-DHE-RSA-WITH-AES-256-CBC-SHA256     \
                    TLS-ECDHE-RSA-WITH-AES-128-CBC-SHA256   \
                    TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA384   \
                    TLS-RSA-WITH-AES-128-GCM-SHA256         \
                    TLS-RSA-WITH-AES-256-GCM-SHA384         \
                    TLS-DHE-RSA-WITH-AES-128-GCM-SHA256     \
                    TLS-DHE-RSA-WITH-AES-256-GCM-SHA384     \
                    TLS-ECDHE-RSA-WITH-AES-128-GCM-SHA256   \
                    TLS-ECDHE-RSA-WITH-AES-256-GCM-SHA384   \
                    "
281 282 283 284 285 286 287 288 289 290 291 292 293 294
                G_CIPHERS="$G_CIPHERS                       \
                    +RSA:+AES-128-CBC:+SHA256               \
                    +DHE-RSA:+AES-128-CBC:+SHA256           \
                    +RSA:+AES-256-CBC:+SHA256               \
                    +DHE-RSA:+AES-256-CBC:+SHA256           \
                    +ECDHE-RSA:+AES-128-CBC:+SHA256         \
                    +ECDHE-RSA:+AES-256-CBC:+SHA384         \
                    +RSA:+AES-128-GCM:+AEAD                 \
                    +RSA:+AES-256-GCM:+AEAD                 \
                    +DHE-RSA:+AES-128-GCM:+AEAD             \
                    +DHE-RSA:+AES-256-GCM:+AEAD             \
                    +ECDHE-RSA:+AES-128-GCM:+AEAD           \
                    +ECDHE-RSA:+AES-256-GCM:+AEAD           \
                    "
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319
                O_CIPHERS="$O_CIPHERS           \
                    NULL-SHA256                 \
                    AES128-SHA256               \
                    DHE-RSA-AES128-SHA256       \
                    AES256-SHA256               \
                    DHE-RSA-AES256-SHA256       \
                    ECDHE-RSA-AES128-SHA256     \
                    ECDHE-RSA-AES256-SHA384     \
                    AES128-GCM-SHA256           \
                    DHE-RSA-AES128-GCM-SHA256   \
                    AES256-GCM-SHA384           \
                    DHE-RSA-AES256-GCM-SHA384   \
                    ECDHE-RSA-AES128-GCM-SHA256 \
                    ECDHE-RSA-AES256-GCM-SHA384 \
                    "
            fi
            ;;

        "PSK")
            P_CIPHERS="$P_CIPHERS                       \
                TLS-PSK-WITH-RC4-128-SHA                \
                TLS-PSK-WITH-3DES-EDE-CBC-SHA           \
                TLS-PSK-WITH-AES-128-CBC-SHA            \
                TLS-PSK-WITH-AES-256-CBC-SHA            \
                "
320 321 322 323 324 325
            G_CIPHERS="$G_CIPHERS                       \
                +PSK:+ARCFOUR-128:+SHA1                 \
                +PSK:+3DES-CBC:+SHA1                    \
                +PSK:+AES-128-CBC:+SHA1                 \
                +PSK:+AES-256-CBC:+SHA1                 \
                "
326 327 328 329 330 331 332 333 334 335
            O_CIPHERS="$O_CIPHERS               \
                PSK-RC4-SHA                     \
                PSK-3DES-EDE-CBC-SHA            \
                PSK-AES128-CBC-SHA              \
                PSK-AES256-CBC-SHA              \
                "
            ;;
    esac
}

336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390
add_openssl_ciphersuites()
{
    case $TYPE in

        "ECDSA")
            if [ "$MODE" != "ssl3" ];
            then
                P_CIPHERS="$P_CIPHERS                       \
                    TLS-ECDH-ECDSA-WITH-NULL-SHA            \
                    TLS-ECDH-ECDSA-WITH-RC4-128-SHA         \
                    TLS-ECDH-ECDSA-WITH-3DES-EDE-CBC-SHA    \
                    TLS-ECDH-ECDSA-WITH-AES-128-CBC-SHA     \
                    TLS-ECDH-ECDSA-WITH-AES-256-CBC-SHA     \
                    "
                O_CIPHERS="$O_CIPHERS               \
                    ECDH-ECDSA-NULL-SHA             \
                    ECDH-ECDSA-RC4-SHA              \
                    ECDH-ECDSA-DES-CBC3-SHA         \
                    ECDH-ECDSA-AES128-SHA           \
                    ECDH-ECDSA-AES256-SHA           \
                    "
            fi
            if [ "$MODE" = "tls1_2" ];
            then
                P_CIPHERS="$P_CIPHERS                               \
                    TLS-ECDH-ECDSA-WITH-AES-128-CBC-SHA256          \
                    TLS-ECDH-ECDSA-WITH-AES-256-CBC-SHA384          \
                    TLS-ECDH-ECDSA-WITH-AES-128-GCM-SHA256          \
                    TLS-ECDH-ECDSA-WITH-AES-256-GCM-SHA384          \
                    "
                O_CIPHERS="$O_CIPHERS               \
                    ECDH-ECDSA-AES128-SHA256        \
                    ECDH-ECDSA-AES256-SHA384        \
                    ECDH-ECDSA-AES128-GCM-SHA256    \
                    ECDH-ECDSA-AES256-GCM-SHA384    \
                    "
            fi
            ;;

        "RSA")
            P_CIPHERS="$P_CIPHERS                       \
                TLS-RSA-WITH-DES-CBC-SHA                \
                TLS-DHE-RSA-WITH-DES-CBC-SHA            \
                "
            O_CIPHERS="$O_CIPHERS               \
                DES-CBC-SHA                     \
                EDH-RSA-DES-CBC-SHA             \
                "
            ;;

        "PSK")
            ;;
    esac
}

391
add_gnutls_ciphersuites()
392 393 394 395
{
    case $TYPE in

        "ECDSA")
396
            if [ "$MODE" = "tls1_2" ];
397
            then
398
                P_CIPHERS="$P_CIPHERS                               \
399 400 401 402
                    TLS-ECDHE-ECDSA-WITH-CAMELLIA-128-CBC-SHA256    \
                    TLS-ECDHE-ECDSA-WITH-CAMELLIA-256-CBC-SHA384    \
                    TLS-ECDHE-ECDSA-WITH-CAMELLIA-128-GCM-SHA256    \
                    TLS-ECDHE-ECDSA-WITH-CAMELLIA-256-GCM-SHA384    \
403 404 405 406 407 408 409
                   "
                G_CIPHERS="$G_CIPHERS                               \
                    +ECDHE-ECDSA:+CAMELLIA-128-CBC:+SHA256          \
                    +ECDHE-ECDSA:+CAMELLIA-256-CBC:+SHA384          \
                    +ECDHE-ECDSA:+CAMELLIA-128-GCM:+AEAD            \
                    +ECDHE-ECDSA:+CAMELLIA-256-GCM:+AEAD            \
                   "
410 411 412 413
            fi
            ;;

        "RSA")
414
            if [ "$MODE" = "tls1_2" ];
415
            then
416
                P_CIPHERS="$P_CIPHERS                           \
417 418 419 420 421 422 423 424 425 426 427 428
                    TLS-ECDHE-RSA-WITH-CAMELLIA-128-CBC-SHA256  \
                    TLS-ECDHE-RSA-WITH-CAMELLIA-256-CBC-SHA384  \
                    TLS-RSA-WITH-CAMELLIA-128-CBC-SHA256        \
                    TLS-RSA-WITH-CAMELLIA-256-CBC-SHA256        \
                    TLS-DHE-RSA-WITH-CAMELLIA-128-CBC-SHA256    \
                    TLS-DHE-RSA-WITH-CAMELLIA-256-CBC-SHA256    \
                    TLS-ECDHE-RSA-WITH-CAMELLIA-128-GCM-SHA256  \
                    TLS-ECDHE-RSA-WITH-CAMELLIA-256-GCM-SHA384  \
                    TLS-DHE-RSA-WITH-CAMELLIA-128-GCM-SHA256    \
                    TLS-DHE-RSA-WITH-CAMELLIA-256-GCM-SHA384    \
                    TLS-RSA-WITH-CAMELLIA-128-GCM-SHA256        \
                    TLS-RSA-WITH-CAMELLIA-256-GCM-SHA384        \
429 430 431 432 433 434 435 436 437 438 439 440 441 442
                    "
                G_CIPHERS="$G_CIPHERS                           \
                    +ECDHE-RSA:+CAMELLIA-128-CBC:+SHA256        \
                    +ECDHE-RSA:+CAMELLIA-256-CBC:+SHA384        \
                    +RSA:+CAMELLIA-128-CBC:+SHA256              \
                    +RSA:+CAMELLIA-256-CBC:+SHA256              \
                    +DHE-RSA:+CAMELLIA-128-CBC:+SHA256          \
                    +DHE-RSA:+CAMELLIA-256-CBC:+SHA256          \
                    +ECDHE-RSA:+CAMELLIA-128-GCM:+AEAD          \
                    +ECDHE-RSA:+CAMELLIA-256-GCM:+AEAD          \
                    +DHE-RSA:+CAMELLIA-128-GCM:+AEAD            \
                    +DHE-RSA:+CAMELLIA-256-GCM:+AEAD            \
                    +RSA:+CAMELLIA-128-GCM:+AEAD                \
                    +RSA:+CAMELLIA-256-GCM:+AEAD                \
443 444 445 446 447
                    "
            fi
            ;;

        "PSK")
448
            # GnuTLS 3.2.11 (2014-02-13) requires TLS 1.x for most *PSK suites
449 450
            if [ "$MODE" != "ssl3" ];
            then
451
                P_CIPHERS="$P_CIPHERS                           \
452 453 454
                    TLS-ECDHE-PSK-WITH-AES-256-CBC-SHA          \
                    TLS-ECDHE-PSK-WITH-AES-128-CBC-SHA          \
                    TLS-ECDHE-PSK-WITH-3DES-EDE-CBC-SHA         \
455 456 457 458 459 460
                    TLS-DHE-PSK-WITH-3DES-EDE-CBC-SHA           \
                    TLS-DHE-PSK-WITH-AES-128-CBC-SHA            \
                    TLS-DHE-PSK-WITH-AES-256-CBC-SHA            \
                    TLS-RSA-PSK-WITH-3DES-EDE-CBC-SHA           \
                    TLS-RSA-PSK-WITH-AES-256-CBC-SHA            \
                    TLS-RSA-PSK-WITH-AES-128-CBC-SHA            \
461 462 463 464 465 466 467 468 469 470 471
                    "
                G_CIPHERS="$G_CIPHERS                           \
                    +ECDHE-PSK:+AES-256-CBC:+SHA1               \
                    +ECDHE-PSK:+AES-128-CBC:+SHA1               \
                    +ECDHE-PSK:+3DES-CBC:+SHA1                  \
                    +DHE-PSK:+3DES-CBC:+SHA1                    \
                    +DHE-PSK:+AES-128-CBC:+SHA1                 \
                    +DHE-PSK:+AES-256-CBC:+SHA1                 \
                    +RSA-PSK:+3DES-CBC:+SHA1                    \
                    +RSA-PSK:+AES-256-CBC:+SHA1                 \
                    +RSA-PSK:+AES-128-CBC:+SHA1                 \
472 473 474 475 476
                    "
            fi
            if [ "$MODE" = "tls1_2" ];
            then
                P_CIPHERS="$P_CIPHERS                           \
477 478 479 480 481 482
                    TLS-ECDHE-PSK-WITH-AES-256-CBC-SHA384       \
                    TLS-ECDHE-PSK-WITH-CAMELLIA-256-CBC-SHA384  \
                    TLS-ECDHE-PSK-WITH-AES-128-CBC-SHA256       \
                    TLS-ECDHE-PSK-WITH-CAMELLIA-128-CBC-SHA256  \
                    TLS-ECDHE-PSK-WITH-NULL-SHA384              \
                    TLS-ECDHE-PSK-WITH-NULL-SHA256              \
483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500
                    TLS-PSK-WITH-AES-128-CBC-SHA256             \
                    TLS-PSK-WITH-AES-256-CBC-SHA384             \
                    TLS-DHE-PSK-WITH-AES-128-CBC-SHA256         \
                    TLS-DHE-PSK-WITH-AES-256-CBC-SHA384         \
                    TLS-PSK-WITH-NULL-SHA256                    \
                    TLS-PSK-WITH-NULL-SHA384                    \
                    TLS-DHE-PSK-WITH-NULL-SHA256                \
                    TLS-DHE-PSK-WITH-NULL-SHA384                \
                    TLS-RSA-PSK-WITH-AES-256-CBC-SHA384         \
                    TLS-RSA-PSK-WITH-AES-128-CBC-SHA256         \
                    TLS-RSA-PSK-WITH-NULL-SHA256                \
                    TLS-RSA-PSK-WITH-NULL-SHA384                \
                    TLS-DHE-PSK-WITH-CAMELLIA-128-CBC-SHA256    \
                    TLS-DHE-PSK-WITH-CAMELLIA-256-CBC-SHA384    \
                    TLS-PSK-WITH-CAMELLIA-128-CBC-SHA256        \
                    TLS-PSK-WITH-CAMELLIA-256-CBC-SHA384        \
                    TLS-RSA-PSK-WITH-CAMELLIA-256-CBC-SHA384    \
                    TLS-RSA-PSK-WITH-CAMELLIA-128-CBC-SHA256    \
501 502 503 504 505 506 507 508 509 510 511 512 513
                    TLS-PSK-WITH-AES-128-GCM-SHA256             \
                    TLS-PSK-WITH-AES-256-GCM-SHA384             \
                    TLS-DHE-PSK-WITH-AES-128-GCM-SHA256         \
                    TLS-DHE-PSK-WITH-AES-256-GCM-SHA384         \
                    TLS-RSA-PSK-WITH-CAMELLIA-128-GCM-SHA256    \
                    TLS-RSA-PSK-WITH-CAMELLIA-256-GCM-SHA384    \
                    TLS-PSK-WITH-CAMELLIA-128-GCM-SHA256        \
                    TLS-PSK-WITH-CAMELLIA-256-GCM-SHA384        \
                    TLS-DHE-PSK-WITH-CAMELLIA-128-GCM-SHA256    \
                    TLS-DHE-PSK-WITH-CAMELLIA-256-GCM-SHA384    \
                    TLS-RSA-PSK-WITH-AES-256-GCM-SHA384         \
                    TLS-RSA-PSK-WITH-AES-128-GCM-SHA256         \
                    "
514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542
                G_CIPHERS="$G_CIPHERS                           \
                    +ECDHE-PSK:+AES-256-CBC:+SHA384             \
                    +ECDHE-PSK:+CAMELLIA-256-CBC:+SHA384        \
                    +ECDHE-PSK:+AES-128-CBC:+SHA256             \
                    +ECDHE-PSK:+CAMELLIA-128-CBC:+SHA256        \
                    +PSK:+AES-128-CBC:+SHA256                   \
                    +PSK:+AES-256-CBC:+SHA384                   \
                    +DHE-PSK:+AES-128-CBC:+SHA256               \
                    +DHE-PSK:+AES-256-CBC:+SHA384               \
                    +RSA-PSK:+AES-256-CBC:+SHA384               \
                    +RSA-PSK:+AES-128-CBC:+SHA256               \
                    +DHE-PSK:+CAMELLIA-128-CBC:+SHA256          \
                    +DHE-PSK:+CAMELLIA-256-CBC:+SHA384          \
                    +PSK:+CAMELLIA-128-CBC:+SHA256              \
                    +PSK:+CAMELLIA-256-CBC:+SHA384              \
                    +RSA-PSK:+CAMELLIA-256-CBC:+SHA384          \
                    +RSA-PSK:+CAMELLIA-128-CBC:+SHA256          \
                    +PSK:+AES-128-GCM:+AEAD                     \
                    +PSK:+AES-256-GCM:+AEAD                     \
                    +DHE-PSK:+AES-128-GCM:+AEAD                 \
                    +DHE-PSK:+AES-256-GCM:+AEAD                 \
                    +RSA-PSK:+CAMELLIA-128-GCM:+AEAD            \
                    +RSA-PSK:+CAMELLIA-256-GCM:+AEAD            \
                    +PSK:+CAMELLIA-128-GCM:+AEAD                \
                    +PSK:+CAMELLIA-256-GCM:+AEAD                \
                    +DHE-PSK:+CAMELLIA-128-GCM:+AEAD            \
                    +DHE-PSK:+CAMELLIA-256-GCM:+AEAD            \
                    +RSA-PSK:+AES-256-GCM:+AEAD                 \
                    +RSA-PSK:+AES-128-GCM:+AEAD                 \
543 544 545 546 547 548 549 550
                    +ECDHE-PSK:+NULL:+SHA384                    \
                    +ECDHE-PSK:+NULL:+SHA256                    \
                    +PSK:+NULL:+SHA256                          \
                    +PSK:+NULL:+SHA384                          \
                    +DHE-PSK:+NULL:+SHA256                      \
                    +DHE-PSK:+NULL:+SHA384                      \
                    +RSA-PSK:+NULL:+SHA256                      \
                    +RSA-PSK:+NULL:+SHA384                      \
551
                    "
552 553 554
            fi
            ;;
    esac
555
}
556

557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596
add_polarssl_ciphersuites()
{
    case $TYPE in

        "ECDSA")
            if [ "$MODE" != "ssl3" ];
            then
                P_CIPHERS="$P_CIPHERS                               \
                    TLS-ECDH-ECDSA-WITH-CAMELLIA-128-CBC-SHA256     \
                    TLS-ECDH-ECDSA-WITH-CAMELLIA-256-CBC-SHA384     \
                    "
            fi
            if [ "$MODE" = "tls1_2" ];
            then
                P_CIPHERS="$P_CIPHERS                               \
                    TLS-ECDH-ECDSA-WITH-CAMELLIA-128-GCM-SHA256     \
                    TLS-ECDH-ECDSA-WITH-CAMELLIA-256-GCM-SHA384     \
                    "
            fi
            ;;

        "RSA")
            ;;

        "PSK")
            P_CIPHERS="$P_CIPHERS                        \
                TLS-PSK-WITH-NULL-SHA                    \
                TLS-DHE-PSK-WITH-RC4-128-SHA             \
                TLS-DHE-PSK-WITH-NULL-SHA                \
                TLS-RSA-PSK-WITH-RC4-128-SHA             \
                "
            if [ "$MODE" != "ssl3" ];
            then
                P_CIPHERS="$P_CIPHERS                    \
                    TLS-ECDHE-PSK-WITH-RC4-128-SHA       \
                    TLS-ECDHE-PSK-WITH-NULL-SHA          \
                    "
            fi
            ;;
    esac
597 598
}

599 600
setup_arguments()
{
601
    case $MODE in
602 603 604 605 606 607 608 609 610 611 612
        "ssl3")
            G_PRIO_MODE="+VERS-SSL3.0"
            ;;
        "tls1")
            G_PRIO_MODE="+VERS-TLS1.0"
            ;;
        "tls1_1")
            G_PRIO_MODE="+VERS-TLS1.1"
            ;;
        "tls1_2")
            G_PRIO_MODE="+VERS-TLS1.2"
613 614 615 616 617 618 619
            ;;
        *)
            echo "error: invalid mode: $MODE" >&2
            exit 1;
    esac

    P_SERVER_ARGS="server_addr=0.0.0.0 force_version=$MODE"
620 621
    O_SERVER_ARGS="-www -cipher NULL,ALL -$MODE"
    G_SERVER_ARGS="-p 4433 --http"
622
    G_SERVER_PRIO="EXPORT:+NULL:+MD5:+PSK:+DHE-PSK:+ECDHE-PSK:+RSA-PSK:-VERS-TLS-ALL:$G_PRIO_MODE"
623 624

    P_CLIENT_ARGS="force_version=$MODE"
625
    O_CLIENT_ARGS="-$MODE"
626
    G_CLIENT_ARGS="-p 4433 --debug 3"
627
    G_CLIENT_PRIO="NONE:$G_PRIO_MODE:+COMP-NULL:+CURVE-ALL:+SIGN-ALL"
628

629 630
    if [ "X$VERIFY" = "XYES" ];
    then
631 632
        P_SERVER_ARGS="$P_SERVER_ARGS ca_file=data_files/test-ca_cat12.crt auth_mode=required"
        O_SERVER_ARGS="$O_SERVER_ARGS -CAfile data_files/test-ca_cat12.crt -Verify 10"
633 634 635
        G_SERVER_ARGS="$G_SERVER_ARGS --x509cafile data_files/test-ca_cat12.crt --require-client-cert"

        P_CLIENT_ARGS="$P_CLIENT_ARGS ca_file=data_files/test-ca_cat12.crt auth_mode=required"
636
        O_CLIENT_ARGS="$O_CLIENT_ARGS -CAfile data_files/test-ca_cat12.crt -verify 10"
637
        G_CLIENT_ARGS="$G_CLIENT_ARGS --x509cafile data_files/test-ca_cat12.crt"
638
    else
639
        # don't request a client cert at all
640
        P_SERVER_ARGS="$P_SERVER_ARGS ca_file=none auth_mode=none"
641 642
        G_SERVER_ARGS="$G_SERVER_ARGS --disable-client-cert"

643 644 645
        P_CLIENT_ARGS="$P_CLIENT_ARGS ca_file=none auth_mode=none"
        O_CLIENT_ARGS="$O_CLIENT_ARGS"
        G_CLIENT_ARGS="$G_CLIENT_ARGS --insecure"
646 647 648 649
    fi

    case $TYPE in
        "ECDSA")
650 651
            P_SERVER_ARGS="$P_SERVER_ARGS crt_file=data_files/server5.crt key_file=data_files/server5.key"
            O_SERVER_ARGS="$O_SERVER_ARGS -cert data_files/server5.crt -key data_files/server5.key"
652 653
            G_SERVER_ARGS="$G_SERVER_ARGS --x509certfile data_files/server5.crt --x509keyfile data_files/server5.key"

654 655 656
            if [ "X$VERIFY" = "XYES" ]; then
                P_CLIENT_ARGS="$P_CLIENT_ARGS crt_file=data_files/server6.crt key_file=data_files/server6.key"
                O_CLIENT_ARGS="$O_CLIENT_ARGS -cert data_files/server6.crt -key data_files/server6.key"
657
                G_CLIENT_ARGS="$G_CLIENT_ARGS --x509certfile data_files/server6.crt --x509keyfile data_files/server6.key"
658 659 660
            else
                P_CLIENT_ARGS="$P_CLIENT_ARGS crt_file=none key_file=none"
            fi
661 662 663
            ;;

        "RSA")
664 665
            P_SERVER_ARGS="$P_SERVER_ARGS crt_file=data_files/server2.crt key_file=data_files/server2.key"
            O_SERVER_ARGS="$O_SERVER_ARGS -cert data_files/server2.crt -key data_files/server2.key"
666 667
            G_SERVER_ARGS="$G_SERVER_ARGS --x509certfile data_files/server2.crt --x509keyfile data_files/server2.key"

668 669 670
            if [ "X$VERIFY" = "XYES" ]; then
                P_CLIENT_ARGS="$P_CLIENT_ARGS crt_file=data_files/server1.crt key_file=data_files/server1.key"
                O_CLIENT_ARGS="$O_CLIENT_ARGS -cert data_files/server1.crt -key data_files/server1.key"
671
                G_CLIENT_ARGS="$G_CLIENT_ARGS --x509certfile data_files/server1.crt --x509keyfile data_files/server1.key"
672 673 674
            else
                P_CLIENT_ARGS="$P_CLIENT_ARGS crt_file=none key_file=none"
            fi
675 676 677
            ;;

        "PSK")
678
            # give RSA-PSK-capable server a RSA cert
679 680 681
            # (should be a separate type, but harder to close with openssl)
            P_SERVER_ARGS="$P_SERVER_ARGS psk=6162636465666768696a6b6c6d6e6f70 ca_file=none crt_file=data_files/server2.crt key_file=data_files/server2.key"
            O_SERVER_ARGS="$O_SERVER_ARGS -psk 6162636465666768696a6b6c6d6e6f70 -nocert"
682 683 684
            G_SERVER_ARGS="$G_SERVER_ARGS --x509certfile data_files/server2.crt --x509keyfile data_files/server2.key --pskpasswd data_files/passwd.psk"

            P_CLIENT_ARGS="$P_CLIENT_ARGS psk=6162636465666768696a6b6c6d6e6f70 crt_file=none key_file=none"
685
            O_CLIENT_ARGS="$O_CLIENT_ARGS -psk 6162636465666768696a6b6c6d6e6f70"
686
            G_CLIENT_ARGS="$G_CLIENT_ARGS --pskusername Client_identity --pskkey=6162636465666768696a6b6c6d6e6f70"
687 688 689 690
            ;;
    esac
}

691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706
# is_polar <cmd_line>
is_polar() {
    echo "$1" | grep 'ssl_server2\|ssl_client2' > /dev/null
}

# has_mem_err <log_file_name>
has_mem_err() {
    if ( grep -F 'All heap blocks were freed -- no leaks are possible' "$1" &&
         grep -F 'ERROR SUMMARY: 0 errors from 0 contexts' "$1" ) > /dev/null
    then
        return 1 # false: does not have errors
    else
        return 0 # true: has errors
    fi
}

707 708 709 710 711
# start_server <name>
# also saves name and command
start_server() {
    case $1 in
        [Oo]pen*)
712
            SERVER_CMD="$OPENSSL_CMD s_server $O_SERVER_ARGS"
713
            ;;
714
        [Gg]nu*)
715
            SERVER_CMD="$GNUTLS_SERV $G_SERVER_ARGS --priority $G_SERVER_PRIO"
716
            ;;
717
        [Pp]olar*)
718
            SERVER_CMD="$P_SRV $P_SERVER_ARGS"
719 720 721
            if [ "$MEMCHECK" -gt 0 ]; then
                SERVER_CMD="valgrind --leak-check=full $SERVER_CMD"
            fi
722 723 724 725 726 727 728 729 730
            ;;
        *)
            echo "error: invalid server name: $1" >&2
            exit 1
            ;;
    esac
    SERVER_NAME=$1

    log "$SERVER_CMD"
731 732
    echo "$SERVER_CMD" > srv_out
    $SERVER_CMD >> srv_out 2>&1 &
733 734 735 736 737
    PROCESS_ID=$!

    sleep 1
}

738
# terminate the running server (closing it cleanly if it is ours)
739
stop_server() {
740 741
    case $SERVER_NAME in
        [Pp]olar*)
742
            # we must force a PSK suite when in PSK mode (otherwise client
743 744 745
            # auth will fail), so try every entry in $P_CIPHERS in turn (in
            # case the first one is not implemented in this configuration)
            for i in $P_CIPHERS; do
746
                log "$P_CLI $P_CLIENT_ARGS request_page=SERVERQUIT auth_mode=none force_ciphersuite=$i"
747 748 749 750 751 752
                "$P_CLI" $P_CLIENT_ARGS request_page=SERVERQUIT auth_mode=none \
                    force_ciphersuite=$i >/dev/null
                if [ "$?" == 0 ]; then
                    break
                fi
            done
753
            ;;
754 755
        *)
            kill $PROCESS_ID 2>/dev/null
756 757
    esac

758
    wait $PROCESS_ID 2>/dev/null
759 760 761 762 763 764 765 766 767

    if [ "$MEMCHECK" -gt 0 ]; then
        if is_polar "$SERVER_CMD" && has_mem_err srv_out; then
            echo "  ! Server had memory errors"
            let "srvmem++"
            return
        fi
    fi

768
    rm -f srv_out
769 770
}

771 772
# kill the running server (used when killed by signal)
cleanup() {
773
    rm -f srv_out cli_out
774 775 776 777
    kill $PROCESS_ID
    exit 1
}

778 779
# run_client <name> <cipher>
run_client() {
780 781 782
    # announce what we're going to do
    let "tests++"
    VERIF=$(echo $VERIFY | tr '[:upper:]' '[:lower:]')
783 784
    TITLE="${1:0:1}->${SERVER_NAME:0:1} $MODE,$VERIF $2"
    echo -n "$TITLE "
785 786 787 788
    LEN=`echo "$TITLE" | wc -c`
    LEN=`echo 72 - $LEN | bc`
    for i in `seq 1 $LEN`; do echo -n '.'; done; echo -n ' '

789 790 791
    # run the command and interpret result
    case $1 in
        [Oo]pen*)
792
            CLIENT_CMD="$OPENSSL_CMD s_client $O_CLIENT_ARGS -cipher $2"
793
            log "$CLIENT_CMD"
794 795
            echo "$CLIENT_CMD" > cli_out
            ( echo -e 'GET HTTP/1.0'; echo; ) | $CLIENT_CMD >> cli_out 2>&1
796 797 798 799 800
            EXIT=$?

            if [ "$EXIT" == "0" ]; then
                RESULT=0
            else
801
                if grep 'Cipher is (NONE)' cli_out >/dev/null; then
802 803 804 805 806 807 808
                    RESULT=1
                else
                    RESULT=2
                fi
            fi
            ;;

809
        [Gg]nu*)
810
            CLIENT_CMD="$GNUTLS_CLI $G_CLIENT_ARGS --priority $G_PRIO_MODE:$2 localhost"
811
            log "$CLIENT_CMD"
812 813
            echo "$CLIENT_CMD" > cli_out
            ( echo -e 'GET HTTP/1.0'; echo; ) | $CLIENT_CMD >> cli_out 2>&1
814 815 816 817 818
            EXIT=$?

            if [ "$EXIT" == "0" ]; then
                RESULT=0
            else
819 820 821 822 823 824 825 826 827
                RESULT=2
                # interpret early failure, with a handshake_failure alert
                # before the server hello, as "no ciphersuite in common"
                if grep -F 'Received alert [40]: Handshake failed' cli_out; then
                    if grep -i 'SERVER HELLO .* was received' cli_out; then :
                    else
                        RESULT=1
                    fi
                fi >/dev/null
828 829 830
            fi
            ;;

831
        [Pp]olar*)
832
            CLIENT_CMD="$P_CLI $P_CLIENT_ARGS force_ciphersuite=$2"
833 834 835
            if [ "$MEMCHECK" -gt 0 ]; then
                CLIENT_CMD="valgrind --leak-check=full $CLIENT_CMD"
            fi
836
            log "$CLIENT_CMD"
837 838
            echo "$CLIENT_CMD" > cli_out
            $CLIENT_CMD >> cli_out 2>&1
839 840 841 842 843 844 845
            EXIT=$?

            case $EXIT in
                "0")    RESULT=0    ;;
                "2")    RESULT=1    ;;
                *)      RESULT=2    ;;
            esac
846 847 848 849 850 851 852

            if [ "$MEMCHECK" -gt 0 ]; then
                if is_polar "$CLIENT_CMD" && has_mem_err cli_out; then
                    RESULT=2
                fi
            fi

853 854 855 856 857 858 859 860
            ;;

        *)
            echo "error: invalid client name: $1" >&2
            exit 1
            ;;
    esac

861 862
    echo "EXIT: $EXIT" >> cli_out

863 864 865
    # report and count result
    case $RESULT in
        "0")
866
            echo PASS
867 868
            ;;
        "1")
869
            echo SKIP
870 871 872
            let "skipped++"
            ;;
        "2")
873
            echo FAIL
874 875 876
            cp srv_out c-srv-${tests}.log
            cp cli_out c-cli-${tests}.log
            echo "  ! outputs saved to c-srv-${tests}.log, c-cli-${tests}.log"
877 878 879
            let "failed++"
            ;;
    esac
880 881

    rm -f cli_out
882 883
}

884 885 886 887
#
# MAIN
#

888 889
get_options "$@"

890 891
# sanity checks, avoid an avalanche of errors
if [ ! -x "$P_SRV" ]; then
892
    echo "Command '$P_SRV' is not an executable file" >&2
893 894 895
    exit 1
fi
if [ ! -x "$P_CLI" ]; then
896
    echo "Command '$P_CLI' is not an executable file" >&2
897 898
    exit 1
fi
899 900 901 902

if echo "$PEERS" | grep -i openssl > /dev/null; then
    if which "$OPENSSL_CMD" >/dev/null 2>&1; then :; else
        echo "Command '$OPENSSL_CMD' not found" >&2
903 904
        exit 1
    fi
905
fi
906

907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924
if echo "$PEERS" | grep -i gnutls > /dev/null; then
    for CMD in "$GNUTLS_CLI" "$GNUTLS_SERV"; do
        if which "$CMD" >/dev/null 2>&1; then :; else
            echo "Command '$CMD' not found" >&2
            exit 1
        fi
    done
fi

for PEER in $PEERS; do
    case "$PEER" in
        [Pp]olar*|[Oo]pen*|[Gg]nu*)
            ;;
        *)
            echo "Unknown peers: $PEER" >&2
            exit 1
    esac
done
925

926
killall -q gnutls-serv openssl ssl_server ssl_server2
927 928
trap cleanup INT TERM HUP

929 930 931
for VERIFY in $VERIFIES; do
    for MODE in $MODES; do
        for TYPE in $TYPES; do
932
            for PEER in $PEERS; do
933

934
            setup_arguments
935

936 937 938 939 940
            case "$PEER" in

                [Oo]pen*)

                    reset_ciphersuites
941
                    add_common_ciphersuites
942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965
                    add_openssl_ciphersuites
                    filter_ciphersuites

                    if [ "X" != "X$P_CIPHERS" ]; then
                        start_server "OpenSSL"
                        for i in $P_CIPHERS; do
                            run_client PolarSSL $i
                        done
                        stop_server
                    fi

                    if [ "X" != "X$O_CIPHERS" ]; then
                        start_server "PolarSSL"
                        for i in $O_CIPHERS; do
                            run_client OpenSSL $i
                        done
                        stop_server
                    fi

                    ;;

                [Gg]nu*)

                    reset_ciphersuites
966
                    add_common_ciphersuites
967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990
                    add_gnutls_ciphersuites
                    filter_ciphersuites

                    if [ "X" != "X$P_CIPHERS" ]; then
                        start_server "GnuTLS"
                        for i in $P_CIPHERS; do
                            run_client PolarSSL $i
                        done
                        stop_server
                    fi

                    if [ "X" != "X$G_CIPHERS" ]; then
                        start_server "PolarSSL"
                        for i in $G_CIPHERS; do
                            run_client GnuTLS $i
                        done
                        stop_server
                    fi

                    ;;

                [Pp]olar*)

                    reset_ciphersuites
991
                    add_common_ciphersuites
992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006
                    add_openssl_ciphersuites
                    add_gnutls_ciphersuites
                    add_polarssl_ciphersuites
                    filter_ciphersuites

                    if [ "X" != "X$P_CIPHERS" ]; then
                        start_server "PolarSSL"
                        for i in $P_CIPHERS; do
                            run_client PolarSSL $i
                        done
                        stop_server
                    fi

                    ;;

1007 1008 1009 1010 1011
                *)
                    echo "Unkown peer: $PEER" >&2
                    exit 1
                    ;;

1012 1013 1014
                esac

            done
1015 1016
        done
    done
1017
done
1018

1019
echo "------------------------------------------------------------------------"
1020

1021
if (( failed != 0 && srvmem != 0 ));
1022 1023 1024 1025 1026 1027
then
    echo -n "FAILED"
else
    echo -n "PASSED"
fi

1028 1029 1030 1031 1032 1033
if [ "$MEMCHECK" -gt 0 ]; then
    MEMREPORT=", $srvmem server memory errors"
else
    MEMREPORT=""
fi

1034
let "passed = tests - failed"
1035
echo " ($passed / $tests tests ($skipped skipped$MEMREPORT))"
1036

1037
let "failed += srvmem"
1038
exit $failed