mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-15 04:18:53 +01:00
Massive refactoring to use pseudonyms instead of nicknames for contacts.
The invitation and private messaging UIs are currently broken. Some key rotation bugs were fixed; others may have been created (unit tests needed). An encoding for private keys was added. Pseudonyms were moved out of the messaging package and ratings were moved in.
This commit is contained in:
@@ -14,12 +14,13 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Random;
|
||||
|
||||
import net.sf.briar.api.Author;
|
||||
import net.sf.briar.api.AuthorFactory;
|
||||
import net.sf.briar.api.ContactId;
|
||||
import net.sf.briar.api.TransportId;
|
||||
import net.sf.briar.api.TransportProperties;
|
||||
import net.sf.briar.api.crypto.CryptoComponent;
|
||||
import net.sf.briar.api.messaging.Ack;
|
||||
import net.sf.briar.api.messaging.Author;
|
||||
import net.sf.briar.api.messaging.AuthorFactory;
|
||||
import net.sf.briar.api.messaging.Group;
|
||||
import net.sf.briar.api.messaging.GroupFactory;
|
||||
import net.sf.briar.api.messaging.Message;
|
||||
@@ -33,7 +34,6 @@ import net.sf.briar.api.messaging.PacketWriter;
|
||||
import net.sf.briar.api.messaging.PacketWriterFactory;
|
||||
import net.sf.briar.api.messaging.Request;
|
||||
import net.sf.briar.api.messaging.SubscriptionUpdate;
|
||||
import net.sf.briar.api.messaging.TransportId;
|
||||
import net.sf.briar.api.messaging.TransportUpdate;
|
||||
import net.sf.briar.api.messaging.UnverifiedMessage;
|
||||
import net.sf.briar.api.transport.ConnectionContext;
|
||||
|
||||
@@ -2,7 +2,6 @@ package net.sf.briar;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import net.sf.briar.api.crypto.Password;
|
||||
import net.sf.briar.api.db.DatabaseConfig;
|
||||
|
||||
public class TestDatabaseConfig implements DatabaseConfig {
|
||||
@@ -19,12 +18,8 @@ public class TestDatabaseConfig implements DatabaseConfig {
|
||||
return dir;
|
||||
}
|
||||
|
||||
public Password getPassword() {
|
||||
return new Password() {
|
||||
public char[] getPassword() {
|
||||
return "foo bar".toCharArray();
|
||||
}
|
||||
};
|
||||
public char[] getPassword() {
|
||||
return "foo bar".toCharArray();
|
||||
}
|
||||
|
||||
public long getMaxSize() {
|
||||
|
||||
@@ -3,7 +3,7 @@ package net.sf.briar;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
|
||||
import net.sf.briar.api.messaging.Author;
|
||||
import net.sf.briar.api.Author;
|
||||
import net.sf.briar.api.messaging.Group;
|
||||
import net.sf.briar.api.messaging.Message;
|
||||
import net.sf.briar.api.messaging.MessageId;
|
||||
|
||||
@@ -10,7 +10,7 @@ import java.util.Random;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import net.sf.briar.api.messaging.UniqueId;
|
||||
import net.sf.briar.api.UniqueId;
|
||||
|
||||
public class TestUtils {
|
||||
|
||||
|
||||
@@ -14,12 +14,12 @@ public class KeyAgreementTest extends BriarTestCase {
|
||||
@Test
|
||||
public void testKeyAgreement() throws Exception {
|
||||
CryptoComponent crypto = new CryptoComponentImpl();
|
||||
KeyPair a = crypto.generateAgreementKeyPair();
|
||||
byte[] aPub = a.getPublic().getEncoded();
|
||||
KeyPair b = crypto.generateAgreementKeyPair();
|
||||
byte[] bPub = b.getPublic().getEncoded();
|
||||
byte[] aSecret = crypto.deriveInitialSecret(aPub, b, true);
|
||||
byte[] bSecret = crypto.deriveInitialSecret(bPub, a, false);
|
||||
KeyPair aPair = crypto.generateAgreementKeyPair();
|
||||
byte[] aPub = aPair.getPublic().getEncoded();
|
||||
KeyPair bPair = crypto.generateAgreementKeyPair();
|
||||
byte[] bPub = bPair.getPublic().getEncoded();
|
||||
byte[] aSecret = crypto.deriveMasterSecret(aPub, bPair, true);
|
||||
byte[] bSecret = crypto.deriveMasterSecret(bPub, aPair, false);
|
||||
assertArrayEquals(aSecret, bSecret);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
package net.sf.briar.crypto;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
|
||||
import java.security.KeyPair;
|
||||
import java.security.PrivateKey;
|
||||
import java.security.PublicKey;
|
||||
|
||||
import net.sf.briar.BriarTestCase;
|
||||
import net.sf.briar.api.crypto.KeyParser;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class KeyEncodingAndParsingTest extends BriarTestCase {
|
||||
|
||||
private final CryptoComponentImpl crypto = new CryptoComponentImpl();
|
||||
|
||||
@Test
|
||||
public void testAgreementPublicKeyEncodingAndParsing() throws Exception {
|
||||
KeyParser parser = crypto.getAgreementKeyParser();
|
||||
// Generate two key pairs
|
||||
KeyPair aPair = crypto.generateAgreementKeyPair();
|
||||
KeyPair bPair = crypto.generateAgreementKeyPair();
|
||||
// Derive the shared secret
|
||||
PublicKey aPub = aPair.getPublic();
|
||||
byte[] secret = crypto.deriveSharedSecret(bPair.getPrivate(), aPub);
|
||||
// Encode and parse the public key - no exceptions should be thrown
|
||||
aPub = parser.parsePublicKey(aPub.getEncoded());
|
||||
aPub = parser.parsePublicKey(aPub.getEncoded());
|
||||
// Derive the shared secret again - it should be the same
|
||||
byte[] secret1 = crypto.deriveSharedSecret(bPair.getPrivate(), aPub);
|
||||
assertArrayEquals(secret, secret1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAgreementPrivateKeyEncodingAndParsing() throws Exception {
|
||||
KeyParser parser = crypto.getAgreementKeyParser();
|
||||
// Generate two key pairs
|
||||
KeyPair aPair = crypto.generateAgreementKeyPair();
|
||||
KeyPair bPair = crypto.generateAgreementKeyPair();
|
||||
// Derive the shared secret
|
||||
PrivateKey bPriv = bPair.getPrivate();
|
||||
byte[] secret = crypto.deriveSharedSecret(bPriv, aPair.getPublic());
|
||||
// Encode and parse the private key - no exceptions should be thrown
|
||||
bPriv = parser.parsePrivateKey(bPriv.getEncoded());
|
||||
bPriv = parser.parsePrivateKey(bPriv.getEncoded());
|
||||
// Derive the shared secret again - it should be the same
|
||||
byte[] secret1 = crypto.deriveSharedSecret(bPriv, aPair.getPublic());
|
||||
assertArrayEquals(secret, secret1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSignaturePublicKeyEncodingAndParsing() throws Exception {
|
||||
KeyParser parser = crypto.getSignatureKeyParser();
|
||||
// Generate two key pairs
|
||||
KeyPair aPair = crypto.generateSignatureKeyPair();
|
||||
KeyPair bPair = crypto.generateSignatureKeyPair();
|
||||
// Derive the shared secret
|
||||
PublicKey aPub = aPair.getPublic();
|
||||
byte[] secret = crypto.deriveSharedSecret(bPair.getPrivate(), aPub);
|
||||
// Encode and parse the public key - no exceptions should be thrown
|
||||
aPub = parser.parsePublicKey(aPub.getEncoded());
|
||||
aPub = parser.parsePublicKey(aPub.getEncoded());
|
||||
// Derive the shared secret again - it should be the same
|
||||
byte[] secret1 = crypto.deriveSharedSecret(bPair.getPrivate(), aPub);
|
||||
assertArrayEquals(secret, secret1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSignaturePrivateKeyEncodingAndParsing() throws Exception {
|
||||
KeyParser parser = crypto.getSignatureKeyParser();
|
||||
// Generate two key pairs
|
||||
KeyPair aPair = crypto.generateSignatureKeyPair();
|
||||
KeyPair bPair = crypto.generateSignatureKeyPair();
|
||||
// Derive the shared secret
|
||||
PrivateKey bPriv = bPair.getPrivate();
|
||||
byte[] secret = crypto.deriveSharedSecret(bPriv, aPair.getPublic());
|
||||
// Encode and parse the private key - no exceptions should be thrown
|
||||
bPriv = parser.parsePrivateKey(bPriv.getEncoded());
|
||||
bPriv = parser.parsePrivateKey(bPriv.getEncoded());
|
||||
// Derive the shared secret again - it should be the same
|
||||
byte[] secret1 = crypto.deriveSharedSecret(bPriv, aPair.getPublic());
|
||||
assertArrayEquals(secret, secret1);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.sf.briar.db;
|
||||
|
||||
import static net.sf.briar.api.Rating.GOOD;
|
||||
import static net.sf.briar.api.Rating.UNRATED;
|
||||
import static net.sf.briar.api.messaging.Rating.GOOD;
|
||||
import static net.sf.briar.api.messaging.Rating.UNRATED;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -14,9 +14,13 @@ import java.util.Map;
|
||||
import net.sf.briar.BriarTestCase;
|
||||
import net.sf.briar.TestMessage;
|
||||
import net.sf.briar.TestUtils;
|
||||
import net.sf.briar.api.Author;
|
||||
import net.sf.briar.api.AuthorId;
|
||||
import net.sf.briar.api.Contact;
|
||||
import net.sf.briar.api.ContactId;
|
||||
import net.sf.briar.api.LocalAuthor;
|
||||
import net.sf.briar.api.TransportConfig;
|
||||
import net.sf.briar.api.TransportId;
|
||||
import net.sf.briar.api.TransportProperties;
|
||||
import net.sf.briar.api.db.DatabaseComponent;
|
||||
import net.sf.briar.api.db.NoSuchContactException;
|
||||
@@ -33,8 +37,6 @@ import net.sf.briar.api.db.event.SubscriptionAddedEvent;
|
||||
import net.sf.briar.api.db.event.SubscriptionRemovedEvent;
|
||||
import net.sf.briar.api.lifecycle.ShutdownManager;
|
||||
import net.sf.briar.api.messaging.Ack;
|
||||
import net.sf.briar.api.messaging.Author;
|
||||
import net.sf.briar.api.messaging.AuthorId;
|
||||
import net.sf.briar.api.messaging.Group;
|
||||
import net.sf.briar.api.messaging.GroupId;
|
||||
import net.sf.briar.api.messaging.Message;
|
||||
@@ -46,7 +48,6 @@ import net.sf.briar.api.messaging.RetentionUpdate;
|
||||
import net.sf.briar.api.messaging.SubscriptionAck;
|
||||
import net.sf.briar.api.messaging.SubscriptionUpdate;
|
||||
import net.sf.briar.api.messaging.TransportAck;
|
||||
import net.sf.briar.api.messaging.TransportId;
|
||||
import net.sf.briar.api.messaging.TransportUpdate;
|
||||
import net.sf.briar.api.transport.Endpoint;
|
||||
import net.sf.briar.api.transport.TemporarySecret;
|
||||
@@ -62,6 +63,8 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
protected final Group group;
|
||||
protected final AuthorId authorId;
|
||||
protected final Author author;
|
||||
protected final AuthorId localAuthorId;
|
||||
protected final LocalAuthor localAuthor;
|
||||
protected final MessageId messageId, messageId1;
|
||||
protected final String contentType, subject;
|
||||
protected final long timestamp;
|
||||
@@ -71,7 +74,6 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
protected final TransportId transportId;
|
||||
protected final TransportProperties transportProperties;
|
||||
protected final ContactId contactId;
|
||||
protected final String contactName;
|
||||
protected final Contact contact;
|
||||
protected final Endpoint endpoint;
|
||||
protected final TemporarySecret temporarySecret;
|
||||
@@ -82,6 +84,9 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
group = new Group(groupId, "Group name", null);
|
||||
authorId = new AuthorId(TestUtils.getRandomId());
|
||||
author = new Author(authorId, "Alice", new byte[60]);
|
||||
localAuthorId = new AuthorId(TestUtils.getRandomId());
|
||||
localAuthor = new LocalAuthor(localAuthorId, "Bob", new byte[60],
|
||||
new byte[60]);
|
||||
messageId = new MessageId(TestUtils.getRandomId());
|
||||
messageId1 = new MessageId(TestUtils.getRandomId());
|
||||
contentType = "text/plain";
|
||||
@@ -97,11 +102,10 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
transportProperties = new TransportProperties(Collections.singletonMap(
|
||||
"foo", "bar"));
|
||||
contactId = new ContactId(234);
|
||||
contactName = "Alice";
|
||||
contact = new Contact(contactId, contactName, timestamp);
|
||||
endpoint = new Endpoint(contactId, transportId, 123, 234, 345, true);
|
||||
temporarySecret = new TemporarySecret(contactId, transportId, 1, 2,
|
||||
3, false, 4, new byte[32], 5, 6, new byte[4]);
|
||||
contact = new Contact(contactId, author, timestamp);
|
||||
endpoint = new Endpoint(contactId, transportId, 123, true);
|
||||
temporarySecret = new TemporarySecret(contactId, transportId, 123,
|
||||
false, 234, new byte[32], 345, 456, new byte[4]);
|
||||
}
|
||||
|
||||
protected abstract <T> DatabaseComponent createDatabaseComponent(
|
||||
@@ -118,9 +122,9 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
final ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
final DatabaseListener listener = context.mock(DatabaseListener.class);
|
||||
context.checking(new Expectations() {{
|
||||
exactly(12).of(database).startTransaction();
|
||||
exactly(13).of(database).startTransaction();
|
||||
will(returnValue(txn));
|
||||
exactly(12).of(database).commitTransaction(txn);
|
||||
exactly(13).of(database).commitTransaction(txn);
|
||||
// open(false)
|
||||
oneOf(database).open(false);
|
||||
oneOf(cleaner).startCleaning(
|
||||
@@ -140,8 +144,12 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
// setRating(authorId, GOOD) again
|
||||
oneOf(database).setRating(txn, authorId, GOOD);
|
||||
will(returnValue(GOOD));
|
||||
// addContact(contactName)
|
||||
oneOf(database).addContact(txn, contactName);
|
||||
// addLocalAuthor(localAuthor)
|
||||
oneOf(database).addLocalAuthor(txn, localAuthor);
|
||||
// addContact(author, localAuthorId)
|
||||
oneOf(database).containsContact(txn, authorId);
|
||||
will(returnValue(false));
|
||||
oneOf(database).addContact(txn, author, localAuthorId);
|
||||
will(returnValue(contactId));
|
||||
oneOf(listener).eventOccurred(with(any(ContactAddedEvent.class)));
|
||||
// getContacts()
|
||||
@@ -196,7 +204,8 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
assertEquals(UNRATED, db.getRating(authorId));
|
||||
db.setRating(authorId, GOOD); // First time - listeners called
|
||||
db.setRating(authorId, GOOD); // Second time - not called
|
||||
assertEquals(contactId, db.addContact(contactName));
|
||||
db.addLocalAuthor(localAuthor);
|
||||
assertEquals(contactId, db.addContact(author, localAuthorId));
|
||||
assertEquals(Arrays.asList(contact), db.getContacts());
|
||||
assertEquals(Collections.emptyMap(),
|
||||
db.getRemoteProperties(transportId));
|
||||
@@ -723,10 +732,17 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
final DatabaseCleaner cleaner = context.mock(DatabaseCleaner.class);
|
||||
final ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
context.checking(new Expectations() {{
|
||||
// addContact()
|
||||
// addLocalAuthor(localAuthor)
|
||||
oneOf(database).startTransaction();
|
||||
will(returnValue(txn));
|
||||
oneOf(database).addContact(txn, contactName);
|
||||
oneOf(database).addLocalAuthor(txn, localAuthor);
|
||||
oneOf(database).commitTransaction(txn);
|
||||
// addContact(author, localAuthorId)
|
||||
oneOf(database).startTransaction();
|
||||
will(returnValue(txn));
|
||||
oneOf(database).containsContact(txn, authorId);
|
||||
will(returnValue(false));
|
||||
oneOf(database).addContact(txn, author, localAuthorId);
|
||||
will(returnValue(contactId));
|
||||
oneOf(database).commitTransaction(txn);
|
||||
// Check whether the transport is in the DB (which it's not)
|
||||
@@ -740,7 +756,8 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
}});
|
||||
DatabaseComponent db = createDatabaseComponent(database, cleaner,
|
||||
shutdown);
|
||||
assertEquals(contactId, db.addContact(contactName));
|
||||
db.addLocalAuthor(localAuthor);
|
||||
assertEquals(contactId, db.addContact(author, localAuthorId));
|
||||
|
||||
try {
|
||||
db.addEndpoint(endpoint);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package net.sf.briar.db;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||
import static net.sf.briar.api.Rating.GOOD;
|
||||
import static net.sf.briar.api.Rating.UNRATED;
|
||||
import static net.sf.briar.api.messaging.Rating.GOOD;
|
||||
import static net.sf.briar.api.messaging.Rating.UNRATED;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
|
||||
import java.io.File;
|
||||
@@ -23,19 +23,20 @@ import net.sf.briar.BriarTestCase;
|
||||
import net.sf.briar.TestDatabaseConfig;
|
||||
import net.sf.briar.TestMessage;
|
||||
import net.sf.briar.TestUtils;
|
||||
import net.sf.briar.api.Author;
|
||||
import net.sf.briar.api.AuthorId;
|
||||
import net.sf.briar.api.ContactId;
|
||||
import net.sf.briar.api.LocalAuthor;
|
||||
import net.sf.briar.api.TransportConfig;
|
||||
import net.sf.briar.api.TransportId;
|
||||
import net.sf.briar.api.TransportProperties;
|
||||
import net.sf.briar.api.clock.SystemClock;
|
||||
import net.sf.briar.api.db.DbException;
|
||||
import net.sf.briar.api.db.GroupMessageHeader;
|
||||
import net.sf.briar.api.messaging.Author;
|
||||
import net.sf.briar.api.messaging.AuthorId;
|
||||
import net.sf.briar.api.messaging.Group;
|
||||
import net.sf.briar.api.messaging.GroupId;
|
||||
import net.sf.briar.api.messaging.Message;
|
||||
import net.sf.briar.api.messaging.MessageId;
|
||||
import net.sf.briar.api.messaging.TransportId;
|
||||
import net.sf.briar.api.transport.Endpoint;
|
||||
import net.sf.briar.api.transport.TemporarySecret;
|
||||
|
||||
@@ -55,6 +56,8 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
private final Group group;
|
||||
private final AuthorId authorId;
|
||||
private final Author author;
|
||||
private final AuthorId localAuthorId;
|
||||
private final LocalAuthor localAuthor;
|
||||
private final MessageId messageId, messageId1;
|
||||
private final String contentType, subject;
|
||||
private final long timestamp;
|
||||
@@ -63,7 +66,6 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
private final Message message, privateMessage;
|
||||
private final TransportId transportId;
|
||||
private final ContactId contactId;
|
||||
private final String contactName;
|
||||
|
||||
public H2DatabaseTest() throws Exception {
|
||||
super();
|
||||
@@ -71,6 +73,9 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
group = new Group(groupId, "Group name", null);
|
||||
authorId = new AuthorId(TestUtils.getRandomId());
|
||||
author = new Author(authorId, "Alice", new byte[60]);
|
||||
localAuthorId = new AuthorId(TestUtils.getRandomId());
|
||||
localAuthor = new LocalAuthor(localAuthorId, "Bob", new byte[60],
|
||||
new byte[60]);
|
||||
messageId = new MessageId(TestUtils.getRandomId());
|
||||
messageId1 = new MessageId(TestUtils.getRandomId());
|
||||
contentType = "text/plain";
|
||||
@@ -85,7 +90,6 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
contentType, subject, timestamp, raw);
|
||||
transportId = new TransportId(TestUtils.getRandomId());
|
||||
contactId = new ContactId(1);
|
||||
contactName = "Alice";
|
||||
}
|
||||
|
||||
@Before
|
||||
@@ -99,7 +103,8 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
Database<Connection> db = open(false);
|
||||
Connection txn = db.startTransaction();
|
||||
assertFalse(db.containsContact(txn, contactId));
|
||||
assertEquals(contactId, db.addContact(txn, contactName));
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
assertTrue(db.containsContact(txn, contactId));
|
||||
assertFalse(db.containsSubscription(txn, groupId));
|
||||
db.addSubscription(txn, group);
|
||||
@@ -145,36 +150,6 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
db.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContactIdsIncrease() throws Exception {
|
||||
ContactId contactId1 = new ContactId(2);
|
||||
ContactId contactId2 = new ContactId(3);
|
||||
ContactId contactId3 = new ContactId(4);
|
||||
Database<Connection> db = open(false);
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Create three contacts, all with the same name
|
||||
assertFalse(db.containsContact(txn, contactId));
|
||||
assertEquals(contactId, db.addContact(txn, contactName));
|
||||
assertTrue(db.containsContact(txn, contactId));
|
||||
assertFalse(db.containsContact(txn, contactId1));
|
||||
assertEquals(contactId1, db.addContact(txn, contactName));
|
||||
assertTrue(db.containsContact(txn, contactId1));
|
||||
assertFalse(db.containsContact(txn, contactId2));
|
||||
assertEquals(contactId2, db.addContact(txn, contactName));
|
||||
assertTrue(db.containsContact(txn, contactId2));
|
||||
// Delete the contact with the highest ID
|
||||
db.removeContact(txn, contactId2);
|
||||
assertFalse(db.containsContact(txn, contactId2));
|
||||
// Add another contact (same name again) - a new ID should be created
|
||||
assertFalse(db.containsContact(txn, contactId3));
|
||||
assertEquals(contactId3, db.addContact(txn, contactName));
|
||||
assertTrue(db.containsContact(txn, contactId3));
|
||||
|
||||
db.commitTransaction(txn);
|
||||
db.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRatings() throws Exception {
|
||||
Database<Connection> db = open(false);
|
||||
@@ -215,7 +190,8 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact and store a private message
|
||||
assertEquals(contactId, db.addContact(txn, contactName));
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
db.addPrivateMessage(txn, privateMessage, contactId);
|
||||
|
||||
// Removing the contact should remove the message
|
||||
@@ -234,7 +210,8 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact and store a private message
|
||||
assertEquals(contactId, db.addContact(txn, contactName));
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
db.addPrivateMessage(txn, privateMessage, contactId);
|
||||
|
||||
// The message has no status yet, so it should not be sendable
|
||||
@@ -262,7 +239,8 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact and store a private message
|
||||
assertEquals(contactId, db.addContact(txn, contactName));
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
db.addPrivateMessage(txn, privateMessage, contactId);
|
||||
db.addStatus(txn, contactId, messageId1, false);
|
||||
|
||||
@@ -290,7 +268,8 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact, subscribe to a group and store a message
|
||||
assertEquals(contactId, db.addContact(txn, contactName));
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
db.addSubscription(txn, group);
|
||||
db.addVisibility(txn, contactId, groupId);
|
||||
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
||||
@@ -328,7 +307,8 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact, subscribe to a group and store a message
|
||||
assertEquals(contactId, db.addContact(txn, contactName));
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
db.addSubscription(txn, group);
|
||||
db.addVisibility(txn, contactId, groupId);
|
||||
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
||||
@@ -365,7 +345,8 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact, subscribe to a group and store a message
|
||||
assertEquals(contactId, db.addContact(txn, contactName));
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
db.addSubscription(txn, group);
|
||||
db.addVisibility(txn, contactId, groupId);
|
||||
db.addGroupMessage(txn, message);
|
||||
@@ -402,7 +383,8 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact, subscribe to a group and store a message
|
||||
assertEquals(contactId, db.addContact(txn, contactName));
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
db.addSubscription(txn, group);
|
||||
db.addVisibility(txn, contactId, groupId);
|
||||
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
||||
@@ -433,7 +415,8 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact, subscribe to a group and store a message
|
||||
assertEquals(contactId, db.addContact(txn, contactName));
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
db.addSubscription(txn, group);
|
||||
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
||||
db.addGroupMessage(txn, message);
|
||||
@@ -465,7 +448,8 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact and some messages to ack
|
||||
assertEquals(contactId, db.addContact(txn, contactName));
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
db.addMessageToAck(txn, contactId, messageId);
|
||||
db.addMessageToAck(txn, contactId, messageId1);
|
||||
|
||||
@@ -490,7 +474,8 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact and receive the same message twice
|
||||
assertEquals(contactId, db.addContact(txn, contactName));
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
db.addMessageToAck(txn, contactId, messageId);
|
||||
db.addMessageToAck(txn, contactId, messageId);
|
||||
|
||||
@@ -515,7 +500,8 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact, subscribe to a group and store a message
|
||||
assertEquals(contactId, db.addContact(txn, contactName));
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
db.addSubscription(txn, group);
|
||||
db.addVisibility(txn, contactId, groupId);
|
||||
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
||||
@@ -752,9 +738,10 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact with a transport
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
TransportProperties p = new TransportProperties(
|
||||
Collections.singletonMap("foo", "bar"));
|
||||
assertEquals(contactId, db.addContact(txn, contactName));
|
||||
db.setRemoteProperties(txn, contactId, transportId, p, 1);
|
||||
assertEquals(Collections.singletonMap(contactId, p),
|
||||
db.getRemoteProperties(txn, transportId));
|
||||
@@ -782,7 +769,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a transport to the database
|
||||
db.addTransport(txn, transportId);
|
||||
db.addTransport(txn, transportId, 123);
|
||||
|
||||
// Set the transport properties
|
||||
TransportProperties p = new TransportProperties();
|
||||
@@ -790,6 +777,8 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
p.put("bar", "bar");
|
||||
db.mergeLocalProperties(txn, transportId, p);
|
||||
assertEquals(p, db.getLocalProperties(txn, transportId));
|
||||
assertEquals(Collections.singletonMap(transportId, p),
|
||||
db.getLocalProperties(txn));
|
||||
|
||||
// Update one of the properties and add another
|
||||
TransportProperties p1 = new TransportProperties();
|
||||
@@ -801,6 +790,8 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
merged.put("bar", "baz");
|
||||
merged.put("bam", "bam");
|
||||
assertEquals(merged, db.getLocalProperties(txn, transportId));
|
||||
assertEquals(Collections.singletonMap(transportId, merged),
|
||||
db.getLocalProperties(txn));
|
||||
|
||||
db.commitTransaction(txn);
|
||||
db.close();
|
||||
@@ -812,7 +803,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a transport to the database
|
||||
db.addTransport(txn, transportId);
|
||||
db.addTransport(txn, transportId, 123);
|
||||
|
||||
// Set the transport config
|
||||
TransportConfig c = new TransportConfig();
|
||||
@@ -841,10 +832,13 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
Database<Connection> db = open(false);
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
|
||||
// Initialise the transport properties with version 1
|
||||
TransportProperties p = new TransportProperties(
|
||||
Collections.singletonMap("foo", "bar"));
|
||||
assertEquals(contactId, db.addContact(txn, contactName));
|
||||
db.setRemoteProperties(txn, contactId, transportId, p, 1);
|
||||
assertEquals(Collections.singletonMap(contactId, p),
|
||||
db.getRemoteProperties(txn, transportId));
|
||||
@@ -876,7 +870,8 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact and subscribe to a group
|
||||
assertEquals(contactId, db.addContact(txn, contactName));
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
db.addSubscription(txn, group);
|
||||
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
||||
|
||||
@@ -893,7 +888,8 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact, subscribe to a group and store a message
|
||||
assertEquals(contactId, db.addContact(txn, contactName));
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
db.addSubscription(txn, group);
|
||||
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
||||
db.addGroupMessage(txn, message);
|
||||
@@ -916,7 +912,8 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact, subscribe to a group and store a message
|
||||
assertEquals(contactId, db.addContact(txn, contactName));
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
db.addSubscription(txn, group);
|
||||
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
||||
db.addGroupMessage(txn, message);
|
||||
@@ -939,7 +936,8 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
|
||||
// Add a contact, subscribe to a group and store a message -
|
||||
// the message is older than the contact's retention time
|
||||
assertEquals(contactId, db.addContact(txn, contactName));
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
db.addSubscription(txn, group);
|
||||
db.addVisibility(txn, contactId, groupId);
|
||||
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
||||
@@ -963,7 +961,8 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact, subscribe to a group and store a message
|
||||
assertEquals(contactId, db.addContact(txn, contactName));
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
db.addSubscription(txn, group);
|
||||
db.addVisibility(txn, contactId, groupId);
|
||||
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
||||
@@ -988,7 +987,8 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact and subscribe to a group
|
||||
assertEquals(contactId, db.addContact(txn, contactName));
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
db.addSubscription(txn, group);
|
||||
db.addVisibility(txn, contactId, groupId);
|
||||
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
||||
@@ -1007,7 +1007,8 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact with a subscription
|
||||
assertEquals(contactId, db.addContact(txn, contactName));
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
||||
|
||||
// There's no local subscription for the group
|
||||
@@ -1024,7 +1025,8 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact, subscribe to a group and store a message
|
||||
assertEquals(contactId, db.addContact(txn, contactName));
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
db.addSubscription(txn, group);
|
||||
db.addGroupMessage(txn, message);
|
||||
db.addStatus(txn, contactId, messageId, false);
|
||||
@@ -1043,7 +1045,8 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact, subscribe to a group and store a message
|
||||
assertEquals(contactId, db.addContact(txn, contactName));
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
db.addSubscription(txn, group);
|
||||
db.addGroupMessage(txn, message);
|
||||
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
||||
@@ -1063,7 +1066,8 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact, subscribe to a group and store a message
|
||||
assertEquals(contactId, db.addContact(txn, contactName));
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
db.addSubscription(txn, group);
|
||||
db.addVisibility(txn, contactId, groupId);
|
||||
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
||||
@@ -1085,7 +1089,8 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact, subscribe to a group and store a message
|
||||
assertEquals(contactId, db.addContact(txn, contactName));
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
db.addSubscription(txn, group);
|
||||
db.addVisibility(txn, contactId, groupId);
|
||||
db.setSubscriptions(txn, contactId, Arrays.asList(group), 1);
|
||||
@@ -1106,13 +1111,17 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact and subscribe to a group
|
||||
assertEquals(contactId, db.addContact(txn, contactName));
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
db.addSubscription(txn, group);
|
||||
|
||||
// The group should not be visible to the contact
|
||||
assertEquals(Collections.emptyList(), db.getVisibility(txn, groupId));
|
||||
|
||||
// Make the group visible to the contact
|
||||
db.addVisibility(txn, contactId, groupId);
|
||||
assertEquals(Arrays.asList(contactId), db.getVisibility(txn, groupId));
|
||||
|
||||
// Make the group invisible again
|
||||
db.removeVisibility(txn, contactId, groupId);
|
||||
assertEquals(Collections.emptyList(), db.getVisibility(txn, groupId));
|
||||
@@ -1198,7 +1207,8 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact and subscribe to a group
|
||||
assertEquals(contactId, db.addContact(txn, contactName));
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
db.addSubscription(txn, group);
|
||||
|
||||
// A message with a private parent should return null
|
||||
@@ -1247,7 +1257,8 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact and subscribe to a group
|
||||
assertEquals(contactId, db.addContact(txn, contactName));
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
db.addSubscription(txn, group);
|
||||
|
||||
// Store a couple of messages
|
||||
@@ -1477,9 +1488,10 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
Database<Connection> db = open(false);
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Subscribe to the groups and add a contact
|
||||
// Add a contact and subscribe to the groups
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
for(Group g : groups) db.addSubscription(txn, g);
|
||||
assertEquals(contactId, db.addContact(txn, contactName));
|
||||
|
||||
// Make the groups visible to the contact
|
||||
Collections.shuffle(groups);
|
||||
@@ -1500,32 +1512,28 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
@Test
|
||||
public void testTemporarySecrets() throws Exception {
|
||||
// Create an endpoint and three consecutive temporary secrets
|
||||
long epoch = 123, clockDiff = 234, latency = 345;
|
||||
long epoch = 123, latency = 234;
|
||||
boolean alice = false;
|
||||
long outgoing1 = 456, centre1 = 567;
|
||||
long outgoing2 = 678, centre2 = 789;
|
||||
long outgoing3 = 890, centre3 = 901;
|
||||
Endpoint ep = new Endpoint(contactId, transportId, epoch, clockDiff,
|
||||
latency, alice);
|
||||
long outgoing1 = 345, centre1 = 456;
|
||||
long outgoing2 = 567, centre2 = 678;
|
||||
long outgoing3 = 789, centre3 = 890;
|
||||
Endpoint ep = new Endpoint(contactId, transportId, epoch, alice);
|
||||
Random random = new Random();
|
||||
byte[] secret1 = new byte[32], bitmap1 = new byte[4];
|
||||
random.nextBytes(secret1);
|
||||
random.nextBytes(bitmap1);
|
||||
TemporarySecret s1 = new TemporarySecret(contactId, transportId, epoch,
|
||||
clockDiff, latency, alice, 0, secret1, outgoing1, centre1,
|
||||
bitmap1);
|
||||
alice, 0, secret1, outgoing1, centre1, bitmap1);
|
||||
byte[] secret2 = new byte[32], bitmap2 = new byte[4];
|
||||
random.nextBytes(secret2);
|
||||
random.nextBytes(bitmap2);
|
||||
TemporarySecret s2 = new TemporarySecret(contactId, transportId, epoch,
|
||||
clockDiff, latency, alice, 1, secret2, outgoing2, centre2,
|
||||
bitmap2);
|
||||
alice, 1, secret2, outgoing2, centre2, bitmap2);
|
||||
byte[] secret3 = new byte[32], bitmap3 = new byte[4];
|
||||
random.nextBytes(secret3);
|
||||
random.nextBytes(bitmap3);
|
||||
TemporarySecret s3 = new TemporarySecret(contactId, transportId, epoch,
|
||||
clockDiff, latency, alice, 2, secret3, outgoing3, centre3,
|
||||
bitmap3);
|
||||
alice, 2, secret3, outgoing3, centre3, bitmap3);
|
||||
|
||||
Database<Connection> db = open(false);
|
||||
Connection txn = db.startTransaction();
|
||||
@@ -1535,8 +1543,9 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
|
||||
// Add the contact, the transport, the endpoint and the first two
|
||||
// secrets (periods 0 and 1)
|
||||
assertEquals(contactId, db.addContact(txn, contactName));
|
||||
db.addTransport(txn, transportId);
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
db.addTransport(txn, transportId, latency);
|
||||
db.addEndpoint(txn, ep);
|
||||
db.addSecrets(txn, Arrays.asList(s1, s2));
|
||||
|
||||
@@ -1548,8 +1557,6 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
assertEquals(contactId, s.getContactId());
|
||||
assertEquals(transportId, s.getTransportId());
|
||||
assertEquals(epoch, s.getEpoch());
|
||||
assertEquals(clockDiff, s.getClockDifference());
|
||||
assertEquals(latency, s.getLatency());
|
||||
assertEquals(alice, s.getAlice());
|
||||
if(s.getPeriod() == 0) {
|
||||
assertArrayEquals(secret1, s.getSecret());
|
||||
@@ -1580,8 +1587,6 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
assertEquals(contactId, s.getContactId());
|
||||
assertEquals(transportId, s.getTransportId());
|
||||
assertEquals(epoch, s.getEpoch());
|
||||
assertEquals(clockDiff, s.getClockDifference());
|
||||
assertEquals(latency, s.getLatency());
|
||||
assertEquals(alice, s.getAlice());
|
||||
if(s.getPeriod() == 1) {
|
||||
assertArrayEquals(secret2, s.getSecret());
|
||||
@@ -1613,24 +1618,23 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
@Test
|
||||
public void testIncrementConnectionCounter() throws Exception {
|
||||
// Create an endpoint and a temporary secret
|
||||
long epoch = 123, clockDiff = 234, latency = 345;
|
||||
long epoch = 123, latency = 234;
|
||||
boolean alice = false;
|
||||
long period = 456, outgoing = 567, centre = 678;
|
||||
Endpoint ep = new Endpoint(contactId, transportId, epoch, clockDiff,
|
||||
latency, alice);
|
||||
long period = 345, outgoing = 456, centre = 567;
|
||||
Endpoint ep = new Endpoint(contactId, transportId, epoch, alice);
|
||||
Random random = new Random();
|
||||
byte[] secret = new byte[32], bitmap = new byte[4];
|
||||
random.nextBytes(secret);
|
||||
TemporarySecret s = new TemporarySecret(contactId, transportId, epoch,
|
||||
clockDiff, latency, alice, period, secret, outgoing, centre,
|
||||
bitmap);
|
||||
alice, period, secret, outgoing, centre, bitmap);
|
||||
|
||||
Database<Connection> db = open(false);
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add the contact, the transport, the endpoint and the temporary secret
|
||||
assertEquals(contactId, db.addContact(txn, contactName));
|
||||
db.addTransport(txn, transportId);
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
db.addTransport(txn, transportId, latency);
|
||||
db.addEndpoint(txn, ep);
|
||||
db.addSecrets(txn, Arrays.asList(s));
|
||||
|
||||
@@ -1669,24 +1673,23 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
@Test
|
||||
public void testSetConnectionWindow() throws Exception {
|
||||
// Create an endpoint and a temporary secret
|
||||
long epoch = 123, clockDiff = 234, latency = 345;
|
||||
long epoch = 123, latency = 234;
|
||||
boolean alice = false;
|
||||
long period = 456, outgoing = 567, centre = 678;
|
||||
Endpoint ep = new Endpoint(contactId, transportId, epoch, clockDiff,
|
||||
latency, alice);
|
||||
long period = 345, outgoing = 456, centre = 567;
|
||||
Endpoint ep = new Endpoint(contactId, transportId, epoch, alice);
|
||||
Random random = new Random();
|
||||
byte[] secret = new byte[32], bitmap = new byte[4];
|
||||
random.nextBytes(secret);
|
||||
TemporarySecret s = new TemporarySecret(contactId, transportId, epoch,
|
||||
clockDiff, latency, alice, period, secret, outgoing, centre,
|
||||
bitmap);
|
||||
alice, period, secret, outgoing, centre, bitmap);
|
||||
|
||||
Database<Connection> db = open(false);
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add the contact, the transport, the endpoint and the temporary secret
|
||||
assertEquals(contactId, db.addContact(txn, contactName));
|
||||
db.addTransport(txn, transportId);
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
db.addTransport(txn, transportId, latency);
|
||||
db.addEndpoint(txn, ep);
|
||||
db.addSecrets(txn, Arrays.asList(s));
|
||||
|
||||
@@ -1739,15 +1742,13 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
@Test
|
||||
public void testContactTransports() throws Exception {
|
||||
// Create some endpoints
|
||||
long epoch1 = 123, clockDiff1 = 234, latency1 = 345;
|
||||
long epoch2 = 456, clockDiff2 = 567, latency2 = 678;
|
||||
long epoch1 = 123, latency1 = 234;
|
||||
long epoch2 = 345, latency2 = 456;
|
||||
boolean alice1 = true, alice2 = false;
|
||||
TransportId transportId1 = new TransportId(TestUtils.getRandomId());
|
||||
TransportId transportId2 = new TransportId(TestUtils.getRandomId());
|
||||
Endpoint ep1 = new Endpoint(contactId, transportId1, epoch1, clockDiff1,
|
||||
latency1, alice1);
|
||||
Endpoint ep2 = new Endpoint(contactId, transportId2, epoch2, clockDiff2,
|
||||
latency2, alice2);
|
||||
Endpoint ep1 = new Endpoint(contactId, transportId1, epoch1, alice1);
|
||||
Endpoint ep2 = new Endpoint(contactId, transportId2, epoch2, alice2);
|
||||
|
||||
Database<Connection> db = open(false);
|
||||
Connection txn = db.startTransaction();
|
||||
@@ -1756,9 +1757,10 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
assertEquals(Collections.emptyList(), db.getEndpoints(txn));
|
||||
|
||||
// Add the contact, the transports and the endpoints
|
||||
assertEquals(contactId, db.addContact(txn, contactName));
|
||||
db.addTransport(txn, transportId1);
|
||||
db.addTransport(txn, transportId2);
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
db.addTransport(txn, transportId1, latency1);
|
||||
db.addTransport(txn, transportId2, latency2);
|
||||
db.addEndpoint(txn, ep1);
|
||||
db.addEndpoint(txn, ep2);
|
||||
|
||||
@@ -1770,14 +1772,10 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
assertEquals(contactId, ep.getContactId());
|
||||
if(ep.getTransportId().equals(transportId1)) {
|
||||
assertEquals(epoch1, ep.getEpoch());
|
||||
assertEquals(clockDiff1, ep.getClockDifference());
|
||||
assertEquals(latency1, ep.getLatency());
|
||||
assertEquals(alice1, ep.getAlice());
|
||||
foundFirst = true;
|
||||
} else if(ep.getTransportId().equals(transportId2)) {
|
||||
assertEquals(epoch2, ep.getEpoch());
|
||||
assertEquals(clockDiff2, ep.getClockDifference());
|
||||
assertEquals(latency2, ep.getLatency());
|
||||
assertEquals(alice2, ep.getAlice());
|
||||
foundSecond = true;
|
||||
} else {
|
||||
|
||||
@@ -2,13 +2,13 @@ package net.sf.briar.messaging;
|
||||
|
||||
import static net.sf.briar.api.messaging.MessagingConstants.MAX_AUTHOR_NAME_LENGTH;
|
||||
import static net.sf.briar.api.messaging.MessagingConstants.MAX_BODY_LENGTH;
|
||||
import static net.sf.briar.api.messaging.MessagingConstants.MAX_CONTENT_TYPE_LENGTH;
|
||||
import static net.sf.briar.api.messaging.MessagingConstants.MAX_GROUP_NAME_LENGTH;
|
||||
import static net.sf.briar.api.messaging.MessagingConstants.MAX_PACKET_LENGTH;
|
||||
import static net.sf.briar.api.messaging.MessagingConstants.MAX_PROPERTIES_PER_TRANSPORT;
|
||||
import static net.sf.briar.api.messaging.MessagingConstants.MAX_PROPERTY_LENGTH;
|
||||
import static net.sf.briar.api.messaging.MessagingConstants.MAX_PUBLIC_KEY_LENGTH;
|
||||
import static net.sf.briar.api.messaging.MessagingConstants.MAX_SIGNATURE_LENGTH;
|
||||
import static net.sf.briar.api.messaging.MessagingConstants.MAX_CONTENT_TYPE_LENGTH;
|
||||
import static net.sf.briar.api.messaging.MessagingConstants.MAX_SUBSCRIPTIONS;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@@ -21,11 +21,13 @@ import java.util.Random;
|
||||
|
||||
import net.sf.briar.BriarTestCase;
|
||||
import net.sf.briar.TestUtils;
|
||||
import net.sf.briar.api.Author;
|
||||
import net.sf.briar.api.AuthorFactory;
|
||||
import net.sf.briar.api.TransportId;
|
||||
import net.sf.briar.api.TransportProperties;
|
||||
import net.sf.briar.api.UniqueId;
|
||||
import net.sf.briar.api.crypto.CryptoComponent;
|
||||
import net.sf.briar.api.messaging.Ack;
|
||||
import net.sf.briar.api.messaging.Author;
|
||||
import net.sf.briar.api.messaging.AuthorFactory;
|
||||
import net.sf.briar.api.messaging.Group;
|
||||
import net.sf.briar.api.messaging.GroupFactory;
|
||||
import net.sf.briar.api.messaging.Message;
|
||||
@@ -35,9 +37,7 @@ import net.sf.briar.api.messaging.Offer;
|
||||
import net.sf.briar.api.messaging.PacketWriter;
|
||||
import net.sf.briar.api.messaging.PacketWriterFactory;
|
||||
import net.sf.briar.api.messaging.SubscriptionUpdate;
|
||||
import net.sf.briar.api.messaging.TransportId;
|
||||
import net.sf.briar.api.messaging.TransportUpdate;
|
||||
import net.sf.briar.api.messaging.UniqueId;
|
||||
import net.sf.briar.clock.ClockModule;
|
||||
import net.sf.briar.crypto.CryptoModule;
|
||||
import net.sf.briar.serial.SerialModule;
|
||||
|
||||
@@ -17,7 +17,6 @@ import net.sf.briar.api.serial.ReaderFactory;
|
||||
import net.sf.briar.api.serial.SerialComponent;
|
||||
import net.sf.briar.api.serial.Writer;
|
||||
import net.sf.briar.api.serial.WriterFactory;
|
||||
import net.sf.briar.messaging.PacketReaderImpl;
|
||||
import net.sf.briar.serial.SerialModule;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -11,8 +11,6 @@ import net.sf.briar.api.serial.SerialComponent;
|
||||
import net.sf.briar.api.serial.WriterFactory;
|
||||
import net.sf.briar.clock.ClockModule;
|
||||
import net.sf.briar.crypto.CryptoModule;
|
||||
import net.sf.briar.messaging.MessagingModule;
|
||||
import net.sf.briar.messaging.PacketWriterImpl;
|
||||
import net.sf.briar.serial.SerialModule;
|
||||
import net.sf.briar.util.StringUtils;
|
||||
|
||||
|
||||
@@ -14,13 +14,13 @@ import java.util.concurrent.Executors;
|
||||
import net.sf.briar.BriarTestCase;
|
||||
import net.sf.briar.TestUtils;
|
||||
import net.sf.briar.api.ContactId;
|
||||
import net.sf.briar.api.TransportId;
|
||||
import net.sf.briar.api.UniqueId;
|
||||
import net.sf.briar.api.db.DatabaseComponent;
|
||||
import net.sf.briar.api.db.DatabaseExecutor;
|
||||
import net.sf.briar.api.messaging.Ack;
|
||||
import net.sf.briar.api.messaging.MessageId;
|
||||
import net.sf.briar.api.messaging.PacketWriterFactory;
|
||||
import net.sf.briar.api.messaging.TransportId;
|
||||
import net.sf.briar.api.messaging.UniqueId;
|
||||
import net.sf.briar.api.transport.ConnectionContext;
|
||||
import net.sf.briar.api.transport.ConnectionRegistry;
|
||||
import net.sf.briar.api.transport.ConnectionWriterFactory;
|
||||
|
||||
@@ -10,7 +10,11 @@ import java.util.Random;
|
||||
import net.sf.briar.BriarTestCase;
|
||||
import net.sf.briar.TestDatabaseModule;
|
||||
import net.sf.briar.TestUtils;
|
||||
import net.sf.briar.api.Author;
|
||||
import net.sf.briar.api.AuthorId;
|
||||
import net.sf.briar.api.ContactId;
|
||||
import net.sf.briar.api.LocalAuthor;
|
||||
import net.sf.briar.api.TransportId;
|
||||
import net.sf.briar.api.crypto.KeyManager;
|
||||
import net.sf.briar.api.db.DatabaseComponent;
|
||||
import net.sf.briar.api.db.event.DatabaseEvent;
|
||||
@@ -21,7 +25,6 @@ import net.sf.briar.api.messaging.MessageFactory;
|
||||
import net.sf.briar.api.messaging.MessageVerifier;
|
||||
import net.sf.briar.api.messaging.PacketReaderFactory;
|
||||
import net.sf.briar.api.messaging.PacketWriterFactory;
|
||||
import net.sf.briar.api.messaging.TransportId;
|
||||
import net.sf.briar.api.transport.ConnectionContext;
|
||||
import net.sf.briar.api.transport.ConnectionReaderFactory;
|
||||
import net.sf.briar.api.transport.ConnectionRecogniser;
|
||||
@@ -103,12 +106,18 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase {
|
||||
// Start Alice's key manager
|
||||
KeyManager km = alice.getInstance(KeyManager.class);
|
||||
km.start();
|
||||
// Add a local pseudonym for Alice
|
||||
AuthorId aliceId = new AuthorId(TestUtils.getRandomId());
|
||||
LocalAuthor aliceAuthor = new LocalAuthor(aliceId, "Alice",
|
||||
new byte[60], new byte[60]);
|
||||
db.addLocalAuthor(aliceAuthor);
|
||||
// Add Bob as a contact
|
||||
ContactId contactId = db.addContact("Bob");
|
||||
Endpoint ep = new Endpoint(contactId, transportId, epoch,
|
||||
CLOCK_DIFFERENCE, LATENCY, true);
|
||||
AuthorId bobId = new AuthorId(TestUtils.getRandomId());
|
||||
Author bobAuthor = new Author(bobId, "Bob", new byte[60]);
|
||||
ContactId contactId = db.addContact(bobAuthor, aliceId);
|
||||
// Add the transport and the endpoint
|
||||
db.addTransport(transportId);
|
||||
db.addTransport(transportId, LATENCY);
|
||||
Endpoint ep = new Endpoint(contactId, transportId, epoch, true);
|
||||
db.addEndpoint(ep);
|
||||
km.endpointAdded(ep, initialSecret.clone());
|
||||
// Send Bob a message
|
||||
@@ -151,12 +160,18 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase {
|
||||
// Start Bob's key manager
|
||||
KeyManager km = bob.getInstance(KeyManager.class);
|
||||
km.start();
|
||||
// Add a local pseudonym for Bob
|
||||
AuthorId bobId = new AuthorId(TestUtils.getRandomId());
|
||||
LocalAuthor bobAuthor = new LocalAuthor(bobId, "Bob", new byte[60],
|
||||
new byte[60]);
|
||||
db.addLocalAuthor(bobAuthor);
|
||||
// Add Alice as a contact
|
||||
ContactId contactId = db.addContact("Alice");
|
||||
Endpoint ep = new Endpoint(contactId, transportId, epoch,
|
||||
CLOCK_DIFFERENCE, LATENCY, false);
|
||||
AuthorId aliceId = new AuthorId(TestUtils.getRandomId());
|
||||
Author aliceAuthor = new Author(aliceId, "Alice", new byte[60]);
|
||||
ContactId contactId = db.addContact(aliceAuthor, bobId);
|
||||
// Add the transport and the endpoint
|
||||
db.addTransport(transportId);
|
||||
db.addTransport(transportId, LATENCY);
|
||||
Endpoint ep = new Endpoint(contactId, transportId, epoch, false);
|
||||
db.addEndpoint(ep);
|
||||
km.endpointAdded(ep, initialSecret.clone());
|
||||
// Set up a database listener
|
||||
|
||||
@@ -6,9 +6,9 @@ import java.util.concurrent.Executors;
|
||||
|
||||
import net.sf.briar.BriarTestCase;
|
||||
import net.sf.briar.TestUtils;
|
||||
import net.sf.briar.api.TransportId;
|
||||
import net.sf.briar.api.android.AndroidExecutor;
|
||||
import net.sf.briar.api.db.DatabaseComponent;
|
||||
import net.sf.briar.api.messaging.TransportId;
|
||||
import net.sf.briar.api.plugins.duplex.DuplexPlugin;
|
||||
import net.sf.briar.api.plugins.duplex.DuplexPluginCallback;
|
||||
import net.sf.briar.api.plugins.duplex.DuplexPluginConfig;
|
||||
@@ -46,23 +46,26 @@ public class PluginManagerImplTest extends BriarTestCase {
|
||||
context.mock(SimplexPluginFactory.class);
|
||||
final SimplexPlugin simplexPlugin = context.mock(SimplexPlugin.class);
|
||||
final TransportId simplexId = new TransportId(TestUtils.getRandomId());
|
||||
final long simplexLatency = 12345;
|
||||
final SimplexPluginFactory simplexFailFactory =
|
||||
context.mock(SimplexPluginFactory.class, "simplexFailFactory");
|
||||
final SimplexPlugin simplexFailPlugin =
|
||||
context.mock(SimplexPlugin.class, "simplexFailPlugin");
|
||||
final TransportId simplexFailId =
|
||||
new TransportId(TestUtils.getRandomId());
|
||||
final long simplexFailLatency = 23456;
|
||||
// Two duplex plugin factories: one creates a plugin, the other fails
|
||||
final DuplexPluginFactory duplexFactory =
|
||||
context.mock(DuplexPluginFactory.class);
|
||||
final DuplexPlugin duplexPlugin = context.mock(DuplexPlugin.class);
|
||||
final TransportId duplexId = new TransportId(TestUtils.getRandomId());
|
||||
final long duplexLatency = 34567;
|
||||
final DuplexPluginFactory duplexFailFactory =
|
||||
context.mock(DuplexPluginFactory.class, "duplexFailFactory");
|
||||
final TransportId duplexFailId =
|
||||
new TransportId(TestUtils.getRandomId());
|
||||
context.checking(new Expectations() {{
|
||||
// Start the simplex plugins
|
||||
// First simplex plugin
|
||||
oneOf(simplexPluginConfig).getFactories();
|
||||
will(returnValue(Arrays.asList(simplexFactory,
|
||||
simplexFailFactory)));
|
||||
@@ -71,20 +74,25 @@ public class PluginManagerImplTest extends BriarTestCase {
|
||||
oneOf(simplexFactory).createPlugin(with(any(
|
||||
SimplexPluginCallback.class)));
|
||||
will(returnValue(simplexPlugin)); // Created
|
||||
oneOf(db).addTransport(simplexId);
|
||||
oneOf(simplexPlugin).getMaxLatency();
|
||||
will(returnValue(simplexLatency));
|
||||
oneOf(db).addTransport(simplexId, simplexLatency);
|
||||
will(returnValue(true));
|
||||
oneOf(simplexPlugin).start();
|
||||
will(returnValue(true)); // Started
|
||||
// Second simplex plugin
|
||||
oneOf(simplexFailFactory).getId();
|
||||
will(returnValue(simplexFailId));
|
||||
oneOf(simplexFailFactory).createPlugin(with(any(
|
||||
SimplexPluginCallback.class)));
|
||||
will(returnValue(simplexFailPlugin)); // Created
|
||||
oneOf(db).addTransport(simplexFailId);
|
||||
oneOf(simplexFailPlugin).getMaxLatency();
|
||||
will(returnValue(simplexFailLatency));
|
||||
oneOf(db).addTransport(simplexFailId, simplexFailLatency);
|
||||
will(returnValue(true));
|
||||
oneOf(simplexFailPlugin).start();
|
||||
will(returnValue(false)); // Failed to start
|
||||
// Start the duplex plugins
|
||||
// First duplex plugin
|
||||
oneOf(duplexPluginConfig).getFactories();
|
||||
will(returnValue(Arrays.asList(duplexFactory, duplexFailFactory)));
|
||||
oneOf(duplexFactory).getId();
|
||||
@@ -92,14 +100,15 @@ public class PluginManagerImplTest extends BriarTestCase {
|
||||
oneOf(duplexFactory).createPlugin(with(any(
|
||||
DuplexPluginCallback.class)));
|
||||
will(returnValue(duplexPlugin)); // Created
|
||||
oneOf(db).addTransport(duplexId);
|
||||
oneOf(duplexPlugin).getMaxLatency();
|
||||
will(returnValue(duplexLatency));
|
||||
oneOf(db).addTransport(duplexId, duplexLatency);
|
||||
will(returnValue(true));
|
||||
oneOf(duplexPlugin).start();
|
||||
will(returnValue(true)); // Started
|
||||
// Second duplex plugin
|
||||
oneOf(duplexFailFactory).getId();
|
||||
will(returnValue(duplexFailId));
|
||||
oneOf(db).addTransport(duplexFailId);
|
||||
will(returnValue(true));
|
||||
oneOf(duplexFailFactory).createPlugin(with(any(
|
||||
DuplexPluginCallback.class)));
|
||||
will(returnValue(null)); // Failed to create a plugin
|
||||
|
||||
@@ -6,7 +6,7 @@ import java.util.Collections;
|
||||
import net.sf.briar.BriarTestCase;
|
||||
import net.sf.briar.TestUtils;
|
||||
import net.sf.briar.api.ContactId;
|
||||
import net.sf.briar.api.messaging.TransportId;
|
||||
import net.sf.briar.api.TransportId;
|
||||
import net.sf.briar.api.transport.ConnectionRegistry;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -11,10 +11,10 @@ import javax.crypto.NullCipher;
|
||||
import net.sf.briar.BriarTestCase;
|
||||
import net.sf.briar.TestUtils;
|
||||
import net.sf.briar.api.ContactId;
|
||||
import net.sf.briar.api.TransportId;
|
||||
import net.sf.briar.api.crypto.CryptoComponent;
|
||||
import net.sf.briar.api.crypto.ErasableKey;
|
||||
import net.sf.briar.api.db.DatabaseComponent;
|
||||
import net.sf.briar.api.messaging.TransportId;
|
||||
import net.sf.briar.api.transport.ConnectionContext;
|
||||
import net.sf.briar.api.transport.TemporarySecret;
|
||||
import net.sf.briar.util.ByteUtils;
|
||||
@@ -62,7 +62,7 @@ public class TransportConnectionRecogniserTest extends BriarTestCase {
|
||||
will(new EncodeTagAction());
|
||||
oneOf(tagKey).erase();
|
||||
}});
|
||||
TemporarySecret s = new TemporarySecret(contactId, transportId, 0, 0, 0,
|
||||
TemporarySecret s = new TemporarySecret(contactId, transportId, 123,
|
||||
alice, 0, secret, 0, 0, new byte[4]);
|
||||
TransportConnectionRecogniser recogniser =
|
||||
new TransportConnectionRecogniser(crypto, db, transportId);
|
||||
@@ -108,7 +108,7 @@ public class TransportConnectionRecogniserTest extends BriarTestCase {
|
||||
oneOf(tagKey).erase();
|
||||
// Accept connection again - no expectations
|
||||
}});
|
||||
TemporarySecret s = new TemporarySecret(contactId, transportId, 0, 0, 0,
|
||||
TemporarySecret s = new TemporarySecret(contactId, transportId, 123,
|
||||
alice, 0, secret, 0, 0, new byte[4]);
|
||||
TransportConnectionRecogniser recogniser =
|
||||
new TransportConnectionRecogniser(crypto, db, transportId);
|
||||
|
||||
@@ -13,10 +13,10 @@ import java.util.Random;
|
||||
import net.sf.briar.BriarTestCase;
|
||||
import net.sf.briar.TestUtils;
|
||||
import net.sf.briar.api.ContactId;
|
||||
import net.sf.briar.api.TransportId;
|
||||
import net.sf.briar.api.crypto.AuthenticatedCipher;
|
||||
import net.sf.briar.api.crypto.CryptoComponent;
|
||||
import net.sf.briar.api.crypto.ErasableKey;
|
||||
import net.sf.briar.api.messaging.TransportId;
|
||||
import net.sf.briar.api.transport.ConnectionContext;
|
||||
import net.sf.briar.api.transport.ConnectionWriter;
|
||||
import net.sf.briar.api.transport.ConnectionWriterFactory;
|
||||
|
||||
Reference in New Issue
Block a user