The aes128cbc cipher is commented out in cipher.go on purpose, anyone wants to use the cipher needs to uncomment line 119 in cipher.go Fixes #4274. Change-Id: I4bbc88ab884bda821c5f155dcf495bb7235c8605 Reviewed-on: https://go-review.googlesource.com/8396 Reviewed-by: Adam Langley <agl@golang.org>
65 lines
1.5 KiB
Go
65 lines
1.5 KiB
Go
// Copyright 2011 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package ssh
|
|
|
|
import (
|
|
"bytes"
|
|
"crypto"
|
|
"crypto/aes"
|
|
"crypto/rand"
|
|
"testing"
|
|
)
|
|
|
|
func TestDefaultCiphersExist(t *testing.T) {
|
|
for _, cipherAlgo := range supportedCiphers {
|
|
if _, ok := cipherModes[cipherAlgo]; !ok {
|
|
t.Errorf("default cipher %q is unknown", cipherAlgo)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestPacketCiphers(t *testing.T) {
|
|
// Still test aes128cbc cipher althought it's commented out.
|
|
cipherModes[aes128cbcID] = &streamCipherMode{16, aes.BlockSize, 0, nil}
|
|
defer delete(cipherModes, aes128cbcID)
|
|
|
|
for cipher := range cipherModes {
|
|
kr := &kexResult{Hash: crypto.SHA1}
|
|
algs := directionAlgorithms{
|
|
Cipher: cipher,
|
|
MAC: "hmac-sha1",
|
|
Compression: "none",
|
|
}
|
|
client, err := newPacketCipher(clientKeys, algs, kr)
|
|
if err != nil {
|
|
t.Errorf("newPacketCipher(client, %q): %v", cipher, err)
|
|
continue
|
|
}
|
|
server, err := newPacketCipher(clientKeys, algs, kr)
|
|
if err != nil {
|
|
t.Errorf("newPacketCipher(client, %q): %v", cipher, err)
|
|
continue
|
|
}
|
|
|
|
want := "bla bla"
|
|
input := []byte(want)
|
|
buf := &bytes.Buffer{}
|
|
if err := client.writePacket(0, buf, rand.Reader, input); err != nil {
|
|
t.Errorf("writePacket(%q): %v", cipher, err)
|
|
continue
|
|
}
|
|
|
|
packet, err := server.readPacket(0, buf)
|
|
if err != nil {
|
|
t.Errorf("readPacket(%q): %v", cipher, err)
|
|
continue
|
|
}
|
|
|
|
if string(packet) != want {
|
|
t.Errorf("roundtrip(%q): got %q, want %q", cipher, packet, want)
|
|
}
|
|
}
|
|
}
|