diff options
author | Moxie Marlinspike <moxie@thoughtcrime.org> | 2015-04-06 12:21:54 -0700 |
---|---|---|
committer | Moxie Marlinspike <moxie@thoughtcrime.org> | 2015-04-06 12:21:54 -0700 |
commit | 3d9c94428898f6e633b67082237b620c7877f5c1 (patch) | |
tree | 07c0b0d5c4ad1698b2436c47acc7a3858b8c6c2f /java | |
parent | 0c98e9f80eaa81da7f4e557395ad7714e690c661 (diff) |
Add decryption callback to group decrypt operations.
Diffstat (limited to 'java')
3 files changed, 34 insertions, 4 deletions
diff --git a/java/src/main/java/org/whispersystems/libaxolotl/DecryptionCallback.java b/java/src/main/java/org/whispersystems/libaxolotl/DecryptionCallback.java new file mode 100644 index 00000000..1c70d6be --- /dev/null +++ b/java/src/main/java/org/whispersystems/libaxolotl/DecryptionCallback.java @@ -0,0 +1,5 @@ +package org.whispersystems.libaxolotl; + +public interface DecryptionCallback { + public void handlePlaintext(byte[] plaintext); +}
\ No newline at end of file diff --git a/java/src/main/java/org/whispersystems/libaxolotl/SessionCipher.java b/java/src/main/java/org/whispersystems/libaxolotl/SessionCipher.java index b9cc6ac1..071e0905 100644 --- a/java/src/main/java/org/whispersystems/libaxolotl/SessionCipher.java +++ b/java/src/main/java/org/whispersystems/libaxolotl/SessionCipher.java @@ -455,10 +455,6 @@ public class SessionCipher { } } - public static interface DecryptionCallback { - public void handlePlaintext(byte[] plaintext); - } - private static class NullDecryptionCallback implements DecryptionCallback { @Override public void handlePlaintext(byte[] plaintext) {} diff --git a/java/src/main/java/org/whispersystems/libaxolotl/groups/GroupCipher.java b/java/src/main/java/org/whispersystems/libaxolotl/groups/GroupCipher.java index 778ca916..55e261ac 100644 --- a/java/src/main/java/org/whispersystems/libaxolotl/groups/GroupCipher.java +++ b/java/src/main/java/org/whispersystems/libaxolotl/groups/GroupCipher.java @@ -16,6 +16,7 @@ */ package org.whispersystems.libaxolotl.groups; +import org.whispersystems.libaxolotl.DecryptionCallback; import org.whispersystems.libaxolotl.DuplicateMessageException; import org.whispersystems.libaxolotl.InvalidKeyIdException; import org.whispersystems.libaxolotl.InvalidMessageException; @@ -101,6 +102,27 @@ public class GroupCipher { * @throws DuplicateMessageException */ public byte[] decrypt(byte[] senderKeyMessageBytes) + throws LegacyMessageException, DuplicateMessageException, InvalidMessageException + { + return decrypt(senderKeyMessageBytes, new NullDecryptionCallback()); + } + + /** + * Decrypt a SenderKey group message. + * + * @param senderKeyMessageBytes The received ciphertext. + * @param callback A callback that is triggered after decryption is complete, + * but before the updated session state has been committed to the session + * DB. This allows some implementations to store the committed plaintext + * to a DB first, in case they are concerned with a crash happening between + * the time the session state is updated but before they're able to store + * the plaintext to disk. + * @return Plaintext + * @throws LegacyMessageException + * @throws InvalidMessageException + * @throws DuplicateMessageException + */ + public byte[] decrypt(byte[] senderKeyMessageBytes, DecryptionCallback callback) throws LegacyMessageException, InvalidMessageException, DuplicateMessageException { synchronized (LOCK) { @@ -115,6 +137,8 @@ public class GroupCipher { byte[] plaintext = getPlainText(senderKey.getIv(), senderKey.getCipherKey(), senderKeyMessage.getCipherText()); + callback.handlePlaintext(plaintext); + senderKeyStore.storeSenderKey(senderKeyId, record); return plaintext; @@ -185,4 +209,9 @@ public class GroupCipher { } } + private static class NullDecryptionCallback implements DecryptionCallback { + @Override + public void handlePlaintext(byte[] plaintext) {} + } + } |