tls.tcl 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. start_server {tags {"tls"}} {
  2. if {$::tls} {
  3. package require tls
  4. test {TLS: Not accepting non-TLS connections on a TLS port} {
  5. set s [redis [srv 0 host] [srv 0 port]]
  6. catch {$s PING} e
  7. set e
  8. } {*I/O error*}
  9. test {TLS: Verify tls-auth-clients behaves as expected} {
  10. set s [redis [srv 0 host] [srv 0 port]]
  11. ::tls::import [$s channel]
  12. catch {$s PING} e
  13. assert_match {*error*} $e
  14. r CONFIG SET tls-auth-clients no
  15. set s [redis [srv 0 host] [srv 0 port]]
  16. ::tls::import [$s channel]
  17. catch {$s PING} e
  18. assert_match {PONG} $e
  19. r CONFIG SET tls-auth-clients yes
  20. }
  21. test {TLS: Verify tls-protocols behaves as expected} {
  22. r CONFIG SET tls-protocols TLSv1
  23. set s [redis [srv 0 host] [srv 0 port] 0 1 {-tls1 0}]
  24. catch {$s PING} e
  25. assert_match {*I/O error*} $e
  26. set s [redis [srv 0 host] [srv 0 port] 0 1 {-tls1 1}]
  27. catch {$s PING} e
  28. assert_match {PONG} $e
  29. r CONFIG SET tls-protocols TLSv1.1
  30. set s [redis [srv 0 host] [srv 0 port] 0 1 {-tls1.1 0}]
  31. catch {$s PING} e
  32. assert_match {*I/O error*} $e
  33. set s [redis [srv 0 host] [srv 0 port] 0 1 {-tls1.1 1}]
  34. catch {$s PING} e
  35. assert_match {PONG} $e
  36. r CONFIG SET tls-protocols TLSv1.2
  37. set s [redis [srv 0 host] [srv 0 port] 0 1 {-tls1.2 0}]
  38. catch {$s PING} e
  39. assert_match {*I/O error*} $e
  40. set s [redis [srv 0 host] [srv 0 port] 0 1 {-tls1.2 1}]
  41. catch {$s PING} e
  42. assert_match {PONG} $e
  43. r CONFIG SET tls-protocols ""
  44. }
  45. test {TLS: Verify tls-ciphers behaves as expected} {
  46. r CONFIG SET tls-protocols TLSv1.2
  47. r CONFIG SET tls-ciphers "DEFAULT:-AES128-SHA256"
  48. set s [redis [srv 0 host] [srv 0 port] 0 1 {-cipher "-ALL:AES128-SHA256"}]
  49. catch {$s PING} e
  50. assert_match {*I/O error*} $e
  51. set s [redis [srv 0 host] [srv 0 port] 0 1 {-cipher "-ALL:AES256-SHA256"}]
  52. catch {$s PING} e
  53. assert_match {PONG} $e
  54. r CONFIG SET tls-ciphers "DEFAULT"
  55. set s [redis [srv 0 host] [srv 0 port] 0 1 {-cipher "-ALL:AES128-SHA256"}]
  56. catch {$s PING} e
  57. assert_match {PONG} $e
  58. r CONFIG SET tls-protocols ""
  59. r CONFIG SET tls-ciphers "DEFAULT"
  60. }
  61. test {TLS: Verify tls-prefer-server-ciphers behaves as expected} {
  62. r CONFIG SET tls-protocols TLSv1.2
  63. r CONFIG SET tls-ciphers "AES128-SHA256:AES256-SHA256"
  64. set s [redis [srv 0 host] [srv 0 port] 0 1 {-cipher "AES256-SHA256:AES128-SHA256"}]
  65. catch {$s PING} e
  66. assert_match {PONG} $e
  67. assert_equal "AES256-SHA256" [dict get [::tls::status [$s channel]] cipher]
  68. r CONFIG SET tls-prefer-server-ciphers yes
  69. set s [redis [srv 0 host] [srv 0 port] 0 1 {-cipher "AES256-SHA256:AES128-SHA256"}]
  70. catch {$s PING} e
  71. assert_match {PONG} $e
  72. assert_equal "AES128-SHA256" [dict get [::tls::status [$s channel]] cipher]
  73. r CONFIG SET tls-protocols ""
  74. r CONFIG SET tls-ciphers "DEFAULT"
  75. }
  76. }
  77. }