From 9cf6301b8c3e2ac4a7e84b5bd94de9f1b0dc7899 Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Sat, 21 Jan 2023 20:31:49 +0100 Subject: [PATCH] More tests --- .../ExternalArmorDearmorRoundTripTest.java | 14 +- .../ExternalDecryptWithSessionKeyTest.java | 2 +- ...ternalDetachedSignVerifyRoundTripTest.java | 127 +++++++++------ .../ExternalEncryptDecryptRoundTripTest.java | 40 ++--- .../sop/external/ExternalExtractCertTest.java | 12 +- ...alInlineSignDetachVerifyRoundTripTest.java | 8 +- .../ExternalInlineSignVerifyTest.java | 146 ++++++++++++------ .../src/test/java/sop/external/JUtils.java | 68 ++++++++ .../external/{TestKeys.java => TestData.java} | 36 ++++- 9 files changed, 319 insertions(+), 134 deletions(-) rename external-sop/src/test/java/sop/external/{TestKeys.java => TestData.java} (93%) diff --git a/external-sop/src/test/java/sop/external/ExternalArmorDearmorRoundTripTest.java b/external-sop/src/test/java/sop/external/ExternalArmorDearmorRoundTripTest.java index 4079fd0..c4cd4ae 100644 --- a/external-sop/src/test/java/sop/external/ExternalArmorDearmorRoundTripTest.java +++ b/external-sop/src/test/java/sop/external/ExternalArmorDearmorRoundTripTest.java @@ -30,7 +30,7 @@ public class ExternalArmorDearmorRoundTripTest extends AbstractExternalSOPTest { @Test public void dearmorArmorAliceKey() throws IOException { - byte[] aliceKey = TestKeys.ALICE_KEY.getBytes(StandardCharsets.UTF_8); + byte[] aliceKey = TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8); byte[] dearmored = getSop().dearmor() .data(aliceKey) @@ -48,7 +48,7 @@ public class ExternalArmorDearmorRoundTripTest extends AbstractExternalSOPTest { @Test public void dearmorArmorAliceCert() throws IOException { - byte[] aliceCert = TestKeys.ALICE_CERT.getBytes(StandardCharsets.UTF_8); + byte[] aliceCert = TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8); byte[] dearmored = getSop().dearmor() .data(aliceCert) @@ -66,7 +66,7 @@ public class ExternalArmorDearmorRoundTripTest extends AbstractExternalSOPTest { @Test public void dearmorArmorBobKey() throws IOException { - byte[] bobKey = TestKeys.BOB_KEY.getBytes(StandardCharsets.UTF_8); + byte[] bobKey = TestData.BOB_KEY.getBytes(StandardCharsets.UTF_8); byte[] dearmored = getSop().dearmor() .data(bobKey) @@ -84,7 +84,7 @@ public class ExternalArmorDearmorRoundTripTest extends AbstractExternalSOPTest { @Test public void dearmorArmorBobCert() throws IOException { - byte[] bobCert = TestKeys.BOB_CERT.getBytes(StandardCharsets.UTF_8); + byte[] bobCert = TestData.BOB_CERT.getBytes(StandardCharsets.UTF_8); byte[] dearmored = getSop().dearmor() .data(bobCert) @@ -102,7 +102,7 @@ public class ExternalArmorDearmorRoundTripTest extends AbstractExternalSOPTest { @Test public void dearmorArmorCarolKey() throws IOException { - byte[] carolKey = TestKeys.CAROL_KEY.getBytes(StandardCharsets.UTF_8); + byte[] carolKey = TestData.CAROL_KEY.getBytes(StandardCharsets.UTF_8); byte[] dearmored = getSop().dearmor() .data(carolKey) @@ -120,7 +120,7 @@ public class ExternalArmorDearmorRoundTripTest extends AbstractExternalSOPTest { @Test public void dearmorArmorCarolCert() throws IOException { - byte[] carolCert = TestKeys.CAROL_CERT.getBytes(StandardCharsets.UTF_8); + byte[] carolCert = TestData.CAROL_CERT.getBytes(StandardCharsets.UTF_8); byte[] dearmored = getSop().dearmor() .data(carolCert) @@ -191,7 +191,7 @@ public class ExternalArmorDearmorRoundTripTest extends AbstractExternalSOPTest { ignoreIf("sqop", Is.eq, "0.27.2"); // IO error because: EOF byte[] dearmored = getSop().dearmor() - .data(TestKeys.ALICE_KEY.getBytes(StandardCharsets.UTF_8)) + .data(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8)) .getBytes(); byte[] dearmoredAgain = getSop().dearmor() diff --git a/external-sop/src/test/java/sop/external/ExternalDecryptWithSessionKeyTest.java b/external-sop/src/test/java/sop/external/ExternalDecryptWithSessionKeyTest.java index fcff3e9..0c1f7c7 100644 --- a/external-sop/src/test/java/sop/external/ExternalDecryptWithSessionKeyTest.java +++ b/external-sop/src/test/java/sop/external/ExternalDecryptWithSessionKeyTest.java @@ -32,7 +32,7 @@ public class ExternalDecryptWithSessionKeyTest extends AbstractExternalSOPTest { @Test public void testDecryptAndExtractSessionKey() throws IOException { ByteArrayAndResult bytesAndResult = getSop().decrypt() - .withKey(TestKeys.ALICE_KEY.getBytes(StandardCharsets.UTF_8)) + .withKey(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8)) .ciphertext(CIPHERTEXT.getBytes(StandardCharsets.UTF_8)) .toByteArrayAndResult(); diff --git a/external-sop/src/test/java/sop/external/ExternalDetachedSignVerifyRoundTripTest.java b/external-sop/src/test/java/sop/external/ExternalDetachedSignVerifyRoundTripTest.java index 63638cc..bdab4b5 100644 --- a/external-sop/src/test/java/sop/external/ExternalDetachedSignVerifyRoundTripTest.java +++ b/external-sop/src/test/java/sop/external/ExternalDetachedSignVerifyRoundTripTest.java @@ -9,7 +9,6 @@ import org.junit.jupiter.api.condition.EnabledIf; import sop.Verification; import sop.enums.SignAs; import sop.exception.SOPGPException; -import sop.util.UTCUtil; import java.io.IOException; import java.nio.charset.StandardCharsets; @@ -18,8 +17,8 @@ import java.util.List; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; import static sop.external.JUtils.assertArrayStartsWith; +import static sop.external.JUtils.assertSignedBy; @EnabledIf("sop.external.AbstractExternalSOPTest#isExternalSopInstalled") public class ExternalDetachedSignVerifyRoundTripTest extends AbstractExternalSOPTest { @@ -29,50 +28,102 @@ public class ExternalDetachedSignVerifyRoundTripTest extends AbstractExternalSOP @Test public void signVerifyWithAliceKey() throws IOException { - byte[] message = "Hello, World!\n".getBytes(StandardCharsets.UTF_8); + byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8); byte[] signature = getSop().detachedSign() - .key(TestKeys.ALICE_KEY.getBytes(StandardCharsets.UTF_8)) + .key(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8)) .data(message) .toByteArrayAndResult() .getBytes(); List verificationList = getSop().detachedVerify() - .cert(TestKeys.ALICE_CERT.getBytes(StandardCharsets.UTF_8)) + .cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8)) .signatures(signature) .data(message); assertFalse(verificationList.isEmpty()); - assertTrue(verificationList.get(0).toString().contains("EB85BB5FA33A75E15E944E63F231550C4F47E38E EB85BB5FA33A75E15E944E63F231550C4F47E38E")); + assertSignedBy(verificationList, TestData.ALICE_SIGNING_FINGERPRINT, TestData.ALICE_PRIMARY_FINGERPRINT); } @Test public void signVerifyTextModeWithAliceKey() throws IOException { - byte[] message = "Hello, World!\n".getBytes(StandardCharsets.UTF_8); + byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8); byte[] signature = getSop().detachedSign() - .key(TestKeys.ALICE_KEY.getBytes(StandardCharsets.UTF_8)) + .key(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8)) .mode(SignAs.Text) .data(message) .toByteArrayAndResult() .getBytes(); List verificationList = getSop().detachedVerify() - .cert(TestKeys.ALICE_CERT.getBytes(StandardCharsets.UTF_8)) + .cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8)) .signatures(signature) .data(message); assertFalse(verificationList.isEmpty()); - assertTrue(verificationList.get(0).toString().contains("EB85BB5FA33A75E15E944E63F231550C4F47E38E EB85BB5FA33A75E15E944E63F231550C4F47E38E")); + assertSignedBy(verificationList, TestData.ALICE_SIGNING_FINGERPRINT, TestData.ALICE_PRIMARY_FINGERPRINT); + } + + @Test + public void verifyKnownMessageWithAliceCert() throws IOException { + byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8); + byte[] signature = TestData.ALICE_DETACHED_SIGNED_MESSAGE.getBytes(StandardCharsets.UTF_8); + + List verificationList = getSop().detachedVerify() + .cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8)) + .signatures(signature) + .data(message); + + assertFalse(verificationList.isEmpty()); + assertSignedBy(verificationList, TestData.ALICE_SIGNING_FINGERPRINT, TestData.ALICE_PRIMARY_FINGERPRINT, TestData.ALICE_DETACHED_SIGNED_MESSAGE_DATE); + } + + @Test + public void signVerifyWithBobKey() throws IOException { + byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8); + + byte[] signature = getSop().detachedSign() + .key(TestData.BOB_KEY.getBytes(StandardCharsets.UTF_8)) + .data(message) + .toByteArrayAndResult() + .getBytes(); + + List verificationList = getSop().detachedVerify() + .cert(TestData.BOB_CERT.getBytes(StandardCharsets.UTF_8)) + .signatures(signature) + .data(message); + + assertFalse(verificationList.isEmpty()); + assertSignedBy(verificationList, TestData.BOB_SIGNING_FINGERPRINT, TestData.BOB_PRIMARY_FINGERPRINT); + } + + @Test + public void signVerifyWithCarolKey() throws IOException { + byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8); + + byte[] signature = getSop().detachedSign() + .key(TestData.CAROL_KEY.getBytes(StandardCharsets.UTF_8)) + .data(message) + .toByteArrayAndResult() + .getBytes(); + + List verificationList = getSop().detachedVerify() + .cert(TestData.CAROL_CERT.getBytes(StandardCharsets.UTF_8)) + .signatures(signature) + .data(message); + + assertFalse(verificationList.isEmpty()); + assertSignedBy(verificationList, TestData.CAROL_SIGNING_FINGERPRINT, TestData.CAROL_PRIMARY_FINGERPRINT); } @Test public void signVerifyWithEncryptedKey() throws IOException { - byte[] message = "Hello, World!\n".getBytes(StandardCharsets.UTF_8); + byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8); byte[] signature = getSop().detachedSign() - .key(TestKeys.PASSWORD_PROTECTED_KEY.getBytes(StandardCharsets.UTF_8)) - .withKeyPassword(TestKeys.PASSWORD) + .key(TestData.PASSWORD_PROTECTED_KEY.getBytes(StandardCharsets.UTF_8)) + .withKeyPassword(TestData.PASSWORD) .data(message) .toByteArrayAndResult() .getBytes(); @@ -80,7 +131,7 @@ public class ExternalDetachedSignVerifyRoundTripTest extends AbstractExternalSOP assertArrayStartsWith(signature, BEGIN_PGP_SIGNATURE_BYTES); List verificationList = getSop().detachedVerify() - .cert(TestKeys.PASSWORD_PROTECTED_CERT.getBytes(StandardCharsets.UTF_8)) + .cert(TestData.PASSWORD_PROTECTED_CERT.getBytes(StandardCharsets.UTF_8)) .signatures(signature) .data(message); @@ -89,10 +140,10 @@ public class ExternalDetachedSignVerifyRoundTripTest extends AbstractExternalSOP @Test public void signArmorVerifyWithBobKey() throws IOException { - byte[] message = "Hello, World!\n".getBytes(StandardCharsets.UTF_8); + byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8); byte[] signature = getSop().detachedSign() - .key(TestKeys.BOB_KEY.getBytes(StandardCharsets.UTF_8)) + .key(TestData.BOB_KEY.getBytes(StandardCharsets.UTF_8)) .noArmor() .data(message) .toByteArrayAndResult() @@ -103,31 +154,25 @@ public class ExternalDetachedSignVerifyRoundTripTest extends AbstractExternalSOP .getBytes(); List verificationList = getSop().detachedVerify() - .cert(TestKeys.BOB_CERT.getBytes(StandardCharsets.UTF_8)) + .cert(TestData.BOB_CERT.getBytes(StandardCharsets.UTF_8)) .signatures(armored) .data(message); assertFalse(verificationList.isEmpty()); - assertTrue(verificationList.get(0).toString().contains("D1A66E1A23B182C9980F788CFBFCC82A015E7330 D1A66E1A23B182C9980F788CFBFCC82A015E7330")); + assertSignedBy(verificationList, TestData.BOB_SIGNING_FINGERPRINT, TestData.BOB_PRIMARY_FINGERPRINT); } @Test public void verifyNotAfterThrowsNoSignature() { ignoreIf("sqop", Is.leq, "0.27.2"); // returns 1 instead of 3 (NO_SIGNATURE) - byte[] message = "Hello, World!\n".getBytes(StandardCharsets.UTF_8); - byte[] signature = ("-----BEGIN PGP SIGNATURE-----\n" + - "\n" + - "iHUEABYKACcFAmPBjZUJEPIxVQxPR+OOFiEE64W7X6M6deFelE5j8jFVDE9H444A\n" + - "ADI/AQC6Bux6WpGYf7HO+QPV/D5iIrqZt9xPLgfUVoNJBmMZZwD+Ib+tn5pSyWUw\n" + - "0K1UgT5roym9Fln8U5W8R03TSbfNiwE=\n" + - "=bxPN\n" + - "-----END PGP SIGNATURE-----").getBytes(StandardCharsets.UTF_8); - Date signatureDate = UTCUtil.parseUTCDate("2023-01-13T16:57:57Z"); + byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8); + byte[] signature = TestData.ALICE_DETACHED_SIGNED_MESSAGE.getBytes(StandardCharsets.UTF_8); + Date signatureDate = TestData.ALICE_DETACHED_SIGNED_MESSAGE_DATE; Date beforeSignature = new Date(signatureDate.getTime() - 1000); // 1 sec before sig assertThrows(SOPGPException.NoSignature.class, () -> getSop().detachedVerify() - .cert(TestKeys.ALICE_CERT.getBytes(StandardCharsets.UTF_8)) + .cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8)) .notAfter(beforeSignature) .signatures(signature) .data(message)); @@ -137,19 +182,13 @@ public class ExternalDetachedSignVerifyRoundTripTest extends AbstractExternalSOP public void verifyNotBeforeThrowsNoSignature() { ignoreIf("sqop", Is.leq, "0.27.2"); // returns 1 instead of 3 (NO_SIGNATURE) - byte[] message = "Hello, World!\n".getBytes(StandardCharsets.UTF_8); - byte[] signature = ("-----BEGIN PGP SIGNATURE-----\n" + - "\n" + - "iHUEABYKACcFAmPBjZUJEPIxVQxPR+OOFiEE64W7X6M6deFelE5j8jFVDE9H444A\n" + - "ADI/AQC6Bux6WpGYf7HO+QPV/D5iIrqZt9xPLgfUVoNJBmMZZwD+Ib+tn5pSyWUw\n" + - "0K1UgT5roym9Fln8U5W8R03TSbfNiwE=\n" + - "=bxPN\n" + - "-----END PGP SIGNATURE-----").getBytes(StandardCharsets.UTF_8); - Date signatureDate = UTCUtil.parseUTCDate("2023-01-13T16:57:57Z"); + byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8); + byte[] signature = TestData.ALICE_DETACHED_SIGNED_MESSAGE.getBytes(StandardCharsets.UTF_8); + Date signatureDate = TestData.ALICE_DETACHED_SIGNED_MESSAGE_DATE; Date afterSignature = new Date(signatureDate.getTime() + 1000); // 1 sec after sig assertThrows(SOPGPException.NoSignature.class, () -> getSop().detachedVerify() - .cert(TestKeys.ALICE_CERT.getBytes(StandardCharsets.UTF_8)) + .cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8)) .notBefore(afterSignature) .signatures(signature) .data(message)); @@ -162,8 +201,8 @@ public class ExternalDetachedSignVerifyRoundTripTest extends AbstractExternalSOP assertThrows(SOPGPException.KeyIsProtected.class, () -> getSop().detachedSign() - .key(TestKeys.PASSWORD_PROTECTED_KEY.getBytes(StandardCharsets.UTF_8)) - .data("Hello, World!\n".getBytes(StandardCharsets.UTF_8)) + .key(TestData.PASSWORD_PROTECTED_KEY.getBytes(StandardCharsets.UTF_8)) + .data(TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8)) .toByteArrayAndResult() .getBytes()); } @@ -171,19 +210,19 @@ public class ExternalDetachedSignVerifyRoundTripTest extends AbstractExternalSOP @Test public void signWithProtectedKeyAndMultiplePassphrasesTest() throws IOException { - byte[] message = "Hello, World!\n".getBytes(StandardCharsets.UTF_8); + byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8); byte[] signature = getSop().sign() - .key(TestKeys.PASSWORD_PROTECTED_KEY.getBytes(StandardCharsets.UTF_8)) + .key(TestData.PASSWORD_PROTECTED_KEY.getBytes(StandardCharsets.UTF_8)) .withKeyPassword("wrong") - .withKeyPassword(TestKeys.PASSWORD) // correct + .withKeyPassword(TestData.PASSWORD) // correct .withKeyPassword("wrong2") .data(message) .toByteArrayAndResult() .getBytes(); assertFalse(getSop().verify() - .cert(TestKeys.PASSWORD_PROTECTED_CERT.getBytes(StandardCharsets.UTF_8)) + .cert(TestData.PASSWORD_PROTECTED_CERT.getBytes(StandardCharsets.UTF_8)) .signatures(signature) .data(message) .isEmpty()); diff --git a/external-sop/src/test/java/sop/external/ExternalEncryptDecryptRoundTripTest.java b/external-sop/src/test/java/sop/external/ExternalEncryptDecryptRoundTripTest.java index 90f08ba..41bb861 100644 --- a/external-sop/src/test/java/sop/external/ExternalEncryptDecryptRoundTripTest.java +++ b/external-sop/src/test/java/sop/external/ExternalEncryptDecryptRoundTripTest.java @@ -49,12 +49,12 @@ public class ExternalEncryptDecryptRoundTripTest extends AbstractExternalSOPTest public void encryptDecryptRoundTripAliceTest() throws IOException { byte[] message = "Hello, World!\n".getBytes(StandardCharsets.UTF_8); byte[] ciphertext = getSop().encrypt() - .withCert(TestKeys.ALICE_CERT.getBytes(StandardCharsets.UTF_8)) + .withCert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8)) .plaintext(message) .getBytes(); ByteArrayAndResult bytesAndResult = getSop().decrypt() - .withKey(TestKeys.ALICE_KEY.getBytes(StandardCharsets.UTF_8)) + .withKey(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8)) .ciphertext(ciphertext) .toByteArrayAndResult(); @@ -69,12 +69,12 @@ public class ExternalEncryptDecryptRoundTripTest extends AbstractExternalSOPTest public void encryptDecryptRoundTripBobTest() throws IOException { byte[] message = "Hello, World!\n".getBytes(StandardCharsets.UTF_8); byte[] ciphertext = getSop().encrypt() - .withCert(TestKeys.BOB_CERT.getBytes(StandardCharsets.UTF_8)) + .withCert(TestData.BOB_CERT.getBytes(StandardCharsets.UTF_8)) .plaintext(message) .getBytes(); byte[] plaintext = getSop().decrypt() - .withKey(TestKeys.BOB_KEY.getBytes(StandardCharsets.UTF_8)) + .withKey(TestData.BOB_KEY.getBytes(StandardCharsets.UTF_8)) .ciphertext(ciphertext) .toByteArrayAndResult() .getBytes(); @@ -88,12 +88,12 @@ public class ExternalEncryptDecryptRoundTripTest extends AbstractExternalSOPTest byte[] message = "Hello, World!\n".getBytes(StandardCharsets.UTF_8); byte[] ciphertext = getSop().encrypt() - .withCert(TestKeys.CAROL_CERT.getBytes(StandardCharsets.UTF_8)) + .withCert(TestData.CAROL_CERT.getBytes(StandardCharsets.UTF_8)) .plaintext(message) .getBytes(); byte[] plaintext = getSop().decrypt() - .withKey(TestKeys.CAROL_KEY.getBytes(StandardCharsets.UTF_8)) + .withKey(TestData.CAROL_KEY.getBytes(StandardCharsets.UTF_8)) .ciphertext(ciphertext) .toByteArrayAndResult() .getBytes(); @@ -107,7 +107,7 @@ public class ExternalEncryptDecryptRoundTripTest extends AbstractExternalSOPTest byte[] message = "Hello, World!\n".getBytes(StandardCharsets.UTF_8); byte[] ciphertext = getSop().encrypt() - .withCert(TestKeys.ALICE_CERT.getBytes(StandardCharsets.UTF_8)) + .withCert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8)) .noArmor() .plaintext(message) .getBytes(); @@ -117,7 +117,7 @@ public class ExternalEncryptDecryptRoundTripTest extends AbstractExternalSOPTest .getBytes(); ByteArrayAndResult bytesAndResult = getSop().decrypt() - .withKey(TestKeys.ALICE_KEY.getBytes(StandardCharsets.UTF_8)) + .withKey(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8)) .ciphertext(armored) .toByteArrayAndResult(); @@ -129,14 +129,14 @@ public class ExternalEncryptDecryptRoundTripTest extends AbstractExternalSOPTest public void encryptSignDecryptVerifyRoundTripAliceTest() throws IOException { byte[] message = "Hello, World!\n".getBytes(StandardCharsets.UTF_8); byte[] ciphertext = getSop().encrypt() - .withCert(TestKeys.ALICE_CERT.getBytes(StandardCharsets.UTF_8)) - .signWith(TestKeys.ALICE_KEY.getBytes(StandardCharsets.UTF_8)) + .withCert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8)) + .signWith(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8)) .plaintext(message) .getBytes(); ByteArrayAndResult bytesAndResult = getSop().decrypt() - .withKey(TestKeys.ALICE_KEY.getBytes(StandardCharsets.UTF_8)) - .verifyWithCert(TestKeys.ALICE_CERT.getBytes(StandardCharsets.UTF_8)) + .withKey(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8)) + .verifyWithCert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8)) .ciphertext(ciphertext) .toByteArrayAndResult(); @@ -154,15 +154,15 @@ public class ExternalEncryptDecryptRoundTripTest extends AbstractExternalSOPTest public void encryptSignAsTextDecryptVerifyRoundTripAliceTest() throws IOException { byte[] message = "Hello, World!\n".getBytes(StandardCharsets.UTF_8); byte[] ciphertext = getSop().encrypt() - .withCert(TestKeys.ALICE_CERT.getBytes(StandardCharsets.UTF_8)) - .signWith(TestKeys.ALICE_KEY.getBytes(StandardCharsets.UTF_8)) + .withCert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8)) + .signWith(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8)) .mode(EncryptAs.Text) .plaintext(message) .getBytes(); ByteArrayAndResult bytesAndResult = getSop().decrypt() - .withKey(TestKeys.ALICE_KEY.getBytes(StandardCharsets.UTF_8)) - .verifyWithCert(TestKeys.ALICE_CERT.getBytes(StandardCharsets.UTF_8)) + .withKey(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8)) + .verifyWithCert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8)) .ciphertext(ciphertext) .toByteArrayAndResult(); @@ -232,8 +232,8 @@ public class ExternalEncryptDecryptRoundTripTest extends AbstractExternalSOPTest assertThrows(SOPGPException.NoSignature.class, () -> { ByteArrayAndResult bytesAndResult = getSop().decrypt() - .withKey(TestKeys.ALICE_KEY.getBytes(StandardCharsets.UTF_8)) - .verifyWithCert(TestKeys.ALICE_CERT.getBytes(StandardCharsets.UTF_8)) + .withKey(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8)) + .verifyWithCert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8)) .verifyNotAfter(beforeSignature) .ciphertext(message) .toByteArrayAndResult(); @@ -267,8 +267,8 @@ public class ExternalEncryptDecryptRoundTripTest extends AbstractExternalSOPTest assertThrows(SOPGPException.NoSignature.class, () -> { ByteArrayAndResult bytesAndResult = getSop().decrypt() - .withKey(TestKeys.ALICE_KEY.getBytes(StandardCharsets.UTF_8)) - .verifyWithCert(TestKeys.ALICE_CERT.getBytes(StandardCharsets.UTF_8)) + .withKey(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8)) + .verifyWithCert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8)) .verifyNotBefore(afterSignature) .ciphertext(message) .toByteArrayAndResult(); diff --git a/external-sop/src/test/java/sop/external/ExternalExtractCertTest.java b/external-sop/src/test/java/sop/external/ExternalExtractCertTest.java index 98111f2..93357a5 100644 --- a/external-sop/src/test/java/sop/external/ExternalExtractCertTest.java +++ b/external-sop/src/test/java/sop/external/ExternalExtractCertTest.java @@ -36,25 +36,25 @@ public class ExternalExtractCertTest extends AbstractExternalSOPTest { @Test public void extractAliceCertFromAliceKeyTest() throws IOException { byte[] armoredCert = getSop().extractCert() - .key(TestKeys.ALICE_KEY.getBytes(StandardCharsets.UTF_8)) + .key(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8)) .getBytes(); - assertAsciiArmorEquals(TestKeys.ALICE_CERT.getBytes(StandardCharsets.UTF_8), armoredCert); + assertAsciiArmorEquals(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8), armoredCert); } @Test public void extractBobsCertFromBobsKeyTest() throws IOException { byte[] armoredCert = getSop().extractCert() - .key(TestKeys.BOB_KEY.getBytes(StandardCharsets.UTF_8)) + .key(TestData.BOB_KEY.getBytes(StandardCharsets.UTF_8)) .getBytes(); - assertAsciiArmorEquals(TestKeys.BOB_CERT.getBytes(StandardCharsets.UTF_8), armoredCert); + assertAsciiArmorEquals(TestData.BOB_CERT.getBytes(StandardCharsets.UTF_8), armoredCert); } @Test public void extractCarolsCertFromCarolsKeyTest() throws IOException { byte[] armoredCert = getSop().extractCert() - .key(TestKeys.CAROL_KEY.getBytes(StandardCharsets.UTF_8)) + .key(TestData.CAROL_KEY.getBytes(StandardCharsets.UTF_8)) .getBytes(); - assertAsciiArmorEquals(TestKeys.CAROL_CERT.getBytes(StandardCharsets.UTF_8), armoredCert); + assertAsciiArmorEquals(TestData.CAROL_CERT.getBytes(StandardCharsets.UTF_8), armoredCert); } @Test diff --git a/external-sop/src/test/java/sop/external/ExternalInlineSignDetachVerifyRoundTripTest.java b/external-sop/src/test/java/sop/external/ExternalInlineSignDetachVerifyRoundTripTest.java index f49601d..41bc67c 100644 --- a/external-sop/src/test/java/sop/external/ExternalInlineSignDetachVerifyRoundTripTest.java +++ b/external-sop/src/test/java/sop/external/ExternalInlineSignDetachVerifyRoundTripTest.java @@ -31,7 +31,7 @@ public class ExternalInlineSignDetachVerifyRoundTripTest extends AbstractExterna byte[] message = "Hello, World!\n".getBytes(StandardCharsets.UTF_8); byte[] inlineSigned = getSop().inlineSign() - .key(TestKeys.ALICE_KEY.getBytes(StandardCharsets.UTF_8)) + .key(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8)) .data(message) .getBytes(); @@ -46,7 +46,7 @@ public class ExternalInlineSignDetachVerifyRoundTripTest extends AbstractExterna .getBytes(); List verifications = getSop().detachedVerify() - .cert(TestKeys.ALICE_CERT.getBytes(StandardCharsets.UTF_8)) + .cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8)) .signatures(signatures) .data(plaintext); @@ -60,7 +60,7 @@ public class ExternalInlineSignDetachVerifyRoundTripTest extends AbstractExterna byte[] message = "Hello, World!\n".getBytes(StandardCharsets.UTF_8); byte[] inlineSigned = getSop().inlineSign() - .key(TestKeys.ALICE_KEY.getBytes(StandardCharsets.UTF_8)) + .key(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8)) .data(message) .getBytes(); @@ -82,7 +82,7 @@ public class ExternalInlineSignDetachVerifyRoundTripTest extends AbstractExterna assertArrayStartsWith(armored, BEGIN_PGP_SIGNATURE); List verifications = getSop().detachedVerify() - .cert(TestKeys.ALICE_CERT.getBytes(StandardCharsets.UTF_8)) + .cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8)) .signatures(armored) .data(plaintext); diff --git a/external-sop/src/test/java/sop/external/ExternalInlineSignVerifyTest.java b/external-sop/src/test/java/sop/external/ExternalInlineSignVerifyTest.java index d99270c..f0a632e 100644 --- a/external-sop/src/test/java/sop/external/ExternalInlineSignVerifyTest.java +++ b/external-sop/src/test/java/sop/external/ExternalInlineSignVerifyTest.java @@ -10,7 +10,6 @@ import sop.ByteArrayAndResult; import sop.Verification; import sop.enums.InlineSignAs; import sop.exception.SOPGPException; -import sop.util.UTCUtil; import java.io.IOException; import java.nio.charset.StandardCharsets; @@ -20,6 +19,7 @@ import java.util.List; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertThrows; +import static sop.external.JUtils.assertSignedBy; @EnabledIf("sop.external.AbstractExternalSOPTest#isExternalSopInstalled") public class ExternalInlineSignVerifyTest extends AbstractExternalSOPTest { @@ -33,32 +33,33 @@ public class ExternalInlineSignVerifyTest extends AbstractExternalSOPTest { public void inlineSignVerifyAlice() throws IOException { ignoreIf("sqop", Is.leq, "0.26.1"); // inline-sign not supported - byte[] message = "Hello, World!\n".getBytes(StandardCharsets.UTF_8); + byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8); byte[] inlineSigned = getSop().inlineSign() - .key(TestKeys.ALICE_KEY.getBytes(StandardCharsets.UTF_8)) + .key(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8)) .data(message) .getBytes(); JUtils.assertArrayStartsWith(inlineSigned, BEGIN_PGP_MESSAGE_BYTES); ByteArrayAndResult> bytesAndResult = getSop().inlineVerify() - .cert(TestKeys.ALICE_CERT.getBytes(StandardCharsets.UTF_8)) + .cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8)) .data(inlineSigned) .toByteArrayAndResult(); assertArrayEquals(message, bytesAndResult.getBytes()); - assertFalse(bytesAndResult.getResult().isEmpty()); + List verificationList = bytesAndResult.getResult(); + assertSignedBy(verificationList, TestData.ALICE_SIGNING_FINGERPRINT, TestData.ALICE_PRIMARY_FINGERPRINT); } @Test public void inlineSignVerifyAliceNoArmor() throws IOException { ignoreIf("sqop", Is.leq, "0.26.1"); // inline-sign not supported - byte[] message = "Hello, World!\n".getBytes(StandardCharsets.UTF_8); + byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8); byte[] inlineSigned = getSop().inlineSign() - .key(TestKeys.ALICE_KEY.getBytes(StandardCharsets.UTF_8)) + .key(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8)) .noArmor() .data(message) .getBytes(); @@ -66,22 +67,23 @@ public class ExternalInlineSignVerifyTest extends AbstractExternalSOPTest { assertFalse(JUtils.arrayStartsWith(inlineSigned, BEGIN_PGP_MESSAGE_BYTES)); ByteArrayAndResult> bytesAndResult = getSop().inlineVerify() - .cert(TestKeys.ALICE_CERT.getBytes(StandardCharsets.UTF_8)) + .cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8)) .data(inlineSigned) .toByteArrayAndResult(); assertArrayEquals(message, bytesAndResult.getBytes()); - assertFalse(bytesAndResult.getResult().isEmpty()); + List verificationList = bytesAndResult.getResult(); + assertSignedBy(verificationList, TestData.ALICE_SIGNING_FINGERPRINT, TestData.ALICE_PRIMARY_FINGERPRINT); } @Test public void clearsignVerifyAlice() throws IOException { ignoreIf("sqop", Is.leq, "0.26.1"); // inline-sign not supported - byte[] message = "Hello, World!\n".getBytes(StandardCharsets.UTF_8); + byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8); byte[] clearsigned = getSop().inlineSign() - .key(TestKeys.ALICE_KEY.getBytes(StandardCharsets.UTF_8)) + .key(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8)) .mode(InlineSignAs.clearsigned) .data(message) .getBytes(); @@ -89,12 +91,29 @@ public class ExternalInlineSignVerifyTest extends AbstractExternalSOPTest { JUtils.assertArrayStartsWith(clearsigned, BEGIN_PGP_SIGNED_MESSAGE_BYTES); ByteArrayAndResult> bytesAndResult = getSop().inlineVerify() - .cert(TestKeys.ALICE_CERT.getBytes(StandardCharsets.UTF_8)) + .cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8)) .data(clearsigned) .toByteArrayAndResult(); assertArrayEquals(message, bytesAndResult.getBytes()); - assertFalse(bytesAndResult.getResult().isEmpty()); + List verificationList = bytesAndResult.getResult(); + assertSignedBy(verificationList, TestData.ALICE_SIGNING_FINGERPRINT, TestData.ALICE_PRIMARY_FINGERPRINT); + } + + @Test + public void inlineVerifyCompareSignatureDate() throws IOException { + ignoreIf("sqop", Is.leq, "0.26.1"); // inline-sign not supported + ignoreIf("sqop", Is.leq, "0.27.2"); // returns 1 instead of 3 (NO_SIGNATURE) + + byte[] message = TestData.ALICE_INLINE_SIGNED_MESSAGE.getBytes(StandardCharsets.UTF_8); + Date signatureDate = TestData.ALICE_INLINE_SIGNED_MESSAGE_DATE; + + ByteArrayAndResult> bytesAndResult = getSop().inlineVerify() + .cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8)) + .data(message) + .toByteArrayAndResult(); + List verificationList = bytesAndResult.getResult(); + assertSignedBy(verificationList, TestData.ALICE_SIGNING_FINGERPRINT, TestData.ALICE_PRIMARY_FINGERPRINT, signatureDate); } @Test @@ -102,20 +121,13 @@ public class ExternalInlineSignVerifyTest extends AbstractExternalSOPTest { ignoreIf("sqop", Is.leq, "0.26.1"); // inline-sign not supported ignoreIf("sqop", Is.leq, "0.27.2"); // returns 1 instead of 3 (NO_SIGNATURE) - byte[] message = ("-----BEGIN PGP MESSAGE-----\n" + - "\n" + - "owGbwMvMwCX2yTCUx9/9cR/jaZEkBhDwSM3JyddRCM8vyklR5OooZWEQ42JQZ2VK\n" + - "PjjpPacATLmYIsvr1t3xi61KH8ZN8UuGCTMwpPcw/E9jS+vcvPu2gmp4jcRbcSNP\n" + - "FYmW8hmLJdUVrdt1V8w6GM/IMEvN0tP339sNGX4swq8T5p62q3jUfLjpstmcI6Ie\n" + - "sfcfswMA\n" + - "=RDAo\n" + - "-----END PGP MESSAGE-----").getBytes(StandardCharsets.UTF_8); - Date signatureDate = UTCUtil.parseUTCDate("2023-01-13T17:20:47Z"); + 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, () -> getSop().inlineVerify() .notBefore(afterSignature) - .cert(TestKeys.ALICE_CERT.getBytes(StandardCharsets.UTF_8)) + .cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8)) .data(message) .toByteArrayAndResult()); } @@ -125,51 +137,83 @@ public class ExternalInlineSignVerifyTest extends AbstractExternalSOPTest { ignoreIf("sqop", Is.leq, "0.26.1"); // inline-sign not supported ignoreIf("sqop", Is.leq, "0.27.2"); // returns 1 instead of 3 (NO_SIGNATURE) - byte[] message = ("-----BEGIN PGP MESSAGE-----\n" + - "\n" + - "owGbwMvMwCX2yTCUx9/9cR/jaZEkBhDwSM3JyddRCM8vyklR5OooZWEQ42JQZ2VK\n" + - "PjjpPacATLmYIsvr1t3xi61KH8ZN8UuGCTMwpPcw/E9jS+vcvPu2gmp4jcRbcSNP\n" + - "FYmW8hmLJdUVrdt1V8w6GM/IMEvN0tP339sNGX4swq8T5p62q3jUfLjpstmcI6Ie\n" + - "sfcfswMA\n" + - "=RDAo\n" + - "-----END PGP MESSAGE-----").getBytes(StandardCharsets.UTF_8); - Date signatureDate = UTCUtil.parseUTCDate("2023-01-13T17:20:47Z"); + 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, () -> getSop().inlineVerify() .notAfter(beforeSignature) - .cert(TestKeys.ALICE_CERT.getBytes(StandardCharsets.UTF_8)) + .cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8)) .data(message) .toByteArrayAndResult()); } @Test - public void signVerifyWithPasswordProtectedKey() throws IOException { + public void inlineSignVerifyBob() throws IOException { ignoreIf("sqop", Is.leq, "0.26.1"); // inline-sign not supported - byte[] message = "Hello, World!\n".getBytes(StandardCharsets.UTF_8); - byte[] keyPassword = "sw0rdf1sh".getBytes(StandardCharsets.UTF_8); - byte[] key = getSop().generateKey() - .userId("Alice ") - .withKeyPassword(keyPassword) - .generate() - .getBytes(); - byte[] cert = getSop().extractCert() - .key(key) - .getBytes(); + byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8); byte[] inlineSigned = getSop().inlineSign() - .withKeyPassword(keyPassword) - .key(key) + .key(TestData.BOB_KEY.getBytes(StandardCharsets.UTF_8)) + .data(message) + .getBytes(); + + JUtils.assertArrayStartsWith(inlineSigned, BEGIN_PGP_MESSAGE_BYTES); + + ByteArrayAndResult> bytesAndResult = getSop().inlineVerify() + .cert(TestData.BOB_CERT.getBytes(StandardCharsets.UTF_8)) + .data(inlineSigned) + .toByteArrayAndResult(); + + assertArrayEquals(message, bytesAndResult.getBytes()); + List verificationList = bytesAndResult.getResult(); + assertSignedBy(verificationList, TestData.BOB_SIGNING_FINGERPRINT, TestData.BOB_PRIMARY_FINGERPRINT); + } + + @Test + public void inlineSignVerifyCarol() throws IOException { + ignoreIf("sqop", Is.leq, "0.26.1"); // inline-sign not supported + + byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8); + + byte[] inlineSigned = getSop().inlineSign() + .key(TestData.CAROL_KEY.getBytes(StandardCharsets.UTF_8)) + .data(message) + .getBytes(); + + JUtils.assertArrayStartsWith(inlineSigned, BEGIN_PGP_MESSAGE_BYTES); + + ByteArrayAndResult> bytesAndResult = getSop().inlineVerify() + .cert(TestData.CAROL_CERT.getBytes(StandardCharsets.UTF_8)) + .data(inlineSigned) + .toByteArrayAndResult(); + + assertArrayEquals(message, bytesAndResult.getBytes()); + List verificationList = bytesAndResult.getResult(); + assertSignedBy(verificationList, TestData.CAROL_SIGNING_FINGERPRINT, TestData.CAROL_PRIMARY_FINGERPRINT); + } + + @Test + public void inlineSignVerifyProtectedKey() throws IOException { + ignoreIf("sqop", Is.leq, "0.26.1"); // inline-sign not supported + + byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8); + + byte[] inlineSigned = getSop().inlineSign() + .withKeyPassword(TestData.PASSWORD) + .key(TestData.PASSWORD_PROTECTED_KEY.getBytes(StandardCharsets.UTF_8)) .mode(InlineSignAs.binary) .data(message) .getBytes(); - assertFalse(getSop().inlineVerify() - .cert(cert) + ByteArrayAndResult> bytesAndResult = getSop().inlineVerify() + .cert(TestData.PASSWORD_PROTECTED_CERT.getBytes(StandardCharsets.UTF_8)) .data(inlineSigned) - .toByteArrayAndResult() - .getResult() - .isEmpty()); + .toByteArrayAndResult(); + + List verificationList = bytesAndResult.getResult(); + assertSignedBy(verificationList, TestData.PASSWORD_PROTECTED_SIGNING_FINGERPRINT, TestData.PASSWORD_PROTECTED_PRIMARY_FINGERPRINT); } + } diff --git a/external-sop/src/test/java/sop/external/JUtils.java b/external-sop/src/test/java/sop/external/JUtils.java index 38a5829..0b15142 100644 --- a/external-sop/src/test/java/sop/external/JUtils.java +++ b/external-sop/src/test/java/sop/external/JUtils.java @@ -4,8 +4,13 @@ package sop.external; +import sop.Verification; +import sop.util.UTCUtil; + import java.nio.charset.StandardCharsets; import java.util.Arrays; +import java.util.Date; +import java.util.List; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.fail; @@ -110,4 +115,67 @@ public class JUtils { .replaceAll("Charset: .+\\R", ""); return string.getBytes(StandardCharsets.UTF_8); } + + public static void assertSignedBy(List verifications, String primaryFingerprint) { + for (Verification verification : verifications) { + if (verification.getSigningCertFingerprint().equals(primaryFingerprint)) { + return; + } + } + + if (verifications.isEmpty()) { + fail("Verification list is empty."); + } + + fail("Verification list does not contain verification by cert " + primaryFingerprint + ":\n" + + Arrays.toString(verifications.toArray(new Verification[0]))); + } + + public static void assertSignedBy(List verifications, String signingFingerprint, String primaryFingerprint) { + for (Verification verification : verifications) { + if (verification.getSigningCertFingerprint().equals(primaryFingerprint) && verification.getSigningKeyFingerprint().equals(signingFingerprint)) { + return; + } + } + + if (verifications.isEmpty()) { + fail("Verification list is empty."); + } + + fail("Verification list does not contain verification by key " + signingFingerprint + " on cert " + primaryFingerprint + ":\n" + + Arrays.toString(verifications.toArray(new Verification[0]))); + } + + public static void assertSignedBy(List verifications, String primaryFingerprint, Date signatureDate) { + for (Verification verification : verifications) { + if (verification.getSigningCertFingerprint().equals(primaryFingerprint) && + verification.getCreationTime().equals(signatureDate)) { + return; + } + } + + if (verifications.isEmpty()) { + fail("Verification list is empty."); + } + + fail("Verification list does not contain verification by cert " + primaryFingerprint + " made at " + UTCUtil.formatUTCDate(signatureDate) + ":\n" + + Arrays.toString(verifications.toArray(new Verification[0]))); + } + + public static void assertSignedBy(List verifications, String signingFingerprint, String primaryFingerprint, Date signatureDate) { + for (Verification verification : verifications) { + if (verification.getSigningCertFingerprint().equals(primaryFingerprint) && + verification.getSigningKeyFingerprint().equals(signingFingerprint) && + verification.getCreationTime().equals(signatureDate)) { + return; + } + } + + if (verifications.isEmpty()) { + fail("Verification list is empty."); + } + + fail("Verification list does not contain verification by key" + signingFingerprint + " on cert " + primaryFingerprint + " made at " + UTCUtil.formatUTCDate(signatureDate) + ":\n" + + Arrays.toString(verifications.toArray(new Verification[0]))); + } } diff --git a/external-sop/src/test/java/sop/external/TestKeys.java b/external-sop/src/test/java/sop/external/TestData.java similarity index 93% rename from external-sop/src/test/java/sop/external/TestKeys.java rename to external-sop/src/test/java/sop/external/TestData.java index b7f73c3..640c70f 100644 --- a/external-sop/src/test/java/sop/external/TestKeys.java +++ b/external-sop/src/test/java/sop/external/TestData.java @@ -4,7 +4,14 @@ package sop.external; -public class TestKeys { +import sop.util.UTCUtil; + +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" + @@ -40,6 +47,27 @@ public class TestKeys { "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 = UTCUtil.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 = UTCUtil.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" + @@ -169,6 +197,8 @@ public class TestKeys { "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" + @@ -304,6 +334,8 @@ public class TestKeys { "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" + @@ -375,4 +407,6 @@ public class TestKeys { "=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"; }