mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-20 22:59:54 +01:00
Created TransportPropertyManager facade.
This commit is contained in:
@@ -13,6 +13,7 @@
|
|||||||
<item>org.briarproject.lifecycle.LifecycleModule</item>
|
<item>org.briarproject.lifecycle.LifecycleModule</item>
|
||||||
<item>org.briarproject.messaging.MessagingModule</item>
|
<item>org.briarproject.messaging.MessagingModule</item>
|
||||||
<item>org.briarproject.plugins.AndroidPluginsModule</item>
|
<item>org.briarproject.plugins.AndroidPluginsModule</item>
|
||||||
|
<item>org.briarproject.property.PropertyModule</item>
|
||||||
<item>org.briarproject.sync.SyncModule</item>
|
<item>org.briarproject.sync.SyncModule</item>
|
||||||
<item>org.briarproject.system.AndroidSystemModule</item>
|
<item>org.briarproject.system.AndroidSystemModule</item>
|
||||||
<item>org.briarproject.transport.TransportModule</item>
|
<item>org.briarproject.transport.TransportModule</item>
|
||||||
|
|||||||
@@ -30,11 +30,11 @@ import org.briarproject.android.util.ListLoadingProgressBar;
|
|||||||
import org.briarproject.api.TransportId;
|
import org.briarproject.api.TransportId;
|
||||||
import org.briarproject.api.TransportProperties;
|
import org.briarproject.api.TransportProperties;
|
||||||
import org.briarproject.api.android.AndroidExecutor;
|
import org.briarproject.api.android.AndroidExecutor;
|
||||||
import org.briarproject.api.db.DatabaseComponent;
|
|
||||||
import org.briarproject.api.db.DbException;
|
import org.briarproject.api.db.DbException;
|
||||||
import org.briarproject.api.lifecycle.LifecycleManager;
|
import org.briarproject.api.lifecycle.LifecycleManager;
|
||||||
import org.briarproject.api.plugins.Plugin;
|
import org.briarproject.api.plugins.Plugin;
|
||||||
import org.briarproject.api.plugins.PluginManager;
|
import org.briarproject.api.plugins.PluginManager;
|
||||||
|
import org.briarproject.api.property.TransportPropertyManager;
|
||||||
import org.briarproject.util.StringUtils;
|
import org.briarproject.util.StringUtils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -84,7 +84,7 @@ public class TestingActivity extends BriarActivity implements OnClickListener {
|
|||||||
@Inject private AndroidExecutor androidExecutor;
|
@Inject private AndroidExecutor androidExecutor;
|
||||||
@Inject private PluginManager pluginManager;
|
@Inject private PluginManager pluginManager;
|
||||||
@Inject private LifecycleManager lifecycleManager;
|
@Inject private LifecycleManager lifecycleManager;
|
||||||
@Inject private DatabaseComponent db;
|
@Inject private TransportPropertyManager transportPropertyManager;
|
||||||
private ScrollView scroll = null;
|
private ScrollView scroll = null;
|
||||||
private ListLoadingProgressBar progress = null;
|
private ListLoadingProgressBar progress = null;
|
||||||
private LinearLayout status = null;
|
private LinearLayout status = null;
|
||||||
@@ -364,7 +364,7 @@ public class TestingActivity extends BriarActivity implements OnClickListener {
|
|||||||
Map<TransportId, TransportProperties> props = Collections.emptyMap();
|
Map<TransportId, TransportProperties> props = Collections.emptyMap();
|
||||||
try {
|
try {
|
||||||
lifecycleManager.waitForDatabase();
|
lifecycleManager.waitForDatabase();
|
||||||
props = db.getLocalProperties();
|
props = transportPropertyManager.getLocalProperties();
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
LOG.info("Interrupted while waiting for database");
|
LOG.info("Interrupted while waiting for database");
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package org.briarproject.api.messaging;
|
package org.briarproject.api.messaging;
|
||||||
|
|
||||||
import org.briarproject.api.contact.ContactId;
|
import org.briarproject.api.contact.ContactId;
|
||||||
|
import org.briarproject.api.crypto.SecretKey;
|
||||||
import org.briarproject.api.db.DbException;
|
import org.briarproject.api.db.DbException;
|
||||||
import org.briarproject.api.sync.GroupId;
|
import org.briarproject.api.sync.GroupId;
|
||||||
import org.briarproject.api.sync.Message;
|
import org.briarproject.api.sync.Message;
|
||||||
@@ -10,6 +11,12 @@ import java.util.Collection;
|
|||||||
|
|
||||||
public interface MessagingManager {
|
public interface MessagingManager {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Informs the messaging manager that a new contact has been added.
|
||||||
|
* Creates a private conversation with the contact.
|
||||||
|
*/
|
||||||
|
void addContact(ContactId c, SecretKey master) throws DbException;
|
||||||
|
|
||||||
/** Stores a local private message. */
|
/** Stores a local private message. */
|
||||||
void addLocalMessage(Message m) throws DbException;
|
void addLocalMessage(Message m) throws DbException;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package org.briarproject.api.property;
|
||||||
|
|
||||||
|
import org.briarproject.api.TransportId;
|
||||||
|
import org.briarproject.api.TransportProperties;
|
||||||
|
import org.briarproject.api.contact.ContactId;
|
||||||
|
import org.briarproject.api.db.DbException;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public interface TransportPropertyManager {
|
||||||
|
|
||||||
|
/** Returns the local transport properties for all transports. */
|
||||||
|
Map<TransportId, TransportProperties> getLocalProperties()
|
||||||
|
throws DbException;
|
||||||
|
|
||||||
|
/** Returns the local transport properties for the given transport. */
|
||||||
|
TransportProperties getLocalProperties(TransportId t) throws DbException;
|
||||||
|
|
||||||
|
/** Returns all remote transport properties for the given transport. */
|
||||||
|
Map<ContactId, TransportProperties> getRemoteProperties(TransportId t)
|
||||||
|
throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Merges the given properties with the existing local properties for the
|
||||||
|
* given transport.
|
||||||
|
*/
|
||||||
|
void mergeLocalProperties(TransportId t, TransportProperties p)
|
||||||
|
throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the remote transport properties for the given contact, replacing
|
||||||
|
* any existing properties.
|
||||||
|
*/
|
||||||
|
void setRemoteProperties(ContactId c,
|
||||||
|
Map<TransportId, TransportProperties> p) throws DbException;
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@ package org.briarproject.api.transport;
|
|||||||
|
|
||||||
import org.briarproject.api.TransportId;
|
import org.briarproject.api.TransportId;
|
||||||
import org.briarproject.api.contact.ContactId;
|
import org.briarproject.api.contact.ContactId;
|
||||||
import org.briarproject.api.db.DbException;
|
import org.briarproject.api.crypto.SecretKey;
|
||||||
import org.briarproject.api.lifecycle.Service;
|
import org.briarproject.api.lifecycle.Service;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@@ -14,11 +14,13 @@ import java.util.Collection;
|
|||||||
public interface KeyManager extends Service {
|
public interface KeyManager extends Service {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Informs the key manager that a new contact has been added.
|
* Informs the key manager that a new contact has been added. Derives and
|
||||||
|
* stores transport keys for communicating with the contact.
|
||||||
* {@link StreamContext StreamContexts} for the contact can be created
|
* {@link StreamContext StreamContexts} for the contact can be created
|
||||||
* after this method has returned.
|
* after this method has returned.
|
||||||
*/
|
*/
|
||||||
void contactAdded(ContactId c, Collection<TransportKeys> keys);
|
void addContact(ContactId c, Collection<TransportId> transports,
|
||||||
|
SecretKey master, long timestamp, boolean alice);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a {@link StreamContext} for sending a stream to the given
|
* Returns a {@link StreamContext} for sending a stream to the given
|
||||||
@@ -29,8 +31,8 @@ public interface KeyManager extends Service {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Looks up the given tag and returns a {@link StreamContext} for reading
|
* Looks up the given tag and returns a {@link StreamContext} for reading
|
||||||
* from the corresponding stream if the tag was expected, or null if the
|
* from the corresponding stream, or null if an error occurs or the tag was
|
||||||
* tag was unexpected.
|
* unexpected.
|
||||||
*/
|
*/
|
||||||
StreamContext recogniseTag(TransportId t, byte[] tag) throws DbException;
|
StreamContext getStreamContext(TransportId t, byte[] tag);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package org.briarproject.invitation;
|
|||||||
|
|
||||||
import org.briarproject.api.TransportId;
|
import org.briarproject.api.TransportId;
|
||||||
import org.briarproject.api.TransportProperties;
|
import org.briarproject.api.TransportProperties;
|
||||||
|
import org.briarproject.api.contact.ContactManager;
|
||||||
import org.briarproject.api.crypto.CryptoComponent;
|
import org.briarproject.api.crypto.CryptoComponent;
|
||||||
import org.briarproject.api.crypto.PseudoRandom;
|
import org.briarproject.api.crypto.PseudoRandom;
|
||||||
import org.briarproject.api.crypto.SecretKey;
|
import org.briarproject.api.crypto.SecretKey;
|
||||||
@@ -9,14 +10,15 @@ import org.briarproject.api.data.Reader;
|
|||||||
import org.briarproject.api.data.ReaderFactory;
|
import org.briarproject.api.data.ReaderFactory;
|
||||||
import org.briarproject.api.data.Writer;
|
import org.briarproject.api.data.Writer;
|
||||||
import org.briarproject.api.data.WriterFactory;
|
import org.briarproject.api.data.WriterFactory;
|
||||||
import org.briarproject.api.db.DatabaseComponent;
|
|
||||||
import org.briarproject.api.db.DbException;
|
import org.briarproject.api.db.DbException;
|
||||||
import org.briarproject.api.identity.Author;
|
import org.briarproject.api.identity.Author;
|
||||||
import org.briarproject.api.identity.AuthorFactory;
|
import org.briarproject.api.identity.AuthorFactory;
|
||||||
import org.briarproject.api.identity.LocalAuthor;
|
import org.briarproject.api.identity.LocalAuthor;
|
||||||
|
import org.briarproject.api.messaging.MessagingManager;
|
||||||
import org.briarproject.api.plugins.ConnectionManager;
|
import org.briarproject.api.plugins.ConnectionManager;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexPlugin;
|
import org.briarproject.api.plugins.duplex.DuplexPlugin;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexTransportConnection;
|
import org.briarproject.api.plugins.duplex.DuplexTransportConnection;
|
||||||
|
import org.briarproject.api.property.TransportPropertyManager;
|
||||||
import org.briarproject.api.sync.GroupFactory;
|
import org.briarproject.api.sync.GroupFactory;
|
||||||
import org.briarproject.api.system.Clock;
|
import org.briarproject.api.system.Clock;
|
||||||
import org.briarproject.api.transport.KeyManager;
|
import org.briarproject.api.transport.KeyManager;
|
||||||
@@ -39,20 +41,24 @@ class AliceConnector extends Connector {
|
|||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(AliceConnector.class.getName());
|
Logger.getLogger(AliceConnector.class.getName());
|
||||||
|
|
||||||
AliceConnector(CryptoComponent crypto, DatabaseComponent db,
|
AliceConnector(CryptoComponent crypto,
|
||||||
ReaderFactory readerFactory, WriterFactory writerFactory,
|
ReaderFactory readerFactory, WriterFactory writerFactory,
|
||||||
StreamReaderFactory streamReaderFactory,
|
StreamReaderFactory streamReaderFactory,
|
||||||
StreamWriterFactory streamWriterFactory,
|
StreamWriterFactory streamWriterFactory,
|
||||||
AuthorFactory authorFactory, GroupFactory groupFactory,
|
AuthorFactory authorFactory, GroupFactory groupFactory,
|
||||||
KeyManager keyManager, ConnectionManager connectionManager,
|
KeyManager keyManager, ConnectionManager connectionManager,
|
||||||
Clock clock, boolean reuseConnection, ConnectorGroup group,
|
ContactManager contactManager, MessagingManager messagingManager,
|
||||||
DuplexPlugin plugin, LocalAuthor localAuthor,
|
TransportPropertyManager transportPropertyManager, Clock clock,
|
||||||
|
boolean reuseConnection, ConnectorGroup group, DuplexPlugin plugin,
|
||||||
|
LocalAuthor localAuthor,
|
||||||
Map<TransportId, TransportProperties> localProps,
|
Map<TransportId, TransportProperties> localProps,
|
||||||
PseudoRandom random) {
|
PseudoRandom random) {
|
||||||
super(crypto, db, readerFactory, writerFactory, streamReaderFactory,
|
super(crypto, readerFactory, writerFactory, streamReaderFactory,
|
||||||
streamWriterFactory, authorFactory, groupFactory,
|
streamWriterFactory, authorFactory, groupFactory,
|
||||||
keyManager, connectionManager, clock, reuseConnection, group,
|
keyManager, connectionManager, contactManager,
|
||||||
plugin, localAuthor, localProps, random);
|
messagingManager, transportPropertyManager, clock,
|
||||||
|
reuseConnection, group, plugin, localAuthor, localProps,
|
||||||
|
random);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package org.briarproject.invitation;
|
|||||||
|
|
||||||
import org.briarproject.api.TransportId;
|
import org.briarproject.api.TransportId;
|
||||||
import org.briarproject.api.TransportProperties;
|
import org.briarproject.api.TransportProperties;
|
||||||
|
import org.briarproject.api.contact.ContactManager;
|
||||||
import org.briarproject.api.crypto.CryptoComponent;
|
import org.briarproject.api.crypto.CryptoComponent;
|
||||||
import org.briarproject.api.crypto.PseudoRandom;
|
import org.briarproject.api.crypto.PseudoRandom;
|
||||||
import org.briarproject.api.crypto.SecretKey;
|
import org.briarproject.api.crypto.SecretKey;
|
||||||
@@ -9,14 +10,15 @@ import org.briarproject.api.data.Reader;
|
|||||||
import org.briarproject.api.data.ReaderFactory;
|
import org.briarproject.api.data.ReaderFactory;
|
||||||
import org.briarproject.api.data.Writer;
|
import org.briarproject.api.data.Writer;
|
||||||
import org.briarproject.api.data.WriterFactory;
|
import org.briarproject.api.data.WriterFactory;
|
||||||
import org.briarproject.api.db.DatabaseComponent;
|
|
||||||
import org.briarproject.api.db.DbException;
|
import org.briarproject.api.db.DbException;
|
||||||
import org.briarproject.api.identity.Author;
|
import org.briarproject.api.identity.Author;
|
||||||
import org.briarproject.api.identity.AuthorFactory;
|
import org.briarproject.api.identity.AuthorFactory;
|
||||||
import org.briarproject.api.identity.LocalAuthor;
|
import org.briarproject.api.identity.LocalAuthor;
|
||||||
|
import org.briarproject.api.messaging.MessagingManager;
|
||||||
import org.briarproject.api.plugins.ConnectionManager;
|
import org.briarproject.api.plugins.ConnectionManager;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexPlugin;
|
import org.briarproject.api.plugins.duplex.DuplexPlugin;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexTransportConnection;
|
import org.briarproject.api.plugins.duplex.DuplexTransportConnection;
|
||||||
|
import org.briarproject.api.property.TransportPropertyManager;
|
||||||
import org.briarproject.api.sync.GroupFactory;
|
import org.briarproject.api.sync.GroupFactory;
|
||||||
import org.briarproject.api.system.Clock;
|
import org.briarproject.api.system.Clock;
|
||||||
import org.briarproject.api.transport.KeyManager;
|
import org.briarproject.api.transport.KeyManager;
|
||||||
@@ -39,20 +41,24 @@ class BobConnector extends Connector {
|
|||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(BobConnector.class.getName());
|
Logger.getLogger(BobConnector.class.getName());
|
||||||
|
|
||||||
BobConnector(CryptoComponent crypto, DatabaseComponent db,
|
BobConnector(CryptoComponent crypto,
|
||||||
ReaderFactory readerFactory, WriterFactory writerFactory,
|
ReaderFactory readerFactory, WriterFactory writerFactory,
|
||||||
StreamReaderFactory streamReaderFactory,
|
StreamReaderFactory streamReaderFactory,
|
||||||
StreamWriterFactory streamWriterFactory,
|
StreamWriterFactory streamWriterFactory,
|
||||||
AuthorFactory authorFactory, GroupFactory groupFactory,
|
AuthorFactory authorFactory, GroupFactory groupFactory,
|
||||||
KeyManager keyManager, ConnectionManager connectionManager,
|
KeyManager keyManager, ConnectionManager connectionManager,
|
||||||
Clock clock, boolean reuseConnection, ConnectorGroup group,
|
ContactManager contactManager, MessagingManager messagingManager,
|
||||||
DuplexPlugin plugin, LocalAuthor localAuthor,
|
TransportPropertyManager transportPropertyManager, Clock clock,
|
||||||
|
boolean reuseConnection, ConnectorGroup group, DuplexPlugin plugin,
|
||||||
|
LocalAuthor localAuthor,
|
||||||
Map<TransportId, TransportProperties> localProps,
|
Map<TransportId, TransportProperties> localProps,
|
||||||
PseudoRandom random) {
|
PseudoRandom random) {
|
||||||
super(crypto, db, readerFactory, writerFactory, streamReaderFactory,
|
super(crypto, readerFactory, writerFactory, streamReaderFactory,
|
||||||
streamWriterFactory, authorFactory, groupFactory,
|
streamWriterFactory, authorFactory, groupFactory,
|
||||||
keyManager, connectionManager, clock, reuseConnection, group,
|
keyManager, connectionManager, contactManager,
|
||||||
plugin, localAuthor, localProps, random);
|
messagingManager, transportPropertyManager, clock,
|
||||||
|
reuseConnection, group, plugin, localAuthor, localProps,
|
||||||
|
random);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import org.briarproject.api.FormatException;
|
|||||||
import org.briarproject.api.TransportId;
|
import org.briarproject.api.TransportId;
|
||||||
import org.briarproject.api.TransportProperties;
|
import org.briarproject.api.TransportProperties;
|
||||||
import org.briarproject.api.contact.ContactId;
|
import org.briarproject.api.contact.ContactId;
|
||||||
|
import org.briarproject.api.contact.ContactManager;
|
||||||
import org.briarproject.api.crypto.CryptoComponent;
|
import org.briarproject.api.crypto.CryptoComponent;
|
||||||
import org.briarproject.api.crypto.KeyPair;
|
import org.briarproject.api.crypto.KeyPair;
|
||||||
import org.briarproject.api.crypto.KeyParser;
|
import org.briarproject.api.crypto.KeyParser;
|
||||||
@@ -15,28 +16,25 @@ import org.briarproject.api.data.Reader;
|
|||||||
import org.briarproject.api.data.ReaderFactory;
|
import org.briarproject.api.data.ReaderFactory;
|
||||||
import org.briarproject.api.data.Writer;
|
import org.briarproject.api.data.Writer;
|
||||||
import org.briarproject.api.data.WriterFactory;
|
import org.briarproject.api.data.WriterFactory;
|
||||||
import org.briarproject.api.db.DatabaseComponent;
|
|
||||||
import org.briarproject.api.db.DbException;
|
import org.briarproject.api.db.DbException;
|
||||||
import org.briarproject.api.identity.Author;
|
import org.briarproject.api.identity.Author;
|
||||||
import org.briarproject.api.identity.AuthorFactory;
|
import org.briarproject.api.identity.AuthorFactory;
|
||||||
import org.briarproject.api.identity.LocalAuthor;
|
import org.briarproject.api.identity.LocalAuthor;
|
||||||
|
import org.briarproject.api.messaging.MessagingManager;
|
||||||
import org.briarproject.api.plugins.ConnectionManager;
|
import org.briarproject.api.plugins.ConnectionManager;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexPlugin;
|
import org.briarproject.api.plugins.duplex.DuplexPlugin;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexTransportConnection;
|
import org.briarproject.api.plugins.duplex.DuplexTransportConnection;
|
||||||
import org.briarproject.api.sync.Group;
|
import org.briarproject.api.property.TransportPropertyManager;
|
||||||
import org.briarproject.api.sync.GroupFactory;
|
import org.briarproject.api.sync.GroupFactory;
|
||||||
import org.briarproject.api.system.Clock;
|
import org.briarproject.api.system.Clock;
|
||||||
import org.briarproject.api.transport.KeyManager;
|
import org.briarproject.api.transport.KeyManager;
|
||||||
import org.briarproject.api.transport.StreamReaderFactory;
|
import org.briarproject.api.transport.StreamReaderFactory;
|
||||||
import org.briarproject.api.transport.StreamWriterFactory;
|
import org.briarproject.api.transport.StreamWriterFactory;
|
||||||
import org.briarproject.api.transport.TransportKeys;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.security.GeneralSecurityException;
|
import java.security.GeneralSecurityException;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
@@ -50,7 +48,6 @@ import static org.briarproject.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENG
|
|||||||
import static org.briarproject.api.identity.AuthorConstants.MAX_PUBLIC_KEY_LENGTH;
|
import static org.briarproject.api.identity.AuthorConstants.MAX_PUBLIC_KEY_LENGTH;
|
||||||
import static org.briarproject.api.identity.AuthorConstants.MAX_SIGNATURE_LENGTH;
|
import static org.briarproject.api.identity.AuthorConstants.MAX_SIGNATURE_LENGTH;
|
||||||
import static org.briarproject.api.invitation.InvitationConstants.CONNECTION_TIMEOUT;
|
import static org.briarproject.api.invitation.InvitationConstants.CONNECTION_TIMEOUT;
|
||||||
import static org.briarproject.api.transport.TransportConstants.MAX_CLOCK_DIFFERENCE;
|
|
||||||
|
|
||||||
// FIXME: This class has way too many dependencies
|
// FIXME: This class has way too many dependencies
|
||||||
abstract class Connector extends Thread {
|
abstract class Connector extends Thread {
|
||||||
@@ -59,7 +56,6 @@ abstract class Connector extends Thread {
|
|||||||
Logger.getLogger(Connector.class.getName());
|
Logger.getLogger(Connector.class.getName());
|
||||||
|
|
||||||
protected final CryptoComponent crypto;
|
protected final CryptoComponent crypto;
|
||||||
protected final DatabaseComponent db;
|
|
||||||
protected final ReaderFactory readerFactory;
|
protected final ReaderFactory readerFactory;
|
||||||
protected final WriterFactory writerFactory;
|
protected final WriterFactory writerFactory;
|
||||||
protected final StreamReaderFactory streamReaderFactory;
|
protected final StreamReaderFactory streamReaderFactory;
|
||||||
@@ -68,6 +64,9 @@ abstract class Connector extends Thread {
|
|||||||
protected final GroupFactory groupFactory;
|
protected final GroupFactory groupFactory;
|
||||||
protected final KeyManager keyManager;
|
protected final KeyManager keyManager;
|
||||||
protected final ConnectionManager connectionManager;
|
protected final ConnectionManager connectionManager;
|
||||||
|
protected final ContactManager contactManager;
|
||||||
|
protected final MessagingManager messagingManager;
|
||||||
|
protected final TransportPropertyManager transportPropertyManager;
|
||||||
protected final Clock clock;
|
protected final Clock clock;
|
||||||
protected final boolean reuseConnection;
|
protected final boolean reuseConnection;
|
||||||
protected final ConnectorGroup group;
|
protected final ConnectorGroup group;
|
||||||
@@ -83,19 +82,20 @@ abstract class Connector extends Thread {
|
|||||||
|
|
||||||
private volatile ContactId contactId = null;
|
private volatile ContactId contactId = null;
|
||||||
|
|
||||||
Connector(CryptoComponent crypto, DatabaseComponent db,
|
Connector(CryptoComponent crypto,
|
||||||
ReaderFactory readerFactory, WriterFactory writerFactory,
|
ReaderFactory readerFactory, WriterFactory writerFactory,
|
||||||
StreamReaderFactory streamReaderFactory,
|
StreamReaderFactory streamReaderFactory,
|
||||||
StreamWriterFactory streamWriterFactory,
|
StreamWriterFactory streamWriterFactory,
|
||||||
AuthorFactory authorFactory, GroupFactory groupFactory,
|
AuthorFactory authorFactory, GroupFactory groupFactory,
|
||||||
KeyManager keyManager, ConnectionManager connectionManager,
|
KeyManager keyManager, ConnectionManager connectionManager,
|
||||||
Clock clock, boolean reuseConnection, ConnectorGroup group,
|
ContactManager contactManager, MessagingManager messagingManager,
|
||||||
DuplexPlugin plugin, LocalAuthor localAuthor,
|
TransportPropertyManager transportPropertyManager, Clock clock,
|
||||||
|
boolean reuseConnection, ConnectorGroup group, DuplexPlugin plugin,
|
||||||
|
LocalAuthor localAuthor,
|
||||||
Map<TransportId, TransportProperties> localProps,
|
Map<TransportId, TransportProperties> localProps,
|
||||||
PseudoRandom random) {
|
PseudoRandom random) {
|
||||||
super("Connector");
|
super("Connector");
|
||||||
this.crypto = crypto;
|
this.crypto = crypto;
|
||||||
this.db = db;
|
|
||||||
this.readerFactory = readerFactory;
|
this.readerFactory = readerFactory;
|
||||||
this.writerFactory = writerFactory;
|
this.writerFactory = writerFactory;
|
||||||
this.streamReaderFactory = streamReaderFactory;
|
this.streamReaderFactory = streamReaderFactory;
|
||||||
@@ -104,6 +104,9 @@ abstract class Connector extends Thread {
|
|||||||
this.groupFactory = groupFactory;
|
this.groupFactory = groupFactory;
|
||||||
this.keyManager = keyManager;
|
this.keyManager = keyManager;
|
||||||
this.connectionManager = connectionManager;
|
this.connectionManager = connectionManager;
|
||||||
|
this.contactManager = contactManager;
|
||||||
|
this.messagingManager = messagingManager;
|
||||||
|
this.transportPropertyManager = transportPropertyManager;
|
||||||
this.clock = clock;
|
this.clock = clock;
|
||||||
this.reuseConnection = reuseConnection;
|
this.reuseConnection = reuseConnection;
|
||||||
this.group = group;
|
this.group = group;
|
||||||
@@ -274,31 +277,15 @@ abstract class Connector extends Thread {
|
|||||||
Map<TransportId, TransportProperties> remoteProps, SecretKey master,
|
Map<TransportId, TransportProperties> remoteProps, SecretKey master,
|
||||||
long timestamp, boolean alice) throws DbException {
|
long timestamp, boolean alice) throws DbException {
|
||||||
// Add the contact to the database
|
// Add the contact to the database
|
||||||
contactId = db.addContact(remoteAuthor, localAuthor.getId());
|
contactId = contactManager.addContact(remoteAuthor,
|
||||||
// Create and store the inbox group
|
localAuthor.getId());
|
||||||
byte[] salt = crypto.deriveGroupSalt(master);
|
// Create a private messaging conversation
|
||||||
Group inbox = groupFactory.createGroup("Inbox", salt);
|
messagingManager.addContact(contactId, master);
|
||||||
db.addGroup(inbox);
|
|
||||||
db.setInboxGroup(contactId, inbox);
|
|
||||||
// Store the remote transport properties
|
// Store the remote transport properties
|
||||||
db.setRemoteProperties(contactId, remoteProps);
|
transportPropertyManager.setRemoteProperties(contactId, remoteProps);
|
||||||
// Derive transport keys for each transport shared with the contact
|
// Derive transport keys for each transport shared with the contact
|
||||||
Map<TransportId, Integer> latencies = db.getTransportLatencies();
|
keyManager.addContact(contactId, remoteProps.keySet(), master,
|
||||||
List<TransportKeys> keys = new ArrayList<TransportKeys>();
|
timestamp, alice);
|
||||||
for (TransportId t : localProps.keySet()) {
|
|
||||||
if (remoteProps.containsKey(t) && latencies.containsKey(t)) {
|
|
||||||
// Work out what rotation period the timestamp belongs to
|
|
||||||
long latency = latencies.get(t);
|
|
||||||
long rotationPeriodLength = latency + MAX_CLOCK_DIFFERENCE;
|
|
||||||
long rotationPeriod = timestamp / rotationPeriodLength;
|
|
||||||
// Derive the transport keys
|
|
||||||
TransportKeys k = crypto.deriveTransportKeys(t, master,
|
|
||||||
rotationPeriod, alice);
|
|
||||||
db.addTransportKeys(contactId, k);
|
|
||||||
keys.add(k);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
keyManager.contactAdded(contactId, keys);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void tryToClose(DuplexTransportConnection conn,
|
protected void tryToClose(DuplexTransportConnection conn,
|
||||||
|
|||||||
@@ -2,22 +2,25 @@ package org.briarproject.invitation;
|
|||||||
|
|
||||||
import org.briarproject.api.TransportId;
|
import org.briarproject.api.TransportId;
|
||||||
import org.briarproject.api.TransportProperties;
|
import org.briarproject.api.TransportProperties;
|
||||||
|
import org.briarproject.api.contact.ContactManager;
|
||||||
import org.briarproject.api.crypto.CryptoComponent;
|
import org.briarproject.api.crypto.CryptoComponent;
|
||||||
import org.briarproject.api.crypto.PseudoRandom;
|
import org.briarproject.api.crypto.PseudoRandom;
|
||||||
import org.briarproject.api.data.ReaderFactory;
|
import org.briarproject.api.data.ReaderFactory;
|
||||||
import org.briarproject.api.data.WriterFactory;
|
import org.briarproject.api.data.WriterFactory;
|
||||||
import org.briarproject.api.db.DatabaseComponent;
|
|
||||||
import org.briarproject.api.db.DbException;
|
import org.briarproject.api.db.DbException;
|
||||||
import org.briarproject.api.identity.Author;
|
import org.briarproject.api.identity.Author;
|
||||||
import org.briarproject.api.identity.AuthorFactory;
|
import org.briarproject.api.identity.AuthorFactory;
|
||||||
import org.briarproject.api.identity.AuthorId;
|
import org.briarproject.api.identity.AuthorId;
|
||||||
|
import org.briarproject.api.identity.IdentityManager;
|
||||||
import org.briarproject.api.identity.LocalAuthor;
|
import org.briarproject.api.identity.LocalAuthor;
|
||||||
import org.briarproject.api.invitation.InvitationListener;
|
import org.briarproject.api.invitation.InvitationListener;
|
||||||
import org.briarproject.api.invitation.InvitationState;
|
import org.briarproject.api.invitation.InvitationState;
|
||||||
import org.briarproject.api.invitation.InvitationTask;
|
import org.briarproject.api.invitation.InvitationTask;
|
||||||
|
import org.briarproject.api.messaging.MessagingManager;
|
||||||
import org.briarproject.api.plugins.ConnectionManager;
|
import org.briarproject.api.plugins.ConnectionManager;
|
||||||
import org.briarproject.api.plugins.PluginManager;
|
import org.briarproject.api.plugins.PluginManager;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexPlugin;
|
import org.briarproject.api.plugins.duplex.DuplexPlugin;
|
||||||
|
import org.briarproject.api.property.TransportPropertyManager;
|
||||||
import org.briarproject.api.sync.GroupFactory;
|
import org.briarproject.api.sync.GroupFactory;
|
||||||
import org.briarproject.api.system.Clock;
|
import org.briarproject.api.system.Clock;
|
||||||
import org.briarproject.api.transport.KeyManager;
|
import org.briarproject.api.transport.KeyManager;
|
||||||
@@ -45,7 +48,6 @@ class ConnectorGroup extends Thread implements InvitationTask {
|
|||||||
Logger.getLogger(ConnectorGroup.class.getName());
|
Logger.getLogger(ConnectorGroup.class.getName());
|
||||||
|
|
||||||
private final CryptoComponent crypto;
|
private final CryptoComponent crypto;
|
||||||
private final DatabaseComponent db;
|
|
||||||
private final ReaderFactory readerFactory;
|
private final ReaderFactory readerFactory;
|
||||||
private final WriterFactory writerFactory;
|
private final WriterFactory writerFactory;
|
||||||
private final StreamReaderFactory streamReaderFactory;
|
private final StreamReaderFactory streamReaderFactory;
|
||||||
@@ -54,6 +56,10 @@ class ConnectorGroup extends Thread implements InvitationTask {
|
|||||||
private final GroupFactory groupFactory;
|
private final GroupFactory groupFactory;
|
||||||
private final KeyManager keyManager;
|
private final KeyManager keyManager;
|
||||||
private final ConnectionManager connectionManager;
|
private final ConnectionManager connectionManager;
|
||||||
|
private final IdentityManager identityManager;
|
||||||
|
private final ContactManager contactManager;
|
||||||
|
private final MessagingManager messagingManager;
|
||||||
|
private final TransportPropertyManager transportPropertyManager;
|
||||||
private final Clock clock;
|
private final Clock clock;
|
||||||
private final PluginManager pluginManager;
|
private final PluginManager pluginManager;
|
||||||
private final AuthorId localAuthorId;
|
private final AuthorId localAuthorId;
|
||||||
@@ -71,18 +77,20 @@ class ConnectorGroup extends Thread implements InvitationTask {
|
|||||||
private boolean localMatched = false, remoteMatched = false;
|
private boolean localMatched = false, remoteMatched = false;
|
||||||
private String remoteName = null;
|
private String remoteName = null;
|
||||||
|
|
||||||
ConnectorGroup(CryptoComponent crypto, DatabaseComponent db,
|
ConnectorGroup(CryptoComponent crypto,
|
||||||
ReaderFactory readerFactory, WriterFactory writerFactory,
|
ReaderFactory readerFactory, WriterFactory writerFactory,
|
||||||
StreamReaderFactory streamReaderFactory,
|
StreamReaderFactory streamReaderFactory,
|
||||||
StreamWriterFactory streamWriterFactory,
|
StreamWriterFactory streamWriterFactory,
|
||||||
AuthorFactory authorFactory, GroupFactory groupFactory,
|
AuthorFactory authorFactory, GroupFactory groupFactory,
|
||||||
KeyManager keyManager, ConnectionManager connectionManager,
|
KeyManager keyManager, ConnectionManager connectionManager,
|
||||||
Clock clock, PluginManager pluginManager, AuthorId localAuthorId,
|
IdentityManager identityManager, ContactManager contactManager,
|
||||||
|
MessagingManager messagingManager,
|
||||||
|
TransportPropertyManager transportPropertyManager, Clock clock,
|
||||||
|
PluginManager pluginManager, AuthorId localAuthorId,
|
||||||
int localInvitationCode, int remoteInvitationCode,
|
int localInvitationCode, int remoteInvitationCode,
|
||||||
boolean reuseConnection) {
|
boolean reuseConnection) {
|
||||||
super("ConnectorGroup");
|
super("ConnectorGroup");
|
||||||
this.crypto = crypto;
|
this.crypto = crypto;
|
||||||
this.db = db;
|
|
||||||
this.readerFactory = readerFactory;
|
this.readerFactory = readerFactory;
|
||||||
this.writerFactory = writerFactory;
|
this.writerFactory = writerFactory;
|
||||||
this.streamReaderFactory = streamReaderFactory;
|
this.streamReaderFactory = streamReaderFactory;
|
||||||
@@ -91,6 +99,10 @@ class ConnectorGroup extends Thread implements InvitationTask {
|
|||||||
this.groupFactory = groupFactory;
|
this.groupFactory = groupFactory;
|
||||||
this.keyManager = keyManager;
|
this.keyManager = keyManager;
|
||||||
this.connectionManager = connectionManager;
|
this.connectionManager = connectionManager;
|
||||||
|
this.identityManager = identityManager;
|
||||||
|
this.contactManager = contactManager;
|
||||||
|
this.messagingManager = messagingManager;
|
||||||
|
this.transportPropertyManager = transportPropertyManager;
|
||||||
this.clock = clock;
|
this.clock = clock;
|
||||||
this.pluginManager = pluginManager;
|
this.pluginManager = pluginManager;
|
||||||
this.localAuthorId = localAuthorId;
|
this.localAuthorId = localAuthorId;
|
||||||
@@ -130,8 +142,8 @@ class ConnectorGroup extends Thread implements InvitationTask {
|
|||||||
Map<TransportId, TransportProperties> localProps;
|
Map<TransportId, TransportProperties> localProps;
|
||||||
// Load the local pseudonym and transport properties
|
// Load the local pseudonym and transport properties
|
||||||
try {
|
try {
|
||||||
localAuthor = db.getLocalAuthor(localAuthorId);
|
localAuthor = identityManager.getLocalAuthor(localAuthorId);
|
||||||
localProps = db.getLocalProperties();
|
localProps = transportPropertyManager.getLocalProperties();
|
||||||
} catch (DbException e) {
|
} catch (DbException e) {
|
||||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||||
lock.lock();
|
lock.lock();
|
||||||
@@ -185,9 +197,10 @@ class ConnectorGroup extends Thread implements InvitationTask {
|
|||||||
Map<TransportId, TransportProperties> localProps) {
|
Map<TransportId, TransportProperties> localProps) {
|
||||||
PseudoRandom random = crypto.getPseudoRandom(localInvitationCode,
|
PseudoRandom random = crypto.getPseudoRandom(localInvitationCode,
|
||||||
remoteInvitationCode);
|
remoteInvitationCode);
|
||||||
return new AliceConnector(crypto, db, readerFactory, writerFactory,
|
return new AliceConnector(crypto, readerFactory, writerFactory,
|
||||||
streamReaderFactory, streamWriterFactory, authorFactory,
|
streamReaderFactory, streamWriterFactory, authorFactory,
|
||||||
groupFactory, keyManager, connectionManager, clock,
|
groupFactory, keyManager, connectionManager, contactManager,
|
||||||
|
messagingManager, transportPropertyManager, clock,
|
||||||
reuseConnection, this, plugin, localAuthor, localProps, random);
|
reuseConnection, this, plugin, localAuthor, localProps, random);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,9 +209,10 @@ class ConnectorGroup extends Thread implements InvitationTask {
|
|||||||
Map<TransportId, TransportProperties> localProps) {
|
Map<TransportId, TransportProperties> localProps) {
|
||||||
PseudoRandom random = crypto.getPseudoRandom(remoteInvitationCode,
|
PseudoRandom random = crypto.getPseudoRandom(remoteInvitationCode,
|
||||||
localInvitationCode);
|
localInvitationCode);
|
||||||
return new BobConnector(crypto, db, readerFactory, writerFactory,
|
return new BobConnector(crypto, readerFactory, writerFactory,
|
||||||
streamReaderFactory, streamWriterFactory, authorFactory,
|
streamReaderFactory, streamWriterFactory, authorFactory,
|
||||||
groupFactory, keyManager, connectionManager, clock,
|
groupFactory, keyManager, connectionManager, contactManager,
|
||||||
|
messagingManager, transportPropertyManager, clock,
|
||||||
reuseConnection, this, plugin, localAuthor, localProps, random);
|
reuseConnection, this, plugin, localAuthor, localProps, random);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,18 @@
|
|||||||
package org.briarproject.invitation;
|
package org.briarproject.invitation;
|
||||||
|
|
||||||
|
import org.briarproject.api.contact.ContactManager;
|
||||||
import org.briarproject.api.crypto.CryptoComponent;
|
import org.briarproject.api.crypto.CryptoComponent;
|
||||||
import org.briarproject.api.data.ReaderFactory;
|
import org.briarproject.api.data.ReaderFactory;
|
||||||
import org.briarproject.api.data.WriterFactory;
|
import org.briarproject.api.data.WriterFactory;
|
||||||
import org.briarproject.api.db.DatabaseComponent;
|
|
||||||
import org.briarproject.api.identity.AuthorFactory;
|
import org.briarproject.api.identity.AuthorFactory;
|
||||||
import org.briarproject.api.identity.AuthorId;
|
import org.briarproject.api.identity.AuthorId;
|
||||||
|
import org.briarproject.api.identity.IdentityManager;
|
||||||
import org.briarproject.api.invitation.InvitationTask;
|
import org.briarproject.api.invitation.InvitationTask;
|
||||||
import org.briarproject.api.invitation.InvitationTaskFactory;
|
import org.briarproject.api.invitation.InvitationTaskFactory;
|
||||||
|
import org.briarproject.api.messaging.MessagingManager;
|
||||||
import org.briarproject.api.plugins.ConnectionManager;
|
import org.briarproject.api.plugins.ConnectionManager;
|
||||||
import org.briarproject.api.plugins.PluginManager;
|
import org.briarproject.api.plugins.PluginManager;
|
||||||
|
import org.briarproject.api.property.TransportPropertyManager;
|
||||||
import org.briarproject.api.sync.GroupFactory;
|
import org.briarproject.api.sync.GroupFactory;
|
||||||
import org.briarproject.api.system.Clock;
|
import org.briarproject.api.system.Clock;
|
||||||
import org.briarproject.api.transport.KeyManager;
|
import org.briarproject.api.transport.KeyManager;
|
||||||
@@ -21,7 +24,6 @@ import javax.inject.Inject;
|
|||||||
class InvitationTaskFactoryImpl implements InvitationTaskFactory {
|
class InvitationTaskFactoryImpl implements InvitationTaskFactory {
|
||||||
|
|
||||||
private final CryptoComponent crypto;
|
private final CryptoComponent crypto;
|
||||||
private final DatabaseComponent db;
|
|
||||||
private final ReaderFactory readerFactory;
|
private final ReaderFactory readerFactory;
|
||||||
private final WriterFactory writerFactory;
|
private final WriterFactory writerFactory;
|
||||||
private final StreamReaderFactory streamReaderFactory;
|
private final StreamReaderFactory streamReaderFactory;
|
||||||
@@ -30,19 +32,25 @@ class InvitationTaskFactoryImpl implements InvitationTaskFactory {
|
|||||||
private final GroupFactory groupFactory;
|
private final GroupFactory groupFactory;
|
||||||
private final KeyManager keyManager;
|
private final KeyManager keyManager;
|
||||||
private final ConnectionManager connectionManager;
|
private final ConnectionManager connectionManager;
|
||||||
|
private final IdentityManager identityManager;
|
||||||
|
private final ContactManager contactManager;
|
||||||
|
private final MessagingManager messagingManager;
|
||||||
|
private final TransportPropertyManager transportPropertyManager;
|
||||||
private final Clock clock;
|
private final Clock clock;
|
||||||
private final PluginManager pluginManager;
|
private final PluginManager pluginManager;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
InvitationTaskFactoryImpl(CryptoComponent crypto, DatabaseComponent db,
|
InvitationTaskFactoryImpl(CryptoComponent crypto,
|
||||||
ReaderFactory readerFactory, WriterFactory writerFactory,
|
ReaderFactory readerFactory, WriterFactory writerFactory,
|
||||||
StreamReaderFactory streamReaderFactory,
|
StreamReaderFactory streamReaderFactory,
|
||||||
StreamWriterFactory streamWriterFactory,
|
StreamWriterFactory streamWriterFactory,
|
||||||
AuthorFactory authorFactory, GroupFactory groupFactory,
|
AuthorFactory authorFactory, GroupFactory groupFactory,
|
||||||
KeyManager keyManager, ConnectionManager connectionManager,
|
KeyManager keyManager, ConnectionManager connectionManager,
|
||||||
|
IdentityManager identityManager, ContactManager contactManager,
|
||||||
|
MessagingManager messagingManager,
|
||||||
|
TransportPropertyManager transportPropertyManager,
|
||||||
Clock clock, PluginManager pluginManager) {
|
Clock clock, PluginManager pluginManager) {
|
||||||
this.crypto = crypto;
|
this.crypto = crypto;
|
||||||
this.db = db;
|
|
||||||
this.readerFactory = readerFactory;
|
this.readerFactory = readerFactory;
|
||||||
this.writerFactory = writerFactory;
|
this.writerFactory = writerFactory;
|
||||||
this.streamReaderFactory = streamReaderFactory;
|
this.streamReaderFactory = streamReaderFactory;
|
||||||
@@ -51,16 +59,21 @@ class InvitationTaskFactoryImpl implements InvitationTaskFactory {
|
|||||||
this.groupFactory = groupFactory;
|
this.groupFactory = groupFactory;
|
||||||
this.keyManager = keyManager;
|
this.keyManager = keyManager;
|
||||||
this.connectionManager = connectionManager;
|
this.connectionManager = connectionManager;
|
||||||
|
this.identityManager = identityManager;
|
||||||
|
this.contactManager = contactManager;
|
||||||
|
this.messagingManager = messagingManager;
|
||||||
|
this.transportPropertyManager = transportPropertyManager;
|
||||||
this.clock = clock;
|
this.clock = clock;
|
||||||
this.pluginManager = pluginManager;
|
this.pluginManager = pluginManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public InvitationTask createTask(AuthorId localAuthorId, int localCode,
|
public InvitationTask createTask(AuthorId localAuthorId, int localCode,
|
||||||
int remoteCode, boolean reuseConnection) {
|
int remoteCode, boolean reuseConnection) {
|
||||||
return new ConnectorGroup(crypto, db, readerFactory, writerFactory,
|
return new ConnectorGroup(crypto, readerFactory, writerFactory,
|
||||||
streamReaderFactory, streamWriterFactory, authorFactory,
|
streamReaderFactory, streamWriterFactory, authorFactory,
|
||||||
groupFactory, keyManager, connectionManager, clock,
|
groupFactory, keyManager, connectionManager, identityManager,
|
||||||
pluginManager, localAuthorId, localCode, remoteCode,
|
contactManager, messagingManager, transportPropertyManager,
|
||||||
|
clock, pluginManager, localAuthorId, localCode, remoteCode,
|
||||||
reuseConnection);
|
reuseConnection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,11 +3,15 @@ package org.briarproject.messaging;
|
|||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
import org.briarproject.api.contact.ContactId;
|
import org.briarproject.api.contact.ContactId;
|
||||||
|
import org.briarproject.api.crypto.CryptoComponent;
|
||||||
|
import org.briarproject.api.crypto.SecretKey;
|
||||||
import org.briarproject.api.db.DatabaseComponent;
|
import org.briarproject.api.db.DatabaseComponent;
|
||||||
import org.briarproject.api.db.DbException;
|
import org.briarproject.api.db.DbException;
|
||||||
import org.briarproject.api.messaging.MessagingManager;
|
import org.briarproject.api.messaging.MessagingManager;
|
||||||
import org.briarproject.api.messaging.PrivateConversation;
|
import org.briarproject.api.messaging.PrivateConversation;
|
||||||
import org.briarproject.api.messaging.PrivateMessageHeader;
|
import org.briarproject.api.messaging.PrivateMessageHeader;
|
||||||
|
import org.briarproject.api.sync.Group;
|
||||||
|
import org.briarproject.api.sync.GroupFactory;
|
||||||
import org.briarproject.api.sync.GroupId;
|
import org.briarproject.api.sync.GroupId;
|
||||||
import org.briarproject.api.sync.Message;
|
import org.briarproject.api.sync.Message;
|
||||||
import org.briarproject.api.sync.MessageHeader;
|
import org.briarproject.api.sync.MessageHeader;
|
||||||
@@ -22,10 +26,23 @@ import java.util.List;
|
|||||||
class MessagingManagerImpl implements MessagingManager {
|
class MessagingManagerImpl implements MessagingManager {
|
||||||
|
|
||||||
private final DatabaseComponent db;
|
private final DatabaseComponent db;
|
||||||
|
private final CryptoComponent crypto;
|
||||||
|
private final GroupFactory groupFactory;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
MessagingManagerImpl(DatabaseComponent db) {
|
MessagingManagerImpl(DatabaseComponent db, CryptoComponent crypto,
|
||||||
|
GroupFactory groupFactory) {
|
||||||
this.db = db;
|
this.db = db;
|
||||||
|
this.crypto = crypto;
|
||||||
|
this.groupFactory = groupFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addContact(ContactId c, SecretKey master) throws DbException {
|
||||||
|
byte[] salt = crypto.deriveGroupSalt(master);
|
||||||
|
Group inbox = groupFactory.createGroup("Inbox", salt);
|
||||||
|
db.addGroup(inbox);
|
||||||
|
db.setInboxGroup(c, inbox);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package org.briarproject.plugins;
|
|||||||
|
|
||||||
import org.briarproject.api.TransportId;
|
import org.briarproject.api.TransportId;
|
||||||
import org.briarproject.api.contact.ContactId;
|
import org.briarproject.api.contact.ContactId;
|
||||||
import org.briarproject.api.db.DbException;
|
|
||||||
import org.briarproject.api.lifecycle.IoExecutor;
|
import org.briarproject.api.lifecycle.IoExecutor;
|
||||||
import org.briarproject.api.plugins.ConnectionManager;
|
import org.briarproject.api.plugins.ConnectionManager;
|
||||||
import org.briarproject.api.plugins.ConnectionRegistry;
|
import org.briarproject.api.plugins.ConnectionRegistry;
|
||||||
@@ -130,15 +129,11 @@ class ConnectionManagerImpl implements ConnectionManager {
|
|||||||
StreamContext ctx;
|
StreamContext ctx;
|
||||||
try {
|
try {
|
||||||
byte[] tag = readTag(transportId, reader);
|
byte[] tag = readTag(transportId, reader);
|
||||||
ctx = keyManager.recogniseTag(transportId, tag);
|
ctx = keyManager.getStreamContext(transportId, tag);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||||
disposeReader(true, false);
|
disposeReader(true, false);
|
||||||
return;
|
return;
|
||||||
} catch (DbException e) {
|
|
||||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
|
||||||
disposeReader(true, false);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
if (ctx == null) {
|
if (ctx == null) {
|
||||||
LOG.info("Unrecognised tag");
|
LOG.info("Unrecognised tag");
|
||||||
@@ -234,15 +229,11 @@ class ConnectionManagerImpl implements ConnectionManager {
|
|||||||
StreamContext ctx;
|
StreamContext ctx;
|
||||||
try {
|
try {
|
||||||
byte[] tag = readTag(transportId, reader);
|
byte[] tag = readTag(transportId, reader);
|
||||||
ctx = keyManager.recogniseTag(transportId, tag);
|
ctx = keyManager.getStreamContext(transportId, tag);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||||
disposeReader(true, false);
|
disposeReader(true, false);
|
||||||
return;
|
return;
|
||||||
} catch (DbException e) {
|
|
||||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
|
||||||
disposeReader(true, false);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
if (ctx == null) {
|
if (ctx == null) {
|
||||||
LOG.info("Unrecognised tag");
|
LOG.info("Unrecognised tag");
|
||||||
@@ -363,15 +354,11 @@ class ConnectionManagerImpl implements ConnectionManager {
|
|||||||
StreamContext ctx;
|
StreamContext ctx;
|
||||||
try {
|
try {
|
||||||
byte[] tag = readTag(transportId, reader);
|
byte[] tag = readTag(transportId, reader);
|
||||||
ctx = keyManager.recogniseTag(transportId, tag);
|
ctx = keyManager.getStreamContext(transportId, tag);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||||
disposeReader(true, true);
|
disposeReader(true, true);
|
||||||
return;
|
return;
|
||||||
} catch (DbException e) {
|
|
||||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
|
||||||
disposeReader(true, true);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
// Unrecognised tags are suspicious in this case
|
// Unrecognised tags are suspicious in this case
|
||||||
if (ctx == null) {
|
if (ctx == null) {
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import org.briarproject.api.plugins.simplex.SimplexPlugin;
|
|||||||
import org.briarproject.api.plugins.simplex.SimplexPluginCallback;
|
import org.briarproject.api.plugins.simplex.SimplexPluginCallback;
|
||||||
import org.briarproject.api.plugins.simplex.SimplexPluginConfig;
|
import org.briarproject.api.plugins.simplex.SimplexPluginConfig;
|
||||||
import org.briarproject.api.plugins.simplex.SimplexPluginFactory;
|
import org.briarproject.api.plugins.simplex.SimplexPluginFactory;
|
||||||
|
import org.briarproject.api.property.TransportPropertyManager;
|
||||||
import org.briarproject.api.system.Clock;
|
import org.briarproject.api.system.Clock;
|
||||||
import org.briarproject.api.ui.UiCallback;
|
import org.briarproject.api.ui.UiCallback;
|
||||||
|
|
||||||
@@ -58,6 +59,7 @@ class PluginManagerImpl implements PluginManager {
|
|||||||
private final DatabaseComponent db;
|
private final DatabaseComponent db;
|
||||||
private final Poller poller;
|
private final Poller poller;
|
||||||
private final ConnectionManager connectionManager;
|
private final ConnectionManager connectionManager;
|
||||||
|
private final TransportPropertyManager transportPropertyManager;
|
||||||
private final UiCallback uiCallback;
|
private final UiCallback uiCallback;
|
||||||
private final Map<TransportId, Plugin> plugins;
|
private final Map<TransportId, Plugin> plugins;
|
||||||
private final List<SimplexPlugin> simplexPlugins;
|
private final List<SimplexPlugin> simplexPlugins;
|
||||||
@@ -68,7 +70,9 @@ class PluginManagerImpl implements PluginManager {
|
|||||||
SimplexPluginConfig simplexPluginConfig,
|
SimplexPluginConfig simplexPluginConfig,
|
||||||
DuplexPluginConfig duplexPluginConfig, Clock clock,
|
DuplexPluginConfig duplexPluginConfig, Clock clock,
|
||||||
DatabaseComponent db, Poller poller,
|
DatabaseComponent db, Poller poller,
|
||||||
ConnectionManager connectionManager, UiCallback uiCallback) {
|
ConnectionManager connectionManager,
|
||||||
|
TransportPropertyManager transportPropertyManager,
|
||||||
|
UiCallback uiCallback) {
|
||||||
this.ioExecutor = ioExecutor;
|
this.ioExecutor = ioExecutor;
|
||||||
this.eventBus = eventBus;
|
this.eventBus = eventBus;
|
||||||
this.simplexPluginConfig = simplexPluginConfig;
|
this.simplexPluginConfig = simplexPluginConfig;
|
||||||
@@ -77,6 +81,7 @@ class PluginManagerImpl implements PluginManager {
|
|||||||
this.db = db;
|
this.db = db;
|
||||||
this.poller = poller;
|
this.poller = poller;
|
||||||
this.connectionManager = connectionManager;
|
this.connectionManager = connectionManager;
|
||||||
|
this.transportPropertyManager = transportPropertyManager;
|
||||||
this.uiCallback = uiCallback;
|
this.uiCallback = uiCallback;
|
||||||
plugins = new ConcurrentHashMap<TransportId, Plugin>();
|
plugins = new ConcurrentHashMap<TransportId, Plugin>();
|
||||||
simplexPlugins = new CopyOnWriteArrayList<SimplexPlugin>();
|
simplexPlugins = new CopyOnWriteArrayList<SimplexPlugin>();
|
||||||
@@ -320,7 +325,8 @@ class PluginManagerImpl implements PluginManager {
|
|||||||
|
|
||||||
public TransportProperties getLocalProperties() {
|
public TransportProperties getLocalProperties() {
|
||||||
try {
|
try {
|
||||||
TransportProperties p = db.getLocalProperties(id);
|
TransportProperties p =
|
||||||
|
transportPropertyManager.getLocalProperties(id);
|
||||||
return p == null ? new TransportProperties() : p;
|
return p == null ? new TransportProperties() : p;
|
||||||
} catch (DbException e) {
|
} catch (DbException e) {
|
||||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||||
@@ -330,7 +336,7 @@ class PluginManagerImpl implements PluginManager {
|
|||||||
|
|
||||||
public Map<ContactId, TransportProperties> getRemoteProperties() {
|
public Map<ContactId, TransportProperties> getRemoteProperties() {
|
||||||
try {
|
try {
|
||||||
return db.getRemoteProperties(id);
|
return transportPropertyManager.getRemoteProperties(id);
|
||||||
} catch (DbException e) {
|
} catch (DbException e) {
|
||||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||||
return Collections.emptyMap();
|
return Collections.emptyMap();
|
||||||
@@ -347,7 +353,7 @@ class PluginManagerImpl implements PluginManager {
|
|||||||
|
|
||||||
public void mergeLocalProperties(TransportProperties p) {
|
public void mergeLocalProperties(TransportProperties p) {
|
||||||
try {
|
try {
|
||||||
db.mergeLocalProperties(id, p);
|
transportPropertyManager.mergeLocalProperties(id, p);
|
||||||
} catch (DbException e) {
|
} catch (DbException e) {
|
||||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||||
}
|
}
|
||||||
|
|||||||
14
briar-core/src/org/briarproject/property/PropertyModule.java
Normal file
14
briar-core/src/org/briarproject/property/PropertyModule.java
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
package org.briarproject.property;
|
||||||
|
|
||||||
|
import com.google.inject.AbstractModule;
|
||||||
|
|
||||||
|
import org.briarproject.api.property.TransportPropertyManager;
|
||||||
|
|
||||||
|
public class PropertyModule extends AbstractModule {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void configure() {
|
||||||
|
bind(TransportPropertyManager.class).to(
|
||||||
|
TransportPropertyManagerImpl.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
package org.briarproject.property;
|
||||||
|
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
|
import org.briarproject.api.TransportId;
|
||||||
|
import org.briarproject.api.TransportProperties;
|
||||||
|
import org.briarproject.api.contact.ContactId;
|
||||||
|
import org.briarproject.api.db.DatabaseComponent;
|
||||||
|
import org.briarproject.api.db.DbException;
|
||||||
|
import org.briarproject.api.property.TransportPropertyManager;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
// Temporary facade during sync protocol refactoring
|
||||||
|
class TransportPropertyManagerImpl implements TransportPropertyManager {
|
||||||
|
|
||||||
|
private final DatabaseComponent db;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
TransportPropertyManagerImpl(DatabaseComponent db) {
|
||||||
|
this.db = db;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<TransportId, TransportProperties> getLocalProperties()
|
||||||
|
throws DbException {
|
||||||
|
return db.getLocalProperties();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TransportProperties getLocalProperties(TransportId t)
|
||||||
|
throws DbException {
|
||||||
|
return db.getLocalProperties(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<ContactId, TransportProperties> getRemoteProperties(
|
||||||
|
TransportId t) throws DbException {
|
||||||
|
return db.getRemoteProperties(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mergeLocalProperties(TransportId t, TransportProperties p)
|
||||||
|
throws DbException {
|
||||||
|
db.mergeLocalProperties(t, p);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setRemoteProperties(ContactId c,
|
||||||
|
Map<TransportId, TransportProperties> p) throws DbException {
|
||||||
|
db.setRemoteProperties(c, p);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ package org.briarproject.transport;
|
|||||||
import org.briarproject.api.TransportId;
|
import org.briarproject.api.TransportId;
|
||||||
import org.briarproject.api.contact.ContactId;
|
import org.briarproject.api.contact.ContactId;
|
||||||
import org.briarproject.api.crypto.CryptoComponent;
|
import org.briarproject.api.crypto.CryptoComponent;
|
||||||
|
import org.briarproject.api.crypto.SecretKey;
|
||||||
import org.briarproject.api.db.DatabaseComponent;
|
import org.briarproject.api.db.DatabaseComponent;
|
||||||
import org.briarproject.api.db.DatabaseExecutor;
|
import org.briarproject.api.db.DatabaseExecutor;
|
||||||
import org.briarproject.api.db.DbException;
|
import org.briarproject.api.db.DbException;
|
||||||
@@ -16,7 +17,6 @@ import org.briarproject.api.system.Clock;
|
|||||||
import org.briarproject.api.system.Timer;
|
import org.briarproject.api.system.Timer;
|
||||||
import org.briarproject.api.transport.KeyManager;
|
import org.briarproject.api.transport.KeyManager;
|
||||||
import org.briarproject.api.transport.StreamContext;
|
import org.briarproject.api.transport.StreamContext;
|
||||||
import org.briarproject.api.transport.TransportKeys;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -73,10 +73,11 @@ class KeyManagerImpl implements KeyManager, EventListener {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void contactAdded(ContactId c, Collection<TransportKeys> keys) {
|
public void addContact(ContactId c, Collection<TransportId> transports,
|
||||||
for (TransportKeys k : keys) {
|
SecretKey master, long timestamp, boolean alice) {
|
||||||
TransportKeyManager m = managers.get(k.getTransportId());
|
for (TransportId t : transports) {
|
||||||
if (m != null) m.addContact(c, k);
|
TransportKeyManager m = managers.get(t);
|
||||||
|
if (m != null) m.addContact(c, master, timestamp, alice);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,8 +86,7 @@ class KeyManagerImpl implements KeyManager, EventListener {
|
|||||||
return m == null ? null : m.getStreamContext(c);
|
return m == null ? null : m.getStreamContext(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
public StreamContext recogniseTag(TransportId t, byte[] tag)
|
public StreamContext getStreamContext(TransportId t, byte[] tag) {
|
||||||
throws DbException {
|
|
||||||
TransportKeyManager m = managers.get(t);
|
TransportKeyManager m = managers.get(t);
|
||||||
return m == null ? null : m.recogniseTag(tag);
|
return m == null ? null : m.recogniseTag(tag);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import org.briarproject.api.Bytes;
|
|||||||
import org.briarproject.api.TransportId;
|
import org.briarproject.api.TransportId;
|
||||||
import org.briarproject.api.contact.ContactId;
|
import org.briarproject.api.contact.ContactId;
|
||||||
import org.briarproject.api.crypto.CryptoComponent;
|
import org.briarproject.api.crypto.CryptoComponent;
|
||||||
|
import org.briarproject.api.crypto.SecretKey;
|
||||||
import org.briarproject.api.db.DatabaseComponent;
|
import org.briarproject.api.db.DatabaseComponent;
|
||||||
import org.briarproject.api.db.DbException;
|
import org.briarproject.api.db.DbException;
|
||||||
import org.briarproject.api.system.Clock;
|
import org.briarproject.api.system.Clock;
|
||||||
@@ -98,9 +99,9 @@ class TransportKeyManager extends TimerTask {
|
|||||||
} finally {
|
} finally {
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
// Schedule a periodic task to rotate the keys
|
// Schedule the next key rotation
|
||||||
long delay = rotationPeriodLength - now % rotationPeriodLength;
|
long delay = rotationPeriodLength - now % rotationPeriodLength;
|
||||||
timer.scheduleAtFixedRate(this, delay, rotationPeriodLength);
|
timer.schedule(this, delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Locking: lock
|
// Locking: lock
|
||||||
@@ -136,16 +137,40 @@ class TransportKeyManager extends TimerTask {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void addContact(ContactId c, TransportKeys k) {
|
void addContact(ContactId c, SecretKey master, long timestamp,
|
||||||
|
boolean alice) {
|
||||||
|
// Work out what rotation period the timestamp belongs to
|
||||||
|
long rotationPeriod = timestamp / rotationPeriodLength;
|
||||||
|
// Derive the transport keys
|
||||||
|
TransportKeys k = crypto.deriveTransportKeys(transportId, master,
|
||||||
|
rotationPeriod, alice);
|
||||||
|
// Rotate the keys to the current rotation period if necessary
|
||||||
|
rotationPeriod = clock.currentTimeMillis() / rotationPeriodLength;
|
||||||
|
k = crypto.rotateTransportKeys(k, rotationPeriod);
|
||||||
lock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
// Initialise mutable state for the contact
|
// Initialise mutable state for the contact
|
||||||
addKeys(c, new MutableTransportKeys(k));
|
addKeys(c, new MutableTransportKeys(k));
|
||||||
|
// Write the keys back to the DB
|
||||||
|
saveTransportKeys(c, k);
|
||||||
} finally {
|
} finally {
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void saveTransportKeys(final ContactId c, final TransportKeys k) {
|
||||||
|
dbExecutor.execute(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
db.addTransportKeys(c, k);
|
||||||
|
} catch (DbException e) {
|
||||||
|
if (LOG.isLoggable(WARNING))
|
||||||
|
LOG.log(WARNING, e.toString(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void removeContact(ContactId c) {
|
void removeContact(ContactId c) {
|
||||||
lock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
@@ -308,6 +333,10 @@ class TransportKeyManager extends TimerTask {
|
|||||||
} finally {
|
} finally {
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
|
// Schedule the next key rotation
|
||||||
|
long now = clock.currentTimeMillis();
|
||||||
|
long delay = rotationPeriodLength - now % rotationPeriodLength;
|
||||||
|
timer.schedule(this, delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class TagContext {
|
private static class TagContext {
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import org.briarproject.BriarTestCase;
|
|||||||
import org.briarproject.api.TransportId;
|
import org.briarproject.api.TransportId;
|
||||||
import org.briarproject.api.db.DatabaseComponent;
|
import org.briarproject.api.db.DatabaseComponent;
|
||||||
import org.briarproject.api.event.EventBus;
|
import org.briarproject.api.event.EventBus;
|
||||||
import org.briarproject.api.lifecycle.IoExecutor;
|
|
||||||
import org.briarproject.api.plugins.ConnectionManager;
|
import org.briarproject.api.plugins.ConnectionManager;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexPlugin;
|
import org.briarproject.api.plugins.duplex.DuplexPlugin;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexPluginCallback;
|
import org.briarproject.api.plugins.duplex.DuplexPluginCallback;
|
||||||
@@ -14,6 +13,7 @@ import org.briarproject.api.plugins.simplex.SimplexPlugin;
|
|||||||
import org.briarproject.api.plugins.simplex.SimplexPluginCallback;
|
import org.briarproject.api.plugins.simplex.SimplexPluginCallback;
|
||||||
import org.briarproject.api.plugins.simplex.SimplexPluginConfig;
|
import org.briarproject.api.plugins.simplex.SimplexPluginConfig;
|
||||||
import org.briarproject.api.plugins.simplex.SimplexPluginFactory;
|
import org.briarproject.api.plugins.simplex.SimplexPluginFactory;
|
||||||
|
import org.briarproject.api.property.TransportPropertyManager;
|
||||||
import org.briarproject.api.system.Clock;
|
import org.briarproject.api.system.Clock;
|
||||||
import org.briarproject.api.ui.UiCallback;
|
import org.briarproject.api.ui.UiCallback;
|
||||||
import org.briarproject.system.SystemClock;
|
import org.briarproject.system.SystemClock;
|
||||||
@@ -41,8 +41,10 @@ public class PluginManagerImplTest extends BriarTestCase {
|
|||||||
context.mock(DuplexPluginConfig.class);
|
context.mock(DuplexPluginConfig.class);
|
||||||
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||||
final Poller poller = context.mock(Poller.class);
|
final Poller poller = context.mock(Poller.class);
|
||||||
final ConnectionManager dispatcher =
|
final ConnectionManager connectionManager =
|
||||||
context.mock(ConnectionManager.class);
|
context.mock(ConnectionManager.class);
|
||||||
|
final TransportPropertyManager transportPropertyManager =
|
||||||
|
context.mock(TransportPropertyManager.class);
|
||||||
final UiCallback uiCallback = context.mock(UiCallback.class);
|
final UiCallback uiCallback = context.mock(UiCallback.class);
|
||||||
// Two simplex plugin factories: both create plugins, one fails to start
|
// Two simplex plugin factories: both create plugins, one fails to start
|
||||||
final SimplexPluginFactory simplexFactory =
|
final SimplexPluginFactory simplexFactory =
|
||||||
@@ -126,7 +128,7 @@ public class PluginManagerImplTest extends BriarTestCase {
|
|||||||
}});
|
}});
|
||||||
PluginManagerImpl p = new PluginManagerImpl(ioExecutor, eventBus,
|
PluginManagerImpl p = new PluginManagerImpl(ioExecutor, eventBus,
|
||||||
simplexPluginConfig, duplexPluginConfig, clock, db, poller,
|
simplexPluginConfig, duplexPluginConfig, clock, db, poller,
|
||||||
dispatcher, uiCallback);
|
connectionManager, transportPropertyManager, uiCallback);
|
||||||
|
|
||||||
// Two plugins should be started and stopped
|
// Two plugins should be started and stopped
|
||||||
assertTrue(p.start());
|
assertTrue(p.start());
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import org.briarproject.TestSystemModule;
|
|||||||
import org.briarproject.TestUtils;
|
import org.briarproject.TestUtils;
|
||||||
import org.briarproject.api.TransportId;
|
import org.briarproject.api.TransportId;
|
||||||
import org.briarproject.api.contact.ContactId;
|
import org.briarproject.api.contact.ContactId;
|
||||||
import org.briarproject.api.crypto.CryptoComponent;
|
import org.briarproject.api.contact.ContactManager;
|
||||||
import org.briarproject.api.crypto.SecretKey;
|
import org.briarproject.api.crypto.SecretKey;
|
||||||
import org.briarproject.api.db.DatabaseComponent;
|
import org.briarproject.api.db.DatabaseComponent;
|
||||||
import org.briarproject.api.event.Event;
|
import org.briarproject.api.event.Event;
|
||||||
@@ -19,11 +19,13 @@ import org.briarproject.api.event.EventListener;
|
|||||||
import org.briarproject.api.event.MessageAddedEvent;
|
import org.briarproject.api.event.MessageAddedEvent;
|
||||||
import org.briarproject.api.identity.Author;
|
import org.briarproject.api.identity.Author;
|
||||||
import org.briarproject.api.identity.AuthorId;
|
import org.briarproject.api.identity.AuthorId;
|
||||||
|
import org.briarproject.api.identity.IdentityManager;
|
||||||
import org.briarproject.api.identity.LocalAuthor;
|
import org.briarproject.api.identity.LocalAuthor;
|
||||||
import org.briarproject.api.sync.Group;
|
import org.briarproject.api.messaging.MessagingManager;
|
||||||
import org.briarproject.api.sync.GroupFactory;
|
import org.briarproject.api.messaging.PrivateConversation;
|
||||||
|
import org.briarproject.api.messaging.PrivateMessageFactory;
|
||||||
|
import org.briarproject.api.sync.GroupId;
|
||||||
import org.briarproject.api.sync.Message;
|
import org.briarproject.api.sync.Message;
|
||||||
import org.briarproject.api.sync.MessageFactory;
|
|
||||||
import org.briarproject.api.sync.MessageVerifier;
|
import org.briarproject.api.sync.MessageVerifier;
|
||||||
import org.briarproject.api.sync.MessagingSession;
|
import org.briarproject.api.sync.MessagingSession;
|
||||||
import org.briarproject.api.sync.PacketReader;
|
import org.briarproject.api.sync.PacketReader;
|
||||||
@@ -34,11 +36,13 @@ import org.briarproject.api.transport.KeyManager;
|
|||||||
import org.briarproject.api.transport.StreamContext;
|
import org.briarproject.api.transport.StreamContext;
|
||||||
import org.briarproject.api.transport.StreamReaderFactory;
|
import org.briarproject.api.transport.StreamReaderFactory;
|
||||||
import org.briarproject.api.transport.StreamWriterFactory;
|
import org.briarproject.api.transport.StreamWriterFactory;
|
||||||
import org.briarproject.api.transport.TransportKeys;
|
import org.briarproject.contact.ContactModule;
|
||||||
import org.briarproject.crypto.CryptoModule;
|
import org.briarproject.crypto.CryptoModule;
|
||||||
import org.briarproject.data.DataModule;
|
import org.briarproject.data.DataModule;
|
||||||
import org.briarproject.db.DatabaseModule;
|
import org.briarproject.db.DatabaseModule;
|
||||||
import org.briarproject.event.EventModule;
|
import org.briarproject.event.EventModule;
|
||||||
|
import org.briarproject.identity.IdentityModule;
|
||||||
|
import org.briarproject.messaging.MessagingModule;
|
||||||
import org.briarproject.plugins.ImmediateExecutor;
|
import org.briarproject.plugins.ImmediateExecutor;
|
||||||
import org.briarproject.transport.TransportModule;
|
import org.briarproject.transport.TransportModule;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
@@ -53,8 +57,6 @@ import java.io.OutputStream;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
import static org.briarproject.api.identity.AuthorConstants.MAX_PUBLIC_KEY_LENGTH;
|
import static org.briarproject.api.identity.AuthorConstants.MAX_PUBLIC_KEY_LENGTH;
|
||||||
import static org.briarproject.api.sync.MessagingConstants.GROUP_SALT_LENGTH;
|
|
||||||
import static org.briarproject.api.transport.TransportConstants.MAX_CLOCK_DIFFERENCE;
|
|
||||||
import static org.briarproject.api.transport.TransportConstants.TAG_LENGTH;
|
import static org.briarproject.api.transport.TransportConstants.TAG_LENGTH;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
@@ -64,8 +66,6 @@ import static org.junit.Assert.assertTrue;
|
|||||||
public class SimplexMessagingIntegrationTest extends BriarTestCase {
|
public class SimplexMessagingIntegrationTest extends BriarTestCase {
|
||||||
|
|
||||||
private static final int MAX_LATENCY = 2 * 60 * 1000; // 2 minutes
|
private static final int MAX_LATENCY = 2 * 60 * 1000; // 2 minutes
|
||||||
private static final long ROTATION_PERIOD_LENGTH =
|
|
||||||
MAX_LATENCY + MAX_CLOCK_DIFFERENCE;
|
|
||||||
|
|
||||||
private final File testDir = TestUtils.getTestDirectory();
|
private final File testDir = TestUtils.getTestDirectory();
|
||||||
private final File aliceDir = new File(testDir, "alice");
|
private final File aliceDir = new File(testDir, "alice");
|
||||||
@@ -86,9 +86,9 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase {
|
|||||||
private Injector createInjector(File dir) {
|
private Injector createInjector(File dir) {
|
||||||
return Guice.createInjector(new TestDatabaseModule(dir),
|
return Guice.createInjector(new TestDatabaseModule(dir),
|
||||||
new TestLifecycleModule(), new TestSystemModule(),
|
new TestLifecycleModule(), new TestSystemModule(),
|
||||||
new CryptoModule(), new DatabaseModule(), new EventModule(),
|
new ContactModule(), new CryptoModule(), new DatabaseModule(),
|
||||||
new SyncModule(), new DataModule(),
|
new DataModule(), new EventModule(), new IdentityModule(),
|
||||||
new TransportModule());
|
new SyncModule(), new MessagingModule(), new TransportModule());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -100,40 +100,41 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase {
|
|||||||
// Open Alice's database
|
// Open Alice's database
|
||||||
DatabaseComponent db = alice.getInstance(DatabaseComponent.class);
|
DatabaseComponent db = alice.getInstance(DatabaseComponent.class);
|
||||||
assertFalse(db.open());
|
assertFalse(db.open());
|
||||||
|
// Add the transport
|
||||||
|
db.addTransport(transportId, MAX_LATENCY);
|
||||||
// Start Alice's key manager
|
// Start Alice's key manager
|
||||||
KeyManager keyManager = alice.getInstance(KeyManager.class);
|
KeyManager keyManager = alice.getInstance(KeyManager.class);
|
||||||
keyManager.start();
|
keyManager.start();
|
||||||
// Add a local pseudonym for Alice
|
// Add an identity for Alice
|
||||||
AuthorId aliceId = new AuthorId(TestUtils.getRandomId());
|
AuthorId aliceId = new AuthorId(TestUtils.getRandomId());
|
||||||
LocalAuthor aliceAuthor = new LocalAuthor(aliceId, "Alice",
|
LocalAuthor aliceAuthor = new LocalAuthor(aliceId, "Alice",
|
||||||
new byte[MAX_PUBLIC_KEY_LENGTH], new byte[100], 1234);
|
new byte[MAX_PUBLIC_KEY_LENGTH], new byte[100], 1234);
|
||||||
db.addLocalAuthor(aliceAuthor);
|
IdentityManager identityManager =
|
||||||
|
alice.getInstance(IdentityManager.class);
|
||||||
|
identityManager.addLocalAuthor(aliceAuthor);
|
||||||
// Add Bob as a contact
|
// Add Bob as a contact
|
||||||
AuthorId bobId = new AuthorId(TestUtils.getRandomId());
|
AuthorId bobId = new AuthorId(TestUtils.getRandomId());
|
||||||
Author bobAuthor = new Author(bobId, "Bob",
|
Author bobAuthor = new Author(bobId, "Bob",
|
||||||
new byte[MAX_PUBLIC_KEY_LENGTH]);
|
new byte[MAX_PUBLIC_KEY_LENGTH]);
|
||||||
ContactId contactId = db.addContact(bobAuthor, aliceId);
|
ContactManager contactManager = alice.getInstance(ContactManager.class);
|
||||||
// Add the inbox group
|
ContactId contactId = contactManager.addContact(bobAuthor, aliceId);
|
||||||
GroupFactory gf = alice.getInstance(GroupFactory.class);
|
// Create the private conversation
|
||||||
Group group = gf.createGroup("Group", new byte[GROUP_SALT_LENGTH]);
|
MessagingManager messagingManager =
|
||||||
db.addGroup(group);
|
alice.getInstance(MessagingManager.class);
|
||||||
db.setInboxGroup(contactId, group);
|
messagingManager.addContact(contactId, master);
|
||||||
// Add the transport
|
|
||||||
db.addTransport(transportId, MAX_LATENCY);
|
|
||||||
// Derive and store the transport keys
|
// Derive and store the transport keys
|
||||||
long rotationPeriod = timestamp / ROTATION_PERIOD_LENGTH;
|
keyManager.addContact(contactId, Collections.singletonList(transportId),
|
||||||
CryptoComponent crypto = alice.getInstance(CryptoComponent.class);
|
master, timestamp, true);
|
||||||
TransportKeys keys = crypto.deriveTransportKeys(transportId, master,
|
|
||||||
rotationPeriod, true);
|
|
||||||
db.addTransportKeys(contactId, keys);
|
|
||||||
keyManager.contactAdded(contactId, Collections.singletonList(keys));
|
|
||||||
// Send Bob a message
|
// Send Bob a message
|
||||||
String contentType = "text/plain";
|
|
||||||
byte[] body = "Hi Bob!".getBytes("UTF-8");
|
byte[] body = "Hi Bob!".getBytes("UTF-8");
|
||||||
MessageFactory messageFactory = alice.getInstance(MessageFactory.class);
|
PrivateMessageFactory messageFactory =
|
||||||
Message message = messageFactory.createAnonymousMessage(null, group,
|
alice.getInstance(PrivateMessageFactory.class);
|
||||||
contentType, timestamp, body);
|
GroupId groupId = messagingManager.getConversationId(contactId);
|
||||||
db.addLocalMessage(message);
|
PrivateConversation conversation =
|
||||||
|
messagingManager.getConversation(groupId);
|
||||||
|
Message message = messageFactory.createPrivateMessage(null,
|
||||||
|
conversation, "text/plain", timestamp, body);
|
||||||
|
messagingManager.addLocalMessage(message);
|
||||||
// Get a stream context
|
// Get a stream context
|
||||||
StreamContext ctx = keyManager.getStreamContext(contactId, transportId);
|
StreamContext ctx = keyManager.getStreamContext(contactId, transportId);
|
||||||
assertNotNull(ctx);
|
assertNotNull(ctx);
|
||||||
@@ -143,13 +144,13 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase {
|
|||||||
alice.getInstance(StreamWriterFactory.class);
|
alice.getInstance(StreamWriterFactory.class);
|
||||||
OutputStream streamWriter =
|
OutputStream streamWriter =
|
||||||
streamWriterFactory.createStreamWriter(out, ctx);
|
streamWriterFactory.createStreamWriter(out, ctx);
|
||||||
// Create an outgoing messaging session
|
// Create an outgoing sync session
|
||||||
EventBus eventBus = alice.getInstance(EventBus.class);
|
EventBus eventBus = alice.getInstance(EventBus.class);
|
||||||
PacketWriterFactory packetWriterFactory =
|
PacketWriterFactory packetWriterFactory =
|
||||||
alice.getInstance(PacketWriterFactory.class);
|
alice.getInstance(PacketWriterFactory.class);
|
||||||
PacketWriter packetWriter = packetWriterFactory.createPacketWriter(
|
PacketWriter packetWriter = packetWriterFactory.createPacketWriter(
|
||||||
streamWriter);
|
streamWriter);
|
||||||
MessagingSession session = new org.briarproject.sync.SimplexOutgoingSession(db,
|
MessagingSession session = new SimplexOutgoingSession(db,
|
||||||
new ImmediateExecutor(), eventBus, contactId, transportId,
|
new ImmediateExecutor(), eventBus, contactId, transportId,
|
||||||
MAX_LATENCY, packetWriter);
|
MAX_LATENCY, packetWriter);
|
||||||
// Write whatever needs to be written
|
// Write whatever needs to be written
|
||||||
@@ -166,33 +167,31 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase {
|
|||||||
// Open Bob's database
|
// Open Bob's database
|
||||||
DatabaseComponent db = bob.getInstance(DatabaseComponent.class);
|
DatabaseComponent db = bob.getInstance(DatabaseComponent.class);
|
||||||
assertFalse(db.open());
|
assertFalse(db.open());
|
||||||
|
// Add the transport
|
||||||
|
db.addTransport(transportId, MAX_LATENCY);
|
||||||
// Start Bob's key manager
|
// Start Bob's key manager
|
||||||
KeyManager keyManager = bob.getInstance(KeyManager.class);
|
KeyManager keyManager = bob.getInstance(KeyManager.class);
|
||||||
keyManager.start();
|
keyManager.start();
|
||||||
// Add a local pseudonym for Bob
|
// Add an identity for Bob
|
||||||
AuthorId bobId = new AuthorId(TestUtils.getRandomId());
|
AuthorId bobId = new AuthorId(TestUtils.getRandomId());
|
||||||
LocalAuthor bobAuthor = new LocalAuthor(bobId, "Bob",
|
LocalAuthor bobAuthor = new LocalAuthor(bobId, "Bob",
|
||||||
new byte[MAX_PUBLIC_KEY_LENGTH], new byte[100], 1234);
|
new byte[MAX_PUBLIC_KEY_LENGTH], new byte[100], 1234);
|
||||||
db.addLocalAuthor(bobAuthor);
|
IdentityManager identityManager =
|
||||||
|
bob.getInstance(IdentityManager.class);
|
||||||
|
identityManager.addLocalAuthor(bobAuthor);
|
||||||
// Add Alice as a contact
|
// Add Alice as a contact
|
||||||
AuthorId aliceId = new AuthorId(TestUtils.getRandomId());
|
AuthorId aliceId = new AuthorId(TestUtils.getRandomId());
|
||||||
Author aliceAuthor = new Author(aliceId, "Alice",
|
Author aliceAuthor = new Author(aliceId, "Alice",
|
||||||
new byte[MAX_PUBLIC_KEY_LENGTH]);
|
new byte[MAX_PUBLIC_KEY_LENGTH]);
|
||||||
ContactId contactId = db.addContact(aliceAuthor, bobId);
|
ContactManager contactManager = bob.getInstance(ContactManager.class);
|
||||||
// Add the inbox group
|
ContactId contactId = contactManager.addContact(aliceAuthor, bobId);
|
||||||
GroupFactory gf = bob.getInstance(GroupFactory.class);
|
// Create the private conversation
|
||||||
Group group = gf.createGroup("Group", new byte[GROUP_SALT_LENGTH]);
|
MessagingManager messagingManager =
|
||||||
db.addGroup(group);
|
bob.getInstance(MessagingManager.class);
|
||||||
db.setInboxGroup(contactId, group);
|
messagingManager.addContact(contactId, master);
|
||||||
// Add the transport
|
|
||||||
db.addTransport(transportId, MAX_LATENCY);
|
|
||||||
// Derive and store the transport keys
|
// Derive and store the transport keys
|
||||||
long rotationPeriod = timestamp / ROTATION_PERIOD_LENGTH;
|
keyManager.addContact(contactId, Collections.singletonList(transportId),
|
||||||
CryptoComponent crypto = bob.getInstance(CryptoComponent.class);
|
master, timestamp, false);
|
||||||
TransportKeys keys = crypto.deriveTransportKeys(transportId, master,
|
|
||||||
rotationPeriod, false);
|
|
||||||
db.addTransportKeys(contactId, keys);
|
|
||||||
keyManager.contactAdded(contactId, Collections.singletonList(keys));
|
|
||||||
// Set up an event listener
|
// Set up an event listener
|
||||||
MessageListener listener = new MessageListener();
|
MessageListener listener = new MessageListener();
|
||||||
bob.getInstance(EventBus.class).addListener(listener);
|
bob.getInstance(EventBus.class).addListener(listener);
|
||||||
@@ -201,14 +200,14 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase {
|
|||||||
byte[] tag = new byte[TAG_LENGTH];
|
byte[] tag = new byte[TAG_LENGTH];
|
||||||
int read = in.read(tag);
|
int read = in.read(tag);
|
||||||
assertEquals(tag.length, read);
|
assertEquals(tag.length, read);
|
||||||
StreamContext ctx = keyManager.recogniseTag(transportId, tag);
|
StreamContext ctx = keyManager.getStreamContext(transportId, tag);
|
||||||
assertNotNull(ctx);
|
assertNotNull(ctx);
|
||||||
// Create a stream reader
|
// Create a stream reader
|
||||||
StreamReaderFactory streamReaderFactory =
|
StreamReaderFactory streamReaderFactory =
|
||||||
bob.getInstance(StreamReaderFactory.class);
|
bob.getInstance(StreamReaderFactory.class);
|
||||||
InputStream streamReader =
|
InputStream streamReader =
|
||||||
streamReaderFactory.createStreamReader(in, ctx);
|
streamReaderFactory.createStreamReader(in, ctx);
|
||||||
// Create an incoming messaging session
|
// Create an incoming sync session
|
||||||
EventBus eventBus = bob.getInstance(EventBus.class);
|
EventBus eventBus = bob.getInstance(EventBus.class);
|
||||||
MessageVerifier messageVerifier =
|
MessageVerifier messageVerifier =
|
||||||
bob.getInstance(MessageVerifier.class);
|
bob.getInstance(MessageVerifier.class);
|
||||||
@@ -216,7 +215,7 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase {
|
|||||||
bob.getInstance(PacketReaderFactory.class);
|
bob.getInstance(PacketReaderFactory.class);
|
||||||
PacketReader packetReader = packetReaderFactory.createPacketReader(
|
PacketReader packetReader = packetReaderFactory.createPacketReader(
|
||||||
streamReader);
|
streamReader);
|
||||||
MessagingSession session = new org.briarproject.sync.IncomingSession(db,
|
MessagingSession session = new IncomingSession(db,
|
||||||
new ImmediateExecutor(), new ImmediateExecutor(), eventBus,
|
new ImmediateExecutor(), new ImmediateExecutor(), eventBus,
|
||||||
messageVerifier, contactId, transportId, packetReader);
|
messageVerifier, contactId, transportId, packetReader);
|
||||||
// No messages should have been added yet
|
// No messages should have been added yet
|
||||||
|
|||||||
Reference in New Issue
Block a user