Skip to content

Commit 3092f0d

Browse files
committed
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
1 parent ed03dad commit 3092f0d

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

openpgp/read.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,10 @@ func CheckDetachedSignature(keyring KeyRing, signed, signature io.Reader) (signe
405405
}
406406
}
407407

408-
return nil, errors.ErrUnknownIssuer
408+
if err == nil {
409+
err = errors.ErrUnknownIssuer
410+
}
411+
return nil, err
409412
}
410413

411414
// CheckArmoredDetachedSignature performs the same actions as

openpgp/read_test.go

+9
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,15 @@ func TestDetachedSignature(t *testing.T) {
279279
testDetachedSignature(t, kring, readerFromHex(detachedSignatureHex), signedInput, "binary", testKey1KeyId)
280280
testDetachedSignature(t, kring, readerFromHex(detachedSignatureTextHex), signedInput, "text", testKey1KeyId)
281281
testDetachedSignature(t, kring, readerFromHex(detachedSignatureV3TextHex), signedInput, "v3", testKey1KeyId)
282+
283+
incorrectSignedInput := signedInput + "X"
284+
_, err := CheckDetachedSignature(kring, bytes.NewBufferString(incorrectSignedInput), readerFromHex(detachedSignatureHex))
285+
if err == nil {
286+
t.Fatal("CheckDetachedSignature returned without error for bad signature")
287+
}
288+
if err == errors.ErrUnknownIssuer {
289+
t.Fatal("CheckDetachedSignature returned ErrUnknownIssuer when the signer was known, but the signature invalid")
290+
}
282291
}
283292

284293
func TestDetachedSignatureDSA(t *testing.T) {

0 commit comments

Comments
 (0)