浏览代码

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
Adam Langley 11 年之前
父节点
当前提交
3092f0d93b
共有 2 个文件被更改,包括 13 次插入1 次删除
  1. 4 1
      openpgp/read.go
  2. 9 0
      openpgp/read_test.go

+ 4 - 1
openpgp/read.go

@@ -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 - 0
openpgp/read_test.go

@@ -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) {