mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-09-09 18:29:39 +02:00
Compare commits
2 commits
c8d6a3dc85
...
4b179d750a
Author | SHA1 | Date | |
---|---|---|---|
4b179d750a | |||
fed6cbcd6e |
59 changed files with 64 additions and 74 deletions
|
@ -139,7 +139,8 @@ class OpenPgpMessageInputStream(
|
|||
|
||||
// Comsume packets, potentially stepping into nested layers
|
||||
layer@ while (run {
|
||||
packet = try {
|
||||
packet =
|
||||
try {
|
||||
pIn.nextPacketTag()
|
||||
} catch (e: NoSuchElementException) {
|
||||
throw MalformedOpenPgpMessageException(e.message)
|
||||
|
@ -210,13 +211,16 @@ class OpenPgpMessageInputStream(
|
|||
syntaxVerifier.next(InputSymbol.LITERAL_DATA)
|
||||
val literalData = packetInputStream!!.readLiteralData()
|
||||
|
||||
val streamEncoding = try {
|
||||
val streamEncoding =
|
||||
try {
|
||||
StreamEncoding.requireFromCode(literalData.format)
|
||||
} catch (e: NoSuchElementException) {
|
||||
throw PGPException("Invalid stream encoding format encountered: ${literalData.format}; ${e.message}")
|
||||
throw PGPException(
|
||||
"Invalid stream encoding format encountered: ${literalData.format}; ${e.message}")
|
||||
}
|
||||
|
||||
val fileName = try {
|
||||
val fileName =
|
||||
try {
|
||||
literalData.fileName
|
||||
} catch (e: IllegalArgumentException) {
|
||||
// Non UTF8
|
||||
|
@ -224,11 +228,7 @@ class OpenPgpMessageInputStream(
|
|||
}
|
||||
|
||||
// Extract Metadata
|
||||
layerMetadata.child =
|
||||
LiteralData(
|
||||
fileName,
|
||||
literalData.modificationTime,
|
||||
streamEncoding)
|
||||
layerMetadata.child = LiteralData(fileName, literalData.modificationTime, streamEncoding)
|
||||
|
||||
nestedInputStream = literalData.inputStream
|
||||
}
|
||||
|
@ -238,17 +238,15 @@ class OpenPgpMessageInputStream(
|
|||
signatures.enterNesting()
|
||||
val compressedData = packetInputStream!!.readCompressedData()
|
||||
|
||||
val compAlg = try {
|
||||
val compAlg =
|
||||
try {
|
||||
CompressionAlgorithm.requireFromId(compressedData.algorithm)
|
||||
} catch (e: NoSuchElementException) {
|
||||
throw PGPException(e.message)
|
||||
}
|
||||
|
||||
// Extract Metadata
|
||||
val compressionLayer =
|
||||
CompressedData(
|
||||
compAlg,
|
||||
layerMetadata.depth + 1)
|
||||
val compressionLayer = CompressedData(compAlg, layerMetadata.depth + 1)
|
||||
|
||||
LOGGER.debug(
|
||||
"Compressed Data Packet (${compressionLayer.algorithm}) at depth ${layerMetadata.depth} encountered.")
|
||||
|
@ -347,7 +345,9 @@ class OpenPgpMessageInputStream(
|
|||
"Symmetrically Encrypted Data Packet at depth ${layerMetadata.depth} encountered.")
|
||||
syntaxVerifier.next(InputSymbol.ENCRYPTED_DATA)
|
||||
val encDataList = packetInputStream!!.readEncryptedDataList()
|
||||
if (!encDataList.isIntegrityProtected && !encDataList.isEmpty && !encDataList.get(0).isAEAD) {
|
||||
if (!encDataList.isIntegrityProtected &&
|
||||
!encDataList.isEmpty &&
|
||||
!encDataList.get(0).isAEAD) {
|
||||
LOGGER.warn("Symmetrically Encrypted Data Packet is not integrity-protected.")
|
||||
if (!options.isIgnoreMDCErrors()) {
|
||||
throw MessageNotIntegrityProtectedException()
|
||||
|
@ -569,7 +569,8 @@ class OpenPgpMessageInputStream(
|
|||
pkesk: PGPPublicKeyEncryptedData
|
||||
): Boolean {
|
||||
try {
|
||||
val decrypted = try {
|
||||
val decrypted =
|
||||
try {
|
||||
pkesk.getDataStream(decryptorFactory)
|
||||
} catch (e: ClassCastException) {
|
||||
throw PGPException(e.message)
|
||||
|
|
|
@ -165,13 +165,13 @@ class SignatureUtils {
|
|||
// having them compressed,
|
||||
// except for an attacker who is trying to exploit flaws in the decompression
|
||||
// algorithm.
|
||||
// Therefore, we ignore compressed data packets without attempting decompression.
|
||||
// Therefore, we ignore compressed data packets without attempting
|
||||
// decompression.
|
||||
if (nextObject is PGPCompressedData) {
|
||||
// getInputStream() does not do decompression, contrary to getDataStream().
|
||||
Streams.drain(
|
||||
(nextObject as PGPCompressedData)
|
||||
.inputStream
|
||||
) // Skip packet without decompressing
|
||||
.inputStream) // Skip packet without decompressing
|
||||
}
|
||||
|
||||
if (nextObject is PGPSignatureList) {
|
||||
|
|
|
@ -247,7 +247,8 @@ class ArmorUtils {
|
|||
.add(OpenPgpFingerprint.of(publicKey).prettyPrint())
|
||||
// Primary / First User ID
|
||||
(primary ?: first)?.let {
|
||||
headerMap.getOrPut(HEADER_COMMENT) { mutableSetOf() }
|
||||
headerMap
|
||||
.getOrPut(HEADER_COMMENT) { mutableSetOf() }
|
||||
.add(it.replace("\n", "\\n").replace("\r", "\\r"))
|
||||
}
|
||||
// X-1 further identities
|
||||
|
|
|
@ -6,13 +6,13 @@ package org.pgpainless.bouncycastle.fuzzing
|
|||
|
||||
import com.code_intelligence.jazzer.api.FuzzedDataProvider
|
||||
import com.code_intelligence.jazzer.junit.FuzzTest
|
||||
import java.io.EOFException
|
||||
import java.io.IOException
|
||||
import org.bouncycastle.bcpg.ArmoredInputException
|
||||
import org.bouncycastle.bcpg.UnsupportedPacketVersionException
|
||||
import org.bouncycastle.openpgp.PGPException
|
||||
import org.bouncycastle.openpgp.PGPUtil
|
||||
import org.bouncycastle.openpgp.bc.BcPGPObjectFactory
|
||||
import java.io.EOFException
|
||||
import java.io.IOException
|
||||
|
||||
class PGPObjectFactoryFuzzingTest {
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
package org.pgpainless.sop
|
||||
|
||||
import java.io.BufferedOutputStream
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
import java.io.OutputStream
|
||||
import kotlin.jvm.Throws
|
||||
|
@ -14,7 +15,6 @@ import org.pgpainless.util.ArmoredOutputStreamFactory
|
|||
import sop.Ready
|
||||
import sop.exception.SOPGPException
|
||||
import sop.operation.Armor
|
||||
import java.io.IOException
|
||||
|
||||
/** Implementation of the `armor` operation using PGPainless. */
|
||||
class ArmorImpl : Armor {
|
||||
|
@ -27,7 +27,8 @@ class ArmorImpl : Armor {
|
|||
val bufferedOutputStream = BufferedOutputStream(outputStream)
|
||||
|
||||
// Determine the nature of the given data
|
||||
val openPgpIn = OpenPgpInputStream(data, false).apply {
|
||||
val openPgpIn =
|
||||
OpenPgpInputStream(data, false).apply {
|
||||
try {
|
||||
inspectBuffer()
|
||||
} catch (e: IOException) {
|
||||
|
|
|
@ -4,11 +4,13 @@
|
|||
|
||||
package org.pgpainless.sop
|
||||
|
||||
import org.bouncycastle.bcpg.UnsupportedPacketVersionException
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
import java.io.OutputStream
|
||||
import java.util.*
|
||||
import java.util.zip.ZipException
|
||||
import kotlin.NoSuchElementException
|
||||
import org.bouncycastle.bcpg.UnsupportedPacketVersionException
|
||||
import org.bouncycastle.openpgp.PGPException
|
||||
import org.bouncycastle.util.io.Streams
|
||||
import org.pgpainless.PGPainless
|
||||
|
@ -25,8 +27,6 @@ import sop.SessionKey
|
|||
import sop.exception.SOPGPException
|
||||
import sop.operation.Decrypt
|
||||
import sop.util.UTF8Util
|
||||
import java.util.zip.ZipException
|
||||
import kotlin.NoSuchElementException
|
||||
|
||||
/** Implementation of the `decrypt` operation using PGPainless. */
|
||||
class DecryptImpl : Decrypt {
|
||||
|
@ -61,8 +61,7 @@ class DecryptImpl : Decrypt {
|
|||
throw SOPGPException.BadData(e)
|
||||
} catch (e: ModificationDetectionException) {
|
||||
throw SOPGPException.BadData(e)
|
||||
}
|
||||
finally {
|
||||
} finally {
|
||||
// Forget passphrases after decryption
|
||||
protector.clear()
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ import java.io.IOException;
|
|||
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
|
||||
public class AsciiArmorFuzzTest {
|
||||
public class ArmorFuzzTest {
|
||||
|
||||
private final SOP sop = new SOPImpl();
|
||||
|
|
@ -6,12 +6,8 @@ package org.pgpainless.sop.fuzzing;
|
|||
|
||||
import com.code_intelligence.jazzer.api.FuzzedDataProvider;
|
||||
import com.code_intelligence.jazzer.junit.FuzzTest;
|
||||
import org.bouncycastle.util.encoders.Hex;
|
||||
import org.bouncycastle.util.io.Streams;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.pgpainless.exception.MissingDecryptionMethodException;
|
||||
import org.pgpainless.exception.ModificationDetectionException;
|
||||
import org.pgpainless.sop.SOPImpl;
|
||||
import sop.SOP;
|
||||
import sop.exception.SOPGPException;
|
||||
|
@ -21,22 +17,14 @@ import java.io.BufferedReader;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
|
||||
public class EncryptedMessageFuzzingTest {
|
||||
public class EncryptFuzzTest {
|
||||
|
||||
private final SOP sop = new SOPImpl();
|
||||
private final String password = "sw0rdf1sh";
|
||||
|
@ -53,7 +41,7 @@ public class EncryptedMessageFuzzingTest {
|
|||
List<byte[]> keys = new ArrayList<>();
|
||||
|
||||
String dir = "/org/pgpainless/sop/fuzzing/testKeys";
|
||||
InputStream in = EncryptedMessageFuzzingTest.class.getResourceAsStream(dir);
|
||||
InputStream in = EncryptFuzzTest.class.getResourceAsStream(dir);
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
|
||||
|
||||
String file;
|
||||
|
@ -62,7 +50,7 @@ public class EncryptedMessageFuzzingTest {
|
|||
continue;
|
||||
}
|
||||
|
||||
try(InputStream fIn = EncryptedMessageFuzzingTest.class.getResourceAsStream(dir + "/" + file)) {
|
||||
try(InputStream fIn = EncryptFuzzTest.class.getResourceAsStream(dir + "/" + file)) {
|
||||
byte[] b = Streams.readAll(fIn);
|
||||
keys.add(b);
|
||||
}
|
|
@ -15,7 +15,7 @@ import java.io.IOException;
|
|||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
|
||||
public class SignatureFuzzTest {
|
||||
public class VerifyFuzzTest {
|
||||
|
||||
private final SOP sop = new SOPImpl();
|
||||
private final byte[] data = "Hello, World!\n".getBytes(StandardCharsets.UTF_8);
|
Loading…
Add table
Add a link
Reference in a new issue