Throw NoSessionException in GroupCipher decrypt()

This commit is contained in:
Moxie Marlinspike 2015-04-06 12:28:16 -07:00
parent 3d9c944288
commit 8335b0ef03
2 changed files with 33 additions and 3 deletions

View File

@ -102,7 +102,7 @@ public class GroupCipher {
* @throws DuplicateMessageException * @throws DuplicateMessageException
*/ */
public byte[] decrypt(byte[] senderKeyMessageBytes) public byte[] decrypt(byte[] senderKeyMessageBytes)
throws LegacyMessageException, DuplicateMessageException, InvalidMessageException throws LegacyMessageException, DuplicateMessageException, InvalidMessageException, NoSessionException
{ {
return decrypt(senderKeyMessageBytes, new NullDecryptionCallback()); return decrypt(senderKeyMessageBytes, new NullDecryptionCallback());
} }
@ -123,11 +123,17 @@ public class GroupCipher {
* @throws DuplicateMessageException * @throws DuplicateMessageException
*/ */
public byte[] decrypt(byte[] senderKeyMessageBytes, DecryptionCallback callback) public byte[] decrypt(byte[] senderKeyMessageBytes, DecryptionCallback callback)
throws LegacyMessageException, InvalidMessageException, DuplicateMessageException throws LegacyMessageException, InvalidMessageException, DuplicateMessageException,
NoSessionException
{ {
synchronized (LOCK) { synchronized (LOCK) {
try { try {
SenderKeyRecord record = senderKeyStore.loadSenderKey(senderKeyId); SenderKeyRecord record = senderKeyStore.loadSenderKey(senderKeyId);
if (record.isEmpty()) {
throw new NoSessionException("No sender key for: " + senderKeyId);
}
SenderKeyMessage senderKeyMessage = new SenderKeyMessage(senderKeyMessageBytes); SenderKeyMessage senderKeyMessage = new SenderKeyMessage(senderKeyMessageBytes);
SenderKeyState senderKeyState = record.getSenderKeyState(senderKeyMessage.getKeyId()); SenderKeyState senderKeyState = record.getSenderKeyState(senderKeyMessage.getKeyId());

View File

@ -18,6 +18,30 @@ public class GroupCipherTest extends TestCase {
private static final AxolotlAddress SENDER_ADDRESS = new AxolotlAddress("+14150001111", 1); private static final AxolotlAddress SENDER_ADDRESS = new AxolotlAddress("+14150001111", 1);
private static final SenderKeyName GROUP_SENDER = new SenderKeyName("nihilist history reading group", SENDER_ADDRESS); private static final SenderKeyName GROUP_SENDER = new SenderKeyName("nihilist history reading group", SENDER_ADDRESS);
public void testNoSession() throws InvalidMessageException, LegacyMessageException, NoSessionException, DuplicateMessageException {
InMemorySenderKeyStore aliceStore = new InMemorySenderKeyStore();
InMemorySenderKeyStore bobStore = new InMemorySenderKeyStore();
GroupSessionBuilder aliceSessionBuilder = new GroupSessionBuilder(aliceStore);
GroupSessionBuilder bobSessionBuilder = new GroupSessionBuilder(bobStore);
GroupCipher aliceGroupCipher = new GroupCipher(aliceStore, GROUP_SENDER);
GroupCipher bobGroupCipher = new GroupCipher(bobStore, GROUP_SENDER);
SenderKeyDistributionMessage sentAliceDistributionMessage = aliceSessionBuilder.create(GROUP_SENDER);
SenderKeyDistributionMessage receivedAliceDistributionMessage = new SenderKeyDistributionMessage(sentAliceDistributionMessage.serialize());
// bobSessionBuilder.process(GROUP_SENDER, receivedAliceDistributionMessage);
byte[] ciphertextFromAlice = aliceGroupCipher.encrypt("smert ze smert".getBytes());
try {
byte[] plaintextFromAlice = bobGroupCipher.decrypt(ciphertextFromAlice);
throw new AssertionError("Should be no session!");
} catch (NoSessionException e) {
// good
}
}
public void testBasicEncryptDecrypt() public void testBasicEncryptDecrypt()
throws LegacyMessageException, DuplicateMessageException, InvalidMessageException, NoSessionException throws LegacyMessageException, DuplicateMessageException, InvalidMessageException, NoSessionException
{ {