From 01f81fabaa8bf9240494a3837a13f54d5a17ea5d Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Sun, 30 Aug 2020 13:16:47 +0200 Subject: [PATCH] Add OnePassSignature verification test --- .../EncryptDecryptTest.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/pgpainless-core/src/test/java/org/pgpainless/encryption_signing/EncryptDecryptTest.java b/pgpainless-core/src/test/java/org/pgpainless/encryption_signing/EncryptDecryptTest.java index d4a18227..981bad98 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/encryption_signing/EncryptDecryptTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/encryption_signing/EncryptDecryptTest.java @@ -227,4 +227,36 @@ public class EncryptDecryptTest { metadata = verifier.getResult(); assertFalse(metadata.getVerifiedSignatures().isEmpty()); } + + @Test + public void testOnePassSignatureCreationAndVerification() throws IOException, PGPException { + PGPKeyRing signingKeys = new PGPKeyRing(TestKeys.getJulietPublicKeyRing(), TestKeys.getJulietSecretKeyRing()); + SecretKeyRingProtector keyRingProtector = new UnprotectedKeysProtector(); + byte[] data = testMessage.getBytes(); + ByteArrayInputStream inputStream = new ByteArrayInputStream(data); + ByteArrayOutputStream signOut = new ByteArrayOutputStream(); + EncryptionStream signer = PGPainless.createEncryptor().onOutputStream(signOut) + .doNotEncrypt() + .signWith(keyRingProtector, signingKeys.getSecretKeys()) + .asciiArmor(); + Streams.pipeAll(inputStream, signer); + signer.close(); + + // CHECKSTYLE:OFF + System.out.println(signOut.toString()); + // CHECKSTYLE:ON + + inputStream = new ByteArrayInputStream(signOut.toByteArray()); + DecryptionStream verifier = PGPainless.createDecryptor().onInputStream(inputStream) + .doNotDecrypt() + .verifyWith(Collections.singleton(signingKeys.getPublicKeys())) + .ignoreMissingPublicKeys() + .build(); + signOut = new ByteArrayOutputStream(); + Streams.pipeAll(verifier, signOut); + verifier.close(); + + OpenPgpMetadata metadata = verifier.getResult(); + assertFalse(metadata.getVerifiedSignatures().isEmpty()); + } }