From 31469a2049ca68f6ce80281568c2d81dc700f104 Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Mon, 22 Jan 2018 20:28:32 +0100 Subject: [PATCH] ssh: remove chacha20-poly1305 from preferredCipher list This effectively disables the cipher. Add a test against OpenSSH which sends larger packets through the tested ciphers. This reproduces the problem reported in golang/go#23510 Change-Id: I4b124c690c409c6a0af2621e58a964ff55815f57 Reviewed-on: https://go-review.googlesource.com/88995 Run-TryBot: Han-Wen Nienhuys TryBot-Result: Gobot Gobot Reviewed-by: Adam Langley --- ssh/common.go | 1 - ssh/test/session_test.go | 51 ++++++++++++++++++++++++++++++---------- 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/ssh/common.go b/ssh/common.go index ffdc01f..abde5fc 100644 --- a/ssh/common.go +++ b/ssh/common.go @@ -38,7 +38,6 @@ var supportedCiphers = []string{ var preferredCiphers = []string{ "aes128-ctr", "aes192-ctr", "aes256-ctr", "aes128-gcm@openssh.com", - chacha20Poly1305ID, } // supportedKexAlgos specifies the supported key-exchange algorithms in diff --git a/ssh/test/session_test.go b/ssh/test/session_test.go index 7588b0c..4eb7afd 100644 --- a/ssh/test/session_test.go +++ b/ssh/test/session_test.go @@ -11,6 +11,7 @@ package test import ( "bytes" "errors" + "fmt" "io" "strings" "testing" @@ -324,6 +325,42 @@ func TestWindowChange(t *testing.T) { } } +func testOneCipher(t *testing.T, cipher string, cipherOrder []string) { + server := newServer(t) + defer server.Shutdown() + conf := clientConfig() + conf.Ciphers = []string{cipher} + // Don't fail if sshd doesn't have the cipher. + conf.Ciphers = append(conf.Ciphers, cipherOrder...) + conn, err := server.TryDial(conf) + if err != nil { + t.Fatalf("TryDial: %v", err) + } + defer conn.Close() + + numBytes := 4096 + + // Exercise sending data to the server + if _, _, err := conn.Conn.SendRequest("drop-me", false, make([]byte, numBytes)); err != nil { + t.Fatalf("SendRequest: %v", err) + } + + // Exercise receiving data from the server + session, err := conn.NewSession() + if err != nil { + t.Fatalf("NewSession: %v", err) + } + + out, err := session.Output(fmt.Sprintf("dd if=/dev/zero of=/dev/stdout bs=%d count=1", numBytes)) + if err != nil { + t.Fatalf("Output: %v", err) + } + + if len(out) != numBytes { + t.Fatalf("got %d bytes, want %d bytes", len(out), numBytes) + } +} + var deprecatedCiphers = []string{ "aes128-cbc", "3des-cbc", "arcfour128", "arcfour256", @@ -336,21 +373,11 @@ func TestCiphers(t *testing.T) { for _, ciph := range cipherOrder { t.Run(ciph, func(t *testing.T) { - server := newServer(t) - defer server.Shutdown() - conf := clientConfig() - conf.Ciphers = []string{ciph} - // Don't fail if sshd doesn't have the cipher. - conf.Ciphers = append(conf.Ciphers, cipherOrder...) - conn, err := server.TryDial(conf) - if err == nil { - conn.Close() - } else { - t.Fatalf("failed for cipher %q", ciph) - } + testOneCipher(t, ciph, cipherOrder) }) } } + func TestMACs(t *testing.T) { var config ssh.Config config.SetDefaults()