mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-11-14 00:12:06 +01:00
Fix checkstyle issues
This commit is contained in:
parent
3255eef387
commit
e56233d09a
8 changed files with 75 additions and 41 deletions
|
@ -90,7 +90,7 @@ public class MessageMetadata {
|
|||
return (LiteralData) nested;
|
||||
}
|
||||
|
||||
public static abstract class Layer {
|
||||
public abstract static class Layer {
|
||||
protected final List<SignatureVerification> verifiedSignatures = new ArrayList<>();
|
||||
protected final List<SignatureVerification.Failure> failedSignatures = new ArrayList<>();
|
||||
protected Nested child;
|
||||
|
@ -198,11 +198,11 @@ public class MessageMetadata {
|
|||
}
|
||||
|
||||
|
||||
private static abstract class LayerIterator<O> implements Iterator<O> {
|
||||
private abstract static class LayerIterator<O> implements Iterator<O> {
|
||||
private Nested current;
|
||||
Layer last = null;
|
||||
|
||||
public LayerIterator(Message message) {
|
||||
LayerIterator(Message message) {
|
||||
super();
|
||||
this.current = message.child;
|
||||
if (matches(current)) {
|
||||
|
|
|
@ -50,6 +50,8 @@ import org.pgpainless.key.protection.UnlockSecretKey;
|
|||
import org.pgpainless.signature.SignatureUtils;
|
||||
import org.pgpainless.util.Passphrase;
|
||||
import org.pgpainless.util.Tuple;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
|
@ -60,6 +62,8 @@ import java.util.List;
|
|||
|
||||
public class OpenPgpMessageInputStream extends InputStream {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(OpenPgpMessageInputStream.class);
|
||||
|
||||
protected final PDA automaton = new PDA();
|
||||
protected final ConsumerOptions options;
|
||||
protected final OpenPgpMetadata.Builder resultBuilder;
|
||||
|
@ -519,7 +523,7 @@ public class OpenPgpMessageInputStream extends InputStream {
|
|||
private final PGPOnePassSignatureList list;
|
||||
private final List<Boolean> encapsulating;
|
||||
|
||||
public PGPOnePassSignatureListWrapper(PGPOnePassSignatureList signatures, List<Boolean> encapsulating) {
|
||||
PGPOnePassSignatureListWrapper(PGPOnePassSignatureList signatures, List<Boolean> encapsulating) {
|
||||
this.list = signatures;
|
||||
this.encapsulating = encapsulating;
|
||||
}
|
||||
|
@ -529,7 +533,7 @@ public class OpenPgpMessageInputStream extends InputStream {
|
|||
}
|
||||
}
|
||||
|
||||
private static class Signatures {
|
||||
private static final class Signatures {
|
||||
final ConsumerOptions options;
|
||||
List<PGPSignature> detachedSignatures = new ArrayList<>();
|
||||
List<PGPSignature> prependedSignatures = new ArrayList<>();
|
||||
|
@ -551,7 +555,6 @@ public class OpenPgpMessageInputStream extends InputStream {
|
|||
}
|
||||
|
||||
void addPrependedSignatures(PGPSignatureList signatures) {
|
||||
System.out.println("Adding " + signatures.size() + " prepended Signatures");
|
||||
for (PGPSignature signature : signatures) {
|
||||
long keyId = SignatureUtils.determineIssuerKeyId(signature);
|
||||
PGPPublicKeyRing certificate = findCertificate(keyId);
|
||||
|
@ -561,7 +564,6 @@ public class OpenPgpMessageInputStream extends InputStream {
|
|||
}
|
||||
|
||||
void addOnePassSignatures(PGPOnePassSignatureListWrapper signatures) {
|
||||
System.out.println("Adding " + signatures.size() + " OPSs");
|
||||
for (PGPOnePassSignature ops : signatures.list) {
|
||||
PGPPublicKeyRing certificate = findCertificate(ops.getKeyID());
|
||||
initialize(ops, certificate);
|
||||
|
@ -570,7 +572,6 @@ public class OpenPgpMessageInputStream extends InputStream {
|
|||
}
|
||||
|
||||
void addOnePassCorrespondingSignatures(PGPSignatureList signatures) {
|
||||
System.out.println("Adding " + signatures.size() + " Corresponding Signatures");
|
||||
for (PGPSignature signature : signatures) {
|
||||
correspondingSignatures.add(signature);
|
||||
}
|
||||
|
@ -631,9 +632,9 @@ public class OpenPgpMessageInputStream extends InputStream {
|
|||
try {
|
||||
verified = detached.verify();
|
||||
} catch (PGPException e) {
|
||||
System.out.println(e.getMessage());
|
||||
LOGGER.debug("Cannot verify detached signature.", e);
|
||||
}
|
||||
System.out.println("Detached Signature by " + Long.toHexString(detached.getKeyID()) + " is " + (verified ? "verified" : "unverified"));
|
||||
LOGGER.debug("Detached Signature by " + Long.toHexString(detached.getKeyID()) + " is " + (verified ? "verified" : "unverified"));
|
||||
}
|
||||
|
||||
for (PGPSignature prepended : prependedSignatures) {
|
||||
|
@ -641,9 +642,9 @@ public class OpenPgpMessageInputStream extends InputStream {
|
|||
try {
|
||||
verified = prepended.verify();
|
||||
} catch (PGPException e) {
|
||||
System.out.println(e.getMessage());
|
||||
LOGGER.debug("Cannot verify prepended signature.", e);
|
||||
}
|
||||
System.out.println("Prepended Signature by " + Long.toHexString(prepended.getKeyID()) + " is " + (verified ? "verified" : "unverified"));
|
||||
LOGGER.debug("Prepended Signature by " + Long.toHexString(prepended.getKeyID()) + " is " + (verified ? "verified" : "unverified"));
|
||||
}
|
||||
|
||||
|
||||
|
@ -654,9 +655,9 @@ public class OpenPgpMessageInputStream extends InputStream {
|
|||
try {
|
||||
verified = ops.verify(signature);
|
||||
} catch (PGPException e) {
|
||||
System.out.println(e.getMessage());
|
||||
LOGGER.debug("Cannot verify OPS signature.", e);
|
||||
}
|
||||
System.out.println("One-Pass-Signature by " + Long.toHexString(ops.getKeyID()) + " is " + (verified ? "verified" : "unverified"));
|
||||
LOGGER.debug("One-Pass-Signature by " + Long.toHexString(ops.getKeyID()) + " is " + (verified ? "verified" : "unverified"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
// SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package org.pgpainless.decryption_verification.automaton;
|
||||
|
||||
import org.bouncycastle.openpgp.PGPCompressedData;
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
// SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package org.pgpainless.decryption_verification.automaton;
|
||||
|
||||
import org.pgpainless.exception.MalformedOpenPgpMessageException;
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
// SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package org.pgpainless.decryption_verification.automaton;
|
||||
|
||||
public enum StackAlphabet {
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
// SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
/**
|
||||
* Pushdown Automaton to verify validity of packet sequences according to the OpenPGP Message format.
|
||||
*/
|
||||
package org.pgpainless.decryption_verification.automaton;
|
|
@ -35,6 +35,7 @@ import org.junit.jupiter.params.provider.MethodSource;
|
|||
import org.pgpainless.PGPainless;
|
||||
import org.pgpainless.algorithm.CompressionAlgorithm;
|
||||
import org.pgpainless.algorithm.StreamEncoding;
|
||||
import org.pgpainless.algorithm.SymmetricKeyAlgorithm;
|
||||
import org.pgpainless.encryption_signing.EncryptionOptions;
|
||||
import org.pgpainless.encryption_signing.EncryptionResult;
|
||||
import org.pgpainless.encryption_signing.EncryptionStream;
|
||||
|
@ -118,7 +119,7 @@ public class OpenPgpMessageInputStreamTest {
|
|||
"=K9Zl\n" +
|
||||
"-----END PGP MESSAGE-----";
|
||||
|
||||
public static final String SIG_LIT = "" +
|
||||
public static final String SIG_COMP_LIT = "" +
|
||||
"-----BEGIN PGP MESSAGE-----\n" +
|
||||
"Version: BCPG v1.71\n" +
|
||||
"\n" +
|
||||
|
@ -235,9 +236,9 @@ public class OpenPgpMessageInputStreamTest {
|
|||
}
|
||||
|
||||
public static void genKey() throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, IOException {
|
||||
System.out.println(PGPainless.asciiArmor(
|
||||
PGPainless.generateKeyRing().modernKeyRing("Alice <alice@pgpainless.org>")
|
||||
));
|
||||
PGPainless.asciiArmor(
|
||||
PGPainless.generateKeyRing().modernKeyRing("Alice <alice@pgpainless.org>"),
|
||||
System.out);
|
||||
}
|
||||
|
||||
public static void genSIG_LIT() throws PGPException, IOException {
|
||||
|
@ -265,54 +266,46 @@ public class OpenPgpMessageInputStreamTest {
|
|||
armorOut.close();
|
||||
|
||||
String armored = out.toString();
|
||||
// CHECKSTYLE:OFF
|
||||
System.out.println(armored
|
||||
.replace("-----BEGIN PGP SIGNATURE-----\n", "-----BEGIN PGP MESSAGE-----\n")
|
||||
.replace("-----END PGP SIGNATURE-----", "-----END PGP MESSAGE-----"));
|
||||
// CHECKSTYLE:ON
|
||||
}
|
||||
|
||||
public static void genSENC_LIT() throws PGPException, IOException {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
EncryptionStream enc = PGPainless.encryptAndOrSign()
|
||||
.onOutputStream(out)
|
||||
.onOutputStream(System.out)
|
||||
.withOptions(ProducerOptions.encrypt(EncryptionOptions.get()
|
||||
.addPassphrase(Passphrase.fromPassword(PASSPHRASE)))
|
||||
.overrideCompressionAlgorithm(CompressionAlgorithm.UNCOMPRESSED));
|
||||
enc.write(PLAINTEXT.getBytes(StandardCharsets.UTF_8));
|
||||
enc.close();
|
||||
|
||||
System.out.println(out);
|
||||
}
|
||||
|
||||
public static void genPENC_COMP_LIT() throws IOException, PGPException {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.readKeyRing().secretKeyRing(KEY);
|
||||
PGPPublicKeyRing cert = PGPainless.extractCertificate(secretKeys);
|
||||
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
EncryptionStream enc = PGPainless.encryptAndOrSign()
|
||||
.onOutputStream(out)
|
||||
.onOutputStream(System.out)
|
||||
.withOptions(ProducerOptions.encrypt(EncryptionOptions.get()
|
||||
.addRecipient(cert))
|
||||
.overrideCompressionAlgorithm(CompressionAlgorithm.ZLIB));
|
||||
|
||||
Streams.pipeAll(new ByteArrayInputStream(PLAINTEXT.getBytes(StandardCharsets.UTF_8)), enc);
|
||||
enc.close();
|
||||
|
||||
System.out.println(out);
|
||||
}
|
||||
|
||||
public static void genOPS_LIT_SIG() throws PGPException, IOException {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.readKeyRing().secretKeyRing(KEY);
|
||||
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
EncryptionStream enc = PGPainless.encryptAndOrSign()
|
||||
.onOutputStream(out)
|
||||
.onOutputStream(System.out)
|
||||
.withOptions(ProducerOptions.sign(SigningOptions.get()
|
||||
.addSignature(SecretKeyRingProtector.unprotectedKeys(), secretKeys))
|
||||
.overrideCompressionAlgorithm(CompressionAlgorithm.UNCOMPRESSED));
|
||||
Streams.pipeAll(new ByteArrayInputStream(PLAINTEXT.getBytes(StandardCharsets.UTF_8)), enc);
|
||||
enc.close();
|
||||
|
||||
System.out.println(out);
|
||||
}
|
||||
|
||||
interface Processor {
|
||||
|
@ -322,7 +315,8 @@ public class OpenPgpMessageInputStreamTest {
|
|||
private static Stream<Arguments> provideMessageProcessors() {
|
||||
return Stream.of(
|
||||
Arguments.of(Named.of("read(buf,off,len)", (Processor) OpenPgpMessageInputStreamTest::processReadBuffered)),
|
||||
Arguments.of(Named.of("read()", (Processor) OpenPgpMessageInputStreamTest::processReadSequential)));
|
||||
Arguments.of(Named.of("read()", (Processor) OpenPgpMessageInputStreamTest::processReadSequential))
|
||||
);
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "Process LIT using {0}")
|
||||
|
@ -349,7 +343,8 @@ public class OpenPgpMessageInputStreamTest {
|
|||
|
||||
@ParameterizedTest(name = "Process COMP(LIT) using {0}")
|
||||
@MethodSource("provideMessageProcessors")
|
||||
public void testProcessCOMP_LIT(Processor processor) throws PGPException, IOException {
|
||||
public void testProcessCOMP_LIT(Processor processor)
|
||||
throws PGPException, IOException {
|
||||
Tuple<String, MessageMetadata> result = processor.process(COMP_LIT, ConsumerOptions.get());
|
||||
String plain = result.getA();
|
||||
assertEquals(PLAINTEXT, plain);
|
||||
|
@ -366,7 +361,8 @@ public class OpenPgpMessageInputStreamTest {
|
|||
|
||||
@ParameterizedTest(name = "Process COMP(COMP(LIT)) using {0}")
|
||||
@MethodSource("provideMessageProcessors")
|
||||
public void testProcessCOMP_COMP_LIT(Processor processor) throws PGPException, IOException {
|
||||
public void testProcessCOMP_COMP_LIT(Processor processor)
|
||||
throws PGPException, IOException {
|
||||
Tuple<String, MessageMetadata> result = processor.process(COMP_COMP_LIT, ConsumerOptions.get());
|
||||
String plain = result.getA();
|
||||
assertEquals(PLAINTEXT, plain);
|
||||
|
@ -376,29 +372,37 @@ public class OpenPgpMessageInputStreamTest {
|
|||
assertEquals(CompressionAlgorithm.ZIP, compressionAlgorithms.next());
|
||||
assertEquals(CompressionAlgorithm.BZIP2, compressionAlgorithms.next());
|
||||
assertFalse(compressionAlgorithms.hasNext());
|
||||
assertNull(metadata.getEncryptionAlgorithm());
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "Process SIG LIT using {0}")
|
||||
@ParameterizedTest(name = "Process SIG COMP(LIT) using {0}")
|
||||
@MethodSource("provideMessageProcessors")
|
||||
public void testProcessSIG_LIT(Processor processor) throws PGPException, IOException {
|
||||
public void testProcessSIG_COMP_LIT(Processor processor) throws PGPException, IOException {
|
||||
PGPPublicKeyRing cert = PGPainless.extractCertificate(
|
||||
PGPainless.readKeyRing().secretKeyRing(KEY));
|
||||
|
||||
Tuple<String, MessageMetadata> result = processor.process(SIG_LIT, ConsumerOptions.get()
|
||||
Tuple<String, MessageMetadata> result = processor.process(SIG_COMP_LIT, ConsumerOptions.get()
|
||||
.addVerificationCert(cert));
|
||||
String plain = result.getA();
|
||||
assertEquals(PLAINTEXT, plain);
|
||||
MessageMetadata metadata = result.getB();
|
||||
assertEquals(CompressionAlgorithm.ZIP, metadata.getCompressionAlgorithm());
|
||||
assertNull(metadata.getEncryptionAlgorithm());
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "Process SENC(LIT) using {0}")
|
||||
@MethodSource("provideMessageProcessors")
|
||||
public void testProcessSENC_LIT(Processor processor) throws PGPException, IOException {
|
||||
Tuple<String, MessageMetadata> result = processor.process(SENC_LIT, ConsumerOptions.get().addDecryptionPassphrase(Passphrase.fromPassword(PASSPHRASE)));
|
||||
Tuple<String, MessageMetadata> result = processor.process(SENC_LIT, ConsumerOptions.get()
|
||||
.addDecryptionPassphrase(Passphrase.fromPassword(PASSPHRASE)));
|
||||
String plain = result.getA();
|
||||
assertEquals(PLAINTEXT, plain);
|
||||
MessageMetadata metadata = result.getB();
|
||||
assertNull(metadata.getCompressionAlgorithm());
|
||||
assertEquals(SymmetricKeyAlgorithm.AES_256, metadata.getEncryptionAlgorithm());
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "Process PENC(LIT) using {0}")
|
||||
@ParameterizedTest(name = "Process PENC(COMP(LIT)) using {0}")
|
||||
@MethodSource("provideMessageProcessors")
|
||||
public void testProcessPENC_COMP_LIT(Processor processor) throws IOException, PGPException {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.readKeyRing().secretKeyRing(KEY);
|
||||
|
@ -406,6 +410,9 @@ public class OpenPgpMessageInputStreamTest {
|
|||
.addDecryptionKey(secretKeys));
|
||||
String plain = result.getA();
|
||||
assertEquals(PLAINTEXT, plain);
|
||||
MessageMetadata metadata = result.getB();
|
||||
assertEquals(CompressionAlgorithm.ZLIB, metadata.getCompressionAlgorithm());
|
||||
assertEquals(SymmetricKeyAlgorithm.AES_256, metadata.getEncryptionAlgorithm());
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "Process OPS LIT SIG using {0}")
|
||||
|
@ -416,6 +423,9 @@ public class OpenPgpMessageInputStreamTest {
|
|||
.addVerificationCert(cert));
|
||||
String plain = result.getA();
|
||||
assertEquals(PLAINTEXT, plain);
|
||||
MessageMetadata metadata = result.getB();
|
||||
assertNull(metadata.getEncryptionAlgorithm());
|
||||
assertNull(metadata.getCompressionAlgorithm());
|
||||
}
|
||||
|
||||
private static Tuple<String, MessageMetadata> processReadBuffered(String armoredMessage, ConsumerOptions options) throws PGPException, IOException {
|
||||
|
|
|
@ -9,6 +9,8 @@ import org.bouncycastle.openpgp.PGPException;
|
|||
import org.junit.jupiter.api.Test;
|
||||
import org.pgpainless.algorithm.OpenPgpPacket;
|
||||
import org.pgpainless.util.ArmoredInputStreamFactory;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
@ -18,6 +20,7 @@ import java.nio.charset.StandardCharsets;
|
|||
|
||||
public class TeeBCPGInputStreamTest {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(TeeBCPGInputStreamTest.class);
|
||||
private static final String INBAND_SIGNED = "-----BEGIN PGP MESSAGE-----\n" +
|
||||
"Version: PGPainless\n" +
|
||||
"\n" +
|
||||
|
@ -48,11 +51,11 @@ public class TeeBCPGInputStreamTest {
|
|||
|
||||
int tag;
|
||||
while ((tag = nestedTeeIn.nextPacketTag()) != -1) {
|
||||
System.out.println(OpenPgpPacket.requireFromTag(tag));
|
||||
LOGGER.debug(OpenPgpPacket.requireFromTag(tag).toString());
|
||||
Packet packet = nestedTeeIn.readPacket();
|
||||
}
|
||||
|
||||
nestedArmorOut.close();
|
||||
System.out.println(nestedOut);
|
||||
LOGGER.debug(nestedOut.toString());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue