ssl-opt.sh 143 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661
  1. #!/bin/sh
  2. # ssl-opt.sh
  3. #
  4. # This file is part of mbed TLS (https://tls.mbed.org)
  5. #
  6. # Copyright (c) 2016, ARM Limited, All Rights Reserved
  7. #
  8. # Purpose
  9. #
  10. # Executes tests to prove various TLS/SSL options and extensions.
  11. #
  12. # The goal is not to cover every ciphersuite/version, but instead to cover
  13. # specific options (max fragment length, truncated hmac, etc) or procedures
  14. # (session resumption from cache or ticket, renego, etc).
  15. #
  16. # The tests assume a build with default options, with exceptions expressed
  17. # with a dependency. The tests focus on functionality and do not consider
  18. # performance.
  19. #
  20. set -u
  21. # default values, can be overriden by the environment
  22. : ${P_SRV:=../programs/ssl/ssl_server2}
  23. : ${P_CLI:=../programs/ssl/ssl_client2}
  24. : ${P_PXY:=../programs/test/udp_proxy}
  25. : ${OPENSSL_CMD:=openssl} # OPENSSL would conflict with the build system
  26. : ${GNUTLS_CLI:=gnutls-cli}
  27. : ${GNUTLS_SERV:=gnutls-serv}
  28. O_SRV="$OPENSSL_CMD s_server -www -cert data_files/server5.crt -key data_files/server5.key"
  29. O_CLI="echo 'GET / HTTP/1.0' | $OPENSSL_CMD s_client"
  30. G_SRV="$GNUTLS_SERV --x509certfile data_files/server5.crt --x509keyfile data_files/server5.key"
  31. G_CLI="echo 'GET / HTTP/1.0' | $GNUTLS_CLI --x509cafile data_files/test-ca_cat12.crt"
  32. TESTS=0
  33. FAILS=0
  34. SKIPS=0
  35. CONFIG_H='../include/mbedtls/config.h'
  36. MEMCHECK=0
  37. FILTER='.*'
  38. EXCLUDE='^$'
  39. SHOW_TEST_NUMBER=0
  40. RUN_TEST_NUMBER=''
  41. PRESERVE_LOGS=0
  42. print_usage() {
  43. echo "Usage: $0 [options]"
  44. printf " -h|--help\tPrint this help.\n"
  45. printf " -m|--memcheck\tCheck memory leaks and errors.\n"
  46. printf " -f|--filter\tOnly matching tests are executed (default: '$FILTER')\n"
  47. printf " -e|--exclude\tMatching tests are excluded (default: '$EXCLUDE')\n"
  48. printf " -n|--number\tExecute only numbered test (comma-separated, e.g. '245,256')\n"
  49. printf " -s|--show-numbers\tShow test numbers in front of test names\n"
  50. printf " -p|--preserve-logs\tPreserve logs of successful tests as well\n"
  51. printf " --seed\tInteger seed value to use for this test run\n"
  52. }
  53. get_options() {
  54. while [ $# -gt 0 ]; do
  55. case "$1" in
  56. -f|--filter)
  57. shift; FILTER=$1
  58. ;;
  59. -e|--exclude)
  60. shift; EXCLUDE=$1
  61. ;;
  62. -m|--memcheck)
  63. MEMCHECK=1
  64. ;;
  65. -n|--number)
  66. shift; RUN_TEST_NUMBER=$1
  67. ;;
  68. -s|--show-numbers)
  69. SHOW_TEST_NUMBER=1
  70. ;;
  71. -p|--preserve-logs)
  72. PRESERVE_LOGS=1
  73. ;;
  74. --seed)
  75. shift; SEED="$1"
  76. ;;
  77. -h|--help)
  78. print_usage
  79. exit 0
  80. ;;
  81. *)
  82. echo "Unknown argument: '$1'"
  83. print_usage
  84. exit 1
  85. ;;
  86. esac
  87. shift
  88. done
  89. }
  90. # skip next test if the flag is not enabled in config.h
  91. requires_config_enabled() {
  92. if grep "^#define $1" $CONFIG_H > /dev/null; then :; else
  93. SKIP_NEXT="YES"
  94. fi
  95. }
  96. # skip next test if OpenSSL doesn't support FALLBACK_SCSV
  97. requires_openssl_with_fallback_scsv() {
  98. if [ -z "${OPENSSL_HAS_FBSCSV:-}" ]; then
  99. if $OPENSSL_CMD s_client -help 2>&1 | grep fallback_scsv >/dev/null
  100. then
  101. OPENSSL_HAS_FBSCSV="YES"
  102. else
  103. OPENSSL_HAS_FBSCSV="NO"
  104. fi
  105. fi
  106. if [ "$OPENSSL_HAS_FBSCSV" = "NO" ]; then
  107. SKIP_NEXT="YES"
  108. fi
  109. }
  110. # skip next test if GnuTLS isn't available
  111. requires_gnutls() {
  112. if [ -z "${GNUTLS_AVAILABLE:-}" ]; then
  113. if ( which "$GNUTLS_CLI" && which "$GNUTLS_SERV" ) >/dev/null 2>&1; then
  114. GNUTLS_AVAILABLE="YES"
  115. else
  116. GNUTLS_AVAILABLE="NO"
  117. fi
  118. fi
  119. if [ "$GNUTLS_AVAILABLE" = "NO" ]; then
  120. SKIP_NEXT="YES"
  121. fi
  122. }
  123. # skip next test if IPv6 isn't available on this host
  124. requires_ipv6() {
  125. if [ -z "${HAS_IPV6:-}" ]; then
  126. $P_SRV server_addr='::1' > $SRV_OUT 2>&1 &
  127. SRV_PID=$!
  128. sleep 1
  129. kill $SRV_PID >/dev/null 2>&1
  130. if grep "NET - Binding of the socket failed" $SRV_OUT >/dev/null; then
  131. HAS_IPV6="NO"
  132. else
  133. HAS_IPV6="YES"
  134. fi
  135. rm -r $SRV_OUT
  136. fi
  137. if [ "$HAS_IPV6" = "NO" ]; then
  138. SKIP_NEXT="YES"
  139. fi
  140. }
  141. # skip the next test if valgrind is in use
  142. not_with_valgrind() {
  143. if [ "$MEMCHECK" -gt 0 ]; then
  144. SKIP_NEXT="YES"
  145. fi
  146. }
  147. # skip the next test if valgrind is NOT in use
  148. only_with_valgrind() {
  149. if [ "$MEMCHECK" -eq 0 ]; then
  150. SKIP_NEXT="YES"
  151. fi
  152. }
  153. # multiply the client timeout delay by the given factor for the next test
  154. client_needs_more_time() {
  155. CLI_DELAY_FACTOR=$1
  156. }
  157. # wait for the given seconds after the client finished in the next test
  158. server_needs_more_time() {
  159. SRV_DELAY_SECONDS=$1
  160. }
  161. # print_name <name>
  162. print_name() {
  163. TESTS=$(( $TESTS + 1 ))
  164. LINE=""
  165. if [ "$SHOW_TEST_NUMBER" -gt 0 ]; then
  166. LINE="$TESTS "
  167. fi
  168. LINE="$LINE$1"
  169. printf "$LINE "
  170. LEN=$(( 72 - `echo "$LINE" | wc -c` ))
  171. for i in `seq 1 $LEN`; do printf '.'; done
  172. printf ' '
  173. }
  174. # fail <message>
  175. fail() {
  176. echo "FAIL"
  177. echo " ! $1"
  178. mv $SRV_OUT o-srv-${TESTS}.log
  179. mv $CLI_OUT o-cli-${TESTS}.log
  180. if [ -n "$PXY_CMD" ]; then
  181. mv $PXY_OUT o-pxy-${TESTS}.log
  182. fi
  183. echo " ! outputs saved to o-XXX-${TESTS}.log"
  184. if [ "X${USER:-}" = Xbuildbot -o "X${LOGNAME:-}" = Xbuildbot ]; then
  185. echo " ! server output:"
  186. cat o-srv-${TESTS}.log
  187. echo " ! ========================================================"
  188. echo " ! client output:"
  189. cat o-cli-${TESTS}.log
  190. if [ -n "$PXY_CMD" ]; then
  191. echo " ! ========================================================"
  192. echo " ! proxy output:"
  193. cat o-pxy-${TESTS}.log
  194. fi
  195. echo ""
  196. fi
  197. FAILS=$(( $FAILS + 1 ))
  198. }
  199. # is_polar <cmd_line>
  200. is_polar() {
  201. echo "$1" | grep 'ssl_server2\|ssl_client2' > /dev/null
  202. }
  203. # openssl s_server doesn't have -www with DTLS
  204. check_osrv_dtls() {
  205. if echo "$SRV_CMD" | grep 's_server.*-dtls' >/dev/null; then
  206. NEEDS_INPUT=1
  207. SRV_CMD="$( echo $SRV_CMD | sed s/-www// )"
  208. else
  209. NEEDS_INPUT=0
  210. fi
  211. }
  212. # provide input to commands that need it
  213. provide_input() {
  214. if [ $NEEDS_INPUT -eq 0 ]; then
  215. return
  216. fi
  217. while true; do
  218. echo "HTTP/1.0 200 OK"
  219. sleep 1
  220. done
  221. }
  222. # has_mem_err <log_file_name>
  223. has_mem_err() {
  224. if ( grep -F 'All heap blocks were freed -- no leaks are possible' "$1" &&
  225. grep -F 'ERROR SUMMARY: 0 errors from 0 contexts' "$1" ) > /dev/null
  226. then
  227. return 1 # false: does not have errors
  228. else
  229. return 0 # true: has errors
  230. fi
  231. }
  232. # wait for server to start: two versions depending on lsof availability
  233. wait_server_start() {
  234. if which lsof >/dev/null 2>&1; then
  235. START_TIME=$( date +%s )
  236. DONE=0
  237. # make a tight loop, server usually takes less than 1 sec to start
  238. if [ "$DTLS" -eq 1 ]; then
  239. while [ $DONE -eq 0 ]; do
  240. if lsof -nbi UDP:"$SRV_PORT" 2>/dev/null | grep UDP >/dev/null
  241. then
  242. DONE=1
  243. elif [ $(( $( date +%s ) - $START_TIME )) -gt $DOG_DELAY ]; then
  244. echo "SERVERSTART TIMEOUT"
  245. echo "SERVERSTART TIMEOUT" >> $SRV_OUT
  246. DONE=1
  247. fi
  248. done
  249. else
  250. while [ $DONE -eq 0 ]; do
  251. if lsof -nbi TCP:"$SRV_PORT" 2>/dev/null | grep LISTEN >/dev/null
  252. then
  253. DONE=1
  254. elif [ $(( $( date +%s ) - $START_TIME )) -gt $DOG_DELAY ]; then
  255. echo "SERVERSTART TIMEOUT"
  256. echo "SERVERSTART TIMEOUT" >> $SRV_OUT
  257. DONE=1
  258. fi
  259. done
  260. fi
  261. else
  262. sleep "$START_DELAY"
  263. fi
  264. }
  265. # wait for client to terminate and set CLI_EXIT
  266. # must be called right after starting the client
  267. wait_client_done() {
  268. CLI_PID=$!
  269. CLI_DELAY=$(( $DOG_DELAY * $CLI_DELAY_FACTOR ))
  270. CLI_DELAY_FACTOR=1
  271. ( sleep $CLI_DELAY; echo "===CLIENT_TIMEOUT===" >> $CLI_OUT; kill $CLI_PID ) &
  272. DOG_PID=$!
  273. wait $CLI_PID
  274. CLI_EXIT=$?
  275. kill $DOG_PID >/dev/null 2>&1
  276. wait $DOG_PID
  277. echo "EXIT: $CLI_EXIT" >> $CLI_OUT
  278. sleep $SRV_DELAY_SECONDS
  279. SRV_DELAY_SECONDS=0
  280. }
  281. # check if the given command uses dtls and sets global variable DTLS
  282. detect_dtls() {
  283. if echo "$1" | grep 'dtls=1\|-dtls1\|-u' >/dev/null; then
  284. DTLS=1
  285. else
  286. DTLS=0
  287. fi
  288. }
  289. # Usage: run_test name [-p proxy_cmd] srv_cmd cli_cmd cli_exit [option [...]]
  290. # Options: -s pattern pattern that must be present in server output
  291. # -c pattern pattern that must be present in client output
  292. # -u pattern lines after pattern must be unique in client output
  293. # -S pattern pattern that must be absent in server output
  294. # -C pattern pattern that must be absent in client output
  295. # -U pattern lines after pattern must be unique in server output
  296. run_test() {
  297. NAME="$1"
  298. shift 1
  299. if echo "$NAME" | grep "$FILTER" | grep -v "$EXCLUDE" >/dev/null; then :
  300. else
  301. SKIP_NEXT="NO"
  302. return
  303. fi
  304. print_name "$NAME"
  305. # Do we only run numbered tests?
  306. if [ "X$RUN_TEST_NUMBER" = "X" ]; then :
  307. elif echo ",$RUN_TEST_NUMBER," | grep ",$TESTS," >/dev/null; then :
  308. else
  309. SKIP_NEXT="YES"
  310. fi
  311. # should we skip?
  312. if [ "X$SKIP_NEXT" = "XYES" ]; then
  313. SKIP_NEXT="NO"
  314. echo "SKIP"
  315. SKIPS=$(( $SKIPS + 1 ))
  316. return
  317. fi
  318. # does this test use a proxy?
  319. if [ "X$1" = "X-p" ]; then
  320. PXY_CMD="$2"
  321. shift 2
  322. else
  323. PXY_CMD=""
  324. fi
  325. # get commands and client output
  326. SRV_CMD="$1"
  327. CLI_CMD="$2"
  328. CLI_EXPECT="$3"
  329. shift 3
  330. # fix client port
  331. if [ -n "$PXY_CMD" ]; then
  332. CLI_CMD=$( echo "$CLI_CMD" | sed s/+SRV_PORT/$PXY_PORT/g )
  333. else
  334. CLI_CMD=$( echo "$CLI_CMD" | sed s/+SRV_PORT/$SRV_PORT/g )
  335. fi
  336. # update DTLS variable
  337. detect_dtls "$SRV_CMD"
  338. # prepend valgrind to our commands if active
  339. if [ "$MEMCHECK" -gt 0 ]; then
  340. if is_polar "$SRV_CMD"; then
  341. SRV_CMD="valgrind --leak-check=full $SRV_CMD"
  342. fi
  343. if is_polar "$CLI_CMD"; then
  344. CLI_CMD="valgrind --leak-check=full $CLI_CMD"
  345. fi
  346. fi
  347. TIMES_LEFT=2
  348. while [ $TIMES_LEFT -gt 0 ]; do
  349. TIMES_LEFT=$(( $TIMES_LEFT - 1 ))
  350. # run the commands
  351. if [ -n "$PXY_CMD" ]; then
  352. echo "$PXY_CMD" > $PXY_OUT
  353. $PXY_CMD >> $PXY_OUT 2>&1 &
  354. PXY_PID=$!
  355. # assume proxy starts faster than server
  356. fi
  357. check_osrv_dtls
  358. echo "$SRV_CMD" > $SRV_OUT
  359. provide_input | $SRV_CMD >> $SRV_OUT 2>&1 &
  360. SRV_PID=$!
  361. wait_server_start
  362. echo "$CLI_CMD" > $CLI_OUT
  363. eval "$CLI_CMD" >> $CLI_OUT 2>&1 &
  364. wait_client_done
  365. # terminate the server (and the proxy)
  366. kill $SRV_PID
  367. wait $SRV_PID
  368. if [ -n "$PXY_CMD" ]; then
  369. kill $PXY_PID >/dev/null 2>&1
  370. wait $PXY_PID
  371. fi
  372. # retry only on timeouts
  373. if grep '===CLIENT_TIMEOUT===' $CLI_OUT >/dev/null; then
  374. printf "RETRY "
  375. else
  376. TIMES_LEFT=0
  377. fi
  378. done
  379. # check if the client and server went at least to the handshake stage
  380. # (useful to avoid tests with only negative assertions and non-zero
  381. # expected client exit to incorrectly succeed in case of catastrophic
  382. # failure)
  383. if is_polar "$SRV_CMD"; then
  384. if grep "Performing the SSL/TLS handshake" $SRV_OUT >/dev/null; then :;
  385. else
  386. fail "server or client failed to reach handshake stage"
  387. return
  388. fi
  389. fi
  390. if is_polar "$CLI_CMD"; then
  391. if grep "Performing the SSL/TLS handshake" $CLI_OUT >/dev/null; then :;
  392. else
  393. fail "server or client failed to reach handshake stage"
  394. return
  395. fi
  396. fi
  397. # check server exit code
  398. if [ $? != 0 ]; then
  399. fail "server fail"
  400. return
  401. fi
  402. # check client exit code
  403. if [ \( "$CLI_EXPECT" = 0 -a "$CLI_EXIT" != 0 \) -o \
  404. \( "$CLI_EXPECT" != 0 -a "$CLI_EXIT" = 0 \) ]
  405. then
  406. fail "bad client exit code (expected $CLI_EXPECT, got $CLI_EXIT)"
  407. return
  408. fi
  409. # check other assertions
  410. # lines beginning with == are added by valgrind, ignore them
  411. # lines with 'Serious error when reading debug info', are valgrind issues as well
  412. while [ $# -gt 0 ]
  413. do
  414. case $1 in
  415. "-s")
  416. if grep -v '^==' $SRV_OUT | grep -v 'Serious error when reading debug info' | grep "$2" >/dev/null; then :; else
  417. fail "pattern '$2' MUST be present in the Server output"
  418. return
  419. fi
  420. ;;
  421. "-c")
  422. if grep -v '^==' $CLI_OUT | grep -v 'Serious error when reading debug info' | grep "$2" >/dev/null; then :; else
  423. fail "pattern '$2' MUST be present in the Client output"
  424. return
  425. fi
  426. ;;
  427. "-S")
  428. if grep -v '^==' $SRV_OUT | grep -v 'Serious error when reading debug info' | grep "$2" >/dev/null; then
  429. fail "pattern '$2' MUST NOT be present in the Server output"
  430. return
  431. fi
  432. ;;
  433. "-C")
  434. if grep -v '^==' $CLI_OUT | grep -v 'Serious error when reading debug info' | grep "$2" >/dev/null; then
  435. fail "pattern '$2' MUST NOT be present in the Client output"
  436. return
  437. fi
  438. ;;
  439. # The filtering in the following two options (-u and -U) do the following
  440. # - ignore valgrind output
  441. # - filter out everything but lines right after the pattern occurances
  442. # - keep one of each non-unique line
  443. # - count how many lines remain
  444. # A line with '--' will remain in the result from previous outputs, so the number of lines in the result will be 1
  445. # if there were no duplicates.
  446. "-U")
  447. if [ $(grep -v '^==' $SRV_OUT | grep -v 'Serious error when reading debug info' | grep -A1 "$2" | grep -v "$2" | sort | uniq -d | wc -l) -gt 1 ]; then
  448. fail "lines following pattern '$2' must be unique in Server output"
  449. return
  450. fi
  451. ;;
  452. "-u")
  453. if [ $(grep -v '^==' $CLI_OUT | grep -v 'Serious error when reading debug info' | grep -A1 "$2" | grep -v "$2" | sort | uniq -d | wc -l) -gt 1 ]; then
  454. fail "lines following pattern '$2' must be unique in Client output"
  455. return
  456. fi
  457. ;;
  458. *)
  459. echo "Unknown test: $1" >&2
  460. exit 1
  461. esac
  462. shift 2
  463. done
  464. # check valgrind's results
  465. if [ "$MEMCHECK" -gt 0 ]; then
  466. if is_polar "$SRV_CMD" && has_mem_err $SRV_OUT; then
  467. fail "Server has memory errors"
  468. return
  469. fi
  470. if is_polar "$CLI_CMD" && has_mem_err $CLI_OUT; then
  471. fail "Client has memory errors"
  472. return
  473. fi
  474. fi
  475. # if we're here, everything is ok
  476. echo "PASS"
  477. if [ "$PRESERVE_LOGS" -gt 0 ]; then
  478. mv $SRV_OUT o-srv-${TESTS}.log
  479. mv $CLI_OUT o-cli-${TESTS}.log
  480. fi
  481. rm -f $SRV_OUT $CLI_OUT $PXY_OUT
  482. }
  483. cleanup() {
  484. rm -f $CLI_OUT $SRV_OUT $PXY_OUT $SESSION
  485. test -n "${SRV_PID:-}" && kill $SRV_PID >/dev/null 2>&1
  486. test -n "${PXY_PID:-}" && kill $PXY_PID >/dev/null 2>&1
  487. test -n "${CLI_PID:-}" && kill $CLI_PID >/dev/null 2>&1
  488. test -n "${DOG_PID:-}" && kill $DOG_PID >/dev/null 2>&1
  489. exit 1
  490. }
  491. #
  492. # MAIN
  493. #
  494. if cd $( dirname $0 ); then :; else
  495. echo "cd $( dirname $0 ) failed" >&2
  496. exit 1
  497. fi
  498. get_options "$@"
  499. # sanity checks, avoid an avalanche of errors
  500. if [ ! -x "$P_SRV" ]; then
  501. echo "Command '$P_SRV' is not an executable file"
  502. exit 1
  503. fi
  504. if [ ! -x "$P_CLI" ]; then
  505. echo "Command '$P_CLI' is not an executable file"
  506. exit 1
  507. fi
  508. if [ ! -x "$P_PXY" ]; then
  509. echo "Command '$P_PXY' is not an executable file"
  510. exit 1
  511. fi
  512. if [ "$MEMCHECK" -gt 0 ]; then
  513. if which valgrind >/dev/null 2>&1; then :; else
  514. echo "Memcheck not possible. Valgrind not found"
  515. exit 1
  516. fi
  517. fi
  518. if which $OPENSSL_CMD >/dev/null 2>&1; then :; else
  519. echo "Command '$OPENSSL_CMD' not found"
  520. exit 1
  521. fi
  522. # used by watchdog
  523. MAIN_PID="$$"
  524. # be more patient with valgrind
  525. if [ "$MEMCHECK" -gt 0 ]; then
  526. START_DELAY=3
  527. DOG_DELAY=30
  528. else
  529. START_DELAY=1
  530. DOG_DELAY=10
  531. fi
  532. CLI_DELAY_FACTOR=1
  533. SRV_DELAY_SECONDS=0
  534. # Pick a "unique" server port in the range 10000-19999, and a proxy port
  535. PORT_BASE="0000$$"
  536. PORT_BASE="$( printf $PORT_BASE | tail -c 4 )"
  537. SRV_PORT="1$PORT_BASE"
  538. PXY_PORT="2$PORT_BASE"
  539. unset PORT_BASE
  540. # fix commands to use this port, force IPv4 while at it
  541. # +SRV_PORT will be replaced by either $SRV_PORT or $PXY_PORT later
  542. P_SRV="$P_SRV server_addr=127.0.0.1 server_port=$SRV_PORT"
  543. P_CLI="$P_CLI server_addr=127.0.0.1 server_port=+SRV_PORT"
  544. P_PXY="$P_PXY server_addr=127.0.0.1 server_port=$SRV_PORT listen_addr=127.0.0.1 listen_port=$PXY_PORT ${SEED:+"seed=$SEED"}"
  545. O_SRV="$O_SRV -accept $SRV_PORT -dhparam data_files/dhparams.pem"
  546. O_CLI="$O_CLI -connect localhost:+SRV_PORT"
  547. G_SRV="$G_SRV -p $SRV_PORT"
  548. G_CLI="$G_CLI -p +SRV_PORT localhost"
  549. # Also pick a unique name for intermediate files
  550. SRV_OUT="srv_out.$$"
  551. CLI_OUT="cli_out.$$"
  552. PXY_OUT="pxy_out.$$"
  553. SESSION="session.$$"
  554. SKIP_NEXT="NO"
  555. trap cleanup INT TERM HUP
  556. # Basic test
  557. # Checks that:
  558. # - things work with all ciphersuites active (used with config-full in all.sh)
  559. # - the expected (highest security) parameters are selected
  560. # ("signature_algorithm ext: 6" means SHA-512 (highest common hash))
  561. run_test "Default" \
  562. "$P_SRV debug_level=3" \
  563. "$P_CLI" \
  564. 0 \
  565. -s "Protocol is TLSv1.2" \
  566. -s "Ciphersuite is TLS-ECDHE-ECDSA-WITH-AES-256-GCM-SHA384" \
  567. -s "client hello v3, signature_algorithm ext: 6" \
  568. -s "ECDHE curve: secp521r1" \
  569. -S "error" \
  570. -C "error"
  571. run_test "Default, DTLS" \
  572. "$P_SRV dtls=1" \
  573. "$P_CLI dtls=1" \
  574. 0 \
  575. -s "Protocol is DTLSv1.2" \
  576. -s "Ciphersuite is TLS-ECDHE-ECDSA-WITH-AES-256-GCM-SHA384"
  577. # Test for uniqueness of IVs in AEAD ciphersuites
  578. run_test "Unique IV in GCM" \
  579. "$P_SRV exchanges=20 debug_level=4" \
  580. "$P_CLI exchanges=20 debug_level=4 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-256-GCM-SHA384" \
  581. 0 \
  582. -u "IV used" \
  583. -U "IV used"
  584. # Tests for rc4 option
  585. requires_config_enabled MBEDTLS_REMOVE_ARC4_CIPHERSUITES
  586. run_test "RC4: server disabled, client enabled" \
  587. "$P_SRV" \
  588. "$P_CLI force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
  589. 1 \
  590. -s "SSL - The server has no ciphersuites in common"
  591. requires_config_enabled MBEDTLS_REMOVE_ARC4_CIPHERSUITES
  592. run_test "RC4: server half, client enabled" \
  593. "$P_SRV arc4=1" \
  594. "$P_CLI force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
  595. 1 \
  596. -s "SSL - The server has no ciphersuites in common"
  597. run_test "RC4: server enabled, client disabled" \
  598. "$P_SRV force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
  599. "$P_CLI" \
  600. 1 \
  601. -s "SSL - The server has no ciphersuites in common"
  602. run_test "RC4: both enabled" \
  603. "$P_SRV force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
  604. "$P_CLI force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
  605. 0 \
  606. -S "SSL - None of the common ciphersuites is usable" \
  607. -S "SSL - The server has no ciphersuites in common"
  608. # Tests for Truncated HMAC extension
  609. run_test "Truncated HMAC: client default, server default" \
  610. "$P_SRV debug_level=4" \
  611. "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
  612. 0 \
  613. -s "dumping 'computed mac' (20 bytes)" \
  614. -S "dumping 'computed mac' (10 bytes)"
  615. run_test "Truncated HMAC: client disabled, server default" \
  616. "$P_SRV debug_level=4" \
  617. "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA \
  618. trunc_hmac=0" \
  619. 0 \
  620. -s "dumping 'computed mac' (20 bytes)" \
  621. -S "dumping 'computed mac' (10 bytes)"
  622. run_test "Truncated HMAC: client enabled, server default" \
  623. "$P_SRV debug_level=4" \
  624. "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA \
  625. trunc_hmac=1" \
  626. 0 \
  627. -s "dumping 'computed mac' (20 bytes)" \
  628. -S "dumping 'computed mac' (10 bytes)"
  629. run_test "Truncated HMAC: client enabled, server disabled" \
  630. "$P_SRV debug_level=4 trunc_hmac=0" \
  631. "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA \
  632. trunc_hmac=1" \
  633. 0 \
  634. -s "dumping 'computed mac' (20 bytes)" \
  635. -S "dumping 'computed mac' (10 bytes)"
  636. run_test "Truncated HMAC: client enabled, server enabled" \
  637. "$P_SRV debug_level=4 trunc_hmac=1" \
  638. "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA \
  639. trunc_hmac=1" \
  640. 0 \
  641. -S "dumping 'computed mac' (20 bytes)" \
  642. -s "dumping 'computed mac' (10 bytes)"
  643. # Tests for Encrypt-then-MAC extension
  644. run_test "Encrypt then MAC: default" \
  645. "$P_SRV debug_level=3 \
  646. force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
  647. "$P_CLI debug_level=3" \
  648. 0 \
  649. -c "client hello, adding encrypt_then_mac extension" \
  650. -s "found encrypt then mac extension" \
  651. -s "server hello, adding encrypt then mac extension" \
  652. -c "found encrypt_then_mac extension" \
  653. -c "using encrypt then mac" \
  654. -s "using encrypt then mac"
  655. run_test "Encrypt then MAC: client enabled, server disabled" \
  656. "$P_SRV debug_level=3 etm=0 \
  657. force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
  658. "$P_CLI debug_level=3 etm=1" \
  659. 0 \
  660. -c "client hello, adding encrypt_then_mac extension" \
  661. -s "found encrypt then mac extension" \
  662. -S "server hello, adding encrypt then mac extension" \
  663. -C "found encrypt_then_mac extension" \
  664. -C "using encrypt then mac" \
  665. -S "using encrypt then mac"
  666. run_test "Encrypt then MAC: client enabled, aead cipher" \
  667. "$P_SRV debug_level=3 etm=1 \
  668. force_ciphersuite=TLS-RSA-WITH-AES-128-GCM-SHA256" \
  669. "$P_CLI debug_level=3 etm=1" \
  670. 0 \
  671. -c "client hello, adding encrypt_then_mac extension" \
  672. -s "found encrypt then mac extension" \
  673. -S "server hello, adding encrypt then mac extension" \
  674. -C "found encrypt_then_mac extension" \
  675. -C "using encrypt then mac" \
  676. -S "using encrypt then mac"
  677. run_test "Encrypt then MAC: client enabled, stream cipher" \
  678. "$P_SRV debug_level=3 etm=1 \
  679. force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
  680. "$P_CLI debug_level=3 etm=1 arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
  681. 0 \
  682. -c "client hello, adding encrypt_then_mac extension" \
  683. -s "found encrypt then mac extension" \
  684. -S "server hello, adding encrypt then mac extension" \
  685. -C "found encrypt_then_mac extension" \
  686. -C "using encrypt then mac" \
  687. -S "using encrypt then mac"
  688. run_test "Encrypt then MAC: client disabled, server enabled" \
  689. "$P_SRV debug_level=3 etm=1 \
  690. force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
  691. "$P_CLI debug_level=3 etm=0" \
  692. 0 \
  693. -C "client hello, adding encrypt_then_mac extension" \
  694. -S "found encrypt then mac extension" \
  695. -S "server hello, adding encrypt then mac extension" \
  696. -C "found encrypt_then_mac extension" \
  697. -C "using encrypt then mac" \
  698. -S "using encrypt then mac"
  699. requires_config_enabled MBEDTLS_SSL_PROTO_SSL3
  700. run_test "Encrypt then MAC: client SSLv3, server enabled" \
  701. "$P_SRV debug_level=3 min_version=ssl3 \
  702. force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
  703. "$P_CLI debug_level=3 force_version=ssl3" \
  704. 0 \
  705. -C "client hello, adding encrypt_then_mac extension" \
  706. -S "found encrypt then mac extension" \
  707. -S "server hello, adding encrypt then mac extension" \
  708. -C "found encrypt_then_mac extension" \
  709. -C "using encrypt then mac" \
  710. -S "using encrypt then mac"
  711. requires_config_enabled MBEDTLS_SSL_PROTO_SSL3
  712. run_test "Encrypt then MAC: client enabled, server SSLv3" \
  713. "$P_SRV debug_level=3 force_version=ssl3 \
  714. force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
  715. "$P_CLI debug_level=3 min_version=ssl3" \
  716. 0 \
  717. -c "client hello, adding encrypt_then_mac extension" \
  718. -S "found encrypt then mac extension" \
  719. -S "server hello, adding encrypt then mac extension" \
  720. -C "found encrypt_then_mac extension" \
  721. -C "using encrypt then mac" \
  722. -S "using encrypt then mac"
  723. # Tests for Extended Master Secret extension
  724. run_test "Extended Master Secret: default" \
  725. "$P_SRV debug_level=3" \
  726. "$P_CLI debug_level=3" \
  727. 0 \
  728. -c "client hello, adding extended_master_secret extension" \
  729. -s "found extended master secret extension" \
  730. -s "server hello, adding extended master secret extension" \
  731. -c "found extended_master_secret extension" \
  732. -c "using extended master secret" \
  733. -s "using extended master secret"
  734. run_test "Extended Master Secret: client enabled, server disabled" \
  735. "$P_SRV debug_level=3 extended_ms=0" \
  736. "$P_CLI debug_level=3 extended_ms=1" \
  737. 0 \
  738. -c "client hello, adding extended_master_secret extension" \
  739. -s "found extended master secret extension" \
  740. -S "server hello, adding extended master secret extension" \
  741. -C "found extended_master_secret extension" \
  742. -C "using extended master secret" \
  743. -S "using extended master secret"
  744. run_test "Extended Master Secret: client disabled, server enabled" \
  745. "$P_SRV debug_level=3 extended_ms=1" \
  746. "$P_CLI debug_level=3 extended_ms=0" \
  747. 0 \
  748. -C "client hello, adding extended_master_secret extension" \
  749. -S "found extended master secret extension" \
  750. -S "server hello, adding extended master secret extension" \
  751. -C "found extended_master_secret extension" \
  752. -C "using extended master secret" \
  753. -S "using extended master secret"
  754. requires_config_enabled MBEDTLS_SSL_PROTO_SSL3
  755. run_test "Extended Master Secret: client SSLv3, server enabled" \
  756. "$P_SRV debug_level=3 min_version=ssl3" \
  757. "$P_CLI debug_level=3 force_version=ssl3" \
  758. 0 \
  759. -C "client hello, adding extended_master_secret extension" \
  760. -S "found extended master secret extension" \
  761. -S "server hello, adding extended master secret extension" \
  762. -C "found extended_master_secret extension" \
  763. -C "using extended master secret" \
  764. -S "using extended master secret"
  765. requires_config_enabled MBEDTLS_SSL_PROTO_SSL3
  766. run_test "Extended Master Secret: client enabled, server SSLv3" \
  767. "$P_SRV debug_level=3 force_version=ssl3" \
  768. "$P_CLI debug_level=3 min_version=ssl3" \
  769. 0 \
  770. -c "client hello, adding extended_master_secret extension" \
  771. -S "found extended master secret extension" \
  772. -S "server hello, adding extended master secret extension" \
  773. -C "found extended_master_secret extension" \
  774. -C "using extended master secret" \
  775. -S "using extended master secret"
  776. # Tests for FALLBACK_SCSV
  777. run_test "Fallback SCSV: default" \
  778. "$P_SRV debug_level=2" \
  779. "$P_CLI debug_level=3 force_version=tls1_1" \
  780. 0 \
  781. -C "adding FALLBACK_SCSV" \
  782. -S "received FALLBACK_SCSV" \
  783. -S "inapropriate fallback" \
  784. -C "is a fatal alert message (msg 86)"
  785. run_test "Fallback SCSV: explicitly disabled" \
  786. "$P_SRV debug_level=2" \
  787. "$P_CLI debug_level=3 force_version=tls1_1 fallback=0" \
  788. 0 \
  789. -C "adding FALLBACK_SCSV" \
  790. -S "received FALLBACK_SCSV" \
  791. -S "inapropriate fallback" \
  792. -C "is a fatal alert message (msg 86)"
  793. run_test "Fallback SCSV: enabled" \
  794. "$P_SRV debug_level=2" \
  795. "$P_CLI debug_level=3 force_version=tls1_1 fallback=1" \
  796. 1 \
  797. -c "adding FALLBACK_SCSV" \
  798. -s "received FALLBACK_SCSV" \
  799. -s "inapropriate fallback" \
  800. -c "is a fatal alert message (msg 86)"
  801. run_test "Fallback SCSV: enabled, max version" \
  802. "$P_SRV debug_level=2" \
  803. "$P_CLI debug_level=3 fallback=1" \
  804. 0 \
  805. -c "adding FALLBACK_SCSV" \
  806. -s "received FALLBACK_SCSV" \
  807. -S "inapropriate fallback" \
  808. -C "is a fatal alert message (msg 86)"
  809. requires_openssl_with_fallback_scsv
  810. run_test "Fallback SCSV: default, openssl server" \
  811. "$O_SRV" \
  812. "$P_CLI debug_level=3 force_version=tls1_1 fallback=0" \
  813. 0 \
  814. -C "adding FALLBACK_SCSV" \
  815. -C "is a fatal alert message (msg 86)"
  816. requires_openssl_with_fallback_scsv
  817. run_test "Fallback SCSV: enabled, openssl server" \
  818. "$O_SRV" \
  819. "$P_CLI debug_level=3 force_version=tls1_1 fallback=1" \
  820. 1 \
  821. -c "adding FALLBACK_SCSV" \
  822. -c "is a fatal alert message (msg 86)"
  823. requires_openssl_with_fallback_scsv
  824. run_test "Fallback SCSV: disabled, openssl client" \
  825. "$P_SRV debug_level=2" \
  826. "$O_CLI -tls1_1" \
  827. 0 \
  828. -S "received FALLBACK_SCSV" \
  829. -S "inapropriate fallback"
  830. requires_openssl_with_fallback_scsv
  831. run_test "Fallback SCSV: enabled, openssl client" \
  832. "$P_SRV debug_level=2" \
  833. "$O_CLI -tls1_1 -fallback_scsv" \
  834. 1 \
  835. -s "received FALLBACK_SCSV" \
  836. -s "inapropriate fallback"
  837. requires_openssl_with_fallback_scsv
  838. run_test "Fallback SCSV: enabled, max version, openssl client" \
  839. "$P_SRV debug_level=2" \
  840. "$O_CLI -fallback_scsv" \
  841. 0 \
  842. -s "received FALLBACK_SCSV" \
  843. -S "inapropriate fallback"
  844. # Tests for CBC 1/n-1 record splitting
  845. run_test "CBC Record splitting: TLS 1.2, no splitting" \
  846. "$P_SRV" \
  847. "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA \
  848. request_size=123 force_version=tls1_2" \
  849. 0 \
  850. -s "Read from client: 123 bytes read" \
  851. -S "Read from client: 1 bytes read" \
  852. -S "122 bytes read"
  853. run_test "CBC Record splitting: TLS 1.1, no splitting" \
  854. "$P_SRV" \
  855. "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA \
  856. request_size=123 force_version=tls1_1" \
  857. 0 \
  858. -s "Read from client: 123 bytes read" \
  859. -S "Read from client: 1 bytes read" \
  860. -S "122 bytes read"
  861. run_test "CBC Record splitting: TLS 1.0, splitting" \
  862. "$P_SRV" \
  863. "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA \
  864. request_size=123 force_version=tls1" \
  865. 0 \
  866. -S "Read from client: 123 bytes read" \
  867. -s "Read from client: 1 bytes read" \
  868. -s "122 bytes read"
  869. requires_config_enabled MBEDTLS_SSL_PROTO_SSL3
  870. run_test "CBC Record splitting: SSLv3, splitting" \
  871. "$P_SRV min_version=ssl3" \
  872. "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA \
  873. request_size=123 force_version=ssl3" \
  874. 0 \
  875. -S "Read from client: 123 bytes read" \
  876. -s "Read from client: 1 bytes read" \
  877. -s "122 bytes read"
  878. run_test "CBC Record splitting: TLS 1.0 RC4, no splitting" \
  879. "$P_SRV arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
  880. "$P_CLI force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA \
  881. request_size=123 force_version=tls1" \
  882. 0 \
  883. -s "Read from client: 123 bytes read" \
  884. -S "Read from client: 1 bytes read" \
  885. -S "122 bytes read"
  886. run_test "CBC Record splitting: TLS 1.0, splitting disabled" \
  887. "$P_SRV" \
  888. "$P_CLI force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA \
  889. request_size=123 force_version=tls1 recsplit=0" \
  890. 0 \
  891. -s "Read from client: 123 bytes read" \
  892. -S "Read from client: 1 bytes read" \
  893. -S "122 bytes read"
  894. run_test "CBC Record splitting: TLS 1.0, splitting, nbio" \
  895. "$P_SRV nbio=2" \
  896. "$P_CLI nbio=2 force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA \
  897. request_size=123 force_version=tls1" \
  898. 0 \
  899. -S "Read from client: 123 bytes read" \
  900. -s "Read from client: 1 bytes read" \
  901. -s "122 bytes read"
  902. # Tests for Session Tickets
  903. run_test "Session resume using tickets: basic" \
  904. "$P_SRV debug_level=3 tickets=1" \
  905. "$P_CLI debug_level=3 tickets=1 reconnect=1" \
  906. 0 \
  907. -c "client hello, adding session ticket extension" \
  908. -s "found session ticket extension" \
  909. -s "server hello, adding session ticket extension" \
  910. -c "found session_ticket extension" \
  911. -c "parse new session ticket" \
  912. -S "session successfully restored from cache" \
  913. -s "session successfully restored from ticket" \
  914. -s "a session has been resumed" \
  915. -c "a session has been resumed"
  916. run_test "Session resume using tickets: cache disabled" \
  917. "$P_SRV debug_level=3 tickets=1 cache_max=0" \
  918. "$P_CLI debug_level=3 tickets=1 reconnect=1" \
  919. 0 \
  920. -c "client hello, adding session ticket extension" \
  921. -s "found session ticket extension" \
  922. -s "server hello, adding session ticket extension" \
  923. -c "found session_ticket extension" \
  924. -c "parse new session ticket" \
  925. -S "session successfully restored from cache" \
  926. -s "session successfully restored from ticket" \
  927. -s "a session has been resumed" \
  928. -c "a session has been resumed"
  929. run_test "Session resume using tickets: timeout" \
  930. "$P_SRV debug_level=3 tickets=1 cache_max=0 ticket_timeout=1" \
  931. "$P_CLI debug_level=3 tickets=1 reconnect=1 reco_delay=2" \
  932. 0 \
  933. -c "client hello, adding session ticket extension" \
  934. -s "found session ticket extension" \
  935. -s "server hello, adding session ticket extension" \
  936. -c "found session_ticket extension" \
  937. -c "parse new session ticket" \
  938. -S "session successfully restored from cache" \
  939. -S "session successfully restored from ticket" \
  940. -S "a session has been resumed" \
  941. -C "a session has been resumed"
  942. run_test "Session resume using tickets: openssl server" \
  943. "$O_SRV" \
  944. "$P_CLI debug_level=3 tickets=1 reconnect=1" \
  945. 0 \
  946. -c "client hello, adding session ticket extension" \
  947. -c "found session_ticket extension" \
  948. -c "parse new session ticket" \
  949. -c "a session has been resumed"
  950. run_test "Session resume using tickets: openssl client" \
  951. "$P_SRV debug_level=3 tickets=1" \
  952. "( $O_CLI -sess_out $SESSION; \
  953. $O_CLI -sess_in $SESSION; \
  954. rm -f $SESSION )" \
  955. 0 \
  956. -s "found session ticket extension" \
  957. -s "server hello, adding session ticket extension" \
  958. -S "session successfully restored from cache" \
  959. -s "session successfully restored from ticket" \
  960. -s "a session has been resumed"
  961. # Tests for Session Resume based on session-ID and cache
  962. run_test "Session resume using cache: tickets enabled on client" \
  963. "$P_SRV debug_level=3 tickets=0" \
  964. "$P_CLI debug_level=3 tickets=1 reconnect=1" \
  965. 0 \
  966. -c "client hello, adding session ticket extension" \
  967. -s "found session ticket extension" \
  968. -S "server hello, adding session ticket extension" \
  969. -C "found session_ticket extension" \
  970. -C "parse new session ticket" \
  971. -s "session successfully restored from cache" \
  972. -S "session successfully restored from ticket" \
  973. -s "a session has been resumed" \
  974. -c "a session has been resumed"
  975. run_test "Session resume using cache: tickets enabled on server" \
  976. "$P_SRV debug_level=3 tickets=1" \
  977. "$P_CLI debug_level=3 tickets=0 reconnect=1" \
  978. 0 \
  979. -C "client hello, adding session ticket extension" \
  980. -S "found session ticket extension" \
  981. -S "server hello, adding session ticket extension" \
  982. -C "found session_ticket extension" \
  983. -C "parse new session ticket" \
  984. -s "session successfully restored from cache" \
  985. -S "session successfully restored from ticket" \
  986. -s "a session has been resumed" \
  987. -c "a session has been resumed"
  988. run_test "Session resume using cache: cache_max=0" \
  989. "$P_SRV debug_level=3 tickets=0 cache_max=0" \
  990. "$P_CLI debug_level=3 tickets=0 reconnect=1" \
  991. 0 \
  992. -S "session successfully restored from cache" \
  993. -S "session successfully restored from ticket" \
  994. -S "a session has been resumed" \
  995. -C "a session has been resumed"
  996. run_test "Session resume using cache: cache_max=1" \
  997. "$P_SRV debug_level=3 tickets=0 cache_max=1" \
  998. "$P_CLI debug_level=3 tickets=0 reconnect=1" \
  999. 0 \
  1000. -s "session successfully restored from cache" \
  1001. -S "session successfully restored from ticket" \
  1002. -s "a session has been resumed" \
  1003. -c "a session has been resumed"
  1004. run_test "Session resume using cache: timeout > delay" \
  1005. "$P_SRV debug_level=3 tickets=0" \
  1006. "$P_CLI debug_level=3 tickets=0 reconnect=1 reco_delay=0" \
  1007. 0 \
  1008. -s "session successfully restored from cache" \
  1009. -S "session successfully restored from ticket" \
  1010. -s "a session has been resumed" \
  1011. -c "a session has been resumed"
  1012. run_test "Session resume using cache: timeout < delay" \
  1013. "$P_SRV debug_level=3 tickets=0 cache_timeout=1" \
  1014. "$P_CLI debug_level=3 tickets=0 reconnect=1 reco_delay=2" \
  1015. 0 \
  1016. -S "session successfully restored from cache" \
  1017. -S "session successfully restored from ticket" \
  1018. -S "a session has been resumed" \
  1019. -C "a session has been resumed"
  1020. run_test "Session resume using cache: no timeout" \
  1021. "$P_SRV debug_level=3 tickets=0 cache_timeout=0" \
  1022. "$P_CLI debug_level=3 tickets=0 reconnect=1 reco_delay=2" \
  1023. 0 \
  1024. -s "session successfully restored from cache" \
  1025. -S "session successfully restored from ticket" \
  1026. -s "a session has been resumed" \
  1027. -c "a session has been resumed"
  1028. run_test "Session resume using cache: openssl client" \
  1029. "$P_SRV debug_level=3 tickets=0" \
  1030. "( $O_CLI -sess_out $SESSION; \
  1031. $O_CLI -sess_in $SESSION; \
  1032. rm -f $SESSION )" \
  1033. 0 \
  1034. -s "found session ticket extension" \
  1035. -S "server hello, adding session ticket extension" \
  1036. -s "session successfully restored from cache" \
  1037. -S "session successfully restored from ticket" \
  1038. -s "a session has been resumed"
  1039. run_test "Session resume using cache: openssl server" \
  1040. "$O_SRV" \
  1041. "$P_CLI debug_level=3 tickets=0 reconnect=1" \
  1042. 0 \
  1043. -C "found session_ticket extension" \
  1044. -C "parse new session ticket" \
  1045. -c "a session has been resumed"
  1046. # Tests for Max Fragment Length extension
  1047. run_test "Max fragment length: not used, reference" \
  1048. "$P_SRV debug_level=3" \
  1049. "$P_CLI debug_level=3" \
  1050. 0 \
  1051. -c "Maximum fragment length is 16384" \
  1052. -s "Maximum fragment length is 16384" \
  1053. -C "client hello, adding max_fragment_length extension" \
  1054. -S "found max fragment length extension" \
  1055. -S "server hello, max_fragment_length extension" \
  1056. -C "found max_fragment_length extension"
  1057. run_test "Max fragment length: used by client" \
  1058. "$P_SRV debug_level=3" \
  1059. "$P_CLI debug_level=3 max_frag_len=4096" \
  1060. 0 \
  1061. -c "Maximum fragment length is 4096" \
  1062. -s "Maximum fragment length is 4096" \
  1063. -c "client hello, adding max_fragment_length extension" \
  1064. -s "found max fragment length extension" \
  1065. -s "server hello, max_fragment_length extension" \
  1066. -c "found max_fragment_length extension"
  1067. run_test "Max fragment length: used by server" \
  1068. "$P_SRV debug_level=3 max_frag_len=4096" \
  1069. "$P_CLI debug_level=3" \
  1070. 0 \
  1071. -c "Maximum fragment length is 16384" \
  1072. -s "Maximum fragment length is 4096" \
  1073. -C "client hello, adding max_fragment_length extension" \
  1074. -S "found max fragment length extension" \
  1075. -S "server hello, max_fragment_length extension" \
  1076. -C "found max_fragment_length extension"
  1077. requires_gnutls
  1078. run_test "Max fragment length: gnutls server" \
  1079. "$G_SRV" \
  1080. "$P_CLI debug_level=3 max_frag_len=4096" \
  1081. 0 \
  1082. -c "Maximum fragment length is 4096" \
  1083. -c "client hello, adding max_fragment_length extension" \
  1084. -c "found max_fragment_length extension"
  1085. run_test "Max fragment length: client, message just fits" \
  1086. "$P_SRV debug_level=3" \
  1087. "$P_CLI debug_level=3 max_frag_len=2048 request_size=2048" \
  1088. 0 \
  1089. -c "Maximum fragment length is 2048" \
  1090. -s "Maximum fragment length is 2048" \
  1091. -c "client hello, adding max_fragment_length extension" \
  1092. -s "found max fragment length extension" \
  1093. -s "server hello, max_fragment_length extension" \
  1094. -c "found max_fragment_length extension" \
  1095. -c "2048 bytes written in 1 fragments" \
  1096. -s "2048 bytes read"
  1097. run_test "Max fragment length: client, larger message" \
  1098. "$P_SRV debug_level=3" \
  1099. "$P_CLI debug_level=3 max_frag_len=2048 request_size=2345" \
  1100. 0 \
  1101. -c "Maximum fragment length is 2048" \
  1102. -s "Maximum fragment length is 2048" \
  1103. -c "client hello, adding max_fragment_length extension" \
  1104. -s "found max fragment length extension" \
  1105. -s "server hello, max_fragment_length extension" \
  1106. -c "found max_fragment_length extension" \
  1107. -c "2345 bytes written in 2 fragments" \
  1108. -s "2048 bytes read" \
  1109. -s "297 bytes read"
  1110. run_test "Max fragment length: DTLS client, larger message" \
  1111. "$P_SRV debug_level=3 dtls=1" \
  1112. "$P_CLI debug_level=3 dtls=1 max_frag_len=2048 request_size=2345" \
  1113. 1 \
  1114. -c "Maximum fragment length is 2048" \
  1115. -s "Maximum fragment length is 2048" \
  1116. -c "client hello, adding max_fragment_length extension" \
  1117. -s "found max fragment length extension" \
  1118. -s "server hello, max_fragment_length extension" \
  1119. -c "found max_fragment_length extension" \
  1120. -c "fragment larger than.*maximum"
  1121. # Tests for renegotiation
  1122. run_test "Renegotiation: none, for reference" \
  1123. "$P_SRV debug_level=3 exchanges=2 auth_mode=optional" \
  1124. "$P_CLI debug_level=3 exchanges=2" \
  1125. 0 \
  1126. -C "client hello, adding renegotiation extension" \
  1127. -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
  1128. -S "found renegotiation extension" \
  1129. -s "server hello, secure renegotiation extension" \
  1130. -c "found renegotiation extension" \
  1131. -C "=> renegotiate" \
  1132. -S "=> renegotiate" \
  1133. -S "write hello request"
  1134. run_test "Renegotiation: client-initiated" \
  1135. "$P_SRV debug_level=3 exchanges=2 renegotiation=1 auth_mode=optional" \
  1136. "$P_CLI debug_level=3 exchanges=2 renegotiation=1 renegotiate=1" \
  1137. 0 \
  1138. -c "client hello, adding renegotiation extension" \
  1139. -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
  1140. -s "found renegotiation extension" \
  1141. -s "server hello, secure renegotiation extension" \
  1142. -c "found renegotiation extension" \
  1143. -c "=> renegotiate" \
  1144. -s "=> renegotiate" \
  1145. -S "write hello request"
  1146. run_test "Renegotiation: server-initiated" \
  1147. "$P_SRV debug_level=3 exchanges=2 renegotiation=1 auth_mode=optional renegotiate=1" \
  1148. "$P_CLI debug_level=3 exchanges=2 renegotiation=1" \
  1149. 0 \
  1150. -c "client hello, adding renegotiation extension" \
  1151. -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
  1152. -s "found renegotiation extension" \
  1153. -s "server hello, secure renegotiation extension" \
  1154. -c "found renegotiation extension" \
  1155. -c "=> renegotiate" \
  1156. -s "=> renegotiate" \
  1157. -s "write hello request"
  1158. run_test "Renegotiation: double" \
  1159. "$P_SRV debug_level=3 exchanges=2 renegotiation=1 auth_mode=optional renegotiate=1" \
  1160. "$P_CLI debug_level=3 exchanges=2 renegotiation=1 renegotiate=1" \
  1161. 0 \
  1162. -c "client hello, adding renegotiation extension" \
  1163. -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
  1164. -s "found renegotiation extension" \
  1165. -s "server hello, secure renegotiation extension" \
  1166. -c "found renegotiation extension" \
  1167. -c "=> renegotiate" \
  1168. -s "=> renegotiate" \
  1169. -s "write hello request"
  1170. run_test "Renegotiation: client-initiated, server-rejected" \
  1171. "$P_SRV debug_level=3 exchanges=2 renegotiation=0 auth_mode=optional" \
  1172. "$P_CLI debug_level=3 exchanges=2 renegotiation=1 renegotiate=1" \
  1173. 1 \
  1174. -c "client hello, adding renegotiation extension" \
  1175. -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
  1176. -S "found renegotiation extension" \
  1177. -s "server hello, secure renegotiation extension" \
  1178. -c "found renegotiation extension" \
  1179. -c "=> renegotiate" \
  1180. -S "=> renegotiate" \
  1181. -S "write hello request" \
  1182. -c "SSL - Unexpected message at ServerHello in renegotiation" \
  1183. -c "failed"
  1184. run_test "Renegotiation: server-initiated, client-rejected, default" \
  1185. "$P_SRV debug_level=3 exchanges=2 renegotiation=1 renegotiate=1 auth_mode=optional" \
  1186. "$P_CLI debug_level=3 exchanges=2 renegotiation=0" \
  1187. 0 \
  1188. -C "client hello, adding renegotiation extension" \
  1189. -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
  1190. -S "found renegotiation extension" \
  1191. -s "server hello, secure renegotiation extension" \
  1192. -c "found renegotiation extension" \
  1193. -C "=> renegotiate" \
  1194. -S "=> renegotiate" \
  1195. -s "write hello request" \
  1196. -S "SSL - An unexpected message was received from our peer" \
  1197. -S "failed"
  1198. run_test "Renegotiation: server-initiated, client-rejected, not enforced" \
  1199. "$P_SRV debug_level=3 exchanges=2 renegotiation=1 renegotiate=1 \
  1200. renego_delay=-1 auth_mode=optional" \
  1201. "$P_CLI debug_level=3 exchanges=2 renegotiation=0" \
  1202. 0 \
  1203. -C "client hello, adding renegotiation extension" \
  1204. -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
  1205. -S "found renegotiation extension" \
  1206. -s "server hello, secure renegotiation extension" \
  1207. -c "found renegotiation extension" \
  1208. -C "=> renegotiate" \
  1209. -S "=> renegotiate" \
  1210. -s "write hello request" \
  1211. -S "SSL - An unexpected message was received from our peer" \
  1212. -S "failed"
  1213. # delay 2 for 1 alert record + 1 application data record
  1214. run_test "Renegotiation: server-initiated, client-rejected, delay 2" \
  1215. "$P_SRV debug_level=3 exchanges=2 renegotiation=1 renegotiate=1 \
  1216. renego_delay=2 auth_mode=optional" \
  1217. "$P_CLI debug_level=3 exchanges=2 renegotiation=0" \
  1218. 0 \
  1219. -C "client hello, adding renegotiation extension" \
  1220. -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
  1221. -S "found renegotiation extension" \
  1222. -s "server hello, secure renegotiation extension" \
  1223. -c "found renegotiation extension" \
  1224. -C "=> renegotiate" \
  1225. -S "=> renegotiate" \
  1226. -s "write hello request" \
  1227. -S "SSL - An unexpected message was received from our peer" \
  1228. -S "failed"
  1229. run_test "Renegotiation: server-initiated, client-rejected, delay 0" \
  1230. "$P_SRV debug_level=3 exchanges=2 renegotiation=1 renegotiate=1 \
  1231. renego_delay=0 auth_mode=optional" \
  1232. "$P_CLI debug_level=3 exchanges=2 renegotiation=0" \
  1233. 0 \
  1234. -C "client hello, adding renegotiation extension" \
  1235. -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
  1236. -S "found renegotiation extension" \
  1237. -s "server hello, secure renegotiation extension" \
  1238. -c "found renegotiation extension" \
  1239. -C "=> renegotiate" \
  1240. -S "=> renegotiate" \
  1241. -s "write hello request" \
  1242. -s "SSL - An unexpected message was received from our peer"
  1243. run_test "Renegotiation: server-initiated, client-accepted, delay 0" \
  1244. "$P_SRV debug_level=3 exchanges=2 renegotiation=1 renegotiate=1 \
  1245. renego_delay=0 auth_mode=optional" \
  1246. "$P_CLI debug_level=3 exchanges=2 renegotiation=1" \
  1247. 0 \
  1248. -c "client hello, adding renegotiation extension" \
  1249. -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
  1250. -s "found renegotiation extension" \
  1251. -s "server hello, secure renegotiation extension" \
  1252. -c "found renegotiation extension" \
  1253. -c "=> renegotiate" \
  1254. -s "=> renegotiate" \
  1255. -s "write hello request" \
  1256. -S "SSL - An unexpected message was received from our peer" \
  1257. -S "failed"
  1258. run_test "Renegotiation: periodic, just below period" \
  1259. "$P_SRV debug_level=3 exchanges=9 renegotiation=1 renego_period=3 auth_mode=optional" \
  1260. "$P_CLI debug_level=3 exchanges=2 renegotiation=1" \
  1261. 0 \
  1262. -C "client hello, adding renegotiation extension" \
  1263. -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
  1264. -S "found renegotiation extension" \
  1265. -s "server hello, secure renegotiation extension" \
  1266. -c "found renegotiation extension" \
  1267. -S "record counter limit reached: renegotiate" \
  1268. -C "=> renegotiate" \
  1269. -S "=> renegotiate" \
  1270. -S "write hello request" \
  1271. -S "SSL - An unexpected message was received from our peer" \
  1272. -S "failed"
  1273. # one extra exchange to be able to complete renego
  1274. run_test "Renegotiation: periodic, just above period" \
  1275. "$P_SRV debug_level=3 exchanges=9 renegotiation=1 renego_period=3 auth_mode=optional" \
  1276. "$P_CLI debug_level=3 exchanges=4 renegotiation=1" \
  1277. 0 \
  1278. -c "client hello, adding renegotiation extension" \
  1279. -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
  1280. -s "found renegotiation extension" \
  1281. -s "server hello, secure renegotiation extension" \
  1282. -c "found renegotiation extension" \
  1283. -s "record counter limit reached: renegotiate" \
  1284. -c "=> renegotiate" \
  1285. -s "=> renegotiate" \
  1286. -s "write hello request" \
  1287. -S "SSL - An unexpected message was received from our peer" \
  1288. -S "failed"
  1289. run_test "Renegotiation: periodic, two times period" \
  1290. "$P_SRV debug_level=3 exchanges=9 renegotiation=1 renego_period=3 auth_mode=optional" \
  1291. "$P_CLI debug_level=3 exchanges=7 renegotiation=1" \
  1292. 0 \
  1293. -c "client hello, adding renegotiation extension" \
  1294. -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
  1295. -s "found renegotiation extension" \
  1296. -s "server hello, secure renegotiation extension" \
  1297. -c "found renegotiation extension" \
  1298. -s "record counter limit reached: renegotiate" \
  1299. -c "=> renegotiate" \
  1300. -s "=> renegotiate" \
  1301. -s "write hello request" \
  1302. -S "SSL - An unexpected message was received from our peer" \
  1303. -S "failed"
  1304. run_test "Renegotiation: periodic, above period, disabled" \
  1305. "$P_SRV debug_level=3 exchanges=9 renegotiation=0 renego_period=3 auth_mode=optional" \
  1306. "$P_CLI debug_level=3 exchanges=4 renegotiation=1" \
  1307. 0 \
  1308. -C "client hello, adding renegotiation extension" \
  1309. -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
  1310. -S "found renegotiation extension" \
  1311. -s "server hello, secure renegotiation extension" \
  1312. -c "found renegotiation extension" \
  1313. -S "record counter limit reached: renegotiate" \
  1314. -C "=> renegotiate" \
  1315. -S "=> renegotiate" \
  1316. -S "write hello request" \
  1317. -S "SSL - An unexpected message was received from our peer" \
  1318. -S "failed"
  1319. run_test "Renegotiation: nbio, client-initiated" \
  1320. "$P_SRV debug_level=3 nbio=2 exchanges=2 renegotiation=1 auth_mode=optional" \
  1321. "$P_CLI debug_level=3 nbio=2 exchanges=2 renegotiation=1 renegotiate=1" \
  1322. 0 \
  1323. -c "client hello, adding renegotiation extension" \
  1324. -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
  1325. -s "found renegotiation extension" \
  1326. -s "server hello, secure renegotiation extension" \
  1327. -c "found renegotiation extension" \
  1328. -c "=> renegotiate" \
  1329. -s "=> renegotiate" \
  1330. -S "write hello request"
  1331. run_test "Renegotiation: nbio, server-initiated" \
  1332. "$P_SRV debug_level=3 nbio=2 exchanges=2 renegotiation=1 renegotiate=1 auth_mode=optional" \
  1333. "$P_CLI debug_level=3 nbio=2 exchanges=2 renegotiation=1" \
  1334. 0 \
  1335. -c "client hello, adding renegotiation extension" \
  1336. -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
  1337. -s "found renegotiation extension" \
  1338. -s "server hello, secure renegotiation extension" \
  1339. -c "found renegotiation extension" \
  1340. -c "=> renegotiate" \
  1341. -s "=> renegotiate" \
  1342. -s "write hello request"
  1343. run_test "Renegotiation: openssl server, client-initiated" \
  1344. "$O_SRV -www" \
  1345. "$P_CLI debug_level=3 exchanges=1 renegotiation=1 renegotiate=1" \
  1346. 0 \
  1347. -c "client hello, adding renegotiation extension" \
  1348. -c "found renegotiation extension" \
  1349. -c "=> renegotiate" \
  1350. -C "ssl_hanshake() returned" \
  1351. -C "error" \
  1352. -c "HTTP/1.0 200 [Oo][Kk]"
  1353. requires_gnutls
  1354. run_test "Renegotiation: gnutls server strict, client-initiated" \
  1355. "$G_SRV --priority=NORMAL:%SAFE_RENEGOTIATION" \
  1356. "$P_CLI debug_level=3 exchanges=1 renegotiation=1 renegotiate=1" \
  1357. 0 \
  1358. -c "client hello, adding renegotiation extension" \
  1359. -c "found renegotiation extension" \
  1360. -c "=> renegotiate" \
  1361. -C "ssl_hanshake() returned" \
  1362. -C "error" \
  1363. -c "HTTP/1.0 200 [Oo][Kk]"
  1364. requires_gnutls
  1365. run_test "Renegotiation: gnutls server unsafe, client-initiated default" \
  1366. "$G_SRV --priority=NORMAL:%DISABLE_SAFE_RENEGOTIATION" \
  1367. "$P_CLI debug_level=3 exchanges=1 renegotiation=1 renegotiate=1" \
  1368. 1 \
  1369. -c "client hello, adding renegotiation extension" \
  1370. -C "found renegotiation extension" \
  1371. -c "=> renegotiate" \
  1372. -c "mbedtls_ssl_handshake() returned" \
  1373. -c "error" \
  1374. -C "HTTP/1.0 200 [Oo][Kk]"
  1375. requires_gnutls
  1376. run_test "Renegotiation: gnutls server unsafe, client-inititated no legacy" \
  1377. "$G_SRV --priority=NORMAL:%DISABLE_SAFE_RENEGOTIATION" \
  1378. "$P_CLI debug_level=3 exchanges=1 renegotiation=1 renegotiate=1 \
  1379. allow_legacy=0" \
  1380. 1 \
  1381. -c "client hello, adding renegotiation extension" \
  1382. -C "found renegotiation extension" \
  1383. -c "=> renegotiate" \
  1384. -c "mbedtls_ssl_handshake() returned" \
  1385. -c "error" \
  1386. -C "HTTP/1.0 200 [Oo][Kk]"
  1387. requires_gnutls
  1388. run_test "Renegotiation: gnutls server unsafe, client-inititated legacy" \
  1389. "$G_SRV --priority=NORMAL:%DISABLE_SAFE_RENEGOTIATION" \
  1390. "$P_CLI debug_level=3 exchanges=1 renegotiation=1 renegotiate=1 \
  1391. allow_legacy=1" \
  1392. 0 \
  1393. -c "client hello, adding renegotiation extension" \
  1394. -C "found renegotiation extension" \
  1395. -c "=> renegotiate" \
  1396. -C "ssl_hanshake() returned" \
  1397. -C "error" \
  1398. -c "HTTP/1.0 200 [Oo][Kk]"
  1399. run_test "Renegotiation: DTLS, client-initiated" \
  1400. "$P_SRV debug_level=3 dtls=1 exchanges=2 renegotiation=1" \
  1401. "$P_CLI debug_level=3 dtls=1 exchanges=2 renegotiation=1 renegotiate=1" \
  1402. 0 \
  1403. -c "client hello, adding renegotiation extension" \
  1404. -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
  1405. -s "found renegotiation extension" \
  1406. -s "server hello, secure renegotiation extension" \
  1407. -c "found renegotiation extension" \
  1408. -c "=> renegotiate" \
  1409. -s "=> renegotiate" \
  1410. -S "write hello request"
  1411. run_test "Renegotiation: DTLS, server-initiated" \
  1412. "$P_SRV debug_level=3 dtls=1 exchanges=2 renegotiation=1 renegotiate=1" \
  1413. "$P_CLI debug_level=3 dtls=1 exchanges=2 renegotiation=1 \
  1414. read_timeout=1000 max_resend=2" \
  1415. 0 \
  1416. -c "client hello, adding renegotiation extension" \
  1417. -s "received TLS_EMPTY_RENEGOTIATION_INFO" \
  1418. -s "found renegotiation extension" \
  1419. -s "server hello, secure renegotiation extension" \
  1420. -c "found renegotiation extension" \
  1421. -c "=> renegotiate" \
  1422. -s "=> renegotiate" \
  1423. -s "write hello request"
  1424. requires_gnutls
  1425. run_test "Renegotiation: DTLS, gnutls server, client-initiated" \
  1426. "$G_SRV -u --mtu 4096" \
  1427. "$P_CLI debug_level=3 dtls=1 exchanges=1 renegotiation=1 renegotiate=1" \
  1428. 0 \
  1429. -c "client hello, adding renegotiation extension" \
  1430. -c "found renegotiation extension" \
  1431. -c "=> renegotiate" \
  1432. -C "mbedtls_ssl_handshake returned" \
  1433. -C "error" \
  1434. -s "Extra-header:"
  1435. # Test for the "secure renegotation" extension only (no actual renegotiation)
  1436. requires_gnutls
  1437. run_test "Renego ext: gnutls server strict, client default" \
  1438. "$G_SRV --priority=NORMAL:%SAFE_RENEGOTIATION" \
  1439. "$P_CLI debug_level=3" \
  1440. 0 \
  1441. -c "found renegotiation extension" \
  1442. -C "error" \
  1443. -c "HTTP/1.0 200 [Oo][Kk]"
  1444. requires_gnutls
  1445. run_test "Renego ext: gnutls server unsafe, client default" \
  1446. "$G_SRV --priority=NORMAL:%DISABLE_SAFE_RENEGOTIATION" \
  1447. "$P_CLI debug_level=3" \
  1448. 0 \
  1449. -C "found renegotiation extension" \
  1450. -C "error" \
  1451. -c "HTTP/1.0 200 [Oo][Kk]"
  1452. requires_gnutls
  1453. run_test "Renego ext: gnutls server unsafe, client break legacy" \
  1454. "$G_SRV --priority=NORMAL:%DISABLE_SAFE_RENEGOTIATION" \
  1455. "$P_CLI debug_level=3 allow_legacy=-1" \
  1456. 1 \
  1457. -C "found renegotiation extension" \
  1458. -c "error" \
  1459. -C "HTTP/1.0 200 [Oo][Kk]"
  1460. requires_gnutls
  1461. run_test "Renego ext: gnutls client strict, server default" \
  1462. "$P_SRV debug_level=3" \
  1463. "$G_CLI --priority=NORMAL:%SAFE_RENEGOTIATION" \
  1464. 0 \
  1465. -s "received TLS_EMPTY_RENEGOTIATION_INFO\|found renegotiation extension" \
  1466. -s "server hello, secure renegotiation extension"
  1467. requires_gnutls
  1468. run_test "Renego ext: gnutls client unsafe, server default" \
  1469. "$P_SRV debug_level=3" \
  1470. "$G_CLI --priority=NORMAL:%DISABLE_SAFE_RENEGOTIATION" \
  1471. 0 \
  1472. -S "received TLS_EMPTY_RENEGOTIATION_INFO\|found renegotiation extension" \
  1473. -S "server hello, secure renegotiation extension"
  1474. requires_gnutls
  1475. run_test "Renego ext: gnutls client unsafe, server break legacy" \
  1476. "$P_SRV debug_level=3 allow_legacy=-1" \
  1477. "$G_CLI --priority=NORMAL:%DISABLE_SAFE_RENEGOTIATION" \
  1478. 1 \
  1479. -S "received TLS_EMPTY_RENEGOTIATION_INFO\|found renegotiation extension" \
  1480. -S "server hello, secure renegotiation extension"
  1481. # Tests for silently dropping trailing extra bytes in .der certificates
  1482. requires_gnutls
  1483. run_test "DER format: no trailing bytes" \
  1484. "$P_SRV crt_file=data_files/server5-der0.crt \
  1485. key_file=data_files/server5.key" \
  1486. "$G_CLI " \
  1487. 0 \
  1488. -c "Handshake was completed" \
  1489. requires_gnutls
  1490. run_test "DER format: with a trailing zero byte" \
  1491. "$P_SRV crt_file=data_files/server5-der1a.crt \
  1492. key_file=data_files/server5.key" \
  1493. "$G_CLI " \
  1494. 0 \
  1495. -c "Handshake was completed" \
  1496. requires_gnutls
  1497. run_test "DER format: with a trailing random byte" \
  1498. "$P_SRV crt_file=data_files/server5-der1b.crt \
  1499. key_file=data_files/server5.key" \
  1500. "$G_CLI " \
  1501. 0 \
  1502. -c "Handshake was completed" \
  1503. requires_gnutls
  1504. run_test "DER format: with 2 trailing random bytes" \
  1505. "$P_SRV crt_file=data_files/server5-der2.crt \
  1506. key_file=data_files/server5.key" \
  1507. "$G_CLI " \
  1508. 0 \
  1509. -c "Handshake was completed" \
  1510. requires_gnutls
  1511. run_test "DER format: with 4 trailing random bytes" \
  1512. "$P_SRV crt_file=data_files/server5-der4.crt \
  1513. key_file=data_files/server5.key" \
  1514. "$G_CLI " \
  1515. 0 \
  1516. -c "Handshake was completed" \
  1517. requires_gnutls
  1518. run_test "DER format: with 8 trailing random bytes" \
  1519. "$P_SRV crt_file=data_files/server5-der8.crt \
  1520. key_file=data_files/server5.key" \
  1521. "$G_CLI " \
  1522. 0 \
  1523. -c "Handshake was completed" \
  1524. requires_gnutls
  1525. run_test "DER format: with 9 trailing random bytes" \
  1526. "$P_SRV crt_file=data_files/server5-der9.crt \
  1527. key_file=data_files/server5.key" \
  1528. "$G_CLI " \
  1529. 0 \
  1530. -c "Handshake was completed" \
  1531. # Tests for auth_mode
  1532. run_test "Authentication: server badcert, client required" \
  1533. "$P_SRV crt_file=data_files/server5-badsign.crt \
  1534. key_file=data_files/server5.key" \
  1535. "$P_CLI debug_level=1 auth_mode=required" \
  1536. 1 \
  1537. -c "x509_verify_cert() returned" \
  1538. -c "! The certificate is not correctly signed by the trusted CA" \
  1539. -c "! mbedtls_ssl_handshake returned" \
  1540. -c "X509 - Certificate verification failed"
  1541. run_test "Authentication: server badcert, client optional" \
  1542. "$P_SRV crt_file=data_files/server5-badsign.crt \
  1543. key_file=data_files/server5.key" \
  1544. "$P_CLI debug_level=1 auth_mode=optional" \
  1545. 0 \
  1546. -c "x509_verify_cert() returned" \
  1547. -c "! The certificate is not correctly signed by the trusted CA" \
  1548. -C "! mbedtls_ssl_handshake returned" \
  1549. -C "X509 - Certificate verification failed"
  1550. run_test "Authentication: server badcert, client none" \
  1551. "$P_SRV crt_file=data_files/server5-badsign.crt \
  1552. key_file=data_files/server5.key" \
  1553. "$P_CLI debug_level=1 auth_mode=none" \
  1554. 0 \
  1555. -C "x509_verify_cert() returned" \
  1556. -C "! The certificate is not correctly signed by the trusted CA" \
  1557. -C "! mbedtls_ssl_handshake returned" \
  1558. -C "X509 - Certificate verification failed"
  1559. run_test "Authentication: client SHA256, server required" \
  1560. "$P_SRV auth_mode=required" \
  1561. "$P_CLI debug_level=3 crt_file=data_files/server6.crt \
  1562. key_file=data_files/server6.key \
  1563. force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-256-GCM-SHA384" \
  1564. 0 \
  1565. -c "Supported Signature Algorithm found: 4," \
  1566. -c "Supported Signature Algorithm found: 5,"
  1567. run_test "Authentication: client SHA384, server required" \
  1568. "$P_SRV auth_mode=required" \
  1569. "$P_CLI debug_level=3 crt_file=data_files/server6.crt \
  1570. key_file=data_files/server6.key \
  1571. force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256" \
  1572. 0 \
  1573. -c "Supported Signature Algorithm found: 4," \
  1574. -c "Supported Signature Algorithm found: 5,"
  1575. run_test "Authentication: client badcert, server required" \
  1576. "$P_SRV debug_level=3 auth_mode=required" \
  1577. "$P_CLI debug_level=3 crt_file=data_files/server5-badsign.crt \
  1578. key_file=data_files/server5.key" \
  1579. 1 \
  1580. -S "skip write certificate request" \
  1581. -C "skip parse certificate request" \
  1582. -c "got a certificate request" \
  1583. -C "skip write certificate" \
  1584. -C "skip write certificate verify" \
  1585. -S "skip parse certificate verify" \
  1586. -s "x509_verify_cert() returned" \
  1587. -s "! The certificate is not correctly signed by the trusted CA" \
  1588. -s "! mbedtls_ssl_handshake returned" \
  1589. -c "! mbedtls_ssl_handshake returned" \
  1590. -s "X509 - Certificate verification failed"
  1591. run_test "Authentication: client badcert, server optional" \
  1592. "$P_SRV debug_level=3 auth_mode=optional" \
  1593. "$P_CLI debug_level=3 crt_file=data_files/server5-badsign.crt \
  1594. key_file=data_files/server5.key" \
  1595. 0 \
  1596. -S "skip write certificate request" \
  1597. -C "skip parse certificate request" \
  1598. -c "got a certificate request" \
  1599. -C "skip write certificate" \
  1600. -C "skip write certificate verify" \
  1601. -S "skip parse certificate verify" \
  1602. -s "x509_verify_cert() returned" \
  1603. -s "! The certificate is not correctly signed by the trusted CA" \
  1604. -S "! mbedtls_ssl_handshake returned" \
  1605. -C "! mbedtls_ssl_handshake returned" \
  1606. -S "X509 - Certificate verification failed"
  1607. run_test "Authentication: client badcert, server none" \
  1608. "$P_SRV debug_level=3 auth_mode=none" \
  1609. "$P_CLI debug_level=3 crt_file=data_files/server5-badsign.crt \
  1610. key_file=data_files/server5.key" \
  1611. 0 \
  1612. -s "skip write certificate request" \
  1613. -C "skip parse certificate request" \
  1614. -c "got no certificate request" \
  1615. -c "skip write certificate" \
  1616. -c "skip write certificate verify" \
  1617. -s "skip parse certificate verify" \
  1618. -S "x509_verify_cert() returned" \
  1619. -S "! The certificate is not correctly signed by the trusted CA" \
  1620. -S "! mbedtls_ssl_handshake returned" \
  1621. -C "! mbedtls_ssl_handshake returned" \
  1622. -S "X509 - Certificate verification failed"
  1623. run_test "Authentication: client no cert, server optional" \
  1624. "$P_SRV debug_level=3 auth_mode=optional" \
  1625. "$P_CLI debug_level=3 crt_file=none key_file=none" \
  1626. 0 \
  1627. -S "skip write certificate request" \
  1628. -C "skip parse certificate request" \
  1629. -c "got a certificate request" \
  1630. -C "skip write certificate$" \
  1631. -C "got no certificate to send" \
  1632. -S "SSLv3 client has no certificate" \
  1633. -c "skip write certificate verify" \
  1634. -s "skip parse certificate verify" \
  1635. -s "! Certificate was missing" \
  1636. -S "! mbedtls_ssl_handshake returned" \
  1637. -C "! mbedtls_ssl_handshake returned" \
  1638. -S "X509 - Certificate verification failed"
  1639. run_test "Authentication: openssl client no cert, server optional" \
  1640. "$P_SRV debug_level=3 auth_mode=optional" \
  1641. "$O_CLI" \
  1642. 0 \
  1643. -S "skip write certificate request" \
  1644. -s "skip parse certificate verify" \
  1645. -s "! Certificate was missing" \
  1646. -S "! mbedtls_ssl_handshake returned" \
  1647. -S "X509 - Certificate verification failed"
  1648. run_test "Authentication: client no cert, openssl server optional" \
  1649. "$O_SRV -verify 10" \
  1650. "$P_CLI debug_level=3 crt_file=none key_file=none" \
  1651. 0 \
  1652. -C "skip parse certificate request" \
  1653. -c "got a certificate request" \
  1654. -C "skip write certificate$" \
  1655. -c "skip write certificate verify" \
  1656. -C "! mbedtls_ssl_handshake returned"
  1657. requires_config_enabled MBEDTLS_SSL_PROTO_SSL3
  1658. run_test "Authentication: client no cert, ssl3" \
  1659. "$P_SRV debug_level=3 auth_mode=optional force_version=ssl3" \
  1660. "$P_CLI debug_level=3 crt_file=none key_file=none min_version=ssl3" \
  1661. 0 \
  1662. -S "skip write certificate request" \
  1663. -C "skip parse certificate request" \
  1664. -c "got a certificate request" \
  1665. -C "skip write certificate$" \
  1666. -c "skip write certificate verify" \
  1667. -c "got no certificate to send" \
  1668. -s "SSLv3 client has no certificate" \
  1669. -s "skip parse certificate verify" \
  1670. -s "! Certificate was missing" \
  1671. -S "! mbedtls_ssl_handshake returned" \
  1672. -C "! mbedtls_ssl_handshake returned" \
  1673. -S "X509 - Certificate verification failed"
  1674. # Tests for certificate selection based on SHA verson
  1675. run_test "Certificate hash: client TLS 1.2 -> SHA-2" \
  1676. "$P_SRV crt_file=data_files/server5.crt \
  1677. key_file=data_files/server5.key \
  1678. crt_file2=data_files/server5-sha1.crt \
  1679. key_file2=data_files/server5.key" \
  1680. "$P_CLI force_version=tls1_2" \
  1681. 0 \
  1682. -c "signed using.*ECDSA with SHA256" \
  1683. -C "signed using.*ECDSA with SHA1"
  1684. run_test "Certificate hash: client TLS 1.1 -> SHA-1" \
  1685. "$P_SRV crt_file=data_files/server5.crt \
  1686. key_file=data_files/server5.key \
  1687. crt_file2=data_files/server5-sha1.crt \
  1688. key_file2=data_files/server5.key" \
  1689. "$P_CLI force_version=tls1_1" \
  1690. 0 \
  1691. -C "signed using.*ECDSA with SHA256" \
  1692. -c "signed using.*ECDSA with SHA1"
  1693. run_test "Certificate hash: client TLS 1.0 -> SHA-1" \
  1694. "$P_SRV crt_file=data_files/server5.crt \
  1695. key_file=data_files/server5.key \
  1696. crt_file2=data_files/server5-sha1.crt \
  1697. key_file2=data_files/server5.key" \
  1698. "$P_CLI force_version=tls1" \
  1699. 0 \
  1700. -C "signed using.*ECDSA with SHA256" \
  1701. -c "signed using.*ECDSA with SHA1"
  1702. run_test "Certificate hash: client TLS 1.1, no SHA-1 -> SHA-2 (order 1)" \
  1703. "$P_SRV crt_file=data_files/server5.crt \
  1704. key_file=data_files/server5.key \
  1705. crt_file2=data_files/server6.crt \
  1706. key_file2=data_files/server6.key" \
  1707. "$P_CLI force_version=tls1_1" \
  1708. 0 \
  1709. -c "serial number.*09" \
  1710. -c "signed using.*ECDSA with SHA256" \
  1711. -C "signed using.*ECDSA with SHA1"
  1712. run_test "Certificate hash: client TLS 1.1, no SHA-1 -> SHA-2 (order 2)" \
  1713. "$P_SRV crt_file=data_files/server6.crt \
  1714. key_file=data_files/server6.key \
  1715. crt_file2=data_files/server5.crt \
  1716. key_file2=data_files/server5.key" \
  1717. "$P_CLI force_version=tls1_1" \
  1718. 0 \
  1719. -c "serial number.*0A" \
  1720. -c "signed using.*ECDSA with SHA256" \
  1721. -C "signed using.*ECDSA with SHA1"
  1722. # tests for SNI
  1723. run_test "SNI: no SNI callback" \
  1724. "$P_SRV debug_level=3 \
  1725. crt_file=data_files/server5.crt key_file=data_files/server5.key" \
  1726. "$P_CLI server_name=localhost" \
  1727. 0 \
  1728. -S "parse ServerName extension" \
  1729. -c "issuer name *: C=NL, O=PolarSSL, CN=Polarssl Test EC CA" \
  1730. -c "subject name *: C=NL, O=PolarSSL, CN=localhost"
  1731. run_test "SNI: matching cert 1" \
  1732. "$P_SRV debug_level=3 \
  1733. crt_file=data_files/server5.crt key_file=data_files/server5.key \
  1734. sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,-,polarssl.example,data_files/server1-nospace.crt,data_files/server1.key,-,-,-" \
  1735. "$P_CLI server_name=localhost" \
  1736. 0 \
  1737. -s "parse ServerName extension" \
  1738. -c "issuer name *: C=NL, O=PolarSSL, CN=PolarSSL Test CA" \
  1739. -c "subject name *: C=NL, O=PolarSSL, CN=localhost"
  1740. run_test "SNI: matching cert 2" \
  1741. "$P_SRV debug_level=3 \
  1742. crt_file=data_files/server5.crt key_file=data_files/server5.key \
  1743. sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,-,polarssl.example,data_files/server1-nospace.crt,data_files/server1.key,-,-,-" \
  1744. "$P_CLI server_name=polarssl.example" \
  1745. 0 \
  1746. -s "parse ServerName extension" \
  1747. -c "issuer name *: C=NL, O=PolarSSL, CN=PolarSSL Test CA" \
  1748. -c "subject name *: C=NL, O=PolarSSL, CN=polarssl.example"
  1749. run_test "SNI: no matching cert" \
  1750. "$P_SRV debug_level=3 \
  1751. crt_file=data_files/server5.crt key_file=data_files/server5.key \
  1752. sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,-,polarssl.example,data_files/server1-nospace.crt,data_files/server1.key,-,-,-" \
  1753. "$P_CLI server_name=nonesuch.example" \
  1754. 1 \
  1755. -s "parse ServerName extension" \
  1756. -s "ssl_sni_wrapper() returned" \
  1757. -s "mbedtls_ssl_handshake returned" \
  1758. -c "mbedtls_ssl_handshake returned" \
  1759. -c "SSL - A fatal alert message was received from our peer"
  1760. run_test "SNI: client auth no override: optional" \
  1761. "$P_SRV debug_level=3 auth_mode=optional \
  1762. crt_file=data_files/server5.crt key_file=data_files/server5.key \
  1763. sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,-" \
  1764. "$P_CLI debug_level=3 server_name=localhost" \
  1765. 0 \
  1766. -S "skip write certificate request" \
  1767. -C "skip parse certificate request" \
  1768. -c "got a certificate request" \
  1769. -C "skip write certificate" \
  1770. -C "skip write certificate verify" \
  1771. -S "skip parse certificate verify"
  1772. run_test "SNI: client auth override: none -> optional" \
  1773. "$P_SRV debug_level=3 auth_mode=none \
  1774. crt_file=data_files/server5.crt key_file=data_files/server5.key \
  1775. sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,optional" \
  1776. "$P_CLI debug_level=3 server_name=localhost" \
  1777. 0 \
  1778. -S "skip write certificate request" \
  1779. -C "skip parse certificate request" \
  1780. -c "got a certificate request" \
  1781. -C "skip write certificate" \
  1782. -C "skip write certificate verify" \
  1783. -S "skip parse certificate verify"
  1784. run_test "SNI: client auth override: optional -> none" \
  1785. "$P_SRV debug_level=3 auth_mode=optional \
  1786. crt_file=data_files/server5.crt key_file=data_files/server5.key \
  1787. sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,none" \
  1788. "$P_CLI debug_level=3 server_name=localhost" \
  1789. 0 \
  1790. -s "skip write certificate request" \
  1791. -C "skip parse certificate request" \
  1792. -c "got no certificate request" \
  1793. -c "skip write certificate" \
  1794. -c "skip write certificate verify" \
  1795. -s "skip parse certificate verify"
  1796. run_test "SNI: CA no override" \
  1797. "$P_SRV debug_level=3 auth_mode=optional \
  1798. crt_file=data_files/server5.crt key_file=data_files/server5.key \
  1799. ca_file=data_files/test-ca.crt \
  1800. sni=localhost,data_files/server2.crt,data_files/server2.key,-,-,required" \
  1801. "$P_CLI debug_level=3 server_name=localhost \
  1802. crt_file=data_files/server6.crt key_file=data_files/server6.key" \
  1803. 1 \
  1804. -S "skip write certificate request" \
  1805. -C "skip parse certificate request" \
  1806. -c "got a certificate request" \
  1807. -C "skip write certificate" \
  1808. -C "skip write certificate verify" \
  1809. -S "skip parse certificate verify" \
  1810. -s "x509_verify_cert() returned" \
  1811. -s "! The certificate is not correctly signed by the trusted CA" \
  1812. -S "The certificate has been revoked (is on a CRL)"
  1813. run_test "SNI: CA override" \
  1814. "$P_SRV debug_level=3 auth_mode=optional \
  1815. crt_file=data_files/server5.crt key_file=data_files/server5.key \
  1816. ca_file=data_files/test-ca.crt \
  1817. sni=localhost,data_files/server2.crt,data_files/server2.key,data_files/test-ca2.crt,-,required" \
  1818. "$P_CLI debug_level=3 server_name=localhost \
  1819. crt_file=data_files/server6.crt key_file=data_files/server6.key" \
  1820. 0 \
  1821. -S "skip write certificate request" \
  1822. -C "skip parse certificate request" \
  1823. -c "got a certificate request" \
  1824. -C "skip write certificate" \
  1825. -C "skip write certificate verify" \
  1826. -S "skip parse certificate verify" \
  1827. -S "x509_verify_cert() returned" \
  1828. -S "! The certificate is not correctly signed by the trusted CA" \
  1829. -S "The certificate has been revoked (is on a CRL)"
  1830. run_test "SNI: CA override with CRL" \
  1831. "$P_SRV debug_level=3 auth_mode=optional \
  1832. crt_file=data_files/server5.crt key_file=data_files/server5.key \
  1833. ca_file=data_files/test-ca.crt \
  1834. sni=localhost,data_files/server2.crt,data_files/server2.key,data_files/test-ca2.crt,data_files/crl-ec-sha256.pem,required" \
  1835. "$P_CLI debug_level=3 server_name=localhost \
  1836. crt_file=data_files/server6.crt key_file=data_files/server6.key" \
  1837. 1 \
  1838. -S "skip write certificate request" \
  1839. -C "skip parse certificate request" \
  1840. -c "got a certificate request" \
  1841. -C "skip write certificate" \
  1842. -C "skip write certificate verify" \
  1843. -S "skip parse certificate verify" \
  1844. -s "x509_verify_cert() returned" \
  1845. -S "! The certificate is not correctly signed by the trusted CA" \
  1846. -s "The certificate has been revoked (is on a CRL)"
  1847. # Tests for non-blocking I/O: exercise a variety of handshake flows
  1848. run_test "Non-blocking I/O: basic handshake" \
  1849. "$P_SRV nbio=2 tickets=0 auth_mode=none" \
  1850. "$P_CLI nbio=2 tickets=0" \
  1851. 0 \
  1852. -S "mbedtls_ssl_handshake returned" \
  1853. -C "mbedtls_ssl_handshake returned" \
  1854. -c "Read from server: .* bytes read"
  1855. run_test "Non-blocking I/O: client auth" \
  1856. "$P_SRV nbio=2 tickets=0 auth_mode=required" \
  1857. "$P_CLI nbio=2 tickets=0" \
  1858. 0 \
  1859. -S "mbedtls_ssl_handshake returned" \
  1860. -C "mbedtls_ssl_handshake returned" \
  1861. -c "Read from server: .* bytes read"
  1862. run_test "Non-blocking I/O: ticket" \
  1863. "$P_SRV nbio=2 tickets=1 auth_mode=none" \
  1864. "$P_CLI nbio=2 tickets=1" \
  1865. 0 \
  1866. -S "mbedtls_ssl_handshake returned" \
  1867. -C "mbedtls_ssl_handshake returned" \
  1868. -c "Read from server: .* bytes read"
  1869. run_test "Non-blocking I/O: ticket + client auth" \
  1870. "$P_SRV nbio=2 tickets=1 auth_mode=required" \
  1871. "$P_CLI nbio=2 tickets=1" \
  1872. 0 \
  1873. -S "mbedtls_ssl_handshake returned" \
  1874. -C "mbedtls_ssl_handshake returned" \
  1875. -c "Read from server: .* bytes read"
  1876. run_test "Non-blocking I/O: ticket + client auth + resume" \
  1877. "$P_SRV nbio=2 tickets=1 auth_mode=required" \
  1878. "$P_CLI nbio=2 tickets=1 reconnect=1" \
  1879. 0 \
  1880. -S "mbedtls_ssl_handshake returned" \
  1881. -C "mbedtls_ssl_handshake returned" \
  1882. -c "Read from server: .* bytes read"
  1883. run_test "Non-blocking I/O: ticket + resume" \
  1884. "$P_SRV nbio=2 tickets=1 auth_mode=none" \
  1885. "$P_CLI nbio=2 tickets=1 reconnect=1" \
  1886. 0 \
  1887. -S "mbedtls_ssl_handshake returned" \
  1888. -C "mbedtls_ssl_handshake returned" \
  1889. -c "Read from server: .* bytes read"
  1890. run_test "Non-blocking I/O: session-id resume" \
  1891. "$P_SRV nbio=2 tickets=0 auth_mode=none" \
  1892. "$P_CLI nbio=2 tickets=0 reconnect=1" \
  1893. 0 \
  1894. -S "mbedtls_ssl_handshake returned" \
  1895. -C "mbedtls_ssl_handshake returned" \
  1896. -c "Read from server: .* bytes read"
  1897. # Tests for version negotiation
  1898. run_test "Version check: all -> 1.2" \
  1899. "$P_SRV" \
  1900. "$P_CLI" \
  1901. 0 \
  1902. -S "mbedtls_ssl_handshake returned" \
  1903. -C "mbedtls_ssl_handshake returned" \
  1904. -s "Protocol is TLSv1.2" \
  1905. -c "Protocol is TLSv1.2"
  1906. run_test "Version check: cli max 1.1 -> 1.1" \
  1907. "$P_SRV" \
  1908. "$P_CLI max_version=tls1_1" \
  1909. 0 \
  1910. -S "mbedtls_ssl_handshake returned" \
  1911. -C "mbedtls_ssl_handshake returned" \
  1912. -s "Protocol is TLSv1.1" \
  1913. -c "Protocol is TLSv1.1"
  1914. run_test "Version check: srv max 1.1 -> 1.1" \
  1915. "$P_SRV max_version=tls1_1" \
  1916. "$P_CLI" \
  1917. 0 \
  1918. -S "mbedtls_ssl_handshake returned" \
  1919. -C "mbedtls_ssl_handshake returned" \
  1920. -s "Protocol is TLSv1.1" \
  1921. -c "Protocol is TLSv1.1"
  1922. run_test "Version check: cli+srv max 1.1 -> 1.1" \
  1923. "$P_SRV max_version=tls1_1" \
  1924. "$P_CLI max_version=tls1_1" \
  1925. 0 \
  1926. -S "mbedtls_ssl_handshake returned" \
  1927. -C "mbedtls_ssl_handshake returned" \
  1928. -s "Protocol is TLSv1.1" \
  1929. -c "Protocol is TLSv1.1"
  1930. run_test "Version check: cli max 1.1, srv min 1.1 -> 1.1" \
  1931. "$P_SRV min_version=tls1_1" \
  1932. "$P_CLI max_version=tls1_1" \
  1933. 0 \
  1934. -S "mbedtls_ssl_handshake returned" \
  1935. -C "mbedtls_ssl_handshake returned" \
  1936. -s "Protocol is TLSv1.1" \
  1937. -c "Protocol is TLSv1.1"
  1938. run_test "Version check: cli min 1.1, srv max 1.1 -> 1.1" \
  1939. "$P_SRV max_version=tls1_1" \
  1940. "$P_CLI min_version=tls1_1" \
  1941. 0 \
  1942. -S "mbedtls_ssl_handshake returned" \
  1943. -C "mbedtls_ssl_handshake returned" \
  1944. -s "Protocol is TLSv1.1" \
  1945. -c "Protocol is TLSv1.1"
  1946. run_test "Version check: cli min 1.2, srv max 1.1 -> fail" \
  1947. "$P_SRV max_version=tls1_1" \
  1948. "$P_CLI min_version=tls1_2" \
  1949. 1 \
  1950. -s "mbedtls_ssl_handshake returned" \
  1951. -c "mbedtls_ssl_handshake returned" \
  1952. -c "SSL - Handshake protocol not within min/max boundaries"
  1953. run_test "Version check: srv min 1.2, cli max 1.1 -> fail" \
  1954. "$P_SRV min_version=tls1_2" \
  1955. "$P_CLI max_version=tls1_1" \
  1956. 1 \
  1957. -s "mbedtls_ssl_handshake returned" \
  1958. -c "mbedtls_ssl_handshake returned" \
  1959. -s "SSL - Handshake protocol not within min/max boundaries"
  1960. # Tests for ALPN extension
  1961. run_test "ALPN: none" \
  1962. "$P_SRV debug_level=3" \
  1963. "$P_CLI debug_level=3" \
  1964. 0 \
  1965. -C "client hello, adding alpn extension" \
  1966. -S "found alpn extension" \
  1967. -C "got an alert message, type: \\[2:120]" \
  1968. -S "server hello, adding alpn extension" \
  1969. -C "found alpn extension " \
  1970. -C "Application Layer Protocol is" \
  1971. -S "Application Layer Protocol is"
  1972. run_test "ALPN: client only" \
  1973. "$P_SRV debug_level=3" \
  1974. "$P_CLI debug_level=3 alpn=abc,1234" \
  1975. 0 \
  1976. -c "client hello, adding alpn extension" \
  1977. -s "found alpn extension" \
  1978. -C "got an alert message, type: \\[2:120]" \
  1979. -S "server hello, adding alpn extension" \
  1980. -C "found alpn extension " \
  1981. -c "Application Layer Protocol is (none)" \
  1982. -S "Application Layer Protocol is"
  1983. run_test "ALPN: server only" \
  1984. "$P_SRV debug_level=3 alpn=abc,1234" \
  1985. "$P_CLI debug_level=3" \
  1986. 0 \
  1987. -C "client hello, adding alpn extension" \
  1988. -S "found alpn extension" \
  1989. -C "got an alert message, type: \\[2:120]" \
  1990. -S "server hello, adding alpn extension" \
  1991. -C "found alpn extension " \
  1992. -C "Application Layer Protocol is" \
  1993. -s "Application Layer Protocol is (none)"
  1994. run_test "ALPN: both, common cli1-srv1" \
  1995. "$P_SRV debug_level=3 alpn=abc,1234" \
  1996. "$P_CLI debug_level=3 alpn=abc,1234" \
  1997. 0 \
  1998. -c "client hello, adding alpn extension" \
  1999. -s "found alpn extension" \
  2000. -C "got an alert message, type: \\[2:120]" \
  2001. -s "server hello, adding alpn extension" \
  2002. -c "found alpn extension" \
  2003. -c "Application Layer Protocol is abc" \
  2004. -s "Application Layer Protocol is abc"
  2005. run_test "ALPN: both, common cli2-srv1" \
  2006. "$P_SRV debug_level=3 alpn=abc,1234" \
  2007. "$P_CLI debug_level=3 alpn=1234,abc" \
  2008. 0 \
  2009. -c "client hello, adding alpn extension" \
  2010. -s "found alpn extension" \
  2011. -C "got an alert message, type: \\[2:120]" \
  2012. -s "server hello, adding alpn extension" \
  2013. -c "found alpn extension" \
  2014. -c "Application Layer Protocol is abc" \
  2015. -s "Application Layer Protocol is abc"
  2016. run_test "ALPN: both, common cli1-srv2" \
  2017. "$P_SRV debug_level=3 alpn=abc,1234" \
  2018. "$P_CLI debug_level=3 alpn=1234,abcde" \
  2019. 0 \
  2020. -c "client hello, adding alpn extension" \
  2021. -s "found alpn extension" \
  2022. -C "got an alert message, type: \\[2:120]" \
  2023. -s "server hello, adding alpn extension" \
  2024. -c "found alpn extension" \
  2025. -c "Application Layer Protocol is 1234" \
  2026. -s "Application Layer Protocol is 1234"
  2027. run_test "ALPN: both, no common" \
  2028. "$P_SRV debug_level=3 alpn=abc,123" \
  2029. "$P_CLI debug_level=3 alpn=1234,abcde" \
  2030. 1 \
  2031. -c "client hello, adding alpn extension" \
  2032. -s "found alpn extension" \
  2033. -c "got an alert message, type: \\[2:120]" \
  2034. -S "server hello, adding alpn extension" \
  2035. -C "found alpn extension" \
  2036. -C "Application Layer Protocol is 1234" \
  2037. -S "Application Layer Protocol is 1234"
  2038. # Tests for keyUsage in leaf certificates, part 1:
  2039. # server-side certificate/suite selection
  2040. run_test "keyUsage srv: RSA, digitalSignature -> (EC)DHE-RSA" \
  2041. "$P_SRV key_file=data_files/server2.key \
  2042. crt_file=data_files/server2.ku-ds.crt" \
  2043. "$P_CLI" \
  2044. 0 \
  2045. -c "Ciphersuite is TLS-[EC]*DHE-RSA-WITH-"
  2046. run_test "keyUsage srv: RSA, keyEncipherment -> RSA" \
  2047. "$P_SRV key_file=data_files/server2.key \
  2048. crt_file=data_files/server2.ku-ke.crt" \
  2049. "$P_CLI" \
  2050. 0 \
  2051. -c "Ciphersuite is TLS-RSA-WITH-"
  2052. run_test "keyUsage srv: RSA, keyAgreement -> fail" \
  2053. "$P_SRV key_file=data_files/server2.key \
  2054. crt_file=data_files/server2.ku-ka.crt" \
  2055. "$P_CLI" \
  2056. 1 \
  2057. -C "Ciphersuite is "
  2058. run_test "keyUsage srv: ECDSA, digitalSignature -> ECDHE-ECDSA" \
  2059. "$P_SRV key_file=data_files/server5.key \
  2060. crt_file=data_files/server5.ku-ds.crt" \
  2061. "$P_CLI" \
  2062. 0 \
  2063. -c "Ciphersuite is TLS-ECDHE-ECDSA-WITH-"
  2064. run_test "keyUsage srv: ECDSA, keyAgreement -> ECDH-" \
  2065. "$P_SRV key_file=data_files/server5.key \
  2066. crt_file=data_files/server5.ku-ka.crt" \
  2067. "$P_CLI" \
  2068. 0 \
  2069. -c "Ciphersuite is TLS-ECDH-"
  2070. run_test "keyUsage srv: ECDSA, keyEncipherment -> fail" \
  2071. "$P_SRV key_file=data_files/server5.key \
  2072. crt_file=data_files/server5.ku-ke.crt" \
  2073. "$P_CLI" \
  2074. 1 \
  2075. -C "Ciphersuite is "
  2076. # Tests for keyUsage in leaf certificates, part 2:
  2077. # client-side checking of server cert
  2078. run_test "keyUsage cli: DigitalSignature+KeyEncipherment, RSA: OK" \
  2079. "$O_SRV -key data_files/server2.key \
  2080. -cert data_files/server2.ku-ds_ke.crt" \
  2081. "$P_CLI debug_level=1 \
  2082. force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
  2083. 0 \
  2084. -C "bad certificate (usage extensions)" \
  2085. -C "Processing of the Certificate handshake message failed" \
  2086. -c "Ciphersuite is TLS-"
  2087. run_test "keyUsage cli: DigitalSignature+KeyEncipherment, DHE-RSA: OK" \
  2088. "$O_SRV -key data_files/server2.key \
  2089. -cert data_files/server2.ku-ds_ke.crt" \
  2090. "$P_CLI debug_level=1 \
  2091. force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA" \
  2092. 0 \
  2093. -C "bad certificate (usage extensions)" \
  2094. -C "Processing of the Certificate handshake message failed" \
  2095. -c "Ciphersuite is TLS-"
  2096. run_test "keyUsage cli: KeyEncipherment, RSA: OK" \
  2097. "$O_SRV -key data_files/server2.key \
  2098. -cert data_files/server2.ku-ke.crt" \
  2099. "$P_CLI debug_level=1 \
  2100. force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
  2101. 0 \
  2102. -C "bad certificate (usage extensions)" \
  2103. -C "Processing of the Certificate handshake message failed" \
  2104. -c "Ciphersuite is TLS-"
  2105. run_test "keyUsage cli: KeyEncipherment, DHE-RSA: fail" \
  2106. "$O_SRV -key data_files/server2.key \
  2107. -cert data_files/server2.ku-ke.crt" \
  2108. "$P_CLI debug_level=1 \
  2109. force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA" \
  2110. 1 \
  2111. -c "bad certificate (usage extensions)" \
  2112. -c "Processing of the Certificate handshake message failed" \
  2113. -C "Ciphersuite is TLS-"
  2114. run_test "keyUsage cli: KeyEncipherment, DHE-RSA: fail, soft" \
  2115. "$O_SRV -key data_files/server2.key \
  2116. -cert data_files/server2.ku-ke.crt" \
  2117. "$P_CLI debug_level=1 auth_mode=optional \
  2118. force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA" \
  2119. 0 \
  2120. -c "bad certificate (usage extensions)" \
  2121. -C "Processing of the Certificate handshake message failed" \
  2122. -c "Ciphersuite is TLS-" \
  2123. -c "! Usage does not match the keyUsage extension"
  2124. run_test "keyUsage cli: DigitalSignature, DHE-RSA: OK" \
  2125. "$O_SRV -key data_files/server2.key \
  2126. -cert data_files/server2.ku-ds.crt" \
  2127. "$P_CLI debug_level=1 \
  2128. force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA" \
  2129. 0 \
  2130. -C "bad certificate (usage extensions)" \
  2131. -C "Processing of the Certificate handshake message failed" \
  2132. -c "Ciphersuite is TLS-"
  2133. run_test "keyUsage cli: DigitalSignature, RSA: fail" \
  2134. "$O_SRV -key data_files/server2.key \
  2135. -cert data_files/server2.ku-ds.crt" \
  2136. "$P_CLI debug_level=1 \
  2137. force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
  2138. 1 \
  2139. -c "bad certificate (usage extensions)" \
  2140. -c "Processing of the Certificate handshake message failed" \
  2141. -C "Ciphersuite is TLS-"
  2142. run_test "keyUsage cli: DigitalSignature, RSA: fail, soft" \
  2143. "$O_SRV -key data_files/server2.key \
  2144. -cert data_files/server2.ku-ds.crt" \
  2145. "$P_CLI debug_level=1 auth_mode=optional \
  2146. force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
  2147. 0 \
  2148. -c "bad certificate (usage extensions)" \
  2149. -C "Processing of the Certificate handshake message failed" \
  2150. -c "Ciphersuite is TLS-" \
  2151. -c "! Usage does not match the keyUsage extension"
  2152. # Tests for keyUsage in leaf certificates, part 3:
  2153. # server-side checking of client cert
  2154. run_test "keyUsage cli-auth: RSA, DigitalSignature: OK" \
  2155. "$P_SRV debug_level=1 auth_mode=optional" \
  2156. "$O_CLI -key data_files/server2.key \
  2157. -cert data_files/server2.ku-ds.crt" \
  2158. 0 \
  2159. -S "bad certificate (usage extensions)" \
  2160. -S "Processing of the Certificate handshake message failed"
  2161. run_test "keyUsage cli-auth: RSA, KeyEncipherment: fail (soft)" \
  2162. "$P_SRV debug_level=1 auth_mode=optional" \
  2163. "$O_CLI -key data_files/server2.key \
  2164. -cert data_files/server2.ku-ke.crt" \
  2165. 0 \
  2166. -s "bad certificate (usage extensions)" \
  2167. -S "Processing of the Certificate handshake message failed"
  2168. run_test "keyUsage cli-auth: RSA, KeyEncipherment: fail (hard)" \
  2169. "$P_SRV debug_level=1 auth_mode=required" \
  2170. "$O_CLI -key data_files/server2.key \
  2171. -cert data_files/server2.ku-ke.crt" \
  2172. 1 \
  2173. -s "bad certificate (usage extensions)" \
  2174. -s "Processing of the Certificate handshake message failed"
  2175. run_test "keyUsage cli-auth: ECDSA, DigitalSignature: OK" \
  2176. "$P_SRV debug_level=1 auth_mode=optional" \
  2177. "$O_CLI -key data_files/server5.key \
  2178. -cert data_files/server5.ku-ds.crt" \
  2179. 0 \
  2180. -S "bad certificate (usage extensions)" \
  2181. -S "Processing of the Certificate handshake message failed"
  2182. run_test "keyUsage cli-auth: ECDSA, KeyAgreement: fail (soft)" \
  2183. "$P_SRV debug_level=1 auth_mode=optional" \
  2184. "$O_CLI -key data_files/server5.key \
  2185. -cert data_files/server5.ku-ka.crt" \
  2186. 0 \
  2187. -s "bad certificate (usage extensions)" \
  2188. -S "Processing of the Certificate handshake message failed"
  2189. # Tests for extendedKeyUsage, part 1: server-side certificate/suite selection
  2190. run_test "extKeyUsage srv: serverAuth -> OK" \
  2191. "$P_SRV key_file=data_files/server5.key \
  2192. crt_file=data_files/server5.eku-srv.crt" \
  2193. "$P_CLI" \
  2194. 0
  2195. run_test "extKeyUsage srv: serverAuth,clientAuth -> OK" \
  2196. "$P_SRV key_file=data_files/server5.key \
  2197. crt_file=data_files/server5.eku-srv.crt" \
  2198. "$P_CLI" \
  2199. 0
  2200. run_test "extKeyUsage srv: codeSign,anyEKU -> OK" \
  2201. "$P_SRV key_file=data_files/server5.key \
  2202. crt_file=data_files/server5.eku-cs_any.crt" \
  2203. "$P_CLI" \
  2204. 0
  2205. run_test "extKeyUsage srv: codeSign -> fail" \
  2206. "$P_SRV key_file=data_files/server5.key \
  2207. crt_file=data_files/server5.eku-cli.crt" \
  2208. "$P_CLI" \
  2209. 1
  2210. # Tests for extendedKeyUsage, part 2: client-side checking of server cert
  2211. run_test "extKeyUsage cli: serverAuth -> OK" \
  2212. "$O_SRV -key data_files/server5.key \
  2213. -cert data_files/server5.eku-srv.crt" \
  2214. "$P_CLI debug_level=1" \
  2215. 0 \
  2216. -C "bad certificate (usage extensions)" \
  2217. -C "Processing of the Certificate handshake message failed" \
  2218. -c "Ciphersuite is TLS-"
  2219. run_test "extKeyUsage cli: serverAuth,clientAuth -> OK" \
  2220. "$O_SRV -key data_files/server5.key \
  2221. -cert data_files/server5.eku-srv_cli.crt" \
  2222. "$P_CLI debug_level=1" \
  2223. 0 \
  2224. -C "bad certificate (usage extensions)" \
  2225. -C "Processing of the Certificate handshake message failed" \
  2226. -c "Ciphersuite is TLS-"
  2227. run_test "extKeyUsage cli: codeSign,anyEKU -> OK" \
  2228. "$O_SRV -key data_files/server5.key \
  2229. -cert data_files/server5.eku-cs_any.crt" \
  2230. "$P_CLI debug_level=1" \
  2231. 0 \
  2232. -C "bad certificate (usage extensions)" \
  2233. -C "Processing of the Certificate handshake message failed" \
  2234. -c "Ciphersuite is TLS-"
  2235. run_test "extKeyUsage cli: codeSign -> fail" \
  2236. "$O_SRV -key data_files/server5.key \
  2237. -cert data_files/server5.eku-cs.crt" \
  2238. "$P_CLI debug_level=1" \
  2239. 1 \
  2240. -c "bad certificate (usage extensions)" \
  2241. -c "Processing of the Certificate handshake message failed" \
  2242. -C "Ciphersuite is TLS-"
  2243. # Tests for extendedKeyUsage, part 3: server-side checking of client cert
  2244. run_test "extKeyUsage cli-auth: clientAuth -> OK" \
  2245. "$P_SRV debug_level=1 auth_mode=optional" \
  2246. "$O_CLI -key data_files/server5.key \
  2247. -cert data_files/server5.eku-cli.crt" \
  2248. 0 \
  2249. -S "bad certificate (usage extensions)" \
  2250. -S "Processing of the Certificate handshake message failed"
  2251. run_test "extKeyUsage cli-auth: serverAuth,clientAuth -> OK" \
  2252. "$P_SRV debug_level=1 auth_mode=optional" \
  2253. "$O_CLI -key data_files/server5.key \
  2254. -cert data_files/server5.eku-srv_cli.crt" \
  2255. 0 \
  2256. -S "bad certificate (usage extensions)" \
  2257. -S "Processing of the Certificate handshake message failed"
  2258. run_test "extKeyUsage cli-auth: codeSign,anyEKU -> OK" \
  2259. "$P_SRV debug_level=1 auth_mode=optional" \
  2260. "$O_CLI -key data_files/server5.key \
  2261. -cert data_files/server5.eku-cs_any.crt" \
  2262. 0 \
  2263. -S "bad certificate (usage extensions)" \
  2264. -S "Processing of the Certificate handshake message failed"
  2265. run_test "extKeyUsage cli-auth: codeSign -> fail (soft)" \
  2266. "$P_SRV debug_level=1 auth_mode=optional" \
  2267. "$O_CLI -key data_files/server5.key \
  2268. -cert data_files/server5.eku-cs.crt" \
  2269. 0 \
  2270. -s "bad certificate (usage extensions)" \
  2271. -S "Processing of the Certificate handshake message failed"
  2272. run_test "extKeyUsage cli-auth: codeSign -> fail (hard)" \
  2273. "$P_SRV debug_level=1 auth_mode=required" \
  2274. "$O_CLI -key data_files/server5.key \
  2275. -cert data_files/server5.eku-cs.crt" \
  2276. 1 \
  2277. -s "bad certificate (usage extensions)" \
  2278. -s "Processing of the Certificate handshake message failed"
  2279. # Tests for DHM parameters loading
  2280. run_test "DHM parameters: reference" \
  2281. "$P_SRV" \
  2282. "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
  2283. debug_level=3" \
  2284. 0 \
  2285. -c "value of 'DHM: P ' (2048 bits)" \
  2286. -c "value of 'DHM: G ' (2048 bits)"
  2287. run_test "DHM parameters: other parameters" \
  2288. "$P_SRV dhm_file=data_files/dhparams.pem" \
  2289. "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
  2290. debug_level=3" \
  2291. 0 \
  2292. -c "value of 'DHM: P ' (1024 bits)" \
  2293. -c "value of 'DHM: G ' (2 bits)"
  2294. # Tests for DHM client-side size checking
  2295. run_test "DHM size: server default, client default, OK" \
  2296. "$P_SRV" \
  2297. "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
  2298. debug_level=1" \
  2299. 0 \
  2300. -C "DHM prime too short:"
  2301. run_test "DHM size: server default, client 2048, OK" \
  2302. "$P_SRV" \
  2303. "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
  2304. debug_level=1 dhmlen=2048" \
  2305. 0 \
  2306. -C "DHM prime too short:"
  2307. run_test "DHM size: server 1024, client default, OK" \
  2308. "$P_SRV dhm_file=data_files/dhparams.pem" \
  2309. "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
  2310. debug_level=1" \
  2311. 0 \
  2312. -C "DHM prime too short:"
  2313. run_test "DHM size: server 1000, client default, rejected" \
  2314. "$P_SRV dhm_file=data_files/dh.1000.pem" \
  2315. "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
  2316. debug_level=1" \
  2317. 1 \
  2318. -c "DHM prime too short:"
  2319. run_test "DHM size: server default, client 2049, rejected" \
  2320. "$P_SRV" \
  2321. "$P_CLI force_ciphersuite=TLS-DHE-RSA-WITH-AES-128-CBC-SHA \
  2322. debug_level=1 dhmlen=2049" \
  2323. 1 \
  2324. -c "DHM prime too short:"
  2325. # Tests for PSK callback
  2326. run_test "PSK callback: psk, no callback" \
  2327. "$P_SRV psk=abc123 psk_identity=foo" \
  2328. "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
  2329. psk_identity=foo psk=abc123" \
  2330. 0 \
  2331. -S "SSL - None of the common ciphersuites is usable" \
  2332. -S "SSL - Unknown identity received" \
  2333. -S "SSL - Verification of the message MAC failed"
  2334. run_test "PSK callback: no psk, no callback" \
  2335. "$P_SRV" \
  2336. "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
  2337. psk_identity=foo psk=abc123" \
  2338. 1 \
  2339. -s "SSL - None of the common ciphersuites is usable" \
  2340. -S "SSL - Unknown identity received" \
  2341. -S "SSL - Verification of the message MAC failed"
  2342. run_test "PSK callback: callback overrides other settings" \
  2343. "$P_SRV psk=abc123 psk_identity=foo psk_list=abc,dead,def,beef" \
  2344. "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
  2345. psk_identity=foo psk=abc123" \
  2346. 1 \
  2347. -S "SSL - None of the common ciphersuites is usable" \
  2348. -s "SSL - Unknown identity received" \
  2349. -S "SSL - Verification of the message MAC failed"
  2350. run_test "PSK callback: first id matches" \
  2351. "$P_SRV psk_list=abc,dead,def,beef" \
  2352. "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
  2353. psk_identity=abc psk=dead" \
  2354. 0 \
  2355. -S "SSL - None of the common ciphersuites is usable" \
  2356. -S "SSL - Unknown identity received" \
  2357. -S "SSL - Verification of the message MAC failed"
  2358. run_test "PSK callback: second id matches" \
  2359. "$P_SRV psk_list=abc,dead,def,beef" \
  2360. "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
  2361. psk_identity=def psk=beef" \
  2362. 0 \
  2363. -S "SSL - None of the common ciphersuites is usable" \
  2364. -S "SSL - Unknown identity received" \
  2365. -S "SSL - Verification of the message MAC failed"
  2366. run_test "PSK callback: no match" \
  2367. "$P_SRV psk_list=abc,dead,def,beef" \
  2368. "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
  2369. psk_identity=ghi psk=beef" \
  2370. 1 \
  2371. -S "SSL - None of the common ciphersuites is usable" \
  2372. -s "SSL - Unknown identity received" \
  2373. -S "SSL - Verification of the message MAC failed"
  2374. run_test "PSK callback: wrong key" \
  2375. "$P_SRV psk_list=abc,dead,def,beef" \
  2376. "$P_CLI force_ciphersuite=TLS-PSK-WITH-AES-128-CBC-SHA \
  2377. psk_identity=abc psk=beef" \
  2378. 1 \
  2379. -S "SSL - None of the common ciphersuites is usable" \
  2380. -S "SSL - Unknown identity received" \
  2381. -s "SSL - Verification of the message MAC failed"
  2382. # Tests for EC J-PAKE
  2383. requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECJPAKE
  2384. run_test "ECJPAKE: client not configured" \
  2385. "$P_SRV debug_level=3" \
  2386. "$P_CLI debug_level=3" \
  2387. 0 \
  2388. -C "add ciphersuite: c0ff" \
  2389. -C "adding ecjpake_kkpp extension" \
  2390. -S "found ecjpake kkpp extension" \
  2391. -S "skip ecjpake kkpp extension" \
  2392. -S "ciphersuite mismatch: ecjpake not configured" \
  2393. -S "server hello, ecjpake kkpp extension" \
  2394. -C "found ecjpake_kkpp extension" \
  2395. -S "None of the common ciphersuites is usable"
  2396. requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECJPAKE
  2397. run_test "ECJPAKE: server not configured" \
  2398. "$P_SRV debug_level=3" \
  2399. "$P_CLI debug_level=3 ecjpake_pw=bla \
  2400. force_ciphersuite=TLS-ECJPAKE-WITH-AES-128-CCM-8" \
  2401. 1 \
  2402. -c "add ciphersuite: c0ff" \
  2403. -c "adding ecjpake_kkpp extension" \
  2404. -s "found ecjpake kkpp extension" \
  2405. -s "skip ecjpake kkpp extension" \
  2406. -s "ciphersuite mismatch: ecjpake not configured" \
  2407. -S "server hello, ecjpake kkpp extension" \
  2408. -C "found ecjpake_kkpp extension" \
  2409. -s "None of the common ciphersuites is usable"
  2410. requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECJPAKE
  2411. run_test "ECJPAKE: working, TLS" \
  2412. "$P_SRV debug_level=3 ecjpake_pw=bla" \
  2413. "$P_CLI debug_level=3 ecjpake_pw=bla \
  2414. force_ciphersuite=TLS-ECJPAKE-WITH-AES-128-CCM-8" \
  2415. 0 \
  2416. -c "add ciphersuite: c0ff" \
  2417. -c "adding ecjpake_kkpp extension" \
  2418. -C "re-using cached ecjpake parameters" \
  2419. -s "found ecjpake kkpp extension" \
  2420. -S "skip ecjpake kkpp extension" \
  2421. -S "ciphersuite mismatch: ecjpake not configured" \
  2422. -s "server hello, ecjpake kkpp extension" \
  2423. -c "found ecjpake_kkpp extension" \
  2424. -S "None of the common ciphersuites is usable" \
  2425. -S "SSL - Verification of the message MAC failed"
  2426. server_needs_more_time 1
  2427. requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECJPAKE
  2428. run_test "ECJPAKE: password mismatch, TLS" \
  2429. "$P_SRV debug_level=3 ecjpake_pw=bla" \
  2430. "$P_CLI debug_level=3 ecjpake_pw=bad \
  2431. force_ciphersuite=TLS-ECJPAKE-WITH-AES-128-CCM-8" \
  2432. 1 \
  2433. -C "re-using cached ecjpake parameters" \
  2434. -s "SSL - Verification of the message MAC failed"
  2435. requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECJPAKE
  2436. run_test "ECJPAKE: working, DTLS" \
  2437. "$P_SRV debug_level=3 dtls=1 ecjpake_pw=bla" \
  2438. "$P_CLI debug_level=3 dtls=1 ecjpake_pw=bla \
  2439. force_ciphersuite=TLS-ECJPAKE-WITH-AES-128-CCM-8" \
  2440. 0 \
  2441. -c "re-using cached ecjpake parameters" \
  2442. -S "SSL - Verification of the message MAC failed"
  2443. requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECJPAKE
  2444. run_test "ECJPAKE: working, DTLS, no cookie" \
  2445. "$P_SRV debug_level=3 dtls=1 ecjpake_pw=bla cookies=0" \
  2446. "$P_CLI debug_level=3 dtls=1 ecjpake_pw=bla \
  2447. force_ciphersuite=TLS-ECJPAKE-WITH-AES-128-CCM-8" \
  2448. 0 \
  2449. -C "re-using cached ecjpake parameters" \
  2450. -S "SSL - Verification of the message MAC failed"
  2451. server_needs_more_time 1
  2452. requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECJPAKE
  2453. run_test "ECJPAKE: password mismatch, DTLS" \
  2454. "$P_SRV debug_level=3 dtls=1 ecjpake_pw=bla" \
  2455. "$P_CLI debug_level=3 dtls=1 ecjpake_pw=bad \
  2456. force_ciphersuite=TLS-ECJPAKE-WITH-AES-128-CCM-8" \
  2457. 1 \
  2458. -c "re-using cached ecjpake parameters" \
  2459. -s "SSL - Verification of the message MAC failed"
  2460. # for tests with configs/config-thread.h
  2461. requires_config_enabled MBEDTLS_KEY_EXCHANGE_ECJPAKE
  2462. run_test "ECJPAKE: working, DTLS, nolog" \
  2463. "$P_SRV dtls=1 ecjpake_pw=bla" \
  2464. "$P_CLI dtls=1 ecjpake_pw=bla \
  2465. force_ciphersuite=TLS-ECJPAKE-WITH-AES-128-CCM-8" \
  2466. 0
  2467. # Tests for ciphersuites per version
  2468. requires_config_enabled MBEDTLS_SSL_PROTO_SSL3
  2469. run_test "Per-version suites: SSL3" \
  2470. "$P_SRV min_version=ssl3 version_suites=TLS-RSA-WITH-3DES-EDE-CBC-SHA,TLS-RSA-WITH-AES-256-CBC-SHA,TLS-RSA-WITH-AES-128-CBC-SHA,TLS-RSA-WITH-AES-128-GCM-SHA256" \
  2471. "$P_CLI force_version=ssl3" \
  2472. 0 \
  2473. -c "Ciphersuite is TLS-RSA-WITH-3DES-EDE-CBC-SHA"
  2474. run_test "Per-version suites: TLS 1.0" \
  2475. "$P_SRV arc4=1 version_suites=TLS-RSA-WITH-3DES-EDE-CBC-SHA,TLS-RSA-WITH-AES-256-CBC-SHA,TLS-RSA-WITH-AES-128-CBC-SHA,TLS-RSA-WITH-AES-128-GCM-SHA256" \
  2476. "$P_CLI force_version=tls1 arc4=1" \
  2477. 0 \
  2478. -c "Ciphersuite is TLS-RSA-WITH-AES-256-CBC-SHA"
  2479. run_test "Per-version suites: TLS 1.1" \
  2480. "$P_SRV version_suites=TLS-RSA-WITH-3DES-EDE-CBC-SHA,TLS-RSA-WITH-AES-256-CBC-SHA,TLS-RSA-WITH-AES-128-CBC-SHA,TLS-RSA-WITH-AES-128-GCM-SHA256" \
  2481. "$P_CLI force_version=tls1_1" \
  2482. 0 \
  2483. -c "Ciphersuite is TLS-RSA-WITH-AES-128-CBC-SHA"
  2484. run_test "Per-version suites: TLS 1.2" \
  2485. "$P_SRV version_suites=TLS-RSA-WITH-3DES-EDE-CBC-SHA,TLS-RSA-WITH-AES-256-CBC-SHA,TLS-RSA-WITH-AES-128-CBC-SHA,TLS-RSA-WITH-AES-128-GCM-SHA256" \
  2486. "$P_CLI force_version=tls1_2" \
  2487. 0 \
  2488. -c "Ciphersuite is TLS-RSA-WITH-AES-128-GCM-SHA256"
  2489. # Test for ClientHello without extensions
  2490. requires_gnutls
  2491. run_test "ClientHello without extensions" \
  2492. "$P_SRV debug_level=3" \
  2493. "$G_CLI --priority=NORMAL:%NO_EXTENSIONS:%DISABLE_SAFE_RENEGOTIATION" \
  2494. 0 \
  2495. -s "dumping 'client hello extensions' (0 bytes)"
  2496. # Tests for mbedtls_ssl_get_bytes_avail()
  2497. run_test "mbedtls_ssl_get_bytes_avail: no extra data" \
  2498. "$P_SRV" \
  2499. "$P_CLI request_size=100" \
  2500. 0 \
  2501. -s "Read from client: 100 bytes read$"
  2502. run_test "mbedtls_ssl_get_bytes_avail: extra data" \
  2503. "$P_SRV" \
  2504. "$P_CLI request_size=500" \
  2505. 0 \
  2506. -s "Read from client: 500 bytes read (.*+.*)"
  2507. # Tests for small packets
  2508. requires_config_enabled MBEDTLS_SSL_PROTO_SSL3
  2509. run_test "Small packet SSLv3 BlockCipher" \
  2510. "$P_SRV min_version=ssl3" \
  2511. "$P_CLI request_size=1 force_version=ssl3 \
  2512. force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
  2513. 0 \
  2514. -s "Read from client: 1 bytes read"
  2515. requires_config_enabled MBEDTLS_SSL_PROTO_SSL3
  2516. run_test "Small packet SSLv3 StreamCipher" \
  2517. "$P_SRV min_version=ssl3 arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
  2518. "$P_CLI request_size=1 force_version=ssl3 \
  2519. force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
  2520. 0 \
  2521. -s "Read from client: 1 bytes read"
  2522. run_test "Small packet TLS 1.0 BlockCipher" \
  2523. "$P_SRV" \
  2524. "$P_CLI request_size=1 force_version=tls1 \
  2525. force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
  2526. 0 \
  2527. -s "Read from client: 1 bytes read"
  2528. run_test "Small packet TLS 1.0 BlockCipher without EtM" \
  2529. "$P_SRV" \
  2530. "$P_CLI request_size=1 force_version=tls1 etm=0 \
  2531. force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
  2532. 0 \
  2533. -s "Read from client: 1 bytes read"
  2534. run_test "Small packet TLS 1.0 BlockCipher truncated MAC" \
  2535. "$P_SRV" \
  2536. "$P_CLI request_size=1 force_version=tls1 \
  2537. force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA \
  2538. trunc_hmac=1" \
  2539. 0 \
  2540. -s "Read from client: 1 bytes read"
  2541. run_test "Small packet TLS 1.0 StreamCipher truncated MAC" \
  2542. "$P_SRV arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
  2543. "$P_CLI request_size=1 force_version=tls1 \
  2544. force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA \
  2545. trunc_hmac=1" \
  2546. 0 \
  2547. -s "Read from client: 1 bytes read"
  2548. run_test "Small packet TLS 1.1 BlockCipher" \
  2549. "$P_SRV" \
  2550. "$P_CLI request_size=1 force_version=tls1_1 \
  2551. force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
  2552. 0 \
  2553. -s "Read from client: 1 bytes read"
  2554. run_test "Small packet TLS 1.1 BlockCipher without EtM" \
  2555. "$P_SRV" \
  2556. "$P_CLI request_size=1 force_version=tls1_1 etm=0 \
  2557. force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
  2558. 0 \
  2559. -s "Read from client: 1 bytes read"
  2560. run_test "Small packet TLS 1.1 StreamCipher" \
  2561. "$P_SRV arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
  2562. "$P_CLI request_size=1 force_version=tls1_1 \
  2563. force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
  2564. 0 \
  2565. -s "Read from client: 1 bytes read"
  2566. run_test "Small packet TLS 1.1 BlockCipher truncated MAC" \
  2567. "$P_SRV" \
  2568. "$P_CLI request_size=1 force_version=tls1_1 \
  2569. force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA \
  2570. trunc_hmac=1" \
  2571. 0 \
  2572. -s "Read from client: 1 bytes read"
  2573. run_test "Small packet TLS 1.1 StreamCipher truncated MAC" \
  2574. "$P_SRV arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
  2575. "$P_CLI request_size=1 force_version=tls1_1 \
  2576. force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA \
  2577. trunc_hmac=1" \
  2578. 0 \
  2579. -s "Read from client: 1 bytes read"
  2580. run_test "Small packet TLS 1.2 BlockCipher" \
  2581. "$P_SRV" \
  2582. "$P_CLI request_size=1 force_version=tls1_2 \
  2583. force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
  2584. 0 \
  2585. -s "Read from client: 1 bytes read"
  2586. run_test "Small packet TLS 1.2 BlockCipher without EtM" \
  2587. "$P_SRV" \
  2588. "$P_CLI request_size=1 force_version=tls1_2 etm=0 \
  2589. force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
  2590. 0 \
  2591. -s "Read from client: 1 bytes read"
  2592. run_test "Small packet TLS 1.2 BlockCipher larger MAC" \
  2593. "$P_SRV" \
  2594. "$P_CLI request_size=1 force_version=tls1_2 \
  2595. force_ciphersuite=TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA384" \
  2596. 0 \
  2597. -s "Read from client: 1 bytes read"
  2598. run_test "Small packet TLS 1.2 BlockCipher truncated MAC" \
  2599. "$P_SRV" \
  2600. "$P_CLI request_size=1 force_version=tls1_2 \
  2601. force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA \
  2602. trunc_hmac=1" \
  2603. 0 \
  2604. -s "Read from client: 1 bytes read"
  2605. run_test "Small packet TLS 1.2 StreamCipher" \
  2606. "$P_SRV arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
  2607. "$P_CLI request_size=1 force_version=tls1_2 \
  2608. force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
  2609. 0 \
  2610. -s "Read from client: 1 bytes read"
  2611. run_test "Small packet TLS 1.2 StreamCipher truncated MAC" \
  2612. "$P_SRV arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
  2613. "$P_CLI request_size=1 force_version=tls1_2 \
  2614. force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA \
  2615. trunc_hmac=1" \
  2616. 0 \
  2617. -s "Read from client: 1 bytes read"
  2618. run_test "Small packet TLS 1.2 AEAD" \
  2619. "$P_SRV" \
  2620. "$P_CLI request_size=1 force_version=tls1_2 \
  2621. force_ciphersuite=TLS-RSA-WITH-AES-256-CCM" \
  2622. 0 \
  2623. -s "Read from client: 1 bytes read"
  2624. run_test "Small packet TLS 1.2 AEAD shorter tag" \
  2625. "$P_SRV" \
  2626. "$P_CLI request_size=1 force_version=tls1_2 \
  2627. force_ciphersuite=TLS-RSA-WITH-AES-256-CCM-8" \
  2628. 0 \
  2629. -s "Read from client: 1 bytes read"
  2630. # A test for extensions in SSLv3
  2631. requires_config_enabled MBEDTLS_SSL_PROTO_SSL3
  2632. run_test "SSLv3 with extensions, server side" \
  2633. "$P_SRV min_version=ssl3 debug_level=3" \
  2634. "$P_CLI force_version=ssl3 tickets=1 max_frag_len=4096 alpn=abc,1234" \
  2635. 0 \
  2636. -S "dumping 'client hello extensions'" \
  2637. -S "server hello, total extension length:"
  2638. # Test for large packets
  2639. requires_config_enabled MBEDTLS_SSL_PROTO_SSL3
  2640. run_test "Large packet SSLv3 BlockCipher" \
  2641. "$P_SRV min_version=ssl3" \
  2642. "$P_CLI request_size=16384 force_version=ssl3 recsplit=0 \
  2643. force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
  2644. 0 \
  2645. -s "Read from client: 16384 bytes read"
  2646. requires_config_enabled MBEDTLS_SSL_PROTO_SSL3
  2647. run_test "Large packet SSLv3 StreamCipher" \
  2648. "$P_SRV min_version=ssl3 arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
  2649. "$P_CLI request_size=16384 force_version=ssl3 \
  2650. force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
  2651. 0 \
  2652. -s "Read from client: 16384 bytes read"
  2653. run_test "Large packet TLS 1.0 BlockCipher" \
  2654. "$P_SRV" \
  2655. "$P_CLI request_size=16384 force_version=tls1 recsplit=0 \
  2656. force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
  2657. 0 \
  2658. -s "Read from client: 16384 bytes read"
  2659. run_test "Large packet TLS 1.0 BlockCipher truncated MAC" \
  2660. "$P_SRV" \
  2661. "$P_CLI request_size=16384 force_version=tls1 recsplit=0 \
  2662. force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA \
  2663. trunc_hmac=1" \
  2664. 0 \
  2665. -s "Read from client: 16384 bytes read"
  2666. run_test "Large packet TLS 1.0 StreamCipher truncated MAC" \
  2667. "$P_SRV arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
  2668. "$P_CLI request_size=16384 force_version=tls1 \
  2669. force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA \
  2670. trunc_hmac=1" \
  2671. 0 \
  2672. -s "Read from client: 16384 bytes read"
  2673. run_test "Large packet TLS 1.1 BlockCipher" \
  2674. "$P_SRV" \
  2675. "$P_CLI request_size=16384 force_version=tls1_1 \
  2676. force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
  2677. 0 \
  2678. -s "Read from client: 16384 bytes read"
  2679. run_test "Large packet TLS 1.1 StreamCipher" \
  2680. "$P_SRV arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
  2681. "$P_CLI request_size=16384 force_version=tls1_1 \
  2682. force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
  2683. 0 \
  2684. -s "Read from client: 16384 bytes read"
  2685. run_test "Large packet TLS 1.1 BlockCipher truncated MAC" \
  2686. "$P_SRV" \
  2687. "$P_CLI request_size=16384 force_version=tls1_1 \
  2688. force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA \
  2689. trunc_hmac=1" \
  2690. 0 \
  2691. -s "Read from client: 16384 bytes read"
  2692. run_test "Large packet TLS 1.1 StreamCipher truncated MAC" \
  2693. "$P_SRV arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
  2694. "$P_CLI request_size=16384 force_version=tls1_1 \
  2695. force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA \
  2696. trunc_hmac=1" \
  2697. 0 \
  2698. -s "Read from client: 16384 bytes read"
  2699. run_test "Large packet TLS 1.2 BlockCipher" \
  2700. "$P_SRV" \
  2701. "$P_CLI request_size=16384 force_version=tls1_2 \
  2702. force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA" \
  2703. 0 \
  2704. -s "Read from client: 16384 bytes read"
  2705. run_test "Large packet TLS 1.2 BlockCipher larger MAC" \
  2706. "$P_SRV" \
  2707. "$P_CLI request_size=16384 force_version=tls1_2 \
  2708. force_ciphersuite=TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA384" \
  2709. 0 \
  2710. -s "Read from client: 16384 bytes read"
  2711. run_test "Large packet TLS 1.2 BlockCipher truncated MAC" \
  2712. "$P_SRV" \
  2713. "$P_CLI request_size=16384 force_version=tls1_2 \
  2714. force_ciphersuite=TLS-RSA-WITH-AES-256-CBC-SHA \
  2715. trunc_hmac=1" \
  2716. 0 \
  2717. -s "Read from client: 16384 bytes read"
  2718. run_test "Large packet TLS 1.2 StreamCipher" \
  2719. "$P_SRV arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
  2720. "$P_CLI request_size=16384 force_version=tls1_2 \
  2721. force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
  2722. 0 \
  2723. -s "Read from client: 16384 bytes read"
  2724. run_test "Large packet TLS 1.2 StreamCipher truncated MAC" \
  2725. "$P_SRV arc4=1 force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA" \
  2726. "$P_CLI request_size=16384 force_version=tls1_2 \
  2727. force_ciphersuite=TLS-RSA-WITH-RC4-128-SHA \
  2728. trunc_hmac=1" \
  2729. 0 \
  2730. -s "Read from client: 16384 bytes read"
  2731. run_test "Large packet TLS 1.2 AEAD" \
  2732. "$P_SRV" \
  2733. "$P_CLI request_size=16384 force_version=tls1_2 \
  2734. force_ciphersuite=TLS-RSA-WITH-AES-256-CCM" \
  2735. 0 \
  2736. -s "Read from client: 16384 bytes read"
  2737. run_test "Large packet TLS 1.2 AEAD shorter tag" \
  2738. "$P_SRV" \
  2739. "$P_CLI request_size=16384 force_version=tls1_2 \
  2740. force_ciphersuite=TLS-RSA-WITH-AES-256-CCM-8" \
  2741. 0 \
  2742. -s "Read from client: 16384 bytes read"
  2743. # Tests for DTLS HelloVerifyRequest
  2744. run_test "DTLS cookie: enabled" \
  2745. "$P_SRV dtls=1 debug_level=2" \
  2746. "$P_CLI dtls=1 debug_level=2" \
  2747. 0 \
  2748. -s "cookie verification failed" \
  2749. -s "cookie verification passed" \
  2750. -S "cookie verification skipped" \
  2751. -c "received hello verify request" \
  2752. -s "hello verification requested" \
  2753. -S "SSL - The requested feature is not available"
  2754. run_test "DTLS cookie: disabled" \
  2755. "$P_SRV dtls=1 debug_level=2 cookies=0" \
  2756. "$P_CLI dtls=1 debug_level=2" \
  2757. 0 \
  2758. -S "cookie verification failed" \
  2759. -S "cookie verification passed" \
  2760. -s "cookie verification skipped" \
  2761. -C "received hello verify request" \
  2762. -S "hello verification requested" \
  2763. -S "SSL - The requested feature is not available"
  2764. run_test "DTLS cookie: default (failing)" \
  2765. "$P_SRV dtls=1 debug_level=2 cookies=-1" \
  2766. "$P_CLI dtls=1 debug_level=2 hs_timeout=100-400" \
  2767. 1 \
  2768. -s "cookie verification failed" \
  2769. -S "cookie verification passed" \
  2770. -S "cookie verification skipped" \
  2771. -C "received hello verify request" \
  2772. -S "hello verification requested" \
  2773. -s "SSL - The requested feature is not available"
  2774. requires_ipv6
  2775. run_test "DTLS cookie: enabled, IPv6" \
  2776. "$P_SRV dtls=1 debug_level=2 server_addr=::1" \
  2777. "$P_CLI dtls=1 debug_level=2 server_addr=::1" \
  2778. 0 \
  2779. -s "cookie verification failed" \
  2780. -s "cookie verification passed" \
  2781. -S "cookie verification skipped" \
  2782. -c "received hello verify request" \
  2783. -s "hello verification requested" \
  2784. -S "SSL - The requested feature is not available"
  2785. run_test "DTLS cookie: enabled, nbio" \
  2786. "$P_SRV dtls=1 nbio=2 debug_level=2" \
  2787. "$P_CLI dtls=1 nbio=2 debug_level=2" \
  2788. 0 \
  2789. -s "cookie verification failed" \
  2790. -s "cookie verification passed" \
  2791. -S "cookie verification skipped" \
  2792. -c "received hello verify request" \
  2793. -s "hello verification requested" \
  2794. -S "SSL - The requested feature is not available"
  2795. # Tests for client reconnecting from the same port with DTLS
  2796. not_with_valgrind # spurious resend
  2797. run_test "DTLS client reconnect from same port: reference" \
  2798. "$P_SRV dtls=1 exchanges=2 read_timeout=1000" \
  2799. "$P_CLI dtls=1 exchanges=2 debug_level=2 hs_timeout=500-1000" \
  2800. 0 \
  2801. -C "resend" \
  2802. -S "The operation timed out" \
  2803. -S "Client initiated reconnection from same port"
  2804. not_with_valgrind # spurious resend
  2805. run_test "DTLS client reconnect from same port: reconnect" \
  2806. "$P_SRV dtls=1 exchanges=2 read_timeout=1000" \
  2807. "$P_CLI dtls=1 exchanges=2 debug_level=2 hs_timeout=500-1000 reconnect_hard=1" \
  2808. 0 \
  2809. -C "resend" \
  2810. -S "The operation timed out" \
  2811. -s "Client initiated reconnection from same port"
  2812. not_with_valgrind # server/client too slow to respond in time (next test has higher timeouts)
  2813. run_test "DTLS client reconnect from same port: reconnect, nbio, no valgrind" \
  2814. "$P_SRV dtls=1 exchanges=2 read_timeout=1000 nbio=2" \
  2815. "$P_CLI dtls=1 exchanges=2 debug_level=2 hs_timeout=500-1000 reconnect_hard=1" \
  2816. 0 \
  2817. -S "The operation timed out" \
  2818. -s "Client initiated reconnection from same port"
  2819. only_with_valgrind # Only with valgrind, do previous test but with higher read_timeout and hs_timeout
  2820. run_test "DTLS client reconnect from same port: reconnect, nbio, valgrind" \
  2821. "$P_SRV dtls=1 exchanges=2 read_timeout=2000 nbio=2 hs_timeout=1500-6000" \
  2822. "$P_CLI dtls=1 exchanges=2 debug_level=2 hs_timeout=1500-3000 reconnect_hard=1" \
  2823. 0 \
  2824. -S "The operation timed out" \
  2825. -s "Client initiated reconnection from same port"
  2826. run_test "DTLS client reconnect from same port: no cookies" \
  2827. "$P_SRV dtls=1 exchanges=2 read_timeout=1000 cookies=0" \
  2828. "$P_CLI dtls=1 exchanges=2 debug_level=2 hs_timeout=500-8000 reconnect_hard=1" \
  2829. 0 \
  2830. -s "The operation timed out" \
  2831. -S "Client initiated reconnection from same port"
  2832. # Tests for various cases of client authentication with DTLS
  2833. # (focused on handshake flows and message parsing)
  2834. run_test "DTLS client auth: required" \
  2835. "$P_SRV dtls=1 auth_mode=required" \
  2836. "$P_CLI dtls=1" \
  2837. 0 \
  2838. -s "Verifying peer X.509 certificate... ok"
  2839. run_test "DTLS client auth: optional, client has no cert" \
  2840. "$P_SRV dtls=1 auth_mode=optional" \
  2841. "$P_CLI dtls=1 crt_file=none key_file=none" \
  2842. 0 \
  2843. -s "! Certificate was missing"
  2844. run_test "DTLS client auth: none, client has no cert" \
  2845. "$P_SRV dtls=1 auth_mode=none" \
  2846. "$P_CLI dtls=1 crt_file=none key_file=none debug_level=2" \
  2847. 0 \
  2848. -c "skip write certificate$" \
  2849. -s "! Certificate verification was skipped"
  2850. run_test "DTLS wrong PSK: badmac alert" \
  2851. "$P_SRV dtls=1 psk=abc123 force_ciphersuite=TLS-PSK-WITH-AES-128-GCM-SHA256" \
  2852. "$P_CLI dtls=1 psk=abc124" \
  2853. 1 \
  2854. -s "SSL - Verification of the message MAC failed" \
  2855. -c "SSL - A fatal alert message was received from our peer"
  2856. # Tests for receiving fragmented handshake messages with DTLS
  2857. requires_gnutls
  2858. run_test "DTLS reassembly: no fragmentation (gnutls server)" \
  2859. "$G_SRV -u --mtu 2048 -a" \
  2860. "$P_CLI dtls=1 debug_level=2" \
  2861. 0 \
  2862. -C "found fragmented DTLS handshake message" \
  2863. -C "error"
  2864. requires_gnutls
  2865. run_test "DTLS reassembly: some fragmentation (gnutls server)" \
  2866. "$G_SRV -u --mtu 512" \
  2867. "$P_CLI dtls=1 debug_level=2" \
  2868. 0 \
  2869. -c "found fragmented DTLS handshake message" \
  2870. -C "error"
  2871. requires_gnutls
  2872. run_test "DTLS reassembly: more fragmentation (gnutls server)" \
  2873. "$G_SRV -u --mtu 128" \
  2874. "$P_CLI dtls=1 debug_level=2" \
  2875. 0 \
  2876. -c "found fragmented DTLS handshake message" \
  2877. -C "error"
  2878. requires_gnutls
  2879. run_test "DTLS reassembly: more fragmentation, nbio (gnutls server)" \
  2880. "$G_SRV -u --mtu 128" \
  2881. "$P_CLI dtls=1 nbio=2 debug_level=2" \
  2882. 0 \
  2883. -c "found fragmented DTLS handshake message" \
  2884. -C "error"
  2885. requires_gnutls
  2886. run_test "DTLS reassembly: fragmentation, renego (gnutls server)" \
  2887. "$G_SRV -u --mtu 256" \
  2888. "$P_CLI debug_level=3 dtls=1 renegotiation=1 renegotiate=1" \
  2889. 0 \
  2890. -c "found fragmented DTLS handshake message" \
  2891. -c "client hello, adding renegotiation extension" \
  2892. -c "found renegotiation extension" \
  2893. -c "=> renegotiate" \
  2894. -C "mbedtls_ssl_handshake returned" \
  2895. -C "error" \
  2896. -s "Extra-header:"
  2897. requires_gnutls
  2898. run_test "DTLS reassembly: fragmentation, nbio, renego (gnutls server)" \
  2899. "$G_SRV -u --mtu 256" \
  2900. "$P_CLI debug_level=3 nbio=2 dtls=1 renegotiation=1 renegotiate=1" \
  2901. 0 \
  2902. -c "found fragmented DTLS handshake message" \
  2903. -c "client hello, adding renegotiation extension" \
  2904. -c "found renegotiation extension" \
  2905. -c "=> renegotiate" \
  2906. -C "mbedtls_ssl_handshake returned" \
  2907. -C "error" \
  2908. -s "Extra-header:"
  2909. run_test "DTLS reassembly: no fragmentation (openssl server)" \
  2910. "$O_SRV -dtls1 -mtu 2048" \
  2911. "$P_CLI dtls=1 debug_level=2" \
  2912. 0 \
  2913. -C "found fragmented DTLS handshake message" \
  2914. -C "error"
  2915. run_test "DTLS reassembly: some fragmentation (openssl server)" \
  2916. "$O_SRV -dtls1 -mtu 768" \
  2917. "$P_CLI dtls=1 debug_level=2" \
  2918. 0 \
  2919. -c "found fragmented DTLS handshake message" \
  2920. -C "error"
  2921. run_test "DTLS reassembly: more fragmentation (openssl server)" \
  2922. "$O_SRV -dtls1 -mtu 256" \
  2923. "$P_CLI dtls=1 debug_level=2" \
  2924. 0 \
  2925. -c "found fragmented DTLS handshake message" \
  2926. -C "error"
  2927. run_test "DTLS reassembly: fragmentation, nbio (openssl server)" \
  2928. "$O_SRV -dtls1 -mtu 256" \
  2929. "$P_CLI dtls=1 nbio=2 debug_level=2" \
  2930. 0 \
  2931. -c "found fragmented DTLS handshake message" \
  2932. -C "error"
  2933. # Tests for specific things with "unreliable" UDP connection
  2934. not_with_valgrind # spurious resend due to timeout
  2935. run_test "DTLS proxy: reference" \
  2936. -p "$P_PXY" \
  2937. "$P_SRV dtls=1 debug_level=2" \
  2938. "$P_CLI dtls=1 debug_level=2" \
  2939. 0 \
  2940. -C "replayed record" \
  2941. -S "replayed record" \
  2942. -C "record from another epoch" \
  2943. -S "record from another epoch" \
  2944. -C "discarding invalid record" \
  2945. -S "discarding invalid record" \
  2946. -S "resend" \
  2947. -s "Extra-header:" \
  2948. -c "HTTP/1.0 200 OK"
  2949. not_with_valgrind # spurious resend due to timeout
  2950. run_test "DTLS proxy: duplicate every packet" \
  2951. -p "$P_PXY duplicate=1" \
  2952. "$P_SRV dtls=1 debug_level=2" \
  2953. "$P_CLI dtls=1 debug_level=2" \
  2954. 0 \
  2955. -c "replayed record" \
  2956. -s "replayed record" \
  2957. -c "discarding invalid record" \
  2958. -s "discarding invalid record" \
  2959. -S "resend" \
  2960. -s "Extra-header:" \
  2961. -c "HTTP/1.0 200 OK"
  2962. run_test "DTLS proxy: duplicate every packet, server anti-replay off" \
  2963. -p "$P_PXY duplicate=1" \
  2964. "$P_SRV dtls=1 debug_level=2 anti_replay=0" \
  2965. "$P_CLI dtls=1 debug_level=2" \
  2966. 0 \
  2967. -c "replayed record" \
  2968. -S "replayed record" \
  2969. -c "discarding invalid record" \
  2970. -s "discarding invalid record" \
  2971. -c "resend" \
  2972. -s "resend" \
  2973. -s "Extra-header:" \
  2974. -c "HTTP/1.0 200 OK"
  2975. run_test "DTLS proxy: inject invalid AD record, default badmac_limit" \
  2976. -p "$P_PXY bad_ad=1" \
  2977. "$P_SRV dtls=1 debug_level=1" \
  2978. "$P_CLI dtls=1 debug_level=1 read_timeout=100" \
  2979. 0 \
  2980. -c "discarding invalid record (mac)" \
  2981. -s "discarding invalid record (mac)" \
  2982. -s "Extra-header:" \
  2983. -c "HTTP/1.0 200 OK" \
  2984. -S "too many records with bad MAC" \
  2985. -S "Verification of the message MAC failed"
  2986. run_test "DTLS proxy: inject invalid AD record, badmac_limit 1" \
  2987. -p "$P_PXY bad_ad=1" \
  2988. "$P_SRV dtls=1 debug_level=1 badmac_limit=1" \
  2989. "$P_CLI dtls=1 debug_level=1 read_timeout=100" \
  2990. 1 \
  2991. -C "discarding invalid record (mac)" \
  2992. -S "discarding invalid record (mac)" \
  2993. -S "Extra-header:" \
  2994. -C "HTTP/1.0 200 OK" \
  2995. -s "too many records with bad MAC" \
  2996. -s "Verification of the message MAC failed"
  2997. run_test "DTLS proxy: inject invalid AD record, badmac_limit 2" \
  2998. -p "$P_PXY bad_ad=1" \
  2999. "$P_SRV dtls=1 debug_level=1 badmac_limit=2" \
  3000. "$P_CLI dtls=1 debug_level=1 read_timeout=100" \
  3001. 0 \
  3002. -c "discarding invalid record (mac)" \
  3003. -s "discarding invalid record (mac)" \
  3004. -s "Extra-header:" \
  3005. -c "HTTP/1.0 200 OK" \
  3006. -S "too many records with bad MAC" \
  3007. -S "Verification of the message MAC failed"
  3008. run_test "DTLS proxy: inject invalid AD record, badmac_limit 2, exchanges 2"\
  3009. -p "$P_PXY bad_ad=1" \
  3010. "$P_SRV dtls=1 debug_level=1 badmac_limit=2 exchanges=2" \
  3011. "$P_CLI dtls=1 debug_level=1 read_timeout=100 exchanges=2" \
  3012. 1 \
  3013. -c "discarding invalid record (mac)" \
  3014. -s "discarding invalid record (mac)" \
  3015. -s "Extra-header:" \
  3016. -c "HTTP/1.0 200 OK" \
  3017. -s "too many records with bad MAC" \
  3018. -s "Verification of the message MAC failed"
  3019. run_test "DTLS proxy: delay ChangeCipherSpec" \
  3020. -p "$P_PXY delay_ccs=1" \
  3021. "$P_SRV dtls=1 debug_level=1" \
  3022. "$P_CLI dtls=1 debug_level=1" \
  3023. 0 \
  3024. -c "record from another epoch" \
  3025. -s "record from another epoch" \
  3026. -c "discarding invalid record" \
  3027. -s "discarding invalid record" \
  3028. -s "Extra-header:" \
  3029. -c "HTTP/1.0 200 OK"
  3030. # Tests for "randomly unreliable connection": try a variety of flows and peers
  3031. client_needs_more_time 2
  3032. run_test "DTLS proxy: 3d (drop, delay, duplicate), \"short\" PSK handshake" \
  3033. -p "$P_PXY drop=5 delay=5 duplicate=5" \
  3034. "$P_SRV dtls=1 hs_timeout=250-10000 tickets=0 auth_mode=none \
  3035. psk=abc123" \
  3036. "$P_CLI dtls=1 hs_timeout=250-10000 tickets=0 psk=abc123 \
  3037. force_ciphersuite=TLS-PSK-WITH-AES-128-CCM-8" \
  3038. 0 \
  3039. -s "Extra-header:" \
  3040. -c "HTTP/1.0 200 OK"
  3041. client_needs_more_time 2
  3042. run_test "DTLS proxy: 3d, \"short\" RSA handshake" \
  3043. -p "$P_PXY drop=5 delay=5 duplicate=5" \
  3044. "$P_SRV dtls=1 hs_timeout=250-10000 tickets=0 auth_mode=none" \
  3045. "$P_CLI dtls=1 hs_timeout=250-10000 tickets=0 \
  3046. force_ciphersuite=TLS-RSA-WITH-AES-128-CBC-SHA" \
  3047. 0 \
  3048. -s "Extra-header:" \
  3049. -c "HTTP/1.0 200 OK"
  3050. client_needs_more_time 2
  3051. run_test "DTLS proxy: 3d, \"short\" (no ticket, no cli_auth) FS handshake" \
  3052. -p "$P_PXY drop=5 delay=5 duplicate=5" \
  3053. "$P_SRV dtls=1 hs_timeout=250-10000 tickets=0 auth_mode=none" \
  3054. "$P_CLI dtls=1 hs_timeout=250-10000 tickets=0" \
  3055. 0 \
  3056. -s "Extra-header:" \
  3057. -c "HTTP/1.0 200 OK"
  3058. client_needs_more_time 2
  3059. run_test "DTLS proxy: 3d, FS, client auth" \
  3060. -p "$P_PXY drop=5 delay=5 duplicate=5" \
  3061. "$P_SRV dtls=1 hs_timeout=250-10000 tickets=0 auth_mode=required" \
  3062. "$P_CLI dtls=1 hs_timeout=250-10000 tickets=0" \
  3063. 0 \
  3064. -s "Extra-header:" \
  3065. -c "HTTP/1.0 200 OK"
  3066. client_needs_more_time 2
  3067. run_test "DTLS proxy: 3d, FS, ticket" \
  3068. -p "$P_PXY drop=5 delay=5 duplicate=5" \
  3069. "$P_SRV dtls=1 hs_timeout=250-10000 tickets=1 auth_mode=none" \
  3070. "$P_CLI dtls=1 hs_timeout=250-10000 tickets=1" \
  3071. 0 \
  3072. -s "Extra-header:" \
  3073. -c "HTTP/1.0 200 OK"
  3074. client_needs_more_time 2
  3075. run_test "DTLS proxy: 3d, max handshake (FS, ticket + client auth)" \
  3076. -p "$P_PXY drop=5 delay=5 duplicate=5" \
  3077. "$P_SRV dtls=1 hs_timeout=250-10000 tickets=1 auth_mode=required" \
  3078. "$P_CLI dtls=1 hs_timeout=250-10000 tickets=1" \
  3079. 0 \
  3080. -s "Extra-header:" \
  3081. -c "HTTP/1.0 200 OK"
  3082. client_needs_more_time 2
  3083. run_test "DTLS proxy: 3d, max handshake, nbio" \
  3084. -p "$P_PXY drop=5 delay=5 duplicate=5" \
  3085. "$P_SRV dtls=1 hs_timeout=250-10000 nbio=2 tickets=1 \
  3086. auth_mode=required" \
  3087. "$P_CLI dtls=1 hs_timeout=250-10000 nbio=2 tickets=1" \
  3088. 0 \
  3089. -s "Extra-header:" \
  3090. -c "HTTP/1.0 200 OK"
  3091. client_needs_more_time 4
  3092. run_test "DTLS proxy: 3d, min handshake, resumption" \
  3093. -p "$P_PXY drop=5 delay=5 duplicate=5" \
  3094. "$P_SRV dtls=1 hs_timeout=250-10000 tickets=0 auth_mode=none \
  3095. psk=abc123 debug_level=3" \
  3096. "$P_CLI dtls=1 hs_timeout=250-10000 tickets=0 psk=abc123 \
  3097. debug_level=3 reconnect=1 read_timeout=1000 max_resend=10 \
  3098. force_ciphersuite=TLS-PSK-WITH-AES-128-CCM-8" \
  3099. 0 \
  3100. -s "a session has been resumed" \
  3101. -c "a session has been resumed" \
  3102. -s "Extra-header:" \
  3103. -c "HTTP/1.0 200 OK"
  3104. client_needs_more_time 4
  3105. run_test "DTLS proxy: 3d, min handshake, resumption, nbio" \
  3106. -p "$P_PXY drop=5 delay=5 duplicate=5" \
  3107. "$P_SRV dtls=1 hs_timeout=250-10000 tickets=0 auth_mode=none \
  3108. psk=abc123 debug_level=3 nbio=2" \
  3109. "$P_CLI dtls=1 hs_timeout=250-10000 tickets=0 psk=abc123 \
  3110. debug_level=3 reconnect=1 read_timeout=1000 max_resend=10 \
  3111. force_ciphersuite=TLS-PSK-WITH-AES-128-CCM-8 nbio=2" \
  3112. 0 \
  3113. -s "a session has been resumed" \
  3114. -c "a session has been resumed" \
  3115. -s "Extra-header:" \
  3116. -c "HTTP/1.0 200 OK"
  3117. client_needs_more_time 4
  3118. run_test "DTLS proxy: 3d, min handshake, client-initiated renego" \
  3119. -p "$P_PXY drop=5 delay=5 duplicate=5" \
  3120. "$P_SRV dtls=1 hs_timeout=250-10000 tickets=0 auth_mode=none \
  3121. psk=abc123 renegotiation=1 debug_level=2" \
  3122. "$P_CLI dtls=1 hs_timeout=250-10000 tickets=0 psk=abc123 \
  3123. renegotiate=1 debug_level=2 \
  3124. force_ciphersuite=TLS-PSK-WITH-AES-128-CCM-8" \
  3125. 0 \
  3126. -c "=> renegotiate" \
  3127. -s "=> renegotiate" \
  3128. -s "Extra-header:" \
  3129. -c "HTTP/1.0 200 OK"
  3130. client_needs_more_time 4
  3131. run_test "DTLS proxy: 3d, min handshake, client-initiated renego, nbio" \
  3132. -p "$P_PXY drop=5 delay=5 duplicate=5" \
  3133. "$P_SRV dtls=1 hs_timeout=250-10000 tickets=0 auth_mode=none \
  3134. psk=abc123 renegotiation=1 debug_level=2" \
  3135. "$P_CLI dtls=1 hs_timeout=250-10000 tickets=0 psk=abc123 \
  3136. renegotiate=1 debug_level=2 \
  3137. force_ciphersuite=TLS-PSK-WITH-AES-128-CCM-8" \
  3138. 0 \
  3139. -c "=> renegotiate" \
  3140. -s "=> renegotiate" \
  3141. -s "Extra-header:" \
  3142. -c "HTTP/1.0 200 OK"
  3143. client_needs_more_time 4
  3144. run_test "DTLS proxy: 3d, min handshake, server-initiated renego" \
  3145. -p "$P_PXY drop=5 delay=5 duplicate=5" \
  3146. "$P_SRV dtls=1 hs_timeout=250-10000 tickets=0 auth_mode=none \
  3147. psk=abc123 renegotiate=1 renegotiation=1 exchanges=4 \
  3148. debug_level=2" \
  3149. "$P_CLI dtls=1 hs_timeout=250-10000 tickets=0 psk=abc123 \
  3150. renegotiation=1 exchanges=4 debug_level=2 \
  3151. force_ciphersuite=TLS-PSK-WITH-AES-128-CCM-8" \
  3152. 0 \
  3153. -c "=> renegotiate" \
  3154. -s "=> renegotiate" \
  3155. -s "Extra-header:" \
  3156. -c "HTTP/1.0 200 OK"
  3157. client_needs_more_time 4
  3158. run_test "DTLS proxy: 3d, min handshake, server-initiated renego, nbio" \
  3159. -p "$P_PXY drop=5 delay=5 duplicate=5" \
  3160. "$P_SRV dtls=1 hs_timeout=250-10000 tickets=0 auth_mode=none \
  3161. psk=abc123 renegotiate=1 renegotiation=1 exchanges=4 \
  3162. debug_level=2 nbio=2" \
  3163. "$P_CLI dtls=1 hs_timeout=250-10000 tickets=0 psk=abc123 \
  3164. renegotiation=1 exchanges=4 debug_level=2 nbio=2 \
  3165. force_ciphersuite=TLS-PSK-WITH-AES-128-CCM-8" \
  3166. 0 \
  3167. -c "=> renegotiate" \
  3168. -s "=> renegotiate" \
  3169. -s "Extra-header:" \
  3170. -c "HTTP/1.0 200 OK"
  3171. client_needs_more_time 6
  3172. not_with_valgrind # risk of non-mbedtls peer timing out
  3173. run_test "DTLS proxy: 3d, openssl server" \
  3174. -p "$P_PXY drop=5 delay=5 duplicate=5 protect_hvr=1" \
  3175. "$O_SRV -dtls1 -mtu 2048" \
  3176. "$P_CLI dtls=1 hs_timeout=250-60000 tickets=0" \
  3177. 0 \
  3178. -c "HTTP/1.0 200 OK"
  3179. client_needs_more_time 8
  3180. not_with_valgrind # risk of non-mbedtls peer timing out
  3181. run_test "DTLS proxy: 3d, openssl server, fragmentation" \
  3182. -p "$P_PXY drop=5 delay=5 duplicate=5 protect_hvr=1" \
  3183. "$O_SRV -dtls1 -mtu 768" \
  3184. "$P_CLI dtls=1 hs_timeout=250-60000 tickets=0" \
  3185. 0 \
  3186. -c "HTTP/1.0 200 OK"
  3187. client_needs_more_time 8
  3188. not_with_valgrind # risk of non-mbedtls peer timing out
  3189. run_test "DTLS proxy: 3d, openssl server, fragmentation, nbio" \
  3190. -p "$P_PXY drop=5 delay=5 duplicate=5 protect_hvr=1" \
  3191. "$O_SRV -dtls1 -mtu 768" \
  3192. "$P_CLI dtls=1 hs_timeout=250-60000 nbio=2 tickets=0" \
  3193. 0 \
  3194. -c "HTTP/1.0 200 OK"
  3195. requires_gnutls
  3196. client_needs_more_time 6
  3197. not_with_valgrind # risk of non-mbedtls peer timing out
  3198. run_test "DTLS proxy: 3d, gnutls server" \
  3199. -p "$P_PXY drop=5 delay=5 duplicate=5" \
  3200. "$G_SRV -u --mtu 2048 -a" \
  3201. "$P_CLI dtls=1 hs_timeout=250-60000" \
  3202. 0 \
  3203. -s "Extra-header:" \
  3204. -c "Extra-header:"
  3205. requires_gnutls
  3206. client_needs_more_time 8
  3207. not_with_valgrind # risk of non-mbedtls peer timing out
  3208. run_test "DTLS proxy: 3d, gnutls server, fragmentation" \
  3209. -p "$P_PXY drop=5 delay=5 duplicate=5" \
  3210. "$G_SRV -u --mtu 512" \
  3211. "$P_CLI dtls=1 hs_timeout=250-60000" \
  3212. 0 \
  3213. -s "Extra-header:" \
  3214. -c "Extra-header:"
  3215. requires_gnutls
  3216. client_needs_more_time 8
  3217. not_with_valgrind # risk of non-mbedtls peer timing out
  3218. run_test "DTLS proxy: 3d, gnutls server, fragmentation, nbio" \
  3219. -p "$P_PXY drop=5 delay=5 duplicate=5" \
  3220. "$G_SRV -u --mtu 512" \
  3221. "$P_CLI dtls=1 hs_timeout=250-60000 nbio=2" \
  3222. 0 \
  3223. -s "Extra-header:" \
  3224. -c "Extra-header:"
  3225. # Final report
  3226. echo "------------------------------------------------------------------------"
  3227. if [ $FAILS = 0 ]; then
  3228. printf "PASSED"
  3229. else
  3230. printf "FAILED"
  3231. fi
  3232. PASSES=$(( $TESTS - $FAILS ))
  3233. echo " ($PASSES / $TESTS tests ($SKIPS skipped))"
  3234. exit $FAILS