diff --git a/briar-android-tests/src/test/java/org/briarproject/BlogManagerTest.java b/briar-android-tests/src/test/java/org/briarproject/BlogManagerTest.java index ad14a5ebc46032d3665c6f06bf2ce606cc9fea43..09e63bd98b87dcc11f26f84c045137a080f63d8f 100644 --- a/briar-android-tests/src/test/java/org/briarproject/BlogManagerTest.java +++ b/briar-android-tests/src/test/java/org/briarproject/BlogManagerTest.java @@ -337,12 +337,12 @@ public class BlogManagerTest { // sharer adds invitee as contact contactId1 = contactManager0.addContact(author1, author0.getId(), master, clock.currentTimeMillis(), true, - true + true, true ); // invitee adds sharer back contactId0 = contactManager1.addContact(author0, author1.getId(), master, clock.currentTimeMillis(), true, - true + true, true ); } diff --git a/briar-android-tests/src/test/java/org/briarproject/BlogSharingIntegrationTest.java b/briar-android-tests/src/test/java/org/briarproject/BlogSharingIntegrationTest.java index ce88e0cd7e03733296aafc0340161af7d7e55eb7..0c62fd4e455a87e90d71ecadeaf23e7571df3ad9 100644 --- a/briar-android-tests/src/test/java/org/briarproject/BlogSharingIntegrationTest.java +++ b/briar-android-tests/src/test/java/org/briarproject/BlogSharingIntegrationTest.java @@ -362,11 +362,11 @@ public class BlogSharingIntegrationTest extends BriarTestCase { // 1 and 2 are adding each other contactManager1.addContact(author2, author1.getId(), master, clock.currentTimeMillis(), true, - true + true, true ); contactManager2.addContact(author1, author2.getId(), master, clock.currentTimeMillis(), true, - true + true, true ); assertEquals(3, blogManager1.getBlogs().size()); @@ -489,11 +489,11 @@ public class BlogSharingIntegrationTest extends BriarTestCase { // 1 and 2 are adding each other contactManager1.addContact(author2, author1.getId(), master, clock.currentTimeMillis(), true, - true + true, true ); contactManager2.addContact(author1, author2.getId(), master, clock.currentTimeMillis(), true, - true + true, true ); assertEquals(3, blogManager1.getBlogs().size()); @@ -671,24 +671,24 @@ public class BlogSharingIntegrationTest extends BriarTestCase { // sharer adds invitee as contact contactId1 = contactManager0.addContact(author1, author0.getId(), master, clock.currentTimeMillis(), true, - true + true, true ); contact1 = contactManager0.getContact(contactId1); // sharer adds second contact contactId2 = contactManager0.addContact(author2, author0.getId(), master, clock.currentTimeMillis(), true, - true + true, true ); contact2 = contactManager0.getContact(contactId2); // contacts add sharer back contactId01 = contactManager1.addContact(author0, author1.getId(), master, clock.currentTimeMillis(), true, - true + true, true ); contact01 = contactManager1.getContact(contactId01); contactId02 = contactManager2.addContact(author0, author2.getId(), master, clock.currentTimeMillis(), true, - true + true, true ); contact02 = contactManager2.getContact(contactId02); } diff --git a/briar-android-tests/src/test/java/org/briarproject/ForumManagerTest.java b/briar-android-tests/src/test/java/org/briarproject/ForumManagerTest.java index cf9d4eff3bedfa283a34be88afdc26725cb778bc..c9e6c9aea9fcd1035c52d5e28d73cfb29ec25e08 100644 --- a/briar-android-tests/src/test/java/org/briarproject/ForumManagerTest.java +++ b/briar-android-tests/src/test/java/org/briarproject/ForumManagerTest.java @@ -365,12 +365,12 @@ public class ForumManagerTest { // sharer adds invitee as contact contactId1 = contactManager0.addContact(author1, author0.getId(), master, clock.currentTimeMillis(), true, - true + true, true ); // invitee adds sharer back contactId0 = contactManager1.addContact(author0, author1.getId(), master, clock.currentTimeMillis(), true, - true + true, true ); } diff --git a/briar-android-tests/src/test/java/org/briarproject/ForumSharingIntegrationTest.java b/briar-android-tests/src/test/java/org/briarproject/ForumSharingIntegrationTest.java index a3c86cb1f8b7cba391b453629f1018807bc34668..3f45a5536a0bf4649aa4cb129143485ef492094a 100644 --- a/briar-android-tests/src/test/java/org/briarproject/ForumSharingIntegrationTest.java +++ b/briar-android-tests/src/test/java/org/briarproject/ForumSharingIntegrationTest.java @@ -1091,21 +1091,21 @@ public class ForumSharingIntegrationTest extends BriarTestCase { // sharer adds invitee as contact contactId1 = contactManager0.addContact(author1, author0.getId(), master, clock.currentTimeMillis(), true, - true + true, true ); // second sharer does the same contactId21 = contactManager2.addContact(author1, author2.getId(), master, clock.currentTimeMillis(), true, - true + true, true ); // invitee adds sharers back contactId0 = contactManager1.addContact(author0, author1.getId(), master, clock.currentTimeMillis(), true, - true + true, true ); contactId2 = contactManager1.addContact(author2, author1.getId(), master, clock.currentTimeMillis(), true, - true + true, true ); } diff --git a/briar-android-tests/src/test/java/org/briarproject/IntroductionIntegrationTest.java b/briar-android-tests/src/test/java/org/briarproject/IntroductionIntegrationTest.java index 52fad50bbfb83256fd3af44f4e9b6c4ed827d970..9d74b6d2a0fe91e94382b034721f8ff38f89e2ec 100644 --- a/briar-android-tests/src/test/java/org/briarproject/IntroductionIntegrationTest.java +++ b/briar-android-tests/src/test/java/org/briarproject/IntroductionIntegrationTest.java @@ -164,20 +164,20 @@ public class IntroductionIntegrationTest extends BriarTestCase { // Add introducees as contacts contactId1 = contactManager0.addContact(author1, author0.getId(), master, clock.currentTimeMillis(), true, - true + true, true ); contactId2 = contactManager0.addContact(author2, author0.getId(), master, clock.currentTimeMillis(), true, - true + true, true ); // Add introducer back contactId0 = contactManager1.addContact(author0, author1.getId(), master, clock.currentTimeMillis(), true, - true + true, true ); ContactId contactId02 = contactManager2.addContact(author0, author2.getId(), master, clock.currentTimeMillis(), true, - true + true, true ); assertTrue(contactId0.equals(contactId02)); @@ -238,6 +238,18 @@ public class IntroductionIntegrationTest extends BriarTestCase { assertTrue(contactManager2 .contactExists(author1.getId(), author2.getId())); + // make sure that introduced contacts are not verified + for (Contact c : contactManager1.getActiveContacts()) { + if (c.getAuthor().equals(author2)) { + assertFalse(c.isVerified()); + } + } + for (Contact c : contactManager2.getActiveContacts()) { + if (c.getAuthor().equals(author1)) { + assertFalse(c.isVerified()); + } + } + assertDefaultUiMessages(); } finally { stopLifecycles(); @@ -256,18 +268,18 @@ public class IntroductionIntegrationTest extends BriarTestCase { // Add introducees as contacts contactId1 = contactManager0.addContact(author1, author0.getId(), - master, clock.currentTimeMillis(), true, true + master, clock.currentTimeMillis(), true, true, true ); contactId2 = contactManager0.addContact(author2, author0.getId(), - master, clock.currentTimeMillis(), true, true + master, clock.currentTimeMillis(), true, true, true ); // Add introducer back contactId0 = contactManager1.addContact(author0, author1.getId(), - master, clock.currentTimeMillis(), true, true + master, clock.currentTimeMillis(), true, true, true ); ContactId contactId02 = contactManager2.addContact(author0, author2.getId(), master, clock.currentTimeMillis(), true, - true + true, true ); assertTrue(contactId0.equals(contactId02)); @@ -349,18 +361,18 @@ public class IntroductionIntegrationTest extends BriarTestCase { // Add introducees as contacts contactId1 = contactManager0.addContact(author1, author0.getId(), - master, clock.currentTimeMillis(), true, true + master, clock.currentTimeMillis(), true, true, true ); contactId2 = contactManager0.addContact(author2, author0.getId(), - master, clock.currentTimeMillis(), true, true + master, clock.currentTimeMillis(), true, true, true ); // Add introducer back contactId0 = contactManager1.addContact(author0, author1.getId(), - master, clock.currentTimeMillis(), false, true + master, clock.currentTimeMillis(), false, true, true ); ContactId contactId02 = contactManager2.addContact(author0, author2.getId(), master, clock.currentTimeMillis(), false, - true + true, true ); assertTrue(contactId0.equals(contactId02)); @@ -437,18 +449,18 @@ public class IntroductionIntegrationTest extends BriarTestCase { // Add introducees as contacts contactId1 = contactManager0.addContact(author1, author0.getId(), - master, clock.currentTimeMillis(), true, true + master, clock.currentTimeMillis(), true, true, true ); contactId2 = contactManager0.addContact(author2, author0.getId(), - master, clock.currentTimeMillis(), true, true + master, clock.currentTimeMillis(), true, true, true ); // Add introducer back contactId0 = contactManager1.addContact(author0, author1.getId(), - master, clock.currentTimeMillis(), false, true + master, clock.currentTimeMillis(), false, true, true ); ContactId contactId02 = contactManager2.addContact(author0, author2.getId(), master, clock.currentTimeMillis(), false, - true + true, true ); assertTrue(contactId0.equals(contactId02)); @@ -516,11 +528,11 @@ public class IntroductionIntegrationTest extends BriarTestCase { // Add introducee as contact contactId1 = contactManager0.addContact(author1, author0.getId(), - master, clock.currentTimeMillis(), true, true + master, clock.currentTimeMillis(), true, true, true ); // Add introducer back contactId0 = contactManager1.addContact(author0, author1.getId(), - master, clock.currentTimeMillis(), true, true + master, clock.currentTimeMillis(), true, true, true ); // listen to events @@ -573,21 +585,21 @@ public class IntroductionIntegrationTest extends BriarTestCase { // Add introducees' authors as contacts contactId1 = contactManager0.addContact(author1, author0.getId(), master, clock.currentTimeMillis(), true, - true + true, true ); contactId2 = contactManager0.addContact(author2, author0.getId(), master, clock.currentTimeMillis(), true, - true + true, true ); // Add introducer back contactId0 = null; ContactId contactId01 = contactManager1.addContact(author0, author1.getId(), master, clock.currentTimeMillis(), false, - true + true, true ); ContactId contactId02 = contactManager1.addContact(author0, author2.getId(), master, clock.currentTimeMillis(), false, - true + true, true ); // listen to events @@ -667,20 +679,20 @@ public class IntroductionIntegrationTest extends BriarTestCase { // Add introducees as contacts contactId1 = contactManager0.addContact(author1, author0.getId(), master, clock.currentTimeMillis(), true, - true + true, true ); contactId2 = contactManager0.addContact(author2, author0.getId(), master, clock.currentTimeMillis(), true, - true + true, true ); // Add introducer back contactId0 = contactManager1.addContact(author0, author1.getId(), master, clock.currentTimeMillis(), true, - true + true, true ); ContactId contactId02 = contactManager2.addContact(author0, author2.getId(), master, clock.currentTimeMillis(), true, - true + true, true ); assertTrue(contactId0.equals(contactId02)); @@ -764,20 +776,20 @@ public class IntroductionIntegrationTest extends BriarTestCase { // Add introducees as contacts contactId1 = contactManager0.addContact(author1, author0.getId(), master, clock.currentTimeMillis(), true, - true + true, true ); contactId2 = contactManager0.addContact(author2, author0.getId(), master, clock.currentTimeMillis(), true, - true + true, true ); // Add introducer back contactId0 = contactManager1.addContact(author0, author1.getId(), master, clock.currentTimeMillis(), true, - true + true, true ); ContactId contactId02 = contactManager2.addContact(author0, author2.getId(), master, clock.currentTimeMillis(), true, - true + true, true ); assertTrue(contactId0.equals(contactId02)); @@ -850,20 +862,20 @@ public class IntroductionIntegrationTest extends BriarTestCase { // Add introducees as contacts contactId1 = contactManager0.addContact(author1, author0.getId(), master, clock.currentTimeMillis(), true, - true + true, true ); contactId2 = contactManager0.addContact(author2, author0.getId(), master, clock.currentTimeMillis(), true, - true + true, true ); // Add introducer back contactId0 = contactManager1.addContact(author0, author1.getId(), master, clock.currentTimeMillis(), true, - true + true, true ); ContactId contactId02 = contactManager2.addContact(author0, author2.getId(), master, clock.currentTimeMillis(), true, - true + true, true ); assertTrue(contactId0.equals(contactId02)); diff --git a/briar-android-tests/src/test/java/org/briarproject/SimplexMessagingIntegrationTest.java b/briar-android-tests/src/test/java/org/briarproject/SimplexMessagingIntegrationTest.java index 3cbf69a6da1e263fa83db6feabc4aa03ae3448b7..661d0465ff1512a35770d710e4a12ed7dbdc7d6e 100644 --- a/briar-android-tests/src/test/java/org/briarproject/SimplexMessagingIntegrationTest.java +++ b/briar-android-tests/src/test/java/org/briarproject/SimplexMessagingIntegrationTest.java @@ -93,7 +93,7 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase { Author bobAuthor = new Author(bobId, "Bob", new byte[MAX_PUBLIC_KEY_LENGTH]); ContactId contactId = contactManager.addContact(bobAuthor, aliceId, - master, timestamp, true, true); + master, timestamp, true, true, true); // Send Bob a message GroupId groupId = messagingManager.getConversationId(contactId); @@ -146,7 +146,7 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase { Author aliceAuthor = new Author(aliceId, "Alice", new byte[MAX_PUBLIC_KEY_LENGTH]); ContactId contactId = contactManager.addContact(aliceAuthor, bobId, - master, timestamp, false, true); + master, timestamp, false, true, true); // Set up an event listener MessageListener listener = new MessageListener(); diff --git a/briar-api/src/org/briarproject/api/contact/Contact.java b/briar-api/src/org/briarproject/api/contact/Contact.java index 12e1efcbfc464df6e094e157dc2cb078c137d477..4de12c21c856a77d42eac20354345435f0416ece 100644 --- a/briar-api/src/org/briarproject/api/contact/Contact.java +++ b/briar-api/src/org/briarproject/api/contact/Contact.java @@ -8,13 +8,14 @@ public class Contact { private final ContactId id; private final Author author; private final AuthorId localAuthorId; - private final boolean active; + private final boolean verified, active; public Contact(ContactId id, Author author, AuthorId localAuthorId, - boolean active) { + boolean verified, boolean active) { this.id = id; this.author = author; this.localAuthorId = localAuthorId; + this.verified = verified; this.active = active; } @@ -30,6 +31,10 @@ public class Contact { return localAuthorId; } + public boolean isVerified() { + return verified; + } + public boolean isActive() { return active; } diff --git a/briar-api/src/org/briarproject/api/contact/ContactManager.java b/briar-api/src/org/briarproject/api/contact/ContactManager.java index 5573e3ea4591d342f8e33922903997e850c9eb38..409d26d88f5de1cc6c1efb76e474e052093a88ba 100644 --- a/briar-api/src/org/briarproject/api/contact/ContactManager.java +++ b/briar-api/src/org/briarproject/api/contact/ContactManager.java @@ -21,16 +21,16 @@ public interface ContactManager { * local and remote pseudonyms, and returns an ID for the contact. */ ContactId addContact(Transaction txn, Author remote, AuthorId local, - SecretKey master, long timestamp, boolean alice, boolean active) - throws DbException; + SecretKey master, long timestamp, boolean alice, boolean verified, + boolean active) throws DbException; /** * Stores a contact associated with the given local and remote pseudonyms, * and returns an ID for the contact. */ ContactId addContact(Author remote, AuthorId local, - SecretKey master, long timestamp, boolean alice, boolean active) - throws DbException; + SecretKey master, long timestamp, boolean alice, boolean verified, + boolean active) throws DbException; /** Returns the contact with the given ID. */ Contact getContact(ContactId c) throws DbException; diff --git a/briar-api/src/org/briarproject/api/db/DatabaseComponent.java b/briar-api/src/org/briarproject/api/db/DatabaseComponent.java index 3f123566f7ea4af22c31b18cd4de727850567a16..b5e6be934dfb8af6b4b6d122ca7479418d776ffb 100644 --- a/briar-api/src/org/briarproject/api/db/DatabaseComponent.java +++ b/briar-api/src/org/briarproject/api/db/DatabaseComponent.java @@ -62,7 +62,7 @@ public interface DatabaseComponent { * and returns an ID for the contact. */ ContactId addContact(Transaction txn, Author remote, AuthorId local, - boolean active) throws DbException; + boolean verified, boolean active) throws DbException; /** * Stores a group. @@ -423,6 +423,12 @@ public interface DatabaseComponent { */ void removeTransport(Transaction txn, TransportId t) throws DbException; + /** + * Marks the given contact as verified or unverified. + */ + void setContactVerified(Transaction txn, ContactId c, boolean verified) + throws DbException; + /** * Marks the given contact as active or inactive. */ diff --git a/briar-core/src/org/briarproject/contact/ContactExchangeTaskImpl.java b/briar-core/src/org/briarproject/contact/ContactExchangeTaskImpl.java index c3d274660cacd3fe553356b0f0fb42f7c7e7ddf9..eb91ed6bd94ace6d7479730ceefe678dc83980bb 100644 --- a/briar-core/src/org/briarproject/contact/ContactExchangeTaskImpl.java +++ b/briar-core/src/org/briarproject/contact/ContactExchangeTaskImpl.java @@ -311,7 +311,7 @@ public class ContactExchangeTaskImpl extends Thread Transaction txn = db.startTransaction(false); try { contactId = contactManager.addContact(txn, remoteAuthor, - localAuthor.getId(), master, timestamp, alice, true); + localAuthor.getId(), master, timestamp, alice, true, true); transportPropertyManager.addRemoteProperties(txn, contactId, remoteProperties); txn.setComplete(); diff --git a/briar-core/src/org/briarproject/contact/ContactManagerImpl.java b/briar-core/src/org/briarproject/contact/ContactManagerImpl.java index 5c5c81d1cc85d8c54ddf30b604f1e40a8a0188f6..fb6ede72d4cddda86ad12e77c5402eb5fb7d0d16 100644 --- a/briar-core/src/org/briarproject/contact/ContactManagerImpl.java +++ b/briar-core/src/org/briarproject/contact/ContactManagerImpl.java @@ -48,9 +48,9 @@ class ContactManagerImpl implements ContactManager, RemoveIdentityHook { @Override public ContactId addContact(Transaction txn, Author remote, AuthorId local, - SecretKey master,long timestamp, boolean alice, boolean active) - throws DbException { - ContactId c = db.addContact(txn, remote, local, active); + SecretKey master,long timestamp, boolean alice, boolean verified, + boolean active) throws DbException { + ContactId c = db.addContact(txn, remote, local, verified, active); keyManager.addContact(txn, c, master, timestamp, alice); Contact contact = db.getContact(txn, c); for (AddContactHook hook : addHooks) @@ -60,13 +60,13 @@ class ContactManagerImpl implements ContactManager, RemoveIdentityHook { @Override public ContactId addContact(Author remote, AuthorId local, SecretKey master, - long timestamp, boolean alice, boolean active) + long timestamp, boolean alice, boolean verified, boolean active) throws DbException { ContactId c; Transaction txn = db.startTransaction(false); try { c = addContact(txn, remote, local, master, timestamp, alice, - active); + verified, active); txn.setComplete(); } finally { db.endTransaction(txn); diff --git a/briar-core/src/org/briarproject/db/Database.java b/briar-core/src/org/briarproject/db/Database.java index a63f411cbb1fda7dad9faf094b6a8008e013d74f..2fa8ced868aae03adbc0f23bcec2549408cd8c76 100644 --- a/briar-core/src/org/briarproject/db/Database.java +++ b/briar-core/src/org/briarproject/db/Database.java @@ -63,8 +63,8 @@ interface Database<T> { * 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 active) - throws DbException; + ContactId addContact(T txn, Author remote, AuthorId local, boolean verified, + boolean active) throws DbException; /** * Stores a group. @@ -575,6 +575,12 @@ interface Database<T> { */ void resetExpiryTime(T txn, ContactId c, MessageId m) throws DbException; + /** + * Marks the given contact as verified or unverified. + */ + void setContactVerified(T txn, ContactId c, boolean verified) + throws DbException; + /** * Marks the given contact as active or inactive. */ diff --git a/briar-core/src/org/briarproject/db/DatabaseComponentImpl.java b/briar-core/src/org/briarproject/db/DatabaseComponentImpl.java index f8eabd84c63453bfdc8bdbe6eb61acb3aec9a6a2..e2ec256969f42d94f10048bd6d62f6f2bf36e5c5 100644 --- a/briar-core/src/org/briarproject/db/DatabaseComponentImpl.java +++ b/briar-core/src/org/briarproject/db/DatabaseComponentImpl.java @@ -152,7 +152,8 @@ class DatabaseComponentImpl<T> implements DatabaseComponent { } public ContactId addContact(Transaction transaction, Author remote, - AuthorId local, boolean active) throws DbException { + AuthorId local, boolean verified, boolean active) + throws DbException { if (transaction.isReadOnly()) throw new IllegalArgumentException(); T txn = unbox(transaction); if (!db.containsLocalAuthor(txn, local)) @@ -161,7 +162,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent { throw new ContactExistsException(); if (db.containsContact(txn, remote.getId(), local)) throw new ContactExistsException(); - ContactId c = db.addContact(txn, remote, local, active); + ContactId c = db.addContact(txn, remote, local, verified, active); transaction.attach(new ContactAddedEvent(c, active)); if (active) transaction.attach(new ContactStatusChangedEvent(c, true)); return c; @@ -682,6 +683,16 @@ class DatabaseComponentImpl<T> implements DatabaseComponent { db.removeTransport(txn, t); } + public void setContactVerified(Transaction transaction, ContactId c, + boolean verified) throws DbException { + if (transaction.isReadOnly()) throw new IllegalArgumentException(); + T txn = unbox(transaction); + if (!db.containsContact(txn, c)) + throw new NoSuchContactException(); + db.setContactVerified(txn, c, verified); + transaction.attach(new ContactStatusChangedEvent(c, verified)); + } + public void setContactActive(Transaction transaction, ContactId c, boolean active) throws DbException { if (transaction.isReadOnly()) throw new IllegalArgumentException(); diff --git a/briar-core/src/org/briarproject/db/JdbcDatabase.java b/briar-core/src/org/briarproject/db/JdbcDatabase.java index 4a5cd78cd07b963fb34582fa9052311fcf1acb21..9e27e91b6747c5931f7ce9f449c68a98ee7277bd 100644 --- a/briar-core/src/org/briarproject/db/JdbcDatabase.java +++ b/briar-core/src/org/briarproject/db/JdbcDatabase.java @@ -67,8 +67,8 @@ import static org.briarproject.db.ExponentialBackoff.calculateExpiry; */ abstract class JdbcDatabase implements Database<Connection> { - private static final int SCHEMA_VERSION = 25; - private static final int MIN_SCHEMA_VERSION = 25; + private static final int SCHEMA_VERSION = 26; + private static final int MIN_SCHEMA_VERSION = 26; private static final String CREATE_SETTINGS = "CREATE TABLE settings" @@ -93,6 +93,7 @@ abstract class JdbcDatabase implements Database<Connection> { + " name VARCHAR NOT NULL," + " publicKey BINARY NOT NULL," + " localAuthorId HASH NOT NULL," + + " verified BOOLEAN NOT NULL," + " active BOOLEAN NOT NULL," + " PRIMARY KEY (contactId)," + " FOREIGN KEY (localAuthorId)" @@ -456,20 +457,21 @@ abstract class JdbcDatabase implements Database<Connection> { } public ContactId addContact(Connection txn, Author remote, AuthorId local, - boolean active) throws DbException { + boolean verified, boolean active) throws DbException { PreparedStatement ps = null; ResultSet rs = null; try { // Create a contact row String sql = "INSERT INTO contacts" - + " (authorId, name, publicKey, localAuthorId, active)" - + " VALUES (?, ?, ?, ?, ?)"; + + " (authorId, name, publicKey, localAuthorId, verified, active)" + + " VALUES (?, ?, ?, ?, ?, ?)"; ps = txn.prepareStatement(sql); ps.setBytes(1, remote.getId().getBytes()); ps.setString(2, remote.getName()); ps.setBytes(3, remote.getPublicKey()); ps.setBytes(4, local.getBytes()); - ps.setBoolean(5, active); + ps.setBoolean(5, verified); + ps.setBoolean(6, active); int affected = ps.executeUpdate(); if (affected != 1) throw new DbStateException(); ps.close(); @@ -961,7 +963,7 @@ abstract class JdbcDatabase implements Database<Connection> { ResultSet rs = null; try { String sql = "SELECT authorId, name, publicKey," - + " localAuthorId, active" + + " localAuthorId, verified, active" + " FROM contacts" + " WHERE contactId = ?"; ps = txn.prepareStatement(sql); @@ -972,11 +974,12 @@ abstract class JdbcDatabase implements Database<Connection> { String name = rs.getString(2); byte[] publicKey = rs.getBytes(3); AuthorId localAuthorId = new AuthorId(rs.getBytes(4)); - boolean active = rs.getBoolean(5); + boolean verified = rs.getBoolean(5); + boolean active = rs.getBoolean(6); rs.close(); ps.close(); Author author = new Author(authorId, name, publicKey); - return new Contact(c, author, localAuthorId, active); + return new Contact(c, author, localAuthorId, verified, active); } catch (SQLException e) { tryToClose(rs); tryToClose(ps); @@ -990,7 +993,7 @@ abstract class JdbcDatabase implements Database<Connection> { ResultSet rs = null; try { String sql = "SELECT contactId, authorId, name, publicKey," - + " localAuthorId, active" + + " localAuthorId, verified, active" + " FROM contacts"; ps = txn.prepareStatement(sql); rs = ps.executeQuery(); @@ -1002,9 +1005,10 @@ abstract class JdbcDatabase implements Database<Connection> { byte[] publicKey = rs.getBytes(4); Author author = new Author(authorId, name, publicKey); AuthorId localAuthorId = new AuthorId(rs.getBytes(5)); - boolean active = rs.getBoolean(6); + boolean verified = rs.getBoolean(6); + boolean active = rs.getBoolean(7); contacts.add(new Contact(contactId, author, localAuthorId, - active)); + verified, active)); } rs.close(); ps.close(); @@ -2245,6 +2249,23 @@ abstract class JdbcDatabase implements Database<Connection> { } } + public void setContactVerified(Connection txn, ContactId c, + boolean verified) throws DbException { + PreparedStatement ps = null; + try { + String sql = "UPDATE contacts SET verified = ? WHERE contactId = ?"; + ps = txn.prepareStatement(sql); + ps.setBoolean(1, verified); + ps.setInt(2, c.getInt()); + int affected = ps.executeUpdate(); + if (affected < 0 || affected > 1) throw new DbStateException(); + ps.close(); + } catch (SQLException e) { + tryToClose(ps); + throw new DbException(e); + } + } + public void setContactActive(Connection txn, ContactId c, boolean active) throws DbException { PreparedStatement ps = null; diff --git a/briar-core/src/org/briarproject/identity/IdentityManagerImpl.java b/briar-core/src/org/briarproject/identity/IdentityManagerImpl.java index 235448b461f32b32212b9e6d9b2ffb976b911b28..dc43c03554eda62f30bb494026fd8f097587b3dd 100644 --- a/briar-core/src/org/briarproject/identity/IdentityManagerImpl.java +++ b/briar-core/src/org/briarproject/identity/IdentityManagerImpl.java @@ -17,6 +17,7 @@ import javax.inject.Inject; import static org.briarproject.api.identity.Author.Status.OURSELVES; import static org.briarproject.api.identity.Author.Status.UNKNOWN; +import static org.briarproject.api.identity.Author.Status.UNVERIFIED; import static org.briarproject.api.identity.Author.Status.VERIFIED; class IdentityManagerImpl implements IdentityManager { @@ -127,10 +128,12 @@ class IdentityManagerImpl implements IdentityManager { for (LocalAuthor a : db.getLocalAuthors(txn)) if (a.getId().equals(authorId)) return OURSELVES; // Compare to the IDs of contacts' identities - for (Contact c : db.getContacts(txn)) - if (c.getAuthor().getId().equals(authorId)) return VERIFIED; - - // TODO also handle UNVERIFIED when #261 is implemented + for (Contact c : db.getContacts(txn)) { + if (c.getAuthor().getId().equals(authorId)) { + if (c.isVerified()) return VERIFIED; + else return UNVERIFIED; + } + } return UNKNOWN; } diff --git a/briar-core/src/org/briarproject/introduction/IntroduceeManager.java b/briar-core/src/org/briarproject/introduction/IntroduceeManager.java index c0f9506f56633082d8b4fb2cb1fb64dc7f8cfef0..325fed6475c2d6cc5d8aaf50831bfcd3cfc38154 100644 --- a/briar-core/src/org/briarproject/introduction/IntroduceeManager.java +++ b/briar-core/src/org/briarproject/introduction/IntroduceeManager.java @@ -325,7 +325,7 @@ class IntroduceeManager { localState.getRaw(PUBLIC_KEY)); ContactId contactId = contactManager .addContact(txn, remoteAuthor, localAuthorId, secretKey, - timestamp, alice, false); + timestamp, alice, false, false); // Update local state with ContactId, so we know what to activate localState.put(ADDED_CONTACT_ID, contactId.getInt()); diff --git a/briar-tests/src/org/briarproject/blogs/BlogManagerImplTest.java b/briar-tests/src/org/briarproject/blogs/BlogManagerImplTest.java index 4663b16a0919bd8325261628ed8394bc8e7bd244..5b380bdda0bd947929c5806ef5dcdb98914504af 100644 --- a/briar-tests/src/org/briarproject/blogs/BlogManagerImplTest.java +++ b/briar-tests/src/org/briarproject/blogs/BlogManagerImplTest.java @@ -94,7 +94,7 @@ public class BlogManagerImplTest extends BriarTestCase { Collections.singletonList(contactId); Contact contact = new Contact(contactId, blog2.getAuthor(), - blog1.getAuthor().getId(), true); + blog1.getAuthor().getId(), true, true); final Collection<Contact> contacts = Collections.singletonList(contact); context.checking(new Expectations() {{ @@ -132,7 +132,7 @@ public class BlogManagerImplTest extends BriarTestCase { final ContactId contactId = new ContactId(0); Contact contact = new Contact(contactId, blog2.getAuthor(), - blog1.getAuthor().getId(), true); + blog1.getAuthor().getId(), true, true); context.checking(new Expectations() {{ oneOf(blogFactory).createPersonalBlog(blog2.getAuthor()); diff --git a/briar-tests/src/org/briarproject/db/DatabaseComponentImplTest.java b/briar-tests/src/org/briarproject/db/DatabaseComponentImplTest.java index 022dea7c343cac200744818aec9dff0d569af888..30f46c03280ba350a99468dac35dd576a6b75be7 100644 --- a/briar-tests/src/org/briarproject/db/DatabaseComponentImplTest.java +++ b/briar-tests/src/org/briarproject/db/DatabaseComponentImplTest.java @@ -111,7 +111,7 @@ public class DatabaseComponentImplTest extends BriarTestCase { transportId = new TransportId("id"); maxLatency = Integer.MAX_VALUE; contactId = new ContactId(234); - contact = new Contact(contactId, author, localAuthorId, true); + contact = new Contact(contactId, author, localAuthorId, true, true); } private DatabaseComponent createDatabaseComponent(Database<Object> database, @@ -149,7 +149,7 @@ public class DatabaseComponentImplTest extends BriarTestCase { will(returnValue(false)); oneOf(database).containsContact(txn, authorId, localAuthorId); will(returnValue(false)); - oneOf(database).addContact(txn, author, localAuthorId, true); + oneOf(database).addContact(txn, author, localAuthorId, true, true); will(returnValue(contactId)); oneOf(eventBus).broadcast(with(any(ContactAddedEvent.class))); oneOf(eventBus).broadcast(with(any( @@ -201,7 +201,8 @@ public class DatabaseComponentImplTest extends BriarTestCase { try { db.addLocalAuthor(transaction, localAuthor); assertEquals(contactId, - db.addContact(transaction, author, localAuthorId, true)); + db.addContact(transaction, author, localAuthorId, true, + true)); assertEquals(Collections.singletonList(contact), db.getContacts(transaction)); db.addGroup(transaction, group); // First time - listeners called @@ -519,7 +520,7 @@ public class DatabaseComponentImplTest extends BriarTestCase { Transaction transaction = db.startTransaction(false); try { - db.addContact(transaction, author, localAuthorId, true); + db.addContact(transaction, author, localAuthorId, true, true); fail(); } catch (NoSuchLocalAuthorException expected) { // Expected @@ -815,7 +816,7 @@ public class DatabaseComponentImplTest extends BriarTestCase { will(returnValue(false)); oneOf(database).containsContact(txn, authorId, localAuthorId); will(returnValue(false)); - oneOf(database).addContact(txn, author, localAuthorId, true); + oneOf(database).addContact(txn, author, localAuthorId, true, true); will(returnValue(contactId)); oneOf(eventBus).broadcast(with(any(ContactAddedEvent.class))); oneOf(eventBus).broadcast(with(any( @@ -838,7 +839,8 @@ public class DatabaseComponentImplTest extends BriarTestCase { try { db.addLocalAuthor(transaction, localAuthor); assertEquals(contactId, - db.addContact(transaction, author, localAuthorId, true)); + db.addContact(transaction, author, localAuthorId, true, + true)); transaction.setComplete(); } finally { db.endTransaction(transaction); @@ -1569,7 +1571,7 @@ public class DatabaseComponentImplTest extends BriarTestCase { Transaction transaction = db.startTransaction(false); try { - db.addContact(transaction, author, localAuthorId, true); + db.addContact(transaction, author, localAuthorId, true, true); fail(); } catch (ContactExistsException expected) { // Expected @@ -1606,7 +1608,7 @@ public class DatabaseComponentImplTest extends BriarTestCase { Transaction transaction = db.startTransaction(false); try { - db.addContact(transaction, author, localAuthorId, true); + db.addContact(transaction, author, localAuthorId, true, true); fail(); } catch (ContactExistsException expected) { // Expected diff --git a/briar-tests/src/org/briarproject/db/H2DatabaseTest.java b/briar-tests/src/org/briarproject/db/H2DatabaseTest.java index f50dcb2bcb36aa3e61b9749128e2e3f61b6e1221..259db68353bfc3af771c6b8288367211f8126b9c 100644 --- a/briar-tests/src/org/briarproject/db/H2DatabaseTest.java +++ b/briar-tests/src/org/briarproject/db/H2DatabaseTest.java @@ -111,7 +111,7 @@ public class H2DatabaseTest extends BriarTestCase { assertFalse(db.containsContact(txn, contactId)); db.addLocalAuthor(txn, localAuthor); assertEquals(contactId, db.addContact(txn, author, localAuthorId, - true)); + true, true)); assertTrue(db.containsContact(txn, contactId)); assertFalse(db.containsGroup(txn, groupId)); db.addGroup(txn, group); @@ -174,7 +174,7 @@ public class H2DatabaseTest extends BriarTestCase { // Add a contact, a group and a message db.addLocalAuthor(txn, localAuthor); assertEquals(contactId, db.addContact(txn, author, localAuthorId, - true)); + true, true)); db.addGroup(txn, group); db.addVisibility(txn, contactId, groupId); db.addMessage(txn, message, DELIVERED, true); @@ -212,7 +212,7 @@ public class H2DatabaseTest extends BriarTestCase { // Add a contact, a group and an unvalidated message db.addLocalAuthor(txn, localAuthor); assertEquals(contactId, db.addContact(txn, author, localAuthorId, - true)); + true, true)); db.addGroup(txn, group); db.addVisibility(txn, contactId, groupId); db.addMessage(txn, message, UNKNOWN, true); @@ -267,7 +267,7 @@ public class H2DatabaseTest extends BriarTestCase { // Add a contact, a group and an unshared message db.addLocalAuthor(txn, localAuthor); assertEquals(contactId, db.addContact(txn, author, localAuthorId, - true)); + true, true)); db.addGroup(txn, group); db.addVisibility(txn, contactId, groupId); db.addMessage(txn, message, DELIVERED, false); @@ -306,7 +306,7 @@ public class H2DatabaseTest extends BriarTestCase { // Add a contact, a group and a message db.addLocalAuthor(txn, localAuthor); assertEquals(contactId, db.addContact(txn, author, localAuthorId, - true)); + true, true)); db.addGroup(txn, group); db.addVisibility(txn, contactId, groupId); db.addMessage(txn, message, DELIVERED, true); @@ -333,7 +333,7 @@ public class H2DatabaseTest extends BriarTestCase { // Add a contact and a group db.addLocalAuthor(txn, localAuthor); assertEquals(contactId, db.addContact(txn, author, localAuthorId, - true)); + true, true)); db.addGroup(txn, group); db.addVisibility(txn, contactId, groupId); @@ -370,7 +370,7 @@ public class H2DatabaseTest extends BriarTestCase { // Add a contact, a group and a message db.addLocalAuthor(txn, localAuthor); assertEquals(contactId, db.addContact(txn, author, localAuthorId, - true)); + true, true)); db.addGroup(txn, group); db.addVisibility(txn, contactId, groupId); db.addMessage(txn, message, DELIVERED, true); @@ -534,7 +534,7 @@ public class H2DatabaseTest extends BriarTestCase { // Add a contact and a group db.addLocalAuthor(txn, localAuthor); assertEquals(contactId, db.addContact(txn, author, localAuthorId, - true)); + true, true)); db.addGroup(txn, group); db.addVisibility(txn, contactId, groupId); @@ -554,7 +554,7 @@ public class H2DatabaseTest extends BriarTestCase { // Add a contact db.addLocalAuthor(txn, localAuthor); assertEquals(contactId, db.addContact(txn, author, localAuthorId, - true)); + true, true)); // The group is not in the database assertFalse(db.containsVisibleMessage(txn, contactId, messageId)); @@ -572,7 +572,7 @@ public class H2DatabaseTest extends BriarTestCase { // Add a contact, a group and a message db.addLocalAuthor(txn, localAuthor); assertEquals(contactId, db.addContact(txn, author, localAuthorId, - true)); + true, true)); db.addGroup(txn, group); db.addMessage(txn, message, DELIVERED, true); db.addStatus(txn, contactId, messageId, false, false); @@ -592,7 +592,7 @@ public class H2DatabaseTest extends BriarTestCase { // Add a contact and a group db.addLocalAuthor(txn, localAuthor); assertEquals(contactId, db.addContact(txn, author, localAuthorId, - true)); + true, true)); db.addGroup(txn, group); // The group should not be visible to the contact @@ -628,7 +628,7 @@ public class H2DatabaseTest extends BriarTestCase { // Add a contact and the groups db.addLocalAuthor(txn, localAuthor); assertEquals(contactId, db.addContact(txn, author, localAuthorId, - true)); + true, true)); for (Group g : groups) db.addGroup(txn, g); // Make the groups visible to the contact @@ -661,7 +661,7 @@ public class H2DatabaseTest extends BriarTestCase { // Add the contact, the transport and the transport keys db.addLocalAuthor(txn, localAuthor); assertEquals(contactId, db.addContact(txn, author, localAuthorId, - true)); + true, true)); db.addTransport(txn, transportId, 123); db.addTransportKeys(txn, contactId, keys); @@ -723,7 +723,7 @@ public class H2DatabaseTest extends BriarTestCase { // Add the contact, transport and transport keys db.addLocalAuthor(txn, localAuthor); assertEquals(contactId, db.addContact(txn, author, localAuthorId, - true)); + true, true)); db.addTransport(txn, transportId, 123); db.updateTransportKeys(txn, Collections.singletonMap(contactId, keys)); @@ -759,7 +759,7 @@ public class H2DatabaseTest extends BriarTestCase { // Add the contact, transport and transport keys db.addLocalAuthor(txn, localAuthor); assertEquals(contactId, db.addContact(txn, author, localAuthorId, - true)); + true, true)); db.addTransport(txn, transportId, 123); db.updateTransportKeys(txn, Collections.singletonMap(contactId, keys)); @@ -796,7 +796,7 @@ public class H2DatabaseTest extends BriarTestCase { // Add a contact associated with the local author assertEquals(contactId, db.addContact(txn, author, localAuthorId, - true)); + true, true)); contacts = db.getContacts(txn, localAuthorId); assertEquals(Collections.singletonList(contactId), contacts); @@ -818,7 +818,7 @@ public class H2DatabaseTest extends BriarTestCase { // Add a contact - initially there should be no offered messages db.addLocalAuthor(txn, localAuthor); assertEquals(contactId, db.addContact(txn, author, localAuthorId, - true)); + true, true)); assertEquals(0, db.countOfferedMessages(txn, contactId)); // Add some offered messages and count them @@ -1377,7 +1377,7 @@ public class H2DatabaseTest extends BriarTestCase { // Add a contact db.addLocalAuthor(txn, localAuthor); assertEquals(contactId, db.addContact(txn, author, localAuthorId, - true)); + true, true)); // Add a group and make it visible to the contact db.addGroup(txn, group); @@ -1454,7 +1454,7 @@ public class H2DatabaseTest extends BriarTestCase { // Add a contact and a group db.addLocalAuthor(txn, localAuthor); assertEquals(contactId, db.addContact(txn, author, localAuthorId, - true)); + true, true)); db.addGroup(txn, group); // The group should not be visible to the contact @@ -1487,8 +1487,10 @@ public class H2DatabaseTest extends BriarTestCase { db.addLocalAuthor(txn, localAuthor1); // Add the same contact for each local pseudonym - ContactId contactId = db.addContact(txn, author, localAuthorId, true); - ContactId contactId1 = db.addContact(txn, author, localAuthorId1, true); + ContactId contactId = + db.addContact(txn, author, localAuthorId, true, true); + ContactId contactId1 = + db.addContact(txn, author, localAuthorId1, true, true); // The contacts should be distinct assertNotEquals(contactId, contactId1); @@ -1508,7 +1510,7 @@ public class H2DatabaseTest extends BriarTestCase { // Add a contact, a group and a message db.addLocalAuthor(txn, localAuthor); assertEquals(contactId, db.addContact(txn, author, localAuthorId, - true)); + true, true)); db.addGroup(txn, group); db.addVisibility(txn, contactId, groupId); db.addMessage(txn, message, DELIVERED, true); @@ -1554,7 +1556,7 @@ public class H2DatabaseTest extends BriarTestCase { // Add a contact db.addLocalAuthor(txn, localAuthor); assertEquals(contactId, db.addContact(txn, author, localAuthorId, - true)); + true, true)); // The contact should be active Contact contact = db.getContact(txn, contactId); diff --git a/briar-tests/src/org/briarproject/introduction/IntroduceeManagerTest.java b/briar-tests/src/org/briarproject/introduction/IntroduceeManagerTest.java index c6a0afa45cff9fd1d12ab667010543649bba123d..8b7e1afe340f2fb98087213712809f5762172505 100644 --- a/briar-tests/src/org/briarproject/introduction/IntroduceeManagerTest.java +++ b/briar-tests/src/org/briarproject/introduction/IntroduceeManagerTest.java @@ -115,20 +115,23 @@ public class IntroduceeManagerTest extends BriarTestCase { TestUtils.getRandomBytes(MAX_PUBLIC_KEY_LENGTH)); AuthorId localAuthorId = new AuthorId(TestUtils.getRandomId()); ContactId contactId0 = new ContactId(234); - introducer = new Contact(contactId0, author0, localAuthorId, true); + introducer = + new Contact(contactId0, author0, localAuthorId, true, true); AuthorId authorId1 = new AuthorId(TestUtils.getRandomId()); Author author1 = new Author(authorId1, "Introducee1", TestUtils.getRandomBytes(MAX_PUBLIC_KEY_LENGTH)); AuthorId localAuthorId1 = new AuthorId(TestUtils.getRandomId()); ContactId contactId1 = new ContactId(234); - introducee1 = new Contact(contactId1, author1, localAuthorId1, true); + introducee1 = + new Contact(contactId1, author1, localAuthorId1, true, true); AuthorId authorId2 = new AuthorId(TestUtils.getRandomId()); Author author2 = new Author(authorId2, "Introducee2", TestUtils.getRandomBytes(MAX_PUBLIC_KEY_LENGTH)); ContactId contactId2 = new ContactId(235); - introducee2 = new Contact(contactId2, author2, localAuthorId, true); + introducee2 = + new Contact(contactId2, author2, localAuthorId, true, true); clientId = IntroductionManagerImpl.CLIENT_ID; localGroup1 = new Group(new GroupId(TestUtils.getRandomId()), diff --git a/briar-tests/src/org/briarproject/introduction/IntroducerManagerTest.java b/briar-tests/src/org/briarproject/introduction/IntroducerManagerTest.java index 9f4cc21746de77fe94fa1d63e75171ffc9d28d9e..9dd4f913cca6cc26e5c982c486a88979d0ff8d2d 100644 --- a/briar-tests/src/org/briarproject/introduction/IntroducerManagerTest.java +++ b/briar-tests/src/org/briarproject/introduction/IntroducerManagerTest.java @@ -85,14 +85,16 @@ public class IntroducerManagerTest extends BriarTestCase { TestUtils.getRandomBytes(MAX_PUBLIC_KEY_LENGTH)); AuthorId localAuthorId1 = new AuthorId(TestUtils.getRandomId()); ContactId contactId1 = new ContactId(234); - introducee1 = new Contact(contactId1, author1, localAuthorId1, true); + introducee1 = + new Contact(contactId1, author1, localAuthorId1, true, true); AuthorId authorId2 = new AuthorId(TestUtils.getRandomId()); Author author2 = new Author(authorId2, "Introducee2", TestUtils.getRandomBytes(MAX_PUBLIC_KEY_LENGTH)); AuthorId localAuthorId2 = new AuthorId(TestUtils.getRandomId()); ContactId contactId2 = new ContactId(235); - introducee2 = new Contact(contactId2, author2, localAuthorId2, true); + introducee2 = + new Contact(contactId2, author2, localAuthorId2, true, true); localGroup0 = new Group(new GroupId(TestUtils.getRandomId()), getClientId(), new byte[0]); diff --git a/briar-tests/src/org/briarproject/introduction/IntroductionManagerImplTest.java b/briar-tests/src/org/briarproject/introduction/IntroductionManagerImplTest.java index 2b3bde49fb13e68d99e6a4ba6a0b8429cc5adf2c..222ea050efd86590fba21ef3f25cc8a356de492c 100644 --- a/briar-tests/src/org/briarproject/introduction/IntroductionManagerImplTest.java +++ b/briar-tests/src/org/briarproject/introduction/IntroductionManagerImplTest.java @@ -77,14 +77,16 @@ public class IntroductionManagerImplTest extends BriarTestCase { new byte[MAX_PUBLIC_KEY_LENGTH]); AuthorId localAuthorId1 = new AuthorId(TestUtils.getRandomId()); ContactId contactId1 = new ContactId(234); - introducee1 = new Contact(contactId1, author1, localAuthorId1, true); + introducee1 = + new Contact(contactId1, author1, localAuthorId1, true, true); AuthorId authorId2 = new AuthorId(TestUtils.getRandomId()); Author author2 = new Author(authorId2, "Introducee2", new byte[MAX_PUBLIC_KEY_LENGTH]); AuthorId localAuthorId2 = new AuthorId(TestUtils.getRandomId()); ContactId contactId2 = new ContactId(235); - introducee2 = new Contact(contactId2, author2, localAuthorId2, true); + introducee2 = + new Contact(contactId2, author2, localAuthorId2, true, true); ClientId clientId = new ClientId(TestUtils.getRandomId()); localGroup0 = new Group(new GroupId(TestUtils.getRandomId()),