mirror of
https://codeberg.org/PGPainless/sop-java.git
synced 2025-09-08 17:59:43 +02:00
Allow for extension of test suite from 3rd party SOP implementations
This commit is contained in:
parent
fd426b533c
commit
0709bce35c
33 changed files with 731 additions and 547 deletions
|
@ -16,21 +16,27 @@ dependencies {
|
|||
testImplementation "org.junit.jupiter:junit-jupiter-api:$junitVersion"
|
||||
testImplementation "org.junit.jupiter:junit-jupiter-params:$junitVersion"
|
||||
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junitVersion"
|
||||
// Read json config file
|
||||
testImplementation "com.google.code.gson:gson:2.10.1"
|
||||
|
||||
api project(":sop-java")
|
||||
testImplementation(testFixtures(project(":sop-java")))
|
||||
|
||||
api "org.slf4j:slf4j-api:$slf4jVersion"
|
||||
testImplementation "ch.qos.logback:logback-classic:$logbackVersion"
|
||||
|
||||
// @Nonnull, @Nullable...
|
||||
implementation "com.google.code.findbugs:jsr305:$jsrVersion"
|
||||
|
||||
// The ExternalTestSubjectFactory reads json config file to find configured SOP binaries...
|
||||
testImplementation "com.google.code.gson:gson:2.10.1"
|
||||
// ...and extends TestSubjectFactory
|
||||
testImplementation(testFixtures(project(":sop-java")))
|
||||
}
|
||||
|
||||
test {
|
||||
// Inject configured external SOP instances using our custom TestSubjectFactory
|
||||
environment("test.implementation", "sop.testsuite.external.ExternalSOPInstanceFactory")
|
||||
|
||||
useJUnitPlatform()
|
||||
|
||||
// since we test external backends, we ignore test failures in this module
|
||||
ignoreFailures = true
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,248 +0,0 @@
|
|||
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sop.external;
|
||||
|
||||
import org.junit.jupiter.api.condition.EnabledIf;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import sop.SOP;
|
||||
import sop.testing.TestData;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static sop.testing.JUtils.arrayStartsWith;
|
||||
import static sop.testing.JUtils.assertArrayEndsWithIgnoreNewlines;
|
||||
import static sop.testing.JUtils.assertArrayStartsWith;
|
||||
import static sop.testing.JUtils.assertAsciiArmorEquals;
|
||||
import static sop.testing.TestData.BEGIN_PGP_MESSAGE;
|
||||
import static sop.testing.TestData.BEGIN_PGP_PRIVATE_KEY_BLOCK;
|
||||
import static sop.testing.TestData.BEGIN_PGP_PUBLIC_KEY_BLOCK;
|
||||
import static sop.testing.TestData.BEGIN_PGP_SIGNATURE;
|
||||
import static sop.testing.TestData.END_PGP_MESSAGE;
|
||||
import static sop.testing.TestData.END_PGP_PRIVATE_KEY_BLOCK;
|
||||
import static sop.testing.TestData.END_PGP_PUBLIC_KEY_BLOCK;
|
||||
import static sop.testing.TestData.END_PGP_SIGNATURE;
|
||||
|
||||
@EnabledIf("sop.external.AbstractExternalSOPTest#hasBackends")
|
||||
public class ExternalArmorDearmorRoundTripTest extends AbstractExternalSOPTest {
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void dearmorArmorAliceKey(SOP sop) throws IOException {
|
||||
byte[] aliceKey = TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] dearmored = sop.dearmor()
|
||||
.data(aliceKey)
|
||||
.getBytes();
|
||||
|
||||
assertFalse(arrayStartsWith(dearmored, BEGIN_PGP_PRIVATE_KEY_BLOCK));
|
||||
|
||||
byte[] armored = sop.armor()
|
||||
.data(dearmored)
|
||||
.getBytes();
|
||||
|
||||
assertArrayStartsWith(armored, BEGIN_PGP_PRIVATE_KEY_BLOCK);
|
||||
assertArrayEndsWithIgnoreNewlines(armored, END_PGP_PRIVATE_KEY_BLOCK);
|
||||
|
||||
// assertAsciiArmorEquals(aliceKey, armored);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void dearmorArmorAliceCert(SOP sop) throws IOException {
|
||||
byte[] aliceCert = TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] dearmored = sop.dearmor()
|
||||
.data(aliceCert)
|
||||
.getBytes();
|
||||
|
||||
assertFalse(arrayStartsWith(dearmored, BEGIN_PGP_PUBLIC_KEY_BLOCK));
|
||||
|
||||
byte[] armored = sop.armor()
|
||||
.data(dearmored)
|
||||
.getBytes();
|
||||
|
||||
assertArrayStartsWith(armored, BEGIN_PGP_PUBLIC_KEY_BLOCK);
|
||||
assertArrayEndsWithIgnoreNewlines(armored, END_PGP_PUBLIC_KEY_BLOCK);
|
||||
|
||||
// assertAsciiArmorEquals(aliceCert, armored);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void dearmorArmorBobKey(SOP sop) throws IOException {
|
||||
byte[] bobKey = TestData.BOB_KEY.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] dearmored = sop.dearmor()
|
||||
.data(bobKey)
|
||||
.getBytes();
|
||||
|
||||
assertFalse(arrayStartsWith(dearmored, BEGIN_PGP_PRIVATE_KEY_BLOCK));
|
||||
|
||||
byte[] armored = sop.armor()
|
||||
.data(dearmored)
|
||||
.getBytes();
|
||||
|
||||
assertArrayStartsWith(armored, BEGIN_PGP_PRIVATE_KEY_BLOCK);
|
||||
assertArrayEndsWithIgnoreNewlines(armored, END_PGP_PRIVATE_KEY_BLOCK);
|
||||
|
||||
// assertAsciiArmorEquals(bobKey, armored);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void dearmorArmorBobCert(SOP sop) throws IOException {
|
||||
byte[] bobCert = TestData.BOB_CERT.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] dearmored = sop.dearmor()
|
||||
.data(bobCert)
|
||||
.getBytes();
|
||||
|
||||
assertFalse(arrayStartsWith(dearmored, BEGIN_PGP_PUBLIC_KEY_BLOCK));
|
||||
|
||||
byte[] armored = sop.armor()
|
||||
.data(dearmored)
|
||||
.getBytes();
|
||||
|
||||
assertArrayStartsWith(armored, BEGIN_PGP_PUBLIC_KEY_BLOCK);
|
||||
assertArrayEndsWithIgnoreNewlines(armored, END_PGP_PUBLIC_KEY_BLOCK);
|
||||
|
||||
// assertAsciiArmorEquals(bobCert, armored);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void dearmorArmorCarolKey(SOP sop) throws IOException {
|
||||
byte[] carolKey = TestData.CAROL_KEY.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] dearmored = sop.dearmor()
|
||||
.data(carolKey)
|
||||
.getBytes();
|
||||
|
||||
assertFalse(arrayStartsWith(dearmored, BEGIN_PGP_PRIVATE_KEY_BLOCK));
|
||||
|
||||
byte[] armored = sop.armor()
|
||||
.data(dearmored)
|
||||
.getBytes();
|
||||
|
||||
assertArrayStartsWith(armored, BEGIN_PGP_PRIVATE_KEY_BLOCK);
|
||||
assertArrayEndsWithIgnoreNewlines(armored, END_PGP_PRIVATE_KEY_BLOCK);
|
||||
|
||||
// assertAsciiArmorEquals(carolKey, armored);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void dearmorArmorCarolCert(SOP sop) throws IOException {
|
||||
byte[] carolCert = TestData.CAROL_CERT.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] dearmored = sop.dearmor()
|
||||
.data(carolCert)
|
||||
.getBytes();
|
||||
|
||||
assertFalse(arrayStartsWith(dearmored, BEGIN_PGP_PUBLIC_KEY_BLOCK));
|
||||
|
||||
byte[] armored = sop.armor()
|
||||
.data(dearmored)
|
||||
.getBytes();
|
||||
|
||||
assertArrayStartsWith(armored, BEGIN_PGP_PUBLIC_KEY_BLOCK);
|
||||
assertArrayEndsWithIgnoreNewlines(armored, END_PGP_PUBLIC_KEY_BLOCK);
|
||||
|
||||
// assertAsciiArmorEquals(carolCert, armored);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void dearmorArmorMessage(SOP sop) throws IOException {
|
||||
byte[] message = ("-----BEGIN PGP MESSAGE-----\n" +
|
||||
"\n" +
|
||||
"wV4DR2b2udXyHrYSAQdAMZy9Iqb1IxszjI3v+TsfK//0lnJ9PKHDqVAB5ohp+RMw\n" +
|
||||
"8fmuL3phS9uISFT/DrizC8ALJhMqw5R+lLB/RvTTA/qS6tN5dRyL+YLFU3/N0CRF\n" +
|
||||
"0j8BtQEsMmRo60LzUq/OBI0dFjwFq1efpfOGkpRYkuIzndCjBEgnLUkrHzUc1uD9\n" +
|
||||
"CePQFpprprnGEzpE3flQLUc=\n" +
|
||||
"=ZiFR\n" +
|
||||
"-----END PGP MESSAGE-----\n").getBytes(StandardCharsets.UTF_8);
|
||||
byte[] dearmored = sop.dearmor()
|
||||
.data(message)
|
||||
.getBytes();
|
||||
|
||||
assertFalse(arrayStartsWith(dearmored, BEGIN_PGP_MESSAGE));
|
||||
|
||||
byte[] armored = sop.armor()
|
||||
.data(dearmored)
|
||||
.getBytes();
|
||||
|
||||
assertArrayStartsWith(armored, BEGIN_PGP_MESSAGE);
|
||||
assertArrayEndsWithIgnoreNewlines(armored, END_PGP_MESSAGE);
|
||||
|
||||
// assertAsciiArmorEquals(message, armored);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void dearmorArmorSignature(SOP sop) throws IOException {
|
||||
byte[] signature = ("-----BEGIN PGP SIGNATURE-----\n" +
|
||||
"\n" +
|
||||
"wr0EABYKAG8FgmPBdRAJEPIxVQxPR+OORxQAAAAAAB4AIHNhbHRAbm90YXRpb25z\n" +
|
||||
"LnNlcXVvaWEtcGdwLm9yZ2un17fF3C46Adgzp0mU4RG8Txy/T/zOBcBw/NYaLGrQ\n" +
|
||||
"FiEE64W7X6M6deFelE5j8jFVDE9H444AAMiEAP9LBQWLo4oP5IrFZPuSUQSPsUxB\n" +
|
||||
"c+Qu1raXDKzS/8Q9IAD+LnHIjRHcqNPobNHXF/saXIYXeZR+LJKszTJozzwqdQE=\n" +
|
||||
"=GHvQ\n" +
|
||||
"-----END PGP SIGNATURE-----\n").getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] dearmored = sop.dearmor()
|
||||
.data(signature)
|
||||
.getBytes();
|
||||
|
||||
assertFalse(arrayStartsWith(dearmored, BEGIN_PGP_SIGNATURE));
|
||||
|
||||
byte[] armored = sop.armor()
|
||||
.data(dearmored)
|
||||
.getBytes();
|
||||
|
||||
assertArrayStartsWith(armored, BEGIN_PGP_SIGNATURE);
|
||||
assertArrayEndsWithIgnoreNewlines(armored, END_PGP_SIGNATURE);
|
||||
|
||||
assertAsciiArmorEquals(signature, armored);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void testDearmoringTwiceIsIdempotent(SOP sop) throws IOException {
|
||||
byte[] dearmored = sop.dearmor()
|
||||
.data(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.getBytes();
|
||||
|
||||
byte[] dearmoredAgain = sop.dearmor()
|
||||
.data(dearmored)
|
||||
.getBytes();
|
||||
|
||||
assertArrayEquals(dearmored, dearmoredAgain);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void testArmoringTwiceIsIdempotent(SOP sop) throws IOException {
|
||||
byte[] armored = ("-----BEGIN PGP SIGNATURE-----\n" +
|
||||
"\n" +
|
||||
"wr0EABYKAG8FgmPBdRAJEPIxVQxPR+OORxQAAAAAAB4AIHNhbHRAbm90YXRpb25z\n" +
|
||||
"LnNlcXVvaWEtcGdwLm9yZ2un17fF3C46Adgzp0mU4RG8Txy/T/zOBcBw/NYaLGrQ\n" +
|
||||
"FiEE64W7X6M6deFelE5j8jFVDE9H444AAMiEAP9LBQWLo4oP5IrFZPuSUQSPsUxB\n" +
|
||||
"c+Qu1raXDKzS/8Q9IAD+LnHIjRHcqNPobNHXF/saXIYXeZR+LJKszTJozzwqdQE=\n" +
|
||||
"=GHvQ\n" +
|
||||
"-----END PGP SIGNATURE-----\n").getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] armoredAgain = sop.armor()
|
||||
.data(armored)
|
||||
.getBytes();
|
||||
|
||||
assertAsciiArmorEquals(armored, armoredAgain);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sop.external;
|
||||
|
||||
import org.junit.jupiter.api.condition.EnabledIf;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import sop.ByteArrayAndResult;
|
||||
import sop.DecryptionResult;
|
||||
import sop.SOP;
|
||||
import sop.SessionKey;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static sop.testing.TestData.ALICE_KEY;
|
||||
import static sop.testing.TestData.PLAINTEXT;
|
||||
|
||||
@EnabledIf("sop.external.AbstractExternalSOPTest#hasBackends")
|
||||
public class ExternalDecryptWithSessionKeyTest extends AbstractExternalSOPTest {
|
||||
|
||||
private static final String CIPHERTEXT = "-----BEGIN PGP MESSAGE-----\n" +
|
||||
"\n" +
|
||||
"wV4DR2b2udXyHrYSAQdAy+Et2hCh4ubh8KsmM8ctRDN6Pee+UHVVcI6YXpY9S2cw\n" +
|
||||
"1QEROCgfm6xGb+hgxmoFrWhtZU03Arb27ZmpWA6e6Ha9jFdB4/DDbqbhlVuFOmti\n" +
|
||||
"0j8BqGjEvEYAon+8F9TwMaDbPjjy9SdgQBorlM88ChIW14KQtpG9FZN+r+xVKPG1\n" +
|
||||
"8EIOxI4qOZaH3Wejraca31M=\n" +
|
||||
"=1imC\n" +
|
||||
"-----END PGP MESSAGE-----\n";
|
||||
private static final String SESSION_KEY = "9:ED682800F5FEA829A82E8B7DDF8CE9CF4BF9BB45024B017764462EE53101C36A";
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void testDecryptAndExtractSessionKey(SOP sop) throws IOException {
|
||||
ByteArrayAndResult<DecryptionResult> bytesAndResult = sop.decrypt()
|
||||
.withKey(ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.ciphertext(CIPHERTEXT.getBytes(StandardCharsets.UTF_8))
|
||||
.toByteArrayAndResult();
|
||||
|
||||
assertEquals(SESSION_KEY, bytesAndResult.getResult().getSessionKey().get().toString());
|
||||
|
||||
assertArrayEquals(PLAINTEXT.getBytes(StandardCharsets.UTF_8), bytesAndResult.getBytes());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void testDecryptWithSessionKey(SOP sop) throws IOException {
|
||||
byte[] decrypted = sop.decrypt()
|
||||
.withSessionKey(SessionKey.fromString(SESSION_KEY))
|
||||
.ciphertext(CIPHERTEXT.getBytes(StandardCharsets.UTF_8))
|
||||
.toByteArrayAndResult()
|
||||
.getBytes();
|
||||
|
||||
assertArrayEquals(PLAINTEXT.getBytes(StandardCharsets.UTF_8), decrypted);
|
||||
}
|
||||
}
|
|
@ -1,263 +0,0 @@
|
|||
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sop.external;
|
||||
|
||||
import org.junit.jupiter.api.condition.EnabledIf;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import sop.SOP;
|
||||
import sop.Verification;
|
||||
import sop.enums.SignAs;
|
||||
import sop.exception.SOPGPException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static sop.testing.JUtils.assertArrayStartsWith;
|
||||
import static sop.testing.JUtils.assertSignedBy;
|
||||
import static sop.testing.TestData.ALICE_CERT;
|
||||
import static sop.testing.TestData.ALICE_DETACHED_SIGNED_MESSAGE;
|
||||
import static sop.testing.TestData.ALICE_DETACHED_SIGNED_MESSAGE_DATE;
|
||||
import static sop.testing.TestData.ALICE_KEY;
|
||||
import static sop.testing.TestData.ALICE_PRIMARY_FINGERPRINT;
|
||||
import static sop.testing.TestData.ALICE_SIGNING_FINGERPRINT;
|
||||
import static sop.testing.TestData.BEGIN_PGP_SIGNATURE;
|
||||
import static sop.testing.TestData.BOB_CERT;
|
||||
import static sop.testing.TestData.BOB_KEY;
|
||||
import static sop.testing.TestData.BOB_PRIMARY_FINGERPRINT;
|
||||
import static sop.testing.TestData.BOB_SIGNING_FINGERPRINT;
|
||||
import static sop.testing.TestData.CAROL_CERT;
|
||||
import static sop.testing.TestData.CAROL_KEY;
|
||||
import static sop.testing.TestData.CAROL_PRIMARY_FINGERPRINT;
|
||||
import static sop.testing.TestData.CAROL_SIGNING_FINGERPRINT;
|
||||
import static sop.testing.TestData.PASSWORD;
|
||||
import static sop.testing.TestData.PASSWORD_PROTECTED_CERT;
|
||||
import static sop.testing.TestData.PASSWORD_PROTECTED_KEY;
|
||||
import static sop.testing.TestData.PLAINTEXT;
|
||||
|
||||
@EnabledIf("sop.external.AbstractExternalSOPTest#hasBackends")
|
||||
public class ExternalDetachedSignVerifyRoundTripTest extends AbstractExternalSOPTest {
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void signVerifyWithAliceKey(SOP sop) throws IOException {
|
||||
byte[] message = PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] signature = sop.detachedSign()
|
||||
.key(ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.data(message)
|
||||
.toByteArrayAndResult()
|
||||
.getBytes();
|
||||
|
||||
List<Verification> verificationList = sop.detachedVerify()
|
||||
.cert(ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.signatures(signature)
|
||||
.data(message);
|
||||
|
||||
assertFalse(verificationList.isEmpty());
|
||||
assertSignedBy(verificationList, ALICE_SIGNING_FINGERPRINT, ALICE_PRIMARY_FINGERPRINT);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void signVerifyTextModeWithAliceKey(SOP sop) throws IOException {
|
||||
byte[] message = PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] signature = sop.detachedSign()
|
||||
.key(ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.mode(SignAs.Text)
|
||||
.data(message)
|
||||
.toByteArrayAndResult()
|
||||
.getBytes();
|
||||
|
||||
List<Verification> verificationList = sop.detachedVerify()
|
||||
.cert(ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.signatures(signature)
|
||||
.data(message);
|
||||
|
||||
assertFalse(verificationList.isEmpty());
|
||||
assertSignedBy(verificationList, ALICE_SIGNING_FINGERPRINT, ALICE_PRIMARY_FINGERPRINT);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void verifyKnownMessageWithAliceCert(SOP sop) throws IOException {
|
||||
byte[] message = PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
byte[] signature = ALICE_DETACHED_SIGNED_MESSAGE.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
List<Verification> verificationList = sop.detachedVerify()
|
||||
.cert(ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.signatures(signature)
|
||||
.data(message);
|
||||
|
||||
assertFalse(verificationList.isEmpty());
|
||||
assertSignedBy(verificationList, ALICE_SIGNING_FINGERPRINT, ALICE_PRIMARY_FINGERPRINT, ALICE_DETACHED_SIGNED_MESSAGE_DATE);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void signVerifyWithBobKey(SOP sop) throws IOException {
|
||||
byte[] message = PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] signature = sop.detachedSign()
|
||||
.key(BOB_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.data(message)
|
||||
.toByteArrayAndResult()
|
||||
.getBytes();
|
||||
|
||||
List<Verification> verificationList = sop.detachedVerify()
|
||||
.cert(BOB_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.signatures(signature)
|
||||
.data(message);
|
||||
|
||||
assertFalse(verificationList.isEmpty());
|
||||
assertSignedBy(verificationList, BOB_SIGNING_FINGERPRINT, BOB_PRIMARY_FINGERPRINT);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void signVerifyWithCarolKey(SOP sop) throws IOException {
|
||||
byte[] message = PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] signature = sop.detachedSign()
|
||||
.key(CAROL_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.data(message)
|
||||
.toByteArrayAndResult()
|
||||
.getBytes();
|
||||
|
||||
List<Verification> verificationList = sop.detachedVerify()
|
||||
.cert(CAROL_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.signatures(signature)
|
||||
.data(message);
|
||||
|
||||
assertFalse(verificationList.isEmpty());
|
||||
assertSignedBy(verificationList, CAROL_SIGNING_FINGERPRINT, CAROL_PRIMARY_FINGERPRINT);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void signVerifyWithEncryptedKey(SOP sop) throws IOException {
|
||||
byte[] message = PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] signature = sop.detachedSign()
|
||||
.key(PASSWORD_PROTECTED_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.withKeyPassword(PASSWORD)
|
||||
.data(message)
|
||||
.toByteArrayAndResult()
|
||||
.getBytes();
|
||||
|
||||
assertArrayStartsWith(signature, BEGIN_PGP_SIGNATURE);
|
||||
|
||||
List<Verification> verificationList = sop.detachedVerify()
|
||||
.cert(PASSWORD_PROTECTED_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.signatures(signature)
|
||||
.data(message);
|
||||
|
||||
assertFalse(verificationList.isEmpty());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void signArmorVerifyWithBobKey(SOP sop) throws IOException {
|
||||
byte[] message = PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] signature = sop.detachedSign()
|
||||
.key(BOB_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.noArmor()
|
||||
.data(message)
|
||||
.toByteArrayAndResult()
|
||||
.getBytes();
|
||||
|
||||
byte[] armored = sop.armor()
|
||||
.data(signature)
|
||||
.getBytes();
|
||||
|
||||
List<Verification> verificationList = sop.detachedVerify()
|
||||
.cert(BOB_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.signatures(armored)
|
||||
.data(message);
|
||||
|
||||
assertFalse(verificationList.isEmpty());
|
||||
assertSignedBy(verificationList, BOB_SIGNING_FINGERPRINT, BOB_PRIMARY_FINGERPRINT);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void verifyNotAfterThrowsNoSignature(SOP sop) {
|
||||
byte[] message = PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
byte[] signature = ALICE_DETACHED_SIGNED_MESSAGE.getBytes(StandardCharsets.UTF_8);
|
||||
Date beforeSignature = new Date(ALICE_DETACHED_SIGNED_MESSAGE_DATE.getTime() - 1000); // 1 sec before sig
|
||||
|
||||
assertThrows(SOPGPException.NoSignature.class, () -> sop.detachedVerify()
|
||||
.cert(ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.notAfter(beforeSignature)
|
||||
.signatures(signature)
|
||||
.data(message));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void verifyNotBeforeThrowsNoSignature(SOP sop) {
|
||||
byte[] message = PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
byte[] signature = ALICE_DETACHED_SIGNED_MESSAGE.getBytes(StandardCharsets.UTF_8);
|
||||
Date afterSignature = new Date(ALICE_DETACHED_SIGNED_MESSAGE_DATE.getTime() + 1000); // 1 sec after sig
|
||||
|
||||
assertThrows(SOPGPException.NoSignature.class, () -> sop.detachedVerify()
|
||||
.cert(ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.notBefore(afterSignature)
|
||||
.signatures(signature)
|
||||
.data(message));
|
||||
}
|
||||
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void signVerifyWithEncryptedKeyWithoutPassphraseFails(SOP sop) {
|
||||
assertThrows(SOPGPException.KeyIsProtected.class, () ->
|
||||
sop.detachedSign()
|
||||
.key(PASSWORD_PROTECTED_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.data(PLAINTEXT.getBytes(StandardCharsets.UTF_8))
|
||||
.toByteArrayAndResult()
|
||||
.getBytes());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void signWithProtectedKeyAndMultiplePassphrasesTest(SOP sop)
|
||||
throws IOException {
|
||||
byte[] message = PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] signature = sop.sign()
|
||||
.key(PASSWORD_PROTECTED_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.withKeyPassword("wrong")
|
||||
.withKeyPassword(PASSWORD) // correct
|
||||
.withKeyPassword("wrong2")
|
||||
.data(message)
|
||||
.toByteArrayAndResult()
|
||||
.getBytes();
|
||||
|
||||
assertFalse(sop.verify()
|
||||
.cert(PASSWORD_PROTECTED_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.signatures(signature)
|
||||
.data(message)
|
||||
.isEmpty());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void verifyMissingCertCausesMissingArg(SOP sop) {
|
||||
byte[] message = PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
assertThrows(SOPGPException.MissingArg.class, () ->
|
||||
sop.verify()
|
||||
.signatures(ALICE_DETACHED_SIGNED_MESSAGE.getBytes(StandardCharsets.UTF_8))
|
||||
.data(message));
|
||||
}
|
||||
|
||||
}
|
|
@ -1,300 +0,0 @@
|
|||
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sop.external;
|
||||
|
||||
import org.junit.jupiter.api.condition.EnabledIf;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import sop.ByteArrayAndResult;
|
||||
import sop.DecryptionResult;
|
||||
import sop.SOP;
|
||||
import sop.Verification;
|
||||
import sop.enums.EncryptAs;
|
||||
import sop.exception.SOPGPException;
|
||||
import sop.util.UTCUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static sop.testing.JUtils.assertSignedBy;
|
||||
import static sop.testing.TestData.ALICE_CERT;
|
||||
import static sop.testing.TestData.ALICE_KEY;
|
||||
import static sop.testing.TestData.ALICE_PRIMARY_FINGERPRINT;
|
||||
import static sop.testing.TestData.ALICE_SIGNING_FINGERPRINT;
|
||||
import static sop.testing.TestData.BOB_CERT;
|
||||
import static sop.testing.TestData.BOB_KEY;
|
||||
import static sop.testing.TestData.CAROL_CERT;
|
||||
import static sop.testing.TestData.CAROL_KEY;
|
||||
import static sop.testing.TestData.PLAINTEXT;
|
||||
|
||||
@EnabledIf("sop.external.AbstractExternalSOPTest#hasBackends")
|
||||
public class ExternalEncryptDecryptRoundTripTest extends AbstractExternalSOPTest {
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void encryptDecryptRoundTripPasswordTest(SOP sop) throws IOException {
|
||||
byte[] message = PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
byte[] ciphertext = sop.encrypt()
|
||||
.withPassword("sw0rdf1sh")
|
||||
.plaintext(message)
|
||||
.getBytes();
|
||||
|
||||
byte[] plaintext = sop.decrypt()
|
||||
.withPassword("sw0rdf1sh")
|
||||
.ciphertext(ciphertext)
|
||||
.toByteArrayAndResult()
|
||||
.getBytes();
|
||||
|
||||
assertArrayEquals(message, plaintext);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void encryptDecryptRoundTripAliceTest(SOP sop) throws IOException {
|
||||
byte[] message = PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
byte[] ciphertext = sop.encrypt()
|
||||
.withCert(ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.plaintext(message)
|
||||
.getBytes();
|
||||
|
||||
ByteArrayAndResult<DecryptionResult> bytesAndResult = sop.decrypt()
|
||||
.withKey(ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.ciphertext(ciphertext)
|
||||
.toByteArrayAndResult();
|
||||
|
||||
byte[] plaintext = bytesAndResult.getBytes();
|
||||
assertArrayEquals(message, plaintext);
|
||||
|
||||
DecryptionResult result = bytesAndResult.getResult();
|
||||
assertNotNull(result.getSessionKey().get());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void encryptDecryptRoundTripBobTest(SOP sop) throws IOException {
|
||||
byte[] message = PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
byte[] ciphertext = sop.encrypt()
|
||||
.withCert(BOB_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.plaintext(message)
|
||||
.getBytes();
|
||||
|
||||
byte[] plaintext = sop.decrypt()
|
||||
.withKey(BOB_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.ciphertext(ciphertext)
|
||||
.toByteArrayAndResult()
|
||||
.getBytes();
|
||||
|
||||
assertArrayEquals(message, plaintext);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void encryptDecryptRoundTripCarolTest(SOP sop) throws IOException {
|
||||
byte[] message = PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
byte[] ciphertext = sop.encrypt()
|
||||
.withCert(CAROL_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.plaintext(message)
|
||||
.getBytes();
|
||||
|
||||
byte[] plaintext = sop.decrypt()
|
||||
.withKey(CAROL_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.ciphertext(ciphertext)
|
||||
.toByteArrayAndResult()
|
||||
.getBytes();
|
||||
|
||||
assertArrayEquals(message, plaintext);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void encryptNoArmorThenArmorThenDecryptRoundTrip(SOP sop) throws IOException {
|
||||
byte[] message = PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
byte[] ciphertext = sop.encrypt()
|
||||
.withCert(ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.noArmor()
|
||||
.plaintext(message)
|
||||
.getBytes();
|
||||
|
||||
byte[] armored = sop.armor()
|
||||
.data(ciphertext)
|
||||
.getBytes();
|
||||
|
||||
ByteArrayAndResult<DecryptionResult> bytesAndResult = sop.decrypt()
|
||||
.withKey(ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.ciphertext(armored)
|
||||
.toByteArrayAndResult();
|
||||
|
||||
byte[] plaintext = bytesAndResult.getBytes();
|
||||
assertArrayEquals(message, plaintext);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void encryptSignDecryptVerifyRoundTripAliceTest(SOP sop) throws IOException {
|
||||
byte[] message = PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
byte[] ciphertext = sop.encrypt()
|
||||
.withCert(ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.signWith(ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.plaintext(message)
|
||||
.getBytes();
|
||||
|
||||
ByteArrayAndResult<DecryptionResult> bytesAndResult = sop.decrypt()
|
||||
.withKey(ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.verifyWithCert(ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.ciphertext(ciphertext)
|
||||
.toByteArrayAndResult();
|
||||
|
||||
byte[] plaintext = bytesAndResult.getBytes();
|
||||
assertArrayEquals(message, plaintext);
|
||||
|
||||
DecryptionResult result = bytesAndResult.getResult();
|
||||
assertNotNull(result.getSessionKey().get());
|
||||
List<Verification> verificationList = result.getVerifications();
|
||||
assertEquals(1, verificationList.size());
|
||||
assertSignedBy(verificationList, ALICE_SIGNING_FINGERPRINT, ALICE_PRIMARY_FINGERPRINT);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void encryptSignAsTextDecryptVerifyRoundTripAliceTest(SOP sop) throws IOException {
|
||||
byte[] message = PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
byte[] ciphertext = sop.encrypt()
|
||||
.withCert(ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.signWith(ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.mode(EncryptAs.Text)
|
||||
.plaintext(message)
|
||||
.getBytes();
|
||||
|
||||
ByteArrayAndResult<DecryptionResult> bytesAndResult = sop.decrypt()
|
||||
.withKey(ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.verifyWithCert(ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.ciphertext(ciphertext)
|
||||
.toByteArrayAndResult();
|
||||
|
||||
byte[] plaintext = bytesAndResult.getBytes();
|
||||
assertArrayEquals(message, plaintext);
|
||||
|
||||
DecryptionResult result = bytesAndResult.getResult();
|
||||
assertNotNull(result.getSessionKey().get());
|
||||
List<Verification> verificationList = result.getVerifications();
|
||||
assertEquals(1, verificationList.size());
|
||||
assertSignedBy(verificationList, ALICE_SIGNING_FINGERPRINT, ALICE_PRIMARY_FINGERPRINT);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void encryptSignDecryptVerifyRoundTripWithFreshEncryptedKeyTest(SOP sop) throws IOException {
|
||||
byte[] keyPassword = "sw0rdf1sh".getBytes(StandardCharsets.UTF_8);
|
||||
byte[] key = sop.generateKey()
|
||||
.withKeyPassword(keyPassword)
|
||||
.userId("Alice <alice@openpgp.org>")
|
||||
.generate()
|
||||
.getBytes();
|
||||
byte[] cert = sop.extractCert()
|
||||
.key(key)
|
||||
.getBytes();
|
||||
|
||||
byte[] message = "Hello, World!\n".getBytes(StandardCharsets.UTF_8);
|
||||
byte[] ciphertext = sop.encrypt()
|
||||
.withCert(cert)
|
||||
.signWith(key)
|
||||
.withKeyPassword(keyPassword)
|
||||
.plaintext(message)
|
||||
.getBytes();
|
||||
|
||||
ByteArrayAndResult<DecryptionResult> bytesAndResult = sop.decrypt()
|
||||
.withKey(key)
|
||||
.withKeyPassword(keyPassword)
|
||||
.verifyWithCert(cert)
|
||||
.ciphertext(ciphertext)
|
||||
.toByteArrayAndResult();
|
||||
|
||||
assertFalse(bytesAndResult.getResult().getVerifications().isEmpty());
|
||||
assertArrayEquals(message, bytesAndResult.getBytes());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void decryptVerifyNotAfterTest(SOP sop) {
|
||||
byte[] message = ("-----BEGIN PGP MESSAGE-----\n" +
|
||||
"\n" +
|
||||
"wV4DR2b2udXyHrYSAQdAwlOwwyxFDJta5+H9abgSj8jum9v7etUc9usdrElESmow\n" +
|
||||
"2Hka48AFVfOezYh0OFn9R8+DMcpuE+e4nw3XnnX5nKs/j3AC2IW6zRHUkRcF3ZCq\n" +
|
||||
"0sBNAfjnTYCMjuBmqdcCLzaZT4Hadnpg6neP1UecT/jP14maGfv8nwt0IDGR0Bik\n" +
|
||||
"0WC/UJLpWyJ/6TgRrA5hNfANVnfiFBzIiThiVBRWPT2StHr2cOAvFxQK4Uk07rK9\n" +
|
||||
"9aTUak8FpML+QA83U8I3qOk4QbzGVBP+IDJ+AKmvDz+0V+9kUhKp+8vyXsBmo9c3\n" +
|
||||
"SAXjhFSiPQkU7ORsc6gQHL9+KPOU+W2poPK87H3cmaGiusnXMeLXLIUbkBUJTswd\n" +
|
||||
"JNrA2yAkTTFP9QabsdcdTGoeYamq1c29kHF3GOTTcEqXw4WWXngcF7Kbcf435kkL\n" +
|
||||
"4iSJnCaxTPftKUxmiGqMqLef7ICVnq/lz3HrH1VD54s=\n" +
|
||||
"=Ebi3\n" +
|
||||
"-----END PGP MESSAGE-----").getBytes(StandardCharsets.UTF_8);
|
||||
Date signatureDate = UTCUtil.parseUTCDate("2023-01-13T16:09:32Z");
|
||||
|
||||
Date beforeSignature = new Date(signatureDate.getTime() - 1000); // 1 sec before signing date
|
||||
|
||||
assertThrows(SOPGPException.NoSignature.class, () -> {
|
||||
ByteArrayAndResult<DecryptionResult> bytesAndResult = sop.decrypt()
|
||||
.withKey(ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.verifyWithCert(ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.verifyNotAfter(beforeSignature)
|
||||
.ciphertext(message)
|
||||
.toByteArrayAndResult();
|
||||
|
||||
if (bytesAndResult.getResult().getVerifications().isEmpty()) {
|
||||
throw new SOPGPException.NoSignature("No verifiable signature found.");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void decryptVerifyNotBeforeTest(SOP sop) {
|
||||
byte[] message = ("-----BEGIN PGP MESSAGE-----\n" +
|
||||
"\n" +
|
||||
"wV4DR2b2udXyHrYSAQdAwlOwwyxFDJta5+H9abgSj8jum9v7etUc9usdrElESmow\n" +
|
||||
"2Hka48AFVfOezYh0OFn9R8+DMcpuE+e4nw3XnnX5nKs/j3AC2IW6zRHUkRcF3ZCq\n" +
|
||||
"0sBNAfjnTYCMjuBmqdcCLzaZT4Hadnpg6neP1UecT/jP14maGfv8nwt0IDGR0Bik\n" +
|
||||
"0WC/UJLpWyJ/6TgRrA5hNfANVnfiFBzIiThiVBRWPT2StHr2cOAvFxQK4Uk07rK9\n" +
|
||||
"9aTUak8FpML+QA83U8I3qOk4QbzGVBP+IDJ+AKmvDz+0V+9kUhKp+8vyXsBmo9c3\n" +
|
||||
"SAXjhFSiPQkU7ORsc6gQHL9+KPOU+W2poPK87H3cmaGiusnXMeLXLIUbkBUJTswd\n" +
|
||||
"JNrA2yAkTTFP9QabsdcdTGoeYamq1c29kHF3GOTTcEqXw4WWXngcF7Kbcf435kkL\n" +
|
||||
"4iSJnCaxTPftKUxmiGqMqLef7ICVnq/lz3HrH1VD54s=\n" +
|
||||
"=Ebi3\n" +
|
||||
"-----END PGP MESSAGE-----").getBytes(StandardCharsets.UTF_8);
|
||||
Date signatureDate = UTCUtil.parseUTCDate("2023-01-13T16:09:32Z");
|
||||
|
||||
Date afterSignature = new Date(signatureDate.getTime() + 1000); // 1 sec after signing date
|
||||
|
||||
assertThrows(SOPGPException.NoSignature.class, () -> {
|
||||
ByteArrayAndResult<DecryptionResult> bytesAndResult = sop.decrypt()
|
||||
.withKey(ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.verifyWithCert(ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.verifyNotBefore(afterSignature)
|
||||
.ciphertext(message)
|
||||
.toByteArrayAndResult();
|
||||
|
||||
if (bytesAndResult.getResult().getVerifications().isEmpty()) {
|
||||
throw new SOPGPException.NoSignature("No verifiable signature found.");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void missingArgsTest(SOP sop) {
|
||||
byte[] message = PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
assertThrows(SOPGPException.MissingArg.class, () -> sop.encrypt()
|
||||
.plaintext(message)
|
||||
.getBytes());
|
||||
}
|
||||
}
|
|
@ -1,117 +0,0 @@
|
|||
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sop.external;
|
||||
|
||||
import org.junit.jupiter.api.condition.EnabledIf;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import sop.SOP;
|
||||
import sop.testing.TestData;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static sop.testing.JUtils.arrayStartsWith;
|
||||
import static sop.testing.JUtils.assertArrayEndsWithIgnoreNewlines;
|
||||
import static sop.testing.JUtils.assertArrayStartsWith;
|
||||
import static sop.testing.JUtils.assertAsciiArmorEquals;
|
||||
import static sop.testing.TestData.BEGIN_PGP_PUBLIC_KEY_BLOCK;
|
||||
import static sop.testing.TestData.END_PGP_PUBLIC_KEY_BLOCK;
|
||||
|
||||
@EnabledIf("sop.external.AbstractExternalSOPTest#hasBackends")
|
||||
public class ExternalExtractCertTest extends AbstractExternalSOPTest {
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void extractArmoredCertFromArmoredKeyTest(SOP sop) throws IOException {
|
||||
InputStream keyIn = sop.generateKey()
|
||||
.userId("Alice <alice@openpgp.org>")
|
||||
.generate()
|
||||
.getInputStream();
|
||||
|
||||
byte[] cert = sop.extractCert().key(keyIn).getBytes();
|
||||
assertArrayStartsWith(cert, BEGIN_PGP_PUBLIC_KEY_BLOCK);
|
||||
assertArrayEndsWithIgnoreNewlines(cert, END_PGP_PUBLIC_KEY_BLOCK);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void extractAliceCertFromAliceKeyTest(SOP sop) throws IOException {
|
||||
byte[] armoredCert = sop.extractCert()
|
||||
.key(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.getBytes();
|
||||
assertAsciiArmorEquals(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8), armoredCert);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void extractBobsCertFromBobsKeyTest(SOP sop) throws IOException {
|
||||
byte[] armoredCert = sop.extractCert()
|
||||
.key(TestData.BOB_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.getBytes();
|
||||
assertAsciiArmorEquals(TestData.BOB_CERT.getBytes(StandardCharsets.UTF_8), armoredCert);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void extractCarolsCertFromCarolsKeyTest(SOP sop) throws IOException {
|
||||
byte[] armoredCert = sop.extractCert()
|
||||
.key(TestData.CAROL_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.getBytes();
|
||||
assertAsciiArmorEquals(TestData.CAROL_CERT.getBytes(StandardCharsets.UTF_8), armoredCert);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void extractUnarmoredCertFromArmoredKeyTest(SOP sop) throws IOException {
|
||||
InputStream keyIn = sop.generateKey()
|
||||
.userId("Alice <alice@openpgp.org>")
|
||||
.generate()
|
||||
.getInputStream();
|
||||
|
||||
byte[] cert = sop.extractCert()
|
||||
.noArmor()
|
||||
.key(keyIn)
|
||||
.getBytes();
|
||||
|
||||
assertFalse(arrayStartsWith(cert, BEGIN_PGP_PUBLIC_KEY_BLOCK));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void extractArmoredCertFromUnarmoredKeyTest(SOP sop) throws IOException {
|
||||
InputStream keyIn = sop.generateKey()
|
||||
.userId("Alice <alice@openpgp.org>")
|
||||
.noArmor()
|
||||
.generate()
|
||||
.getInputStream();
|
||||
|
||||
byte[] cert = sop.extractCert()
|
||||
.key(keyIn)
|
||||
.getBytes();
|
||||
|
||||
assertArrayStartsWith(cert, BEGIN_PGP_PUBLIC_KEY_BLOCK);
|
||||
assertArrayEndsWithIgnoreNewlines(cert, END_PGP_PUBLIC_KEY_BLOCK);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void extractUnarmoredCertFromUnarmoredKeyTest(SOP sop) throws IOException {
|
||||
InputStream keyIn = sop.generateKey()
|
||||
.noArmor()
|
||||
.userId("Alice <alice@openpgp.org>")
|
||||
.generate()
|
||||
.getInputStream();
|
||||
|
||||
byte[] cert = sop.extractCert()
|
||||
.noArmor()
|
||||
.key(keyIn)
|
||||
.getBytes();
|
||||
|
||||
assertFalse(arrayStartsWith(cert, BEGIN_PGP_PUBLIC_KEY_BLOCK));
|
||||
}
|
||||
}
|
|
@ -1,98 +0,0 @@
|
|||
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sop.external;
|
||||
|
||||
import org.junit.jupiter.api.condition.EnabledIf;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import sop.SOP;
|
||||
import sop.testing.JUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static sop.testing.JUtils.assertArrayEndsWithIgnoreNewlines;
|
||||
import static sop.testing.JUtils.assertArrayStartsWith;
|
||||
import static sop.testing.TestData.BEGIN_PGP_PRIVATE_KEY_BLOCK;
|
||||
import static sop.testing.TestData.END_PGP_PRIVATE_KEY_BLOCK;
|
||||
|
||||
@EnabledIf("sop.external.AbstractExternalSOPTest#hasBackends")
|
||||
public class ExternalGenerateKeyTest extends AbstractExternalSOPTest {
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void generateKeyTest(SOP sop) throws IOException {
|
||||
byte[] key = sop.generateKey()
|
||||
.userId("Alice <alice@openpgp.org>")
|
||||
.generate()
|
||||
.getBytes();
|
||||
|
||||
assertArrayStartsWith(key, BEGIN_PGP_PRIVATE_KEY_BLOCK);
|
||||
assertArrayEndsWithIgnoreNewlines(key, END_PGP_PRIVATE_KEY_BLOCK);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void generateKeyNoArmor(SOP sop) throws IOException {
|
||||
byte[] key = sop.generateKey()
|
||||
.userId("Alice <alice@openpgp.org>")
|
||||
.noArmor()
|
||||
.generate()
|
||||
.getBytes();
|
||||
|
||||
assertFalse(JUtils.arrayStartsWith(key, BEGIN_PGP_PRIVATE_KEY_BLOCK));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void generateKeyWithMultipleUserIdsTest(SOP sop) throws IOException {
|
||||
byte[] key = sop.generateKey()
|
||||
.userId("Alice <alice@openpgp.org>")
|
||||
.userId("Bob <bob@openpgp.org>")
|
||||
.generate()
|
||||
.getBytes();
|
||||
|
||||
assertArrayStartsWith(key, BEGIN_PGP_PRIVATE_KEY_BLOCK);
|
||||
assertArrayEndsWithIgnoreNewlines(key, END_PGP_PRIVATE_KEY_BLOCK);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void generateKeyWithoutUserIdTest(SOP sop) throws IOException {
|
||||
byte[] key = sop.generateKey()
|
||||
.generate()
|
||||
.getBytes();
|
||||
|
||||
assertArrayStartsWith(key, BEGIN_PGP_PRIVATE_KEY_BLOCK);
|
||||
assertArrayEndsWithIgnoreNewlines(key, END_PGP_PRIVATE_KEY_BLOCK);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void generateKeyWithPasswordTest(SOP sop) throws IOException {
|
||||
byte[] key = sop.generateKey()
|
||||
.userId("Alice <alice@openpgp.org>")
|
||||
.withKeyPassword("sw0rdf1sh")
|
||||
.generate()
|
||||
.getBytes();
|
||||
|
||||
assertArrayStartsWith(key, BEGIN_PGP_PRIVATE_KEY_BLOCK);
|
||||
assertArrayEndsWithIgnoreNewlines(key, END_PGP_PRIVATE_KEY_BLOCK);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void generateKeyWithMultipleUserIdsAndPassword(SOP sop) throws IOException {
|
||||
byte[] key = sop.generateKey()
|
||||
.userId("Alice <alice@openpgp.org>")
|
||||
.userId("Bob <bob@openpgp.org>")
|
||||
.withKeyPassword("sw0rdf1sh")
|
||||
.generate()
|
||||
.getBytes();
|
||||
|
||||
assertArrayStartsWith(key, BEGIN_PGP_PRIVATE_KEY_BLOCK);
|
||||
assertArrayEndsWithIgnoreNewlines(key, END_PGP_PRIVATE_KEY_BLOCK);
|
||||
}
|
||||
}
|
|
@ -1,93 +0,0 @@
|
|||
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sop.external;
|
||||
|
||||
import org.junit.jupiter.api.condition.EnabledIf;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import sop.ByteArrayAndResult;
|
||||
import sop.SOP;
|
||||
import sop.Signatures;
|
||||
import sop.Verification;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static sop.testing.JUtils.arrayStartsWith;
|
||||
import static sop.testing.JUtils.assertArrayStartsWith;
|
||||
import static sop.testing.TestData.ALICE_CERT;
|
||||
import static sop.testing.TestData.ALICE_KEY;
|
||||
import static sop.testing.TestData.BEGIN_PGP_SIGNATURE;
|
||||
import static sop.testing.TestData.PLAINTEXT;
|
||||
|
||||
@EnabledIf("sop.external.AbstractExternalSOPTest#hasBackends")
|
||||
public class ExternalInlineSignDetachVerifyRoundTripTest extends AbstractExternalSOPTest {
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void inlineSignThenDetachThenDetachedVerifyTest(SOP sop) throws IOException {
|
||||
byte[] message = PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] inlineSigned = sop.inlineSign()
|
||||
.key(ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.data(message)
|
||||
.getBytes();
|
||||
|
||||
ByteArrayAndResult<Signatures> bytesAndResult = sop.inlineDetach()
|
||||
.message(inlineSigned)
|
||||
.toByteArrayAndResult();
|
||||
|
||||
byte[] plaintext = bytesAndResult.getBytes();
|
||||
assertArrayEquals(message, plaintext);
|
||||
|
||||
byte[] signatures = bytesAndResult.getResult()
|
||||
.getBytes();
|
||||
|
||||
List<Verification> verifications = sop.detachedVerify()
|
||||
.cert(ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.signatures(signatures)
|
||||
.data(plaintext);
|
||||
|
||||
assertFalse(verifications.isEmpty());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void inlineSignThenDetachNoArmorThenArmorThenDetachedVerifyTest(SOP sop) throws IOException {
|
||||
byte[] message = "Hello, World!\n".getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] inlineSigned = sop.inlineSign()
|
||||
.key(ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.data(message)
|
||||
.getBytes();
|
||||
|
||||
ByteArrayAndResult<Signatures> bytesAndResult = sop.inlineDetach()
|
||||
.noArmor()
|
||||
.message(inlineSigned)
|
||||
.toByteArrayAndResult();
|
||||
|
||||
byte[] plaintext = bytesAndResult.getBytes();
|
||||
assertArrayEquals(message, plaintext);
|
||||
|
||||
byte[] signatures = bytesAndResult.getResult()
|
||||
.getBytes();
|
||||
assertFalse(arrayStartsWith(signatures, BEGIN_PGP_SIGNATURE));
|
||||
|
||||
byte[] armored = sop.armor()
|
||||
.data(signatures)
|
||||
.getBytes();
|
||||
assertArrayStartsWith(armored, BEGIN_PGP_SIGNATURE);
|
||||
|
||||
List<Verification> verifications = sop.detachedVerify()
|
||||
.cert(ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.signatures(armored)
|
||||
.data(plaintext);
|
||||
|
||||
assertFalse(verifications.isEmpty());
|
||||
}
|
||||
}
|
|
@ -1,213 +0,0 @@
|
|||
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sop.external;
|
||||
|
||||
import org.junit.jupiter.api.condition.EnabledIf;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import sop.ByteArrayAndResult;
|
||||
import sop.SOP;
|
||||
import sop.Verification;
|
||||
import sop.enums.InlineSignAs;
|
||||
import sop.exception.SOPGPException;
|
||||
import sop.testing.JUtils;
|
||||
import sop.testing.TestData;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static sop.testing.JUtils.assertSignedBy;
|
||||
import static sop.testing.TestData.ALICE_CERT;
|
||||
import static sop.testing.TestData.ALICE_KEY;
|
||||
import static sop.testing.TestData.ALICE_PRIMARY_FINGERPRINT;
|
||||
import static sop.testing.TestData.ALICE_SIGNING_FINGERPRINT;
|
||||
import static sop.testing.TestData.BEGIN_PGP_MESSAGE;
|
||||
import static sop.testing.TestData.BEGIN_PGP_SIGNED_MESSAGE;
|
||||
import static sop.testing.TestData.PLAINTEXT;
|
||||
|
||||
@EnabledIf("sop.external.AbstractExternalSOPTest#hasBackends")
|
||||
public class ExternalInlineSignVerifyTest extends AbstractExternalSOPTest {
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void inlineSignVerifyAlice(SOP sop) throws IOException {
|
||||
byte[] message = PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] inlineSigned = sop.inlineSign()
|
||||
.key(ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.data(message)
|
||||
.getBytes();
|
||||
|
||||
JUtils.assertArrayStartsWith(inlineSigned, BEGIN_PGP_MESSAGE);
|
||||
|
||||
ByteArrayAndResult<List<Verification>> bytesAndResult = sop.inlineVerify()
|
||||
.cert(ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.data(inlineSigned)
|
||||
.toByteArrayAndResult();
|
||||
|
||||
assertArrayEquals(message, bytesAndResult.getBytes());
|
||||
List<Verification> verificationList = bytesAndResult.getResult();
|
||||
assertSignedBy(verificationList, ALICE_SIGNING_FINGERPRINT, ALICE_PRIMARY_FINGERPRINT);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void inlineSignVerifyAliceNoArmor(SOP sop) throws IOException {
|
||||
byte[] message = PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] inlineSigned = sop.inlineSign()
|
||||
.key(ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.noArmor()
|
||||
.data(message)
|
||||
.getBytes();
|
||||
|
||||
assertFalse(JUtils.arrayStartsWith(inlineSigned, BEGIN_PGP_MESSAGE));
|
||||
|
||||
ByteArrayAndResult<List<Verification>> bytesAndResult = sop.inlineVerify()
|
||||
.cert(ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.data(inlineSigned)
|
||||
.toByteArrayAndResult();
|
||||
|
||||
assertArrayEquals(message, bytesAndResult.getBytes());
|
||||
List<Verification> verificationList = bytesAndResult.getResult();
|
||||
assertSignedBy(verificationList, ALICE_SIGNING_FINGERPRINT, ALICE_PRIMARY_FINGERPRINT);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void clearsignVerifyAlice(SOP sop) throws IOException {
|
||||
byte[] message = PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] clearsigned = sop.inlineSign()
|
||||
.key(ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.mode(InlineSignAs.clearsigned)
|
||||
.data(message)
|
||||
.getBytes();
|
||||
|
||||
JUtils.assertArrayStartsWith(clearsigned, BEGIN_PGP_SIGNED_MESSAGE);
|
||||
|
||||
ByteArrayAndResult<List<Verification>> bytesAndResult = sop.inlineVerify()
|
||||
.cert(ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.data(clearsigned)
|
||||
.toByteArrayAndResult();
|
||||
|
||||
assertArrayEquals(message, bytesAndResult.getBytes());
|
||||
List<Verification> verificationList = bytesAndResult.getResult();
|
||||
assertSignedBy(verificationList, ALICE_SIGNING_FINGERPRINT, ALICE_PRIMARY_FINGERPRINT);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void inlineVerifyCompareSignatureDate(SOP sop) throws IOException {
|
||||
byte[] message = TestData.ALICE_INLINE_SIGNED_MESSAGE.getBytes(StandardCharsets.UTF_8);
|
||||
Date signatureDate = TestData.ALICE_INLINE_SIGNED_MESSAGE_DATE;
|
||||
|
||||
ByteArrayAndResult<List<Verification>> bytesAndResult = sop.inlineVerify()
|
||||
.cert(ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.data(message)
|
||||
.toByteArrayAndResult();
|
||||
List<Verification> verificationList = bytesAndResult.getResult();
|
||||
assertSignedBy(verificationList, ALICE_SIGNING_FINGERPRINT, ALICE_PRIMARY_FINGERPRINT, signatureDate);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void assertNotBeforeThrowsNoSignature(SOP sop) {
|
||||
byte[] message = TestData.ALICE_INLINE_SIGNED_MESSAGE.getBytes(StandardCharsets.UTF_8);
|
||||
Date signatureDate = TestData.ALICE_INLINE_SIGNED_MESSAGE_DATE;
|
||||
Date afterSignature = new Date(signatureDate.getTime() + 1000); // 1 sec before sig
|
||||
|
||||
assertThrows(SOPGPException.NoSignature.class, () -> sop.inlineVerify()
|
||||
.notBefore(afterSignature)
|
||||
.cert(ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.data(message)
|
||||
.toByteArrayAndResult());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void assertNotAfterThrowsNoSignature(SOP sop) {
|
||||
byte[] message = TestData.ALICE_INLINE_SIGNED_MESSAGE.getBytes(StandardCharsets.UTF_8);
|
||||
Date signatureDate = TestData.ALICE_INLINE_SIGNED_MESSAGE_DATE;
|
||||
Date beforeSignature = new Date(signatureDate.getTime() - 1000); // 1 sec before sig
|
||||
|
||||
assertThrows(SOPGPException.NoSignature.class, () -> sop.inlineVerify()
|
||||
.notAfter(beforeSignature)
|
||||
.cert(ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.data(message)
|
||||
.toByteArrayAndResult());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void inlineSignVerifyBob(SOP sop) throws IOException {
|
||||
byte[] message = PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] inlineSigned = sop.inlineSign()
|
||||
.key(TestData.BOB_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.data(message)
|
||||
.getBytes();
|
||||
|
||||
JUtils.assertArrayStartsWith(inlineSigned, BEGIN_PGP_MESSAGE);
|
||||
|
||||
ByteArrayAndResult<List<Verification>> bytesAndResult = sop.inlineVerify()
|
||||
.cert(TestData.BOB_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.data(inlineSigned)
|
||||
.toByteArrayAndResult();
|
||||
|
||||
assertArrayEquals(message, bytesAndResult.getBytes());
|
||||
List<Verification> verificationList = bytesAndResult.getResult();
|
||||
assertSignedBy(verificationList, TestData.BOB_SIGNING_FINGERPRINT, TestData.BOB_PRIMARY_FINGERPRINT);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void inlineSignVerifyCarol(SOP sop) throws IOException {
|
||||
byte[] message = PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] inlineSigned = sop.inlineSign()
|
||||
.key(TestData.CAROL_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.data(message)
|
||||
.getBytes();
|
||||
|
||||
JUtils.assertArrayStartsWith(inlineSigned, BEGIN_PGP_MESSAGE);
|
||||
|
||||
ByteArrayAndResult<List<Verification>> bytesAndResult = sop.inlineVerify()
|
||||
.cert(TestData.CAROL_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.data(inlineSigned)
|
||||
.toByteArrayAndResult();
|
||||
|
||||
assertArrayEquals(message, bytesAndResult.getBytes());
|
||||
List<Verification> verificationList = bytesAndResult.getResult();
|
||||
assertSignedBy(verificationList, TestData.CAROL_SIGNING_FINGERPRINT, TestData.CAROL_PRIMARY_FINGERPRINT);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void inlineSignVerifyProtectedKey(SOP sop) throws IOException {
|
||||
byte[] message = PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] inlineSigned = sop.inlineSign()
|
||||
.withKeyPassword(TestData.PASSWORD)
|
||||
.key(TestData.PASSWORD_PROTECTED_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.mode(InlineSignAs.binary)
|
||||
.data(message)
|
||||
.getBytes();
|
||||
|
||||
ByteArrayAndResult<List<Verification>> bytesAndResult = sop.inlineVerify()
|
||||
.cert(TestData.PASSWORD_PROTECTED_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.data(inlineSigned)
|
||||
.toByteArrayAndResult();
|
||||
|
||||
List<Verification> verificationList = bytesAndResult.getResult();
|
||||
assertSignedBy(verificationList, TestData.PASSWORD_PROTECTED_SIGNING_FINGERPRINT, TestData.PASSWORD_PROTECTED_PRIMARY_FINGERPRINT);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sop.external;
|
||||
|
||||
import org.junit.jupiter.api.condition.EnabledIf;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import sop.SOP;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@EnabledIf("sop.external.AbstractExternalSOPTest#hasBackends")
|
||||
public class ExternalVersionTest extends AbstractExternalSOPTest {
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void versionNameTest(SOP sop) {
|
||||
String name = sop.version().getName();
|
||||
assertNotNull(name);
|
||||
assertFalse(name.isEmpty());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void versionVersionTest(SOP sop) {
|
||||
String version = sop.version().getVersion();
|
||||
assertTrue(version.matches("\\d+(\\.\\d+)*\\S*"));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void backendVersionTest(SOP sop) {
|
||||
String backend = sop.version().getBackendVersion();
|
||||
assertFalse(backend.isEmpty());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void extendedVersionTest(SOP sop) {
|
||||
String extended = sop.version().getExtendedVersion();
|
||||
assertFalse(extended.isEmpty());
|
||||
}
|
||||
|
||||
}
|
|
@ -2,26 +2,26 @@
|
|||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sop.external;
|
||||
package sop.testsuite.external;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import org.junit.jupiter.api.Named;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import sop.SOP;
|
||||
import sop.external.ExternalSOP;
|
||||
import sop.testsuite.SOPInstanceFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public abstract class AbstractExternalSOPTest {
|
||||
public class ExternalSOPInstanceFactory extends SOPInstanceFactory {
|
||||
|
||||
private static final List<Arguments> backends = new ArrayList<>();
|
||||
|
||||
static {
|
||||
@Override
|
||||
public Map<String, SOP> provideSOPInstances() {
|
||||
Map<String, SOP> backends = new HashMap<>();
|
||||
TestSuite suite = readConfiguration();
|
||||
if (suite != null && !suite.backends.isEmpty()) {
|
||||
for (TestSubject subject : suite.backends) {
|
||||
|
@ -37,30 +37,24 @@ public abstract class AbstractExternalSOPTest {
|
|||
}
|
||||
|
||||
SOP sop = new ExternalSOP(subject.sop, env);
|
||||
backends.add(Arguments.of(Named.of(subject.name, sop)));
|
||||
backends.put(subject.name, sop);
|
||||
}
|
||||
}
|
||||
return backends;
|
||||
}
|
||||
|
||||
public static Stream<Arguments> provideBackends() {
|
||||
return backends.stream();
|
||||
}
|
||||
|
||||
public static TestSuite readConfiguration() {
|
||||
Gson gson = new Gson();
|
||||
InputStream inputStream = AbstractExternalSOPTest.class.getResourceAsStream("config.json");
|
||||
InputStream inputStream = ExternalSOPInstanceFactory.class.getResourceAsStream("config.json");
|
||||
if (inputStream == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
InputStreamReader reader = new InputStreamReader(inputStream);
|
||||
TestSuite suite = gson.fromJson(reader, TestSuite.class);
|
||||
return suite;
|
||||
return gson.fromJson(reader, TestSuite.class);
|
||||
}
|
||||
|
||||
public static boolean hasBackends() {
|
||||
return !backends.isEmpty();
|
||||
}
|
||||
|
||||
// JSON DTOs
|
||||
|
11
external-sop/src/test/java/sop/testsuite/external/operation/ExternalArmorDearmorTest.java
vendored
Normal file
11
external-sop/src/test/java/sop/testsuite/external/operation/ExternalArmorDearmorTest.java
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sop.testsuite.external.operation;
|
||||
|
||||
import sop.testsuite.operation.ArmorDearmorTest;
|
||||
|
||||
public class ExternalArmorDearmorTest extends ArmorDearmorTest {
|
||||
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sop.testsuite.external.operation;
|
||||
|
||||
import sop.testsuite.operation.DecryptWithSessionKeyTest;
|
||||
|
||||
public class ExternalDecryptWithSessionKeyTest extends DecryptWithSessionKeyTest {
|
||||
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sop.testsuite.external.operation;
|
||||
|
||||
import sop.testsuite.operation.DetachedSignDetachedVerifyTest;
|
||||
|
||||
public class ExternalDetachedSignDetachedVerifyTest extends DetachedSignDetachedVerifyTest {
|
||||
}
|
11
external-sop/src/test/java/sop/testsuite/external/operation/ExternalEncryptDecryptTest.java
vendored
Normal file
11
external-sop/src/test/java/sop/testsuite/external/operation/ExternalEncryptDecryptTest.java
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sop.testsuite.external.operation;
|
||||
|
||||
import sop.testsuite.operation.EncryptDecryptTest;
|
||||
|
||||
public class ExternalEncryptDecryptTest extends EncryptDecryptTest {
|
||||
|
||||
}
|
11
external-sop/src/test/java/sop/testsuite/external/operation/ExternalExtractCertTest.java
vendored
Normal file
11
external-sop/src/test/java/sop/testsuite/external/operation/ExternalExtractCertTest.java
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sop.testsuite.external.operation;
|
||||
|
||||
import sop.testsuite.operation.ExtractCertTest;
|
||||
|
||||
public class ExternalExtractCertTest extends ExtractCertTest {
|
||||
|
||||
}
|
11
external-sop/src/test/java/sop/testsuite/external/operation/ExternalGenerateKeyTest.java
vendored
Normal file
11
external-sop/src/test/java/sop/testsuite/external/operation/ExternalGenerateKeyTest.java
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sop.testsuite.external.operation;
|
||||
|
||||
import sop.testsuite.operation.GenerateKeyTest;
|
||||
|
||||
public class ExternalGenerateKeyTest extends GenerateKeyTest {
|
||||
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sop.testsuite.external.operation;
|
||||
|
||||
import sop.testsuite.operation.InlineSignInlineDetachDetachedVerifyTest;
|
||||
|
||||
public class ExternalInlineSignInlineDetachDetachedVerifyTest
|
||||
extends InlineSignInlineDetachDetachedVerifyTest {
|
||||
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sop.testsuite.external.operation;
|
||||
|
||||
import sop.testsuite.operation.InlineSignInlineVerifyTest;
|
||||
|
||||
public class ExternalInlineSignInlineVerifyTest extends InlineSignInlineVerifyTest {
|
||||
|
||||
}
|
11
external-sop/src/test/java/sop/testsuite/external/operation/ExternalVersionTest.java
vendored
Normal file
11
external-sop/src/test/java/sop/testsuite/external/operation/ExternalVersionTest.java
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sop.testsuite.external.operation;
|
||||
|
||||
import sop.testsuite.operation.VersionTest;
|
||||
|
||||
public class ExternalVersionTest extends VersionTest {
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue