You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.0 KiB

  1. // Copyright 2013 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package ssh
  5. // Key exchange tests.
  6. import (
  7. "crypto/rand"
  8. "reflect"
  9. "testing"
  10. )
  11. func TestKexes(t *testing.T) {
  12. type kexResultErr struct {
  13. result *kexResult
  14. err error
  15. }
  16. for name, kex := range kexAlgoMap {
  17. a, b := memPipe()
  18. s := make(chan kexResultErr, 1)
  19. c := make(chan kexResultErr, 1)
  20. var magics handshakeMagics
  21. go func() {
  22. r, e := kex.Client(a, rand.Reader, &magics)
  23. a.Close()
  24. c <- kexResultErr{r, e}
  25. }()
  26. go func() {
  27. r, e := kex.Server(b, rand.Reader, &magics, testSigners["ecdsa"])
  28. b.Close()
  29. s <- kexResultErr{r, e}
  30. }()
  31. clientRes := <-c
  32. serverRes := <-s
  33. if clientRes.err != nil {
  34. t.Errorf("client: %v", clientRes.err)
  35. }
  36. if serverRes.err != nil {
  37. t.Errorf("server: %v", serverRes.err)
  38. }
  39. if !reflect.DeepEqual(clientRes.result, serverRes.result) {
  40. t.Errorf("kex %q: mismatch %#v, %#v", name, clientRes.result, serverRes.result)
  41. }
  42. }
  43. }