1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2025-09-10 18:59:39 +02:00

Enfore max recursion depth and fix CRC test

This commit is contained in:
Paul Schaub 2022-10-18 15:55:47 +02:00
parent 7097d44916
commit dfbb01d61c
5 changed files with 66 additions and 22 deletions

View file

@ -489,7 +489,7 @@ public class AsciiArmorCRCTests {
Passphrase passphrase = Passphrase.fromPassword("flowcrypt compatibility tests");
@Test
public void testInvalidArmorCRCThrowsOnClose() throws PGPException, IOException {
public void testInvalidArmorCRCThrowsOnClose() throws IOException {
String message = "-----BEGIN PGP MESSAGE-----\n" +
"Version: FlowCrypt 5.0.4 Gmail Encryption flowcrypt.com\n" +
"Comment: Seamlessly send, receive and search encrypted email\n" +
@ -542,14 +542,16 @@ public class AsciiArmorCRCTests {
"-----END PGP MESSAGE-----\n";
PGPSecretKeyRing key = PGPainless.readKeyRing().secretKeyRing(ASCII_KEY);
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
.onInputStream(new ByteArrayInputStream(message.getBytes(StandardCharsets.UTF_8)))
.withOptions(new ConsumerOptions().addDecryptionKey(
key, SecretKeyRingProtector.unlockAnyKeyWith(passphrase)
));
assertThrows(IOException.class, () -> {
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
.onInputStream(new ByteArrayInputStream(message.getBytes(StandardCharsets.UTF_8)))
.withOptions(new ConsumerOptions().addDecryptionKey(
key, SecretKeyRingProtector.unlockAnyKeyWith(passphrase)
));
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
Streams.pipeAll(decryptionStream, outputStream);
assertThrows(IOException.class, decryptionStream::close);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
Streams.pipeAll(decryptionStream, outputStream);
decryptionStream.close();
});
}
}

View file

@ -28,9 +28,9 @@ public class MessageMetadataTest {
// For the sake of testing though, this is okay.
MessageMetadata.Message message = new MessageMetadata.Message();
MessageMetadata.CompressedData compressedData = new MessageMetadata.CompressedData(CompressionAlgorithm.ZIP);
MessageMetadata.EncryptedData encryptedData = new MessageMetadata.EncryptedData(SymmetricKeyAlgorithm.AES_128);
MessageMetadata.EncryptedData encryptedData1 = new MessageMetadata.EncryptedData(SymmetricKeyAlgorithm.AES_256);
MessageMetadata.CompressedData compressedData = new MessageMetadata.CompressedData(CompressionAlgorithm.ZIP, message.depth + 1);
MessageMetadata.EncryptedData encryptedData = new MessageMetadata.EncryptedData(SymmetricKeyAlgorithm.AES_128, compressedData.depth + 1);
MessageMetadata.EncryptedData encryptedData1 = new MessageMetadata.EncryptedData(SymmetricKeyAlgorithm.AES_256, encryptedData.depth + 1);
MessageMetadata.LiteralData literalData = new MessageMetadata.LiteralData();
message.setChild(compressedData);

View file

@ -11,12 +11,12 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.bouncycastle.util.io.Streams;
import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.api.extension.ExtendWith;
import org.pgpainless.PGPainless;
import org.pgpainless.exception.MalformedOpenPgpMessageException;
import org.pgpainless.util.TestAllImplementations;
public class RecursionDepthTest {
@ -143,7 +143,7 @@ public class RecursionDepthTest {
"-----END PGP ARMORED FILE-----\n";
assertThrows(PGPException.class, () -> {
assertThrows(MalformedOpenPgpMessageException.class, () -> {
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
.onInputStream(new ByteArrayInputStream(msg.getBytes(StandardCharsets.UTF_8)))
.withOptions(new ConsumerOptions().addDecryptionKey(secretKey));