This repository has been archived by the owner on Oct 15, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 283
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix null pointer exception when using public only keys (#3143)
- Loading branch information
Greg Renda
committed
Jul 30, 2024
1 parent
f1cb72a
commit c55c2da
Showing
2 changed files
with
37 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 <[email protected]>", KEY_PASSPHRASE) | ||
val bob = PGPainless.generateKeyRing().modernKeyRing("Bob <[email protected]>", 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) | ||
} | ||
} |