compat.sh 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418
  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 tls1_2 dtls1 dtls1_2"
  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" = "dtls1_2"
  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. tls1_2|dtls1_2)
  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. "tls1_2")
  843. G_PRIO_MODE="+VERS-TLS1.2"
  844. ;;
  845. "dtls1")
  846. G_PRIO_MODE="+VERS-DTLS1.0"
  847. G_MODE="-u"
  848. ;;
  849. "dtls1_2")
  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 -dhparam data_files/dhparams.pem"
  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. # with OpenSSL 1.0.1h, -www, -WWW and -HTTP break DTLS handshakes
  868. if is_dtls "$MODE"; then
  869. O_SERVER_ARGS="$O_SERVER_ARGS"
  870. else
  871. O_SERVER_ARGS="$O_SERVER_ARGS -www"
  872. fi
  873. M_CLIENT_ARGS="server_port=$PORT server_addr=127.0.0.1 force_version=$MODE"
  874. O_CLIENT_ARGS="-connect localhost:$PORT -$MODE"
  875. G_CLIENT_ARGS="-p $PORT --debug 3 $G_MODE"
  876. G_CLIENT_PRIO="NONE:$G_PRIO_MODE:+COMP-NULL:+CURVE-ALL:+SIGN-ALL"
  877. if [ "X$VERIFY" = "XYES" ];
  878. then
  879. M_SERVER_ARGS="$M_SERVER_ARGS ca_file=data_files/test-ca_cat12.crt auth_mode=required"
  880. O_SERVER_ARGS="$O_SERVER_ARGS -CAfile data_files/test-ca_cat12.crt -Verify 10"
  881. G_SERVER_ARGS="$G_SERVER_ARGS --x509cafile data_files/test-ca_cat12.crt --require-client-cert"
  882. M_CLIENT_ARGS="$M_CLIENT_ARGS ca_file=data_files/test-ca_cat12.crt auth_mode=required"
  883. O_CLIENT_ARGS="$O_CLIENT_ARGS -CAfile data_files/test-ca_cat12.crt -verify 10"
  884. G_CLIENT_ARGS="$G_CLIENT_ARGS --x509cafile data_files/test-ca_cat12.crt"
  885. else
  886. # don't request a client cert at all
  887. M_SERVER_ARGS="$M_SERVER_ARGS ca_file=none auth_mode=none"
  888. G_SERVER_ARGS="$G_SERVER_ARGS --disable-client-cert"
  889. M_CLIENT_ARGS="$M_CLIENT_ARGS ca_file=none auth_mode=none"
  890. O_CLIENT_ARGS="$O_CLIENT_ARGS"
  891. G_CLIENT_ARGS="$G_CLIENT_ARGS --insecure"
  892. fi
  893. case $TYPE in
  894. "ECDSA")
  895. M_SERVER_ARGS="$M_SERVER_ARGS crt_file=data_files/server5.crt key_file=data_files/server5.key"
  896. O_SERVER_ARGS="$O_SERVER_ARGS -cert data_files/server5.crt -key data_files/server5.key"
  897. G_SERVER_ARGS="$G_SERVER_ARGS --x509certfile data_files/server5.crt --x509keyfile data_files/server5.key"
  898. if [ "X$VERIFY" = "XYES" ]; then
  899. M_CLIENT_ARGS="$M_CLIENT_ARGS crt_file=data_files/server6.crt key_file=data_files/server6.key"
  900. O_CLIENT_ARGS="$O_CLIENT_ARGS -cert data_files/server6.crt -key data_files/server6.key"
  901. G_CLIENT_ARGS="$G_CLIENT_ARGS --x509certfile data_files/server6.crt --x509keyfile data_files/server6.key"
  902. else
  903. M_CLIENT_ARGS="$M_CLIENT_ARGS crt_file=none key_file=none"
  904. fi
  905. ;;
  906. "RSA")
  907. M_SERVER_ARGS="$M_SERVER_ARGS crt_file=data_files/server2-sha256.crt key_file=data_files/server2.key"
  908. O_SERVER_ARGS="$O_SERVER_ARGS -cert data_files/server2-sha256.crt -key data_files/server2.key"
  909. G_SERVER_ARGS="$G_SERVER_ARGS --x509certfile data_files/server2-sha256.crt --x509keyfile data_files/server2.key"
  910. if [ "X$VERIFY" = "XYES" ]; then
  911. M_CLIENT_ARGS="$M_CLIENT_ARGS crt_file=data_files/cert_sha256.crt key_file=data_files/server1.key"
  912. O_CLIENT_ARGS="$O_CLIENT_ARGS -cert data_files/cert_sha256.crt -key data_files/server1.key"
  913. G_CLIENT_ARGS="$G_CLIENT_ARGS --x509certfile data_files/cert_sha256.crt --x509keyfile data_files/server1.key"
  914. else
  915. M_CLIENT_ARGS="$M_CLIENT_ARGS crt_file=none key_file=none"
  916. fi
  917. ;;
  918. "PSK")
  919. # give RSA-PSK-capable server a RSA cert
  920. # (should be a separate type, but harder to close with openssl)
  921. M_SERVER_ARGS="$M_SERVER_ARGS psk=6162636465666768696a6b6c6d6e6f70 ca_file=none crt_file=data_files/server2-sha256.crt key_file=data_files/server2.key"
  922. O_SERVER_ARGS="$O_SERVER_ARGS -psk 6162636465666768696a6b6c6d6e6f70 -nocert"
  923. G_SERVER_ARGS="$G_SERVER_ARGS --x509certfile data_files/server2-sha256.crt --x509keyfile data_files/server2.key --pskpasswd data_files/passwd.psk"
  924. M_CLIENT_ARGS="$M_CLIENT_ARGS psk=6162636465666768696a6b6c6d6e6f70 crt_file=none key_file=none"
  925. O_CLIENT_ARGS="$O_CLIENT_ARGS -psk 6162636465666768696a6b6c6d6e6f70"
  926. G_CLIENT_ARGS="$G_CLIENT_ARGS --pskusername Client_identity --pskkey=6162636465666768696a6b6c6d6e6f70"
  927. ;;
  928. esac
  929. }
  930. # is_mbedtls <cmd_line>
  931. is_mbedtls() {
  932. echo "$1" | grep 'ssl_server2\|ssl_client2' > /dev/null
  933. }
  934. # has_mem_err <log_file_name>
  935. has_mem_err() {
  936. if ( grep -F 'All heap blocks were freed -- no leaks are possible' "$1" &&
  937. grep -F 'ERROR SUMMARY: 0 errors from 0 contexts' "$1" ) > /dev/null
  938. then
  939. return 1 # false: does not have errors
  940. else
  941. return 0 # true: has errors
  942. fi
  943. }
  944. # Wait for process $2 to be listening on port $1
  945. if type lsof >/dev/null 2>/dev/null; then
  946. wait_server_start() {
  947. START_TIME=$(date +%s)
  948. if is_dtls "$MODE"; then
  949. proto=UDP
  950. else
  951. proto=TCP
  952. fi
  953. while ! lsof -a -n -b -i "$proto:$1" -p "$2" >/dev/null 2>/dev/null; do
  954. if [ $(( $(date +%s) - $START_TIME )) -gt $DOG_DELAY ]; then
  955. echo "SERVERSTART TIMEOUT"
  956. echo "SERVERSTART TIMEOUT" >> $SRV_OUT
  957. break
  958. fi
  959. # Linux and *BSD support decimal arguments to sleep. On other
  960. # OSes this may be a tight loop.
  961. sleep 0.1 2>/dev/null || true
  962. done
  963. }
  964. else
  965. echo "Warning: lsof not available, wait_server_start = sleep"
  966. wait_server_start() {
  967. sleep 2
  968. }
  969. fi
  970. # start_server <name>
  971. # also saves name and command
  972. start_server() {
  973. case $1 in
  974. [Oo]pen*)
  975. SERVER_CMD="$OPENSSL_CMD s_server $O_SERVER_ARGS"
  976. ;;
  977. [Gg]nu*)
  978. SERVER_CMD="$GNUTLS_SERV $G_SERVER_ARGS --priority $G_SERVER_PRIO"
  979. ;;
  980. mbed*)
  981. SERVER_CMD="$M_SRV $M_SERVER_ARGS"
  982. if [ "$MEMCHECK" -gt 0 ]; then
  983. SERVER_CMD="valgrind --leak-check=full $SERVER_CMD"
  984. fi
  985. ;;
  986. *)
  987. echo "error: invalid server name: $1" >&2
  988. exit 1
  989. ;;
  990. esac
  991. SERVER_NAME=$1
  992. log "$SERVER_CMD"
  993. echo "$SERVER_CMD" > $SRV_OUT
  994. # for servers without -www or equivalent
  995. while :; do echo bla; sleep 1; done | $SERVER_CMD >> $SRV_OUT 2>&1 &
  996. PROCESS_ID=$!
  997. wait_server_start "$PORT" "$PROCESS_ID"
  998. }
  999. # terminate the running server
  1000. stop_server() {
  1001. kill $PROCESS_ID 2>/dev/null
  1002. wait $PROCESS_ID 2>/dev/null
  1003. if [ "$MEMCHECK" -gt 0 ]; then
  1004. if is_mbedtls "$SERVER_CMD" && has_mem_err $SRV_OUT; then
  1005. echo " ! Server had memory errors"
  1006. SRVMEM=$(( $SRVMEM + 1 ))
  1007. return
  1008. fi
  1009. fi
  1010. rm -f $SRV_OUT
  1011. }
  1012. # kill the running server (used when killed by signal)
  1013. cleanup() {
  1014. rm -f $SRV_OUT $CLI_OUT
  1015. kill $PROCESS_ID >/dev/null 2>&1
  1016. kill $WATCHDOG_PID >/dev/null 2>&1
  1017. exit 1
  1018. }
  1019. # wait for client to terminate and set EXIT
  1020. # must be called right after starting the client
  1021. wait_client_done() {
  1022. CLI_PID=$!
  1023. ( sleep "$DOG_DELAY"; echo "TIMEOUT" >> $CLI_OUT; kill $CLI_PID ) &
  1024. WATCHDOG_PID=$!
  1025. wait $CLI_PID
  1026. EXIT=$?
  1027. kill $WATCHDOG_PID
  1028. wait $WATCHDOG_PID
  1029. echo "EXIT: $EXIT" >> $CLI_OUT
  1030. }
  1031. # run_client <name> <cipher>
  1032. run_client() {
  1033. # announce what we're going to do
  1034. TESTS=$(( $TESTS + 1 ))
  1035. VERIF=$(echo $VERIFY | tr '[:upper:]' '[:lower:]')
  1036. TITLE="`echo $1 | head -c1`->`echo $SERVER_NAME | head -c1`"
  1037. TITLE="$TITLE $MODE,$VERIF $2"
  1038. printf "%s " "$TITLE"
  1039. LEN=$(( 72 - `echo "$TITLE" | wc -c` ))
  1040. for i in `seq 1 $LEN`; do printf '.'; done; printf ' '
  1041. # should we skip?
  1042. if [ "X$SKIP_NEXT" = "XYES" ]; then
  1043. SKIP_NEXT="NO"
  1044. echo "SKIP"
  1045. SKIPPED=$(( $SKIPPED + 1 ))
  1046. return
  1047. fi
  1048. # run the command and interpret result
  1049. case $1 in
  1050. [Oo]pen*)
  1051. CLIENT_CMD="$OPENSSL_CMD s_client $O_CLIENT_ARGS -cipher $2"
  1052. log "$CLIENT_CMD"
  1053. echo "$CLIENT_CMD" > $CLI_OUT
  1054. printf 'GET HTTP/1.0\r\n\r\n' | $CLIENT_CMD >> $CLI_OUT 2>&1 &
  1055. wait_client_done
  1056. if [ $EXIT -eq 0 ]; then
  1057. RESULT=0
  1058. else
  1059. # If the cipher isn't supported...
  1060. if grep 'Cipher is (NONE)' $CLI_OUT >/dev/null; then
  1061. RESULT=1
  1062. else
  1063. RESULT=2
  1064. fi
  1065. fi
  1066. ;;
  1067. [Gg]nu*)
  1068. # need to force IPv4 with UDP, but keep localhost for auth
  1069. if is_dtls "$MODE"; then
  1070. G_HOST="127.0.0.1"
  1071. else
  1072. G_HOST="localhost"
  1073. fi
  1074. CLIENT_CMD="$GNUTLS_CLI $G_CLIENT_ARGS --priority $G_PRIO_MODE:$2 $G_HOST"
  1075. log "$CLIENT_CMD"
  1076. echo "$CLIENT_CMD" > $CLI_OUT
  1077. printf 'GET HTTP/1.0\r\n\r\n' | $CLIENT_CMD >> $CLI_OUT 2>&1 &
  1078. wait_client_done
  1079. if [ $EXIT -eq 0 ]; then
  1080. RESULT=0
  1081. else
  1082. RESULT=2
  1083. # interpret early failure, with a handshake_failure alert
  1084. # before the server hello, as "no ciphersuite in common"
  1085. if grep -F 'Received alert [40]: Handshake failed' $CLI_OUT; then
  1086. if grep -i 'SERVER HELLO .* was received' $CLI_OUT; then :
  1087. else
  1088. RESULT=1
  1089. fi
  1090. fi >/dev/null
  1091. fi
  1092. ;;
  1093. mbed*)
  1094. CLIENT_CMD="$M_CLI $M_CLIENT_ARGS force_ciphersuite=$2"
  1095. if [ "$MEMCHECK" -gt 0 ]; then
  1096. CLIENT_CMD="valgrind --leak-check=full $CLIENT_CMD"
  1097. fi
  1098. log "$CLIENT_CMD"
  1099. echo "$CLIENT_CMD" > $CLI_OUT
  1100. $CLIENT_CMD >> $CLI_OUT 2>&1 &
  1101. wait_client_done
  1102. case $EXIT in
  1103. # Success
  1104. "0") RESULT=0 ;;
  1105. # Ciphersuite not supported
  1106. "2") RESULT=1 ;;
  1107. # Error
  1108. *) RESULT=2 ;;
  1109. esac
  1110. if [ "$MEMCHECK" -gt 0 ]; then
  1111. if is_mbedtls "$CLIENT_CMD" && has_mem_err $CLI_OUT; then
  1112. RESULT=2
  1113. fi
  1114. fi
  1115. ;;
  1116. *)
  1117. echo "error: invalid client name: $1" >&2
  1118. exit 1
  1119. ;;
  1120. esac
  1121. echo "EXIT: $EXIT" >> $CLI_OUT
  1122. # report and count result
  1123. case $RESULT in
  1124. "0")
  1125. echo PASS
  1126. ;;
  1127. "1")
  1128. echo SKIP
  1129. SKIPPED=$(( $SKIPPED + 1 ))
  1130. ;;
  1131. "2")
  1132. echo FAIL
  1133. cp $SRV_OUT c-srv-${TESTS}.log
  1134. cp $CLI_OUT c-cli-${TESTS}.log
  1135. echo " ! outputs saved to c-srv-${TESTS}.log, c-cli-${TESTS}.log"
  1136. if [ "${LOG_FAILURE_ON_STDOUT:-0}" != 0 ]; then
  1137. echo " ! server output:"
  1138. cat c-srv-${TESTS}.log
  1139. echo " ! ==================================================="
  1140. echo " ! client output:"
  1141. cat c-cli-${TESTS}.log
  1142. fi
  1143. FAILED=$(( $FAILED + 1 ))
  1144. ;;
  1145. esac
  1146. rm -f $CLI_OUT
  1147. }
  1148. #
  1149. # MAIN
  1150. #
  1151. if cd $( dirname $0 ); then :; else
  1152. echo "cd $( dirname $0 ) failed" >&2
  1153. exit 1
  1154. fi
  1155. get_options "$@"
  1156. # sanity checks, avoid an avalanche of errors
  1157. if [ ! -x "$M_SRV" ]; then
  1158. echo "Command '$M_SRV' is not an executable file" >&2
  1159. exit 1
  1160. fi
  1161. if [ ! -x "$M_CLI" ]; then
  1162. echo "Command '$M_CLI' is not an executable file" >&2
  1163. exit 1
  1164. fi
  1165. if echo "$PEERS" | grep -i openssl > /dev/null; then
  1166. if which "$OPENSSL_CMD" >/dev/null 2>&1; then :; else
  1167. echo "Command '$OPENSSL_CMD' not found" >&2
  1168. exit 1
  1169. fi
  1170. fi
  1171. if echo "$PEERS" | grep -i gnutls > /dev/null; then
  1172. for CMD in "$GNUTLS_CLI" "$GNUTLS_SERV"; do
  1173. if which "$CMD" >/dev/null 2>&1; then :; else
  1174. echo "Command '$CMD' not found" >&2
  1175. exit 1
  1176. fi
  1177. done
  1178. fi
  1179. for PEER in $PEERS; do
  1180. case "$PEER" in
  1181. mbed*|[Oo]pen*|[Gg]nu*)
  1182. ;;
  1183. *)
  1184. echo "Unknown peers: $PEER" >&2
  1185. exit 1
  1186. esac
  1187. done
  1188. # Pick a "unique" port in the range 10000-19999.
  1189. PORT="0000$$"
  1190. PORT="1$(echo $PORT | tail -c 5)"
  1191. # Also pick a unique name for intermediate files
  1192. SRV_OUT="srv_out.$$"
  1193. CLI_OUT="cli_out.$$"
  1194. # client timeout delay: be more patient with valgrind
  1195. if [ "$MEMCHECK" -gt 0 ]; then
  1196. DOG_DELAY=30
  1197. else
  1198. DOG_DELAY=10
  1199. fi
  1200. SKIP_NEXT="NO"
  1201. trap cleanup INT TERM HUP
  1202. for VERIFY in $VERIFIES; do
  1203. for MODE in $MODES; do
  1204. for TYPE in $TYPES; do
  1205. for PEER in $PEERS; do
  1206. setup_arguments
  1207. case "$PEER" in
  1208. [Oo]pen*)
  1209. if test "$OSSL_NO_DTLS" -gt 0 && is_dtls "$MODE"; then
  1210. continue;
  1211. fi
  1212. reset_ciphersuites
  1213. add_common_ciphersuites
  1214. add_openssl_ciphersuites
  1215. filter_ciphersuites
  1216. if [ "X" != "X$M_CIPHERS" ]; then
  1217. start_server "OpenSSL"
  1218. for i in $M_CIPHERS; do
  1219. check_openssl_server_bug $i
  1220. run_client mbedTLS $i
  1221. done
  1222. stop_server
  1223. fi
  1224. if [ "X" != "X$O_CIPHERS" ]; then
  1225. start_server "mbedTLS"
  1226. for i in $O_CIPHERS; do
  1227. run_client OpenSSL $i
  1228. done
  1229. stop_server
  1230. fi
  1231. ;;
  1232. [Gg]nu*)
  1233. reset_ciphersuites
  1234. add_common_ciphersuites
  1235. add_gnutls_ciphersuites
  1236. filter_ciphersuites
  1237. if [ "X" != "X$M_CIPHERS" ]; then
  1238. start_server "GnuTLS"
  1239. for i in $M_CIPHERS; do
  1240. run_client mbedTLS $i
  1241. done
  1242. stop_server
  1243. fi
  1244. if [ "X" != "X$G_CIPHERS" ]; then
  1245. start_server "mbedTLS"
  1246. for i in $G_CIPHERS; do
  1247. run_client GnuTLS $i
  1248. done
  1249. stop_server
  1250. fi
  1251. ;;
  1252. mbed*)
  1253. reset_ciphersuites
  1254. add_common_ciphersuites
  1255. add_openssl_ciphersuites
  1256. add_gnutls_ciphersuites
  1257. add_mbedtls_ciphersuites
  1258. filter_ciphersuites
  1259. if [ "X" != "X$M_CIPHERS" ]; then
  1260. start_server "mbedTLS"
  1261. for i in $M_CIPHERS; do
  1262. run_client mbedTLS $i
  1263. done
  1264. stop_server
  1265. fi
  1266. ;;
  1267. *)
  1268. echo "Unknown peer: $PEER" >&2
  1269. exit 1
  1270. ;;
  1271. esac
  1272. done
  1273. done
  1274. done
  1275. done
  1276. echo "------------------------------------------------------------------------"
  1277. if [ $FAILED -ne 0 -o $SRVMEM -ne 0 ];
  1278. then
  1279. printf "FAILED"
  1280. else
  1281. printf "PASSED"
  1282. fi
  1283. if [ "$MEMCHECK" -gt 0 ]; then
  1284. MEMREPORT=", $SRVMEM server memory errors"
  1285. else
  1286. MEMREPORT=""
  1287. fi
  1288. PASSED=$(( $TESTS - $FAILED ))
  1289. echo " ($PASSED / $TESTS tests ($SKIPPED skipped$MEMREPORT))"
  1290. FAILED=$(( $FAILED + $SRVMEM ))
  1291. exit $FAILED