diff --git a/pgpainless-core/build.gradle b/pgpainless-core/build.gradle index 3c748a37..937daf5f 100644 --- a/pgpainless-core/build.gradle +++ b/pgpainless-core/build.gradle @@ -4,6 +4,7 @@ plugins { dependencies { testImplementation "org.junit.jupiter:junit-jupiter-api:$junitVersion" + testImplementation "org.junit.jupiter:junit-jupiter-params:$junitVersion" testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junitVersion" /* diff --git a/pgpainless-core/src/main/java/org/pgpainless/implementation/ImplementationFactory.java b/pgpainless-core/src/main/java/org/pgpainless/implementation/ImplementationFactory.java index 9fdd3deb..4e5bd7d5 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/implementation/ImplementationFactory.java +++ b/pgpainless-core/src/main/java/org/pgpainless/implementation/ImplementationFactory.java @@ -46,6 +46,11 @@ import org.pgpainless.util.Passphrase; public abstract class ImplementationFactory { + enum FactoryType { + bc, + jce + } + private static ImplementationFactory FACTORY_IMPLEMENTATION = new BcImplementationFactory(); public static void setFactoryImplementation(ImplementationFactory implementation) { diff --git a/pgpainless-core/src/main/java/org/pgpainless/util/TestUtil.java b/pgpainless-core/src/main/java/org/pgpainless/util/TestUtil.java new file mode 100644 index 00000000..7c48800e --- /dev/null +++ b/pgpainless-core/src/main/java/org/pgpainless/util/TestUtil.java @@ -0,0 +1,38 @@ +/* + * Copyright 2021 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.util; + +import org.pgpainless.implementation.BcImplementationFactory; +import org.pgpainless.implementation.ImplementationFactory; +import org.pgpainless.implementation.JceImplementationFactory; + +import java.util.Arrays; +import java.util.List; + +/** + * Utility class used to provide all available implementations of {@link ImplementationFactory} for parametrized tests. + */ +public class TestUtil { + + private static final List IMPLEMENTATIONS = Arrays.asList( + new BcImplementationFactory(), + new JceImplementationFactory() + ); + + public static List provideImplementationFactories() { + return IMPLEMENTATIONS; + } +} 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 67ba24b1..3dae999f 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 @@ -31,10 +31,12 @@ import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.bouncycastle.openpgp.PGPSecretKeyRingCollection; import org.bouncycastle.util.io.Streams; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.pgpainless.PGPainless; import org.pgpainless.algorithm.CompressionAlgorithm; import org.pgpainless.algorithm.SymmetricKeyAlgorithm; +import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.key.TestKeys; import org.pgpainless.key.protection.UnprotectedKeysProtector; @@ -52,8 +54,10 @@ public class DecryptAndVerifyMessageTest { romeo = TestKeys.getRomeoSecretKeyRing(); } - @Test - public void decryptMessageAndVerifySignatureTest() throws Exception { + @ParameterizedTest + @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories") + public void decryptMessageAndVerifySignatureTest(ImplementationFactory implementationFactory) throws Exception { + ImplementationFactory.setFactoryImplementation(implementationFactory); String encryptedMessage = TestKeys.MSG_SIGN_CRYPT_JULIET_JULIET; DecryptionStream decryptor = PGPainless.decryptAndOrVerify() diff --git a/pgpainless-core/src/test/java/org/pgpainless/decryption_verification/DecryptHiddenRecipientMessage.java b/pgpainless-core/src/test/java/org/pgpainless/decryption_verification/DecryptHiddenRecipientMessage.java index 111cb228..4b388cba 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/decryption_verification/DecryptHiddenRecipientMessage.java +++ b/pgpainless-core/src/test/java/org/pgpainless/decryption_verification/DecryptHiddenRecipientMessage.java @@ -29,9 +29,11 @@ import org.bouncycastle.openpgp.PGPPublicKey; import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.bouncycastle.openpgp.PGPSecretKeyRingCollection; import org.bouncycastle.util.io.Streams; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.pgpainless.PGPainless; import org.pgpainless.algorithm.KeyFlag; +import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.key.OpenPgpV4Fingerprint; import org.pgpainless.key.protection.SecretKeyRingProtector; import org.pgpainless.key.util.KeyRingUtils; @@ -39,8 +41,10 @@ import org.pgpainless.util.selection.key.impl.EncryptionKeySelectionStrategy; public class DecryptHiddenRecipientMessage { - @Test - public void testDecryptionWithWildcardRecipient() throws IOException, PGPException { + @ParameterizedTest + @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories") + public void testDecryptionWithWildcardRecipient(ImplementationFactory implementationFactory) throws IOException, PGPException { + ImplementationFactory.setFactoryImplementation(implementationFactory); String secretKeyAscii = "-----BEGIN PGP PRIVATE KEY BLOCK-----\n" + "Comment: Bob's OpenPGP Transferable Secret Key\n" + "\n" + diff --git a/pgpainless-core/src/test/java/org/pgpainless/decryption_verification/ModificationDetectionTests.java b/pgpainless-core/src/test/java/org/pgpainless/decryption_verification/ModificationDetectionTests.java index a51b937e..f9a870da 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/decryption_verification/ModificationDetectionTests.java +++ b/pgpainless-core/src/test/java/org/pgpainless/decryption_verification/ModificationDetectionTests.java @@ -29,8 +29,10 @@ import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.bouncycastle.openpgp.PGPSecretKeyRingCollection; import org.bouncycastle.util.io.Streams; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.pgpainless.PGPainless; +import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.key.protection.SecretKeyRingProtector; public class ModificationDetectionTests { @@ -118,8 +120,10 @@ public class ModificationDetectionTests { "=miES\n" + "-----END PGP PRIVATE KEY BLOCK-----\n"; - @Test - public void testMissingMDC() throws IOException, PGPException { + @ParameterizedTest + @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories") + public void testMissingMDC(ImplementationFactory implementationFactory) throws IOException, PGPException { + ImplementationFactory.setFactoryImplementation(implementationFactory); String message = "-----BEGIN PGP MESSAGE-----\n" + "\n" + "wcDMA3wvqk35PDeyAQwAnTmchA6ve/aF7cPEnyJSb9Ot61LSIMrU3+RaEdA90qn4\n" + @@ -151,8 +155,10 @@ public class ModificationDetectionTests { }); } - @Test - public void tamperedCiphertextTest() throws IOException, PGPException { + @ParameterizedTest + @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories") + public void tamperedCiphertextTest(ImplementationFactory implementationFactory) throws IOException, PGPException { + ImplementationFactory.setFactoryImplementation(implementationFactory); String message = "-----BEGIN PGP MESSAGE-----\n" + "\n" + "wcDMA3wvqk35PDeyAQwAnTmchA6ve/aF7cPEnyJSb9Ot61LSIMrU3+RaEdA90qn4\n" + @@ -180,8 +186,10 @@ public class ModificationDetectionTests { assertThrows(IOException.class, decryptionStream::close); } - @Test - public void tamperedMDCTest() throws IOException, PGPException { + @ParameterizedTest + @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories") + public void tamperedMDCTest(ImplementationFactory implementationFactory) throws IOException, PGPException { + ImplementationFactory.setFactoryImplementation(implementationFactory); String message = "-----BEGIN PGP MESSAGE-----\n" + "\n" + "wcDMA3wvqk35PDeyAQwAnTmchA6ve/aF7cPEnyJSb9Ot61LSIMrU3+RaEdA90qn4\n" + diff --git a/pgpainless-core/src/test/java/org/pgpainless/decryption_verification/RecursionDepthTest.java b/pgpainless-core/src/test/java/org/pgpainless/decryption_verification/RecursionDepthTest.java index 7b66561c..30f8b609 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/decryption_verification/RecursionDepthTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/decryption_verification/RecursionDepthTest.java @@ -27,8 +27,10 @@ import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.bouncycastle.openpgp.PGPSecretKeyRingCollection; import org.bouncycastle.util.io.Streams; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.pgpainless.PGPainless; +import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.key.protection.SecretKeyRingProtector; public class RecursionDepthTest { @@ -40,8 +42,10 @@ public class RecursionDepthTest { * @throws IOException * @throws PGPException */ - @Test - public void decryptionAbortsWhenMaximumRecursionDepthReachedTest() throws IOException, PGPException { + @ParameterizedTest + @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories") + public void decryptionAbortsWhenMaximumRecursionDepthReachedTest(ImplementationFactory implementationFactory) throws IOException, PGPException { + ImplementationFactory.setFactoryImplementation(implementationFactory); String key = "-----BEGIN PGP PRIVATE KEY BLOCK-----\n" + "Comment: Bob's OpenPGP Transferable Secret Key\n" + "\n" + 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 a5028d99..b4832fa6 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 @@ -36,17 +36,19 @@ import org.bouncycastle.openpgp.PGPPublicKeyRing; import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.bouncycastle.openpgp.PGPSignature; import org.bouncycastle.util.io.Streams; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.pgpainless.PGPainless; import org.pgpainless.algorithm.KeyFlag; import org.pgpainless.algorithm.SymmetricKeyAlgorithm; import org.pgpainless.decryption_verification.DecryptionStream; import org.pgpainless.decryption_verification.OpenPgpMetadata; +import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.key.OpenPgpV4Fingerprint; import org.pgpainless.key.TestKeys; import org.pgpainless.key.generation.KeySpec; -import org.pgpainless.key.generation.type.elgamal.ElGamal; import org.pgpainless.key.generation.type.KeyType; +import org.pgpainless.key.generation.type.elgamal.ElGamal; import org.pgpainless.key.generation.type.elgamal.ElGamalLength; import org.pgpainless.key.generation.type.rsa.RsaLength; import org.pgpainless.key.protection.SecretKeyRingProtector; @@ -69,9 +71,11 @@ public class EncryptDecryptTest { "Unfold the imagined happiness that both\n" + "Receive in either by this dear encounter."; - @Test - public void freshKeysRsaToElGamalTest() + @ParameterizedTest + @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories") + public void freshKeysRsaToElGamalTest(ImplementationFactory implementationFactory) throws PGPException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, IOException { + ImplementationFactory.setFactoryImplementation(implementationFactory); PGPSecretKeyRing sender = PGPainless.generateKeyRing().simpleRsaKeyRing("romeo@montague.lit", RsaLength._3072); PGPSecretKeyRing recipient = PGPainless.generateKeyRing() .withSubKey(KeySpec.getBuilder(ElGamal.withLength(ElGamalLength._3072)).withKeyFlags(KeyFlag.ENCRYPT_STORAGE, KeyFlag.ENCRYPT_COMMS).withDefaultAlgorithms()) @@ -81,44 +85,54 @@ public class EncryptDecryptTest { encryptDecryptForSecretKeyRings(sender, recipient); } - @Test - public void freshKeysRsaToRsaTest() + @ParameterizedTest + @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories") + public void freshKeysRsaToRsaTest(ImplementationFactory implementationFactory) throws PGPException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, IOException { + ImplementationFactory.setFactoryImplementation(implementationFactory); PGPSecretKeyRing sender = PGPainless.generateKeyRing().simpleRsaKeyRing("romeo@montague.lit", RsaLength._3072); PGPSecretKeyRing recipient = PGPainless.generateKeyRing().simpleRsaKeyRing("juliet@capulet.lit", RsaLength._3072); encryptDecryptForSecretKeyRings(sender, recipient); } - @Test - public void freshKeysEcToEcTest() + @ParameterizedTest + @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories") + public void freshKeysEcToEcTest(ImplementationFactory implementationFactory) throws IOException, PGPException, NoSuchAlgorithmException, InvalidAlgorithmParameterException { + ImplementationFactory.setFactoryImplementation(implementationFactory); PGPSecretKeyRing sender = PGPainless.generateKeyRing().simpleEcKeyRing("romeo@montague.lit"); PGPSecretKeyRing recipient = PGPainless.generateKeyRing().simpleEcKeyRing("juliet@capulet.lit"); encryptDecryptForSecretKeyRings(sender, recipient); } - @Test - public void freshKeysEcToRsaTest() + @ParameterizedTest + @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories") + public void freshKeysEcToRsaTest(ImplementationFactory implementationFactory) throws PGPException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, IOException { + ImplementationFactory.setFactoryImplementation(implementationFactory); PGPSecretKeyRing sender = PGPainless.generateKeyRing().simpleEcKeyRing("romeo@montague.lit"); PGPSecretKeyRing recipient = PGPainless.generateKeyRing().simpleRsaKeyRing("juliet@capulet.lit", RsaLength._3072); encryptDecryptForSecretKeyRings(sender, recipient); } - @Test - public void freshKeysRsaToEcTest() + @ParameterizedTest + @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories") + public void freshKeysRsaToEcTest(ImplementationFactory implementationFactory) throws PGPException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, IOException { + ImplementationFactory.setFactoryImplementation(implementationFactory); PGPSecretKeyRing sender = PGPainless.generateKeyRing().simpleRsaKeyRing("romeo@montague.lit", RsaLength._3072); PGPSecretKeyRing recipient = PGPainless.generateKeyRing().simpleEcKeyRing("juliet@capulet.lit"); encryptDecryptForSecretKeyRings(sender, recipient); } - @Test - public void existingRsaKeysTest() throws IOException, PGPException { + @ParameterizedTest + @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories") + public void existingRsaKeysTest(ImplementationFactory implementationFactory) throws IOException, PGPException { + ImplementationFactory.setFactoryImplementation(implementationFactory); PGPSecretKeyRing sender = TestKeys.getJulietSecretKeyRing(); PGPSecretKeyRing recipient = TestKeys.getRomeoSecretKeyRing(); @@ -187,8 +201,11 @@ public class EncryptDecryptTest { assertTrue(result.isVerified()); } - @Test - public void testDetachedSignatureCreationAndVerification() throws IOException, PGPException { + @ParameterizedTest + @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories") + public void testDetachedSignatureCreationAndVerification(ImplementationFactory implementationFactory) throws IOException, PGPException { + ImplementationFactory.setFactoryImplementation(implementationFactory); + PGPSecretKeyRing signingKeys = TestKeys.getJulietSecretKeyRing(); SecretKeyRingProtector keyRingProtector = new UnprotectedKeysProtector(); byte[] data = testMessage.getBytes(); @@ -230,8 +247,10 @@ public class EncryptDecryptTest { assertFalse(metadata.getVerifiedSignatures().isEmpty()); } - @Test - public void testOnePassSignatureCreationAndVerification() throws IOException, PGPException { + @ParameterizedTest + @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories") + public void testOnePassSignatureCreationAndVerification(ImplementationFactory implementationFactory) throws IOException, PGPException { + ImplementationFactory.setFactoryImplementation(implementationFactory); PGPSecretKeyRing signingKeys = TestKeys.getJulietSecretKeyRing(); SecretKeyRingProtector keyRingProtector = new UnprotectedKeysProtector(); byte[] data = testMessage.getBytes(); diff --git a/pgpainless-core/src/test/java/org/pgpainless/encryption_signing/EncryptionStreamClosedTest.java b/pgpainless-core/src/test/java/org/pgpainless/encryption_signing/EncryptionStreamClosedTest.java index 93797281..7efec438 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/encryption_signing/EncryptionStreamClosedTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/encryption_signing/EncryptionStreamClosedTest.java @@ -22,14 +22,18 @@ import java.io.IOException; import java.io.OutputStream; import org.bouncycastle.openpgp.PGPException; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.pgpainless.PGPainless; +import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.util.Passphrase; public class EncryptionStreamClosedTest { - @Test - public void testStreamHasToBeClosedBeforeGetResultCanBeCalled() throws IOException, PGPException { + @ParameterizedTest + @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories") + public void testStreamHasToBeClosedBeforeGetResultCanBeCalled(ImplementationFactory implementationFactory) throws IOException, PGPException { + ImplementationFactory.setFactoryImplementation(implementationFactory); OutputStream out = new ByteArrayOutputStream(); EncryptionStream stream = PGPainless.encryptAndOrSign() .onOutputStream(out) diff --git a/pgpainless-core/src/test/java/org/pgpainless/encryption_signing/SigningTest.java b/pgpainless-core/src/test/java/org/pgpainless/encryption_signing/SigningTest.java index 357d5e53..feb01915 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/encryption_signing/SigningTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/encryption_signing/SigningTest.java @@ -34,13 +34,15 @@ import org.bouncycastle.openpgp.PGPSecretKey; import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.bouncycastle.openpgp.PGPSecretKeyRingCollection; import org.bouncycastle.util.io.Streams; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.pgpainless.PGPainless; import org.pgpainless.algorithm.CompressionAlgorithm; import org.pgpainless.algorithm.HashAlgorithm; import org.pgpainless.algorithm.SymmetricKeyAlgorithm; import org.pgpainless.decryption_verification.DecryptionStream; import org.pgpainless.decryption_verification.OpenPgpMetadata; +import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.key.OpenPgpV4Fingerprint; import org.pgpainless.key.TestKeys; import org.pgpainless.key.protection.SecretKeyRingProtector; @@ -49,8 +51,10 @@ import org.pgpainless.util.selection.key.impl.SignatureKeySelectionStrategy; public class SigningTest { - @Test - public void testEncryptionAndSignatureVerification() throws IOException, PGPException { + @ParameterizedTest + @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories") + public void testEncryptionAndSignatureVerification(ImplementationFactory implementationFactory) throws IOException, PGPException { + ImplementationFactory.setFactoryImplementation(implementationFactory); PGPPublicKeyRing julietKeys = TestKeys.getJulietPublicKeyRing(); PGPPublicKeyRing romeoKeys = TestKeys.getRomeoPublicKeyRing(); diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/BouncycastleExportSubkeys.java b/pgpainless-core/src/test/java/org/pgpainless/key/BouncycastleExportSubkeys.java index ba3ccba8..3478502e 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/key/BouncycastleExportSubkeys.java +++ b/pgpainless-core/src/test/java/org/pgpainless/key/BouncycastleExportSubkeys.java @@ -40,13 +40,17 @@ import org.bouncycastle.openpgp.operator.PGPDigestCalculator; import org.bouncycastle.openpgp.operator.jcajce.JcaPGPContentSignerBuilder; import org.bouncycastle.openpgp.operator.jcajce.JcaPGPDigestCalculatorProviderBuilder; import org.bouncycastle.openpgp.operator.jcajce.JcaPGPKeyPair; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.provider.ProviderFactory; public class BouncycastleExportSubkeys { - @Test - public void testExportImport() throws NoSuchAlgorithmException, InvalidAlgorithmParameterException, PGPException { + @ParameterizedTest + @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories") + public void testExportImport(ImplementationFactory implementationFactory) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException, PGPException { + ImplementationFactory.setFactoryImplementation(implementationFactory); KeyPairGenerator generator; KeyPair pair; diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/ImportExportKeyTest.java b/pgpainless-core/src/test/java/org/pgpainless/key/ImportExportKeyTest.java index a6c81578..22b0af1a 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/key/ImportExportKeyTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/key/ImportExportKeyTest.java @@ -25,6 +25,9 @@ import org.bouncycastle.openpgp.PGPPublicKeyRing; import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.bouncycastle.openpgp.operator.bc.BcKeyFingerprintCalculator; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +import org.pgpainless.implementation.ImplementationFactory; public class ImportExportKeyTest { @@ -32,8 +35,10 @@ public class ImportExportKeyTest { * Test the export and import of a key ring with sub keys. * @throws IOException in case of a IO error */ - @Test - public void testExportImportPublicKeyRing() throws IOException { + @ParameterizedTest + @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories") + public void testExportImportPublicKeyRing(ImplementationFactory implementationFactory) throws IOException { + ImplementationFactory.setFactoryImplementation(implementationFactory); PGPPublicKeyRing publicKeys = TestKeys.getJulietPublicKeyRing(); BcKeyFingerprintCalculator calc = new BcKeyFingerprintCalculator(); diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/generation/BrainpoolKeyGeneration.java b/pgpainless-core/src/test/java/org/pgpainless/key/generation/BrainpoolKeyGeneration.java index 106298f4..a948b6fa 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/key/generation/BrainpoolKeyGeneration.java +++ b/pgpainless-core/src/test/java/org/pgpainless/key/generation/BrainpoolKeyGeneration.java @@ -17,25 +17,30 @@ package org.pgpainless.key.generation; import static org.junit.jupiter.api.Assertions.assertEquals; -import java.io.IOException; import java.security.InvalidAlgorithmParameterException; import java.security.NoSuchAlgorithmException; import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.openpgp.PGPPublicKey; import org.bouncycastle.openpgp.PGPSecretKeyRing; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.pgpainless.PGPainless; import org.pgpainless.algorithm.KeyFlag; import org.pgpainless.algorithm.PublicKeyAlgorithm; +import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.key.generation.type.KeyType; import org.pgpainless.key.generation.type.ecc.EllipticCurve; import org.pgpainless.key.info.KeyInfo; public class BrainpoolKeyGeneration { - @Test - public void generateEcKeysTest() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, IOException { + @ParameterizedTest + @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories") + public void generateEcKeysTest(ImplementationFactory implementationFactory) + throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException { + ImplementationFactory.setFactoryImplementation(implementationFactory); + for (EllipticCurve curve : EllipticCurve.values()) { PGPSecretKeyRing secretKeys = generateKey( KeySpec.getBuilder(KeyType.ECDSA(curve)) diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/generation/CertificationKeyMustBeAbleToCertifyTest.java b/pgpainless-core/src/test/java/org/pgpainless/key/generation/CertificationKeyMustBeAbleToCertifyTest.java index 15752d6e..5327c243 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/key/generation/CertificationKeyMustBeAbleToCertifyTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/key/generation/CertificationKeyMustBeAbleToCertifyTest.java @@ -17,9 +17,11 @@ package org.pgpainless.key.generation; import static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.pgpainless.PGPainless; import org.pgpainless.algorithm.KeyFlag; +import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.key.generation.type.KeyType; import org.pgpainless.key.generation.type.ecc.EllipticCurve; import org.pgpainless.key.generation.type.xdh.XDHCurve; @@ -31,8 +33,10 @@ public class CertificationKeyMustBeAbleToCertifyTest { * would result in an invalid key. * This test therefore verifies that generating such keys fails. */ - @Test - public void testCertificationIncapableKeyTypesThrow() { + @ParameterizedTest + @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories") + public void testCertificationIncapableKeyTypesThrow(ImplementationFactory implementationFactory) { + ImplementationFactory.setFactoryImplementation(implementationFactory); KeyType[] typesIncapableOfCreatingVerifications = new KeyType[] { KeyType.ECDH(EllipticCurve._P256), KeyType.ECDH(EllipticCurve._P384), diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateEllipticCurveKeyTest.java b/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateEllipticCurveKeyTest.java index dcee18e9..11358f24 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateEllipticCurveKeyTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateEllipticCurveKeyTest.java @@ -21,9 +21,11 @@ import java.security.NoSuchAlgorithmException; import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.openpgp.PGPSecretKeyRing; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.pgpainless.PGPainless; import org.pgpainless.algorithm.KeyFlag; +import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.key.generation.type.KeyType; import org.pgpainless.key.generation.type.eddsa.EdDSACurve; import org.pgpainless.key.generation.type.xdh.XDHCurve; @@ -32,8 +34,10 @@ import org.pgpainless.util.ArmorUtils; public class GenerateEllipticCurveKeyTest { - @Test - public void test() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, IOException { + @ParameterizedTest + @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories") + public void test(ImplementationFactory implementationFactory) throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, IOException { + ImplementationFactory.setFactoryImplementation(implementationFactory); PGPSecretKeyRing keyRing = PGPainless.generateKeyRing() .withSubKey(KeySpec.getBuilder(KeyType.XDH(XDHCurve._X25519)) .withKeyFlags(KeyFlag.ENCRYPT_COMMS) diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateKeyTest.java b/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateKeyTest.java index 41c82992..9bc3dcdd 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateKeyTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateKeyTest.java @@ -26,8 +26,10 @@ import org.bouncycastle.bcpg.ArmoredOutputStream; import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.openpgp.PGPPublicKeyRing; import org.bouncycastle.openpgp.PGPSecretKeyRing; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.pgpainless.PGPainless; +import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.key.OpenPgpV4Fingerprint; import org.pgpainless.key.util.KeyRingUtils; import org.pgpainless.util.ArmoredOutputStreamFactory; @@ -36,8 +38,11 @@ public class GenerateKeyTest { private static final Logger LOGGER = Logger.getLogger(GenerateKeyTest.class.getName()); - @Test - public void generateKey() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, IOException { + @ParameterizedTest + @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories") + public void generateKey(ImplementationFactory implementationFactory) throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, IOException { + ImplementationFactory.setFactoryImplementation(implementationFactory); + PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().simpleEcKeyRing("fresh@encrypted.key", "password123"); PGPPublicKeyRing publicKeys = KeyRingUtils.publicKeyRingFrom(secretKeys); diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateKeyWithAdditionalUserIdTest.java b/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateKeyWithAdditionalUserIdTest.java index afecc5a3..5d359fd3 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateKeyWithAdditionalUserIdTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateKeyWithAdditionalUserIdTest.java @@ -30,9 +30,11 @@ import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.openpgp.PGPPublicKeyRing; import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.junit.JUtils; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.pgpainless.PGPainless; import org.pgpainless.algorithm.KeyFlag; +import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.key.generation.type.KeyType; import org.pgpainless.key.generation.type.rsa.RsaLength; import org.pgpainless.key.util.KeyRingUtils; @@ -40,8 +42,10 @@ import org.pgpainless.util.ArmoredOutputStreamFactory; public class GenerateKeyWithAdditionalUserIdTest { - @Test - public void test() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, IOException { + @ParameterizedTest + @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories") + public void test(ImplementationFactory implementationFactory) throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, IOException { + ImplementationFactory.setFactoryImplementation(implementationFactory); Date now = new Date(); Date expiration = new Date(now.getTime() + 1000 * 60); PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing() diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateWithEmptyPassphrase.java b/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateWithEmptyPassphrase.java index 3c829eeb..28af382e 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateWithEmptyPassphrase.java +++ b/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateWithEmptyPassphrase.java @@ -22,9 +22,11 @@ import java.security.InvalidAlgorithmParameterException; import java.security.NoSuchAlgorithmException; import org.bouncycastle.openpgp.PGPException; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.pgpainless.PGPainless; import org.pgpainless.algorithm.KeyFlag; +import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.key.generation.type.KeyType; import org.pgpainless.key.generation.type.rsa.RsaLength; import org.pgpainless.util.Passphrase; @@ -38,8 +40,11 @@ import org.pgpainless.util.Passphrase; */ public class GenerateWithEmptyPassphrase { - @Test - public void testGeneratingKeyWithEmptyPassphraseDoesNotThrow() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, IOException { + @ParameterizedTest + @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories") + public void testGeneratingKeyWithEmptyPassphraseDoesNotThrow(ImplementationFactory implementationFactory) throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, IOException { + ImplementationFactory.setFactoryImplementation(implementationFactory); + assertNotNull(PGPainless.generateKeyRing() .withPrimaryKey(KeySpec.getBuilder(KeyType.RSA(RsaLength._3072)) .withKeyFlags(KeyFlag.CERTIFY_OTHER, KeyFlag.SIGN_DATA, KeyFlag.ENCRYPT_COMMS) diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/generation/IllegalKeyFlagsTest.java b/pgpainless-core/src/test/java/org/pgpainless/key/generation/IllegalKeyFlagsTest.java index 8d043755..a146dc4d 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/key/generation/IllegalKeyFlagsTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/key/generation/IllegalKeyFlagsTest.java @@ -17,17 +17,21 @@ package org.pgpainless.key.generation; import static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.pgpainless.PGPainless; import org.pgpainless.algorithm.KeyFlag; +import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.key.generation.type.KeyType; import org.pgpainless.key.generation.type.eddsa.EdDSACurve; import org.pgpainless.key.generation.type.xdh.XDHCurve; public class IllegalKeyFlagsTest { - @Test - public void testKeyCannotCarryFlagsTest() { + @ParameterizedTest + @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories") + public void testKeyCannotCarryFlagsTest(ImplementationFactory implementationFactory) { + ImplementationFactory.setFactoryImplementation(implementationFactory); assertThrows(IllegalArgumentException.class, () -> PGPainless.generateKeyRing() .withPrimaryKey(KeySpec.getBuilder(KeyType.XDH(XDHCurve._X25519)) .withKeyFlags(KeyFlag.SIGN_DATA) // <- should throw diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/modification/AddSubKeyTest.java b/pgpainless-core/src/test/java/org/pgpainless/key/modification/AddSubKeyTest.java index 472f8e10..c198bc44 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/key/modification/AddSubKeyTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/key/modification/AddSubKeyTest.java @@ -29,20 +29,24 @@ import org.bouncycastle.openpgp.PGPPrivateKey; import org.bouncycastle.openpgp.PGPPublicKey; import org.bouncycastle.openpgp.PGPSecretKey; import org.bouncycastle.openpgp.PGPSecretKeyRing; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.pgpainless.PGPainless; import org.pgpainless.algorithm.KeyFlag; +import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.key.TestKeys; import org.pgpainless.key.generation.KeySpec; -import org.pgpainless.key.generation.type.ecc.ecdsa.ECDSA; import org.pgpainless.key.generation.type.ecc.EllipticCurve; +import org.pgpainless.key.generation.type.ecc.ecdsa.ECDSA; import org.pgpainless.key.protection.PasswordBasedSecretKeyRingProtector; import org.pgpainless.util.Passphrase; public class AddSubKeyTest { - @Test - public void testAddSubKey() throws IOException, PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException { + @ParameterizedTest + @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories") + public void testAddSubKey(ImplementationFactory implementationFactory) throws IOException, PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException { + ImplementationFactory.setFactoryImplementation(implementationFactory); PGPSecretKeyRing secretKeys = TestKeys.getCryptieSecretKeyRing(); List keyIdsBefore = new ArrayList<>(); diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/modification/AddUserIdTest.java b/pgpainless-core/src/test/java/org/pgpainless/key/modification/AddUserIdTest.java index 0594754a..8c94be98 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/key/modification/AddUserIdTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/key/modification/AddUserIdTest.java @@ -28,7 +28,10 @@ import java.util.NoSuchElementException; import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.pgpainless.PGPainless; +import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.key.TestKeys; import org.pgpainless.key.protection.PasswordBasedSecretKeyRingProtector; import org.pgpainless.key.protection.SecretKeyRingProtector; @@ -37,8 +40,10 @@ import org.pgpainless.util.Passphrase; public class AddUserIdTest { - @Test - public void addUserIdToExistingKeyRing() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException { + @ParameterizedTest + @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories") + public void addUserIdToExistingKeyRing(ImplementationFactory implementationFactory) throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException { + ImplementationFactory.setFactoryImplementation(implementationFactory); PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().simpleEcKeyRing("alice@wonderland.lit", "rabb1th0le"); Iterator userIds = secretKeys.getSecretKey().getPublicKey().getUserIDs(); diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/modification/ChangeExpirationTest.java b/pgpainless-core/src/test/java/org/pgpainless/key/modification/ChangeExpirationTest.java index b0b7d2ab..e0f02e5e 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/key/modification/ChangeExpirationTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/key/modification/ChangeExpirationTest.java @@ -19,24 +19,29 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; +import java.io.IOException; +import java.util.Date; + import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.pgpainless.PGPainless; +import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.key.OpenPgpV4Fingerprint; import org.pgpainless.key.TestKeys; import org.pgpainless.key.info.KeyRingInfo; import org.pgpainless.key.protection.UnprotectedKeysProtector; -import java.io.IOException; -import java.util.Date; - public class ChangeExpirationTest { private final OpenPgpV4Fingerprint subKeyFingerprint = new OpenPgpV4Fingerprint("F73FDE6439ABE210B1AF4EDD273EF7A0C749807B"); - @Test - public void setExpirationDateAndThenUnsetIt_OnPrimaryKey() throws PGPException, IOException, InterruptedException { + @ParameterizedTest + @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories") + public void setExpirationDateAndThenUnsetIt_OnPrimaryKey(ImplementationFactory implementationFactory) throws PGPException, IOException, InterruptedException { + ImplementationFactory.setFactoryImplementation(implementationFactory); PGPSecretKeyRing secretKeys = TestKeys.getEmilSecretKeyRing(); KeyRingInfo sInfo = PGPainless.inspectKeyRing(secretKeys); diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/modification/ChangeSecretKeyRingPassphraseTest.java b/pgpainless-core/src/test/java/org/pgpainless/key/modification/ChangeSecretKeyRingPassphraseTest.java index 7cc3fd80..12159f3f 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/key/modification/ChangeSecretKeyRingPassphraseTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/key/modification/ChangeSecretKeyRingPassphraseTest.java @@ -34,10 +34,12 @@ import org.bouncycastle.openpgp.operator.PGPDigestCalculatorProvider; import org.bouncycastle.openpgp.operator.bc.BcPBESecretKeyDecryptorBuilder; import org.bouncycastle.openpgp.operator.bc.BcPGPDigestCalculatorProvider; import org.bouncycastle.util.io.Streams; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.pgpainless.PGPainless; import org.pgpainless.algorithm.SymmetricKeyAlgorithm; import org.pgpainless.encryption_signing.EncryptionStream; +import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.key.protection.KeyRingProtectionSettings; import org.pgpainless.key.protection.PasswordBasedSecretKeyRingProtector; import org.pgpainless.util.Passphrase; @@ -49,8 +51,10 @@ public class ChangeSecretKeyRingPassphraseTest { public ChangeSecretKeyRingPassphraseTest() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException { } - @Test - public void changePassphraseOfWholeKeyRingTest() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, IOException { + @ParameterizedTest + @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories") + public void changePassphraseOfWholeKeyRingTest(ImplementationFactory implementationFactory) throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, IOException { + ImplementationFactory.setFactoryImplementation(implementationFactory); PGPSecretKeyRing secretKeys = PGPainless.modifyKeyRing(keyRing) .changePassphraseFromOldPassphrase(Passphrase.fromPassword("weakPassphrase")) @@ -75,8 +79,10 @@ public class ChangeSecretKeyRingPassphraseTest { "Unlocking the secret key ring with the new passphrase MUST succeed."); } - @Test - public void changePassphraseOfWholeKeyRingToEmptyPassphrase() throws PGPException, IOException { + @ParameterizedTest + @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories") + public void changePassphraseOfWholeKeyRingToEmptyPassphrase(ImplementationFactory implementationFactory) throws PGPException, IOException { + ImplementationFactory.setFactoryImplementation(implementationFactory); PGPSecretKeyRing secretKeys = PGPainless.modifyKeyRing(keyRing) .changePassphraseFromOldPassphrase(Passphrase.fromPassword("weakPassphrase")) .withSecureDefaultSettings() @@ -91,8 +97,10 @@ public class ChangeSecretKeyRingPassphraseTest { signDummyMessageWithKeysAndPassphrase(changedPassphraseKeyRing, Passphrase.emptyPassphrase()); } - @Test - public void changePassphraseOfSingleSubkeyToNewPassphrase() throws PGPException { + @ParameterizedTest + @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories") + public void changePassphraseOfSingleSubkeyToNewPassphrase(ImplementationFactory implementationFactory) throws PGPException { + ImplementationFactory.setFactoryImplementation(implementationFactory); Iterator keys = keyRing.getSecretKeys(); PGPSecretKey primaryKey = keys.next(); @@ -126,8 +134,11 @@ public class ChangeSecretKeyRingPassphraseTest { "Unlocking the subkey with the primary key passphrase must fail."); } - @Test - public void changePassphraseOfSingleSubkeyToEmptyPassphrase() throws PGPException { + @ParameterizedTest + @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories") + public void changePassphraseOfSingleSubkeyToEmptyPassphrase(ImplementationFactory implementationFactory) throws PGPException { + ImplementationFactory.setFactoryImplementation(implementationFactory); + Iterator keys = keyRing.getSecretKeys(); PGPSecretKey primaryKey = keys.next(); PGPSecretKey subKey = keys.next(); diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/modification/OldSignatureSubpacketsArePreservedOnNewSig.java b/pgpainless-core/src/test/java/org/pgpainless/key/modification/OldSignatureSubpacketsArePreservedOnNewSig.java index 75c03910..550d6beb 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/key/modification/OldSignatureSubpacketsArePreservedOnNewSig.java +++ b/pgpainless-core/src/test/java/org/pgpainless/key/modification/OldSignatureSubpacketsArePreservedOnNewSig.java @@ -28,15 +28,20 @@ import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.bouncycastle.openpgp.PGPSignature; import org.bouncycastle.openpgp.PGPSignatureSubpacketVector; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.pgpainless.PGPainless; +import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.key.OpenPgpV4Fingerprint; import org.pgpainless.key.protection.UnprotectedKeysProtector; public class OldSignatureSubpacketsArePreservedOnNewSig { - @Test - public void verifyOldSignatureSubpacketsArePreservedOnNewExpirationDateSig() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, InterruptedException, IOException { + @ParameterizedTest + @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories") + public void verifyOldSignatureSubpacketsArePreservedOnNewExpirationDateSig(ImplementationFactory implementationFactory) + throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, InterruptedException, IOException { + ImplementationFactory.setFactoryImplementation(implementationFactory); PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing() .simpleEcKeyRing("Alice "); diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/modification/RevokeKeyWithGenericCertificationSignatureTest.java b/pgpainless-core/src/test/java/org/pgpainless/key/modification/RevokeKeyWithGenericCertificationSignatureTest.java index 5ab4ed16..2a577430 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/key/modification/RevokeKeyWithGenericCertificationSignatureTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/key/modification/RevokeKeyWithGenericCertificationSignatureTest.java @@ -25,8 +25,10 @@ import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.openpgp.PGPPublicKey; import org.bouncycastle.openpgp.PGPSecretKey; import org.bouncycastle.openpgp.PGPSecretKeyRing; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.pgpainless.PGPainless; +import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.key.protection.UnprotectedKeysProtector; import org.pgpainless.util.ArmoredOutputStreamFactory; @@ -72,8 +74,10 @@ public class RevokeKeyWithGenericCertificationSignatureTest { } } - @Test - public void test() throws IOException, PGPException { + @ParameterizedTest + @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories") + public void test(ImplementationFactory implementationFactory) throws IOException, PGPException { + ImplementationFactory.setFactoryImplementation(implementationFactory); revokeKey(SAMPLE_PRIVATE_KEY); // would crash previously } diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/modification/RevokeKeyWithoutPreferredAlgorithmsOnPrimaryKey.java b/pgpainless-core/src/test/java/org/pgpainless/key/modification/RevokeKeyWithoutPreferredAlgorithmsOnPrimaryKey.java index 7afcd7fd..c5983fa8 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/key/modification/RevokeKeyWithoutPreferredAlgorithmsOnPrimaryKey.java +++ b/pgpainless-core/src/test/java/org/pgpainless/key/modification/RevokeKeyWithoutPreferredAlgorithmsOnPrimaryKey.java @@ -25,8 +25,10 @@ import java.util.List; import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.openpgp.PGPSecretKey; import org.bouncycastle.openpgp.PGPSecretKeyRing; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.pgpainless.PGPainless; +import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.key.OpenPgpV4Fingerprint; import org.pgpainless.key.info.KeyRingInfo; import org.pgpainless.key.modification.secretkeyring.SecretKeyRingEditorInterface; @@ -109,8 +111,10 @@ public class RevokeKeyWithoutPreferredAlgorithmsOnPrimaryKey { "=3Zyp\n" + "-----END PGP PRIVATE KEY BLOCK-----"; - @Test - public void testChangingExpirationTimeWithKeyWithoutPrefAlgos() throws IOException, PGPException { + @ParameterizedTest + @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories") + public void testChangingExpirationTimeWithKeyWithoutPrefAlgos(ImplementationFactory implementationFactory) throws IOException, PGPException { + ImplementationFactory.setFactoryImplementation(implementationFactory); Date expirationDate = new Date(); PGPSecretKeyRing secretKeys = PGPainless.readKeyRing().secretKeyRing(KEY); List fingerprintList = new ArrayList<>(); diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/modification/RevokeSubKeyTest.java b/pgpainless-core/src/test/java/org/pgpainless/key/modification/RevokeSubKeyTest.java index e9b64f6e..7c344a3e 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/key/modification/RevokeSubKeyTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/key/modification/RevokeSubKeyTest.java @@ -29,8 +29,11 @@ import org.bouncycastle.openpgp.PGPSecretKey; import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.bouncycastle.openpgp.PGPSignature; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.pgpainless.PGPainless; import org.pgpainless.algorithm.SignatureType; +import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.key.OpenPgpV4Fingerprint; import org.pgpainless.key.TestKeys; import org.pgpainless.key.modification.secretkeyring.SecretKeyRingEditorInterface; @@ -42,8 +45,10 @@ import org.pgpainless.util.Passphrase; public class RevokeSubKeyTest { - @Test - public void revokeSukeyTest() throws IOException, PGPException { + @ParameterizedTest + @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories") + public void revokeSukeyTest(ImplementationFactory implementationFactory) throws IOException, PGPException { + ImplementationFactory.setFactoryImplementation(implementationFactory); PGPSecretKeyRing secretKeys = TestKeys.getCryptieSecretKeyRing(); Iterator keysIterator = secretKeys.iterator(); @@ -65,8 +70,10 @@ public class RevokeSubKeyTest { assertTrue(subKey.getPublicKey().hasRevocation()); } - @Test - public void detachedRevokeSubkeyTest() throws IOException, PGPException { + @ParameterizedTest + @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories") + public void detachedRevokeSubkeyTest(ImplementationFactory implementationFactory) throws IOException, PGPException { + ImplementationFactory.setFactoryImplementation(implementationFactory); PGPSecretKeyRing secretKeys = TestKeys.getCryptieSecretKeyRing(); OpenPgpV4Fingerprint fingerprint = new OpenPgpV4Fingerprint(secretKeys); SecretKeyRingProtector protector = PasswordBasedSecretKeyRingProtector.forKey(secretKeys, Passphrase.fromPassword("password123")); @@ -89,8 +96,10 @@ public class RevokeSubKeyTest { assertTrue(publicKey.hasRevocation()); } - @Test - public void testRevocationSignatureTypeCorrect() throws IOException, PGPException { + @ParameterizedTest + @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories") + public void testRevocationSignatureTypeCorrect(ImplementationFactory implementationFactory) throws IOException, PGPException { + ImplementationFactory.setFactoryImplementation(implementationFactory); PGPSecretKeyRing secretKeys = TestKeys.getCryptieSecretKeyRing(); Iterator keysIterator = secretKeys.getPublicKeys(); PGPPublicKey primaryKey = keysIterator.next(); diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/protection/SecretKeyRingProtectorTest.java b/pgpainless-core/src/test/java/org/pgpainless/key/protection/SecretKeyRingProtectorTest.java index 3e3332e3..11349324 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/key/protection/SecretKeyRingProtectorTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/key/protection/SecretKeyRingProtectorTest.java @@ -35,15 +35,21 @@ import org.bouncycastle.openpgp.PGPSecretKey; import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.bouncycastle.openpgp.operator.PBESecretKeyDecryptor; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.pgpainless.PGPainless; +import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.key.TestKeys; import org.pgpainless.key.protection.passphrase_provider.SecretKeyPassphraseProvider; import org.pgpainless.util.Passphrase; public class SecretKeyRingProtectorTest { - @Test - public void testUnlockAllKeysWithSamePassword() throws IOException, PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException { + @ParameterizedTest + @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories") + public void testUnlockAllKeysWithSamePassword(ImplementationFactory implementationFactory) throws IOException, PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException { + ImplementationFactory.setFactoryImplementation(implementationFactory); + PGPSecretKeyRing secretKeys = TestKeys.getCryptieSecretKeyRing(); SecretKeyRingProtector protector = SecretKeyRingProtector.unlockAllKeysWith(TestKeys.CRYPTIE_PASSPHRASE, secretKeys); for (PGPSecretKey secretKey : secretKeys) { @@ -71,8 +77,11 @@ public class SecretKeyRingProtectorTest { } } - @Test - public void testUnlockSingleKeyWithPassphrase() throws IOException, PGPException { + @ParameterizedTest + @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories") + public void testUnlockSingleKeyWithPassphrase(ImplementationFactory implementationFactory) throws IOException, PGPException { + ImplementationFactory.setFactoryImplementation(implementationFactory); + PGPSecretKeyRing secretKeys = TestKeys.getCryptieSecretKeyRing(); Iterator iterator = secretKeys.iterator(); PGPSecretKey secretKey = iterator.next(); @@ -118,8 +127,10 @@ public class SecretKeyRingProtectorTest { assertEquals(Passphrase.fromPassword("missingP455w0rd"), protector.getPassphraseFor(3L)); } - @Test - public void testCallbackBasedKeyRingProtector() throws IOException, PGPException { + @ParameterizedTest + @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories") + public void testCallbackBasedKeyRingProtector(ImplementationFactory implementationFactory) throws IOException, PGPException { + ImplementationFactory.setFactoryImplementation(implementationFactory); SecretKeyRingProtector2 protector = new CallbackBasedKeyringProtector(new CallbackBasedKeyringProtector.Callback() { @Override public Passphrase getPassphraseFor(PGPSecretKey secretKey) { @@ -130,6 +141,7 @@ public class SecretKeyRingProtectorTest { PGPSecretKeyRing secretKeys = TestKeys.getEmilSecretKeyRing(); for (PGPSecretKey secretKey : secretKeys) { secretKey.extractPrivateKey(protector.getDecryptor(secretKey)); + assertNotNull(protector.getEncryptor(secretKey)); } } } diff --git a/pgpainless-core/src/test/java/org/pgpainless/symmetric_encryption/LegacySymmetricEncryptionTest.java b/pgpainless-core/src/test/java/org/pgpainless/symmetric_encryption/LegacySymmetricEncryptionTest.java index c31b31b5..477e0067 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/symmetric_encryption/LegacySymmetricEncryptionTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/symmetric_encryption/LegacySymmetricEncryptionTest.java @@ -24,9 +24,11 @@ import java.util.logging.Logger; import org.bouncycastle.bcpg.ArmoredOutputStream; import org.bouncycastle.openpgp.PGPException; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.pgpainless.PGPainless; import org.pgpainless.algorithm.SymmetricKeyAlgorithm; +import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.util.ArmoredOutputStreamFactory; import org.pgpainless.util.Passphrase; @@ -46,8 +48,10 @@ public class LegacySymmetricEncryptionTest { "- Edward Snowden -"; @SuppressWarnings("deprecation") - @Test - public void testSymmetricEncryptionDecryption() throws IOException, PGPException { + @ParameterizedTest + @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories") + public void testSymmetricEncryptionDecryption(ImplementationFactory implementationFactory) throws IOException, PGPException { + ImplementationFactory.setFactoryImplementation(implementationFactory); byte[] plain = message.getBytes(); String password = "choose_a_better_password_please"; Passphrase passphrase = new Passphrase(password.toCharArray()); diff --git a/pgpainless-core/src/test/java/org/pgpainless/symmetric_encryption/MultiPassphraseSymmetricEncryptionTest.java b/pgpainless-core/src/test/java/org/pgpainless/symmetric_encryption/MultiPassphraseSymmetricEncryptionTest.java index aee992f2..e591a963 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/symmetric_encryption/MultiPassphraseSymmetricEncryptionTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/symmetric_encryption/MultiPassphraseSymmetricEncryptionTest.java @@ -22,16 +22,20 @@ import java.nio.charset.StandardCharsets; import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.util.io.Streams; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.pgpainless.PGPainless; import org.pgpainless.decryption_verification.DecryptionStream; import org.pgpainless.encryption_signing.EncryptionStream; +import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.util.Passphrase; public class MultiPassphraseSymmetricEncryptionTest { - @Test - public void test() throws IOException, PGPException { + @ParameterizedTest + @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories") + public void test(ImplementationFactory implementationFactory) throws IOException, PGPException { + ImplementationFactory.setFactoryImplementation(implementationFactory); String message = "Here we test if during decryption of a message that was encrypted with two passphrases, " + "the decryptor finds the session key encrypted for the right passphrase."; ByteArrayInputStream plaintextIn = new ByteArrayInputStream(message.getBytes(StandardCharsets.UTF_8)); diff --git a/pgpainless-core/src/test/java/org/pgpainless/symmetric_encryption/SymmetricEncryptionTest.java b/pgpainless-core/src/test/java/org/pgpainless/symmetric_encryption/SymmetricEncryptionTest.java index ea4c35bd..7d6e834b 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/symmetric_encryption/SymmetricEncryptionTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/symmetric_encryption/SymmetricEncryptionTest.java @@ -26,10 +26,12 @@ import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.openpgp.PGPPublicKeyRing; import org.bouncycastle.openpgp.PGPSecretKeyRingCollection; import org.bouncycastle.util.io.Streams; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.pgpainless.PGPainless; import org.pgpainless.decryption_verification.DecryptionStream; import org.pgpainless.encryption_signing.EncryptionStream; +import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.key.TestKeys; import org.pgpainless.key.protection.KeyRingProtectionSettings; import org.pgpainless.key.protection.PasswordBasedSecretKeyRingProtector; @@ -42,8 +44,10 @@ import org.pgpainless.util.Passphrase; */ public class SymmetricEncryptionTest { - @Test - public void test() throws IOException, PGPException { + @ParameterizedTest + @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories") + public void test(ImplementationFactory implementationFactory) throws IOException, PGPException { + ImplementationFactory.setFactoryImplementation(implementationFactory); byte[] plaintext = "This is a secret message".getBytes(StandardCharsets.UTF_8); ByteArrayInputStream plaintextIn = new ByteArrayInputStream(plaintext); PGPPublicKeyRing encryptionKey = TestKeys.getCryptiePublicKeyRing();