diff --git a/pgpainless-core/src/main/java/org/pgpainless/decryption_verification/DecryptionStream.java b/pgpainless-core/src/main/java/org/pgpainless/decryption_verification/DecryptionStream.java index 366aafc9..ce2586f8 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/decryption_verification/DecryptionStream.java +++ b/pgpainless-core/src/main/java/org/pgpainless/decryption_verification/DecryptionStream.java @@ -1,5 +1,5 @@ /* - * Copyright 2018 Paul Schaub. + * Copyright 2018-2020 Paul Schaub. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,11 +18,15 @@ package org.pgpainless.decryption_verification; import javax.annotation.Nonnull; import java.io.IOException; import java.io.InputStream; +import java.util.logging.Level; +import java.util.logging.Logger; import org.bouncycastle.openpgp.PGPException; public class DecryptionStream extends InputStream { + private static final Logger LOGGER = Logger.getLogger(DecryptionStream.class.getName()); + private final InputStream inputStream; private final OpenPgpMetadata.Builder resultBuilder; private boolean isClosed = false; @@ -59,7 +63,7 @@ public class DecryptionStream extends InputStream { try { s.setVerified(s.getSignature().verify()); } catch (PGPException e) { - e.printStackTrace(); + LOGGER.log(Level.WARNING, "Could not verify signature of key " + s.getFingerprint(), e); } } } diff --git a/pgpainless-core/src/main/java/org/pgpainless/decryption_verification/DetachedSignature.java b/pgpainless-core/src/main/java/org/pgpainless/decryption_verification/DetachedSignature.java index daf08007..28db7e04 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/decryption_verification/DetachedSignature.java +++ b/pgpainless-core/src/main/java/org/pgpainless/decryption_verification/DetachedSignature.java @@ -1,3 +1,18 @@ +/* + * Copyright 2020 Paul Schaub. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.pgpainless.decryption_verification; import org.bouncycastle.openpgp.PGPSignature; diff --git a/pgpainless-core/src/main/java/org/pgpainless/decryption_verification/OnePassSignature.java b/pgpainless-core/src/main/java/org/pgpainless/decryption_verification/OnePassSignature.java index 4d2cfccf..65736069 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/decryption_verification/OnePassSignature.java +++ b/pgpainless-core/src/main/java/org/pgpainless/decryption_verification/OnePassSignature.java @@ -1,3 +1,18 @@ +/* + * Copyright 2020 Paul Schaub. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.pgpainless.decryption_verification; import org.bouncycastle.openpgp.PGPException; diff --git a/pgpainless-core/src/main/java/org/pgpainless/encryption_signing/EncryptionBuilder.java b/pgpainless-core/src/main/java/org/pgpainless/encryption_signing/EncryptionBuilder.java index dc498f8b..12c1a8b2 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/encryption_signing/EncryptionBuilder.java +++ b/pgpainless-core/src/main/java/org/pgpainless/encryption_signing/EncryptionBuilder.java @@ -15,7 +15,6 @@ */ package org.pgpainless.encryption_signing; -import javax.annotation.Nonnull; import java.io.IOException; import java.io.OutputStream; import java.util.HashSet; @@ -23,6 +22,7 @@ import java.util.Iterator; import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; +import javax.annotation.Nonnull; import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.openpgp.PGPPrivateKey; @@ -32,7 +32,6 @@ import org.bouncycastle.openpgp.PGPPublicKeyRingCollection; import org.bouncycastle.openpgp.PGPSecretKey; import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.bouncycastle.openpgp.PGPSecretKeyRingCollection; -import org.jetbrains.annotations.NotNull; import org.pgpainless.algorithm.CompressionAlgorithm; import org.pgpainless.algorithm.HashAlgorithm; import org.pgpainless.algorithm.SymmetricKeyAlgorithm; @@ -41,10 +40,10 @@ import org.pgpainless.key.OpenPgpV4Fingerprint; import org.pgpainless.key.protection.SecretKeyRingProtector; import org.pgpainless.key.selection.key.PublicKeySelectionStrategy; import org.pgpainless.key.selection.key.SecretKeySelectionStrategy; -import org.pgpainless.key.selection.key.util.And; import org.pgpainless.key.selection.key.impl.EncryptionKeySelectionStrategy; import org.pgpainless.key.selection.key.impl.NoRevocation; import org.pgpainless.key.selection.key.impl.SignatureKeySelectionStrategy; +import org.pgpainless.key.selection.key.util.And; import org.pgpainless.key.selection.keyring.PublicKeyRingSelectionStrategy; import org.pgpainless.key.selection.keyring.SecretKeyRingSelectionStrategy; import org.pgpainless.util.MultiMap; diff --git a/pgpainless-core/src/main/java/org/pgpainless/encryption_signing/EncryptionStream.java b/pgpainless-core/src/main/java/org/pgpainless/encryption_signing/EncryptionStream.java index 872abb90..23821b94 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/encryption_signing/EncryptionStream.java +++ b/pgpainless-core/src/main/java/org/pgpainless/encryption_signing/EncryptionStream.java @@ -15,19 +15,16 @@ */ package org.pgpainless.encryption_signing; -import javax.annotation.Nonnull; import java.io.IOException; import java.io.OutputStream; -import java.util.ArrayList; import java.util.Collections; import java.util.Date; -import java.util.HashSet; -import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Level; import java.util.logging.Logger; +import javax.annotation.Nonnull; import org.bouncycastle.bcpg.ArmoredOutputStream; import org.bouncycastle.bcpg.BCPGOutputStream; @@ -38,10 +35,8 @@ import org.bouncycastle.openpgp.PGPLiteralData; import org.bouncycastle.openpgp.PGPLiteralDataGenerator; import org.bouncycastle.openpgp.PGPPrivateKey; import org.bouncycastle.openpgp.PGPPublicKey; -import org.bouncycastle.openpgp.PGPSecretKey; import org.bouncycastle.openpgp.PGPSignature; import org.bouncycastle.openpgp.PGPSignatureGenerator; -import org.bouncycastle.openpgp.operator.bc.BcKeyFingerprintCalculator; import org.bouncycastle.openpgp.operator.bc.BcPGPContentSignerBuilder; import org.bouncycastle.openpgp.operator.bc.BcPGPDataEncryptorBuilder; import org.bouncycastle.openpgp.operator.bc.BcPublicKeyKeyEncryptionMethodGenerator; diff --git a/pgpainless-core/src/test/java/org/pgpainless/decryption_verification/DecryptAndVerifyMessageTest.java b/pgpainless-core/src/test/java/org/pgpainless/decryption_verification/DecryptAndVerifyMessageTest.java index 838e230b..104bf1c7 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/decryption_verification/DecryptAndVerifyMessageTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/decryption_verification/DecryptAndVerifyMessageTest.java @@ -80,7 +80,7 @@ public class DecryptAndVerifyMessageTest { assertTrue(metadata.isVerified()); assertEquals(CompressionAlgorithm.ZLIB, metadata.getCompressionAlgorithm()); assertEquals(SymmetricKeyAlgorithm.AES_256, metadata.getSymmetricKeyAlgorithm()); - //assertEquals(1, metadata.getSignatureKeyIDs().size()); + assertEquals(1, metadata.getSignatures().size()); assertEquals(1, metadata.getVerifiedSignatureKeyFingerprints().size()); assertTrue(metadata.containsVerifiedSignatureFrom(TestKeys.JULIET_FINGERPRINT)); assertEquals(TestKeys.JULIET_FINGERPRINT, metadata.getDecryptionFingerprint()); diff --git a/pgpainless-core/src/test/java/org/pgpainless/encryption_signing/EncryptDecryptTest.java b/pgpainless-core/src/test/java/org/pgpainless/encryption_signing/EncryptDecryptTest.java index e079adf1..d4a18227 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/encryption_signing/EncryptDecryptTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/encryption_signing/EncryptDecryptTest.java @@ -209,7 +209,9 @@ public class EncryptDecryptTest { armorOut.close(); String armorSig = sigOut.toString(); + // CHECKSTYLE:OFF System.out.println(armorSig); + // CHECKSTYLE:ON inputStream = new ByteArrayInputStream(testMessage.getBytes()); DecryptionStream verifier = PGPainless.createDecryptor().onInputStream(inputStream)