diff --git a/bramble-api/src/main/java/org/briarproject/bramble/api/db/DatabaseComponent.java b/bramble-api/src/main/java/org/briarproject/bramble/api/db/DatabaseComponent.java index a953d7095..775a0d869 100644 --- a/bramble-api/src/main/java/org/briarproject/bramble/api/db/DatabaseComponent.java +++ b/bramble-api/src/main/java/org/briarproject/bramble/api/db/DatabaseComponent.java @@ -61,14 +61,7 @@ public interface DatabaseComponent extends TransactionManager { * and returns an ID for the contact. */ ContactId addContact(Transaction txn, Author remote, AuthorId local, - boolean verified) throws DbException; - - /** - * Stores a contact associated with the given local and remote pseudonyms, - * replacing the given pending contact, and returns an ID for the contact. - */ - ContactId addContact(Transaction txn, PendingContactId p, Author remote, - AuthorId local, boolean verified) throws DbException; + @Nullable PublicKey handshake, boolean verified) throws DbException; /** * Stores a group. 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 30c3b3c42..b094e5272 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 @@ -9,6 +9,7 @@ import org.briarproject.bramble.api.contact.PendingContact; import org.briarproject.bramble.api.contact.PendingContactId; import org.briarproject.bramble.api.contact.PendingContactState; import org.briarproject.bramble.api.crypto.KeyPair; +import org.briarproject.bramble.api.crypto.PublicKey; import org.briarproject.bramble.api.crypto.SecretKey; import org.briarproject.bramble.api.db.DatabaseComponent; import org.briarproject.bramble.api.db.DbException; @@ -76,7 +77,7 @@ class ContactManagerImpl implements ContactManager { public ContactId addContact(Transaction txn, Author remote, AuthorId local, SecretKey rootKey, long timestamp, boolean alice, boolean verified, boolean active) throws DbException { - ContactId c = db.addContact(txn, remote, local, verified); + ContactId c = db.addContact(txn, remote, local, null, verified); keyManager.addContactWithRotationKeys(txn, c, rootKey, timestamp, alice, active); Contact contact = db.getContact(txn, c); @@ -89,7 +90,9 @@ class ContactManagerImpl implements ContactManager { Author remote, AuthorId local, SecretKey rootKey, long timestamp, boolean alice, boolean verified, boolean active) throws DbException { - ContactId c = db.addContact(txn, p, remote, local, verified); + PublicKey handshake = db.getPendingContact(txn, p).getPublicKey(); + db.removePendingContact(txn, p); + ContactId c = db.addContact(txn, remote, local, handshake, verified); keyManager.addContactWithRotationKeys(txn, c, rootKey, timestamp, alice, active); Contact contact = db.getContact(txn, c); @@ -100,7 +103,7 @@ class ContactManagerImpl implements ContactManager { @Override public ContactId addContact(Transaction txn, Author remote, AuthorId local, boolean verified) throws DbException { - ContactId c = db.addContact(txn, remote, local, verified); + ContactId c = db.addContact(txn, remote, local, null, verified); 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/db/Database.java b/bramble-core/src/main/java/org/briarproject/bramble/db/Database.java index 47ef5e0b3..65203229a 100644 --- a/bramble-core/src/main/java/org/briarproject/bramble/db/Database.java +++ b/bramble-core/src/main/java/org/briarproject/bramble/db/Database.java @@ -88,8 +88,8 @@ interface Database { * Stores a contact associated with the given local and remote pseudonyms, * and returns an ID for the contact. */ - ContactId addContact(T txn, Author remote, AuthorId local, boolean verified) - throws DbException; + ContactId addContact(T txn, Author remote, AuthorId local, + @Nullable PublicKey handshake, boolean verified) throws DbException; /** * Stores a group. @@ -695,14 +695,6 @@ interface Database { void setTransportKeysActive(T txn, TransportId t, KeySetId k) throws DbException; - /** - * Transfers ownership of any transport keys from the given pending contact - * to the given contact and copies the pending contact's handshake public - * key to the contact. - */ - void transferKeys(T txn, PendingContactId p, ContactId c) - throws DbException; - /** * Updates the transmission count, expiry time and estimated time of arrival * of the given message with respect to the given contact, using the latency diff --git a/bramble-core/src/main/java/org/briarproject/bramble/db/DatabaseComponentImpl.java b/bramble-core/src/main/java/org/briarproject/bramble/db/DatabaseComponentImpl.java index 876d419b2..666c54a23 100644 --- a/bramble-core/src/main/java/org/briarproject/bramble/db/DatabaseComponentImpl.java +++ b/bramble-core/src/main/java/org/briarproject/bramble/db/DatabaseComponentImpl.java @@ -85,6 +85,7 @@ import javax.annotation.concurrent.ThreadSafe; import javax.inject.Inject; import static java.util.logging.Level.WARNING; +import static java.util.logging.Logger.getLogger; import static org.briarproject.bramble.api.sync.Group.Visibility.INVISIBLE; import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED; import static org.briarproject.bramble.api.sync.validation.MessageState.DELIVERED; @@ -99,7 +100,7 @@ import static org.briarproject.bramble.util.LogUtils.now; class DatabaseComponentImpl implements DatabaseComponent { private static final Logger LOG = - Logger.getLogger(DatabaseComponentImpl.class.getName()); + getLogger(DatabaseComponentImpl.class.getName()); private final Database db; private final Class txnClass; @@ -234,39 +235,18 @@ class DatabaseComponentImpl implements DatabaseComponent { @Override public ContactId addContact(Transaction transaction, Author remote, - AuthorId local, boolean verified) throws DbException { - if (transaction.isReadOnly()) throw new IllegalArgumentException(); - T txn = unbox(transaction); - if (!db.containsIdentity(txn, local)) - throw new NoSuchIdentityException(); - if (db.containsIdentity(txn, remote.getId())) - throw new ContactExistsException(local, remote); - if (db.containsContact(txn, remote.getId(), local)) - throw new ContactExistsException(local, remote); - ContactId c = db.addContact(txn, remote, local, verified); - transaction.attach(new ContactAddedEvent(c, verified)); - return c; - } - - @Override - public ContactId addContact(Transaction transaction, PendingContactId p, - Author remote, AuthorId local, boolean verified) + AuthorId local, @Nullable PublicKey handshake, boolean verified) throws DbException { if (transaction.isReadOnly()) throw new IllegalArgumentException(); T txn = unbox(transaction); - if (!db.containsPendingContact(txn, p)) - throw new NoSuchPendingContactException(); if (!db.containsIdentity(txn, local)) throw new NoSuchIdentityException(); if (db.containsIdentity(txn, remote.getId())) throw new ContactExistsException(local, remote); if (db.containsContact(txn, remote.getId(), local)) throw new ContactExistsException(local, remote); - ContactId c = db.addContact(txn, remote, local, verified); - db.transferKeys(txn, p, c); - db.removePendingContact(txn, p); + ContactId c = db.addContact(txn, remote, local, handshake, verified); transaction.attach(new ContactAddedEvent(c, verified)); - transaction.attach(new PendingContactRemovedEvent(p)); return c; } diff --git a/bramble-core/src/main/java/org/briarproject/bramble/db/JdbcDatabase.java b/bramble-core/src/main/java/org/briarproject/bramble/db/JdbcDatabase.java index f3d80a8e5..7b51a6e29 100644 --- a/bramble-core/src/main/java/org/briarproject/bramble/db/JdbcDatabase.java +++ b/bramble-core/src/main/java/org/briarproject/bramble/db/JdbcDatabase.java @@ -629,22 +629,25 @@ abstract class JdbcDatabase implements Database { @Override public ContactId addContact(Connection txn, Author remote, AuthorId local, - boolean verified) throws DbException { + @Nullable PublicKey handshake, boolean verified) + throws DbException { PreparedStatement ps = null; ResultSet rs = null; try { // Create a contact row String sql = "INSERT INTO contacts" + " (authorId, formatVersion, name, publicKey," - + " localAuthorId, verified)" - + " VALUES (?, ?, ?, ?, ?, ?)"; + + " localAuthorId, handshakePublicKey, verified)" + + " VALUES (?, ?, ?, ?, ?, ?, ?)"; ps = txn.prepareStatement(sql); ps.setBytes(1, remote.getId().getBytes()); ps.setInt(2, remote.getFormatVersion()); ps.setString(3, remote.getName()); ps.setBytes(4, remote.getPublicKey().getEncoded()); ps.setBytes(5, local.getBytes()); - ps.setBoolean(6, verified); + if (handshake == null) ps.setNull(6, BINARY); + else ps.setBytes(6, handshake.getEncoded()); + ps.setBoolean(7, verified); int affected = ps.executeUpdate(); if (affected != 1) throw new DbStateException(); ps.close(); @@ -3139,48 +3142,6 @@ abstract class JdbcDatabase implements Database { } } - @Override - public void transferKeys(Connection txn, PendingContactId p, ContactId c) - throws DbException { - PreparedStatement ps = null; - ResultSet rs = null; - try { - // Transfer the handshake public key - String sql = "SELECT publicKey from pendingContacts" - + " WHERE pendingContactId = ?"; - ps = txn.prepareStatement(sql); - ps.setBytes(1, p.getBytes()); - rs = ps.executeQuery(); - if (!rs.next()) throw new DbStateException(); - byte[] publicKey = rs.getBytes(1); - if (rs.next()) throw new DbStateException(); - rs.close(); - ps.close(); - sql = "UPDATE contacts SET handshakePublicKey = ?" - + " WHERE contactId = ?"; - ps = txn.prepareStatement(sql); - ps.setBytes(1, publicKey); - ps.setInt(2, c.getInt()); - int affected = ps.executeUpdate(); - if (affected < 0 || affected > 1) throw new DbStateException(); - ps.close(); - // Transfer the transport keys - sql = "UPDATE outgoingKeys" - + " SET contactId = ?, pendingContactId = NULL" - + " WHERE pendingContactId = ?"; - ps = txn.prepareStatement(sql); - ps.setInt(1, c.getInt()); - ps.setBytes(2, p.getBytes()); - affected = ps.executeUpdate(); - if (affected < 0) throw new DbStateException(); - ps.close(); - } catch (SQLException e) { - tryToClose(rs, LOG, WARNING); - tryToClose(ps, LOG, WARNING); - throw new DbException(e); - } - } - @Override public void updateExpiryTimeAndEta(Connection txn, ContactId c, MessageId m, int maxLatency) throws DbException { 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 86a3932ee..059cb7aa9 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 @@ -71,7 +71,7 @@ public class ContactManagerImplTest extends BrambleMockTestCase { context.checking(new DbExpectations() {{ oneOf(db).transactionWithResult(with(false), withDbCallable(txn)); - oneOf(db).addContact(txn, remote, local, verified); + oneOf(db).addContact(txn, remote, local, null, verified); will(returnValue(contactId)); oneOf(keyManager).addContactWithRotationKeys(txn, contactId, rootKey, timestamp, alice, active); diff --git a/bramble-core/src/test/java/org/briarproject/bramble/db/DatabaseComponentImplTest.java b/bramble-core/src/test/java/org/briarproject/bramble/db/DatabaseComponentImplTest.java index 9afc37b18..1570d1b08 100644 --- a/bramble-core/src/test/java/org/briarproject/bramble/db/DatabaseComponentImplTest.java +++ b/bramble-core/src/test/java/org/briarproject/bramble/db/DatabaseComponentImplTest.java @@ -176,7 +176,8 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase { oneOf(database).containsContact(txn, author.getId(), localAuthor.getId()); will(returnValue(false)); - oneOf(database).addContact(txn, author, localAuthor.getId(), true); + oneOf(database).addContact(txn, author, localAuthor.getId(), + null, true); will(returnValue(contactId)); oneOf(eventBus).broadcast(with(any(ContactAddedEvent.class))); // getContacts() @@ -224,7 +225,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase { db.transaction(false, transaction -> { db.addIdentity(transaction, identity); assertEquals(contactId, db.addContact(transaction, author, - localAuthor.getId(), true)); + localAuthor.getId(), null, true)); assertEquals(singletonList(contact), db.getContacts(transaction)); db.addGroup(transaction, group); // First time - listeners called @@ -445,7 +446,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase { try { db.transaction(false, transaction -> db.addContact(transaction, author, localAuthor.getId(), - true)); + null, true)); fail(); } catch (NoSuchIdentityException expected) { // Expected @@ -763,25 +764,16 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase { throws Exception { context.checking(new Expectations() {{ // Check whether the pending contact is in the DB (which it's not) - exactly(4).of(database).startTransaction(); + exactly(3).of(database).startTransaction(); will(returnValue(txn)); - exactly(4).of(database).containsPendingContact(txn, + exactly(3).of(database).containsPendingContact(txn, pendingContactId); will(returnValue(false)); - exactly(4).of(database).abortTransaction(txn); + exactly(3).of(database).abortTransaction(txn); }}); DatabaseComponent db = createDatabaseComponent(database, eventBus, eventExecutor, shutdownManager); - try { - db.transaction(false, transaction -> - db.addContact(transaction, pendingContactId, author, - localAuthor.getId(), true)); - fail(); - } catch (NoSuchPendingContactException expected) { - // Expected - } - try { db.transaction(false, transaction -> db.addTransportKeys(transaction, pendingContactId, @@ -1473,7 +1465,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase { try { db.transaction(false, transaction -> db.addContact(transaction, author, localAuthor.getId(), - true)); + null, true)); fail(); } catch (ContactExistsException expected) { assertEquals(localAuthor.getId(), expected.getLocalAuthorId()); @@ -1503,70 +1495,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase { try { db.transaction(false, transaction -> db.addContact(transaction, author, localAuthor.getId(), - true)); - fail(); - } catch (ContactExistsException expected) { - assertEquals(localAuthor.getId(), expected.getLocalAuthorId()); - assertEquals(author, expected.getRemoteAuthor()); - } - } - - @Test - public void testCannotAddLocalIdentityAsContactFromPendingContact() - throws Exception { - context.checking(new Expectations() {{ - oneOf(database).startTransaction(); - will(returnValue(txn)); - oneOf(database).containsPendingContact(txn, pendingContactId); - will(returnValue(true)); - oneOf(database).containsIdentity(txn, localAuthor.getId()); - will(returnValue(true)); - // Contact is a local identity - oneOf(database).containsIdentity(txn, author.getId()); - will(returnValue(true)); - oneOf(database).abortTransaction(txn); - }}); - - DatabaseComponent db = createDatabaseComponent(database, eventBus, - eventExecutor, shutdownManager); - - try { - db.transaction(false, transaction -> - db.addContact(transaction, pendingContactId, author, - localAuthor.getId(), true)); - fail(); - } catch (ContactExistsException expected) { - assertEquals(localAuthor.getId(), expected.getLocalAuthorId()); - assertEquals(author, expected.getRemoteAuthor()); - } - } - - @Test - public void testCannotAddDuplicateContactFromPendingContact() - throws Exception { - context.checking(new Expectations() {{ - oneOf(database).startTransaction(); - will(returnValue(txn)); - oneOf(database).containsPendingContact(txn, pendingContactId); - will(returnValue(true)); - oneOf(database).containsIdentity(txn, localAuthor.getId()); - will(returnValue(true)); - oneOf(database).containsIdentity(txn, author.getId()); - will(returnValue(false)); - // Contact already exists for this local identity - oneOf(database).containsContact(txn, author.getId(), - localAuthor.getId()); - will(returnValue(true)); - oneOf(database).abortTransaction(txn); - }}); - - DatabaseComponent db = createDatabaseComponent(database, eventBus, - eventExecutor, shutdownManager); - - try { - db.transaction(false, transaction -> - db.addContact(transaction, pendingContactId, author, - localAuthor.getId(), true)); + null, true)); fail(); } catch (ContactExistsException expected) { assertEquals(localAuthor.getId(), expected.getLocalAuthorId()); diff --git a/bramble-core/src/test/java/org/briarproject/bramble/db/DatabasePerformanceTest.java b/bramble-core/src/test/java/org/briarproject/bramble/db/DatabasePerformanceTest.java index fe060e3df..556634431 100644 --- a/bramble-core/src/test/java/org/briarproject/bramble/db/DatabasePerformanceTest.java +++ b/bramble-core/src/test/java/org/briarproject/bramble/db/DatabasePerformanceTest.java @@ -548,7 +548,7 @@ public abstract class DatabasePerformanceTest extends BrambleTestCase { db.addIdentity(txn, identity); for (int i = 0; i < CONTACTS; i++) { ContactId c = db.addContact(txn, getAuthor(), localAuthor.getId(), - random.nextBoolean()); + null, random.nextBoolean()); contacts.add(db.getContact(txn, c)); contactGroups.put(c, new ArrayList<>()); for (int j = 0; j < GROUPS_PER_CONTACT; j++) { diff --git a/bramble-core/src/test/java/org/briarproject/bramble/db/JdbcDatabaseTest.java b/bramble-core/src/test/java/org/briarproject/bramble/db/JdbcDatabaseTest.java index bdbe53240..1bf92d83a 100644 --- a/bramble-core/src/test/java/org/briarproject/bramble/db/JdbcDatabaseTest.java +++ b/bramble-core/src/test/java/org/briarproject/bramble/db/JdbcDatabaseTest.java @@ -147,7 +147,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase { assertFalse(db.containsContact(txn, contactId)); db.addIdentity(txn, identity); assertEquals(contactId, - db.addContact(txn, author, localAuthor.getId(), true)); + db.addContact(txn, author, localAuthor.getId(), null, true)); assertTrue(db.containsContact(txn, contactId)); assertFalse(db.containsGroup(txn, groupId)); db.addGroup(txn, group); @@ -210,7 +210,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase { // Add a contact, a shared group and a shared message db.addIdentity(txn, identity); assertEquals(contactId, - db.addContact(txn, author, localAuthor.getId(), true)); + db.addContact(txn, author, localAuthor.getId(), null, true)); db.addGroup(txn, group); db.addGroupVisibility(txn, contactId, groupId, true); db.addMessage(txn, message, DELIVERED, true, null); @@ -241,7 +241,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase { // Add a contact, a shared group and a shared but unvalidated message db.addIdentity(txn, identity); assertEquals(contactId, - db.addContact(txn, author, localAuthor.getId(), true)); + db.addContact(txn, author, localAuthor.getId(), null, true)); db.addGroup(txn, group); db.addGroupVisibility(txn, contactId, groupId, true); db.addMessage(txn, message, UNKNOWN, true, null); @@ -286,7 +286,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase { // Add a contact, an invisible group and a shared message db.addIdentity(txn, identity); assertEquals(contactId, - db.addContact(txn, author, localAuthor.getId(), true)); + db.addContact(txn, author, localAuthor.getId(), null, true)); db.addGroup(txn, group); db.addMessage(txn, message, DELIVERED, true, null); @@ -337,7 +337,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase { // Add a contact, a shared group and an unshared message db.addIdentity(txn, identity); assertEquals(contactId, - db.addContact(txn, author, localAuthor.getId(), true)); + db.addContact(txn, author, localAuthor.getId(), null, true)); db.addGroup(txn, group); db.addGroupVisibility(txn, contactId, groupId, true); db.addMessage(txn, message, DELIVERED, false, null); @@ -368,7 +368,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase { // Add a contact, a shared group and a shared message db.addIdentity(txn, identity); assertEquals(contactId, - db.addContact(txn, author, localAuthor.getId(), true)); + db.addContact(txn, author, localAuthor.getId(), null, true)); db.addGroup(txn, group); db.addGroupVisibility(txn, contactId, groupId, true); db.addMessage(txn, message, DELIVERED, true, null); @@ -395,7 +395,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase { // Add a contact and a visible group db.addIdentity(txn, identity); assertEquals(contactId, - db.addContact(txn, author, localAuthor.getId(), true)); + db.addContact(txn, author, localAuthor.getId(), null, true)); db.addGroup(txn, group); db.addGroupVisibility(txn, contactId, groupId, false); @@ -436,7 +436,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase { // Add a contact, a shared group and a shared message db.addIdentity(txn, identity); assertEquals(contactId, - db.addContact(txn, author, localAuthor.getId(), true)); + db.addContact(txn, author, localAuthor.getId(), null, true)); db.addGroup(txn, group); db.addGroupVisibility(txn, contactId, groupId, true); db.addMessage(txn, message, DELIVERED, true, null); @@ -568,7 +568,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase { // Add a contact and a shared group db.addIdentity(txn, identity); assertEquals(contactId, - db.addContact(txn, author, localAuthor.getId(), true)); + db.addContact(txn, author, localAuthor.getId(), null, true)); db.addGroup(txn, group); db.addGroupVisibility(txn, contactId, groupId, true); @@ -588,7 +588,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase { // Add a contact db.addIdentity(txn, identity); assertEquals(contactId, - db.addContact(txn, author, localAuthor.getId(), true)); + db.addContact(txn, author, localAuthor.getId(), null, true)); // The group is not in the database assertFalse(db.containsVisibleMessage(txn, contactId, messageId)); @@ -606,7 +606,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase { // Add a contact, an invisible group and a message db.addIdentity(txn, identity); assertEquals(contactId, - db.addContact(txn, author, localAuthor.getId(), true)); + db.addContact(txn, author, localAuthor.getId(), null, true)); db.addGroup(txn, group); db.addMessage(txn, message, DELIVERED, true, null); @@ -625,7 +625,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase { // Add a contact and a group db.addIdentity(txn, identity); assertEquals(contactId, - db.addContact(txn, author, localAuthor.getId(), true)); + db.addContact(txn, author, localAuthor.getId(), null, true)); db.addGroup(txn, group); // The group should not be visible to the contact @@ -677,7 +677,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase { // Add the contact, the transport and the transport keys db.addIdentity(txn, identity); assertEquals(contactId, - db.addContact(txn, author, localAuthor.getId(), true)); + db.addContact(txn, author, localAuthor.getId(), null, true)); db.addTransport(txn, transportId, 123); assertEquals(keySetId, db.addTransportKeys(txn, contactId, keys)); assertEquals(keySetId1, db.addTransportKeys(txn, contactId, keys1)); @@ -786,7 +786,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase { // Add the contact, the transport and the handshake keys db.addIdentity(txn, identity); assertEquals(contactId, - db.addContact(txn, author, localAuthor.getId(), true)); + db.addContact(txn, author, localAuthor.getId(), null, true)); db.addTransport(txn, transportId, 123); assertEquals(keySetId, db.addTransportKeys(txn, contactId, keys)); assertEquals(keySetId1, db.addTransportKeys(txn, contactId, keys1)); @@ -920,7 +920,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase { // Add the contact, transport and transport keys db.addIdentity(txn, identity); assertEquals(contactId, - db.addContact(txn, author, localAuthor.getId(), true)); + db.addContact(txn, author, localAuthor.getId(), null, true)); db.addTransport(txn, transportId, 123); assertEquals(keySetId, db.addTransportKeys(txn, contactId, keys)); @@ -964,7 +964,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase { // Add the contact, transport and handshake keys db.addIdentity(txn, identity); assertEquals(contactId, - db.addContact(txn, author, localAuthor.getId(), true)); + db.addContact(txn, author, localAuthor.getId(), null, true)); db.addTransport(txn, transportId, 123); assertEquals(keySetId, db.addTransportKeys(txn, contactId, keys)); @@ -1011,7 +1011,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase { // Add the contact, transport and transport keys db.addIdentity(txn, identity); assertEquals(contactId, - db.addContact(txn, author, localAuthor.getId(), true)); + db.addContact(txn, author, localAuthor.getId(), null, true)); db.addTransport(txn, transportId, 123); assertEquals(keySetId, db.addTransportKeys(txn, contactId, keys)); @@ -1058,7 +1058,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase { // Add the contact, transport and handshake keys db.addIdentity(txn, identity); assertEquals(contactId, - db.addContact(txn, author, localAuthor.getId(), true)); + db.addContact(txn, author, localAuthor.getId(), null, true)); db.addTransport(txn, transportId, 123); assertEquals(keySetId, db.addTransportKeys(txn, contactId, keys)); @@ -1104,7 +1104,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase { // Add a contact associated with the local author assertEquals(contactId, - db.addContact(txn, author, localAuthor.getId(), true)); + db.addContact(txn, author, localAuthor.getId(), null, true)); // Ensure contact is returned from database by author ID Collection contacts = @@ -1135,7 +1135,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase { // Add a contact associated with the local author assertEquals(contactId, - db.addContact(txn, author, localAuthor.getId(), true)); + db.addContact(txn, author, localAuthor.getId(), null, true)); contacts = db.getContacts(txn, localAuthor.getId()); assertEquals(singletonList(contactId), contacts); @@ -1157,7 +1157,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase { // Add a contact - initially there should be no offered messages db.addIdentity(txn, identity); assertEquals(contactId, - db.addContact(txn, author, localAuthor.getId(), true)); + db.addContact(txn, author, localAuthor.getId(), null, true)); assertEquals(0, db.countOfferedMessages(txn, contactId)); // Add some offered messages and count them @@ -1741,7 +1741,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase { // Add a contact, a shared group and a shared message db.addIdentity(txn, identity); assertEquals(contactId, - db.addContact(txn, author, localAuthor.getId(), true)); + db.addContact(txn, author, localAuthor.getId(), null, true)); db.addGroup(txn, group); db.addGroupVisibility(txn, contactId, groupId, true); db.addMessage(txn, message, DELIVERED, true, null); @@ -1853,9 +1853,9 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase { // Add the same contact for each local author ContactId contactId = - db.addContact(txn, author, localAuthor.getId(), true); + db.addContact(txn, author, localAuthor.getId(), null, true); ContactId contactId1 = - db.addContact(txn, author, localAuthor1.getId(), true); + db.addContact(txn, author, localAuthor1.getId(), null, true); // The contacts should be distinct assertNotEquals(contactId, contactId1); @@ -1875,7 +1875,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase { // Add a contact, a shared group and a shared message db.addIdentity(txn, identity); assertEquals(contactId, - db.addContact(txn, author, localAuthor.getId(), true)); + db.addContact(txn, author, localAuthor.getId(), null, true)); db.addGroup(txn, group); db.addGroupVisibility(txn, contactId, groupId, true); db.addMessage(txn, message, DELIVERED, true, null); @@ -1929,7 +1929,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase { // Add a contact db.addIdentity(txn, identity); assertEquals(contactId, - db.addContact(txn, author, localAuthor.getId(), true)); + db.addContact(txn, author, localAuthor.getId(), null, true)); // The contact should have no alias Contact contact = db.getContact(txn, contactId); @@ -1986,7 +1986,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase { // Add a contact, a group and a message db.addIdentity(txn, identity); assertEquals(contactId, - db.addContact(txn, author, localAuthor.getId(), true)); + db.addContact(txn, author, localAuthor.getId(), null, true)); db.addGroup(txn, group); db.addMessage(txn, message, UNKNOWN, false, null); @@ -2070,7 +2070,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase { // Add a contact, a shared group and a shared message db.addIdentity(txn, identity); assertEquals(contactId, - db.addContact(txn, author, localAuthor.getId(), true)); + db.addContact(txn, author, localAuthor.getId(), null, true)); db.addGroup(txn, group); db.addGroupVisibility(txn, contactId, groupId, true); db.addMessage(txn, message, DELIVERED, true, null); @@ -2115,7 +2115,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase { // Add a contact, a shared group and a shared message db.addIdentity(txn, identity); assertEquals(contactId, - db.addContact(txn, author, localAuthor.getId(), true)); + db.addContact(txn, author, localAuthor.getId(), null, true)); db.addGroup(txn, group); db.addGroupVisibility(txn, contactId, groupId, true); db.addMessage(txn, message, DELIVERED, true, null); @@ -2229,60 +2229,6 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase { assertEquals(expected.getTimestamp(), actual.getTimestamp()); } - @Test - public void testTransferKeys() throws Exception { - boolean alice = random.nextBoolean(); - TransportKeys transportKeys = - createHandshakeKeys(1000, getSecretKey(), alice); - - Database db = open(false); - Connection txn = db.startTransaction(); - - // Add the pending contact, the transport and the handshake keys - db.addPendingContact(txn, pendingContact); - db.addTransport(txn, transportId, 123); - assertEquals(keySetId, db.addTransportKeys(txn, pendingContact.getId(), - transportKeys)); - - Collection allKeys = - db.getTransportKeys(txn, transportId); - assertEquals(1, allKeys.size()); - TransportKeySet ks = allKeys.iterator().next(); - assertEquals(keySetId, ks.getKeySetId()); - assertNull(ks.getContactId()); - assertEquals(pendingContact.getId(), ks.getPendingContactId()); - - // Add a contact - db.addIdentity(txn, identity); - assertEquals(contactId, - db.addContact(txn, author, localAuthor.getId(), true)); - - // The contact shouldn't have a handshake public key - Contact contact = db.getContact(txn, contactId); - assertNull(contact.getHandshakePublicKey()); - - // Transfer the keys to the contact - db.transferKeys(txn, pendingContact.getId(), contactId); - - // The handshake public key should have been copied to the contact - contact = db.getContact(txn, contactId); - PublicKey handshakePublicKey = contact.getHandshakePublicKey(); - assertNotNull(handshakePublicKey); - assertArrayEquals(pendingContact.getPublicKey().getEncoded(), - handshakePublicKey.getEncoded()); - - // The transport keys should have been transferred to the contact - allKeys = db.getTransportKeys(txn, transportId); - assertEquals(1, allKeys.size()); - ks = allKeys.iterator().next(); - assertEquals(keySetId, ks.getKeySetId()); - assertEquals(contactId, ks.getContactId()); - assertNull(ks.getPendingContactId()); - - db.commitTransaction(txn); - db.close(); - } - @Test public void testSetHandshakeKeyPair() throws Exception { Identity withoutKeys = new Identity(localAuthor, null, null,