mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 11:19:04 +01:00
Store the incoming and outgoing secrets separately.
This commit is contained in:
@@ -85,7 +85,7 @@ public class H2DatabaseTest extends TestCase {
|
||||
private final Map<ContactId, TransportProperties> remoteProperties;
|
||||
private final Collection<Transport> remoteTransports;
|
||||
private final Map<Group, Long> subscriptions;
|
||||
private final byte[] secret;
|
||||
private final byte[] inSecret, outSecret;
|
||||
|
||||
public H2DatabaseTest() throws Exception {
|
||||
super();
|
||||
@@ -122,7 +122,11 @@ public class H2DatabaseTest extends TestCase {
|
||||
properties);
|
||||
remoteTransports = Collections.singletonList(remoteTransport);
|
||||
subscriptions = Collections.singletonMap(group, 0L);
|
||||
secret = new byte[123];
|
||||
Random r = new Random();
|
||||
inSecret = new byte[123];
|
||||
r.nextBytes(inSecret);
|
||||
outSecret = new byte[123];
|
||||
r.nextBytes(outSecret);
|
||||
}
|
||||
|
||||
@Before
|
||||
@@ -136,7 +140,8 @@ public class H2DatabaseTest extends TestCase {
|
||||
Database<Connection> db = open(false);
|
||||
Connection txn = db.startTransaction();
|
||||
assertFalse(db.containsContact(txn, contactId));
|
||||
assertEquals(contactId, db.addContact(txn, secret));
|
||||
assertEquals(contactId,
|
||||
db.addContact(txn, inSecret, outSecret));
|
||||
assertTrue(db.containsContact(txn, contactId));
|
||||
assertFalse(db.containsSubscription(txn, groupId));
|
||||
db.addSubscription(txn, group);
|
||||
@@ -192,20 +197,20 @@ public class H2DatabaseTest extends TestCase {
|
||||
|
||||
// Create three contacts
|
||||
assertFalse(db.containsContact(txn, contactId));
|
||||
assertEquals(contactId, db.addContact(txn, secret));
|
||||
assertEquals(contactId, db.addContact(txn, inSecret, outSecret));
|
||||
assertTrue(db.containsContact(txn, contactId));
|
||||
assertFalse(db.containsContact(txn, contactId1));
|
||||
assertEquals(contactId1, db.addContact(txn, secret));
|
||||
assertEquals(contactId1, db.addContact(txn, inSecret, outSecret));
|
||||
assertTrue(db.containsContact(txn, contactId1));
|
||||
assertFalse(db.containsContact(txn, contactId2));
|
||||
assertEquals(contactId2, db.addContact(txn, secret));
|
||||
assertEquals(contactId2, db.addContact(txn, inSecret, outSecret));
|
||||
assertTrue(db.containsContact(txn, contactId2));
|
||||
// Delete the contact with the highest ID
|
||||
db.removeContact(txn, contactId2);
|
||||
assertFalse(db.containsContact(txn, contactId2));
|
||||
// Add another contact - a new ID should be created
|
||||
assertFalse(db.containsContact(txn, contactId3));
|
||||
assertEquals(contactId3, db.addContact(txn, secret));
|
||||
assertEquals(contactId3, db.addContact(txn, inSecret, outSecret));
|
||||
assertTrue(db.containsContact(txn, contactId3));
|
||||
|
||||
db.commitTransaction(txn);
|
||||
@@ -252,7 +257,7 @@ public class H2DatabaseTest extends TestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact and store a private message
|
||||
assertEquals(contactId, db.addContact(txn, secret));
|
||||
assertEquals(contactId, db.addContact(txn, inSecret, outSecret));
|
||||
db.addPrivateMessage(txn, privateMessage, contactId);
|
||||
|
||||
// Removing the contact should remove the message
|
||||
@@ -271,7 +276,7 @@ public class H2DatabaseTest extends TestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact and store a private message
|
||||
assertEquals(contactId, db.addContact(txn, secret));
|
||||
assertEquals(contactId, db.addContact(txn, inSecret, outSecret));
|
||||
db.addPrivateMessage(txn, privateMessage, contactId);
|
||||
|
||||
// The message has no status yet, so it should not be sendable
|
||||
@@ -310,7 +315,7 @@ public class H2DatabaseTest extends TestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact and store a private message
|
||||
assertEquals(contactId, db.addContact(txn, secret));
|
||||
assertEquals(contactId, db.addContact(txn, inSecret, outSecret));
|
||||
db.addPrivateMessage(txn, privateMessage, contactId);
|
||||
db.setStatus(txn, contactId, privateMessageId, Status.NEW);
|
||||
|
||||
@@ -338,7 +343,7 @@ public class H2DatabaseTest extends TestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact, subscribe to a group and store a message
|
||||
assertEquals(contactId, db.addContact(txn, secret));
|
||||
assertEquals(contactId, db.addContact(txn, inSecret, outSecret));
|
||||
db.addSubscription(txn, group);
|
||||
db.setVisibility(txn, groupId, Collections.singletonList(contactId));
|
||||
db.setSubscriptions(txn, contactId, subscriptions, 1);
|
||||
@@ -376,7 +381,7 @@ public class H2DatabaseTest extends TestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact, subscribe to a group and store a message
|
||||
assertEquals(contactId, db.addContact(txn, secret));
|
||||
assertEquals(contactId, db.addContact(txn, inSecret, outSecret));
|
||||
db.addSubscription(txn, group);
|
||||
db.setVisibility(txn, groupId, Collections.singletonList(contactId));
|
||||
db.setSubscriptions(txn, contactId, subscriptions, 1);
|
||||
@@ -418,7 +423,7 @@ public class H2DatabaseTest extends TestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact, subscribe to a group and store a message
|
||||
assertEquals(contactId, db.addContact(txn, secret));
|
||||
assertEquals(contactId, db.addContact(txn, inSecret, outSecret));
|
||||
db.addSubscription(txn, group);
|
||||
db.setVisibility(txn, groupId, Collections.singletonList(contactId));
|
||||
db.addGroupMessage(txn, message);
|
||||
@@ -457,7 +462,7 @@ public class H2DatabaseTest extends TestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact, subscribe to a group and store a message
|
||||
assertEquals(contactId, db.addContact(txn, secret));
|
||||
assertEquals(contactId, db.addContact(txn, inSecret, outSecret));
|
||||
db.addSubscription(txn, group);
|
||||
db.setVisibility(txn, groupId, Collections.singletonList(contactId));
|
||||
db.addGroupMessage(txn, message);
|
||||
@@ -492,7 +497,7 @@ public class H2DatabaseTest extends TestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact, subscribe to a group and store a message
|
||||
assertEquals(contactId, db.addContact(txn, secret));
|
||||
assertEquals(contactId, db.addContact(txn, inSecret, outSecret));
|
||||
db.addSubscription(txn, group);
|
||||
db.setVisibility(txn, groupId, Collections.singletonList(contactId));
|
||||
db.setSubscriptions(txn, contactId, subscriptions, 1);
|
||||
@@ -523,7 +528,7 @@ public class H2DatabaseTest extends TestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact, subscribe to a group and store a message
|
||||
assertEquals(contactId, db.addContact(txn, secret));
|
||||
assertEquals(contactId, db.addContact(txn, inSecret, outSecret));
|
||||
db.addSubscription(txn, group);
|
||||
db.setSubscriptions(txn, contactId, subscriptions, 1);
|
||||
db.addGroupMessage(txn, message);
|
||||
@@ -556,7 +561,7 @@ public class H2DatabaseTest extends TestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact and some batches to ack
|
||||
assertEquals(contactId, db.addContact(txn, secret));
|
||||
assertEquals(contactId, db.addContact(txn, inSecret, outSecret));
|
||||
db.addBatchToAck(txn, contactId, batchId);
|
||||
db.addBatchToAck(txn, contactId, batchId1);
|
||||
|
||||
@@ -583,7 +588,7 @@ public class H2DatabaseTest extends TestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact and receive the same batch twice
|
||||
assertEquals(contactId, db.addContact(txn, secret));
|
||||
assertEquals(contactId, db.addContact(txn, inSecret, outSecret));
|
||||
db.addBatchToAck(txn, contactId, batchId);
|
||||
db.addBatchToAck(txn, contactId, batchId);
|
||||
|
||||
@@ -609,7 +614,7 @@ public class H2DatabaseTest extends TestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact, subscribe to a group and store a message
|
||||
assertEquals(contactId, db.addContact(txn, secret));
|
||||
assertEquals(contactId, db.addContact(txn, inSecret, outSecret));
|
||||
db.addSubscription(txn, group);
|
||||
db.addGroupMessage(txn, message);
|
||||
|
||||
@@ -634,8 +639,8 @@ public class H2DatabaseTest extends TestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add two contacts, subscribe to a group and store a message
|
||||
assertEquals(contactId, db.addContact(txn, secret));
|
||||
ContactId contactId1 = db.addContact(txn, secret);
|
||||
assertEquals(contactId, db.addContact(txn, inSecret, outSecret));
|
||||
ContactId contactId1 = db.addContact(txn, inSecret, outSecret);
|
||||
db.addSubscription(txn, group);
|
||||
db.addGroupMessage(txn, message);
|
||||
|
||||
@@ -657,7 +662,7 @@ public class H2DatabaseTest extends TestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact, subscribe to a group and store a message
|
||||
assertEquals(contactId, db.addContact(txn, secret));
|
||||
assertEquals(contactId, db.addContact(txn, inSecret, outSecret));
|
||||
db.addSubscription(txn, group);
|
||||
db.setVisibility(txn, groupId, Collections.singletonList(contactId));
|
||||
db.setSubscriptions(txn, contactId, subscriptions, 1);
|
||||
@@ -696,7 +701,7 @@ public class H2DatabaseTest extends TestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact, subscribe to a group and store a message
|
||||
assertEquals(contactId, db.addContact(txn, secret));
|
||||
assertEquals(contactId, db.addContact(txn, inSecret, outSecret));
|
||||
db.addSubscription(txn, group);
|
||||
db.setVisibility(txn, groupId, Collections.singletonList(contactId));
|
||||
db.setSubscriptions(txn, contactId, subscriptions, 1);
|
||||
@@ -741,7 +746,7 @@ public class H2DatabaseTest extends TestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact
|
||||
assertEquals(contactId, db.addContact(txn, secret));
|
||||
assertEquals(contactId, db.addContact(txn, inSecret, outSecret));
|
||||
|
||||
// Add some outstanding batches, a few ms apart
|
||||
for(int i = 0; i < ids.length; i++) {
|
||||
@@ -781,7 +786,7 @@ public class H2DatabaseTest extends TestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact
|
||||
assertEquals(contactId, db.addContact(txn, secret));
|
||||
assertEquals(contactId, db.addContact(txn, inSecret, outSecret));
|
||||
|
||||
// Add some outstanding batches, a few ms apart
|
||||
for(int i = 0; i < ids.length; i++) {
|
||||
@@ -1001,7 +1006,7 @@ public class H2DatabaseTest extends TestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact with a transport
|
||||
assertEquals(contactId, db.addContact(txn, secret));
|
||||
assertEquals(contactId, db.addContact(txn, inSecret, outSecret));
|
||||
db.setTransports(txn, contactId, remoteTransports, 1);
|
||||
assertEquals(remoteProperties,
|
||||
db.getRemoteProperties(txn, transportId));
|
||||
@@ -1094,7 +1099,7 @@ public class H2DatabaseTest extends TestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact with a transport
|
||||
assertEquals(contactId, db.addContact(txn, secret));
|
||||
assertEquals(contactId, db.addContact(txn, inSecret, outSecret));
|
||||
db.setTransports(txn, contactId, remoteTransports, 1);
|
||||
assertEquals(remoteProperties,
|
||||
db.getRemoteProperties(txn, transportId));
|
||||
@@ -1138,7 +1143,7 @@ public class H2DatabaseTest extends TestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact with some subscriptions
|
||||
assertEquals(contactId, db.addContact(txn, secret));
|
||||
assertEquals(contactId, db.addContact(txn, inSecret, outSecret));
|
||||
db.setSubscriptions(txn, contactId, subscriptions, 1);
|
||||
assertEquals(Collections.singletonList(group),
|
||||
db.getSubscriptions(txn, contactId));
|
||||
@@ -1163,7 +1168,7 @@ public class H2DatabaseTest extends TestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact with some subscriptions
|
||||
assertEquals(contactId, db.addContact(txn, secret));
|
||||
assertEquals(contactId, db.addContact(txn, inSecret, outSecret));
|
||||
db.setSubscriptions(txn, contactId, subscriptions, 2);
|
||||
assertEquals(Collections.singletonList(group),
|
||||
db.getSubscriptions(txn, contactId));
|
||||
@@ -1187,7 +1192,7 @@ public class H2DatabaseTest extends TestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact and subscribe to a group
|
||||
assertEquals(contactId, db.addContact(txn, secret));
|
||||
assertEquals(contactId, db.addContact(txn, inSecret, outSecret));
|
||||
db.addSubscription(txn, group);
|
||||
db.setSubscriptions(txn, contactId, subscriptions, 1);
|
||||
|
||||
@@ -1205,7 +1210,7 @@ public class H2DatabaseTest extends TestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact, subscribe to a group and store a message
|
||||
assertEquals(contactId, db.addContact(txn, secret));
|
||||
assertEquals(contactId, db.addContact(txn, inSecret, outSecret));
|
||||
db.addSubscription(txn, group);
|
||||
db.setSubscriptions(txn, contactId, subscriptions, 1);
|
||||
db.addGroupMessage(txn, message);
|
||||
@@ -1228,7 +1233,7 @@ public class H2DatabaseTest extends TestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact, subscribe to a group and store a message
|
||||
assertEquals(contactId, db.addContact(txn, secret));
|
||||
assertEquals(contactId, db.addContact(txn, inSecret, outSecret));
|
||||
db.addSubscription(txn, group);
|
||||
db.setSubscriptions(txn, contactId, subscriptions, 1);
|
||||
db.addGroupMessage(txn, message);
|
||||
@@ -1251,7 +1256,7 @@ public class H2DatabaseTest extends TestCase {
|
||||
|
||||
// Add a contact, subscribe to a group and store a message -
|
||||
// the message is older than the contact's subscription
|
||||
assertEquals(contactId, db.addContact(txn, secret));
|
||||
assertEquals(contactId, db.addContact(txn, inSecret, outSecret));
|
||||
db.addSubscription(txn, group);
|
||||
db.setVisibility(txn, groupId, Collections.singletonList(contactId));
|
||||
Map<Group, Long> subs = Collections.singletonMap(group, timestamp + 1);
|
||||
@@ -1275,7 +1280,7 @@ public class H2DatabaseTest extends TestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact, subscribe to a group and store a message
|
||||
assertEquals(contactId, db.addContact(txn, secret));
|
||||
assertEquals(contactId, db.addContact(txn, inSecret, outSecret));
|
||||
db.addSubscription(txn, group);
|
||||
db.setVisibility(txn, groupId, Collections.singletonList(contactId));
|
||||
db.setSubscriptions(txn, contactId, subscriptions, 1);
|
||||
@@ -1300,7 +1305,7 @@ public class H2DatabaseTest extends TestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact and subscribe to a group
|
||||
assertEquals(contactId, db.addContact(txn, secret));
|
||||
assertEquals(contactId, db.addContact(txn, inSecret, outSecret));
|
||||
db.addSubscription(txn, group);
|
||||
db.setVisibility(txn, groupId, Collections.singletonList(contactId));
|
||||
db.setSubscriptions(txn, contactId, subscriptions, 1);
|
||||
@@ -1319,7 +1324,7 @@ public class H2DatabaseTest extends TestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact with a subscription
|
||||
assertEquals(contactId, db.addContact(txn, secret));
|
||||
assertEquals(contactId, db.addContact(txn, inSecret, outSecret));
|
||||
db.setSubscriptions(txn, contactId, subscriptions, 1);
|
||||
|
||||
// There's no local subscription for the group
|
||||
@@ -1336,7 +1341,7 @@ public class H2DatabaseTest extends TestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact, subscribe to a group and store a message
|
||||
assertEquals(contactId, db.addContact(txn, secret));
|
||||
assertEquals(contactId, db.addContact(txn, inSecret, outSecret));
|
||||
db.addSubscription(txn, group);
|
||||
db.addGroupMessage(txn, message);
|
||||
db.setStatus(txn, contactId, messageId, Status.NEW);
|
||||
@@ -1355,7 +1360,7 @@ public class H2DatabaseTest extends TestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact, subscribe to a group and store a message
|
||||
assertEquals(contactId, db.addContact(txn, secret));
|
||||
assertEquals(contactId, db.addContact(txn, inSecret, outSecret));
|
||||
db.addSubscription(txn, group);
|
||||
db.addGroupMessage(txn, message);
|
||||
db.setSubscriptions(txn, contactId, subscriptions, 1);
|
||||
@@ -1375,7 +1380,7 @@ public class H2DatabaseTest extends TestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact, subscribe to a group and store a message
|
||||
assertEquals(contactId, db.addContact(txn, secret));
|
||||
assertEquals(contactId, db.addContact(txn, inSecret, outSecret));
|
||||
db.addSubscription(txn, group);
|
||||
db.setVisibility(txn, groupId, Collections.singletonList(contactId));
|
||||
db.setSubscriptions(txn, contactId, subscriptions, 1);
|
||||
@@ -1397,7 +1402,7 @@ public class H2DatabaseTest extends TestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact, subscribe to a group and store a message
|
||||
assertEquals(contactId, db.addContact(txn, secret));
|
||||
assertEquals(contactId, db.addContact(txn, inSecret, outSecret));
|
||||
db.addSubscription(txn, group);
|
||||
db.setVisibility(txn, groupId, Collections.singletonList(contactId));
|
||||
db.setSubscriptions(txn, contactId, subscriptions, 1);
|
||||
@@ -1418,7 +1423,7 @@ public class H2DatabaseTest extends TestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact and subscribe to a group
|
||||
assertEquals(contactId, db.addContact(txn, secret));
|
||||
assertEquals(contactId, db.addContact(txn, inSecret, outSecret));
|
||||
db.addSubscription(txn, group);
|
||||
// The group should not be visible to the contact
|
||||
assertEquals(Collections.emptyList(), db.getVisibility(txn, groupId));
|
||||
@@ -1441,7 +1446,7 @@ public class H2DatabaseTest extends TestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact
|
||||
assertEquals(contactId, db.addContact(txn, secret));
|
||||
assertEquals(contactId, db.addContact(txn, inSecret, outSecret));
|
||||
// Get the connection window for a new index
|
||||
ConnectionWindow w = db.getConnectionWindow(txn, contactId,
|
||||
remoteIndex);
|
||||
@@ -1460,7 +1465,7 @@ public class H2DatabaseTest extends TestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact
|
||||
assertEquals(contactId, db.addContact(txn, secret));
|
||||
assertEquals(contactId, db.addContact(txn, inSecret, outSecret));
|
||||
// Get the connection window for a new index
|
||||
ConnectionWindow w = db.getConnectionWindow(txn, contactId,
|
||||
remoteIndex);
|
||||
@@ -1564,7 +1569,7 @@ public class H2DatabaseTest extends TestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact and subscribe to a group
|
||||
assertEquals(contactId, db.addContact(txn, secret));
|
||||
assertEquals(contactId, db.addContact(txn, inSecret, outSecret));
|
||||
db.addSubscription(txn, group);
|
||||
|
||||
// A message with a private parent should return null
|
||||
@@ -1613,7 +1618,7 @@ public class H2DatabaseTest extends TestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact
|
||||
assertEquals(contactId, db.addContact(txn, secret));
|
||||
assertEquals(contactId, db.addContact(txn, inSecret, outSecret));
|
||||
|
||||
// The subscription and transport timestamps should be initialised to 0
|
||||
assertEquals(0L, db.getSubscriptionsModified(txn, contactId));
|
||||
@@ -1644,7 +1649,7 @@ public class H2DatabaseTest extends TestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact and subscribe to a group
|
||||
assertEquals(contactId, db.addContact(txn, secret));
|
||||
assertEquals(contactId, db.addContact(txn, inSecret, outSecret));
|
||||
db.addSubscription(txn, group);
|
||||
|
||||
// Store a couple of messages
|
||||
|
||||
Reference in New Issue
Block a user