go.crypto/openpgp: return signature error rather than unknown issuer.

In the event that a detached signature fails to verify, the code would
continue trying to find other keys with the same key ID and eventually
conclude that the signature was issued by someone unknown
(ErrUnknownIssuer).

With this change, the signature verification error would be returned
instead. (Technically the last error if several keys had a matching key
id and neither verified.)

Fixes golang/go#8509.

LGTM=bradfitz
R=bradfitz
CC=golang-codereviews
https://golang.org/cl/125030043
This commit is contained in:
Adam Langley
2014-08-11 15:41:56 -07:00
parent ed03dad8de
commit 3092f0d93b
2 changed files with 13 additions and 1 deletions
+4 -1
View File
@@ -405,7 +405,10 @@ func CheckDetachedSignature(keyring KeyRing, signed, signature io.Reader) (signe
}
}
return nil, errors.ErrUnknownIssuer
if err == nil {
err = errors.ErrUnknownIssuer
}
return nil, err
}
// CheckArmoredDetachedSignature performs the same actions as
+9
View File
@@ -279,6 +279,15 @@ func TestDetachedSignature(t *testing.T) {
testDetachedSignature(t, kring, readerFromHex(detachedSignatureHex), signedInput, "binary", testKey1KeyId)
testDetachedSignature(t, kring, readerFromHex(detachedSignatureTextHex), signedInput, "text", testKey1KeyId)
testDetachedSignature(t, kring, readerFromHex(detachedSignatureV3TextHex), signedInput, "v3", testKey1KeyId)
incorrectSignedInput := signedInput + "X"
_, err := CheckDetachedSignature(kring, bytes.NewBufferString(incorrectSignedInput), readerFromHex(detachedSignatureHex))
if err == nil {
t.Fatal("CheckDetachedSignature returned without error for bad signature")
}
if err == errors.ErrUnknownIssuer {
t.Fatal("CheckDetachedSignature returned ErrUnknownIssuer when the signer was known, but the signature invalid")
}
}
func TestDetachedSignatureDSA(t *testing.T) {