mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 19:59:05 +01:00
Merge branch 'add-contact-transaction' into 'master'
Add contact and transport keys in the same transaction This avoids a potential problem where the app crashes after adding the contact but before adding the transport keys, leaving the contact unusable. See merge request !112
This commit is contained in:
@@ -31,6 +31,7 @@ import org.briarproject.event.EventModule;
|
||||
import org.briarproject.forum.ForumModule;
|
||||
import org.briarproject.identity.IdentityModule;
|
||||
import org.briarproject.messaging.MessagingModule;
|
||||
import org.briarproject.transport.TransportModule;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Random;
|
||||
@@ -57,7 +58,8 @@ public class ConstantsTest extends BriarTestCase {
|
||||
new TestLifecycleModule(), new TestSystemModule(),
|
||||
new ContactModule(), new CryptoModule(), new DatabaseModule(),
|
||||
new DataModule(), new EventModule(), new ForumModule(),
|
||||
new IdentityModule(), new MessagingModule(), new SyncModule());
|
||||
new IdentityModule(), new MessagingModule(), new SyncModule(),
|
||||
new TransportModule());
|
||||
crypto = i.getInstance(CryptoComponent.class);
|
||||
authorFactory = i.getInstance(AuthorFactory.class);
|
||||
privateMessageFactory = i.getInstance(PrivateMessageFactory.class);
|
||||
|
||||
@@ -135,9 +135,7 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase {
|
||||
Author bobAuthor = new Author(bobId, "Bob",
|
||||
new byte[MAX_PUBLIC_KEY_LENGTH]);
|
||||
ContactId contactId = contactManager.addContact(bobAuthor, aliceId,
|
||||
true);
|
||||
// Derive and store the transport keys
|
||||
keyManager.addContact(contactId, master, timestamp, true);
|
||||
master, timestamp, true, true);
|
||||
|
||||
// Send Bob a message
|
||||
GroupId groupId = messagingManager.getConversationId(contactId);
|
||||
@@ -206,9 +204,7 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase {
|
||||
Author aliceAuthor = new Author(aliceId, "Alice",
|
||||
new byte[MAX_PUBLIC_KEY_LENGTH]);
|
||||
ContactId contactId = contactManager.addContact(aliceAuthor, bobId,
|
||||
true);
|
||||
// Derive and store the transport keys
|
||||
keyManager.addContact(contactId, master, timestamp, false);
|
||||
master, timestamp, false, true);
|
||||
|
||||
// Set up an event listener
|
||||
MessageListener listener = new MessageListener();
|
||||
|
||||
@@ -133,17 +133,15 @@ public class TransportKeyManagerTest extends BriarTestCase {
|
||||
will(new EncodeTagAction());
|
||||
}
|
||||
// Save the keys
|
||||
oneOf(db).startTransaction();
|
||||
will(returnValue(txn));
|
||||
oneOf(db).addTransportKeys(txn, contactId, rotated);
|
||||
oneOf(db).endTransaction(txn);
|
||||
}});
|
||||
|
||||
TransportKeyManager transportKeyManager = new TransportKeyManager(db,
|
||||
crypto, timer, clock, transportId, maxLatency);
|
||||
// The timestamp is 1 ms before the start of rotation period 1000
|
||||
long timestamp = rotationPeriodLength * 1000 - 1;
|
||||
transportKeyManager.addContact(contactId, masterKey, timestamp, alice);
|
||||
transportKeyManager.addContact(txn, contactId, masterKey, timestamp,
|
||||
alice);
|
||||
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
@@ -194,17 +192,15 @@ public class TransportKeyManagerTest extends BriarTestCase {
|
||||
oneOf(crypto).rotateTransportKeys(transportKeys, 1000);
|
||||
will(returnValue(transportKeys));
|
||||
// Save the keys
|
||||
oneOf(db).startTransaction();
|
||||
will(returnValue(txn));
|
||||
oneOf(db).addTransportKeys(txn, contactId, transportKeys);
|
||||
oneOf(db).endTransaction(txn);
|
||||
}});
|
||||
|
||||
TransportKeyManager transportKeyManager = new TransportKeyManager(db,
|
||||
crypto, timer, clock, transportId, maxLatency);
|
||||
// The timestamp is at the start of rotation period 1000
|
||||
long timestamp = rotationPeriodLength * 1000;
|
||||
transportKeyManager.addContact(contactId, masterKey, timestamp, alice);
|
||||
transportKeyManager.addContact(txn, contactId, masterKey, timestamp,
|
||||
alice);
|
||||
assertNull(transportKeyManager.getStreamContext(contactId));
|
||||
|
||||
context.assertIsSatisfied();
|
||||
@@ -240,10 +236,7 @@ public class TransportKeyManagerTest extends BriarTestCase {
|
||||
oneOf(crypto).rotateTransportKeys(transportKeys, 1000);
|
||||
will(returnValue(transportKeys));
|
||||
// Save the keys
|
||||
oneOf(db).startTransaction();
|
||||
will(returnValue(txn));
|
||||
oneOf(db).addTransportKeys(txn, contactId, transportKeys);
|
||||
oneOf(db).endTransaction(txn);
|
||||
// Increment the stream counter
|
||||
oneOf(db).startTransaction();
|
||||
will(returnValue(txn1));
|
||||
@@ -256,7 +249,8 @@ public class TransportKeyManagerTest extends BriarTestCase {
|
||||
crypto, timer, clock, transportId, maxLatency);
|
||||
// The timestamp is at the start of rotation period 1000
|
||||
long timestamp = rotationPeriodLength * 1000;
|
||||
transportKeyManager.addContact(contactId, masterKey, timestamp, alice);
|
||||
transportKeyManager.addContact(txn, contactId, masterKey, timestamp,
|
||||
alice);
|
||||
// The first request should return a stream context
|
||||
StreamContext ctx = transportKeyManager.getStreamContext(contactId);
|
||||
assertNotNull(ctx);
|
||||
@@ -299,17 +293,15 @@ public class TransportKeyManagerTest extends BriarTestCase {
|
||||
oneOf(crypto).rotateTransportKeys(transportKeys, 1000);
|
||||
will(returnValue(transportKeys));
|
||||
// Save the keys
|
||||
oneOf(db).startTransaction();
|
||||
will(returnValue(txn));
|
||||
oneOf(db).addTransportKeys(txn, contactId, transportKeys);
|
||||
oneOf(db).endTransaction(txn);
|
||||
}});
|
||||
|
||||
TransportKeyManager transportKeyManager = new TransportKeyManager(db,
|
||||
crypto, timer, clock, transportId, maxLatency);
|
||||
// The timestamp is at the start of rotation period 1000
|
||||
long timestamp = rotationPeriodLength * 1000;
|
||||
transportKeyManager.addContact(contactId, masterKey, timestamp, alice);
|
||||
transportKeyManager.addContact(txn, contactId, masterKey, timestamp,
|
||||
alice);
|
||||
assertNull(transportKeyManager.getStreamContext(new byte[TAG_LENGTH]));
|
||||
|
||||
context.assertIsSatisfied();
|
||||
@@ -345,10 +337,7 @@ public class TransportKeyManagerTest extends BriarTestCase {
|
||||
oneOf(crypto).rotateTransportKeys(transportKeys, 1000);
|
||||
will(returnValue(transportKeys));
|
||||
// Save the keys
|
||||
oneOf(db).startTransaction();
|
||||
will(returnValue(txn));
|
||||
oneOf(db).addTransportKeys(txn, contactId, transportKeys);
|
||||
oneOf(db).endTransaction(txn);
|
||||
// Encode a new tag after sliding the window
|
||||
oneOf(crypto).encodeTag(with(any(byte[].class)),
|
||||
with(tagKey), with((long) REORDERING_WINDOW_SIZE));
|
||||
@@ -365,7 +354,8 @@ public class TransportKeyManagerTest extends BriarTestCase {
|
||||
crypto, timer, clock, transportId, maxLatency);
|
||||
// The timestamp is at the start of rotation period 1000
|
||||
long timestamp = rotationPeriodLength * 1000;
|
||||
transportKeyManager.addContact(contactId, masterKey, timestamp, alice);
|
||||
transportKeyManager.addContact(txn, contactId, masterKey, timestamp,
|
||||
alice);
|
||||
// Use the first tag (previous rotation period, stream number 0)
|
||||
assertEquals(REORDERING_WINDOW_SIZE * 3, tags.size());
|
||||
byte[] tag = tags.get(0);
|
||||
|
||||
Reference in New Issue
Block a user