mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-12-22 19:08:00 +01:00
More debug logging
This commit is contained in:
parent
9d9edbfd9d
commit
0c99c52955
4 changed files with 19 additions and 4 deletions
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
Loading…
Reference in a new issue