compat.sh 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431
  1. #!/bin/sh
  2. # compat.sh
  3. #
  4. # Copyright The Mbed TLS Contributors
  5. # SPDX-License-Identifier: Apache-2.0
  6. #
  7. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  8. # not use this file except in compliance with the License.
  9. # You may obtain a copy of the License at
  10. #
  11. # http://www.apache.org/licenses/LICENSE-2.0
  12. #
  13. # Unless required by applicable law or agreed to in writing, software
  14. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. # See the License for the specific language governing permissions and
  17. # limitations under the License.
  18. #
  19. # Purpose
  20. #
  21. # Test interoperbility with OpenSSL, GnuTLS as well as itself.
  22. #
  23. # Check each common ciphersuite, with each version, both ways (client/server),
  24. # with and without client authentication.
  25. set -u
  26. # Limit the size of each log to 10 GiB, in case of failures with this script
  27. # where it may output seemingly unlimited length error logs.
  28. ulimit -f 20971520
  29. # initialise counters
  30. TESTS=0
  31. FAILED=0
  32. SKIPPED=0
  33. SRVMEM=0
  34. # default commands, can be overridden by the environment
  35. : ${M_SRV:=../programs/ssl/ssl_server2}
  36. : ${M_CLI:=../programs/ssl/ssl_client2}
  37. : ${OPENSSL_CMD:=openssl} # OPENSSL would conflict with the build system
  38. : ${GNUTLS_CLI:=gnutls-cli}
  39. : ${GNUTLS_SERV:=gnutls-serv}
  40. # do we have a recent enough GnuTLS?
  41. if ( which $GNUTLS_CLI && which $GNUTLS_SERV ) >/dev/null 2>&1; then
  42. G_VER="$( $GNUTLS_CLI --version | head -n1 )"
  43. if echo "$G_VER" | grep '@VERSION@' > /dev/null; then # git version
  44. PEER_GNUTLS=" GnuTLS"
  45. else
  46. eval $( echo $G_VER | sed 's/.* \([0-9]*\)\.\([0-9]\)*\.\([0-9]*\)$/MAJOR="\1" MINOR="\2" PATCH="\3"/' )
  47. if [ $MAJOR -lt 3 -o \
  48. \( $MAJOR -eq 3 -a $MINOR -lt 2 \) -o \
  49. \( $MAJOR -eq 3 -a $MINOR -eq 2 -a $PATCH -lt 15 \) ]
  50. then
  51. PEER_GNUTLS=""
  52. else
  53. PEER_GNUTLS=" GnuTLS"
  54. if [ $MINOR -lt 4 ]; then
  55. GNUTLS_MINOR_LT_FOUR='x'
  56. fi
  57. fi
  58. fi
  59. else
  60. PEER_GNUTLS=""
  61. fi
  62. # default values for options
  63. MODES="tls1 tls1_1 tls12 dtls1 dtls12"
  64. VERIFIES="NO YES"
  65. TYPES="ECDSA RSA PSK"
  66. FILTER=""
  67. # exclude:
  68. # - NULL: excluded from our default config
  69. # - RC4, single-DES: requires legacy OpenSSL/GnuTLS versions
  70. # avoid plain DES but keep 3DES-EDE-CBC (mbedTLS), DES-CBC3 (OpenSSL)
  71. # - ARIA: not in default config.h + requires OpenSSL >= 1.1.1
  72. # - ChachaPoly: requires OpenSSL >= 1.1.0
  73. # - 3DES: not in default config
  74. EXCLUDE='NULL\|DES\|RC4\|ARCFOUR\|ARIA\|CHACHA20-POLY1305'
  75. VERBOSE=""
  76. MEMCHECK=0
  77. PEERS="OpenSSL$PEER_GNUTLS mbedTLS"
  78. # hidden option: skip DTLS with OpenSSL
  79. # (travis CI has a version that doesn't work for us)
  80. : ${OSSL_NO_DTLS:=0}
  81. print_usage() {
  82. echo "Usage: $0"
  83. printf " -h|--help\tPrint this help.\n"
  84. printf " -f|--filter\tOnly matching ciphersuites are tested (Default: '%s')\n" "$FILTER"
  85. printf " -e|--exclude\tMatching ciphersuites are excluded (Default: '%s')\n" "$EXCLUDE"
  86. printf " -m|--modes\tWhich modes to perform (Default: '%s')\n" "$MODES"
  87. printf " -t|--types\tWhich key exchange type to perform (Default: '%s')\n" "$TYPES"
  88. printf " -V|--verify\tWhich verification modes to perform (Default: '%s')\n" "$VERIFIES"
  89. printf " -p|--peers\tWhich peers to use (Default: '%s')\n" "$PEERS"
  90. printf " \tAlso available: GnuTLS (needs v3.2.15 or higher)\n"
  91. printf " -M|--memcheck\tCheck memory leaks and errors.\n"
  92. printf " -v|--verbose\tSet verbose output.\n"
  93. }
  94. get_options() {
  95. while [ $# -gt 0 ]; do
  96. case "$1" in
  97. -f|--filter)
  98. shift; FILTER=$1
  99. ;;
  100. -e|--exclude)
  101. shift; EXCLUDE=$1
  102. ;;
  103. -m|--modes)
  104. shift; MODES=$1
  105. ;;
  106. -t|--types)
  107. shift; TYPES=$1
  108. ;;
  109. -V|--verify)
  110. shift; VERIFIES=$1
  111. ;;
  112. -p|--peers)
  113. shift; PEERS=$1
  114. ;;
  115. -v|--verbose)
  116. VERBOSE=1
  117. ;;
  118. -M|--memcheck)
  119. MEMCHECK=1
  120. ;;
  121. -h|--help)
  122. print_usage
  123. exit 0
  124. ;;
  125. *)
  126. echo "Unknown argument: '$1'"
  127. print_usage
  128. exit 1
  129. ;;
  130. esac
  131. shift
  132. done
  133. # sanitize some options (modes checked later)
  134. VERIFIES="$( echo $VERIFIES | tr [a-z] [A-Z] )"
  135. TYPES="$( echo $TYPES | tr [a-z] [A-Z] )"
  136. }
  137. log() {
  138. if [ "X" != "X$VERBOSE" ]; then
  139. echo ""
  140. echo "$@"
  141. fi
  142. }
  143. # is_dtls <mode>
  144. is_dtls()
  145. {
  146. test "$1" = "dtls1" -o "$1" = "dtls12"
  147. }
  148. # minor_ver <mode>
  149. minor_ver()
  150. {
  151. case "$1" in
  152. ssl3)
  153. echo 0
  154. ;;
  155. tls1)
  156. echo 1
  157. ;;
  158. tls1_1|dtls1)
  159. echo 2
  160. ;;
  161. tls12|dtls12)
  162. echo 3
  163. ;;
  164. *)
  165. echo "error: invalid mode: $MODE" >&2
  166. # exiting is no good here, typically called in a subshell
  167. echo -1
  168. esac
  169. }
  170. filter()
  171. {
  172. LIST="$1"
  173. NEW_LIST=""
  174. if is_dtls "$MODE"; then
  175. EXCLMODE="$EXCLUDE"'\|RC4\|ARCFOUR'
  176. else
  177. EXCLMODE="$EXCLUDE"
  178. fi
  179. for i in $LIST;
  180. do
  181. NEW_LIST="$NEW_LIST $( echo "$i" | grep "$FILTER" | grep -v "$EXCLMODE" )"
  182. done
  183. # normalize whitespace
  184. echo "$NEW_LIST" | sed -e 's/[[:space:]][[:space:]]*/ /g' -e 's/^ //' -e 's/ $//'
  185. }
  186. # OpenSSL 1.0.1h with -Verify wants a ClientCertificate message even for
  187. # PSK ciphersuites with DTLS, which is incorrect, so disable them for now
  188. check_openssl_server_bug()
  189. {
  190. if test "X$VERIFY" = "XYES" && is_dtls "$MODE" && \
  191. echo "$1" | grep "^TLS-PSK" >/dev/null;
  192. then
  193. SKIP_NEXT="YES"
  194. fi
  195. }
  196. filter_ciphersuites()
  197. {
  198. if [ "X" != "X$FILTER" -o "X" != "X$EXCLUDE" ];
  199. then
  200. # Ciphersuite for mbed TLS
  201. M_CIPHERS=$( filter "$M_CIPHERS" )
  202. # Ciphersuite for OpenSSL
  203. O_CIPHERS=$( filter "$O_CIPHERS" )
  204. # Ciphersuite for GnuTLS
  205. G_CIPHERS=$( filter "$G_CIPHERS" )
  206. fi
  207. # OpenSSL <1.0.2 doesn't support DTLS 1.2. Check what OpenSSL
  208. # supports from the s_server help. (The s_client help isn't
  209. # accurate as of 1.0.2g: it supports DTLS 1.2 but doesn't list it.
  210. # But the s_server help seems to be accurate.)
  211. if ! $OPENSSL_CMD s_server -help 2>&1 | grep -q "^ *-$MODE "; then
  212. M_CIPHERS=""
  213. O_CIPHERS=""
  214. fi
  215. # For GnuTLS client -> mbed TLS server,
  216. # we need to force IPv4 by connecting to 127.0.0.1 but then auth fails
  217. if [ "X$VERIFY" = "XYES" ] && is_dtls "$MODE"; then
  218. G_CIPHERS=""
  219. fi
  220. }
  221. reset_ciphersuites()
  222. {
  223. M_CIPHERS=""
  224. O_CIPHERS=""
  225. G_CIPHERS=""
  226. }
  227. # Ciphersuites that can be used with all peers.
  228. # Since we currently have three possible peers, each ciphersuite should appear
  229. # three times: in each peer's list (with the name that this peer uses).
  230. add_common_ciphersuites()
  231. {
  232. case $TYPE in
  233. "ECDSA")
  234. if [ `minor_ver "$MODE"` -gt 0 ]
  235. then
  236. M_CIPHERS="$M_CIPHERS \
  237. TLS-ECDHE-ECDSA-WITH-NULL-SHA \
  238. TLS-ECDHE-ECDSA-WITH-RC4-128-SHA \
  239. TLS-ECDHE-ECDSA-WITH-3DES-EDE-CBC-SHA \
  240. TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA \
  241. TLS-ECDHE-ECDSA-WITH-AES-256-CBC-SHA \
  242. "
  243. G_CIPHERS="$G_CIPHERS \
  244. +ECDHE-ECDSA:+NULL:+SHA1 \
  245. +ECDHE-ECDSA:+ARCFOUR-128:+SHA1 \
  246. +ECDHE-ECDSA:+3DES-CBC:+SHA1 \
  247. +ECDHE-ECDSA:+AES-128-CBC:+SHA1 \
  248. +ECDHE-ECDSA:+AES-256-CBC:+SHA1 \
  249. "
  250. O_CIPHERS="$O_CIPHERS \
  251. ECDHE-ECDSA-NULL-SHA \
  252. ECDHE-ECDSA-RC4-SHA \
  253. ECDHE-ECDSA-DES-CBC3-SHA \
  254. ECDHE-ECDSA-AES128-SHA \
  255. ECDHE-ECDSA-AES256-SHA \
  256. "
  257. fi
  258. if [ `minor_ver "$MODE"` -ge 3 ]
  259. then
  260. M_CIPHERS="$M_CIPHERS \
  261. TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256 \
  262. TLS-ECDHE-ECDSA-WITH-AES-256-CBC-SHA384 \
  263. TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
  264. TLS-ECDHE-ECDSA-WITH-AES-256-GCM-SHA384 \
  265. "
  266. G_CIPHERS="$G_CIPHERS \
  267. +ECDHE-ECDSA:+AES-128-CBC:+SHA256 \
  268. +ECDHE-ECDSA:+AES-256-CBC:+SHA384 \
  269. +ECDHE-ECDSA:+AES-128-GCM:+AEAD \
  270. +ECDHE-ECDSA:+AES-256-GCM:+AEAD \
  271. "
  272. O_CIPHERS="$O_CIPHERS \
  273. ECDHE-ECDSA-AES128-SHA256 \
  274. ECDHE-ECDSA-AES256-SHA384 \
  275. ECDHE-ECDSA-AES128-GCM-SHA256 \
  276. ECDHE-ECDSA-AES256-GCM-SHA384 \
  277. "
  278. fi
  279. ;;
  280. "RSA")
  281. M_CIPHERS="$M_CIPHERS \
  282. TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
  283. TLS-DHE-RSA-WITH-AES-256-CBC-SHA \
  284. TLS-DHE-RSA-WITH-CAMELLIA-128-CBC-SHA \
  285. TLS-DHE-RSA-WITH-CAMELLIA-256-CBC-SHA \
  286. TLS-DHE-RSA-WITH-3DES-EDE-CBC-SHA \
  287. TLS-RSA-WITH-AES-256-CBC-SHA \
  288. TLS-RSA-WITH-CAMELLIA-256-CBC-SHA \
  289. TLS-RSA-WITH-AES-128-CBC-SHA \
  290. TLS-RSA-WITH-CAMELLIA-128-CBC-SHA \
  291. TLS-RSA-WITH-3DES-EDE-CBC-SHA \
  292. TLS-RSA-WITH-RC4-128-SHA \
  293. TLS-RSA-WITH-RC4-128-MD5 \
  294. TLS-RSA-WITH-NULL-MD5 \
  295. TLS-RSA-WITH-NULL-SHA \
  296. "
  297. G_CIPHERS="$G_CIPHERS \
  298. +DHE-RSA:+AES-128-CBC:+SHA1 \
  299. +DHE-RSA:+AES-256-CBC:+SHA1 \
  300. +DHE-RSA:+CAMELLIA-128-CBC:+SHA1 \
  301. +DHE-RSA:+CAMELLIA-256-CBC:+SHA1 \
  302. +DHE-RSA:+3DES-CBC:+SHA1 \
  303. +RSA:+AES-256-CBC:+SHA1 \
  304. +RSA:+CAMELLIA-256-CBC:+SHA1 \
  305. +RSA:+AES-128-CBC:+SHA1 \
  306. +RSA:+CAMELLIA-128-CBC:+SHA1 \
  307. +RSA:+3DES-CBC:+SHA1 \
  308. +RSA:+ARCFOUR-128:+SHA1 \
  309. +RSA:+ARCFOUR-128:+MD5 \
  310. +RSA:+NULL:+MD5 \
  311. +RSA:+NULL:+SHA1 \
  312. "
  313. O_CIPHERS="$O_CIPHERS \
  314. DHE-RSA-AES128-SHA \
  315. DHE-RSA-AES256-SHA \
  316. DHE-RSA-CAMELLIA128-SHA \
  317. DHE-RSA-CAMELLIA256-SHA \
  318. EDH-RSA-DES-CBC3-SHA \
  319. AES256-SHA \
  320. CAMELLIA256-SHA \
  321. AES128-SHA \
  322. CAMELLIA128-SHA \
  323. DES-CBC3-SHA \
  324. RC4-SHA \
  325. RC4-MD5 \
  326. NULL-MD5 \
  327. NULL-SHA \
  328. "
  329. if [ `minor_ver "$MODE"` -gt 0 ]
  330. then
  331. M_CIPHERS="$M_CIPHERS \
  332. TLS-ECDHE-RSA-WITH-AES-128-CBC-SHA \
  333. TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA \
  334. TLS-ECDHE-RSA-WITH-3DES-EDE-CBC-SHA \
  335. TLS-ECDHE-RSA-WITH-RC4-128-SHA \
  336. TLS-ECDHE-RSA-WITH-NULL-SHA \
  337. "
  338. G_CIPHERS="$G_CIPHERS \
  339. +ECDHE-RSA:+AES-128-CBC:+SHA1 \
  340. +ECDHE-RSA:+AES-256-CBC:+SHA1 \
  341. +ECDHE-RSA:+3DES-CBC:+SHA1 \
  342. +ECDHE-RSA:+ARCFOUR-128:+SHA1 \
  343. +ECDHE-RSA:+NULL:+SHA1 \
  344. "
  345. O_CIPHERS="$O_CIPHERS \
  346. ECDHE-RSA-AES256-SHA \
  347. ECDHE-RSA-AES128-SHA \
  348. ECDHE-RSA-DES-CBC3-SHA \
  349. ECDHE-RSA-RC4-SHA \
  350. ECDHE-RSA-NULL-SHA \
  351. "
  352. fi
  353. if [ `minor_ver "$MODE"` -ge 3 ]
  354. then
  355. M_CIPHERS="$M_CIPHERS \
  356. TLS-RSA-WITH-AES-128-CBC-SHA256 \
  357. TLS-DHE-RSA-WITH-AES-128-CBC-SHA256 \
  358. TLS-RSA-WITH-AES-256-CBC-SHA256 \
  359. TLS-DHE-RSA-WITH-AES-256-CBC-SHA256 \
  360. TLS-ECDHE-RSA-WITH-AES-128-CBC-SHA256 \
  361. TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA384 \
  362. TLS-RSA-WITH-AES-128-GCM-SHA256 \
  363. TLS-RSA-WITH-AES-256-GCM-SHA384 \
  364. TLS-DHE-RSA-WITH-AES-128-GCM-SHA256 \
  365. TLS-DHE-RSA-WITH-AES-256-GCM-SHA384 \
  366. TLS-ECDHE-RSA-WITH-AES-128-GCM-SHA256 \
  367. TLS-ECDHE-RSA-WITH-AES-256-GCM-SHA384 \
  368. "
  369. G_CIPHERS="$G_CIPHERS \
  370. +RSA:+AES-128-CBC:+SHA256 \
  371. +DHE-RSA:+AES-128-CBC:+SHA256 \
  372. +RSA:+AES-256-CBC:+SHA256 \
  373. +DHE-RSA:+AES-256-CBC:+SHA256 \
  374. +ECDHE-RSA:+AES-128-CBC:+SHA256 \
  375. +ECDHE-RSA:+AES-256-CBC:+SHA384 \
  376. +RSA:+AES-128-GCM:+AEAD \
  377. +RSA:+AES-256-GCM:+AEAD \
  378. +DHE-RSA:+AES-128-GCM:+AEAD \
  379. +DHE-RSA:+AES-256-GCM:+AEAD \
  380. +ECDHE-RSA:+AES-128-GCM:+AEAD \
  381. +ECDHE-RSA:+AES-256-GCM:+AEAD \
  382. "
  383. O_CIPHERS="$O_CIPHERS \
  384. NULL-SHA256 \
  385. AES128-SHA256 \
  386. DHE-RSA-AES128-SHA256 \
  387. AES256-SHA256 \
  388. DHE-RSA-AES256-SHA256 \
  389. ECDHE-RSA-AES128-SHA256 \
  390. ECDHE-RSA-AES256-SHA384 \
  391. AES128-GCM-SHA256 \
  392. DHE-RSA-AES128-GCM-SHA256 \
  393. AES256-GCM-SHA384 \
  394. DHE-RSA-AES256-GCM-SHA384 \
  395. ECDHE-RSA-AES128-GCM-SHA256 \
  396. ECDHE-RSA-AES256-GCM-SHA384 \
  397. "
  398. fi
  399. ;;
  400. "PSK")
  401. M_CIPHERS="$M_CIPHERS \
  402. TLS-PSK-WITH-RC4-128-SHA \
  403. TLS-PSK-WITH-3DES-EDE-CBC-SHA \
  404. TLS-PSK-WITH-AES-128-CBC-SHA \
  405. TLS-PSK-WITH-AES-256-CBC-SHA \
  406. "
  407. G_CIPHERS="$G_CIPHERS \
  408. +PSK:+ARCFOUR-128:+SHA1 \
  409. +PSK:+3DES-CBC:+SHA1 \
  410. +PSK:+AES-128-CBC:+SHA1 \
  411. +PSK:+AES-256-CBC:+SHA1 \
  412. "
  413. O_CIPHERS="$O_CIPHERS \
  414. PSK-RC4-SHA \
  415. PSK-3DES-EDE-CBC-SHA \
  416. PSK-AES128-CBC-SHA \
  417. PSK-AES256-CBC-SHA \
  418. "
  419. ;;
  420. esac
  421. }
  422. # Ciphersuites usable only with Mbed TLS and OpenSSL
  423. # Each ciphersuite should appear two times, once with its OpenSSL name, once
  424. # with its Mbed TLS name.
  425. #
  426. # NOTE: for some reason RSA-PSK doesn't work with OpenSSL,
  427. # so RSA-PSK ciphersuites need to go in other sections, see
  428. # https://github.com/ARMmbed/mbedtls/issues/1419
  429. #
  430. # ChachaPoly suites are here rather than in "common", as they were added in
  431. # GnuTLS in 3.5.0 and the CI only has 3.4.x so far.
  432. add_openssl_ciphersuites()
  433. {
  434. case $TYPE in
  435. "ECDSA")
  436. if [ `minor_ver "$MODE"` -gt 0 ]
  437. then
  438. M_CIPHERS="$M_CIPHERS \
  439. TLS-ECDH-ECDSA-WITH-NULL-SHA \
  440. TLS-ECDH-ECDSA-WITH-RC4-128-SHA \
  441. TLS-ECDH-ECDSA-WITH-3DES-EDE-CBC-SHA \
  442. TLS-ECDH-ECDSA-WITH-AES-128-CBC-SHA \
  443. TLS-ECDH-ECDSA-WITH-AES-256-CBC-SHA \
  444. "
  445. O_CIPHERS="$O_CIPHERS \
  446. ECDH-ECDSA-NULL-SHA \
  447. ECDH-ECDSA-RC4-SHA \
  448. ECDH-ECDSA-DES-CBC3-SHA \
  449. ECDH-ECDSA-AES128-SHA \
  450. ECDH-ECDSA-AES256-SHA \
  451. "
  452. fi
  453. if [ `minor_ver "$MODE"` -ge 3 ]
  454. then
  455. M_CIPHERS="$M_CIPHERS \
  456. TLS-ECDH-ECDSA-WITH-AES-128-CBC-SHA256 \
  457. TLS-ECDH-ECDSA-WITH-AES-256-CBC-SHA384 \
  458. TLS-ECDH-ECDSA-WITH-AES-128-GCM-SHA256 \
  459. TLS-ECDH-ECDSA-WITH-AES-256-GCM-SHA384 \
  460. TLS-ECDHE-ECDSA-WITH-ARIA-256-GCM-SHA384 \
  461. TLS-ECDHE-ECDSA-WITH-ARIA-128-GCM-SHA256 \
  462. TLS-ECDHE-ECDSA-WITH-CHACHA20-POLY1305-SHA256 \
  463. "
  464. O_CIPHERS="$O_CIPHERS \
  465. ECDH-ECDSA-AES128-SHA256 \
  466. ECDH-ECDSA-AES256-SHA384 \
  467. ECDH-ECDSA-AES128-GCM-SHA256 \
  468. ECDH-ECDSA-AES256-GCM-SHA384 \
  469. ECDHE-ECDSA-ARIA256-GCM-SHA384 \
  470. ECDHE-ECDSA-ARIA128-GCM-SHA256 \
  471. ECDHE-ECDSA-CHACHA20-POLY1305 \
  472. "
  473. fi
  474. ;;
  475. "RSA")
  476. M_CIPHERS="$M_CIPHERS \
  477. TLS-RSA-WITH-DES-CBC-SHA \
  478. TLS-DHE-RSA-WITH-DES-CBC-SHA \
  479. "
  480. O_CIPHERS="$O_CIPHERS \
  481. DES-CBC-SHA \
  482. EDH-RSA-DES-CBC-SHA \
  483. "
  484. if [ `minor_ver "$MODE"` -ge 3 ]
  485. then
  486. M_CIPHERS="$M_CIPHERS \
  487. TLS-ECDHE-RSA-WITH-ARIA-256-GCM-SHA384 \
  488. TLS-DHE-RSA-WITH-ARIA-256-GCM-SHA384 \
  489. TLS-RSA-WITH-ARIA-256-GCM-SHA384 \
  490. TLS-ECDHE-RSA-WITH-ARIA-128-GCM-SHA256 \
  491. TLS-DHE-RSA-WITH-ARIA-128-GCM-SHA256 \
  492. TLS-RSA-WITH-ARIA-128-GCM-SHA256 \
  493. TLS-DHE-RSA-WITH-CHACHA20-POLY1305-SHA256 \
  494. TLS-ECDHE-RSA-WITH-CHACHA20-POLY1305-SHA256 \
  495. "
  496. O_CIPHERS="$O_CIPHERS \
  497. ECDHE-ARIA256-GCM-SHA384 \
  498. DHE-RSA-ARIA256-GCM-SHA384 \
  499. ARIA256-GCM-SHA384 \
  500. ECDHE-ARIA128-GCM-SHA256 \
  501. DHE-RSA-ARIA128-GCM-SHA256 \
  502. ARIA128-GCM-SHA256 \
  503. DHE-RSA-CHACHA20-POLY1305 \
  504. ECDHE-RSA-CHACHA20-POLY1305 \
  505. "
  506. fi
  507. ;;
  508. "PSK")
  509. if [ `minor_ver "$MODE"` -ge 3 ]
  510. then
  511. M_CIPHERS="$M_CIPHERS \
  512. TLS-DHE-PSK-WITH-ARIA-256-GCM-SHA384 \
  513. TLS-DHE-PSK-WITH-ARIA-128-GCM-SHA256 \
  514. TLS-PSK-WITH-ARIA-256-GCM-SHA384 \
  515. TLS-PSK-WITH-ARIA-128-GCM-SHA256 \
  516. TLS-PSK-WITH-CHACHA20-POLY1305-SHA256 \
  517. TLS-ECDHE-PSK-WITH-CHACHA20-POLY1305-SHA256 \
  518. TLS-DHE-PSK-WITH-CHACHA20-POLY1305-SHA256 \
  519. "
  520. O_CIPHERS="$O_CIPHERS \
  521. DHE-PSK-ARIA256-GCM-SHA384 \
  522. DHE-PSK-ARIA128-GCM-SHA256 \
  523. PSK-ARIA256-GCM-SHA384 \
  524. PSK-ARIA128-GCM-SHA256 \
  525. DHE-PSK-CHACHA20-POLY1305 \
  526. ECDHE-PSK-CHACHA20-POLY1305 \
  527. PSK-CHACHA20-POLY1305 \
  528. "
  529. fi
  530. ;;
  531. esac
  532. }
  533. # Ciphersuites usable only with Mbed TLS and GnuTLS
  534. # Each ciphersuite should appear two times, once with its GnuTLS name, once
  535. # with its Mbed TLS name.
  536. add_gnutls_ciphersuites()
  537. {
  538. case $TYPE in
  539. "ECDSA")
  540. if [ `minor_ver "$MODE"` -ge 3 ]
  541. then
  542. M_CIPHERS="$M_CIPHERS \
  543. TLS-ECDHE-ECDSA-WITH-CAMELLIA-128-CBC-SHA256 \
  544. TLS-ECDHE-ECDSA-WITH-CAMELLIA-256-CBC-SHA384 \
  545. TLS-ECDHE-ECDSA-WITH-CAMELLIA-128-GCM-SHA256 \
  546. TLS-ECDHE-ECDSA-WITH-CAMELLIA-256-GCM-SHA384 \
  547. TLS-ECDHE-ECDSA-WITH-AES-128-CCM \
  548. TLS-ECDHE-ECDSA-WITH-AES-256-CCM \
  549. TLS-ECDHE-ECDSA-WITH-AES-128-CCM-8 \
  550. TLS-ECDHE-ECDSA-WITH-AES-256-CCM-8 \
  551. "
  552. G_CIPHERS="$G_CIPHERS \
  553. +ECDHE-ECDSA:+CAMELLIA-128-CBC:+SHA256 \
  554. +ECDHE-ECDSA:+CAMELLIA-256-CBC:+SHA384 \
  555. +ECDHE-ECDSA:+CAMELLIA-128-GCM:+AEAD \
  556. +ECDHE-ECDSA:+CAMELLIA-256-GCM:+AEAD \
  557. +ECDHE-ECDSA:+AES-128-CCM:+AEAD \
  558. +ECDHE-ECDSA:+AES-256-CCM:+AEAD \
  559. +ECDHE-ECDSA:+AES-128-CCM-8:+AEAD \
  560. +ECDHE-ECDSA:+AES-256-CCM-8:+AEAD \
  561. "
  562. fi
  563. ;;
  564. "RSA")
  565. if [ `minor_ver "$MODE"` -gt 0 ]
  566. then
  567. M_CIPHERS="$M_CIPHERS \
  568. TLS-RSA-WITH-NULL-SHA256 \
  569. "
  570. G_CIPHERS="$G_CIPHERS \
  571. +RSA:+NULL:+SHA256 \
  572. "
  573. fi
  574. if [ `minor_ver "$MODE"` -ge 3 ]
  575. then
  576. M_CIPHERS="$M_CIPHERS \
  577. TLS-ECDHE-RSA-WITH-CAMELLIA-128-CBC-SHA256 \
  578. TLS-ECDHE-RSA-WITH-CAMELLIA-256-CBC-SHA384 \
  579. TLS-RSA-WITH-CAMELLIA-128-CBC-SHA256 \
  580. TLS-RSA-WITH-CAMELLIA-256-CBC-SHA256 \
  581. TLS-DHE-RSA-WITH-CAMELLIA-128-CBC-SHA256 \
  582. TLS-DHE-RSA-WITH-CAMELLIA-256-CBC-SHA256 \
  583. TLS-ECDHE-RSA-WITH-CAMELLIA-128-GCM-SHA256 \
  584. TLS-ECDHE-RSA-WITH-CAMELLIA-256-GCM-SHA384 \
  585. TLS-DHE-RSA-WITH-CAMELLIA-128-GCM-SHA256 \
  586. TLS-DHE-RSA-WITH-CAMELLIA-256-GCM-SHA384 \
  587. TLS-RSA-WITH-CAMELLIA-128-GCM-SHA256 \
  588. TLS-RSA-WITH-CAMELLIA-256-GCM-SHA384 \
  589. TLS-RSA-WITH-AES-128-CCM \
  590. TLS-RSA-WITH-AES-256-CCM \
  591. TLS-DHE-RSA-WITH-AES-128-CCM \
  592. TLS-DHE-RSA-WITH-AES-256-CCM \
  593. TLS-RSA-WITH-AES-128-CCM-8 \
  594. TLS-RSA-WITH-AES-256-CCM-8 \
  595. TLS-DHE-RSA-WITH-AES-128-CCM-8 \
  596. TLS-DHE-RSA-WITH-AES-256-CCM-8 \
  597. "
  598. G_CIPHERS="$G_CIPHERS \
  599. +ECDHE-RSA:+CAMELLIA-128-CBC:+SHA256 \
  600. +ECDHE-RSA:+CAMELLIA-256-CBC:+SHA384 \
  601. +RSA:+CAMELLIA-128-CBC:+SHA256 \
  602. +RSA:+CAMELLIA-256-CBC:+SHA256 \
  603. +DHE-RSA:+CAMELLIA-128-CBC:+SHA256 \
  604. +DHE-RSA:+CAMELLIA-256-CBC:+SHA256 \
  605. +ECDHE-RSA:+CAMELLIA-128-GCM:+AEAD \
  606. +ECDHE-RSA:+CAMELLIA-256-GCM:+AEAD \
  607. +DHE-RSA:+CAMELLIA-128-GCM:+AEAD \
  608. +DHE-RSA:+CAMELLIA-256-GCM:+AEAD \
  609. +RSA:+CAMELLIA-128-GCM:+AEAD \
  610. +RSA:+CAMELLIA-256-GCM:+AEAD \
  611. +RSA:+AES-128-CCM:+AEAD \
  612. +RSA:+AES-256-CCM:+AEAD \
  613. +RSA:+AES-128-CCM-8:+AEAD \
  614. +RSA:+AES-256-CCM-8:+AEAD \
  615. +DHE-RSA:+AES-128-CCM:+AEAD \
  616. +DHE-RSA:+AES-256-CCM:+AEAD \
  617. +DHE-RSA:+AES-128-CCM-8:+AEAD \
  618. +DHE-RSA:+AES-256-CCM-8:+AEAD \
  619. "
  620. fi
  621. ;;
  622. "PSK")
  623. M_CIPHERS="$M_CIPHERS \
  624. TLS-DHE-PSK-WITH-3DES-EDE-CBC-SHA \
  625. TLS-DHE-PSK-WITH-AES-128-CBC-SHA \
  626. TLS-DHE-PSK-WITH-AES-256-CBC-SHA \
  627. TLS-DHE-PSK-WITH-RC4-128-SHA \
  628. "
  629. G_CIPHERS="$G_CIPHERS \
  630. +DHE-PSK:+3DES-CBC:+SHA1 \
  631. +DHE-PSK:+AES-128-CBC:+SHA1 \
  632. +DHE-PSK:+AES-256-CBC:+SHA1 \
  633. +DHE-PSK:+ARCFOUR-128:+SHA1 \
  634. "
  635. if [ `minor_ver "$MODE"` -gt 0 ]
  636. then
  637. M_CIPHERS="$M_CIPHERS \
  638. TLS-ECDHE-PSK-WITH-AES-256-CBC-SHA \
  639. TLS-ECDHE-PSK-WITH-AES-128-CBC-SHA \
  640. TLS-ECDHE-PSK-WITH-3DES-EDE-CBC-SHA \
  641. TLS-ECDHE-PSK-WITH-RC4-128-SHA \
  642. TLS-RSA-PSK-WITH-3DES-EDE-CBC-SHA \
  643. TLS-RSA-PSK-WITH-AES-256-CBC-SHA \
  644. TLS-RSA-PSK-WITH-AES-128-CBC-SHA \
  645. TLS-RSA-PSK-WITH-RC4-128-SHA \
  646. "
  647. G_CIPHERS="$G_CIPHERS \
  648. +ECDHE-PSK:+3DES-CBC:+SHA1 \
  649. +ECDHE-PSK:+AES-128-CBC:+SHA1 \
  650. +ECDHE-PSK:+AES-256-CBC:+SHA1 \
  651. +ECDHE-PSK:+ARCFOUR-128:+SHA1 \
  652. +RSA-PSK:+3DES-CBC:+SHA1 \
  653. +RSA-PSK:+AES-256-CBC:+SHA1 \
  654. +RSA-PSK:+AES-128-CBC:+SHA1 \
  655. +RSA-PSK:+ARCFOUR-128:+SHA1 \
  656. "
  657. fi
  658. if [ `minor_ver "$MODE"` -ge 3 ]
  659. then
  660. M_CIPHERS="$M_CIPHERS \
  661. TLS-ECDHE-PSK-WITH-AES-256-CBC-SHA384 \
  662. TLS-ECDHE-PSK-WITH-CAMELLIA-256-CBC-SHA384 \
  663. TLS-ECDHE-PSK-WITH-AES-128-CBC-SHA256 \
  664. TLS-ECDHE-PSK-WITH-CAMELLIA-128-CBC-SHA256 \
  665. TLS-ECDHE-PSK-WITH-NULL-SHA384 \
  666. TLS-ECDHE-PSK-WITH-NULL-SHA256 \
  667. TLS-PSK-WITH-AES-128-CBC-SHA256 \
  668. TLS-PSK-WITH-AES-256-CBC-SHA384 \
  669. TLS-DHE-PSK-WITH-AES-128-CBC-SHA256 \
  670. TLS-DHE-PSK-WITH-AES-256-CBC-SHA384 \
  671. TLS-PSK-WITH-NULL-SHA256 \
  672. TLS-PSK-WITH-NULL-SHA384 \
  673. TLS-DHE-PSK-WITH-NULL-SHA256 \
  674. TLS-DHE-PSK-WITH-NULL-SHA384 \
  675. TLS-RSA-PSK-WITH-AES-256-CBC-SHA384 \
  676. TLS-RSA-PSK-WITH-AES-128-CBC-SHA256 \
  677. TLS-RSA-PSK-WITH-NULL-SHA256 \
  678. TLS-RSA-PSK-WITH-NULL-SHA384 \
  679. TLS-DHE-PSK-WITH-CAMELLIA-128-CBC-SHA256 \
  680. TLS-DHE-PSK-WITH-CAMELLIA-256-CBC-SHA384 \
  681. TLS-PSK-WITH-CAMELLIA-128-CBC-SHA256 \
  682. TLS-PSK-WITH-CAMELLIA-256-CBC-SHA384 \
  683. TLS-RSA-PSK-WITH-CAMELLIA-256-CBC-SHA384 \
  684. TLS-RSA-PSK-WITH-CAMELLIA-128-CBC-SHA256 \
  685. TLS-PSK-WITH-AES-128-GCM-SHA256 \
  686. TLS-PSK-WITH-AES-256-GCM-SHA384 \
  687. TLS-DHE-PSK-WITH-AES-128-GCM-SHA256 \
  688. TLS-DHE-PSK-WITH-AES-256-GCM-SHA384 \
  689. TLS-PSK-WITH-AES-128-CCM \
  690. TLS-PSK-WITH-AES-256-CCM \
  691. TLS-DHE-PSK-WITH-AES-128-CCM \
  692. TLS-DHE-PSK-WITH-AES-256-CCM \
  693. TLS-PSK-WITH-AES-128-CCM-8 \
  694. TLS-PSK-WITH-AES-256-CCM-8 \
  695. TLS-DHE-PSK-WITH-AES-128-CCM-8 \
  696. TLS-DHE-PSK-WITH-AES-256-CCM-8 \
  697. TLS-RSA-PSK-WITH-CAMELLIA-128-GCM-SHA256 \
  698. TLS-RSA-PSK-WITH-CAMELLIA-256-GCM-SHA384 \
  699. TLS-PSK-WITH-CAMELLIA-128-GCM-SHA256 \
  700. TLS-PSK-WITH-CAMELLIA-256-GCM-SHA384 \
  701. TLS-DHE-PSK-WITH-CAMELLIA-128-GCM-SHA256 \
  702. TLS-DHE-PSK-WITH-CAMELLIA-256-GCM-SHA384 \
  703. TLS-RSA-PSK-WITH-AES-256-GCM-SHA384 \
  704. TLS-RSA-PSK-WITH-AES-128-GCM-SHA256 \
  705. "
  706. G_CIPHERS="$G_CIPHERS \
  707. +ECDHE-PSK:+AES-256-CBC:+SHA384 \
  708. +ECDHE-PSK:+CAMELLIA-256-CBC:+SHA384 \
  709. +ECDHE-PSK:+AES-128-CBC:+SHA256 \
  710. +ECDHE-PSK:+CAMELLIA-128-CBC:+SHA256 \
  711. +PSK:+AES-128-CBC:+SHA256 \
  712. +PSK:+AES-256-CBC:+SHA384 \
  713. +DHE-PSK:+AES-128-CBC:+SHA256 \
  714. +DHE-PSK:+AES-256-CBC:+SHA384 \
  715. +RSA-PSK:+AES-256-CBC:+SHA384 \
  716. +RSA-PSK:+AES-128-CBC:+SHA256 \
  717. +DHE-PSK:+CAMELLIA-128-CBC:+SHA256 \
  718. +DHE-PSK:+CAMELLIA-256-CBC:+SHA384 \
  719. +PSK:+CAMELLIA-128-CBC:+SHA256 \
  720. +PSK:+CAMELLIA-256-CBC:+SHA384 \
  721. +RSA-PSK:+CAMELLIA-256-CBC:+SHA384 \
  722. +RSA-PSK:+CAMELLIA-128-CBC:+SHA256 \
  723. +PSK:+AES-128-GCM:+AEAD \
  724. +PSK:+AES-256-GCM:+AEAD \
  725. +DHE-PSK:+AES-128-GCM:+AEAD \
  726. +DHE-PSK:+AES-256-GCM:+AEAD \
  727. +PSK:+AES-128-CCM:+AEAD \
  728. +PSK:+AES-256-CCM:+AEAD \
  729. +DHE-PSK:+AES-128-CCM:+AEAD \
  730. +DHE-PSK:+AES-256-CCM:+AEAD \
  731. +PSK:+AES-128-CCM-8:+AEAD \
  732. +PSK:+AES-256-CCM-8:+AEAD \
  733. +DHE-PSK:+AES-128-CCM-8:+AEAD \
  734. +DHE-PSK:+AES-256-CCM-8:+AEAD \
  735. +RSA-PSK:+CAMELLIA-128-GCM:+AEAD \
  736. +RSA-PSK:+CAMELLIA-256-GCM:+AEAD \
  737. +PSK:+CAMELLIA-128-GCM:+AEAD \
  738. +PSK:+CAMELLIA-256-GCM:+AEAD \
  739. +DHE-PSK:+CAMELLIA-128-GCM:+AEAD \
  740. +DHE-PSK:+CAMELLIA-256-GCM:+AEAD \
  741. +RSA-PSK:+AES-256-GCM:+AEAD \
  742. +RSA-PSK:+AES-128-GCM:+AEAD \
  743. +ECDHE-PSK:+NULL:+SHA384 \
  744. +ECDHE-PSK:+NULL:+SHA256 \
  745. +PSK:+NULL:+SHA256 \
  746. +PSK:+NULL:+SHA384 \
  747. +DHE-PSK:+NULL:+SHA256 \
  748. +DHE-PSK:+NULL:+SHA384 \
  749. +RSA-PSK:+NULL:+SHA256 \
  750. +RSA-PSK:+NULL:+SHA384 \
  751. "
  752. fi
  753. ;;
  754. esac
  755. }
  756. # Ciphersuites usable only with Mbed TLS (not currently supported by another
  757. # peer usable in this script). This provide only very rudimentaty testing, as
  758. # this is not interop testing, but it's better than nothing.
  759. add_mbedtls_ciphersuites()
  760. {
  761. case $TYPE in
  762. "ECDSA")
  763. if [ `minor_ver "$MODE"` -gt 0 ]
  764. then
  765. M_CIPHERS="$M_CIPHERS \
  766. TLS-ECDH-ECDSA-WITH-CAMELLIA-128-CBC-SHA256 \
  767. TLS-ECDH-ECDSA-WITH-CAMELLIA-256-CBC-SHA384 \
  768. "
  769. fi
  770. if [ `minor_ver "$MODE"` -ge 3 ]
  771. then
  772. M_CIPHERS="$M_CIPHERS \
  773. TLS-ECDH-ECDSA-WITH-CAMELLIA-128-GCM-SHA256 \
  774. TLS-ECDH-ECDSA-WITH-CAMELLIA-256-GCM-SHA384 \
  775. TLS-ECDHE-ECDSA-WITH-ARIA-256-CBC-SHA384 \
  776. TLS-ECDHE-ECDSA-WITH-ARIA-128-CBC-SHA256 \
  777. TLS-ECDH-ECDSA-WITH-ARIA-256-GCM-SHA384 \
  778. TLS-ECDH-ECDSA-WITH-ARIA-128-GCM-SHA256 \
  779. TLS-ECDH-ECDSA-WITH-ARIA-256-CBC-SHA384 \
  780. TLS-ECDH-ECDSA-WITH-ARIA-128-CBC-SHA256 \
  781. "
  782. fi
  783. ;;
  784. "RSA")
  785. if [ `minor_ver "$MODE"` -ge 3 ]
  786. then
  787. M_CIPHERS="$M_CIPHERS \
  788. TLS-ECDHE-RSA-WITH-ARIA-256-CBC-SHA384 \
  789. TLS-DHE-RSA-WITH-ARIA-256-CBC-SHA384 \
  790. TLS-ECDHE-RSA-WITH-ARIA-128-CBC-SHA256 \
  791. TLS-DHE-RSA-WITH-ARIA-128-CBC-SHA256 \
  792. TLS-RSA-WITH-ARIA-256-CBC-SHA384 \
  793. TLS-RSA-WITH-ARIA-128-CBC-SHA256 \
  794. "
  795. fi
  796. ;;
  797. "PSK")
  798. # *PSK-NULL-SHA suites supported by GnuTLS 3.3.5 but not 3.2.15
  799. M_CIPHERS="$M_CIPHERS \
  800. TLS-PSK-WITH-NULL-SHA \
  801. TLS-DHE-PSK-WITH-NULL-SHA \
  802. "
  803. if [ `minor_ver "$MODE"` -gt 0 ]
  804. then
  805. M_CIPHERS="$M_CIPHERS \
  806. TLS-ECDHE-PSK-WITH-NULL-SHA \
  807. TLS-RSA-PSK-WITH-NULL-SHA \
  808. "
  809. fi
  810. if [ `minor_ver "$MODE"` -ge 3 ]
  811. then
  812. M_CIPHERS="$M_CIPHERS \
  813. TLS-RSA-PSK-WITH-ARIA-256-CBC-SHA384 \
  814. TLS-RSA-PSK-WITH-ARIA-128-CBC-SHA256 \
  815. TLS-PSK-WITH-ARIA-256-CBC-SHA384 \
  816. TLS-PSK-WITH-ARIA-128-CBC-SHA256 \
  817. TLS-RSA-PSK-WITH-ARIA-256-GCM-SHA384 \
  818. TLS-RSA-PSK-WITH-ARIA-128-GCM-SHA256 \
  819. TLS-ECDHE-PSK-WITH-ARIA-256-CBC-SHA384 \
  820. TLS-ECDHE-PSK-WITH-ARIA-128-CBC-SHA256 \
  821. TLS-DHE-PSK-WITH-ARIA-256-CBC-SHA384 \
  822. TLS-DHE-PSK-WITH-ARIA-128-CBC-SHA256 \
  823. TLS-RSA-PSK-WITH-CHACHA20-POLY1305-SHA256 \
  824. "
  825. fi
  826. ;;
  827. esac
  828. }
  829. setup_arguments()
  830. {
  831. G_MODE=""
  832. case "$MODE" in
  833. "ssl3")
  834. G_PRIO_MODE="+VERS-SSL3.0"
  835. ;;
  836. "tls1")
  837. G_PRIO_MODE="+VERS-TLS1.0"
  838. ;;
  839. "tls1_1")
  840. G_PRIO_MODE="+VERS-TLS1.1"
  841. ;;
  842. "tls12")
  843. G_PRIO_MODE="+VERS-TLS1.2"
  844. ;;
  845. "dtls1")
  846. G_PRIO_MODE="+VERS-DTLS1.0"
  847. G_MODE="-u"
  848. ;;
  849. "dtls12")
  850. G_PRIO_MODE="+VERS-DTLS1.2"
  851. G_MODE="-u"
  852. ;;
  853. *)
  854. echo "error: invalid mode: $MODE" >&2
  855. exit 1;
  856. esac
  857. # GnuTLS < 3.4 will choke if we try to allow CCM-8
  858. if [ -z "${GNUTLS_MINOR_LT_FOUR-}" ]; then
  859. G_PRIO_CCM="+AES-256-CCM-8:+AES-128-CCM-8:"
  860. else
  861. G_PRIO_CCM=""
  862. fi
  863. M_SERVER_ARGS="server_port=$PORT server_addr=0.0.0.0 force_version=$MODE arc4=1"
  864. O_SERVER_ARGS="-accept $PORT -cipher NULL,ALL -$MODE"
  865. G_SERVER_ARGS="-p $PORT --http $G_MODE"
  866. G_SERVER_PRIO="NORMAL:${G_PRIO_CCM}+ARCFOUR-128:+NULL:+MD5:+PSK:+DHE-PSK:+ECDHE-PSK:+SHA256:+SHA384:+RSA-PSK:-VERS-TLS-ALL:$G_PRIO_MODE"
  867. # The default prime for `openssl s_server` depends on the version:
  868. # * OpenSSL <= 1.0.2a: 512-bit
  869. # * OpenSSL 1.0.2b to 1.1.1b: 1024-bit
  870. # * OpenSSL >= 1.1.1c: 2048-bit
  871. # Mbed TLS wants >=1024, so force that for older versions. Don't force
  872. # it for newer versions, which reject a 1024-bit prime. Indifferently
  873. # force it or not for intermediate versions.
  874. case $($OPENSSL_CMD version) in
  875. "OpenSSL 1.0"*)
  876. O_SERVER_ARGS="$O_SERVER_ARGS -dhparam data_files/dhparams.pem"
  877. ;;
  878. esac
  879. # with OpenSSL 1.0.1h, -www, -WWW and -HTTP break DTLS handshakes
  880. if is_dtls "$MODE"; then
  881. O_SERVER_ARGS="$O_SERVER_ARGS"
  882. else
  883. O_SERVER_ARGS="$O_SERVER_ARGS -www"
  884. fi
  885. M_CLIENT_ARGS="server_port=$PORT server_addr=127.0.0.1 force_version=$MODE"
  886. O_CLIENT_ARGS="-connect localhost:$PORT -$MODE"
  887. G_CLIENT_ARGS="-p $PORT --debug 3 $G_MODE"
  888. G_CLIENT_PRIO="NONE:$G_PRIO_MODE:+COMP-NULL:+CURVE-ALL:+SIGN-ALL"
  889. if [ "X$VERIFY" = "XYES" ];
  890. then
  891. M_SERVER_ARGS="$M_SERVER_ARGS ca_file=data_files/test-ca_cat12.crt auth_mode=required"
  892. O_SERVER_ARGS="$O_SERVER_ARGS -CAfile data_files/test-ca_cat12.crt -Verify 10"
  893. G_SERVER_ARGS="$G_SERVER_ARGS --x509cafile data_files/test-ca_cat12.crt --require-client-cert"
  894. M_CLIENT_ARGS="$M_CLIENT_ARGS ca_file=data_files/test-ca_cat12.crt auth_mode=required"
  895. O_CLIENT_ARGS="$O_CLIENT_ARGS -CAfile data_files/test-ca_cat12.crt -verify 10"
  896. G_CLIENT_ARGS="$G_CLIENT_ARGS --x509cafile data_files/test-ca_cat12.crt"
  897. else
  898. # don't request a client cert at all
  899. M_SERVER_ARGS="$M_SERVER_ARGS ca_file=none auth_mode=none"
  900. G_SERVER_ARGS="$G_SERVER_ARGS --disable-client-cert"
  901. M_CLIENT_ARGS="$M_CLIENT_ARGS ca_file=none auth_mode=none"
  902. O_CLIENT_ARGS="$O_CLIENT_ARGS"
  903. G_CLIENT_ARGS="$G_CLIENT_ARGS --insecure"
  904. fi
  905. case $TYPE in
  906. "ECDSA")
  907. M_SERVER_ARGS="$M_SERVER_ARGS crt_file=data_files/server5.crt key_file=data_files/server5.key"
  908. O_SERVER_ARGS="$O_SERVER_ARGS -cert data_files/server5.crt -key data_files/server5.key"
  909. G_SERVER_ARGS="$G_SERVER_ARGS --x509certfile data_files/server5.crt --x509keyfile data_files/server5.key"
  910. if [ "X$VERIFY" = "XYES" ]; then
  911. M_CLIENT_ARGS="$M_CLIENT_ARGS crt_file=data_files/server6.crt key_file=data_files/server6.key"
  912. O_CLIENT_ARGS="$O_CLIENT_ARGS -cert data_files/server6.crt -key data_files/server6.key"
  913. G_CLIENT_ARGS="$G_CLIENT_ARGS --x509certfile data_files/server6.crt --x509keyfile data_files/server6.key"
  914. else
  915. M_CLIENT_ARGS="$M_CLIENT_ARGS crt_file=none key_file=none"
  916. fi
  917. ;;
  918. "RSA")
  919. M_SERVER_ARGS="$M_SERVER_ARGS crt_file=data_files/server2-sha256.crt key_file=data_files/server2.key"
  920. O_SERVER_ARGS="$O_SERVER_ARGS -cert data_files/server2-sha256.crt -key data_files/server2.key"
  921. G_SERVER_ARGS="$G_SERVER_ARGS --x509certfile data_files/server2-sha256.crt --x509keyfile data_files/server2.key"
  922. if [ "X$VERIFY" = "XYES" ]; then
  923. M_CLIENT_ARGS="$M_CLIENT_ARGS crt_file=data_files/cert_sha256.crt key_file=data_files/server1.key"
  924. O_CLIENT_ARGS="$O_CLIENT_ARGS -cert data_files/cert_sha256.crt -key data_files/server1.key"
  925. G_CLIENT_ARGS="$G_CLIENT_ARGS --x509certfile data_files/cert_sha256.crt --x509keyfile data_files/server1.key"
  926. else
  927. M_CLIENT_ARGS="$M_CLIENT_ARGS crt_file=none key_file=none"
  928. fi
  929. ;;
  930. "PSK")
  931. # give RSA-PSK-capable server a RSA cert
  932. # (should be a separate type, but harder to close with openssl)
  933. M_SERVER_ARGS="$M_SERVER_ARGS psk=6162636465666768696a6b6c6d6e6f70 ca_file=none crt_file=data_files/server2-sha256.crt key_file=data_files/server2.key"
  934. O_SERVER_ARGS="$O_SERVER_ARGS -psk 6162636465666768696a6b6c6d6e6f70 -nocert"
  935. G_SERVER_ARGS="$G_SERVER_ARGS --x509certfile data_files/server2-sha256.crt --x509keyfile data_files/server2.key --pskpasswd data_files/passwd.psk"
  936. M_CLIENT_ARGS="$M_CLIENT_ARGS psk=6162636465666768696a6b6c6d6e6f70 crt_file=none key_file=none"
  937. O_CLIENT_ARGS="$O_CLIENT_ARGS -psk 6162636465666768696a6b6c6d6e6f70"
  938. G_CLIENT_ARGS="$G_CLIENT_ARGS --pskusername Client_identity --pskkey=6162636465666768696a6b6c6d6e6f70"
  939. ;;
  940. esac
  941. }
  942. # is_mbedtls <cmd_line>
  943. is_mbedtls() {
  944. echo "$1" | grep 'ssl_server2\|ssl_client2' > /dev/null
  945. }
  946. # has_mem_err <log_file_name>
  947. has_mem_err() {
  948. if ( grep -F 'All heap blocks were freed -- no leaks are possible' "$1" &&
  949. grep -F 'ERROR SUMMARY: 0 errors from 0 contexts' "$1" ) > /dev/null
  950. then
  951. return 1 # false: does not have errors
  952. else
  953. return 0 # true: has errors
  954. fi
  955. }
  956. # Wait for process $2 to be listening on port $1
  957. if type lsof >/dev/null 2>/dev/null; then
  958. wait_server_start() {
  959. START_TIME=$(date +%s)
  960. if is_dtls "$MODE"; then
  961. proto=UDP
  962. else
  963. proto=TCP
  964. fi
  965. while ! lsof -a -n -b -i "$proto:$1" -p "$2" >/dev/null 2>/dev/null; do
  966. if [ $(( $(date +%s) - $START_TIME )) -gt $DOG_DELAY ]; then
  967. echo "SERVERSTART TIMEOUT"
  968. echo "SERVERSTART TIMEOUT" >> $SRV_OUT
  969. break
  970. fi
  971. # Linux and *BSD support decimal arguments to sleep. On other
  972. # OSes this may be a tight loop.
  973. sleep 0.1 2>/dev/null || true
  974. done
  975. }
  976. else
  977. echo "Warning: lsof not available, wait_server_start = sleep"
  978. wait_server_start() {
  979. sleep 2
  980. }
  981. fi
  982. # start_server <name>
  983. # also saves name and command
  984. start_server() {
  985. case $1 in
  986. [Oo]pen*)
  987. SERVER_CMD="$OPENSSL_CMD s_server $O_SERVER_ARGS"
  988. ;;
  989. [Gg]nu*)
  990. SERVER_CMD="$GNUTLS_SERV $G_SERVER_ARGS --priority $G_SERVER_PRIO"
  991. ;;
  992. mbed*)
  993. SERVER_CMD="$M_SRV $M_SERVER_ARGS"
  994. if [ "$MEMCHECK" -gt 0 ]; then
  995. SERVER_CMD="valgrind --leak-check=full $SERVER_CMD"
  996. fi
  997. ;;
  998. *)
  999. echo "error: invalid server name: $1" >&2
  1000. exit 1
  1001. ;;
  1002. esac
  1003. SERVER_NAME=$1
  1004. log "$SERVER_CMD"
  1005. echo "$SERVER_CMD" > $SRV_OUT
  1006. # for servers without -www or equivalent
  1007. while :; do echo bla; sleep 1; done | $SERVER_CMD >> $SRV_OUT 2>&1 &
  1008. PROCESS_ID=$!
  1009. wait_server_start "$PORT" "$PROCESS_ID"
  1010. }
  1011. # terminate the running server
  1012. stop_server() {
  1013. kill $PROCESS_ID 2>/dev/null
  1014. wait $PROCESS_ID 2>/dev/null
  1015. if [ "$MEMCHECK" -gt 0 ]; then
  1016. if is_mbedtls "$SERVER_CMD" && has_mem_err $SRV_OUT; then
  1017. echo " ! Server had memory errors"
  1018. SRVMEM=$(( $SRVMEM + 1 ))
  1019. return
  1020. fi
  1021. fi
  1022. rm -f $SRV_OUT
  1023. }
  1024. # kill the running server (used when killed by signal)
  1025. cleanup() {
  1026. rm -f $SRV_OUT $CLI_OUT
  1027. kill $PROCESS_ID >/dev/null 2>&1
  1028. kill $WATCHDOG_PID >/dev/null 2>&1
  1029. exit 1
  1030. }
  1031. # wait for client to terminate and set EXIT
  1032. # must be called right after starting the client
  1033. wait_client_done() {
  1034. CLI_PID=$!
  1035. ( sleep "$DOG_DELAY"; echo "TIMEOUT" >> $CLI_OUT; kill $CLI_PID ) &
  1036. WATCHDOG_PID=$!
  1037. wait $CLI_PID
  1038. EXIT=$?
  1039. kill $WATCHDOG_PID
  1040. wait $WATCHDOG_PID
  1041. echo "EXIT: $EXIT" >> $CLI_OUT
  1042. }
  1043. # run_client <name> <cipher>
  1044. run_client() {
  1045. # announce what we're going to do
  1046. TESTS=$(( $TESTS + 1 ))
  1047. VERIF=$(echo $VERIFY | tr '[:upper:]' '[:lower:]')
  1048. TITLE="`echo $1 | head -c1`->`echo $SERVER_NAME | head -c1`"
  1049. TITLE="$TITLE $MODE,$VERIF $2"
  1050. printf "%s " "$TITLE"
  1051. LEN=$(( 72 - `echo "$TITLE" | wc -c` ))
  1052. for i in `seq 1 $LEN`; do printf '.'; done; printf ' '
  1053. # should we skip?
  1054. if [ "X$SKIP_NEXT" = "XYES" ]; then
  1055. SKIP_NEXT="NO"
  1056. echo "SKIP"
  1057. SKIPPED=$(( $SKIPPED + 1 ))
  1058. return
  1059. fi
  1060. # run the command and interpret result
  1061. case $1 in
  1062. [Oo]pen*)
  1063. CLIENT_CMD="$OPENSSL_CMD s_client $O_CLIENT_ARGS -cipher $2"
  1064. log "$CLIENT_CMD"
  1065. echo "$CLIENT_CMD" > $CLI_OUT
  1066. printf 'GET HTTP/1.0\r\n\r\n' | $CLIENT_CMD >> $CLI_OUT 2>&1 &
  1067. wait_client_done
  1068. if [ $EXIT -eq 0 ]; then
  1069. RESULT=0
  1070. else
  1071. # If the cipher isn't supported...
  1072. if grep 'Cipher is (NONE)' $CLI_OUT >/dev/null; then
  1073. RESULT=1
  1074. else
  1075. RESULT=2
  1076. fi
  1077. fi
  1078. ;;
  1079. [Gg]nu*)
  1080. # need to force IPv4 with UDP, but keep localhost for auth
  1081. if is_dtls "$MODE"; then
  1082. G_HOST="127.0.0.1"
  1083. else
  1084. G_HOST="localhost"
  1085. fi
  1086. CLIENT_CMD="$GNUTLS_CLI $G_CLIENT_ARGS --priority $G_PRIO_MODE:$2 $G_HOST"
  1087. log "$CLIENT_CMD"
  1088. echo "$CLIENT_CMD" > $CLI_OUT
  1089. printf 'GET HTTP/1.0\r\n\r\n' | $CLIENT_CMD >> $CLI_OUT 2>&1 &
  1090. wait_client_done
  1091. if [ $EXIT -eq 0 ]; then
  1092. RESULT=0
  1093. else
  1094. RESULT=2
  1095. # interpret early failure, with a handshake_failure alert
  1096. # before the server hello, as "no ciphersuite in common"
  1097. if grep -F 'Received alert [40]: Handshake failed' $CLI_OUT; then
  1098. if grep -i 'SERVER HELLO .* was received' $CLI_OUT; then :
  1099. else
  1100. RESULT=1
  1101. fi
  1102. fi >/dev/null
  1103. fi
  1104. ;;
  1105. mbed*)
  1106. CLIENT_CMD="$M_CLI $M_CLIENT_ARGS force_ciphersuite=$2"
  1107. if [ "$MEMCHECK" -gt 0 ]; then
  1108. CLIENT_CMD="valgrind --leak-check=full $CLIENT_CMD"
  1109. fi
  1110. log "$CLIENT_CMD"
  1111. echo "$CLIENT_CMD" > $CLI_OUT
  1112. $CLIENT_CMD >> $CLI_OUT 2>&1 &
  1113. wait_client_done
  1114. case $EXIT in
  1115. # Success
  1116. "0") RESULT=0 ;;
  1117. # Ciphersuite not supported
  1118. "2") RESULT=1 ;;
  1119. # Error
  1120. *) RESULT=2 ;;
  1121. esac
  1122. if [ "$MEMCHECK" -gt 0 ]; then
  1123. if is_mbedtls "$CLIENT_CMD" && has_mem_err $CLI_OUT; then
  1124. RESULT=2
  1125. fi
  1126. fi
  1127. ;;
  1128. *)
  1129. echo "error: invalid client name: $1" >&2
  1130. exit 1
  1131. ;;
  1132. esac
  1133. echo "EXIT: $EXIT" >> $CLI_OUT
  1134. # report and count result
  1135. case $RESULT in
  1136. "0")
  1137. echo PASS
  1138. ;;
  1139. "1")
  1140. echo SKIP
  1141. SKIPPED=$(( $SKIPPED + 1 ))
  1142. ;;
  1143. "2")
  1144. echo FAIL
  1145. cp $SRV_OUT c-srv-${TESTS}.log
  1146. cp $CLI_OUT c-cli-${TESTS}.log
  1147. echo " ! outputs saved to c-srv-${TESTS}.log, c-cli-${TESTS}.log"
  1148. if [ "${LOG_FAILURE_ON_STDOUT:-0}" != 0 ]; then
  1149. echo " ! server output:"
  1150. cat c-srv-${TESTS}.log
  1151. echo " ! ==================================================="
  1152. echo " ! client output:"
  1153. cat c-cli-${TESTS}.log
  1154. fi
  1155. FAILED=$(( $FAILED + 1 ))
  1156. ;;
  1157. esac
  1158. rm -f $CLI_OUT
  1159. }
  1160. #
  1161. # MAIN
  1162. #
  1163. if cd $( dirname $0 ); then :; else
  1164. echo "cd $( dirname $0 ) failed" >&2
  1165. exit 1
  1166. fi
  1167. get_options "$@"
  1168. # sanity checks, avoid an avalanche of errors
  1169. if [ ! -x "$M_SRV" ]; then
  1170. echo "Command '$M_SRV' is not an executable file" >&2
  1171. exit 1
  1172. fi
  1173. if [ ! -x "$M_CLI" ]; then
  1174. echo "Command '$M_CLI' is not an executable file" >&2
  1175. exit 1
  1176. fi
  1177. if echo "$PEERS" | grep -i openssl > /dev/null; then
  1178. if which "$OPENSSL_CMD" >/dev/null 2>&1; then :; else
  1179. echo "Command '$OPENSSL_CMD' not found" >&2
  1180. exit 1
  1181. fi
  1182. fi
  1183. if echo "$PEERS" | grep -i gnutls > /dev/null; then
  1184. for CMD in "$GNUTLS_CLI" "$GNUTLS_SERV"; do
  1185. if which "$CMD" >/dev/null 2>&1; then :; else
  1186. echo "Command '$CMD' not found" >&2
  1187. exit 1
  1188. fi
  1189. done
  1190. fi
  1191. for PEER in $PEERS; do
  1192. case "$PEER" in
  1193. mbed*|[Oo]pen*|[Gg]nu*)
  1194. ;;
  1195. *)
  1196. echo "Unknown peers: $PEER" >&2
  1197. exit 1
  1198. esac
  1199. done
  1200. # Pick a "unique" port in the range 10000-19999.
  1201. PORT="0000$$"
  1202. PORT="1$(echo $PORT | tail -c 5)"
  1203. # Also pick a unique name for intermediate files
  1204. SRV_OUT="srv_out.$$"
  1205. CLI_OUT="cli_out.$$"
  1206. # client timeout delay: be more patient with valgrind
  1207. if [ "$MEMCHECK" -gt 0 ]; then
  1208. DOG_DELAY=30
  1209. else
  1210. DOG_DELAY=10
  1211. fi
  1212. SKIP_NEXT="NO"
  1213. trap cleanup INT TERM HUP
  1214. for VERIFY in $VERIFIES; do
  1215. for MODE in $MODES; do
  1216. for TYPE in $TYPES; do
  1217. for PEER in $PEERS; do
  1218. setup_arguments
  1219. case "$PEER" in
  1220. [Oo]pen*)
  1221. if test "$OSSL_NO_DTLS" -gt 0 && is_dtls "$MODE"; then
  1222. continue;
  1223. fi
  1224. reset_ciphersuites
  1225. add_common_ciphersuites
  1226. add_openssl_ciphersuites
  1227. filter_ciphersuites
  1228. if [ "X" != "X$M_CIPHERS" ]; then
  1229. start_server "OpenSSL"
  1230. for i in $M_CIPHERS; do
  1231. check_openssl_server_bug $i
  1232. run_client mbedTLS $i
  1233. done
  1234. stop_server
  1235. fi
  1236. if [ "X" != "X$O_CIPHERS" ]; then
  1237. start_server "mbedTLS"
  1238. for i in $O_CIPHERS; do
  1239. run_client OpenSSL $i
  1240. done
  1241. stop_server
  1242. fi
  1243. ;;
  1244. [Gg]nu*)
  1245. reset_ciphersuites
  1246. add_common_ciphersuites
  1247. add_gnutls_ciphersuites
  1248. filter_ciphersuites
  1249. if [ "X" != "X$M_CIPHERS" ]; then
  1250. start_server "GnuTLS"
  1251. for i in $M_CIPHERS; do
  1252. run_client mbedTLS $i
  1253. done
  1254. stop_server
  1255. fi
  1256. if [ "X" != "X$G_CIPHERS" ]; then
  1257. start_server "mbedTLS"
  1258. for i in $G_CIPHERS; do
  1259. run_client GnuTLS $i
  1260. done
  1261. stop_server
  1262. fi
  1263. ;;
  1264. mbed*)
  1265. reset_ciphersuites
  1266. add_common_ciphersuites
  1267. add_openssl_ciphersuites
  1268. add_gnutls_ciphersuites
  1269. add_mbedtls_ciphersuites
  1270. filter_ciphersuites
  1271. if [ "X" != "X$M_CIPHERS" ]; then
  1272. start_server "mbedTLS"
  1273. for i in $M_CIPHERS; do
  1274. run_client mbedTLS $i
  1275. done
  1276. stop_server
  1277. fi
  1278. ;;
  1279. *)
  1280. echo "Unknown peer: $PEER" >&2
  1281. exit 1
  1282. ;;
  1283. esac
  1284. done
  1285. done
  1286. done
  1287. done
  1288. echo "------------------------------------------------------------------------"
  1289. if [ $FAILED -ne 0 -o $SRVMEM -ne 0 ];
  1290. then
  1291. printf "FAILED"
  1292. else
  1293. printf "PASSED"
  1294. fi
  1295. if [ "$MEMCHECK" -gt 0 ]; then
  1296. MEMREPORT=", $SRVMEM server memory errors"
  1297. else
  1298. MEMREPORT=""
  1299. fi
  1300. PASSED=$(( $TESTS - $FAILED ))
  1301. echo " ($PASSED / $TESTS tests ($SKIPPED skipped$MEMREPORT))"
  1302. FAILED=$(( $FAILED + $SRVMEM ))
  1303. exit $FAILED