1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-17 18:02:05 +01:00

More debug logging

This commit is contained in:
Paul Schaub 2018-06-21 15:19:07 +02:00
parent 9d9edbfd9d
commit 0c99c52955
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
4 changed files with 19 additions and 4 deletions

View file

@ -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;

View file

@ -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();

View file

@ -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<PGPSignatureGenerator> 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());

View file

@ -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();