1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-26 22:32:07 +01:00

Replace @ArgumentSource with @TestTemplate, @ExtendWith

This commit is contained in:
Paul Schaub 2021-12-14 16:55:04 +01:00
parent 2ebf4be39c
commit c331dee6b1
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
37 changed files with 514 additions and 586 deletions

View file

@ -19,18 +19,17 @@ import org.bouncycastle.openpgp.PGPLiteralData;
import org.bouncycastle.openpgp.PGPLiteralDataGenerator; import org.bouncycastle.openpgp.PGPLiteralDataGenerator;
import org.bouncycastle.openpgp.PGPObjectFactory; import org.bouncycastle.openpgp.PGPObjectFactory;
import org.bouncycastle.util.io.Streams; import org.bouncycastle.util.io.Streams;
import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.params.provider.ArgumentsSource; import org.junit.jupiter.api.extension.ExtendWith;
import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.util.ImplementationFactoryTestInvocationContextProvider;
import org.pgpainless.util.PGPUtilWrapper; import org.pgpainless.util.PGPUtilWrapper;
import org.pgpainless.util.TestImplementationFactoryProvider;
public class PGPUtilWrapperTest { public class PGPUtilWrapperTest {
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void testGetDecoderStream(ImplementationFactory implementationFactory) throws IOException { public void testGetDecoderStream() throws IOException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
ByteArrayInputStream msg = new ByteArrayInputStream("Foo\nBar".getBytes(StandardCharsets.UTF_8)); ByteArrayInputStream msg = new ByteArrayInputStream("Foo\nBar".getBytes(StandardCharsets.UTF_8));
PGPLiteralDataGenerator literalDataGenerator = new PGPLiteralDataGenerator(); PGPLiteralDataGenerator literalDataGenerator = new PGPLiteralDataGenerator();

View file

@ -17,16 +17,15 @@ import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.bouncycastle.openpgp.PGPSecretKeyRing;
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.params.ParameterizedTest; import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.params.provider.ArgumentsSource; import org.junit.jupiter.api.extension.ExtendWith;
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.SubkeyIdentifier; import org.pgpainless.key.SubkeyIdentifier;
import org.pgpainless.key.TestKeys; import org.pgpainless.key.TestKeys;
import org.pgpainless.key.util.KeyRingUtils; import org.pgpainless.key.util.KeyRingUtils;
import org.pgpainless.util.TestImplementationFactoryProvider; import org.pgpainless.util.ImplementationFactoryTestInvocationContextProvider;
public class DecryptAndVerifyMessageTest { public class DecryptAndVerifyMessageTest {
@ -42,10 +41,9 @@ public class DecryptAndVerifyMessageTest {
romeo = TestKeys.getRomeoSecretKeyRing(); romeo = TestKeys.getRomeoSecretKeyRing();
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void decryptMessageAndVerifySignatureTest(ImplementationFactory implementationFactory) throws Exception { public void decryptMessageAndVerifySignatureTest() throws Exception {
ImplementationFactory.setFactoryImplementation(implementationFactory);
String encryptedMessage = TestKeys.MSG_SIGN_CRYPT_JULIET_JULIET; String encryptedMessage = TestKeys.MSG_SIGN_CRYPT_JULIET_JULIET;
ConsumerOptions options = new ConsumerOptions() ConsumerOptions options = new ConsumerOptions()

View file

@ -16,21 +16,19 @@ 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.bouncycastle.util.io.Streams; import org.bouncycastle.util.io.Streams;
import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.params.provider.ArgumentsSource; import org.junit.jupiter.api.extension.ExtendWith;
import org.pgpainless.PGPainless; import org.pgpainless.PGPainless;
import org.pgpainless.algorithm.EncryptionPurpose; import org.pgpainless.algorithm.EncryptionPurpose;
import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.SubkeyIdentifier; import org.pgpainless.key.SubkeyIdentifier;
import org.pgpainless.key.info.KeyRingInfo; import org.pgpainless.key.info.KeyRingInfo;
import org.pgpainless.util.TestImplementationFactoryProvider; import org.pgpainless.util.ImplementationFactoryTestInvocationContextProvider;
public class DecryptHiddenRecipientMessage { public class DecryptHiddenRecipientMessage {
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void testDecryptionWithWildcardRecipient(ImplementationFactory implementationFactory) throws IOException, PGPException { public void testDecryptionWithWildcardRecipient() 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

@ -18,15 +18,14 @@ 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.params.ParameterizedTest; import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.params.provider.ArgumentsSource; import org.junit.jupiter.api.extension.ExtendWith;
import org.pgpainless.PGPainless; import org.pgpainless.PGPainless;
import org.pgpainless.exception.MessageNotIntegrityProtectedException; import org.pgpainless.exception.MessageNotIntegrityProtectedException;
import org.pgpainless.exception.ModificationDetectionException; import org.pgpainless.exception.ModificationDetectionException;
import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.protection.SecretKeyRingProtector; import org.pgpainless.key.protection.SecretKeyRingProtector;
import org.pgpainless.util.ImplementationFactoryTestInvocationContextProvider;
import org.pgpainless.util.Passphrase; import org.pgpainless.util.Passphrase;
import org.pgpainless.util.TestImplementationFactoryProvider;
public class ModificationDetectionTests { public class ModificationDetectionTests {
@ -205,14 +204,12 @@ public class ModificationDetectionTests {
/** /**
* Messages containing a missing MDC shall fail to decrypt. * Messages containing a missing MDC shall fail to decrypt.
* @param implementationFactory implementation factory
* @throws IOException in case of an io-error * @throws IOException in case of an io-error
* @throws PGPException in case of a pgp error * @throws PGPException in case of a pgp error
*/ */
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void testMissingMDCThrowsByDefault(ImplementationFactory implementationFactory) throws IOException, PGPException { public void testMissingMDCThrowsByDefault() throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPSecretKeyRingCollection secretKeyRings = getDecryptionKey(); PGPSecretKeyRingCollection secretKeyRings = getDecryptionKey();
@ -230,10 +227,9 @@ public class ModificationDetectionTests {
}); });
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void testTamperedCiphertextThrows(ImplementationFactory implementationFactory) throws IOException, PGPException { public void testTamperedCiphertextThrows() throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE_TAMPERED_CIPHERTEXT.getBytes(StandardCharsets.UTF_8)); ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE_TAMPERED_CIPHERTEXT.getBytes(StandardCharsets.UTF_8));
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify() DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
.onInputStream(in) .onInputStream(in)
@ -246,10 +242,9 @@ public class ModificationDetectionTests {
assertThrows(ModificationDetectionException.class, decryptionStream::close); assertThrows(ModificationDetectionException.class, decryptionStream::close);
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void testIgnoreTamperedCiphertext(ImplementationFactory implementationFactory) throws IOException, PGPException { public void testIgnoreTamperedCiphertext() throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE_TAMPERED_CIPHERTEXT.getBytes(StandardCharsets.UTF_8)); ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE_TAMPERED_CIPHERTEXT.getBytes(StandardCharsets.UTF_8));
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify() DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
.onInputStream(in) .onInputStream(in)
@ -263,10 +258,9 @@ public class ModificationDetectionTests {
decryptionStream.close(); decryptionStream.close();
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void testTamperedMDCThrowsByDefault(ImplementationFactory implementationFactory) throws IOException, PGPException { public void testTamperedMDCThrowsByDefault() throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE_TAMPERED_MDC.getBytes(StandardCharsets.UTF_8)); ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE_TAMPERED_MDC.getBytes(StandardCharsets.UTF_8));
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify() DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
.onInputStream(in) .onInputStream(in)
@ -279,10 +273,9 @@ public class ModificationDetectionTests {
assertThrows(ModificationDetectionException.class, decryptionStream::close); assertThrows(ModificationDetectionException.class, decryptionStream::close);
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void testIgnoreTamperedMDC(ImplementationFactory implementationFactory) throws IOException, PGPException { public void testIgnoreTamperedMDC() throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE_TAMPERED_MDC.getBytes(StandardCharsets.UTF_8)); ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE_TAMPERED_MDC.getBytes(StandardCharsets.UTF_8));
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify() DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
.onInputStream(in) .onInputStream(in)
@ -295,10 +288,9 @@ public class ModificationDetectionTests {
Streams.pipeAll(decryptionStream, out); Streams.pipeAll(decryptionStream, out);
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void testTruncatedMDCThrows(ImplementationFactory implementationFactory) throws IOException, PGPException { public void testTruncatedMDCThrows() throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE_TRUNCATED_MDC.getBytes(StandardCharsets.UTF_8)); ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE_TRUNCATED_MDC.getBytes(StandardCharsets.UTF_8));
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify() DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
.onInputStream(in) .onInputStream(in)
@ -310,10 +302,9 @@ public class ModificationDetectionTests {
assertThrows(EOFException.class, () -> Streams.pipeAll(decryptionStream, out)); assertThrows(EOFException.class, () -> Streams.pipeAll(decryptionStream, out));
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void testMDCWithBadCTBThrows(ImplementationFactory implementationFactory) throws IOException, PGPException { public void testMDCWithBadCTBThrows() throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE_MDC_WITH_BAD_CTB.getBytes(StandardCharsets.UTF_8)); ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE_MDC_WITH_BAD_CTB.getBytes(StandardCharsets.UTF_8));
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify() DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
.onInputStream(in) .onInputStream(in)
@ -326,10 +317,9 @@ public class ModificationDetectionTests {
assertThrows(ModificationDetectionException.class, decryptionStream::close); assertThrows(ModificationDetectionException.class, decryptionStream::close);
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void testIgnoreMDCWithBadCTB(ImplementationFactory implementationFactory) throws IOException, PGPException { public void testIgnoreMDCWithBadCTB() throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE_MDC_WITH_BAD_CTB.getBytes(StandardCharsets.UTF_8)); ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE_MDC_WITH_BAD_CTB.getBytes(StandardCharsets.UTF_8));
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify() DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
.onInputStream(in) .onInputStream(in)
@ -343,10 +333,9 @@ public class ModificationDetectionTests {
decryptionStream.close(); decryptionStream.close();
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void testMDCWithBadLengthThrows(ImplementationFactory implementationFactory) throws IOException, PGPException { public void testMDCWithBadLengthThrows() throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE_MDC_WITH_BAD_LENGTH.getBytes(StandardCharsets.UTF_8)); ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE_MDC_WITH_BAD_LENGTH.getBytes(StandardCharsets.UTF_8));
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify() DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
.onInputStream(in) .onInputStream(in)
@ -359,10 +348,9 @@ public class ModificationDetectionTests {
assertThrows(ModificationDetectionException.class, decryptionStream::close); assertThrows(ModificationDetectionException.class, decryptionStream::close);
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void testIgnoreMDCWithBadLength(ImplementationFactory implementationFactory) throws IOException, PGPException { public void testIgnoreMDCWithBadLength() throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE_MDC_WITH_BAD_LENGTH.getBytes(StandardCharsets.UTF_8)); ByteArrayInputStream in = new ByteArrayInputStream(MESSAGE_MDC_WITH_BAD_LENGTH.getBytes(StandardCharsets.UTF_8));
DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify() DecryptionStream decryptionStream = PGPainless.decryptAndOrVerify()
.onInputStream(in) .onInputStream(in)
@ -376,10 +364,9 @@ public class ModificationDetectionTests {
decryptionStream.close(); decryptionStream.close();
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void decryptMessageWithSEDPacket(ImplementationFactory implementationFactory) throws IOException { public void decryptMessageWithSEDPacket() throws IOException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
Passphrase passphrase = Passphrase.fromPassword("flowcrypt compatibility tests"); Passphrase passphrase = Passphrase.fromPassword("flowcrypt compatibility tests");
String key = "-----BEGIN PGP PRIVATE KEY BLOCK-----\r\n" + String key = "-----BEGIN PGP PRIVATE KEY BLOCK-----\r\n" +
"Version: FlowCrypt 6.9.1 Gmail Encryption\r\n" + "Version: FlowCrypt 6.9.1 Gmail Encryption\r\n" +

View file

@ -14,11 +14,10 @@ import java.nio.charset.StandardCharsets;
import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.bouncycastle.util.io.Streams; import org.bouncycastle.util.io.Streams;
import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.params.provider.ArgumentsSource; import org.junit.jupiter.api.extension.ExtendWith;
import org.pgpainless.PGPainless; import org.pgpainless.PGPainless;
import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.util.ImplementationFactoryTestInvocationContextProvider;
import org.pgpainless.util.TestImplementationFactoryProvider;
public class RecursionDepthTest { public class RecursionDepthTest {
@ -27,11 +26,10 @@ public class RecursionDepthTest {
* *
* @see <a href="https://tests.sequoia-pgp.org/#Maximum_recursion_depth">Sequoia-PGP Test Suite</a> * @see <a href="https://tests.sequoia-pgp.org/#Maximum_recursion_depth">Sequoia-PGP Test Suite</a>
*/ */
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void decryptionAbortsWhenMaximumRecursionDepthReachedTest(ImplementationFactory implementationFactory) public void decryptionAbortsWhenMaximumRecursionDepthReachedTest()
throws IOException { throws IOException {
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

@ -25,8 +25,8 @@ 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.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.params.provider.ArgumentsSource; import org.junit.jupiter.api.extension.ExtendWith;
import org.pgpainless.PGPainless; import org.pgpainless.PGPainless;
import org.pgpainless.algorithm.DocumentSignatureType; import org.pgpainless.algorithm.DocumentSignatureType;
import org.pgpainless.algorithm.KeyFlag; import org.pgpainless.algorithm.KeyFlag;
@ -34,7 +34,6 @@ import org.pgpainless.algorithm.SymmetricKeyAlgorithm;
import org.pgpainless.decryption_verification.ConsumerOptions; import org.pgpainless.decryption_verification.ConsumerOptions;
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.SubkeyIdentifier; import org.pgpainless.key.SubkeyIdentifier;
import org.pgpainless.key.TestKeys; import org.pgpainless.key.TestKeys;
import org.pgpainless.key.generation.KeySpec; import org.pgpainless.key.generation.KeySpec;
@ -47,7 +46,7 @@ import org.pgpainless.key.protection.UnprotectedKeysProtector;
import org.pgpainless.key.util.KeyRingUtils; import org.pgpainless.key.util.KeyRingUtils;
import org.pgpainless.policy.Policy; import org.pgpainless.policy.Policy;
import org.pgpainless.util.ArmoredOutputStreamFactory; import org.pgpainless.util.ArmoredOutputStreamFactory;
import org.pgpainless.util.TestImplementationFactoryProvider; import org.pgpainless.util.ImplementationFactoryTestInvocationContextProvider;
public class EncryptDecryptTest { public class EncryptDecryptTest {
@ -70,11 +69,10 @@ public class EncryptDecryptTest {
Policy.SymmetricKeyAlgorithmPolicy.defaultSymmetricKeyDecryptionAlgorithmPolicy()); Policy.SymmetricKeyAlgorithmPolicy.defaultSymmetricKeyDecryptionAlgorithmPolicy());
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void freshKeysRsaToElGamalTest(ImplementationFactory implementationFactory) public void freshKeysRsaToElGamalTest()
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.buildKeyRing() PGPSecretKeyRing recipient = PGPainless.buildKeyRing()
.setPrimaryKey(KeySpec.getBuilder( .setPrimaryKey(KeySpec.getBuilder(
@ -88,54 +86,49 @@ public class EncryptDecryptTest {
encryptDecryptForSecretKeyRings(sender, recipient); encryptDecryptForSecretKeyRings(sender, recipient);
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void freshKeysRsaToRsaTest(ImplementationFactory implementationFactory) public void freshKeysRsaToRsaTest()
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);
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void freshKeysEcToEcTest(ImplementationFactory implementationFactory) public void freshKeysEcToEcTest()
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);
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void freshKeysEcToRsaTest(ImplementationFactory implementationFactory) public void freshKeysEcToRsaTest()
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);
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void freshKeysRsaToEcTest(ImplementationFactory implementationFactory) public void freshKeysRsaToEcTest()
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);
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void existingRsaKeysTest(ImplementationFactory implementationFactory) throws IOException, PGPException { public void existingRsaKeysTest() throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPSecretKeyRing sender = TestKeys.getJulietSecretKeyRing(); PGPSecretKeyRing sender = TestKeys.getJulietSecretKeyRing();
PGPSecretKeyRing recipient = TestKeys.getRomeoSecretKeyRing(); PGPSecretKeyRing recipient = TestKeys.getRomeoSecretKeyRing();
@ -197,10 +190,9 @@ public class EncryptDecryptTest {
assertTrue(result.isVerified()); assertTrue(result.isVerified());
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void testDetachedSignatureCreationAndVerification(ImplementationFactory implementationFactory) throws IOException, PGPException { public void testDetachedSignatureCreationAndVerification() throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPSecretKeyRing signingKeys = TestKeys.getJulietSecretKeyRing(); PGPSecretKeyRing signingKeys = TestKeys.getJulietSecretKeyRing();
SecretKeyRingProtector keyRingProtector = new UnprotectedKeysProtector(); SecretKeyRingProtector keyRingProtector = new UnprotectedKeysProtector();
@ -243,10 +235,9 @@ public class EncryptDecryptTest {
assertFalse(decryptionResult.getVerifiedSignatures().isEmpty()); assertFalse(decryptionResult.getVerifiedSignatures().isEmpty());
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void testOnePassSignatureCreationAndVerification(ImplementationFactory implementationFactory) throws IOException, PGPException { public void testOnePassSignatureCreationAndVerification() 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();
@ -274,10 +265,9 @@ public class EncryptDecryptTest {
assertFalse(metadata.getVerifiedSignatures().isEmpty()); assertFalse(metadata.getVerifiedSignatures().isEmpty());
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void expiredSubkeyBacksigTest(ImplementationFactory implementationFactory) throws IOException { public void expiredSubkeyBacksigTest() throws IOException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" + String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"\n" + "\n" +
"xsDNBF2lnPIBDAC5cL9PQoQLTMuhjbYvb4Ncuuo0bfmgPRFywX53jPhoFf4Zg6mv\n" + "xsDNBF2lnPIBDAC5cL9PQoQLTMuhjbYvb4Ncuuo0bfmgPRFywX53jPhoFf4Zg6mv\n" +

View file

@ -11,19 +11,17 @@ 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.params.ParameterizedTest; import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.params.provider.ArgumentsSource; import org.junit.jupiter.api.extension.ExtendWith;
import org.pgpainless.PGPainless; import org.pgpainless.PGPainless;
import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.util.ImplementationFactoryTestInvocationContextProvider;
import org.pgpainless.util.Passphrase; import org.pgpainless.util.Passphrase;
import org.pgpainless.util.TestImplementationFactoryProvider;
public class EncryptionStreamClosedTest { public class EncryptionStreamClosedTest {
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void testStreamHasToBeClosedBeforeGetResultCanBeCalled(ImplementationFactory implementationFactory) throws IOException, PGPException { public void testStreamHasToBeClosedBeforeGetResultCanBeCalled() 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

@ -26,8 +26,8 @@ import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.bouncycastle.openpgp.PGPSecretKeyRingCollection; import org.bouncycastle.openpgp.PGPSecretKeyRingCollection;
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.params.ParameterizedTest; import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.params.provider.ArgumentsSource; import org.junit.jupiter.api.extension.ExtendWith;
import org.pgpainless.PGPainless; import org.pgpainless.PGPainless;
import org.pgpainless.algorithm.DocumentSignatureType; import org.pgpainless.algorithm.DocumentSignatureType;
import org.pgpainless.algorithm.HashAlgorithm; import org.pgpainless.algorithm.HashAlgorithm;
@ -37,7 +37,6 @@ import org.pgpainless.decryption_verification.DecryptionStream;
import org.pgpainless.decryption_verification.OpenPgpMetadata; import org.pgpainless.decryption_verification.OpenPgpMetadata;
import org.pgpainless.exception.KeyCannotSignException; import org.pgpainless.exception.KeyCannotSignException;
import org.pgpainless.exception.KeyValidationError; import org.pgpainless.exception.KeyValidationError;
import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.SubkeyIdentifier; import org.pgpainless.key.SubkeyIdentifier;
import org.pgpainless.key.TestKeys; import org.pgpainless.key.TestKeys;
import org.pgpainless.key.generation.KeySpec; import org.pgpainless.key.generation.KeySpec;
@ -46,17 +45,16 @@ import org.pgpainless.key.generation.type.eddsa.EdDSACurve;
import org.pgpainless.key.info.KeyRingInfo; import org.pgpainless.key.info.KeyRingInfo;
import org.pgpainless.key.protection.SecretKeyRingProtector; import org.pgpainless.key.protection.SecretKeyRingProtector;
import org.pgpainless.key.util.KeyRingUtils; import org.pgpainless.key.util.KeyRingUtils;
import org.pgpainless.util.ImplementationFactoryTestInvocationContextProvider;
import org.pgpainless.util.MultiMap; import org.pgpainless.util.MultiMap;
import org.pgpainless.util.Passphrase; import org.pgpainless.util.Passphrase;
import org.pgpainless.util.TestImplementationFactoryProvider;
public class SigningTest { public class SigningTest {
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void testEncryptionAndSignatureVerification(ImplementationFactory implementationFactory) public void testEncryptionAndSignatureVerification()
throws IOException, PGPException { throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPPublicKeyRing julietKeys = TestKeys.getJulietPublicKeyRing(); PGPPublicKeyRing julietKeys = TestKeys.getJulietPublicKeyRing();
PGPPublicKeyRing romeoKeys = TestKeys.getRomeoPublicKeyRing(); PGPPublicKeyRing romeoKeys = TestKeys.getRomeoPublicKeyRing();
@ -117,11 +115,10 @@ public class SigningTest {
assertFalse(metadata.containsVerifiedSignatureFrom(julietKeys)); assertFalse(metadata.containsVerifiedSignatureFrom(julietKeys));
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void testSignWithInvalidUserIdFails(ImplementationFactory implementationFactory) public void testSignWithInvalidUserIdFails()
throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException { throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing() PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
.modernKeyRing("alice", "password123"); .modernKeyRing("alice", "password123");
SecretKeyRingProtector protector = SecretKeyRingProtector.unlockAnyKeyWith(Passphrase.fromPassword("password123")); SecretKeyRingProtector protector = SecretKeyRingProtector.unlockAnyKeyWith(Passphrase.fromPassword("password123"));
@ -133,11 +130,10 @@ public class SigningTest {
DocumentSignatureType.CANONICAL_TEXT_DOCUMENT)); DocumentSignatureType.CANONICAL_TEXT_DOCUMENT));
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void testSignWithRevokedUserIdFails(ImplementationFactory implementationFactory) public void testSignWithRevokedUserIdFails()
throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException { throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing() PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
.modernKeyRing("alice", "password123"); .modernKeyRing("alice", "password123");
SecretKeyRingProtector protector = SecretKeyRingProtector.unlockAnyKeyWith( SecretKeyRingProtector protector = SecretKeyRingProtector.unlockAnyKeyWith(
@ -155,10 +151,9 @@ public class SigningTest {
DocumentSignatureType.CANONICAL_TEXT_DOCUMENT)); DocumentSignatureType.CANONICAL_TEXT_DOCUMENT));
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void signWithHashAlgorithmOverride(ImplementationFactory implementationFactory) throws PGPException, IOException { public void signWithHashAlgorithmOverride() throws PGPException, IOException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPSecretKeyRing secretKeys = TestKeys.getEmilSecretKeyRing(); PGPSecretKeyRing secretKeys = TestKeys.getEmilSecretKeyRing();
SecretKeyRingProtector protector = SecretKeyRingProtector.unprotectedKeys(); SecretKeyRingProtector protector = SecretKeyRingProtector.unprotectedKeys();
@ -188,11 +183,10 @@ public class SigningTest {
assertEquals(HashAlgorithm.SHA224.getAlgorithmId(), signature.getHashAlgorithm()); assertEquals(HashAlgorithm.SHA224.getAlgorithmId(), signature.getHashAlgorithm());
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void negotiateHashAlgorithmChoseFallbackIfEmptyPreferences(ImplementationFactory implementationFactory) public void negotiateHashAlgorithmChoseFallbackIfEmptyPreferences()
throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, IOException { throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, IOException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPSecretKeyRing secretKeys = PGPainless.buildKeyRing() PGPSecretKeyRing secretKeys = PGPainless.buildKeyRing()
.setPrimaryKey(KeySpec.getBuilder( .setPrimaryKey(KeySpec.getBuilder(
KeyType.EDDSA(EdDSACurve._Ed25519), KeyFlag.CERTIFY_OTHER, KeyFlag.SIGN_DATA) KeyType.EDDSA(EdDSACurve._Ed25519), KeyFlag.CERTIFY_OTHER, KeyFlag.SIGN_DATA)
@ -219,11 +213,10 @@ public class SigningTest {
signature.getHashAlgorithm()); signature.getHashAlgorithm());
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void negotiateHashAlgorithmChoseFallbackIfUnacceptablePreferences(ImplementationFactory implementationFactory) public void negotiateHashAlgorithmChoseFallbackIfUnacceptablePreferences()
throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, IOException { throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, IOException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPSecretKeyRing secretKeys = PGPainless.buildKeyRing() PGPSecretKeyRing secretKeys = PGPainless.buildKeyRing()
.setPrimaryKey( .setPrimaryKey(
KeySpec.getBuilder(KeyType.EDDSA(EdDSACurve._Ed25519), KeyFlag.CERTIFY_OTHER, KeyFlag.SIGN_DATA) KeySpec.getBuilder(KeyType.EDDSA(EdDSACurve._Ed25519), KeyFlag.CERTIFY_OTHER, KeyFlag.SIGN_DATA)
@ -250,11 +243,10 @@ public class SigningTest {
signature.getHashAlgorithm()); signature.getHashAlgorithm());
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void signingWithNonCapableKeyThrowsKeyCannotSignException(ImplementationFactory implementationFactory) public void signingWithNonCapableKeyThrowsKeyCannotSignException()
throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException { throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPSecretKeyRing secretKeys = PGPainless.buildKeyRing() PGPSecretKeyRing secretKeys = PGPainless.buildKeyRing()
.setPrimaryKey(KeySpec.getBuilder(KeyType.EDDSA(EdDSACurve._Ed25519), KeyFlag.CERTIFY_OTHER)) .setPrimaryKey(KeySpec.getBuilder(KeyType.EDDSA(EdDSACurve._Ed25519), KeyFlag.CERTIFY_OTHER))
.addUserId("Alice") .addUserId("Alice")
@ -267,11 +259,10 @@ public class SigningTest {
SecretKeyRingProtector.unprotectedKeys(), secretKeys, DocumentSignatureType.BINARY_DOCUMENT)); SecretKeyRingProtector.unprotectedKeys(), secretKeys, DocumentSignatureType.BINARY_DOCUMENT));
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void signWithInvalidUserIdThrowsKeyValidationError(ImplementationFactory implementationFactory) public void signWithInvalidUserIdThrowsKeyValidationError()
throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException { throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPSecretKeyRing secretKeys = PGPainless.buildKeyRing() PGPSecretKeyRing secretKeys = PGPainless.buildKeyRing()
.setPrimaryKey(KeySpec.getBuilder(KeyType.EDDSA(EdDSACurve._Ed25519), .setPrimaryKey(KeySpec.getBuilder(KeyType.EDDSA(EdDSACurve._Ed25519),
KeyFlag.CERTIFY_OTHER, KeyFlag.SIGN_DATA)) KeyFlag.CERTIFY_OTHER, KeyFlag.SIGN_DATA))

View file

@ -29,18 +29,16 @@ 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.params.ParameterizedTest; import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.params.provider.ArgumentsSource; import org.junit.jupiter.api.extension.ExtendWith;
import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.provider.ProviderFactory; import org.pgpainless.provider.ProviderFactory;
import org.pgpainless.util.TestImplementationFactoryProvider; import org.pgpainless.util.ImplementationFactoryTestInvocationContextProvider;
public class BouncycastleExportSubkeys { public class BouncycastleExportSubkeys {
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void testExportImport(ImplementationFactory implementationFactory) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException, PGPException { public void testExportImport() throws NoSuchAlgorithmException, InvalidAlgorithmParameterException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
KeyPairGenerator generator; KeyPairGenerator generator;
KeyPair pair; KeyPair pair;

View file

@ -13,10 +13,10 @@ 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.bouncycastle.openpgp.operator.KeyFingerPrintCalculator; import org.bouncycastle.openpgp.operator.KeyFingerPrintCalculator;
import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.params.provider.ArgumentsSource; import org.junit.jupiter.api.extension.ExtendWith;
import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.util.TestImplementationFactoryProvider; import org.pgpainless.util.ImplementationFactoryTestInvocationContextProvider;
public class ImportExportKeyTest { public class ImportExportKeyTest {
@ -24,10 +24,9 @@ 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
*/ */
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void testExportImportPublicKeyRing(ImplementationFactory implementationFactory) throws IOException { public void testExportImportPublicKeyRing() throws IOException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPPublicKeyRing publicKeys = TestKeys.getJulietPublicKeyRing(); PGPPublicKeyRing publicKeys = TestKeys.getJulietPublicKeyRing();
KeyFingerPrintCalculator calc = ImplementationFactory.getInstance().getKeyFingerprintCalculator(); KeyFingerPrintCalculator calc = ImplementationFactory.getInstance().getKeyFingerprintCalculator();
@ -36,10 +35,9 @@ public class ImportExportKeyTest {
assertArrayEquals(publicKeys.getEncoded(), parsed.getEncoded()); assertArrayEquals(publicKeys.getEncoded(), parsed.getEncoded());
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void testExportImportSecretKeyRing(ImplementationFactory implementationFactory) throws IOException, PGPException { public void testExportImportSecretKeyRing() throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPSecretKeyRing secretKeys = TestKeys.getRomeoSecretKeyRing(); PGPSecretKeyRing secretKeys = TestKeys.getRomeoSecretKeyRing();
KeyFingerPrintCalculator calc = ImplementationFactory.getInstance().getKeyFingerprintCalculator(); KeyFingerPrintCalculator calc = ImplementationFactory.getInstance().getKeyFingerprintCalculator();

View file

@ -17,12 +17,11 @@ 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.params.ParameterizedTest; import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.params.provider.ArgumentsSource; import org.junit.jupiter.api.extension.ExtendWith;
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.generation.type.eddsa.EdDSACurve; import org.pgpainless.key.generation.type.eddsa.EdDSACurve;
@ -31,16 +30,15 @@ import org.pgpainless.key.generation.type.xdh.XDHSpec;
import org.pgpainless.key.info.KeyInfo; import org.pgpainless.key.info.KeyInfo;
import org.pgpainless.key.util.UserId; import org.pgpainless.key.util.UserId;
import org.pgpainless.util.BCUtil; import org.pgpainless.util.BCUtil;
import org.pgpainless.util.ImplementationFactoryTestInvocationContextProvider;
import org.pgpainless.util.Passphrase; import org.pgpainless.util.Passphrase;
import org.pgpainless.util.TestImplementationFactoryProvider;
public class BrainpoolKeyGenerationTest { public class BrainpoolKeyGenerationTest {
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void generateEcKeysTest(ImplementationFactory implementationFactory) public void generateEcKeysTest()
throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException { throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
for (EllipticCurve curve : EllipticCurve.values()) { for (EllipticCurve curve : EllipticCurve.values()) {
PGPSecretKeyRing secretKeys = generateKey( PGPSecretKeyRing secretKeys = generateKey(
@ -66,11 +64,10 @@ public class BrainpoolKeyGenerationTest {
} }
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void generateEdDSAKeyTest(ImplementationFactory implementationFactory) public void generateEdDSAKeyTest()
throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException { throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPSecretKeyRing secretKeys = PGPainless.buildKeyRing() PGPSecretKeyRing secretKeys = PGPainless.buildKeyRing()
.setPrimaryKey(KeySpec.getBuilder( .setPrimaryKey(KeySpec.getBuilder(

View file

@ -6,15 +6,14 @@ 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.params.ParameterizedTest; import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.params.provider.ArgumentsSource; import org.junit.jupiter.api.extension.ExtendWith;
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.XDHSpec; import org.pgpainless.key.generation.type.xdh.XDHSpec;
import org.pgpainless.util.TestImplementationFactoryProvider; import org.pgpainless.util.ImplementationFactoryTestInvocationContextProvider;
public class CertificationKeyMustBeAbleToCertifyTest { public class CertificationKeyMustBeAbleToCertifyTest {
@ -23,10 +22,9 @@ 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.
*/ */
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void testCertificationIncapableKeyTypesThrow(ImplementationFactory implementationFactory) { public void testCertificationIncapableKeyTypesThrow() {
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

@ -6,32 +6,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.PGPSecretKeyRing; import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.params.provider.ArgumentsSource; import org.junit.jupiter.api.extension.ExtendWith;
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.eddsa.EdDSACurve; import org.pgpainless.key.generation.type.eddsa.EdDSACurve;
import org.pgpainless.key.generation.type.xdh.XDHSpec; import org.pgpainless.key.generation.type.xdh.XDHSpec;
import org.pgpainless.key.protection.SecretKeyRingProtector; import org.pgpainless.key.protection.SecretKeyRingProtector;
import org.pgpainless.key.protection.UnlockSecretKey; import org.pgpainless.key.protection.UnlockSecretKey;
import org.pgpainless.key.util.UserId; import org.pgpainless.key.util.UserId;
import org.pgpainless.util.TestImplementationFactoryProvider; import org.pgpainless.util.ImplementationFactoryTestInvocationContextProvider;
public class GenerateEllipticCurveKeyTest { public class GenerateEllipticCurveKeyTest {
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void generateEllipticCurveKeys(ImplementationFactory implementationFactory) throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, IOException { public void generateEllipticCurveKeys()
ImplementationFactory.setFactoryImplementation(implementationFactory); throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException {
PGPSecretKeyRing keyRing = PGPainless.buildKeyRing() PGPSecretKeyRing keyRing = PGPainless.buildKeyRing()
.setPrimaryKey(KeySpec.getBuilder( .setPrimaryKey(KeySpec.getBuilder(
KeyType.EDDSA(EdDSACurve._Ed25519), KeyType.EDDSA(EdDSACurve._Ed25519),

View file

@ -17,24 +17,22 @@ 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.params.ParameterizedTest; import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.params.provider.ArgumentsSource; import org.junit.jupiter.api.extension.ExtendWith;
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;
import org.pgpainless.key.util.UserId; import org.pgpainless.key.util.UserId;
import org.pgpainless.util.DateUtil; import org.pgpainless.util.DateUtil;
import org.pgpainless.util.TestImplementationFactoryProvider; import org.pgpainless.util.ImplementationFactoryTestInvocationContextProvider;
public class GenerateKeyWithAdditionalUserIdTest { public class GenerateKeyWithAdditionalUserIdTest {
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void test(ImplementationFactory implementationFactory) throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, IOException { public void test() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, IOException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
Date expiration = new Date(DateUtil.now().getTime() + 60 * 1000); Date expiration = new Date(DateUtil.now().getTime() + 60 * 1000);
PGPSecretKeyRing secretKeys = PGPainless.buildKeyRing() PGPSecretKeyRing secretKeys = PGPainless.buildKeyRing()
.setPrimaryKey(KeySpec.getBuilder( .setPrimaryKey(KeySpec.getBuilder(

View file

@ -6,20 +6,18 @@ package org.pgpainless.key.generation;
import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
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.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.params.provider.ArgumentsSource; import org.junit.jupiter.api.extension.ExtendWith;
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.ImplementationFactoryTestInvocationContextProvider;
import org.pgpainless.util.Passphrase; import org.pgpainless.util.Passphrase;
import org.pgpainless.util.TestImplementationFactoryProvider;
/** /**
* Reproduce behavior of https://github.com/pgpainless/pgpainless/issues/16 * Reproduce behavior of https://github.com/pgpainless/pgpainless/issues/16
@ -30,10 +28,10 @@ import org.pgpainless.util.TestImplementationFactoryProvider;
*/ */
public class GenerateWithEmptyPassphraseTest { public class GenerateWithEmptyPassphraseTest {
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void testGeneratingKeyWithEmptyPassphraseDoesNotThrow(ImplementationFactory implementationFactory) throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, IOException { public void testGeneratingKeyWithEmptyPassphraseDoesNotThrow()
ImplementationFactory.setFactoryImplementation(implementationFactory); throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException {
assertNotNull(PGPainless.buildKeyRing() assertNotNull(PGPainless.buildKeyRing()
.setPrimaryKey(KeySpec.getBuilder( .setPrimaryKey(KeySpec.getBuilder(

View file

@ -6,21 +6,19 @@ 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.params.ParameterizedTest; import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.params.provider.ArgumentsSource; import org.junit.jupiter.api.extension.ExtendWith;
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.XDHSpec; import org.pgpainless.key.generation.type.xdh.XDHSpec;
import org.pgpainless.util.TestImplementationFactoryProvider; import org.pgpainless.util.ImplementationFactoryTestInvocationContextProvider;
public class IllegalKeyFlagsTest { public class IllegalKeyFlagsTest {
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void testKeyCannotCarryFlagsTest(ImplementationFactory implementationFactory) { public void testKeyCannotCarryFlagsTest() {
ImplementationFactory.setFactoryImplementation(implementationFactory);
assertThrows(IllegalArgumentException.class, () -> KeySpec.getBuilder( assertThrows(IllegalArgumentException.class, () -> KeySpec.getBuilder(
KeyType.XDH(XDHSpec._X25519), KeyFlag.SIGN_DATA)); KeyType.XDH(XDHSpec._X25519), KeyFlag.SIGN_DATA));

View file

@ -31,8 +31,8 @@ import org.bouncycastle.openpgp.PGPSecretKey;
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.api.Test;
import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.params.provider.ArgumentsSource; import org.junit.jupiter.api.extension.ExtendWith;
import org.pgpainless.PGPainless; import org.pgpainless.PGPainless;
import org.pgpainless.algorithm.CompressionAlgorithm; import org.pgpainless.algorithm.CompressionAlgorithm;
import org.pgpainless.algorithm.EncryptionPurpose; import org.pgpainless.algorithm.EncryptionPurpose;
@ -40,7 +40,6 @@ import org.pgpainless.algorithm.HashAlgorithm;
import org.pgpainless.algorithm.KeyFlag; import org.pgpainless.algorithm.KeyFlag;
import org.pgpainless.algorithm.PublicKeyAlgorithm; import org.pgpainless.algorithm.PublicKeyAlgorithm;
import org.pgpainless.algorithm.SymmetricKeyAlgorithm; import org.pgpainless.algorithm.SymmetricKeyAlgorithm;
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;
@ -52,15 +51,14 @@ import org.pgpainless.key.protection.UnprotectedKeysProtector;
import org.pgpainless.key.util.KeyRingUtils; import org.pgpainless.key.util.KeyRingUtils;
import org.pgpainless.key.util.UserId; import org.pgpainless.key.util.UserId;
import org.pgpainless.util.DateUtil; import org.pgpainless.util.DateUtil;
import org.pgpainless.util.ImplementationFactoryTestInvocationContextProvider;
import org.pgpainless.util.Passphrase; import org.pgpainless.util.Passphrase;
import org.pgpainless.util.TestImplementationFactoryProvider;
public class KeyRingInfoTest { public class KeyRingInfoTest {
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void testWithEmilsKeys(ImplementationFactory implementationFactory) throws IOException, PGPException { public void testWithEmilsKeys() throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPSecretKeyRing secretKeys = TestKeys.getEmilSecretKeyRing(); PGPSecretKeyRing secretKeys = TestKeys.getEmilSecretKeyRing();
PGPPublicKeyRing publicKeys = TestKeys.getEmilPublicKeyRing(); PGPPublicKeyRing publicKeys = TestKeys.getEmilPublicKeyRing();
@ -175,10 +173,9 @@ public class KeyRingInfoTest {
KeyRingUtils.requireSecretKeyFrom(secretKeys, secretKeys.getPublicKey().getKeyID())); KeyRingUtils.requireSecretKeyFrom(secretKeys, secretKeys.getPublicKey().getKeyID()));
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void dummyS2KTest(ImplementationFactory implementationFactory) throws IOException { public void dummyS2KTest() throws IOException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
String withDummyS2K = "-----BEGIN PGP PRIVATE KEY BLOCK-----\n" + String withDummyS2K = "-----BEGIN PGP PRIVATE KEY BLOCK-----\n" +
"\n" + "\n" +
@ -214,10 +211,9 @@ public class KeyRingInfoTest {
assertTrue(new KeyInfo(secretKeys.getSecretKey()).hasDummyS2K()); assertTrue(new KeyInfo(secretKeys.getSecretKey()).hasDummyS2K());
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void testGetKeysWithFlagsAndExpiry(ImplementationFactory implementationFactory) throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException { public void testGetKeysWithFlagsAndExpiry() throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPSecretKeyRing secretKeys = PGPainless.buildKeyRing() PGPSecretKeyRing secretKeys = PGPainless.buildKeyRing()
.setPrimaryKey(KeySpec.getBuilder( .setPrimaryKey(KeySpec.getBuilder(

View file

@ -20,11 +20,10 @@ 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.params.ParameterizedTest; import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.params.provider.ArgumentsSource; import org.junit.jupiter.api.extension.ExtendWith;
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.EllipticCurve; import org.pgpainless.key.generation.type.ecc.EllipticCurve;
@ -33,15 +32,15 @@ import org.pgpainless.key.info.KeyRingInfo;
import org.pgpainless.key.protection.PasswordBasedSecretKeyRingProtector; import org.pgpainless.key.protection.PasswordBasedSecretKeyRingProtector;
import org.pgpainless.key.protection.SecretKeyRingProtector; import org.pgpainless.key.protection.SecretKeyRingProtector;
import org.pgpainless.key.protection.UnlockSecretKey; import org.pgpainless.key.protection.UnlockSecretKey;
import org.pgpainless.util.ImplementationFactoryTestInvocationContextProvider;
import org.pgpainless.util.Passphrase; import org.pgpainless.util.Passphrase;
import org.pgpainless.util.TestImplementationFactoryProvider;
public class AddSubKeyTest { public class AddSubKeyTest {
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void testAddSubKey(ImplementationFactory implementationFactory) throws IOException, PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException { public void testAddSubKey()
ImplementationFactory.setFactoryImplementation(implementationFactory); throws IOException, PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException {
PGPSecretKeyRing secretKeys = TestKeys.getCryptieSecretKeyRing(); PGPSecretKeyRing secretKeys = TestKeys.getCryptieSecretKeyRing();
List<Long> keyIdsBefore = new ArrayList<>(); List<Long> keyIdsBefore = new ArrayList<>();

View file

@ -18,26 +18,24 @@ 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.api.TestTemplate;
import org.junit.jupiter.params.provider.ArgumentsSource; import org.junit.jupiter.api.extension.ExtendWith;
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.info.KeyRingInfo; import org.pgpainless.key.info.KeyRingInfo;
import org.pgpainless.key.protection.PasswordBasedSecretKeyRingProtector; import org.pgpainless.key.protection.PasswordBasedSecretKeyRingProtector;
import org.pgpainless.key.protection.SecretKeyRingProtector; import org.pgpainless.key.protection.SecretKeyRingProtector;
import org.pgpainless.key.protection.UnprotectedKeysProtector; import org.pgpainless.key.protection.UnprotectedKeysProtector;
import org.pgpainless.key.util.UserId; import org.pgpainless.key.util.UserId;
import org.pgpainless.util.ImplementationFactoryTestInvocationContextProvider;
import org.pgpainless.util.Passphrase; import org.pgpainless.util.Passphrase;
import org.pgpainless.util.TestImplementationFactoryProvider;
public class AddUserIdTest { public class AddUserIdTest {
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void addUserIdToExistingKeyRing(ImplementationFactory implementationFactory) public void addUserIdToExistingKeyRing()
throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException { 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");
KeyRingInfo info = PGPainless.inspectKeyRing(secretKeys); KeyRingInfo info = PGPainless.inspectKeyRing(secretKeys);
@ -66,20 +64,18 @@ public class AddUserIdTest {
assertFalse(userIds.hasNext()); assertFalse(userIds.hasNext());
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void deleteUserId_noSuchElementExceptionForMissingUserId(ImplementationFactory implementationFactory) throws IOException, PGPException { public void deleteUserId_noSuchElementExceptionForMissingUserId() throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPSecretKeyRing secretKeys = TestKeys.getCryptieSecretKeyRing(); PGPSecretKeyRing secretKeys = TestKeys.getCryptieSecretKeyRing();
assertThrows(NoSuchElementException.class, () -> PGPainless.modifyKeyRing(secretKeys) assertThrows(NoSuchElementException.class, () -> PGPainless.modifyKeyRing(secretKeys)
.revokeUserId("invalid@user.id", new UnprotectedKeysProtector())); .revokeUserId("invalid@user.id", new UnprotectedKeysProtector()));
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void deleteExistingAndAddNewUserIdToExistingKeyRing(ImplementationFactory implementationFactory) throws PGPException, IOException { public void deleteExistingAndAddNewUserIdToExistingKeyRing() throws PGPException, IOException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
final String ARMORED_PRIVATE_KEY = final String ARMORED_PRIVATE_KEY =
"-----BEGIN PGP PRIVATE KEY BLOCK-----\r\n\r\n" + "-----BEGIN PGP PRIVATE KEY BLOCK-----\r\n\r\n" +

View file

@ -10,13 +10,12 @@ 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.JUtils; import org.junit.JUtils;
import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.params.provider.ArgumentsSource; import org.junit.jupiter.api.extension.ExtendWith;
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;
import org.pgpainless.util.DateUtil; import org.pgpainless.util.DateUtil;
import org.pgpainless.util.TestImplementationFactoryProvider; import org.pgpainless.util.ImplementationFactoryTestInvocationContextProvider;
public class ChangeExpirationOnKeyWithDifferentSignatureTypesTest { public class ChangeExpirationOnKeyWithDifferentSignatureTypesTest {
@ -136,21 +135,19 @@ public class ChangeExpirationOnKeyWithDifferentSignatureTypesTest {
"=GIQn\n" + "=GIQn\n" +
"-----END PGP PRIVATE KEY BLOCK-----"; "-----END PGP PRIVATE KEY BLOCK-----";
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void setExpirationDate_keyHasSigClass10(ImplementationFactory implementationFactory) public void setExpirationDate_keyHasSigClass10()
throws PGPException, IOException { throws PGPException, IOException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPSecretKeyRing keys = PGPainless.readKeyRing().secretKeyRing(keyWithGenericCertification); PGPSecretKeyRing keys = PGPainless.readKeyRing().secretKeyRing(keyWithGenericCertification);
SecretKeyRingProtector protector = SecretKeyRingProtector.unprotectedKeys(); SecretKeyRingProtector protector = SecretKeyRingProtector.unprotectedKeys();
executeTestForKeys(keys, protector); executeTestForKeys(keys, protector);
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void setExpirationDate_keyHasSigClass12(ImplementationFactory implementationFactory) public void setExpirationDate_keyHasSigClass12()
throws PGPException, IOException { throws PGPException, IOException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPSecretKeyRing keys = PGPainless.readKeyRing().secretKeyRing(keyWithCasualCertification); PGPSecretKeyRing keys = PGPainless.readKeyRing().secretKeyRing(keyWithCasualCertification);
SecretKeyRingProtector protector = SecretKeyRingProtector.unprotectedKeys(); SecretKeyRingProtector protector = SecretKeyRingProtector.unprotectedKeys();
executeTestForKeys(keys, protector); executeTestForKeys(keys, protector);

View file

@ -13,26 +13,24 @@ 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.params.ParameterizedTest; import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.params.provider.ArgumentsSource; import org.junit.jupiter.api.extension.ExtendWith;
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 org.pgpainless.util.DateUtil; import org.pgpainless.util.DateUtil;
import org.pgpainless.util.TestImplementationFactoryProvider; import org.pgpainless.util.ImplementationFactoryTestInvocationContextProvider;
public class ChangeExpirationTest { public class ChangeExpirationTest {
private final OpenPgpV4Fingerprint subKeyFingerprint = new OpenPgpV4Fingerprint("F73FDE6439ABE210B1AF4EDD273EF7A0C749807B"); private final OpenPgpV4Fingerprint subKeyFingerprint = new OpenPgpV4Fingerprint("F73FDE6439ABE210B1AF4EDD273EF7A0C749807B");
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void setExpirationDateAndThenUnsetIt_OnPrimaryKey(ImplementationFactory implementationFactory) public void setExpirationDateAndThenUnsetIt_OnPrimaryKey()
throws PGPException, IOException, InterruptedException { 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);
@ -62,11 +60,10 @@ public class ChangeExpirationTest {
assertNull(sInfo.getSubkeyExpirationDate(subKeyFingerprint)); assertNull(sInfo.getSubkeyExpirationDate(subKeyFingerprint));
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void setExpirationDateAndThenUnsetIt_OnSubkey(ImplementationFactory implementationFactory) public void setExpirationDateAndThenUnsetIt_OnSubkey()
throws PGPException, IOException, InterruptedException { 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

@ -20,8 +20,8 @@ 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.bouncycastle.util.io.Streams; import org.bouncycastle.util.io.Streams;
import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.params.provider.ArgumentsSource; import org.junit.jupiter.api.extension.ExtendWith;
import org.pgpainless.PGPainless; import org.pgpainless.PGPainless;
import org.pgpainless.algorithm.DocumentSignatureType; import org.pgpainless.algorithm.DocumentSignatureType;
import org.pgpainless.algorithm.SymmetricKeyAlgorithm; import org.pgpainless.algorithm.SymmetricKeyAlgorithm;
@ -32,8 +32,8 @@ 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.key.protection.UnlockSecretKey; import org.pgpainless.key.protection.UnlockSecretKey;
import org.pgpainless.util.ImplementationFactoryTestInvocationContextProvider;
import org.pgpainless.util.Passphrase; import org.pgpainless.util.Passphrase;
import org.pgpainless.util.TestImplementationFactoryProvider;
public class ChangeSecretKeyRingPassphraseTest { public class ChangeSecretKeyRingPassphraseTest {
@ -42,10 +42,9 @@ public class ChangeSecretKeyRingPassphraseTest {
public ChangeSecretKeyRingPassphraseTest() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException { public ChangeSecretKeyRingPassphraseTest() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException {
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void changePassphraseOfWholeKeyRingTest(ImplementationFactory implementationFactory) throws PGPException { public void changePassphraseOfWholeKeyRingTest() throws PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPSecretKeyRing secretKeys = PGPainless.modifyKeyRing(keyRing) PGPSecretKeyRing secretKeys = PGPainless.modifyKeyRing(keyRing)
.changePassphraseFromOldPassphrase(Passphrase.fromPassword("weakPassphrase")) .changePassphraseFromOldPassphrase(Passphrase.fromPassword("weakPassphrase"))
@ -70,10 +69,9 @@ 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.");
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void changePassphraseOfWholeKeyRingToEmptyPassphrase(ImplementationFactory implementationFactory) throws PGPException, IOException { public void changePassphraseOfWholeKeyRingToEmptyPassphrase() 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()
@ -88,10 +86,9 @@ public class ChangeSecretKeyRingPassphraseTest {
signDummyMessageWithKeysAndPassphrase(changedPassphraseKeyRing, Passphrase.emptyPassphrase()); signDummyMessageWithKeysAndPassphrase(changedPassphraseKeyRing, Passphrase.emptyPassphrase());
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void changePassphraseOfSingleSubkeyToNewPassphrase(ImplementationFactory implementationFactory) throws PGPException { public void changePassphraseOfSingleSubkeyToNewPassphrase() throws PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
Iterator<PGPSecretKey> keys = keyRing.getSecretKeys(); Iterator<PGPSecretKey> keys = keyRing.getSecretKeys();
PGPSecretKey primaryKey = keys.next(); PGPSecretKey primaryKey = keys.next();
@ -125,10 +122,9 @@ public class ChangeSecretKeyRingPassphraseTest {
"Unlocking the subkey with the primary key passphrase must fail."); "Unlocking the subkey with the primary key passphrase must fail.");
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void changePassphraseOfSingleSubkeyToEmptyPassphrase(ImplementationFactory implementationFactory) throws PGPException { public void changePassphraseOfSingleSubkeyToEmptyPassphrase() throws PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
Iterator<PGPSecretKey> keys = keyRing.getSecretKeys(); Iterator<PGPSecretKey> keys = keyRing.getSecretKeys();
PGPSecretKey primaryKey = keys.next(); PGPSecretKey primaryKey = keys.next();

View file

@ -16,21 +16,19 @@ 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.params.ParameterizedTest; import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.params.provider.ArgumentsSource; import org.junit.jupiter.api.extension.ExtendWith;
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;
import org.pgpainless.util.TestImplementationFactoryProvider; import org.pgpainless.util.ImplementationFactoryTestInvocationContextProvider;
public class OldSignatureSubpacketsArePreservedOnNewSig { public class OldSignatureSubpacketsArePreservedOnNewSig {
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void verifyOldSignatureSubpacketsArePreservedOnNewExpirationDateSig(ImplementationFactory implementationFactory) public void verifyOldSignatureSubpacketsArePreservedOnNewExpirationDateSig()
throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, InterruptedException { throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, InterruptedException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing() PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
.simpleEcKeyRing("Alice <alice@wonderland.lit>"); .simpleEcKeyRing("Alice <alice@wonderland.lit>");

View file

@ -14,13 +14,12 @@ 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.params.ParameterizedTest; import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.params.provider.ArgumentsSource; import org.junit.jupiter.api.extension.ExtendWith;
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;
import org.pgpainless.util.TestImplementationFactoryProvider; import org.pgpainless.util.ImplementationFactoryTestInvocationContextProvider;
/** /**
* Test that makes sure that PGPainless can deal with keys that carry a key * Test that makes sure that PGPainless can deal with keys that carry a key
@ -64,10 +63,9 @@ public class RevokeKeyWithGenericCertificationSignatureTest {
} }
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void test(ImplementationFactory implementationFactory) throws IOException, PGPException { public void test() throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
revokeKey(SAMPLE_PRIVATE_KEY); // would crash previously revokeKey(SAMPLE_PRIVATE_KEY); // would crash previously
} }

View file

@ -13,17 +13,16 @@ 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.JUtils; import org.junit.JUtils;
import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.params.provider.ArgumentsSource; import org.junit.jupiter.api.extension.ExtendWith;
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;
import org.pgpainless.key.protection.SecretKeyRingProtector; import org.pgpainless.key.protection.SecretKeyRingProtector;
import org.pgpainless.key.protection.UnprotectedKeysProtector; import org.pgpainless.key.protection.UnprotectedKeysProtector;
import org.pgpainless.util.DateUtil; import org.pgpainless.util.DateUtil;
import org.pgpainless.util.TestImplementationFactoryProvider; import org.pgpainless.util.ImplementationFactoryTestInvocationContextProvider;
public class RevokeKeyWithoutPreferredAlgorithmsOnPrimaryKey { public class RevokeKeyWithoutPreferredAlgorithmsOnPrimaryKey {
@ -101,11 +100,10 @@ public class RevokeKeyWithoutPreferredAlgorithmsOnPrimaryKey {
"=3Zyp\n" + "=3Zyp\n" +
"-----END PGP PRIVATE KEY BLOCK-----"; "-----END PGP PRIVATE KEY BLOCK-----";
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void testChangingExpirationTimeWithKeyWithoutPrefAlgos(ImplementationFactory implementationFactory) public void testChangingExpirationTimeWithKeyWithoutPrefAlgos()
throws IOException, PGPException { throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
Date expirationDate = DateUtil.parseUTCDate(DateUtil.formatUTCDate(new Date())); Date expirationDate = DateUtil.parseUTCDate(DateUtil.formatUTCDate(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

@ -24,12 +24,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.api.TestTemplate;
import org.junit.jupiter.params.provider.ArgumentsSource; import org.junit.jupiter.api.extension.ExtendWith;
import org.pgpainless.PGPainless; import org.pgpainless.PGPainless;
import org.pgpainless.algorithm.EncryptionPurpose; import org.pgpainless.algorithm.EncryptionPurpose;
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;
@ -39,15 +38,14 @@ import org.pgpainless.key.util.RevocationAttributes;
import org.pgpainless.signature.SignatureUtils; import org.pgpainless.signature.SignatureUtils;
import org.pgpainless.signature.subpackets.RevocationSignatureSubpackets; import org.pgpainless.signature.subpackets.RevocationSignatureSubpackets;
import org.pgpainless.signature.subpackets.SignatureSubpacketsUtil; import org.pgpainless.signature.subpackets.SignatureSubpacketsUtil;
import org.pgpainless.util.ImplementationFactoryTestInvocationContextProvider;
import org.pgpainless.util.Passphrase; import org.pgpainless.util.Passphrase;
import org.pgpainless.util.TestImplementationFactoryProvider;
public class RevokeSubKeyTest { public class RevokeSubKeyTest {
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void revokeSukeyTest(ImplementationFactory implementationFactory) throws IOException, PGPException { public void revokeSukeyTest() throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPSecretKeyRing secretKeys = TestKeys.getCryptieSecretKeyRing(); PGPSecretKeyRing secretKeys = TestKeys.getCryptieSecretKeyRing();
Iterator<PGPSecretKey> keysIterator = secretKeys.iterator(); Iterator<PGPSecretKey> keysIterator = secretKeys.iterator();
@ -69,10 +67,9 @@ public class RevokeSubKeyTest {
assertTrue(subKey.getPublicKey().hasRevocation()); assertTrue(subKey.getPublicKey().hasRevocation());
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void detachedRevokeSubkeyTest(ImplementationFactory implementationFactory) throws IOException, PGPException { public void detachedRevokeSubkeyTest() 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"));
@ -90,10 +87,9 @@ public class RevokeSubKeyTest {
assertTrue(publicKey.hasRevocation()); assertTrue(publicKey.hasRevocation());
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void testRevocationSignatureTypeCorrect(ImplementationFactory implementationFactory) throws IOException, PGPException { public void testRevocationSignatureTypeCorrect() 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

@ -13,6 +13,8 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.pgpainless.util.Passphrase; import org.pgpainless.util.Passphrase;
public class PassphraseTest { public class PassphraseTest {
@ -49,15 +51,13 @@ public class PassphraseTest {
assertTrue(fromEmptyChars.isEmpty()); assertTrue(fromEmptyChars.isEmpty());
} }
@Test @ParameterizedTest
public void testEmptyPassphrase() { @ValueSource(strings = {"", " ", " ", "\t", "\t\t"})
Passphrase empty = Passphrase.emptyPassphrase(); public void testEmptyPassphrases(String empty) {
assertNull(empty.getChars()); Passphrase passphrase = Passphrase.fromPassword(empty);
assertTrue(empty.isEmpty()); assertTrue(passphrase.isEmpty());
Passphrase trimmedEmpty = Passphrase.fromPassword(" "); assertEquals(Passphrase.emptyPassphrase(), passphrase);
assertNull(trimmedEmpty.getChars());
assertTrue(trimmedEmpty.isEmpty());
} }
@Test @Test

View file

@ -23,22 +23,20 @@ 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.api.TestTemplate;
import org.junit.jupiter.params.provider.ArgumentsSource; import org.junit.jupiter.api.extension.ExtendWith;
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.ImplementationFactoryTestInvocationContextProvider;
import org.pgpainless.util.Passphrase; import org.pgpainless.util.Passphrase;
import org.pgpainless.util.TestImplementationFactoryProvider;
public class SecretKeyRingProtectorTest { public class SecretKeyRingProtectorTest {
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void testUnlockAllKeysWithSamePassword(ImplementationFactory implementationFactory) public void testUnlockAllKeysWithSamePassword()
throws IOException, PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException { throws IOException, PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPSecretKeyRing secretKeys = TestKeys.getCryptieSecretKeyRing(); PGPSecretKeyRing secretKeys = TestKeys.getCryptieSecretKeyRing();
SecretKeyRingProtector protector = SecretKeyRingProtector protector =
@ -69,11 +67,10 @@ public class SecretKeyRingProtectorTest {
} }
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void testUnlockSingleKeyWithPassphrase(ImplementationFactory implementationFactory) public void testUnlockSingleKeyWithPassphrase()
throws IOException, PGPException { throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
PGPSecretKeyRing secretKeys = TestKeys.getCryptieSecretKeyRing(); PGPSecretKeyRing secretKeys = TestKeys.getCryptieSecretKeyRing();
Iterator<PGPSecretKey> iterator = secretKeys.iterator(); Iterator<PGPSecretKey> iterator = secretKeys.iterator();

View file

@ -16,14 +16,13 @@ import java.util.Date;
import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPPublicKeyRing; import org.bouncycastle.openpgp.PGPPublicKeyRing;
import org.bouncycastle.openpgp.PGPSignature; import org.bouncycastle.openpgp.PGPSignature;
import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.params.provider.ArgumentsSource; import org.junit.jupiter.api.extension.ExtendWith;
import org.pgpainless.PGPainless; import org.pgpainless.PGPainless;
import org.pgpainless.exception.SignatureValidationException; import org.pgpainless.exception.SignatureValidationException;
import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.policy.Policy; import org.pgpainless.policy.Policy;
import org.pgpainless.signature.consumer.CertificateValidator; import org.pgpainless.signature.consumer.CertificateValidator;
import org.pgpainless.util.TestImplementationFactoryProvider; import org.pgpainless.util.ImplementationFactoryTestInvocationContextProvider;
/** /**
* Explores how subpackets on binding sigs are handled. * Explores how subpackets on binding sigs are handled.
@ -52,10 +51,9 @@ public class BindingSignatureSubpacketsTest {
private Date validationDate = new Date(); private Date validationDate = new Date();
private Policy policy = PGPainless.getPolicy(); private Policy policy = PGPainless.getPolicy();
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void baseCase(ImplementationFactory implementationFactory) throws IOException, PGPException { public void baseCase() throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" + String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"\n" + "\n" +
@ -114,10 +112,9 @@ public class BindingSignatureSubpacketsTest {
expectSignatureValidationSucceeds(key, "Base case. Is valid."); expectSignatureValidationSucceeds(key, "Base case. Is valid.");
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void subkeyBindingIssuerFpOnly(ImplementationFactory implementationFactory) throws IOException, PGPException { public void subkeyBindingIssuerFpOnly() throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" + String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"\n" + "\n" +
@ -176,10 +173,9 @@ public class BindingSignatureSubpacketsTest {
expectSignatureValidationSucceeds(key, "Interoperability concern."); expectSignatureValidationSucceeds(key, "Interoperability concern.");
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void subkeyBindingIssuerV6IssuerFp(ImplementationFactory implementationFactory) throws IOException, PGPException { public void subkeyBindingIssuerV6IssuerFp() throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" + String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"\n" + "\n" +
@ -238,10 +234,9 @@ public class BindingSignatureSubpacketsTest {
expectSignatureValidationSucceeds(key, "Interoperability concern"); expectSignatureValidationSucceeds(key, "Interoperability concern");
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void subkeyBindingIssuerFakeIssuer(ImplementationFactory implementationFactory) throws IOException, PGPException { public void subkeyBindingIssuerFakeIssuer() throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" + String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"\n" + "\n" +
@ -300,10 +295,9 @@ public class BindingSignatureSubpacketsTest {
expectSignatureValidationSucceeds(key, "Interoperability concern."); expectSignatureValidationSucceeds(key, "Interoperability concern.");
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void subkeyBindingFakeIssuerIssuer(ImplementationFactory implementationFactory) throws IOException, PGPException { public void subkeyBindingFakeIssuerIssuer() throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" + String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"\n" + "\n" +
@ -362,10 +356,9 @@ public class BindingSignatureSubpacketsTest {
expectSignatureValidationSucceeds(key, "Interop concern"); expectSignatureValidationSucceeds(key, "Interop concern");
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void subkeyBindingFakeIssuer(ImplementationFactory implementationFactory) throws IOException, PGPException { public void subkeyBindingFakeIssuer() throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" + String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"\n" + "\n" +
@ -424,10 +417,9 @@ public class BindingSignatureSubpacketsTest {
expectSignatureValidationSucceeds(key, "fake issuers do not throw us off here."); expectSignatureValidationSucceeds(key, "fake issuers do not throw us off here.");
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void subkeyBindingNoIssuer(ImplementationFactory implementationFactory) throws IOException, PGPException { public void subkeyBindingNoIssuer() throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" + String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"\n" + "\n" +
@ -485,10 +477,9 @@ public class BindingSignatureSubpacketsTest {
expectSignatureValidationSucceeds(key, "subkey binding sig does not need issuer"); expectSignatureValidationSucceeds(key, "subkey binding sig does not need issuer");
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void unknownSubpacketHashed(ImplementationFactory implementationFactory) throws IOException, PGPException { public void unknownSubpacketHashed() throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" + String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"\n" + "\n" +
@ -547,10 +538,9 @@ public class BindingSignatureSubpacketsTest {
expectSignatureValidationSucceeds(key, "Unknown subpackets are okay in hashed area"); expectSignatureValidationSucceeds(key, "Unknown subpackets are okay in hashed area");
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void subkeyBindingUnknownCriticalSubpacket(ImplementationFactory implementationFactory) throws IOException, PGPException { public void subkeyBindingUnknownCriticalSubpacket() throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" + String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"\n" + "\n" +
@ -609,10 +599,9 @@ public class BindingSignatureSubpacketsTest {
expectSignatureValidationFails(key, "Unknown critical subpacket in hashed area invalidates signature"); expectSignatureValidationFails(key, "Unknown critical subpacket in hashed area invalidates signature");
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void subkeyBindingUnknownSubpacketUnhashed(ImplementationFactory implementationFactory) throws IOException, PGPException { public void subkeyBindingUnknownSubpacketUnhashed() throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" + String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"\n" + "\n" +
@ -671,10 +660,9 @@ public class BindingSignatureSubpacketsTest {
expectSignatureValidationSucceeds(key, "Unknown subpackets may be allowed in unhashed area."); expectSignatureValidationSucceeds(key, "Unknown subpackets may be allowed in unhashed area.");
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void subkeyBindingUnknownCriticalSubpacketUnhashed(ImplementationFactory implementationFactory) throws IOException, PGPException { public void subkeyBindingUnknownCriticalSubpacketUnhashed() throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" + String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"\n" + "\n" +
@ -733,10 +721,9 @@ public class BindingSignatureSubpacketsTest {
expectSignatureValidationSucceeds(key, "Critical unknown subpacket is okay in unhashed area."); expectSignatureValidationSucceeds(key, "Critical unknown subpacket is okay in unhashed area.");
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void subkeyBindingUnknownNotationHashed(ImplementationFactory implementationFactory) throws IOException, PGPException { public void subkeyBindingUnknownNotationHashed() throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" + String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"\n" + "\n" +
@ -796,10 +783,9 @@ public class BindingSignatureSubpacketsTest {
expectSignatureValidationSucceeds(key, "Unknown notation is okay in subkey binding sig."); expectSignatureValidationSucceeds(key, "Unknown notation is okay in subkey binding sig.");
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void subkeyBindingCriticalUnknownNotationHashed(ImplementationFactory implementationFactory) throws IOException, PGPException { public void subkeyBindingCriticalUnknownNotationHashed() throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" + String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"\n" + "\n" +
@ -859,10 +845,9 @@ public class BindingSignatureSubpacketsTest {
expectSignatureValidationFails(key, "Critical unknown notation invalidates subkey binding sig."); expectSignatureValidationFails(key, "Critical unknown notation invalidates subkey binding sig.");
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void subkeyBindingUnknownNotationUnhashed(ImplementationFactory implementationFactory) throws IOException, PGPException { public void subkeyBindingUnknownNotationUnhashed() throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" + String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"\n" + "\n" +
@ -922,10 +907,9 @@ public class BindingSignatureSubpacketsTest {
expectSignatureValidationSucceeds(key, "Unknown notation is okay in unhashed area."); expectSignatureValidationSucceeds(key, "Unknown notation is okay in unhashed area.");
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void subkeyBindingCriticalUnknownNotationUnhashed(ImplementationFactory implementationFactory) throws IOException, PGPException { public void subkeyBindingCriticalUnknownNotationUnhashed() throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" + String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"\n" + "\n" +
@ -985,10 +969,9 @@ public class BindingSignatureSubpacketsTest {
expectSignatureValidationSucceeds(key, "Critical unknown notation is okay in unhashed area."); expectSignatureValidationSucceeds(key, "Critical unknown notation is okay in unhashed area.");
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void subkeyBindingBackSigFakeBackSig(ImplementationFactory implementationFactory) throws IOException, PGPException { public void subkeyBindingBackSigFakeBackSig() throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" + String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"\n" + "\n" +
@ -1058,10 +1041,9 @@ public class BindingSignatureSubpacketsTest {
expectSignatureValidationSucceeds(key, "Back-sig, fake back-sig should succeed to verify"); expectSignatureValidationSucceeds(key, "Back-sig, fake back-sig should succeed to verify");
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void subkeyBindingFakeBackSigBackSig(ImplementationFactory implementationFactory) throws IOException, PGPException { public void subkeyBindingFakeBackSigBackSig() throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" + String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"\n" + "\n" +
@ -1131,10 +1113,9 @@ public class BindingSignatureSubpacketsTest {
expectSignatureValidationSucceeds(key, "Fake back-sig, back-sig should succeed to verify."); expectSignatureValidationSucceeds(key, "Fake back-sig, back-sig should succeed to verify.");
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void primaryBindingIssuerFpOnly(ImplementationFactory implementationFactory) throws IOException, PGPException { public void primaryBindingIssuerFpOnly() throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" + String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"\n" + "\n" +
@ -1193,10 +1174,9 @@ public class BindingSignatureSubpacketsTest {
expectSignatureValidationSucceeds(key, "issuer fp is enough"); expectSignatureValidationSucceeds(key, "issuer fp is enough");
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void primaryBindingIssuerV6IssuerFp(ImplementationFactory implementationFactory) throws IOException, PGPException { public void primaryBindingIssuerV6IssuerFp() throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" + String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"\n" + "\n" +
@ -1255,10 +1235,9 @@ public class BindingSignatureSubpacketsTest {
expectSignatureValidationSucceeds(key, "interop"); expectSignatureValidationSucceeds(key, "interop");
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void primaryBindingIssuerFakeIssuer(ImplementationFactory implementationFactory) throws IOException, PGPException { public void primaryBindingIssuerFakeIssuer() throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" + String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"\n" + "\n" +
@ -1317,10 +1296,9 @@ public class BindingSignatureSubpacketsTest {
expectSignatureValidationSucceeds(key, "interop"); expectSignatureValidationSucceeds(key, "interop");
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void primaryBindingFakeIssuerIssuer(ImplementationFactory implementationFactory) throws IOException, PGPException { public void primaryBindingFakeIssuerIssuer() throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" + String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"\n" + "\n" +
@ -1379,10 +1357,9 @@ public class BindingSignatureSubpacketsTest {
expectSignatureValidationSucceeds(key, "interop"); expectSignatureValidationSucceeds(key, "interop");
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void primaryBindingFakeIssuer(ImplementationFactory implementationFactory) throws IOException, PGPException { public void primaryBindingFakeIssuer() throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" + String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"\n" + "\n" +
@ -1441,10 +1418,9 @@ public class BindingSignatureSubpacketsTest {
expectSignatureValidationSucceeds(key, "Fake issuer on primary key binding sig is not an issue."); expectSignatureValidationSucceeds(key, "Fake issuer on primary key binding sig is not an issue.");
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void primaryBindingNoIssuer(ImplementationFactory implementationFactory) throws IOException, PGPException { public void primaryBindingNoIssuer() throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" + String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"\n" + "\n" +
@ -1502,10 +1478,9 @@ public class BindingSignatureSubpacketsTest {
expectSignatureValidationSucceeds(key, "Missing issuer on primary key binding sig is not an issue"); expectSignatureValidationSucceeds(key, "Missing issuer on primary key binding sig is not an issue");
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void primaryBindingUnknownSubpacketHashed(ImplementationFactory implementationFactory) throws IOException, PGPException { public void primaryBindingUnknownSubpacketHashed() throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" + String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"\n" + "\n" +
@ -1564,10 +1539,9 @@ public class BindingSignatureSubpacketsTest {
expectSignatureValidationSucceeds(key, "Unknown subpacket in hashed area is not a problem."); expectSignatureValidationSucceeds(key, "Unknown subpacket in hashed area is not a problem.");
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void primaryBindingCriticalUnknownSubpacketHashed(ImplementationFactory implementationFactory) throws IOException, PGPException { public void primaryBindingCriticalUnknownSubpacketHashed() throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" + String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"\n" + "\n" +
@ -1626,10 +1600,9 @@ public class BindingSignatureSubpacketsTest {
expectSignatureValidationFails(key, "Critical unknown subpacket in hashed area invalidates signature."); expectSignatureValidationFails(key, "Critical unknown subpacket in hashed area invalidates signature.");
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void primaryBindingUnknownSubpacketUnhashed(ImplementationFactory implementationFactory) throws IOException, PGPException { public void primaryBindingUnknownSubpacketUnhashed() throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" + String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"\n" + "\n" +
@ -1688,10 +1661,9 @@ public class BindingSignatureSubpacketsTest {
expectSignatureValidationSucceeds(key, "Unknown subpacket is not an issue in the unhashed area"); expectSignatureValidationSucceeds(key, "Unknown subpacket is not an issue in the unhashed area");
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void primaryBindingCriticalUnknownSubpacketUnhashed(ImplementationFactory implementationFactory) throws IOException, PGPException { public void primaryBindingCriticalUnknownSubpacketUnhashed() throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" + String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"\n" + "\n" +
@ -1750,10 +1722,9 @@ public class BindingSignatureSubpacketsTest {
expectSignatureValidationSucceeds(key, "Critical unknown subpacket is acceptable in unhashed area of primary binding sig"); expectSignatureValidationSucceeds(key, "Critical unknown subpacket is acceptable in unhashed area of primary binding sig");
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void primaryBindingUnknownNotationHashed(ImplementationFactory implementationFactory) throws IOException, PGPException { public void primaryBindingUnknownNotationHashed() throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" + String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"\n" + "\n" +
@ -1813,10 +1784,9 @@ public class BindingSignatureSubpacketsTest {
expectSignatureValidationSucceeds(key, "Unknown notation is acceptable in hashed area of primary binding sig."); expectSignatureValidationSucceeds(key, "Unknown notation is acceptable in hashed area of primary binding sig.");
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void primaryBindingCriticalUnknownNotationHashed(ImplementationFactory implementationFactory) throws IOException, PGPException { public void primaryBindingCriticalUnknownNotationHashed() throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" + String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"\n" + "\n" +
@ -1876,10 +1846,9 @@ public class BindingSignatureSubpacketsTest {
expectSignatureValidationFails(key, "Critical unknown notation in hashed area invalidates primary binding sig"); expectSignatureValidationFails(key, "Critical unknown notation in hashed area invalidates primary binding sig");
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void primaryBindingUnknownNotationUnhashed(ImplementationFactory implementationFactory) throws IOException, PGPException { public void primaryBindingUnknownNotationUnhashed() throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" + String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"\n" + "\n" +
@ -1939,10 +1908,9 @@ public class BindingSignatureSubpacketsTest {
expectSignatureValidationSucceeds(key, "Unknown notation in unhashed area of primary key binding is okay."); expectSignatureValidationSucceeds(key, "Unknown notation in unhashed area of primary key binding is okay.");
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void primaryBindingCriticalUnknownNotationUnhashed(ImplementationFactory implementationFactory) throws IOException, PGPException { public void primaryBindingCriticalUnknownNotationUnhashed() throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" + String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"\n" + "\n" +

View file

@ -19,17 +19,16 @@ import org.bouncycastle.openpgp.PGPPublicKeyRing;
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.api.Test;
import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.params.provider.ArgumentsSource; import org.junit.jupiter.api.extension.ExtendWith;
import org.pgpainless.PGPainless; import org.pgpainless.PGPainless;
import org.pgpainless.decryption_verification.ConsumerOptions; import org.pgpainless.decryption_verification.ConsumerOptions;
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.exception.SignatureValidationException; import org.pgpainless.exception.SignatureValidationException;
import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.policy.Policy; import org.pgpainless.policy.Policy;
import org.pgpainless.signature.consumer.CertificateValidator; import org.pgpainless.signature.consumer.CertificateValidator;
import org.pgpainless.util.TestImplementationFactoryProvider; import org.pgpainless.util.ImplementationFactoryTestInvocationContextProvider;
public class CertificateValidatorTest { public class CertificateValidatorTest {
@ -38,10 +37,9 @@ public class CertificateValidatorTest {
* *
* @see <a href="https://tests.sequoia-pgp.org/#Key_revocation_test__primary_key_signs_and_is_revoked__revoked__unknown">Sequoia Test Suite</a> * @see <a href="https://tests.sequoia-pgp.org/#Key_revocation_test__primary_key_signs_and_is_revoked__revoked__unknown">Sequoia Test Suite</a>
*/ */
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void testPrimaryKeySignsAndIsHardRevokedUnknown(ImplementationFactory implementationFactory) throws IOException, PGPException { public void testPrimaryKeySignsAndIsHardRevokedUnknown() throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
String key = "-----BEGIN PGP ARMORED FILE-----\n" + String key = "-----BEGIN PGP ARMORED FILE-----\n" +
"Comment: ASCII Armor added by openpgp-interoperability-test-suite\n" + "Comment: ASCII Armor added by openpgp-interoperability-test-suite\n" +
@ -190,10 +188,9 @@ public class CertificateValidatorTest {
* Subkey signs, primary key is hard revoked with reason: unknown. * Subkey signs, primary key is hard revoked with reason: unknown.
* @see <a href="https://tests.sequoia-pgp.org/#Key_revocation_test__subkey_signs__primary_key_is_revoked__revoked__unknown">Sequoia Test Suite</a> * @see <a href="https://tests.sequoia-pgp.org/#Key_revocation_test__subkey_signs__primary_key_is_revoked__revoked__unknown">Sequoia Test Suite</a>
*/ */
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void testSubkeySignsPrimaryKeyIsHardRevokedUnknown(ImplementationFactory implementationFactory) throws IOException, PGPException { public void testSubkeySignsPrimaryKeyIsHardRevokedUnknown() throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
String key = "-----BEGIN PGP ARMORED FILE-----\n" + String key = "-----BEGIN PGP ARMORED FILE-----\n" +
"Comment: ASCII Armor added by openpgp-interoperability-test-suite\n" + "Comment: ASCII Armor added by openpgp-interoperability-test-suite\n" +
@ -343,10 +340,9 @@ public class CertificateValidatorTest {
* *
* @see <a href="https://tests.sequoia-pgp.org/#Key_revocation_test__subkey_signs__subkey_is_revoked__revoked__unknown">Sequoia Test Suite</a> * @see <a href="https://tests.sequoia-pgp.org/#Key_revocation_test__subkey_signs__subkey_is_revoked__revoked__unknown">Sequoia Test Suite</a>
*/ */
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void testSubkeySignsAndIsHardRevokedUnknown(ImplementationFactory implementationFactory) throws IOException, PGPException { public void testSubkeySignsAndIsHardRevokedUnknown() throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
String keyWithHardRev = "-----BEGIN PGP ARMORED FILE-----\n" + String keyWithHardRev = "-----BEGIN PGP ARMORED FILE-----\n" +
"Comment: ASCII Armor added by openpgp-interoperability-test-suite\n" + "Comment: ASCII Armor added by openpgp-interoperability-test-suite\n" +
@ -496,10 +492,9 @@ public class CertificateValidatorTest {
* *
* @see <a href="https://tests.sequoia-pgp.org/#Key_revocation_test__primary_key_signs_and_is_revoked__revoked__superseded">Sequoia Test Suite</a> * @see <a href="https://tests.sequoia-pgp.org/#Key_revocation_test__primary_key_signs_and_is_revoked__revoked__superseded">Sequoia Test Suite</a>
*/ */
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void testPrimaryKeySignsAndIsSoftRevokedSuperseded(ImplementationFactory implementationFactory) throws IOException, PGPException { public void testPrimaryKeySignsAndIsSoftRevokedSuperseded() throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
String keyWithSoftRev = "-----BEGIN PGP ARMORED FILE-----\n" + String keyWithSoftRev = "-----BEGIN PGP ARMORED FILE-----\n" +
"Comment: ASCII Armor added by openpgp-interoperability-test-suite\n" + "Comment: ASCII Armor added by openpgp-interoperability-test-suite\n" +
@ -654,10 +649,9 @@ public class CertificateValidatorTest {
* *
* @see <a href="https://tests.sequoia-pgp.org/#Key_revocation_test__subkey_signs__primary_key_is_revoked__revoked__superseded">Sequoia Test Suite</a> * @see <a href="https://tests.sequoia-pgp.org/#Key_revocation_test__subkey_signs__primary_key_is_revoked__revoked__superseded">Sequoia Test Suite</a>
*/ */
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void testSubkeySignsPrimaryKeyIsSoftRevokedSuperseded(ImplementationFactory implementationFactory) throws IOException, PGPException { public void testSubkeySignsPrimaryKeyIsSoftRevokedSuperseded() throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
String key = "-----BEGIN PGP ARMORED FILE-----\n" + String key = "-----BEGIN PGP ARMORED FILE-----\n" +
"Comment: ASCII Armor added by openpgp-interoperability-test-suite\n" + "Comment: ASCII Armor added by openpgp-interoperability-test-suite\n" +
@ -808,10 +802,9 @@ public class CertificateValidatorTest {
* *
* @see <a href="https://tests.sequoia-pgp.org/#Key_revocation_test__primary_key_signs_and_is_revoked__revoked__key_retired">Sequoia Test Suite</a> * @see <a href="https://tests.sequoia-pgp.org/#Key_revocation_test__primary_key_signs_and_is_revoked__revoked__key_retired">Sequoia Test Suite</a>
*/ */
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void testPrimaryKeySignsAndIsSoftRevokedRetired(ImplementationFactory implementationFactory) throws IOException, PGPException { public void testPrimaryKeySignsAndIsSoftRevokedRetired() throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
String key = "-----BEGIN PGP ARMORED FILE-----\n" + String key = "-----BEGIN PGP ARMORED FILE-----\n" +
"Comment: ASCII Armor added by openpgp-interoperability-test-suite\n" + "Comment: ASCII Armor added by openpgp-interoperability-test-suite\n" +
@ -962,10 +955,9 @@ public class CertificateValidatorTest {
* *
* @see <a href="https://tests.sequoia-pgp.org/#Temporary_validity">Sequoia Test Suite</a> * @see <a href="https://tests.sequoia-pgp.org/#Temporary_validity">Sequoia Test Suite</a>
*/ */
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void testTemporaryValidity(ImplementationFactory implementationFactory) throws IOException, PGPException { public void testTemporaryValidity() throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
String keyA = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" + String keyA = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
"Comment: D1A6 6E1A 23B1 82C9 980F 788C FBFC C82A 015E 7330\n" + "Comment: D1A6 6E1A 23B1 82C9 980F 788C FBFC C82A 015E 7330\n" +

View file

@ -14,22 +14,20 @@ import java.util.Date;
import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPPublicKeyRing; import org.bouncycastle.openpgp.PGPPublicKeyRing;
import org.bouncycastle.openpgp.PGPSignature; import org.bouncycastle.openpgp.PGPSignature;
import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.params.provider.ArgumentsSource; import org.junit.jupiter.api.extension.ExtendWith;
import org.pgpainless.PGPainless; import org.pgpainless.PGPainless;
import org.pgpainless.exception.SignatureValidationException; import org.pgpainless.exception.SignatureValidationException;
import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.signature.consumer.CertificateValidator; import org.pgpainless.signature.consumer.CertificateValidator;
import org.pgpainless.util.TestImplementationFactoryProvider; import org.pgpainless.util.ImplementationFactoryTestInvocationContextProvider;
public class KeyRevocationTest { public class KeyRevocationTest {
private static final String data = "Hello, World"; private static final String data = "Hello, World";
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void subkeySignsPrimaryKeyRevokedNoReason(ImplementationFactory implementationFactory) throws IOException, PGPException { public void subkeySignsPrimaryKeyRevokedNoReason() throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
String key = "-----BEGIN PGP ARMORED FILE-----\n" + String key = "-----BEGIN PGP ARMORED FILE-----\n" +
"Comment: ASCII Armor added by openpgp-interoperability-test-suite\n" + "Comment: ASCII Armor added by openpgp-interoperability-test-suite\n" +
@ -174,10 +172,9 @@ public class KeyRevocationTest {
* *
* @see <a href="https://tests.sequoia-pgp.org/#Key_revocation_test__subkey_signs__primary_key_is_not_revoked__base_case_">Sequoia Test-Suite</a> * @see <a href="https://tests.sequoia-pgp.org/#Key_revocation_test__subkey_signs__primary_key_is_not_revoked__base_case_">Sequoia Test-Suite</a>
*/ */
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void subkeySignsPrimaryKeyNotRevoked(ImplementationFactory implementationFactory) throws IOException, PGPException { public void subkeySignsPrimaryKeyNotRevoked() throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
String key = "-----BEGIN PGP ARMORED FILE-----\n" + String key = "-----BEGIN PGP ARMORED FILE-----\n" +
"Comment: ASCII Armor added by openpgp-interoperability-test-suite\n" + "Comment: ASCII Armor added by openpgp-interoperability-test-suite\n" +

View file

@ -33,8 +33,8 @@ import org.bouncycastle.openpgp.PGPSignatureList;
import org.bouncycastle.openpgp.PGPUtil; import org.bouncycastle.openpgp.PGPUtil;
import org.bouncycastle.openpgp.operator.PublicKeyDataDecryptorFactory; import org.bouncycastle.openpgp.operator.PublicKeyDataDecryptorFactory;
import org.bouncycastle.util.io.Streams; import org.bouncycastle.util.io.Streams;
import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.params.provider.ArgumentsSource; import org.junit.jupiter.api.extension.ExtendWith;
import org.pgpainless.PGPainless; import org.pgpainless.PGPainless;
import org.pgpainless.algorithm.DocumentSignatureType; import org.pgpainless.algorithm.DocumentSignatureType;
import org.pgpainless.algorithm.HashAlgorithm; import org.pgpainless.algorithm.HashAlgorithm;
@ -47,14 +47,14 @@ import org.pgpainless.encryption_signing.SigningOptions;
import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.protection.SecretKeyRingProtector; import org.pgpainless.key.protection.SecretKeyRingProtector;
import org.pgpainless.key.protection.UnlockSecretKey; import org.pgpainless.key.protection.UnlockSecretKey;
import org.pgpainless.util.TestImplementationFactoryProvider; import org.pgpainless.util.ImplementationFactoryTestInvocationContextProvider;
public class OnePassSignatureBracketingTest { public class OnePassSignatureBracketingTest {
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void onePassSignaturePacketsAndSignaturesAreBracketedTest(ImplementationFactory implementationFactory) throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, IOException { public void onePassSignaturePacketsAndSignaturesAreBracketedTest()
ImplementationFactory.setFactoryImplementation(implementationFactory); throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, IOException {
PGPSecretKeyRing key1 = PGPainless.generateKeyRing().modernKeyRing("Alice", null); PGPSecretKeyRing key1 = PGPainless.generateKeyRing().modernKeyRing("Alice", null);
PGPSecretKeyRing key2 = PGPainless.generateKeyRing().modernKeyRing("Bob", null); PGPSecretKeyRing key2 = PGPainless.generateKeyRing().modernKeyRing("Bob", null);

View file

@ -11,24 +11,22 @@ 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.params.ParameterizedTest; import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.params.provider.ArgumentsSource; import org.junit.jupiter.api.extension.ExtendWith;
import org.pgpainless.PGPainless; import org.pgpainless.PGPainless;
import org.pgpainless.decryption_verification.ConsumerOptions; import org.pgpainless.decryption_verification.ConsumerOptions;
import org.pgpainless.decryption_verification.DecryptionStream; import org.pgpainless.decryption_verification.DecryptionStream;
import org.pgpainless.encryption_signing.EncryptionOptions; import org.pgpainless.encryption_signing.EncryptionOptions;
import org.pgpainless.encryption_signing.EncryptionStream; import org.pgpainless.encryption_signing.EncryptionStream;
import org.pgpainless.encryption_signing.ProducerOptions; import org.pgpainless.encryption_signing.ProducerOptions;
import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.util.ImplementationFactoryTestInvocationContextProvider;
import org.pgpainless.util.Passphrase; import org.pgpainless.util.Passphrase;
import org.pgpainless.util.TestImplementationFactoryProvider;
public class MultiPassphraseSymmetricEncryptionTest { public class MultiPassphraseSymmetricEncryptionTest {
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void encryptDecryptWithMultiplePassphrases(ImplementationFactory implementationFactory) throws IOException, PGPException { public void encryptDecryptWithMultiplePassphrases() 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

@ -17,8 +17,9 @@ 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.params.ParameterizedTest; import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.params.provider.ArgumentsSource; import org.junit.jupiter.api.extension.ExtendWith;
import org.pgpainless.util.ImplementationFactoryTestInvocationContextProvider;
import org.pgpainless.PGPainless; import org.pgpainless.PGPainless;
import org.pgpainless.decryption_verification.ConsumerOptions; import org.pgpainless.decryption_verification.ConsumerOptions;
import org.pgpainless.decryption_verification.DecryptionStream; import org.pgpainless.decryption_verification.DecryptionStream;
@ -27,24 +28,21 @@ import org.pgpainless.encryption_signing.EncryptionOptions;
import org.pgpainless.encryption_signing.EncryptionStream; import org.pgpainless.encryption_signing.EncryptionStream;
import org.pgpainless.encryption_signing.ProducerOptions; import org.pgpainless.encryption_signing.ProducerOptions;
import org.pgpainless.exception.MissingDecryptionMethodException; import org.pgpainless.exception.MissingDecryptionMethodException;
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;
import org.pgpainless.key.protection.SecretKeyRingProtector; import org.pgpainless.key.protection.SecretKeyRingProtector;
import org.pgpainless.key.protection.passphrase_provider.SolitaryPassphraseProvider; import org.pgpainless.key.protection.passphrase_provider.SolitaryPassphraseProvider;
import org.pgpainless.util.Passphrase; import org.pgpainless.util.Passphrase;
import org.pgpainless.util.TestImplementationFactoryProvider;
/** /**
* Test parallel symmetric and public key encryption/decryption. * Test parallel symmetric and public key encryption/decryption.
*/ */
public class SymmetricEncryptionTest { public class SymmetricEncryptionTest {
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void encryptWithKeyAndPassphrase_DecryptWithKey(ImplementationFactory implementationFactory) throws IOException, PGPException { public void encryptWithKeyAndPassphrase_DecryptWithKey() 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();
@ -95,11 +93,9 @@ public class SymmetricEncryptionTest {
assertArrayEquals(plaintext, decrypted.toByteArray()); assertArrayEquals(plaintext, decrypted.toByteArray());
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void testMismatchPassphraseFails(ImplementationFactory implementationFactory) throws IOException, PGPException { public void testMismatchPassphraseFails() throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
byte[] bytes = new byte[5000]; byte[] bytes = new byte[5000];
new Random().nextBytes(bytes); new Random().nextBytes(bytes);

View file

@ -26,8 +26,8 @@ import org.bouncycastle.openpgp.PGPUtil;
import org.bouncycastle.util.io.Streams; import org.bouncycastle.util.io.Streams;
import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.params.provider.ArgumentsSource; import org.junit.jupiter.api.extension.ExtendWith;
import org.pgpainless.algorithm.HashAlgorithm; import org.pgpainless.algorithm.HashAlgorithm;
import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.TestKeys; import org.pgpainless.key.TestKeys;
@ -144,10 +144,9 @@ public class ArmorUtilsTest {
"-----END PGP MESSAGE-----\n", out.toString()); "-----END PGP MESSAGE-----\n", out.toString());
} }
@ParameterizedTest @TestTemplate
@ArgumentsSource(TestImplementationFactoryProvider.class) @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
public void decodeExampleTest(ImplementationFactory implementationFactory) throws IOException, PGPException { public void decodeExampleTest() throws IOException, PGPException {
ImplementationFactory.setFactoryImplementation(implementationFactory);
String armored = "-----BEGIN PGP MESSAGE-----\n" + String armored = "-----BEGIN PGP MESSAGE-----\n" +
"Version: OpenPrivacy 0.99\n" + "Version: OpenPrivacy 0.99\n" +
"\n" + "\n" +

View file

@ -0,0 +1,66 @@
// SPDX-FileCopyrightText: 2021 Paul Schaub <vanitasvitae@fsfe.org>
//
// SPDX-License-Identifier: Apache-2.0
package org.pgpainless.util;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Stream;
import org.junit.jupiter.api.extension.BeforeTestExecutionCallback;
import org.junit.jupiter.api.extension.Extension;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.TestTemplateInvocationContext;
import org.junit.jupiter.api.extension.TestTemplateInvocationContextProvider;
import org.pgpainless.implementation.BcImplementationFactory;
import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.implementation.JceImplementationFactory;
/**
* InvocationContextProvider that sets different {@link ImplementationFactory} implementations before running annotated
* tests.
*
* Example test annotation:
* {@code
* @TestTemplate
* @ExtendWith(ImplementationFactoryTestInvocationContextProvider.class)
* public void testAllImplementationFactories() {
* ...
* }
* }
*
* @see <a href="https://www.baeldung.com/junit5-test-templates">Baeldung: Writing Templates for Test Cases Using JUnit 5</a>
*/
public class ImplementationFactoryTestInvocationContextProvider implements TestTemplateInvocationContextProvider {
private static final List<ImplementationFactory> IMPLEMENTATIONS = Arrays.asList(
new BcImplementationFactory(),
new JceImplementationFactory()
);
@Override
public boolean supportsTestTemplate(ExtensionContext context) {
return true;
}
@Override
public Stream<TestTemplateInvocationContext> provideTestTemplateInvocationContexts(ExtensionContext context) {
return IMPLEMENTATIONS.stream()
.map(implementationFactory -> new TestTemplateInvocationContext() {
@Override
public String getDisplayName(int invocationIndex) {
return context.getDisplayName() + " with " + implementationFactory.getClass().getSimpleName();
}
@Override
public List<Extension> getAdditionalExtensions() {
return Collections.singletonList(
(BeforeTestExecutionCallback) ctx -> ImplementationFactory.setFactoryImplementation(implementationFactory)
);
}
});
}
}

View file

@ -17,6 +17,8 @@ import java.util.stream.Stream;
/** /**
* Utility class used to provide all available implementations of {@link ImplementationFactory} for parametrized tests. * Utility class used to provide all available implementations of {@link ImplementationFactory} for parametrized tests.
*
* @deprecated in favor of {@link ImplementationFactoryTestInvocationContextProvider}.
*/ */
public class TestImplementationFactoryProvider implements ArgumentsProvider { public class TestImplementationFactoryProvider implements ArgumentsProvider {