ciphercheck_test.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. package fp_test
  2. import (
  3. "testing"
  4. fp "github.com/cloudflare/mitmengine/fputil"
  5. "github.com/cloudflare/mitmengine/testutil"
  6. )
  7. func TestCipherCheckAnyTriviallyBroken(t *testing.T) {
  8. var tests = []struct {
  9. in fp.IntList
  10. out bool
  11. }{
  12. {fp.IntList{}, false},
  13. {fp.IntList{0x00FF}, false},
  14. {fp.IntList{0x0000}, true},
  15. {fp.IntList{0x0003}, true},
  16. {fp.IntList{0x0004}, false},
  17. {fp.IntList{0xC02B}, false},
  18. {fp.IntList{0x00FF, 0xC02B}, false},
  19. {fp.IntList{0xC02B, 0x0004, 0x00FF}, false},
  20. {fp.IntList{0x00FF, 0xC02B, 0x0004}, false},
  21. {fp.IntList{0x0004, 0xC02B, 0x0003}, true},
  22. }
  23. check := fp.NewCipherCheck()
  24. for _, test := range tests {
  25. actual := check.AnyTriviallyBroken(test.in)
  26. testutil.Equals(t, test.out, actual)
  27. }
  28. }
  29. func TestCipherCheckAnyKnownAttack(t *testing.T) {
  30. var tests = []struct {
  31. in fp.IntList
  32. out bool
  33. }{
  34. {fp.IntList{}, false},
  35. {fp.IntList{0x00FF}, false},
  36. {fp.IntList{0x0000}, true},
  37. {fp.IntList{0x0003}, true},
  38. {fp.IntList{0x0004}, true},
  39. {fp.IntList{0xC02B}, false},
  40. {fp.IntList{0x00FF, 0xC02B}, false},
  41. {fp.IntList{0xC02B, 0x0004, 0x00FF}, true},
  42. {fp.IntList{0x00FF, 0xC02B, 0x0004}, true},
  43. {fp.IntList{0x0004, 0xC02B, 0x0003}, true},
  44. }
  45. check := fp.NewCipherCheck()
  46. for _, test := range tests {
  47. actual := check.AnyKnownAttack(test.in)
  48. testutil.Equals(t, test.out, actual)
  49. }
  50. }
  51. func TestCipherCheckGrade(t *testing.T) {
  52. var tests = []struct {
  53. in fp.IntList
  54. out fp.Grade
  55. }{
  56. {fp.IntList{}, fp.GradeEmpty},
  57. {fp.IntList{0x00FF}, fp.GradeEmpty},
  58. {fp.IntList{0x0000}, fp.GradeF},
  59. {fp.IntList{0x0003}, fp.GradeF},
  60. {fp.IntList{0x0004}, fp.GradeC},
  61. {fp.IntList{0xC02B}, fp.GradeA},
  62. {fp.IntList{0x00FF, 0xC02B}, fp.GradeA},
  63. {fp.IntList{0xC02B, 0x0004, 0x00FF}, fp.GradeC},
  64. {fp.IntList{0x00FF, 0xC02B, 0x0004}, fp.GradeC},
  65. {fp.IntList{0x0004, 0xC02B, 0x0003}, fp.GradeF},
  66. }
  67. check := fp.NewCipherCheck()
  68. for _, test := range tests {
  69. actual := check.Grade(test.in)
  70. testutil.Equals(t, test.out, actual)
  71. }
  72. }
  73. func TestCipherCheckIsFirstPfs(t *testing.T) {
  74. var tests = []struct {
  75. in fp.IntList
  76. out bool
  77. }{
  78. {fp.IntList{}, false},
  79. {fp.IntList{0x00FF}, false},
  80. {fp.IntList{0x0000}, false},
  81. {fp.IntList{0x0003}, false},
  82. {fp.IntList{0x0004}, false},
  83. {fp.IntList{0xC02B}, true},
  84. {fp.IntList{0x00FF, 0xC02B}, true},
  85. {fp.IntList{0xC02B, 0x0004, 0x00FF}, true},
  86. {fp.IntList{0x00FF, 0xC02B, 0x0004}, true},
  87. {fp.IntList{0x0004, 0xC02B, 0x0003}, false},
  88. }
  89. check := fp.NewCipherCheck()
  90. for _, test := range tests {
  91. actual := check.IsFirstPfs(test.in)
  92. testutil.Equals(t, test.out, actual)
  93. }
  94. }