openssl.test 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122
  1. #!/bin/sh
  2. #openssl.test
  3. if ! test -n "$WOLFSSL_OPENSSL_TEST"; then
  4. echo "WOLFSSL_OPENSSL_TEST NOT set, won't run"
  5. exit 0
  6. fi
  7. # if we can, isolate the network namespace to eliminate port collisions.
  8. if [ "${AM_BWRAPPED-}" != "yes" ]; then
  9. bwrap_path="$(command -v bwrap)"
  10. if [ -n "$bwrap_path" ]; then
  11. export AM_BWRAPPED=yes
  12. exec "$bwrap_path" --unshare-net --dev-bind / / "$0" "$@"
  13. fi
  14. unset AM_BWRAPPED
  15. fi
  16. echo "WOLFSSL_OPENSSL_TEST set, running test..."
  17. # need a unique port since may run the same time as testsuite
  18. generate_port() {
  19. port=$(($(od -An -N2 /dev/random) % (65535-49512) + 49512))
  20. }
  21. no_pid=-1
  22. servers=""
  23. openssl_pid=$no_pid
  24. ecdh_openssl_pid=$no_pid
  25. ecdsa_openssl_pid=$no_pid
  26. ed25519_openssl_pid=$no_pid
  27. ed448_openssl_pid=$no_pid
  28. tls13_psk_openssl_pid=$no_pid
  29. wolfssl_pid=$no_pid
  30. ecdh_wolfssl_pid=$no_pid
  31. ecdsa_wolfssl_pid=$no_pid
  32. ed25519_wolfssl_pid=$no_pid
  33. ed448_wolfssl_pid=$no_pid
  34. tls13_psk_wolfssl_pid=$no_pid
  35. anon_wolfssl_pid=$no_pid
  36. wolf_cases_tested=0
  37. wolf_cases_total=0
  38. counter=0
  39. testing_summary="OpenSSL Interop Testing Summary:\nVersion\tTested\t#Found\t#wolf\t#Found\t#OpenSSL\n"
  40. versionName="Invalid"
  41. if [ "$OPENSSL" = "" ]; then
  42. OPENSSL=openssl
  43. fi
  44. WOLFSSL_SERVER=./examples/server/server
  45. WOLFSSL_CLIENT=./examples/client/client
  46. version_name() {
  47. case $version in "0")
  48. versionName="SSLv3"
  49. ;;
  50. "1")
  51. versionName="TLSv1"
  52. ;;
  53. "2")
  54. versionName="TLSv1.1"
  55. ;;
  56. "3")
  57. versionName="TLSv1.2"
  58. ;;
  59. "4")
  60. versionName="TLSv1.3"
  61. ;;
  62. "d")
  63. versionName="Down"
  64. ;;
  65. "")
  66. versionName="Def"
  67. ;;
  68. "5")
  69. versionName="ALL"
  70. ;;
  71. esac
  72. }
  73. do_cleanup() {
  74. echo "in cleanup"
  75. IFS=$OIFS #restore separator
  76. for s in $servers
  77. do
  78. f2=${s%:*}
  79. sname=${f2%:*}
  80. pid=${f2##*:}
  81. port=${s##*:}
  82. echo "killing server: $sname ($port)"
  83. kill -9 $pid
  84. done
  85. }
  86. do_trap() {
  87. echo "got trap"
  88. do_cleanup
  89. exit 1
  90. }
  91. trap do_trap INT TERM
  92. check_process_running() {
  93. if [ "$ps_grep" = "" ]
  94. then
  95. ps -p $server_pid > /dev/null
  96. PS_EXIT=$?
  97. else
  98. ps | grep "^ *$server_pid " > /dev/null
  99. PS_EXIT=$?
  100. fi
  101. }
  102. #
  103. # Start an OpenSSL server
  104. #
  105. start_openssl_server() {
  106. if [ "$wolfssl_client_avail" = "" ]
  107. then
  108. return
  109. fi
  110. generate_port
  111. server_port=$port
  112. found_free_port=0
  113. counter=0
  114. while [ "$counter" -lt 20 ]; do
  115. echo -e "\n# Trying to start $openssl_suite OpenSSL server on port $server_port..."
  116. echo "#"
  117. if [ "$cert_file" != "" ]
  118. then
  119. echo "# " $OPENSSL s_server -accept $server_port -cert $cert_file -key $key_file -quiet -CAfile $ca_file -www -dhparam ./certs/dh2048.pem -verify 10 -verify_return_error -psk $psk_hex -cipher "ALL:eNULL"
  120. $OPENSSL s_server -accept $server_port -cert $cert_file -key $key_file -quiet -CAfile $ca_file -www -dhparam ./certs/dh2048.pem -verify 10 -verify_return_error -psk $psk_hex -cipher "ALL:eNULL" &
  121. else
  122. echo "# " $OPENSSL s_server -accept $server_port -quiet -nocert -www -dhparam ./certs/dh2048.pem -verify 10 -verify_return_error -psk $psk_hex -cipher "ALL:eNULL"
  123. $OPENSSL s_server -accept $server_port -quiet -nocert -www -dhparam ./certs/dh2048.pem -verify 10 -verify_return_error -psk $psk_hex -cipher "ALL:eNULL" &
  124. fi
  125. server_pid=$!
  126. # wait to see if s_server successfully starts before continuing
  127. sleep 0.1
  128. check_process_running
  129. if [ "$PS_EXIT" = "0" ]
  130. then
  131. echo "s_server started successfully on port $server_port"
  132. found_free_port=1
  133. break
  134. else
  135. #port already started, try a different port
  136. counter=$((counter+ 1))
  137. generate_port
  138. server_port=$port
  139. fi
  140. done
  141. if [ $found_free_port = 0 ]
  142. then
  143. echo -e "Couldn't find free port for server"
  144. do_cleanup
  145. exit 1
  146. fi
  147. servers="$servers OpenSSL_$openssl_suite:$server_pid:$server_port"
  148. }
  149. #
  150. # Start a wolfSSL server
  151. #
  152. start_wolfssl_server() {
  153. if [ "$wolfssl_server_avail" = "" ]
  154. then
  155. echo "# wolfSSL server not available"
  156. return
  157. fi
  158. wolfssl_cert=""
  159. wolfssl_key=""
  160. wolfssl_caCert=""
  161. if [ "$cert_file" != "" ]
  162. then
  163. wolfssl_cert="-c$cert_file"
  164. fi
  165. if [ "$key_file" != "" ]
  166. then
  167. wolfssl_key="-k$key_file"
  168. fi
  169. if [ "$ca_file" != "" ]
  170. then
  171. wolfssl_caCert="-A$ca_file"
  172. fi
  173. generate_port
  174. server_port=$port
  175. found_free_port=0
  176. counter=0
  177. while [ "$counter" -lt 20 ]; do
  178. echo -e "\n# Trying to start $wolfssl_suite wolfSSL server on port $server_port..."
  179. echo "#"
  180. echo "# $WOLFSSL_SERVER -p $server_port $wolfssl_cert $wolfssl_key $wolfssl_caCert -g -v d -x -i $psk $crl -l ALL"
  181. $WOLFSSL_SERVER -p $server_port $wolfssl_cert $wolfssl_key $wolfssl_caCert -g -v d -x -i $psk $crl -l ALL &
  182. server_pid=$!
  183. # wait to see if s_server successfully starts before continuing
  184. sleep 0.1
  185. check_process_running
  186. if [ "$PS_EXIT" = "0" ]
  187. then
  188. echo "wolfSSL server started successfully on port $server_port"
  189. found_free_port=1
  190. break
  191. else
  192. #port already started, try a different port
  193. counter=$((counter+ 1))
  194. generate_port
  195. server_port=$port
  196. fi
  197. done
  198. if [ $found_free_port = 0 ]
  199. then
  200. echo -e "Couldn't find free port for server"
  201. do_cleanup
  202. exit 1
  203. fi
  204. servers="$servers wolfSSL_$wolfssl_suite:$server_pid:$server_port"
  205. }
  206. check_server_ready() {
  207. # server should be ready, let's make sure
  208. server_ready=0
  209. while [ "$counter" -lt 20 ]; do
  210. echo -e "waiting for $server_name ready..."
  211. echo -e Checking | nc localhost $server_port
  212. nc_result=$?
  213. if [ $nc_result = 0 ]
  214. then
  215. echo -e "$server_name ready!"
  216. server_ready=1
  217. break
  218. fi
  219. sleep 0.1
  220. counter=$((counter+ 1))
  221. done
  222. if [ $server_ready = 0 ]
  223. then
  224. echo -e "Couldn't verify $server_name is running, timeout error"
  225. do_cleanup
  226. exit 1
  227. fi
  228. }
  229. #
  230. # Run wolfSSL client against OpenSSL server
  231. #
  232. do_wolfssl_client() {
  233. if [ "$wolfssl_client_avail" = "" ]
  234. then
  235. return
  236. fi
  237. wolfssl_cert=""
  238. wolfssl_key=""
  239. wolfssl_caCert=""
  240. if [ "$cert" != "" ]
  241. then
  242. wolfssl_cert="-c$cert"
  243. fi
  244. if [ "$key" != "" ]
  245. then
  246. wolfssl_key="-k$key"
  247. fi
  248. if [ "$caCert" != "" ]
  249. then
  250. wolfssl_caCert="-A$caCert"
  251. fi
  252. wolfssl_resume="-r"
  253. if [ "$openssl_psk_resume_bug" != "" -a "$tls13_suite" != "" ]
  254. then
  255. wolfssl_resume=
  256. fi
  257. if [ "$version" != "5" -a "$version" != "" ]
  258. then
  259. echo "#"
  260. echo "# $WOLFSSL_CLIENT -p $port -g $wolfssl_resume -l $wolfSuite -v $version $psk $adh $wolfssl_cert $wolfssl_key $wolfssl_caCert $crl"
  261. $WOLFSSL_CLIENT -p $port -g $wolfssl_resume -l $wolfSuite -v $version $psk $adh $wolfssl_cert $wolfssl_key $wolfssl_caCert $crl
  262. else
  263. echo "#"
  264. echo "# $WOLFSSL_CLIENT -p $port -g $wolfssl_resume -l $wolfSuite $psk $adh $wolfssl_cert $wolfssl_key $wolfssl_caCert $crl"
  265. # do all versions
  266. $WOLFSSL_CLIENT -p $port -g $wolfssl_resume -l $wolfSuite $psk $adh $wolfssl_cert $wolfssl_key $wolfssl_caCert $crl
  267. fi
  268. client_result=$?
  269. if [ $client_result != 0 ]
  270. then
  271. echo -e "client failed! Suite = $wolfSuite version = $version"
  272. do_cleanup
  273. exit 1
  274. fi
  275. wolf_temp_cases_tested=$((wolf_temp_cases_tested+1))
  276. }
  277. #
  278. # Run OpenSSL client against wolfSSL server
  279. #
  280. do_openssl_client() {
  281. if [ "$wolfssl_server_avail" = "" ]
  282. then
  283. return
  284. fi
  285. if [ "$version" = "" -o "$version" = "5" ]
  286. then
  287. if [ "$tls13_cipher" = "" -a "$openssl_tls13" != "" ]
  288. then
  289. openssl_version="-no_tls1_3"
  290. fi
  291. fi
  292. if [ "$cert" != "" ]
  293. then
  294. openssl_cert1="-cert"
  295. openssl_cert2="$cert"
  296. fi
  297. if [ "$key" != "" ]
  298. then
  299. openssl_key1="-key"
  300. openssl_key2="$key"
  301. fi
  302. if [ "$caCert" != "" ]
  303. then
  304. openssl_caCert1="-CAfile"
  305. openssl_caCert2="$caCert"
  306. fi
  307. if [ "$tls13_cipher" = "" ]
  308. then
  309. echo "#"
  310. echo "# $OPENSSL s_client -connect localhost:$port -reconnect -cipher $cmpSuite $openssl_version $openssl_psk $openssl_cert1 $openssl_cert2 $openssl_key1 $openssl_key2 $openssl_caCert1 $openssl_caCert2"
  311. echo "Hello" | eval "$OPENSSL s_client -connect localhost:$port -reconnect -cipher $cmpSuite $openssl_version $openssl_psk $openssl_cert1 $openssl_cert2 $openssl_key1 $openssl_key2 $openssl_caCert1 $openssl_caCert2"
  312. else
  313. echo "#"
  314. echo "# $OPENSSL s_client -connect localhost:$port -reconnect -ciphersuites=$cmpSuite $openssl_version $openssl_psk $openssl_cert1 $openssl_cert2 $openssl_key1 $openssl_key2 $openssl_caCert1 $openssl_caCert2"
  315. echo "Hello" | eval "$OPENSSL s_client -connect localhost:$port -reconnect -ciphersuites=$cmpSuite $openssl_version $openssl_psk $openssl_cert1 $openssl_cert2 $openssl_key1 $openssl_key2 $openssl_caCert1 $openssl_caCert2"
  316. fi
  317. client_result=$?
  318. if [ $client_result != 0 ]
  319. then
  320. echo -e "client failed! Suite = $wolfSuite version = $version"
  321. do_cleanup
  322. exit 1
  323. fi
  324. open_temp_cases_tested=$((open_temp_cases_tested+1))
  325. }
  326. OIFS=$IFS # store old separator to reset
  327. #
  328. # Start
  329. #
  330. ps -p $PPID >/dev/null 2>&1
  331. if [ "$?" = "1" ]
  332. then
  333. ps_grep="yes"
  334. echo "ps -p not working, using ps and grep"
  335. fi
  336. echo -e "\nTesting existence of openssl command...\n"
  337. command -v $OPENSSL >/dev/null 2>&1 || { echo >&2 "Requires openssl command, but it's not installed. Ending."; do_cleanup; exit 0; }
  338. echo -e "\nTesting for _build directory as part of distcheck, different paths"
  339. currentDir=`pwd`
  340. if [ $currentDir = *"_build" ]
  341. then
  342. echo -e "_build directory detected, moving a directory back"
  343. cd ..
  344. fi
  345. echo -e "\nChecking for wolfSSL client - needed for cipher list"
  346. wolfssl_client_avail=`$WOLFSSL_CLIENT -?`
  347. case $wolfssl_client_avail in
  348. *"Client not compiled in!"*)
  349. wolfssl_client_avail=
  350. echo >&2 "Requires wolfSSL client, but it's not built. Ending."
  351. do_cleanup
  352. exit 0
  353. ;;
  354. esac
  355. echo -e "\nTesting for buggy version of OpenSSL - TLS 1.3, PSK and session ticket"
  356. openssl_version=`$OPENSSL version`
  357. case $openssl_version in
  358. "OpenSSL 1.1.1 "*)
  359. openssl_psk_resume_bug=yes
  360. ;;
  361. "OpenSSL 1.0.2"*)
  362. openssl_adh_reneg_bug=yes
  363. ;;
  364. esac
  365. # check for wolfssl server
  366. wolfssl_server_avail=`$WOLFSSL_SERVER -?`
  367. case $wolfssl_server_avail in
  368. *"Server not compiled in!"*)
  369. wolfssl_server_avail=
  370. ;;
  371. esac
  372. # get wolfssl ciphers
  373. wolf_ciphers=`$WOLFSSL_CLIENT -e`
  374. # get wolfssl supported versions
  375. wolf_versions=`$WOLFSSL_CLIENT -V`
  376. wolf_versions="$wolf_versions:5" #5 will test without -v flag
  377. OIFS=$IFS # store old separator to reset
  378. IFS=$'\:' # set delimiter
  379. for version in $wolf_versions
  380. do
  381. case $version in
  382. 1|2|3)
  383. wolf_tls=yes
  384. ;;
  385. 4)
  386. wolf_tls13=yes
  387. ;;
  388. esac
  389. done
  390. IFS=$OIFS #restore separator
  391. #
  392. # Start OpenSSL servers
  393. #
  394. # Check if ECC certificates supported in wolfSSL
  395. wolf_ecc=`$WOLFSSL_CLIENT -A ./certs/ed25519/ca-ecc-cert.pem 2>&1`
  396. case $wolf_ecc in
  397. *"ca file"*)
  398. wolf_ecc=""
  399. ;;
  400. *)
  401. ;;
  402. esac
  403. # Check if Ed25519 certificates supported in wolfSSL
  404. wolf_ed25519=`$WOLFSSL_CLIENT -A ./certs/ed25519/root-ed25519.pem 2>&1`
  405. case $wolf_ed25519 in
  406. *"ca file"*)
  407. wolf_ed25519=""
  408. ;;
  409. *)
  410. ;;
  411. esac
  412. # Check if Ed25519 certificates supported in OpenSSL
  413. openssl_ed25519=`$OPENSSL s_client -cert ./certs/ed25519/client-ed25519.pem -key ./certs/ed25519/client-ed25519-priv.pem 2>&1`
  414. case $openssl_ed25519 in
  415. *"unable to load"*)
  416. wolf_ed25519=""
  417. ;;
  418. *)
  419. ;;
  420. esac
  421. # Check if Ed448 certificates supported in wolfSSL
  422. wolf_ed448=`$WOLFSSL_CLIENT -A ./certs/ed448/root-ed448.pem 2>&1`
  423. case $wolf_ed448 in
  424. *"ca file"*)
  425. wolf_ed448=""
  426. ;;
  427. *)
  428. ;;
  429. esac
  430. # Check if Ed448 certificates supported in OpenSSL
  431. openssl_ed448=`$OPENSSL s_client -cert ./certs/ed448/client-ed448.pem -key ./certs/ed448/client-ed448-priv.pem 2>&1`
  432. case $openssl_ed448 in
  433. *"unable to load"*)
  434. wolf_ed448=""
  435. ;;
  436. *)
  437. ;;
  438. esac
  439. openssl_tls13=`$OPENSSL s_client -help 2>&1`
  440. case $openssl_tls13 in
  441. *no_tls1_3*)
  442. ;;
  443. *)
  444. openssl_tls13=
  445. ;;
  446. esac
  447. # Check suites to determine support in wolfSSL
  448. OIFS=$IFS # store old separator to reset
  449. IFS=$'\:' # set delimiter
  450. for wolfSuite in $wolf_ciphers; do
  451. case $wolfSuite in
  452. *ECDHE-RSA-*)
  453. ecdhe_avail=yes
  454. wolf_rsa=yes
  455. ;;
  456. *DHE-RSA-*)
  457. wolf_rsa=yes
  458. ;;
  459. *ECDH-RSA*)
  460. wolf_ecdh_rsa=yes
  461. ;;
  462. *ECDHE-ECDSA*|*ECDH-ECDSA*)
  463. wolf_ecdsa=yes
  464. ;;
  465. *ADH*)
  466. wolf_anon=yes
  467. ;;
  468. *PSK*)
  469. if [ "$wolf_psk" = "" ]
  470. then
  471. echo "Testing PSK"
  472. wolf_psk=1
  473. fi
  474. if [ "$wolf_tls" != "" ]
  475. then
  476. wolf_tls_psk=yes
  477. fi
  478. ;;
  479. *TLS13*)
  480. ;;
  481. *)
  482. wolf_rsa=yes
  483. esac
  484. done
  485. IFS=$OIFS #restore separator
  486. openssl_ciphers=`$OPENSSL ciphers ALL 2>&1`
  487. case $openssl_ciphers in
  488. *ADH*)
  489. openssl_anon=yes
  490. ;;
  491. esac
  492. # TLSv1 -> TLSv1.2 PSK secret
  493. psk_hex="1a2b3c4d"
  494. # If RSA cipher suites supported in wolfSSL then start servers
  495. if [ "$wolf_rsa" != "" -o "$wolf_tls_psk" != "" ]
  496. then
  497. if [ "$wolf_rsa" != "" ]
  498. then
  499. cert_file="./certs/server-cert.pem"
  500. key_file="./certs/server-key.pem"
  501. ca_file="./certs/client-ca.pem"
  502. else
  503. cert_file=
  504. key_file=
  505. ca_file=
  506. fi
  507. openssl_suite="RSA"
  508. start_openssl_server
  509. openssl_port=$server_port
  510. openssl_pid=$server_pid
  511. wolfssl_suite="RSA"
  512. if [ "$wolf_tls_psk" != "" ]
  513. then
  514. psk="-j"
  515. fi
  516. echo "cert_file=$cert_file"
  517. start_wolfssl_server
  518. psk=
  519. wolfssl_port=$server_port
  520. wolfssl_pid=$server_pid
  521. fi
  522. # If ECDH-RSA cipher suites supported in wolfSSL then start servers
  523. if [ "$wolf_ecdh_rsa" != "" ]
  524. then
  525. cert_file="./certs/server-ecc-rsa.pem"
  526. key_file="./certs/ecc-key.pem"
  527. ca_file="./certs/client-ca.pem"
  528. openssl_suite="ECDH-RSA"
  529. start_openssl_server
  530. ecdh_openssl_port=$server_port
  531. ecdh_openssl_pid=$server_pid
  532. wolfssl_suite="ECDH-RSA"
  533. start_wolfssl_server
  534. ecdh_wolfssl_port=$server_port
  535. ecdh_wolfssl_pid=$server_pid
  536. fi
  537. if [ "$wolf_ecdsa" != "" -a "$wolf_ecc" != "" ]
  538. then
  539. cert_file="./certs/server-ecc.pem"
  540. key_file="./certs/ecc-key.pem"
  541. ca_file="./certs/client-ca.pem"
  542. openssl_suite="ECDH[E]-ECDSA"
  543. start_openssl_server
  544. ecdsa_openssl_port=$server_port
  545. ecdsa_openssl_pid=$server_pid
  546. wolfssl_suite="ECDH[E]-ECDSA"
  547. start_wolfssl_server
  548. ecdsa_wolfssl_port=$server_port
  549. ecdsa_wolfssl_pid=$server_pid
  550. fi
  551. # If Ed25519 certificates supported in wolfSSL then start servers
  552. if [ "$wolf_ed25519" != "" ];
  553. then
  554. cert_file="./certs/ed25519/server-ed25519.pem"
  555. key_file="./certs/ed25519/server-ed25519-priv.pem"
  556. ca_file="./certs/ed25519/root-ed25519.pem"
  557. openssl_suite="Ed25519"
  558. start_openssl_server
  559. ed25519_openssl_port=$server_port
  560. ed25519_openssl_pid=$server_pid
  561. crl="-V"
  562. wolfssl_suite="Ed25519"
  563. start_wolfssl_server
  564. ed25519_wolfssl_port=$server_port
  565. ed25519_wolfssl_pid=$server_pid
  566. crl=
  567. fi
  568. # If Ed448 certificates supported in wolfSSL then start servers
  569. if [ "$wolf_ed448" != "" ];
  570. then
  571. cert_file="./certs/ed448/server-ed448.pem"
  572. key_file="./certs/ed448/server-ed448-priv.pem"
  573. ca_file="./certs/ed448/client-ed448.pem"
  574. openssl_suite="Ed448"
  575. start_openssl_server
  576. ed448_openssl_port=$server_port
  577. ed448_openssl_pid=$server_pid
  578. crl="-V"
  579. wolfssl_suite="Ed448"
  580. start_wolfssl_server
  581. ed448_wolfssl_port=$server_port
  582. ed448_wolfssl_pid=$server_pid
  583. crl=
  584. fi
  585. if [ "$wolf_tls13" != "" -a "$wolf_psk" != "" ]
  586. then
  587. cert_file="./certs/server-cert.pem"
  588. key_file="./certs/server-key.pem"
  589. psk_hex="0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
  590. openssl_suite="TLSv1.3_PSK"
  591. start_openssl_server
  592. tls13_psk_openssl_port=$server_port
  593. tls13_psk_openssl_pid=$server_pid
  594. psk="-s"
  595. wolfssl_suite="TLSv1.3_PSK"
  596. start_wolfssl_server
  597. tls13_psk_wolfssl_port=$server_port
  598. tls13_psk_wolfssl_pid=$server_pid
  599. fi
  600. if [ "$wolf_anon" != "" -a "$openssl_anon" ]
  601. then
  602. cert_file=""
  603. key_file=""
  604. ca_file=""
  605. wolfssl_suite="Anon"
  606. psk="-a" # anonymous not psk
  607. start_wolfssl_server
  608. anon_wolfssl_port=$server_port
  609. anon_wolfssl_pid=$server_pid
  610. fi
  611. for s in $servers
  612. do
  613. f2=${s%:*}
  614. server_name=${f2%:*}
  615. server_port=${s##*:}
  616. check_server_ready
  617. done
  618. OIFS=$IFS # store old separator to reset
  619. IFS=$'\:' # set delimiter
  620. set -f # no globbing
  621. wolf_temp_cases_total=0
  622. wolf_temp_cases_tested=0
  623. # Testing of OpenSSL support for version requires a running OpenSSL server
  624. for version in $wolf_versions;
  625. do
  626. echo -e "version = $version"
  627. # get openssl ciphers depending on version
  628. # -s flag for only supported ciphers
  629. case $version in
  630. "0")
  631. openssl_ciphers=`$OPENSSL ciphers "SSLv3" 2>&1`
  632. # double check that can actually do a sslv3 connection using
  633. # client-cert.pem to send but any file with EOF works
  634. $OPENSSL s_client -ssl3 -no_ign_eof -host localhost -port $openssl_port < ./certs/client-cert.pem
  635. sslv3_sup=$?
  636. if [ $sslv3_sup != 0 ]
  637. then
  638. echo -e "Not testing SSLv3. No OpenSSL support for 'SSLv3' modifier"
  639. testing_summary="${testing_summary}SSLv3\tNo\tN/A\tN/A\tN/A\tN/A\t (No OpenSSL cipherstring)\n"
  640. continue
  641. fi
  642. openssl_version="-ssl3"
  643. ;;
  644. "1")
  645. proto_check=`echo "hell" | $OPENSSL s_client -connect localhost:$openssl_port -tls1 2>&1`
  646. tlsv1_sup=$?
  647. if [ $tlsv1_sup != 0 ]
  648. then
  649. echo -e "Not testing TLSv1. No OpenSSL support for '-tls1'"
  650. testing_summary="${testing_summary}TLSv1\tNo\tN/A\tN/A\tN/A\tN/A\t (No OpenSSL Support)\n"
  651. continue
  652. fi
  653. openssl_ciphers=`$OPENSSL ciphers -s "TLSv1" 2>&1`
  654. tlsv1_sup=$?
  655. if [ $tlsv1_sup != 0 ]
  656. then
  657. echo -e "Not testing TLSv1. No OpenSSL support for 'TLSv1' modifier"
  658. testing_summary="${testing_summary}TLSv1\tNo\tN/A\tN/A\tN/A\tN/A\t (No OpenSSL cipherstring)\n"
  659. continue
  660. fi
  661. openssl_version="-tls1"
  662. ;;
  663. "2")
  664. # Same ciphers for TLSv1.1 as TLSv1
  665. proto_check=`echo "hello" | $OPENSSL s_client -connect localhost:$openssl_port -tls1_1 2>&1`
  666. tlsv1_1_sup=$?
  667. if [ $tlsv1_1_sup != 0 ]
  668. then
  669. echo -e "Not testing TLSv1.1. No OpenSSL support for 'TLSv1.1' modifier"
  670. testing_summary="${testing_summary}TLSv1.1\tNo\tN/A\tN/A\tN/A\tN/A\t (No OpenSSL cipherstring)\n"
  671. continue
  672. fi
  673. openssl_ciphers=`$OPENSSL ciphers -s "TLSv1" 2>&1`
  674. tlsv1_sup=$?
  675. if [ $tlsv1_sup != 0 ]
  676. then
  677. echo -e "Not testing TLSv1. No OpenSSL support for 'TLSv1' modifier"
  678. testing_summary="${testing_summary}TLSv1\tNo\tN/A\tN/A\tN/A\tN/A\t (No OpenSSL cipherstring)\n"
  679. continue
  680. fi
  681. openssl_version="-tls1_1"
  682. ;;
  683. "3")
  684. openssl_ciphers=`$OPENSSL ciphers -s "TLSv1.2" 2>&1`
  685. tlsv1_2_sup=$?
  686. if [ $tlsv1_2_sup != 0 ]
  687. then
  688. echo -e "Not testing TLSv1.2. No OpenSSL support for 'TLSv1.2' modifier"
  689. testing_summary="${testing_summary}TLSv1.2\tNo\tN/A\tN/A\tN/A\tN/A\t (No OpenSSL cipherstring)\n"
  690. continue
  691. fi
  692. openssl_version="-tls1_2"
  693. ;;
  694. "4")
  695. openssl_ciphers=`$OPENSSL ciphers -tls1_3 2>&1`
  696. tlsv1_3_sup=$?
  697. if [ $tlsv1_3_sup != 0 ]
  698. then
  699. echo -e "Not testing TLSv1.3. No OpenSSL support for 'TLSv1.3' modifier"
  700. testing_summary="${testing_summary}TLSv1.3\tNo\tN/A\tN/A\tN/A\tN/A\t (No OpenSSL cipherstring)\n"
  701. continue
  702. fi
  703. ecc_support=`$WOLFSSL_CLIENT -? 2>&1 | grep 'ECC named groups'`
  704. openssl_version="-tls1_3"
  705. ;;
  706. "d(downgrade)")
  707. version="d"
  708. openssl_version=""
  709. ;;
  710. "e(either)")
  711. continue
  712. ;;
  713. "5") #test all suites
  714. openssl_ciphers=`$OPENSSL ciphers -s "ALL" 2>&1`
  715. all_sup=$?
  716. if [ $all_sup != 0 ]
  717. then
  718. echo -e "Not testing ALL. No OpenSSL support for ALL modifier"
  719. testing_summary="${testing_summary}ALL\tNo\tN/A\tN/A\tN/A\tN/A\t (No OpenSSL cipherstring)\n"
  720. continue
  721. fi
  722. openssl_version=""
  723. ;;
  724. "")
  725. openssl_ciphers=`$OPENSSL ciphers 2>&1`
  726. all_sup=$?
  727. if [ $all_sup != 0 ]
  728. then
  729. echo -e "Not testing ALL. No OpenSSL support for ALL modifier"
  730. testing_summary="${testing_summary}ALL\tNo\tN/A\tN/A\tN/A\tN/A\t (No OpenSSL cipherstring)\n"
  731. continue
  732. fi
  733. openssl_version=""
  734. ;;
  735. esac
  736. for wolfSuite in $wolf_ciphers; do
  737. echo -e "trying wolfSSL cipher suite $wolfSuite"
  738. wolf_temp_cases_total=$((wolf_temp_cases_total + 1))
  739. open_temp_cases_total=$((open_temp_cases_total + 1))
  740. matchSuite=0;
  741. tls13_suite=
  742. case $wolfSuite in
  743. "TLS13-AES128-GCM-SHA256")
  744. cmpSuite="TLS_AES_128_GCM_SHA256"
  745. tls13_suite="yes"
  746. ;;
  747. "TLS13-AES256-GCM-SHA384")
  748. cmpSuite="TLS_AES_256_GCM_SHA384"
  749. tls13_suite="yes"
  750. ;;
  751. "TLS13-CHACHA20-POLY1305-SHA256")
  752. cmpSuite="TLS_CHACHA20_POLY1305_SHA256"
  753. tls13_suite="yes"
  754. ;;
  755. "TLS13-AES128-CCM-SHA256")
  756. cmpSuite="TLS_AES_128_CCM_SHA256"
  757. tls13_suite="yes"
  758. ;;
  759. "TLS13-AES128-CCM-8-SHA256")
  760. cmpSuite="TLS_AES_128_CCM_8_SHA256"
  761. tls13_suite="yes"
  762. ;;
  763. "TLS13-SHA256-SHA256")
  764. continue
  765. ;;
  766. "TLS13-SHA384-SHA384")
  767. continue
  768. ;;
  769. "TLS13-"*)
  770. echo -e "Suite = $wolfSuite not recognized!"
  771. echo -e "Add translation of wolfSSL name to OpenSSL"
  772. do_cleanup
  773. exit 1
  774. ;;
  775. *)
  776. cmpSuite=$wolfSuite
  777. ;;
  778. esac
  779. case ":$openssl_ciphers:" in *":$cmpSuite:"*) # add extra : for edge cases
  780. case "$cmpSuite" in
  781. "TLS_"*)
  782. if [ "$version" != "4" -a "$version" != "d" ]
  783. then
  784. echo -e "TLS 1.3 cipher suite but not TLS 1.3 protocol"
  785. matchSuite=0
  786. else
  787. echo -e "Matched to OpenSSL suite support"
  788. matchSuite=1
  789. fi
  790. ;;
  791. *)
  792. if [ "$version" = "d" -a "$wolfdowngrade" = "4" ]
  793. then
  794. echo -e "Not TLS 1.3 cipher suite but TLS 1.3 downgrade"
  795. matchSuite=0
  796. elif [ "$version" != "4" ]
  797. then
  798. echo -e "Matched to OpenSSL suite support"
  799. matchSuite=1
  800. else
  801. echo -e "Not TLS 1.3 cipher suite but TLS 1.3 protocol"
  802. matchSuite=0
  803. fi
  804. ;;
  805. esac
  806. ;;
  807. esac
  808. if [ $matchSuite = 0 ]
  809. then
  810. echo -e "Couldn't match suite, continuing..."
  811. continue
  812. fi
  813. # check for psk suite and turn on client psk if so
  814. psk=""
  815. adh=""
  816. crl=""
  817. cert=""
  818. key=""
  819. caCert=""
  820. case $wolfSuite in
  821. *ECDH-RSA*)
  822. cert="./certs/client-cert.pem"
  823. key="./certs/client-key.pem"
  824. caCert="./certs/ca-cert.pem"
  825. port=$ecdh_openssl_port
  826. do_wolfssl_client
  827. port=$ecdh_wolfssl_port
  828. do_openssl_client
  829. ;;
  830. *ECDHE-ECDSA*|*ECDH-ECDSA*)
  831. if [ "$wolf_ecc" != "" ]
  832. then
  833. cert="./certs/client-cert.pem"
  834. key="./certs/client-key.pem"
  835. caCert="./certs/ca-ecc-cert.pem"
  836. port=$ecdsa_openssl_port
  837. do_wolfssl_client
  838. port=$ecdsa_wolfssl_port
  839. do_openssl_client
  840. else
  841. wolf_temp_cases_total=$((wolf_temp_cases_total - 1))
  842. fi
  843. if [ $ed25519_openssl_pid != $no_pid -a "$version" != "0" -a "$version" != "1" -a "$version" != "2" ]
  844. then
  845. cert="./certs/ed25519/server-ed25519.pem"
  846. key="./certs/ed25519/server-ed25519-priv.pem"
  847. caCert="./certs/ed25519/server-ed25519.pem"
  848. wolf_temp_cases_total=$((wolf_temp_cases_total + 1))
  849. port=$ed25519_openssl_port
  850. crl="-C"
  851. do_wolfssl_client
  852. open_temp_cases_total=$((open_temp_cases_total + 1))
  853. port=$ed25519_wolfssl_port
  854. do_openssl_client
  855. fi
  856. if [ $ed448_openssl_pid != $no_pid -a "$version" != "0" -a "$version" != "1" -a "$version" != "2" ]
  857. then
  858. cert="./certs/ed448/client-ed448.pem"
  859. key="./certs/ed448/client-ed448-priv.pem"
  860. caCert="./certs/ed448/server-ed448.pem"
  861. wolf_temp_cases_total=$((wolf_temp_cases_total + 1))
  862. port=$ed448_openssl_port
  863. crl="-C"
  864. do_wolfssl_client
  865. open_temp_cases_total=$((open_temp_cases_total + 1))
  866. port=$ed448_wolfssl_port
  867. do_openssl_client
  868. fi
  869. ;;
  870. *DHE-PSK*)
  871. cert="./certs/client-cert.pem"
  872. key="./certs/client-key.pem"
  873. caCert="./certs/ca-cert.pem"
  874. port=$openssl_port
  875. psk="-s"
  876. do_wolfssl_client
  877. # Skip when no RSA as some versions of OpenSSL can't handle no
  878. # signature
  879. if [ "$wolf_rsa" != "" ]
  880. then
  881. port=$wolfssl_port
  882. openssl_psk="-psk=1a2b3c4d"
  883. do_openssl_client
  884. fi
  885. ;;
  886. *PSK*)
  887. cert="./certs/client-cert.pem"
  888. key="./certs/client-key.pem"
  889. caCert="./certs/ca-cert.pem"
  890. port=$openssl_port
  891. psk="-s"
  892. do_wolfssl_client
  893. port=$wolfssl_port
  894. openssl_psk="-psk=1a2b3c4d"
  895. do_openssl_client
  896. ;;
  897. *ADH*)
  898. cert="./certs/client-cert.pem"
  899. key="./certs/client-key.pem"
  900. caCert="./certs/ca-cert.pem"
  901. if [ "$version" != "0" -a "$version" != "1" -a "$version" != "2" -a "$openssl_adh_reneg_bug" != "" ]
  902. then
  903. continue
  904. fi
  905. port=$openssl_port
  906. adh="-a"
  907. do_wolfssl_client
  908. port=$anon_wolfssl_port
  909. do_openssl_client
  910. ;;
  911. TLS13*)
  912. if [ $version != "4" -a $version != "d" -a $version != " " -a $version != "5" ]
  913. then
  914. continue
  915. fi
  916. tls13_cipher=yes
  917. # RSA
  918. if [ $openssl_pid != $no_pid -a "$ecdhe_avail" = "yes" ]
  919. then
  920. cert="./certs/client-cert.pem"
  921. key="./certs/client-key.pem"
  922. caCert="./certs/ca-cert.pem"
  923. port=$openssl_port
  924. do_wolfssl_client
  925. port=$wolfssl_port
  926. do_openssl_client
  927. fi
  928. # PSK
  929. if [ "$wolf_psk" != "" -a $wolfSuite = "TLS13-AES128-GCM-SHA256" ]
  930. then
  931. cert="./certs/client-cert.pem"
  932. key="./certs/client-key.pem"
  933. caCert="./certs/ca-cert.pem"
  934. wolf_temp_cases_total=$((wolf_temp_cases_total + 1))
  935. port=$tls13_psk_openssl_port
  936. psk="-s"
  937. do_wolfssl_client
  938. psk=""
  939. openssl_psk="-psk=0123456789abcdef0123456789abcdef"
  940. open_temp_cases_total=$((open_temp_cases_total + 1))
  941. port=$wolfssl_port
  942. do_openssl_client
  943. open_temp_cases_total=$((open_temp_cases_total + 1))
  944. port=$tls13_psk_wolfssl_port
  945. do_openssl_client
  946. openssl_psk=""
  947. fi
  948. # ECDSA
  949. if [ $ecdsa_openssl_pid != $no_pid -a "$wolf_ecc" != "" ]
  950. then
  951. cert="./certs/client-ecc-cert.pem"
  952. key="./certs/ecc-client-key.pem"
  953. caCert="./certs/ca-ecc-cert.pem"
  954. wolf_temp_cases_total=$((wolf_temp_cases_total + 1))
  955. port=$ecdsa_openssl_port
  956. caCert="./certs/ca-ecc-cert.pem"
  957. do_wolfssl_client
  958. open_temp_cases_total=$((open_temp_cases_total + 1))
  959. port=$ecdsa_wolfssl_port
  960. caCert="./certs/ca-ecc-cert.pem"
  961. do_openssl_client
  962. fi
  963. # Ed25519
  964. if [ $ed25519_openssl_pid != $no_pid ]
  965. then
  966. cert="./certs/ed25519/server-ed25519.pem"
  967. key="./certs/ed25519/server-ed25519-priv.pem"
  968. caCert="./certs/ed25519/server-ed25519.pem"
  969. wolf_temp_cases_total=$((wolf_temp_cases_total + 1))
  970. port=$ed25519_openssl_port
  971. crl="-C"
  972. do_wolfssl_client
  973. open_temp_cases_total=$((open_temp_cases_total + 1))
  974. port=$ed25519_wolfssl_port
  975. do_openssl_client
  976. fi
  977. # Ed448
  978. if [ $ed448_openssl_pid != $no_pid ]
  979. then
  980. cert="./certs/ed448/client-ed448.pem"
  981. key="./certs/ed448/client-ed448-priv.pem"
  982. caCert="./certs/ed448/server-ed448.pem"
  983. wolf_temp_cases_total=$((wolf_temp_cases_total + 1))
  984. port=$ed448_openssl_port
  985. crl="-C"
  986. do_wolfssl_client
  987. open_temp_cases_total=$((open_temp_cases_total + 1))
  988. port=$ed448_wolfssl_port
  989. do_openssl_client
  990. fi
  991. tls13_cipher=
  992. ;;
  993. *)
  994. cert="./certs/client-cert.pem"
  995. key="./certs/client-key.pem"
  996. caCert="./certs/ca-cert.pem"
  997. port=$openssl_port
  998. do_wolfssl_client
  999. port=$wolfssl_port
  1000. do_openssl_client
  1001. ;;
  1002. esac
  1003. done
  1004. wolf_cases_tested=$((wolf_temp_cases_tested+wolf_cases_tested))
  1005. wolf_cases_total=$((wolf_temp_cases_total+wolf_cases_total))
  1006. echo -e "wolfSSL cases tested with version:$version $wolf_temp_cases_tested"
  1007. open_cases_tested=$((open_temp_cases_tested+open_cases_tested))
  1008. open_cases_total=$((open_temp_cases_total+open_cases_total))
  1009. echo -e "OpenSSL cases tested with version:$version $open_temp_cases_tested"
  1010. version_name
  1011. testing_summary="$testing_summary$versionName\tYes\t$wolf_temp_cases_total\t$wolf_temp_cases_tested\t$open_temp_cases_total\t$open_temp_cases_tested\n"
  1012. wolf_temp_cases_total=0
  1013. wolf_temp_cases_tested=0
  1014. open_temp_cases_total=0
  1015. open_temp_cases_tested=0
  1016. wolfdowngrade="$version"
  1017. done
  1018. IFS=$OIFS #restore separator
  1019. do_cleanup
  1020. echo -e "wolfSSL total cases $wolf_cases_total"
  1021. echo -e "wolfSSL cases tested $wolf_cases_tested"
  1022. echo -e "OpenSSL total cases $open_cases_total"
  1023. echo -e "OpenSSL cases tested $open_cases_tested"
  1024. echo -e "\nSuccess!\n\n\n\n"
  1025. echo -e "$testing_summary"
  1026. exit 0