mirror of
https://codeberg.org/PGPainless/sop-java.git
synced 2025-09-09 10:19:47 +02:00
Move testfixtures to own artifact
This commit is contained in:
parent
ca65cbe668
commit
b3b8da4e35
30 changed files with 29 additions and 8 deletions
24
sop-java-testfixtures/build.gradle
Normal file
24
sop-java-testfixtures/build.gradle
Normal file
|
@ -0,0 +1,24 @@
|
|||
// SPDX-FileCopyrightText: 2024 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
plugins {
|
||||
id 'java-library'
|
||||
}
|
||||
|
||||
group 'org.pgpainless'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(project(":sop-java"))
|
||||
implementation "org.junit.jupiter:junit-jupiter-api:$junitVersion"
|
||||
implementation "org.junit.jupiter:junit-jupiter-params:$junitVersion"
|
||||
runtimeOnly "org.junit.jupiter:junit-jupiter-engine:$junitVersion"
|
||||
|
||||
// @Nullable, @Nonnull annotations
|
||||
implementation "com.google.code.findbugs:jsr305:3.0.2"
|
||||
|
||||
}
|
167
sop-java-testfixtures/src/main/java/sop/testsuite/JUtils.java
Normal file
167
sop-java-testfixtures/src/main/java/sop/testsuite/JUtils.java
Normal file
|
@ -0,0 +1,167 @@
|
|||
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sop.testsuite;
|
||||
|
||||
import sop.util.UTCUtil;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
public class JUtils {
|
||||
|
||||
/**
|
||||
* Return true, if the given <pre>array</pre> starts with <pre>start</pre>.
|
||||
*
|
||||
* @param array array
|
||||
* @param start start
|
||||
* @return true if array starts with start, false otherwise
|
||||
*/
|
||||
public static boolean arrayStartsWith(byte[] array, byte[] start) {
|
||||
return arrayStartsWith(array, start, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true, if the given <pre>array</pre> contains the given <pre>start</pre> at offset <pre>offset</pre>.
|
||||
*
|
||||
* @param array array
|
||||
* @param start start
|
||||
* @param offset offset
|
||||
* @return true, if array contains start at offset, false otherwise
|
||||
*/
|
||||
public static boolean arrayStartsWith(byte[] array, byte[] start, int offset) {
|
||||
if (offset < 0) {
|
||||
throw new IllegalArgumentException("Offset cannot be negative");
|
||||
}
|
||||
|
||||
if (start.length + offset > array.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < start.length; i++) {
|
||||
if (array[offset + i] != start[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the given <pre>array</pre> starts with <pre>start</pre>.
|
||||
*
|
||||
* @param array array
|
||||
* @param start start
|
||||
*/
|
||||
public static void assertArrayStartsWith(byte[] array, byte[] start) {
|
||||
if (!arrayStartsWith(array, start)) {
|
||||
byte[] actual = new byte[Math.min(start.length, array.length)];
|
||||
System.arraycopy(array, 0, actual, 0, actual.length);
|
||||
fail("Array does not start with expected bytes.\n" +
|
||||
"Expected: <" + Arrays.toString(start) + ">\n" +
|
||||
"Actual: <" + Arrays.toString(actual) + ">");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the given <pre>array</pre> contains <pre>start</pre> at <pre>offset</pre>.
|
||||
*
|
||||
* @param array array
|
||||
* @param start start
|
||||
* @param offset offset
|
||||
*/
|
||||
public static void assertArrayStartsWith(byte[] array, byte[] start, int offset) {
|
||||
if (!arrayStartsWith(array, start, offset)) {
|
||||
byte[] actual = new byte[Math.min(start.length, array.length - offset)];
|
||||
System.arraycopy(array, offset, actual, 0, actual.length);
|
||||
fail("Array does not start with expected bytes at offset " + offset + ".\n" +
|
||||
"Expected: <" + Arrays.toString(start) + ">\n" +
|
||||
"Actual: <" + Arrays.toString(actual) + ">");
|
||||
}
|
||||
}
|
||||
|
||||
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.
|
||||
*
|
||||
* @param first first ascii armored bytes
|
||||
* @param second second ascii armored bytes
|
||||
*/
|
||||
public static void assertAsciiArmorEquals(byte[] first, byte[] second) {
|
||||
byte[] firstCleaned = removeArmorHeaders(first);
|
||||
byte[] secondCleaned = removeArmorHeaders(second);
|
||||
|
||||
assertArrayEquals(firstCleaned, secondCleaned);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove armor headers "Comment:", "Version:", "MessageID:", "Hash:" and "Charset:" along with their values
|
||||
* from the given ascii armored byte array.
|
||||
*
|
||||
* @param armor ascii armored byte array
|
||||
* @return ascii armored byte array with header lines removed
|
||||
*/
|
||||
public static byte[] removeArmorHeaders(byte[] armor) {
|
||||
String string = new String(armor, StandardCharsets.UTF_8);
|
||||
string = string.replaceAll("Comment: .+\\R", "")
|
||||
.replaceAll("Version: .+\\R", "")
|
||||
.replaceAll("MessageID: .+\\R", "")
|
||||
.replaceAll("Hash: .+\\R", "")
|
||||
.replaceAll("Charset: .+\\R", "");
|
||||
return string.getBytes(StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
public static void assertDateEquals(Date expected, Date actual) {
|
||||
assertEquals(UTCUtil.formatUTCDate(expected), UTCUtil.formatUTCDate(actual));
|
||||
}
|
||||
|
||||
public static boolean dateEquals(Date expected, Date actual) {
|
||||
return UTCUtil.formatUTCDate(expected).equals(UTCUtil.formatUTCDate(actual));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sop.testsuite;
|
||||
|
||||
import sop.SOP;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Factory class to instantiate SOP implementations for testing.
|
||||
* Overwrite this class and the {@link #provideSOPInstances()} method to return the SOP instances you want
|
||||
* to test.
|
||||
* Then, add the following line to your <pre>build.gradle</pre> files <pre>dependencies</pre> section:
|
||||
* <pre>{@code
|
||||
* testImplementation(testFixtures("org.pgpainless:sop-java:<version>"))
|
||||
* }</pre>
|
||||
* To inject the factory class into the test suite, add the following line to your modules <pre>test</pre> task:
|
||||
* <pre>{@code
|
||||
* environment("test.implementation", "org.example.YourTestSubjectFactory")
|
||||
* }</pre>
|
||||
* Next, in your <pre>test</pre> sources, extend all test classes from the <pre>testFixtures</pre>
|
||||
* <pre>sop.operation</pre> package.
|
||||
* Take a look at the <pre>external-sop</pre> module for an example.
|
||||
*/
|
||||
public abstract class SOPInstanceFactory {
|
||||
|
||||
public abstract Map<String, SOP> provideSOPInstances();
|
||||
}
|
433
sop-java-testfixtures/src/main/java/sop/testsuite/TestData.java
Normal file
433
sop-java-testfixtures/src/main/java/sop/testsuite/TestData.java
Normal file
|
@ -0,0 +1,433 @@
|
|||
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sop.testsuite;
|
||||
|
||||
import sop.util.UTCUtil;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.ParseException;
|
||||
import java.util.Date;
|
||||
|
||||
public class TestData {
|
||||
|
||||
|
||||
public static final String PLAINTEXT = "Hello, World!\n";
|
||||
|
||||
// 'Alice' key from draft-bre-openpgp-samples-00
|
||||
public static final String ALICE_CERT = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
|
||||
"Comment: EB85 BB5F A33A 75E1 5E94 4E63 F231 550C 4F47 E38E\n" +
|
||||
"Comment: Alice Lovelace <alice@openpgp.example>\n" +
|
||||
"\n" +
|
||||
"xjMEXEcE6RYJKwYBBAHaRw8BAQdArjWwk3FAqyiFbFBKT4TzXcVBqPTB3gmzlC/U\n" +
|
||||
"b7O1u13NJkFsaWNlIExvdmVsYWNlIDxhbGljZUBvcGVucGdwLmV4YW1wbGU+wpAE\n" +
|
||||
"ExYIADgCGwMFCwkIBwIGFQoJCAsCBBYCAwECHgECF4AWIQTrhbtfozp14V6UTmPy\n" +
|
||||
"MVUMT0fjjgUCXaWfOgAKCRDyMVUMT0fjjukrAPoDnHBSogOmsHOsd9qGsiZpgRnO\n" +
|
||||
"dypvbm+QtXZqth9rvwD9HcDC0tC+PHAsO7OTh1S1TC9RiJsvawAfCPaQZoed8gLO\n" +
|
||||
"OARcRwTpEgorBgEEAZdVAQUBAQdAQv8GIa2rSTzgqbXCpDDYMiKRVitCsy203x3s\n" +
|
||||
"E9+eviIDAQgHwngEGBYIACAWIQTrhbtfozp14V6UTmPyMVUMT0fjjgUCXEcE6QIb\n" +
|
||||
"DAAKCRDyMVUMT0fjjlnQAQDFHUs6TIcxrNTtEZFjUFm1M0PJ1Dng/cDW4xN80fsn\n" +
|
||||
"0QEA22Kr7VkCjeAEC08VSTeV+QFsmz55/lntWkwYWhmvOgE=\n" +
|
||||
"=QX3Q\n" +
|
||||
"-----END PGP PUBLIC KEY BLOCK-----\n";
|
||||
|
||||
public static final String ALICE_KEY = "-----BEGIN PGP PRIVATE KEY BLOCK-----\n" +
|
||||
"Comment: EB85 BB5F A33A 75E1 5E94 4E63 F231 550C 4F47 E38E\n" +
|
||||
"Comment: Alice Lovelace <alice@openpgp.example>\n" +
|
||||
"\n" +
|
||||
"xVgEXEcE6RYJKwYBBAHaRw8BAQdArjWwk3FAqyiFbFBKT4TzXcVBqPTB3gmzlC/U\n" +
|
||||
"b7O1u10AAP9XBeW6lzGOLx7zHH9AsUDUTb2pggYGMzd0P3ulJ2AfvQ4RzSZBbGlj\n" +
|
||||
"ZSBMb3ZlbGFjZSA8YWxpY2VAb3BlbnBncC5leGFtcGxlPsKQBBMWCAA4AhsDBQsJ\n" +
|
||||
"CAcCBhUKCQgLAgQWAgMBAh4BAheAFiEE64W7X6M6deFelE5j8jFVDE9H444FAl2l\n" +
|
||||
"nzoACgkQ8jFVDE9H447pKwD6A5xwUqIDprBzrHfahrImaYEZzncqb25vkLV2arYf\n" +
|
||||
"a78A/R3AwtLQvjxwLDuzk4dUtUwvUYibL2sAHwj2kGaHnfICx10EXEcE6RIKKwYB\n" +
|
||||
"BAGXVQEFAQEHQEL/BiGtq0k84Km1wqQw2DIikVYrQrMttN8d7BPfnr4iAwEIBwAA\n" +
|
||||
"/3/xFPG6U17rhTuq+07gmEvaFYKfxRB6sgAYiW6TMTpQEK7CeAQYFggAIBYhBOuF\n" +
|
||||
"u1+jOnXhXpROY/IxVQxPR+OOBQJcRwTpAhsMAAoJEPIxVQxPR+OOWdABAMUdSzpM\n" +
|
||||
"hzGs1O0RkWNQWbUzQ8nUOeD9wNbjE3zR+yfRAQDbYqvtWQKN4AQLTxVJN5X5AWyb\n" +
|
||||
"Pnn+We1aTBhaGa86AQ==\n" +
|
||||
"=3GfK\n" +
|
||||
"-----END PGP PRIVATE KEY BLOCK-----\n";
|
||||
public static final String ALICE_PRIMARY_FINGERPRINT = "EB85BB5FA33A75E15E944E63F231550C4F47E38E";
|
||||
public static final String ALICE_SIGNING_FINGERPRINT = "EB85BB5FA33A75E15E944E63F231550C4F47E38E";
|
||||
|
||||
public static final String ALICE_INLINE_SIGNED_MESSAGE = "-----BEGIN PGP MESSAGE-----\n" +
|
||||
"\n" +
|
||||
"owGbwMvMwCX2yTCUx9/9cR/jaZEkBhDwSM3JyddRCM8vyklR5OooZWEQ42JQZ2VK\n" +
|
||||
"PjjpPacATLmYIsvr1t3xi61KH8ZN8UuGCTMwpPcw/E9jS+vcvPu2gmp4jcRbcSNP\n" +
|
||||
"FYmW8hmLJdUVrdt1V8w6GM/IMEvN0tP339sNGX4swq8T5p62q3jUfLjpstmcI6Ie\n" +
|
||||
"sfcfswMA\n" +
|
||||
"=RDAo\n" +
|
||||
"-----END PGP MESSAGE-----";
|
||||
public static final Date ALICE_INLINE_SIGNED_MESSAGE_DATE = parseUTCDate("2023-01-13T17:20:47Z");
|
||||
// signature over PLAINTEXT
|
||||
public static final String ALICE_DETACHED_SIGNED_MESSAGE = "-----BEGIN PGP SIGNATURE-----\n" +
|
||||
"\n" +
|
||||
"iHUEABYKACcFAmPBjZUJEPIxVQxPR+OOFiEE64W7X6M6deFelE5j8jFVDE9H444A\n" +
|
||||
"ADI/AQC6Bux6WpGYf7HO+QPV/D5iIrqZt9xPLgfUVoNJBmMZZwD+Ib+tn5pSyWUw\n" +
|
||||
"0K1UgT5roym9Fln8U5W8R03TSbfNiwE=\n" +
|
||||
"=bxPN\n" +
|
||||
"-----END PGP SIGNATURE-----";
|
||||
public static final Date ALICE_DETACHED_SIGNED_MESSAGE_DATE = parseUTCDate("2023-01-13T16:57:57Z");
|
||||
|
||||
// 'Bob' key from draft-bre-openpgp-samples-00
|
||||
public static final String BOB_CERT = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
|
||||
"Comment: D1A6 6E1A 23B1 82C9 980F 788C FBFC C82A 015E 7330\n" +
|
||||
"Comment: Bob Babbage <bob@openpgp.example>\n" +
|
||||
"\n" +
|
||||
"xsDNBF2lnPIBDAC5cL9PQoQLTMuhjbYvb4Ncuuo0bfmgPRFywX53jPhoFf4Zg6mv\n" +
|
||||
"/seOXpgecTdOcVttfzC8ycIKrt3aQTiwOG/ctaR4Bk/t6ayNFfdUNxHWk4WCKzdz\n" +
|
||||
"/56fW2O0F23qIRd8UUJp5IIlN4RDdRCtdhVQIAuzvp2oVy/LaS2kxQoKvph/5pQ/\n" +
|
||||
"5whqsyroEWDJoSV0yOb25B/iwk/pLUFoyhDG9bj0kIzDxrEqW+7Ba8nocQlecMF3\n" +
|
||||
"X5KMN5kp2zraLv9dlBBpWW43XktjcCZgMy20SouraVma8Je/ECwUWYUiAZxLIlMv\n" +
|
||||
"9CurEOtxUw6N3RdOtLmYZS9uEnn5y1UkF88o8Nku890uk6BrewFzJyLAx5wRZ4F0\n" +
|
||||
"qV/yq36UWQ0JB/AUGhHVPdFf6pl6eaxBwT5GXvbBUibtf8YI2og5RsgTWtXfU7eb\n" +
|
||||
"SGXrl5ZMpbA6mbfhd0R8aPxWfmDWiIOhBufhMCvUHh1sApMKVZnvIff9/0Dca3wb\n" +
|
||||
"vLIwa3T4CyshfT0AEQEAAc0hQm9iIEJhYmJhZ2UgPGJvYkBvcGVucGdwLmV4YW1w\n" +
|
||||
"bGU+wsEOBBMBCgA4AhsDBQsJCAcCBhUKCQgLAgQWAgMBAh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Q01rh\n" +
|
||||
"827KVZW4lXvqsge+wtnWlszcselGATyzqOK9LdHPdZGzROZYI2e8c+paLNDdVPL6\n" +
|
||||
"vdRBUnkCaEkOtl1mr2JpQi5nTU+gTX4IeInC7E+1a9UDF/Y85ybUz8XV8rUnR76U\n" +
|
||||
"qVC7KidNepdHbZjjXCt8/Zo+Tec9JNbYNQB/e9ExmDntmlHEsSEQzFwzj8sxH48A\n" +
|
||||
"EQEAAcLA9gQYAQoAIBYhBNGmbhojsYLJmA94jPv8yCoBXnMwBQJdpZzyAhsMAAoJ\n" +
|
||||
"EPv8yCoBXnMw6f8L/26C34dkjBffTzMj5Bdzm8MtF67OYneJ4TQMw7+41IL4rVcS\n" +
|
||||
"KhIhk/3Ud5knaRtP2ef1+5F66h9/RPQOJ5+tvBwhBAcUWSupKnUrdVaZQanYmtSx\n" +
|
||||
"cVV2PL9+QEiNN3tzluhaWO//rACxJ+K/ZXQlIzwQVTpNhfGzAaMVV9zpf3u0k14i\n" +
|
||||
"tcv6alKY8+rLZvO1wIIeRZLmU0tZDD5HtWDvUV7rIFI1WuoLb+KZgbYn3OWjCPHV\n" +
|
||||
"dTrdZ2CqnZbG3SXw6awH9bzRLV9EXkbhIMez0deCVdeo+wFFklh8/5VK2b0vk/+w\n" +
|
||||
"qMJxfpa1lHvJLobzOP9fvrswsr92MA2+k901WeISR7qEzcI0Fdg8AyFAExaEK6Vy\n" +
|
||||
"jP7SXGLwvfisw34OxuZr3qmx1Sufu4toH3XrB7QJN8XyqqbsGxUCBqWif9RSK4xj\n" +
|
||||
"zRTe56iPeiSJJOIciMP9i2ldI+KgLycyeDvGoBj0HCLO3gVaBe4ubVrj5KjhX2PV\n" +
|
||||
"NEJd3XZRzaXZE2aAMQ==\n" +
|
||||
"=F9yX\n" +
|
||||
"-----END PGP PUBLIC KEY BLOCK-----\n";
|
||||
|
||||
public static final String BOB_KEY = "-----BEGIN PGP PRIVATE KEY BLOCK-----\n" +
|
||||
"Comment: D1A6 6E1A 23B1 82C9 980F 788C FBFC C82A 015E 7330\n" +
|
||||
"Comment: Bob Babbage <bob@openpgp.example>\n" +
|
||||
"\n" +
|
||||
"xcSYBF2lnPIBDAC5cL9PQoQLTMuhjbYvb4Ncuuo0bfmgPRFywX53jPhoFf4Zg6mv\n" +
|
||||
"/seOXpgecTdOcVttfzC8ycIKrt3aQTiwOG/ctaR4Bk/t6ayNFfdUNxHWk4WCKzdz\n" +
|
||||
"/56fW2O0F23qIRd8UUJp5IIlN4RDdRCtdhVQIAuzvp2oVy/LaS2kxQoKvph/5pQ/\n" +
|
||||
"5whqsyroEWDJoSV0yOb25B/iwk/pLUFoyhDG9bj0kIzDxrEqW+7Ba8nocQlecMF3\n" +
|
||||
"X5KMN5kp2zraLv9dlBBpWW43XktjcCZgMy20SouraVma8Je/ECwUWYUiAZxLIlMv\n" +
|
||||
"9CurEOtxUw6N3RdOtLmYZS9uEnn5y1UkF88o8Nku890uk6BrewFzJyLAx5wRZ4F0\n" +
|
||||
"qV/yq36UWQ0JB/AUGhHVPdFf6pl6eaxBwT5GXvbBUibtf8YI2og5RsgTWtXfU7eb\n" +
|
||||
"SGXrl5ZMpbA6mbfhd0R8aPxWfmDWiIOhBufhMCvUHh1sApMKVZnvIff9/0Dca3wb\n" +
|
||||
"vLIwa3T4CyshfT0AEQEAAQAL/RZqbJW2IqQDCnJi4Ozm++gPqBPiX1RhTWSjwxfM\n" +
|
||||
"cJKUZfzLj414rMKm6Jh1cwwGY9jekROhB9WmwaaKT8HtcIgrZNAlYzANGRCM4TLK\n" +
|
||||
"3VskxfSwKKna8l+s+mZglqbAjUg3wmFuf9Tj2xcUZYmyRm1DEmcN2ZzpvRtHgX7z\n" +
|
||||
"Wn1mAKUlSDJZSQks0zjuMNbupcpyJokdlkUg2+wBznBOTKzgMxVNC9b2g5/tMPUs\n" +
|
||||
"hGGWmF1UH+7AHMTaS6dlmr2ZBIyogdnfUqdNg5sZwsxSNrbglKP4sqe7X61uEAIQ\n" +
|
||||
"b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n" +
|
||||
"rbwcIQQHFFkrqSp1K3VWmUGp2JrUsXFVdjy/fkBIjTd7c5boWljv/6wAsSfiv2V0\n" +
|
||||
"JSM8EFU6TYXxswGjFVfc6X97tJNeIrXL+mpSmPPqy2bztcCCHkWS5lNLWQw+R7Vg\n" +
|
||||
"71Fe6yBSNVrqC2/imYG2J9zlowjx1XU63Wdgqp2Wxt0l8OmsB/W80S1fRF5G4SDH\n" +
|
||||
"s9HXglXXqPsBRZJYfP+VStm9L5P/sKjCcX6WtZR7yS6G8zj/X767MLK/djANvpPd\n" +
|
||||
"NVniEke6hM3CNBXYPAMhQBMWhCulcoz+0lxi8L34rMN+Dsbma96psdUrn7uLaB91\n" +
|
||||
"6we0CTfF8qqm7BsVAgalon/UUiuMY80U3ueoj3okiSTiHIjD/YtpXSPioC8nMng7\n" +
|
||||
"xqAY9Bwizt4FWgXuLm1a4+So4V9j1TRCXd12Uc2l2RNmgDE=\n" +
|
||||
"=FAzO\n" +
|
||||
"-----END PGP PRIVATE KEY BLOCK-----\n";
|
||||
public static final String BOB_PRIMARY_FINGERPRINT = "D1A66E1A23B182C9980F788CFBFCC82A015E7330";
|
||||
public static final String BOB_SIGNING_FINGERPRINT = "D1A66E1A23B182C9980F788CFBFCC82A015E7330";
|
||||
|
||||
// 'Carol' key from draft-bre-openpgp-samples-00
|
||||
public static final String CAROL_CERT = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
|
||||
"Comment: 71FF DA00 4409 E5DD B0C3 E8F1 9BA7 89DC 76D6 849A\n" +
|
||||
"Comment: Carol Oldstyle <carol@openpgp.example>\n" +
|
||||
"\n" +
|
||||
"xsPuBF3+CmgRDADZhdKTM3ms3XpXnQke83FgaIBtP1g1qhqpCfg50WiPS0kjiMC0\n" +
|
||||
"OJz2vh59nusbBLzgI//Y1VMhKfIWYbqMcIY+lWbseHjl52rqW6AaJ0TH4NgVt7vh\n" +
|
||||
"yVeJt0k/NnxvNhMd0587KXmfpDxrwBqc/l5cVB+p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LIC KEY BLOCK-----\n";
|
||||
|
||||
public static final String CAROL_KEY = "-----BEGIN PGP PRIVATE KEY BLOCK-----\n" +
|
||||
"Comment: 71FF DA00 4409 E5DD B0C3 E8F1 9BA7 89DC 76D6 849A\n" +
|
||||
"Comment: Carol Oldstyle <carol@openpgp.example>\n" +
|
||||
"\n" +
|
||||
"xcQTBF3+CmgRDADZhdKTM3ms3XpXnQke83FgaIBtP1g1qhqpCfg50WiPS0kjiMC0\n" +
|
||||
"OJz2vh59nusbBLzgI//Y1VMhKfIWYbqMcIY+lWbseHjl52rqW6AaJ0TH4NgVt7vh\n" +
|
||||
"yVeJt0k/NnxvNhMd0587KXmfpDxrwBqc/l5cVB+p0rL8vs8kxojHXAi5V3koM0Uj\n" +
|
||||
"REWs5Jpj/XU9LhEoyXZkeJC/pes1u6UKoFYn7dFIP49Kkd1kb+1bNfdPYtA0JpcG\n" +
|
||||
"zYgeMNOvdWJwn43dNhxoeuXfmAEhA8LdzT0C0O+7akXOKWrfhXJ8MTBqvPgWZYx7\n" +
|
||||
"MNuQx/ejIMZHl+Iaf7hG976ILH+NCGiKkhidd9GIuA/WteHiQbXLyfiQ4n8P12q9\n" +
|
||||
"+4dq6ybUM65tnozRyyN+1m3rU2a/+Ly3JCh4TeO27w+cxMWkaeHyTQaJVMbMbDpX\n" +
|
||||
"duVd32MA33UVNH5/KXMVczVi5asVjuKDSojJDV1QwX8izZNl1t+AI0L3balCabV0\n" +
|
||||
"SFhlfnBEUj1my1sBAMOSO/I67BvBS3IPHZWXHjgclhs26mPzRlZLryAUWR2DDACH\n" +
|
||||
"5fx+yUAdZ8Vu/2zWTHxwWJ/X6gGTLqa9CmfDq5UDqYFFzuWwN4HJ+ryOuak1CGwS\n" +
|
||||
"KJUBSA75HExbv0naWg+suy+pEDvF0VALPU9VUkSQtHyR10YO2FWOe3AEtpbYDRwp\n" +
|
||||
"dr1ZwEbb3L6IGQ5i/4CNHbJ2u3yUeXsDNAvrpVSEcIjA01RPCOKmf58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b9s86g7hYtpRmE12Jlai2MzPSmyztlsRP9tcZwYy7JdPZf\n" +
|
||||
"xXQP24XWat7eP2qWxTnkEP4/wKYb81m7CZ4RvUO/nd1aA5c9IBYknbgmCAAKvHVD\n" +
|
||||
"iTY61E5GbC9aTiI4WIwjItroikukUJE+p77rpjxfw/1U51BnmQAA/ih5jIthn2ZE\n" +
|
||||
"r1YoOsUs8CBhylTsRZK6VS4ZCErcyl2tD2LCigQYEQgAPAUCXf4KaQMLCQoJEJun\n" +
|
||||
"idx21oSaBBUKCQgCFgECF4ACGwwCHgEWIQRx/9oARAnl3bDD6PGbp4ncdtaEmgAA\n" +
|
||||
"QSkA/3WEWqZxvZmpVxpEMxJWaGQRwUhGake8OhC1WfywCtarAQCLwfBsyEv5jBEi\n" +
|
||||
"1FkOSekLi8WNMdUx3XMyvP8nJ65P2Q==\n" +
|
||||
"=Xj8h\n" +
|
||||
"-----END PGP PRIVATE KEY BLOCK-----\n";
|
||||
public static final String CAROL_PRIMARY_FINGERPRINT = "71FFDA004409E5DDB0C3E8F19BA789DC76D6849A";
|
||||
public static final String CAROL_SIGNING_FINGERPRINT = "71FFDA004409E5DDB0C3E8F19BA789DC76D6849A";
|
||||
|
||||
public static final String PASSWORD_PROTECTED_KEY = "-----BEGIN PGP PRIVATE KEY BLOCK-----\n" +
|
||||
"Comment: FC63 688A 5E69 8C29 40AF 7029 7C62 2B00 D459 2657\n" +
|
||||
"Comment: Password Protected <protected@openpgp.org>\n" +
|
||||
"\n" +
|
||||
"xYYEY8qfmxYJKwYBBAHaRw8BAQdAv5atAPgP3WOvjoeEGAXIpX+k9LbX1+roEQQE\n" +
|
||||
"WaQfbMv+CQMI7d4yuArkBqz/J/UllaSoHN2kYdJE4Biiqgto2d39B8JRCrb0LSeX\n" +
|
||||
"25TolXynV3bdiTsVKtnNOOcCzP09kDMu8uCMpregFrMdI511iR+dysLAEQQfFgoA\n" +
|
||||
"gwWCY8qfmwWJBZ+mAAMLCQcJEHxiKwDUWSZ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EGRYKAG8FgmPKn5sJ\n" +
|
||||
"EGiGL7kPBxZbRxQAAAAAAB4AIHNhbHRAbm90YXRpb25zLnNlcXVvaWEtcGdwLm9y\n" +
|
||||
"Z62UKDMX/Uh2ywrGJjKi3Ex6jpghyED+kPlNuxS8uMs6FiEE2PHLwmEzUNGnZtNf\n" +
|
||||
"aIYvuQ8HFlsAAPgiAPwIlVOxTF7J80KAiHrApEgfLHsEeGivjEtnkKO6eUa2awEA\n" +
|
||||
"5qlATwB3bQVkMFYa893MxrjVmmasil81uwMiU8gtRQoWIQT8Y2iKXmmMKUCvcCl8\n" +
|
||||
"YisA1FkmVwAAktwBAOEXjAXOZaFM8PoSNtrKVLakPXCadY8zduAqqgmp5PBwAP0R\n" +
|
||||
"EpO9g0mQuCCmg6eeXm2GxChWORWArh9of7l/epycAceLBGPKn5sSCisGAQQBl1UB\n" +
|
||||
"BQEBB0DDEzY37G8GNXIJqbVsawutIqNTZcizObXrau9F0H5wHQMBCAf+CQMI9ppA\n" +
|
||||
"+RYt5Sv/gIPNmVm7UraBpK75qOC/tN9h/uNaaadcgrWEXMr6+YWjvBmH+iCV61/y\n" +
|
||||
"b9Gkfxn2V/lw8asgch86Y6tN0Rhy+uXTFKMHecLABgQYFgoAeAWCY8qfmwWJBZ+m\n" +
|
||||
"AAkQfGIrANRZJldHFAAAAAAAHgAgc2FsdEBub3RhdGlvbnMuc2VxdW9pYS1wZ3Au\n" +
|
||||
"b3JnYeL3YzJjnG3vwSjzVnzgbFCe5QyC0/mFnqML7+hQi0kCmwwWIQT8Y2iKXmmM\n" +
|
||||
"KUCvcCl8YisA1FkmVwAAbRcA/3haEwnnHhitQNbvDs2DqzVvz0QtjEW59ZKFgzX2\n" +
|
||||
"PUMXAQDJzcz9GoPTqU8hioiSBoQUjN883qv6sJHiEveRyDbMDQ==\n" +
|
||||
"=xHUd\n" +
|
||||
"-----END PGP PRIVATE KEY BLOCK-----\n";
|
||||
public static final String PASSWORD_PROTECTED_CERT = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
|
||||
"Comment: FC63 688A 5E69 8C29 40AF 7029 7C62 2B00 D459 2657\n" +
|
||||
"Comment: Password Protected <protected@openpgp.org>\n" +
|
||||
"\n" +
|
||||
"xjMEY8qfmxYJKwYBBAHaRw8BAQdAv5atAPgP3WOvjoeEGAXIpX+k9LbX1+roEQQE\n" +
|
||||
"WaQfbMvCwBEEHxYKAIMFgmPKn5sFiQWfpgADCwkHCRB8YisA1FkmV0cUAAAAAAAe\n" +
|
||||
"ACBzYWx0QG5vdGF0aW9ucy5zZXF1b2lhLXBncC5vcmeUbfpMSxRYhW02mTtkW3+d\n" +
|
||||
"iuhRHHraoobfI5PVbQzm0gMVCggCmwECHgEWIQT8Y2iKXmmMKUCvcCl8YisA1Fkm\n" +
|
||||
"VwAAU80BAPVctnuXlHRY/oH8D1C7cBCajKY9vXjd+ydFX8BdUXVtAQDHl7rRNXcy\n" +
|
||||
"+T3SCF/FSQCL/UV1UZcOU7o7Yy4a/LsxCs0qUGFzc3dvcmQgUHJvdGVjdGVkIDxw\n" +
|
||||
"cm90ZWN0ZWRAb3BlbnBncC5vcmc+wsAUBBMWCgCGBYJjyp+bBYkFn6YAAwsJBwkQ\n" +
|
||||
"fGIrANRZJldHFAAAAAAAHgAgc2FsdEBub3RhdGlvbnMuc2VxdW9pYS1wZ3Aub3Jn\n" +
|
||||
"UzrhYxi+3MjiFRH3puW/4AiSz+ixSk8tz/4BRkQe1RADFQoIApkBApsBAh4BFiEE\n" +
|
||||
"/GNoil5pjClAr3ApfGIrANRZJlcAAEV7AQD+I8EVpwKhHufQVftFr4mMwvDYSqSI\n" +
|
||||
"18EUCDOcg+hPdAEAkMH4arHsQdq1UBsNLIltnP9w1IZpyvKLDSuX/Ii7+QXOMwRj\n" +
|
||||
"yp+bFgkrBgEEAdpHDwEBB0DP379c8cDI67ioqvVuz3DFG3DCkN5WxXaj7cBCdei8\n" +
|
||||
"WMLAxQQYFgoBNwWCY8qfmwWJBZ+mAAkQfGIrANRZJldHFAAAAAAAHgAgc2FsdEBu\n" +
|
||||
"b3RhdGlvbnMuc2VxdW9pYS1wZ3Aub3JnRfeJWfJrU4KyaS3s6KMYtdJO/0VFsVV/\n" +
|
||||
"59xAZIzNWIECmwK+oAQZFgoAbwWCY8qfmwkQaIYvuQ8HFltHFAAAAAAAHgAgc2Fs\n" +
|
||||
"dEBub3RhdGlvbnMuc2VxdW9pYS1wZ3Aub3JnrZQoMxf9SHbLCsYmMqLcTHqOmCHI\n" +
|
||||
"QP6Q+U27FLy4yzoWIQTY8cvCYTNQ0adm019ohi+5DwcWWwAA+CIA/AiVU7FMXsnz\n" +
|
||||
"QoCIesCkSB8sewR4aK+MS2eQo7p5RrZrAQDmqUBPAHdtBWQwVhrz3czGuNWaZqyK\n" +
|
||||
"XzW7AyJTyC1FChYhBPxjaIpeaYwpQK9wKXxiKwDUWSZXAACS3AEA4ReMBc5loUzw\n" +
|
||||
"+hI22spUtqQ9cJp1jzN24CqqCank8HAA/RESk72DSZC4IKaDp55ebYbEKFY5FYCu\n" +
|
||||
"H2h/uX96nJwBzjgEY8qfmxIKKwYBBAGXVQEFAQEHQMMTNjfsbwY1cgmptWxrC60i\n" +
|
||||
"o1NlyLM5tetq70XQfnAdAwEIB8LABgQYFgoAeAWCY8qfmwWJBZ+mAAkQfGIrANRZ\n" +
|
||||
"JldHFAAAAAAAHgAgc2FsdEBub3RhdGlvbnMuc2VxdW9pYS1wZ3Aub3JnYeL3YzJj\n" +
|
||||
"nG3vwSjzVnzgbFCe5QyC0/mFnqML7+hQi0kCmwwWIQT8Y2iKXmmMKUCvcCl8YisA\n" +
|
||||
"1FkmVwAAbRcA/3haEwnnHhitQNbvDs2DqzVvz0QtjEW59ZKFgzX2PUMXAQDJzcz9\n" +
|
||||
"GoPTqU8hioiSBoQUjN883qv6sJHiEveRyDbMDQ==\n" +
|
||||
"=xlgc\n" +
|
||||
"-----END PGP PUBLIC KEY BLOCK-----\n";
|
||||
public static final String PASSWORD = "sw0rdf1sh";
|
||||
public static final String PASSWORD_PROTECTED_PRIMARY_FINGERPRINT = "FC63688A5E698C2940AF70297C622B00D4592657";
|
||||
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);
|
||||
|
||||
private static Date parseUTCDate(String utcFormatted) {
|
||||
try {
|
||||
return UTCUtil.parseUTCDate(utcFormatted);
|
||||
} catch (ParseException e) {
|
||||
throw new IllegalArgumentException("Malformed UTC timestamp.", e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,235 @@
|
|||
// SPDX-FileCopyrightText: 2024 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sop.testsuite.assertions;
|
||||
|
||||
import sop.exception.SOPGPException;
|
||||
|
||||
import java.util.function.IntSupplier;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
|
||||
/**
|
||||
* DSL for testing the return values of SOP method calls.
|
||||
*/
|
||||
public class SopExecutionAssertions {
|
||||
|
||||
/**
|
||||
* Assert that the execution of the given function returns 0.
|
||||
*
|
||||
* @param function function to execute
|
||||
*/
|
||||
public static void assertSuccess(IntSupplier function) {
|
||||
assertEquals(0, function.getAsInt());
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the execution of the given function returns a generic error with error code 1.
|
||||
*
|
||||
* @param function function to execute.
|
||||
*/
|
||||
public static void assertGenericError(IntSupplier function) {
|
||||
assertEquals(1, function.getAsInt());
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the execution of the given function returns a non-zero error code.
|
||||
*
|
||||
* @param function function to execute
|
||||
*/
|
||||
public static void assertAnyError(IntSupplier function) {
|
||||
assertNotEquals(0, function.getAsInt());
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the execution of the given function returns error code 3
|
||||
* (which corresponds to {@link sop.exception.SOPGPException.NoSignature}).
|
||||
*
|
||||
* @param function function to execute.
|
||||
*/
|
||||
public static void assertNoSignature(IntSupplier function) {
|
||||
assertEquals(SOPGPException.NoSignature.EXIT_CODE, function.getAsInt());
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the execution of the given function returns error code 13
|
||||
* (which corresponds to {@link sop.exception.SOPGPException.UnsupportedAsymmetricAlgo}).
|
||||
*
|
||||
* @param function function to execute.
|
||||
*/
|
||||
public static void assertUnsupportedAsymmetricAlgo(IntSupplier function) {
|
||||
assertEquals(SOPGPException.UnsupportedAsymmetricAlgo.EXIT_CODE, function.getAsInt());
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the execution of the given function returns error code 17
|
||||
* (which corresponds to {@link sop.exception.SOPGPException.CertCannotEncrypt}).
|
||||
*
|
||||
* @param function function to execute.
|
||||
*/
|
||||
public static void assertCertCannotEncrypt(IntSupplier function) {
|
||||
assertEquals(SOPGPException.CertCannotEncrypt.EXIT_CODE, function.getAsInt());
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the execution of the given function returns error code 19
|
||||
* (which corresponds to {@link sop.exception.SOPGPException.MissingArg}).
|
||||
*
|
||||
* @param function function to execute.
|
||||
*/
|
||||
public static void assertMissingArg(IntSupplier function) {
|
||||
assertEquals(SOPGPException.MissingArg.EXIT_CODE, function.getAsInt());
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the execution of the given function returns error code 23
|
||||
* (which corresponds to {@link sop.exception.SOPGPException.IncompleteVerification}).
|
||||
*
|
||||
* @param function function to execute.
|
||||
*/
|
||||
public static void assertIncompleteVerification(IntSupplier function) {
|
||||
assertEquals(SOPGPException.IncompleteVerification.EXIT_CODE, function.getAsInt());
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the execution of the given function returns error code 29
|
||||
* (which corresponds to {@link sop.exception.SOPGPException.CannotDecrypt}).
|
||||
*
|
||||
* @param function function to execute.
|
||||
*/
|
||||
public static void assertCannotDecrypt(IntSupplier function) {
|
||||
assertEquals(SOPGPException.CannotDecrypt.EXIT_CODE, function.getAsInt());
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the execution of the given function returns error code 31
|
||||
* (which corresponds to {@link sop.exception.SOPGPException.PasswordNotHumanReadable}).
|
||||
*
|
||||
* @param function function to execute.
|
||||
*/
|
||||
public static void assertPasswordNotHumanReadable(IntSupplier function) {
|
||||
assertEquals(SOPGPException.PasswordNotHumanReadable.EXIT_CODE, function.getAsInt());
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the execution of the given function returns error code 37
|
||||
* (which corresponds to {@link sop.exception.SOPGPException.UnsupportedOption}).
|
||||
*
|
||||
* @param function function to execute.
|
||||
*/
|
||||
public static void assertUnsupportedOption(IntSupplier function) {
|
||||
assertEquals(SOPGPException.UnsupportedOption.EXIT_CODE, function.getAsInt());
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the execution of the given function returns error code 41
|
||||
* (which corresponds to {@link sop.exception.SOPGPException.BadData}).
|
||||
*
|
||||
* @param function function to execute.
|
||||
*/
|
||||
public static void assertBadData(IntSupplier function) {
|
||||
assertEquals(SOPGPException.BadData.EXIT_CODE, function.getAsInt());
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the execution of the given function returns error code 53
|
||||
* (which corresponds to {@link sop.exception.SOPGPException.ExpectedText}).
|
||||
*
|
||||
* @param function function to execute.
|
||||
*/
|
||||
public static void assertExpectedText(IntSupplier function) {
|
||||
assertEquals(SOPGPException.ExpectedText.EXIT_CODE, function.getAsInt());
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the execution of the given function returns error code 59
|
||||
* (which corresponds to {@link sop.exception.SOPGPException.OutputExists}).
|
||||
*
|
||||
* @param function function to execute.
|
||||
*/
|
||||
public static void assertOutputExists(IntSupplier function) {
|
||||
assertEquals(SOPGPException.OutputExists.EXIT_CODE, function.getAsInt());
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the execution of the given function returns error code 61
|
||||
* (which corresponds to {@link sop.exception.SOPGPException.MissingInput}).
|
||||
*
|
||||
* @param function function to execute.
|
||||
*/
|
||||
public static void assertMissingInput(IntSupplier function) {
|
||||
assertEquals(SOPGPException.MissingInput.EXIT_CODE, function.getAsInt());
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the execution of the given function returns error code 67
|
||||
* (which corresponds to {@link sop.exception.SOPGPException.KeyIsProtected}).
|
||||
*
|
||||
* @param function function to execute.
|
||||
*/
|
||||
public static void assertKeyIsProtected(IntSupplier function) {
|
||||
assertEquals(SOPGPException.KeyIsProtected.EXIT_CODE, function.getAsInt());
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the execution of the given function returns error code 69
|
||||
* (which corresponds to {@link sop.exception.SOPGPException.UnsupportedSubcommand}).
|
||||
*
|
||||
* @param function function to execute.
|
||||
*/
|
||||
public static void assertUnsupportedSubcommand(IntSupplier function) {
|
||||
assertEquals(SOPGPException.UnsupportedSubcommand.EXIT_CODE, function.getAsInt());
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the execution of the given function returns error code 71
|
||||
* (which corresponds to {@link sop.exception.SOPGPException.UnsupportedSpecialPrefix}).
|
||||
*
|
||||
* @param function function to execute.
|
||||
*/
|
||||
public static void assertUnsupportedSpecialPrefix(IntSupplier function) {
|
||||
assertEquals(SOPGPException.UnsupportedSpecialPrefix.EXIT_CODE, function.getAsInt());
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the execution of the given function returns error code 73
|
||||
* (which corresponds to {@link sop.exception.SOPGPException.AmbiguousInput}).
|
||||
*
|
||||
* @param function function to execute.
|
||||
*/
|
||||
public static void assertAmbiguousInput(IntSupplier function) {
|
||||
assertEquals(SOPGPException.AmbiguousInput.EXIT_CODE, function.getAsInt());
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the execution of the given function returns error code 79
|
||||
* (which corresponds to {@link sop.exception.SOPGPException.KeyCannotSign}).
|
||||
*
|
||||
* @param function function to execute.
|
||||
*/
|
||||
public static void assertKeyCannotSign(IntSupplier function) {
|
||||
assertEquals(SOPGPException.KeyCannotSign.EXIT_CODE, function.getAsInt());
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the execution of the given function returns error code 83
|
||||
* (which corresponds to {@link sop.exception.SOPGPException.IncompatibleOptions}).
|
||||
*
|
||||
* @param function function to execute.
|
||||
*/
|
||||
public static void assertIncompatibleOptions(IntSupplier function) {
|
||||
assertEquals(SOPGPException.IncompatibleOptions.EXIT_CODE, function.getAsInt());
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the execution of the given function returns error code 89
|
||||
* (which corresponds to {@link sop.exception.SOPGPException.UnsupportedProfile}).
|
||||
*
|
||||
* @param function function to execute.
|
||||
*/
|
||||
public static void assertUnsupportedProfile(IntSupplier function) {
|
||||
assertEquals(SOPGPException.UnsupportedProfile.EXIT_CODE, function.getAsInt());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sop.testsuite.assertions;
|
||||
|
||||
import sop.Verification;
|
||||
import sop.enums.SignatureMode;
|
||||
import sop.testsuite.JUtils;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public final class VerificationAssert {
|
||||
|
||||
private final Verification verification;
|
||||
|
||||
public static VerificationAssert assertThatVerification(Verification verification) {
|
||||
return new VerificationAssert(verification);
|
||||
}
|
||||
|
||||
private VerificationAssert(Verification verification) {
|
||||
this.verification = verification;
|
||||
}
|
||||
|
||||
public VerificationAssert issuedBy(String signingKeyFingerprint, String primaryFingerprint) {
|
||||
return isBySigningKey(signingKeyFingerprint)
|
||||
.issuedBy(primaryFingerprint);
|
||||
}
|
||||
|
||||
public VerificationAssert issuedBy(String primaryFingerprint) {
|
||||
assertEquals(primaryFingerprint, verification.getSigningCertFingerprint());
|
||||
return this;
|
||||
}
|
||||
|
||||
public VerificationAssert isBySigningKey(String signingKeyFingerprint) {
|
||||
assertEquals(signingKeyFingerprint, verification.getSigningKeyFingerprint());
|
||||
return this;
|
||||
}
|
||||
|
||||
public VerificationAssert isCreatedAt(Date creationDate) {
|
||||
JUtils.assertDateEquals(creationDate, verification.getCreationTime());
|
||||
return this;
|
||||
}
|
||||
|
||||
public VerificationAssert hasDescription(String description) {
|
||||
assertEquals(description, verification.getDescription().get());
|
||||
return this;
|
||||
}
|
||||
|
||||
public VerificationAssert hasDescriptionOrNull(String description) {
|
||||
if (verification.getDescription().isEmpty()) {
|
||||
return this;
|
||||
}
|
||||
|
||||
return hasDescription(description);
|
||||
}
|
||||
|
||||
public VerificationAssert hasMode(SignatureMode mode) {
|
||||
assertEquals(mode, verification.getSignatureMode().get());
|
||||
return this;
|
||||
}
|
||||
|
||||
public VerificationAssert hasModeOrNull(SignatureMode mode) {
|
||||
if (verification.getSignatureMode().isEmpty()) {
|
||||
return this;
|
||||
}
|
||||
return hasMode(mode);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sop.testsuite.assertions;
|
||||
|
||||
import sop.Verification;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
public final class VerificationListAssert {
|
||||
|
||||
private final List<Verification> verificationList = new ArrayList<>();
|
||||
|
||||
private VerificationListAssert(List<Verification> verifications) {
|
||||
this.verificationList.addAll(verifications);
|
||||
}
|
||||
|
||||
public static VerificationListAssert assertThatVerificationList(List<Verification> verifications) {
|
||||
return new VerificationListAssert(verifications);
|
||||
}
|
||||
|
||||
public VerificationListAssert isEmpty() {
|
||||
assertTrue(verificationList.isEmpty());
|
||||
return this;
|
||||
}
|
||||
|
||||
public VerificationListAssert isNotEmpty() {
|
||||
assertFalse(verificationList.isEmpty());
|
||||
return this;
|
||||
}
|
||||
|
||||
public VerificationListAssert sizeEquals(int size) {
|
||||
assertEquals(size, verificationList.size());
|
||||
return this;
|
||||
}
|
||||
|
||||
public VerificationAssert hasSingleItem() {
|
||||
sizeEquals(1);
|
||||
return VerificationAssert.assertThatVerification(verificationList.get(0));
|
||||
}
|
||||
|
||||
public VerificationListAssert containsVerificationByCert(String primaryFingerprint) {
|
||||
for (Verification verification : verificationList) {
|
||||
if (primaryFingerprint.equals(verification.getSigningCertFingerprint())) {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
fail("No verification was issued by certificate " + primaryFingerprint);
|
||||
return this;
|
||||
}
|
||||
|
||||
public VerificationListAssert containsVerificationBy(String signingKeyFingerprint, String primaryFingerprint) {
|
||||
for (Verification verification : verificationList) {
|
||||
if (primaryFingerprint.equals(verification.getSigningCertFingerprint()) &&
|
||||
signingKeyFingerprint.equals(verification.getSigningKeyFingerprint())) {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
fail("No verification was issued by key " + signingKeyFingerprint + " of cert " + primaryFingerprint);
|
||||
return this;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
/**
|
||||
* DSL for assertions on SOP objects.
|
||||
*/
|
||||
package sop.testsuite.assertions;
|
|
@ -0,0 +1,62 @@
|
|||
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sop.testsuite.operation;
|
||||
|
||||
import org.junit.jupiter.api.Named;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import sop.SOP;
|
||||
import sop.testsuite.AbortOnUnsupportedOption;
|
||||
import sop.testsuite.AbortOnUnsupportedOptionExtension;
|
||||
import sop.testsuite.SOPInstanceFactory;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@ExtendWith(AbortOnUnsupportedOptionExtension.class)
|
||||
@AbortOnUnsupportedOption
|
||||
public abstract class AbstractSOPTest {
|
||||
|
||||
private static final List<Arguments> backends = new ArrayList<>();
|
||||
|
||||
static {
|
||||
initBackends();
|
||||
}
|
||||
|
||||
// populate instances list via configured test subject factory
|
||||
private static void initBackends() {
|
||||
String factoryName = System.getenv("test.implementation");
|
||||
if (factoryName == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
SOPInstanceFactory factory;
|
||||
try {
|
||||
Class<?> testSubjectFactoryClass = Class.forName(factoryName);
|
||||
factory = (SOPInstanceFactory) testSubjectFactoryClass
|
||||
.getDeclaredConstructor().newInstance();
|
||||
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException |
|
||||
InvocationTargetException | NoSuchMethodException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
Map<String, SOP> testSubjects = factory.provideSOPInstances();
|
||||
for (String key : testSubjects.keySet()) {
|
||||
backends.add(Arguments.of(Named.of(key, testSubjects.get(key))));
|
||||
}
|
||||
}
|
||||
|
||||
public static Stream<Arguments> provideBackends() {
|
||||
return backends.stream();
|
||||
}
|
||||
|
||||
public static boolean hasBackends() {
|
||||
return !backends.isEmpty();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,243 @@
|
|||
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sop.testsuite.operation;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.condition.EnabledIf;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import sop.SOP;
|
||||
import sop.testsuite.JUtils;
|
||||
import sop.testsuite.TestData;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
|
||||
@EnabledIf("sop.testsuite.operation.AbstractSOPTest#hasBackends")
|
||||
public class ArmorDearmorTest {
|
||||
|
||||
static Stream<Arguments> provideInstances() {
|
||||
return AbstractSOPTest.provideBackends();
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void dearmorArmorAliceKey(SOP sop) throws IOException {
|
||||
byte[] aliceKey = TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] dearmored = sop.dearmor()
|
||||
.data(aliceKey)
|
||||
.getBytes();
|
||||
|
||||
Assertions.assertFalse(JUtils.arrayStartsWith(dearmored, TestData.BEGIN_PGP_PRIVATE_KEY_BLOCK));
|
||||
|
||||
byte[] armored = sop.armor()
|
||||
.data(dearmored)
|
||||
.getBytes();
|
||||
|
||||
JUtils.assertArrayStartsWith(armored, TestData.BEGIN_PGP_PRIVATE_KEY_BLOCK);
|
||||
JUtils.assertArrayEndsWithIgnoreNewlines(armored, TestData.END_PGP_PRIVATE_KEY_BLOCK);
|
||||
|
||||
// assertAsciiArmorEquals(aliceKey, armored);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void dearmorArmorAliceCert(SOP sop) throws IOException {
|
||||
byte[] aliceCert = TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] dearmored = sop.dearmor()
|
||||
.data(aliceCert)
|
||||
.getBytes();
|
||||
|
||||
Assertions.assertFalse(JUtils.arrayStartsWith(dearmored, TestData.BEGIN_PGP_PUBLIC_KEY_BLOCK));
|
||||
|
||||
byte[] armored = sop.armor()
|
||||
.data(dearmored)
|
||||
.getBytes();
|
||||
|
||||
JUtils.assertArrayStartsWith(armored, TestData.BEGIN_PGP_PUBLIC_KEY_BLOCK);
|
||||
JUtils.assertArrayEndsWithIgnoreNewlines(armored, TestData.END_PGP_PUBLIC_KEY_BLOCK);
|
||||
|
||||
// assertAsciiArmorEquals(aliceCert, armored);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void dearmorArmorBobKey(SOP sop) throws IOException {
|
||||
byte[] bobKey = TestData.BOB_KEY.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] dearmored = sop.dearmor()
|
||||
.data(bobKey)
|
||||
.getBytes();
|
||||
|
||||
Assertions.assertFalse(JUtils.arrayStartsWith(dearmored, TestData.BEGIN_PGP_PRIVATE_KEY_BLOCK));
|
||||
|
||||
byte[] armored = sop.armor()
|
||||
.data(dearmored)
|
||||
.getBytes();
|
||||
|
||||
JUtils.assertArrayStartsWith(armored, TestData.BEGIN_PGP_PRIVATE_KEY_BLOCK);
|
||||
JUtils.assertArrayEndsWithIgnoreNewlines(armored, TestData.END_PGP_PRIVATE_KEY_BLOCK);
|
||||
|
||||
// assertAsciiArmorEquals(bobKey, armored);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void dearmorArmorBobCert(SOP sop) throws IOException {
|
||||
byte[] bobCert = TestData.BOB_CERT.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] dearmored = sop.dearmor()
|
||||
.data(bobCert)
|
||||
.getBytes();
|
||||
|
||||
Assertions.assertFalse(JUtils.arrayStartsWith(dearmored, TestData.BEGIN_PGP_PUBLIC_KEY_BLOCK));
|
||||
|
||||
byte[] armored = sop.armor()
|
||||
.data(dearmored)
|
||||
.getBytes();
|
||||
|
||||
JUtils.assertArrayStartsWith(armored, TestData.BEGIN_PGP_PUBLIC_KEY_BLOCK);
|
||||
JUtils.assertArrayEndsWithIgnoreNewlines(armored, TestData.END_PGP_PUBLIC_KEY_BLOCK);
|
||||
|
||||
// assertAsciiArmorEquals(bobCert, armored);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void dearmorArmorCarolKey(SOP sop) throws IOException {
|
||||
byte[] carolKey = TestData.CAROL_KEY.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] dearmored = sop.dearmor()
|
||||
.data(carolKey)
|
||||
.getBytes();
|
||||
|
||||
Assertions.assertFalse(JUtils.arrayStartsWith(dearmored, TestData.BEGIN_PGP_PRIVATE_KEY_BLOCK));
|
||||
|
||||
byte[] armored = sop.armor()
|
||||
.data(dearmored)
|
||||
.getBytes();
|
||||
|
||||
JUtils.assertArrayStartsWith(armored, TestData.BEGIN_PGP_PRIVATE_KEY_BLOCK);
|
||||
JUtils.assertArrayEndsWithIgnoreNewlines(armored, TestData.END_PGP_PRIVATE_KEY_BLOCK);
|
||||
|
||||
// assertAsciiArmorEquals(carolKey, armored);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void dearmorArmorCarolCert(SOP sop) throws IOException {
|
||||
byte[] carolCert = TestData.CAROL_CERT.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] dearmored = sop.dearmor()
|
||||
.data(carolCert)
|
||||
.getBytes();
|
||||
|
||||
Assertions.assertFalse(JUtils.arrayStartsWith(dearmored, TestData.BEGIN_PGP_PUBLIC_KEY_BLOCK));
|
||||
|
||||
byte[] armored = sop.armor()
|
||||
.data(dearmored)
|
||||
.getBytes();
|
||||
|
||||
JUtils.assertArrayStartsWith(armored, TestData.BEGIN_PGP_PUBLIC_KEY_BLOCK);
|
||||
JUtils.assertArrayEndsWithIgnoreNewlines(armored, TestData.END_PGP_PUBLIC_KEY_BLOCK);
|
||||
|
||||
// assertAsciiArmorEquals(carolCert, armored);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
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();
|
||||
|
||||
Assertions.assertFalse(JUtils.arrayStartsWith(dearmored, TestData.BEGIN_PGP_MESSAGE));
|
||||
|
||||
byte[] armored = sop.armor()
|
||||
.data(dearmored)
|
||||
.getBytes();
|
||||
|
||||
JUtils.assertArrayStartsWith(armored, TestData.BEGIN_PGP_MESSAGE);
|
||||
JUtils.assertArrayEndsWithIgnoreNewlines(armored, TestData.END_PGP_MESSAGE);
|
||||
|
||||
// assertAsciiArmorEquals(message, armored);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
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();
|
||||
|
||||
Assertions.assertFalse(JUtils.arrayStartsWith(dearmored, TestData.BEGIN_PGP_SIGNATURE));
|
||||
|
||||
byte[] armored = sop.armor()
|
||||
.data(dearmored)
|
||||
.getBytes();
|
||||
|
||||
JUtils.assertArrayStartsWith(armored, TestData.BEGIN_PGP_SIGNATURE);
|
||||
JUtils.assertArrayEndsWithIgnoreNewlines(armored, TestData.END_PGP_SIGNATURE);
|
||||
|
||||
JUtils.assertAsciiArmorEquals(signature, armored);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
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("provideInstances")
|
||||
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();
|
||||
|
||||
JUtils.assertAsciiArmorEquals(armored, armoredAgain);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,124 @@
|
|||
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sop.testsuite.operation;
|
||||
|
||||
import org.junit.jupiter.api.condition.EnabledIf;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import sop.SOP;
|
||||
import sop.exception.SOPGPException;
|
||||
import sop.testsuite.JUtils;
|
||||
import sop.testsuite.TestData;
|
||||
import sop.util.UTF8Util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
@EnabledIf("sop.testsuite.operation.AbstractSOPTest#hasBackends")
|
||||
public class ChangeKeyPasswordTest extends AbstractSOPTest {
|
||||
|
||||
static Stream<Arguments> provideInstances() {
|
||||
return AbstractSOPTest.provideBackends();
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void changePasswordFromUnprotectedToProtected(SOP sop) throws IOException {
|
||||
byte[] unprotectedKey = sop.generateKey().generate().getBytes();
|
||||
byte[] password = "sw0rdf1sh".getBytes(UTF8Util.UTF8);
|
||||
byte[] protectedKey = sop.changeKeyPassword().newKeyPassphrase(password).keys(unprotectedKey).getBytes();
|
||||
|
||||
sop.sign().withKeyPassword(password).key(protectedKey).data("Test123".getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void changePasswordFromUnprotectedToUnprotected(SOP sop) throws IOException {
|
||||
byte[] unprotectedKey = sop.generateKey().noArmor().generate().getBytes();
|
||||
byte[] stillUnprotectedKey = sop.changeKeyPassword().noArmor().keys(unprotectedKey).getBytes();
|
||||
|
||||
assertArrayEquals(unprotectedKey, stillUnprotectedKey);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void changePasswordFromProtectedToUnprotected(SOP sop) throws IOException {
|
||||
byte[] password = "sw0rdf1sh".getBytes(UTF8Util.UTF8);
|
||||
byte[] protectedKey = sop.generateKey().withKeyPassword(password).generate().getBytes();
|
||||
byte[] unprotectedKey = sop.changeKeyPassword()
|
||||
.oldKeyPassphrase(password)
|
||||
.keys(protectedKey).getBytes();
|
||||
|
||||
sop.sign().key(unprotectedKey).data("Test123".getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void changePasswordFromProtectedToDifferentProtected(SOP sop) throws IOException {
|
||||
byte[] oldPassword = "sw0rdf1sh".getBytes(UTF8Util.UTF8);
|
||||
byte[] newPassword = "0r4ng3".getBytes(UTF8Util.UTF8);
|
||||
byte[] protectedKey = sop.generateKey().withKeyPassword(oldPassword).generate().getBytes();
|
||||
byte[] reprotectedKey = sop.changeKeyPassword()
|
||||
.oldKeyPassphrase(oldPassword)
|
||||
.newKeyPassphrase(newPassword)
|
||||
.keys(protectedKey).getBytes();
|
||||
|
||||
sop.sign().key(reprotectedKey).withKeyPassword(newPassword).data("Test123".getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void changePasswordWithWrongOldPasswordFails(SOP sop) throws IOException {
|
||||
byte[] oldPassword = "sw0rdf1sh".getBytes(UTF8Util.UTF8);
|
||||
byte[] newPassword = "monkey123".getBytes(UTF8Util.UTF8);
|
||||
byte[] wrongPassword = "0r4ng3".getBytes(UTF8Util.UTF8);
|
||||
|
||||
byte[] protectedKey = sop.generateKey().withKeyPassword(oldPassword).generate().getBytes();
|
||||
assertThrows(SOPGPException.KeyIsProtected.class, () -> sop.changeKeyPassword()
|
||||
.oldKeyPassphrase(wrongPassword)
|
||||
.newKeyPassphrase(newPassword)
|
||||
.keys(protectedKey).getBytes());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void nonUtf8PasswordsFail(SOP sop) {
|
||||
assertThrows(SOPGPException.PasswordNotHumanReadable.class, () ->
|
||||
sop.changeKeyPassword().oldKeyPassphrase(new byte[] {(byte) 0xff, (byte) 0xfe}));
|
||||
assertThrows(SOPGPException.PasswordNotHumanReadable.class, () ->
|
||||
sop.changeKeyPassword().newKeyPassphrase(new byte[] {(byte) 0xff, (byte) 0xfe}));
|
||||
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void testNoArmor(SOP sop) throws IOException {
|
||||
byte[] oldPassword = "sw0rdf1sh".getBytes(UTF8Util.UTF8);
|
||||
byte[] newPassword = "0r4ng3".getBytes(UTF8Util.UTF8);
|
||||
byte[] protectedKey = sop.generateKey().withKeyPassword(oldPassword).generate().getBytes();
|
||||
|
||||
byte[] armored = sop.changeKeyPassword()
|
||||
.oldKeyPassphrase(oldPassword)
|
||||
.newKeyPassphrase(newPassword)
|
||||
.keys(protectedKey)
|
||||
.getBytes();
|
||||
JUtils.assertArrayStartsWith(armored, TestData.BEGIN_PGP_PRIVATE_KEY_BLOCK);
|
||||
|
||||
byte[] unarmored = sop.changeKeyPassword()
|
||||
.noArmor()
|
||||
.oldKeyPassphrase(oldPassword)
|
||||
.newKeyPassphrase(newPassword)
|
||||
.keys(protectedKey)
|
||||
.getBytes();
|
||||
assertFalse(JUtils.arrayStartsWith(unarmored, TestData.BEGIN_PGP_PRIVATE_KEY_BLOCK));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sop.testsuite.operation;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.condition.EnabledIf;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import sop.ByteArrayAndResult;
|
||||
import sop.DecryptionResult;
|
||||
import sop.SOP;
|
||||
import sop.SessionKey;
|
||||
import sop.testsuite.TestData;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
@EnabledIf("sop.testsuite.operation.AbstractSOPTest#hasBackends")
|
||||
public class DecryptWithSessionKeyTest extends AbstractSOPTest {
|
||||
|
||||
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";
|
||||
|
||||
static Stream<Arguments> provideInstances() {
|
||||
return provideBackends();
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void testDecryptAndExtractSessionKey(SOP sop) throws IOException {
|
||||
ByteArrayAndResult<DecryptionResult> bytesAndResult = sop.decrypt()
|
||||
.withKey(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.ciphertext(CIPHERTEXT.getBytes(StandardCharsets.UTF_8))
|
||||
.toByteArrayAndResult();
|
||||
|
||||
assertEquals(SESSION_KEY, bytesAndResult.getResult().getSessionKey().get().toString());
|
||||
|
||||
Assertions.assertArrayEquals(TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8), bytesAndResult.getBytes());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void testDecryptWithSessionKey(SOP sop) throws IOException {
|
||||
byte[] decrypted = sop.decrypt()
|
||||
.withSessionKey(SessionKey.fromString(SESSION_KEY))
|
||||
.ciphertext(CIPHERTEXT.getBytes(StandardCharsets.UTF_8))
|
||||
.toByteArrayAndResult()
|
||||
.getBytes();
|
||||
|
||||
Assertions.assertArrayEquals(TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8), decrypted);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,312 @@
|
|||
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sop.testsuite.operation;
|
||||
|
||||
import org.junit.jupiter.api.condition.EnabledIf;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import sop.SOP;
|
||||
import sop.Verification;
|
||||
import sop.enums.SignAs;
|
||||
import sop.enums.SignatureMode;
|
||||
import sop.exception.SOPGPException;
|
||||
import sop.testsuite.JUtils;
|
||||
import sop.testsuite.TestData;
|
||||
import sop.testsuite.assertions.VerificationListAssert;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
@EnabledIf("sop.testsuite.operation.AbstractSOPTest#hasBackends")
|
||||
public class DetachedSignDetachedVerifyTest extends AbstractSOPTest {
|
||||
|
||||
static Stream<Arguments> provideInstances() {
|
||||
return provideBackends();
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void signVerifyWithAliceKey(SOP sop) throws IOException {
|
||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] signature = sop.detachedSign()
|
||||
.key(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.data(message)
|
||||
.toByteArrayAndResult()
|
||||
.getBytes();
|
||||
|
||||
List<Verification> verificationList = sop.detachedVerify()
|
||||
.cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.signatures(signature)
|
||||
.data(message);
|
||||
|
||||
VerificationListAssert.assertThatVerificationList(verificationList)
|
||||
.isNotEmpty()
|
||||
.hasSingleItem()
|
||||
.issuedBy(TestData.ALICE_SIGNING_FINGERPRINT, TestData.ALICE_PRIMARY_FINGERPRINT)
|
||||
.hasModeOrNull(SignatureMode.binary);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void signVerifyTextModeWithAliceKey(SOP sop) throws IOException {
|
||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] signature = sop.detachedSign()
|
||||
.key(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.mode(SignAs.text)
|
||||
.data(message)
|
||||
.toByteArrayAndResult()
|
||||
.getBytes();
|
||||
|
||||
List<Verification> verificationList = sop.detachedVerify()
|
||||
.cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.signatures(signature)
|
||||
.data(message);
|
||||
|
||||
VerificationListAssert.assertThatVerificationList(verificationList)
|
||||
.isNotEmpty()
|
||||
.hasSingleItem()
|
||||
.issuedBy(TestData.ALICE_SIGNING_FINGERPRINT, TestData.ALICE_PRIMARY_FINGERPRINT)
|
||||
.hasModeOrNull(SignatureMode.text);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void verifyKnownMessageWithAliceCert(SOP sop) throws IOException {
|
||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
byte[] signature = TestData.ALICE_DETACHED_SIGNED_MESSAGE.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
List<Verification> verificationList = sop.detachedVerify()
|
||||
.cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.signatures(signature)
|
||||
.data(message);
|
||||
|
||||
VerificationListAssert.assertThatVerificationList(verificationList)
|
||||
.isNotEmpty()
|
||||
.hasSingleItem()
|
||||
.issuedBy(TestData.ALICE_SIGNING_FINGERPRINT, TestData.ALICE_PRIMARY_FINGERPRINT);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void signVerifyWithBobKey(SOP sop) throws IOException {
|
||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] signature = sop.detachedSign()
|
||||
.key(TestData.BOB_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.data(message)
|
||||
.toByteArrayAndResult()
|
||||
.getBytes();
|
||||
|
||||
List<Verification> verificationList = sop.detachedVerify()
|
||||
.cert(TestData.BOB_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.signatures(signature)
|
||||
.data(message);
|
||||
|
||||
VerificationListAssert.assertThatVerificationList(verificationList)
|
||||
.isNotEmpty()
|
||||
.hasSingleItem()
|
||||
.issuedBy(TestData.BOB_SIGNING_FINGERPRINT, TestData.BOB_PRIMARY_FINGERPRINT);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void signVerifyWithCarolKey(SOP sop) throws IOException {
|
||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] signature = sop.detachedSign()
|
||||
.key(TestData.CAROL_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.data(message)
|
||||
.toByteArrayAndResult()
|
||||
.getBytes();
|
||||
|
||||
List<Verification> verificationList = sop.detachedVerify()
|
||||
.cert(TestData.CAROL_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.signatures(signature)
|
||||
.data(message);
|
||||
|
||||
VerificationListAssert.assertThatVerificationList(verificationList)
|
||||
.isNotEmpty()
|
||||
.hasSingleItem()
|
||||
.issuedBy(TestData.CAROL_SIGNING_FINGERPRINT, TestData.CAROL_PRIMARY_FINGERPRINT);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void signVerifyWithEncryptedKey(SOP sop) throws IOException {
|
||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] signature = sop.detachedSign()
|
||||
.key(TestData.PASSWORD_PROTECTED_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.withKeyPassword(TestData.PASSWORD)
|
||||
.data(message)
|
||||
.toByteArrayAndResult()
|
||||
.getBytes();
|
||||
|
||||
JUtils.assertArrayStartsWith(signature, TestData.BEGIN_PGP_SIGNATURE);
|
||||
|
||||
List<Verification> verificationList = sop.detachedVerify()
|
||||
.cert(TestData.PASSWORD_PROTECTED_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.signatures(signature)
|
||||
.data(message);
|
||||
|
||||
VerificationListAssert.assertThatVerificationList(verificationList)
|
||||
.isNotEmpty()
|
||||
.hasSingleItem()
|
||||
.issuedBy(TestData.PASSWORD_PROTECTED_SIGNING_FINGERPRINT, TestData.PASSWORD_PROTECTED_PRIMARY_FINGERPRINT);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void signArmorVerifyWithBobKey(SOP sop) throws IOException {
|
||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] signature = sop.detachedSign()
|
||||
.key(TestData.BOB_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.noArmor()
|
||||
.data(message)
|
||||
.toByteArrayAndResult()
|
||||
.getBytes();
|
||||
|
||||
byte[] armored = sop.armor()
|
||||
.data(signature)
|
||||
.getBytes();
|
||||
|
||||
List<Verification> verificationList = sop.detachedVerify()
|
||||
.cert(TestData.BOB_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.signatures(armored)
|
||||
.data(message);
|
||||
|
||||
VerificationListAssert.assertThatVerificationList(verificationList)
|
||||
.isNotEmpty()
|
||||
.hasSingleItem()
|
||||
.issuedBy(TestData.BOB_SIGNING_FINGERPRINT, TestData.BOB_PRIMARY_FINGERPRINT);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void verifyNotAfterThrowsNoSignature(SOP sop) {
|
||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
byte[] signature = TestData.ALICE_DETACHED_SIGNED_MESSAGE.getBytes(StandardCharsets.UTF_8);
|
||||
Date beforeSignature = new Date(TestData.ALICE_DETACHED_SIGNED_MESSAGE_DATE.getTime() - 1000); // 1 sec before sig
|
||||
|
||||
assertThrows(SOPGPException.NoSignature.class, () -> sop.detachedVerify()
|
||||
.cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.notAfter(beforeSignature)
|
||||
.signatures(signature)
|
||||
.data(message));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void verifyNotBeforeThrowsNoSignature(SOP sop) {
|
||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
byte[] signature = TestData.ALICE_DETACHED_SIGNED_MESSAGE.getBytes(StandardCharsets.UTF_8);
|
||||
Date afterSignature = new Date(TestData.ALICE_DETACHED_SIGNED_MESSAGE_DATE.getTime() + 1000); // 1 sec after sig
|
||||
|
||||
assertThrows(SOPGPException.NoSignature.class, () -> sop.detachedVerify()
|
||||
.cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.notBefore(afterSignature)
|
||||
.signatures(signature)
|
||||
.data(message));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void signWithAliceVerifyWithBobThrowsNoSignature(SOP sop) throws IOException {
|
||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
byte[] signatures = sop.detachedSign()
|
||||
.key(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.data(message)
|
||||
.toByteArrayAndResult()
|
||||
.getBytes();
|
||||
|
||||
assertThrows(SOPGPException.NoSignature.class, () -> sop.detachedVerify()
|
||||
.cert(TestData.BOB_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.signatures(signatures)
|
||||
.data(message));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void signVerifyWithEncryptedKeyWithoutPassphraseFails(SOP sop) {
|
||||
assertThrows(SOPGPException.KeyIsProtected.class, () ->
|
||||
sop.detachedSign()
|
||||
.key(TestData.PASSWORD_PROTECTED_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.data(TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8))
|
||||
.toByteArrayAndResult()
|
||||
.getBytes());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void signWithProtectedKeyAndMultiplePassphrasesTest(SOP sop)
|
||||
throws IOException {
|
||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] signature = sop.sign()
|
||||
.key(TestData.PASSWORD_PROTECTED_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.withKeyPassword("wrong")
|
||||
.withKeyPassword(TestData.PASSWORD) // correct
|
||||
.withKeyPassword("wrong2")
|
||||
.data(message)
|
||||
.toByteArrayAndResult()
|
||||
.getBytes();
|
||||
|
||||
List<Verification> verificationList = sop.verify()
|
||||
.cert(TestData.PASSWORD_PROTECTED_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.signatures(signature)
|
||||
.data(message);
|
||||
|
||||
VerificationListAssert.assertThatVerificationList(verificationList)
|
||||
.isNotEmpty()
|
||||
.hasSingleItem()
|
||||
.issuedBy(TestData.PASSWORD_PROTECTED_SIGNING_FINGERPRINT, TestData.PASSWORD_PROTECTED_PRIMARY_FINGERPRINT);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void verifyMissingCertCausesMissingArg(SOP sop) {
|
||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
assertThrows(SOPGPException.MissingArg.class, () ->
|
||||
sop.verify()
|
||||
.signatures(TestData.ALICE_DETACHED_SIGNED_MESSAGE.getBytes(StandardCharsets.UTF_8))
|
||||
.data(message));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void signVerifyWithMultipleKeys(SOP sop) throws IOException {
|
||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
byte[] signatures = sop.detachedSign()
|
||||
.key(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.key(TestData.BOB_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.data(message)
|
||||
.toByteArrayAndResult()
|
||||
.getBytes();
|
||||
|
||||
List<Verification> verificationList = sop.detachedVerify()
|
||||
.cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.cert(TestData.BOB_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.signatures(signatures)
|
||||
.data(message);
|
||||
|
||||
VerificationListAssert.assertThatVerificationList(verificationList)
|
||||
.isNotEmpty()
|
||||
.sizeEquals(2)
|
||||
.containsVerificationBy(TestData.ALICE_SIGNING_FINGERPRINT, TestData.ALICE_PRIMARY_FINGERPRINT)
|
||||
.containsVerificationBy(TestData.BOB_SIGNING_FINGERPRINT, TestData.BOB_PRIMARY_FINGERPRINT);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,341 @@
|
|||
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sop.testsuite.operation;
|
||||
|
||||
import org.junit.jupiter.api.condition.EnabledIf;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import sop.ByteArrayAndResult;
|
||||
import sop.DecryptionResult;
|
||||
import sop.EncryptionResult;
|
||||
import sop.SOP;
|
||||
import sop.SessionKey;
|
||||
import sop.Verification;
|
||||
import sop.enums.EncryptAs;
|
||||
import sop.enums.SignatureMode;
|
||||
import sop.exception.SOPGPException;
|
||||
import sop.testsuite.TestData;
|
||||
import sop.testsuite.assertions.VerificationListAssert;
|
||||
import sop.util.Optional;
|
||||
import sop.util.UTCUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.ParseException;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
@EnabledIf("sop.testsuite.operation.AbstractSOPTest#hasBackends")
|
||||
public class EncryptDecryptTest extends AbstractSOPTest {
|
||||
|
||||
static Stream<Arguments> provideInstances() {
|
||||
return provideBackends();
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void encryptDecryptRoundTripPasswordTest(SOP sop) throws IOException {
|
||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
ByteArrayAndResult<EncryptionResult> encResult = sop.encrypt()
|
||||
.withPassword("sw0rdf1sh")
|
||||
.plaintext(message)
|
||||
.toByteArrayAndResult();
|
||||
|
||||
byte[] ciphertext = encResult.getBytes();
|
||||
Optional<SessionKey> encSessionKey = encResult.getResult().getSessionKey();
|
||||
|
||||
ByteArrayAndResult<DecryptionResult> decResult = sop.decrypt()
|
||||
.withPassword("sw0rdf1sh")
|
||||
.ciphertext(ciphertext)
|
||||
.toByteArrayAndResult();
|
||||
|
||||
byte[] plaintext = decResult.getBytes();
|
||||
Optional<SessionKey> decSessionKey = decResult.getResult().getSessionKey();
|
||||
|
||||
assertArrayEquals(message, plaintext);
|
||||
if (encSessionKey.isPresent() && decSessionKey.isPresent()) {
|
||||
assertEquals(encSessionKey.get(), decSessionKey.get());
|
||||
}
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void encryptDecryptRoundTripAliceTest(SOP sop) throws IOException {
|
||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
byte[] ciphertext = sop.encrypt()
|
||||
.withCert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.plaintext(message)
|
||||
.toByteArrayAndResult()
|
||||
.getBytes();
|
||||
|
||||
ByteArrayAndResult<DecryptionResult> bytesAndResult = sop.decrypt()
|
||||
.withKey(TestData.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("provideInstances")
|
||||
public void encryptDecryptRoundTripBobTest(SOP sop) throws IOException {
|
||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
byte[] ciphertext = sop.encrypt()
|
||||
.withCert(TestData.BOB_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.plaintext(message)
|
||||
.toByteArrayAndResult()
|
||||
.getBytes();
|
||||
|
||||
byte[] plaintext = sop.decrypt()
|
||||
.withKey(TestData.BOB_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.ciphertext(ciphertext)
|
||||
.toByteArrayAndResult()
|
||||
.getBytes();
|
||||
|
||||
assertArrayEquals(message, plaintext);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void encryptDecryptRoundTripCarolTest(SOP sop) throws IOException {
|
||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
byte[] ciphertext = sop.encrypt()
|
||||
.withCert(TestData.CAROL_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.plaintext(message)
|
||||
.toByteArrayAndResult()
|
||||
.getBytes();
|
||||
|
||||
byte[] plaintext = sop.decrypt()
|
||||
.withKey(TestData.CAROL_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.ciphertext(ciphertext)
|
||||
.toByteArrayAndResult()
|
||||
.getBytes();
|
||||
|
||||
assertArrayEquals(message, plaintext);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void encryptNoArmorThenArmorThenDecryptRoundTrip(SOP sop) throws IOException {
|
||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
byte[] ciphertext = sop.encrypt()
|
||||
.withCert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.noArmor()
|
||||
.plaintext(message)
|
||||
.toByteArrayAndResult()
|
||||
.getBytes();
|
||||
|
||||
byte[] armored = sop.armor()
|
||||
.data(ciphertext)
|
||||
.getBytes();
|
||||
|
||||
ByteArrayAndResult<DecryptionResult> bytesAndResult = sop.decrypt()
|
||||
.withKey(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.ciphertext(armored)
|
||||
.toByteArrayAndResult();
|
||||
|
||||
byte[] plaintext = bytesAndResult.getBytes();
|
||||
assertArrayEquals(message, plaintext);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void encryptSignDecryptVerifyRoundTripAliceTest(SOP sop) throws IOException {
|
||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
byte[] ciphertext = sop.encrypt()
|
||||
.withCert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.signWith(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.mode(EncryptAs.binary)
|
||||
.plaintext(message)
|
||||
.toByteArrayAndResult()
|
||||
.getBytes();
|
||||
|
||||
ByteArrayAndResult<DecryptionResult> bytesAndResult = sop.decrypt()
|
||||
.withKey(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.verifyWithCert(TestData.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();
|
||||
VerificationListAssert.assertThatVerificationList(verificationList)
|
||||
.isNotEmpty()
|
||||
.hasSingleItem()
|
||||
.issuedBy(TestData.ALICE_SIGNING_FINGERPRINT, TestData.ALICE_PRIMARY_FINGERPRINT)
|
||||
.hasModeOrNull(SignatureMode.binary);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void encryptSignAsTextDecryptVerifyRoundTripAliceTest(SOP sop) throws IOException {
|
||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
byte[] ciphertext = sop.encrypt()
|
||||
.withCert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.signWith(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.mode(EncryptAs.text)
|
||||
.plaintext(message)
|
||||
.toByteArrayAndResult()
|
||||
.getBytes();
|
||||
|
||||
ByteArrayAndResult<DecryptionResult> bytesAndResult = sop.decrypt()
|
||||
.withKey(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.verifyWithCert(TestData.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();
|
||||
VerificationListAssert.assertThatVerificationList(verificationList)
|
||||
.hasSingleItem()
|
||||
.issuedBy(TestData.ALICE_SIGNING_FINGERPRINT, TestData.ALICE_PRIMARY_FINGERPRINT)
|
||||
.hasModeOrNull(SignatureMode.text);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
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)
|
||||
.toByteArrayAndResult()
|
||||
.getBytes();
|
||||
|
||||
ByteArrayAndResult<DecryptionResult> bytesAndResult = sop.decrypt()
|
||||
.withKey(key)
|
||||
.withKeyPassword(keyPassword)
|
||||
.verifyWithCert(cert)
|
||||
.ciphertext(ciphertext)
|
||||
.toByteArrayAndResult();
|
||||
|
||||
List<Verification> verifications = bytesAndResult.getResult().getVerifications();
|
||||
VerificationListAssert.assertThatVerificationList(verifications)
|
||||
.isNotEmpty()
|
||||
.hasSingleItem();
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void decryptVerifyNotAfterTest(SOP sop) throws ParseException {
|
||||
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(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.verifyWithCert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.verifyNotAfter(beforeSignature)
|
||||
.ciphertext(message)
|
||||
.toByteArrayAndResult();
|
||||
|
||||
// Some implementations do not throw NoSignature and instead return an empty list.
|
||||
if (bytesAndResult.getResult().getVerifications().isEmpty()) {
|
||||
throw new SOPGPException.NoSignature("No verifiable signature found.");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void decryptVerifyNotBeforeTest(SOP sop) throws ParseException {
|
||||
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(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.verifyWithCert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.verifyNotBefore(afterSignature)
|
||||
.ciphertext(message)
|
||||
.toByteArrayAndResult();
|
||||
|
||||
// Some implementations do not throw NoSignature and instead return an empty list.
|
||||
if (bytesAndResult.getResult().getVerifications().isEmpty()) {
|
||||
throw new SOPGPException.NoSignature("No verifiable signature found.");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void missingArgsTest(SOP sop) {
|
||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
assertThrows(SOPGPException.MissingArg.class, () -> sop.encrypt()
|
||||
.plaintext(message)
|
||||
.toByteArrayAndResult()
|
||||
.getBytes());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void passingSecretKeysForPublicKeysFails(SOP sop) {
|
||||
assertThrows(SOPGPException.BadData.class, () ->
|
||||
sop.encrypt()
|
||||
.withCert(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.plaintext(TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8))
|
||||
.toByteArrayAndResult()
|
||||
.getBytes());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,117 @@
|
|||
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sop.testsuite.operation;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.condition.EnabledIf;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import sop.SOP;
|
||||
import sop.testsuite.JUtils;
|
||||
import sop.testsuite.TestData;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@EnabledIf("sop.testsuite.operation.AbstractSOPTest#hasBackends")
|
||||
public class ExtractCertTest extends AbstractSOPTest {
|
||||
|
||||
static Stream<Arguments> provideInstances() {
|
||||
return provideBackends();
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
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();
|
||||
JUtils.assertArrayStartsWith(cert, TestData.BEGIN_PGP_PUBLIC_KEY_BLOCK);
|
||||
JUtils.assertArrayEndsWithIgnoreNewlines(cert, TestData.END_PGP_PUBLIC_KEY_BLOCK);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void extractAliceCertFromAliceKeyTest(SOP sop) throws IOException {
|
||||
byte[] armoredCert = sop.extractCert()
|
||||
.key(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.getBytes();
|
||||
JUtils.assertAsciiArmorEquals(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8), armoredCert);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void extractBobsCertFromBobsKeyTest(SOP sop) throws IOException {
|
||||
byte[] armoredCert = sop.extractCert()
|
||||
.key(TestData.BOB_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.getBytes();
|
||||
JUtils.assertAsciiArmorEquals(TestData.BOB_CERT.getBytes(StandardCharsets.UTF_8), armoredCert);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void extractCarolsCertFromCarolsKeyTest(SOP sop) throws IOException {
|
||||
byte[] armoredCert = sop.extractCert()
|
||||
.key(TestData.CAROL_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.getBytes();
|
||||
JUtils.assertAsciiArmorEquals(TestData.CAROL_CERT.getBytes(StandardCharsets.UTF_8), armoredCert);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
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();
|
||||
|
||||
Assertions.assertFalse(JUtils.arrayStartsWith(cert, TestData.BEGIN_PGP_PUBLIC_KEY_BLOCK));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
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();
|
||||
|
||||
JUtils.assertArrayStartsWith(cert, TestData.BEGIN_PGP_PUBLIC_KEY_BLOCK);
|
||||
JUtils.assertArrayEndsWithIgnoreNewlines(cert, TestData.END_PGP_PUBLIC_KEY_BLOCK);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
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();
|
||||
|
||||
Assertions.assertFalse(JUtils.arrayStartsWith(cert, TestData.BEGIN_PGP_PUBLIC_KEY_BLOCK));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,121 @@
|
|||
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sop.testsuite.operation;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.condition.EnabledIf;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import sop.SOP;
|
||||
import sop.exception.SOPGPException;
|
||||
import sop.testsuite.JUtils;
|
||||
import sop.testsuite.TestData;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
@EnabledIf("sop.testsuite.operation.AbstractSOPTest#hasBackends")
|
||||
public class GenerateKeyTest extends AbstractSOPTest {
|
||||
|
||||
static Stream<Arguments> provideInstances() {
|
||||
return provideBackends();
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void generateKeyTest(SOP sop) throws IOException {
|
||||
byte[] key = sop.generateKey()
|
||||
.userId("Alice <alice@openpgp.org>")
|
||||
.generate()
|
||||
.getBytes();
|
||||
|
||||
JUtils.assertArrayStartsWith(key, TestData.BEGIN_PGP_PRIVATE_KEY_BLOCK);
|
||||
JUtils.assertArrayEndsWithIgnoreNewlines(key, TestData.END_PGP_PRIVATE_KEY_BLOCK);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void generateKeyNoArmor(SOP sop) throws IOException {
|
||||
byte[] key = sop.generateKey()
|
||||
.userId("Alice <alice@openpgp.org>")
|
||||
.noArmor()
|
||||
.generate()
|
||||
.getBytes();
|
||||
|
||||
Assertions.assertFalse(JUtils.arrayStartsWith(key, TestData.BEGIN_PGP_PRIVATE_KEY_BLOCK));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void generateKeyWithMultipleUserIdsTest(SOP sop) throws IOException {
|
||||
byte[] key = sop.generateKey()
|
||||
.userId("Alice <alice@openpgp.org>")
|
||||
.userId("Bob <bob@openpgp.org>")
|
||||
.generate()
|
||||
.getBytes();
|
||||
|
||||
JUtils.assertArrayStartsWith(key, TestData.BEGIN_PGP_PRIVATE_KEY_BLOCK);
|
||||
JUtils.assertArrayEndsWithIgnoreNewlines(key, TestData.END_PGP_PRIVATE_KEY_BLOCK);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void generateKeyWithoutUserIdTest(SOP sop) throws IOException {
|
||||
byte[] key = sop.generateKey()
|
||||
.generate()
|
||||
.getBytes();
|
||||
|
||||
JUtils.assertArrayStartsWith(key, TestData.BEGIN_PGP_PRIVATE_KEY_BLOCK);
|
||||
JUtils.assertArrayEndsWithIgnoreNewlines(key, TestData.END_PGP_PRIVATE_KEY_BLOCK);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void generateKeyWithPasswordTest(SOP sop) throws IOException {
|
||||
byte[] key = sop.generateKey()
|
||||
.userId("Alice <alice@openpgp.org>")
|
||||
.withKeyPassword("sw0rdf1sh")
|
||||
.generate()
|
||||
.getBytes();
|
||||
|
||||
JUtils.assertArrayStartsWith(key, TestData.BEGIN_PGP_PRIVATE_KEY_BLOCK);
|
||||
JUtils.assertArrayEndsWithIgnoreNewlines(key, TestData.END_PGP_PRIVATE_KEY_BLOCK);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
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();
|
||||
|
||||
JUtils.assertArrayStartsWith(key, TestData.BEGIN_PGP_PRIVATE_KEY_BLOCK);
|
||||
JUtils.assertArrayEndsWithIgnoreNewlines(key, TestData.END_PGP_PRIVATE_KEY_BLOCK);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void generateSigningOnlyKey(SOP sop) throws IOException {
|
||||
byte[] signingOnlyKey = sop.generateKey()
|
||||
.signingOnly()
|
||||
.userId("Alice <alice@pgpainless.org>")
|
||||
.generate()
|
||||
.getBytes();
|
||||
byte[] signingOnlyCert = sop.extractCert()
|
||||
.key(signingOnlyKey)
|
||||
.getBytes();
|
||||
|
||||
assertThrows(SOPGPException.CertCannotEncrypt.class, () ->
|
||||
sop.encrypt().withCert(signingOnlyCert)
|
||||
.plaintext(TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8)));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sop.testsuite.operation;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.condition.EnabledIf;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import sop.ByteArrayAndResult;
|
||||
import sop.SOP;
|
||||
import sop.Signatures;
|
||||
import sop.Verification;
|
||||
import sop.testsuite.JUtils;
|
||||
import sop.testsuite.TestData;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
|
||||
@EnabledIf("sop.testsuite.operation.AbstractSOPTest#hasBackends")
|
||||
public class InlineSignInlineDetachDetachedVerifyTest extends AbstractSOPTest {
|
||||
|
||||
static Stream<Arguments> provideInstances() {
|
||||
return provideBackends();
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void inlineSignThenDetachThenDetachedVerifyTest(SOP sop) throws IOException {
|
||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] inlineSigned = sop.inlineSign()
|
||||
.key(TestData.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(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.signatures(signatures)
|
||||
.data(plaintext);
|
||||
|
||||
assertFalse(verifications.isEmpty());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void inlineSignThenDetachNoArmorThenArmorThenDetachedVerifyTest(SOP sop) throws IOException {
|
||||
byte[] message = "Hello, World!\n".getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] inlineSigned = sop.inlineSign()
|
||||
.key(TestData.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();
|
||||
Assertions.assertFalse(JUtils.arrayStartsWith(signatures, TestData.BEGIN_PGP_SIGNATURE));
|
||||
|
||||
byte[] armored = sop.armor()
|
||||
.data(signatures)
|
||||
.getBytes();
|
||||
JUtils.assertArrayStartsWith(armored, TestData.BEGIN_PGP_SIGNATURE);
|
||||
|
||||
List<Verification> verifications = sop.detachedVerify()
|
||||
.cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.signatures(armored)
|
||||
.data(plaintext);
|
||||
|
||||
assertFalse(verifications.isEmpty());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,240 @@
|
|||
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sop.testsuite.operation;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.condition.EnabledIf;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import sop.ByteArrayAndResult;
|
||||
import sop.SOP;
|
||||
import sop.Verification;
|
||||
import sop.enums.InlineSignAs;
|
||||
import sop.enums.SignatureMode;
|
||||
import sop.exception.SOPGPException;
|
||||
import sop.testsuite.JUtils;
|
||||
import sop.testsuite.TestData;
|
||||
import sop.testsuite.assertions.VerificationListAssert;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
@EnabledIf("sop.testsuite.operation.AbstractSOPTest#hasBackends")
|
||||
public class InlineSignInlineVerifyTest extends AbstractSOPTest {
|
||||
|
||||
static Stream<Arguments> provideInstances() {
|
||||
return provideBackends();
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void inlineSignVerifyAlice(SOP sop) throws IOException {
|
||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] inlineSigned = sop.inlineSign()
|
||||
.key(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.data(message)
|
||||
.getBytes();
|
||||
|
||||
JUtils.assertArrayStartsWith(inlineSigned, TestData.BEGIN_PGP_MESSAGE);
|
||||
|
||||
ByteArrayAndResult<List<Verification>> bytesAndResult = sop.inlineVerify()
|
||||
.cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.data(inlineSigned)
|
||||
.toByteArrayAndResult();
|
||||
|
||||
assertArrayEquals(message, bytesAndResult.getBytes());
|
||||
|
||||
List<Verification> verificationList = bytesAndResult.getResult();
|
||||
VerificationListAssert.assertThatVerificationList(verificationList)
|
||||
.isNotEmpty()
|
||||
.hasSingleItem()
|
||||
.issuedBy(TestData.ALICE_SIGNING_FINGERPRINT, TestData.ALICE_PRIMARY_FINGERPRINT);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void inlineSignVerifyAliceNoArmor(SOP sop) throws IOException {
|
||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] inlineSigned = sop.inlineSign()
|
||||
.key(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.noArmor()
|
||||
.data(message)
|
||||
.getBytes();
|
||||
|
||||
Assertions.assertFalse(JUtils.arrayStartsWith(inlineSigned, TestData.BEGIN_PGP_MESSAGE));
|
||||
|
||||
ByteArrayAndResult<List<Verification>> bytesAndResult = sop.inlineVerify()
|
||||
.cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.data(inlineSigned)
|
||||
.toByteArrayAndResult();
|
||||
|
||||
assertArrayEquals(message, bytesAndResult.getBytes());
|
||||
|
||||
List<Verification> verificationList = bytesAndResult.getResult();
|
||||
VerificationListAssert.assertThatVerificationList(verificationList)
|
||||
.isNotEmpty()
|
||||
.hasSingleItem()
|
||||
.issuedBy(TestData.ALICE_SIGNING_FINGERPRINT, TestData.ALICE_PRIMARY_FINGERPRINT);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void clearsignVerifyAlice(SOP sop) throws IOException {
|
||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] clearsigned = sop.inlineSign()
|
||||
.key(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.mode(InlineSignAs.clearsigned)
|
||||
.data(message)
|
||||
.getBytes();
|
||||
|
||||
JUtils.assertArrayStartsWith(clearsigned, TestData.BEGIN_PGP_SIGNED_MESSAGE);
|
||||
|
||||
ByteArrayAndResult<List<Verification>> bytesAndResult = sop.inlineVerify()
|
||||
.cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.data(clearsigned)
|
||||
.toByteArrayAndResult();
|
||||
|
||||
assertArrayEquals(message, bytesAndResult.getBytes());
|
||||
|
||||
List<Verification> verificationList = bytesAndResult.getResult();
|
||||
VerificationListAssert.assertThatVerificationList(verificationList)
|
||||
.hasSingleItem()
|
||||
.issuedBy(TestData.ALICE_SIGNING_FINGERPRINT, TestData.ALICE_PRIMARY_FINGERPRINT)
|
||||
.hasModeOrNull(SignatureMode.text);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
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(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.data(message)
|
||||
.toByteArrayAndResult();
|
||||
|
||||
List<Verification> verificationList = bytesAndResult.getResult();
|
||||
VerificationListAssert.assertThatVerificationList(verificationList)
|
||||
.isNotEmpty()
|
||||
.hasSingleItem()
|
||||
.isCreatedAt(signatureDate)
|
||||
.issuedBy(TestData.ALICE_SIGNING_FINGERPRINT, TestData.ALICE_PRIMARY_FINGERPRINT);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
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(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.data(message)
|
||||
.toByteArrayAndResult());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
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(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.data(message)
|
||||
.toByteArrayAndResult());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void inlineSignVerifyBob(SOP sop) throws IOException {
|
||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] inlineSigned = sop.inlineSign()
|
||||
.key(TestData.BOB_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.data(message)
|
||||
.getBytes();
|
||||
|
||||
JUtils.assertArrayStartsWith(inlineSigned, TestData.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();
|
||||
VerificationListAssert.assertThatVerificationList(verificationList)
|
||||
.isNotEmpty()
|
||||
.hasSingleItem()
|
||||
.issuedBy(TestData.BOB_SIGNING_FINGERPRINT, TestData.BOB_PRIMARY_FINGERPRINT);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void inlineSignVerifyCarol(SOP sop) throws IOException {
|
||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] inlineSigned = sop.inlineSign()
|
||||
.key(TestData.CAROL_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.data(message)
|
||||
.getBytes();
|
||||
|
||||
JUtils.assertArrayStartsWith(inlineSigned, TestData.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();
|
||||
VerificationListAssert.assertThatVerificationList(verificationList)
|
||||
.isNotEmpty()
|
||||
.hasSingleItem()
|
||||
.issuedBy(TestData.CAROL_SIGNING_FINGERPRINT, TestData.CAROL_PRIMARY_FINGERPRINT);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void inlineSignVerifyProtectedKey(SOP sop) throws IOException {
|
||||
byte[] message = TestData.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();
|
||||
VerificationListAssert.assertThatVerificationList(verificationList)
|
||||
.hasSingleItem()
|
||||
.issuedBy(TestData.PASSWORD_PROTECTED_SIGNING_FINGERPRINT, TestData.PASSWORD_PROTECTED_PRIMARY_FINGERPRINT);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sop.testsuite.operation;
|
||||
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import sop.Profile;
|
||||
import sop.SOP;
|
||||
import sop.exception.SOPGPException;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
public class ListProfilesTest extends AbstractSOPTest {
|
||||
|
||||
static Stream<Arguments> provideInstances() {
|
||||
return provideBackends();
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void listGenerateKeyProfiles(SOP sop) {
|
||||
List<Profile> profiles = sop
|
||||
.listProfiles()
|
||||
.generateKey();
|
||||
|
||||
assertFalse(profiles.isEmpty());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void listEncryptProfiles(SOP sop) {
|
||||
List<Profile> profiles = sop
|
||||
.listProfiles()
|
||||
.encrypt();
|
||||
|
||||
assertFalse(profiles.isEmpty());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void listUnsupportedProfiles(SOP sop) {
|
||||
assertThrows(SOPGPException.UnsupportedProfile.class, () -> sop
|
||||
.listProfiles()
|
||||
.subcommand("invalid"));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,132 @@
|
|||
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sop.testsuite.operation;
|
||||
|
||||
import org.junit.jupiter.api.condition.EnabledIf;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import sop.SOP;
|
||||
import sop.Verification;
|
||||
import sop.exception.SOPGPException;
|
||||
import sop.testsuite.JUtils;
|
||||
import sop.testsuite.TestData;
|
||||
import sop.testsuite.assertions.VerificationListAssert;
|
||||
import sop.util.UTF8Util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@EnabledIf("sop.testsuite.operation.AbstractSOPTest#hasBackends")
|
||||
public class RevokeKeyTest extends AbstractSOPTest {
|
||||
|
||||
static Stream<Arguments> provideInstances() {
|
||||
return provideBackends();
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void revokeUnprotectedKey(SOP sop) throws IOException {
|
||||
byte[] secretKey = sop.generateKey().userId("Alice <alice@pgpainless.org>").generate().getBytes();
|
||||
byte[] revocation = sop.revokeKey().keys(secretKey).getBytes();
|
||||
|
||||
assertTrue(JUtils.arrayStartsWith(revocation, TestData.BEGIN_PGP_PUBLIC_KEY_BLOCK));
|
||||
assertFalse(Arrays.equals(secretKey, revocation));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void revokeUnprotectedKeyNoArmor(SOP sop) throws IOException {
|
||||
byte[] secretKey = sop.generateKey().userId("Alice <alice@pgpainless.org>").generate().getBytes();
|
||||
byte[] revocation = sop.revokeKey().noArmor().keys(secretKey).getBytes();
|
||||
|
||||
assertFalse(JUtils.arrayStartsWith(revocation, TestData.BEGIN_PGP_PUBLIC_KEY_BLOCK));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void revokeUnprotectedKeyUnarmored(SOP sop) throws IOException {
|
||||
byte[] secretKey = sop.generateKey().userId("Alice <alice@pgpainless.org>").noArmor().generate().getBytes();
|
||||
byte[] revocation = sop.revokeKey().noArmor().keys(secretKey).getBytes();
|
||||
|
||||
assertFalse(JUtils.arrayStartsWith(revocation, TestData.BEGIN_PGP_PUBLIC_KEY_BLOCK));
|
||||
assertFalse(Arrays.equals(secretKey, revocation));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void revokeCertificateFails(SOP sop) throws IOException {
|
||||
byte[] secretKey = sop.generateKey().generate().getBytes();
|
||||
byte[] certificate = sop.extractCert().key(secretKey).getBytes();
|
||||
|
||||
assertThrows(SOPGPException.BadData.class, () -> sop.revokeKey().keys(certificate).getBytes());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void revokeProtectedKey(SOP sop) throws IOException {
|
||||
byte[] password = "sw0rdf1sh".getBytes(UTF8Util.UTF8);
|
||||
byte[] secretKey = sop.generateKey().withKeyPassword(password).userId("Alice <alice@pgpainless.org>").generate().getBytes();
|
||||
byte[] revocation = sop.revokeKey().withKeyPassword(password).keys(secretKey).getBytes();
|
||||
|
||||
assertFalse(Arrays.equals(secretKey, revocation));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void revokeProtectedKeyWithMultiplePasswordOptions(SOP sop) throws IOException {
|
||||
byte[] password = "sw0rdf1sh".getBytes(UTF8Util.UTF8);
|
||||
byte[] wrongPassword = "0r4ng3".getBytes(UTF8Util.UTF8);
|
||||
byte[] secretKey = sop.generateKey().withKeyPassword(password).userId("Alice <alice@pgpainless.org>").generate().getBytes();
|
||||
byte[] revocation = sop.revokeKey().withKeyPassword(wrongPassword).withKeyPassword(password).keys(secretKey).getBytes();
|
||||
|
||||
assertFalse(Arrays.equals(secretKey, revocation));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void revokeProtectedKeyWithMissingPassphraseFails(SOP sop) throws IOException {
|
||||
byte[] password = "sw0rdf1sh".getBytes(UTF8Util.UTF8);
|
||||
byte[] secretKey = sop.generateKey().withKeyPassword(password).userId("Alice <alice@pgpainless.org>").generate().getBytes();
|
||||
|
||||
assertThrows(SOPGPException.KeyIsProtected.class, () -> sop.revokeKey().keys(secretKey).getBytes());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void revokeProtectedKeyWithWrongPassphraseFails(SOP sop) throws IOException {
|
||||
byte[] password = "sw0rdf1sh".getBytes(UTF8Util.UTF8);
|
||||
String wrongPassword = "or4ng3";
|
||||
byte[] secretKey = sop.generateKey().withKeyPassword(password).userId("Alice <alice@pgpainless.org>").generate().getBytes();
|
||||
|
||||
assertThrows(SOPGPException.KeyIsProtected.class, () -> sop.revokeKey().withKeyPassword(wrongPassword).keys(secretKey).getBytes());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void revokeKeyIsNowHardRevoked(SOP sop) throws IOException {
|
||||
byte[] key = sop.generateKey().generate().getBytes();
|
||||
byte[] cert = sop.extractCert().key(key).getBytes();
|
||||
|
||||
// Sign a message with the key
|
||||
byte[] msg = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
byte[] signedMsg = sop.inlineSign().key(key).data(msg).getBytes();
|
||||
|
||||
// Verifying the message with the valid cert works
|
||||
List<Verification> result = sop.inlineVerify().cert(cert).data(signedMsg).toByteArrayAndResult().getResult();
|
||||
VerificationListAssert.assertThatVerificationList(result).hasSingleItem();
|
||||
|
||||
// Now hard revoke the key and re-check signature, expecting no valid certification
|
||||
byte[] revokedCert = sop.revokeKey().keys(key).getBytes();
|
||||
assertThrows(SOPGPException.NoSignature.class, () -> sop.inlineVerify().cert(revokedCert).data(signedMsg).toByteArrayAndResult());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sop.testsuite.operation;
|
||||
|
||||
import org.junit.jupiter.api.condition.EnabledIf;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import org.opentest4j.TestAbortedException;
|
||||
import sop.SOP;
|
||||
import sop.exception.SOPGPException;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
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.testsuite.operation.AbstractSOPTest#hasBackends")
|
||||
public class VersionTest extends AbstractSOPTest {
|
||||
|
||||
static Stream<Arguments> provideInstances() {
|
||||
return provideBackends();
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void versionNameTest(SOP sop) {
|
||||
String name = sop.version().getName();
|
||||
assertNotNull(name);
|
||||
assertFalse(name.isEmpty());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void versionVersionTest(SOP sop) {
|
||||
String version = sop.version().getVersion();
|
||||
assertFalse(version.isEmpty());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void backendVersionTest(SOP sop) {
|
||||
String backend = sop.version().getBackendVersion();
|
||||
assertFalse(backend.isEmpty());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void extendedVersionTest(SOP sop) {
|
||||
String extended = sop.version().getExtendedVersion();
|
||||
assertFalse(extended.isEmpty());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void sopSpecVersionTest(SOP sop) {
|
||||
try {
|
||||
sop.version().getSopSpecVersion();
|
||||
} catch (RuntimeException e) {
|
||||
throw new TestAbortedException("SOP backend does not support 'version --sop-spec' yet.");
|
||||
}
|
||||
|
||||
String sopSpec = sop.version().getSopSpecVersion();
|
||||
if (sop.version().isSopSpecImplementationIncomplete()) {
|
||||
assertTrue(sopSpec.startsWith("~draft-dkg-openpgp-stateless-cli-"));
|
||||
} else {
|
||||
assertTrue(sopSpec.startsWith("draft-dkg-openpgp-stateless-cli-"));
|
||||
}
|
||||
|
||||
int sopRevision = sop.version().getSopSpecRevisionNumber();
|
||||
assertTrue(sop.version().getSopSpecRevisionName().endsWith("" + sopRevision));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void sopVVersionTest(SOP sop) {
|
||||
try {
|
||||
sop.version().getSopVVersion();
|
||||
} catch (SOPGPException.UnsupportedOption e) {
|
||||
throw new TestAbortedException(
|
||||
"Implementation does (gracefully) not provide coverage for any sopv interface version.");
|
||||
} catch (RuntimeException e) {
|
||||
throw new TestAbortedException("Implementation does not provide coverage for any sopv interface version.");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
/**
|
||||
* SOP binary test suite.
|
||||
*/
|
||||
package sop.testsuite.operation;
|
|
@ -0,0 +1,8 @@
|
|||
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
/**
|
||||
* SOP binary test suite.
|
||||
*/
|
||||
package sop.testsuite;
|
|
@ -0,0 +1,12 @@
|
|||
// SPDX-FileCopyrightText: 2024 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sop.testsuite
|
||||
|
||||
import java.lang.annotation.Inherited
|
||||
|
||||
@Target(AnnotationTarget.TYPE)
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
@Inherited
|
||||
annotation class AbortOnUnsupportedOption
|
|
@ -0,0 +1,21 @@
|
|||
// SPDX-FileCopyrightText: 2024 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sop.testsuite
|
||||
|
||||
import org.junit.jupiter.api.Assumptions
|
||||
import org.junit.jupiter.api.extension.ExtensionContext
|
||||
import org.junit.jupiter.api.extension.TestExecutionExceptionHandler
|
||||
import sop.exception.SOPGPException
|
||||
|
||||
class AbortOnUnsupportedOptionExtension : TestExecutionExceptionHandler {
|
||||
override fun handleTestExecutionException(context: ExtensionContext, throwable: Throwable) {
|
||||
val testClass = context.requiredTestClass
|
||||
val annotation = testClass.getAnnotation(AbortOnUnsupportedOption::class.java)
|
||||
if (annotation != null && SOPGPException.UnsupportedOption::class.isInstance(throwable)) {
|
||||
Assumptions.assumeTrue(false, "Test aborted due to: " + throwable.message)
|
||||
}
|
||||
throw throwable
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue