aboutsummaryrefslogtreecommitdiff
path: root/crypto/pgpainless/src/test/kotlin/app
diff options
context:
space:
mode:
authorGreg Renda <104654128+gregrenda@users.noreply.github.com>2024-07-30 11:31:10 -0700
committerGitHub <noreply@github.com>2024-07-30 18:31:10 +0000
commitb5b7f746dfd6cf9be752431978e05f19c5d2c2cd (patch)
tree90436dfd3dafed1924d6fca49ae9b91fbc5b710e /crypto/pgpainless/src/test/kotlin/app
parent1ae6cc4c8f3e2187133bdc023f2e0e8b2aeb96d5 (diff)
fix null pointer exception when using public only keys (#3143) (#3144)
Co-authored-by: Greg Renda <greg@renda.org>
Diffstat (limited to 'crypto/pgpainless/src/test/kotlin/app')
-rw-r--r--crypto/pgpainless/src/test/kotlin/app/passwordstore/crypto/PGPainlessCryptoHandlerTest.kt36
1 files changed, 36 insertions, 0 deletions
diff --git a/crypto/pgpainless/src/test/kotlin/app/passwordstore/crypto/PGPainlessCryptoHandlerTest.kt b/crypto/pgpainless/src/test/kotlin/app/passwordstore/crypto/PGPainlessCryptoHandlerTest.kt
index 600cc39d..55c3faeb 100644
--- a/crypto/pgpainless/src/test/kotlin/app/passwordstore/crypto/PGPainlessCryptoHandlerTest.kt
+++ b/crypto/pgpainless/src/test/kotlin/app/passwordstore/crypto/PGPainlessCryptoHandlerTest.kt
@@ -181,4 +181,40 @@ class PGPainlessCryptoHandlerTest {
assertTrue { cryptoHandler.canHandle("example.com.gpg") }
assertFalse { cryptoHandler.canHandle("example.com.asc") }
}
+
+ @Test
+ fun decryptWithPublicKeys() {
+ val alice =
+ PGPainless.generateKeyRing().modernKeyRing("Alice <owner@example.com>", KEY_PASSPHRASE)
+ val bob = PGPainless.generateKeyRing().modernKeyRing("Bob <owner@example.com>", KEY_PASSPHRASE)
+ val bobCertificate = PGPainless.extractCertificate(bob)
+ val aliceKey = PGPKey(PGPainless.asciiArmor(alice).encodeToByteArray())
+ val bobPublicKey = PGPKey(PGPainless.asciiArmor(bobCertificate).encodeToByteArray())
+ val ciphertextStream = ByteArrayOutputStream()
+ val encryptRes =
+ cryptoHandler.encrypt(
+ listOf(aliceKey, bobPublicKey),
+ PLAIN_TEXT.byteInputStream(Charsets.UTF_8),
+ ciphertextStream,
+ PGPEncryptOptions.Builder().withAsciiArmor(true).build(),
+ )
+ assertTrue(encryptRes.isOk)
+ val message = ciphertextStream.toByteArray().decodeToString()
+ val info = MessageInspector.determineEncryptionInfoForMessage(message)
+ assertTrue(info.isEncrypted)
+ assertEquals(2, info.keyIds.size)
+ assertFalse(info.isSignedOnly)
+
+ val ciphertextStreamCopy = message.byteInputStream()
+ val plaintextStream = ByteArrayOutputStream()
+ val res =
+ cryptoHandler.decrypt(
+ listOf(aliceKey, bobPublicKey),
+ KEY_PASSPHRASE,
+ ciphertextStreamCopy,
+ plaintextStream,
+ PGPDecryptOptions.Builder().build(),
+ )
+ assertTrue(res.isOk)
+ }
}