mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-12-23 03:17:58 +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.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Set;
|
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 de.vanitasvitae.crypto.pgpainless.key.SecretKeyRingProtector;
|
||||||
import org.bouncycastle.openpgp.PGPException;
|
import org.bouncycastle.openpgp.PGPException;
|
||||||
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
||||||
|
|
|
@ -54,7 +54,7 @@ import org.bouncycastle.openpgp.operator.bc.BcPublicKeyDataDecryptorFactory;
|
||||||
public class DecryptionStreamFactory {
|
public class DecryptionStreamFactory {
|
||||||
|
|
||||||
private static final Logger LOGGER = Logger.getLogger(DecryptionStreamFactory.class.getName());
|
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 PGPSecretKeyRingCollection decryptionKeys;
|
||||||
private final SecretKeyRingProtector decryptionKeyDecryptor;
|
private final SecretKeyRingProtector decryptionKeyDecryptor;
|
||||||
|
@ -125,7 +125,7 @@ public class DecryptionStreamFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pgpObj instanceof PGPLiteralData) {
|
if (pgpObj instanceof PGPLiteralData) {
|
||||||
LOGGER.log(LEVEL, "Encountered PGPLiteralData");
|
LOGGER.log(LEVEL, "Found PGPLiteralData");
|
||||||
PGPLiteralData literalData = (PGPLiteralData) pgpObj;
|
PGPLiteralData literalData = (PGPLiteralData) pgpObj;
|
||||||
InputStream literalDataInputStream = literalData.getInputStream();
|
InputStream literalDataInputStream = literalData.getInputStream();
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,8 @@ import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
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.CompressionAlgorithm;
|
||||||
import de.vanitasvitae.crypto.pgpainless.algorithm.HashAlgorithm;
|
import de.vanitasvitae.crypto.pgpainless.algorithm.HashAlgorithm;
|
||||||
|
@ -46,6 +48,9 @@ import org.bouncycastle.openpgp.operator.bc.BcPublicKeyKeyEncryptionMethodGenera
|
||||||
*/
|
*/
|
||||||
public class EncryptionStream extends OutputStream {
|
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 static final int BUFFER_SIZE = 1 << 8;
|
||||||
|
|
||||||
private List<PGPSignatureGenerator> signatureGenerators = new ArrayList<>();
|
private List<PGPSignatureGenerator> signatureGenerators = new ArrayList<>();
|
||||||
|
@ -77,23 +82,28 @@ public class EncryptionStream extends OutputStream {
|
||||||
// Currently outermost Stream
|
// Currently outermost Stream
|
||||||
OutputStream outerMostStream;
|
OutputStream outerMostStream;
|
||||||
if (asciiArmor) {
|
if (asciiArmor) {
|
||||||
|
LOGGER.log(LEVEL, "Wrap encryption output in ASCII armor");
|
||||||
armorOutputStream = new ArmoredOutputStream(targetOutputStream);
|
armorOutputStream = new ArmoredOutputStream(targetOutputStream);
|
||||||
outerMostStream = armorOutputStream;
|
outerMostStream = armorOutputStream;
|
||||||
} else {
|
} else {
|
||||||
|
LOGGER.log(LEVEL, "Encryption output will be binary");
|
||||||
outerMostStream = targetOutputStream;
|
outerMostStream = targetOutputStream;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we want to encrypt
|
// If we want to encrypt
|
||||||
if (!encryptionKeys.isEmpty()) {
|
if (!encryptionKeys.isEmpty()) {
|
||||||
|
LOGGER.log(LEVEL, "At least one encryption key is available -> encrypt using " + symmetricKeyAlgorithm);
|
||||||
BcPGPDataEncryptorBuilder dataEncryptorBuilder =
|
BcPGPDataEncryptorBuilder dataEncryptorBuilder =
|
||||||
new BcPGPDataEncryptorBuilder(symmetricKeyAlgorithm.getAlgorithmId());
|
new BcPGPDataEncryptorBuilder(symmetricKeyAlgorithm.getAlgorithmId());
|
||||||
|
|
||||||
|
LOGGER.log(LEVEL, "Integrity protection enabled");
|
||||||
dataEncryptorBuilder.setWithIntegrityPacket(true);
|
dataEncryptorBuilder.setWithIntegrityPacket(true);
|
||||||
|
|
||||||
PGPEncryptedDataGenerator encryptedDataGenerator =
|
PGPEncryptedDataGenerator encryptedDataGenerator =
|
||||||
new PGPEncryptedDataGenerator(dataEncryptorBuilder);
|
new PGPEncryptedDataGenerator(dataEncryptorBuilder);
|
||||||
|
|
||||||
for (PGPPublicKey key : encryptionKeys) {
|
for (PGPPublicKey key : encryptionKeys) {
|
||||||
|
LOGGER.log(LEVEL, "Encrypt for key " + Long.toHexString(key.getKeyID()));
|
||||||
encryptedDataGenerator.addMethod(new BcPublicKeyKeyEncryptionMethodGenerator(key));
|
encryptedDataGenerator.addMethod(new BcPublicKeyKeyEncryptionMethodGenerator(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,8 +113,9 @@ public class EncryptionStream extends OutputStream {
|
||||||
|
|
||||||
// If we want to sign, prepare for signing
|
// If we want to sign, prepare for signing
|
||||||
if (!signingKeys.isEmpty()) {
|
if (!signingKeys.isEmpty()) {
|
||||||
|
LOGGER.log(LEVEL, "At least one signing key is available -> sign " + hashAlgorithm + " hash of message");
|
||||||
for (PGPPrivateKey privateKey : signingKeys) {
|
for (PGPPrivateKey privateKey : signingKeys) {
|
||||||
|
LOGGER.log(LEVEL, "Sign using key " + Long.toHexString(privateKey.getKeyID()));
|
||||||
BcPGPContentSignerBuilder contentSignerBuilder = new BcPGPContentSignerBuilder(
|
BcPGPContentSignerBuilder contentSignerBuilder = new BcPGPContentSignerBuilder(
|
||||||
privateKey.getPublicKeyPacket().getAlgorithm(), hashAlgorithm.getAlgorithmId());
|
privateKey.getPublicKeyPacket().getAlgorithm(), hashAlgorithm.getAlgorithmId());
|
||||||
|
|
||||||
|
@ -114,6 +125,7 @@ public class EncryptionStream extends OutputStream {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LOGGER.log(LEVEL, "Compress using " + compressionAlgorithm);
|
||||||
// Compression
|
// Compression
|
||||||
compressedDataGenerator = new PGPCompressedDataGenerator(
|
compressedDataGenerator = new PGPCompressedDataGenerator(
|
||||||
compressionAlgorithm.getAlgorithmId());
|
compressionAlgorithm.getAlgorithmId());
|
||||||
|
|
|
@ -133,7 +133,7 @@ public class EncryptDecryptTest extends AbstractPGPainlessTest {
|
||||||
DecryptionStream decryptor = PGPainless.createDecryptor()
|
DecryptionStream decryptor = PGPainless.createDecryptor()
|
||||||
.onInputStream(envelopeIn)
|
.onInputStream(envelopeIn)
|
||||||
.decryptWith(BCUtil.keyRingsToKeyRingCollection(recipient), keyDecryptor)
|
.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()
|
.ignoreMissingPublicKeys()
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue