testssl 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. #!/bin/sh
  2. if [ "$1" = "" ]; then
  3. key=../apps/server.pem
  4. else
  5. key="$1"
  6. fi
  7. if [ "$2" = "" ]; then
  8. cert=../apps/server.pem
  9. else
  10. cert="$2"
  11. fi
  12. ssltest="../util/shlib_wrap.sh ./ssltest -s_key $key -s_cert $cert -c_key $key -c_cert $cert"
  13. if ../util/shlib_wrap.sh ../apps/openssl x509 -in $cert -text -noout | fgrep 'DSA Public Key' >/dev/null; then
  14. dsa_cert=YES
  15. else
  16. dsa_cert=NO
  17. fi
  18. if [ "$3" = "" ]; then
  19. CA="-CApath ../certs"
  20. else
  21. CA="-CAfile $3"
  22. fi
  23. if [ "$4" = "" ]; then
  24. extra=""
  25. else
  26. extra="$4"
  27. fi
  28. serverinfo="./serverinfo.pem"
  29. #############################################################################
  30. echo test sslv3
  31. $ssltest -ssl3 $extra || exit 1
  32. echo test sslv3 with server authentication
  33. $ssltest -ssl3 -server_auth $CA $extra || exit 1
  34. echo test sslv3 with client authentication
  35. $ssltest -ssl3 -client_auth $CA $extra || exit 1
  36. echo test sslv3 with both client and server authentication
  37. $ssltest -ssl3 -server_auth -client_auth $CA $extra || exit 1
  38. echo test sslv2/sslv3
  39. $ssltest $extra || exit 1
  40. echo test sslv2/sslv3 with server authentication
  41. $ssltest -server_auth $CA $extra || exit 1
  42. echo test sslv2/sslv3 with client authentication
  43. $ssltest -client_auth $CA $extra || exit 1
  44. echo test sslv2/sslv3 with both client and server authentication
  45. $ssltest -server_auth -client_auth $CA $extra || exit 1
  46. echo test sslv3 via BIO pair
  47. $ssltest -bio_pair -ssl3 $extra || exit 1
  48. echo test sslv3 with server authentication via BIO pair
  49. $ssltest -bio_pair -ssl3 -server_auth $CA $extra || exit 1
  50. echo test sslv3 with client authentication via BIO pair
  51. $ssltest -bio_pair -ssl3 -client_auth $CA $extra || exit 1
  52. echo test sslv3 with both client and server authentication via BIO pair
  53. $ssltest -bio_pair -ssl3 -server_auth -client_auth $CA $extra || exit 1
  54. echo test sslv2/sslv3 via BIO pair
  55. $ssltest $extra || exit 1
  56. echo test dtlsv1
  57. $ssltest -dtls1 $extra || exit 1
  58. echo test dtlsv1 with server authentication
  59. $ssltest -dtls1 -server_auth $CA $extra || exit 1
  60. echo test dtlsv1 with client authentication
  61. $ssltest -dtls1 -client_auth $CA $extra || exit 1
  62. echo test dtlsv1 with both client and server authentication
  63. $ssltest -dtls1 -server_auth -client_auth $CA $extra || exit 1
  64. echo test dtlsv1.2
  65. $ssltest -dtls12 $extra || exit 1
  66. echo test dtlsv1.2 with server authentication
  67. $ssltest -dtls12 -server_auth $CA $extra || exit 1
  68. echo test dtlsv1.2 with client authentication
  69. $ssltest -dtls12 -client_auth $CA $extra || exit 1
  70. echo test dtlsv1.2 with both client and server authentication
  71. $ssltest -dtls12 -server_auth -client_auth $CA $extra || exit 1
  72. if [ $dsa_cert = NO ]; then
  73. echo 'test sslv2/sslv3 w/o (EC)DHE via BIO pair'
  74. $ssltest -bio_pair -no_dhe -no_ecdhe $extra || exit 1
  75. fi
  76. echo test sslv2/sslv3 with 1024bit DHE via BIO pair
  77. $ssltest -bio_pair -dhe1024dsa -v $extra || exit 1
  78. echo test sslv2/sslv3 with server authentication
  79. $ssltest -bio_pair -server_auth $CA $extra || exit 1
  80. echo test sslv2/sslv3 with client authentication via BIO pair
  81. $ssltest -bio_pair -client_auth $CA $extra || exit 1
  82. echo test sslv2/sslv3 with both client and server authentication via BIO pair
  83. $ssltest -bio_pair -server_auth -client_auth $CA $extra || exit 1
  84. echo test sslv2/sslv3 with both client and server authentication via BIO pair and app verify
  85. $ssltest -bio_pair -server_auth -client_auth -app_verify $CA $extra || exit 1
  86. test_cipher() {
  87. _cipher=$1
  88. echo "Testing $_cipher"
  89. prot=""
  90. if [ $2 = "SSLv3" ] ; then
  91. prot="-ssl3"
  92. fi
  93. _exarg=$3
  94. $ssltest $_exarg -cipher $_cipher $prot
  95. if [ $? -ne 0 ] ; then
  96. echo "Failed $_cipher"
  97. exit 1
  98. fi
  99. }
  100. echo "Testing ciphersuites"
  101. exkeys=""
  102. ciphers="-EXP:-PSK:-SRP:-kDH:-kECDHe"
  103. if ../util/shlib_wrap.sh ../apps/openssl no-dhparam >/dev/null; then
  104. echo "skipping DHE tests"
  105. ciphers="$ciphers:-kDHE"
  106. fi
  107. if ../util/shlib_wrap.sh ../apps/openssl no-dsa >/dev/null; then
  108. echo "skipping DSA tests"
  109. ciphers="$ciphers:-aDSA"
  110. else
  111. exkeys="$exkeys -s_cert certD.ss -s_key keyD.ss"
  112. fi
  113. if ../util/shlib_wrap.sh ../apps/openssl no-ec >/dev/null; then
  114. echo "skipping EC tests"
  115. ciphers="$ciphers:!aECDSA:!kECDH"
  116. else
  117. exkeys="$exkeys -s_cert certE.ss -s_key keyE.ss"
  118. fi
  119. for protocol in TLSv1.2 SSLv3; do
  120. echo "Testing ciphersuites for $protocol"
  121. for cipher in `../util/shlib_wrap.sh ../apps/openssl ciphers "$protocol:$ciphers" | tr ':' ' '`; do
  122. test_cipher $cipher $protocol "$exkeys"
  123. done
  124. echo "testing connection with weak DH, expecting failure"
  125. if [ $protocol = "SSLv3" ] ; then
  126. $ssltest -s_cipher "EDH" -c_cipher "EDH:@SECLEVEL=1" -dhe512 -ssl3
  127. else
  128. $ssltest -s_cipher "EDH" -c_cipher "EDH:@SECLEVEL=1" -dhe512
  129. fi
  130. if [ $? -eq 0 ]; then
  131. echo "FAIL: connection with weak DH succeeded"
  132. exit 1
  133. fi
  134. done
  135. #############################################################################
  136. if ../util/shlib_wrap.sh ../apps/openssl no-dhparam; then
  137. echo skipping anonymous DH tests
  138. else
  139. echo test tls1 with 1024bit anonymous DH, multiple handshakes
  140. $ssltest -v -bio_pair -tls1 -cipher ADH -dhe1024dsa -num 10 -f -time $extra || exit 1
  141. fi
  142. if ../util/shlib_wrap.sh ../apps/openssl no-rsa; then
  143. echo skipping RSA tests
  144. else
  145. echo 'test tls1 with 1024bit RSA, no (EC)DHE, multiple handshakes'
  146. ../util/shlib_wrap.sh ./ssltest -v -bio_pair -tls1 -s_cert ../apps/server2.pem -no_dhe -no_ecdhe -num 10 -f -time $extra || exit 1
  147. if ../util/shlib_wrap.sh ../apps/openssl no-dhparam; then
  148. echo skipping RSA+DHE tests
  149. else
  150. echo test tls1 with 1024bit RSA, 1024bit DHE, multiple handshakes
  151. ../util/shlib_wrap.sh ./ssltest -v -bio_pair -tls1 -s_cert ../apps/server2.pem -dhe1024dsa -num 10 -f -time $extra || exit 1
  152. fi
  153. fi
  154. echo test tls1 with PSK
  155. $ssltest -tls1 -cipher PSK -psk abc123 $extra || exit 1
  156. echo test tls1 with PSK via BIO pair
  157. $ssltest -bio_pair -tls1 -cipher PSK -psk abc123 $extra || exit 1
  158. #############################################################################
  159. # Next Protocol Negotiation Tests
  160. $ssltest -bio_pair -tls1 -npn_client || exit 1
  161. $ssltest -bio_pair -tls1 -npn_server || exit 1
  162. $ssltest -bio_pair -tls1 -npn_server_reject || exit 1
  163. $ssltest -bio_pair -tls1 -npn_client -npn_server_reject || exit 1
  164. $ssltest -bio_pair -tls1 -npn_client -npn_server || exit 1
  165. $ssltest -bio_pair -tls1 -npn_client -npn_server -num 2 || exit 1
  166. $ssltest -bio_pair -tls1 -npn_client -npn_server -num 2 -reuse || exit 1
  167. #############################################################################
  168. # Custom Extension tests
  169. echo test tls1 with custom extensions
  170. $ssltest -bio_pair -tls1 -custom_ext || exit 1
  171. #############################################################################
  172. # Serverinfo tests
  173. echo test tls1 with serverinfo
  174. $ssltest -bio_pair -tls1 -serverinfo_file $serverinfo || exit 1
  175. $ssltest -bio_pair -tls1 -serverinfo_file $serverinfo -serverinfo_sct || exit 1
  176. $ssltest -bio_pair -tls1 -serverinfo_file $serverinfo -serverinfo_tack || exit 1
  177. $ssltest -bio_pair -tls1 -serverinfo_file $serverinfo -serverinfo_sct -serverinfo_tack || exit 1
  178. $ssltest -bio_pair -tls1 -custom_ext -serverinfo_file $serverinfo -serverinfo_sct -serverinfo_tack || exit 1
  179. #############################################################################
  180. # ALPN tests
  181. $ssltest -bio_pair -tls1 -alpn_client foo -alpn_server bar || exit 1
  182. $ssltest -bio_pair -tls1 -alpn_client foo -alpn_server foo -alpn_expected foo || exit 1
  183. $ssltest -bio_pair -tls1 -alpn_client foo,bar -alpn_server foo -alpn_expected foo || exit 1
  184. $ssltest -bio_pair -tls1 -alpn_client bar,foo -alpn_server foo -alpn_expected foo || exit 1
  185. $ssltest -bio_pair -tls1 -alpn_client bar,foo -alpn_server foo,bar -alpn_expected foo || exit 1
  186. $ssltest -bio_pair -tls1 -alpn_client bar,foo -alpn_server bar,foo -alpn_expected bar || exit 1
  187. $ssltest -bio_pair -tls1 -alpn_client foo,bar -alpn_server bar,foo -alpn_expected bar || exit 1
  188. $ssltest -bio_pair -tls1 -alpn_client baz -alpn_server bar,foo || exit 1
  189. if ../util/shlib_wrap.sh ../apps/openssl no-srp; then
  190. echo skipping SRP tests
  191. else
  192. echo test tls1 with SRP
  193. $ssltest -tls1 -cipher SRP -srpuser test -srppass abc123 || exit 1
  194. echo test tls1 with SRP via BIO pair
  195. $ssltest -bio_pair -tls1 -cipher SRP -srpuser test -srppass abc123 || exit 1
  196. echo test tls1 with SRP auth
  197. $ssltest -tls1 -cipher aSRP -srpuser test -srppass abc123 || exit 1
  198. echo test tls1 with SRP auth via BIO pair
  199. $ssltest -bio_pair -tls1 -cipher aSRP -srpuser test -srppass abc123 || exit 1
  200. fi
  201. #############################################################################
  202. # Multi-buffer tests
  203. if [ -z "$extra" -a `uname -m` = "x86_64" ]; then
  204. $ssltest -cipher AES128-SHA -bytes 8m || exit 1
  205. $ssltest -cipher AES128-SHA256 -bytes 8m || exit 1
  206. fi
  207. exit 0