1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-12-22 19:08:00 +01:00

Make sop decrypt throw for unencrypted data

This commit is contained in:
Paul Schaub 2022-06-23 11:47:48 +02:00
parent efc0cb357b
commit 14531f0050
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
2 changed files with 22 additions and 0 deletions

View file

@ -149,6 +149,10 @@ public class DecryptImpl implements Decrypt {
decryptionStream.close();
OpenPgpMetadata metadata = decryptionStream.getResult();
if (!metadata.isEncrypted()) {
throw new SOPGPException.BadData("Data is not encrypted.");
}
List<Verification> verificationList = new ArrayList<>();
for (SignatureVerification signatureVerification : metadata.getVerifiedInbandSignatures()) {
verificationList.add(map(signatureVerification));

View file

@ -515,4 +515,22 @@ public class EncryptDecryptRoundTripTest {
assertThrows(SOPGPException.BadData.class, () ->
sop.decrypt().withSessionKey(wrongSessionKey).ciphertext(ciphertext));
}
@Test
public void decryptNonEncryptedDataFailsBadData() throws IOException {
byte[] signed = sop.inlineSign()
.key(aliceKey)
.withKeyPassword(alicePassword)
.data(message)
.getBytes();
assertThrows(SOPGPException.BadData.class, () ->
sop.decrypt()
.verifyWithCert(aliceCert)
.withKey(aliceKey)
.withKeyPassword(alicePassword)
.ciphertext(signed)
.toByteArrayAndResult()
);
}
}