diff --git a/bramble-api/src/main/java/org/briarproject/bramble/api/transport/KeyManager.java b/bramble-api/src/main/java/org/briarproject/bramble/api/transport/KeyManager.java index 1651a135a..75ae88d86 100644 --- a/bramble-api/src/main/java/org/briarproject/bramble/api/transport/KeyManager.java +++ b/bramble-api/src/main/java/org/briarproject/bramble/api/transport/KeyManager.java @@ -28,9 +28,9 @@ public interface KeyManager { * @param alice True if the local party is Alice * @param active Whether the derived keys can be used for outgoing streams */ - Map addContact(Transaction txn, ContactId c, - SecretKey rootKey, long timestamp, boolean alice, boolean active) - throws DbException; + Map addContactWithRotationKeys(Transaction txn, + ContactId c, SecretKey rootKey, long timestamp, boolean alice, + boolean active) throws DbException; /** * Informs the key manager that a new contact has been added. Derives and @@ -42,8 +42,8 @@ public interface KeyManager { * * @param alice True if the local party is Alice */ - Map addContact(Transaction txn, ContactId c, - SecretKey rootKey, boolean alice) throws DbException; + Map addContactWithHandshakeKeys(Transaction txn, + ContactId c, SecretKey rootKey, boolean alice) throws DbException; /** * Informs the key manager that a new pending contact has been added. diff --git a/bramble-core/src/main/java/org/briarproject/bramble/contact/ContactManagerImpl.java b/bramble-core/src/main/java/org/briarproject/bramble/contact/ContactManagerImpl.java index 632d9226b..985793843 100644 --- a/bramble-core/src/main/java/org/briarproject/bramble/contact/ContactManagerImpl.java +++ b/bramble-core/src/main/java/org/briarproject/bramble/contact/ContactManagerImpl.java @@ -70,7 +70,8 @@ class ContactManagerImpl implements ContactManager { SecretKey rootKey, long timestamp, boolean alice, boolean verified, boolean active) throws DbException { ContactId c = db.addContact(txn, remote, local, verified); - keyManager.addContact(txn, c, rootKey, timestamp, alice, active); + keyManager.addContactWithRotationKeys(txn, c, rootKey, timestamp, + alice, active); Contact contact = db.getContact(txn, c); for (ContactHook hook : hooks) hook.addingContact(txn, contact); return c; diff --git a/bramble-core/src/main/java/org/briarproject/bramble/transport/KeyManagerImpl.java b/bramble-core/src/main/java/org/briarproject/bramble/transport/KeyManagerImpl.java index 036b9d2d9..b5adf450d 100644 --- a/bramble-core/src/main/java/org/briarproject/bramble/transport/KeyManagerImpl.java +++ b/bramble-core/src/main/java/org/briarproject/bramble/transport/KeyManagerImpl.java @@ -89,26 +89,28 @@ class KeyManagerImpl implements KeyManager, Service, EventListener { } @Override - public Map addContact(Transaction txn, - ContactId c, SecretKey rootKey, long timestamp, boolean alice, - boolean active) throws DbException { + public Map addContactWithRotationKeys( + Transaction txn, ContactId c, SecretKey rootKey, long timestamp, + boolean alice, boolean active) throws DbException { Map ids = new HashMap<>(); for (Entry e : managers.entrySet()) { TransportId t = e.getKey(); TransportKeyManager m = e.getValue(); - ids.put(t, m.addContact(txn, c, rootKey, timestamp, alice, active)); + ids.put(t, m.addContactWithRotationKeys(txn, c, rootKey, timestamp, + alice, active)); } return ids; } @Override - public Map addContact(Transaction txn, - ContactId c, SecretKey rootKey, boolean alice) throws DbException { + public Map addContactWithHandshakeKeys( + Transaction txn, ContactId c, SecretKey rootKey, boolean alice) + throws DbException { Map ids = new HashMap<>(); for (Entry e : managers.entrySet()) { TransportId t = e.getKey(); TransportKeyManager m = e.getValue(); - ids.put(t, m.addContact(txn, c, rootKey, alice)); + ids.put(t, m.addContactWithHandshakeKeys(txn, c, rootKey, alice)); } return ids; } diff --git a/bramble-core/src/main/java/org/briarproject/bramble/transport/TransportKeyManager.java b/bramble-core/src/main/java/org/briarproject/bramble/transport/TransportKeyManager.java index bed597398..45be00197 100644 --- a/bramble-core/src/main/java/org/briarproject/bramble/transport/TransportKeyManager.java +++ b/bramble-core/src/main/java/org/briarproject/bramble/transport/TransportKeyManager.java @@ -16,11 +16,12 @@ interface TransportKeyManager { void start(Transaction txn) throws DbException; - KeySetId addContact(Transaction txn, ContactId c, SecretKey rootKey, - long timestamp, boolean alice, boolean active) throws DbException; + KeySetId addContactWithRotationKeys(Transaction txn, ContactId c, + SecretKey rootKey, long timestamp, boolean alice, boolean active) + throws DbException; - KeySetId addContact(Transaction txn, ContactId c, SecretKey rootKey, - boolean alice) throws DbException; + KeySetId addContactWithHandshakeKeys(Transaction txn, ContactId c, + SecretKey rootKey, boolean alice) throws DbException; KeySetId addPendingContact(Transaction txn, PendingContactId p, SecretKey rootKey, boolean alice) throws DbException; diff --git a/bramble-core/src/main/java/org/briarproject/bramble/transport/TransportKeyManagerImpl.java b/bramble-core/src/main/java/org/briarproject/bramble/transport/TransportKeyManagerImpl.java index ba31f851c..81255dbc3 100644 --- a/bramble-core/src/main/java/org/briarproject/bramble/transport/TransportKeyManagerImpl.java +++ b/bramble-core/src/main/java/org/briarproject/bramble/transport/TransportKeyManagerImpl.java @@ -207,8 +207,9 @@ class TransportKeyManagerImpl implements TransportKeyManager { } @Override - public KeySetId addContact(Transaction txn, ContactId c, SecretKey rootKey, - long timestamp, boolean alice, boolean active) throws DbException { + public KeySetId addContactWithRotationKeys(Transaction txn, ContactId c, + SecretKey rootKey, long timestamp, boolean alice, boolean active) + throws DbException { lock.lock(); try { // Work out what time period the timestamp belongs to @@ -230,8 +231,8 @@ class TransportKeyManagerImpl implements TransportKeyManager { } @Override - public KeySetId addContact(Transaction txn, ContactId c, SecretKey rootKey, - boolean alice) throws DbException { + public KeySetId addContactWithHandshakeKeys(Transaction txn, ContactId c, + SecretKey rootKey, boolean alice) throws DbException { lock.lock(); try { // Work out what time period we're in diff --git a/bramble-core/src/test/java/org/briarproject/bramble/contact/ContactManagerImplTest.java b/bramble-core/src/test/java/org/briarproject/bramble/contact/ContactManagerImplTest.java index df7463983..86a3932ee 100644 --- a/bramble-core/src/test/java/org/briarproject/bramble/contact/ContactManagerImplTest.java +++ b/bramble-core/src/test/java/org/briarproject/bramble/contact/ContactManagerImplTest.java @@ -73,8 +73,8 @@ public class ContactManagerImplTest extends BrambleMockTestCase { oneOf(db).transactionWithResult(with(false), withDbCallable(txn)); oneOf(db).addContact(txn, remote, local, verified); will(returnValue(contactId)); - oneOf(keyManager).addContact(txn, contactId, rootKey, timestamp, - alice, active); + oneOf(keyManager).addContactWithRotationKeys(txn, contactId, + rootKey, timestamp, alice, active); oneOf(db).getContact(txn, contactId); will(returnValue(contact)); }}); diff --git a/bramble-core/src/test/java/org/briarproject/bramble/transport/KeyManagerImplTest.java b/bramble-core/src/test/java/org/briarproject/bramble/transport/KeyManagerImplTest.java index 7d212aff5..0220c358b 100644 --- a/bramble-core/src/test/java/org/briarproject/bramble/transport/KeyManagerImplTest.java +++ b/bramble-core/src/test/java/org/briarproject/bramble/transport/KeyManagerImplTest.java @@ -98,13 +98,13 @@ public class KeyManagerImplTest extends BrambleMockTestCase { boolean active = random.nextBoolean(); context.checking(new Expectations() {{ - oneOf(transportKeyManager).addContact(txn, contactId, secretKey, - timestamp, alice, active); + oneOf(transportKeyManager).addContactWithRotationKeys(txn, + contactId, secretKey, timestamp, alice, active); will(returnValue(keySetId)); }}); - Map ids = keyManager.addContact(txn, contactId, - secretKey, timestamp, alice, active); + Map ids = keyManager.addContactWithRotationKeys( + txn, contactId, secretKey, timestamp, alice, active); assertEquals(singletonMap(transportId, keySetId), ids); } @@ -114,13 +114,13 @@ public class KeyManagerImplTest extends BrambleMockTestCase { boolean alice = random.nextBoolean(); context.checking(new Expectations() {{ - oneOf(transportKeyManager).addContact(txn, contactId, secretKey, - alice); + oneOf(transportKeyManager).addContactWithHandshakeKeys( + txn, contactId, secretKey, alice); will(returnValue(keySetId)); }}); - Map ids = keyManager.addContact(txn, contactId, - secretKey, alice); + Map ids = keyManager.addContactWithHandshakeKeys( + txn, contactId, secretKey, alice); assertEquals(singletonMap(transportId, keySetId), ids); } diff --git a/bramble-core/src/test/java/org/briarproject/bramble/transport/TransportKeyManagerImplTest.java b/bramble-core/src/test/java/org/briarproject/bramble/transport/TransportKeyManagerImplTest.java index 57abdab52..660476610 100644 --- a/bramble-core/src/test/java/org/briarproject/bramble/transport/TransportKeyManagerImplTest.java +++ b/bramble-core/src/test/java/org/briarproject/bramble/transport/TransportKeyManagerImplTest.java @@ -156,8 +156,8 @@ public class TransportKeyManagerImplTest extends BrambleMockTestCase { maxLatency); // The timestamp is 1 ms before the start of time period 1000 long timestamp = timePeriodLength * 1000 - 1; - assertEquals(keySetId, transportKeyManager.addContact(txn, contactId, - rootKey, timestamp, alice, active)); + assertEquals(keySetId, transportKeyManager.addContactWithRotationKeys( + txn, contactId, rootKey, timestamp, alice, active)); assertEquals(active, transportKeyManager.canSendOutgoingStreams(contactId)); } @@ -192,8 +192,8 @@ public class TransportKeyManagerImplTest extends BrambleMockTestCase { TransportKeyManager transportKeyManager = new TransportKeyManagerImpl( db, transportCrypto, dbExecutor, scheduler, clock, transportId, maxLatency); - assertEquals(keySetId, transportKeyManager.addContact(txn, contactId, - rootKey, alice)); + assertEquals(keySetId, transportKeyManager.addContactWithHandshakeKeys( + txn, contactId, rootKey, alice)); assertTrue(transportKeyManager.canSendOutgoingStreams(contactId)); } @@ -274,8 +274,8 @@ public class TransportKeyManagerImplTest extends BrambleMockTestCase { maxLatency); // The timestamp is at the start of time period 1000 long timestamp = timePeriodLength * 1000; - assertEquals(keySetId, transportKeyManager.addContact(txn, contactId, - rootKey, timestamp, alice, true)); + assertEquals(keySetId, transportKeyManager.addContactWithRotationKeys( + txn, contactId, rootKey, timestamp, alice, true)); assertFalse(transportKeyManager.canSendOutgoingStreams(contactId)); assertNull(transportKeyManager.getStreamContext(txn, contactId)); } @@ -300,8 +300,8 @@ public class TransportKeyManagerImplTest extends BrambleMockTestCase { maxLatency); // The timestamp is at the start of time period 1000 long timestamp = timePeriodLength * 1000; - assertEquals(keySetId, transportKeyManager.addContact(txn, contactId, - rootKey, timestamp, alice, true)); + assertEquals(keySetId, transportKeyManager.addContactWithRotationKeys( + txn, contactId, rootKey, timestamp, alice, true)); // The first request should return a stream context assertTrue(transportKeyManager.canSendOutgoingStreams(contactId)); StreamContext ctx = transportKeyManager.getStreamContext(txn, @@ -332,8 +332,8 @@ public class TransportKeyManagerImplTest extends BrambleMockTestCase { maxLatency); // The timestamp is at the start of time period 1000 long timestamp = timePeriodLength * 1000; - assertEquals(keySetId, transportKeyManager.addContact(txn, contactId, - rootKey, timestamp, alice, active)); + assertEquals(keySetId, transportKeyManager.addContactWithRotationKeys( + txn, contactId, rootKey, timestamp, alice, active)); assertEquals(active, transportKeyManager.canSendOutgoingStreams(contactId)); // The tag should not be recognised @@ -385,8 +385,8 @@ public class TransportKeyManagerImplTest extends BrambleMockTestCase { maxLatency); // The timestamp is at the start of time period 1000 long timestamp = timePeriodLength * 1000; - assertEquals(keySetId, transportKeyManager.addContact(txn, contactId, - rootKey, timestamp, alice, true)); + assertEquals(keySetId, transportKeyManager.addContactWithRotationKeys( + txn, contactId, rootKey, timestamp, alice, true)); assertTrue(transportKeyManager.canSendOutgoingStreams(contactId)); // Use the first tag (previous time period, stream number 0) assertEquals(REORDERING_WINDOW_SIZE * 3, tags.size()); @@ -488,8 +488,8 @@ public class TransportKeyManagerImplTest extends BrambleMockTestCase { maxLatency); // The timestamp is at the start of time period 1000 long timestamp = timePeriodLength * 1000; - assertEquals(keySetId, transportKeyManager.addContact(txn, contactId, - rootKey, timestamp, alice, false)); + assertEquals(keySetId, transportKeyManager.addContactWithRotationKeys( + txn, contactId, rootKey, timestamp, alice, false)); // The keys are inactive so no stream context should be returned assertFalse(transportKeyManager.canSendOutgoingStreams(contactId)); assertNull(transportKeyManager.getStreamContext(txn, contactId)); @@ -554,8 +554,8 @@ public class TransportKeyManagerImplTest extends BrambleMockTestCase { maxLatency); // The timestamp is at the start of time period 1000 long timestamp = timePeriodLength * 1000; - assertEquals(keySetId, transportKeyManager.addContact(txn, contactId, - rootKey, timestamp, alice, false)); + assertEquals(keySetId, transportKeyManager.addContactWithRotationKeys( + txn, contactId, rootKey, timestamp, alice, false)); // The keys are inactive so no stream context should be returned assertFalse(transportKeyManager.canSendOutgoingStreams(contactId)); assertNull(transportKeyManager.getStreamContext(txn, contactId)); diff --git a/briar-core/src/main/java/org/briarproject/briar/introduction/IntroduceeProtocolEngine.java b/briar-core/src/main/java/org/briarproject/briar/introduction/IntroduceeProtocolEngine.java index 49ed450e8..b2fd5170d 100644 --- a/briar-core/src/main/java/org/briarproject/briar/introduction/IntroduceeProtocolEngine.java +++ b/briar-core/src/main/java/org/briarproject/briar/introduction/IntroduceeProtocolEngine.java @@ -5,6 +5,7 @@ import org.briarproject.bramble.api.client.ClientHelper; import org.briarproject.bramble.api.client.ContactGroupFactory; import org.briarproject.bramble.api.contact.Contact; import org.briarproject.bramble.api.contact.ContactManager; +import org.briarproject.bramble.api.contact.event.ContactAddedRemotelyEvent; import org.briarproject.bramble.api.crypto.KeyPair; import org.briarproject.bramble.api.crypto.SecretKey; import org.briarproject.bramble.api.data.BdfDictionary; @@ -30,7 +31,6 @@ import org.briarproject.briar.api.client.SessionId; import org.briarproject.briar.api.introduction.IntroductionRequest; import org.briarproject.briar.api.introduction.event.IntroductionAbortedEvent; import org.briarproject.briar.api.introduction.event.IntroductionRequestReceivedEvent; -import org.briarproject.bramble.api.contact.event.ContactAddedRemotelyEvent; import java.security.GeneralSecurityException; import java.util.Map; @@ -443,7 +443,7 @@ class IntroduceeProtocolEngine // add the keys to the new contact //noinspection ConstantConditions - keys = keyManager.addContact(txn, c.getId(), + keys = keyManager.addContactWithRotationKeys(txn, c.getId(), new SecretKey(s.getMasterKey()), timestamp, s.getLocal().alice, false);