From 0c99c52955e8f1ed58300b2ede115baccf948442 Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Thu, 21 Jun 2018 15:19:07 +0200 Subject: [PATCH] More debug logging --- .../decryption_verification/DecryptionBuilder.java | 3 +++ .../DecryptionStreamFactory.java | 4 ++-- .../encryption_signing/EncryptionStream.java | 14 +++++++++++++- .../crypto/pgpainless/EncryptDecryptTest.java | 2 +- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/vanitasvitae/crypto/pgpainless/decryption_verification/DecryptionBuilder.java b/src/main/java/de/vanitasvitae/crypto/pgpainless/decryption_verification/DecryptionBuilder.java index 80cf1473..5bf49c8d 100644 --- a/src/main/java/de/vanitasvitae/crypto/pgpainless/decryption_verification/DecryptionBuilder.java +++ b/src/main/java/de/vanitasvitae/crypto/pgpainless/decryption_verification/DecryptionBuilder.java @@ -20,7 +20,10 @@ import java.io.InputStream; import java.util.HashSet; import java.util.Iterator; import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; +import com.sun.glass.ui.Window; import de.vanitasvitae.crypto.pgpainless.key.SecretKeyRingProtector; import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.openpgp.PGPPublicKeyRing; diff --git a/src/main/java/de/vanitasvitae/crypto/pgpainless/decryption_verification/DecryptionStreamFactory.java b/src/main/java/de/vanitasvitae/crypto/pgpainless/decryption_verification/DecryptionStreamFactory.java index b3e71b17..d651b1bf 100644 --- a/src/main/java/de/vanitasvitae/crypto/pgpainless/decryption_verification/DecryptionStreamFactory.java +++ b/src/main/java/de/vanitasvitae/crypto/pgpainless/decryption_verification/DecryptionStreamFactory.java @@ -54,7 +54,7 @@ import org.bouncycastle.openpgp.operator.bc.BcPublicKeyDataDecryptorFactory; public class DecryptionStreamFactory { private static final Logger LOGGER = Logger.getLogger(DecryptionStreamFactory.class.getName()); - private static final Level LEVEL = Level.INFO; + private static final Level LEVEL = Level.FINE; private final PGPSecretKeyRingCollection decryptionKeys; private final SecretKeyRingProtector decryptionKeyDecryptor; @@ -125,7 +125,7 @@ public class DecryptionStreamFactory { } if (pgpObj instanceof PGPLiteralData) { - LOGGER.log(LEVEL, "Encountered PGPLiteralData"); + LOGGER.log(LEVEL, "Found PGPLiteralData"); PGPLiteralData literalData = (PGPLiteralData) pgpObj; InputStream literalDataInputStream = literalData.getInputStream(); diff --git a/src/main/java/de/vanitasvitae/crypto/pgpainless/encryption_signing/EncryptionStream.java b/src/main/java/de/vanitasvitae/crypto/pgpainless/encryption_signing/EncryptionStream.java index 857bedf6..f5831d7b 100644 --- a/src/main/java/de/vanitasvitae/crypto/pgpainless/encryption_signing/EncryptionStream.java +++ b/src/main/java/de/vanitasvitae/crypto/pgpainless/encryption_signing/EncryptionStream.java @@ -21,6 +21,8 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; import de.vanitasvitae.crypto.pgpainless.algorithm.CompressionAlgorithm; import de.vanitasvitae.crypto.pgpainless.algorithm.HashAlgorithm; @@ -46,6 +48,9 @@ import org.bouncycastle.openpgp.operator.bc.BcPublicKeyKeyEncryptionMethodGenera */ public class EncryptionStream extends OutputStream { + private static final Logger LOGGER = Logger.getLogger(EncryptionStream.class.getName()); + private static final Level LEVEL = Level.FINE; + private static final int BUFFER_SIZE = 1 << 8; private List signatureGenerators = new ArrayList<>(); @@ -77,23 +82,28 @@ public class EncryptionStream extends OutputStream { // Currently outermost Stream OutputStream outerMostStream; if (asciiArmor) { + LOGGER.log(LEVEL, "Wrap encryption output in ASCII armor"); armorOutputStream = new ArmoredOutputStream(targetOutputStream); outerMostStream = armorOutputStream; } else { + LOGGER.log(LEVEL, "Encryption output will be binary"); outerMostStream = targetOutputStream; } // If we want to encrypt if (!encryptionKeys.isEmpty()) { + LOGGER.log(LEVEL, "At least one encryption key is available -> encrypt using " + symmetricKeyAlgorithm); BcPGPDataEncryptorBuilder dataEncryptorBuilder = new BcPGPDataEncryptorBuilder(symmetricKeyAlgorithm.getAlgorithmId()); + LOGGER.log(LEVEL, "Integrity protection enabled"); dataEncryptorBuilder.setWithIntegrityPacket(true); PGPEncryptedDataGenerator encryptedDataGenerator = new PGPEncryptedDataGenerator(dataEncryptorBuilder); for (PGPPublicKey key : encryptionKeys) { + LOGGER.log(LEVEL, "Encrypt for key " + Long.toHexString(key.getKeyID())); encryptedDataGenerator.addMethod(new BcPublicKeyKeyEncryptionMethodGenerator(key)); } @@ -103,8 +113,9 @@ public class EncryptionStream extends OutputStream { // If we want to sign, prepare for signing if (!signingKeys.isEmpty()) { + LOGGER.log(LEVEL, "At least one signing key is available -> sign " + hashAlgorithm + " hash of message"); for (PGPPrivateKey privateKey : signingKeys) { - + LOGGER.log(LEVEL, "Sign using key " + Long.toHexString(privateKey.getKeyID())); BcPGPContentSignerBuilder contentSignerBuilder = new BcPGPContentSignerBuilder( privateKey.getPublicKeyPacket().getAlgorithm(), hashAlgorithm.getAlgorithmId()); @@ -114,6 +125,7 @@ public class EncryptionStream extends OutputStream { } } + LOGGER.log(LEVEL, "Compress using " + compressionAlgorithm); // Compression compressedDataGenerator = new PGPCompressedDataGenerator( compressionAlgorithm.getAlgorithmId()); diff --git a/src/test/java/de/vanitasvitae/crypto/pgpainless/EncryptDecryptTest.java b/src/test/java/de/vanitasvitae/crypto/pgpainless/EncryptDecryptTest.java index 1329c8b5..3ea9fd84 100644 --- a/src/test/java/de/vanitasvitae/crypto/pgpainless/EncryptDecryptTest.java +++ b/src/test/java/de/vanitasvitae/crypto/pgpainless/EncryptDecryptTest.java @@ -133,7 +133,7 @@ public class EncryptDecryptTest extends AbstractPGPainlessTest { DecryptionStream decryptor = PGPainless.createDecryptor() .onInputStream(envelopeIn) .decryptWith(BCUtil.keyRingsToKeyRingCollection(recipient), keyDecryptor) - .verifyWith(Collections.singleton(TestKeys.ROMEO_KEY_ID), BCUtil.keyRingsToKeyRingCollection(senderPub)) + .verifyWith(Collections.singleton(senderPub.getPublicKey().getKeyID()), BCUtil.keyRingsToKeyRingCollection(senderPub)) .ignoreMissingPublicKeys() .build();