passthrough_test.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * Copyright (c) 2020, Psiphon Inc.
  3. * All rights reserved.
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. */
  19. package obfuscator
  20. import (
  21. "bytes"
  22. "testing"
  23. )
  24. func TestTLSPassthrough(t *testing.T) {
  25. correctMasterKey := "correct-master-key"
  26. incorrectMasterKey := "incorrect-master-key"
  27. passthroughKey, err := DeriveTLSPassthroughKey(correctMasterKey)
  28. if err != nil {
  29. t.Fatalf("DeriveTLSPassthroughKey failed: %s", err)
  30. }
  31. validMessage, err := MakeTLSPassthroughMessage(correctMasterKey)
  32. if err != nil {
  33. t.Fatalf("MakeTLSPassthroughMessage failed: %s", err)
  34. }
  35. if !VerifyTLSPassthroughMessage(passthroughKey, validMessage) {
  36. t.Fatalf("unexpected invalid passthrough messages")
  37. }
  38. anotherValidMessage, err := MakeTLSPassthroughMessage(correctMasterKey)
  39. if err != nil {
  40. t.Fatalf("MakeTLSPassthroughMessage failed: %s", err)
  41. }
  42. if bytes.Equal(validMessage, anotherValidMessage) {
  43. t.Fatalf("unexpected identical passthrough messages")
  44. }
  45. invalidMessage, err := MakeTLSPassthroughMessage(incorrectMasterKey)
  46. if err != nil {
  47. t.Fatalf("MakeTLSPassthroughMessage failed: %s", err)
  48. }
  49. if VerifyTLSPassthroughMessage(passthroughKey, invalidMessage) {
  50. t.Fatalf("unexpected valid passthrough messages")
  51. }
  52. }