mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-17 13:19:52 +01:00
Merge branch '617-protocol-versioning' into 'master'
Protocol versioning See merge request !646
This commit is contained in:
@@ -12,18 +12,19 @@ public interface ContactGroupFactory {
|
|||||||
/**
|
/**
|
||||||
* Creates a group that is not shared with any contacts.
|
* Creates a group that is not shared with any contacts.
|
||||||
*/
|
*/
|
||||||
Group createLocalGroup(ClientId clientId);
|
Group createLocalGroup(ClientId clientId, int clientVersion);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a group for the given client to share with the given contact.
|
* Creates a group for the given client to share with the given contact.
|
||||||
*/
|
*/
|
||||||
Group createContactGroup(ClientId clientId, Contact contact);
|
Group createContactGroup(ClientId clientId, int clientVersion,
|
||||||
|
Contact contact);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a group for the given client to share between the given authors
|
* Creates a group for the given client to share between the given authors
|
||||||
* identified by their AuthorIds.
|
* identified by their AuthorIds.
|
||||||
*/
|
*/
|
||||||
Group createContactGroup(ClientId clientId, AuthorId authorId1,
|
Group createContactGroup(ClientId clientId, int clientVersion,
|
||||||
AuthorId authorId2);
|
AuthorId authorId1, AuthorId authorId2);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,11 @@ import org.briarproject.bramble.api.plugin.duplex.DuplexTransportConnection;
|
|||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
public interface ContactExchangeTask {
|
public interface ContactExchangeTask {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The current version of the contact exchange protocol
|
||||||
|
*/
|
||||||
|
int PROTOCOL_VERSION = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Label for deriving Alice's header key from the master secret.
|
* Label for deriving Alice's header key from the master secret.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -41,11 +41,11 @@ public interface CryptoComponent {
|
|||||||
* secret derived for another purpose
|
* secret derived for another purpose
|
||||||
* @param theirPublicKey the public key of the remote party
|
* @param theirPublicKey the public key of the remote party
|
||||||
* @param ourKeyPair the key pair of the local party
|
* @param ourKeyPair the key pair of the local party
|
||||||
* @param alice true if the local party is Alice
|
|
||||||
* @return the shared secret
|
* @return the shared secret
|
||||||
*/
|
*/
|
||||||
SecretKey deriveSharedSecret(String label, PublicKey theirPublicKey,
|
SecretKey deriveSharedSecret(String label, PublicKey theirPublicKey,
|
||||||
KeyPair ourKeyPair, boolean alice) throws GeneralSecurityException;
|
KeyPair ourKeyPair, byte[]... inputs)
|
||||||
|
throws GeneralSecurityException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Signs the given byte[] with the given ECDSA private key.
|
* Signs the given byte[] with the given ECDSA private key.
|
||||||
|
|||||||
@@ -17,6 +17,11 @@ public interface TransportPropertyManager {
|
|||||||
*/
|
*/
|
||||||
ClientId CLIENT_ID = new ClientId("org.briarproject.briar.properties");
|
ClientId CLIENT_ID = new ClientId("org.briarproject.briar.properties");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The current version of the transport property client.
|
||||||
|
*/
|
||||||
|
int CLIENT_VERSION = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stores the given properties received while adding a contact - they will
|
* Stores the given properties received while adding a contact - they will
|
||||||
* be superseded by any properties synced from the contact.
|
* be superseded by any properties synced from the contact.
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
|||||||
public interface GroupFactory {
|
public interface GroupFactory {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a group with the given client ID and descriptor.
|
* Creates a group with the given client ID, client version and descriptor.
|
||||||
*/
|
*/
|
||||||
Group createGroup(ClientId c, byte[] descriptor);
|
Group createGroup(ClientId c, int clientVersion, byte[] descriptor);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,23 +32,25 @@ class ContactGroupFactoryImpl implements ContactGroupFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Group createLocalGroup(ClientId clientId) {
|
public Group createLocalGroup(ClientId clientId, int clientVersion) {
|
||||||
return groupFactory.createGroup(clientId, LOCAL_GROUP_DESCRIPTOR);
|
return groupFactory.createGroup(clientId, clientVersion,
|
||||||
|
LOCAL_GROUP_DESCRIPTOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Group createContactGroup(ClientId clientId, Contact contact) {
|
public Group createContactGroup(ClientId clientId, int clientVersion,
|
||||||
|
Contact contact) {
|
||||||
AuthorId local = contact.getLocalAuthorId();
|
AuthorId local = contact.getLocalAuthorId();
|
||||||
AuthorId remote = contact.getAuthor().getId();
|
AuthorId remote = contact.getAuthor().getId();
|
||||||
byte[] descriptor = createGroupDescriptor(local, remote);
|
byte[] descriptor = createGroupDescriptor(local, remote);
|
||||||
return groupFactory.createGroup(clientId, descriptor);
|
return groupFactory.createGroup(clientId, clientVersion, descriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Group createContactGroup(ClientId clientId, AuthorId authorId1,
|
public Group createContactGroup(ClientId clientId, int clientVersion,
|
||||||
AuthorId authorId2) {
|
AuthorId authorId1, AuthorId authorId2) {
|
||||||
byte[] descriptor = createGroupDescriptor(authorId1, authorId2);
|
byte[] descriptor = createGroupDescriptor(authorId1, authorId2);
|
||||||
return groupFactory.createGroup(clientId, descriptor);
|
return groupFactory.createGroup(clientId, clientVersion, descriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
private byte[] createGroupDescriptor(AuthorId local, AuthorId remote) {
|
private byte[] createGroupDescriptor(AuthorId local, AuthorId remote) {
|
||||||
|
|||||||
@@ -142,8 +142,9 @@ class ContactExchangeTaskImpl extends Thread implements ContactExchangeTask {
|
|||||||
|
|
||||||
// Derive the header keys for the transport streams
|
// Derive the header keys for the transport streams
|
||||||
SecretKey aliceHeaderKey = crypto.deriveKey(ALICE_KEY_LABEL,
|
SecretKey aliceHeaderKey = crypto.deriveKey(ALICE_KEY_LABEL,
|
||||||
masterSecret);
|
masterSecret, new byte[] {PROTOCOL_VERSION});
|
||||||
SecretKey bobHeaderKey = crypto.deriveKey(BOB_KEY_LABEL, masterSecret);
|
SecretKey bobHeaderKey = crypto.deriveKey(BOB_KEY_LABEL, masterSecret,
|
||||||
|
new byte[] {PROTOCOL_VERSION});
|
||||||
|
|
||||||
// Create the readers
|
// Create the readers
|
||||||
InputStream streamReader =
|
InputStream streamReader =
|
||||||
@@ -157,8 +158,10 @@ class ContactExchangeTaskImpl extends Thread implements ContactExchangeTask {
|
|||||||
BdfWriter w = bdfWriterFactory.createWriter(streamWriter);
|
BdfWriter w = bdfWriterFactory.createWriter(streamWriter);
|
||||||
|
|
||||||
// Derive the nonces to be signed
|
// Derive the nonces to be signed
|
||||||
byte[] aliceNonce = crypto.mac(ALICE_NONCE_LABEL, masterSecret);
|
byte[] aliceNonce = crypto.mac(ALICE_NONCE_LABEL, masterSecret,
|
||||||
byte[] bobNonce = crypto.mac(BOB_NONCE_LABEL, masterSecret);
|
new byte[] {PROTOCOL_VERSION});
|
||||||
|
byte[] bobNonce = crypto.mac(BOB_NONCE_LABEL, masterSecret,
|
||||||
|
new byte[] {PROTOCOL_VERSION});
|
||||||
|
|
||||||
// Exchange pseudonyms, signed nonces, and timestamps
|
// Exchange pseudonyms, signed nonces, and timestamps
|
||||||
long localTimestamp = clock.currentTimeMillis();
|
long localTimestamp = clock.currentTimeMillis();
|
||||||
@@ -197,8 +200,8 @@ class ContactExchangeTaskImpl extends Thread implements ContactExchangeTask {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// Add the contact
|
// Add the contact
|
||||||
ContactId contactId = addContact(remoteAuthor, masterSecret,
|
ContactId contactId = addContact(remoteAuthor, timestamp,
|
||||||
timestamp, alice, remoteProperties);
|
remoteProperties);
|
||||||
// Reuse the connection as a transport connection
|
// Reuse the connection as a transport connection
|
||||||
connectionManager.manageOutgoingConnection(contactId, transportId,
|
connectionManager.manageOutgoingConnection(contactId, transportId,
|
||||||
conn);
|
conn);
|
||||||
@@ -295,15 +298,15 @@ class ContactExchangeTaskImpl extends Thread implements ContactExchangeTask {
|
|||||||
return remote;
|
return remote;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ContactId addContact(Author remoteAuthor, SecretKey master,
|
private ContactId addContact(Author remoteAuthor, long timestamp,
|
||||||
long timestamp, boolean alice,
|
|
||||||
Map<TransportId, TransportProperties> remoteProperties)
|
Map<TransportId, TransportProperties> remoteProperties)
|
||||||
throws DbException {
|
throws DbException {
|
||||||
ContactId contactId;
|
ContactId contactId;
|
||||||
Transaction txn = db.startTransaction(false);
|
Transaction txn = db.startTransaction(false);
|
||||||
try {
|
try {
|
||||||
contactId = contactManager.addContact(txn, remoteAuthor,
|
contactId = contactManager.addContact(txn, remoteAuthor,
|
||||||
localAuthor.getId(), master, timestamp, alice, true, true);
|
localAuthor.getId(), masterSecret, timestamp, alice,
|
||||||
|
true, true);
|
||||||
transportPropertyManager.addRemoteProperties(txn, contactId,
|
transportPropertyManager.addRemoteProperties(txn, contactId,
|
||||||
remoteProperties);
|
remoteProperties);
|
||||||
db.commitTransaction(txn);
|
db.commitTransaction(txn);
|
||||||
|
|||||||
@@ -227,18 +227,15 @@ class CryptoComponentImpl implements CryptoComponent {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SecretKey deriveSharedSecret(String label, PublicKey theirPublicKey,
|
public SecretKey deriveSharedSecret(String label, PublicKey theirPublicKey,
|
||||||
KeyPair ourKeyPair, boolean alice) throws GeneralSecurityException {
|
KeyPair ourKeyPair, byte[]... inputs)
|
||||||
|
throws GeneralSecurityException {
|
||||||
PrivateKey ourPriv = ourKeyPair.getPrivate();
|
PrivateKey ourPriv = ourKeyPair.getPrivate();
|
||||||
byte[] raw = performRawKeyAgreement(ourPriv, theirPublicKey);
|
byte[][] hashInputs = new byte[inputs.length + 1][];
|
||||||
byte[] alicePub, bobPub;
|
hashInputs[0] = performRawKeyAgreement(ourPriv, theirPublicKey);
|
||||||
if (alice) {
|
System.arraycopy(inputs, 0, hashInputs, 1, inputs.length);
|
||||||
alicePub = ourKeyPair.getPublic().getEncoded();
|
byte[] hash = hash(label, hashInputs);
|
||||||
bobPub = theirPublicKey.getEncoded();
|
if (hash.length != SecretKey.LENGTH) throw new IllegalStateException();
|
||||||
} else {
|
return new SecretKey(hash);
|
||||||
alicePub = theirPublicKey.getEncoded();
|
|
||||||
bobPub = ourKeyPair.getPublic().getEncoded();
|
|
||||||
}
|
|
||||||
return new SecretKey(hash(label, raw, alicePub, bobPub));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import java.security.GeneralSecurityException;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import static org.briarproject.bramble.api.keyagreement.KeyAgreementConstants.MASTER_SECRET_LABEL;
|
import static org.briarproject.bramble.api.keyagreement.KeyAgreementConstants.MASTER_SECRET_LABEL;
|
||||||
|
import static org.briarproject.bramble.api.keyagreement.KeyAgreementConstants.PROTOCOL_VERSION;
|
||||||
import static org.briarproject.bramble.api.keyagreement.KeyAgreementConstants.SHARED_SECRET_LABEL;
|
import static org.briarproject.bramble.api.keyagreement.KeyAgreementConstants.SHARED_SECRET_LABEL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -142,8 +143,15 @@ class KeyAgreementProtocol {
|
|||||||
private SecretKey deriveSharedSecret(PublicKey theirPublicKey)
|
private SecretKey deriveSharedSecret(PublicKey theirPublicKey)
|
||||||
throws AbortException {
|
throws AbortException {
|
||||||
try {
|
try {
|
||||||
|
byte[] ourPublicKeyBytes = ourKeyPair.getPublic().getEncoded();
|
||||||
|
byte[] theirPublicKeyBytes = theirPublicKey.getEncoded();
|
||||||
|
byte[][] inputs = {
|
||||||
|
new byte[] {PROTOCOL_VERSION},
|
||||||
|
alice ? ourPublicKeyBytes : theirPublicKeyBytes,
|
||||||
|
alice ? theirPublicKeyBytes : ourPublicKeyBytes
|
||||||
|
};
|
||||||
return crypto.deriveSharedSecret(SHARED_SECRET_LABEL,
|
return crypto.deriveSharedSecret(SHARED_SECRET_LABEL,
|
||||||
theirPublicKey, ourKeyPair, alice);
|
theirPublicKey, ourKeyPair, inputs);
|
||||||
} catch (GeneralSecurityException e) {
|
} catch (GeneralSecurityException e) {
|
||||||
throw new AbortException(e);
|
throw new AbortException(e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,7 +58,8 @@ class TransportPropertyManagerImpl implements TransportPropertyManager,
|
|||||||
this.metadataParser = metadataParser;
|
this.metadataParser = metadataParser;
|
||||||
this.contactGroupFactory = contactGroupFactory;
|
this.contactGroupFactory = contactGroupFactory;
|
||||||
this.clock = clock;
|
this.clock = clock;
|
||||||
localGroup = contactGroupFactory.createLocalGroup(CLIENT_ID);
|
localGroup = contactGroupFactory.createLocalGroup(CLIENT_ID,
|
||||||
|
CLIENT_VERSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -287,7 +288,8 @@ class TransportPropertyManagerImpl implements TransportPropertyManager,
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Group getContactGroup(Contact c) {
|
private Group getContactGroup(Contact c) {
|
||||||
return contactGroupFactory.createContactGroup(CLIENT_ID, c);
|
return contactGroupFactory.createContactGroup(CLIENT_ID,
|
||||||
|
CLIENT_VERSION, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void storeMessage(Transaction txn, GroupId g, TransportId t,
|
private void storeMessage(Transaction txn, GroupId g, TransportId t,
|
||||||
|
|||||||
@@ -6,11 +6,16 @@ import org.briarproject.bramble.api.sync.ClientId;
|
|||||||
import org.briarproject.bramble.api.sync.Group;
|
import org.briarproject.bramble.api.sync.Group;
|
||||||
import org.briarproject.bramble.api.sync.GroupFactory;
|
import org.briarproject.bramble.api.sync.GroupFactory;
|
||||||
import org.briarproject.bramble.api.sync.GroupId;
|
import org.briarproject.bramble.api.sync.GroupId;
|
||||||
|
import org.briarproject.bramble.util.ByteUtils;
|
||||||
import org.briarproject.bramble.util.StringUtils;
|
import org.briarproject.bramble.util.StringUtils;
|
||||||
|
|
||||||
import javax.annotation.concurrent.Immutable;
|
import javax.annotation.concurrent.Immutable;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import static org.briarproject.bramble.api.sync.GroupId.LABEL;
|
||||||
|
import static org.briarproject.bramble.api.sync.SyncConstants.PROTOCOL_VERSION;
|
||||||
|
import static org.briarproject.bramble.util.ByteUtils.INT_32_BYTES;
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
class GroupFactoryImpl implements GroupFactory {
|
class GroupFactoryImpl implements GroupFactory {
|
||||||
@@ -23,9 +28,12 @@ class GroupFactoryImpl implements GroupFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Group createGroup(ClientId c, byte[] descriptor) {
|
public Group createGroup(ClientId c, int clientVersion, byte[] descriptor) {
|
||||||
byte[] hash = crypto.hash(GroupId.LABEL,
|
byte[] clientVersionBytes = new byte[INT_32_BYTES];
|
||||||
StringUtils.toUtf8(c.getString()), descriptor);
|
ByteUtils.writeUint32(clientVersion, clientVersionBytes, 0);
|
||||||
|
byte[] hash = crypto.hash(LABEL, new byte[] {PROTOCOL_VERSION},
|
||||||
|
StringUtils.toUtf8(c.getString()), clientVersionBytes,
|
||||||
|
descriptor);
|
||||||
return new Group(new GroupId(hash), c, descriptor);
|
return new Group(new GroupId(hash), c, descriptor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,8 +12,10 @@ import org.briarproject.bramble.util.ByteUtils;
|
|||||||
import javax.annotation.concurrent.Immutable;
|
import javax.annotation.concurrent.Immutable;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import static org.briarproject.bramble.api.sync.MessageId.LABEL;
|
||||||
import static org.briarproject.bramble.api.sync.SyncConstants.MAX_MESSAGE_BODY_LENGTH;
|
import static org.briarproject.bramble.api.sync.SyncConstants.MAX_MESSAGE_BODY_LENGTH;
|
||||||
import static org.briarproject.bramble.api.sync.SyncConstants.MESSAGE_HEADER_LENGTH;
|
import static org.briarproject.bramble.api.sync.SyncConstants.MESSAGE_HEADER_LENGTH;
|
||||||
|
import static org.briarproject.bramble.api.sync.SyncConstants.PROTOCOL_VERSION;
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
@@ -32,9 +34,9 @@ class MessageFactoryImpl implements MessageFactory {
|
|||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
byte[] timeBytes = new byte[ByteUtils.INT_64_BYTES];
|
byte[] timeBytes = new byte[ByteUtils.INT_64_BYTES];
|
||||||
ByteUtils.writeUint64(timestamp, timeBytes, 0);
|
ByteUtils.writeUint64(timestamp, timeBytes, 0);
|
||||||
byte[] idHash =
|
byte[] hash = crypto.hash(LABEL, new byte[] {PROTOCOL_VERSION},
|
||||||
crypto.hash(MessageId.LABEL, g.getBytes(), timeBytes, body);
|
g.getBytes(), timeBytes, body);
|
||||||
MessageId id = new MessageId(idHash);
|
MessageId id = new MessageId(hash);
|
||||||
byte[] raw = new byte[MESSAGE_HEADER_LENGTH + body.length];
|
byte[] raw = new byte[MESSAGE_HEADER_LENGTH + body.length];
|
||||||
System.arraycopy(g.getBytes(), 0, raw, 0, UniqueId.LENGTH);
|
System.arraycopy(g.getBytes(), 0, raw, 0, UniqueId.LENGTH);
|
||||||
ByteUtils.writeUint64(timestamp, raw, UniqueId.LENGTH);
|
ByteUtils.writeUint64(timestamp, raw, UniqueId.LENGTH);
|
||||||
|
|||||||
@@ -7,7 +7,10 @@ import org.briarproject.bramble.test.BrambleTestCase;
|
|||||||
import org.briarproject.bramble.test.TestSecureRandomProvider;
|
import org.briarproject.bramble.test.TestSecureRandomProvider;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
import static org.briarproject.bramble.api.keyagreement.KeyAgreementConstants.SHARED_SECRET_LABEL;
|
import static org.briarproject.bramble.api.keyagreement.KeyAgreementConstants.SHARED_SECRET_LABEL;
|
||||||
|
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
import static org.junit.Assert.assertArrayEquals;
|
||||||
|
|
||||||
public class KeyAgreementTest extends BrambleTestCase {
|
public class KeyAgreementTest extends BrambleTestCase {
|
||||||
@@ -18,10 +21,14 @@ public class KeyAgreementTest extends BrambleTestCase {
|
|||||||
new CryptoComponentImpl(new TestSecureRandomProvider());
|
new CryptoComponentImpl(new TestSecureRandomProvider());
|
||||||
KeyPair aPair = crypto.generateAgreementKeyPair();
|
KeyPair aPair = crypto.generateAgreementKeyPair();
|
||||||
KeyPair bPair = crypto.generateAgreementKeyPair();
|
KeyPair bPair = crypto.generateAgreementKeyPair();
|
||||||
|
Random random = new Random();
|
||||||
|
byte[][] inputs = new byte[random.nextInt(10) + 1][];
|
||||||
|
for (int i = 0; i < inputs.length; i++)
|
||||||
|
inputs[i] = getRandomBytes(random.nextInt(256));
|
||||||
SecretKey aShared = crypto.deriveSharedSecret(SHARED_SECRET_LABEL,
|
SecretKey aShared = crypto.deriveSharedSecret(SHARED_SECRET_LABEL,
|
||||||
bPair.getPublic(), aPair, true);
|
bPair.getPublic(), aPair, inputs);
|
||||||
SecretKey bShared = crypto.deriveSharedSecret(SHARED_SECRET_LABEL,
|
SecretKey bShared = crypto.deriveSharedSecret(SHARED_SECRET_LABEL,
|
||||||
aPair.getPublic(), bPair, false);
|
aPair.getPublic(), bPair, inputs);
|
||||||
assertArrayEquals(aShared.getBytes(), bShared.getBytes());
|
assertArrayEquals(aShared.getBytes(), bShared.getBytes());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import org.junit.Test;
|
|||||||
|
|
||||||
import static org.briarproject.bramble.api.keyagreement.KeyAgreementConstants.COMMIT_LENGTH;
|
import static org.briarproject.bramble.api.keyagreement.KeyAgreementConstants.COMMIT_LENGTH;
|
||||||
import static org.briarproject.bramble.api.keyagreement.KeyAgreementConstants.MASTER_SECRET_LABEL;
|
import static org.briarproject.bramble.api.keyagreement.KeyAgreementConstants.MASTER_SECRET_LABEL;
|
||||||
|
import static org.briarproject.bramble.api.keyagreement.KeyAgreementConstants.PROTOCOL_VERSION;
|
||||||
import static org.briarproject.bramble.api.keyagreement.KeyAgreementConstants.SHARED_SECRET_LABEL;
|
import static org.briarproject.bramble.api.keyagreement.KeyAgreementConstants.SHARED_SECRET_LABEL;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getSecretKey;
|
import static org.briarproject.bramble.test.TestUtils.getSecretKey;
|
||||||
@@ -90,6 +91,10 @@ public class KeyAgreementProtocolTest extends BrambleTestCase {
|
|||||||
will(returnValue(alicePubKeyBytes));
|
will(returnValue(alicePubKeyBytes));
|
||||||
allowing(crypto).getAgreementKeyParser();
|
allowing(crypto).getAgreementKeyParser();
|
||||||
will(returnValue(keyParser));
|
will(returnValue(keyParser));
|
||||||
|
allowing(alicePubKey).getEncoded();
|
||||||
|
will(returnValue(alicePubKeyBytes));
|
||||||
|
allowing(bobPubKey).getEncoded();
|
||||||
|
will(returnValue(bobPubKeyBytes));
|
||||||
|
|
||||||
// Alice sends her public key
|
// Alice sends her public key
|
||||||
oneOf(transport).sendKey(alicePubKeyBytes);
|
oneOf(transport).sendKey(alicePubKeyBytes);
|
||||||
@@ -108,7 +113,8 @@ public class KeyAgreementProtocolTest extends BrambleTestCase {
|
|||||||
|
|
||||||
// Alice computes shared secret
|
// Alice computes shared secret
|
||||||
oneOf(crypto).deriveSharedSecret(SHARED_SECRET_LABEL, bobPubKey,
|
oneOf(crypto).deriveSharedSecret(SHARED_SECRET_LABEL, bobPubKey,
|
||||||
ourKeyPair, true);
|
ourKeyPair, new byte[] {PROTOCOL_VERSION},
|
||||||
|
alicePubKeyBytes, bobPubKeyBytes);
|
||||||
will(returnValue(sharedSecret));
|
will(returnValue(sharedSecret));
|
||||||
|
|
||||||
// Alice sends her confirmation record
|
// Alice sends her confirmation record
|
||||||
@@ -161,6 +167,10 @@ public class KeyAgreementProtocolTest extends BrambleTestCase {
|
|||||||
will(returnValue(bobPubKeyBytes));
|
will(returnValue(bobPubKeyBytes));
|
||||||
allowing(crypto).getAgreementKeyParser();
|
allowing(crypto).getAgreementKeyParser();
|
||||||
will(returnValue(keyParser));
|
will(returnValue(keyParser));
|
||||||
|
allowing(alicePubKey).getEncoded();
|
||||||
|
will(returnValue(alicePubKeyBytes));
|
||||||
|
allowing(bobPubKey).getEncoded();
|
||||||
|
will(returnValue(bobPubKeyBytes));
|
||||||
|
|
||||||
// Bob receives Alice's public key
|
// Bob receives Alice's public key
|
||||||
oneOf(transport).receiveKey();
|
oneOf(transport).receiveKey();
|
||||||
@@ -178,7 +188,8 @@ public class KeyAgreementProtocolTest extends BrambleTestCase {
|
|||||||
|
|
||||||
// Bob computes shared secret
|
// Bob computes shared secret
|
||||||
oneOf(crypto).deriveSharedSecret(SHARED_SECRET_LABEL, alicePubKey,
|
oneOf(crypto).deriveSharedSecret(SHARED_SECRET_LABEL, alicePubKey,
|
||||||
ourKeyPair, false);
|
ourKeyPair, new byte[] {PROTOCOL_VERSION},
|
||||||
|
alicePubKeyBytes, bobPubKeyBytes);
|
||||||
will(returnValue(sharedSecret));
|
will(returnValue(sharedSecret));
|
||||||
|
|
||||||
// Bob receives Alices's confirmation record
|
// Bob receives Alices's confirmation record
|
||||||
@@ -246,7 +257,8 @@ public class KeyAgreementProtocolTest extends BrambleTestCase {
|
|||||||
|
|
||||||
// Alice never computes shared secret
|
// Alice never computes shared secret
|
||||||
never(crypto).deriveSharedSecret(SHARED_SECRET_LABEL, badPubKey,
|
never(crypto).deriveSharedSecret(SHARED_SECRET_LABEL, badPubKey,
|
||||||
ourKeyPair, true);
|
ourKeyPair, new byte[] {PROTOCOL_VERSION},
|
||||||
|
alicePubKeyBytes, bobPubKeyBytes);
|
||||||
}});
|
}});
|
||||||
|
|
||||||
// execute
|
// execute
|
||||||
@@ -317,6 +329,8 @@ public class KeyAgreementProtocolTest extends BrambleTestCase {
|
|||||||
will(returnValue(alicePubKeyBytes));
|
will(returnValue(alicePubKeyBytes));
|
||||||
allowing(crypto).getAgreementKeyParser();
|
allowing(crypto).getAgreementKeyParser();
|
||||||
will(returnValue(keyParser));
|
will(returnValue(keyParser));
|
||||||
|
allowing(bobPubKey).getEncoded();
|
||||||
|
will(returnValue(bobPubKeyBytes));
|
||||||
|
|
||||||
// Alice sends her public key
|
// Alice sends her public key
|
||||||
oneOf(transport).sendKey(alicePubKeyBytes);
|
oneOf(transport).sendKey(alicePubKeyBytes);
|
||||||
@@ -335,7 +349,8 @@ public class KeyAgreementProtocolTest extends BrambleTestCase {
|
|||||||
|
|
||||||
// Alice computes shared secret
|
// Alice computes shared secret
|
||||||
oneOf(crypto).deriveSharedSecret(SHARED_SECRET_LABEL, bobPubKey,
|
oneOf(crypto).deriveSharedSecret(SHARED_SECRET_LABEL, bobPubKey,
|
||||||
ourKeyPair, true);
|
ourKeyPair, new byte[] {PROTOCOL_VERSION},
|
||||||
|
alicePubKeyBytes, bobPubKeyBytes);
|
||||||
will(returnValue(sharedSecret));
|
will(returnValue(sharedSecret));
|
||||||
|
|
||||||
// Alice sends her confirmation record
|
// Alice sends her confirmation record
|
||||||
@@ -389,6 +404,8 @@ public class KeyAgreementProtocolTest extends BrambleTestCase {
|
|||||||
will(returnValue(bobPubKeyBytes));
|
will(returnValue(bobPubKeyBytes));
|
||||||
allowing(crypto).getAgreementKeyParser();
|
allowing(crypto).getAgreementKeyParser();
|
||||||
will(returnValue(keyParser));
|
will(returnValue(keyParser));
|
||||||
|
allowing(alicePubKey).getEncoded();
|
||||||
|
will(returnValue(alicePubKeyBytes));
|
||||||
|
|
||||||
// Bob receives Alice's public key
|
// Bob receives Alice's public key
|
||||||
oneOf(transport).receiveKey();
|
oneOf(transport).receiveKey();
|
||||||
@@ -406,7 +423,8 @@ public class KeyAgreementProtocolTest extends BrambleTestCase {
|
|||||||
|
|
||||||
// Bob computes shared secret
|
// Bob computes shared secret
|
||||||
oneOf(crypto).deriveSharedSecret(SHARED_SECRET_LABEL, alicePubKey,
|
oneOf(crypto).deriveSharedSecret(SHARED_SECRET_LABEL, alicePubKey,
|
||||||
ourKeyPair, false);
|
ourKeyPair, new byte[] {PROTOCOL_VERSION},
|
||||||
|
alicePubKeyBytes, bobPubKeyBytes);
|
||||||
will(returnValue(sharedSecret));
|
will(returnValue(sharedSecret));
|
||||||
|
|
||||||
// Bob receives a bad confirmation record
|
// Bob receives a bad confirmation record
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ import java.util.Map;
|
|||||||
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH;
|
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH;
|
||||||
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_PUBLIC_KEY_LENGTH;
|
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_PUBLIC_KEY_LENGTH;
|
||||||
import static org.briarproject.bramble.api.properties.TransportPropertyManager.CLIENT_ID;
|
import static org.briarproject.bramble.api.properties.TransportPropertyManager.CLIENT_ID;
|
||||||
|
import static org.briarproject.bramble.api.properties.TransportPropertyManager.CLIENT_VERSION;
|
||||||
import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
|
import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
|
||||||
import static org.briarproject.bramble.api.sync.SyncConstants.MAX_GROUP_DESCRIPTOR_LENGTH;
|
import static org.briarproject.bramble.api.sync.SyncConstants.MAX_GROUP_DESCRIPTOR_LENGTH;
|
||||||
import static org.briarproject.bramble.api.sync.SyncConstants.MAX_MESSAGE_BODY_LENGTH;
|
import static org.briarproject.bramble.api.sync.SyncConstants.MAX_MESSAGE_BODY_LENGTH;
|
||||||
@@ -78,7 +79,8 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
|||||||
|
|
||||||
private TransportPropertyManagerImpl createInstance() {
|
private TransportPropertyManagerImpl createInstance() {
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
oneOf(contactGroupFactory).createLocalGroup(CLIENT_ID);
|
oneOf(contactGroupFactory).createLocalGroup(CLIENT_ID,
|
||||||
|
CLIENT_VERSION);
|
||||||
will(returnValue(localGroup));
|
will(returnValue(localGroup));
|
||||||
}});
|
}});
|
||||||
return new TransportPropertyManagerImpl(db, clientHelper,
|
return new TransportPropertyManagerImpl(db, clientHelper,
|
||||||
@@ -98,12 +100,14 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
|||||||
oneOf(db).getContacts(txn);
|
oneOf(db).getContacts(txn);
|
||||||
will(returnValue(contacts));
|
will(returnValue(contacts));
|
||||||
// The first contact's group has already been set up
|
// The first contact's group has already been set up
|
||||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID, contact1);
|
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||||
|
CLIENT_VERSION, contact1);
|
||||||
will(returnValue(contactGroup1));
|
will(returnValue(contactGroup1));
|
||||||
oneOf(db).containsGroup(txn, contactGroup1.getId());
|
oneOf(db).containsGroup(txn, contactGroup1.getId());
|
||||||
will(returnValue(true));
|
will(returnValue(true));
|
||||||
// The second contact's group hasn't been set up
|
// The second contact's group hasn't been set up
|
||||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID, contact2);
|
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||||
|
CLIENT_VERSION, contact2);
|
||||||
will(returnValue(contactGroup2));
|
will(returnValue(contactGroup2));
|
||||||
oneOf(db).containsGroup(txn, contactGroup2.getId());
|
oneOf(db).containsGroup(txn, contactGroup2.getId());
|
||||||
will(returnValue(false));
|
will(returnValue(false));
|
||||||
@@ -130,7 +134,8 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
|||||||
|
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
// Create the group and share it with the contact
|
// Create the group and share it with the contact
|
||||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID, contact);
|
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||||
|
CLIENT_VERSION, contact);
|
||||||
will(returnValue(contactGroup));
|
will(returnValue(contactGroup));
|
||||||
oneOf(db).containsGroup(txn, contactGroup.getId());
|
oneOf(db).containsGroup(txn, contactGroup.getId());
|
||||||
will(returnValue(false));
|
will(returnValue(false));
|
||||||
@@ -156,7 +161,8 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
|||||||
Group contactGroup = getGroup();
|
Group contactGroup = getGroup();
|
||||||
|
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID, contact);
|
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||||
|
CLIENT_VERSION, contact);
|
||||||
will(returnValue(contactGroup));
|
will(returnValue(contactGroup));
|
||||||
oneOf(db).removeGroup(txn, contactGroup);
|
oneOf(db).removeGroup(txn, contactGroup);
|
||||||
}});
|
}});
|
||||||
@@ -297,7 +303,8 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
|||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
oneOf(db).getContact(txn, contact.getId());
|
oneOf(db).getContact(txn, contact.getId());
|
||||||
will(returnValue(contact));
|
will(returnValue(contact));
|
||||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID, contact);
|
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||||
|
CLIENT_VERSION, contact);
|
||||||
will(returnValue(contactGroup));
|
will(returnValue(contactGroup));
|
||||||
}});
|
}});
|
||||||
expectStoreMessage(txn, contactGroup.getId(), "foo", fooPropertiesDict,
|
expectStoreMessage(txn, contactGroup.getId(), "foo", fooPropertiesDict,
|
||||||
@@ -431,13 +438,15 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
|||||||
will(returnValue(contacts));
|
will(returnValue(contacts));
|
||||||
// First contact: skipped because not active
|
// First contact: skipped because not active
|
||||||
// Second contact: no updates
|
// Second contact: no updates
|
||||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID, contact2);
|
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||||
|
CLIENT_VERSION, contact2);
|
||||||
will(returnValue(contactGroup2));
|
will(returnValue(contactGroup2));
|
||||||
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
|
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
|
||||||
contactGroup2.getId());
|
contactGroup2.getId());
|
||||||
will(returnValue(Collections.emptyMap()));
|
will(returnValue(Collections.emptyMap()));
|
||||||
// Third contact: returns an update
|
// Third contact: returns an update
|
||||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID, contact3);
|
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||||
|
CLIENT_VERSION, contact3);
|
||||||
will(returnValue(contactGroup3));
|
will(returnValue(contactGroup3));
|
||||||
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
|
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
|
||||||
contactGroup3.getId());
|
contactGroup3.getId());
|
||||||
@@ -507,7 +516,8 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
|||||||
// Store the new properties in each contact's group, version 1
|
// Store the new properties in each contact's group, version 1
|
||||||
oneOf(db).getContacts(txn);
|
oneOf(db).getContacts(txn);
|
||||||
will(returnValue(Collections.singletonList(contact)));
|
will(returnValue(Collections.singletonList(contact)));
|
||||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID, contact);
|
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||||
|
CLIENT_VERSION, contact);
|
||||||
will(returnValue(contactGroup));
|
will(returnValue(contactGroup));
|
||||||
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
|
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
|
||||||
contactGroup.getId());
|
contactGroup.getId());
|
||||||
@@ -559,7 +569,8 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
|||||||
// Store the merged properties in each contact's group, version 2
|
// Store the merged properties in each contact's group, version 2
|
||||||
oneOf(db).getContacts(txn);
|
oneOf(db).getContacts(txn);
|
||||||
will(returnValue(Collections.singletonList(contact)));
|
will(returnValue(Collections.singletonList(contact)));
|
||||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID, contact);
|
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||||
|
CLIENT_VERSION, contact);
|
||||||
will(returnValue(contactGroup));
|
will(returnValue(contactGroup));
|
||||||
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
|
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
|
||||||
contactGroup.getId());
|
contactGroup.getId());
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ import org.briarproject.bramble.api.transport.StreamReaderFactory;
|
|||||||
import org.briarproject.bramble.api.transport.StreamWriterFactory;
|
import org.briarproject.bramble.api.transport.StreamWriterFactory;
|
||||||
import org.briarproject.bramble.test.BrambleTestCase;
|
import org.briarproject.bramble.test.BrambleTestCase;
|
||||||
import org.briarproject.bramble.test.TestUtils;
|
import org.briarproject.bramble.test.TestUtils;
|
||||||
import org.briarproject.bramble.util.StringUtils;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
@@ -37,6 +36,7 @@ import javax.inject.Inject;
|
|||||||
import static org.briarproject.bramble.api.sync.SyncConstants.MAX_GROUP_DESCRIPTOR_LENGTH;
|
import static org.briarproject.bramble.api.sync.SyncConstants.MAX_GROUP_DESCRIPTOR_LENGTH;
|
||||||
import static org.briarproject.bramble.api.transport.TransportConstants.PROTOCOL_VERSION;
|
import static org.briarproject.bramble.api.transport.TransportConstants.PROTOCOL_VERSION;
|
||||||
import static org.briarproject.bramble.api.transport.TransportConstants.TAG_LENGTH;
|
import static org.briarproject.bramble.api.transport.TransportConstants.TAG_LENGTH;
|
||||||
|
import static org.briarproject.bramble.util.StringUtils.getRandomString;
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
import static org.junit.Assert.assertArrayEquals;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
@@ -79,9 +79,11 @@ public class SyncIntegrationTest extends BrambleTestCase {
|
|||||||
headerKey = TestUtils.getSecretKey();
|
headerKey = TestUtils.getSecretKey();
|
||||||
streamNumber = 123;
|
streamNumber = 123;
|
||||||
// Create a group
|
// Create a group
|
||||||
ClientId clientId = new ClientId(StringUtils.getRandomString(5));
|
ClientId clientId = new ClientId(getRandomString(123));
|
||||||
|
int clientVersion = 1234567890;
|
||||||
byte[] descriptor = new byte[MAX_GROUP_DESCRIPTOR_LENGTH];
|
byte[] descriptor = new byte[MAX_GROUP_DESCRIPTOR_LENGTH];
|
||||||
Group group = groupFactory.createGroup(clientId, descriptor);
|
Group group = groupFactory.createGroup(clientId, clientVersion,
|
||||||
|
descriptor);
|
||||||
// Add two messages to the group
|
// Add two messages to the group
|
||||||
long timestamp = System.currentTimeMillis();
|
long timestamp = System.currentTimeMillis();
|
||||||
byte[] body = "Hello world".getBytes("UTF-8");
|
byte[] body = "Hello world".getBytes("UTF-8");
|
||||||
|
|||||||
@@ -17,10 +17,15 @@ import javax.annotation.Nullable;
|
|||||||
public interface BlogManager {
|
public interface BlogManager {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unique ID of the blog client.
|
* The unique ID of the blog client.
|
||||||
*/
|
*/
|
||||||
ClientId CLIENT_ID = new ClientId("org.briarproject.briar.blog");
|
ClientId CLIENT_ID = new ClientId("org.briarproject.briar.blog");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The current version of the blog client.
|
||||||
|
*/
|
||||||
|
int CLIENT_VERSION = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the given {@link Blog).}
|
* Adds the given {@link Blog).}
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -5,6 +5,13 @@ import org.briarproject.briar.api.sharing.SharingManager;
|
|||||||
|
|
||||||
public interface BlogSharingManager extends SharingManager<Blog> {
|
public interface BlogSharingManager extends SharingManager<Blog> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The unique ID of the blog sharing client.
|
||||||
|
*/
|
||||||
ClientId CLIENT_ID = new ClientId("org.briarproject.briar.blog.sharing");
|
ClientId CLIENT_ID = new ClientId("org.briarproject.briar.blog.sharing");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The current version of the blog sharing client.
|
||||||
|
*/
|
||||||
|
int CLIENT_VERSION = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,11 @@ public interface FeedManager {
|
|||||||
*/
|
*/
|
||||||
ClientId CLIENT_ID = new ClientId("org.briarproject.briar.feed");
|
ClientId CLIENT_ID = new ClientId("org.briarproject.briar.feed");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The current version of the RSS feed client.
|
||||||
|
*/
|
||||||
|
int CLIENT_VERSION = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds an RSS feed as a new dedicated blog.
|
* Adds an RSS feed as a new dedicated blog.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -22,6 +22,11 @@ public interface ForumManager {
|
|||||||
*/
|
*/
|
||||||
ClientId CLIENT_ID = new ClientId("org.briarproject.briar.forum");
|
ClientId CLIENT_ID = new ClientId("org.briarproject.briar.forum");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The current version of the forum client.
|
||||||
|
*/
|
||||||
|
int CLIENT_VERSION = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Subscribes to a forum.
|
* Subscribes to a forum.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -5,6 +5,13 @@ import org.briarproject.briar.api.sharing.SharingManager;
|
|||||||
|
|
||||||
public interface ForumSharingManager extends SharingManager<Forum> {
|
public interface ForumSharingManager extends SharingManager<Forum> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The unique ID of the forum sharing client.
|
||||||
|
*/
|
||||||
ClientId CLIENT_ID = new ClientId("org.briarproject.briar.forum.sharing");
|
ClientId CLIENT_ID = new ClientId("org.briarproject.briar.forum.sharing");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The current version of the forum sharing client.
|
||||||
|
*/
|
||||||
|
int CLIENT_VERSION = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,11 @@ public interface IntroductionManager extends ConversationClient {
|
|||||||
*/
|
*/
|
||||||
ClientId CLIENT_ID = new ClientId("org.briarproject.briar.introduction");
|
ClientId CLIENT_ID = new ClientId("org.briarproject.briar.introduction");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The current version of the introduction client.
|
||||||
|
*/
|
||||||
|
int CLIENT_VERSION = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends two initial introduction messages.
|
* Sends two initial introduction messages.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -18,6 +18,11 @@ public interface MessagingManager extends ConversationClient {
|
|||||||
*/
|
*/
|
||||||
ClientId CLIENT_ID = new ClientId("org.briarproject.briar.messaging");
|
ClientId CLIENT_ID = new ClientId("org.briarproject.briar.messaging");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The current version of the messaging client.
|
||||||
|
*/
|
||||||
|
int CLIENT_VERSION = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stores a local private message.
|
* Stores a local private message.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -21,6 +21,11 @@ public interface PrivateGroupManager {
|
|||||||
*/
|
*/
|
||||||
ClientId CLIENT_ID = new ClientId("org.briarproject.briar.privategroup");
|
ClientId CLIENT_ID = new ClientId("org.briarproject.briar.privategroup");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The current version of the private group client.
|
||||||
|
*/
|
||||||
|
int CLIENT_VERSION = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a new private group and joins it.
|
* Adds a new private group and joins it.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -25,6 +25,11 @@ public interface GroupInvitationManager extends ConversationClient {
|
|||||||
ClientId CLIENT_ID =
|
ClientId CLIENT_ID =
|
||||||
new ClientId("org.briarproject.briar.privategroup.invitation");
|
new ClientId("org.briarproject.briar.privategroup.invitation");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The current version of the private group invitation client.
|
||||||
|
*/
|
||||||
|
int CLIENT_VERSION = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends an invitation to share the given private group with the given
|
* Sends an invitation to share the given private group with the given
|
||||||
* contact, including an optional message.
|
* contact, including an optional message.
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ import javax.inject.Inject;
|
|||||||
|
|
||||||
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH;
|
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH;
|
||||||
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_PUBLIC_KEY_LENGTH;
|
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_PUBLIC_KEY_LENGTH;
|
||||||
|
import static org.briarproject.briar.api.blog.BlogManager.CLIENT_ID;
|
||||||
|
import static org.briarproject.briar.api.blog.BlogManager.CLIENT_VERSION;
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
@@ -52,8 +54,8 @@ class BlogFactoryImpl implements BlogFactory {
|
|||||||
rssFeed
|
rssFeed
|
||||||
);
|
);
|
||||||
byte[] descriptor = clientHelper.toByteArray(blog);
|
byte[] descriptor = clientHelper.toByteArray(blog);
|
||||||
Group g = groupFactory
|
Group g = groupFactory.createGroup(CLIENT_ID, CLIENT_VERSION,
|
||||||
.createGroup(BlogManagerImpl.CLIENT_ID, descriptor);
|
descriptor);
|
||||||
return new Blog(g, a, rssFeed);
|
return new Blog(g, a, rssFeed);
|
||||||
} catch (FormatException e) {
|
} catch (FormatException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
|||||||
@@ -45,6 +45,8 @@ import static org.briarproject.briar.api.blog.BlogConstants.KEY_TIME_RECEIVED;
|
|||||||
import static org.briarproject.briar.api.blog.BlogConstants.KEY_TYPE;
|
import static org.briarproject.briar.api.blog.BlogConstants.KEY_TYPE;
|
||||||
import static org.briarproject.briar.api.blog.BlogConstants.MAX_BLOG_COMMENT_LENGTH;
|
import static org.briarproject.briar.api.blog.BlogConstants.MAX_BLOG_COMMENT_LENGTH;
|
||||||
import static org.briarproject.briar.api.blog.BlogConstants.MAX_BLOG_POST_BODY_LENGTH;
|
import static org.briarproject.briar.api.blog.BlogConstants.MAX_BLOG_POST_BODY_LENGTH;
|
||||||
|
import static org.briarproject.briar.api.blog.BlogManager.CLIENT_ID;
|
||||||
|
import static org.briarproject.briar.api.blog.BlogManager.CLIENT_VERSION;
|
||||||
import static org.briarproject.briar.api.blog.BlogPostFactory.SIGNING_LABEL_COMMENT;
|
import static org.briarproject.briar.api.blog.BlogPostFactory.SIGNING_LABEL_COMMENT;
|
||||||
import static org.briarproject.briar.api.blog.BlogPostFactory.SIGNING_LABEL_POST;
|
import static org.briarproject.briar.api.blog.BlogPostFactory.SIGNING_LABEL_POST;
|
||||||
import static org.briarproject.briar.api.blog.MessageType.COMMENT;
|
import static org.briarproject.briar.api.blog.MessageType.COMMENT;
|
||||||
@@ -199,8 +201,8 @@ class BlogPostValidator extends BdfMessageValidator {
|
|||||||
checkLength(signature, 1, MAX_SIGNATURE_LENGTH);
|
checkLength(signature, 1, MAX_SIGNATURE_LENGTH);
|
||||||
|
|
||||||
// Get and Validate the Wrapped Message
|
// Get and Validate the Wrapped Message
|
||||||
Group wGroup = groupFactory
|
Group wGroup = groupFactory.createGroup(CLIENT_ID, CLIENT_VERSION,
|
||||||
.createGroup(BlogManagerImpl.CLIENT_ID, descriptor);
|
descriptor);
|
||||||
Blog wBlog = blogFactory.parseBlog(wGroup);
|
Blog wBlog = blogFactory.parseBlog(wGroup);
|
||||||
BdfList wBodyList = BdfList.of(POST.getInt(), content, signature);
|
BdfList wBodyList = BdfList.of(POST.getInt(), content, signature);
|
||||||
byte[] wBody = clientHelper.toByteArray(wBodyList);
|
byte[] wBody = clientHelper.toByteArray(wBodyList);
|
||||||
@@ -262,8 +264,8 @@ class BlogPostValidator extends BdfMessageValidator {
|
|||||||
MessageId parentId = new MessageId(parentIdBytes);
|
MessageId parentId = new MessageId(parentIdBytes);
|
||||||
|
|
||||||
// Get and Validate the Wrapped Comment
|
// Get and Validate the Wrapped Comment
|
||||||
Group wGroup = groupFactory
|
Group wGroup = groupFactory.createGroup(CLIENT_ID, CLIENT_VERSION,
|
||||||
.createGroup(BlogManagerImpl.CLIENT_ID, descriptor);
|
descriptor);
|
||||||
BdfList wBodyList = BdfList.of(COMMENT.getInt(), comment, pOriginalId,
|
BdfList wBodyList = BdfList.of(COMMENT.getInt(), comment, pOriginalId,
|
||||||
oldId, signature);
|
oldId, signature);
|
||||||
byte[] wBody = clientHelper.toByteArray(wBodyList);
|
byte[] wBody = clientHelper.toByteArray(wBodyList);
|
||||||
|
|||||||
@@ -12,8 +12,10 @@ import org.briarproject.briar.api.client.QueueMessageFactory;
|
|||||||
import javax.annotation.concurrent.Immutable;
|
import javax.annotation.concurrent.Immutable;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import static org.briarproject.bramble.api.sync.MessageId.LABEL;
|
||||||
import static org.briarproject.bramble.api.sync.SyncConstants.MAX_MESSAGE_LENGTH;
|
import static org.briarproject.bramble.api.sync.SyncConstants.MAX_MESSAGE_LENGTH;
|
||||||
import static org.briarproject.bramble.api.sync.SyncConstants.MESSAGE_HEADER_LENGTH;
|
import static org.briarproject.bramble.api.sync.SyncConstants.MESSAGE_HEADER_LENGTH;
|
||||||
|
import static org.briarproject.bramble.api.sync.SyncConstants.PROTOCOL_VERSION;
|
||||||
import static org.briarproject.bramble.util.ByteUtils.INT_64_BYTES;
|
import static org.briarproject.bramble.util.ByteUtils.INT_64_BYTES;
|
||||||
import static org.briarproject.briar.api.client.QueueMessage.MAX_QUEUE_MESSAGE_BODY_LENGTH;
|
import static org.briarproject.briar.api.client.QueueMessage.MAX_QUEUE_MESSAGE_BODY_LENGTH;
|
||||||
import static org.briarproject.briar.api.client.QueueMessage.QUEUE_MESSAGE_HEADER_LENGTH;
|
import static org.briarproject.briar.api.client.QueueMessage.QUEUE_MESSAGE_HEADER_LENGTH;
|
||||||
@@ -45,9 +47,9 @@ class QueueMessageFactoryImpl implements QueueMessageFactory {
|
|||||||
byte[] bodyBytes = new byte[body.length + INT_64_BYTES];
|
byte[] bodyBytes = new byte[body.length + INT_64_BYTES];
|
||||||
System.arraycopy(raw, MESSAGE_HEADER_LENGTH, bodyBytes, 0,
|
System.arraycopy(raw, MESSAGE_HEADER_LENGTH, bodyBytes, 0,
|
||||||
body.length + INT_64_BYTES);
|
body.length + INT_64_BYTES);
|
||||||
MessageId id = new MessageId(
|
byte[] hash = crypto.hash(LABEL, new byte[] {PROTOCOL_VERSION},
|
||||||
crypto.hash(MessageId.LABEL, groupId.getBytes(), timeBytes,
|
groupId.getBytes(), timeBytes, bodyBytes);
|
||||||
bodyBytes));
|
MessageId id = new MessageId(hash);
|
||||||
return new QueueMessage(id, groupId, timestamp, queuePosition, raw);
|
return new QueueMessage(id, groupId, timestamp, queuePosition, raw);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -496,7 +496,7 @@ class FeedManagerImpl implements FeedManager, Client, EventListener,
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Group getLocalGroup() {
|
private Group getLocalGroup() {
|
||||||
return contactGroupFactory.createLocalGroup(CLIENT_ID);
|
return contactGroupFactory.createLocalGroup(CLIENT_ID, CLIENT_VERSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import javax.inject.Inject;
|
|||||||
import static org.briarproject.briar.api.forum.ForumConstants.FORUM_SALT_LENGTH;
|
import static org.briarproject.briar.api.forum.ForumConstants.FORUM_SALT_LENGTH;
|
||||||
import static org.briarproject.briar.api.forum.ForumConstants.MAX_FORUM_NAME_LENGTH;
|
import static org.briarproject.briar.api.forum.ForumConstants.MAX_FORUM_NAME_LENGTH;
|
||||||
import static org.briarproject.briar.api.forum.ForumManager.CLIENT_ID;
|
import static org.briarproject.briar.api.forum.ForumManager.CLIENT_ID;
|
||||||
|
import static org.briarproject.briar.api.forum.ForumManager.CLIENT_VERSION;
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
@@ -52,7 +53,8 @@ class ForumFactoryImpl implements ForumFactory {
|
|||||||
try {
|
try {
|
||||||
BdfList forum = BdfList.of(name, salt);
|
BdfList forum = BdfList.of(name, salt);
|
||||||
byte[] descriptor = clientHelper.toByteArray(forum);
|
byte[] descriptor = clientHelper.toByteArray(forum);
|
||||||
Group g = groupFactory.createGroup(CLIENT_ID, descriptor);
|
Group g = groupFactory.createGroup(CLIENT_ID, CLIENT_VERSION,
|
||||||
|
descriptor);
|
||||||
return new Forum(g, name, salt);
|
return new Forum(g, name, salt);
|
||||||
} catch (FormatException e) {
|
} catch (FormatException e) {
|
||||||
throw new AssertionError(e);
|
throw new AssertionError(e);
|
||||||
|
|||||||
@@ -96,6 +96,7 @@ import static org.briarproject.briar.api.introduction.IntroductionConstants.TYPE
|
|||||||
import static org.briarproject.briar.api.introduction.IntroductionConstants.TYPE_ABORT;
|
import static org.briarproject.briar.api.introduction.IntroductionConstants.TYPE_ABORT;
|
||||||
import static org.briarproject.briar.api.introduction.IntroductionConstants.TYPE_ACK;
|
import static org.briarproject.briar.api.introduction.IntroductionConstants.TYPE_ACK;
|
||||||
import static org.briarproject.briar.api.introduction.IntroductionConstants.TYPE_RESPONSE;
|
import static org.briarproject.briar.api.introduction.IntroductionConstants.TYPE_RESPONSE;
|
||||||
|
import static org.briarproject.briar.api.introduction.IntroductionManager.CLIENT_VERSION;
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
@@ -433,8 +434,13 @@ class IntroduceeManager {
|
|||||||
|
|
||||||
// The shared secret is derived from the local ephemeral key pair
|
// The shared secret is derived from the local ephemeral key pair
|
||||||
// and the remote ephemeral public key
|
// and the remote ephemeral public key
|
||||||
|
byte[][] inputs = {
|
||||||
|
new byte[] {CLIENT_VERSION},
|
||||||
|
alice ? ourPublicKeyBytes : theirPublicKeyBytes,
|
||||||
|
alice ? theirPublicKeyBytes : ourPublicKeyBytes
|
||||||
|
};
|
||||||
return cryptoComponent.deriveSharedSecret(SHARED_SECRET_LABEL,
|
return cryptoComponent.deriveSharedSecret(SHARED_SECRET_LABEL,
|
||||||
theirPublicKey, ourKeyPair, alice);
|
theirPublicKey, ourKeyPair, inputs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import org.briarproject.bramble.api.sync.Group;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import static org.briarproject.briar.api.introduction.IntroductionManager.CLIENT_ID;
|
import static org.briarproject.briar.api.introduction.IntroductionManager.CLIENT_ID;
|
||||||
|
import static org.briarproject.briar.api.introduction.IntroductionManager.CLIENT_VERSION;
|
||||||
|
|
||||||
class IntroductionGroupFactory {
|
class IntroductionGroupFactory {
|
||||||
|
|
||||||
@@ -16,14 +17,16 @@ class IntroductionGroupFactory {
|
|||||||
@Inject
|
@Inject
|
||||||
IntroductionGroupFactory(ContactGroupFactory contactGroupFactory) {
|
IntroductionGroupFactory(ContactGroupFactory contactGroupFactory) {
|
||||||
this.contactGroupFactory = contactGroupFactory;
|
this.contactGroupFactory = contactGroupFactory;
|
||||||
localGroup = contactGroupFactory.createLocalGroup(CLIENT_ID);
|
localGroup = contactGroupFactory.createLocalGroup(CLIENT_ID,
|
||||||
|
CLIENT_VERSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
Group createIntroductionGroup(Contact c) {
|
Group createIntroductionGroup(Contact c) {
|
||||||
return contactGroupFactory.createContactGroup(CLIENT_ID, c);
|
return contactGroupFactory.createContactGroup(CLIENT_ID,
|
||||||
|
CLIENT_VERSION, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Group createLocalGroup() {
|
Group createLocalGroup() {
|
||||||
return localGroup;
|
return localGroup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -79,7 +79,8 @@ class MessagingManagerImpl extends ConversationClientImpl
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Group getContactGroup(Contact c) {
|
public Group getContactGroup(Contact c) {
|
||||||
return contactGroupFactory.createContactGroup(CLIENT_ID, c);
|
return contactGroupFactory.createContactGroup(CLIENT_ID,
|
||||||
|
CLIENT_VERSION, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import javax.inject.Inject;
|
|||||||
import static org.briarproject.briar.api.privategroup.PrivateGroupConstants.GROUP_SALT_LENGTH;
|
import static org.briarproject.briar.api.privategroup.PrivateGroupConstants.GROUP_SALT_LENGTH;
|
||||||
import static org.briarproject.briar.api.privategroup.PrivateGroupConstants.MAX_GROUP_NAME_LENGTH;
|
import static org.briarproject.briar.api.privategroup.PrivateGroupConstants.MAX_GROUP_NAME_LENGTH;
|
||||||
import static org.briarproject.briar.api.privategroup.PrivateGroupManager.CLIENT_ID;
|
import static org.briarproject.briar.api.privategroup.PrivateGroupManager.CLIENT_ID;
|
||||||
|
import static org.briarproject.briar.api.privategroup.PrivateGroupManager.CLIENT_VERSION;
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
@@ -64,7 +65,8 @@ class PrivateGroupFactoryImpl implements PrivateGroupFactory {
|
|||||||
salt
|
salt
|
||||||
);
|
);
|
||||||
byte[] descriptor = clientHelper.toByteArray(group);
|
byte[] descriptor = clientHelper.toByteArray(group);
|
||||||
Group g = groupFactory.createGroup(CLIENT_ID, descriptor);
|
Group g = groupFactory.createGroup(CLIENT_ID, CLIENT_VERSION,
|
||||||
|
descriptor);
|
||||||
return new PrivateGroup(g, name, author, salt);
|
return new PrivateGroup(g, name, author, salt);
|
||||||
} catch (FormatException e) {
|
} catch (FormatException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import javax.annotation.concurrent.Immutable;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import static org.briarproject.briar.api.privategroup.invitation.GroupInvitationManager.CLIENT_ID;
|
import static org.briarproject.briar.api.privategroup.invitation.GroupInvitationManager.CLIENT_ID;
|
||||||
|
import static org.briarproject.briar.api.privategroup.invitation.GroupInvitationManager.CLIENT_VERSION;
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
@@ -52,7 +53,7 @@ class GroupInvitationFactoryImpl implements GroupInvitationFactory {
|
|||||||
public BdfList createInviteToken(AuthorId creatorId, AuthorId memberId,
|
public BdfList createInviteToken(AuthorId creatorId, AuthorId memberId,
|
||||||
GroupId privateGroupId, long timestamp) {
|
GroupId privateGroupId, long timestamp) {
|
||||||
Group contactGroup = contactGroupFactory.createContactGroup(CLIENT_ID,
|
Group contactGroup = contactGroupFactory.createContactGroup(CLIENT_ID,
|
||||||
creatorId, memberId);
|
CLIENT_VERSION, creatorId, memberId);
|
||||||
return BdfList.of(
|
return BdfList.of(
|
||||||
timestamp,
|
timestamp,
|
||||||
contactGroup.getId(),
|
contactGroup.getId(),
|
||||||
|
|||||||
@@ -132,7 +132,8 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Group getContactGroup(Contact c) {
|
public Group getContactGroup(Contact c) {
|
||||||
return contactGroupFactory.createContactGroup(CLIENT_ID, c);
|
return contactGroupFactory.createContactGroup(CLIENT_ID,
|
||||||
|
CLIENT_VERSION, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -51,6 +51,11 @@ class BlogSharingManagerImpl extends SharingManagerImpl<Blog>
|
|||||||
return CLIENT_ID;
|
return CLIENT_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getClientVersion() {
|
||||||
|
return CLIENT_VERSION;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is called during each startup for each existing Contact.
|
* This is called during each startup for each existing Contact.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -38,6 +38,11 @@ class ForumSharingManagerImpl extends SharingManagerImpl<Forum>
|
|||||||
return CLIENT_ID;
|
return CLIENT_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getClientVersion() {
|
||||||
|
return CLIENT_VERSION;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removingForum(Transaction txn, Forum f) throws DbException {
|
public void removingForum(Transaction txn, Forum f) throws DbException {
|
||||||
removingShareable(txn, f);
|
removingShareable(txn, f);
|
||||||
|
|||||||
@@ -80,6 +80,8 @@ abstract class SharingManagerImpl<S extends Shareable>
|
|||||||
|
|
||||||
protected abstract ClientId getClientId();
|
protected abstract ClientId getClientId();
|
||||||
|
|
||||||
|
protected abstract int getClientVersion();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createLocalState(Transaction txn) throws DbException {
|
public void createLocalState(Transaction txn) throws DbException {
|
||||||
// Ensure we've set things up for any pre-existing contacts
|
// Ensure we've set things up for any pre-existing contacts
|
||||||
@@ -113,7 +115,8 @@ abstract class SharingManagerImpl<S extends Shareable>
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Group getContactGroup(Contact c) {
|
public Group getContactGroup(Contact c) {
|
||||||
return contactGroupFactory.createContactGroup(getClientId(), c);
|
return contactGroupFactory.createContactGroup(getClientId(),
|
||||||
|
getClientVersion(), c);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import org.briarproject.bramble.api.data.BdfList;
|
|||||||
import org.briarproject.bramble.api.data.MetadataEncoder;
|
import org.briarproject.bramble.api.data.MetadataEncoder;
|
||||||
import org.briarproject.bramble.api.identity.Author;
|
import org.briarproject.bramble.api.identity.Author;
|
||||||
import org.briarproject.bramble.api.identity.AuthorId;
|
import org.briarproject.bramble.api.identity.AuthorId;
|
||||||
import org.briarproject.bramble.api.sync.ClientId;
|
|
||||||
import org.briarproject.bramble.api.sync.Group;
|
import org.briarproject.bramble.api.sync.Group;
|
||||||
import org.briarproject.bramble.api.sync.GroupFactory;
|
import org.briarproject.bramble.api.sync.GroupFactory;
|
||||||
import org.briarproject.bramble.api.sync.GroupId;
|
import org.briarproject.bramble.api.sync.GroupId;
|
||||||
@@ -40,6 +39,8 @@ import static org.briarproject.briar.api.blog.BlogConstants.KEY_PARENT_MSG_ID;
|
|||||||
import static org.briarproject.briar.api.blog.BlogConstants.KEY_PUBLIC_KEY;
|
import static org.briarproject.briar.api.blog.BlogConstants.KEY_PUBLIC_KEY;
|
||||||
import static org.briarproject.briar.api.blog.BlogConstants.KEY_READ;
|
import static org.briarproject.briar.api.blog.BlogConstants.KEY_READ;
|
||||||
import static org.briarproject.briar.api.blog.BlogConstants.KEY_RSS_FEED;
|
import static org.briarproject.briar.api.blog.BlogConstants.KEY_RSS_FEED;
|
||||||
|
import static org.briarproject.briar.api.blog.BlogManager.CLIENT_ID;
|
||||||
|
import static org.briarproject.briar.api.blog.BlogManager.CLIENT_VERSION;
|
||||||
import static org.briarproject.briar.api.blog.BlogPostFactory.SIGNING_LABEL_COMMENT;
|
import static org.briarproject.briar.api.blog.BlogPostFactory.SIGNING_LABEL_COMMENT;
|
||||||
import static org.briarproject.briar.api.blog.BlogPostFactory.SIGNING_LABEL_POST;
|
import static org.briarproject.briar.api.blog.BlogPostFactory.SIGNING_LABEL_POST;
|
||||||
import static org.briarproject.briar.api.blog.MessageType.COMMENT;
|
import static org.briarproject.briar.api.blog.MessageType.COMMENT;
|
||||||
@@ -54,7 +55,6 @@ public class BlogPostValidatorTest extends BriarTestCase {
|
|||||||
private final Mockery context = new Mockery();
|
private final Mockery context = new Mockery();
|
||||||
private final Blog blog, rssBlog;
|
private final Blog blog, rssBlog;
|
||||||
private final BdfDictionary authorDict;
|
private final BdfDictionary authorDict;
|
||||||
private final ClientId clientId;
|
|
||||||
private final byte[] descriptor;
|
private final byte[] descriptor;
|
||||||
private final Group group;
|
private final Group group;
|
||||||
private final Message message;
|
private final Message message;
|
||||||
@@ -69,9 +69,8 @@ public class BlogPostValidatorTest extends BriarTestCase {
|
|||||||
|
|
||||||
public BlogPostValidatorTest() {
|
public BlogPostValidatorTest() {
|
||||||
GroupId groupId = new GroupId(TestUtils.getRandomId());
|
GroupId groupId = new GroupId(TestUtils.getRandomId());
|
||||||
clientId = BlogManagerImpl.CLIENT_ID;
|
|
||||||
descriptor = TestUtils.getRandomBytes(42);
|
descriptor = TestUtils.getRandomBytes(42);
|
||||||
group = new Group(groupId, clientId, descriptor);
|
group = new Group(groupId, CLIENT_ID, descriptor);
|
||||||
AuthorId authorId =
|
AuthorId authorId =
|
||||||
new AuthorId(TestUtils.getRandomBytes(AuthorId.LENGTH));
|
new AuthorId(TestUtils.getRandomBytes(AuthorId.LENGTH));
|
||||||
byte[] publicKey = TestUtils.getRandomBytes(MAX_PUBLIC_KEY_LENGTH);
|
byte[] publicKey = TestUtils.getRandomBytes(MAX_PUBLIC_KEY_LENGTH);
|
||||||
@@ -215,7 +214,8 @@ public class BlogPostValidatorTest extends BriarTestCase {
|
|||||||
byte[] originalBody = TestUtils.getRandomBytes(42);
|
byte[] originalBody = TestUtils.getRandomBytes(42);
|
||||||
|
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
oneOf(groupFactory).createGroup(clientId, descriptor);
|
oneOf(groupFactory).createGroup(CLIENT_ID, CLIENT_VERSION,
|
||||||
|
descriptor);
|
||||||
will(returnValue(b.getGroup()));
|
will(returnValue(b.getGroup()));
|
||||||
oneOf(blogFactory).parseBlog(b.getGroup());
|
oneOf(blogFactory).parseBlog(b.getGroup());
|
||||||
will(returnValue(b));
|
will(returnValue(b));
|
||||||
@@ -258,7 +258,8 @@ public class BlogPostValidatorTest extends BriarTestCase {
|
|||||||
byte[] originalBody = TestUtils.getRandomBytes(42);
|
byte[] originalBody = TestUtils.getRandomBytes(42);
|
||||||
|
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
oneOf(groupFactory).createGroup(clientId, descriptor);
|
oneOf(groupFactory).createGroup(CLIENT_ID, CLIENT_VERSION,
|
||||||
|
descriptor);
|
||||||
will(returnValue(blog.getGroup()));
|
will(returnValue(blog.getGroup()));
|
||||||
oneOf(clientHelper).toByteArray(originalList);
|
oneOf(clientHelper).toByteArray(originalList);
|
||||||
will(returnValue(originalBody));
|
will(returnValue(originalBody));
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
|||||||
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
||||||
import static org.briarproject.briar.api.feed.FeedConstants.KEY_FEEDS;
|
import static org.briarproject.briar.api.feed.FeedConstants.KEY_FEEDS;
|
||||||
import static org.briarproject.briar.api.feed.FeedManager.CLIENT_ID;
|
import static org.briarproject.briar.api.feed.FeedManager.CLIENT_ID;
|
||||||
|
import static org.briarproject.briar.api.feed.FeedManager.CLIENT_VERSION;
|
||||||
|
|
||||||
public class FeedManagerImplTest extends BrambleMockTestCase {
|
public class FeedManagerImplTest extends BrambleMockTestCase {
|
||||||
|
|
||||||
@@ -133,7 +134,8 @@ public class FeedManagerImplTest extends BrambleMockTestCase {
|
|||||||
|
|
||||||
private void expectGetLocalGroup() {
|
private void expectGetLocalGroup() {
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
oneOf(contactGroupFactory).createLocalGroup(CLIENT_ID);
|
oneOf(contactGroupFactory).createLocalGroup(CLIENT_ID,
|
||||||
|
CLIENT_VERSION);
|
||||||
will(returnValue(localGroup));
|
will(returnValue(localGroup));
|
||||||
}});
|
}});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,6 +75,7 @@ import static org.briarproject.briar.api.introduction.IntroductionConstants.TRAN
|
|||||||
import static org.briarproject.briar.api.introduction.IntroductionConstants.TYPE;
|
import static org.briarproject.briar.api.introduction.IntroductionConstants.TYPE;
|
||||||
import static org.briarproject.briar.api.introduction.IntroductionConstants.TYPE_REQUEST;
|
import static org.briarproject.briar.api.introduction.IntroductionConstants.TYPE_REQUEST;
|
||||||
import static org.briarproject.briar.api.introduction.IntroductionConstants.TYPE_RESPONSE;
|
import static org.briarproject.briar.api.introduction.IntroductionConstants.TYPE_RESPONSE;
|
||||||
|
import static org.briarproject.briar.api.introduction.IntroductionManager.CLIENT_VERSION;
|
||||||
import static org.briarproject.briar.test.BriarTestUtils.assertGroupCount;
|
import static org.briarproject.briar.test.BriarTestUtils.assertGroupCount;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
@@ -753,8 +754,13 @@ public class IntroductionIntegrationTest
|
|||||||
KeyPair eKeyPair2 = crypto.generateAgreementKeyPair();
|
KeyPair eKeyPair2 = crypto.generateAgreementKeyPair();
|
||||||
|
|
||||||
// Nonce 1
|
// Nonce 1
|
||||||
|
byte[][] inputs = {
|
||||||
|
new byte[] {CLIENT_VERSION},
|
||||||
|
eKeyPair1.getPublic().getEncoded(),
|
||||||
|
eKeyPair2.getPublic().getEncoded()
|
||||||
|
};
|
||||||
SecretKey sharedSecret = crypto.deriveSharedSecret(SHARED_SECRET_LABEL,
|
SecretKey sharedSecret = crypto.deriveSharedSecret(SHARED_SECRET_LABEL,
|
||||||
eKeyPair2.getPublic(), eKeyPair1, true);
|
eKeyPair2.getPublic(), eKeyPair1, inputs);
|
||||||
byte[] nonce1 = crypto.mac(ALICE_NONCE_LABEL, sharedSecret);
|
byte[] nonce1 = crypto.mac(ALICE_NONCE_LABEL, sharedSecret);
|
||||||
|
|
||||||
// Signature 1
|
// Signature 1
|
||||||
@@ -787,20 +793,24 @@ public class IntroductionIntegrationTest
|
|||||||
|
|
||||||
// replace ephemeral key pair and recalculate matching keys and nonce
|
// replace ephemeral key pair and recalculate matching keys and nonce
|
||||||
KeyPair eKeyPair1f = crypto.generateAgreementKeyPair();
|
KeyPair eKeyPair1f = crypto.generateAgreementKeyPair();
|
||||||
byte[] ePublicKeyBytes1f = eKeyPair1f.getPublic().getEncoded();
|
byte[][] fakeInputs = {
|
||||||
|
new byte[] {CLIENT_VERSION},
|
||||||
|
eKeyPair1f.getPublic().getEncoded(),
|
||||||
|
eKeyPair2.getPublic().getEncoded()
|
||||||
|
};
|
||||||
sharedSecret = crypto.deriveSharedSecret(SHARED_SECRET_LABEL,
|
sharedSecret = crypto.deriveSharedSecret(SHARED_SECRET_LABEL,
|
||||||
eKeyPair2.getPublic(), eKeyPair1f, true);
|
eKeyPair2.getPublic(), eKeyPair1f, fakeInputs);
|
||||||
nonce1 = crypto.mac(ALICE_NONCE_LABEL, sharedSecret);
|
nonce1 = crypto.mac(ALICE_NONCE_LABEL, sharedSecret);
|
||||||
|
|
||||||
// recalculate MAC
|
// recalculate MAC
|
||||||
macKey1 = crypto.deriveKey(ALICE_MAC_KEY_LABEL, sharedSecret);
|
macKey1 = crypto.deriveKey(ALICE_MAC_KEY_LABEL, sharedSecret);
|
||||||
toMacList = BdfList.of(keyPair1.getPublic().getEncoded(),
|
toMacList = BdfList.of(keyPair1.getPublic().getEncoded(),
|
||||||
ePublicKeyBytes1f, tp1, time1);
|
eKeyPair1f.getPublic().getEncoded(), tp1, time1);
|
||||||
toMac = clientHelper.toByteArray(toMacList);
|
toMac = clientHelper.toByteArray(toMacList);
|
||||||
mac1 = crypto.mac(MAC_LABEL, macKey1, toMac);
|
mac1 = crypto.mac(MAC_LABEL, macKey1, toMac);
|
||||||
|
|
||||||
// update state with faked information
|
// update state with faked information
|
||||||
state.put(E_PUBLIC_KEY, ePublicKeyBytes1f);
|
state.put(E_PUBLIC_KEY, eKeyPair1f.getPublic().getEncoded());
|
||||||
state.put(MAC, mac1);
|
state.put(MAC, mac1);
|
||||||
state.put(MAC_KEY, macKey1.getBytes());
|
state.put(MAC_KEY, macKey1.getBytes());
|
||||||
state.put(NONCE, nonce1);
|
state.put(NONCE, nonce1);
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ import static org.briarproject.bramble.util.StringUtils.getRandomString;
|
|||||||
import static org.briarproject.briar.api.privategroup.PrivateGroupConstants.GROUP_SALT_LENGTH;
|
import static org.briarproject.briar.api.privategroup.PrivateGroupConstants.GROUP_SALT_LENGTH;
|
||||||
import static org.briarproject.briar.api.privategroup.PrivateGroupConstants.MAX_GROUP_NAME_LENGTH;
|
import static org.briarproject.briar.api.privategroup.PrivateGroupConstants.MAX_GROUP_NAME_LENGTH;
|
||||||
import static org.briarproject.briar.api.privategroup.invitation.GroupInvitationManager.CLIENT_ID;
|
import static org.briarproject.briar.api.privategroup.invitation.GroupInvitationManager.CLIENT_ID;
|
||||||
|
import static org.briarproject.briar.api.privategroup.invitation.GroupInvitationManager.CLIENT_VERSION;
|
||||||
import static org.briarproject.briar.privategroup.invitation.GroupInvitationConstants.GROUP_KEY_CONTACT_ID;
|
import static org.briarproject.briar.privategroup.invitation.GroupInvitationConstants.GROUP_KEY_CONTACT_ID;
|
||||||
import static org.briarproject.briar.privategroup.invitation.MessageType.ABORT;
|
import static org.briarproject.briar.privategroup.invitation.MessageType.ABORT;
|
||||||
import static org.briarproject.briar.privategroup.invitation.MessageType.INVITE;
|
import static org.briarproject.briar.privategroup.invitation.MessageType.INVITE;
|
||||||
@@ -162,7 +163,8 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
|||||||
private void expectAddingContact(Contact c, boolean contactExists)
|
private void expectAddingContact(Contact c, boolean contactExists)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID, c);
|
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||||
|
CLIENT_VERSION, c);
|
||||||
will(returnValue(contactGroup));
|
will(returnValue(contactGroup));
|
||||||
oneOf(db).containsGroup(txn, contactGroup.getId());
|
oneOf(db).containsGroup(txn, contactGroup.getId());
|
||||||
will(returnValue(contactExists));
|
will(returnValue(contactExists));
|
||||||
@@ -188,7 +190,8 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
|||||||
|
|
||||||
private void expectAddingMember(GroupId g, Contact c) throws Exception {
|
private void expectAddingMember(GroupId g, Contact c) throws Exception {
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID, c);
|
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||||
|
CLIENT_VERSION, c);
|
||||||
will(returnValue(contactGroup));
|
will(returnValue(contactGroup));
|
||||||
}});
|
}});
|
||||||
expectGetSession(noResults, new SessionId(g.getBytes()),
|
expectGetSession(noResults, new SessionId(g.getBytes()),
|
||||||
@@ -243,7 +246,8 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void testRemovingContact() throws Exception {
|
public void testRemovingContact() throws Exception {
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID, contact);
|
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||||
|
CLIENT_VERSION, contact);
|
||||||
will(returnValue(contactGroup));
|
will(returnValue(contactGroup));
|
||||||
oneOf(db).removeGroup(txn, contactGroup);
|
oneOf(db).removeGroup(txn, contactGroup);
|
||||||
}});
|
}});
|
||||||
@@ -457,7 +461,8 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
|||||||
will(returnValue(txn));
|
will(returnValue(txn));
|
||||||
oneOf(db).getContact(txn, contactId);
|
oneOf(db).getContact(txn, contactId);
|
||||||
will(returnValue(contact));
|
will(returnValue(contact));
|
||||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID, contact);
|
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||||
|
CLIENT_VERSION, contact);
|
||||||
will(returnValue(contactGroup));
|
will(returnValue(contactGroup));
|
||||||
}});
|
}});
|
||||||
expectCreateStorageId();
|
expectCreateStorageId();
|
||||||
@@ -488,7 +493,8 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
|||||||
will(returnValue(txn));
|
will(returnValue(txn));
|
||||||
oneOf(db).getContact(txn, contactId);
|
oneOf(db).getContact(txn, contactId);
|
||||||
will(returnValue(contact));
|
will(returnValue(contact));
|
||||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID, contact);
|
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||||
|
CLIENT_VERSION, contact);
|
||||||
will(returnValue(contactGroup));
|
will(returnValue(contactGroup));
|
||||||
oneOf(sessionParser)
|
oneOf(sessionParser)
|
||||||
.parseCreatorSession(contactGroup.getId(), bdfSession);
|
.parseCreatorSession(contactGroup.getId(), bdfSession);
|
||||||
@@ -516,7 +522,8 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
|||||||
will(returnValue(txn));
|
will(returnValue(txn));
|
||||||
oneOf(db).getContact(txn, contactId);
|
oneOf(db).getContact(txn, contactId);
|
||||||
will(returnValue(contact));
|
will(returnValue(contact));
|
||||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID, contact);
|
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||||
|
CLIENT_VERSION, contact);
|
||||||
will(returnValue(contactGroup));
|
will(returnValue(contactGroup));
|
||||||
oneOf(db).endTransaction(txn);
|
oneOf(db).endTransaction(txn);
|
||||||
}});
|
}});
|
||||||
@@ -567,7 +574,8 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
|||||||
will(returnValue(txn));
|
will(returnValue(txn));
|
||||||
oneOf(db).getContact(txn, contactId);
|
oneOf(db).getContact(txn, contactId);
|
||||||
will(returnValue(contact));
|
will(returnValue(contact));
|
||||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID, contact);
|
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||||
|
CLIENT_VERSION, contact);
|
||||||
will(returnValue(contactGroup));
|
will(returnValue(contactGroup));
|
||||||
oneOf(sessionParser)
|
oneOf(sessionParser)
|
||||||
.parseInviteeSession(contactGroup.getId(), bdfSession);
|
.parseInviteeSession(contactGroup.getId(), bdfSession);
|
||||||
@@ -588,7 +596,8 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
|||||||
will(returnValue(txn));
|
will(returnValue(txn));
|
||||||
oneOf(db).getContact(txn, contactId);
|
oneOf(db).getContact(txn, contactId);
|
||||||
will(returnValue(contact));
|
will(returnValue(contact));
|
||||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID, contact);
|
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||||
|
CLIENT_VERSION, contact);
|
||||||
will(returnValue(contactGroup));
|
will(returnValue(contactGroup));
|
||||||
oneOf(sessionParser)
|
oneOf(sessionParser)
|
||||||
.parsePeerSession(contactGroup.getId(), bdfSession);
|
.parsePeerSession(contactGroup.getId(), bdfSession);
|
||||||
@@ -612,7 +621,8 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
|||||||
will(returnValue(txn));
|
will(returnValue(txn));
|
||||||
oneOf(db).getContact(txn, contactId);
|
oneOf(db).getContact(txn, contactId);
|
||||||
will(returnValue(contact));
|
will(returnValue(contact));
|
||||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID, contact);
|
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||||
|
CLIENT_VERSION, contact);
|
||||||
will(returnValue(contactGroup));
|
will(returnValue(contactGroup));
|
||||||
oneOf(db).endTransaction(txn);
|
oneOf(db).endTransaction(txn);
|
||||||
}});
|
}});
|
||||||
@@ -650,7 +660,8 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
|||||||
will(returnValue(txn));
|
will(returnValue(txn));
|
||||||
oneOf(db).getContact(txn, contactId);
|
oneOf(db).getContact(txn, contactId);
|
||||||
will(returnValue(contact));
|
will(returnValue(contact));
|
||||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID, contact);
|
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||||
|
CLIENT_VERSION, contact);
|
||||||
will(returnValue(contactGroup));
|
will(returnValue(contactGroup));
|
||||||
oneOf(messageParser).getMessagesVisibleInUiQuery();
|
oneOf(messageParser).getMessagesVisibleInUiQuery();
|
||||||
will(returnValue(query));
|
will(returnValue(query));
|
||||||
@@ -726,7 +737,8 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
|||||||
will(returnValue(txn));
|
will(returnValue(txn));
|
||||||
oneOf(db).getContacts(txn);
|
oneOf(db).getContacts(txn);
|
||||||
will(returnValue(Collections.singletonList(contact)));
|
will(returnValue(Collections.singletonList(contact)));
|
||||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID, contact);
|
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||||
|
CLIENT_VERSION, contact);
|
||||||
will(returnValue(contactGroup));
|
will(returnValue(contactGroup));
|
||||||
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
|
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
|
||||||
contactGroup.getId(), query);
|
contactGroup.getId(), query);
|
||||||
@@ -793,7 +805,8 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
|||||||
throws Exception {
|
throws Exception {
|
||||||
expectGetSession(oneResult, sessionId, contactGroup.getId());
|
expectGetSession(oneResult, sessionId, contactGroup.getId());
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID, contact);
|
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||||
|
CLIENT_VERSION, contact);
|
||||||
will(returnValue(contactGroup));
|
will(returnValue(contactGroup));
|
||||||
oneOf(db).startTransaction(true);
|
oneOf(db).startTransaction(true);
|
||||||
will(returnValue(txn));
|
will(returnValue(txn));
|
||||||
@@ -847,11 +860,14 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
|||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
oneOf(db).getContacts(txn);
|
oneOf(db).getContacts(txn);
|
||||||
will(returnValue(contacts));
|
will(returnValue(contacts));
|
||||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID, contact);
|
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||||
|
CLIENT_VERSION, contact);
|
||||||
will(returnValue(contactGroup));
|
will(returnValue(contactGroup));
|
||||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID, contact2);
|
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||||
|
CLIENT_VERSION, contact2);
|
||||||
will(returnValue(contactGroup2));
|
will(returnValue(contactGroup2));
|
||||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID, contact3);
|
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||||
|
CLIENT_VERSION, contact3);
|
||||||
will(returnValue(contactGroup3));
|
will(returnValue(contactGroup3));
|
||||||
// session 1
|
// session 1
|
||||||
oneOf(sessionParser).getRole(bdfSession);
|
oneOf(sessionParser).getRole(bdfSession);
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ import java.util.Collection;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.briarproject.briar.api.blog.BlogSharingManager.CLIENT_ID;
|
import static org.briarproject.briar.api.blog.BlogSharingManager.CLIENT_ID;
|
||||||
|
import static org.briarproject.briar.api.blog.BlogSharingManager.CLIENT_VERSION;
|
||||||
import static org.briarproject.briar.test.BriarTestUtils.assertGroupCount;
|
import static org.briarproject.briar.test.BriarTestUtils.assertGroupCount;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
@@ -125,7 +126,7 @@ public class BlogSharingIntegrationTest
|
|||||||
|
|
||||||
// get sharing group and assert group message count
|
// get sharing group and assert group message count
|
||||||
GroupId g = contactGroupFactory.createContactGroup(CLIENT_ID,
|
GroupId g = contactGroupFactory.createContactGroup(CLIENT_ID,
|
||||||
contact1From0).getId();
|
CLIENT_VERSION, contact1From0).getId();
|
||||||
assertGroupCount(messageTracker0, g, 1, 0);
|
assertGroupCount(messageTracker0, g, 1, 0);
|
||||||
|
|
||||||
// sync first request message
|
// sync first request message
|
||||||
@@ -200,7 +201,7 @@ public class BlogSharingIntegrationTest
|
|||||||
|
|
||||||
// get sharing group and assert group message count
|
// get sharing group and assert group message count
|
||||||
GroupId g = contactGroupFactory.createContactGroup(CLIENT_ID,
|
GroupId g = contactGroupFactory.createContactGroup(CLIENT_ID,
|
||||||
contact1From0).getId();
|
CLIENT_VERSION, contact1From0).getId();
|
||||||
assertGroupCount(messageTracker0, g, 1, 0);
|
assertGroupCount(messageTracker0, g, 1, 0);
|
||||||
|
|
||||||
// sync first request message
|
// sync first request message
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
|
|||||||
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
||||||
import static org.briarproject.briar.api.blog.BlogSharingManager.CLIENT_ID;
|
import static org.briarproject.briar.api.blog.BlogSharingManager.CLIENT_ID;
|
||||||
|
import static org.briarproject.briar.api.blog.BlogSharingManager.CLIENT_VERSION;
|
||||||
import static org.briarproject.briar.sharing.SharingConstants.GROUP_KEY_CONTACT_ID;
|
import static org.briarproject.briar.sharing.SharingConstants.GROUP_KEY_CONTACT_ID;
|
||||||
|
|
||||||
public class BlogSharingManagerImplTest extends BrambleMockTestCase {
|
public class BlogSharingManagerImplTest extends BrambleMockTestCase {
|
||||||
@@ -152,7 +153,8 @@ public class BlogSharingManagerImplTest extends BrambleMockTestCase {
|
|||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
oneOf(db).getContacts(txn);
|
oneOf(db).getContacts(txn);
|
||||||
will(returnValue(contacts));
|
will(returnValue(contacts));
|
||||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID, contact);
|
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||||
|
CLIENT_VERSION, contact);
|
||||||
will(returnValue(contactGroup));
|
will(returnValue(contactGroup));
|
||||||
oneOf(db).containsGroup(txn, contactGroup.getId());
|
oneOf(db).containsGroup(txn, contactGroup.getId());
|
||||||
will(returnValue(false));
|
will(returnValue(false));
|
||||||
@@ -185,8 +187,8 @@ public class BlogSharingManagerImplTest extends BrambleMockTestCase {
|
|||||||
new Message(new MessageId(getRandomId()), contactGroup.getId(),
|
new Message(new MessageId(getRandomId()), contactGroup.getId(),
|
||||||
42L, getRandomBytes(1337));
|
42L, getRandomBytes(1337));
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
oneOf(contactGroupFactory)
|
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||||
.createContactGroup(CLIENT_ID, contact);
|
CLIENT_VERSION, contact);
|
||||||
will(returnValue(contactGroup));
|
will(returnValue(contactGroup));
|
||||||
oneOf(sessionParser)
|
oneOf(sessionParser)
|
||||||
.getSessionQuery(new SessionId(blog.getId().getBytes()));
|
.getSessionQuery(new SessionId(blog.getId().getBytes()));
|
||||||
@@ -220,7 +222,8 @@ public class BlogSharingManagerImplTest extends BrambleMockTestCase {
|
|||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
oneOf(db).getContacts(txn);
|
oneOf(db).getContacts(txn);
|
||||||
will(returnValue(contacts));
|
will(returnValue(contacts));
|
||||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID, contact);
|
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||||
|
CLIENT_VERSION, contact);
|
||||||
will(returnValue(contactGroup));
|
will(returnValue(contactGroup));
|
||||||
oneOf(sessionParser)
|
oneOf(sessionParser)
|
||||||
.getSessionQuery(new SessionId(blog.getId().getBytes()));
|
.getSessionQuery(new SessionId(blog.getId().getBytes()));
|
||||||
|
|||||||
@@ -38,6 +38,8 @@ import java.util.List;
|
|||||||
|
|
||||||
import static junit.framework.Assert.assertNotNull;
|
import static junit.framework.Assert.assertNotNull;
|
||||||
import static org.briarproject.bramble.util.StringUtils.getRandomString;
|
import static org.briarproject.bramble.util.StringUtils.getRandomString;
|
||||||
|
import static org.briarproject.briar.api.forum.ForumSharingManager.CLIENT_ID;
|
||||||
|
import static org.briarproject.briar.api.forum.ForumSharingManager.CLIENT_VERSION;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
@@ -399,9 +401,8 @@ public class ForumSharingIntegrationTest
|
|||||||
assertTrue(listener0.responseReceived);
|
assertTrue(listener0.responseReceived);
|
||||||
|
|
||||||
// response and invitation got tracked
|
// response and invitation got tracked
|
||||||
Group group = contactGroupFactory
|
Group group = contactGroupFactory.createContactGroup(CLIENT_ID,
|
||||||
.createContactGroup(ForumSharingManager.CLIENT_ID,
|
CLIENT_VERSION, contact0From1);
|
||||||
contact0From1);
|
|
||||||
assertEquals(2, c1.getMessageTracker().getGroupCount(group.getId())
|
assertEquals(2, c1.getMessageTracker().getGroupCount(group.getId())
|
||||||
.getMsgCount());
|
.getMsgCount());
|
||||||
|
|
||||||
@@ -432,9 +433,8 @@ public class ForumSharingIntegrationTest
|
|||||||
assertEquals(1, forumSharingManager1.getInvitations().size());
|
assertEquals(1, forumSharingManager1.getInvitations().size());
|
||||||
|
|
||||||
// assert that the invitation arrived
|
// assert that the invitation arrived
|
||||||
Group group = contactGroupFactory
|
Group group = contactGroupFactory.createContactGroup(CLIENT_ID,
|
||||||
.createContactGroup(ForumSharingManager.CLIENT_ID,
|
CLIENT_VERSION, contact0From1);
|
||||||
contact0From1);
|
|
||||||
assertEquals(1, c1.getMessageTracker().getGroupCount(group.getId())
|
assertEquals(1, c1.getMessageTracker().getGroupCount(group.getId())
|
||||||
.getMsgCount());
|
.getMsgCount());
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user