mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-18 13:49:53 +01:00
Renamed a load of things from 'connection' to 'stream'.
This commit is contained in:
@@ -19,6 +19,7 @@ import static java.util.logging.Level.WARNING;
|
|||||||
import static org.briarproject.android.util.CommonLayoutParams.MATCH_MATCH;
|
import static org.briarproject.android.util.CommonLayoutParams.MATCH_MATCH;
|
||||||
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP;
|
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP;
|
||||||
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP_1;
|
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP_1;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -34,7 +35,9 @@ import java.util.concurrent.Callable;
|
|||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import org.briarproject.R;
|
import org.briarproject.R;
|
||||||
import org.briarproject.android.util.ElasticHorizontalSpace;
|
import org.briarproject.android.util.ElasticHorizontalSpace;
|
||||||
import org.briarproject.android.util.HorizontalBorder;
|
import org.briarproject.android.util.HorizontalBorder;
|
||||||
@@ -50,6 +53,7 @@ import org.briarproject.api.plugins.Plugin;
|
|||||||
import org.briarproject.api.plugins.PluginManager;
|
import org.briarproject.api.plugins.PluginManager;
|
||||||
import org.briarproject.api.system.FileUtils;
|
import org.briarproject.api.system.FileUtils;
|
||||||
import org.briarproject.util.StringUtils;
|
import org.briarproject.util.StringUtils;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.ActivityManager;
|
import android.app.ActivityManager;
|
||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothAdapter;
|
||||||
|
|||||||
@@ -2,7 +2,9 @@ package org.briarproject.system;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.briarproject.api.system.FileUtils;
|
import org.briarproject.api.system.FileUtils;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.StatFs;
|
import android.os.StatFs;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package org.briarproject.system;
|
|||||||
|
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
|
||||||
|
|||||||
@@ -71,21 +71,20 @@ public interface CryptoComponent {
|
|||||||
SecretKey deriveTagKey(byte[] secret, boolean alice);
|
SecretKey deriveTagKey(byte[] secret, boolean alice);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Derives a frame key from the given temporary secret and connection
|
* Derives a frame key from the given temporary secret and stream number.
|
||||||
* number.
|
|
||||||
* @param alice indicates whether the key is for a connection initiated by
|
* @param alice indicates whether the key is for a connection initiated by
|
||||||
* Alice or Bob.
|
* Alice or Bob.
|
||||||
* @param initiator indicates whether the key is for the initiator's or the
|
* @param initiator indicates whether the key is for the initiator's or the
|
||||||
* responder's side of the connection.
|
* responder's side of the connection.
|
||||||
*/
|
*/
|
||||||
SecretKey deriveFrameKey(byte[] secret, long connection, boolean alice,
|
SecretKey deriveFrameKey(byte[] secret, long streamNumber, boolean alice,
|
||||||
boolean initiator);
|
boolean initiator);
|
||||||
|
|
||||||
/** Returns a cipher for encrypting and authenticating connections. */
|
/** Returns a cipher for encrypting and authenticating frames. */
|
||||||
AuthenticatedCipher getFrameCipher();
|
AuthenticatedCipher getFrameCipher();
|
||||||
|
|
||||||
/** Encodes the pseudo-random tag that is used to recognise a connection. */
|
/** Encodes the pseudo-random tag that is used to recognise a stream. */
|
||||||
void encodeTag(byte[] tag, SecretKey tagKey, long connection);
|
void encodeTag(byte[] tag, SecretKey tagKey, long streamNumber);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encrypts and authenticates the given plaintext so it can be written to
|
* Encrypts and authenticates the given plaintext so it can be written to
|
||||||
|
|||||||
@@ -3,21 +3,22 @@ package org.briarproject.api.crypto;
|
|||||||
import org.briarproject.api.ContactId;
|
import org.briarproject.api.ContactId;
|
||||||
import org.briarproject.api.TransportId;
|
import org.briarproject.api.TransportId;
|
||||||
import org.briarproject.api.lifecycle.Service;
|
import org.briarproject.api.lifecycle.Service;
|
||||||
import org.briarproject.api.transport.ConnectionContext;
|
|
||||||
import org.briarproject.api.transport.Endpoint;
|
import org.briarproject.api.transport.Endpoint;
|
||||||
|
import org.briarproject.api.transport.StreamContext;
|
||||||
|
|
||||||
public interface KeyManager extends Service {
|
public interface KeyManager extends Service {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a connection context for connecting to the given contact over
|
* Returns a {@link org.briarproject.api.transport.StreamContext
|
||||||
* the given transport, or null if an error occurs or the contact does not
|
* StreamContext} for sending data to the given contact over the given
|
||||||
* support the transport.
|
* transport, or null if an error occurs or the contact does not support
|
||||||
|
* the transport.
|
||||||
*/
|
*/
|
||||||
ConnectionContext getConnectionContext(ContactId c, TransportId t);
|
StreamContext getStreamContext(ContactId c, TransportId t);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called whenever an endpoint has been added. The initial secret
|
* Called whenever an endpoint has been added. The initial secret is erased
|
||||||
* is erased before returning.
|
* before returning.
|
||||||
*/
|
*/
|
||||||
void endpointAdded(Endpoint ep, long maxLatency, byte[] initialSecret);
|
void endpointAdded(Endpoint ep, long maxLatency, byte[] initialSecret);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -237,11 +237,11 @@ public interface DatabaseComponent {
|
|||||||
Collection<ContactId> getVisibility(GroupId g) throws DbException;
|
Collection<ContactId> getVisibility(GroupId g) throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Increments the outgoing connection counter for the given endpoint
|
* Increments the outgoing stream counter for the given endpoint in the
|
||||||
* in the given rotation period and returns the old value, or -1 if the
|
* given rotation period and returns the old value, or -1 if the counter
|
||||||
* counter does not exist.
|
* does not exist.
|
||||||
*/
|
*/
|
||||||
long incrementConnectionCounter(ContactId c, TransportId t, long period)
|
long incrementStreamCounter(ContactId c, TransportId t, long period)
|
||||||
throws DbException;
|
throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -315,10 +315,10 @@ public interface DatabaseComponent {
|
|||||||
void removeTransport(TransportId t) throws DbException;
|
void removeTransport(TransportId t) throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the connection reordering window for the given endpoint in the
|
* Sets the reordering window for the given endpoint in the given rotation
|
||||||
* given rotation period.
|
* period.
|
||||||
*/
|
*/
|
||||||
void setConnectionWindow(ContactId c, TransportId t, long period,
|
void setReorderingWindow(ContactId c, TransportId t, long period,
|
||||||
long centre, byte[] bitmap) throws DbException;
|
long centre, byte[] bitmap) throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
package org.briarproject.api.messaging;
|
package org.briarproject.api.messaging;
|
||||||
|
|
||||||
import static org.briarproject.api.transport.TransportConstants.MIN_CONNECTION_LENGTH;
|
import static org.briarproject.api.transport.TransportConstants.MIN_STREAM_LENGTH;
|
||||||
|
|
||||||
public interface MessagingConstants {
|
public interface MessagingConstants {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The maximum length of a serialised packet in bytes. To allow for future
|
* The maximum length of a serialised packet in bytes. To allow for future
|
||||||
* changes in the protocol, this is smaller than the minimum connection
|
* changes in the protocol, this is smaller than the minimum stream length
|
||||||
* length minus the maximum encryption and authentication overhead.
|
* minus the maximum encryption and authentication overhead.
|
||||||
*/
|
*/
|
||||||
int MAX_PACKET_LENGTH = MIN_CONNECTION_LENGTH / 2;
|
int MAX_PACKET_LENGTH = MIN_STREAM_LENGTH / 2;
|
||||||
|
|
||||||
/** The maximum number of public groups a user may subscribe to. */
|
/** The maximum number of public groups a user may subscribe to. */
|
||||||
int MAX_SUBSCRIPTIONS = 3000;
|
int MAX_SUBSCRIPTIONS = 3000;
|
||||||
|
|||||||
@@ -3,11 +3,11 @@ package org.briarproject.api.messaging.duplex;
|
|||||||
import org.briarproject.api.ContactId;
|
import org.briarproject.api.ContactId;
|
||||||
import org.briarproject.api.TransportId;
|
import org.briarproject.api.TransportId;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexTransportConnection;
|
import org.briarproject.api.plugins.duplex.DuplexTransportConnection;
|
||||||
import org.briarproject.api.transport.ConnectionContext;
|
import org.briarproject.api.transport.StreamContext;
|
||||||
|
|
||||||
public interface DuplexConnectionFactory {
|
public interface DuplexConnectionFactory {
|
||||||
|
|
||||||
void createIncomingConnection(ConnectionContext ctx,
|
void createIncomingConnection(StreamContext ctx,
|
||||||
DuplexTransportConnection d);
|
DuplexTransportConnection d);
|
||||||
|
|
||||||
void createOutgoingConnection(ContactId c, TransportId t,
|
void createOutgoingConnection(ContactId c, TransportId t,
|
||||||
|
|||||||
@@ -4,11 +4,11 @@ import org.briarproject.api.ContactId;
|
|||||||
import org.briarproject.api.TransportId;
|
import org.briarproject.api.TransportId;
|
||||||
import org.briarproject.api.plugins.simplex.SimplexTransportReader;
|
import org.briarproject.api.plugins.simplex.SimplexTransportReader;
|
||||||
import org.briarproject.api.plugins.simplex.SimplexTransportWriter;
|
import org.briarproject.api.plugins.simplex.SimplexTransportWriter;
|
||||||
import org.briarproject.api.transport.ConnectionContext;
|
import org.briarproject.api.transport.StreamContext;
|
||||||
|
|
||||||
public interface SimplexConnectionFactory {
|
public interface SimplexConnectionFactory {
|
||||||
|
|
||||||
void createIncomingConnection(ConnectionContext ctx,
|
void createIncomingConnection(StreamContext ctx,
|
||||||
SimplexTransportReader r);
|
SimplexTransportReader r);
|
||||||
|
|
||||||
void createOutgoingConnection(ContactId c, TransportId t,
|
void createOutgoingConnection(ContactId c, TransportId t,
|
||||||
|
|||||||
@@ -8,13 +8,13 @@ import org.briarproject.api.plugins.simplex.SimplexTransportWriter;
|
|||||||
|
|
||||||
public interface ConnectionDispatcher {
|
public interface ConnectionDispatcher {
|
||||||
|
|
||||||
void dispatchReader(TransportId t, SimplexTransportReader r);
|
void dispatchIncomingConnection(TransportId t, SimplexTransportReader r);
|
||||||
|
|
||||||
void dispatchWriter(ContactId c, TransportId t,
|
|
||||||
SimplexTransportWriter w);
|
|
||||||
|
|
||||||
void dispatchIncomingConnection(TransportId t, DuplexTransportConnection d);
|
void dispatchIncomingConnection(TransportId t, DuplexTransportConnection d);
|
||||||
|
|
||||||
|
void dispatchOutgoingConnection(ContactId c, TransportId t,
|
||||||
|
SimplexTransportWriter w);
|
||||||
|
|
||||||
void dispatchOutgoingConnection(ContactId c, TransportId t,
|
void dispatchOutgoingConnection(ContactId c, TransportId t,
|
||||||
DuplexTransportConnection d);
|
DuplexTransportConnection d);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +0,0 @@
|
|||||||
package org.briarproject.api.transport;
|
|
||||||
|
|
||||||
import java.io.InputStream;
|
|
||||||
|
|
||||||
public interface ConnectionReaderFactory {
|
|
||||||
|
|
||||||
/** Creates a connection reader for one side of a connection. */
|
|
||||||
ConnectionReader createConnectionReader(InputStream in, int maxFrameLength,
|
|
||||||
ConnectionContext ctx, boolean incoming, boolean initiator);
|
|
||||||
|
|
||||||
/** Creates a connection reader for one side of an invitation connection. */
|
|
||||||
ConnectionReader createInvitationConnectionReader(InputStream in,
|
|
||||||
int maxFrameLength, byte[] secret, boolean alice);
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
package org.briarproject.api.transport;
|
|
||||||
|
|
||||||
import org.briarproject.api.ContactId;
|
|
||||||
import org.briarproject.api.TransportId;
|
|
||||||
import org.briarproject.api.db.DbException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Maintains the connection reordering windows and decides whether incoming
|
|
||||||
* connections should be accepted or rejected.
|
|
||||||
*/
|
|
||||||
public interface ConnectionRecogniser {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the context for the given connection if the connection was
|
|
||||||
* expected, or null if the connection was not expected.
|
|
||||||
*/
|
|
||||||
ConnectionContext acceptConnection(TransportId t, byte[] tag)
|
|
||||||
throws DbException;
|
|
||||||
|
|
||||||
void addSecret(TemporarySecret s);
|
|
||||||
|
|
||||||
void removeSecret(ContactId c, TransportId t, long period);
|
|
||||||
|
|
||||||
void removeSecrets(ContactId c);
|
|
||||||
|
|
||||||
void removeSecrets(TransportId t);
|
|
||||||
|
|
||||||
void removeSecrets();
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
package org.briarproject.api.transport;
|
|
||||||
|
|
||||||
import java.io.OutputStream;
|
|
||||||
|
|
||||||
public interface ConnectionWriterFactory {
|
|
||||||
|
|
||||||
/** Creates a connection writer for one side of a connection. */
|
|
||||||
ConnectionWriter createConnectionWriter(OutputStream out,
|
|
||||||
int maxFrameLength, long capacity, ConnectionContext ctx,
|
|
||||||
boolean incoming, boolean initiator);
|
|
||||||
|
|
||||||
/** Creates a connection writer for one side of an invitation connection. */
|
|
||||||
ConnectionWriter createInvitationConnectionWriter(OutputStream out,
|
|
||||||
int maxFrameLength, byte[] secret, boolean alice);
|
|
||||||
}
|
|
||||||
@@ -3,20 +3,20 @@ package org.briarproject.api.transport;
|
|||||||
import org.briarproject.api.ContactId;
|
import org.briarproject.api.ContactId;
|
||||||
import org.briarproject.api.TransportId;
|
import org.briarproject.api.TransportId;
|
||||||
|
|
||||||
public class ConnectionContext {
|
public class StreamContext {
|
||||||
|
|
||||||
private final ContactId contactId;
|
private final ContactId contactId;
|
||||||
private final TransportId transportId;
|
private final TransportId transportId;
|
||||||
private final byte[] secret;
|
private final byte[] secret;
|
||||||
private final long connection;
|
private final long streamNumber;
|
||||||
private final boolean alice;
|
private final boolean alice;
|
||||||
|
|
||||||
public ConnectionContext(ContactId contactId, TransportId transportId,
|
public StreamContext(ContactId contactId, TransportId transportId,
|
||||||
byte[] secret, long connection, boolean alice) {
|
byte[] secret, long streamNumber, boolean alice) {
|
||||||
this.contactId = contactId;
|
this.contactId = contactId;
|
||||||
this.transportId = transportId;
|
this.transportId = transportId;
|
||||||
this.secret = secret;
|
this.secret = secret;
|
||||||
this.connection = connection;
|
this.streamNumber = streamNumber;
|
||||||
this.alice = alice;
|
this.alice = alice;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,8 +32,8 @@ public class ConnectionContext {
|
|||||||
return secret;
|
return secret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getConnectionNumber() {
|
public long getStreamNumber() {
|
||||||
return connection;
|
return streamNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getAlice() {
|
public boolean getAlice() {
|
||||||
@@ -2,8 +2,8 @@ package org.briarproject.api.transport;
|
|||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
/** Decrypts and authenticates data received over a connection. */
|
/** Decrypts and authenticates data received over an underlying transport. */
|
||||||
public interface ConnectionReader {
|
public interface StreamReader {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an input stream from which the decrypted, authenticated data can
|
* Returns an input stream from which the decrypted, authenticated data can
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package org.briarproject.api.transport;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
public interface StreamReaderFactory {
|
||||||
|
|
||||||
|
/** Creates a {@link StreamReader} for a transport connection. */
|
||||||
|
StreamReader createStreamReader(InputStream in, int maxFrameLength,
|
||||||
|
StreamContext ctx, boolean incoming, boolean initiator);
|
||||||
|
|
||||||
|
/** Creates a {@link StreamReader} for an invitation connection. */
|
||||||
|
StreamReader createInvitationStreamReader(InputStream in,
|
||||||
|
int maxFrameLength, byte[] secret, boolean alice);
|
||||||
|
}
|
||||||
@@ -2,8 +2,8 @@ package org.briarproject.api.transport;
|
|||||||
|
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
|
||||||
/** Encrypts and authenticates data to be sent over a connection. */
|
/** Encrypts and authenticates data to be sent over an underlying transport. */
|
||||||
public interface ConnectionWriter {
|
public interface StreamWriter {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an output stream to which unencrypted, unauthenticated data can
|
* Returns an output stream to which unencrypted, unauthenticated data can
|
||||||
@@ -11,6 +11,9 @@ public interface ConnectionWriter {
|
|||||||
*/
|
*/
|
||||||
OutputStream getOutputStream();
|
OutputStream getOutputStream();
|
||||||
|
|
||||||
/** Returns the maximum number of bytes that can be written. */
|
/**
|
||||||
|
* Returns the maximum number of bytes that can be written to the output
|
||||||
|
* stream.
|
||||||
|
*/
|
||||||
long getRemainingCapacity();
|
long getRemainingCapacity();
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package org.briarproject.api.transport;
|
||||||
|
|
||||||
|
import java.io.OutputStream;
|
||||||
|
|
||||||
|
public interface StreamWriterFactory {
|
||||||
|
|
||||||
|
/** Creates a {@link StreamWriter} for a transport connection. */
|
||||||
|
StreamWriter createStreamWriter(OutputStream out, int maxFrameLength,
|
||||||
|
long capacity, StreamContext ctx, boolean incoming,
|
||||||
|
boolean initiator);
|
||||||
|
|
||||||
|
/** Creates a {@link StreamWriter} for an invitation connection. */
|
||||||
|
StreamWriter createInvitationStreamWriter(OutputStream out,
|
||||||
|
int maxFrameLength, byte[] secret, boolean alice);
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package org.briarproject.api.transport;
|
||||||
|
|
||||||
|
import org.briarproject.api.ContactId;
|
||||||
|
import org.briarproject.api.TransportId;
|
||||||
|
import org.briarproject.api.db.DbException;
|
||||||
|
|
||||||
|
/** Maintains the table of expected tags for recognising incoming streams. */
|
||||||
|
public interface TagRecogniser {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a {@link StreamContext} for reading from the stream with the
|
||||||
|
* given tag if the tag was expected, or null if the tag was unexpected.
|
||||||
|
*/
|
||||||
|
StreamContext recogniseTag(TransportId t, byte[] tag) throws DbException;
|
||||||
|
|
||||||
|
void addSecret(TemporarySecret s);
|
||||||
|
|
||||||
|
void removeSecret(ContactId c, TransportId t, long period);
|
||||||
|
|
||||||
|
void removeSecrets(ContactId c);
|
||||||
|
|
||||||
|
void removeSecrets(TransportId t);
|
||||||
|
|
||||||
|
void removeSecrets();
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package org.briarproject.api.transport;
|
package org.briarproject.api.transport;
|
||||||
|
|
||||||
import static org.briarproject.api.transport.TransportConstants.CONNECTION_WINDOW_SIZE;
|
import static org.briarproject.api.transport.TransportConstants.REORDERING_WINDOW_SIZE;
|
||||||
|
|
||||||
import org.briarproject.api.ContactId;
|
import org.briarproject.api.ContactId;
|
||||||
import org.briarproject.api.TransportId;
|
import org.briarproject.api.TransportId;
|
||||||
|
|
||||||
@@ -9,7 +10,7 @@ public class TemporarySecret extends Endpoint {
|
|||||||
private final long period, outgoing, centre;
|
private final long period, outgoing, centre;
|
||||||
private final byte[] secret, bitmap;
|
private final byte[] secret, bitmap;
|
||||||
|
|
||||||
/** Creates a temporary secret with the given connection window. */
|
/** Creates a temporary secret with the given reordering window. */
|
||||||
public TemporarySecret(ContactId contactId, TransportId transportId,
|
public TemporarySecret(ContactId contactId, TransportId transportId,
|
||||||
long epoch, boolean alice, long period, byte[] secret,
|
long epoch, boolean alice, long period, byte[] secret,
|
||||||
long outgoing, long centre, byte[] bitmap) {
|
long outgoing, long centre, byte[] bitmap) {
|
||||||
@@ -21,11 +22,11 @@ public class TemporarySecret extends Endpoint {
|
|||||||
this.bitmap = bitmap;
|
this.bitmap = bitmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Creates a temporary secret with a new connection window. */
|
/** Creates a temporary secret with a new reordering window. */
|
||||||
public TemporarySecret(ContactId contactId, TransportId transportId,
|
public TemporarySecret(ContactId contactId, TransportId transportId,
|
||||||
long epoch, boolean alice, long period, byte[] secret) {
|
long epoch, boolean alice, long period, byte[] secret) {
|
||||||
this(contactId, transportId, epoch, alice, period, secret, 0, 0,
|
this(contactId, transportId, epoch, alice, period, secret, 0, 0,
|
||||||
new byte[CONNECTION_WINDOW_SIZE / 8]);
|
new byte[REORDERING_WINDOW_SIZE / 8]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Creates a temporary secret derived from the given endpoint. */
|
/** Creates a temporary secret derived from the given endpoint. */
|
||||||
@@ -42,7 +43,7 @@ public class TemporarySecret extends Endpoint {
|
|||||||
return secret;
|
return secret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getOutgoingConnectionCounter() {
|
public long getOutgoingStreamCounter() {
|
||||||
return outgoing;
|
return outgoing;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package org.briarproject.api.transport;
|
|||||||
|
|
||||||
public interface TransportConstants {
|
public interface TransportConstants {
|
||||||
|
|
||||||
/** The length of the connection tag in bytes. */
|
/** The length of the pseudo-random tag in bytes. */
|
||||||
int TAG_LENGTH = 16;
|
int TAG_LENGTH = 16;
|
||||||
|
|
||||||
/** The maximum length of a frame in bytes, including the header and MAC. */
|
/** The maximum length of a frame in bytes, including the header and MAC. */
|
||||||
@@ -21,15 +21,15 @@ public interface TransportConstants {
|
|||||||
int MAC_LENGTH = 16;
|
int MAC_LENGTH = 16;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The minimum connection length in bytes that all transport plugins must
|
* The minimum stream length in bytes that all transport plugins must
|
||||||
* support. Connections may be shorter than this length, but all transport
|
* support. Streams may be shorter than this length, but all transport
|
||||||
* plugins must support connections of at least this length.
|
* plugins must support streams of at least this length.
|
||||||
*/
|
*/
|
||||||
int MIN_CONNECTION_LENGTH = 1024 * 1024; // 2^20, 1 MiB
|
int MIN_STREAM_LENGTH = 1024 * 1024; // 2^20, 1 MiB
|
||||||
|
|
||||||
/** The maximum difference between two communicating devices' clocks. */
|
/** The maximum difference between two communicating devices' clocks. */
|
||||||
int MAX_CLOCK_DIFFERENCE = 60 * 60 * 1000; // 1 hour
|
int MAX_CLOCK_DIFFERENCE = 60 * 60 * 1000; // 1 hour
|
||||||
|
|
||||||
/** The size of the connection reordering window. */
|
/** The size of the reordering window. */
|
||||||
int CONNECTION_WINDOW_SIZE = 32;
|
int REORDERING_WINDOW_SIZE = 32;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -287,20 +287,20 @@ class CryptoComponentImpl implements CryptoComponent {
|
|||||||
else return deriveKey(secret, B_TAG, 0);
|
else return deriveKey(secret, B_TAG, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SecretKey deriveFrameKey(byte[] secret, long connection,
|
public SecretKey deriveFrameKey(byte[] secret, long streamNumber,
|
||||||
boolean alice, boolean initiator) {
|
boolean alice, boolean initiator) {
|
||||||
if(secret.length != CIPHER_KEY_BYTES)
|
if(secret.length != CIPHER_KEY_BYTES)
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
if(Arrays.equals(secret, BLANK_SECRET))
|
if(Arrays.equals(secret, BLANK_SECRET))
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
if(connection < 0 || connection > MAX_32_BIT_UNSIGNED)
|
if(streamNumber < 0 || streamNumber > MAX_32_BIT_UNSIGNED)
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
if(alice) {
|
if(alice) {
|
||||||
if(initiator) return deriveKey(secret, A_FRAME_A, connection);
|
if(initiator) return deriveKey(secret, A_FRAME_A, streamNumber);
|
||||||
else return deriveKey(secret, A_FRAME_B, connection);
|
else return deriveKey(secret, A_FRAME_B, streamNumber);
|
||||||
} else {
|
} else {
|
||||||
if(initiator) return deriveKey(secret, B_FRAME_A, connection);
|
if(initiator) return deriveKey(secret, B_FRAME_A, streamNumber);
|
||||||
else return deriveKey(secret, B_FRAME_B, connection);
|
else return deriveKey(secret, B_FRAME_B, streamNumber);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -318,12 +318,12 @@ class CryptoComponentImpl implements CryptoComponent {
|
|||||||
return new AuthenticatedCipherImpl(a, MAC_BYTES);
|
return new AuthenticatedCipherImpl(a, MAC_BYTES);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void encodeTag(byte[] tag, SecretKey tagKey, long connection) {
|
public void encodeTag(byte[] tag, SecretKey tagKey, long streamNumber) {
|
||||||
if(tag.length < TAG_LENGTH) throw new IllegalArgumentException();
|
if(tag.length < TAG_LENGTH) throw new IllegalArgumentException();
|
||||||
if(connection < 0 || connection > MAX_32_BIT_UNSIGNED)
|
if(streamNumber < 0 || streamNumber > MAX_32_BIT_UNSIGNED)
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
for(int i = 0; i < TAG_LENGTH; i++) tag[i] = 0;
|
for(int i = 0; i < TAG_LENGTH; i++) tag[i] = 0;
|
||||||
ByteUtils.writeUint32(connection, tag, 0);
|
ByteUtils.writeUint32(streamNumber, tag, 0);
|
||||||
BlockCipher cipher = new AESLightEngine();
|
BlockCipher cipher = new AESLightEngine();
|
||||||
assert cipher.getBlockSize() == TAG_LENGTH;
|
assert cipher.getBlockSize() == TAG_LENGTH;
|
||||||
KeyParameter k = new KeyParameter(tagKey.getEncoded());
|
KeyParameter k = new KeyParameter(tagKey.getEncoded());
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package org.briarproject.crypto;
|
package org.briarproject.crypto;
|
||||||
|
|
||||||
import org.briarproject.api.crypto.MessageDigest;
|
import org.briarproject.api.crypto.MessageDigest;
|
||||||
|
|
||||||
import org.spongycastle.crypto.Digest;
|
import org.spongycastle.crypto.Digest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package org.briarproject.crypto;
|
package org.briarproject.crypto;
|
||||||
|
|
||||||
import org.briarproject.api.crypto.PrivateKey;
|
import org.briarproject.api.crypto.PrivateKey;
|
||||||
|
|
||||||
import org.spongycastle.crypto.params.ECPrivateKeyParameters;
|
import org.spongycastle.crypto.params.ECPrivateKeyParameters;
|
||||||
|
|
||||||
class Sec1PrivateKey implements PrivateKey {
|
class Sec1PrivateKey implements PrivateKey {
|
||||||
|
|||||||
@@ -542,14 +542,14 @@ interface Database<T> {
|
|||||||
Collection<ContactId> getVisibility(T txn, GroupId g) throws DbException;
|
Collection<ContactId> getVisibility(T txn, GroupId g) throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Increments the outgoing connection counter for the given endpoint
|
* Increments the outgoing stream counter for the given endpoint in the
|
||||||
* in the given rotation period and returns the old value, or -1 if the
|
* given rotation period and returns the old value, or -1 if the counter
|
||||||
* counter does not exist.
|
* does not exist.
|
||||||
* <p>
|
* <p>
|
||||||
* Locking: write.
|
* Locking: write.
|
||||||
*/
|
*/
|
||||||
long incrementConnectionCounter(T txn, ContactId c, TransportId t,
|
long incrementStreamCounter(T txn, ContactId c, TransportId t, long period)
|
||||||
long period) throws DbException;
|
throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Increments the retention time versions for all contacts to indicate that
|
* Increments the retention time versions for all contacts to indicate that
|
||||||
@@ -694,12 +694,12 @@ interface Database<T> {
|
|||||||
void resetExpiryTime(T txn, ContactId c, MessageId m) throws DbException;
|
void resetExpiryTime(T txn, ContactId c, MessageId m) throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the connection reordering window for the given endpoint in the
|
* Sets the reordering window for the given endpoint in the given rotation
|
||||||
* given rotation period.
|
* period.
|
||||||
* <p>
|
* <p>
|
||||||
* Locking: write.
|
* Locking: write.
|
||||||
*/
|
*/
|
||||||
void setConnectionWindow(T txn, ContactId c, TransportId t, long period,
|
void setReorderingWindow(T txn, ContactId c, TransportId t, long period,
|
||||||
long centre, byte[] bitmap) throws DbException;
|
long centre, byte[] bitmap) throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -986,7 +986,7 @@ DatabaseCleaner.Callback {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public long incrementConnectionCounter(ContactId c, TransportId t,
|
public long incrementStreamCounter(ContactId c, TransportId t,
|
||||||
long period) throws DbException {
|
long period) throws DbException {
|
||||||
lock.writeLock().lock();
|
lock.writeLock().lock();
|
||||||
try {
|
try {
|
||||||
@@ -996,7 +996,7 @@ DatabaseCleaner.Callback {
|
|||||||
throw new NoSuchContactException();
|
throw new NoSuchContactException();
|
||||||
if(!db.containsTransport(txn, t))
|
if(!db.containsTransport(txn, t))
|
||||||
throw new NoSuchTransportException();
|
throw new NoSuchTransportException();
|
||||||
long counter = db.incrementConnectionCounter(txn, c, t, period);
|
long counter = db.incrementStreamCounter(txn, c, t, period);
|
||||||
db.commitTransaction(txn);
|
db.commitTransaction(txn);
|
||||||
return counter;
|
return counter;
|
||||||
} catch(DbException e) {
|
} catch(DbException e) {
|
||||||
@@ -1401,7 +1401,7 @@ DatabaseCleaner.Callback {
|
|||||||
eventBus.broadcast(new TransportRemovedEvent(t));
|
eventBus.broadcast(new TransportRemovedEvent(t));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setConnectionWindow(ContactId c, TransportId t, long period,
|
public void setReorderingWindow(ContactId c, TransportId t, long period,
|
||||||
long centre, byte[] bitmap) throws DbException {
|
long centre, byte[] bitmap) throws DbException {
|
||||||
lock.writeLock().lock();
|
lock.writeLock().lock();
|
||||||
try {
|
try {
|
||||||
@@ -1411,7 +1411,7 @@ DatabaseCleaner.Callback {
|
|||||||
throw new NoSuchContactException();
|
throw new NoSuchContactException();
|
||||||
if(!db.containsTransport(txn, t))
|
if(!db.containsTransport(txn, t))
|
||||||
throw new NoSuchTransportException();
|
throw new NoSuchTransportException();
|
||||||
db.setConnectionWindow(txn, c, t, period, centre, bitmap);
|
db.setReorderingWindow(txn, c, t, period, centre, bitmap);
|
||||||
db.commitTransaction(txn);
|
db.commitTransaction(txn);
|
||||||
} catch(DbException e) {
|
} catch(DbException e) {
|
||||||
db.abortTransaction(txn);
|
db.abortTransaction(txn);
|
||||||
|
|||||||
@@ -813,7 +813,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
ps.setString(2, s.getTransportId().getString());
|
ps.setString(2, s.getTransportId().getString());
|
||||||
ps.setLong(3, s.getPeriod());
|
ps.setLong(3, s.getPeriod());
|
||||||
ps.setBytes(4, s.getSecret());
|
ps.setBytes(4, s.getSecret());
|
||||||
ps.setLong(5, s.getOutgoingConnectionCounter());
|
ps.setLong(5, s.getOutgoingStreamCounter());
|
||||||
ps.setLong(6, s.getWindowCentre());
|
ps.setLong(6, s.getWindowCentre());
|
||||||
ps.setBytes(7, s.getWindowBitmap());
|
ps.setBytes(7, s.getWindowBitmap());
|
||||||
ps.addBatch();
|
ps.addBatch();
|
||||||
@@ -2433,12 +2433,12 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public long incrementConnectionCounter(Connection txn, ContactId c,
|
public long incrementStreamCounter(Connection txn, ContactId c,
|
||||||
TransportId t, long period) throws DbException {
|
TransportId t, long period) throws DbException {
|
||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
try {
|
try {
|
||||||
// Get the current connection counter
|
// Get the current stream counter
|
||||||
String sql = "SELECT outgoing FROM secrets"
|
String sql = "SELECT outgoing FROM secrets"
|
||||||
+ " WHERE contactId = ? AND transportId = ? AND period = ?";
|
+ " WHERE contactId = ? AND transportId = ? AND period = ?";
|
||||||
ps = txn.prepareStatement(sql);
|
ps = txn.prepareStatement(sql);
|
||||||
@@ -2451,11 +2451,11 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
ps.close();
|
ps.close();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
long connection = rs.getLong(1);
|
long streamNumber = rs.getLong(1);
|
||||||
if(rs.next()) throw new DbStateException();
|
if(rs.next()) throw new DbStateException();
|
||||||
rs.close();
|
rs.close();
|
||||||
ps.close();
|
ps.close();
|
||||||
// Increment the connection counter
|
// Increment the stream counter
|
||||||
sql = "UPDATE secrets SET outgoing = outgoing + 1"
|
sql = "UPDATE secrets SET outgoing = outgoing + 1"
|
||||||
+ " WHERE contactId = ? AND transportId = ? AND period = ?";
|
+ " WHERE contactId = ? AND transportId = ? AND period = ?";
|
||||||
ps = txn.prepareStatement(sql);
|
ps = txn.prepareStatement(sql);
|
||||||
@@ -2465,7 +2465,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
int affected = ps.executeUpdate();
|
int affected = ps.executeUpdate();
|
||||||
if(affected != 1) throw new DbStateException();
|
if(affected != 1) throw new DbStateException();
|
||||||
ps.close();
|
ps.close();
|
||||||
return connection;
|
return streamNumber;
|
||||||
} catch(SQLException e) {
|
} catch(SQLException e) {
|
||||||
tryToClose(ps);
|
tryToClose(ps);
|
||||||
tryToClose(rs);
|
tryToClose(rs);
|
||||||
@@ -2907,7 +2907,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
throw new DbException(e);
|
throw new DbException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void setConnectionWindow(Connection txn, ContactId c, TransportId t,
|
public void setReorderingWindow(Connection txn, ContactId c, TransportId t,
|
||||||
long period, long centre, byte[] bitmap) throws DbException {
|
long period, long centre, byte[] bitmap) throws DbException {
|
||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -29,10 +29,10 @@ import org.briarproject.api.serial.Writer;
|
|||||||
import org.briarproject.api.serial.WriterFactory;
|
import org.briarproject.api.serial.WriterFactory;
|
||||||
import org.briarproject.api.system.Clock;
|
import org.briarproject.api.system.Clock;
|
||||||
import org.briarproject.api.transport.ConnectionDispatcher;
|
import org.briarproject.api.transport.ConnectionDispatcher;
|
||||||
import org.briarproject.api.transport.ConnectionReader;
|
import org.briarproject.api.transport.StreamReader;
|
||||||
import org.briarproject.api.transport.ConnectionReaderFactory;
|
import org.briarproject.api.transport.StreamReaderFactory;
|
||||||
import org.briarproject.api.transport.ConnectionWriter;
|
import org.briarproject.api.transport.StreamWriter;
|
||||||
import org.briarproject.api.transport.ConnectionWriterFactory;
|
import org.briarproject.api.transport.StreamWriterFactory;
|
||||||
|
|
||||||
/** A connection thread for the peer being Alice in the invitation protocol. */
|
/** A connection thread for the peer being Alice in the invitation protocol. */
|
||||||
class AliceConnector extends Connector {
|
class AliceConnector extends Connector {
|
||||||
@@ -42,16 +42,16 @@ class AliceConnector extends Connector {
|
|||||||
|
|
||||||
AliceConnector(CryptoComponent crypto, DatabaseComponent db,
|
AliceConnector(CryptoComponent crypto, DatabaseComponent db,
|
||||||
ReaderFactory readerFactory, WriterFactory writerFactory,
|
ReaderFactory readerFactory, WriterFactory writerFactory,
|
||||||
ConnectionReaderFactory connectionReaderFactory,
|
StreamReaderFactory streamReaderFactory,
|
||||||
ConnectionWriterFactory connectionWriterFactory,
|
StreamWriterFactory streamWriterFactory,
|
||||||
AuthorFactory authorFactory, GroupFactory groupFactory,
|
AuthorFactory authorFactory, GroupFactory groupFactory,
|
||||||
KeyManager keyManager, ConnectionDispatcher connectionDispatcher,
|
KeyManager keyManager, ConnectionDispatcher connectionDispatcher,
|
||||||
Clock clock, boolean reuseConnection, ConnectorGroup group,
|
Clock clock, boolean reuseConnection, ConnectorGroup group,
|
||||||
DuplexPlugin plugin, LocalAuthor localAuthor,
|
DuplexPlugin plugin, LocalAuthor localAuthor,
|
||||||
Map<TransportId, TransportProperties> localProps,
|
Map<TransportId, TransportProperties> localProps,
|
||||||
PseudoRandom random) {
|
PseudoRandom random) {
|
||||||
super(crypto, db, readerFactory, writerFactory, connectionReaderFactory,
|
super(crypto, db, readerFactory, writerFactory, streamReaderFactory,
|
||||||
connectionWriterFactory, authorFactory, groupFactory,
|
streamWriterFactory, authorFactory, groupFactory,
|
||||||
keyManager, connectionDispatcher, clock, reuseConnection, group,
|
keyManager, connectionDispatcher, clock, reuseConnection, group,
|
||||||
plugin, localAuthor, localProps, random);
|
plugin, localAuthor, localProps, random);
|
||||||
}
|
}
|
||||||
@@ -131,14 +131,14 @@ class AliceConnector extends Connector {
|
|||||||
if(LOG.isLoggable(INFO))
|
if(LOG.isLoggable(INFO))
|
||||||
LOG.info(pluginName + " confirmation succeeded");
|
LOG.info(pluginName + " confirmation succeeded");
|
||||||
int maxFrameLength = conn.getMaxFrameLength();
|
int maxFrameLength = conn.getMaxFrameLength();
|
||||||
ConnectionReader connectionReader =
|
StreamReader streamReader =
|
||||||
connectionReaderFactory.createInvitationConnectionReader(in,
|
streamReaderFactory.createInvitationStreamReader(in,
|
||||||
maxFrameLength, secret, false);
|
maxFrameLength, secret, false);
|
||||||
r = readerFactory.createReader(connectionReader.getInputStream());
|
r = readerFactory.createReader(streamReader.getInputStream());
|
||||||
ConnectionWriter connectionWriter =
|
StreamWriter streamWriter =
|
||||||
connectionWriterFactory.createInvitationConnectionWriter(out,
|
streamWriterFactory.createInvitationStreamWriter(out,
|
||||||
maxFrameLength, secret, true);
|
maxFrameLength, secret, true);
|
||||||
w = writerFactory.createWriter(connectionWriter.getOutputStream());
|
w = writerFactory.createWriter(streamWriter.getOutputStream());
|
||||||
// Derive the invitation nonces
|
// Derive the invitation nonces
|
||||||
byte[][] nonces = crypto.deriveInvitationNonces(secret);
|
byte[][] nonces = crypto.deriveInvitationNonces(secret);
|
||||||
byte[] aliceNonce = nonces[0], bobNonce = nonces[1];
|
byte[] aliceNonce = nonces[0], bobNonce = nonces[1];
|
||||||
@@ -179,7 +179,7 @@ class AliceConnector extends Connector {
|
|||||||
if(LOG.isLoggable(INFO))
|
if(LOG.isLoggable(INFO))
|
||||||
LOG.info(pluginName + " pseudonym exchange succeeded");
|
LOG.info(pluginName + " pseudonym exchange succeeded");
|
||||||
group.pseudonymExchangeSucceeded(remoteAuthor);
|
group.pseudonymExchangeSucceeded(remoteAuthor);
|
||||||
// Reuse the connection as an outgoing BTP connection
|
// Reuse the connection as an outgoing transport connection
|
||||||
if(reuseConnection) reuseConnection(conn, true);
|
if(reuseConnection) reuseConnection(conn, true);
|
||||||
else tryToClose(conn, false);
|
else tryToClose(conn, false);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,10 +29,10 @@ import org.briarproject.api.serial.Writer;
|
|||||||
import org.briarproject.api.serial.WriterFactory;
|
import org.briarproject.api.serial.WriterFactory;
|
||||||
import org.briarproject.api.system.Clock;
|
import org.briarproject.api.system.Clock;
|
||||||
import org.briarproject.api.transport.ConnectionDispatcher;
|
import org.briarproject.api.transport.ConnectionDispatcher;
|
||||||
import org.briarproject.api.transport.ConnectionReader;
|
import org.briarproject.api.transport.StreamReader;
|
||||||
import org.briarproject.api.transport.ConnectionReaderFactory;
|
import org.briarproject.api.transport.StreamReaderFactory;
|
||||||
import org.briarproject.api.transport.ConnectionWriter;
|
import org.briarproject.api.transport.StreamWriter;
|
||||||
import org.briarproject.api.transport.ConnectionWriterFactory;
|
import org.briarproject.api.transport.StreamWriterFactory;
|
||||||
|
|
||||||
/** A connection thread for the peer being Bob in the invitation protocol. */
|
/** A connection thread for the peer being Bob in the invitation protocol. */
|
||||||
class BobConnector extends Connector {
|
class BobConnector extends Connector {
|
||||||
@@ -42,16 +42,16 @@ class BobConnector extends Connector {
|
|||||||
|
|
||||||
BobConnector(CryptoComponent crypto, DatabaseComponent db,
|
BobConnector(CryptoComponent crypto, DatabaseComponent db,
|
||||||
ReaderFactory readerFactory, WriterFactory writerFactory,
|
ReaderFactory readerFactory, WriterFactory writerFactory,
|
||||||
ConnectionReaderFactory connectionReaderFactory,
|
StreamReaderFactory streamReaderFactory,
|
||||||
ConnectionWriterFactory connectionWriterFactory,
|
StreamWriterFactory streamWriterFactory,
|
||||||
AuthorFactory authorFactory, GroupFactory groupFactory,
|
AuthorFactory authorFactory, GroupFactory groupFactory,
|
||||||
KeyManager keyManager, ConnectionDispatcher connectionDispatcher,
|
KeyManager keyManager, ConnectionDispatcher connectionDispatcher,
|
||||||
Clock clock, boolean reuseConnection, ConnectorGroup group,
|
Clock clock, boolean reuseConnection, ConnectorGroup group,
|
||||||
DuplexPlugin plugin, LocalAuthor localAuthor,
|
DuplexPlugin plugin, LocalAuthor localAuthor,
|
||||||
Map<TransportId, TransportProperties> localProps,
|
Map<TransportId, TransportProperties> localProps,
|
||||||
PseudoRandom random) {
|
PseudoRandom random) {
|
||||||
super(crypto, db, readerFactory, writerFactory, connectionReaderFactory,
|
super(crypto, db, readerFactory, writerFactory, streamReaderFactory,
|
||||||
connectionWriterFactory, authorFactory, groupFactory,
|
streamWriterFactory, authorFactory, groupFactory,
|
||||||
keyManager, connectionDispatcher, clock, reuseConnection, group,
|
keyManager, connectionDispatcher, clock, reuseConnection, group,
|
||||||
plugin, localAuthor, localProps, random);
|
plugin, localAuthor, localProps, random);
|
||||||
}
|
}
|
||||||
@@ -131,14 +131,14 @@ class BobConnector extends Connector {
|
|||||||
if(LOG.isLoggable(INFO))
|
if(LOG.isLoggable(INFO))
|
||||||
LOG.info(pluginName + " confirmation succeeded");
|
LOG.info(pluginName + " confirmation succeeded");
|
||||||
int maxFrameLength = conn.getMaxFrameLength();
|
int maxFrameLength = conn.getMaxFrameLength();
|
||||||
ConnectionReader connectionReader =
|
StreamReader streamReader =
|
||||||
connectionReaderFactory.createInvitationConnectionReader(in,
|
streamReaderFactory.createInvitationStreamReader(in,
|
||||||
maxFrameLength, secret, true);
|
maxFrameLength, secret, true);
|
||||||
r = readerFactory.createReader(connectionReader.getInputStream());
|
r = readerFactory.createReader(streamReader.getInputStream());
|
||||||
ConnectionWriter connectionWriter =
|
StreamWriter streamWriter =
|
||||||
connectionWriterFactory.createInvitationConnectionWriter(out,
|
streamWriterFactory.createInvitationStreamWriter(out,
|
||||||
maxFrameLength, secret, false);
|
maxFrameLength, secret, false);
|
||||||
w = writerFactory.createWriter(connectionWriter.getOutputStream());
|
w = writerFactory.createWriter(streamWriter.getOutputStream());
|
||||||
// Derive the nonces
|
// Derive the nonces
|
||||||
byte[][] nonces = crypto.deriveInvitationNonces(secret);
|
byte[][] nonces = crypto.deriveInvitationNonces(secret);
|
||||||
byte[] aliceNonce = nonces[0], bobNonce = nonces[1];
|
byte[] aliceNonce = nonces[0], bobNonce = nonces[1];
|
||||||
@@ -179,7 +179,7 @@ class BobConnector extends Connector {
|
|||||||
if(LOG.isLoggable(INFO))
|
if(LOG.isLoggable(INFO))
|
||||||
LOG.info(pluginName + " pseudonym exchange succeeded");
|
LOG.info(pluginName + " pseudonym exchange succeeded");
|
||||||
group.pseudonymExchangeSucceeded(remoteAuthor);
|
group.pseudonymExchangeSucceeded(remoteAuthor);
|
||||||
// Reuse the connection as an incoming BTP connection
|
// Reuse the connection as an incoming transport connection
|
||||||
if(reuseConnection) reuseConnection(conn, false);
|
if(reuseConnection) reuseConnection(conn, false);
|
||||||
else tryToClose(conn, false);
|
else tryToClose(conn, false);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,9 +51,9 @@ import org.briarproject.api.serial.Writer;
|
|||||||
import org.briarproject.api.serial.WriterFactory;
|
import org.briarproject.api.serial.WriterFactory;
|
||||||
import org.briarproject.api.system.Clock;
|
import org.briarproject.api.system.Clock;
|
||||||
import org.briarproject.api.transport.ConnectionDispatcher;
|
import org.briarproject.api.transport.ConnectionDispatcher;
|
||||||
import org.briarproject.api.transport.ConnectionReaderFactory;
|
|
||||||
import org.briarproject.api.transport.ConnectionWriterFactory;
|
|
||||||
import org.briarproject.api.transport.Endpoint;
|
import org.briarproject.api.transport.Endpoint;
|
||||||
|
import org.briarproject.api.transport.StreamReaderFactory;
|
||||||
|
import org.briarproject.api.transport.StreamWriterFactory;
|
||||||
|
|
||||||
abstract class Connector extends Thread {
|
abstract class Connector extends Thread {
|
||||||
|
|
||||||
@@ -64,8 +64,8 @@ abstract class Connector extends Thread {
|
|||||||
protected final DatabaseComponent db;
|
protected final DatabaseComponent db;
|
||||||
protected final ReaderFactory readerFactory;
|
protected final ReaderFactory readerFactory;
|
||||||
protected final WriterFactory writerFactory;
|
protected final WriterFactory writerFactory;
|
||||||
protected final ConnectionReaderFactory connectionReaderFactory;
|
protected final StreamReaderFactory streamReaderFactory;
|
||||||
protected final ConnectionWriterFactory connectionWriterFactory;
|
protected final StreamWriterFactory streamWriterFactory;
|
||||||
protected final AuthorFactory authorFactory;
|
protected final AuthorFactory authorFactory;
|
||||||
protected final GroupFactory groupFactory;
|
protected final GroupFactory groupFactory;
|
||||||
protected final KeyManager keyManager;
|
protected final KeyManager keyManager;
|
||||||
@@ -87,8 +87,8 @@ abstract class Connector extends Thread {
|
|||||||
|
|
||||||
Connector(CryptoComponent crypto, DatabaseComponent db,
|
Connector(CryptoComponent crypto, DatabaseComponent db,
|
||||||
ReaderFactory readerFactory, WriterFactory writerFactory,
|
ReaderFactory readerFactory, WriterFactory writerFactory,
|
||||||
ConnectionReaderFactory connectionReaderFactory,
|
StreamReaderFactory streamReaderFactory,
|
||||||
ConnectionWriterFactory connectionWriterFactory,
|
StreamWriterFactory streamWriterFactory,
|
||||||
AuthorFactory authorFactory, GroupFactory groupFactory,
|
AuthorFactory authorFactory, GroupFactory groupFactory,
|
||||||
KeyManager keyManager, ConnectionDispatcher connectionDispatcher,
|
KeyManager keyManager, ConnectionDispatcher connectionDispatcher,
|
||||||
Clock clock, boolean reuseConnection, ConnectorGroup group,
|
Clock clock, boolean reuseConnection, ConnectorGroup group,
|
||||||
@@ -100,8 +100,8 @@ abstract class Connector extends Thread {
|
|||||||
this.db = db;
|
this.db = db;
|
||||||
this.readerFactory = readerFactory;
|
this.readerFactory = readerFactory;
|
||||||
this.writerFactory = writerFactory;
|
this.writerFactory = writerFactory;
|
||||||
this.connectionReaderFactory = connectionReaderFactory;
|
this.streamReaderFactory = streamReaderFactory;
|
||||||
this.connectionWriterFactory = connectionWriterFactory;
|
this.streamWriterFactory = streamWriterFactory;
|
||||||
this.authorFactory = authorFactory;
|
this.authorFactory = authorFactory;
|
||||||
this.groupFactory = groupFactory;
|
this.groupFactory = groupFactory;
|
||||||
this.keyManager = keyManager;
|
this.keyManager = keyManager;
|
||||||
|
|||||||
@@ -33,8 +33,8 @@ import org.briarproject.api.serial.ReaderFactory;
|
|||||||
import org.briarproject.api.serial.WriterFactory;
|
import org.briarproject.api.serial.WriterFactory;
|
||||||
import org.briarproject.api.system.Clock;
|
import org.briarproject.api.system.Clock;
|
||||||
import org.briarproject.api.transport.ConnectionDispatcher;
|
import org.briarproject.api.transport.ConnectionDispatcher;
|
||||||
import org.briarproject.api.transport.ConnectionReaderFactory;
|
import org.briarproject.api.transport.StreamReaderFactory;
|
||||||
import org.briarproject.api.transport.ConnectionWriterFactory;
|
import org.briarproject.api.transport.StreamWriterFactory;
|
||||||
|
|
||||||
/** A task consisting of one or more parallel connection attempts. */
|
/** A task consisting of one or more parallel connection attempts. */
|
||||||
class ConnectorGroup extends Thread implements InvitationTask {
|
class ConnectorGroup extends Thread implements InvitationTask {
|
||||||
@@ -46,8 +46,8 @@ class ConnectorGroup extends Thread implements InvitationTask {
|
|||||||
private final DatabaseComponent db;
|
private final DatabaseComponent db;
|
||||||
private final ReaderFactory readerFactory;
|
private final ReaderFactory readerFactory;
|
||||||
private final WriterFactory writerFactory;
|
private final WriterFactory writerFactory;
|
||||||
private final ConnectionReaderFactory connectionReaderFactory;
|
private final StreamReaderFactory streamReaderFactory;
|
||||||
private final ConnectionWriterFactory connectionWriterFactory;
|
private final StreamWriterFactory streamWriterFactory;
|
||||||
private final AuthorFactory authorFactory;
|
private final AuthorFactory authorFactory;
|
||||||
private final GroupFactory groupFactory;
|
private final GroupFactory groupFactory;
|
||||||
private final KeyManager keyManager;
|
private final KeyManager keyManager;
|
||||||
@@ -64,8 +64,8 @@ class ConnectorGroup extends Thread implements InvitationTask {
|
|||||||
/*
|
/*
|
||||||
* All of the following require locking: this. We don't want to call the
|
* All of the following require locking: this. We don't want to call the
|
||||||
* listeners with a lock held, but we need to avoid a race condition in
|
* listeners with a lock held, but we need to avoid a race condition in
|
||||||
* addListener(), so the state that's accessed there after calling
|
* addListener(), so the state that's accessed in addListener() after
|
||||||
* listeners.add() must be guarded by a lock.
|
* calling listeners.add() must be guarded by a lock.
|
||||||
*/
|
*/
|
||||||
private int localConfirmationCode = -1, remoteConfirmationCode = -1;
|
private int localConfirmationCode = -1, remoteConfirmationCode = -1;
|
||||||
private boolean connectionFailed = false;
|
private boolean connectionFailed = false;
|
||||||
@@ -75,8 +75,8 @@ class ConnectorGroup extends Thread implements InvitationTask {
|
|||||||
|
|
||||||
ConnectorGroup(CryptoComponent crypto, DatabaseComponent db,
|
ConnectorGroup(CryptoComponent crypto, DatabaseComponent db,
|
||||||
ReaderFactory readerFactory, WriterFactory writerFactory,
|
ReaderFactory readerFactory, WriterFactory writerFactory,
|
||||||
ConnectionReaderFactory connectionReaderFactory,
|
StreamReaderFactory streamReaderFactory,
|
||||||
ConnectionWriterFactory connectionWriterFactory,
|
StreamWriterFactory streamWriterFactory,
|
||||||
AuthorFactory authorFactory, GroupFactory groupFactory,
|
AuthorFactory authorFactory, GroupFactory groupFactory,
|
||||||
KeyManager keyManager, ConnectionDispatcher connectionDispatcher,
|
KeyManager keyManager, ConnectionDispatcher connectionDispatcher,
|
||||||
Clock clock, PluginManager pluginManager, AuthorId localAuthorId,
|
Clock clock, PluginManager pluginManager, AuthorId localAuthorId,
|
||||||
@@ -87,8 +87,8 @@ class ConnectorGroup extends Thread implements InvitationTask {
|
|||||||
this.db = db;
|
this.db = db;
|
||||||
this.readerFactory = readerFactory;
|
this.readerFactory = readerFactory;
|
||||||
this.writerFactory = writerFactory;
|
this.writerFactory = writerFactory;
|
||||||
this.connectionReaderFactory = connectionReaderFactory;
|
this.streamReaderFactory = streamReaderFactory;
|
||||||
this.connectionWriterFactory = connectionWriterFactory;
|
this.streamWriterFactory = streamWriterFactory;
|
||||||
this.authorFactory = authorFactory;
|
this.authorFactory = authorFactory;
|
||||||
this.groupFactory = groupFactory;
|
this.groupFactory = groupFactory;
|
||||||
this.keyManager = keyManager;
|
this.keyManager = keyManager;
|
||||||
@@ -176,7 +176,7 @@ class ConnectorGroup extends Thread implements InvitationTask {
|
|||||||
PseudoRandom random = crypto.getPseudoRandom(localInvitationCode,
|
PseudoRandom random = crypto.getPseudoRandom(localInvitationCode,
|
||||||
remoteInvitationCode);
|
remoteInvitationCode);
|
||||||
return new AliceConnector(crypto, db, readerFactory, writerFactory,
|
return new AliceConnector(crypto, db, readerFactory, writerFactory,
|
||||||
connectionReaderFactory, connectionWriterFactory, authorFactory,
|
streamReaderFactory, streamWriterFactory, authorFactory,
|
||||||
groupFactory, keyManager, connectionDispatcher, clock,
|
groupFactory, keyManager, connectionDispatcher, clock,
|
||||||
reuseConnection, this, plugin, localAuthor, localProps, random);
|
reuseConnection, this, plugin, localAuthor, localProps, random);
|
||||||
}
|
}
|
||||||
@@ -187,7 +187,7 @@ class ConnectorGroup extends Thread implements InvitationTask {
|
|||||||
PseudoRandom random = crypto.getPseudoRandom(remoteInvitationCode,
|
PseudoRandom random = crypto.getPseudoRandom(remoteInvitationCode,
|
||||||
localInvitationCode);
|
localInvitationCode);
|
||||||
return new BobConnector(crypto, db, readerFactory, writerFactory,
|
return new BobConnector(crypto, db, readerFactory, writerFactory,
|
||||||
connectionReaderFactory, connectionWriterFactory, authorFactory,
|
streamReaderFactory, streamWriterFactory, authorFactory,
|
||||||
groupFactory, keyManager, connectionDispatcher, clock,
|
groupFactory, keyManager, connectionDispatcher, clock,
|
||||||
reuseConnection, this, plugin, localAuthor, localProps, random);
|
reuseConnection, this, plugin, localAuthor, localProps, random);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ import org.briarproject.api.serial.ReaderFactory;
|
|||||||
import org.briarproject.api.serial.WriterFactory;
|
import org.briarproject.api.serial.WriterFactory;
|
||||||
import org.briarproject.api.system.Clock;
|
import org.briarproject.api.system.Clock;
|
||||||
import org.briarproject.api.transport.ConnectionDispatcher;
|
import org.briarproject.api.transport.ConnectionDispatcher;
|
||||||
import org.briarproject.api.transport.ConnectionReaderFactory;
|
import org.briarproject.api.transport.StreamReaderFactory;
|
||||||
import org.briarproject.api.transport.ConnectionWriterFactory;
|
import org.briarproject.api.transport.StreamWriterFactory;
|
||||||
|
|
||||||
class InvitationTaskFactoryImpl implements InvitationTaskFactory {
|
class InvitationTaskFactoryImpl implements InvitationTaskFactory {
|
||||||
|
|
||||||
@@ -24,8 +24,8 @@ class InvitationTaskFactoryImpl implements InvitationTaskFactory {
|
|||||||
private final DatabaseComponent db;
|
private final DatabaseComponent db;
|
||||||
private final ReaderFactory readerFactory;
|
private final ReaderFactory readerFactory;
|
||||||
private final WriterFactory writerFactory;
|
private final WriterFactory writerFactory;
|
||||||
private final ConnectionReaderFactory connectionReaderFactory;
|
private final StreamReaderFactory streamReaderFactory;
|
||||||
private final ConnectionWriterFactory connectionWriterFactory;
|
private final StreamWriterFactory streamWriterFactory;
|
||||||
private final AuthorFactory authorFactory;
|
private final AuthorFactory authorFactory;
|
||||||
private final GroupFactory groupFactory;
|
private final GroupFactory groupFactory;
|
||||||
private final KeyManager keyManager;
|
private final KeyManager keyManager;
|
||||||
@@ -36,8 +36,8 @@ class InvitationTaskFactoryImpl implements InvitationTaskFactory {
|
|||||||
@Inject
|
@Inject
|
||||||
InvitationTaskFactoryImpl(CryptoComponent crypto, DatabaseComponent db,
|
InvitationTaskFactoryImpl(CryptoComponent crypto, DatabaseComponent db,
|
||||||
ReaderFactory readerFactory, WriterFactory writerFactory,
|
ReaderFactory readerFactory, WriterFactory writerFactory,
|
||||||
ConnectionReaderFactory connectionReaderFactory,
|
StreamReaderFactory streamReaderFactory,
|
||||||
ConnectionWriterFactory connectionWriterFactory,
|
StreamWriterFactory streamWriterFactory,
|
||||||
AuthorFactory authorFactory, GroupFactory groupFactory,
|
AuthorFactory authorFactory, GroupFactory groupFactory,
|
||||||
KeyManager keyManager, ConnectionDispatcher connectionDispatcher,
|
KeyManager keyManager, ConnectionDispatcher connectionDispatcher,
|
||||||
Clock clock, PluginManager pluginManager) {
|
Clock clock, PluginManager pluginManager) {
|
||||||
@@ -45,8 +45,8 @@ class InvitationTaskFactoryImpl implements InvitationTaskFactory {
|
|||||||
this.db = db;
|
this.db = db;
|
||||||
this.readerFactory = readerFactory;
|
this.readerFactory = readerFactory;
|
||||||
this.writerFactory = writerFactory;
|
this.writerFactory = writerFactory;
|
||||||
this.connectionReaderFactory = connectionReaderFactory;
|
this.streamReaderFactory = streamReaderFactory;
|
||||||
this.connectionWriterFactory = connectionWriterFactory;
|
this.streamWriterFactory = streamWriterFactory;
|
||||||
this.authorFactory = authorFactory;
|
this.authorFactory = authorFactory;
|
||||||
this.groupFactory = groupFactory;
|
this.groupFactory = groupFactory;
|
||||||
this.keyManager = keyManager;
|
this.keyManager = keyManager;
|
||||||
@@ -58,7 +58,7 @@ class InvitationTaskFactoryImpl implements InvitationTaskFactory {
|
|||||||
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, db, readerFactory, writerFactory,
|
||||||
connectionReaderFactory, connectionWriterFactory,
|
streamReaderFactory, streamWriterFactory,
|
||||||
authorFactory, groupFactory, keyManager, connectionDispatcher,
|
authorFactory, groupFactory, keyManager, connectionDispatcher,
|
||||||
clock, pluginManager, localAuthorId, localCode, remoteCode,
|
clock, pluginManager, localAuthorId, localCode, remoteCode,
|
||||||
reuseConnection);
|
reuseConnection);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package org.briarproject.messaging;
|
package org.briarproject.messaging;
|
||||||
|
|
||||||
import static org.briarproject.api.messaging.MessagingConstants.MAX_BODY_LENGTH;
|
import static org.briarproject.api.messaging.MessagingConstants.MAX_BODY_LENGTH;
|
||||||
|
|
||||||
import org.briarproject.api.Author;
|
import org.briarproject.api.Author;
|
||||||
import org.briarproject.api.messaging.Group;
|
import org.briarproject.api.messaging.Group;
|
||||||
import org.briarproject.api.messaging.Message;
|
import org.briarproject.api.messaging.Message;
|
||||||
|
|||||||
@@ -51,12 +51,12 @@ import org.briarproject.api.messaging.TransportAck;
|
|||||||
import org.briarproject.api.messaging.TransportUpdate;
|
import org.briarproject.api.messaging.TransportUpdate;
|
||||||
import org.briarproject.api.messaging.UnverifiedMessage;
|
import org.briarproject.api.messaging.UnverifiedMessage;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexTransportConnection;
|
import org.briarproject.api.plugins.duplex.DuplexTransportConnection;
|
||||||
import org.briarproject.api.transport.ConnectionContext;
|
|
||||||
import org.briarproject.api.transport.ConnectionReader;
|
|
||||||
import org.briarproject.api.transport.ConnectionReaderFactory;
|
|
||||||
import org.briarproject.api.transport.ConnectionRegistry;
|
import org.briarproject.api.transport.ConnectionRegistry;
|
||||||
import org.briarproject.api.transport.ConnectionWriter;
|
import org.briarproject.api.transport.StreamContext;
|
||||||
import org.briarproject.api.transport.ConnectionWriterFactory;
|
import org.briarproject.api.transport.StreamReader;
|
||||||
|
import org.briarproject.api.transport.StreamReaderFactory;
|
||||||
|
import org.briarproject.api.transport.StreamWriter;
|
||||||
|
import org.briarproject.api.transport.StreamWriterFactory;
|
||||||
import org.briarproject.util.ByteUtils;
|
import org.briarproject.util.ByteUtils;
|
||||||
|
|
||||||
abstract class DuplexConnection implements EventListener {
|
abstract class DuplexConnection implements EventListener {
|
||||||
@@ -75,11 +75,11 @@ abstract class DuplexConnection implements EventListener {
|
|||||||
protected final DatabaseComponent db;
|
protected final DatabaseComponent db;
|
||||||
protected final EventBus eventBus;
|
protected final EventBus eventBus;
|
||||||
protected final ConnectionRegistry connRegistry;
|
protected final ConnectionRegistry connRegistry;
|
||||||
protected final ConnectionReaderFactory connReaderFactory;
|
protected final StreamReaderFactory connReaderFactory;
|
||||||
protected final ConnectionWriterFactory connWriterFactory;
|
protected final StreamWriterFactory connWriterFactory;
|
||||||
protected final PacketReaderFactory packetReaderFactory;
|
protected final PacketReaderFactory packetReaderFactory;
|
||||||
protected final PacketWriterFactory packetWriterFactory;
|
protected final PacketWriterFactory packetWriterFactory;
|
||||||
protected final ConnectionContext ctx;
|
protected final StreamContext ctx;
|
||||||
protected final DuplexTransportConnection transport;
|
protected final DuplexTransportConnection transport;
|
||||||
protected final ContactId contactId;
|
protected final ContactId contactId;
|
||||||
protected final TransportId transportId;
|
protected final TransportId transportId;
|
||||||
@@ -95,10 +95,10 @@ abstract class DuplexConnection implements EventListener {
|
|||||||
DuplexConnection(Executor dbExecutor, Executor cryptoExecutor,
|
DuplexConnection(Executor dbExecutor, Executor cryptoExecutor,
|
||||||
MessageVerifier messageVerifier, DatabaseComponent db,
|
MessageVerifier messageVerifier, DatabaseComponent db,
|
||||||
EventBus eventBus, ConnectionRegistry connRegistry,
|
EventBus eventBus, ConnectionRegistry connRegistry,
|
||||||
ConnectionReaderFactory connReaderFactory,
|
StreamReaderFactory connReaderFactory,
|
||||||
ConnectionWriterFactory connWriterFactory,
|
StreamWriterFactory connWriterFactory,
|
||||||
PacketReaderFactory packetReaderFactory,
|
PacketReaderFactory packetReaderFactory,
|
||||||
PacketWriterFactory packetWriterFactory, ConnectionContext ctx,
|
PacketWriterFactory packetWriterFactory, StreamContext ctx,
|
||||||
DuplexTransportConnection transport) {
|
DuplexTransportConnection transport) {
|
||||||
this.dbExecutor = dbExecutor;
|
this.dbExecutor = dbExecutor;
|
||||||
this.cryptoExecutor = cryptoExecutor;
|
this.cryptoExecutor = cryptoExecutor;
|
||||||
@@ -119,11 +119,9 @@ abstract class DuplexConnection implements EventListener {
|
|||||||
writerTasks = new LinkedBlockingQueue<Runnable>();
|
writerTasks = new LinkedBlockingQueue<Runnable>();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract ConnectionReader createConnectionReader()
|
protected abstract StreamReader createStreamReader() throws IOException;
|
||||||
throws IOException;
|
|
||||||
|
|
||||||
protected abstract ConnectionWriter createConnectionWriter()
|
protected abstract StreamWriter createStreamWriter() throws IOException;
|
||||||
throws IOException;
|
|
||||||
|
|
||||||
public void eventOccurred(Event e) {
|
public void eventOccurred(Event e) {
|
||||||
if(e instanceof ContactRemovedEvent) {
|
if(e instanceof ContactRemovedEvent) {
|
||||||
@@ -163,7 +161,7 @@ abstract class DuplexConnection implements EventListener {
|
|||||||
|
|
||||||
void read() {
|
void read() {
|
||||||
try {
|
try {
|
||||||
InputStream in = createConnectionReader().getInputStream();
|
InputStream in = createStreamReader().getInputStream();
|
||||||
PacketReader reader = packetReaderFactory.createPacketReader(in);
|
PacketReader reader = packetReaderFactory.createPacketReader(in);
|
||||||
LOG.info("Starting to read");
|
LOG.info("Starting to read");
|
||||||
while(!reader.eof()) {
|
while(!reader.eof()) {
|
||||||
@@ -223,7 +221,7 @@ abstract class DuplexConnection implements EventListener {
|
|||||||
connRegistry.registerConnection(contactId, transportId);
|
connRegistry.registerConnection(contactId, transportId);
|
||||||
eventBus.addListener(this);
|
eventBus.addListener(this);
|
||||||
try {
|
try {
|
||||||
OutputStream out = createConnectionWriter().getOutputStream();
|
OutputStream out = createStreamWriter().getOutputStream();
|
||||||
writer = packetWriterFactory.createPacketWriter(out, true);
|
writer = packetWriterFactory.createPacketWriter(out, true);
|
||||||
LOG.info("Starting to write");
|
LOG.info("Starting to write");
|
||||||
// Ensure the tag is sent
|
// Ensure the tag is sent
|
||||||
|
|||||||
@@ -17,10 +17,10 @@ import org.briarproject.api.messaging.PacketReaderFactory;
|
|||||||
import org.briarproject.api.messaging.PacketWriterFactory;
|
import org.briarproject.api.messaging.PacketWriterFactory;
|
||||||
import org.briarproject.api.messaging.duplex.DuplexConnectionFactory;
|
import org.briarproject.api.messaging.duplex.DuplexConnectionFactory;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexTransportConnection;
|
import org.briarproject.api.plugins.duplex.DuplexTransportConnection;
|
||||||
import org.briarproject.api.transport.ConnectionContext;
|
|
||||||
import org.briarproject.api.transport.ConnectionReaderFactory;
|
|
||||||
import org.briarproject.api.transport.ConnectionRegistry;
|
import org.briarproject.api.transport.ConnectionRegistry;
|
||||||
import org.briarproject.api.transport.ConnectionWriterFactory;
|
import org.briarproject.api.transport.StreamContext;
|
||||||
|
import org.briarproject.api.transport.StreamReaderFactory;
|
||||||
|
import org.briarproject.api.transport.StreamWriterFactory;
|
||||||
|
|
||||||
class DuplexConnectionFactoryImpl implements DuplexConnectionFactory {
|
class DuplexConnectionFactoryImpl implements DuplexConnectionFactory {
|
||||||
|
|
||||||
@@ -33,8 +33,8 @@ class DuplexConnectionFactoryImpl implements DuplexConnectionFactory {
|
|||||||
private final EventBus eventBus;
|
private final EventBus eventBus;
|
||||||
private final KeyManager keyManager;
|
private final KeyManager keyManager;
|
||||||
private final ConnectionRegistry connRegistry;
|
private final ConnectionRegistry connRegistry;
|
||||||
private final ConnectionReaderFactory connReaderFactory;
|
private final StreamReaderFactory connReaderFactory;
|
||||||
private final ConnectionWriterFactory connWriterFactory;
|
private final StreamWriterFactory connWriterFactory;
|
||||||
private final PacketReaderFactory packetReaderFactory;
|
private final PacketReaderFactory packetReaderFactory;
|
||||||
private final PacketWriterFactory packetWriterFactory;
|
private final PacketWriterFactory packetWriterFactory;
|
||||||
|
|
||||||
@@ -44,8 +44,8 @@ class DuplexConnectionFactoryImpl implements DuplexConnectionFactory {
|
|||||||
MessageVerifier messageVerifier, DatabaseComponent db,
|
MessageVerifier messageVerifier, DatabaseComponent db,
|
||||||
EventBus eventBus, KeyManager keyManager,
|
EventBus eventBus, KeyManager keyManager,
|
||||||
ConnectionRegistry connRegistry,
|
ConnectionRegistry connRegistry,
|
||||||
ConnectionReaderFactory connReaderFactory,
|
StreamReaderFactory connReaderFactory,
|
||||||
ConnectionWriterFactory connWriterFactory,
|
StreamWriterFactory connWriterFactory,
|
||||||
PacketReaderFactory packetReaderFactory,
|
PacketReaderFactory packetReaderFactory,
|
||||||
PacketWriterFactory packetWriterFactory) {
|
PacketWriterFactory packetWriterFactory) {
|
||||||
this.dbExecutor = dbExecutor;
|
this.dbExecutor = dbExecutor;
|
||||||
@@ -61,7 +61,7 @@ class DuplexConnectionFactoryImpl implements DuplexConnectionFactory {
|
|||||||
this.packetWriterFactory = packetWriterFactory;
|
this.packetWriterFactory = packetWriterFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createIncomingConnection(ConnectionContext ctx,
|
public void createIncomingConnection(StreamContext ctx,
|
||||||
DuplexTransportConnection transport) {
|
DuplexTransportConnection transport) {
|
||||||
final DuplexConnection conn = new IncomingDuplexConnection(dbExecutor,
|
final DuplexConnection conn = new IncomingDuplexConnection(dbExecutor,
|
||||||
cryptoExecutor, messageVerifier, db, eventBus, connRegistry,
|
cryptoExecutor, messageVerifier, db, eventBus, connRegistry,
|
||||||
@@ -83,9 +83,9 @@ class DuplexConnectionFactoryImpl implements DuplexConnectionFactory {
|
|||||||
|
|
||||||
public void createOutgoingConnection(ContactId c, TransportId t,
|
public void createOutgoingConnection(ContactId c, TransportId t,
|
||||||
DuplexTransportConnection transport) {
|
DuplexTransportConnection transport) {
|
||||||
ConnectionContext ctx = keyManager.getConnectionContext(c, t);
|
StreamContext ctx = keyManager.getStreamContext(c, t);
|
||||||
if(ctx == null) {
|
if(ctx == null) {
|
||||||
LOG.warning("Could not create outgoing connection context");
|
LOG.warning("Could not create outgoing stream context");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final DuplexConnection conn = new OutgoingDuplexConnection(dbExecutor,
|
final DuplexConnection conn = new OutgoingDuplexConnection(dbExecutor,
|
||||||
|
|||||||
@@ -11,41 +11,41 @@ import org.briarproject.api.messaging.MessageVerifier;
|
|||||||
import org.briarproject.api.messaging.PacketReaderFactory;
|
import org.briarproject.api.messaging.PacketReaderFactory;
|
||||||
import org.briarproject.api.messaging.PacketWriterFactory;
|
import org.briarproject.api.messaging.PacketWriterFactory;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexTransportConnection;
|
import org.briarproject.api.plugins.duplex.DuplexTransportConnection;
|
||||||
import org.briarproject.api.transport.ConnectionContext;
|
|
||||||
import org.briarproject.api.transport.ConnectionReader;
|
|
||||||
import org.briarproject.api.transport.ConnectionReaderFactory;
|
|
||||||
import org.briarproject.api.transport.ConnectionRegistry;
|
import org.briarproject.api.transport.ConnectionRegistry;
|
||||||
import org.briarproject.api.transport.ConnectionWriter;
|
import org.briarproject.api.transport.StreamContext;
|
||||||
import org.briarproject.api.transport.ConnectionWriterFactory;
|
import org.briarproject.api.transport.StreamReader;
|
||||||
|
import org.briarproject.api.transport.StreamReaderFactory;
|
||||||
|
import org.briarproject.api.transport.StreamWriter;
|
||||||
|
import org.briarproject.api.transport.StreamWriterFactory;
|
||||||
|
|
||||||
class IncomingDuplexConnection extends DuplexConnection {
|
class IncomingDuplexConnection extends DuplexConnection {
|
||||||
|
|
||||||
IncomingDuplexConnection(Executor dbExecutor, Executor cryptoExecutor,
|
IncomingDuplexConnection(Executor dbExecutor, Executor cryptoExecutor,
|
||||||
MessageVerifier messageVerifier, DatabaseComponent db,
|
MessageVerifier messageVerifier, DatabaseComponent db,
|
||||||
EventBus eventBus, ConnectionRegistry connRegistry,
|
EventBus eventBus, ConnectionRegistry connRegistry,
|
||||||
ConnectionReaderFactory connReaderFactory,
|
StreamReaderFactory connReaderFactory,
|
||||||
ConnectionWriterFactory connWriterFactory,
|
StreamWriterFactory connWriterFactory,
|
||||||
PacketReaderFactory packetReaderFactory,
|
PacketReaderFactory packetReaderFactory,
|
||||||
PacketWriterFactory packetWriterFactory,
|
PacketWriterFactory packetWriterFactory,
|
||||||
ConnectionContext ctx, DuplexTransportConnection transport) {
|
StreamContext ctx, DuplexTransportConnection transport) {
|
||||||
super(dbExecutor, cryptoExecutor, messageVerifier, db, eventBus,
|
super(dbExecutor, cryptoExecutor, messageVerifier, db, eventBus,
|
||||||
connRegistry, connReaderFactory, connWriterFactory,
|
connRegistry, connReaderFactory, connWriterFactory,
|
||||||
packetReaderFactory, packetWriterFactory, ctx, transport);
|
packetReaderFactory, packetWriterFactory, ctx, transport);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ConnectionReader createConnectionReader() throws IOException {
|
protected StreamReader createStreamReader() throws IOException {
|
||||||
InputStream in = transport.getInputStream();
|
InputStream in = transport.getInputStream();
|
||||||
int maxFrameLength = transport.getMaxFrameLength();
|
int maxFrameLength = transport.getMaxFrameLength();
|
||||||
return connReaderFactory.createConnectionReader(in, maxFrameLength,
|
return connReaderFactory.createStreamReader(in, maxFrameLength,
|
||||||
ctx, true, true);
|
ctx, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ConnectionWriter createConnectionWriter() throws IOException {
|
protected StreamWriter createStreamWriter() throws IOException {
|
||||||
OutputStream out = transport.getOutputStream();
|
OutputStream out = transport.getOutputStream();
|
||||||
int maxFrameLength = transport.getMaxFrameLength();
|
int maxFrameLength = transport.getMaxFrameLength();
|
||||||
return connWriterFactory.createConnectionWriter(out, maxFrameLength,
|
return connWriterFactory.createStreamWriter(out, maxFrameLength,
|
||||||
Long.MAX_VALUE, ctx, true, false);
|
Long.MAX_VALUE, ctx, true, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,22 +11,22 @@ import org.briarproject.api.messaging.MessageVerifier;
|
|||||||
import org.briarproject.api.messaging.PacketReaderFactory;
|
import org.briarproject.api.messaging.PacketReaderFactory;
|
||||||
import org.briarproject.api.messaging.PacketWriterFactory;
|
import org.briarproject.api.messaging.PacketWriterFactory;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexTransportConnection;
|
import org.briarproject.api.plugins.duplex.DuplexTransportConnection;
|
||||||
import org.briarproject.api.transport.ConnectionContext;
|
|
||||||
import org.briarproject.api.transport.ConnectionReader;
|
|
||||||
import org.briarproject.api.transport.ConnectionReaderFactory;
|
|
||||||
import org.briarproject.api.transport.ConnectionRegistry;
|
import org.briarproject.api.transport.ConnectionRegistry;
|
||||||
import org.briarproject.api.transport.ConnectionWriter;
|
import org.briarproject.api.transport.StreamContext;
|
||||||
import org.briarproject.api.transport.ConnectionWriterFactory;
|
import org.briarproject.api.transport.StreamReader;
|
||||||
|
import org.briarproject.api.transport.StreamReaderFactory;
|
||||||
|
import org.briarproject.api.transport.StreamWriter;
|
||||||
|
import org.briarproject.api.transport.StreamWriterFactory;
|
||||||
|
|
||||||
class OutgoingDuplexConnection extends DuplexConnection {
|
class OutgoingDuplexConnection extends DuplexConnection {
|
||||||
|
|
||||||
OutgoingDuplexConnection(Executor dbExecutor, Executor cryptoExecutor,
|
OutgoingDuplexConnection(Executor dbExecutor, Executor cryptoExecutor,
|
||||||
MessageVerifier messageVerifier, DatabaseComponent db,
|
MessageVerifier messageVerifier, DatabaseComponent db,
|
||||||
EventBus eventBus, ConnectionRegistry connRegistry,
|
EventBus eventBus, ConnectionRegistry connRegistry,
|
||||||
ConnectionReaderFactory connReaderFactory,
|
StreamReaderFactory connReaderFactory,
|
||||||
ConnectionWriterFactory connWriterFactory,
|
StreamWriterFactory connWriterFactory,
|
||||||
PacketReaderFactory packetReaderFactory,
|
PacketReaderFactory packetReaderFactory,
|
||||||
PacketWriterFactory packetWriterFactory, ConnectionContext ctx,
|
PacketWriterFactory packetWriterFactory, StreamContext ctx,
|
||||||
DuplexTransportConnection transport) {
|
DuplexTransportConnection transport) {
|
||||||
super(dbExecutor, cryptoExecutor, messageVerifier, db, eventBus,
|
super(dbExecutor, cryptoExecutor, messageVerifier, db, eventBus,
|
||||||
connRegistry, connReaderFactory, connWriterFactory,
|
connRegistry, connReaderFactory, connWriterFactory,
|
||||||
@@ -34,18 +34,18 @@ class OutgoingDuplexConnection extends DuplexConnection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ConnectionReader createConnectionReader() throws IOException {
|
protected StreamReader createStreamReader() throws IOException {
|
||||||
InputStream in = transport.getInputStream();
|
InputStream in = transport.getInputStream();
|
||||||
int maxFrameLength = transport.getMaxFrameLength();
|
int maxFrameLength = transport.getMaxFrameLength();
|
||||||
return connReaderFactory.createConnectionReader(in, maxFrameLength,
|
return connReaderFactory.createStreamReader(in, maxFrameLength,
|
||||||
ctx, false, false);
|
ctx, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ConnectionWriter createConnectionWriter() throws IOException {
|
protected StreamWriter createStreamWriter() throws IOException {
|
||||||
OutputStream out = transport.getOutputStream();
|
OutputStream out = transport.getOutputStream();
|
||||||
int maxFrameLength = transport.getMaxFrameLength();
|
int maxFrameLength = transport.getMaxFrameLength();
|
||||||
return connWriterFactory.createConnectionWriter(out, maxFrameLength,
|
return connWriterFactory.createStreamWriter(out, maxFrameLength,
|
||||||
Long.MAX_VALUE, ctx, false, true);
|
Long.MAX_VALUE, ctx, false, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,10 +26,10 @@ import org.briarproject.api.messaging.TransportAck;
|
|||||||
import org.briarproject.api.messaging.TransportUpdate;
|
import org.briarproject.api.messaging.TransportUpdate;
|
||||||
import org.briarproject.api.messaging.UnverifiedMessage;
|
import org.briarproject.api.messaging.UnverifiedMessage;
|
||||||
import org.briarproject.api.plugins.simplex.SimplexTransportReader;
|
import org.briarproject.api.plugins.simplex.SimplexTransportReader;
|
||||||
import org.briarproject.api.transport.ConnectionContext;
|
|
||||||
import org.briarproject.api.transport.ConnectionReader;
|
|
||||||
import org.briarproject.api.transport.ConnectionReaderFactory;
|
|
||||||
import org.briarproject.api.transport.ConnectionRegistry;
|
import org.briarproject.api.transport.ConnectionRegistry;
|
||||||
|
import org.briarproject.api.transport.StreamContext;
|
||||||
|
import org.briarproject.api.transport.StreamReader;
|
||||||
|
import org.briarproject.api.transport.StreamReaderFactory;
|
||||||
import org.briarproject.util.ByteUtils;
|
import org.briarproject.util.ByteUtils;
|
||||||
|
|
||||||
class IncomingSimplexConnection {
|
class IncomingSimplexConnection {
|
||||||
@@ -41,9 +41,9 @@ class IncomingSimplexConnection {
|
|||||||
private final MessageVerifier messageVerifier;
|
private final MessageVerifier messageVerifier;
|
||||||
private final DatabaseComponent db;
|
private final DatabaseComponent db;
|
||||||
private final ConnectionRegistry connRegistry;
|
private final ConnectionRegistry connRegistry;
|
||||||
private final ConnectionReaderFactory connReaderFactory;
|
private final StreamReaderFactory connReaderFactory;
|
||||||
private final PacketReaderFactory packetReaderFactory;
|
private final PacketReaderFactory packetReaderFactory;
|
||||||
private final ConnectionContext ctx;
|
private final StreamContext ctx;
|
||||||
private final SimplexTransportReader transport;
|
private final SimplexTransportReader transport;
|
||||||
private final ContactId contactId;
|
private final ContactId contactId;
|
||||||
private final TransportId transportId;
|
private final TransportId transportId;
|
||||||
@@ -51,8 +51,8 @@ class IncomingSimplexConnection {
|
|||||||
IncomingSimplexConnection(Executor dbExecutor, Executor cryptoExecutor,
|
IncomingSimplexConnection(Executor dbExecutor, Executor cryptoExecutor,
|
||||||
MessageVerifier messageVerifier, DatabaseComponent db,
|
MessageVerifier messageVerifier, DatabaseComponent db,
|
||||||
ConnectionRegistry connRegistry,
|
ConnectionRegistry connRegistry,
|
||||||
ConnectionReaderFactory connReaderFactory,
|
StreamReaderFactory connReaderFactory,
|
||||||
PacketReaderFactory packetReaderFactory, ConnectionContext ctx,
|
PacketReaderFactory packetReaderFactory, StreamContext ctx,
|
||||||
SimplexTransportReader transport) {
|
SimplexTransportReader transport) {
|
||||||
this.dbExecutor = dbExecutor;
|
this.dbExecutor = dbExecutor;
|
||||||
this.cryptoExecutor = cryptoExecutor;
|
this.cryptoExecutor = cryptoExecutor;
|
||||||
@@ -72,7 +72,7 @@ class IncomingSimplexConnection {
|
|||||||
try {
|
try {
|
||||||
InputStream in = transport.getInputStream();
|
InputStream in = transport.getInputStream();
|
||||||
int maxFrameLength = transport.getMaxFrameLength();
|
int maxFrameLength = transport.getMaxFrameLength();
|
||||||
ConnectionReader conn = connReaderFactory.createConnectionReader(in,
|
StreamReader conn = connReaderFactory.createStreamReader(in,
|
||||||
maxFrameLength, ctx, true, true);
|
maxFrameLength, ctx, true, true);
|
||||||
in = conn.getInputStream();
|
in = conn.getInputStream();
|
||||||
PacketReader reader = packetReaderFactory.createPacketReader(in);
|
PacketReader reader = packetReaderFactory.createPacketReader(in);
|
||||||
|
|||||||
@@ -23,10 +23,10 @@ import org.briarproject.api.messaging.SubscriptionUpdate;
|
|||||||
import org.briarproject.api.messaging.TransportAck;
|
import org.briarproject.api.messaging.TransportAck;
|
||||||
import org.briarproject.api.messaging.TransportUpdate;
|
import org.briarproject.api.messaging.TransportUpdate;
|
||||||
import org.briarproject.api.plugins.simplex.SimplexTransportWriter;
|
import org.briarproject.api.plugins.simplex.SimplexTransportWriter;
|
||||||
import org.briarproject.api.transport.ConnectionContext;
|
|
||||||
import org.briarproject.api.transport.ConnectionRegistry;
|
import org.briarproject.api.transport.ConnectionRegistry;
|
||||||
import org.briarproject.api.transport.ConnectionWriter;
|
import org.briarproject.api.transport.StreamContext;
|
||||||
import org.briarproject.api.transport.ConnectionWriterFactory;
|
import org.briarproject.api.transport.StreamWriter;
|
||||||
|
import org.briarproject.api.transport.StreamWriterFactory;
|
||||||
import org.briarproject.util.ByteUtils;
|
import org.briarproject.util.ByteUtils;
|
||||||
|
|
||||||
class OutgoingSimplexConnection {
|
class OutgoingSimplexConnection {
|
||||||
@@ -36,9 +36,9 @@ class OutgoingSimplexConnection {
|
|||||||
|
|
||||||
private final DatabaseComponent db;
|
private final DatabaseComponent db;
|
||||||
private final ConnectionRegistry connRegistry;
|
private final ConnectionRegistry connRegistry;
|
||||||
private final ConnectionWriterFactory connWriterFactory;
|
private final StreamWriterFactory connWriterFactory;
|
||||||
private final PacketWriterFactory packetWriterFactory;
|
private final PacketWriterFactory packetWriterFactory;
|
||||||
private final ConnectionContext ctx;
|
private final StreamContext ctx;
|
||||||
private final SimplexTransportWriter transport;
|
private final SimplexTransportWriter transport;
|
||||||
private final ContactId contactId;
|
private final ContactId contactId;
|
||||||
private final TransportId transportId;
|
private final TransportId transportId;
|
||||||
@@ -46,8 +46,8 @@ class OutgoingSimplexConnection {
|
|||||||
|
|
||||||
OutgoingSimplexConnection(DatabaseComponent db,
|
OutgoingSimplexConnection(DatabaseComponent db,
|
||||||
ConnectionRegistry connRegistry,
|
ConnectionRegistry connRegistry,
|
||||||
ConnectionWriterFactory connWriterFactory,
|
StreamWriterFactory connWriterFactory,
|
||||||
PacketWriterFactory packetWriterFactory, ConnectionContext ctx,
|
PacketWriterFactory packetWriterFactory, StreamContext ctx,
|
||||||
SimplexTransportWriter transport) {
|
SimplexTransportWriter transport) {
|
||||||
this.db = db;
|
this.db = db;
|
||||||
this.connRegistry = connRegistry;
|
this.connRegistry = connRegistry;
|
||||||
@@ -66,7 +66,7 @@ class OutgoingSimplexConnection {
|
|||||||
OutputStream out = transport.getOutputStream();
|
OutputStream out = transport.getOutputStream();
|
||||||
long capacity = transport.getCapacity();
|
long capacity = transport.getCapacity();
|
||||||
int maxFrameLength = transport.getMaxFrameLength();
|
int maxFrameLength = transport.getMaxFrameLength();
|
||||||
ConnectionWriter conn = connWriterFactory.createConnectionWriter(
|
StreamWriter conn = connWriterFactory.createStreamWriter(
|
||||||
out, maxFrameLength, capacity, ctx, false, true);
|
out, maxFrameLength, capacity, ctx, false, true);
|
||||||
out = conn.getOutputStream();
|
out = conn.getOutputStream();
|
||||||
if(conn.getRemainingCapacity() < MAX_PACKET_LENGTH)
|
if(conn.getRemainingCapacity() < MAX_PACKET_LENGTH)
|
||||||
@@ -114,7 +114,7 @@ class OutgoingSimplexConnection {
|
|||||||
connRegistry.unregisterConnection(contactId, transportId);
|
connRegistry.unregisterConnection(contactId, transportId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean writeTransportAcks(ConnectionWriter conn,
|
private boolean writeTransportAcks(StreamWriter conn,
|
||||||
PacketWriter writer) throws DbException, IOException {
|
PacketWriter writer) throws DbException, IOException {
|
||||||
assert conn.getRemainingCapacity() >= MAX_PACKET_LENGTH;
|
assert conn.getRemainingCapacity() >= MAX_PACKET_LENGTH;
|
||||||
Collection<TransportAck> acks = db.generateTransportAcks(contactId);
|
Collection<TransportAck> acks = db.generateTransportAcks(contactId);
|
||||||
@@ -126,7 +126,7 @@ class OutgoingSimplexConnection {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean writeTransportUpdates(ConnectionWriter conn,
|
private boolean writeTransportUpdates(StreamWriter conn,
|
||||||
PacketWriter writer) throws DbException, IOException {
|
PacketWriter writer) throws DbException, IOException {
|
||||||
assert conn.getRemainingCapacity() >= MAX_PACKET_LENGTH;
|
assert conn.getRemainingCapacity() >= MAX_PACKET_LENGTH;
|
||||||
Collection<TransportUpdate> updates =
|
Collection<TransportUpdate> updates =
|
||||||
@@ -139,7 +139,7 @@ class OutgoingSimplexConnection {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean writeSubscriptionAck(ConnectionWriter conn,
|
private boolean writeSubscriptionAck(StreamWriter conn,
|
||||||
PacketWriter writer) throws DbException, IOException {
|
PacketWriter writer) throws DbException, IOException {
|
||||||
assert conn.getRemainingCapacity() >= MAX_PACKET_LENGTH;
|
assert conn.getRemainingCapacity() >= MAX_PACKET_LENGTH;
|
||||||
SubscriptionAck a = db.generateSubscriptionAck(contactId);
|
SubscriptionAck a = db.generateSubscriptionAck(contactId);
|
||||||
@@ -148,7 +148,7 @@ class OutgoingSimplexConnection {
|
|||||||
return conn.getRemainingCapacity() >= MAX_PACKET_LENGTH;
|
return conn.getRemainingCapacity() >= MAX_PACKET_LENGTH;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean writeSubscriptionUpdate(ConnectionWriter conn,
|
private boolean writeSubscriptionUpdate(StreamWriter conn,
|
||||||
PacketWriter writer) throws DbException, IOException {
|
PacketWriter writer) throws DbException, IOException {
|
||||||
assert conn.getRemainingCapacity() >= MAX_PACKET_LENGTH;
|
assert conn.getRemainingCapacity() >= MAX_PACKET_LENGTH;
|
||||||
SubscriptionUpdate u =
|
SubscriptionUpdate u =
|
||||||
@@ -158,7 +158,7 @@ class OutgoingSimplexConnection {
|
|||||||
return conn.getRemainingCapacity() >= MAX_PACKET_LENGTH;
|
return conn.getRemainingCapacity() >= MAX_PACKET_LENGTH;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean writeRetentionAck(ConnectionWriter conn,
|
private boolean writeRetentionAck(StreamWriter conn,
|
||||||
PacketWriter writer) throws DbException, IOException {
|
PacketWriter writer) throws DbException, IOException {
|
||||||
assert conn.getRemainingCapacity() >= MAX_PACKET_LENGTH;
|
assert conn.getRemainingCapacity() >= MAX_PACKET_LENGTH;
|
||||||
RetentionAck a = db.generateRetentionAck(contactId);
|
RetentionAck a = db.generateRetentionAck(contactId);
|
||||||
@@ -167,7 +167,7 @@ class OutgoingSimplexConnection {
|
|||||||
return conn.getRemainingCapacity() >= MAX_PACKET_LENGTH;
|
return conn.getRemainingCapacity() >= MAX_PACKET_LENGTH;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean writeRetentionUpdate(ConnectionWriter conn,
|
private boolean writeRetentionUpdate(StreamWriter conn,
|
||||||
PacketWriter writer) throws DbException, IOException {
|
PacketWriter writer) throws DbException, IOException {
|
||||||
assert conn.getRemainingCapacity() >= MAX_PACKET_LENGTH;
|
assert conn.getRemainingCapacity() >= MAX_PACKET_LENGTH;
|
||||||
RetentionUpdate u = db.generateRetentionUpdate(contactId, maxLatency);
|
RetentionUpdate u = db.generateRetentionUpdate(contactId, maxLatency);
|
||||||
|
|||||||
@@ -17,10 +17,10 @@ import org.briarproject.api.messaging.PacketWriterFactory;
|
|||||||
import org.briarproject.api.messaging.simplex.SimplexConnectionFactory;
|
import org.briarproject.api.messaging.simplex.SimplexConnectionFactory;
|
||||||
import org.briarproject.api.plugins.simplex.SimplexTransportReader;
|
import org.briarproject.api.plugins.simplex.SimplexTransportReader;
|
||||||
import org.briarproject.api.plugins.simplex.SimplexTransportWriter;
|
import org.briarproject.api.plugins.simplex.SimplexTransportWriter;
|
||||||
import org.briarproject.api.transport.ConnectionContext;
|
|
||||||
import org.briarproject.api.transport.ConnectionReaderFactory;
|
|
||||||
import org.briarproject.api.transport.ConnectionRegistry;
|
import org.briarproject.api.transport.ConnectionRegistry;
|
||||||
import org.briarproject.api.transport.ConnectionWriterFactory;
|
import org.briarproject.api.transport.StreamContext;
|
||||||
|
import org.briarproject.api.transport.StreamReaderFactory;
|
||||||
|
import org.briarproject.api.transport.StreamWriterFactory;
|
||||||
|
|
||||||
class SimplexConnectionFactoryImpl implements SimplexConnectionFactory {
|
class SimplexConnectionFactoryImpl implements SimplexConnectionFactory {
|
||||||
|
|
||||||
@@ -32,8 +32,8 @@ class SimplexConnectionFactoryImpl implements SimplexConnectionFactory {
|
|||||||
private final DatabaseComponent db;
|
private final DatabaseComponent db;
|
||||||
private final KeyManager keyManager;
|
private final KeyManager keyManager;
|
||||||
private final ConnectionRegistry connRegistry;
|
private final ConnectionRegistry connRegistry;
|
||||||
private final ConnectionReaderFactory connReaderFactory;
|
private final StreamReaderFactory connReaderFactory;
|
||||||
private final ConnectionWriterFactory connWriterFactory;
|
private final StreamWriterFactory connWriterFactory;
|
||||||
private final PacketReaderFactory packetReaderFactory;
|
private final PacketReaderFactory packetReaderFactory;
|
||||||
private final PacketWriterFactory packetWriterFactory;
|
private final PacketWriterFactory packetWriterFactory;
|
||||||
|
|
||||||
@@ -42,8 +42,8 @@ class SimplexConnectionFactoryImpl implements SimplexConnectionFactory {
|
|||||||
@CryptoExecutor Executor cryptoExecutor,
|
@CryptoExecutor Executor cryptoExecutor,
|
||||||
MessageVerifier messageVerifier, DatabaseComponent db,
|
MessageVerifier messageVerifier, DatabaseComponent db,
|
||||||
KeyManager keyManager, ConnectionRegistry connRegistry,
|
KeyManager keyManager, ConnectionRegistry connRegistry,
|
||||||
ConnectionReaderFactory connReaderFactory,
|
StreamReaderFactory connReaderFactory,
|
||||||
ConnectionWriterFactory connWriterFactory,
|
StreamWriterFactory connWriterFactory,
|
||||||
PacketReaderFactory packetReaderFactory,
|
PacketReaderFactory packetReaderFactory,
|
||||||
PacketWriterFactory packetWriterFactory) {
|
PacketWriterFactory packetWriterFactory) {
|
||||||
this.dbExecutor = dbExecutor;
|
this.dbExecutor = dbExecutor;
|
||||||
@@ -58,7 +58,7 @@ class SimplexConnectionFactoryImpl implements SimplexConnectionFactory {
|
|||||||
this.packetWriterFactory = packetWriterFactory;
|
this.packetWriterFactory = packetWriterFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createIncomingConnection(ConnectionContext ctx,
|
public void createIncomingConnection(StreamContext ctx,
|
||||||
SimplexTransportReader r) {
|
SimplexTransportReader r) {
|
||||||
final IncomingSimplexConnection conn = new IncomingSimplexConnection(
|
final IncomingSimplexConnection conn = new IncomingSimplexConnection(
|
||||||
dbExecutor, cryptoExecutor, messageVerifier, db, connRegistry,
|
dbExecutor, cryptoExecutor, messageVerifier, db, connRegistry,
|
||||||
@@ -73,7 +73,7 @@ class SimplexConnectionFactoryImpl implements SimplexConnectionFactory {
|
|||||||
|
|
||||||
public void createOutgoingConnection(ContactId c, TransportId t,
|
public void createOutgoingConnection(ContactId c, TransportId t,
|
||||||
SimplexTransportWriter w) {
|
SimplexTransportWriter w) {
|
||||||
ConnectionContext ctx = keyManager.getConnectionContext(c, t);
|
StreamContext ctx = keyManager.getStreamContext(c, t);
|
||||||
if(ctx == null) {
|
if(ctx == null) {
|
||||||
LOG.warning("Could not create outgoing connection context");
|
LOG.warning("Could not create outgoing connection context");
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -378,11 +378,11 @@ class PluginManagerImpl implements PluginManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void readerCreated(SimplexTransportReader r) {
|
public void readerCreated(SimplexTransportReader r) {
|
||||||
dispatcher.dispatchReader(id, r);
|
dispatcher.dispatchIncomingConnection(id, r);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writerCreated(ContactId c, SimplexTransportWriter w) {
|
public void writerCreated(ContactId c, SimplexTransportWriter w) {
|
||||||
dispatcher.dispatchWriter(c, id, w);
|
dispatcher.dispatchOutgoingConnection(c, id, w);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package org.briarproject.plugins.file;
|
package org.briarproject.plugins.file;
|
||||||
|
|
||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
import static org.briarproject.api.transport.TransportConstants.MIN_CONNECTION_LENGTH;
|
import static org.briarproject.api.transport.TransportConstants.MIN_STREAM_LENGTH;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
@@ -88,7 +88,7 @@ public abstract class FilePlugin implements SimplexPlugin {
|
|||||||
File f = new File(dir, filename);
|
File f = new File(dir, filename);
|
||||||
try {
|
try {
|
||||||
long capacity = fileUtils.getFreeSpace(dir);
|
long capacity = fileUtils.getFreeSpace(dir);
|
||||||
if(capacity < MIN_CONNECTION_LENGTH) return null;
|
if(capacity < MIN_STREAM_LENGTH) return null;
|
||||||
OutputStream out = new FileOutputStream(f);
|
OutputStream out = new FileOutputStream(f);
|
||||||
return new FileTransportWriter(f, out, capacity, this);
|
return new FileTransportWriter(f, out, capacity, this);
|
||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
|
|||||||
@@ -10,10 +10,9 @@ import java.util.logging.Logger;
|
|||||||
|
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
|
||||||
import org.briarproject.api.lifecycle.ShutdownManager;
|
|
||||||
|
|
||||||
import org.bitlet.weupnp.GatewayDevice;
|
import org.bitlet.weupnp.GatewayDevice;
|
||||||
import org.bitlet.weupnp.GatewayDiscover;
|
import org.bitlet.weupnp.GatewayDiscover;
|
||||||
|
import org.briarproject.api.lifecycle.ShutdownManager;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
class PortMapperImpl implements PortMapper {
|
class PortMapperImpl implements PortMapper {
|
||||||
|
|||||||
@@ -20,9 +20,9 @@ import org.briarproject.api.messaging.simplex.SimplexConnectionFactory;
|
|||||||
import org.briarproject.api.plugins.duplex.DuplexTransportConnection;
|
import org.briarproject.api.plugins.duplex.DuplexTransportConnection;
|
||||||
import org.briarproject.api.plugins.simplex.SimplexTransportReader;
|
import org.briarproject.api.plugins.simplex.SimplexTransportReader;
|
||||||
import org.briarproject.api.plugins.simplex.SimplexTransportWriter;
|
import org.briarproject.api.plugins.simplex.SimplexTransportWriter;
|
||||||
import org.briarproject.api.transport.ConnectionContext;
|
|
||||||
import org.briarproject.api.transport.ConnectionDispatcher;
|
import org.briarproject.api.transport.ConnectionDispatcher;
|
||||||
import org.briarproject.api.transport.ConnectionRecogniser;
|
import org.briarproject.api.transport.StreamContext;
|
||||||
|
import org.briarproject.api.transport.TagRecogniser;
|
||||||
|
|
||||||
class ConnectionDispatcherImpl implements ConnectionDispatcher {
|
class ConnectionDispatcherImpl implements ConnectionDispatcher {
|
||||||
|
|
||||||
@@ -30,35 +30,36 @@ class ConnectionDispatcherImpl implements ConnectionDispatcher {
|
|||||||
Logger.getLogger(ConnectionDispatcherImpl.class.getName());
|
Logger.getLogger(ConnectionDispatcherImpl.class.getName());
|
||||||
|
|
||||||
private final Executor ioExecutor;
|
private final Executor ioExecutor;
|
||||||
private final ConnectionRecogniser recogniser;
|
private final TagRecogniser tagRecogniser;
|
||||||
private final SimplexConnectionFactory simplexConnFactory;
|
private final SimplexConnectionFactory simplexConnFactory;
|
||||||
private final DuplexConnectionFactory duplexConnFactory;
|
private final DuplexConnectionFactory duplexConnFactory;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
ConnectionDispatcherImpl(@IoExecutor Executor ioExecutor,
|
ConnectionDispatcherImpl(@IoExecutor Executor ioExecutor,
|
||||||
ConnectionRecogniser recogniser,
|
TagRecogniser tagRecogniser,
|
||||||
SimplexConnectionFactory simplexConnFactory,
|
SimplexConnectionFactory simplexConnFactory,
|
||||||
DuplexConnectionFactory duplexConnFactory) {
|
DuplexConnectionFactory duplexConnFactory) {
|
||||||
this.ioExecutor = ioExecutor;
|
this.ioExecutor = ioExecutor;
|
||||||
this.recogniser = recogniser;
|
this.tagRecogniser = tagRecogniser;
|
||||||
this.simplexConnFactory = simplexConnFactory;
|
this.simplexConnFactory = simplexConnFactory;
|
||||||
this.duplexConnFactory = duplexConnFactory;
|
this.duplexConnFactory = duplexConnFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dispatchReader(TransportId t, SimplexTransportReader r) {
|
public void dispatchIncomingConnection(TransportId t,
|
||||||
|
SimplexTransportReader r) {
|
||||||
ioExecutor.execute(new DispatchSimplexConnection(t, r));
|
ioExecutor.execute(new DispatchSimplexConnection(t, r));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dispatchWriter(ContactId c, TransportId t,
|
|
||||||
SimplexTransportWriter w) {
|
|
||||||
simplexConnFactory.createOutgoingConnection(c, t, w);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void dispatchIncomingConnection(TransportId t,
|
public void dispatchIncomingConnection(TransportId t,
|
||||||
DuplexTransportConnection d) {
|
DuplexTransportConnection d) {
|
||||||
ioExecutor.execute(new DispatchDuplexConnection(t, d));
|
ioExecutor.execute(new DispatchDuplexConnection(t, d));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void dispatchOutgoingConnection(ContactId c, TransportId t,
|
||||||
|
SimplexTransportWriter w) {
|
||||||
|
simplexConnFactory.createOutgoingConnection(c, t, w);
|
||||||
|
}
|
||||||
|
|
||||||
public void dispatchOutgoingConnection(ContactId c, TransportId t,
|
public void dispatchOutgoingConnection(ContactId c, TransportId t,
|
||||||
DuplexTransportConnection d) {
|
DuplexTransportConnection d) {
|
||||||
duplexConnFactory.createOutgoingConnection(c, t, d);
|
duplexConnFactory.createOutgoingConnection(c, t, d);
|
||||||
@@ -89,7 +90,7 @@ class ConnectionDispatcherImpl implements ConnectionDispatcher {
|
|||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
byte[] tag = readTag(transport.getInputStream());
|
byte[] tag = readTag(transport.getInputStream());
|
||||||
ConnectionContext ctx = recogniser.acceptConnection(transportId,
|
StreamContext ctx = tagRecogniser.recogniseTag(transportId,
|
||||||
tag);
|
tag);
|
||||||
if(ctx == null) {
|
if(ctx == null) {
|
||||||
transport.dispose(false, false);
|
transport.dispose(false, false);
|
||||||
@@ -137,9 +138,9 @@ class ConnectionDispatcherImpl implements ConnectionDispatcher {
|
|||||||
dispose(true, false);
|
dispose(true, false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ConnectionContext ctx = null;
|
StreamContext ctx = null;
|
||||||
try {
|
try {
|
||||||
ctx = recogniser.acceptConnection(transportId, tag);
|
ctx = tagRecogniser.recogniseTag(transportId, tag);
|
||||||
} 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);
|
||||||
dispose(true, false);
|
dispose(true, false);
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import static org.briarproject.api.transport.TransportConstants.IV_LENGTH;
|
|||||||
import static org.briarproject.api.transport.TransportConstants.MAC_LENGTH;
|
import static org.briarproject.api.transport.TransportConstants.MAC_LENGTH;
|
||||||
import static org.briarproject.api.transport.TransportConstants.MAX_FRAME_LENGTH;
|
import static org.briarproject.api.transport.TransportConstants.MAX_FRAME_LENGTH;
|
||||||
import static org.briarproject.util.ByteUtils.MAX_32_BIT_UNSIGNED;
|
import static org.briarproject.util.ByteUtils.MAX_32_BIT_UNSIGNED;
|
||||||
|
|
||||||
import org.briarproject.util.ByteUtils;
|
import org.briarproject.util.ByteUtils;
|
||||||
|
|
||||||
class FrameEncoder {
|
class FrameEncoder {
|
||||||
|
|||||||
@@ -29,9 +29,9 @@ import org.briarproject.api.event.TransportAddedEvent;
|
|||||||
import org.briarproject.api.event.TransportRemovedEvent;
|
import org.briarproject.api.event.TransportRemovedEvent;
|
||||||
import org.briarproject.api.system.Clock;
|
import org.briarproject.api.system.Clock;
|
||||||
import org.briarproject.api.system.Timer;
|
import org.briarproject.api.system.Timer;
|
||||||
import org.briarproject.api.transport.ConnectionContext;
|
|
||||||
import org.briarproject.api.transport.ConnectionRecogniser;
|
|
||||||
import org.briarproject.api.transport.Endpoint;
|
import org.briarproject.api.transport.Endpoint;
|
||||||
|
import org.briarproject.api.transport.StreamContext;
|
||||||
|
import org.briarproject.api.transport.TagRecogniser;
|
||||||
import org.briarproject.api.transport.TemporarySecret;
|
import org.briarproject.api.transport.TemporarySecret;
|
||||||
import org.briarproject.util.ByteUtils;
|
import org.briarproject.util.ByteUtils;
|
||||||
|
|
||||||
@@ -46,7 +46,7 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
|
|||||||
private final CryptoComponent crypto;
|
private final CryptoComponent crypto;
|
||||||
private final DatabaseComponent db;
|
private final DatabaseComponent db;
|
||||||
private final EventBus eventBus;
|
private final EventBus eventBus;
|
||||||
private final ConnectionRecogniser connectionRecogniser;
|
private final TagRecogniser connectionRecogniser;
|
||||||
private final Clock clock;
|
private final Clock clock;
|
||||||
private final Timer timer;
|
private final Timer timer;
|
||||||
|
|
||||||
@@ -58,7 +58,7 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
|
|||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
KeyManagerImpl(CryptoComponent crypto, DatabaseComponent db,
|
KeyManagerImpl(CryptoComponent crypto, DatabaseComponent db,
|
||||||
EventBus eventBus, ConnectionRecogniser connectionRecogniser,
|
EventBus eventBus, TagRecogniser connectionRecogniser,
|
||||||
Clock clock, Timer timer) {
|
Clock clock, Timer timer) {
|
||||||
this.crypto = crypto;
|
this.crypto = crypto;
|
||||||
this.db = db;
|
this.db = db;
|
||||||
@@ -232,17 +232,17 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
|
|||||||
m.clear();
|
m.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized ConnectionContext getConnectionContext(ContactId c,
|
public synchronized StreamContext getStreamContext(ContactId c,
|
||||||
TransportId t) {
|
TransportId t) {
|
||||||
TemporarySecret s = currentSecrets.get(new EndpointKey(c, t));
|
TemporarySecret s = currentSecrets.get(new EndpointKey(c, t));
|
||||||
if(s == null) {
|
if(s == null) {
|
||||||
LOG.info("No secret for endpoint");
|
LOG.info("No secret for endpoint");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
long connection;
|
long streamNumber;
|
||||||
try {
|
try {
|
||||||
connection = db.incrementConnectionCounter(c, t, s.getPeriod());
|
streamNumber = db.incrementStreamCounter(c, t, s.getPeriod());
|
||||||
if(connection == -1) {
|
if(streamNumber == -1) {
|
||||||
LOG.info("No counter for period");
|
LOG.info("No counter for period");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -252,7 +252,7 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
|
|||||||
}
|
}
|
||||||
// Clone the secret - the original will be erased
|
// Clone the secret - the original will be erased
|
||||||
byte[] secret = s.getSecret().clone();
|
byte[] secret = s.getSecret().clone();
|
||||||
return new ConnectionContext(c, t, secret, connection, s.getAlice());
|
return new StreamContext(c, t, secret, streamNumber, s.getAlice());
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void endpointAdded(Endpoint ep, long maxLatency,
|
public synchronized void endpointAdded(Endpoint ep, long maxLatency,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package org.briarproject.transport;
|
package org.briarproject.transport;
|
||||||
|
|
||||||
import static org.briarproject.api.transport.TransportConstants.CONNECTION_WINDOW_SIZE;
|
import static org.briarproject.api.transport.TransportConstants.REORDERING_WINDOW_SIZE;
|
||||||
import static org.briarproject.util.ByteUtils.MAX_32_BIT_UNSIGNED;
|
import static org.briarproject.util.ByteUtils.MAX_32_BIT_UNSIGNED;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -9,51 +9,51 @@ import java.util.HashSet;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
// This class is not thread-safe
|
// This class is not thread-safe
|
||||||
class ConnectionWindow {
|
class ReorderingWindow {
|
||||||
|
|
||||||
private final Set<Long> unseen;
|
private final Set<Long> unseen;
|
||||||
|
|
||||||
private long centre;
|
private long centre;
|
||||||
|
|
||||||
ConnectionWindow() {
|
ReorderingWindow() {
|
||||||
unseen = new HashSet<Long>();
|
unseen = new HashSet<Long>();
|
||||||
for(long l = 0; l < CONNECTION_WINDOW_SIZE / 2; l++) unseen.add(l);
|
for(long l = 0; l < REORDERING_WINDOW_SIZE / 2; l++) unseen.add(l);
|
||||||
centre = 0;
|
centre = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ConnectionWindow(long centre, byte[] bitmap) {
|
ReorderingWindow(long centre, byte[] bitmap) {
|
||||||
if(centre < 0 || centre > MAX_32_BIT_UNSIGNED + 1)
|
if(centre < 0 || centre > MAX_32_BIT_UNSIGNED + 1)
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
if(bitmap.length != CONNECTION_WINDOW_SIZE / 8)
|
if(bitmap.length != REORDERING_WINDOW_SIZE / 8)
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
this.centre = centre;
|
this.centre = centre;
|
||||||
unseen = new HashSet<Long>();
|
unseen = new HashSet<Long>();
|
||||||
long bitmapBottom = centre - CONNECTION_WINDOW_SIZE / 2;
|
long bitmapBottom = centre - REORDERING_WINDOW_SIZE / 2;
|
||||||
for(int bytes = 0; bytes < bitmap.length; bytes++) {
|
for(int bytes = 0; bytes < bitmap.length; bytes++) {
|
||||||
for(int bits = 0; bits < 8; bits++) {
|
for(int bits = 0; bits < 8; bits++) {
|
||||||
long connection = bitmapBottom + bytes * 8 + bits;
|
long streamNumber = bitmapBottom + bytes * 8 + bits;
|
||||||
if(connection >= 0 && connection <= MAX_32_BIT_UNSIGNED) {
|
if(streamNumber >= 0 && streamNumber <= MAX_32_BIT_UNSIGNED) {
|
||||||
if((bitmap[bytes] & (128 >> bits)) == 0)
|
if((bitmap[bytes] & (128 >> bits)) == 0)
|
||||||
unseen.add(connection);
|
unseen.add(streamNumber);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isSeen(long connection) {
|
boolean isSeen(long streamNumber) {
|
||||||
return !unseen.contains(connection);
|
return !unseen.contains(streamNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
Collection<Long> setSeen(long connection) {
|
Collection<Long> setSeen(long streamNumber) {
|
||||||
long bottom = getBottom(centre);
|
long bottom = getBottom(centre);
|
||||||
long top = getTop(centre);
|
long top = getTop(centre);
|
||||||
if(connection < bottom || connection > top)
|
if(streamNumber < bottom || streamNumber > top)
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
if(!unseen.remove(connection))
|
if(!unseen.remove(streamNumber))
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
Collection<Long> changed = new ArrayList<Long>();
|
Collection<Long> changed = new ArrayList<Long>();
|
||||||
if(connection >= centre) {
|
if(streamNumber >= centre) {
|
||||||
centre = connection + 1;
|
centre = streamNumber + 1;
|
||||||
long newBottom = getBottom(centre);
|
long newBottom = getBottom(centre);
|
||||||
long newTop = getTop(centre);
|
long newTop = getTop(centre);
|
||||||
for(long l = bottom; l < newBottom; l++) {
|
for(long l = bottom; l < newBottom; l++) {
|
||||||
@@ -71,13 +71,13 @@ class ConnectionWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
byte[] getBitmap() {
|
byte[] getBitmap() {
|
||||||
byte[] bitmap = new byte[CONNECTION_WINDOW_SIZE / 8];
|
byte[] bitmap = new byte[REORDERING_WINDOW_SIZE / 8];
|
||||||
long bitmapBottom = centre - CONNECTION_WINDOW_SIZE / 2;
|
long bitmapBottom = centre - REORDERING_WINDOW_SIZE / 2;
|
||||||
for(int bytes = 0; bytes < bitmap.length; bytes++) {
|
for(int bytes = 0; bytes < bitmap.length; bytes++) {
|
||||||
for(int bits = 0; bits < 8; bits++) {
|
for(int bits = 0; bits < 8; bits++) {
|
||||||
long connection = bitmapBottom + bytes * 8 + bits;
|
long streamNumber = bitmapBottom + bytes * 8 + bits;
|
||||||
if(connection >= 0 && connection <= MAX_32_BIT_UNSIGNED) {
|
if(streamNumber >= 0 && streamNumber <= MAX_32_BIT_UNSIGNED) {
|
||||||
if(!unseen.contains(connection))
|
if(!unseen.contains(streamNumber))
|
||||||
bitmap[bytes] |= 128 >> bits;
|
bitmap[bytes] |= 128 >> bits;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -87,13 +87,13 @@ class ConnectionWindow {
|
|||||||
|
|
||||||
// Returns the lowest value contained in a window with the given centre
|
// Returns the lowest value contained in a window with the given centre
|
||||||
private static long getBottom(long centre) {
|
private static long getBottom(long centre) {
|
||||||
return Math.max(0, centre - CONNECTION_WINDOW_SIZE / 2);
|
return Math.max(0, centre - REORDERING_WINDOW_SIZE / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the highest value contained in a window with the given centre
|
// Returns the highest value contained in a window with the given centre
|
||||||
private static long getTop(long centre) {
|
private static long getTop(long centre) {
|
||||||
return Math.min(MAX_32_BIT_UNSIGNED,
|
return Math.min(MAX_32_BIT_UNSIGNED,
|
||||||
centre + CONNECTION_WINDOW_SIZE / 2 - 1);
|
centre + REORDERING_WINDOW_SIZE / 2 - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<Long> getUnseen() {
|
public Collection<Long> getUnseen() {
|
||||||
@@ -6,38 +6,38 @@ import javax.inject.Inject;
|
|||||||
|
|
||||||
import org.briarproject.api.crypto.CryptoComponent;
|
import org.briarproject.api.crypto.CryptoComponent;
|
||||||
import org.briarproject.api.crypto.SecretKey;
|
import org.briarproject.api.crypto.SecretKey;
|
||||||
import org.briarproject.api.transport.ConnectionContext;
|
import org.briarproject.api.transport.StreamContext;
|
||||||
import org.briarproject.api.transport.ConnectionReader;
|
import org.briarproject.api.transport.StreamReader;
|
||||||
import org.briarproject.api.transport.ConnectionReaderFactory;
|
import org.briarproject.api.transport.StreamReaderFactory;
|
||||||
|
|
||||||
class ConnectionReaderFactoryImpl implements ConnectionReaderFactory {
|
class StreamReaderFactoryImpl implements StreamReaderFactory {
|
||||||
|
|
||||||
private final CryptoComponent crypto;
|
private final CryptoComponent crypto;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
ConnectionReaderFactoryImpl(CryptoComponent crypto) {
|
StreamReaderFactoryImpl(CryptoComponent crypto) {
|
||||||
this.crypto = crypto;
|
this.crypto = crypto;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConnectionReader createConnectionReader(InputStream in,
|
public StreamReader createStreamReader(InputStream in,
|
||||||
int maxFrameLength, ConnectionContext ctx, boolean incoming,
|
int maxFrameLength, StreamContext ctx, boolean incoming,
|
||||||
boolean initiator) {
|
boolean initiator) {
|
||||||
byte[] secret = ctx.getSecret();
|
byte[] secret = ctx.getSecret();
|
||||||
long connection = ctx.getConnectionNumber();
|
long streamNumber = ctx.getStreamNumber();
|
||||||
boolean weAreAlice = ctx.getAlice();
|
boolean weAreAlice = ctx.getAlice();
|
||||||
boolean initiatorIsAlice = incoming ? !weAreAlice : weAreAlice;
|
boolean initiatorIsAlice = incoming ? !weAreAlice : weAreAlice;
|
||||||
SecretKey frameKey = crypto.deriveFrameKey(secret, connection,
|
SecretKey frameKey = crypto.deriveFrameKey(secret, streamNumber,
|
||||||
initiatorIsAlice, initiator);
|
initiatorIsAlice, initiator);
|
||||||
FrameReader encryption = new IncomingEncryptionLayer(in,
|
FrameReader encryption = new IncomingEncryptionLayer(in,
|
||||||
crypto.getFrameCipher(), frameKey, maxFrameLength);
|
crypto.getFrameCipher(), frameKey, maxFrameLength);
|
||||||
return new ConnectionReaderImpl(encryption, maxFrameLength);
|
return new StreamReaderImpl(encryption, maxFrameLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConnectionReader createInvitationConnectionReader(InputStream in,
|
public StreamReader createInvitationStreamReader(InputStream in,
|
||||||
int maxFrameLength, byte[] secret, boolean alice) {
|
int maxFrameLength, byte[] secret, boolean alice) {
|
||||||
SecretKey frameKey = crypto.deriveFrameKey(secret, 0, true, alice);
|
SecretKey frameKey = crypto.deriveFrameKey(secret, 0, true, alice);
|
||||||
FrameReader encryption = new IncomingEncryptionLayer(in,
|
FrameReader encryption = new IncomingEncryptionLayer(in,
|
||||||
crypto.getFrameCipher(), frameKey, maxFrameLength);
|
crypto.getFrameCipher(), frameKey, maxFrameLength);
|
||||||
return new ConnectionReaderImpl(encryption, maxFrameLength);
|
return new StreamReaderImpl(encryption, maxFrameLength);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,16 +6,16 @@ import static org.briarproject.api.transport.TransportConstants.MAC_LENGTH;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
import org.briarproject.api.transport.ConnectionReader;
|
import org.briarproject.api.transport.StreamReader;
|
||||||
|
|
||||||
class ConnectionReaderImpl extends InputStream implements ConnectionReader {
|
class StreamReaderImpl extends InputStream implements StreamReader {
|
||||||
|
|
||||||
private final FrameReader in;
|
private final FrameReader in;
|
||||||
private final byte[] frame;
|
private final byte[] frame;
|
||||||
|
|
||||||
private int offset = 0, length = 0;
|
private int offset = 0, length = 0;
|
||||||
|
|
||||||
ConnectionReaderImpl(FrameReader in, int frameLength) {
|
StreamReaderImpl(FrameReader in, int frameLength) {
|
||||||
this.in = in;
|
this.in = in;
|
||||||
frame = new byte[frameLength - MAC_LENGTH];
|
frame = new byte[frameLength - MAC_LENGTH];
|
||||||
}
|
}
|
||||||
@@ -8,33 +8,33 @@ import javax.inject.Inject;
|
|||||||
|
|
||||||
import org.briarproject.api.crypto.CryptoComponent;
|
import org.briarproject.api.crypto.CryptoComponent;
|
||||||
import org.briarproject.api.crypto.SecretKey;
|
import org.briarproject.api.crypto.SecretKey;
|
||||||
import org.briarproject.api.transport.ConnectionContext;
|
import org.briarproject.api.transport.StreamContext;
|
||||||
import org.briarproject.api.transport.ConnectionWriter;
|
import org.briarproject.api.transport.StreamWriter;
|
||||||
import org.briarproject.api.transport.ConnectionWriterFactory;
|
import org.briarproject.api.transport.StreamWriterFactory;
|
||||||
|
|
||||||
class ConnectionWriterFactoryImpl implements ConnectionWriterFactory {
|
class StreamWriterFactoryImpl implements StreamWriterFactory {
|
||||||
|
|
||||||
private final CryptoComponent crypto;
|
private final CryptoComponent crypto;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
ConnectionWriterFactoryImpl(CryptoComponent crypto) {
|
StreamWriterFactoryImpl(CryptoComponent crypto) {
|
||||||
this.crypto = crypto;
|
this.crypto = crypto;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConnectionWriter createConnectionWriter(OutputStream out,
|
public StreamWriter createStreamWriter(OutputStream out,
|
||||||
int maxFrameLength, long capacity, ConnectionContext ctx,
|
int maxFrameLength, long capacity, StreamContext ctx,
|
||||||
boolean incoming, boolean initiator) {
|
boolean incoming, boolean initiator) {
|
||||||
byte[] secret = ctx.getSecret();
|
byte[] secret = ctx.getSecret();
|
||||||
long connection = ctx.getConnectionNumber();
|
long streamNumber = ctx.getStreamNumber();
|
||||||
boolean weAreAlice = ctx.getAlice();
|
boolean weAreAlice = ctx.getAlice();
|
||||||
boolean initiatorIsAlice = incoming ? !weAreAlice : weAreAlice;
|
boolean initiatorIsAlice = incoming ? !weAreAlice : weAreAlice;
|
||||||
SecretKey frameKey = crypto.deriveFrameKey(secret, connection,
|
SecretKey frameKey = crypto.deriveFrameKey(secret, streamNumber,
|
||||||
initiatorIsAlice, initiator);
|
initiatorIsAlice, initiator);
|
||||||
FrameWriter encryption;
|
FrameWriter encryption;
|
||||||
if(initiator) {
|
if(initiator) {
|
||||||
byte[] tag = new byte[TAG_LENGTH];
|
byte[] tag = new byte[TAG_LENGTH];
|
||||||
SecretKey tagKey = crypto.deriveTagKey(secret, initiatorIsAlice);
|
SecretKey tagKey = crypto.deriveTagKey(secret, initiatorIsAlice);
|
||||||
crypto.encodeTag(tag, tagKey, connection);
|
crypto.encodeTag(tag, tagKey, streamNumber);
|
||||||
tagKey.erase();
|
tagKey.erase();
|
||||||
encryption = new OutgoingEncryptionLayer(out, capacity,
|
encryption = new OutgoingEncryptionLayer(out, capacity,
|
||||||
crypto.getFrameCipher(), frameKey, maxFrameLength, tag);
|
crypto.getFrameCipher(), frameKey, maxFrameLength, tag);
|
||||||
@@ -42,15 +42,15 @@ class ConnectionWriterFactoryImpl implements ConnectionWriterFactory {
|
|||||||
encryption = new OutgoingEncryptionLayer(out, capacity,
|
encryption = new OutgoingEncryptionLayer(out, capacity,
|
||||||
crypto.getFrameCipher(), frameKey, maxFrameLength);
|
crypto.getFrameCipher(), frameKey, maxFrameLength);
|
||||||
}
|
}
|
||||||
return new ConnectionWriterImpl(encryption, maxFrameLength);
|
return new StreamWriterImpl(encryption, maxFrameLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConnectionWriter createInvitationConnectionWriter(OutputStream out,
|
public StreamWriter createInvitationStreamWriter(OutputStream out,
|
||||||
int maxFrameLength, byte[] secret, boolean alice) {
|
int maxFrameLength, byte[] secret, boolean alice) {
|
||||||
SecretKey frameKey = crypto.deriveFrameKey(secret, 0, true, alice);
|
SecretKey frameKey = crypto.deriveFrameKey(secret, 0, true, alice);
|
||||||
FrameWriter encryption = new OutgoingEncryptionLayer(out,
|
FrameWriter encryption = new OutgoingEncryptionLayer(out,
|
||||||
Long.MAX_VALUE, crypto.getFrameCipher(), frameKey,
|
Long.MAX_VALUE, crypto.getFrameCipher(), frameKey,
|
||||||
maxFrameLength);
|
maxFrameLength);
|
||||||
return new ConnectionWriterImpl(encryption, maxFrameLength);
|
return new StreamWriterImpl(encryption, maxFrameLength);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,15 +6,16 @@ import static org.briarproject.api.transport.TransportConstants.MAC_LENGTH;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
|
||||||
import org.briarproject.api.transport.ConnectionWriter;
|
import org.briarproject.api.transport.StreamWriter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A ConnectionWriter that buffers its input and writes a frame whenever there
|
* A {@link org.briarproject.api.transport.StreamWriter StreamWriter} that
|
||||||
* is a full frame to write or the {@link #flush()} method is called.
|
* buffers its input and writes a frame whenever there is a full frame to write
|
||||||
|
* or the {@link #flush()} method is called.
|
||||||
* <p>
|
* <p>
|
||||||
* This class is not thread-safe.
|
* This class is not thread-safe.
|
||||||
*/
|
*/
|
||||||
class ConnectionWriterImpl extends OutputStream implements ConnectionWriter {
|
class StreamWriterImpl extends OutputStream implements StreamWriter {
|
||||||
|
|
||||||
private final FrameWriter out;
|
private final FrameWriter out;
|
||||||
private final byte[] frame;
|
private final byte[] frame;
|
||||||
@@ -22,7 +23,7 @@ class ConnectionWriterImpl extends OutputStream implements ConnectionWriter {
|
|||||||
|
|
||||||
private int length = 0;
|
private int length = 0;
|
||||||
|
|
||||||
ConnectionWriterImpl(FrameWriter out, int frameLength) {
|
StreamWriterImpl(FrameWriter out, int frameLength) {
|
||||||
this.out = out;
|
this.out = out;
|
||||||
this.frameLength = frameLength;
|
this.frameLength = frameLength;
|
||||||
frame = new byte[frameLength - MAC_LENGTH];
|
frame = new byte[frameLength - MAC_LENGTH];
|
||||||
@@ -10,41 +10,41 @@ import org.briarproject.api.TransportId;
|
|||||||
import org.briarproject.api.crypto.CryptoComponent;
|
import org.briarproject.api.crypto.CryptoComponent;
|
||||||
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.transport.ConnectionContext;
|
import org.briarproject.api.transport.StreamContext;
|
||||||
import org.briarproject.api.transport.ConnectionRecogniser;
|
import org.briarproject.api.transport.TagRecogniser;
|
||||||
import org.briarproject.api.transport.TemporarySecret;
|
import org.briarproject.api.transport.TemporarySecret;
|
||||||
|
|
||||||
class ConnectionRecogniserImpl implements ConnectionRecogniser {
|
class TagRecogniserImpl implements TagRecogniser {
|
||||||
|
|
||||||
private final CryptoComponent crypto;
|
private final CryptoComponent crypto;
|
||||||
private final DatabaseComponent db;
|
private final DatabaseComponent db;
|
||||||
// Locking: this
|
// Locking: this
|
||||||
private final Map<TransportId, TransportConnectionRecogniser> recognisers;
|
private final Map<TransportId, TransportTagRecogniser> recognisers;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
ConnectionRecogniserImpl(CryptoComponent crypto, DatabaseComponent db) {
|
TagRecogniserImpl(CryptoComponent crypto, DatabaseComponent db) {
|
||||||
this.crypto = crypto;
|
this.crypto = crypto;
|
||||||
this.db = db;
|
this.db = db;
|
||||||
recognisers = new HashMap<TransportId, TransportConnectionRecogniser>();
|
recognisers = new HashMap<TransportId, TransportTagRecogniser>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConnectionContext acceptConnection(TransportId t, byte[] tag)
|
public StreamContext recogniseTag(TransportId t, byte[] tag)
|
||||||
throws DbException {
|
throws DbException {
|
||||||
TransportConnectionRecogniser r;
|
TransportTagRecogniser r;
|
||||||
synchronized(this) {
|
synchronized(this) {
|
||||||
r = recognisers.get(t);
|
r = recognisers.get(t);
|
||||||
}
|
}
|
||||||
if(r == null) return null;
|
if(r == null) return null;
|
||||||
return r.acceptConnection(tag);
|
return r.recogniseTag(tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addSecret(TemporarySecret s) {
|
public void addSecret(TemporarySecret s) {
|
||||||
TransportId t = s.getTransportId();
|
TransportId t = s.getTransportId();
|
||||||
TransportConnectionRecogniser r;
|
TransportTagRecogniser r;
|
||||||
synchronized(this) {
|
synchronized(this) {
|
||||||
r = recognisers.get(t);
|
r = recognisers.get(t);
|
||||||
if(r == null) {
|
if(r == null) {
|
||||||
r = new TransportConnectionRecogniser(crypto, db, t);
|
r = new TransportTagRecogniser(crypto, db, t);
|
||||||
recognisers.put(t, r);
|
recognisers.put(t, r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -52,7 +52,7 @@ class ConnectionRecogniserImpl implements ConnectionRecogniser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void removeSecret(ContactId c, TransportId t, long period) {
|
public void removeSecret(ContactId c, TransportId t, long period) {
|
||||||
TransportConnectionRecogniser r;
|
TransportTagRecogniser r;
|
||||||
synchronized(this) {
|
synchronized(this) {
|
||||||
r = recognisers.get(t);
|
r = recognisers.get(t);
|
||||||
}
|
}
|
||||||
@@ -60,7 +60,7 @@ class ConnectionRecogniserImpl implements ConnectionRecogniser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void removeSecrets(ContactId c) {
|
public synchronized void removeSecrets(ContactId c) {
|
||||||
for(TransportConnectionRecogniser r : recognisers.values())
|
for(TransportTagRecogniser r : recognisers.values())
|
||||||
r.removeSecrets(c);
|
r.removeSecrets(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,7 +69,7 @@ class ConnectionRecogniserImpl implements ConnectionRecogniser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void removeSecrets() {
|
public synchronized void removeSecrets() {
|
||||||
for(TransportConnectionRecogniser r : recognisers.values())
|
for(TransportTagRecogniser r : recognisers.values())
|
||||||
r.removeSecrets();
|
r.removeSecrets();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,10 +5,10 @@ import javax.inject.Singleton;
|
|||||||
import org.briarproject.api.crypto.KeyManager;
|
import org.briarproject.api.crypto.KeyManager;
|
||||||
import org.briarproject.api.lifecycle.LifecycleManager;
|
import org.briarproject.api.lifecycle.LifecycleManager;
|
||||||
import org.briarproject.api.transport.ConnectionDispatcher;
|
import org.briarproject.api.transport.ConnectionDispatcher;
|
||||||
import org.briarproject.api.transport.ConnectionReaderFactory;
|
|
||||||
import org.briarproject.api.transport.ConnectionRecogniser;
|
|
||||||
import org.briarproject.api.transport.ConnectionRegistry;
|
import org.briarproject.api.transport.ConnectionRegistry;
|
||||||
import org.briarproject.api.transport.ConnectionWriterFactory;
|
import org.briarproject.api.transport.StreamReaderFactory;
|
||||||
|
import org.briarproject.api.transport.StreamWriterFactory;
|
||||||
|
import org.briarproject.api.transport.TagRecogniser;
|
||||||
|
|
||||||
import com.google.inject.AbstractModule;
|
import com.google.inject.AbstractModule;
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
@@ -18,14 +18,14 @@ public class TransportModule extends AbstractModule {
|
|||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
bind(ConnectionDispatcher.class).to(ConnectionDispatcherImpl.class);
|
bind(ConnectionDispatcher.class).to(ConnectionDispatcherImpl.class);
|
||||||
bind(ConnectionReaderFactory.class).to(
|
bind(StreamReaderFactory.class).to(
|
||||||
ConnectionReaderFactoryImpl.class);
|
StreamReaderFactoryImpl.class);
|
||||||
bind(ConnectionRecogniser.class).to(
|
bind(TagRecogniser.class).to(
|
||||||
ConnectionRecogniserImpl.class).in(Singleton.class);
|
TagRecogniserImpl.class).in(Singleton.class);
|
||||||
bind(ConnectionRegistry.class).to(
|
bind(ConnectionRegistry.class).to(
|
||||||
ConnectionRegistryImpl.class).in(Singleton.class);;
|
ConnectionRegistryImpl.class).in(Singleton.class);;
|
||||||
bind(ConnectionWriterFactory.class).to(
|
bind(StreamWriterFactory.class).to(
|
||||||
ConnectionWriterFactoryImpl.class);
|
StreamWriterFactoryImpl.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides @Singleton
|
@Provides @Singleton
|
||||||
|
|||||||
@@ -14,12 +14,15 @@ import org.briarproject.api.crypto.CryptoComponent;
|
|||||||
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.db.DbException;
|
import org.briarproject.api.db.DbException;
|
||||||
import org.briarproject.api.transport.ConnectionContext;
|
import org.briarproject.api.transport.StreamContext;
|
||||||
import org.briarproject.api.transport.TemporarySecret;
|
import org.briarproject.api.transport.TemporarySecret;
|
||||||
|
|
||||||
// FIXME: Don't make alien calls with a lock held
|
// FIXME: Don't make alien calls with a lock held
|
||||||
/** A connection recogniser for a specific transport. */
|
/**
|
||||||
class TransportConnectionRecogniser {
|
* A {@link org.briarproject.api.transport.TagRecogniser TagRecogniser} for a
|
||||||
|
* specific transport.
|
||||||
|
*/
|
||||||
|
class TransportTagRecogniser {
|
||||||
|
|
||||||
private final CryptoComponent crypto;
|
private final CryptoComponent crypto;
|
||||||
private final DatabaseComponent db;
|
private final DatabaseComponent db;
|
||||||
@@ -27,7 +30,7 @@ class TransportConnectionRecogniser {
|
|||||||
private final Map<Bytes, TagContext> tagMap; // Locking: this
|
private final Map<Bytes, TagContext> tagMap; // Locking: this
|
||||||
private final Map<RemovalKey, RemovalContext> removalMap; // Locking: this
|
private final Map<RemovalKey, RemovalContext> removalMap; // Locking: this
|
||||||
|
|
||||||
TransportConnectionRecogniser(CryptoComponent crypto, DatabaseComponent db,
|
TransportTagRecogniser(CryptoComponent crypto, DatabaseComponent db,
|
||||||
TransportId transportId) {
|
TransportId transportId) {
|
||||||
this.crypto = crypto;
|
this.crypto = crypto;
|
||||||
this.db = db;
|
this.db = db;
|
||||||
@@ -36,32 +39,31 @@ class TransportConnectionRecogniser {
|
|||||||
removalMap = new HashMap<RemovalKey, RemovalContext>();
|
removalMap = new HashMap<RemovalKey, RemovalContext>();
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized ConnectionContext acceptConnection(byte[] tag)
|
synchronized StreamContext recogniseTag(byte[] tag) throws DbException {
|
||||||
throws DbException {
|
|
||||||
TagContext t = tagMap.remove(new Bytes(tag));
|
TagContext t = tagMap.remove(new Bytes(tag));
|
||||||
if(t == null) return null; // The tag was not expected
|
if(t == null) return null; // The tag was not expected
|
||||||
// Update the connection window and the expected tags
|
// Update the reordering window and the expected tags
|
||||||
SecretKey key = crypto.deriveTagKey(t.secret, !t.alice);
|
SecretKey key = crypto.deriveTagKey(t.secret, !t.alice);
|
||||||
for(long connection : t.window.setSeen(t.connection)) {
|
for(long streamNumber : t.window.setSeen(t.streamNumber)) {
|
||||||
byte[] tag1 = new byte[TAG_LENGTH];
|
byte[] tag1 = new byte[TAG_LENGTH];
|
||||||
crypto.encodeTag(tag1, key, connection);
|
crypto.encodeTag(tag1, key, streamNumber);
|
||||||
if(connection < t.connection) {
|
if(streamNumber < t.streamNumber) {
|
||||||
TagContext removed = tagMap.remove(new Bytes(tag1));
|
TagContext removed = tagMap.remove(new Bytes(tag1));
|
||||||
assert removed != null;
|
assert removed != null;
|
||||||
} else {
|
} else {
|
||||||
TagContext added = new TagContext(t, connection);
|
TagContext added = new TagContext(t, streamNumber);
|
||||||
TagContext duplicate = tagMap.put(new Bytes(tag1), added);
|
TagContext duplicate = tagMap.put(new Bytes(tag1), added);
|
||||||
assert duplicate == null;
|
assert duplicate == null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
key.erase();
|
key.erase();
|
||||||
// Store the updated connection window in the DB
|
// Store the updated reordering window in the DB
|
||||||
db.setConnectionWindow(t.contactId, transportId, t.period,
|
db.setReorderingWindow(t.contactId, transportId, t.period,
|
||||||
t.window.getCentre(), t.window.getBitmap());
|
t.window.getCentre(), t.window.getBitmap());
|
||||||
// Clone the secret - the key manager will erase the original
|
// Clone the secret - the key manager will erase the original
|
||||||
byte[] secret = t.secret.clone();
|
byte[] secret = t.secret.clone();
|
||||||
return new ConnectionContext(t.contactId, transportId, secret,
|
return new StreamContext(t.contactId, transportId, secret,
|
||||||
t.connection, t.alice);
|
t.streamNumber, t.alice);
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized void addSecret(TemporarySecret s) {
|
synchronized void addSecret(TemporarySecret s) {
|
||||||
@@ -71,14 +73,14 @@ class TransportConnectionRecogniser {
|
|||||||
byte[] secret = s.getSecret();
|
byte[] secret = s.getSecret();
|
||||||
long centre = s.getWindowCentre();
|
long centre = s.getWindowCentre();
|
||||||
byte[] bitmap = s.getWindowBitmap();
|
byte[] bitmap = s.getWindowBitmap();
|
||||||
// Create the connection window and the expected tags
|
// Create the reordering window and the expected tags
|
||||||
SecretKey key = crypto.deriveTagKey(secret, !alice);
|
SecretKey key = crypto.deriveTagKey(secret, !alice);
|
||||||
ConnectionWindow window = new ConnectionWindow(centre, bitmap);
|
ReorderingWindow window = new ReorderingWindow(centre, bitmap);
|
||||||
for(long connection : window.getUnseen()) {
|
for(long streamNumber : window.getUnseen()) {
|
||||||
byte[] tag = new byte[TAG_LENGTH];
|
byte[] tag = new byte[TAG_LENGTH];
|
||||||
crypto.encodeTag(tag, key, connection);
|
crypto.encodeTag(tag, key, streamNumber);
|
||||||
TagContext added = new TagContext(contactId, alice, period,
|
TagContext added = new TagContext(contactId, alice, period,
|
||||||
secret, window, connection);
|
secret, window, streamNumber);
|
||||||
TagContext duplicate = tagMap.put(new Bytes(tag), added);
|
TagContext duplicate = tagMap.put(new Bytes(tag), added);
|
||||||
assert duplicate == null;
|
assert duplicate == null;
|
||||||
}
|
}
|
||||||
@@ -100,8 +102,8 @@ class TransportConnectionRecogniser {
|
|||||||
// Remove the expected tags
|
// Remove the expected tags
|
||||||
SecretKey key = crypto.deriveTagKey(r.secret, !r.alice);
|
SecretKey key = crypto.deriveTagKey(r.secret, !r.alice);
|
||||||
byte[] tag = new byte[TAG_LENGTH];
|
byte[] tag = new byte[TAG_LENGTH];
|
||||||
for(long connection : r.window.getUnseen()) {
|
for(long streamNumber : r.window.getUnseen()) {
|
||||||
crypto.encodeTag(tag, key, connection);
|
crypto.encodeTag(tag, key, streamNumber);
|
||||||
TagContext removed = tagMap.remove(new Bytes(tag));
|
TagContext removed = tagMap.remove(new Bytes(tag));
|
||||||
assert removed != null;
|
assert removed != null;
|
||||||
}
|
}
|
||||||
@@ -127,22 +129,22 @@ class TransportConnectionRecogniser {
|
|||||||
private final boolean alice;
|
private final boolean alice;
|
||||||
private final long period;
|
private final long period;
|
||||||
private final byte[] secret;
|
private final byte[] secret;
|
||||||
private final ConnectionWindow window;
|
private final ReorderingWindow window;
|
||||||
private final long connection;
|
private final long streamNumber;
|
||||||
|
|
||||||
private TagContext(ContactId contactId, boolean alice, long period,
|
private TagContext(ContactId contactId, boolean alice, long period,
|
||||||
byte[] secret, ConnectionWindow window, long connection) {
|
byte[] secret, ReorderingWindow window, long streamNumber) {
|
||||||
this.contactId = contactId;
|
this.contactId = contactId;
|
||||||
this.alice = alice;
|
this.alice = alice;
|
||||||
this.period = period;
|
this.period = period;
|
||||||
this.secret = secret;
|
this.secret = secret;
|
||||||
this.window = window;
|
this.window = window;
|
||||||
this.connection = connection;
|
this.streamNumber = streamNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
private TagContext(TagContext t, long connection) {
|
private TagContext(TagContext t, long streamNumber) {
|
||||||
this(t.contactId, t.alice, t.period, t.secret, t.window,
|
this(t.contactId, t.alice, t.period, t.secret, t.window,
|
||||||
connection);
|
streamNumber);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,11 +175,11 @@ class TransportConnectionRecogniser {
|
|||||||
|
|
||||||
private static class RemovalContext {
|
private static class RemovalContext {
|
||||||
|
|
||||||
private final ConnectionWindow window;
|
private final ReorderingWindow window;
|
||||||
private final byte[] secret;
|
private final byte[] secret;
|
||||||
private final boolean alice;
|
private final boolean alice;
|
||||||
|
|
||||||
private RemovalContext(ConnectionWindow window, byte[] secret,
|
private RemovalContext(ReorderingWindow window, byte[] secret,
|
||||||
boolean alice) {
|
boolean alice) {
|
||||||
this.window = window;
|
this.window = window;
|
||||||
this.secret = secret;
|
this.secret = secret;
|
||||||
@@ -14,6 +14,7 @@ import java.util.logging.Logger;
|
|||||||
|
|
||||||
import jssc.SerialPortEvent;
|
import jssc.SerialPortEvent;
|
||||||
import jssc.SerialPortEventListener;
|
import jssc.SerialPortEventListener;
|
||||||
|
|
||||||
import org.briarproject.api.reliability.ReliabilityLayer;
|
import org.briarproject.api.reliability.ReliabilityLayer;
|
||||||
import org.briarproject.api.reliability.ReliabilityLayerFactory;
|
import org.briarproject.api.reliability.ReliabilityLayerFactory;
|
||||||
import org.briarproject.api.reliability.WriteHandler;
|
import org.briarproject.api.reliability.WriteHandler;
|
||||||
|
|||||||
@@ -125,16 +125,16 @@
|
|||||||
<test name='org.briarproject.serial.ReaderImplTest'/>
|
<test name='org.briarproject.serial.ReaderImplTest'/>
|
||||||
<test name='org.briarproject.serial.WriterImplTest'/>
|
<test name='org.briarproject.serial.WriterImplTest'/>
|
||||||
<test name='org.briarproject.system.LinuxSeedProviderTest'/>
|
<test name='org.briarproject.system.LinuxSeedProviderTest'/>
|
||||||
<test name='org.briarproject.transport.ConnectionReaderImplTest'/>
|
|
||||||
<test name='org.briarproject.transport.ConnectionRegistryImplTest'/>
|
<test name='org.briarproject.transport.ConnectionRegistryImplTest'/>
|
||||||
<test name='org.briarproject.transport.ConnectionWindowTest'/>
|
|
||||||
<test name='org.briarproject.transport.ConnectionWriterImplTest'/>
|
|
||||||
<test name='org.briarproject.transport.IncomingEncryptionLayerTest'/>
|
<test name='org.briarproject.transport.IncomingEncryptionLayerTest'/>
|
||||||
<test name='org.briarproject.transport.KeyManagerImplTest'/>
|
<test name='org.briarproject.transport.KeyManagerImplTest'/>
|
||||||
<test name='org.briarproject.transport.KeyRotationIntegrationTest'/>
|
<test name='org.briarproject.transport.KeyRotationIntegrationTest'/>
|
||||||
<test name='org.briarproject.transport.OutgoingEncryptionLayerTest'/>
|
<test name='org.briarproject.transport.OutgoingEncryptionLayerTest'/>
|
||||||
|
<test name='org.briarproject.transport.ReorderingWindowTest'/>
|
||||||
|
<test name='org.briarproject.transport.StreamReaderImplTest'/>
|
||||||
|
<test name='org.briarproject.transport.StreamWriterImplTest'/>
|
||||||
<test name='org.briarproject.transport.TransportIntegrationTest'/>
|
<test name='org.briarproject.transport.TransportIntegrationTest'/>
|
||||||
<test name='org.briarproject.transport.TransportConnectionRecogniserTest'/>
|
<test name='org.briarproject.transport.TransportTagRecogniserTest'/>
|
||||||
<test name='org.briarproject.util.ByteUtilsTest'/>
|
<test name='org.briarproject.util.ByteUtilsTest'/>
|
||||||
<test name='org.briarproject.util.StringUtilsTest'/>
|
<test name='org.briarproject.util.StringUtilsTest'/>
|
||||||
</junit>
|
</junit>
|
||||||
|
|||||||
@@ -36,11 +36,11 @@ import org.briarproject.api.messaging.Request;
|
|||||||
import org.briarproject.api.messaging.SubscriptionUpdate;
|
import org.briarproject.api.messaging.SubscriptionUpdate;
|
||||||
import org.briarproject.api.messaging.TransportUpdate;
|
import org.briarproject.api.messaging.TransportUpdate;
|
||||||
import org.briarproject.api.messaging.UnverifiedMessage;
|
import org.briarproject.api.messaging.UnverifiedMessage;
|
||||||
import org.briarproject.api.transport.ConnectionContext;
|
import org.briarproject.api.transport.StreamContext;
|
||||||
import org.briarproject.api.transport.ConnectionReader;
|
import org.briarproject.api.transport.StreamReader;
|
||||||
import org.briarproject.api.transport.ConnectionReaderFactory;
|
import org.briarproject.api.transport.StreamReaderFactory;
|
||||||
import org.briarproject.api.transport.ConnectionWriter;
|
import org.briarproject.api.transport.StreamWriter;
|
||||||
import org.briarproject.api.transport.ConnectionWriterFactory;
|
import org.briarproject.api.transport.StreamWriterFactory;
|
||||||
import org.briarproject.crypto.CryptoModule;
|
import org.briarproject.crypto.CryptoModule;
|
||||||
import org.briarproject.db.DatabaseModule;
|
import org.briarproject.db.DatabaseModule;
|
||||||
import org.briarproject.event.EventModule;
|
import org.briarproject.event.EventModule;
|
||||||
@@ -57,8 +57,8 @@ import com.google.inject.Injector;
|
|||||||
|
|
||||||
public class ProtocolIntegrationTest extends BriarTestCase {
|
public class ProtocolIntegrationTest extends BriarTestCase {
|
||||||
|
|
||||||
private final ConnectionReaderFactory connectionReaderFactory;
|
private final StreamReaderFactory streamReaderFactory;
|
||||||
private final ConnectionWriterFactory connectionWriterFactory;
|
private final StreamWriterFactory streamWriterFactory;
|
||||||
private final PacketReaderFactory packetReaderFactory;
|
private final PacketReaderFactory packetReaderFactory;
|
||||||
private final PacketWriterFactory packetWriterFactory;
|
private final PacketWriterFactory packetWriterFactory;
|
||||||
private final MessageVerifier messageVerifier;
|
private final MessageVerifier messageVerifier;
|
||||||
@@ -84,8 +84,8 @@ public class ProtocolIntegrationTest extends BriarTestCase {
|
|||||||
new DuplexMessagingModule(), new SimplexMessagingModule(),
|
new DuplexMessagingModule(), new SimplexMessagingModule(),
|
||||||
new ReliabilityModule(), new SerialModule(),
|
new ReliabilityModule(), new SerialModule(),
|
||||||
new TransportModule());
|
new TransportModule());
|
||||||
connectionReaderFactory = i.getInstance(ConnectionReaderFactory.class);
|
streamReaderFactory = i.getInstance(StreamReaderFactory.class);
|
||||||
connectionWriterFactory = i.getInstance(ConnectionWriterFactory.class);
|
streamWriterFactory = i.getInstance(StreamWriterFactory.class);
|
||||||
packetReaderFactory = i.getInstance(PacketReaderFactory.class);
|
packetReaderFactory = i.getInstance(PacketReaderFactory.class);
|
||||||
packetWriterFactory = i.getInstance(PacketWriterFactory.class);
|
packetWriterFactory = i.getInstance(PacketWriterFactory.class);
|
||||||
messageVerifier = i.getInstance(MessageVerifier.class);
|
messageVerifier = i.getInstance(MessageVerifier.class);
|
||||||
@@ -123,9 +123,9 @@ public class ProtocolIntegrationTest extends BriarTestCase {
|
|||||||
|
|
||||||
private byte[] write() throws Exception {
|
private byte[] write() throws Exception {
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
ConnectionContext ctx = new ConnectionContext(contactId, transportId,
|
StreamContext ctx = new StreamContext(contactId, transportId,
|
||||||
secret.clone(), 0, true);
|
secret.clone(), 0, true);
|
||||||
ConnectionWriter conn = connectionWriterFactory.createConnectionWriter(
|
StreamWriter conn = streamWriterFactory.createStreamWriter(
|
||||||
out, MAX_FRAME_LENGTH, Long.MAX_VALUE, ctx, false, true);
|
out, MAX_FRAME_LENGTH, Long.MAX_VALUE, ctx, false, true);
|
||||||
OutputStream out1 = conn.getOutputStream();
|
OutputStream out1 = conn.getOutputStream();
|
||||||
PacketWriter writer = packetWriterFactory.createPacketWriter(out1,
|
PacketWriter writer = packetWriterFactory.createPacketWriter(out1,
|
||||||
@@ -156,9 +156,9 @@ public class ProtocolIntegrationTest extends BriarTestCase {
|
|||||||
byte[] tag = new byte[TAG_LENGTH];
|
byte[] tag = new byte[TAG_LENGTH];
|
||||||
assertEquals(TAG_LENGTH, in.read(tag, 0, TAG_LENGTH));
|
assertEquals(TAG_LENGTH, in.read(tag, 0, TAG_LENGTH));
|
||||||
// FIXME: Check that the expected tag was received
|
// FIXME: Check that the expected tag was received
|
||||||
ConnectionContext ctx = new ConnectionContext(contactId, transportId,
|
StreamContext ctx = new StreamContext(contactId, transportId,
|
||||||
secret.clone(), 0, false);
|
secret.clone(), 0, false);
|
||||||
ConnectionReader conn = connectionReaderFactory.createConnectionReader(
|
StreamReader conn = streamReaderFactory.createStreamReader(
|
||||||
in, MAX_FRAME_LENGTH, ctx, true, true);
|
in, MAX_FRAME_LENGTH, ctx, true, true);
|
||||||
InputStream in1 = conn.getInputStream();
|
InputStream in1 = conn.getInputStream();
|
||||||
PacketReader reader = packetReaderFactory.createPacketReader(in1);
|
PacketReader reader = packetReaderFactory.createPacketReader(in1);
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ public class KeyDerivationTest extends BriarTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConnectionNumberAffectsDerivation() {
|
public void testStreamNumberAffectsDerivation() {
|
||||||
List<byte[]> secrets = new ArrayList<byte[]>();
|
List<byte[]> secrets = new ArrayList<byte[]>();
|
||||||
for(int i = 0; i < 20; i++) {
|
for(int i = 0; i < 20; i++) {
|
||||||
secrets.add(crypto.deriveNextSecret(secret.clone(), i));
|
secrets.add(crypto.deriveNextSecret(secret.clone(), i));
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import org.briarproject.api.crypto.KeyPair;
|
|||||||
import org.briarproject.api.crypto.KeyParser;
|
import org.briarproject.api.crypto.KeyParser;
|
||||||
import org.briarproject.api.crypto.PrivateKey;
|
import org.briarproject.api.crypto.PrivateKey;
|
||||||
import org.briarproject.api.crypto.PublicKey;
|
import org.briarproject.api.crypto.PublicKey;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class KeyEncodingAndParsingTest extends BriarTestCase {
|
public class KeyEncodingAndParsingTest extends BriarTestCase {
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import java.util.Random;
|
|||||||
|
|
||||||
import org.briarproject.BriarTestCase;
|
import org.briarproject.BriarTestCase;
|
||||||
import org.briarproject.api.crypto.SecretKey;
|
import org.briarproject.api.crypto.SecretKey;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class SecretKeyImplTest extends BriarTestCase {
|
public class SecretKeyImplTest extends BriarTestCase {
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import java.util.Random;
|
|||||||
|
|
||||||
import org.briarproject.BriarTestCase;
|
import org.briarproject.BriarTestCase;
|
||||||
import org.briarproject.TestUtils;
|
import org.briarproject.TestUtils;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|||||||
@@ -388,7 +388,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
|||||||
} catch(NoSuchContactException expected) {}
|
} catch(NoSuchContactException expected) {}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
db.incrementConnectionCounter(contactId, transportId, 0);
|
db.incrementStreamCounter(contactId, transportId, 0);
|
||||||
fail();
|
fail();
|
||||||
} catch(NoSuchContactException expected) {}
|
} catch(NoSuchContactException expected) {}
|
||||||
|
|
||||||
@@ -453,7 +453,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
|||||||
} catch(NoSuchContactException expected) {}
|
} catch(NoSuchContactException expected) {}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
db.setConnectionWindow(contactId, transportId, 0, 0, new byte[4]);
|
db.setReorderingWindow(contactId, transportId, 0, 0, new byte[4]);
|
||||||
fail();
|
fail();
|
||||||
} catch(NoSuchContactException expected) {}
|
} catch(NoSuchContactException expected) {}
|
||||||
|
|
||||||
@@ -624,7 +624,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
|||||||
} catch(NoSuchTransportException expected) {}
|
} catch(NoSuchTransportException expected) {}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
db.incrementConnectionCounter(contactId, transportId, 0);
|
db.incrementStreamCounter(contactId, transportId, 0);
|
||||||
fail();
|
fail();
|
||||||
} catch(NoSuchTransportException expected) {}
|
} catch(NoSuchTransportException expected) {}
|
||||||
|
|
||||||
@@ -634,7 +634,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
|||||||
} catch(NoSuchTransportException expected) {}
|
} catch(NoSuchTransportException expected) {}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
db.setConnectionWindow(contactId, transportId, 0, 0, new byte[4]);
|
db.setReorderingWindow(contactId, transportId, 0, 0, new byte[4]);
|
||||||
fail();
|
fail();
|
||||||
} catch(NoSuchTransportException expected) {}
|
} catch(NoSuchTransportException expected) {}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package org.briarproject.db;
|
package org.briarproject.db;
|
||||||
|
|
||||||
import org.briarproject.BriarTestCase;
|
import org.briarproject.BriarTestCase;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class ExponentialBackoffTest extends BriarTestCase {
|
public class ExponentialBackoffTest extends BriarTestCase {
|
||||||
|
|||||||
@@ -88,6 +88,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
contactId = new ContactId(1);
|
contactId = new ContactId(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
testDir.mkdirs();
|
testDir.mkdirs();
|
||||||
@@ -465,6 +466,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
// In another thread, close the database
|
// In another thread, close the database
|
||||||
Thread close = new Thread() {
|
Thread close = new Thread() {
|
||||||
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
closing.countDown();
|
closing.countDown();
|
||||||
@@ -501,6 +503,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
// In another thread, close the database
|
// In another thread, close the database
|
||||||
Thread close = new Thread() {
|
Thread close = new Thread() {
|
||||||
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
closing.countDown();
|
closing.countDown();
|
||||||
@@ -1160,19 +1163,19 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
assertEquals(alice, s.getAlice());
|
assertEquals(alice, s.getAlice());
|
||||||
if(s.getPeriod() == 0) {
|
if(s.getPeriod() == 0) {
|
||||||
assertArrayEquals(secret1, s.getSecret());
|
assertArrayEquals(secret1, s.getSecret());
|
||||||
assertEquals(outgoing1, s.getOutgoingConnectionCounter());
|
assertEquals(outgoing1, s.getOutgoingStreamCounter());
|
||||||
assertEquals(centre1, s.getWindowCentre());
|
assertEquals(centre1, s.getWindowCentre());
|
||||||
assertArrayEquals(bitmap1, s.getWindowBitmap());
|
assertArrayEquals(bitmap1, s.getWindowBitmap());
|
||||||
foundFirst = true;
|
foundFirst = true;
|
||||||
} else if(s.getPeriod() == 1) {
|
} else if(s.getPeriod() == 1) {
|
||||||
assertArrayEquals(secret2, s.getSecret());
|
assertArrayEquals(secret2, s.getSecret());
|
||||||
assertEquals(outgoing2, s.getOutgoingConnectionCounter());
|
assertEquals(outgoing2, s.getOutgoingStreamCounter());
|
||||||
assertEquals(centre2, s.getWindowCentre());
|
assertEquals(centre2, s.getWindowCentre());
|
||||||
assertArrayEquals(bitmap2, s.getWindowBitmap());
|
assertArrayEquals(bitmap2, s.getWindowBitmap());
|
||||||
foundSecond = true;
|
foundSecond = true;
|
||||||
} else if(s.getPeriod() == 2) {
|
} else if(s.getPeriod() == 2) {
|
||||||
assertArrayEquals(secret3, s.getSecret());
|
assertArrayEquals(secret3, s.getSecret());
|
||||||
assertEquals(outgoing3, s.getOutgoingConnectionCounter());
|
assertEquals(outgoing3, s.getOutgoingStreamCounter());
|
||||||
assertEquals(centre3, s.getWindowCentre());
|
assertEquals(centre3, s.getWindowCentre());
|
||||||
assertArrayEquals(bitmap3, s.getWindowBitmap());
|
assertArrayEquals(bitmap3, s.getWindowBitmap());
|
||||||
foundThird = true;
|
foundThird = true;
|
||||||
@@ -1197,19 +1200,19 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
assertEquals(alice, s.getAlice());
|
assertEquals(alice, s.getAlice());
|
||||||
if(s.getPeriod() == 1) {
|
if(s.getPeriod() == 1) {
|
||||||
assertArrayEquals(secret2, s.getSecret());
|
assertArrayEquals(secret2, s.getSecret());
|
||||||
assertEquals(outgoing2, s.getOutgoingConnectionCounter());
|
assertEquals(outgoing2, s.getOutgoingStreamCounter());
|
||||||
assertEquals(centre2, s.getWindowCentre());
|
assertEquals(centre2, s.getWindowCentre());
|
||||||
assertArrayEquals(bitmap2, s.getWindowBitmap());
|
assertArrayEquals(bitmap2, s.getWindowBitmap());
|
||||||
foundSecond = true;
|
foundSecond = true;
|
||||||
} else if(s.getPeriod() == 2) {
|
} else if(s.getPeriod() == 2) {
|
||||||
assertArrayEquals(secret3, s.getSecret());
|
assertArrayEquals(secret3, s.getSecret());
|
||||||
assertEquals(outgoing3, s.getOutgoingConnectionCounter());
|
assertEquals(outgoing3, s.getOutgoingStreamCounter());
|
||||||
assertEquals(centre3, s.getWindowCentre());
|
assertEquals(centre3, s.getWindowCentre());
|
||||||
assertArrayEquals(bitmap3, s.getWindowBitmap());
|
assertArrayEquals(bitmap3, s.getWindowBitmap());
|
||||||
foundThird = true;
|
foundThird = true;
|
||||||
} else if(s.getPeriod() == 3) {
|
} else if(s.getPeriod() == 3) {
|
||||||
assertArrayEquals(secret4, s.getSecret());
|
assertArrayEquals(secret4, s.getSecret());
|
||||||
assertEquals(outgoing4, s.getOutgoingConnectionCounter());
|
assertEquals(outgoing4, s.getOutgoingStreamCounter());
|
||||||
assertEquals(centre4, s.getWindowCentre());
|
assertEquals(centre4, s.getWindowCentre());
|
||||||
assertArrayEquals(bitmap4, s.getWindowBitmap());
|
assertArrayEquals(bitmap4, s.getWindowBitmap());
|
||||||
foundFourth = true;
|
foundFourth = true;
|
||||||
@@ -1230,7 +1233,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIncrementConnectionCounter() throws Exception {
|
public void testIncrementStreamCounter() throws Exception {
|
||||||
// Create an endpoint and a temporary secret
|
// Create an endpoint and a temporary secret
|
||||||
long epoch = 123, latency = 234;
|
long epoch = 123, latency = 234;
|
||||||
boolean alice = false;
|
boolean alice = false;
|
||||||
@@ -1245,7 +1248,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
Database<Connection> db = open(false);
|
Database<Connection> db = open(false);
|
||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
|
|
||||||
// Add the contact, the transport, the endpoint and the temporary secret
|
// Add the contact, transport, endpoint and temporary secret
|
||||||
db.addLocalAuthor(txn, localAuthor);
|
db.addLocalAuthor(txn, localAuthor);
|
||||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||||
db.addTransport(txn, transportId, latency);
|
db.addTransport(txn, transportId, latency);
|
||||||
@@ -1260,14 +1263,14 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
assertEquals(transportId, s.getTransportId());
|
assertEquals(transportId, s.getTransportId());
|
||||||
assertEquals(period, s.getPeriod());
|
assertEquals(period, s.getPeriod());
|
||||||
assertArrayEquals(secret, s.getSecret());
|
assertArrayEquals(secret, s.getSecret());
|
||||||
assertEquals(outgoing, s.getOutgoingConnectionCounter());
|
assertEquals(outgoing, s.getOutgoingStreamCounter());
|
||||||
assertEquals(centre, s.getWindowCentre());
|
assertEquals(centre, s.getWindowCentre());
|
||||||
assertArrayEquals(bitmap, s.getWindowBitmap());
|
assertArrayEquals(bitmap, s.getWindowBitmap());
|
||||||
|
|
||||||
// Increment the connection counter twice and retrieve the secret again
|
// Increment the stream counter twice and retrieve the secret again
|
||||||
assertEquals(outgoing, db.incrementConnectionCounter(txn,
|
assertEquals(outgoing, db.incrementStreamCounter(txn,
|
||||||
s.getContactId(), s.getTransportId(), s.getPeriod()));
|
s.getContactId(), s.getTransportId(), s.getPeriod()));
|
||||||
assertEquals(outgoing + 1, db.incrementConnectionCounter(txn,
|
assertEquals(outgoing + 1, db.incrementStreamCounter(txn,
|
||||||
s.getContactId(), s.getTransportId(), s.getPeriod()));
|
s.getContactId(), s.getTransportId(), s.getPeriod()));
|
||||||
secrets = db.getSecrets(txn);
|
secrets = db.getSecrets(txn);
|
||||||
assertEquals(1, secrets.size());
|
assertEquals(1, secrets.size());
|
||||||
@@ -1276,7 +1279,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
assertEquals(transportId, s.getTransportId());
|
assertEquals(transportId, s.getTransportId());
|
||||||
assertEquals(period, s.getPeriod());
|
assertEquals(period, s.getPeriod());
|
||||||
assertArrayEquals(secret, s.getSecret());
|
assertArrayEquals(secret, s.getSecret());
|
||||||
assertEquals(outgoing + 2, s.getOutgoingConnectionCounter());
|
assertEquals(outgoing + 2, s.getOutgoingStreamCounter());
|
||||||
assertEquals(centre, s.getWindowCentre());
|
assertEquals(centre, s.getWindowCentre());
|
||||||
assertArrayEquals(bitmap, s.getWindowBitmap());
|
assertArrayEquals(bitmap, s.getWindowBitmap());
|
||||||
|
|
||||||
@@ -1285,7 +1288,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetConnectionWindow() throws Exception {
|
public void testSetReorderingWindow() throws Exception {
|
||||||
// Create an endpoint and a temporary secret
|
// Create an endpoint and a temporary secret
|
||||||
long epoch = 123, latency = 234;
|
long epoch = 123, latency = 234;
|
||||||
boolean alice = false;
|
boolean alice = false;
|
||||||
@@ -1300,7 +1303,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
Database<Connection> db = open(false);
|
Database<Connection> db = open(false);
|
||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
|
|
||||||
// Add the contact, the transport, the endpoint and the temporary secret
|
// Add the contact, transport, endpoint and temporary secret
|
||||||
db.addLocalAuthor(txn, localAuthor);
|
db.addLocalAuthor(txn, localAuthor);
|
||||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||||
db.addTransport(txn, transportId, latency);
|
db.addTransport(txn, transportId, latency);
|
||||||
@@ -1315,13 +1318,13 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
assertEquals(transportId, s.getTransportId());
|
assertEquals(transportId, s.getTransportId());
|
||||||
assertEquals(period, s.getPeriod());
|
assertEquals(period, s.getPeriod());
|
||||||
assertArrayEquals(secret, s.getSecret());
|
assertArrayEquals(secret, s.getSecret());
|
||||||
assertEquals(outgoing, s.getOutgoingConnectionCounter());
|
assertEquals(outgoing, s.getOutgoingStreamCounter());
|
||||||
assertEquals(centre, s.getWindowCentre());
|
assertEquals(centre, s.getWindowCentre());
|
||||||
assertArrayEquals(bitmap, s.getWindowBitmap());
|
assertArrayEquals(bitmap, s.getWindowBitmap());
|
||||||
|
|
||||||
// Update the connection window and retrieve the secret again
|
// Update the reordering window and retrieve the secret again
|
||||||
random.nextBytes(bitmap);
|
random.nextBytes(bitmap);
|
||||||
db.setConnectionWindow(txn, contactId, transportId, period, centre,
|
db.setReorderingWindow(txn, contactId, transportId, period, centre,
|
||||||
bitmap);
|
bitmap);
|
||||||
secrets = db.getSecrets(txn);
|
secrets = db.getSecrets(txn);
|
||||||
assertEquals(1, secrets.size());
|
assertEquals(1, secrets.size());
|
||||||
@@ -1330,12 +1333,12 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
assertEquals(transportId, s.getTransportId());
|
assertEquals(transportId, s.getTransportId());
|
||||||
assertEquals(period, s.getPeriod());
|
assertEquals(period, s.getPeriod());
|
||||||
assertArrayEquals(secret, s.getSecret());
|
assertArrayEquals(secret, s.getSecret());
|
||||||
assertEquals(outgoing, s.getOutgoingConnectionCounter());
|
assertEquals(outgoing, s.getOutgoingStreamCounter());
|
||||||
assertEquals(centre, s.getWindowCentre());
|
assertEquals(centre, s.getWindowCentre());
|
||||||
assertArrayEquals(bitmap, s.getWindowBitmap());
|
assertArrayEquals(bitmap, s.getWindowBitmap());
|
||||||
|
|
||||||
// Updating a nonexistent window should not throw an exception
|
// Updating a nonexistent window should not throw an exception
|
||||||
db.setConnectionWindow(txn, contactId, transportId, period + 1, 1,
|
db.setReorderingWindow(txn, contactId, transportId, period + 1, 1,
|
||||||
bitmap);
|
bitmap);
|
||||||
// The nonexistent window should not have been created
|
// The nonexistent window should not have been created
|
||||||
secrets = db.getSecrets(txn);
|
secrets = db.getSecrets(txn);
|
||||||
@@ -1345,7 +1348,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
assertEquals(transportId, s.getTransportId());
|
assertEquals(transportId, s.getTransportId());
|
||||||
assertEquals(period, s.getPeriod());
|
assertEquals(period, s.getPeriod());
|
||||||
assertArrayEquals(secret, s.getSecret());
|
assertArrayEquals(secret, s.getSecret());
|
||||||
assertEquals(outgoing, s.getOutgoingConnectionCounter());
|
assertEquals(outgoing, s.getOutgoingStreamCounter());
|
||||||
assertEquals(centre, s.getWindowCentre());
|
assertEquals(centre, s.getWindowCentre());
|
||||||
assertArrayEquals(bitmap, s.getWindowBitmap());
|
assertArrayEquals(bitmap, s.getWindowBitmap());
|
||||||
|
|
||||||
@@ -1354,7 +1357,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testContactTransports() throws Exception {
|
public void testEndpoints() throws Exception {
|
||||||
// Create some endpoints
|
// Create some endpoints
|
||||||
long epoch1 = 123, latency1 = 234;
|
long epoch1 = 123, latency1 = 234;
|
||||||
long epoch2 = 345, latency2 = 456;
|
long epoch2 = 345, latency2 = 456;
|
||||||
@@ -1378,7 +1381,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
db.addEndpoint(txn, ep1);
|
db.addEndpoint(txn, ep1);
|
||||||
db.addEndpoint(txn, ep2);
|
db.addEndpoint(txn, ep2);
|
||||||
|
|
||||||
// Retrieve the contact transports
|
// Retrieve the endpoints
|
||||||
Collection<Endpoint> endpoints = db.getEndpoints(txn);
|
Collection<Endpoint> endpoints = db.getEndpoints(txn);
|
||||||
assertEquals(2, endpoints.size());
|
assertEquals(2, endpoints.size());
|
||||||
boolean foundFirst = false, foundSecond = false;
|
boolean foundFirst = false, foundSecond = false;
|
||||||
@@ -1399,7 +1402,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
assertTrue(foundFirst);
|
assertTrue(foundFirst);
|
||||||
assertTrue(foundSecond);
|
assertTrue(foundSecond);
|
||||||
|
|
||||||
// Removing the contact should remove the contact transports
|
// Removing the contact should remove the endpoints
|
||||||
db.removeContact(txn, contactId);
|
db.removeContact(txn, contactId);
|
||||||
assertEquals(Collections.emptyList(), db.getEndpoints(txn));
|
assertEquals(Collections.emptyList(), db.getEndpoints(txn));
|
||||||
|
|
||||||
@@ -1646,6 +1649,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
return db;
|
return db;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
@After
|
@After
|
||||||
public void tearDown() {
|
public void tearDown() {
|
||||||
TestUtils.deleteTestDirectory(testDir);
|
TestUtils.deleteTestDirectory(testDir);
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import java.util.Set;
|
|||||||
|
|
||||||
import org.briarproject.BriarTestCase;
|
import org.briarproject.BriarTestCase;
|
||||||
import org.briarproject.api.lifecycle.ShutdownManager;
|
import org.briarproject.api.lifecycle.ShutdownManager;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class ShutdownManagerImplTest extends BriarTestCase {
|
public class ShutdownManagerImplTest extends BriarTestCase {
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package org.briarproject.lifecycle;
|
package org.briarproject.lifecycle;
|
||||||
|
|
||||||
import org.briarproject.api.lifecycle.ShutdownManager;
|
import org.briarproject.api.lifecycle.ShutdownManager;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class WindowsShutdownManagerImplTest extends ShutdownManagerImplTest {
|
public class WindowsShutdownManagerImplTest extends ShutdownManagerImplTest {
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import org.briarproject.api.crypto.MessageDigest;
|
|||||||
import org.briarproject.api.serial.CopyingConsumer;
|
import org.briarproject.api.serial.CopyingConsumer;
|
||||||
import org.briarproject.api.serial.CountingConsumer;
|
import org.briarproject.api.serial.CountingConsumer;
|
||||||
import org.briarproject.api.serial.DigestingConsumer;
|
import org.briarproject.api.serial.DigestingConsumer;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class ConsumersTest extends BriarTestCase {
|
public class ConsumersTest extends BriarTestCase {
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ import org.briarproject.api.serial.SerialComponent;
|
|||||||
import org.briarproject.api.serial.Writer;
|
import org.briarproject.api.serial.Writer;
|
||||||
import org.briarproject.api.serial.WriterFactory;
|
import org.briarproject.api.serial.WriterFactory;
|
||||||
import org.briarproject.serial.SerialModule;
|
import org.briarproject.serial.SerialModule;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import com.google.inject.Guice;
|
import com.google.inject.Guice;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package org.briarproject.messaging.simplex;
|
|||||||
import static org.briarproject.api.messaging.MessagingConstants.MAX_PACKET_LENGTH;
|
import static org.briarproject.api.messaging.MessagingConstants.MAX_PACKET_LENGTH;
|
||||||
import static org.briarproject.api.transport.TransportConstants.HEADER_LENGTH;
|
import static org.briarproject.api.transport.TransportConstants.HEADER_LENGTH;
|
||||||
import static org.briarproject.api.transport.TransportConstants.MAC_LENGTH;
|
import static org.briarproject.api.transport.TransportConstants.MAC_LENGTH;
|
||||||
import static org.briarproject.api.transport.TransportConstants.MIN_CONNECTION_LENGTH;
|
import static org.briarproject.api.transport.TransportConstants.MIN_STREAM_LENGTH;
|
||||||
import static org.briarproject.api.transport.TransportConstants.TAG_LENGTH;
|
import static org.briarproject.api.transport.TransportConstants.TAG_LENGTH;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
@@ -24,9 +24,9 @@ import org.briarproject.api.db.DatabaseExecutor;
|
|||||||
import org.briarproject.api.messaging.Ack;
|
import org.briarproject.api.messaging.Ack;
|
||||||
import org.briarproject.api.messaging.MessageId;
|
import org.briarproject.api.messaging.MessageId;
|
||||||
import org.briarproject.api.messaging.PacketWriterFactory;
|
import org.briarproject.api.messaging.PacketWriterFactory;
|
||||||
import org.briarproject.api.transport.ConnectionContext;
|
|
||||||
import org.briarproject.api.transport.ConnectionRegistry;
|
import org.briarproject.api.transport.ConnectionRegistry;
|
||||||
import org.briarproject.api.transport.ConnectionWriterFactory;
|
import org.briarproject.api.transport.StreamContext;
|
||||||
|
import org.briarproject.api.transport.StreamWriterFactory;
|
||||||
import org.briarproject.crypto.CryptoModule;
|
import org.briarproject.crypto.CryptoModule;
|
||||||
import org.briarproject.event.EventModule;
|
import org.briarproject.event.EventModule;
|
||||||
import org.briarproject.messaging.MessagingModule;
|
import org.briarproject.messaging.MessagingModule;
|
||||||
@@ -49,7 +49,7 @@ public class OutgoingSimplexConnectionTest extends BriarTestCase {
|
|||||||
private final Mockery context;
|
private final Mockery context;
|
||||||
private final DatabaseComponent db;
|
private final DatabaseComponent db;
|
||||||
private final ConnectionRegistry connRegistry;
|
private final ConnectionRegistry connRegistry;
|
||||||
private final ConnectionWriterFactory connWriterFactory;
|
private final StreamWriterFactory connWriterFactory;
|
||||||
private final PacketWriterFactory packetWriterFactory;
|
private final PacketWriterFactory packetWriterFactory;
|
||||||
private final ContactId contactId;
|
private final ContactId contactId;
|
||||||
private final MessageId messageId;
|
private final MessageId messageId;
|
||||||
@@ -74,7 +74,7 @@ public class OutgoingSimplexConnectionTest extends BriarTestCase {
|
|||||||
new DuplexMessagingModule(), new SimplexMessagingModule(),
|
new DuplexMessagingModule(), new SimplexMessagingModule(),
|
||||||
new SerialModule(), new TransportModule());
|
new SerialModule(), new TransportModule());
|
||||||
connRegistry = i.getInstance(ConnectionRegistry.class);
|
connRegistry = i.getInstance(ConnectionRegistry.class);
|
||||||
connWriterFactory = i.getInstance(ConnectionWriterFactory.class);
|
connWriterFactory = i.getInstance(StreamWriterFactory.class);
|
||||||
packetWriterFactory = i.getInstance(PacketWriterFactory.class);
|
packetWriterFactory = i.getInstance(PacketWriterFactory.class);
|
||||||
contactId = new ContactId(234);
|
contactId = new ContactId(234);
|
||||||
messageId = new MessageId(TestUtils.getRandomId());
|
messageId = new MessageId(TestUtils.getRandomId());
|
||||||
@@ -88,7 +88,7 @@ public class OutgoingSimplexConnectionTest extends BriarTestCase {
|
|||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
TestSimplexTransportWriter transport = new TestSimplexTransportWriter(
|
TestSimplexTransportWriter transport = new TestSimplexTransportWriter(
|
||||||
out, MAX_PACKET_LENGTH, Long.MAX_VALUE);
|
out, MAX_PACKET_LENGTH, Long.MAX_VALUE);
|
||||||
ConnectionContext ctx = new ConnectionContext(contactId, transportId,
|
StreamContext ctx = new StreamContext(contactId, transportId,
|
||||||
secret, 0, true);
|
secret, 0, true);
|
||||||
OutgoingSimplexConnection connection = new OutgoingSimplexConnection(db,
|
OutgoingSimplexConnection connection = new OutgoingSimplexConnection(db,
|
||||||
connRegistry, connWriterFactory, packetWriterFactory, ctx,
|
connRegistry, connWriterFactory, packetWriterFactory, ctx,
|
||||||
@@ -105,8 +105,8 @@ public class OutgoingSimplexConnectionTest extends BriarTestCase {
|
|||||||
public void testNothingToSend() throws Exception {
|
public void testNothingToSend() throws Exception {
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
TestSimplexTransportWriter transport = new TestSimplexTransportWriter(
|
TestSimplexTransportWriter transport = new TestSimplexTransportWriter(
|
||||||
out, MIN_CONNECTION_LENGTH, Long.MAX_VALUE);
|
out, MIN_STREAM_LENGTH, Long.MAX_VALUE);
|
||||||
ConnectionContext ctx = new ConnectionContext(contactId, transportId,
|
StreamContext ctx = new StreamContext(contactId, transportId,
|
||||||
secret, 0, true);
|
secret, 0, true);
|
||||||
OutgoingSimplexConnection connection = new OutgoingSimplexConnection(db,
|
OutgoingSimplexConnection connection = new OutgoingSimplexConnection(db,
|
||||||
connRegistry, connWriterFactory, packetWriterFactory, ctx,
|
connRegistry, connWriterFactory, packetWriterFactory, ctx,
|
||||||
@@ -154,8 +154,8 @@ public class OutgoingSimplexConnectionTest extends BriarTestCase {
|
|||||||
public void testSomethingToSend() throws Exception {
|
public void testSomethingToSend() throws Exception {
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
TestSimplexTransportWriter transport = new TestSimplexTransportWriter(
|
TestSimplexTransportWriter transport = new TestSimplexTransportWriter(
|
||||||
out, MIN_CONNECTION_LENGTH, Long.MAX_VALUE);
|
out, MIN_STREAM_LENGTH, Long.MAX_VALUE);
|
||||||
ConnectionContext ctx = new ConnectionContext(contactId, transportId,
|
StreamContext ctx = new StreamContext(contactId, transportId,
|
||||||
secret, 0, true);
|
secret, 0, true);
|
||||||
OutgoingSimplexConnection connection = new OutgoingSimplexConnection(db,
|
OutgoingSimplexConnection connection = new OutgoingSimplexConnection(db,
|
||||||
connRegistry, connWriterFactory, packetWriterFactory, ctx,
|
connRegistry, connWriterFactory, packetWriterFactory, ctx,
|
||||||
|
|||||||
@@ -32,12 +32,12 @@ import org.briarproject.api.messaging.MessageFactory;
|
|||||||
import org.briarproject.api.messaging.MessageVerifier;
|
import org.briarproject.api.messaging.MessageVerifier;
|
||||||
import org.briarproject.api.messaging.PacketReaderFactory;
|
import org.briarproject.api.messaging.PacketReaderFactory;
|
||||||
import org.briarproject.api.messaging.PacketWriterFactory;
|
import org.briarproject.api.messaging.PacketWriterFactory;
|
||||||
import org.briarproject.api.transport.ConnectionContext;
|
|
||||||
import org.briarproject.api.transport.ConnectionReaderFactory;
|
|
||||||
import org.briarproject.api.transport.ConnectionRecogniser;
|
|
||||||
import org.briarproject.api.transport.ConnectionRegistry;
|
import org.briarproject.api.transport.ConnectionRegistry;
|
||||||
import org.briarproject.api.transport.ConnectionWriterFactory;
|
|
||||||
import org.briarproject.api.transport.Endpoint;
|
import org.briarproject.api.transport.Endpoint;
|
||||||
|
import org.briarproject.api.transport.StreamContext;
|
||||||
|
import org.briarproject.api.transport.StreamReaderFactory;
|
||||||
|
import org.briarproject.api.transport.StreamWriterFactory;
|
||||||
|
import org.briarproject.api.transport.TagRecogniser;
|
||||||
import org.briarproject.crypto.CryptoModule;
|
import org.briarproject.crypto.CryptoModule;
|
||||||
import org.briarproject.db.DatabaseModule;
|
import org.briarproject.db.DatabaseModule;
|
||||||
import org.briarproject.event.EventModule;
|
import org.briarproject.event.EventModule;
|
||||||
@@ -144,13 +144,13 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase {
|
|||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
ConnectionRegistry connRegistry =
|
ConnectionRegistry connRegistry =
|
||||||
alice.getInstance(ConnectionRegistry.class);
|
alice.getInstance(ConnectionRegistry.class);
|
||||||
ConnectionWriterFactory connWriterFactory =
|
StreamWriterFactory connWriterFactory =
|
||||||
alice.getInstance(ConnectionWriterFactory.class);
|
alice.getInstance(StreamWriterFactory.class);
|
||||||
PacketWriterFactory packetWriterFactory =
|
PacketWriterFactory packetWriterFactory =
|
||||||
alice.getInstance(PacketWriterFactory.class);
|
alice.getInstance(PacketWriterFactory.class);
|
||||||
TestSimplexTransportWriter transport = new TestSimplexTransportWriter(
|
TestSimplexTransportWriter transport = new TestSimplexTransportWriter(
|
||||||
out, Long.MAX_VALUE, Long.MAX_VALUE);
|
out, Long.MAX_VALUE, Long.MAX_VALUE);
|
||||||
ConnectionContext ctx = km.getConnectionContext(contactId, transportId);
|
StreamContext ctx = km.getStreamContext(contactId, transportId);
|
||||||
assertNotNull(ctx);
|
assertNotNull(ctx);
|
||||||
OutgoingSimplexConnection simplex = new OutgoingSimplexConnection(db,
|
OutgoingSimplexConnection simplex = new OutgoingSimplexConnection(db,
|
||||||
connRegistry, connWriterFactory, packetWriterFactory, ctx,
|
connRegistry, connWriterFactory, packetWriterFactory, ctx,
|
||||||
@@ -196,21 +196,21 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase {
|
|||||||
// 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);
|
||||||
// Create a connection recogniser and recognise the connection
|
// Create a tag recogniser and recognise the tag
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
||||||
ConnectionRecogniser rec = bob.getInstance(ConnectionRecogniser.class);
|
TagRecogniser rec = bob.getInstance(TagRecogniser.class);
|
||||||
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);
|
||||||
ConnectionContext ctx = rec.acceptConnection(transportId, tag);
|
StreamContext ctx = rec.recogniseTag(transportId, tag);
|
||||||
assertNotNull(ctx);
|
assertNotNull(ctx);
|
||||||
// Create an incoming simplex connection
|
// Create an incoming simplex connection
|
||||||
MessageVerifier messageVerifier =
|
MessageVerifier messageVerifier =
|
||||||
bob.getInstance(MessageVerifier.class);
|
bob.getInstance(MessageVerifier.class);
|
||||||
ConnectionRegistry connRegistry =
|
ConnectionRegistry connRegistry =
|
||||||
bob.getInstance(ConnectionRegistry.class);
|
bob.getInstance(ConnectionRegistry.class);
|
||||||
ConnectionReaderFactory connWriterFactory =
|
StreamReaderFactory connWriterFactory =
|
||||||
bob.getInstance(ConnectionReaderFactory.class);
|
bob.getInstance(StreamReaderFactory.class);
|
||||||
PacketReaderFactory packetWriterFactory =
|
PacketReaderFactory packetWriterFactory =
|
||||||
bob.getInstance(PacketReaderFactory.class);
|
bob.getInstance(PacketReaderFactory.class);
|
||||||
TestSimplexTransportReader transport =
|
TestSimplexTransportReader transport =
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package org.briarproject.plugins.file;
|
package org.briarproject.plugins.file;
|
||||||
|
|
||||||
import org.briarproject.BriarTestCase;
|
import org.briarproject.BriarTestCase;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class LinuxRemovableDriveFinderTest extends BriarTestCase {
|
public class LinuxRemovableDriveFinderTest extends BriarTestCase {
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package org.briarproject.plugins.file;
|
package org.briarproject.plugins.file;
|
||||||
|
|
||||||
import org.briarproject.BriarTestCase;
|
import org.briarproject.BriarTestCase;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class MacRemovableDriveFinderTest extends BriarTestCase {
|
public class MacRemovableDriveFinderTest extends BriarTestCase {
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
|||||||
|
|
||||||
import org.briarproject.BriarTestCase;
|
import org.briarproject.BriarTestCase;
|
||||||
import org.briarproject.plugins.file.RemovableDriveMonitor.Callback;
|
import org.briarproject.plugins.file.RemovableDriveMonitor.Callback;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class PollingRemovableDriveMonitorTest extends BriarTestCase {
|
public class PollingRemovableDriveMonitorTest extends BriarTestCase {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package org.briarproject.plugins.file;
|
package org.briarproject.plugins.file;
|
||||||
|
|
||||||
import static org.briarproject.api.transport.TransportConstants.MAX_FRAME_LENGTH;
|
import static org.briarproject.api.transport.TransportConstants.MAX_FRAME_LENGTH;
|
||||||
import static org.briarproject.api.transport.TransportConstants.MIN_CONNECTION_LENGTH;
|
import static org.briarproject.api.transport.TransportConstants.MIN_STREAM_LENGTH;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
@@ -20,7 +20,6 @@ import org.briarproject.api.plugins.simplex.SimplexTransportWriter;
|
|||||||
import org.briarproject.api.system.FileUtils;
|
import org.briarproject.api.system.FileUtils;
|
||||||
import org.briarproject.plugins.ImmediateExecutor;
|
import org.briarproject.plugins.ImmediateExecutor;
|
||||||
import org.briarproject.plugins.file.RemovableDriveMonitor.Callback;
|
import org.briarproject.plugins.file.RemovableDriveMonitor.Callback;
|
||||||
|
|
||||||
import org.jmock.Expectations;
|
import org.jmock.Expectations;
|
||||||
import org.jmock.Mockery;
|
import org.jmock.Mockery;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
@@ -344,10 +343,10 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
|||||||
|
|
||||||
File f = new File(testDir, "abcdefgh.dat");
|
File f = new File(testDir, "abcdefgh.dat");
|
||||||
OutputStream out = new FileOutputStream(f);
|
OutputStream out = new FileOutputStream(f);
|
||||||
out.write(new byte[MIN_CONNECTION_LENGTH]);
|
out.write(new byte[MIN_STREAM_LENGTH]);
|
||||||
out.flush();
|
out.flush();
|
||||||
out.close();
|
out.close();
|
||||||
assertEquals(MIN_CONNECTION_LENGTH, f.length());
|
assertEquals(MIN_STREAM_LENGTH, f.length());
|
||||||
plugin.driveInserted(testDir);
|
plugin.driveInserted(testDir);
|
||||||
|
|
||||||
context.assertIsSatisfied();
|
context.assertIsSatisfied();
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package org.briarproject.plugins.modem;
|
package org.briarproject.plugins.modem;
|
||||||
|
|
||||||
import org.briarproject.BriarTestCase;
|
import org.briarproject.BriarTestCase;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class CountryCodesTest extends BriarTestCase {
|
public class CountryCodesTest extends BriarTestCase {
|
||||||
|
|||||||
@@ -15,9 +15,9 @@ import org.briarproject.api.event.EventBus;
|
|||||||
import org.briarproject.api.event.EventListener;
|
import org.briarproject.api.event.EventListener;
|
||||||
import org.briarproject.api.system.Clock;
|
import org.briarproject.api.system.Clock;
|
||||||
import org.briarproject.api.system.Timer;
|
import org.briarproject.api.system.Timer;
|
||||||
import org.briarproject.api.transport.ConnectionContext;
|
|
||||||
import org.briarproject.api.transport.ConnectionRecogniser;
|
|
||||||
import org.briarproject.api.transport.Endpoint;
|
import org.briarproject.api.transport.Endpoint;
|
||||||
|
import org.briarproject.api.transport.StreamContext;
|
||||||
|
import org.briarproject.api.transport.TagRecogniser;
|
||||||
import org.briarproject.api.transport.TemporarySecret;
|
import org.briarproject.api.transport.TemporarySecret;
|
||||||
import org.jmock.Expectations;
|
import org.jmock.Expectations;
|
||||||
import org.jmock.Mockery;
|
import org.jmock.Mockery;
|
||||||
@@ -58,8 +58,8 @@ public class KeyManagerImplTest extends BriarTestCase {
|
|||||||
final CryptoComponent crypto = context.mock(CryptoComponent.class);
|
final CryptoComponent crypto = context.mock(CryptoComponent.class);
|
||||||
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||||
final EventBus eventBus = context.mock(EventBus.class);
|
final EventBus eventBus = context.mock(EventBus.class);
|
||||||
final ConnectionRecogniser connectionRecogniser =
|
final TagRecogniser connectionRecogniser =
|
||||||
context.mock(ConnectionRecogniser.class);
|
context.mock(TagRecogniser.class);
|
||||||
final Clock clock = context.mock(Clock.class);
|
final Clock clock = context.mock(Clock.class);
|
||||||
final Timer timer = context.mock(Timer.class);
|
final Timer timer = context.mock(Timer.class);
|
||||||
|
|
||||||
@@ -95,8 +95,8 @@ public class KeyManagerImplTest extends BriarTestCase {
|
|||||||
final CryptoComponent crypto = context.mock(CryptoComponent.class);
|
final CryptoComponent crypto = context.mock(CryptoComponent.class);
|
||||||
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||||
final EventBus eventBus = context.mock(EventBus.class);
|
final EventBus eventBus = context.mock(EventBus.class);
|
||||||
final ConnectionRecogniser connectionRecogniser =
|
final TagRecogniser connectionRecogniser =
|
||||||
context.mock(ConnectionRecogniser.class);
|
context.mock(TagRecogniser.class);
|
||||||
final Clock clock = context.mock(Clock.class);
|
final Clock clock = context.mock(Clock.class);
|
||||||
final Timer timer = context.mock(Timer.class);
|
final Timer timer = context.mock(Timer.class);
|
||||||
|
|
||||||
@@ -154,8 +154,8 @@ public class KeyManagerImplTest extends BriarTestCase {
|
|||||||
final CryptoComponent crypto = context.mock(CryptoComponent.class);
|
final CryptoComponent crypto = context.mock(CryptoComponent.class);
|
||||||
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||||
final EventBus eventBus = context.mock(EventBus.class);
|
final EventBus eventBus = context.mock(EventBus.class);
|
||||||
final ConnectionRecogniser connectionRecogniser =
|
final TagRecogniser connectionRecogniser =
|
||||||
context.mock(ConnectionRecogniser.class);
|
context.mock(TagRecogniser.class);
|
||||||
final Clock clock = context.mock(Clock.class);
|
final Clock clock = context.mock(Clock.class);
|
||||||
final Timer timer = context.mock(Timer.class);
|
final Timer timer = context.mock(Timer.class);
|
||||||
|
|
||||||
@@ -195,7 +195,7 @@ public class KeyManagerImplTest extends BriarTestCase {
|
|||||||
oneOf(connectionRecogniser).addSecret(s1);
|
oneOf(connectionRecogniser).addSecret(s1);
|
||||||
oneOf(connectionRecogniser).addSecret(s2);
|
oneOf(connectionRecogniser).addSecret(s2);
|
||||||
// getConnectionContext()
|
// getConnectionContext()
|
||||||
oneOf(db).incrementConnectionCounter(contactId, transportId, 1);
|
oneOf(db).incrementStreamCounter(contactId, transportId, 1);
|
||||||
will(returnValue(0L));
|
will(returnValue(0L));
|
||||||
// stop()
|
// stop()
|
||||||
oneOf(eventBus).removeListener(with(any(EventListener.class)));
|
oneOf(eventBus).removeListener(with(any(EventListener.class)));
|
||||||
@@ -205,13 +205,13 @@ public class KeyManagerImplTest extends BriarTestCase {
|
|||||||
|
|
||||||
assertTrue(keyManager.start());
|
assertTrue(keyManager.start());
|
||||||
keyManager.endpointAdded(ep, MAX_LATENCY, initialSecret.clone());
|
keyManager.endpointAdded(ep, MAX_LATENCY, initialSecret.clone());
|
||||||
ConnectionContext ctx =
|
StreamContext ctx =
|
||||||
keyManager.getConnectionContext(contactId, transportId);
|
keyManager.getStreamContext(contactId, transportId);
|
||||||
assertNotNull(ctx);
|
assertNotNull(ctx);
|
||||||
assertEquals(contactId, ctx.getContactId());
|
assertEquals(contactId, ctx.getContactId());
|
||||||
assertEquals(transportId, ctx.getTransportId());
|
assertEquals(transportId, ctx.getTransportId());
|
||||||
assertArrayEquals(secret1, ctx.getSecret());
|
assertArrayEquals(secret1, ctx.getSecret());
|
||||||
assertEquals(0, ctx.getConnectionNumber());
|
assertEquals(0, ctx.getStreamNumber());
|
||||||
assertEquals(true, ctx.getAlice());
|
assertEquals(true, ctx.getAlice());
|
||||||
keyManager.stop();
|
keyManager.stop();
|
||||||
|
|
||||||
@@ -224,8 +224,8 @@ public class KeyManagerImplTest extends BriarTestCase {
|
|||||||
final CryptoComponent crypto = context.mock(CryptoComponent.class);
|
final CryptoComponent crypto = context.mock(CryptoComponent.class);
|
||||||
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||||
final EventBus eventBus = context.mock(EventBus.class);
|
final EventBus eventBus = context.mock(EventBus.class);
|
||||||
final ConnectionRecogniser connectionRecogniser =
|
final TagRecogniser connectionRecogniser =
|
||||||
context.mock(ConnectionRecogniser.class);
|
context.mock(TagRecogniser.class);
|
||||||
final Clock clock = context.mock(Clock.class);
|
final Clock clock = context.mock(Clock.class);
|
||||||
final Timer timer = context.mock(Timer.class);
|
final Timer timer = context.mock(Timer.class);
|
||||||
|
|
||||||
@@ -273,8 +273,8 @@ public class KeyManagerImplTest extends BriarTestCase {
|
|||||||
final CryptoComponent crypto = context.mock(CryptoComponent.class);
|
final CryptoComponent crypto = context.mock(CryptoComponent.class);
|
||||||
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||||
final EventBus eventBus = context.mock(EventBus.class);
|
final EventBus eventBus = context.mock(EventBus.class);
|
||||||
final ConnectionRecogniser connectionRecogniser =
|
final TagRecogniser connectionRecogniser =
|
||||||
context.mock(ConnectionRecogniser.class);
|
context.mock(TagRecogniser.class);
|
||||||
final Clock clock = context.mock(Clock.class);
|
final Clock clock = context.mock(Clock.class);
|
||||||
final Timer timer = context.mock(Timer.class);
|
final Timer timer = context.mock(Timer.class);
|
||||||
|
|
||||||
@@ -332,8 +332,8 @@ public class KeyManagerImplTest extends BriarTestCase {
|
|||||||
final CryptoComponent crypto = context.mock(CryptoComponent.class);
|
final CryptoComponent crypto = context.mock(CryptoComponent.class);
|
||||||
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||||
final EventBus eventBus = context.mock(EventBus.class);
|
final EventBus eventBus = context.mock(EventBus.class);
|
||||||
final ConnectionRecogniser connectionRecogniser =
|
final TagRecogniser connectionRecogniser =
|
||||||
context.mock(ConnectionRecogniser.class);
|
context.mock(TagRecogniser.class);
|
||||||
final Clock clock = context.mock(Clock.class);
|
final Clock clock = context.mock(Clock.class);
|
||||||
final Timer timer = context.mock(Timer.class);
|
final Timer timer = context.mock(Timer.class);
|
||||||
|
|
||||||
@@ -393,8 +393,8 @@ public class KeyManagerImplTest extends BriarTestCase {
|
|||||||
final CryptoComponent crypto = context.mock(CryptoComponent.class);
|
final CryptoComponent crypto = context.mock(CryptoComponent.class);
|
||||||
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||||
final EventBus eventBus = context.mock(EventBus.class);
|
final EventBus eventBus = context.mock(EventBus.class);
|
||||||
final ConnectionRecogniser connectionRecogniser =
|
final TagRecogniser connectionRecogniser =
|
||||||
context.mock(ConnectionRecogniser.class);
|
context.mock(TagRecogniser.class);
|
||||||
final Clock clock = context.mock(Clock.class);
|
final Clock clock = context.mock(Clock.class);
|
||||||
final Timer timer = context.mock(Timer.class);
|
final Timer timer = context.mock(Timer.class);
|
||||||
|
|
||||||
@@ -428,7 +428,7 @@ public class KeyManagerImplTest extends BriarTestCase {
|
|||||||
oneOf(clock).currentTimeMillis();
|
oneOf(clock).currentTimeMillis();
|
||||||
will(returnValue(EPOCH + 1));
|
will(returnValue(EPOCH + 1));
|
||||||
// getConnectionContext()
|
// getConnectionContext()
|
||||||
oneOf(db).incrementConnectionCounter(contactId, transportId, 1);
|
oneOf(db).incrementStreamCounter(contactId, transportId, 1);
|
||||||
will(returnValue(0L));
|
will(returnValue(0L));
|
||||||
// stop()
|
// stop()
|
||||||
oneOf(eventBus).removeListener(with(any(EventListener.class)));
|
oneOf(eventBus).removeListener(with(any(EventListener.class)));
|
||||||
@@ -438,13 +438,13 @@ public class KeyManagerImplTest extends BriarTestCase {
|
|||||||
|
|
||||||
assertTrue(keyManager.start());
|
assertTrue(keyManager.start());
|
||||||
keyManager.run();
|
keyManager.run();
|
||||||
ConnectionContext ctx =
|
StreamContext ctx =
|
||||||
keyManager.getConnectionContext(contactId, transportId);
|
keyManager.getStreamContext(contactId, transportId);
|
||||||
assertNotNull(ctx);
|
assertNotNull(ctx);
|
||||||
assertEquals(contactId, ctx.getContactId());
|
assertEquals(contactId, ctx.getContactId());
|
||||||
assertEquals(transportId, ctx.getTransportId());
|
assertEquals(transportId, ctx.getTransportId());
|
||||||
assertArrayEquals(secret1, ctx.getSecret());
|
assertArrayEquals(secret1, ctx.getSecret());
|
||||||
assertEquals(0, ctx.getConnectionNumber());
|
assertEquals(0, ctx.getStreamNumber());
|
||||||
assertEquals(true, ctx.getAlice());
|
assertEquals(true, ctx.getAlice());
|
||||||
keyManager.stop();
|
keyManager.stop();
|
||||||
|
|
||||||
@@ -457,8 +457,8 @@ public class KeyManagerImplTest extends BriarTestCase {
|
|||||||
final CryptoComponent crypto = context.mock(CryptoComponent.class);
|
final CryptoComponent crypto = context.mock(CryptoComponent.class);
|
||||||
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||||
final EventBus eventBus = context.mock(EventBus.class);
|
final EventBus eventBus = context.mock(EventBus.class);
|
||||||
final ConnectionRecogniser connectionRecogniser =
|
final TagRecogniser connectionRecogniser =
|
||||||
context.mock(ConnectionRecogniser.class);
|
context.mock(TagRecogniser.class);
|
||||||
final Clock clock = context.mock(Clock.class);
|
final Clock clock = context.mock(Clock.class);
|
||||||
final Timer timer = context.mock(Timer.class);
|
final Timer timer = context.mock(Timer.class);
|
||||||
|
|
||||||
@@ -503,7 +503,7 @@ public class KeyManagerImplTest extends BriarTestCase {
|
|||||||
oneOf(db).addSecrets(Arrays.asList(s3));
|
oneOf(db).addSecrets(Arrays.asList(s3));
|
||||||
oneOf(connectionRecogniser).addSecret(s3);
|
oneOf(connectionRecogniser).addSecret(s3);
|
||||||
// getConnectionContext()
|
// getConnectionContext()
|
||||||
oneOf(db).incrementConnectionCounter(contactId, transportId, 2);
|
oneOf(db).incrementStreamCounter(contactId, transportId, 2);
|
||||||
will(returnValue(0L));
|
will(returnValue(0L));
|
||||||
// stop()
|
// stop()
|
||||||
oneOf(eventBus).removeListener(with(any(EventListener.class)));
|
oneOf(eventBus).removeListener(with(any(EventListener.class)));
|
||||||
@@ -513,13 +513,13 @@ public class KeyManagerImplTest extends BriarTestCase {
|
|||||||
|
|
||||||
assertTrue(keyManager.start());
|
assertTrue(keyManager.start());
|
||||||
keyManager.run();
|
keyManager.run();
|
||||||
ConnectionContext ctx =
|
StreamContext ctx =
|
||||||
keyManager.getConnectionContext(contactId, transportId);
|
keyManager.getStreamContext(contactId, transportId);
|
||||||
assertNotNull(ctx);
|
assertNotNull(ctx);
|
||||||
assertEquals(contactId, ctx.getContactId());
|
assertEquals(contactId, ctx.getContactId());
|
||||||
assertEquals(transportId, ctx.getTransportId());
|
assertEquals(transportId, ctx.getTransportId());
|
||||||
assertArrayEquals(secret2, ctx.getSecret());
|
assertArrayEquals(secret2, ctx.getSecret());
|
||||||
assertEquals(0, ctx.getConnectionNumber());
|
assertEquals(0, ctx.getStreamNumber());
|
||||||
assertEquals(true, ctx.getAlice());
|
assertEquals(true, ctx.getAlice());
|
||||||
keyManager.stop();
|
keyManager.stop();
|
||||||
|
|
||||||
@@ -532,8 +532,8 @@ public class KeyManagerImplTest extends BriarTestCase {
|
|||||||
final CryptoComponent crypto = context.mock(CryptoComponent.class);
|
final CryptoComponent crypto = context.mock(CryptoComponent.class);
|
||||||
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||||
final EventBus eventBus = context.mock(EventBus.class);
|
final EventBus eventBus = context.mock(EventBus.class);
|
||||||
final ConnectionRecogniser connectionRecogniser =
|
final TagRecogniser connectionRecogniser =
|
||||||
context.mock(ConnectionRecogniser.class);
|
context.mock(TagRecogniser.class);
|
||||||
final Clock clock = context.mock(Clock.class);
|
final Clock clock = context.mock(Clock.class);
|
||||||
final Timer timer = context.mock(Timer.class);
|
final Timer timer = context.mock(Timer.class);
|
||||||
|
|
||||||
@@ -581,7 +581,7 @@ public class KeyManagerImplTest extends BriarTestCase {
|
|||||||
oneOf(connectionRecogniser).addSecret(s3);
|
oneOf(connectionRecogniser).addSecret(s3);
|
||||||
oneOf(connectionRecogniser).addSecret(s4);
|
oneOf(connectionRecogniser).addSecret(s4);
|
||||||
// getConnectionContext()
|
// getConnectionContext()
|
||||||
oneOf(db).incrementConnectionCounter(contactId, transportId, 3);
|
oneOf(db).incrementStreamCounter(contactId, transportId, 3);
|
||||||
will(returnValue(0L));
|
will(returnValue(0L));
|
||||||
// stop()
|
// stop()
|
||||||
oneOf(eventBus).removeListener(with(any(EventListener.class)));
|
oneOf(eventBus).removeListener(with(any(EventListener.class)));
|
||||||
@@ -591,13 +591,13 @@ public class KeyManagerImplTest extends BriarTestCase {
|
|||||||
|
|
||||||
assertTrue(keyManager.start());
|
assertTrue(keyManager.start());
|
||||||
keyManager.run();
|
keyManager.run();
|
||||||
ConnectionContext ctx =
|
StreamContext ctx =
|
||||||
keyManager.getConnectionContext(contactId, transportId);
|
keyManager.getStreamContext(contactId, transportId);
|
||||||
assertNotNull(ctx);
|
assertNotNull(ctx);
|
||||||
assertEquals(contactId, ctx.getContactId());
|
assertEquals(contactId, ctx.getContactId());
|
||||||
assertEquals(transportId, ctx.getTransportId());
|
assertEquals(transportId, ctx.getTransportId());
|
||||||
assertArrayEquals(secret3, ctx.getSecret());
|
assertArrayEquals(secret3, ctx.getSecret());
|
||||||
assertEquals(0, ctx.getConnectionNumber());
|
assertEquals(0, ctx.getStreamNumber());
|
||||||
assertEquals(true, ctx.getAlice());
|
assertEquals(true, ctx.getAlice());
|
||||||
keyManager.stop();
|
keyManager.stop();
|
||||||
|
|
||||||
|
|||||||
@@ -17,9 +17,9 @@ import org.briarproject.api.event.EventBus;
|
|||||||
import org.briarproject.api.event.EventListener;
|
import org.briarproject.api.event.EventListener;
|
||||||
import org.briarproject.api.system.Clock;
|
import org.briarproject.api.system.Clock;
|
||||||
import org.briarproject.api.system.Timer;
|
import org.briarproject.api.system.Timer;
|
||||||
import org.briarproject.api.transport.ConnectionContext;
|
|
||||||
import org.briarproject.api.transport.ConnectionRecogniser;
|
|
||||||
import org.briarproject.api.transport.Endpoint;
|
import org.briarproject.api.transport.Endpoint;
|
||||||
|
import org.briarproject.api.transport.StreamContext;
|
||||||
|
import org.briarproject.api.transport.TagRecogniser;
|
||||||
import org.briarproject.api.transport.TemporarySecret;
|
import org.briarproject.api.transport.TemporarySecret;
|
||||||
import org.briarproject.util.ByteUtils;
|
import org.briarproject.util.ByteUtils;
|
||||||
import org.hamcrest.Description;
|
import org.hamcrest.Description;
|
||||||
@@ -78,8 +78,8 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
|
|||||||
final Clock clock = context.mock(Clock.class);
|
final Clock clock = context.mock(Clock.class);
|
||||||
final Timer timer = context.mock(Timer.class);
|
final Timer timer = context.mock(Timer.class);
|
||||||
|
|
||||||
final ConnectionRecogniser connectionRecogniser =
|
final TagRecogniser connectionRecogniser =
|
||||||
new ConnectionRecogniserImpl(crypto, db);
|
new TagRecogniserImpl(crypto, db);
|
||||||
final KeyManagerImpl keyManager = new KeyManagerImpl(crypto, db,
|
final KeyManagerImpl keyManager = new KeyManagerImpl(crypto, db,
|
||||||
eventBus, connectionRecogniser, clock, timer);
|
eventBus, connectionRecogniser, clock, timer);
|
||||||
|
|
||||||
@@ -117,8 +117,8 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
|
|||||||
final SecretKey k1 = context.mock(SecretKey.class, "k1");
|
final SecretKey k1 = context.mock(SecretKey.class, "k1");
|
||||||
final SecretKey k2 = context.mock(SecretKey.class, "k2");
|
final SecretKey k2 = context.mock(SecretKey.class, "k2");
|
||||||
|
|
||||||
final ConnectionRecogniser connectionRecogniser =
|
final TagRecogniser connectionRecogniser =
|
||||||
new ConnectionRecogniserImpl(crypto, db);
|
new TagRecogniserImpl(crypto, db);
|
||||||
final KeyManagerImpl keyManager = new KeyManagerImpl(crypto, db,
|
final KeyManagerImpl keyManager = new KeyManagerImpl(crypto, db,
|
||||||
eventBus, connectionRecogniser, clock, timer);
|
eventBus, connectionRecogniser, clock, timer);
|
||||||
|
|
||||||
@@ -241,8 +241,8 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
|
|||||||
final SecretKey k1 = context.mock(SecretKey.class, "k1");
|
final SecretKey k1 = context.mock(SecretKey.class, "k1");
|
||||||
final SecretKey k2 = context.mock(SecretKey.class, "k2");
|
final SecretKey k2 = context.mock(SecretKey.class, "k2");
|
||||||
|
|
||||||
final ConnectionRecogniser connectionRecogniser =
|
final TagRecogniser connectionRecogniser =
|
||||||
new ConnectionRecogniserImpl(crypto, db);
|
new TagRecogniserImpl(crypto, db);
|
||||||
final KeyManagerImpl keyManager = new KeyManagerImpl(crypto, db,
|
final KeyManagerImpl keyManager = new KeyManagerImpl(crypto, db,
|
||||||
eventBus, connectionRecogniser, clock, timer);
|
eventBus, connectionRecogniser, clock, timer);
|
||||||
|
|
||||||
@@ -308,7 +308,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
|
|||||||
}
|
}
|
||||||
oneOf(k2).erase();
|
oneOf(k2).erase();
|
||||||
// getConnectionContext()
|
// getConnectionContext()
|
||||||
oneOf(db).incrementConnectionCounter(contactId, transportId, 1);
|
oneOf(db).incrementStreamCounter(contactId, transportId, 1);
|
||||||
will(returnValue(0L));
|
will(returnValue(0L));
|
||||||
// stop()
|
// stop()
|
||||||
// The recogniser should derive the tags for period 0
|
// The recogniser should derive the tags for period 0
|
||||||
@@ -351,13 +351,13 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
|
|||||||
|
|
||||||
assertTrue(keyManager.start());
|
assertTrue(keyManager.start());
|
||||||
keyManager.endpointAdded(ep, MAX_LATENCY, initialSecret.clone());
|
keyManager.endpointAdded(ep, MAX_LATENCY, initialSecret.clone());
|
||||||
ConnectionContext ctx =
|
StreamContext ctx =
|
||||||
keyManager.getConnectionContext(contactId, transportId);
|
keyManager.getStreamContext(contactId, transportId);
|
||||||
assertNotNull(ctx);
|
assertNotNull(ctx);
|
||||||
assertEquals(contactId, ctx.getContactId());
|
assertEquals(contactId, ctx.getContactId());
|
||||||
assertEquals(transportId, ctx.getTransportId());
|
assertEquals(transportId, ctx.getTransportId());
|
||||||
assertArrayEquals(secret1, ctx.getSecret());
|
assertArrayEquals(secret1, ctx.getSecret());
|
||||||
assertEquals(0, ctx.getConnectionNumber());
|
assertEquals(0, ctx.getStreamNumber());
|
||||||
assertEquals(true, ctx.getAlice());
|
assertEquals(true, ctx.getAlice());
|
||||||
keyManager.stop();
|
keyManager.stop();
|
||||||
|
|
||||||
@@ -376,10 +376,10 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
|
|||||||
final SecretKey k1 = context.mock(SecretKey.class, "k1");
|
final SecretKey k1 = context.mock(SecretKey.class, "k1");
|
||||||
final SecretKey k2 = context.mock(SecretKey.class, "k2");
|
final SecretKey k2 = context.mock(SecretKey.class, "k2");
|
||||||
|
|
||||||
final ConnectionRecogniser connectionRecogniser =
|
final TagRecogniser tagRecogniser =
|
||||||
new ConnectionRecogniserImpl(crypto, db);
|
new TagRecogniserImpl(crypto, db);
|
||||||
final KeyManagerImpl keyManager = new KeyManagerImpl(crypto, db,
|
final KeyManagerImpl keyManager = new KeyManagerImpl(crypto, db,
|
||||||
eventBus, connectionRecogniser, clock, timer);
|
eventBus, tagRecogniser, clock, timer);
|
||||||
|
|
||||||
// The secrets for periods 0 - 2 should be derived
|
// The secrets for periods 0 - 2 should be derived
|
||||||
Endpoint ep = new Endpoint(contactId, transportId, EPOCH, true);
|
Endpoint ep = new Endpoint(contactId, transportId, EPOCH, true);
|
||||||
@@ -450,7 +450,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
|
|||||||
will(new EncodeTagAction());
|
will(new EncodeTagAction());
|
||||||
oneOf(k2).getEncoded();
|
oneOf(k2).getEncoded();
|
||||||
will(returnValue(key2));
|
will(returnValue(key2));
|
||||||
oneOf(db).setConnectionWindow(contactId, transportId, 2, 1,
|
oneOf(db).setReorderingWindow(contactId, transportId, 2, 1,
|
||||||
new byte[] {0, 1, 0, 0});
|
new byte[] {0, 1, 0, 0});
|
||||||
oneOf(k2).erase();
|
oneOf(k2).erase();
|
||||||
// stop()
|
// stop()
|
||||||
@@ -497,13 +497,12 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
|
|||||||
// Recognise the tag for connection 0 in period 2
|
// Recognise the tag for connection 0 in period 2
|
||||||
byte[] tag = new byte[TAG_LENGTH];
|
byte[] tag = new byte[TAG_LENGTH];
|
||||||
encodeTag(tag, key2, 0);
|
encodeTag(tag, key2, 0);
|
||||||
ConnectionContext ctx =
|
StreamContext ctx = tagRecogniser.recogniseTag(transportId, tag);
|
||||||
connectionRecogniser.acceptConnection(transportId, tag);
|
|
||||||
assertNotNull(ctx);
|
assertNotNull(ctx);
|
||||||
assertEquals(contactId, ctx.getContactId());
|
assertEquals(contactId, ctx.getContactId());
|
||||||
assertEquals(transportId, ctx.getTransportId());
|
assertEquals(transportId, ctx.getTransportId());
|
||||||
assertArrayEquals(secret2, ctx.getSecret());
|
assertArrayEquals(secret2, ctx.getSecret());
|
||||||
assertEquals(0, ctx.getConnectionNumber());
|
assertEquals(0, ctx.getStreamNumber());
|
||||||
assertEquals(true, ctx.getAlice());
|
assertEquals(true, ctx.getAlice());
|
||||||
keyManager.stop();
|
keyManager.stop();
|
||||||
|
|
||||||
@@ -522,8 +521,8 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
|
|||||||
final SecretKey k1 = context.mock(SecretKey.class, "k1");
|
final SecretKey k1 = context.mock(SecretKey.class, "k1");
|
||||||
final SecretKey k2 = context.mock(SecretKey.class, "k2");
|
final SecretKey k2 = context.mock(SecretKey.class, "k2");
|
||||||
|
|
||||||
final ConnectionRecogniser connectionRecogniser =
|
final TagRecogniser connectionRecogniser =
|
||||||
new ConnectionRecogniserImpl(crypto, db);
|
new TagRecogniserImpl(crypto, db);
|
||||||
final KeyManagerImpl keyManager = new KeyManagerImpl(crypto, db,
|
final KeyManagerImpl keyManager = new KeyManagerImpl(crypto, db,
|
||||||
eventBus, connectionRecogniser, clock, timer);
|
eventBus, connectionRecogniser, clock, timer);
|
||||||
|
|
||||||
@@ -637,8 +636,8 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
|
|||||||
final SecretKey k2 = context.mock(SecretKey.class, "k2");
|
final SecretKey k2 = context.mock(SecretKey.class, "k2");
|
||||||
final SecretKey k3 = context.mock(SecretKey.class, "k3");
|
final SecretKey k3 = context.mock(SecretKey.class, "k3");
|
||||||
|
|
||||||
final ConnectionRecogniser connectionRecogniser =
|
final TagRecogniser connectionRecogniser =
|
||||||
new ConnectionRecogniserImpl(crypto, db);
|
new TagRecogniserImpl(crypto, db);
|
||||||
final KeyManagerImpl keyManager = new KeyManagerImpl(crypto, db,
|
final KeyManagerImpl keyManager = new KeyManagerImpl(crypto, db,
|
||||||
eventBus, connectionRecogniser, clock, timer);
|
eventBus, connectionRecogniser, clock, timer);
|
||||||
|
|
||||||
@@ -762,8 +761,8 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
|
|||||||
final SecretKey k3 = context.mock(SecretKey.class, "k3");
|
final SecretKey k3 = context.mock(SecretKey.class, "k3");
|
||||||
final SecretKey k4 = context.mock(SecretKey.class, "k4");
|
final SecretKey k4 = context.mock(SecretKey.class, "k4");
|
||||||
|
|
||||||
final ConnectionRecogniser connectionRecogniser =
|
final TagRecogniser connectionRecogniser =
|
||||||
new ConnectionRecogniserImpl(crypto, db);
|
new TagRecogniserImpl(crypto, db);
|
||||||
final KeyManagerImpl keyManager = new KeyManagerImpl(crypto, db,
|
final KeyManagerImpl keyManager = new KeyManagerImpl(crypto, db,
|
||||||
eventBus, connectionRecogniser, clock, timer);
|
eventBus, connectionRecogniser, clock, timer);
|
||||||
|
|
||||||
@@ -877,10 +876,10 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
|
|||||||
context.assertIsSatisfied();
|
context.assertIsSatisfied();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void encodeTag(byte[] tag, byte[] rawKey, long connection) {
|
private void encodeTag(byte[] tag, byte[] rawKey, long streamNumber) {
|
||||||
// Encode a fake tag based on the key and connection number
|
// Encode a fake tag based on the key and stream number
|
||||||
System.arraycopy(rawKey, 0, tag, 0, tag.length);
|
System.arraycopy(rawKey, 0, tag, 0, tag.length);
|
||||||
ByteUtils.writeUint32(connection, tag, 0);
|
ByteUtils.writeUint32(streamNumber, tag, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class EncodeTagAction implements Action {
|
private class EncodeTagAction implements Action {
|
||||||
@@ -892,8 +891,8 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
|
|||||||
public Object invoke(Invocation invocation) throws Throwable {
|
public Object invoke(Invocation invocation) throws Throwable {
|
||||||
byte[] tag = (byte[]) invocation.getParameter(0);
|
byte[] tag = (byte[]) invocation.getParameter(0);
|
||||||
SecretKey key = (SecretKey) invocation.getParameter(1);
|
SecretKey key = (SecretKey) invocation.getParameter(1);
|
||||||
long connection = (Long) invocation.getParameter(2);
|
long streamNumber = (Long) invocation.getParameter(2);
|
||||||
encodeTag(tag, key.getEncoded(), connection);
|
encodeTag(tag, key.getEncoded(), streamNumber);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +1,19 @@
|
|||||||
package org.briarproject.transport;
|
package org.briarproject.transport;
|
||||||
|
|
||||||
import static org.briarproject.api.transport.TransportConstants.CONNECTION_WINDOW_SIZE;
|
import static org.briarproject.api.transport.TransportConstants.REORDERING_WINDOW_SIZE;
|
||||||
import static org.briarproject.util.ByteUtils.MAX_32_BIT_UNSIGNED;
|
import static org.briarproject.util.ByteUtils.MAX_32_BIT_UNSIGNED;
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
import static org.junit.Assert.assertArrayEquals;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
import org.briarproject.BriarTestCase;
|
import org.briarproject.BriarTestCase;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class ConnectionWindowTest extends BriarTestCase {
|
public class ReorderingWindowTest extends BriarTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWindowSliding() {
|
public void testWindowSliding() {
|
||||||
ConnectionWindow w = new ConnectionWindow();
|
ReorderingWindow w = new ReorderingWindow();
|
||||||
for(int i = 0; i < 100; i++) {
|
for(int i = 0; i < 100; i++) {
|
||||||
assertFalse(w.isSeen(i));
|
assertFalse(w.isSeen(i));
|
||||||
w.setSeen(i);
|
w.setSeen(i);
|
||||||
@@ -24,7 +23,7 @@ public class ConnectionWindowTest extends BriarTestCase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWindowJumping() {
|
public void testWindowJumping() {
|
||||||
ConnectionWindow w = new ConnectionWindow();
|
ReorderingWindow w = new ReorderingWindow();
|
||||||
for(int i = 0; i < 100; i += 13) {
|
for(int i = 0; i < 100; i += 13) {
|
||||||
assertFalse(w.isSeen(i));
|
assertFalse(w.isSeen(i));
|
||||||
w.setSeen(i);
|
w.setSeen(i);
|
||||||
@@ -34,7 +33,7 @@ public class ConnectionWindowTest extends BriarTestCase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWindowUpperLimit() {
|
public void testWindowUpperLimit() {
|
||||||
ConnectionWindow w = new ConnectionWindow();
|
ReorderingWindow w = new ReorderingWindow();
|
||||||
// Centre is 0, highest value in window is 15
|
// Centre is 0, highest value in window is 15
|
||||||
w.setSeen(15);
|
w.setSeen(15);
|
||||||
// Centre is 16, highest value in window is 31
|
// Centre is 16, highest value in window is 31
|
||||||
@@ -45,8 +44,8 @@ public class ConnectionWindowTest extends BriarTestCase {
|
|||||||
fail();
|
fail();
|
||||||
} catch(IllegalArgumentException expected) {}
|
} catch(IllegalArgumentException expected) {}
|
||||||
// Centre is max - 1, highest value in window is max
|
// Centre is max - 1, highest value in window is max
|
||||||
byte[] bitmap = new byte[CONNECTION_WINDOW_SIZE / 8];
|
byte[] bitmap = new byte[REORDERING_WINDOW_SIZE / 8];
|
||||||
w = new ConnectionWindow(MAX_32_BIT_UNSIGNED - 1, bitmap);
|
w = new ReorderingWindow(MAX_32_BIT_UNSIGNED - 1, bitmap);
|
||||||
assertFalse(w.isSeen(MAX_32_BIT_UNSIGNED - 1));
|
assertFalse(w.isSeen(MAX_32_BIT_UNSIGNED - 1));
|
||||||
assertFalse(w.isSeen(MAX_32_BIT_UNSIGNED));
|
assertFalse(w.isSeen(MAX_32_BIT_UNSIGNED));
|
||||||
// Values greater than max should never be allowed
|
// Values greater than max should never be allowed
|
||||||
@@ -59,7 +58,7 @@ public class ConnectionWindowTest extends BriarTestCase {
|
|||||||
// Centre should have moved to max + 1
|
// Centre should have moved to max + 1
|
||||||
assertEquals(MAX_32_BIT_UNSIGNED + 1, w.getCentre());
|
assertEquals(MAX_32_BIT_UNSIGNED + 1, w.getCentre());
|
||||||
// The bit corresponding to max should be set
|
// The bit corresponding to max should be set
|
||||||
byte[] expectedBitmap = new byte[CONNECTION_WINDOW_SIZE / 8];
|
byte[] expectedBitmap = new byte[REORDERING_WINDOW_SIZE / 8];
|
||||||
expectedBitmap[expectedBitmap.length / 2 - 1] = 1; // 00000001
|
expectedBitmap[expectedBitmap.length / 2 - 1] = 1; // 00000001
|
||||||
assertArrayEquals(expectedBitmap, w.getBitmap());
|
assertArrayEquals(expectedBitmap, w.getBitmap());
|
||||||
// Values greater than max should never be allowed even if centre > max
|
// Values greater than max should never be allowed even if centre > max
|
||||||
@@ -71,7 +70,7 @@ public class ConnectionWindowTest extends BriarTestCase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWindowLowerLimit() {
|
public void testWindowLowerLimit() {
|
||||||
ConnectionWindow w = new ConnectionWindow();
|
ReorderingWindow w = new ReorderingWindow();
|
||||||
// Centre is 0, negative values should never be allowed
|
// Centre is 0, negative values should never be allowed
|
||||||
try {
|
try {
|
||||||
w.setSeen(-1);
|
w.setSeen(-1);
|
||||||
@@ -100,7 +99,7 @@ public class ConnectionWindowTest extends BriarTestCase {
|
|||||||
// Centre should still be 26
|
// Centre should still be 26
|
||||||
assertEquals(26, w.getCentre());
|
assertEquals(26, w.getCentre());
|
||||||
// The bits corresponding to 10, 15, 16 and 25 should be set
|
// The bits corresponding to 10, 15, 16 and 25 should be set
|
||||||
byte[] expectedBitmap = new byte[CONNECTION_WINDOW_SIZE / 8];
|
byte[] expectedBitmap = new byte[REORDERING_WINDOW_SIZE / 8];
|
||||||
expectedBitmap[0] = (byte) 134; // 10000110
|
expectedBitmap[0] = (byte) 134; // 10000110
|
||||||
expectedBitmap[1] = 1; // 00000001
|
expectedBitmap[1] = 1; // 00000001
|
||||||
assertArrayEquals(expectedBitmap, w.getBitmap());
|
assertArrayEquals(expectedBitmap, w.getBitmap());
|
||||||
@@ -108,7 +107,7 @@ public class ConnectionWindowTest extends BriarTestCase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCannotSetSeenTwice() {
|
public void testCannotSetSeenTwice() {
|
||||||
ConnectionWindow w = new ConnectionWindow();
|
ReorderingWindow w = new ReorderingWindow();
|
||||||
w.setSeen(15);
|
w.setSeen(15);
|
||||||
try {
|
try {
|
||||||
w.setSeen(15);
|
w.setSeen(15);
|
||||||
@@ -117,8 +116,8 @@ public class ConnectionWindowTest extends BriarTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetUnseenConnectionNumbers() {
|
public void testGetUnseenStreamNumbers() {
|
||||||
ConnectionWindow w = new ConnectionWindow();
|
ReorderingWindow w = new ReorderingWindow();
|
||||||
// Centre is 0; window should cover 0 to 15, inclusive, with none seen
|
// Centre is 0; window should cover 0 to 15, inclusive, with none seen
|
||||||
Collection<Long> unseen = w.getUnseen();
|
Collection<Long> unseen = w.getUnseen();
|
||||||
assertEquals(16, unseen.size());
|
assertEquals(16, unseen.size());
|
||||||
@@ -2,13 +2,13 @@ package org.briarproject.transport;
|
|||||||
|
|
||||||
import static org.briarproject.api.transport.TransportConstants.HEADER_LENGTH;
|
import static org.briarproject.api.transport.TransportConstants.HEADER_LENGTH;
|
||||||
import static org.briarproject.api.transport.TransportConstants.MAC_LENGTH;
|
import static org.briarproject.api.transport.TransportConstants.MAC_LENGTH;
|
||||||
import org.briarproject.BriarTestCase;
|
|
||||||
|
|
||||||
|
import org.briarproject.BriarTestCase;
|
||||||
import org.jmock.Expectations;
|
import org.jmock.Expectations;
|
||||||
import org.jmock.Mockery;
|
import org.jmock.Mockery;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class ConnectionReaderImplTest extends BriarTestCase {
|
public class StreamReaderImplTest extends BriarTestCase {
|
||||||
|
|
||||||
private static final int FRAME_LENGTH = 1024;
|
private static final int FRAME_LENGTH = 1024;
|
||||||
private static final int MAX_PAYLOAD_LENGTH =
|
private static final int MAX_PAYLOAD_LENGTH =
|
||||||
@@ -28,13 +28,13 @@ public class ConnectionReaderImplTest extends BriarTestCase {
|
|||||||
oneOf(reader).readFrame(with(any(byte[].class)));
|
oneOf(reader).readFrame(with(any(byte[].class)));
|
||||||
will(returnValue(-1)); // No more frames
|
will(returnValue(-1)); // No more frames
|
||||||
}});
|
}});
|
||||||
ConnectionReaderImpl c = new ConnectionReaderImpl(reader, FRAME_LENGTH);
|
StreamReaderImpl r = new StreamReaderImpl(reader, FRAME_LENGTH);
|
||||||
assertEquals(0, c.read()); // Skip the first empty frame, read a byte
|
assertEquals(0, r.read()); // Skip the first empty frame, read a byte
|
||||||
assertEquals(0, c.read()); // Read another byte
|
assertEquals(0, r.read()); // Read another byte
|
||||||
assertEquals(-1, c.read()); // Skip the second empty frame, reach EOF
|
assertEquals(-1, r.read()); // Skip the second empty frame, reach EOF
|
||||||
assertEquals(-1, c.read()); // Still at EOF
|
assertEquals(-1, r.read()); // Still at EOF
|
||||||
context.assertIsSatisfied();
|
context.assertIsSatisfied();
|
||||||
c.close();
|
r.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -51,16 +51,16 @@ public class ConnectionReaderImplTest extends BriarTestCase {
|
|||||||
oneOf(reader).readFrame(with(any(byte[].class)));
|
oneOf(reader).readFrame(with(any(byte[].class)));
|
||||||
will(returnValue(-1)); // No more frames
|
will(returnValue(-1)); // No more frames
|
||||||
}});
|
}});
|
||||||
ConnectionReaderImpl c = new ConnectionReaderImpl(reader, FRAME_LENGTH);
|
StreamReaderImpl r = new StreamReaderImpl(reader, FRAME_LENGTH);
|
||||||
byte[] buf = new byte[MAX_PAYLOAD_LENGTH];
|
byte[] buf = new byte[MAX_PAYLOAD_LENGTH];
|
||||||
// Skip the first empty frame, read the two payload bytes
|
// Skip the first empty frame, read the two payload bytes
|
||||||
assertEquals(2, c.read(buf));
|
assertEquals(2, r.read(buf));
|
||||||
// Skip the second empty frame, reach EOF
|
// Skip the second empty frame, reach EOF
|
||||||
assertEquals(-1, c.read(buf));
|
assertEquals(-1, r.read(buf));
|
||||||
// Still at EOF
|
// Still at EOF
|
||||||
assertEquals(-1, c.read(buf));
|
assertEquals(-1, r.read(buf));
|
||||||
context.assertIsSatisfied();
|
context.assertIsSatisfied();
|
||||||
c.close();
|
r.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -73,16 +73,16 @@ public class ConnectionReaderImplTest extends BriarTestCase {
|
|||||||
oneOf(reader).readFrame(with(any(byte[].class)));
|
oneOf(reader).readFrame(with(any(byte[].class)));
|
||||||
will(returnValue(-1)); // No more frames
|
will(returnValue(-1)); // No more frames
|
||||||
}});
|
}});
|
||||||
ConnectionReaderImpl c = new ConnectionReaderImpl(reader, FRAME_LENGTH);
|
StreamReaderImpl r = new StreamReaderImpl(reader, FRAME_LENGTH);
|
||||||
byte[] buf = new byte[MAX_PAYLOAD_LENGTH / 2];
|
byte[] buf = new byte[MAX_PAYLOAD_LENGTH / 2];
|
||||||
// Read the first half of the payload
|
// Read the first half of the payload
|
||||||
assertEquals(MAX_PAYLOAD_LENGTH / 2, c.read(buf));
|
assertEquals(MAX_PAYLOAD_LENGTH / 2, r.read(buf));
|
||||||
// Read the second half of the payload
|
// Read the second half of the payload
|
||||||
assertEquals(MAX_PAYLOAD_LENGTH / 2, c.read(buf));
|
assertEquals(MAX_PAYLOAD_LENGTH / 2, r.read(buf));
|
||||||
// Reach EOF
|
// Reach EOF
|
||||||
assertEquals(-1, c.read(buf, 0, buf.length));
|
assertEquals(-1, r.read(buf, 0, buf.length));
|
||||||
context.assertIsSatisfied();
|
context.assertIsSatisfied();
|
||||||
c.close();
|
r.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -95,17 +95,17 @@ public class ConnectionReaderImplTest extends BriarTestCase {
|
|||||||
oneOf(reader).readFrame(with(any(byte[].class)));
|
oneOf(reader).readFrame(with(any(byte[].class)));
|
||||||
will(returnValue(-1)); // No more frames
|
will(returnValue(-1)); // No more frames
|
||||||
}});
|
}});
|
||||||
ConnectionReaderImpl c = new ConnectionReaderImpl(reader, FRAME_LENGTH);
|
StreamReaderImpl r = new StreamReaderImpl(reader, FRAME_LENGTH);
|
||||||
byte[] buf = new byte[MAX_PAYLOAD_LENGTH];
|
byte[] buf = new byte[MAX_PAYLOAD_LENGTH];
|
||||||
// Read the first half of the payload
|
// Read the first half of the payload
|
||||||
assertEquals(MAX_PAYLOAD_LENGTH / 2, c.read(buf, MAX_PAYLOAD_LENGTH / 2,
|
assertEquals(MAX_PAYLOAD_LENGTH / 2, r.read(buf, MAX_PAYLOAD_LENGTH / 2,
|
||||||
MAX_PAYLOAD_LENGTH / 2));
|
MAX_PAYLOAD_LENGTH / 2));
|
||||||
// Read the second half of the payload
|
// Read the second half of the payload
|
||||||
assertEquals(MAX_PAYLOAD_LENGTH / 2, c.read(buf, 123,
|
assertEquals(MAX_PAYLOAD_LENGTH / 2, r.read(buf, 123,
|
||||||
MAX_PAYLOAD_LENGTH / 2));
|
MAX_PAYLOAD_LENGTH / 2));
|
||||||
// Reach EOF
|
// Reach EOF
|
||||||
assertEquals(-1, c.read(buf, 0, buf.length));
|
assertEquals(-1, r.read(buf, 0, buf.length));
|
||||||
context.assertIsSatisfied();
|
context.assertIsSatisfied();
|
||||||
c.close();
|
r.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,13 +2,13 @@ package org.briarproject.transport;
|
|||||||
|
|
||||||
import static org.briarproject.api.transport.TransportConstants.HEADER_LENGTH;
|
import static org.briarproject.api.transport.TransportConstants.HEADER_LENGTH;
|
||||||
import static org.briarproject.api.transport.TransportConstants.MAC_LENGTH;
|
import static org.briarproject.api.transport.TransportConstants.MAC_LENGTH;
|
||||||
import org.briarproject.BriarTestCase;
|
|
||||||
|
|
||||||
|
import org.briarproject.BriarTestCase;
|
||||||
import org.jmock.Expectations;
|
import org.jmock.Expectations;
|
||||||
import org.jmock.Mockery;
|
import org.jmock.Mockery;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class ConnectionWriterImplTest extends BriarTestCase {
|
public class StreamWriterImplTest extends BriarTestCase {
|
||||||
|
|
||||||
private static final int FRAME_LENGTH = 1024;
|
private static final int FRAME_LENGTH = 1024;
|
||||||
private static final int MAX_PAYLOAD_LENGTH =
|
private static final int MAX_PAYLOAD_LENGTH =
|
||||||
@@ -25,8 +25,8 @@ public class ConnectionWriterImplTest extends BriarTestCase {
|
|||||||
// Flush the stream
|
// Flush the stream
|
||||||
oneOf(writer).flush();
|
oneOf(writer).flush();
|
||||||
}});
|
}});
|
||||||
ConnectionWriterImpl c = new ConnectionWriterImpl(writer, FRAME_LENGTH);
|
StreamWriterImpl w = new StreamWriterImpl(writer, FRAME_LENGTH);
|
||||||
c.close();
|
w.close();
|
||||||
context.assertIsSatisfied();
|
context.assertIsSatisfied();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,12 +34,12 @@ public class ConnectionWriterImplTest extends BriarTestCase {
|
|||||||
public void testFlushWithoutBufferedDataWritesFrame() throws Exception {
|
public void testFlushWithoutBufferedDataWritesFrame() throws Exception {
|
||||||
Mockery context = new Mockery();
|
Mockery context = new Mockery();
|
||||||
final FrameWriter writer = context.mock(FrameWriter.class);
|
final FrameWriter writer = context.mock(FrameWriter.class);
|
||||||
ConnectionWriterImpl c = new ConnectionWriterImpl(writer, FRAME_LENGTH);
|
StreamWriterImpl w = new StreamWriterImpl(writer, FRAME_LENGTH);
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
// Flush the stream
|
// Flush the stream
|
||||||
oneOf(writer).flush();
|
oneOf(writer).flush();
|
||||||
}});
|
}});
|
||||||
c.flush();
|
w.flush();
|
||||||
context.assertIsSatisfied();
|
context.assertIsSatisfied();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,7 +48,7 @@ public class ConnectionWriterImplTest extends BriarTestCase {
|
|||||||
throws Exception {
|
throws Exception {
|
||||||
Mockery context = new Mockery();
|
Mockery context = new Mockery();
|
||||||
final FrameWriter writer = context.mock(FrameWriter.class);
|
final FrameWriter writer = context.mock(FrameWriter.class);
|
||||||
ConnectionWriterImpl c = new ConnectionWriterImpl(writer, FRAME_LENGTH);
|
StreamWriterImpl w = new StreamWriterImpl(writer, FRAME_LENGTH);
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
// Write a non-final frame with one payload byte
|
// Write a non-final frame with one payload byte
|
||||||
oneOf(writer).writeFrame(with(any(byte[].class)), with(1),
|
oneOf(writer).writeFrame(with(any(byte[].class)), with(1),
|
||||||
@@ -56,8 +56,8 @@ public class ConnectionWriterImplTest extends BriarTestCase {
|
|||||||
// Flush the stream
|
// Flush the stream
|
||||||
oneOf(writer).flush();
|
oneOf(writer).flush();
|
||||||
}});
|
}});
|
||||||
c.write(0);
|
w.write(0);
|
||||||
c.flush();
|
w.flush();
|
||||||
context.assertIsSatisfied();
|
context.assertIsSatisfied();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,14 +65,14 @@ public class ConnectionWriterImplTest extends BriarTestCase {
|
|||||||
public void testSingleByteWritesWriteFullFrame() throws Exception {
|
public void testSingleByteWritesWriteFullFrame() throws Exception {
|
||||||
Mockery context = new Mockery();
|
Mockery context = new Mockery();
|
||||||
final FrameWriter writer = context.mock(FrameWriter.class);
|
final FrameWriter writer = context.mock(FrameWriter.class);
|
||||||
ConnectionWriterImpl c = new ConnectionWriterImpl(writer, FRAME_LENGTH);
|
StreamWriterImpl w = new StreamWriterImpl(writer, FRAME_LENGTH);
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
// Write a full non-final frame
|
// Write a full non-final frame
|
||||||
oneOf(writer).writeFrame(with(any(byte[].class)),
|
oneOf(writer).writeFrame(with(any(byte[].class)),
|
||||||
with(MAX_PAYLOAD_LENGTH), with(false));
|
with(MAX_PAYLOAD_LENGTH), with(false));
|
||||||
}});
|
}});
|
||||||
for(int i = 0; i < MAX_PAYLOAD_LENGTH; i++) {
|
for(int i = 0; i < MAX_PAYLOAD_LENGTH; i++) {
|
||||||
c.write(0);
|
w.write(0);
|
||||||
}
|
}
|
||||||
context.assertIsSatisfied();
|
context.assertIsSatisfied();
|
||||||
}
|
}
|
||||||
@@ -81,7 +81,7 @@ public class ConnectionWriterImplTest extends BriarTestCase {
|
|||||||
public void testMultiByteWritesWriteFullFrames() throws Exception {
|
public void testMultiByteWritesWriteFullFrames() throws Exception {
|
||||||
Mockery context = new Mockery();
|
Mockery context = new Mockery();
|
||||||
final FrameWriter writer = context.mock(FrameWriter.class);
|
final FrameWriter writer = context.mock(FrameWriter.class);
|
||||||
ConnectionWriterImpl c = new ConnectionWriterImpl(writer, FRAME_LENGTH);
|
StreamWriterImpl w = new StreamWriterImpl(writer, FRAME_LENGTH);
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
// Write two full non-final frames
|
// Write two full non-final frames
|
||||||
exactly(2).of(writer).writeFrame(with(any(byte[].class)),
|
exactly(2).of(writer).writeFrame(with(any(byte[].class)),
|
||||||
@@ -91,10 +91,10 @@ public class ConnectionWriterImplTest extends BriarTestCase {
|
|||||||
assertEquals(0, MAX_PAYLOAD_LENGTH % 2);
|
assertEquals(0, MAX_PAYLOAD_LENGTH % 2);
|
||||||
// Write two full payloads using four multi-byte writes
|
// Write two full payloads using four multi-byte writes
|
||||||
byte[] b = new byte[MAX_PAYLOAD_LENGTH / 2];
|
byte[] b = new byte[MAX_PAYLOAD_LENGTH / 2];
|
||||||
c.write(b);
|
w.write(b);
|
||||||
c.write(b);
|
w.write(b);
|
||||||
c.write(b);
|
w.write(b);
|
||||||
c.write(b);
|
w.write(b);
|
||||||
context.assertIsSatisfied();
|
context.assertIsSatisfied();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,7 +102,7 @@ public class ConnectionWriterImplTest extends BriarTestCase {
|
|||||||
public void testLargeMultiByteWriteWritesFullFrames() throws Exception {
|
public void testLargeMultiByteWriteWritesFullFrames() throws Exception {
|
||||||
Mockery context = new Mockery();
|
Mockery context = new Mockery();
|
||||||
final FrameWriter writer = context.mock(FrameWriter.class);
|
final FrameWriter writer = context.mock(FrameWriter.class);
|
||||||
ConnectionWriterImpl c = new ConnectionWriterImpl(writer, FRAME_LENGTH);
|
StreamWriterImpl w = new StreamWriterImpl(writer, FRAME_LENGTH);
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
// Write two full non-final frames
|
// Write two full non-final frames
|
||||||
exactly(2).of(writer).writeFrame(with(any(byte[].class)),
|
exactly(2).of(writer).writeFrame(with(any(byte[].class)),
|
||||||
@@ -115,9 +115,9 @@ public class ConnectionWriterImplTest extends BriarTestCase {
|
|||||||
}});
|
}});
|
||||||
// Write two full payloads using one large multi-byte write
|
// Write two full payloads using one large multi-byte write
|
||||||
byte[] b = new byte[MAX_PAYLOAD_LENGTH * 2 + 1];
|
byte[] b = new byte[MAX_PAYLOAD_LENGTH * 2 + 1];
|
||||||
c.write(b);
|
w.write(b);
|
||||||
// There should be one byte left in the buffer
|
// There should be one byte left in the buffer
|
||||||
c.close();
|
w.close();
|
||||||
context.assertIsSatisfied();
|
context.assertIsSatisfied();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,7 @@ package org.briarproject.transport;
|
|||||||
|
|
||||||
import static org.briarproject.api.messaging.MessagingConstants.MAX_PACKET_LENGTH;
|
import static org.briarproject.api.messaging.MessagingConstants.MAX_PACKET_LENGTH;
|
||||||
import static org.briarproject.api.transport.TransportConstants.MAX_FRAME_LENGTH;
|
import static org.briarproject.api.transport.TransportConstants.MAX_FRAME_LENGTH;
|
||||||
import static org.briarproject.api.transport.TransportConstants.MIN_CONNECTION_LENGTH;
|
import static org.briarproject.api.transport.TransportConstants.MIN_STREAM_LENGTH;
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
import static org.junit.Assert.assertArrayEquals;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
@@ -19,9 +19,9 @@ import org.briarproject.api.TransportId;
|
|||||||
import org.briarproject.api.crypto.AuthenticatedCipher;
|
import org.briarproject.api.crypto.AuthenticatedCipher;
|
||||||
import org.briarproject.api.crypto.CryptoComponent;
|
import org.briarproject.api.crypto.CryptoComponent;
|
||||||
import org.briarproject.api.crypto.SecretKey;
|
import org.briarproject.api.crypto.SecretKey;
|
||||||
import org.briarproject.api.transport.ConnectionContext;
|
import org.briarproject.api.transport.StreamContext;
|
||||||
import org.briarproject.api.transport.ConnectionWriter;
|
import org.briarproject.api.transport.StreamWriter;
|
||||||
import org.briarproject.api.transport.ConnectionWriterFactory;
|
import org.briarproject.api.transport.StreamWriterFactory;
|
||||||
import org.briarproject.crypto.CryptoModule;
|
import org.briarproject.crypto.CryptoModule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
@@ -35,7 +35,7 @@ public class TransportIntegrationTest extends BriarTestCase {
|
|||||||
private final int FRAME_LENGTH = 2048;
|
private final int FRAME_LENGTH = 2048;
|
||||||
|
|
||||||
private final CryptoComponent crypto;
|
private final CryptoComponent crypto;
|
||||||
private final ConnectionWriterFactory connectionWriterFactory;
|
private final StreamWriterFactory streamWriterFactory;
|
||||||
private final ContactId contactId;
|
private final ContactId contactId;
|
||||||
private final TransportId transportId;
|
private final TransportId transportId;
|
||||||
private final AuthenticatedCipher frameCipher;
|
private final AuthenticatedCipher frameCipher;
|
||||||
@@ -45,15 +45,16 @@ public class TransportIntegrationTest extends BriarTestCase {
|
|||||||
|
|
||||||
public TransportIntegrationTest() {
|
public TransportIntegrationTest() {
|
||||||
Module testModule = new AbstractModule() {
|
Module testModule = new AbstractModule() {
|
||||||
|
@Override
|
||||||
public void configure() {
|
public void configure() {
|
||||||
bind(ConnectionWriterFactory.class).to(
|
bind(StreamWriterFactory.class).to(
|
||||||
ConnectionWriterFactoryImpl.class);
|
StreamWriterFactoryImpl.class);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Injector i = Guice.createInjector(testModule, new CryptoModule(),
|
Injector i = Guice.createInjector(testModule, new CryptoModule(),
|
||||||
new TestLifecycleModule(), new TestSystemModule());
|
new TestLifecycleModule(), new TestSystemModule());
|
||||||
crypto = i.getInstance(CryptoComponent.class);
|
crypto = i.getInstance(CryptoComponent.class);
|
||||||
connectionWriterFactory = i.getInstance(ConnectionWriterFactory.class);
|
streamWriterFactory = i.getInstance(StreamWriterFactory.class);
|
||||||
contactId = new ContactId(234);
|
contactId = new ContactId(234);
|
||||||
transportId = new TransportId("id");
|
transportId = new TransportId("id");
|
||||||
frameCipher = crypto.getFrameCipher();
|
frameCipher = crypto.getFrameCipher();
|
||||||
@@ -86,7 +87,7 @@ public class TransportIntegrationTest extends BriarTestCase {
|
|||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
FrameWriter encryptionOut = new OutgoingEncryptionLayer(out,
|
FrameWriter encryptionOut = new OutgoingEncryptionLayer(out,
|
||||||
Long.MAX_VALUE, frameCipher, frameCopy, FRAME_LENGTH);
|
Long.MAX_VALUE, frameCipher, frameCopy, FRAME_LENGTH);
|
||||||
ConnectionWriterImpl writer = new ConnectionWriterImpl(encryptionOut,
|
StreamWriterImpl writer = new StreamWriterImpl(encryptionOut,
|
||||||
FRAME_LENGTH);
|
FRAME_LENGTH);
|
||||||
OutputStream out1 = writer.getOutputStream();
|
OutputStream out1 = writer.getOutputStream();
|
||||||
out1.write(frame);
|
out1.write(frame);
|
||||||
@@ -99,7 +100,7 @@ public class TransportIntegrationTest extends BriarTestCase {
|
|||||||
ByteArrayInputStream in = new ByteArrayInputStream(output);
|
ByteArrayInputStream in = new ByteArrayInputStream(output);
|
||||||
FrameReader encryptionIn = new IncomingEncryptionLayer(in, frameCipher,
|
FrameReader encryptionIn = new IncomingEncryptionLayer(in, frameCipher,
|
||||||
frameKey, FRAME_LENGTH);
|
frameKey, FRAME_LENGTH);
|
||||||
ConnectionReaderImpl reader = new ConnectionReaderImpl(encryptionIn,
|
StreamReaderImpl reader = new StreamReaderImpl(encryptionIn,
|
||||||
FRAME_LENGTH);
|
FRAME_LENGTH);
|
||||||
InputStream in1 = reader.getInputStream();
|
InputStream in1 = reader.getInputStream();
|
||||||
byte[] recovered = new byte[frame.length];
|
byte[] recovered = new byte[frame.length];
|
||||||
@@ -127,42 +128,42 @@ public class TransportIntegrationTest extends BriarTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void testOverheadWithTag() throws Exception {
|
public void testOverheadWithTag() throws Exception {
|
||||||
ByteArrayOutputStream out =
|
ByteArrayOutputStream out =
|
||||||
new ByteArrayOutputStream(MIN_CONNECTION_LENGTH);
|
new ByteArrayOutputStream(MIN_STREAM_LENGTH);
|
||||||
ConnectionContext ctx = new ConnectionContext(contactId, transportId,
|
StreamContext ctx = new StreamContext(contactId, transportId,
|
||||||
secret, 0, true);
|
secret, 0, true);
|
||||||
ConnectionWriter w = connectionWriterFactory.createConnectionWriter(out,
|
StreamWriter w = streamWriterFactory.createStreamWriter(out,
|
||||||
MAX_FRAME_LENGTH, MIN_CONNECTION_LENGTH, ctx, false, true);
|
MAX_FRAME_LENGTH, MIN_STREAM_LENGTH, ctx, false, true);
|
||||||
// Check that the connection writer thinks there's room for a packet
|
// Check that the connection writer thinks there's room for a packet
|
||||||
long capacity = w.getRemainingCapacity();
|
long capacity = w.getRemainingCapacity();
|
||||||
assertTrue(capacity > MAX_PACKET_LENGTH);
|
assertTrue(capacity > MAX_PACKET_LENGTH);
|
||||||
assertTrue(capacity < MIN_CONNECTION_LENGTH);
|
assertTrue(capacity < MIN_STREAM_LENGTH);
|
||||||
// Check that there really is room for a packet
|
// Check that there really is room for a packet
|
||||||
byte[] payload = new byte[MAX_PACKET_LENGTH];
|
byte[] payload = new byte[MAX_PACKET_LENGTH];
|
||||||
w.getOutputStream().write(payload);
|
w.getOutputStream().write(payload);
|
||||||
w.getOutputStream().close();
|
w.getOutputStream().close();
|
||||||
long used = out.size();
|
long used = out.size();
|
||||||
assertTrue(used > MAX_PACKET_LENGTH);
|
assertTrue(used > MAX_PACKET_LENGTH);
|
||||||
assertTrue(used <= MIN_CONNECTION_LENGTH);
|
assertTrue(used <= MIN_STREAM_LENGTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOverheadWithoutTag() throws Exception {
|
public void testOverheadWithoutTag() throws Exception {
|
||||||
ByteArrayOutputStream out =
|
ByteArrayOutputStream out =
|
||||||
new ByteArrayOutputStream(MIN_CONNECTION_LENGTH);
|
new ByteArrayOutputStream(MIN_STREAM_LENGTH);
|
||||||
ConnectionContext ctx = new ConnectionContext(contactId, transportId,
|
StreamContext ctx = new StreamContext(contactId, transportId,
|
||||||
secret, 0, true);
|
secret, 0, true);
|
||||||
ConnectionWriter w = connectionWriterFactory.createConnectionWriter(out,
|
StreamWriter w = streamWriterFactory.createStreamWriter(out,
|
||||||
MAX_FRAME_LENGTH, MIN_CONNECTION_LENGTH, ctx, false, false);
|
MAX_FRAME_LENGTH, MIN_STREAM_LENGTH, ctx, false, false);
|
||||||
// Check that the connection writer thinks there's room for a packet
|
// Check that the connection writer thinks there's room for a packet
|
||||||
long capacity = w.getRemainingCapacity();
|
long capacity = w.getRemainingCapacity();
|
||||||
assertTrue(capacity > MAX_PACKET_LENGTH);
|
assertTrue(capacity > MAX_PACKET_LENGTH);
|
||||||
assertTrue(capacity < MIN_CONNECTION_LENGTH);
|
assertTrue(capacity < MIN_STREAM_LENGTH);
|
||||||
// Check that there really is room for a packet
|
// Check that there really is room for a packet
|
||||||
byte[] payload = new byte[MAX_PACKET_LENGTH];
|
byte[] payload = new byte[MAX_PACKET_LENGTH];
|
||||||
w.getOutputStream().write(payload);
|
w.getOutputStream().write(payload);
|
||||||
w.getOutputStream().close();
|
w.getOutputStream().close();
|
||||||
long used = out.size();
|
long used = out.size();
|
||||||
assertTrue(used > MAX_PACKET_LENGTH);
|
assertTrue(used > MAX_PACKET_LENGTH);
|
||||||
assertTrue(used <= MIN_CONNECTION_LENGTH);
|
assertTrue(used <= MIN_STREAM_LENGTH);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import org.briarproject.api.TransportId;
|
|||||||
import org.briarproject.api.crypto.CryptoComponent;
|
import org.briarproject.api.crypto.CryptoComponent;
|
||||||
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.transport.ConnectionContext;
|
import org.briarproject.api.transport.StreamContext;
|
||||||
import org.briarproject.api.transport.TemporarySecret;
|
import org.briarproject.api.transport.TemporarySecret;
|
||||||
import org.briarproject.util.ByteUtils;
|
import org.briarproject.util.ByteUtils;
|
||||||
import org.hamcrest.Description;
|
import org.hamcrest.Description;
|
||||||
@@ -21,7 +21,7 @@ import org.jmock.api.Action;
|
|||||||
import org.jmock.api.Invocation;
|
import org.jmock.api.Invocation;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class TransportConnectionRecogniserTest extends BriarTestCase {
|
public class TransportTagRecogniserTest extends BriarTestCase {
|
||||||
|
|
||||||
private final ContactId contactId = new ContactId(234);
|
private final ContactId contactId = new ContactId(234);
|
||||||
private final TransportId transportId = new TransportId("id");
|
private final TransportId transportId = new TransportId("id");
|
||||||
@@ -57,15 +57,15 @@ public class TransportConnectionRecogniserTest extends BriarTestCase {
|
|||||||
}});
|
}});
|
||||||
TemporarySecret s = new TemporarySecret(contactId, transportId, 123,
|
TemporarySecret s = new TemporarySecret(contactId, transportId, 123,
|
||||||
alice, 0, secret, 0, 0, new byte[4]);
|
alice, 0, secret, 0, 0, new byte[4]);
|
||||||
TransportConnectionRecogniser recogniser =
|
TransportTagRecogniser recogniser =
|
||||||
new TransportConnectionRecogniser(crypto, db, transportId);
|
new TransportTagRecogniser(crypto, db, transportId);
|
||||||
recogniser.addSecret(s);
|
recogniser.addSecret(s);
|
||||||
recogniser.removeSecret(contactId, 0);
|
recogniser.removeSecret(contactId, 0);
|
||||||
context.assertIsSatisfied();
|
context.assertIsSatisfied();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAcceptConnection() throws Exception {
|
public void testRecogniseTag() throws Exception {
|
||||||
Mockery context = new Mockery();
|
Mockery context = new Mockery();
|
||||||
final CryptoComponent crypto = context.mock(CryptoComponent.class);
|
final CryptoComponent crypto = context.mock(CryptoComponent.class);
|
||||||
final byte[] secret = new byte[32];
|
final byte[] secret = new byte[32];
|
||||||
@@ -83,33 +83,35 @@ public class TransportConnectionRecogniserTest extends BriarTestCase {
|
|||||||
will(new EncodeTagAction());
|
will(new EncodeTagAction());
|
||||||
}
|
}
|
||||||
oneOf(tagKey).erase();
|
oneOf(tagKey).erase();
|
||||||
// Accept connection 0
|
// Recognise tag 0
|
||||||
oneOf(crypto).deriveTagKey(secret, !alice);
|
oneOf(crypto).deriveTagKey(secret, !alice);
|
||||||
will(returnValue(tagKey));
|
will(returnValue(tagKey));
|
||||||
// The window should slide to include connection 16
|
// The window should slide to include tag 16
|
||||||
oneOf(crypto).encodeTag(with(any(byte[].class)), with(tagKey),
|
oneOf(crypto).encodeTag(with(any(byte[].class)), with(tagKey),
|
||||||
with(16L));
|
with(16L));
|
||||||
will(new EncodeTagAction());
|
will(new EncodeTagAction());
|
||||||
// The updated window should be stored
|
// The updated window should be stored
|
||||||
oneOf(db).setConnectionWindow(contactId, transportId, 0, 1,
|
oneOf(db).setReorderingWindow(contactId, transportId, 0, 1,
|
||||||
new byte[] {0, 1, 0, 0});
|
new byte[] {0, 1, 0, 0});
|
||||||
oneOf(tagKey).erase();
|
oneOf(tagKey).erase();
|
||||||
// Accept connection again - no expectations
|
// Recognise tag again - no expectations
|
||||||
}});
|
}});
|
||||||
TemporarySecret s = new TemporarySecret(contactId, transportId, 123,
|
TemporarySecret s = new TemporarySecret(contactId, transportId, 123,
|
||||||
alice, 0, secret, 0, 0, new byte[4]);
|
alice, 0, secret, 0, 0, new byte[4]);
|
||||||
TransportConnectionRecogniser recogniser =
|
TransportTagRecogniser recogniser =
|
||||||
new TransportConnectionRecogniser(crypto, db, transportId);
|
new TransportTagRecogniser(crypto, db, transportId);
|
||||||
recogniser.addSecret(s);
|
recogniser.addSecret(s);
|
||||||
// Connection 0 should be expected
|
// Tag 0 should be expected
|
||||||
byte[] tag = new byte[TAG_LENGTH];
|
byte[] tag = new byte[TAG_LENGTH];
|
||||||
ConnectionContext ctx = recogniser.acceptConnection(tag);
|
StreamContext ctx = recogniser.recogniseTag(tag);
|
||||||
assertNotNull(ctx);
|
assertNotNull(ctx);
|
||||||
assertEquals(contactId, ctx.getContactId());
|
assertEquals(contactId, ctx.getContactId());
|
||||||
assertEquals(transportId, ctx.getTransportId());
|
assertEquals(transportId, ctx.getTransportId());
|
||||||
assertArrayEquals(secret, ctx.getSecret());
|
assertArrayEquals(secret, ctx.getSecret());
|
||||||
assertEquals(0, ctx.getConnectionNumber());
|
assertEquals(0, ctx.getStreamNumber());
|
||||||
assertEquals(alice, ctx.getAlice());
|
assertEquals(alice, ctx.getAlice());
|
||||||
|
// Tag 0 should not be expected again
|
||||||
|
assertNull(recogniser.recogniseTag(tag));
|
||||||
context.assertIsSatisfied();
|
context.assertIsSatisfied();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,9 +123,9 @@ public class TransportConnectionRecogniserTest extends BriarTestCase {
|
|||||||
|
|
||||||
public Object invoke(Invocation invocation) throws Throwable {
|
public Object invoke(Invocation invocation) throws Throwable {
|
||||||
byte[] tag = (byte[]) invocation.getParameter(0);
|
byte[] tag = (byte[]) invocation.getParameter(0);
|
||||||
long connection = (Long) invocation.getParameter(2);
|
long streamNumber = (Long) invocation.getParameter(2);
|
||||||
// Encode a fake tag based on the connection number
|
// Encode a fake tag based on the stream number
|
||||||
ByteUtils.writeUint32(connection, tag, 0);
|
ByteUtils.writeUint32(streamNumber, tag, 0);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
package org.briarproject.util;
|
package org.briarproject.util;
|
||||||
|
|
||||||
import org.briarproject.BriarTestCase;
|
import org.briarproject.BriarTestCase;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class ByteUtilsTest extends BriarTestCase {
|
public class ByteUtilsTest extends BriarTestCase {
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package org.briarproject.util;
|
package org.briarproject.util;
|
||||||
|
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
import static org.junit.Assert.assertArrayEquals;
|
||||||
import org.briarproject.BriarTestCase;
|
|
||||||
|
|
||||||
|
import org.briarproject.BriarTestCase;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class StringUtilsTest extends BriarTestCase {
|
public class StringUtilsTest extends BriarTestCase {
|
||||||
|
|||||||
Reference in New Issue
Block a user