golang.org/x/crypto/openssh: don't loop forever after a bad password.

SymmetricKeyEncrypted cached the results of decryption so, if a bad
password was given, ReadMessage would prompt forever because a later,
correct password wouldn't override the cached decryption.

The SymmetricKeyEncrypted object can't know whether a given passphrase
is correct so it should never have been a mutable object in the first
place. This change makes it so that it doesn't cache anything.

Fixes #9315

Change-Id: Ic2b75f7f60a575e2182ac7e5c5d4198597c5d0a2
Reviewed-on: https://go-review.googlesource.com/14038
Reviewed-by: Andrew Gerrand <adg@golang.org>
Reviewed-by: Adam Langley <agl@golang.org>
This commit is contained in:
Adam Langley
2015-09-30 00:38:34 +00:00
parent 59a4410d82
commit 0c93e1ff9f
4 changed files with 48 additions and 50 deletions
+7 -1
View File
@@ -243,7 +243,7 @@ func TestUnspecifiedRecipient(t *testing.T) {
}
func TestSymmetricallyEncrypted(t *testing.T) {
expected := "Symmetrically encrypted.\n"
firstTimeCalled := true
prompt := func(keys []Key, symmetric bool) ([]byte, error) {
if len(keys) != 0 {
@@ -254,6 +254,11 @@ func TestSymmetricallyEncrypted(t *testing.T) {
t.Errorf("symmetric is not set")
}
if firstTimeCalled {
firstTimeCalled = false
return []byte("wrongpassword"), nil
}
return []byte("password"), nil
}
@@ -273,6 +278,7 @@ func TestSymmetricallyEncrypted(t *testing.T) {
t.Errorf("LiteralData.Time is %d, want %d", md.LiteralData.Time, expectedCreationTime)
}
const expected = "Symmetrically encrypted.\n"
if string(contents) != expected {
t.Errorf("contents got: %s want: %s", string(contents), expected)
}