mirror of
https://codeberg.org/PGPainless/sop-java.git
synced 2024-12-22 21:07:57 +01:00
Restructure test artifacts into sop-java testFixtures
This commit is contained in:
parent
88e3ba0095
commit
fd426b533c
13 changed files with 303 additions and 185 deletions
|
@ -20,6 +20,7 @@ dependencies {
|
||||||
testImplementation "com.google.code.gson:gson:2.10.1"
|
testImplementation "com.google.code.gson:gson:2.10.1"
|
||||||
|
|
||||||
api project(":sop-java")
|
api project(":sop-java")
|
||||||
|
testImplementation(testFixtures(project(":sop-java")))
|
||||||
|
|
||||||
api "org.slf4j:slf4j-api:$slf4jVersion"
|
api "org.slf4j:slf4j-api:$slf4jVersion"
|
||||||
testImplementation "ch.qos.logback:logback-classic:$logbackVersion"
|
testImplementation "ch.qos.logback:logback-classic:$logbackVersion"
|
||||||
|
|
|
@ -8,28 +8,29 @@ import org.junit.jupiter.api.condition.EnabledIf;
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
import org.junit.jupiter.params.provider.MethodSource;
|
import org.junit.jupiter.params.provider.MethodSource;
|
||||||
import sop.SOP;
|
import sop.SOP;
|
||||||
|
import sop.testing.TestData;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static sop.external.JUtils.arrayStartsWith;
|
import static sop.testing.JUtils.arrayStartsWith;
|
||||||
import static sop.external.JUtils.assertArrayStartsWith;
|
import static sop.testing.JUtils.assertArrayEndsWithIgnoreNewlines;
|
||||||
import static sop.external.JUtils.assertAsciiArmorEquals;
|
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")
|
@EnabledIf("sop.external.AbstractExternalSOPTest#hasBackends")
|
||||||
public class ExternalArmorDearmorRoundTripTest extends AbstractExternalSOPTest {
|
public class ExternalArmorDearmorRoundTripTest extends AbstractExternalSOPTest {
|
||||||
|
|
||||||
private static final String BEGIN_PGP_PRIVATE_KEY_BLOCK = "-----BEGIN PGP PRIVATE KEY BLOCK-----\n";
|
|
||||||
private static final byte[] BEGIN_PGP_PRIVATE_KEY_BLOCK_BYTES = BEGIN_PGP_PRIVATE_KEY_BLOCK.getBytes(StandardCharsets.UTF_8);
|
|
||||||
private static final String BEGIN_PGP_PUBLIC_KEY_BLOCK = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n";
|
|
||||||
private static final byte[] BEGIN_PGP_PUBLIC_KEY_BLOCK_BYTES = BEGIN_PGP_PUBLIC_KEY_BLOCK.getBytes(StandardCharsets.UTF_8);
|
|
||||||
private static final String BEGIN_PGP_MESSAGE = "-----BEGIN PGP MESSAGE-----\n";
|
|
||||||
private static final byte[] BEGIN_PGP_MESSAGE_BYTES = BEGIN_PGP_MESSAGE.getBytes(StandardCharsets.UTF_8);
|
|
||||||
private static final String BEGIN_PGP_SIGNATURE = "-----BEGIN PGP SIGNATURE-----\n";
|
|
||||||
private static final byte[] BEGIN_PGP_SIGNATURE_BYTES = BEGIN_PGP_SIGNATURE.getBytes(StandardCharsets.UTF_8);
|
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||||
public void dearmorArmorAliceKey(SOP sop) throws IOException {
|
public void dearmorArmorAliceKey(SOP sop) throws IOException {
|
||||||
|
@ -39,14 +40,16 @@ public class ExternalArmorDearmorRoundTripTest extends AbstractExternalSOPTest {
|
||||||
.data(aliceKey)
|
.data(aliceKey)
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
assertFalse(arrayStartsWith(dearmored, BEGIN_PGP_PRIVATE_KEY_BLOCK_BYTES));
|
assertFalse(arrayStartsWith(dearmored, BEGIN_PGP_PRIVATE_KEY_BLOCK));
|
||||||
|
|
||||||
byte[] armored = sop.armor()
|
byte[] armored = sop.armor()
|
||||||
.data(dearmored)
|
.data(dearmored)
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
assertArrayStartsWith(armored, BEGIN_PGP_PRIVATE_KEY_BLOCK_BYTES);
|
assertArrayStartsWith(armored, BEGIN_PGP_PRIVATE_KEY_BLOCK);
|
||||||
assertAsciiArmorEquals(aliceKey, armored);
|
assertArrayEndsWithIgnoreNewlines(armored, END_PGP_PRIVATE_KEY_BLOCK);
|
||||||
|
|
||||||
|
// assertAsciiArmorEquals(aliceKey, armored);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
|
@ -58,14 +61,16 @@ public class ExternalArmorDearmorRoundTripTest extends AbstractExternalSOPTest {
|
||||||
.data(aliceCert)
|
.data(aliceCert)
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
assertFalse(arrayStartsWith(dearmored, BEGIN_PGP_PUBLIC_KEY_BLOCK_BYTES));
|
assertFalse(arrayStartsWith(dearmored, BEGIN_PGP_PUBLIC_KEY_BLOCK));
|
||||||
|
|
||||||
byte[] armored = sop.armor()
|
byte[] armored = sop.armor()
|
||||||
.data(dearmored)
|
.data(dearmored)
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
assertArrayStartsWith(armored, BEGIN_PGP_PUBLIC_KEY_BLOCK_BYTES);
|
assertArrayStartsWith(armored, BEGIN_PGP_PUBLIC_KEY_BLOCK);
|
||||||
assertAsciiArmorEquals(aliceCert, armored);
|
assertArrayEndsWithIgnoreNewlines(armored, END_PGP_PUBLIC_KEY_BLOCK);
|
||||||
|
|
||||||
|
// assertAsciiArmorEquals(aliceCert, armored);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
|
@ -77,14 +82,16 @@ public class ExternalArmorDearmorRoundTripTest extends AbstractExternalSOPTest {
|
||||||
.data(bobKey)
|
.data(bobKey)
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
assertFalse(arrayStartsWith(dearmored, BEGIN_PGP_PRIVATE_KEY_BLOCK_BYTES));
|
assertFalse(arrayStartsWith(dearmored, BEGIN_PGP_PRIVATE_KEY_BLOCK));
|
||||||
|
|
||||||
byte[] armored = sop.armor()
|
byte[] armored = sop.armor()
|
||||||
.data(dearmored)
|
.data(dearmored)
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
assertArrayStartsWith(armored, BEGIN_PGP_PRIVATE_KEY_BLOCK_BYTES);
|
assertArrayStartsWith(armored, BEGIN_PGP_PRIVATE_KEY_BLOCK);
|
||||||
assertAsciiArmorEquals(bobKey, armored);
|
assertArrayEndsWithIgnoreNewlines(armored, END_PGP_PRIVATE_KEY_BLOCK);
|
||||||
|
|
||||||
|
// assertAsciiArmorEquals(bobKey, armored);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
|
@ -96,14 +103,16 @@ public class ExternalArmorDearmorRoundTripTest extends AbstractExternalSOPTest {
|
||||||
.data(bobCert)
|
.data(bobCert)
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
assertFalse(arrayStartsWith(dearmored, BEGIN_PGP_PUBLIC_KEY_BLOCK_BYTES));
|
assertFalse(arrayStartsWith(dearmored, BEGIN_PGP_PUBLIC_KEY_BLOCK));
|
||||||
|
|
||||||
byte[] armored = sop.armor()
|
byte[] armored = sop.armor()
|
||||||
.data(dearmored)
|
.data(dearmored)
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
assertArrayStartsWith(armored, BEGIN_PGP_PUBLIC_KEY_BLOCK_BYTES);
|
assertArrayStartsWith(armored, BEGIN_PGP_PUBLIC_KEY_BLOCK);
|
||||||
assertAsciiArmorEquals(bobCert, armored);
|
assertArrayEndsWithIgnoreNewlines(armored, END_PGP_PUBLIC_KEY_BLOCK);
|
||||||
|
|
||||||
|
// assertAsciiArmorEquals(bobCert, armored);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
|
@ -115,14 +124,16 @@ public class ExternalArmorDearmorRoundTripTest extends AbstractExternalSOPTest {
|
||||||
.data(carolKey)
|
.data(carolKey)
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
assertFalse(arrayStartsWith(dearmored, BEGIN_PGP_PRIVATE_KEY_BLOCK_BYTES));
|
assertFalse(arrayStartsWith(dearmored, BEGIN_PGP_PRIVATE_KEY_BLOCK));
|
||||||
|
|
||||||
byte[] armored = sop.armor()
|
byte[] armored = sop.armor()
|
||||||
.data(dearmored)
|
.data(dearmored)
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
assertArrayStartsWith(armored, BEGIN_PGP_PRIVATE_KEY_BLOCK_BYTES);
|
assertArrayStartsWith(armored, BEGIN_PGP_PRIVATE_KEY_BLOCK);
|
||||||
assertAsciiArmorEquals(carolKey, armored);
|
assertArrayEndsWithIgnoreNewlines(armored, END_PGP_PRIVATE_KEY_BLOCK);
|
||||||
|
|
||||||
|
// assertAsciiArmorEquals(carolKey, armored);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
|
@ -134,14 +145,16 @@ public class ExternalArmorDearmorRoundTripTest extends AbstractExternalSOPTest {
|
||||||
.data(carolCert)
|
.data(carolCert)
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
assertFalse(arrayStartsWith(dearmored, BEGIN_PGP_PUBLIC_KEY_BLOCK_BYTES));
|
assertFalse(arrayStartsWith(dearmored, BEGIN_PGP_PUBLIC_KEY_BLOCK));
|
||||||
|
|
||||||
byte[] armored = sop.armor()
|
byte[] armored = sop.armor()
|
||||||
.data(dearmored)
|
.data(dearmored)
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
assertArrayStartsWith(armored, BEGIN_PGP_PUBLIC_KEY_BLOCK_BYTES);
|
assertArrayStartsWith(armored, BEGIN_PGP_PUBLIC_KEY_BLOCK);
|
||||||
assertAsciiArmorEquals(carolCert, armored);
|
assertArrayEndsWithIgnoreNewlines(armored, END_PGP_PUBLIC_KEY_BLOCK);
|
||||||
|
|
||||||
|
// assertAsciiArmorEquals(carolCert, armored);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
|
@ -159,14 +172,16 @@ public class ExternalArmorDearmorRoundTripTest extends AbstractExternalSOPTest {
|
||||||
.data(message)
|
.data(message)
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
assertFalse(arrayStartsWith(dearmored, BEGIN_PGP_MESSAGE_BYTES));
|
assertFalse(arrayStartsWith(dearmored, BEGIN_PGP_MESSAGE));
|
||||||
|
|
||||||
byte[] armored = sop.armor()
|
byte[] armored = sop.armor()
|
||||||
.data(dearmored)
|
.data(dearmored)
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
assertArrayStartsWith(armored, BEGIN_PGP_MESSAGE_BYTES);
|
assertArrayStartsWith(armored, BEGIN_PGP_MESSAGE);
|
||||||
assertAsciiArmorEquals(message, armored);
|
assertArrayEndsWithIgnoreNewlines(armored, END_PGP_MESSAGE);
|
||||||
|
|
||||||
|
// assertAsciiArmorEquals(message, armored);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
|
@ -185,13 +200,15 @@ public class ExternalArmorDearmorRoundTripTest extends AbstractExternalSOPTest {
|
||||||
.data(signature)
|
.data(signature)
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
assertFalse(arrayStartsWith(dearmored, BEGIN_PGP_SIGNATURE_BYTES));
|
assertFalse(arrayStartsWith(dearmored, BEGIN_PGP_SIGNATURE));
|
||||||
|
|
||||||
byte[] armored = sop.armor()
|
byte[] armored = sop.armor()
|
||||||
.data(dearmored)
|
.data(dearmored)
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
assertArrayStartsWith(armored, BEGIN_PGP_SIGNATURE_BYTES);
|
assertArrayStartsWith(armored, BEGIN_PGP_SIGNATURE);
|
||||||
|
assertArrayEndsWithIgnoreNewlines(armored, END_PGP_SIGNATURE);
|
||||||
|
|
||||||
assertAsciiArmorEquals(signature, armored);
|
assertAsciiArmorEquals(signature, armored);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,8 @@ import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
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")
|
@EnabledIf("sop.external.AbstractExternalSOPTest#hasBackends")
|
||||||
public class ExternalDecryptWithSessionKeyTest extends AbstractExternalSOPTest {
|
public class ExternalDecryptWithSessionKeyTest extends AbstractExternalSOPTest {
|
||||||
|
@ -35,13 +37,13 @@ public class ExternalDecryptWithSessionKeyTest extends AbstractExternalSOPTest {
|
||||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||||
public void testDecryptAndExtractSessionKey(SOP sop) throws IOException {
|
public void testDecryptAndExtractSessionKey(SOP sop) throws IOException {
|
||||||
ByteArrayAndResult<DecryptionResult> bytesAndResult = sop.decrypt()
|
ByteArrayAndResult<DecryptionResult> bytesAndResult = sop.decrypt()
|
||||||
.withKey(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
.withKey(ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||||
.ciphertext(CIPHERTEXT.getBytes(StandardCharsets.UTF_8))
|
.ciphertext(CIPHERTEXT.getBytes(StandardCharsets.UTF_8))
|
||||||
.toByteArrayAndResult();
|
.toByteArrayAndResult();
|
||||||
|
|
||||||
assertEquals(SESSION_KEY, bytesAndResult.getResult().getSessionKey().get().toString());
|
assertEquals(SESSION_KEY, bytesAndResult.getResult().getSessionKey().get().toString());
|
||||||
|
|
||||||
assertArrayEquals("Hello, World!\n".getBytes(StandardCharsets.UTF_8), bytesAndResult.getBytes());
|
assertArrayEquals(PLAINTEXT.getBytes(StandardCharsets.UTF_8), bytesAndResult.getBytes());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
|
@ -53,6 +55,6 @@ public class ExternalDecryptWithSessionKeyTest extends AbstractExternalSOPTest {
|
||||||
.toByteArrayAndResult()
|
.toByteArrayAndResult()
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
assertArrayEquals("Hello, World!\n".getBytes(StandardCharsets.UTF_8), decrypted);
|
assertArrayEquals(PLAINTEXT.getBytes(StandardCharsets.UTF_8), decrypted);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,127 +19,143 @@ import java.util.List;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static sop.external.JUtils.assertArrayStartsWith;
|
import static sop.testing.JUtils.assertArrayStartsWith;
|
||||||
import static sop.external.JUtils.assertSignedBy;
|
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")
|
@EnabledIf("sop.external.AbstractExternalSOPTest#hasBackends")
|
||||||
public class ExternalDetachedSignVerifyRoundTripTest extends AbstractExternalSOPTest {
|
public class ExternalDetachedSignVerifyRoundTripTest extends AbstractExternalSOPTest {
|
||||||
|
|
||||||
private static final String BEGIN_PGP_SIGNATURE = "-----BEGIN PGP SIGNATURE-----\n";
|
|
||||||
private static final byte[] BEGIN_PGP_SIGNATURE_BYTES = BEGIN_PGP_SIGNATURE.getBytes(StandardCharsets.UTF_8);
|
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||||
public void signVerifyWithAliceKey(SOP sop) throws IOException {
|
public void signVerifyWithAliceKey(SOP sop) throws IOException {
|
||||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
byte[] message = PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||||
|
|
||||||
byte[] signature = sop.detachedSign()
|
byte[] signature = sop.detachedSign()
|
||||||
.key(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
.key(ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||||
.data(message)
|
.data(message)
|
||||||
.toByteArrayAndResult()
|
.toByteArrayAndResult()
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
List<Verification> verificationList = sop.detachedVerify()
|
List<Verification> verificationList = sop.detachedVerify()
|
||||||
.cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
.cert(ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||||
.signatures(signature)
|
.signatures(signature)
|
||||||
.data(message);
|
.data(message);
|
||||||
|
|
||||||
assertFalse(verificationList.isEmpty());
|
assertFalse(verificationList.isEmpty());
|
||||||
assertSignedBy(verificationList, TestData.ALICE_SIGNING_FINGERPRINT, TestData.ALICE_PRIMARY_FINGERPRINT);
|
assertSignedBy(verificationList, ALICE_SIGNING_FINGERPRINT, ALICE_PRIMARY_FINGERPRINT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||||
public void signVerifyTextModeWithAliceKey(SOP sop) throws IOException {
|
public void signVerifyTextModeWithAliceKey(SOP sop) throws IOException {
|
||||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
byte[] message = PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||||
|
|
||||||
byte[] signature = sop.detachedSign()
|
byte[] signature = sop.detachedSign()
|
||||||
.key(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
.key(ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||||
.mode(SignAs.Text)
|
.mode(SignAs.Text)
|
||||||
.data(message)
|
.data(message)
|
||||||
.toByteArrayAndResult()
|
.toByteArrayAndResult()
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
List<Verification> verificationList = sop.detachedVerify()
|
List<Verification> verificationList = sop.detachedVerify()
|
||||||
.cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
.cert(ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||||
.signatures(signature)
|
.signatures(signature)
|
||||||
.data(message);
|
.data(message);
|
||||||
|
|
||||||
assertFalse(verificationList.isEmpty());
|
assertFalse(verificationList.isEmpty());
|
||||||
assertSignedBy(verificationList, TestData.ALICE_SIGNING_FINGERPRINT, TestData.ALICE_PRIMARY_FINGERPRINT);
|
assertSignedBy(verificationList, ALICE_SIGNING_FINGERPRINT, ALICE_PRIMARY_FINGERPRINT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||||
public void verifyKnownMessageWithAliceCert(SOP sop) throws IOException {
|
public void verifyKnownMessageWithAliceCert(SOP sop) throws IOException {
|
||||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
byte[] message = PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||||
byte[] signature = TestData.ALICE_DETACHED_SIGNED_MESSAGE.getBytes(StandardCharsets.UTF_8);
|
byte[] signature = ALICE_DETACHED_SIGNED_MESSAGE.getBytes(StandardCharsets.UTF_8);
|
||||||
|
|
||||||
List<Verification> verificationList = sop.detachedVerify()
|
List<Verification> verificationList = sop.detachedVerify()
|
||||||
.cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
.cert(ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||||
.signatures(signature)
|
.signatures(signature)
|
||||||
.data(message);
|
.data(message);
|
||||||
|
|
||||||
assertFalse(verificationList.isEmpty());
|
assertFalse(verificationList.isEmpty());
|
||||||
assertSignedBy(verificationList, TestData.ALICE_SIGNING_FINGERPRINT, TestData.ALICE_PRIMARY_FINGERPRINT, TestData.ALICE_DETACHED_SIGNED_MESSAGE_DATE);
|
assertSignedBy(verificationList, ALICE_SIGNING_FINGERPRINT, ALICE_PRIMARY_FINGERPRINT, ALICE_DETACHED_SIGNED_MESSAGE_DATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||||
public void signVerifyWithBobKey(SOP sop) throws IOException {
|
public void signVerifyWithBobKey(SOP sop) throws IOException {
|
||||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
byte[] message = PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||||
|
|
||||||
byte[] signature = sop.detachedSign()
|
byte[] signature = sop.detachedSign()
|
||||||
.key(TestData.BOB_KEY.getBytes(StandardCharsets.UTF_8))
|
.key(BOB_KEY.getBytes(StandardCharsets.UTF_8))
|
||||||
.data(message)
|
.data(message)
|
||||||
.toByteArrayAndResult()
|
.toByteArrayAndResult()
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
List<Verification> verificationList = sop.detachedVerify()
|
List<Verification> verificationList = sop.detachedVerify()
|
||||||
.cert(TestData.BOB_CERT.getBytes(StandardCharsets.UTF_8))
|
.cert(BOB_CERT.getBytes(StandardCharsets.UTF_8))
|
||||||
.signatures(signature)
|
.signatures(signature)
|
||||||
.data(message);
|
.data(message);
|
||||||
|
|
||||||
assertFalse(verificationList.isEmpty());
|
assertFalse(verificationList.isEmpty());
|
||||||
assertSignedBy(verificationList, TestData.BOB_SIGNING_FINGERPRINT, TestData.BOB_PRIMARY_FINGERPRINT);
|
assertSignedBy(verificationList, BOB_SIGNING_FINGERPRINT, BOB_PRIMARY_FINGERPRINT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||||
public void signVerifyWithCarolKey(SOP sop) throws IOException {
|
public void signVerifyWithCarolKey(SOP sop) throws IOException {
|
||||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
byte[] message = PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||||
|
|
||||||
byte[] signature = sop.detachedSign()
|
byte[] signature = sop.detachedSign()
|
||||||
.key(TestData.CAROL_KEY.getBytes(StandardCharsets.UTF_8))
|
.key(CAROL_KEY.getBytes(StandardCharsets.UTF_8))
|
||||||
.data(message)
|
.data(message)
|
||||||
.toByteArrayAndResult()
|
.toByteArrayAndResult()
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
List<Verification> verificationList = sop.detachedVerify()
|
List<Verification> verificationList = sop.detachedVerify()
|
||||||
.cert(TestData.CAROL_CERT.getBytes(StandardCharsets.UTF_8))
|
.cert(CAROL_CERT.getBytes(StandardCharsets.UTF_8))
|
||||||
.signatures(signature)
|
.signatures(signature)
|
||||||
.data(message);
|
.data(message);
|
||||||
|
|
||||||
assertFalse(verificationList.isEmpty());
|
assertFalse(verificationList.isEmpty());
|
||||||
assertSignedBy(verificationList, TestData.CAROL_SIGNING_FINGERPRINT, TestData.CAROL_PRIMARY_FINGERPRINT);
|
assertSignedBy(verificationList, CAROL_SIGNING_FINGERPRINT, CAROL_PRIMARY_FINGERPRINT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||||
public void signVerifyWithEncryptedKey(SOP sop) throws IOException {
|
public void signVerifyWithEncryptedKey(SOP sop) throws IOException {
|
||||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
byte[] message = PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||||
|
|
||||||
byte[] signature = sop.detachedSign()
|
byte[] signature = sop.detachedSign()
|
||||||
.key(TestData.PASSWORD_PROTECTED_KEY.getBytes(StandardCharsets.UTF_8))
|
.key(PASSWORD_PROTECTED_KEY.getBytes(StandardCharsets.UTF_8))
|
||||||
.withKeyPassword(TestData.PASSWORD)
|
.withKeyPassword(PASSWORD)
|
||||||
.data(message)
|
.data(message)
|
||||||
.toByteArrayAndResult()
|
.toByteArrayAndResult()
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
assertArrayStartsWith(signature, BEGIN_PGP_SIGNATURE_BYTES);
|
assertArrayStartsWith(signature, BEGIN_PGP_SIGNATURE);
|
||||||
|
|
||||||
List<Verification> verificationList = sop.detachedVerify()
|
List<Verification> verificationList = sop.detachedVerify()
|
||||||
.cert(TestData.PASSWORD_PROTECTED_CERT.getBytes(StandardCharsets.UTF_8))
|
.cert(PASSWORD_PROTECTED_CERT.getBytes(StandardCharsets.UTF_8))
|
||||||
.signatures(signature)
|
.signatures(signature)
|
||||||
.data(message);
|
.data(message);
|
||||||
|
|
||||||
|
@ -149,10 +165,10 @@ public class ExternalDetachedSignVerifyRoundTripTest extends AbstractExternalSOP
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||||
public void signArmorVerifyWithBobKey(SOP sop) throws IOException {
|
public void signArmorVerifyWithBobKey(SOP sop) throws IOException {
|
||||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
byte[] message = PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||||
|
|
||||||
byte[] signature = sop.detachedSign()
|
byte[] signature = sop.detachedSign()
|
||||||
.key(TestData.BOB_KEY.getBytes(StandardCharsets.UTF_8))
|
.key(BOB_KEY.getBytes(StandardCharsets.UTF_8))
|
||||||
.noArmor()
|
.noArmor()
|
||||||
.data(message)
|
.data(message)
|
||||||
.toByteArrayAndResult()
|
.toByteArrayAndResult()
|
||||||
|
@ -163,24 +179,23 @@ public class ExternalDetachedSignVerifyRoundTripTest extends AbstractExternalSOP
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
List<Verification> verificationList = sop.detachedVerify()
|
List<Verification> verificationList = sop.detachedVerify()
|
||||||
.cert(TestData.BOB_CERT.getBytes(StandardCharsets.UTF_8))
|
.cert(BOB_CERT.getBytes(StandardCharsets.UTF_8))
|
||||||
.signatures(armored)
|
.signatures(armored)
|
||||||
.data(message);
|
.data(message);
|
||||||
|
|
||||||
assertFalse(verificationList.isEmpty());
|
assertFalse(verificationList.isEmpty());
|
||||||
assertSignedBy(verificationList, TestData.BOB_SIGNING_FINGERPRINT, TestData.BOB_PRIMARY_FINGERPRINT);
|
assertSignedBy(verificationList, BOB_SIGNING_FINGERPRINT, BOB_PRIMARY_FINGERPRINT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||||
public void verifyNotAfterThrowsNoSignature(SOP sop) {
|
public void verifyNotAfterThrowsNoSignature(SOP sop) {
|
||||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
byte[] message = PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||||
byte[] signature = TestData.ALICE_DETACHED_SIGNED_MESSAGE.getBytes(StandardCharsets.UTF_8);
|
byte[] signature = ALICE_DETACHED_SIGNED_MESSAGE.getBytes(StandardCharsets.UTF_8);
|
||||||
Date signatureDate = TestData.ALICE_DETACHED_SIGNED_MESSAGE_DATE;
|
Date beforeSignature = new Date(ALICE_DETACHED_SIGNED_MESSAGE_DATE.getTime() - 1000); // 1 sec before sig
|
||||||
Date beforeSignature = new Date(signatureDate.getTime() - 1000); // 1 sec before sig
|
|
||||||
|
|
||||||
assertThrows(SOPGPException.NoSignature.class, () -> sop.detachedVerify()
|
assertThrows(SOPGPException.NoSignature.class, () -> sop.detachedVerify()
|
||||||
.cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
.cert(ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||||
.notAfter(beforeSignature)
|
.notAfter(beforeSignature)
|
||||||
.signatures(signature)
|
.signatures(signature)
|
||||||
.data(message));
|
.data(message));
|
||||||
|
@ -189,13 +204,12 @@ public class ExternalDetachedSignVerifyRoundTripTest extends AbstractExternalSOP
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||||
public void verifyNotBeforeThrowsNoSignature(SOP sop) {
|
public void verifyNotBeforeThrowsNoSignature(SOP sop) {
|
||||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
byte[] message = PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||||
byte[] signature = TestData.ALICE_DETACHED_SIGNED_MESSAGE.getBytes(StandardCharsets.UTF_8);
|
byte[] signature = ALICE_DETACHED_SIGNED_MESSAGE.getBytes(StandardCharsets.UTF_8);
|
||||||
Date signatureDate = TestData.ALICE_DETACHED_SIGNED_MESSAGE_DATE;
|
Date afterSignature = new Date(ALICE_DETACHED_SIGNED_MESSAGE_DATE.getTime() + 1000); // 1 sec after sig
|
||||||
Date afterSignature = new Date(signatureDate.getTime() + 1000); // 1 sec after sig
|
|
||||||
|
|
||||||
assertThrows(SOPGPException.NoSignature.class, () -> sop.detachedVerify()
|
assertThrows(SOPGPException.NoSignature.class, () -> sop.detachedVerify()
|
||||||
.cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
.cert(ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||||
.notBefore(afterSignature)
|
.notBefore(afterSignature)
|
||||||
.signatures(signature)
|
.signatures(signature)
|
||||||
.data(message));
|
.data(message));
|
||||||
|
@ -207,8 +221,8 @@ public class ExternalDetachedSignVerifyRoundTripTest extends AbstractExternalSOP
|
||||||
public void signVerifyWithEncryptedKeyWithoutPassphraseFails(SOP sop) {
|
public void signVerifyWithEncryptedKeyWithoutPassphraseFails(SOP sop) {
|
||||||
assertThrows(SOPGPException.KeyIsProtected.class, () ->
|
assertThrows(SOPGPException.KeyIsProtected.class, () ->
|
||||||
sop.detachedSign()
|
sop.detachedSign()
|
||||||
.key(TestData.PASSWORD_PROTECTED_KEY.getBytes(StandardCharsets.UTF_8))
|
.key(PASSWORD_PROTECTED_KEY.getBytes(StandardCharsets.UTF_8))
|
||||||
.data(TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8))
|
.data(PLAINTEXT.getBytes(StandardCharsets.UTF_8))
|
||||||
.toByteArrayAndResult()
|
.toByteArrayAndResult()
|
||||||
.getBytes());
|
.getBytes());
|
||||||
}
|
}
|
||||||
|
@ -217,19 +231,19 @@ public class ExternalDetachedSignVerifyRoundTripTest extends AbstractExternalSOP
|
||||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||||
public void signWithProtectedKeyAndMultiplePassphrasesTest(SOP sop)
|
public void signWithProtectedKeyAndMultiplePassphrasesTest(SOP sop)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
byte[] message = PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||||
|
|
||||||
byte[] signature = sop.sign()
|
byte[] signature = sop.sign()
|
||||||
.key(TestData.PASSWORD_PROTECTED_KEY.getBytes(StandardCharsets.UTF_8))
|
.key(PASSWORD_PROTECTED_KEY.getBytes(StandardCharsets.UTF_8))
|
||||||
.withKeyPassword("wrong")
|
.withKeyPassword("wrong")
|
||||||
.withKeyPassword(TestData.PASSWORD) // correct
|
.withKeyPassword(PASSWORD) // correct
|
||||||
.withKeyPassword("wrong2")
|
.withKeyPassword("wrong2")
|
||||||
.data(message)
|
.data(message)
|
||||||
.toByteArrayAndResult()
|
.toByteArrayAndResult()
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
assertFalse(sop.verify()
|
assertFalse(sop.verify()
|
||||||
.cert(TestData.PASSWORD_PROTECTED_CERT.getBytes(StandardCharsets.UTF_8))
|
.cert(PASSWORD_PROTECTED_CERT.getBytes(StandardCharsets.UTF_8))
|
||||||
.signatures(signature)
|
.signatures(signature)
|
||||||
.data(message)
|
.data(message)
|
||||||
.isEmpty());
|
.isEmpty());
|
||||||
|
@ -238,11 +252,11 @@ public class ExternalDetachedSignVerifyRoundTripTest extends AbstractExternalSOP
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||||
public void verifyMissingCertCausesMissingArg(SOP sop) {
|
public void verifyMissingCertCausesMissingArg(SOP sop) {
|
||||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
byte[] message = PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||||
|
|
||||||
assertThrows(SOPGPException.MissingArg.class, () ->
|
assertThrows(SOPGPException.MissingArg.class, () ->
|
||||||
sop.verify()
|
sop.verify()
|
||||||
.signatures(TestData.ALICE_DETACHED_SIGNED_MESSAGE.getBytes(StandardCharsets.UTF_8))
|
.signatures(ALICE_DETACHED_SIGNED_MESSAGE.getBytes(StandardCharsets.UTF_8))
|
||||||
.data(message));
|
.data(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,16 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
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")
|
@EnabledIf("sop.external.AbstractExternalSOPTest#hasBackends")
|
||||||
public class ExternalEncryptDecryptRoundTripTest extends AbstractExternalSOPTest {
|
public class ExternalEncryptDecryptRoundTripTest extends AbstractExternalSOPTest {
|
||||||
|
@ -33,7 +42,7 @@ public class ExternalEncryptDecryptRoundTripTest extends AbstractExternalSOPTest
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||||
public void encryptDecryptRoundTripPasswordTest(SOP sop) throws IOException {
|
public void encryptDecryptRoundTripPasswordTest(SOP sop) throws IOException {
|
||||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
byte[] message = PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||||
byte[] ciphertext = sop.encrypt()
|
byte[] ciphertext = sop.encrypt()
|
||||||
.withPassword("sw0rdf1sh")
|
.withPassword("sw0rdf1sh")
|
||||||
.plaintext(message)
|
.plaintext(message)
|
||||||
|
@ -51,14 +60,14 @@ public class ExternalEncryptDecryptRoundTripTest extends AbstractExternalSOPTest
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||||
public void encryptDecryptRoundTripAliceTest(SOP sop) throws IOException {
|
public void encryptDecryptRoundTripAliceTest(SOP sop) throws IOException {
|
||||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
byte[] message = PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||||
byte[] ciphertext = sop.encrypt()
|
byte[] ciphertext = sop.encrypt()
|
||||||
.withCert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
.withCert(ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||||
.plaintext(message)
|
.plaintext(message)
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
ByteArrayAndResult<DecryptionResult> bytesAndResult = sop.decrypt()
|
ByteArrayAndResult<DecryptionResult> bytesAndResult = sop.decrypt()
|
||||||
.withKey(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
.withKey(ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||||
.ciphertext(ciphertext)
|
.ciphertext(ciphertext)
|
||||||
.toByteArrayAndResult();
|
.toByteArrayAndResult();
|
||||||
|
|
||||||
|
@ -72,14 +81,14 @@ public class ExternalEncryptDecryptRoundTripTest extends AbstractExternalSOPTest
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||||
public void encryptDecryptRoundTripBobTest(SOP sop) throws IOException {
|
public void encryptDecryptRoundTripBobTest(SOP sop) throws IOException {
|
||||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
byte[] message = PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||||
byte[] ciphertext = sop.encrypt()
|
byte[] ciphertext = sop.encrypt()
|
||||||
.withCert(TestData.BOB_CERT.getBytes(StandardCharsets.UTF_8))
|
.withCert(BOB_CERT.getBytes(StandardCharsets.UTF_8))
|
||||||
.plaintext(message)
|
.plaintext(message)
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
byte[] plaintext = sop.decrypt()
|
byte[] plaintext = sop.decrypt()
|
||||||
.withKey(TestData.BOB_KEY.getBytes(StandardCharsets.UTF_8))
|
.withKey(BOB_KEY.getBytes(StandardCharsets.UTF_8))
|
||||||
.ciphertext(ciphertext)
|
.ciphertext(ciphertext)
|
||||||
.toByteArrayAndResult()
|
.toByteArrayAndResult()
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
@ -90,14 +99,14 @@ public class ExternalEncryptDecryptRoundTripTest extends AbstractExternalSOPTest
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||||
public void encryptDecryptRoundTripCarolTest(SOP sop) throws IOException {
|
public void encryptDecryptRoundTripCarolTest(SOP sop) throws IOException {
|
||||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
byte[] message = PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||||
byte[] ciphertext = sop.encrypt()
|
byte[] ciphertext = sop.encrypt()
|
||||||
.withCert(TestData.CAROL_CERT.getBytes(StandardCharsets.UTF_8))
|
.withCert(CAROL_CERT.getBytes(StandardCharsets.UTF_8))
|
||||||
.plaintext(message)
|
.plaintext(message)
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
byte[] plaintext = sop.decrypt()
|
byte[] plaintext = sop.decrypt()
|
||||||
.withKey(TestData.CAROL_KEY.getBytes(StandardCharsets.UTF_8))
|
.withKey(CAROL_KEY.getBytes(StandardCharsets.UTF_8))
|
||||||
.ciphertext(ciphertext)
|
.ciphertext(ciphertext)
|
||||||
.toByteArrayAndResult()
|
.toByteArrayAndResult()
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
@ -108,9 +117,9 @@ public class ExternalEncryptDecryptRoundTripTest extends AbstractExternalSOPTest
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||||
public void encryptNoArmorThenArmorThenDecryptRoundTrip(SOP sop) throws IOException {
|
public void encryptNoArmorThenArmorThenDecryptRoundTrip(SOP sop) throws IOException {
|
||||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
byte[] message = PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||||
byte[] ciphertext = sop.encrypt()
|
byte[] ciphertext = sop.encrypt()
|
||||||
.withCert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
.withCert(ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||||
.noArmor()
|
.noArmor()
|
||||||
.plaintext(message)
|
.plaintext(message)
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
@ -120,7 +129,7 @@ public class ExternalEncryptDecryptRoundTripTest extends AbstractExternalSOPTest
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
ByteArrayAndResult<DecryptionResult> bytesAndResult = sop.decrypt()
|
ByteArrayAndResult<DecryptionResult> bytesAndResult = sop.decrypt()
|
||||||
.withKey(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
.withKey(ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||||
.ciphertext(armored)
|
.ciphertext(armored)
|
||||||
.toByteArrayAndResult();
|
.toByteArrayAndResult();
|
||||||
|
|
||||||
|
@ -131,16 +140,16 @@ public class ExternalEncryptDecryptRoundTripTest extends AbstractExternalSOPTest
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||||
public void encryptSignDecryptVerifyRoundTripAliceTest(SOP sop) throws IOException {
|
public void encryptSignDecryptVerifyRoundTripAliceTest(SOP sop) throws IOException {
|
||||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
byte[] message = PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||||
byte[] ciphertext = sop.encrypt()
|
byte[] ciphertext = sop.encrypt()
|
||||||
.withCert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
.withCert(ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||||
.signWith(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
.signWith(ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||||
.plaintext(message)
|
.plaintext(message)
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
ByteArrayAndResult<DecryptionResult> bytesAndResult = sop.decrypt()
|
ByteArrayAndResult<DecryptionResult> bytesAndResult = sop.decrypt()
|
||||||
.withKey(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
.withKey(ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||||
.verifyWithCert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
.verifyWithCert(ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||||
.ciphertext(ciphertext)
|
.ciphertext(ciphertext)
|
||||||
.toByteArrayAndResult();
|
.toByteArrayAndResult();
|
||||||
|
|
||||||
|
@ -151,23 +160,23 @@ public class ExternalEncryptDecryptRoundTripTest extends AbstractExternalSOPTest
|
||||||
assertNotNull(result.getSessionKey().get());
|
assertNotNull(result.getSessionKey().get());
|
||||||
List<Verification> verificationList = result.getVerifications();
|
List<Verification> verificationList = result.getVerifications();
|
||||||
assertEquals(1, verificationList.size());
|
assertEquals(1, verificationList.size());
|
||||||
assertTrue(verificationList.get(0).toString().contains("EB85BB5FA33A75E15E944E63F231550C4F47E38E EB85BB5FA33A75E15E944E63F231550C4F47E38E"));
|
assertSignedBy(verificationList, ALICE_SIGNING_FINGERPRINT, ALICE_PRIMARY_FINGERPRINT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||||
public void encryptSignAsTextDecryptVerifyRoundTripAliceTest(SOP sop) throws IOException {
|
public void encryptSignAsTextDecryptVerifyRoundTripAliceTest(SOP sop) throws IOException {
|
||||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
byte[] message = PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||||
byte[] ciphertext = sop.encrypt()
|
byte[] ciphertext = sop.encrypt()
|
||||||
.withCert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
.withCert(ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||||
.signWith(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
.signWith(ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||||
.mode(EncryptAs.Text)
|
.mode(EncryptAs.Text)
|
||||||
.plaintext(message)
|
.plaintext(message)
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
ByteArrayAndResult<DecryptionResult> bytesAndResult = sop.decrypt()
|
ByteArrayAndResult<DecryptionResult> bytesAndResult = sop.decrypt()
|
||||||
.withKey(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
.withKey(ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||||
.verifyWithCert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
.verifyWithCert(ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||||
.ciphertext(ciphertext)
|
.ciphertext(ciphertext)
|
||||||
.toByteArrayAndResult();
|
.toByteArrayAndResult();
|
||||||
|
|
||||||
|
@ -178,7 +187,7 @@ public class ExternalEncryptDecryptRoundTripTest extends AbstractExternalSOPTest
|
||||||
assertNotNull(result.getSessionKey().get());
|
assertNotNull(result.getSessionKey().get());
|
||||||
List<Verification> verificationList = result.getVerifications();
|
List<Verification> verificationList = result.getVerifications();
|
||||||
assertEquals(1, verificationList.size());
|
assertEquals(1, verificationList.size());
|
||||||
assertTrue(verificationList.get(0).toString().contains("EB85BB5FA33A75E15E944E63F231550C4F47E38E EB85BB5FA33A75E15E944E63F231550C4F47E38E"));
|
assertSignedBy(verificationList, ALICE_SIGNING_FINGERPRINT, ALICE_PRIMARY_FINGERPRINT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
|
@ -234,8 +243,8 @@ public class ExternalEncryptDecryptRoundTripTest extends AbstractExternalSOPTest
|
||||||
|
|
||||||
assertThrows(SOPGPException.NoSignature.class, () -> {
|
assertThrows(SOPGPException.NoSignature.class, () -> {
|
||||||
ByteArrayAndResult<DecryptionResult> bytesAndResult = sop.decrypt()
|
ByteArrayAndResult<DecryptionResult> bytesAndResult = sop.decrypt()
|
||||||
.withKey(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
.withKey(ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||||
.verifyWithCert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
.verifyWithCert(ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||||
.verifyNotAfter(beforeSignature)
|
.verifyNotAfter(beforeSignature)
|
||||||
.ciphertext(message)
|
.ciphertext(message)
|
||||||
.toByteArrayAndResult();
|
.toByteArrayAndResult();
|
||||||
|
@ -267,8 +276,8 @@ public class ExternalEncryptDecryptRoundTripTest extends AbstractExternalSOPTest
|
||||||
|
|
||||||
assertThrows(SOPGPException.NoSignature.class, () -> {
|
assertThrows(SOPGPException.NoSignature.class, () -> {
|
||||||
ByteArrayAndResult<DecryptionResult> bytesAndResult = sop.decrypt()
|
ByteArrayAndResult<DecryptionResult> bytesAndResult = sop.decrypt()
|
||||||
.withKey(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
.withKey(ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||||
.verifyWithCert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
.verifyWithCert(ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||||
.verifyNotBefore(afterSignature)
|
.verifyNotBefore(afterSignature)
|
||||||
.ciphertext(message)
|
.ciphertext(message)
|
||||||
.toByteArrayAndResult();
|
.toByteArrayAndResult();
|
||||||
|
@ -282,7 +291,7 @@ public class ExternalEncryptDecryptRoundTripTest extends AbstractExternalSOPTest
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||||
public void missingArgsTest(SOP sop) {
|
public void missingArgsTest(SOP sop) {
|
||||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
byte[] message = PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||||
|
|
||||||
assertThrows(SOPGPException.MissingArg.class, () -> sop.encrypt()
|
assertThrows(SOPGPException.MissingArg.class, () -> sop.encrypt()
|
||||||
.plaintext(message)
|
.plaintext(message)
|
||||||
|
|
|
@ -8,22 +8,23 @@ import org.junit.jupiter.api.condition.EnabledIf;
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
import org.junit.jupiter.params.provider.MethodSource;
|
import org.junit.jupiter.params.provider.MethodSource;
|
||||||
import sop.SOP;
|
import sop.SOP;
|
||||||
|
import sop.testing.TestData;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static sop.external.JUtils.arrayStartsWith;
|
import static sop.testing.JUtils.arrayStartsWith;
|
||||||
import static sop.external.JUtils.assertArrayStartsWith;
|
import static sop.testing.JUtils.assertArrayEndsWithIgnoreNewlines;
|
||||||
import static sop.external.JUtils.assertAsciiArmorEquals;
|
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")
|
@EnabledIf("sop.external.AbstractExternalSOPTest#hasBackends")
|
||||||
public class ExternalExtractCertTest extends AbstractExternalSOPTest {
|
public class ExternalExtractCertTest extends AbstractExternalSOPTest {
|
||||||
|
|
||||||
private static final String BEGIN_PGP_PUBLIC_KEY_BLOCK = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n";
|
|
||||||
private static final byte[] BEGIN_PGP_PUBLIC_KEY_BLOCK_BYTES = BEGIN_PGP_PUBLIC_KEY_BLOCK.getBytes(StandardCharsets.UTF_8);
|
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||||
public void extractArmoredCertFromArmoredKeyTest(SOP sop) throws IOException {
|
public void extractArmoredCertFromArmoredKeyTest(SOP sop) throws IOException {
|
||||||
|
@ -33,7 +34,8 @@ public class ExternalExtractCertTest extends AbstractExternalSOPTest {
|
||||||
.getInputStream();
|
.getInputStream();
|
||||||
|
|
||||||
byte[] cert = sop.extractCert().key(keyIn).getBytes();
|
byte[] cert = sop.extractCert().key(keyIn).getBytes();
|
||||||
assertArrayStartsWith(cert, BEGIN_PGP_PUBLIC_KEY_BLOCK_BYTES);
|
assertArrayStartsWith(cert, BEGIN_PGP_PUBLIC_KEY_BLOCK);
|
||||||
|
assertArrayEndsWithIgnoreNewlines(cert, END_PGP_PUBLIC_KEY_BLOCK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
|
@ -76,7 +78,7 @@ public class ExternalExtractCertTest extends AbstractExternalSOPTest {
|
||||||
.key(keyIn)
|
.key(keyIn)
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
assertFalse(arrayStartsWith(cert, BEGIN_PGP_PUBLIC_KEY_BLOCK_BYTES));
|
assertFalse(arrayStartsWith(cert, BEGIN_PGP_PUBLIC_KEY_BLOCK));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
|
@ -92,7 +94,8 @@ public class ExternalExtractCertTest extends AbstractExternalSOPTest {
|
||||||
.key(keyIn)
|
.key(keyIn)
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
assertArrayStartsWith(cert, BEGIN_PGP_PUBLIC_KEY_BLOCK_BYTES);
|
assertArrayStartsWith(cert, BEGIN_PGP_PUBLIC_KEY_BLOCK);
|
||||||
|
assertArrayEndsWithIgnoreNewlines(cert, END_PGP_PUBLIC_KEY_BLOCK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
|
@ -109,6 +112,6 @@ public class ExternalExtractCertTest extends AbstractExternalSOPTest {
|
||||||
.key(keyIn)
|
.key(keyIn)
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
assertFalse(arrayStartsWith(cert, BEGIN_PGP_PUBLIC_KEY_BLOCK_BYTES));
|
assertFalse(arrayStartsWith(cert, BEGIN_PGP_PUBLIC_KEY_BLOCK));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,21 +8,19 @@ import org.junit.jupiter.api.condition.EnabledIf;
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
import org.junit.jupiter.params.provider.MethodSource;
|
import org.junit.jupiter.params.provider.MethodSource;
|
||||||
import sop.SOP;
|
import sop.SOP;
|
||||||
|
import sop.testing.JUtils;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.Charset;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static sop.external.JUtils.assertArrayStartsWith;
|
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")
|
@EnabledIf("sop.external.AbstractExternalSOPTest#hasBackends")
|
||||||
public class ExternalGenerateKeyTest extends AbstractExternalSOPTest {
|
public class ExternalGenerateKeyTest extends AbstractExternalSOPTest {
|
||||||
|
|
||||||
private static final Charset UTF8 = StandardCharsets.UTF_8;
|
|
||||||
private static final String BEGIN_PGP_PRIVATE_KEY_BLOCK = "-----BEGIN PGP PRIVATE KEY BLOCK-----\n";
|
|
||||||
byte[] BEGIN_PGP_PRIVATE_KEY_BLOCK_BYTES = BEGIN_PGP_PRIVATE_KEY_BLOCK.getBytes(UTF8);
|
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||||
public void generateKeyTest(SOP sop) throws IOException {
|
public void generateKeyTest(SOP sop) throws IOException {
|
||||||
|
@ -31,7 +29,8 @@ public class ExternalGenerateKeyTest extends AbstractExternalSOPTest {
|
||||||
.generate()
|
.generate()
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
assertArrayStartsWith(key, BEGIN_PGP_PRIVATE_KEY_BLOCK_BYTES);
|
assertArrayStartsWith(key, BEGIN_PGP_PRIVATE_KEY_BLOCK);
|
||||||
|
assertArrayEndsWithIgnoreNewlines(key, END_PGP_PRIVATE_KEY_BLOCK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
|
@ -43,7 +42,7 @@ public class ExternalGenerateKeyTest extends AbstractExternalSOPTest {
|
||||||
.generate()
|
.generate()
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
assertFalse(JUtils.arrayStartsWith(key, BEGIN_PGP_PRIVATE_KEY_BLOCK_BYTES));
|
assertFalse(JUtils.arrayStartsWith(key, BEGIN_PGP_PRIVATE_KEY_BLOCK));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
|
@ -55,7 +54,8 @@ public class ExternalGenerateKeyTest extends AbstractExternalSOPTest {
|
||||||
.generate()
|
.generate()
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
assertArrayStartsWith(key, BEGIN_PGP_PRIVATE_KEY_BLOCK_BYTES);
|
assertArrayStartsWith(key, BEGIN_PGP_PRIVATE_KEY_BLOCK);
|
||||||
|
assertArrayEndsWithIgnoreNewlines(key, END_PGP_PRIVATE_KEY_BLOCK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
|
@ -65,7 +65,8 @@ public class ExternalGenerateKeyTest extends AbstractExternalSOPTest {
|
||||||
.generate()
|
.generate()
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
assertArrayStartsWith(key, BEGIN_PGP_PRIVATE_KEY_BLOCK_BYTES);
|
assertArrayStartsWith(key, BEGIN_PGP_PRIVATE_KEY_BLOCK);
|
||||||
|
assertArrayEndsWithIgnoreNewlines(key, END_PGP_PRIVATE_KEY_BLOCK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
|
@ -77,7 +78,8 @@ public class ExternalGenerateKeyTest extends AbstractExternalSOPTest {
|
||||||
.generate()
|
.generate()
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
assertArrayStartsWith(key, BEGIN_PGP_PRIVATE_KEY_BLOCK_BYTES);
|
assertArrayStartsWith(key, BEGIN_PGP_PRIVATE_KEY_BLOCK);
|
||||||
|
assertArrayEndsWithIgnoreNewlines(key, END_PGP_PRIVATE_KEY_BLOCK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
|
@ -90,6 +92,7 @@ public class ExternalGenerateKeyTest extends AbstractExternalSOPTest {
|
||||||
.generate()
|
.generate()
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
assertArrayStartsWith(key, BEGIN_PGP_PRIVATE_KEY_BLOCK_BYTES);
|
assertArrayStartsWith(key, BEGIN_PGP_PRIVATE_KEY_BLOCK);
|
||||||
|
assertArrayEndsWithIgnoreNewlines(key, END_PGP_PRIVATE_KEY_BLOCK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,21 +18,23 @@ import java.util.List;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static sop.external.JUtils.arrayStartsWith;
|
import static sop.testing.JUtils.arrayStartsWith;
|
||||||
import static sop.external.JUtils.assertArrayStartsWith;
|
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")
|
@EnabledIf("sop.external.AbstractExternalSOPTest#hasBackends")
|
||||||
public class ExternalInlineSignDetachVerifyRoundTripTest extends AbstractExternalSOPTest {
|
public class ExternalInlineSignDetachVerifyRoundTripTest extends AbstractExternalSOPTest {
|
||||||
|
|
||||||
private static final byte[] BEGIN_PGP_SIGNATURE = "-----BEGIN PGP SIGNATURE-----\n".getBytes(StandardCharsets.UTF_8);
|
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||||
public void inlineSignThenDetachThenDetachedVerifyTest(SOP sop) throws IOException {
|
public void inlineSignThenDetachThenDetachedVerifyTest(SOP sop) throws IOException {
|
||||||
byte[] message = "Hello, World!\n".getBytes(StandardCharsets.UTF_8);
|
byte[] message = PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||||
|
|
||||||
byte[] inlineSigned = sop.inlineSign()
|
byte[] inlineSigned = sop.inlineSign()
|
||||||
.key(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
.key(ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||||
.data(message)
|
.data(message)
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
|
@ -47,7 +49,7 @@ public class ExternalInlineSignDetachVerifyRoundTripTest extends AbstractExterna
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
List<Verification> verifications = sop.detachedVerify()
|
List<Verification> verifications = sop.detachedVerify()
|
||||||
.cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
.cert(ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||||
.signatures(signatures)
|
.signatures(signatures)
|
||||||
.data(plaintext);
|
.data(plaintext);
|
||||||
|
|
||||||
|
@ -60,7 +62,7 @@ public class ExternalInlineSignDetachVerifyRoundTripTest extends AbstractExterna
|
||||||
byte[] message = "Hello, World!\n".getBytes(StandardCharsets.UTF_8);
|
byte[] message = "Hello, World!\n".getBytes(StandardCharsets.UTF_8);
|
||||||
|
|
||||||
byte[] inlineSigned = sop.inlineSign()
|
byte[] inlineSigned = sop.inlineSign()
|
||||||
.key(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
.key(ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||||
.data(message)
|
.data(message)
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
|
@ -82,7 +84,7 @@ public class ExternalInlineSignDetachVerifyRoundTripTest extends AbstractExterna
|
||||||
assertArrayStartsWith(armored, BEGIN_PGP_SIGNATURE);
|
assertArrayStartsWith(armored, BEGIN_PGP_SIGNATURE);
|
||||||
|
|
||||||
List<Verification> verifications = sop.detachedVerify()
|
List<Verification> verifications = sop.detachedVerify()
|
||||||
.cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
.cert(ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||||
.signatures(armored)
|
.signatures(armored)
|
||||||
.data(plaintext);
|
.data(plaintext);
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,8 @@ import sop.SOP;
|
||||||
import sop.Verification;
|
import sop.Verification;
|
||||||
import sop.enums.InlineSignAs;
|
import sop.enums.InlineSignAs;
|
||||||
import sop.exception.SOPGPException;
|
import sop.exception.SOPGPException;
|
||||||
|
import sop.testing.JUtils;
|
||||||
|
import sop.testing.TestData;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
@ -21,82 +23,84 @@ import java.util.List;
|
||||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static sop.external.JUtils.assertSignedBy;
|
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")
|
@EnabledIf("sop.external.AbstractExternalSOPTest#hasBackends")
|
||||||
public class ExternalInlineSignVerifyTest extends AbstractExternalSOPTest {
|
public class ExternalInlineSignVerifyTest extends AbstractExternalSOPTest {
|
||||||
|
|
||||||
private static final String BEGIN_PGP_MESSAGE = "-----BEGIN PGP MESSAGE-----\n";
|
|
||||||
private static final byte[] BEGIN_PGP_MESSAGE_BYTES = BEGIN_PGP_MESSAGE.getBytes(StandardCharsets.UTF_8);
|
|
||||||
private static final String BEGIN_PGP_SIGNED_MESSAGE = "-----BEGIN PGP SIGNED MESSAGE-----\n";
|
|
||||||
private static final byte[] BEGIN_PGP_SIGNED_MESSAGE_BYTES = BEGIN_PGP_SIGNED_MESSAGE.getBytes(StandardCharsets.UTF_8);
|
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||||
public void inlineSignVerifyAlice(SOP sop) throws IOException {
|
public void inlineSignVerifyAlice(SOP sop) throws IOException {
|
||||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
byte[] message = PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||||
|
|
||||||
byte[] inlineSigned = sop.inlineSign()
|
byte[] inlineSigned = sop.inlineSign()
|
||||||
.key(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
.key(ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||||
.data(message)
|
.data(message)
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
JUtils.assertArrayStartsWith(inlineSigned, BEGIN_PGP_MESSAGE_BYTES);
|
JUtils.assertArrayStartsWith(inlineSigned, BEGIN_PGP_MESSAGE);
|
||||||
|
|
||||||
ByteArrayAndResult<List<Verification>> bytesAndResult = sop.inlineVerify()
|
ByteArrayAndResult<List<Verification>> bytesAndResult = sop.inlineVerify()
|
||||||
.cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
.cert(ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||||
.data(inlineSigned)
|
.data(inlineSigned)
|
||||||
.toByteArrayAndResult();
|
.toByteArrayAndResult();
|
||||||
|
|
||||||
assertArrayEquals(message, bytesAndResult.getBytes());
|
assertArrayEquals(message, bytesAndResult.getBytes());
|
||||||
List<Verification> verificationList = bytesAndResult.getResult();
|
List<Verification> verificationList = bytesAndResult.getResult();
|
||||||
assertSignedBy(verificationList, TestData.ALICE_SIGNING_FINGERPRINT, TestData.ALICE_PRIMARY_FINGERPRINT);
|
assertSignedBy(verificationList, ALICE_SIGNING_FINGERPRINT, ALICE_PRIMARY_FINGERPRINT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||||
public void inlineSignVerifyAliceNoArmor(SOP sop) throws IOException {
|
public void inlineSignVerifyAliceNoArmor(SOP sop) throws IOException {
|
||||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
byte[] message = PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||||
|
|
||||||
byte[] inlineSigned = sop.inlineSign()
|
byte[] inlineSigned = sop.inlineSign()
|
||||||
.key(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
.key(ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||||
.noArmor()
|
.noArmor()
|
||||||
.data(message)
|
.data(message)
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
assertFalse(JUtils.arrayStartsWith(inlineSigned, BEGIN_PGP_MESSAGE_BYTES));
|
assertFalse(JUtils.arrayStartsWith(inlineSigned, BEGIN_PGP_MESSAGE));
|
||||||
|
|
||||||
ByteArrayAndResult<List<Verification>> bytesAndResult = sop.inlineVerify()
|
ByteArrayAndResult<List<Verification>> bytesAndResult = sop.inlineVerify()
|
||||||
.cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
.cert(ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||||
.data(inlineSigned)
|
.data(inlineSigned)
|
||||||
.toByteArrayAndResult();
|
.toByteArrayAndResult();
|
||||||
|
|
||||||
assertArrayEquals(message, bytesAndResult.getBytes());
|
assertArrayEquals(message, bytesAndResult.getBytes());
|
||||||
List<Verification> verificationList = bytesAndResult.getResult();
|
List<Verification> verificationList = bytesAndResult.getResult();
|
||||||
assertSignedBy(verificationList, TestData.ALICE_SIGNING_FINGERPRINT, TestData.ALICE_PRIMARY_FINGERPRINT);
|
assertSignedBy(verificationList, ALICE_SIGNING_FINGERPRINT, ALICE_PRIMARY_FINGERPRINT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||||
public void clearsignVerifyAlice(SOP sop) throws IOException {
|
public void clearsignVerifyAlice(SOP sop) throws IOException {
|
||||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
byte[] message = PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||||
|
|
||||||
byte[] clearsigned = sop.inlineSign()
|
byte[] clearsigned = sop.inlineSign()
|
||||||
.key(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
.key(ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||||
.mode(InlineSignAs.clearsigned)
|
.mode(InlineSignAs.clearsigned)
|
||||||
.data(message)
|
.data(message)
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
JUtils.assertArrayStartsWith(clearsigned, BEGIN_PGP_SIGNED_MESSAGE_BYTES);
|
JUtils.assertArrayStartsWith(clearsigned, BEGIN_PGP_SIGNED_MESSAGE);
|
||||||
|
|
||||||
ByteArrayAndResult<List<Verification>> bytesAndResult = sop.inlineVerify()
|
ByteArrayAndResult<List<Verification>> bytesAndResult = sop.inlineVerify()
|
||||||
.cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
.cert(ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||||
.data(clearsigned)
|
.data(clearsigned)
|
||||||
.toByteArrayAndResult();
|
.toByteArrayAndResult();
|
||||||
|
|
||||||
assertArrayEquals(message, bytesAndResult.getBytes());
|
assertArrayEquals(message, bytesAndResult.getBytes());
|
||||||
List<Verification> verificationList = bytesAndResult.getResult();
|
List<Verification> verificationList = bytesAndResult.getResult();
|
||||||
assertSignedBy(verificationList, TestData.ALICE_SIGNING_FINGERPRINT, TestData.ALICE_PRIMARY_FINGERPRINT);
|
assertSignedBy(verificationList, ALICE_SIGNING_FINGERPRINT, ALICE_PRIMARY_FINGERPRINT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
|
@ -106,11 +110,11 @@ public class ExternalInlineSignVerifyTest extends AbstractExternalSOPTest {
|
||||||
Date signatureDate = TestData.ALICE_INLINE_SIGNED_MESSAGE_DATE;
|
Date signatureDate = TestData.ALICE_INLINE_SIGNED_MESSAGE_DATE;
|
||||||
|
|
||||||
ByteArrayAndResult<List<Verification>> bytesAndResult = sop.inlineVerify()
|
ByteArrayAndResult<List<Verification>> bytesAndResult = sop.inlineVerify()
|
||||||
.cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
.cert(ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||||
.data(message)
|
.data(message)
|
||||||
.toByteArrayAndResult();
|
.toByteArrayAndResult();
|
||||||
List<Verification> verificationList = bytesAndResult.getResult();
|
List<Verification> verificationList = bytesAndResult.getResult();
|
||||||
assertSignedBy(verificationList, TestData.ALICE_SIGNING_FINGERPRINT, TestData.ALICE_PRIMARY_FINGERPRINT, signatureDate);
|
assertSignedBy(verificationList, ALICE_SIGNING_FINGERPRINT, ALICE_PRIMARY_FINGERPRINT, signatureDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
|
@ -122,7 +126,7 @@ public class ExternalInlineSignVerifyTest extends AbstractExternalSOPTest {
|
||||||
|
|
||||||
assertThrows(SOPGPException.NoSignature.class, () -> sop.inlineVerify()
|
assertThrows(SOPGPException.NoSignature.class, () -> sop.inlineVerify()
|
||||||
.notBefore(afterSignature)
|
.notBefore(afterSignature)
|
||||||
.cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
.cert(ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||||
.data(message)
|
.data(message)
|
||||||
.toByteArrayAndResult());
|
.toByteArrayAndResult());
|
||||||
}
|
}
|
||||||
|
@ -136,7 +140,7 @@ public class ExternalInlineSignVerifyTest extends AbstractExternalSOPTest {
|
||||||
|
|
||||||
assertThrows(SOPGPException.NoSignature.class, () -> sop.inlineVerify()
|
assertThrows(SOPGPException.NoSignature.class, () -> sop.inlineVerify()
|
||||||
.notAfter(beforeSignature)
|
.notAfter(beforeSignature)
|
||||||
.cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
.cert(ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||||
.data(message)
|
.data(message)
|
||||||
.toByteArrayAndResult());
|
.toByteArrayAndResult());
|
||||||
}
|
}
|
||||||
|
@ -144,14 +148,14 @@ public class ExternalInlineSignVerifyTest extends AbstractExternalSOPTest {
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||||
public void inlineSignVerifyBob(SOP sop) throws IOException {
|
public void inlineSignVerifyBob(SOP sop) throws IOException {
|
||||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
byte[] message = PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||||
|
|
||||||
byte[] inlineSigned = sop.inlineSign()
|
byte[] inlineSigned = sop.inlineSign()
|
||||||
.key(TestData.BOB_KEY.getBytes(StandardCharsets.UTF_8))
|
.key(TestData.BOB_KEY.getBytes(StandardCharsets.UTF_8))
|
||||||
.data(message)
|
.data(message)
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
JUtils.assertArrayStartsWith(inlineSigned, BEGIN_PGP_MESSAGE_BYTES);
|
JUtils.assertArrayStartsWith(inlineSigned, BEGIN_PGP_MESSAGE);
|
||||||
|
|
||||||
ByteArrayAndResult<List<Verification>> bytesAndResult = sop.inlineVerify()
|
ByteArrayAndResult<List<Verification>> bytesAndResult = sop.inlineVerify()
|
||||||
.cert(TestData.BOB_CERT.getBytes(StandardCharsets.UTF_8))
|
.cert(TestData.BOB_CERT.getBytes(StandardCharsets.UTF_8))
|
||||||
|
@ -166,14 +170,14 @@ public class ExternalInlineSignVerifyTest extends AbstractExternalSOPTest {
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||||
public void inlineSignVerifyCarol(SOP sop) throws IOException {
|
public void inlineSignVerifyCarol(SOP sop) throws IOException {
|
||||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
byte[] message = PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||||
|
|
||||||
byte[] inlineSigned = sop.inlineSign()
|
byte[] inlineSigned = sop.inlineSign()
|
||||||
.key(TestData.CAROL_KEY.getBytes(StandardCharsets.UTF_8))
|
.key(TestData.CAROL_KEY.getBytes(StandardCharsets.UTF_8))
|
||||||
.data(message)
|
.data(message)
|
||||||
.getBytes();
|
.getBytes();
|
||||||
|
|
||||||
JUtils.assertArrayStartsWith(inlineSigned, BEGIN_PGP_MESSAGE_BYTES);
|
JUtils.assertArrayStartsWith(inlineSigned, BEGIN_PGP_MESSAGE);
|
||||||
|
|
||||||
ByteArrayAndResult<List<Verification>> bytesAndResult = sop.inlineVerify()
|
ByteArrayAndResult<List<Verification>> bytesAndResult = sop.inlineVerify()
|
||||||
.cert(TestData.CAROL_CERT.getBytes(StandardCharsets.UTF_8))
|
.cert(TestData.CAROL_CERT.getBytes(StandardCharsets.UTF_8))
|
||||||
|
@ -188,7 +192,7 @@ public class ExternalInlineSignVerifyTest extends AbstractExternalSOPTest {
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||||
public void inlineSignVerifyProtectedKey(SOP sop) throws IOException {
|
public void inlineSignVerifyProtectedKey(SOP sop) throws IOException {
|
||||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
byte[] message = PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||||
|
|
||||||
byte[] inlineSigned = sop.inlineSign()
|
byte[] inlineSigned = sop.inlineSign()
|
||||||
.withKeyPassword(TestData.PASSWORD)
|
.withKeyPassword(TestData.PASSWORD)
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id 'java-library'
|
id 'java-library'
|
||||||
|
id 'java-test-fixtures'
|
||||||
}
|
}
|
||||||
|
|
||||||
group 'org.pgpainless'
|
group 'org.pgpainless'
|
||||||
|
@ -15,6 +16,7 @@ repositories {
|
||||||
dependencies {
|
dependencies {
|
||||||
testImplementation "org.junit.jupiter:junit-jupiter-api:$junitVersion"
|
testImplementation "org.junit.jupiter:junit-jupiter-api:$junitVersion"
|
||||||
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junitVersion"
|
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junitVersion"
|
||||||
|
testFixturesImplementation "org.junit.jupiter:junit-jupiter-api:$junitVersion"
|
||||||
}
|
}
|
||||||
|
|
||||||
test {
|
test {
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
//
|
//
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
package sop.external;
|
package sop.testing;
|
||||||
|
|
||||||
import sop.Verification;
|
import sop.Verification;
|
||||||
import sop.util.UTCUtil;
|
import sop.util.UTCUtil;
|
||||||
|
@ -86,6 +86,47 @@ public class JUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean arrayEndsWith(byte[] array, byte[] end) {
|
||||||
|
return arrayEndsWith(array, end, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean arrayEndsWith(byte[] array, byte[] end, int offset) {
|
||||||
|
if (end.length + offset > array.length) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < end.length; i++) {
|
||||||
|
int arrOff = array.length - end.length - offset;
|
||||||
|
if (end[i] != array[arrOff + i]) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void assertArrayEndsWith(byte[] array, byte[] end) {
|
||||||
|
assertArrayEndsWith(array, end, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void assertArrayEndsWith(byte[] array, byte[] end, int offset) {
|
||||||
|
if (!arrayEndsWith(array, end, offset)) {
|
||||||
|
byte[] actual = new byte[Math.min(end.length, array.length - offset)];
|
||||||
|
System.arraycopy(array, array.length - actual.length, actual, 0, actual.length);
|
||||||
|
fail("Array does not end with the expected bytes.\n" +
|
||||||
|
"Expected: <" + Arrays.toString(end) + ">\n" +
|
||||||
|
"Actual: <" + Arrays.toString(actual) + ">");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void assertArrayEndsWithIgnoreNewlines(byte[] array, byte[] end) {
|
||||||
|
int offset = 0;
|
||||||
|
while (offset < array.length && array[array.length - 1 - offset] == (byte) 10) {
|
||||||
|
offset++;
|
||||||
|
}
|
||||||
|
|
||||||
|
assertArrayEndsWith(array, end, offset);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assert equality of the given two ascii armored byte arrays, ignoring armor header lines.
|
* Assert equality of the given two ascii armored byte arrays, ignoring armor header lines.
|
||||||
*
|
*
|
|
@ -2,10 +2,11 @@
|
||||||
//
|
//
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
package sop.external;
|
package sop.testing;
|
||||||
|
|
||||||
import sop.util.UTCUtil;
|
import sop.util.UTCUtil;
|
||||||
|
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
public class TestData {
|
public class TestData {
|
||||||
|
@ -409,4 +410,15 @@ public class TestData {
|
||||||
public static final String PASSWORD = "sw0rdf1sh";
|
public static final String PASSWORD = "sw0rdf1sh";
|
||||||
public static final String PASSWORD_PROTECTED_PRIMARY_FINGERPRINT = "FC63688A5E698C2940AF70297C622B00D4592657";
|
public static final String PASSWORD_PROTECTED_PRIMARY_FINGERPRINT = "FC63688A5E698C2940AF70297C622B00D4592657";
|
||||||
public static final String PASSWORD_PROTECTED_SIGNING_FINGERPRINT = "D8F1CBC2613350D1A766D35F68862FB90F07165B";
|
public static final String PASSWORD_PROTECTED_SIGNING_FINGERPRINT = "D8F1CBC2613350D1A766D35F68862FB90F07165B";
|
||||||
|
|
||||||
|
|
||||||
|
public static final byte[] BEGIN_PGP_PRIVATE_KEY_BLOCK = "-----BEGIN PGP PRIVATE KEY BLOCK-----\n".getBytes(StandardCharsets.UTF_8);
|
||||||
|
public static final byte[] END_PGP_PRIVATE_KEY_BLOCK = "-----END PGP PRIVATE KEY BLOCK-----".getBytes(StandardCharsets.UTF_8);
|
||||||
|
public static final byte[] BEGIN_PGP_PUBLIC_KEY_BLOCK = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n".getBytes(StandardCharsets.UTF_8);
|
||||||
|
public static final byte[] END_PGP_PUBLIC_KEY_BLOCK = "-----END PGP PUBLIC KEY BLOCK-----".getBytes(StandardCharsets.UTF_8);
|
||||||
|
public static final byte[] BEGIN_PGP_MESSAGE = "-----BEGIN PGP MESSAGE-----\n".getBytes(StandardCharsets.UTF_8);
|
||||||
|
public static final byte[] END_PGP_MESSAGE = "-----END PGP MESSAGE-----".getBytes(StandardCharsets.UTF_8);
|
||||||
|
public static final byte[] BEGIN_PGP_SIGNATURE = "-----BEGIN PGP SIGNATURE-----\n".getBytes(StandardCharsets.UTF_8);
|
||||||
|
public static final byte[] END_PGP_SIGNATURE = "-----END PGP SIGNATURE-----".getBytes(StandardCharsets.UTF_8);
|
||||||
|
public static final byte[] BEGIN_PGP_SIGNED_MESSAGE = "-----BEGIN PGP SIGNED MESSAGE-----\n".getBytes(StandardCharsets.UTF_8);
|
||||||
}
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
// SPDX-FileCopyrightText: 2021 Paul Schaub <vanitasvitae@fsfe.org>
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stateless OpenPGP Interface for Java.
|
||||||
|
*/
|
||||||
|
package sop.testing;
|
Loading…
Reference in a new issue