cipher_test.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright 2011 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. import (
  6. "bytes"
  7. "crypto"
  8. "crypto/rand"
  9. "testing"
  10. )
  11. func TestDefaultCiphersExist(t *testing.T) {
  12. for _, cipherAlgo := range supportedCiphers {
  13. if _, ok := cipherModes[cipherAlgo]; !ok {
  14. t.Errorf("default cipher %q is unknown", cipherAlgo)
  15. }
  16. }
  17. }
  18. func TestPacketCiphers(t *testing.T) {
  19. for cipher := range cipherModes {
  20. kr := &kexResult{Hash: crypto.SHA1}
  21. algs := directionAlgorithms{
  22. Cipher: cipher,
  23. MAC: "hmac-sha1",
  24. Compression: "none",
  25. }
  26. client, err := newPacketCipher(clientKeys, algs, kr)
  27. if err != nil {
  28. t.Errorf("newPacketCipher(client, %q): %v", cipher, err)
  29. continue
  30. }
  31. server, err := newPacketCipher(clientKeys, algs, kr)
  32. if err != nil {
  33. t.Errorf("newPacketCipher(client, %q): %v", cipher, err)
  34. continue
  35. }
  36. want := "bla bla"
  37. input := []byte(want)
  38. buf := &bytes.Buffer{}
  39. if err := client.writePacket(0, buf, rand.Reader, input); err != nil {
  40. t.Errorf("writePacket(%q): %v", cipher, err)
  41. continue
  42. }
  43. packet, err := server.readPacket(0, buf)
  44. if err != nil {
  45. t.Errorf("readPacket(%q): %v", cipher, err)
  46. continue
  47. }
  48. if string(packet) != want {
  49. t.Errorf("roundtrip(%q): got %q, want %q", cipher, packet, want)
  50. }
  51. }
  52. }