1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-23 12:52:07 +01:00

Introduce parametrized tests to also test the JceImplementationFactory

This commit is contained in:
Paul Schaub 2021-02-25 23:27:08 +01:00
parent 8c041e6856
commit bfab4b60f0
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
31 changed files with 319 additions and 117 deletions

View file

@ -4,6 +4,7 @@ plugins {
dependencies { dependencies {
testImplementation "org.junit.jupiter:junit-jupiter-api:$junitVersion" testImplementation "org.junit.jupiter:junit-jupiter-api:$junitVersion"
testImplementation "org.junit.jupiter:junit-jupiter-params:$junitVersion"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junitVersion" testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junitVersion"
/* /*

View file

@ -46,6 +46,11 @@ import org.pgpainless.util.Passphrase;
public abstract class ImplementationFactory { public abstract class ImplementationFactory {
enum FactoryType {
bc,
jce
}
private static ImplementationFactory FACTORY_IMPLEMENTATION = new BcImplementationFactory(); private static ImplementationFactory FACTORY_IMPLEMENTATION = new BcImplementationFactory();
public static void setFactoryImplementation(ImplementationFactory implementation) { public static void setFactoryImplementation(ImplementationFactory implementation) {

View file

@ -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<ImplementationFactory> IMPLEMENTATIONS = Arrays.asList(
new BcImplementationFactory(),
new JceImplementationFactory()
);
public static List<ImplementationFactory> provideImplementationFactories() {
return IMPLEMENTATIONS;
}
}

View file

@ -31,10 +31,12 @@ import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.bouncycastle.openpgp.PGPSecretKeyRingCollection; import org.bouncycastle.openpgp.PGPSecretKeyRingCollection;
import org.bouncycastle.util.io.Streams; import org.bouncycastle.util.io.Streams;
import org.junit.jupiter.api.BeforeEach; 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.PGPainless;
import org.pgpainless.algorithm.CompressionAlgorithm; import org.pgpainless.algorithm.CompressionAlgorithm;
import org.pgpainless.algorithm.SymmetricKeyAlgorithm; import org.pgpainless.algorithm.SymmetricKeyAlgorithm;
import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.TestKeys; import org.pgpainless.key.TestKeys;
import org.pgpainless.key.protection.UnprotectedKeysProtector; import org.pgpainless.key.protection.UnprotectedKeysProtector;
@ -52,8 +54,10 @@ public class DecryptAndVerifyMessageTest {
romeo = TestKeys.getRomeoSecretKeyRing(); romeo = TestKeys.getRomeoSecretKeyRing();
} }
@Test @ParameterizedTest
public void decryptMessageAndVerifySignatureTest() throws Exception { @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories")
public void decryptMessageAndVerifySignatureTest(ImplementationFactory implementationFactory) throws Exception {
ImplementationFactory.setFactoryImplementation(implementationFactory);
String encryptedMessage = TestKeys.MSG_SIGN_CRYPT_JULIET_JULIET; String encryptedMessage = TestKeys.MSG_SIGN_CRYPT_JULIET_JULIET;
DecryptionStream decryptor = PGPainless.decryptAndOrVerify() DecryptionStream decryptor = PGPainless.decryptAndOrVerify()

View file

@ -29,9 +29,11 @@ import org.bouncycastle.openpgp.PGPPublicKey;
import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.bouncycastle.openpgp.PGPSecretKeyRingCollection; import org.bouncycastle.openpgp.PGPSecretKeyRingCollection;
import org.bouncycastle.util.io.Streams; 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.PGPainless;
import org.pgpainless.algorithm.KeyFlag; import org.pgpainless.algorithm.KeyFlag;
import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.OpenPgpV4Fingerprint; import org.pgpainless.key.OpenPgpV4Fingerprint;
import org.pgpainless.key.protection.SecretKeyRingProtector; import org.pgpainless.key.protection.SecretKeyRingProtector;
import org.pgpainless.key.util.KeyRingUtils; import org.pgpainless.key.util.KeyRingUtils;
@ -39,8 +41,10 @@ import org.pgpainless.util.selection.key.impl.EncryptionKeySelectionStrategy;
public class DecryptHiddenRecipientMessage { public class DecryptHiddenRecipientMessage {
@Test @ParameterizedTest
public void testDecryptionWithWildcardRecipient() throws IOException, PGPException { @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" + String secretKeyAscii = "-----BEGIN PGP PRIVATE KEY BLOCK-----\n" +
"Comment: Bob's OpenPGP Transferable Secret Key\n" + "Comment: Bob's OpenPGP Transferable Secret Key\n" +
"\n" + "\n" +

View file

@ -29,8 +29,10 @@ import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.bouncycastle.openpgp.PGPSecretKeyRingCollection; import org.bouncycastle.openpgp.PGPSecretKeyRingCollection;
import org.bouncycastle.util.io.Streams; 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.PGPainless;
import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.protection.SecretKeyRingProtector; import org.pgpainless.key.protection.SecretKeyRingProtector;
public class ModificationDetectionTests { public class ModificationDetectionTests {
@ -118,8 +120,10 @@ public class ModificationDetectionTests {
"=miES\n" + "=miES\n" +
"-----END PGP PRIVATE KEY BLOCK-----\n"; "-----END PGP PRIVATE KEY BLOCK-----\n";
@Test @ParameterizedTest
public void testMissingMDC() throws IOException, PGPException { @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories")
public void testMissingMDC(ImplementationFactory implementationFactory) throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
String message = "-----BEGIN PGP MESSAGE-----\n" + String message = "-----BEGIN PGP MESSAGE-----\n" +
"\n" + "\n" +
"wcDMA3wvqk35PDeyAQwAnTmchA6ve/aF7cPEnyJSb9Ot61LSIMrU3+RaEdA90qn4\n" + "wcDMA3wvqk35PDeyAQwAnTmchA6ve/aF7cPEnyJSb9Ot61LSIMrU3+RaEdA90qn4\n" +
@ -151,8 +155,10 @@ public class ModificationDetectionTests {
}); });
} }
@Test @ParameterizedTest
public void tamperedCiphertextTest() throws IOException, PGPException { @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories")
public void tamperedCiphertextTest(ImplementationFactory implementationFactory) throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
String message = "-----BEGIN PGP MESSAGE-----\n" + String message = "-----BEGIN PGP MESSAGE-----\n" +
"\n" + "\n" +
"wcDMA3wvqk35PDeyAQwAnTmchA6ve/aF7cPEnyJSb9Ot61LSIMrU3+RaEdA90qn4\n" + "wcDMA3wvqk35PDeyAQwAnTmchA6ve/aF7cPEnyJSb9Ot61LSIMrU3+RaEdA90qn4\n" +
@ -180,8 +186,10 @@ public class ModificationDetectionTests {
assertThrows(IOException.class, decryptionStream::close); assertThrows(IOException.class, decryptionStream::close);
} }
@Test @ParameterizedTest
public void tamperedMDCTest() throws IOException, PGPException { @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories")
public void tamperedMDCTest(ImplementationFactory implementationFactory) throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
String message = "-----BEGIN PGP MESSAGE-----\n" + String message = "-----BEGIN PGP MESSAGE-----\n" +
"\n" + "\n" +
"wcDMA3wvqk35PDeyAQwAnTmchA6ve/aF7cPEnyJSb9Ot61LSIMrU3+RaEdA90qn4\n" + "wcDMA3wvqk35PDeyAQwAnTmchA6ve/aF7cPEnyJSb9Ot61LSIMrU3+RaEdA90qn4\n" +

View file

@ -27,8 +27,10 @@ import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.bouncycastle.openpgp.PGPSecretKeyRingCollection; import org.bouncycastle.openpgp.PGPSecretKeyRingCollection;
import org.bouncycastle.util.io.Streams; 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.PGPainless;
import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.protection.SecretKeyRingProtector; import org.pgpainless.key.protection.SecretKeyRingProtector;
public class RecursionDepthTest { public class RecursionDepthTest {
@ -40,8 +42,10 @@ public class RecursionDepthTest {
* @throws IOException * @throws IOException
* @throws PGPException * @throws PGPException
*/ */
@Test @ParameterizedTest
public void decryptionAbortsWhenMaximumRecursionDepthReachedTest() throws IOException, PGPException { @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" + String key = "-----BEGIN PGP PRIVATE KEY BLOCK-----\n" +
"Comment: Bob's OpenPGP Transferable Secret Key\n" + "Comment: Bob's OpenPGP Transferable Secret Key\n" +
"\n" + "\n" +

View file

@ -36,17 +36,19 @@ import org.bouncycastle.openpgp.PGPPublicKeyRing;
import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.bouncycastle.openpgp.PGPSignature; import org.bouncycastle.openpgp.PGPSignature;
import org.bouncycastle.util.io.Streams; 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.PGPainless;
import org.pgpainless.algorithm.KeyFlag; import org.pgpainless.algorithm.KeyFlag;
import org.pgpainless.algorithm.SymmetricKeyAlgorithm; import org.pgpainless.algorithm.SymmetricKeyAlgorithm;
import org.pgpainless.decryption_verification.DecryptionStream; import org.pgpainless.decryption_verification.DecryptionStream;
import org.pgpainless.decryption_verification.OpenPgpMetadata; import org.pgpainless.decryption_verification.OpenPgpMetadata;
import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.OpenPgpV4Fingerprint; import org.pgpainless.key.OpenPgpV4Fingerprint;
import org.pgpainless.key.TestKeys; import org.pgpainless.key.TestKeys;
import org.pgpainless.key.generation.KeySpec; 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.KeyType;
import org.pgpainless.key.generation.type.elgamal.ElGamal;
import org.pgpainless.key.generation.type.elgamal.ElGamalLength; import org.pgpainless.key.generation.type.elgamal.ElGamalLength;
import org.pgpainless.key.generation.type.rsa.RsaLength; import org.pgpainless.key.generation.type.rsa.RsaLength;
import org.pgpainless.key.protection.SecretKeyRingProtector; import org.pgpainless.key.protection.SecretKeyRingProtector;
@ -69,9 +71,11 @@ public class EncryptDecryptTest {
"Unfold the imagined happiness that both\n" + "Unfold the imagined happiness that both\n" +
"Receive in either by this dear encounter."; "Receive in either by this dear encounter.";
@Test @ParameterizedTest
public void freshKeysRsaToElGamalTest() @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories")
public void freshKeysRsaToElGamalTest(ImplementationFactory implementationFactory)
throws PGPException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, IOException { throws PGPException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, IOException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPSecretKeyRing sender = PGPainless.generateKeyRing().simpleRsaKeyRing("romeo@montague.lit", RsaLength._3072); PGPSecretKeyRing sender = PGPainless.generateKeyRing().simpleRsaKeyRing("romeo@montague.lit", RsaLength._3072);
PGPSecretKeyRing recipient = PGPainless.generateKeyRing() PGPSecretKeyRing recipient = PGPainless.generateKeyRing()
.withSubKey(KeySpec.getBuilder(ElGamal.withLength(ElGamalLength._3072)).withKeyFlags(KeyFlag.ENCRYPT_STORAGE, KeyFlag.ENCRYPT_COMMS).withDefaultAlgorithms()) .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); encryptDecryptForSecretKeyRings(sender, recipient);
} }
@Test @ParameterizedTest
public void freshKeysRsaToRsaTest() @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories")
public void freshKeysRsaToRsaTest(ImplementationFactory implementationFactory)
throws PGPException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, IOException { throws PGPException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, IOException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPSecretKeyRing sender = PGPainless.generateKeyRing().simpleRsaKeyRing("romeo@montague.lit", RsaLength._3072); PGPSecretKeyRing sender = PGPainless.generateKeyRing().simpleRsaKeyRing("romeo@montague.lit", RsaLength._3072);
PGPSecretKeyRing recipient = PGPainless.generateKeyRing().simpleRsaKeyRing("juliet@capulet.lit", RsaLength._3072); PGPSecretKeyRing recipient = PGPainless.generateKeyRing().simpleRsaKeyRing("juliet@capulet.lit", RsaLength._3072);
encryptDecryptForSecretKeyRings(sender, recipient); encryptDecryptForSecretKeyRings(sender, recipient);
} }
@Test @ParameterizedTest
public void freshKeysEcToEcTest() @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories")
public void freshKeysEcToEcTest(ImplementationFactory implementationFactory)
throws IOException, PGPException, NoSuchAlgorithmException, InvalidAlgorithmParameterException { throws IOException, PGPException, NoSuchAlgorithmException, InvalidAlgorithmParameterException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPSecretKeyRing sender = PGPainless.generateKeyRing().simpleEcKeyRing("romeo@montague.lit"); PGPSecretKeyRing sender = PGPainless.generateKeyRing().simpleEcKeyRing("romeo@montague.lit");
PGPSecretKeyRing recipient = PGPainless.generateKeyRing().simpleEcKeyRing("juliet@capulet.lit"); PGPSecretKeyRing recipient = PGPainless.generateKeyRing().simpleEcKeyRing("juliet@capulet.lit");
encryptDecryptForSecretKeyRings(sender, recipient); encryptDecryptForSecretKeyRings(sender, recipient);
} }
@Test @ParameterizedTest
public void freshKeysEcToRsaTest() @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories")
public void freshKeysEcToRsaTest(ImplementationFactory implementationFactory)
throws PGPException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, IOException { throws PGPException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, IOException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPSecretKeyRing sender = PGPainless.generateKeyRing().simpleEcKeyRing("romeo@montague.lit"); PGPSecretKeyRing sender = PGPainless.generateKeyRing().simpleEcKeyRing("romeo@montague.lit");
PGPSecretKeyRing recipient = PGPainless.generateKeyRing().simpleRsaKeyRing("juliet@capulet.lit", RsaLength._3072); PGPSecretKeyRing recipient = PGPainless.generateKeyRing().simpleRsaKeyRing("juliet@capulet.lit", RsaLength._3072);
encryptDecryptForSecretKeyRings(sender, recipient); encryptDecryptForSecretKeyRings(sender, recipient);
} }
@Test @ParameterizedTest
public void freshKeysRsaToEcTest() @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories")
public void freshKeysRsaToEcTest(ImplementationFactory implementationFactory)
throws PGPException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, IOException { throws PGPException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, IOException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPSecretKeyRing sender = PGPainless.generateKeyRing().simpleRsaKeyRing("romeo@montague.lit", RsaLength._3072); PGPSecretKeyRing sender = PGPainless.generateKeyRing().simpleRsaKeyRing("romeo@montague.lit", RsaLength._3072);
PGPSecretKeyRing recipient = PGPainless.generateKeyRing().simpleEcKeyRing("juliet@capulet.lit"); PGPSecretKeyRing recipient = PGPainless.generateKeyRing().simpleEcKeyRing("juliet@capulet.lit");
encryptDecryptForSecretKeyRings(sender, recipient); encryptDecryptForSecretKeyRings(sender, recipient);
} }
@Test @ParameterizedTest
public void existingRsaKeysTest() throws IOException, PGPException { @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories")
public void existingRsaKeysTest(ImplementationFactory implementationFactory) throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPSecretKeyRing sender = TestKeys.getJulietSecretKeyRing(); PGPSecretKeyRing sender = TestKeys.getJulietSecretKeyRing();
PGPSecretKeyRing recipient = TestKeys.getRomeoSecretKeyRing(); PGPSecretKeyRing recipient = TestKeys.getRomeoSecretKeyRing();
@ -187,8 +201,11 @@ public class EncryptDecryptTest {
assertTrue(result.isVerified()); assertTrue(result.isVerified());
} }
@Test @ParameterizedTest
public void testDetachedSignatureCreationAndVerification() throws IOException, PGPException { @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories")
public void testDetachedSignatureCreationAndVerification(ImplementationFactory implementationFactory) throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPSecretKeyRing signingKeys = TestKeys.getJulietSecretKeyRing(); PGPSecretKeyRing signingKeys = TestKeys.getJulietSecretKeyRing();
SecretKeyRingProtector keyRingProtector = new UnprotectedKeysProtector(); SecretKeyRingProtector keyRingProtector = new UnprotectedKeysProtector();
byte[] data = testMessage.getBytes(); byte[] data = testMessage.getBytes();
@ -230,8 +247,10 @@ public class EncryptDecryptTest {
assertFalse(metadata.getVerifiedSignatures().isEmpty()); assertFalse(metadata.getVerifiedSignatures().isEmpty());
} }
@Test @ParameterizedTest
public void testOnePassSignatureCreationAndVerification() throws IOException, PGPException { @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories")
public void testOnePassSignatureCreationAndVerification(ImplementationFactory implementationFactory) throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPSecretKeyRing signingKeys = TestKeys.getJulietSecretKeyRing(); PGPSecretKeyRing signingKeys = TestKeys.getJulietSecretKeyRing();
SecretKeyRingProtector keyRingProtector = new UnprotectedKeysProtector(); SecretKeyRingProtector keyRingProtector = new UnprotectedKeysProtector();
byte[] data = testMessage.getBytes(); byte[] data = testMessage.getBytes();

View file

@ -22,14 +22,18 @@ import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import org.bouncycastle.openpgp.PGPException; 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.PGPainless;
import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.util.Passphrase; import org.pgpainless.util.Passphrase;
public class EncryptionStreamClosedTest { public class EncryptionStreamClosedTest {
@Test @ParameterizedTest
public void testStreamHasToBeClosedBeforeGetResultCanBeCalled() throws IOException, PGPException { @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories")
public void testStreamHasToBeClosedBeforeGetResultCanBeCalled(ImplementationFactory implementationFactory) throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
OutputStream out = new ByteArrayOutputStream(); OutputStream out = new ByteArrayOutputStream();
EncryptionStream stream = PGPainless.encryptAndOrSign() EncryptionStream stream = PGPainless.encryptAndOrSign()
.onOutputStream(out) .onOutputStream(out)

View file

@ -34,13 +34,15 @@ import org.bouncycastle.openpgp.PGPSecretKey;
import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.bouncycastle.openpgp.PGPSecretKeyRingCollection; import org.bouncycastle.openpgp.PGPSecretKeyRingCollection;
import org.bouncycastle.util.io.Streams; 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.PGPainless;
import org.pgpainless.algorithm.CompressionAlgorithm; import org.pgpainless.algorithm.CompressionAlgorithm;
import org.pgpainless.algorithm.HashAlgorithm; import org.pgpainless.algorithm.HashAlgorithm;
import org.pgpainless.algorithm.SymmetricKeyAlgorithm; import org.pgpainless.algorithm.SymmetricKeyAlgorithm;
import org.pgpainless.decryption_verification.DecryptionStream; import org.pgpainless.decryption_verification.DecryptionStream;
import org.pgpainless.decryption_verification.OpenPgpMetadata; import org.pgpainless.decryption_verification.OpenPgpMetadata;
import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.OpenPgpV4Fingerprint; import org.pgpainless.key.OpenPgpV4Fingerprint;
import org.pgpainless.key.TestKeys; import org.pgpainless.key.TestKeys;
import org.pgpainless.key.protection.SecretKeyRingProtector; import org.pgpainless.key.protection.SecretKeyRingProtector;
@ -49,8 +51,10 @@ import org.pgpainless.util.selection.key.impl.SignatureKeySelectionStrategy;
public class SigningTest { public class SigningTest {
@Test @ParameterizedTest
public void testEncryptionAndSignatureVerification() throws IOException, PGPException { @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories")
public void testEncryptionAndSignatureVerification(ImplementationFactory implementationFactory) throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPPublicKeyRing julietKeys = TestKeys.getJulietPublicKeyRing(); PGPPublicKeyRing julietKeys = TestKeys.getJulietPublicKeyRing();
PGPPublicKeyRing romeoKeys = TestKeys.getRomeoPublicKeyRing(); PGPPublicKeyRing romeoKeys = TestKeys.getRomeoPublicKeyRing();

View file

@ -40,13 +40,17 @@ import org.bouncycastle.openpgp.operator.PGPDigestCalculator;
import org.bouncycastle.openpgp.operator.jcajce.JcaPGPContentSignerBuilder; import org.bouncycastle.openpgp.operator.jcajce.JcaPGPContentSignerBuilder;
import org.bouncycastle.openpgp.operator.jcajce.JcaPGPDigestCalculatorProviderBuilder; import org.bouncycastle.openpgp.operator.jcajce.JcaPGPDigestCalculatorProviderBuilder;
import org.bouncycastle.openpgp.operator.jcajce.JcaPGPKeyPair; 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; import org.pgpainless.provider.ProviderFactory;
public class BouncycastleExportSubkeys { public class BouncycastleExportSubkeys {
@Test @ParameterizedTest
public void testExportImport() throws NoSuchAlgorithmException, InvalidAlgorithmParameterException, PGPException { @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories")
public void testExportImport(ImplementationFactory implementationFactory) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
KeyPairGenerator generator; KeyPairGenerator generator;
KeyPair pair; KeyPair pair;

View file

@ -25,6 +25,9 @@ import org.bouncycastle.openpgp.PGPPublicKeyRing;
import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.bouncycastle.openpgp.operator.bc.BcKeyFingerprintCalculator; import org.bouncycastle.openpgp.operator.bc.BcKeyFingerprintCalculator;
import org.junit.jupiter.api.Test; 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 { public class ImportExportKeyTest {
@ -32,8 +35,10 @@ public class ImportExportKeyTest {
* Test the export and import of a key ring with sub keys. * Test the export and import of a key ring with sub keys.
* @throws IOException in case of a IO error * @throws IOException in case of a IO error
*/ */
@Test @ParameterizedTest
public void testExportImportPublicKeyRing() throws IOException { @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories")
public void testExportImportPublicKeyRing(ImplementationFactory implementationFactory) throws IOException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPPublicKeyRing publicKeys = TestKeys.getJulietPublicKeyRing(); PGPPublicKeyRing publicKeys = TestKeys.getJulietPublicKeyRing();
BcKeyFingerprintCalculator calc = new BcKeyFingerprintCalculator(); BcKeyFingerprintCalculator calc = new BcKeyFingerprintCalculator();

View file

@ -17,25 +17,30 @@ package org.pgpainless.key.generation;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException;
import java.security.InvalidAlgorithmParameterException; import java.security.InvalidAlgorithmParameterException;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPPublicKey; import org.bouncycastle.openpgp.PGPPublicKey;
import org.bouncycastle.openpgp.PGPSecretKeyRing; 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.PGPainless;
import org.pgpainless.algorithm.KeyFlag; import org.pgpainless.algorithm.KeyFlag;
import org.pgpainless.algorithm.PublicKeyAlgorithm; import org.pgpainless.algorithm.PublicKeyAlgorithm;
import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.generation.type.KeyType; import org.pgpainless.key.generation.type.KeyType;
import org.pgpainless.key.generation.type.ecc.EllipticCurve; import org.pgpainless.key.generation.type.ecc.EllipticCurve;
import org.pgpainless.key.info.KeyInfo; import org.pgpainless.key.info.KeyInfo;
public class BrainpoolKeyGeneration { public class BrainpoolKeyGeneration {
@Test @ParameterizedTest
public void generateEcKeysTest() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, IOException { @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories")
public void generateEcKeysTest(ImplementationFactory implementationFactory)
throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
for (EllipticCurve curve : EllipticCurve.values()) { for (EllipticCurve curve : EllipticCurve.values()) {
PGPSecretKeyRing secretKeys = generateKey( PGPSecretKeyRing secretKeys = generateKey(
KeySpec.getBuilder(KeyType.ECDSA(curve)) KeySpec.getBuilder(KeyType.ECDSA(curve))

View file

@ -17,9 +17,11 @@ package org.pgpainless.key.generation;
import static org.junit.jupiter.api.Assertions.assertThrows; 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.PGPainless;
import org.pgpainless.algorithm.KeyFlag; import org.pgpainless.algorithm.KeyFlag;
import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.generation.type.KeyType; import org.pgpainless.key.generation.type.KeyType;
import org.pgpainless.key.generation.type.ecc.EllipticCurve; import org.pgpainless.key.generation.type.ecc.EllipticCurve;
import org.pgpainless.key.generation.type.xdh.XDHCurve; import org.pgpainless.key.generation.type.xdh.XDHCurve;
@ -31,8 +33,10 @@ public class CertificationKeyMustBeAbleToCertifyTest {
* would result in an invalid key. * would result in an invalid key.
* This test therefore verifies that generating such keys fails. * This test therefore verifies that generating such keys fails.
*/ */
@Test @ParameterizedTest
public void testCertificationIncapableKeyTypesThrow() { @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories")
public void testCertificationIncapableKeyTypesThrow(ImplementationFactory implementationFactory) {
ImplementationFactory.setFactoryImplementation(implementationFactory);
KeyType[] typesIncapableOfCreatingVerifications = new KeyType[] { KeyType[] typesIncapableOfCreatingVerifications = new KeyType[] {
KeyType.ECDH(EllipticCurve._P256), KeyType.ECDH(EllipticCurve._P256),
KeyType.ECDH(EllipticCurve._P384), KeyType.ECDH(EllipticCurve._P384),

View file

@ -21,9 +21,11 @@ import java.security.NoSuchAlgorithmException;
import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPSecretKeyRing; 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.PGPainless;
import org.pgpainless.algorithm.KeyFlag; import org.pgpainless.algorithm.KeyFlag;
import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.generation.type.KeyType; import org.pgpainless.key.generation.type.KeyType;
import org.pgpainless.key.generation.type.eddsa.EdDSACurve; import org.pgpainless.key.generation.type.eddsa.EdDSACurve;
import org.pgpainless.key.generation.type.xdh.XDHCurve; import org.pgpainless.key.generation.type.xdh.XDHCurve;
@ -32,8 +34,10 @@ import org.pgpainless.util.ArmorUtils;
public class GenerateEllipticCurveKeyTest { public class GenerateEllipticCurveKeyTest {
@Test @ParameterizedTest
public void test() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, IOException { @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories")
public void test(ImplementationFactory implementationFactory) throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, IOException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPSecretKeyRing keyRing = PGPainless.generateKeyRing() PGPSecretKeyRing keyRing = PGPainless.generateKeyRing()
.withSubKey(KeySpec.getBuilder(KeyType.XDH(XDHCurve._X25519)) .withSubKey(KeySpec.getBuilder(KeyType.XDH(XDHCurve._X25519))
.withKeyFlags(KeyFlag.ENCRYPT_COMMS) .withKeyFlags(KeyFlag.ENCRYPT_COMMS)

View file

@ -26,8 +26,10 @@ import org.bouncycastle.bcpg.ArmoredOutputStream;
import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPPublicKeyRing; import org.bouncycastle.openpgp.PGPPublicKeyRing;
import org.bouncycastle.openpgp.PGPSecretKeyRing; 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.PGPainless;
import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.OpenPgpV4Fingerprint; import org.pgpainless.key.OpenPgpV4Fingerprint;
import org.pgpainless.key.util.KeyRingUtils; import org.pgpainless.key.util.KeyRingUtils;
import org.pgpainless.util.ArmoredOutputStreamFactory; import org.pgpainless.util.ArmoredOutputStreamFactory;
@ -36,8 +38,11 @@ public class GenerateKeyTest {
private static final Logger LOGGER = Logger.getLogger(GenerateKeyTest.class.getName()); private static final Logger LOGGER = Logger.getLogger(GenerateKeyTest.class.getName());
@Test @ParameterizedTest
public void generateKey() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, IOException { @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"); PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().simpleEcKeyRing("fresh@encrypted.key", "password123");
PGPPublicKeyRing publicKeys = KeyRingUtils.publicKeyRingFrom(secretKeys); PGPPublicKeyRing publicKeys = KeyRingUtils.publicKeyRingFrom(secretKeys);

View file

@ -30,9 +30,11 @@ import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPPublicKeyRing; import org.bouncycastle.openpgp.PGPPublicKeyRing;
import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.junit.JUtils; 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.PGPainless;
import org.pgpainless.algorithm.KeyFlag; import org.pgpainless.algorithm.KeyFlag;
import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.generation.type.KeyType; import org.pgpainless.key.generation.type.KeyType;
import org.pgpainless.key.generation.type.rsa.RsaLength; import org.pgpainless.key.generation.type.rsa.RsaLength;
import org.pgpainless.key.util.KeyRingUtils; import org.pgpainless.key.util.KeyRingUtils;
@ -40,8 +42,10 @@ import org.pgpainless.util.ArmoredOutputStreamFactory;
public class GenerateKeyWithAdditionalUserIdTest { public class GenerateKeyWithAdditionalUserIdTest {
@Test @ParameterizedTest
public void test() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, IOException { @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories")
public void test(ImplementationFactory implementationFactory) throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, IOException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
Date now = new Date(); Date now = new Date();
Date expiration = new Date(now.getTime() + 1000 * 60); Date expiration = new Date(now.getTime() + 1000 * 60);
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing() PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()

View file

@ -22,9 +22,11 @@ import java.security.InvalidAlgorithmParameterException;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import org.bouncycastle.openpgp.PGPException; 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.PGPainless;
import org.pgpainless.algorithm.KeyFlag; import org.pgpainless.algorithm.KeyFlag;
import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.generation.type.KeyType; import org.pgpainless.key.generation.type.KeyType;
import org.pgpainless.key.generation.type.rsa.RsaLength; import org.pgpainless.key.generation.type.rsa.RsaLength;
import org.pgpainless.util.Passphrase; import org.pgpainless.util.Passphrase;
@ -38,8 +40,11 @@ import org.pgpainless.util.Passphrase;
*/ */
public class GenerateWithEmptyPassphrase { public class GenerateWithEmptyPassphrase {
@Test @ParameterizedTest
public void testGeneratingKeyWithEmptyPassphraseDoesNotThrow() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, IOException { @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories")
public void testGeneratingKeyWithEmptyPassphraseDoesNotThrow(ImplementationFactory implementationFactory) throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, IOException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
assertNotNull(PGPainless.generateKeyRing() assertNotNull(PGPainless.generateKeyRing()
.withPrimaryKey(KeySpec.getBuilder(KeyType.RSA(RsaLength._3072)) .withPrimaryKey(KeySpec.getBuilder(KeyType.RSA(RsaLength._3072))
.withKeyFlags(KeyFlag.CERTIFY_OTHER, KeyFlag.SIGN_DATA, KeyFlag.ENCRYPT_COMMS) .withKeyFlags(KeyFlag.CERTIFY_OTHER, KeyFlag.SIGN_DATA, KeyFlag.ENCRYPT_COMMS)

View file

@ -17,17 +17,21 @@ package org.pgpainless.key.generation;
import static org.junit.jupiter.api.Assertions.assertThrows; 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.PGPainless;
import org.pgpainless.algorithm.KeyFlag; import org.pgpainless.algorithm.KeyFlag;
import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.generation.type.KeyType; import org.pgpainless.key.generation.type.KeyType;
import org.pgpainless.key.generation.type.eddsa.EdDSACurve; import org.pgpainless.key.generation.type.eddsa.EdDSACurve;
import org.pgpainless.key.generation.type.xdh.XDHCurve; import org.pgpainless.key.generation.type.xdh.XDHCurve;
public class IllegalKeyFlagsTest { public class IllegalKeyFlagsTest {
@Test @ParameterizedTest
public void testKeyCannotCarryFlagsTest() { @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories")
public void testKeyCannotCarryFlagsTest(ImplementationFactory implementationFactory) {
ImplementationFactory.setFactoryImplementation(implementationFactory);
assertThrows(IllegalArgumentException.class, () -> PGPainless.generateKeyRing() assertThrows(IllegalArgumentException.class, () -> PGPainless.generateKeyRing()
.withPrimaryKey(KeySpec.getBuilder(KeyType.XDH(XDHCurve._X25519)) .withPrimaryKey(KeySpec.getBuilder(KeyType.XDH(XDHCurve._X25519))
.withKeyFlags(KeyFlag.SIGN_DATA) // <- should throw .withKeyFlags(KeyFlag.SIGN_DATA) // <- should throw

View file

@ -29,20 +29,24 @@ import org.bouncycastle.openpgp.PGPPrivateKey;
import org.bouncycastle.openpgp.PGPPublicKey; import org.bouncycastle.openpgp.PGPPublicKey;
import org.bouncycastle.openpgp.PGPSecretKey; import org.bouncycastle.openpgp.PGPSecretKey;
import org.bouncycastle.openpgp.PGPSecretKeyRing; 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.PGPainless;
import org.pgpainless.algorithm.KeyFlag; import org.pgpainless.algorithm.KeyFlag;
import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.TestKeys; import org.pgpainless.key.TestKeys;
import org.pgpainless.key.generation.KeySpec; 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.EllipticCurve;
import org.pgpainless.key.generation.type.ecc.ecdsa.ECDSA;
import org.pgpainless.key.protection.PasswordBasedSecretKeyRingProtector; import org.pgpainless.key.protection.PasswordBasedSecretKeyRingProtector;
import org.pgpainless.util.Passphrase; import org.pgpainless.util.Passphrase;
public class AddSubKeyTest { public class AddSubKeyTest {
@Test @ParameterizedTest
public void testAddSubKey() throws IOException, PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException { @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories")
public void testAddSubKey(ImplementationFactory implementationFactory) throws IOException, PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPSecretKeyRing secretKeys = TestKeys.getCryptieSecretKeyRing(); PGPSecretKeyRing secretKeys = TestKeys.getCryptieSecretKeyRing();
List<Long> keyIdsBefore = new ArrayList<>(); List<Long> keyIdsBefore = new ArrayList<>();

View file

@ -28,7 +28,10 @@ import java.util.NoSuchElementException;
import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.junit.jupiter.api.Test; 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.PGPainless;
import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.TestKeys; import org.pgpainless.key.TestKeys;
import org.pgpainless.key.protection.PasswordBasedSecretKeyRingProtector; import org.pgpainless.key.protection.PasswordBasedSecretKeyRingProtector;
import org.pgpainless.key.protection.SecretKeyRingProtector; import org.pgpainless.key.protection.SecretKeyRingProtector;
@ -37,8 +40,10 @@ import org.pgpainless.util.Passphrase;
public class AddUserIdTest { public class AddUserIdTest {
@Test @ParameterizedTest
public void addUserIdToExistingKeyRing() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException { @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"); PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing().simpleEcKeyRing("alice@wonderland.lit", "rabb1th0le");
Iterator<String> userIds = secretKeys.getSecretKey().getPublicKey().getUserIDs(); Iterator<String> userIds = secretKeys.getSecretKey().getPublicKey().getUserIDs();

View file

@ -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.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull; 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.PGPException;
import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.junit.jupiter.api.Test; 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.PGPainless;
import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.OpenPgpV4Fingerprint; import org.pgpainless.key.OpenPgpV4Fingerprint;
import org.pgpainless.key.TestKeys; import org.pgpainless.key.TestKeys;
import org.pgpainless.key.info.KeyRingInfo; import org.pgpainless.key.info.KeyRingInfo;
import org.pgpainless.key.protection.UnprotectedKeysProtector; import org.pgpainless.key.protection.UnprotectedKeysProtector;
import java.io.IOException;
import java.util.Date;
public class ChangeExpirationTest { public class ChangeExpirationTest {
private final OpenPgpV4Fingerprint subKeyFingerprint = new OpenPgpV4Fingerprint("F73FDE6439ABE210B1AF4EDD273EF7A0C749807B"); private final OpenPgpV4Fingerprint subKeyFingerprint = new OpenPgpV4Fingerprint("F73FDE6439ABE210B1AF4EDD273EF7A0C749807B");
@Test @ParameterizedTest
public void setExpirationDateAndThenUnsetIt_OnPrimaryKey() throws PGPException, IOException, InterruptedException { @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories")
public void setExpirationDateAndThenUnsetIt_OnPrimaryKey(ImplementationFactory implementationFactory) throws PGPException, IOException, InterruptedException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPSecretKeyRing secretKeys = TestKeys.getEmilSecretKeyRing(); PGPSecretKeyRing secretKeys = TestKeys.getEmilSecretKeyRing();
KeyRingInfo sInfo = PGPainless.inspectKeyRing(secretKeys); KeyRingInfo sInfo = PGPainless.inspectKeyRing(secretKeys);

View file

@ -34,10 +34,12 @@ import org.bouncycastle.openpgp.operator.PGPDigestCalculatorProvider;
import org.bouncycastle.openpgp.operator.bc.BcPBESecretKeyDecryptorBuilder; import org.bouncycastle.openpgp.operator.bc.BcPBESecretKeyDecryptorBuilder;
import org.bouncycastle.openpgp.operator.bc.BcPGPDigestCalculatorProvider; import org.bouncycastle.openpgp.operator.bc.BcPGPDigestCalculatorProvider;
import org.bouncycastle.util.io.Streams; 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.PGPainless;
import org.pgpainless.algorithm.SymmetricKeyAlgorithm; import org.pgpainless.algorithm.SymmetricKeyAlgorithm;
import org.pgpainless.encryption_signing.EncryptionStream; import org.pgpainless.encryption_signing.EncryptionStream;
import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.protection.KeyRingProtectionSettings; import org.pgpainless.key.protection.KeyRingProtectionSettings;
import org.pgpainless.key.protection.PasswordBasedSecretKeyRingProtector; import org.pgpainless.key.protection.PasswordBasedSecretKeyRingProtector;
import org.pgpainless.util.Passphrase; import org.pgpainless.util.Passphrase;
@ -49,8 +51,10 @@ public class ChangeSecretKeyRingPassphraseTest {
public ChangeSecretKeyRingPassphraseTest() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException { public ChangeSecretKeyRingPassphraseTest() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException {
} }
@Test @ParameterizedTest
public void changePassphraseOfWholeKeyRingTest() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, IOException { @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories")
public void changePassphraseOfWholeKeyRingTest(ImplementationFactory implementationFactory) throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, IOException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPSecretKeyRing secretKeys = PGPainless.modifyKeyRing(keyRing) PGPSecretKeyRing secretKeys = PGPainless.modifyKeyRing(keyRing)
.changePassphraseFromOldPassphrase(Passphrase.fromPassword("weakPassphrase")) .changePassphraseFromOldPassphrase(Passphrase.fromPassword("weakPassphrase"))
@ -75,8 +79,10 @@ public class ChangeSecretKeyRingPassphraseTest {
"Unlocking the secret key ring with the new passphrase MUST succeed."); "Unlocking the secret key ring with the new passphrase MUST succeed.");
} }
@Test @ParameterizedTest
public void changePassphraseOfWholeKeyRingToEmptyPassphrase() throws PGPException, IOException { @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories")
public void changePassphraseOfWholeKeyRingToEmptyPassphrase(ImplementationFactory implementationFactory) throws PGPException, IOException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPSecretKeyRing secretKeys = PGPainless.modifyKeyRing(keyRing) PGPSecretKeyRing secretKeys = PGPainless.modifyKeyRing(keyRing)
.changePassphraseFromOldPassphrase(Passphrase.fromPassword("weakPassphrase")) .changePassphraseFromOldPassphrase(Passphrase.fromPassword("weakPassphrase"))
.withSecureDefaultSettings() .withSecureDefaultSettings()
@ -91,8 +97,10 @@ public class ChangeSecretKeyRingPassphraseTest {
signDummyMessageWithKeysAndPassphrase(changedPassphraseKeyRing, Passphrase.emptyPassphrase()); signDummyMessageWithKeysAndPassphrase(changedPassphraseKeyRing, Passphrase.emptyPassphrase());
} }
@Test @ParameterizedTest
public void changePassphraseOfSingleSubkeyToNewPassphrase() throws PGPException { @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories")
public void changePassphraseOfSingleSubkeyToNewPassphrase(ImplementationFactory implementationFactory) throws PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
Iterator<PGPSecretKey> keys = keyRing.getSecretKeys(); Iterator<PGPSecretKey> keys = keyRing.getSecretKeys();
PGPSecretKey primaryKey = keys.next(); PGPSecretKey primaryKey = keys.next();
@ -126,8 +134,11 @@ public class ChangeSecretKeyRingPassphraseTest {
"Unlocking the subkey with the primary key passphrase must fail."); "Unlocking the subkey with the primary key passphrase must fail.");
} }
@Test @ParameterizedTest
public void changePassphraseOfSingleSubkeyToEmptyPassphrase() throws PGPException { @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories")
public void changePassphraseOfSingleSubkeyToEmptyPassphrase(ImplementationFactory implementationFactory) throws PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
Iterator<PGPSecretKey> keys = keyRing.getSecretKeys(); Iterator<PGPSecretKey> keys = keyRing.getSecretKeys();
PGPSecretKey primaryKey = keys.next(); PGPSecretKey primaryKey = keys.next();
PGPSecretKey subKey = keys.next(); PGPSecretKey subKey = keys.next();

View file

@ -28,15 +28,20 @@ import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.bouncycastle.openpgp.PGPSignature; import org.bouncycastle.openpgp.PGPSignature;
import org.bouncycastle.openpgp.PGPSignatureSubpacketVector; 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.PGPainless;
import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.OpenPgpV4Fingerprint; import org.pgpainless.key.OpenPgpV4Fingerprint;
import org.pgpainless.key.protection.UnprotectedKeysProtector; import org.pgpainless.key.protection.UnprotectedKeysProtector;
public class OldSignatureSubpacketsArePreservedOnNewSig { public class OldSignatureSubpacketsArePreservedOnNewSig {
@Test @ParameterizedTest
public void verifyOldSignatureSubpacketsArePreservedOnNewExpirationDateSig() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, InterruptedException, IOException { @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories")
public void verifyOldSignatureSubpacketsArePreservedOnNewExpirationDateSig(ImplementationFactory implementationFactory)
throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, InterruptedException, IOException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing() PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
.simpleEcKeyRing("Alice <alice@wonderland.lit>"); .simpleEcKeyRing("Alice <alice@wonderland.lit>");

View file

@ -25,8 +25,10 @@ import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPPublicKey; import org.bouncycastle.openpgp.PGPPublicKey;
import org.bouncycastle.openpgp.PGPSecretKey; import org.bouncycastle.openpgp.PGPSecretKey;
import org.bouncycastle.openpgp.PGPSecretKeyRing; 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.PGPainless;
import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.protection.UnprotectedKeysProtector; import org.pgpainless.key.protection.UnprotectedKeysProtector;
import org.pgpainless.util.ArmoredOutputStreamFactory; import org.pgpainless.util.ArmoredOutputStreamFactory;
@ -72,8 +74,10 @@ public class RevokeKeyWithGenericCertificationSignatureTest {
} }
} }
@Test @ParameterizedTest
public void test() throws IOException, PGPException { @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories")
public void test(ImplementationFactory implementationFactory) throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
revokeKey(SAMPLE_PRIVATE_KEY); // would crash previously revokeKey(SAMPLE_PRIVATE_KEY); // would crash previously
} }

View file

@ -25,8 +25,10 @@ import java.util.List;
import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPSecretKey; import org.bouncycastle.openpgp.PGPSecretKey;
import org.bouncycastle.openpgp.PGPSecretKeyRing; 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.PGPainless;
import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.OpenPgpV4Fingerprint; import org.pgpainless.key.OpenPgpV4Fingerprint;
import org.pgpainless.key.info.KeyRingInfo; import org.pgpainless.key.info.KeyRingInfo;
import org.pgpainless.key.modification.secretkeyring.SecretKeyRingEditorInterface; import org.pgpainless.key.modification.secretkeyring.SecretKeyRingEditorInterface;
@ -109,8 +111,10 @@ public class RevokeKeyWithoutPreferredAlgorithmsOnPrimaryKey {
"=3Zyp\n" + "=3Zyp\n" +
"-----END PGP PRIVATE KEY BLOCK-----"; "-----END PGP PRIVATE KEY BLOCK-----";
@Test @ParameterizedTest
public void testChangingExpirationTimeWithKeyWithoutPrefAlgos() throws IOException, PGPException { @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories")
public void testChangingExpirationTimeWithKeyWithoutPrefAlgos(ImplementationFactory implementationFactory) throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
Date expirationDate = new Date(); Date expirationDate = new Date();
PGPSecretKeyRing secretKeys = PGPainless.readKeyRing().secretKeyRing(KEY); PGPSecretKeyRing secretKeys = PGPainless.readKeyRing().secretKeyRing(KEY);
List<OpenPgpV4Fingerprint> fingerprintList = new ArrayList<>(); List<OpenPgpV4Fingerprint> fingerprintList = new ArrayList<>();

View file

@ -29,8 +29,11 @@ import org.bouncycastle.openpgp.PGPSecretKey;
import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.bouncycastle.openpgp.PGPSignature; import org.bouncycastle.openpgp.PGPSignature;
import org.junit.jupiter.api.Test; 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.PGPainless;
import org.pgpainless.algorithm.SignatureType; import org.pgpainless.algorithm.SignatureType;
import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.OpenPgpV4Fingerprint; import org.pgpainless.key.OpenPgpV4Fingerprint;
import org.pgpainless.key.TestKeys; import org.pgpainless.key.TestKeys;
import org.pgpainless.key.modification.secretkeyring.SecretKeyRingEditorInterface; import org.pgpainless.key.modification.secretkeyring.SecretKeyRingEditorInterface;
@ -42,8 +45,10 @@ import org.pgpainless.util.Passphrase;
public class RevokeSubKeyTest { public class RevokeSubKeyTest {
@Test @ParameterizedTest
public void revokeSukeyTest() throws IOException, PGPException { @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories")
public void revokeSukeyTest(ImplementationFactory implementationFactory) throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPSecretKeyRing secretKeys = TestKeys.getCryptieSecretKeyRing(); PGPSecretKeyRing secretKeys = TestKeys.getCryptieSecretKeyRing();
Iterator<PGPSecretKey> keysIterator = secretKeys.iterator(); Iterator<PGPSecretKey> keysIterator = secretKeys.iterator();
@ -65,8 +70,10 @@ public class RevokeSubKeyTest {
assertTrue(subKey.getPublicKey().hasRevocation()); assertTrue(subKey.getPublicKey().hasRevocation());
} }
@Test @ParameterizedTest
public void detachedRevokeSubkeyTest() throws IOException, PGPException { @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories")
public void detachedRevokeSubkeyTest(ImplementationFactory implementationFactory) throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPSecretKeyRing secretKeys = TestKeys.getCryptieSecretKeyRing(); PGPSecretKeyRing secretKeys = TestKeys.getCryptieSecretKeyRing();
OpenPgpV4Fingerprint fingerprint = new OpenPgpV4Fingerprint(secretKeys); OpenPgpV4Fingerprint fingerprint = new OpenPgpV4Fingerprint(secretKeys);
SecretKeyRingProtector protector = PasswordBasedSecretKeyRingProtector.forKey(secretKeys, Passphrase.fromPassword("password123")); SecretKeyRingProtector protector = PasswordBasedSecretKeyRingProtector.forKey(secretKeys, Passphrase.fromPassword("password123"));
@ -89,8 +96,10 @@ public class RevokeSubKeyTest {
assertTrue(publicKey.hasRevocation()); assertTrue(publicKey.hasRevocation());
} }
@Test @ParameterizedTest
public void testRevocationSignatureTypeCorrect() throws IOException, PGPException { @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories")
public void testRevocationSignatureTypeCorrect(ImplementationFactory implementationFactory) throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPSecretKeyRing secretKeys = TestKeys.getCryptieSecretKeyRing(); PGPSecretKeyRing secretKeys = TestKeys.getCryptieSecretKeyRing();
Iterator<PGPPublicKey> keysIterator = secretKeys.getPublicKeys(); Iterator<PGPPublicKey> keysIterator = secretKeys.getPublicKeys();
PGPPublicKey primaryKey = keysIterator.next(); PGPPublicKey primaryKey = keysIterator.next();

View file

@ -35,15 +35,21 @@ import org.bouncycastle.openpgp.PGPSecretKey;
import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.bouncycastle.openpgp.operator.PBESecretKeyDecryptor; import org.bouncycastle.openpgp.operator.PBESecretKeyDecryptor;
import org.junit.jupiter.api.Test; 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.PGPainless;
import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.TestKeys; import org.pgpainless.key.TestKeys;
import org.pgpainless.key.protection.passphrase_provider.SecretKeyPassphraseProvider; import org.pgpainless.key.protection.passphrase_provider.SecretKeyPassphraseProvider;
import org.pgpainless.util.Passphrase; import org.pgpainless.util.Passphrase;
public class SecretKeyRingProtectorTest { public class SecretKeyRingProtectorTest {
@Test @ParameterizedTest
public void testUnlockAllKeysWithSamePassword() throws IOException, PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException { @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories")
public void testUnlockAllKeysWithSamePassword(ImplementationFactory implementationFactory) throws IOException, PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPSecretKeyRing secretKeys = TestKeys.getCryptieSecretKeyRing(); PGPSecretKeyRing secretKeys = TestKeys.getCryptieSecretKeyRing();
SecretKeyRingProtector protector = SecretKeyRingProtector.unlockAllKeysWith(TestKeys.CRYPTIE_PASSPHRASE, secretKeys); SecretKeyRingProtector protector = SecretKeyRingProtector.unlockAllKeysWith(TestKeys.CRYPTIE_PASSPHRASE, secretKeys);
for (PGPSecretKey secretKey : secretKeys) { for (PGPSecretKey secretKey : secretKeys) {
@ -71,8 +77,11 @@ public class SecretKeyRingProtectorTest {
} }
} }
@Test @ParameterizedTest
public void testUnlockSingleKeyWithPassphrase() throws IOException, PGPException { @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories")
public void testUnlockSingleKeyWithPassphrase(ImplementationFactory implementationFactory) throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPSecretKeyRing secretKeys = TestKeys.getCryptieSecretKeyRing(); PGPSecretKeyRing secretKeys = TestKeys.getCryptieSecretKeyRing();
Iterator<PGPSecretKey> iterator = secretKeys.iterator(); Iterator<PGPSecretKey> iterator = secretKeys.iterator();
PGPSecretKey secretKey = iterator.next(); PGPSecretKey secretKey = iterator.next();
@ -118,8 +127,10 @@ public class SecretKeyRingProtectorTest {
assertEquals(Passphrase.fromPassword("missingP455w0rd"), protector.getPassphraseFor(3L)); assertEquals(Passphrase.fromPassword("missingP455w0rd"), protector.getPassphraseFor(3L));
} }
@Test @ParameterizedTest
public void testCallbackBasedKeyRingProtector() throws IOException, PGPException { @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories")
public void testCallbackBasedKeyRingProtector(ImplementationFactory implementationFactory) throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
SecretKeyRingProtector2 protector = new CallbackBasedKeyringProtector(new CallbackBasedKeyringProtector.Callback() { SecretKeyRingProtector2 protector = new CallbackBasedKeyringProtector(new CallbackBasedKeyringProtector.Callback() {
@Override @Override
public Passphrase getPassphraseFor(PGPSecretKey secretKey) { public Passphrase getPassphraseFor(PGPSecretKey secretKey) {
@ -130,6 +141,7 @@ public class SecretKeyRingProtectorTest {
PGPSecretKeyRing secretKeys = TestKeys.getEmilSecretKeyRing(); PGPSecretKeyRing secretKeys = TestKeys.getEmilSecretKeyRing();
for (PGPSecretKey secretKey : secretKeys) { for (PGPSecretKey secretKey : secretKeys) {
secretKey.extractPrivateKey(protector.getDecryptor(secretKey)); secretKey.extractPrivateKey(protector.getDecryptor(secretKey));
assertNotNull(protector.getEncryptor(secretKey));
} }
} }
} }

View file

@ -24,9 +24,11 @@ import java.util.logging.Logger;
import org.bouncycastle.bcpg.ArmoredOutputStream; import org.bouncycastle.bcpg.ArmoredOutputStream;
import org.bouncycastle.openpgp.PGPException; 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.PGPainless;
import org.pgpainless.algorithm.SymmetricKeyAlgorithm; import org.pgpainless.algorithm.SymmetricKeyAlgorithm;
import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.util.ArmoredOutputStreamFactory; import org.pgpainless.util.ArmoredOutputStreamFactory;
import org.pgpainless.util.Passphrase; import org.pgpainless.util.Passphrase;
@ -46,8 +48,10 @@ public class LegacySymmetricEncryptionTest {
"- Edward Snowden -"; "- Edward Snowden -";
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@Test @ParameterizedTest
public void testSymmetricEncryptionDecryption() throws IOException, PGPException { @MethodSource("org.pgpainless.util.TestUtil#provideImplementationFactories")
public void testSymmetricEncryptionDecryption(ImplementationFactory implementationFactory) throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
byte[] plain = message.getBytes(); byte[] plain = message.getBytes();
String password = "choose_a_better_password_please"; String password = "choose_a_better_password_please";
Passphrase passphrase = new Passphrase(password.toCharArray()); Passphrase passphrase = new Passphrase(password.toCharArray());

View file

@ -22,16 +22,20 @@ import java.nio.charset.StandardCharsets;
import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.util.io.Streams; 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.PGPainless;
import org.pgpainless.decryption_verification.DecryptionStream; import org.pgpainless.decryption_verification.DecryptionStream;
import org.pgpainless.encryption_signing.EncryptionStream; import org.pgpainless.encryption_signing.EncryptionStream;
import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.util.Passphrase; import org.pgpainless.util.Passphrase;
public class MultiPassphraseSymmetricEncryptionTest { public class MultiPassphraseSymmetricEncryptionTest {
@Test @ParameterizedTest
public void test() throws IOException, PGPException { @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, " + 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."; "the decryptor finds the session key encrypted for the right passphrase.";
ByteArrayInputStream plaintextIn = new ByteArrayInputStream(message.getBytes(StandardCharsets.UTF_8)); ByteArrayInputStream plaintextIn = new ByteArrayInputStream(message.getBytes(StandardCharsets.UTF_8));

View file

@ -26,10 +26,12 @@ import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPPublicKeyRing; import org.bouncycastle.openpgp.PGPPublicKeyRing;
import org.bouncycastle.openpgp.PGPSecretKeyRingCollection; import org.bouncycastle.openpgp.PGPSecretKeyRingCollection;
import org.bouncycastle.util.io.Streams; 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.PGPainless;
import org.pgpainless.decryption_verification.DecryptionStream; import org.pgpainless.decryption_verification.DecryptionStream;
import org.pgpainless.encryption_signing.EncryptionStream; import org.pgpainless.encryption_signing.EncryptionStream;
import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.TestKeys; import org.pgpainless.key.TestKeys;
import org.pgpainless.key.protection.KeyRingProtectionSettings; import org.pgpainless.key.protection.KeyRingProtectionSettings;
import org.pgpainless.key.protection.PasswordBasedSecretKeyRingProtector; import org.pgpainless.key.protection.PasswordBasedSecretKeyRingProtector;
@ -42,8 +44,10 @@ import org.pgpainless.util.Passphrase;
*/ */
public class SymmetricEncryptionTest { public class SymmetricEncryptionTest {
@Test @ParameterizedTest
public void test() throws IOException, PGPException { @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); byte[] plaintext = "This is a secret message".getBytes(StandardCharsets.UTF_8);
ByteArrayInputStream plaintextIn = new ByteArrayInputStream(plaintext); ByteArrayInputStream plaintextIn = new ByteArrayInputStream(plaintext);
PGPPublicKeyRing encryptionKey = TestKeys.getCryptiePublicKeyRing(); PGPPublicKeyRing encryptionKey = TestKeys.getCryptiePublicKeyRing();