Skip to content

Commit

Permalink
test: Add tests for decryption with singing key
Browse files Browse the repository at this point in the history
  • Loading branch information
lubux committed Nov 20, 2024
1 parent 25c09e6 commit 788cec1
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
38 changes: 38 additions & 0 deletions openpgp/v2/read_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1023,3 +1023,41 @@ func testMalformedMessage(t *testing.T, keyring EntityList, message string) {
return
}
}

func TestReadMessageWithSignOnly(t *testing.T) {
config := packet.Config{
InsecureAllowDecryptionWithSigningKeys: true,
}
key, err := ReadArmoredKeyRing(strings.NewReader(rsaSignOnly))
if err != nil {
t.Error(err)
return
}
// Success
msgReader, err := armor.Decode(strings.NewReader(armoredMessageRsaSignOnly))
if err != nil {
t.Error(err)
return
}
md, err := ReadMessage(msgReader.Body, key, nil, &config)
if err != nil {
t.Error(err)
return
}
_, err = io.ReadAll(md.UnverifiedBody)
if err != nil {
t.Error(err)
return
}

// Fail
msgReader, err = armor.Decode(strings.NewReader(armoredMessageRsaSignOnly))
if err != nil {
t.Error(err)
return
}
md, err = ReadMessage(msgReader.Body, key, nil, nil)
if err == nil {
t.Fatal("Should not decrypt")
}
}
48 changes: 48 additions & 0 deletions openpgp/v2/read_write_test_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -740,3 +740,51 @@ NVniEke6hM3CNBXYPAMhQBMWhCulcoz+0lxi8L34rMN+Dsbma96psdUrn7uLaB91
xqAY9Bwizt4FWgXuLm1a4+So4V9j1TRCXd12Uc2l2RNmgDE=
=miES
-----END PGP PRIVATE KEY BLOCK-----`

const rsaSignOnly = `-----BEGIN PGP PRIVATE KEY BLOCK-----
xcLYBF9Gl+MBCACc09O3gjyO0B1ledGxGFSUpPmhhJzkxKoY1WDX8VlASCHz
bAA/BytgYBXHTe7N+N3yJ6uiN3DIQ2j5uGWk/h5jyIOsRuzQxJ40n8AdK/71
SGDCG1X5l1h9vmVTJxkQ3pcOxqRg55EEuJWKN1v7B1hIPx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mb0Bib2IuY29tPsLA
jQQQAQgAIAUCX0aX4wYLCQcIAwIEFQgKAgQWAgEAAhkBAhsDAh4BACEJEAr9
x5ZY6oZmFiEEm+B7p+lshgEOwGGZCv3HlljqhmaUWgf/efmGSpOKIGQ3Kh32
HUqn/4ARvUmqMtZz4xUA9P3GAPY8XwJf00jSQlAo4//3aA1eEOJFHCr2qzCk
/4gIoZEScTTZp4itfL/Fer3UX+bV/VeTNgZGi+MRylSDQxLRQNpRgu+FmRAi
E6fr8D8GMvEcGb0jTRgWGj1EVtfOHfDg+EyPrtw+Z8u/bErUJ+Fnxz+KOGSN
SBQVAOflUYFoQhUNgZiq1s8WFD55sfes3UdBwsmHquDtYGo9dvWLJXxTEF8q
QCyKHYdk25ShIlNpRUqOH3CHqY/38z7QeV7INwtZaQvoES08RlD6ZMtczYLj
BZou86lozq7ISvRg1RSIWZ0ZRA==
=A9Ts
-----END PGP PRIVATE KEY BLOCK-----
`

const armoredMessageRsaSignOnly = `-----BEGIN PGP MESSAGE-----
wcBMAwr9x5ZY6oZmAQf+Lxghg4keIFpEq8a65gFkIfW+chHTDPlfI8xnx6U9
HdsICX3Oye5V0ToCVKkEWDxfN1yCfXiYalSNo7ScRZKR7C+j02/pC+FfR6AJ
2cvdFoGIrLaXdjXXc/oXbsCCZA4C1DhQqpdORo2qGF0Q6Sm8659B0CfOgYSL
fBfKQ5VJngUT5JG8Uek3YuXBufPNhzdmXLHyB2Y2CwKkldi2vo4YNAukDhrR
2TojxdNoouhnMm+gloCE1n8huY1vw5F78/uiHen0tmHQ0dxtfk8cc1burgl/
zUdJ3Sg6Eu+OC2ae5II63iB5fG+lCwZtfuepWnePDv8RDKNHCVP/LoBNpGOZ
U9I6AUkZWdcsueib9ghKDDy+HbUbf2kCJWUnuyeOCKqQifDb8bsLmdQY4Wb6
EBeLgD8oZHVsH3NLjPakPw==
=STqy
-----END PGP MESSAGE-----`

0 comments on commit 788cec1

Please sign in to comment.