Fix signature status when verifying unsigned message

Return `SIGNATURE_NOT_SIGNED` instead of `SIGNATURE_NO_VERIFIER` when
verifying a messages with no embedded signatures.
This commit is contained in:
marin thiercelin 2021-07-15 18:56:15 +02:00
parent f4ccc63c40
commit 77df8cba3d
No known key found for this signature in database
GPG key ID: 117C025B1F21B2C6
3 changed files with 13 additions and 3 deletions

View file

@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Unreleased
### Changed
- Changed the returned `SignatureVerificationError.Status` when trying to verify a message with no embedded signature. It used to return `constants.SIGNATURE_NO_VERIFIER` and now returns `constants.SIGNATURE_NOT_SIGNED`.
This change impacts :
- `func (sk *SessionKey) DecryptAndVerify(...)`
- `func (msg *PlainMessageReader) VerifySignature(...)`
- `func (keyRing *KeyRing) Decrypt(...)`
### Added
- Helper to access the SignatureVerificationError explicitly when decrypting streams in mobile apps:
```go

View file

@ -99,8 +99,10 @@ func processSignatureExpiration(md *openpgp.MessageDetails, verifyTime int64) {
// verifyDetailsSignature verifies signature from message details.
func verifyDetailsSignature(md *openpgp.MessageDetails, verifierKey *KeyRing) error {
if !md.IsSigned ||
md.SignedBy == nil ||
if !md.IsSigned {
return newSignatureNotSigned()
}
if md.SignedBy == nil ||
len(verifierKey.entities) == 0 ||
len(verifierKey.entities.KeysById(md.SignedByKeyId)) == 0 {
return newSignatureNoVerifier()

View file

@ -85,7 +85,7 @@ func TestMobileSignedMessageDecryptionWithSessionKey(t *testing.T) {
t.Fatal("Expected no error when decrypting, got:", err)
}
assert.Exactly(t, constants.SIGNATURE_NO_VERIFIER, decrypted.SignatureVerificationError.Status)
assert.Exactly(t, constants.SIGNATURE_NOT_SIGNED, decrypted.SignatureVerificationError.Status)
assert.Exactly(t, message.GetString(), decrypted.Message.GetString())
publicKey, _ = crypto.NewKeyFromArmored(readTestFile("keyring_publicKey", false))