diff --git a/briar-android/src/org/briarproject/plugins/droidtooth/DroidtoothPlugin.java b/briar-android/src/org/briarproject/plugins/droidtooth/DroidtoothPlugin.java index 1aff5ba37258f851fd6228fac0b9c5d305e65cf6..a63bbc7ebbc189a19c7d9a47094709caf5e78b40 100644 --- a/briar-android/src/org/briarproject/plugins/droidtooth/DroidtoothPlugin.java +++ b/briar-android/src/org/briarproject/plugins/droidtooth/DroidtoothPlugin.java @@ -69,7 +69,7 @@ class DroidtoothPlugin implements DuplexPlugin { private final SecureRandom secureRandom; private final Clock clock; private final DuplexPluginCallback callback; - private final int maxFrameLength, maxLatency, pollingInterval; + private final int maxLatency, pollingInterval; private volatile boolean running = false; private volatile boolean wasDisabled = false; @@ -81,7 +81,7 @@ class DroidtoothPlugin implements DuplexPlugin { DroidtoothPlugin(Executor ioExecutor, AndroidExecutor androidExecutor, Context appContext, SecureRandom secureRandom, Clock clock, - DuplexPluginCallback callback, int maxFrameLength, int maxLatency, + DuplexPluginCallback callback, int maxLatency, int pollingInterval) { this.ioExecutor = ioExecutor; this.androidExecutor = androidExecutor; @@ -89,7 +89,6 @@ class DroidtoothPlugin implements DuplexPlugin { this.secureRandom = secureRandom; this.clock = clock; this.callback = callback; - this.maxFrameLength = maxFrameLength; this.maxLatency = maxLatency; this.pollingInterval = pollingInterval; } @@ -98,10 +97,6 @@ class DroidtoothPlugin implements DuplexPlugin { return ID; } - public int getMaxFrameLength() { - return maxFrameLength; - } - public int getMaxLatency() { return maxLatency; } diff --git a/briar-android/src/org/briarproject/plugins/droidtooth/DroidtoothPluginFactory.java b/briar-android/src/org/briarproject/plugins/droidtooth/DroidtoothPluginFactory.java index 8cc21085d7a02686ae29b6da33d8348bdea0c274..2b04481c4b6e1f2d0641a734011bf90634d00201 100644 --- a/briar-android/src/org/briarproject/plugins/droidtooth/DroidtoothPluginFactory.java +++ b/briar-android/src/org/briarproject/plugins/droidtooth/DroidtoothPluginFactory.java @@ -15,7 +15,6 @@ import android.content.Context; public class DroidtoothPluginFactory implements DuplexPluginFactory { - private static final int MAX_FRAME_LENGTH = 1024; private static final int MAX_LATENCY = 30 * 1000; // 30 seconds private static final int POLLING_INTERVAL = 3 * 60 * 1000; // 3 minutes @@ -41,7 +40,6 @@ public class DroidtoothPluginFactory implements DuplexPluginFactory { public DuplexPlugin createPlugin(DuplexPluginCallback callback) { return new DroidtoothPlugin(ioExecutor, androidExecutor, appContext, - secureRandom, clock, callback, MAX_FRAME_LENGTH, MAX_LATENCY, - POLLING_INTERVAL); + secureRandom, clock, callback, MAX_LATENCY, POLLING_INTERVAL); } } diff --git a/briar-android/src/org/briarproject/plugins/droidtooth/DroidtoothTransportConnection.java b/briar-android/src/org/briarproject/plugins/droidtooth/DroidtoothTransportConnection.java index fa38875de088974578aaa8876aab450cb3464c87..e9b645e1c81d8c4efa31f34ac3467c00518c7968 100644 --- a/briar-android/src/org/briarproject/plugins/droidtooth/DroidtoothTransportConnection.java +++ b/briar-android/src/org/briarproject/plugins/droidtooth/DroidtoothTransportConnection.java @@ -39,10 +39,6 @@ class DroidtoothTransportConnection implements DuplexTransportConnection { private class Reader implements TransportConnectionReader { - public int getMaxFrameLength() { - return plugin.getMaxFrameLength(); - } - public long getMaxLatency() { return plugin.getMaxLatency(); } @@ -60,10 +56,6 @@ class DroidtoothTransportConnection implements DuplexTransportConnection { private class Writer implements TransportConnectionWriter { - public int getMaxFrameLength() { - return plugin.getMaxFrameLength(); - } - public int getMaxLatency() { return plugin.getMaxLatency(); } diff --git a/briar-android/src/org/briarproject/plugins/tcp/AndroidLanTcpPlugin.java b/briar-android/src/org/briarproject/plugins/tcp/AndroidLanTcpPlugin.java index 6194e2ee8ff107e14f000f867ca3ce0444ab8d4c..a7689bbda817040374156027b5616220025d2f22 100644 --- a/briar-android/src/org/briarproject/plugins/tcp/AndroidLanTcpPlugin.java +++ b/briar-android/src/org/briarproject/plugins/tcp/AndroidLanTcpPlugin.java @@ -26,10 +26,9 @@ class AndroidLanTcpPlugin extends LanTcpPlugin { private volatile BroadcastReceiver networkStateReceiver = null; AndroidLanTcpPlugin(Executor ioExecutor, Context appContext, - DuplexPluginCallback callback, int maxFrameLength, int maxLatency, + DuplexPluginCallback callback, int maxLatency, int maxIdleTime, int pollingInterval) { - super(ioExecutor, callback, maxFrameLength, maxLatency, maxIdleTime, - pollingInterval); + super(ioExecutor, callback, maxLatency, maxIdleTime, pollingInterval); this.appContext = appContext; } diff --git a/briar-android/src/org/briarproject/plugins/tcp/AndroidLanTcpPluginFactory.java b/briar-android/src/org/briarproject/plugins/tcp/AndroidLanTcpPluginFactory.java index 7e0a5469c2410a868c6d084891f097754acbed14..debad159c47e8d84eb96c11182186b67f2526dbd 100644 --- a/briar-android/src/org/briarproject/plugins/tcp/AndroidLanTcpPluginFactory.java +++ b/briar-android/src/org/briarproject/plugins/tcp/AndroidLanTcpPluginFactory.java @@ -11,7 +11,6 @@ import android.content.Context; public class AndroidLanTcpPluginFactory implements DuplexPluginFactory { - private static final int MAX_FRAME_LENGTH = 1024; private static final int MAX_LATENCY = 30 * 1000; // 30 seconds private static final int MAX_IDLE_TIME = 30 * 1000; // 30 seconds private static final int POLLING_INTERVAL = 3 * 60 * 1000; // 3 minutes @@ -30,6 +29,6 @@ public class AndroidLanTcpPluginFactory implements DuplexPluginFactory { public DuplexPlugin createPlugin(DuplexPluginCallback callback) { return new AndroidLanTcpPlugin(ioExecutor, appContext, callback, - MAX_FRAME_LENGTH, MAX_LATENCY, MAX_IDLE_TIME, POLLING_INTERVAL); + MAX_LATENCY, MAX_IDLE_TIME, POLLING_INTERVAL); } } diff --git a/briar-android/src/org/briarproject/plugins/tor/TorPlugin.java b/briar-android/src/org/briarproject/plugins/tor/TorPlugin.java index 4222da1ba99683e8e6200249351ab8ca35afa6ef..0d89832611d713258abc8848756cbe70d2d88285 100644 --- a/briar-android/src/org/briarproject/plugins/tor/TorPlugin.java +++ b/briar-android/src/org/briarproject/plugins/tor/TorPlugin.java @@ -75,8 +75,7 @@ class TorPlugin implements DuplexPlugin, EventHandler { private final Context appContext; private final LocationUtils locationUtils; private final DuplexPluginCallback callback; - private final int maxFrameLength, maxLatency, maxIdleTime, pollingInterval; - private final int socketTimeout; + private final int maxLatency, maxIdleTime, pollingInterval, socketTimeout; private final File torDirectory, torFile, geoIpFile, configFile, doneFile; private final File cookieFile, hostnameFile; private final AtomicBoolean circuitBuilt; @@ -90,13 +89,11 @@ class TorPlugin implements DuplexPlugin, EventHandler { TorPlugin(Executor ioExecutor, Context appContext, LocationUtils locationUtils, DuplexPluginCallback callback, - int maxFrameLength, int maxLatency, int maxIdleTime, - int pollingInterval) { + int maxLatency, int maxIdleTime, int pollingInterval) { this.ioExecutor = ioExecutor; this.appContext = appContext; this.locationUtils = locationUtils; this.callback = callback; - this.maxFrameLength = maxFrameLength; this.maxLatency = maxLatency; this.maxIdleTime = maxIdleTime; this.pollingInterval = pollingInterval; @@ -117,10 +114,6 @@ class TorPlugin implements DuplexPlugin, EventHandler { return ID; } - public int getMaxFrameLength() { - return maxFrameLength; - } - public int getMaxLatency() { return maxLatency; } diff --git a/briar-android/src/org/briarproject/plugins/tor/TorPluginFactory.java b/briar-android/src/org/briarproject/plugins/tor/TorPluginFactory.java index bf44a35933f96c4bc84b792ffc2f1097b46fdc0f..4861ba6b797188982c9433a4922f8fea107127f5 100644 --- a/briar-android/src/org/briarproject/plugins/tor/TorPluginFactory.java +++ b/briar-android/src/org/briarproject/plugins/tor/TorPluginFactory.java @@ -17,7 +17,6 @@ public class TorPluginFactory implements DuplexPluginFactory { private static final Logger LOG = Logger.getLogger(TorPluginFactory.class.getName()); - private static final int MAX_FRAME_LENGTH = 1024; private static final int MAX_LATENCY = 30 * 1000; // 30 seconds private static final int MAX_IDLE_TIME = 30 * 1000; // 30 seconds private static final int POLLING_INTERVAL = 3 * 60 * 1000; // 3 minutes @@ -44,6 +43,6 @@ public class TorPluginFactory implements DuplexPluginFactory { return null; } return new TorPlugin(ioExecutor,appContext, locationUtils, callback, - MAX_FRAME_LENGTH, MAX_LATENCY, MAX_IDLE_TIME, POLLING_INTERVAL); + MAX_LATENCY, MAX_IDLE_TIME, POLLING_INTERVAL); } } diff --git a/briar-android/src/org/briarproject/plugins/tor/TorTransportConnection.java b/briar-android/src/org/briarproject/plugins/tor/TorTransportConnection.java index 12880977f9dc27332ff78fd1a5ea8973e57e0465..4640eb1f6be81d3ae0275ed2274141aec2c385b2 100644 --- a/briar-android/src/org/briarproject/plugins/tor/TorTransportConnection.java +++ b/briar-android/src/org/briarproject/plugins/tor/TorTransportConnection.java @@ -38,10 +38,6 @@ class TorTransportConnection implements DuplexTransportConnection { private class Reader implements TransportConnectionReader { - public int getMaxFrameLength() { - return plugin.getMaxFrameLength(); - } - public long getMaxLatency() { return plugin.getMaxLatency(); } @@ -59,10 +55,6 @@ class TorTransportConnection implements DuplexTransportConnection { private class Writer implements TransportConnectionWriter { - public int getMaxFrameLength() { - return plugin.getMaxFrameLength(); - } - public int getMaxLatency() { return plugin.getMaxLatency(); } diff --git a/briar-api/src/org/briarproject/api/crypto/AuthenticatedCipher.java b/briar-api/src/org/briarproject/api/crypto/AuthenticatedCipher.java index 1a6d955229509fc9888ff2e11f94eaf5500b8bc3..444fcf13faa6de5cc5cfbaf38c92c96ed8dbf16a 100644 --- a/briar-api/src/org/briarproject/api/crypto/AuthenticatedCipher.java +++ b/briar-api/src/org/briarproject/api/crypto/AuthenticatedCipher.java @@ -2,7 +2,7 @@ package org.briarproject.api.crypto; import java.security.GeneralSecurityException; -/** An authenticated cipher that support additional authenticated data. */ +/** An authenticated cipher that supports additional authenticated data. */ public interface AuthenticatedCipher { /** diff --git a/briar-api/src/org/briarproject/api/crypto/StreamDecrypterFactory.java b/briar-api/src/org/briarproject/api/crypto/StreamDecrypterFactory.java index 46948f2a26625dc9b41fe434bd1e80cdebd8b78f..8b758ec11feef6c53fe7ef5cbb8ad65ca4a6f6aa 100644 --- a/briar-api/src/org/briarproject/api/crypto/StreamDecrypterFactory.java +++ b/briar-api/src/org/briarproject/api/crypto/StreamDecrypterFactory.java @@ -7,12 +7,11 @@ import org.briarproject.api.transport.StreamContext; public interface StreamDecrypterFactory { /** Creates a {@link StreamDecrypter} for decrypting a transport stream. */ - StreamDecrypter createStreamDecrypter(InputStream in, int maxFrameLength, - StreamContext ctx); + StreamDecrypter createStreamDecrypter(InputStream in, StreamContext ctx); /** * Creates a {@link StreamDecrypter} for decrypting an invitation stream. */ StreamDecrypter createInvitationStreamDecrypter(InputStream in, - int maxFrameLength, byte[] secret, boolean alice); + byte[] secret, boolean alice); } diff --git a/briar-api/src/org/briarproject/api/crypto/StreamEncrypterFactory.java b/briar-api/src/org/briarproject/api/crypto/StreamEncrypterFactory.java index 95912937e4e57a57ad7f39d64ec42bad0a7ba5ca..86df7bbe2439f1f0ea9c6417cd60c8b1911614f3 100644 --- a/briar-api/src/org/briarproject/api/crypto/StreamEncrypterFactory.java +++ b/briar-api/src/org/briarproject/api/crypto/StreamEncrypterFactory.java @@ -7,12 +7,11 @@ import org.briarproject.api.transport.StreamContext; public interface StreamEncrypterFactory { /** Creates a {@link StreamEncrypter} for encrypting a transport stream. */ - StreamEncrypter createStreamEncrypter(OutputStream out, - int maxFrameLength, StreamContext ctx); + StreamEncrypter createStreamEncrypter(OutputStream out, StreamContext ctx); /** * Creates a {@link StreamEncrypter} for encrypting an invitation stream. */ StreamEncrypter createInvitationStreamEncrypter(OutputStream out, - int maxFrameLength, byte[] secret, boolean alice); + byte[] secret, boolean alice); } diff --git a/briar-api/src/org/briarproject/api/plugins/Plugin.java b/briar-api/src/org/briarproject/api/plugins/Plugin.java index eafb9100707c1db7d20cab3e747986d5a2fe2d28..cc0338a4a3b9d1d9386db6885368e6f34adbef6c 100644 --- a/briar-api/src/org/briarproject/api/plugins/Plugin.java +++ b/briar-api/src/org/briarproject/api/plugins/Plugin.java @@ -11,9 +11,6 @@ public interface Plugin { /** Returns the plugin's transport identifier. */ TransportId getId(); - /** Returns the transport's maximum frame length in bytes. */ - int getMaxFrameLength(); - /** Returns the transport's maximum latency in milliseconds. */ int getMaxLatency(); diff --git a/briar-api/src/org/briarproject/api/plugins/TransportConnectionReader.java b/briar-api/src/org/briarproject/api/plugins/TransportConnectionReader.java index c4c99dfa37c3e17c94a43a438922fe5a52d173c2..e071c4432b0b8d5eeccd0f014294b25281ed262a 100644 --- a/briar-api/src/org/briarproject/api/plugins/TransportConnectionReader.java +++ b/briar-api/src/org/briarproject/api/plugins/TransportConnectionReader.java @@ -9,9 +9,6 @@ import java.io.InputStream; */ public interface TransportConnectionReader { - /** Returns the maximum frame length of the transport in bytes. */ - int getMaxFrameLength(); - /** Returns the maximum latency of the transport in milliseconds. */ long getMaxLatency(); diff --git a/briar-api/src/org/briarproject/api/plugins/TransportConnectionWriter.java b/briar-api/src/org/briarproject/api/plugins/TransportConnectionWriter.java index 7f07411c635bae555543243ff13d4d0b78dd1c19..d75522f1bb2c48f6541909864008e4bbf876ddb9 100644 --- a/briar-api/src/org/briarproject/api/plugins/TransportConnectionWriter.java +++ b/briar-api/src/org/briarproject/api/plugins/TransportConnectionWriter.java @@ -9,9 +9,6 @@ import java.io.OutputStream; */ public interface TransportConnectionWriter { - /** Returns the maximum frame length of the transport in bytes. */ - int getMaxFrameLength(); - /** Returns the maximum latency of the transport in milliseconds. */ int getMaxLatency(); diff --git a/briar-api/src/org/briarproject/api/transport/StreamReaderFactory.java b/briar-api/src/org/briarproject/api/transport/StreamReaderFactory.java index 3bf4cf049041e2fc8d1cb25298c6377f40c14477..5cf4fd6394ac7f9004d5ad1d48f5d1cca25f7fe2 100644 --- a/briar-api/src/org/briarproject/api/transport/StreamReaderFactory.java +++ b/briar-api/src/org/briarproject/api/transport/StreamReaderFactory.java @@ -8,13 +8,12 @@ public interface StreamReaderFactory { * Creates an {@link java.io.InputStream InputStream} for reading from a * transport stream. */ - InputStream createStreamReader(InputStream in, int maxFrameLength, - StreamContext ctx); + InputStream createStreamReader(InputStream in, StreamContext ctx); /** * Creates an {@link java.io.InputStream InputStream} for reading from an * invitation stream. */ InputStream createInvitationStreamReader(InputStream in, - int maxFrameLength, byte[] secret, boolean alice); + byte[] secret, boolean alice); } diff --git a/briar-api/src/org/briarproject/api/transport/StreamWriterFactory.java b/briar-api/src/org/briarproject/api/transport/StreamWriterFactory.java index 04a924cc674e6f9ddc1ae7b48289d117608f670a..38e373ccc244a1439d332176ee5380a89343aa9f 100644 --- a/briar-api/src/org/briarproject/api/transport/StreamWriterFactory.java +++ b/briar-api/src/org/briarproject/api/transport/StreamWriterFactory.java @@ -8,13 +8,12 @@ public interface StreamWriterFactory { * Creates an {@link java.io.OutputStream OutputStream} for writing to a * transport stream */ - OutputStream createStreamWriter(OutputStream out, int maxFrameLength, - StreamContext ctx); + OutputStream createStreamWriter(OutputStream out, StreamContext ctx); /** * Creates an {@link java.io.OutputStream OutputStream} for writing to an * invitation stream. */ OutputStream createInvitationStreamWriter(OutputStream out, - int maxFrameLength, byte[] secret, boolean alice); + byte[] secret, boolean alice); } diff --git a/briar-api/src/org/briarproject/api/transport/TransportConstants.java b/briar-api/src/org/briarproject/api/transport/TransportConstants.java index 666d74e964b00202b89b907c1011caa5e98616d3..7a13dbe9eb6689fcb44178b602db91befac104d6 100644 --- a/briar-api/src/org/briarproject/api/transport/TransportConstants.java +++ b/briar-api/src/org/briarproject/api/transport/TransportConstants.java @@ -6,7 +6,7 @@ public interface TransportConstants { int TAG_LENGTH = 16; /** The maximum length of a frame in bytes, including the header and MAC. */ - int MAX_FRAME_LENGTH = 32768; // 2^15, 32 KiB + int MAX_FRAME_LENGTH = 1024; /** The length of the initalisation vector (IV) in bytes. */ int IV_LENGTH = 12; diff --git a/briar-core/src/org/briarproject/crypto/StreamDecrypterFactoryImpl.java b/briar-core/src/org/briarproject/crypto/StreamDecrypterFactoryImpl.java index 8f04e686ae86d21b492bfc77b7df94d52eeab1db..5fb504b8480db6393ee6dd7edbfeab1ffc9c25ec 100644 --- a/briar-core/src/org/briarproject/crypto/StreamDecrypterFactoryImpl.java +++ b/briar-core/src/org/briarproject/crypto/StreamDecrypterFactoryImpl.java @@ -20,23 +20,21 @@ class StreamDecrypterFactoryImpl implements StreamDecrypterFactory { } public StreamDecrypter createStreamDecrypter(InputStream in, - int maxFrameLength, StreamContext ctx) { + StreamContext ctx) { byte[] secret = ctx.getSecret(); long streamNumber = ctx.getStreamNumber(); boolean alice = !ctx.getAlice(); // Derive the frame key SecretKey frameKey = crypto.deriveFrameKey(secret, streamNumber, alice); // Create the decrypter - return new StreamDecrypterImpl(in, crypto.getFrameCipher(), frameKey, - maxFrameLength); + return new StreamDecrypterImpl(in, crypto.getFrameCipher(), frameKey); } public StreamDecrypter createInvitationStreamDecrypter(InputStream in, - int maxFrameLength, byte[] secret, boolean alice) { + byte[] secret, boolean alice) { // Derive the frame key SecretKey frameKey = crypto.deriveFrameKey(secret, 0, alice); // Create the decrypter - return new StreamDecrypterImpl(in, crypto.getFrameCipher(), frameKey, - maxFrameLength); + return new StreamDecrypterImpl(in, crypto.getFrameCipher(), frameKey); } } diff --git a/briar-core/src/org/briarproject/crypto/StreamDecrypterImpl.java b/briar-core/src/org/briarproject/crypto/StreamDecrypterImpl.java index 4127e99a7099dc8f42de842b3606434df0df0676..206a12c617fef5f886b7a1c869fd43d252f45df7 100644 --- a/briar-core/src/org/briarproject/crypto/StreamDecrypterImpl.java +++ b/briar-core/src/org/briarproject/crypto/StreamDecrypterImpl.java @@ -4,6 +4,7 @@ import static org.briarproject.api.transport.TransportConstants.AAD_LENGTH; import static org.briarproject.api.transport.TransportConstants.HEADER_LENGTH; 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.MAX_FRAME_LENGTH; import java.io.EOFException; import java.io.IOException; @@ -21,21 +22,19 @@ class StreamDecrypterImpl implements StreamDecrypter { private final AuthenticatedCipher frameCipher; private final SecretKey frameKey; private final byte[] iv, aad, plaintext, ciphertext; - private final int frameLength; private long frameNumber; private boolean finalFrame; StreamDecrypterImpl(InputStream in, AuthenticatedCipher frameCipher, - SecretKey frameKey, int frameLength) { + SecretKey frameKey) { this.in = in; this.frameCipher = frameCipher; this.frameKey = frameKey; - this.frameLength = frameLength; iv = new byte[IV_LENGTH]; aad = new byte[AAD_LENGTH]; - plaintext = new byte[frameLength - MAC_LENGTH]; - ciphertext = new byte[frameLength]; + plaintext = new byte[MAX_FRAME_LENGTH - MAC_LENGTH]; + ciphertext = new byte[MAX_FRAME_LENGTH]; frameNumber = 0; finalFrame = false; } @@ -44,9 +43,9 @@ class StreamDecrypterImpl implements StreamDecrypter { if(finalFrame) return -1; // Read the frame int ciphertextLength = 0; - while(ciphertextLength < frameLength) { + while(ciphertextLength < MAX_FRAME_LENGTH) { int read = in.read(ciphertext, ciphertextLength, - frameLength - ciphertextLength); + MAX_FRAME_LENGTH - ciphertextLength); if(read == -1) break; // We'll check the length later ciphertextLength += read; } @@ -65,7 +64,7 @@ class StreamDecrypterImpl implements StreamDecrypter { } // Decode and validate the header finalFrame = FrameEncoder.isFinalFrame(plaintext); - if(!finalFrame && ciphertextLength < frameLength) + if(!finalFrame && ciphertextLength < MAX_FRAME_LENGTH) throw new FormatException(); int payloadLength = FrameEncoder.getPayloadLength(plaintext); if(payloadLength > plaintextLength - HEADER_LENGTH) diff --git a/briar-core/src/org/briarproject/crypto/StreamEncrypterFactoryImpl.java b/briar-core/src/org/briarproject/crypto/StreamEncrypterFactoryImpl.java index 07c9deaabf4affec9cfcc7892664351d766a9403..ec8286e06100b00598b726925e6a4eb0eb096cc7 100644 --- a/briar-core/src/org/briarproject/crypto/StreamEncrypterFactoryImpl.java +++ b/briar-core/src/org/briarproject/crypto/StreamEncrypterFactoryImpl.java @@ -22,7 +22,7 @@ class StreamEncrypterFactoryImpl implements StreamEncrypterFactory { } public StreamEncrypter createStreamEncrypter(OutputStream out, - int maxFrameLength, StreamContext ctx) { + StreamContext ctx) { byte[] secret = ctx.getSecret(); long streamNumber = ctx.getStreamNumber(); boolean alice = ctx.getAlice(); @@ -34,15 +34,15 @@ class StreamEncrypterFactoryImpl implements StreamEncrypterFactory { SecretKey frameKey = crypto.deriveFrameKey(secret, streamNumber, alice); // Create the encrypter return new StreamEncrypterImpl(out, crypto.getFrameCipher(), frameKey, - maxFrameLength, tag); + tag); } public StreamEncrypter createInvitationStreamEncrypter(OutputStream out, - int maxFrameLength, byte[] secret, boolean alice) { + byte[] secret, boolean alice) { // Derive the frame key SecretKey frameKey = crypto.deriveFrameKey(secret, 0, alice); // Create the encrypter return new StreamEncrypterImpl(out, crypto.getFrameCipher(), frameKey, - maxFrameLength, null); + null); } } diff --git a/briar-core/src/org/briarproject/crypto/StreamEncrypterImpl.java b/briar-core/src/org/briarproject/crypto/StreamEncrypterImpl.java index 43a6403912874e163f5a893361f1868713cca205..0a09fc2055a6aacc7d04188c811f92b5b7079194 100644 --- a/briar-core/src/org/briarproject/crypto/StreamEncrypterImpl.java +++ b/briar-core/src/org/briarproject/crypto/StreamEncrypterImpl.java @@ -4,6 +4,7 @@ import static org.briarproject.api.transport.TransportConstants.AAD_LENGTH; import static org.briarproject.api.transport.TransportConstants.HEADER_LENGTH; 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.MAX_FRAME_LENGTH; import static org.briarproject.util.ByteUtils.MAX_32_BIT_UNSIGNED; import java.io.IOException; @@ -20,22 +21,20 @@ class StreamEncrypterImpl implements StreamEncrypter { private final AuthenticatedCipher frameCipher; private final SecretKey frameKey; private final byte[] tag, iv, aad, plaintext, ciphertext; - private final int frameLength; private long frameNumber; private boolean writeTag; StreamEncrypterImpl(OutputStream out, AuthenticatedCipher frameCipher, - SecretKey frameKey, int frameLength, byte[] tag) { + SecretKey frameKey, byte[] tag) { this.out = out; this.frameCipher = frameCipher; this.frameKey = frameKey; - this.frameLength = frameLength; this.tag = tag; iv = new byte[IV_LENGTH]; aad = new byte[AAD_LENGTH]; - plaintext = new byte[frameLength - MAC_LENGTH]; - ciphertext = new byte[frameLength]; + plaintext = new byte[MAX_FRAME_LENGTH - MAC_LENGTH]; + ciphertext = new byte[MAX_FRAME_LENGTH]; frameNumber = 0; writeTag = (tag != null); } @@ -54,8 +53,8 @@ class StreamEncrypterImpl implements StreamEncrypter { plaintextLength = HEADER_LENGTH + payloadLength; ciphertextLength = plaintextLength + MAC_LENGTH; } else { - plaintextLength = frameLength - MAC_LENGTH; - ciphertextLength = frameLength; + plaintextLength = MAX_FRAME_LENGTH - MAC_LENGTH; + ciphertextLength = MAX_FRAME_LENGTH; } // Encode the header FrameEncoder.encodeHeader(plaintext, finalFrame, payloadLength); diff --git a/briar-core/src/org/briarproject/invitation/AliceConnector.java b/briar-core/src/org/briarproject/invitation/AliceConnector.java index 8c0bd78130b535ac9c0729d99dd84084addbfa97..f641af40a65124ff9df9ae4584910aa95fd1f52e 100644 --- a/briar-core/src/org/briarproject/invitation/AliceConnector.java +++ b/briar-core/src/org/briarproject/invitation/AliceConnector.java @@ -128,16 +128,15 @@ class AliceConnector extends Connector { // Confirmation succeeded - upgrade to a secure connection if(LOG.isLoggable(INFO)) LOG.info(pluginName + " confirmation succeeded"); - int maxFrameLength = conn.getReader().getMaxFrameLength(); // Create the readers InputStream streamReader = streamReaderFactory.createInvitationStreamReader(in, - maxFrameLength, secret, false); // Bob's stream + secret, false); // Bob's stream r = readerFactory.createReader(streamReader); // Create the writers OutputStream streamWriter = streamWriterFactory.createInvitationStreamWriter(out, - maxFrameLength, secret, true); // Alice's stream + secret, true); // Alice's stream w = writerFactory.createWriter(streamWriter); // Derive the invitation nonces byte[][] nonces = crypto.deriveInvitationNonces(secret); diff --git a/briar-core/src/org/briarproject/invitation/BobConnector.java b/briar-core/src/org/briarproject/invitation/BobConnector.java index 6b435fd2a6c12e92d3d1bf3d54ec4307f871ab3b..dae8691920e1acf62cfc81c4af54feae020ba704 100644 --- a/briar-core/src/org/briarproject/invitation/BobConnector.java +++ b/briar-core/src/org/briarproject/invitation/BobConnector.java @@ -128,16 +128,15 @@ class BobConnector extends Connector { // Confirmation succeeded - upgrade to a secure connection if(LOG.isLoggable(INFO)) LOG.info(pluginName + " confirmation succeeded"); - int maxFrameLength = conn.getReader().getMaxFrameLength(); // Create the readers InputStream streamReader = streamReaderFactory.createInvitationStreamReader(in, - maxFrameLength, secret, true); // Alice's stream + secret, true); // Alice's stream r = readerFactory.createReader(streamReader); // Create the writers OutputStream streamWriter = streamWriterFactory.createInvitationStreamWriter(out, - maxFrameLength, secret, false); // Bob's stream + secret, false); // Bob's stream w = writerFactory.createWriter(streamWriter); // Derive the nonces byte[][] nonces = crypto.deriveInvitationNonces(secret); diff --git a/briar-core/src/org/briarproject/plugins/ConnectionManagerImpl.java b/briar-core/src/org/briarproject/plugins/ConnectionManagerImpl.java index 2b1a5c633ee8fbb63f13d1f2fcd57b514f7ad925..b7cb70c1bd8fc9b90560145603d1d49722c8992c 100644 --- a/briar-core/src/org/briarproject/plugins/ConnectionManagerImpl.java +++ b/briar-core/src/org/briarproject/plugins/ConnectionManagerImpl.java @@ -95,7 +95,7 @@ class ConnectionManagerImpl implements ConnectionManager { private MessagingSession createIncomingSession(StreamContext ctx, TransportConnectionReader r) throws IOException { InputStream streamReader = streamReaderFactory.createStreamReader( - r.getInputStream(), r.getMaxFrameLength(), ctx); + r.getInputStream(), ctx); return messagingSessionFactory.createIncomingSession( ctx.getContactId(), ctx.getTransportId(), streamReader); } @@ -103,7 +103,7 @@ class ConnectionManagerImpl implements ConnectionManager { private MessagingSession createSimplexOutgoingSession(StreamContext ctx, TransportConnectionWriter w) throws IOException { OutputStream streamWriter = streamWriterFactory.createStreamWriter( - w.getOutputStream(), w.getMaxFrameLength(), ctx); + w.getOutputStream(), ctx); return messagingSessionFactory.createSimplexOutgoingSession( ctx.getContactId(), ctx.getTransportId(), w.getMaxLatency(), streamWriter); @@ -112,7 +112,7 @@ class ConnectionManagerImpl implements ConnectionManager { private MessagingSession createDuplexOutgoingSession(StreamContext ctx, TransportConnectionWriter w) throws IOException { OutputStream streamWriter = streamWriterFactory.createStreamWriter( - w.getOutputStream(), w.getMaxFrameLength(), ctx); + w.getOutputStream(), ctx); return messagingSessionFactory.createDuplexOutgoingSession( ctx.getContactId(), ctx.getTransportId(), w.getMaxLatency(), w.getMaxIdleTime(), streamWriter); diff --git a/briar-core/src/org/briarproject/plugins/file/FilePlugin.java b/briar-core/src/org/briarproject/plugins/file/FilePlugin.java index a187760aafdfcce5dc7700c66c93ccd266af33ee..abaa6349256d34c3d8e663922f78e2d28e5b74dd 100644 --- a/briar-core/src/org/briarproject/plugins/file/FilePlugin.java +++ b/briar-core/src/org/briarproject/plugins/file/FilePlugin.java @@ -28,7 +28,7 @@ public abstract class FilePlugin implements SimplexPlugin { protected final Executor ioExecutor; protected final FileUtils fileUtils; protected final SimplexPluginCallback callback; - protected final int maxFrameLength, maxLatency; + protected final int maxLatency; protected volatile boolean running = false; @@ -38,19 +38,13 @@ public abstract class FilePlugin implements SimplexPlugin { protected abstract void readerFinished(File f); protected FilePlugin(Executor ioExecutor, FileUtils fileUtils, - SimplexPluginCallback callback, int maxFrameLength, - int maxLatency) { + SimplexPluginCallback callback, int maxLatency) { this.ioExecutor = ioExecutor; this.fileUtils = fileUtils; this.callback = callback; - this.maxFrameLength = maxFrameLength; this.maxLatency = maxLatency; } - public int getMaxFrameLength() { - return maxFrameLength; - } - public int getMaxLatency() { return maxLatency; } diff --git a/briar-core/src/org/briarproject/plugins/file/FileTransportReader.java b/briar-core/src/org/briarproject/plugins/file/FileTransportReader.java index 316773ec01270fc0b45282edd62a6b40785985e5..4c434faa621a94788ad9b0f3649fb61518081de3 100644 --- a/briar-core/src/org/briarproject/plugins/file/FileTransportReader.java +++ b/briar-core/src/org/briarproject/plugins/file/FileTransportReader.java @@ -24,10 +24,6 @@ class FileTransportReader implements TransportConnectionReader { this.plugin = plugin; } - public int getMaxFrameLength() { - return plugin.getMaxFrameLength(); - } - public long getMaxLatency() { return plugin.getMaxLatency(); } diff --git a/briar-core/src/org/briarproject/plugins/file/FileTransportWriter.java b/briar-core/src/org/briarproject/plugins/file/FileTransportWriter.java index c2ffcde0892b49a924165531a767f69901a11316..f9b14651e1e4a3ed8b4a3913faf3511f7795bd3d 100644 --- a/briar-core/src/org/briarproject/plugins/file/FileTransportWriter.java +++ b/briar-core/src/org/briarproject/plugins/file/FileTransportWriter.java @@ -27,10 +27,6 @@ class FileTransportWriter implements TransportConnectionWriter { this.plugin = plugin; } - public int getMaxFrameLength() { - return plugin.getMaxFrameLength(); - } - public int getMaxLatency() { return plugin.getMaxLatency(); } diff --git a/briar-core/src/org/briarproject/plugins/tcp/LanTcpPlugin.java b/briar-core/src/org/briarproject/plugins/tcp/LanTcpPlugin.java index 6f15c6fe81d5f0e1b51e8981e177c4e6967a036b..ea030c40ee629ed527a9393dc51fd04bb5a9a713 100644 --- a/briar-core/src/org/briarproject/plugins/tcp/LanTcpPlugin.java +++ b/briar-core/src/org/briarproject/plugins/tcp/LanTcpPlugin.java @@ -17,10 +17,8 @@ class LanTcpPlugin extends TcpPlugin { static final TransportId ID = new TransportId("lan"); LanTcpPlugin(Executor ioExecutor, DuplexPluginCallback callback, - int maxFrameLength, int maxLatency, int maxIdleTime, - int pollingInterval) { - super(ioExecutor, callback, maxFrameLength, maxLatency, maxIdleTime, - pollingInterval); + int maxLatency, int maxIdleTime, int pollingInterval) { + super(ioExecutor, callback, maxLatency, maxIdleTime, pollingInterval); } public TransportId getId() { diff --git a/briar-core/src/org/briarproject/plugins/tcp/LanTcpPluginFactory.java b/briar-core/src/org/briarproject/plugins/tcp/LanTcpPluginFactory.java index 8527df94137b60548894abc24be5541d62c6846e..68f2edc0e77aab769e242a3e63f4334376ac5083 100644 --- a/briar-core/src/org/briarproject/plugins/tcp/LanTcpPluginFactory.java +++ b/briar-core/src/org/briarproject/plugins/tcp/LanTcpPluginFactory.java @@ -9,7 +9,6 @@ import org.briarproject.api.plugins.duplex.DuplexPluginFactory; public class LanTcpPluginFactory implements DuplexPluginFactory { - private static final int MAX_FRAME_LENGTH = 1024; private static final int MAX_LATENCY = 30 * 1000; // 30 seconds private static final int MAX_IDLE_TIME = 30 * 1000; // 30 seconds private static final int POLLING_INTERVAL = 3 * 60 * 1000; // 3 minutes @@ -25,7 +24,7 @@ public class LanTcpPluginFactory implements DuplexPluginFactory { } public DuplexPlugin createPlugin(DuplexPluginCallback callback) { - return new LanTcpPlugin(ioExecutor, callback, MAX_FRAME_LENGTH, - MAX_LATENCY, MAX_IDLE_TIME, POLLING_INTERVAL); + return new LanTcpPlugin(ioExecutor, callback, MAX_LATENCY, + MAX_IDLE_TIME, POLLING_INTERVAL); } } diff --git a/briar-core/src/org/briarproject/plugins/tcp/TcpPlugin.java b/briar-core/src/org/briarproject/plugins/tcp/TcpPlugin.java index 0a4946b4824b777b449a6ca2c4805f6c68946caa..083f46598d04095aa9e3a094901462f3c421afef 100644 --- a/briar-core/src/org/briarproject/plugins/tcp/TcpPlugin.java +++ b/briar-core/src/org/briarproject/plugins/tcp/TcpPlugin.java @@ -37,8 +37,7 @@ abstract class TcpPlugin implements DuplexPlugin { protected final Executor ioExecutor; protected final DuplexPluginCallback callback; - protected final int maxFrameLength, maxLatency, maxIdleTime; - protected final int pollingInterval, socketTimeout; + protected final int maxLatency, maxIdleTime, pollingInterval, socketTimeout; protected volatile boolean running = false; protected volatile ServerSocket socket = null; @@ -53,11 +52,9 @@ abstract class TcpPlugin implements DuplexPlugin { protected abstract boolean isConnectable(InetSocketAddress remote); protected TcpPlugin(Executor ioExecutor, DuplexPluginCallback callback, - int maxFrameLength, int maxLatency, int maxIdleTime, - int pollingInterval) { + int maxLatency, int maxIdleTime, int pollingInterval) { this.ioExecutor = ioExecutor; this.callback = callback; - this.maxFrameLength = maxFrameLength; this.maxLatency = maxLatency; this.maxIdleTime = maxIdleTime; this.pollingInterval = pollingInterval; @@ -66,10 +63,6 @@ abstract class TcpPlugin implements DuplexPlugin { else socketTimeout = maxIdleTime * 2; } - public int getMaxFrameLength() { - return maxFrameLength; - } - public int getMaxLatency() { return maxLatency; } diff --git a/briar-core/src/org/briarproject/plugins/tcp/TcpTransportConnection.java b/briar-core/src/org/briarproject/plugins/tcp/TcpTransportConnection.java index fff4ee01b1d8f78758c78b4410a2a931a5896f16..aae3c53ba86ba2232d0f8313f0ce27983d058ea4 100644 --- a/briar-core/src/org/briarproject/plugins/tcp/TcpTransportConnection.java +++ b/briar-core/src/org/briarproject/plugins/tcp/TcpTransportConnection.java @@ -38,10 +38,6 @@ class TcpTransportConnection implements DuplexTransportConnection { private class Reader implements TransportConnectionReader { - public int getMaxFrameLength() { - return plugin.getMaxFrameLength(); - } - public long getMaxLatency() { return plugin.getMaxLatency(); } @@ -59,10 +55,6 @@ class TcpTransportConnection implements DuplexTransportConnection { private class Writer implements TransportConnectionWriter { - public int getMaxFrameLength() { - return plugin.getMaxFrameLength(); - } - public int getMaxLatency() { return plugin.getMaxLatency(); } diff --git a/briar-core/src/org/briarproject/plugins/tcp/WanTcpPlugin.java b/briar-core/src/org/briarproject/plugins/tcp/WanTcpPlugin.java index 67be0c72166d1293420b9e597957451a63b980e7..15a4dfde82ebfc8e4094decafecb92ad257915b5 100644 --- a/briar-core/src/org/briarproject/plugins/tcp/WanTcpPlugin.java +++ b/briar-core/src/org/briarproject/plugins/tcp/WanTcpPlugin.java @@ -21,10 +21,9 @@ class WanTcpPlugin extends TcpPlugin { private volatile MappingResult mappingResult; WanTcpPlugin(Executor ioExecutor, PortMapper portMapper, - DuplexPluginCallback callback, int maxFrameLength, int maxLatency, - int maxIdleTime, int pollingInterval) { - super(ioExecutor, callback, maxFrameLength, maxLatency, maxIdleTime, - pollingInterval); + DuplexPluginCallback callback, int maxLatency, int maxIdleTime, + int pollingInterval) { + super(ioExecutor, callback, maxLatency, maxIdleTime, pollingInterval); this.portMapper = portMapper; } diff --git a/briar-core/src/org/briarproject/plugins/tcp/WanTcpPluginFactory.java b/briar-core/src/org/briarproject/plugins/tcp/WanTcpPluginFactory.java index 8129661ffc65c5c2c8c431653339eea0f13559d1..bd326ebbc0e8281f47511ceae223cc536caaa25d 100644 --- a/briar-core/src/org/briarproject/plugins/tcp/WanTcpPluginFactory.java +++ b/briar-core/src/org/briarproject/plugins/tcp/WanTcpPluginFactory.java @@ -10,7 +10,6 @@ import org.briarproject.api.plugins.duplex.DuplexPluginFactory; public class WanTcpPluginFactory implements DuplexPluginFactory { - private static final int MAX_FRAME_LENGTH = 1024; private static final int MAX_LATENCY = 30 * 1000; // 30 seconds private static final int MAX_IDLE_TIME = 30 * 1000; // 30 seconds private static final int POLLING_INTERVAL = 5 * 60 * 1000; // 5 minutes @@ -30,7 +29,6 @@ public class WanTcpPluginFactory implements DuplexPluginFactory { public DuplexPlugin createPlugin(DuplexPluginCallback callback) { return new WanTcpPlugin(ioExecutor, new PortMapperImpl(shutdownManager), - callback, MAX_FRAME_LENGTH, MAX_LATENCY, MAX_IDLE_TIME, - POLLING_INTERVAL); + callback, MAX_LATENCY, MAX_IDLE_TIME, POLLING_INTERVAL); } } diff --git a/briar-core/src/org/briarproject/transport/StreamReaderFactoryImpl.java b/briar-core/src/org/briarproject/transport/StreamReaderFactoryImpl.java index daa4f2bb769f93d9da0664cb7b67e8b718ebc5e0..d066cacd4f6dcefe45ea1a5ad230f6c3fa03b87e 100644 --- a/briar-core/src/org/briarproject/transport/StreamReaderFactoryImpl.java +++ b/briar-core/src/org/briarproject/transport/StreamReaderFactoryImpl.java @@ -4,7 +4,6 @@ import java.io.InputStream; import javax.inject.Inject; -import org.briarproject.api.crypto.StreamDecrypter; import org.briarproject.api.crypto.StreamDecrypterFactory; import org.briarproject.api.transport.StreamContext; import org.briarproject.api.transport.StreamReaderFactory; @@ -18,18 +17,15 @@ class StreamReaderFactoryImpl implements StreamReaderFactory { this.streamDecrypterFactory = streamDecrypterFactory; } - public InputStream createStreamReader(InputStream in, int maxFrameLength, - StreamContext ctx) { - StreamDecrypter s = streamDecrypterFactory.createStreamDecrypter(in, - maxFrameLength, ctx); - return new StreamReaderImpl(s, maxFrameLength); + public InputStream createStreamReader(InputStream in, StreamContext ctx) { + return new StreamReaderImpl( + streamDecrypterFactory.createStreamDecrypter(in, ctx)); } public InputStream createInvitationStreamReader(InputStream in, - int maxFrameLength, byte[] secret, boolean alice) { - StreamDecrypter s = + byte[] secret, boolean alice) { + return new StreamReaderImpl( streamDecrypterFactory.createInvitationStreamDecrypter(in, - maxFrameLength, secret, alice); - return new StreamReaderImpl(s, maxFrameLength); + secret, alice)); } } diff --git a/briar-core/src/org/briarproject/transport/StreamReaderImpl.java b/briar-core/src/org/briarproject/transport/StreamReaderImpl.java index e9a30b24a96d5bd871087c49f4bcf5aef78b9ffc..f0a1a26c129c0af1e8dc45e0cd57fef3079bc40e 100644 --- a/briar-core/src/org/briarproject/transport/StreamReaderImpl.java +++ b/briar-core/src/org/briarproject/transport/StreamReaderImpl.java @@ -2,6 +2,7 @@ package org.briarproject.transport; 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.MAX_FRAME_LENGTH; import java.io.IOException; import java.io.InputStream; @@ -15,9 +16,9 @@ class StreamReaderImpl extends InputStream { private int offset = 0, length = 0; - StreamReaderImpl(StreamDecrypter decrypter, int frameLength) { + StreamReaderImpl(StreamDecrypter decrypter) { this.decrypter = decrypter; - payload = new byte[frameLength - HEADER_LENGTH - MAC_LENGTH]; + payload = new byte[MAX_FRAME_LENGTH - HEADER_LENGTH - MAC_LENGTH]; } @Override diff --git a/briar-core/src/org/briarproject/transport/StreamWriterFactoryImpl.java b/briar-core/src/org/briarproject/transport/StreamWriterFactoryImpl.java index f57a8f69bf96c413bbae7f88bbbf9ae5523b905f..89da3a46445d4dbed63895332179229562c38417 100644 --- a/briar-core/src/org/briarproject/transport/StreamWriterFactoryImpl.java +++ b/briar-core/src/org/briarproject/transport/StreamWriterFactoryImpl.java @@ -4,7 +4,6 @@ import java.io.OutputStream; import javax.inject.Inject; -import org.briarproject.api.crypto.StreamEncrypter; import org.briarproject.api.crypto.StreamEncrypterFactory; import org.briarproject.api.transport.StreamContext; import org.briarproject.api.transport.StreamWriterFactory; @@ -18,18 +17,16 @@ class StreamWriterFactoryImpl implements StreamWriterFactory { this.streamEncrypterFactory = streamEncrypterFactory; } - public OutputStream createStreamWriter(OutputStream out, int maxFrameLength, + public OutputStream createStreamWriter(OutputStream out, StreamContext ctx) { - StreamEncrypter s = streamEncrypterFactory.createStreamEncrypter(out, - maxFrameLength, ctx); - return new StreamWriterImpl(s, maxFrameLength); + return new StreamWriterImpl( + streamEncrypterFactory.createStreamEncrypter(out, ctx)); } public OutputStream createInvitationStreamWriter(OutputStream out, - int maxFrameLength, byte[] secret, boolean alice) { - StreamEncrypter s = + byte[] secret, boolean alice) { + return new StreamWriterImpl( streamEncrypterFactory.createInvitationStreamEncrypter(out, - maxFrameLength, secret, alice); - return new StreamWriterImpl(s, maxFrameLength); + secret, alice)); } } \ No newline at end of file diff --git a/briar-core/src/org/briarproject/transport/StreamWriterImpl.java b/briar-core/src/org/briarproject/transport/StreamWriterImpl.java index 05653fd42a4754b005d6b49e9e3b8617876a64ec..22384dd22bc644c139103a7f5e75417df287d59c 100644 --- a/briar-core/src/org/briarproject/transport/StreamWriterImpl.java +++ b/briar-core/src/org/briarproject/transport/StreamWriterImpl.java @@ -2,6 +2,7 @@ package org.briarproject.transport; 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.MAX_FRAME_LENGTH; import java.io.IOException; import java.io.OutputStream; @@ -22,9 +23,9 @@ class StreamWriterImpl extends OutputStream { private int length = 0; - StreamWriterImpl(StreamEncrypter encrypter, int maxFrameLength) { + StreamWriterImpl(StreamEncrypter encrypter) { this.encrypter = encrypter; - payload = new byte[maxFrameLength - HEADER_LENGTH - MAC_LENGTH]; + payload = new byte[MAX_FRAME_LENGTH - HEADER_LENGTH - MAC_LENGTH]; } @Override diff --git a/briar-desktop/src/org/briarproject/plugins/bluetooth/BluetoothPlugin.java b/briar-desktop/src/org/briarproject/plugins/bluetooth/BluetoothPlugin.java index be87193edb12fc4cd4a94116cc1e76ee22b84732..45dca315f2a2b6ad64e7f21cc20e1a6b721c0b16 100644 --- a/briar-desktop/src/org/briarproject/plugins/bluetooth/BluetoothPlugin.java +++ b/briar-desktop/src/org/briarproject/plugins/bluetooth/BluetoothPlugin.java @@ -46,7 +46,7 @@ class BluetoothPlugin implements DuplexPlugin { private final Clock clock; private final SecureRandom secureRandom; private final DuplexPluginCallback callback; - private final int maxFrameLength, maxLatency, pollingInterval; + private final int maxLatency, pollingInterval; private final Semaphore discoverySemaphore = new Semaphore(1); private volatile boolean running = false; @@ -54,13 +54,12 @@ class BluetoothPlugin implements DuplexPlugin { private volatile LocalDevice localDevice = null; BluetoothPlugin(Executor ioExecutor, Clock clock, SecureRandom secureRandom, - DuplexPluginCallback callback, int maxFrameLength, int maxLatency, + DuplexPluginCallback callback, int maxLatency, int pollingInterval) { this.ioExecutor = ioExecutor; this.clock = clock; this.secureRandom = secureRandom; this.callback = callback; - this.maxFrameLength = maxFrameLength; this.maxLatency = maxLatency; this.pollingInterval = pollingInterval; } @@ -69,10 +68,6 @@ class BluetoothPlugin implements DuplexPlugin { return ID; } - public int getMaxFrameLength() { - return maxFrameLength; - } - public int getMaxLatency() { return maxLatency; } diff --git a/briar-desktop/src/org/briarproject/plugins/bluetooth/BluetoothPluginFactory.java b/briar-desktop/src/org/briarproject/plugins/bluetooth/BluetoothPluginFactory.java index a25a73c3706b941595ac14818a2e10ccfe54a6fa..28859c4d7eae9e79ff42baf2081b70f71dafc809 100644 --- a/briar-desktop/src/org/briarproject/plugins/bluetooth/BluetoothPluginFactory.java +++ b/briar-desktop/src/org/briarproject/plugins/bluetooth/BluetoothPluginFactory.java @@ -12,7 +12,6 @@ import org.briarproject.system.SystemClock; public class BluetoothPluginFactory implements DuplexPluginFactory { - private static final int MAX_FRAME_LENGTH = 1024; private static final int MAX_LATENCY = 30 * 1000; // 30 seconds private static final int POLLING_INTERVAL = 3 * 60 * 1000; // 3 minutes @@ -33,6 +32,6 @@ public class BluetoothPluginFactory implements DuplexPluginFactory { public DuplexPlugin createPlugin(DuplexPluginCallback callback) { return new BluetoothPlugin(ioExecutor, clock, secureRandom, callback, - MAX_FRAME_LENGTH, MAX_LATENCY, POLLING_INTERVAL); + MAX_LATENCY, POLLING_INTERVAL); } } diff --git a/briar-desktop/src/org/briarproject/plugins/bluetooth/BluetoothTransportConnection.java b/briar-desktop/src/org/briarproject/plugins/bluetooth/BluetoothTransportConnection.java index 0767c42d9a045373e8f8138dd53eb0e81a8e7c50..8e70db480b0cfa70cdb256c110ffb5c275740a02 100644 --- a/briar-desktop/src/org/briarproject/plugins/bluetooth/BluetoothTransportConnection.java +++ b/briar-desktop/src/org/briarproject/plugins/bluetooth/BluetoothTransportConnection.java @@ -39,10 +39,6 @@ class BluetoothTransportConnection implements DuplexTransportConnection { private class Reader implements TransportConnectionReader { - public int getMaxFrameLength() { - return plugin.getMaxFrameLength(); - } - public long getMaxLatency() { return plugin.getMaxLatency(); } @@ -60,10 +56,6 @@ class BluetoothTransportConnection implements DuplexTransportConnection { private class Writer implements TransportConnectionWriter { - public int getMaxFrameLength() { - return plugin.getMaxFrameLength(); - } - public int getMaxLatency() { return plugin.getMaxLatency(); } diff --git a/briar-desktop/src/org/briarproject/plugins/file/RemovableDrivePlugin.java b/briar-desktop/src/org/briarproject/plugins/file/RemovableDrivePlugin.java index faaf4b01c4424a25470c5cc65a27b621d7519d6e..f648ff092c402c0df55d767838a64d92b22ef996 100644 --- a/briar-desktop/src/org/briarproject/plugins/file/RemovableDrivePlugin.java +++ b/briar-desktop/src/org/briarproject/plugins/file/RemovableDrivePlugin.java @@ -29,8 +29,8 @@ implements RemovableDriveMonitor.Callback { RemovableDrivePlugin(Executor ioExecutor, FileUtils fileUtils, SimplexPluginCallback callback, RemovableDriveFinder finder, - RemovableDriveMonitor monitor, int maxFrameLength, int maxLatency) { - super(ioExecutor, fileUtils, callback, maxFrameLength, maxLatency); + RemovableDriveMonitor monitor, int maxLatency) { + super(ioExecutor, fileUtils, callback, maxLatency); this.finder = finder; this.monitor = monitor; } diff --git a/briar-desktop/src/org/briarproject/plugins/file/RemovableDrivePluginFactory.java b/briar-desktop/src/org/briarproject/plugins/file/RemovableDrivePluginFactory.java index 4b7d6835fc95a019251d1aed1bb1a33b5416b1d6..68b1eaf31c8bb2a4e856f8f21b19b0705db99e66 100644 --- a/briar-desktop/src/org/briarproject/plugins/file/RemovableDrivePluginFactory.java +++ b/briar-desktop/src/org/briarproject/plugins/file/RemovableDrivePluginFactory.java @@ -1,7 +1,5 @@ package org.briarproject.plugins.file; -import static org.briarproject.api.transport.TransportConstants.MAX_FRAME_LENGTH; - import java.util.concurrent.Executor; import org.briarproject.api.TransportId; @@ -52,6 +50,6 @@ public class RemovableDrivePluginFactory implements SimplexPluginFactory { return null; } return new RemovableDrivePlugin(ioExecutor, fileUtils, callback, - finder, monitor, MAX_FRAME_LENGTH, MAX_LATENCY); + finder, monitor, MAX_LATENCY); } } diff --git a/briar-desktop/src/org/briarproject/plugins/modem/ModemPlugin.java b/briar-desktop/src/org/briarproject/plugins/modem/ModemPlugin.java index 092eeec8baa45406ecb42548dd50b1e00e1b206e..b0a58969cb6ccb1a533994b7640c5e00f8a81ad8 100644 --- a/briar-desktop/src/org/briarproject/plugins/modem/ModemPlugin.java +++ b/briar-desktop/src/org/briarproject/plugins/modem/ModemPlugin.java @@ -32,17 +32,16 @@ class ModemPlugin implements DuplexPlugin, Modem.Callback { private final ModemFactory modemFactory; private final SerialPortList serialPortList; private final DuplexPluginCallback callback; - private final int maxFrameLength, maxLatency; + private final int maxLatency; private volatile boolean running = false; private volatile Modem modem = null; ModemPlugin(ModemFactory modemFactory, SerialPortList serialPortList, - DuplexPluginCallback callback, int maxFrameLength, int maxLatency) { + DuplexPluginCallback callback, int maxLatency) { this.modemFactory = modemFactory; this.serialPortList = serialPortList; this.callback = callback; - this.maxFrameLength = maxFrameLength; this.maxLatency = maxLatency; } @@ -50,10 +49,6 @@ class ModemPlugin implements DuplexPlugin, Modem.Callback { return ID; } - public int getMaxFrameLength() { - return maxFrameLength; - } - public int getMaxLatency() { return maxLatency; } @@ -199,10 +194,6 @@ class ModemPlugin implements DuplexPlugin, Modem.Callback { private class Reader implements TransportConnectionReader { - public int getMaxFrameLength() { - return maxFrameLength; - } - public long getMaxLatency() { return maxLatency; } @@ -219,10 +210,6 @@ class ModemPlugin implements DuplexPlugin, Modem.Callback { private class Writer implements TransportConnectionWriter { - public int getMaxFrameLength() { - return getMaxFrameLength(); - } - public int getMaxLatency() { return getMaxLatency(); } diff --git a/briar-desktop/src/org/briarproject/plugins/modem/ModemPluginFactory.java b/briar-desktop/src/org/briarproject/plugins/modem/ModemPluginFactory.java index 670be76fcacc8c92cb46309ccea5179ba81f9801..f70fc3be712fc4a5ca32cd415b0aadadd8177a05 100644 --- a/briar-desktop/src/org/briarproject/plugins/modem/ModemPluginFactory.java +++ b/briar-desktop/src/org/briarproject/plugins/modem/ModemPluginFactory.java @@ -11,7 +11,6 @@ import org.briarproject.util.StringUtils; public class ModemPluginFactory implements DuplexPluginFactory { - private static final int MAX_FRAME_LENGTH = 1024; private static final int MAX_LATENCY = 30 * 1000; // 30 seconds private final ModemFactory modemFactory; @@ -32,6 +31,6 @@ public class ModemPluginFactory implements DuplexPluginFactory { String enabled = callback.getConfig().get("enabled"); if(StringUtils.isNullOrEmpty(enabled)) return null; return new ModemPlugin(modemFactory, serialPortList, callback, - MAX_FRAME_LENGTH, MAX_LATENCY); + MAX_LATENCY); } } diff --git a/briar-tests/src/org/briarproject/ProtocolIntegrationTest.java b/briar-tests/src/org/briarproject/ProtocolIntegrationTest.java index cfd5af2d57e179779eeea1b2fa133a09e5f98e71..633a4929ad23c580685f96f2a63cbc05d20682ca 100644 --- a/briar-tests/src/org/briarproject/ProtocolIntegrationTest.java +++ b/briar-tests/src/org/briarproject/ProtocolIntegrationTest.java @@ -1,6 +1,5 @@ package org.briarproject; -import static org.briarproject.api.transport.TransportConstants.MAX_FRAME_LENGTH; import static org.briarproject.api.transport.TransportConstants.TAG_LENGTH; import static org.junit.Assert.assertArrayEquals; @@ -118,8 +117,8 @@ public class ProtocolIntegrationTest extends BriarTestCase { ByteArrayOutputStream out = new ByteArrayOutputStream(); StreamContext ctx = new StreamContext(contactId, transportId, secret, 0, true); - OutputStream streamWriter = streamWriterFactory.createStreamWriter(out, - MAX_FRAME_LENGTH, ctx); + OutputStream streamWriter = + streamWriterFactory.createStreamWriter(out, ctx); PacketWriter packetWriter = packetWriterFactory.createPacketWriter( streamWriter); @@ -150,8 +149,8 @@ public class ProtocolIntegrationTest extends BriarTestCase { // FIXME: Check that the expected tag was received StreamContext ctx = new StreamContext(contactId, transportId, secret, 0, false); - InputStream streamReader = streamReaderFactory.createStreamReader(in, - MAX_FRAME_LENGTH, ctx); + InputStream streamReader = + streamReaderFactory.createStreamReader(in, ctx); PacketReader packetReader = packetReaderFactory.createPacketReader( streamReader); diff --git a/briar-tests/src/org/briarproject/crypto/StreamDecrypterImplTest.java b/briar-tests/src/org/briarproject/crypto/StreamDecrypterImplTest.java index 1ee05436a6af717656b71924aa968d8697ea4307..b0b5f239a538564a0cd4e1e36292e4ecf39627fb 100644 --- a/briar-tests/src/org/briarproject/crypto/StreamDecrypterImplTest.java +++ b/briar-tests/src/org/briarproject/crypto/StreamDecrypterImplTest.java @@ -4,6 +4,7 @@ import static org.briarproject.api.transport.TransportConstants.AAD_LENGTH; import static org.briarproject.api.transport.TransportConstants.HEADER_LENGTH; 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.MAX_FRAME_LENGTH; import java.io.ByteArrayInputStream; @@ -14,6 +15,7 @@ import org.briarproject.api.FormatException; import org.briarproject.api.crypto.AuthenticatedCipher; import org.briarproject.api.crypto.CryptoComponent; import org.briarproject.api.crypto.SecretKey; +import org.briarproject.util.ByteUtils; import org.junit.Test; import com.google.inject.Guice; @@ -23,9 +25,8 @@ public class StreamDecrypterImplTest extends BriarTestCase { // FIXME: This is an integration test, not a unit test - private static final int FRAME_LENGTH = 1024; private static final int MAX_PAYLOAD_LENGTH = - FRAME_LENGTH - HEADER_LENGTH - MAC_LENGTH; + MAX_FRAME_LENGTH - HEADER_LENGTH - MAC_LENGTH; private final CryptoComponent crypto; private final AuthenticatedCipher frameCipher; @@ -42,16 +43,16 @@ public class StreamDecrypterImplTest extends BriarTestCase { @Test public void testReadValidFrames() throws Exception { // Generate two valid frames - byte[] frame = generateFrame(0, FRAME_LENGTH, 123, false, false); - byte[] frame1 = generateFrame(1, FRAME_LENGTH, 123, false, false); + byte[] frame = generateFrame(0, MAX_FRAME_LENGTH, 123, false, false); + byte[] frame1 = generateFrame(1, MAX_FRAME_LENGTH, 123, false, false); // Concatenate the frames - byte[] valid = new byte[FRAME_LENGTH * 2]; - System.arraycopy(frame, 0, valid, 0, FRAME_LENGTH); - System.arraycopy(frame1, 0, valid, FRAME_LENGTH, FRAME_LENGTH); + byte[] valid = new byte[MAX_FRAME_LENGTH * 2]; + System.arraycopy(frame, 0, valid, 0, MAX_FRAME_LENGTH); + System.arraycopy(frame1, 0, valid, MAX_FRAME_LENGTH, MAX_FRAME_LENGTH); // Read the frames ByteArrayInputStream in = new ByteArrayInputStream(valid); StreamDecrypterImpl i = new StreamDecrypterImpl(in, frameCipher, - frameKey, FRAME_LENGTH); + frameKey); byte[] payload = new byte[MAX_PAYLOAD_LENGTH]; assertEquals(123, i.readFrame(payload)); assertEquals(123, i.readFrame(payload)); @@ -60,14 +61,14 @@ public class StreamDecrypterImplTest extends BriarTestCase { @Test public void testTruncatedFrameThrowsException() throws Exception { // Generate a valid frame - byte[] frame = generateFrame(0, FRAME_LENGTH, 123, false, false); + byte[] frame = generateFrame(0, MAX_FRAME_LENGTH, 123, false, false); // Chop off the last byte - byte[] truncated = new byte[FRAME_LENGTH - 1]; - System.arraycopy(frame, 0, truncated, 0, FRAME_LENGTH - 1); + byte[] truncated = new byte[MAX_FRAME_LENGTH - 1]; + System.arraycopy(frame, 0, truncated, 0, MAX_FRAME_LENGTH - 1); // Try to read the frame, which should fail due to truncation ByteArrayInputStream in = new ByteArrayInputStream(truncated); StreamDecrypterImpl i = new StreamDecrypterImpl(in, frameCipher, - frameKey, FRAME_LENGTH); + frameKey); try { i.readFrame(new byte[MAX_PAYLOAD_LENGTH]); fail(); @@ -77,13 +78,13 @@ public class StreamDecrypterImplTest extends BriarTestCase { @Test public void testModifiedFrameThrowsException() throws Exception { // Generate a valid frame - byte[] frame = generateFrame(0, FRAME_LENGTH, 123, false, false); + byte[] frame = generateFrame(0, MAX_FRAME_LENGTH, 123, false, false); // Modify a randomly chosen byte of the frame - frame[(int) (Math.random() * FRAME_LENGTH)] ^= 1; + frame[(int) (Math.random() * MAX_FRAME_LENGTH)] ^= 1; // Try to read the frame, which should fail due to modification ByteArrayInputStream in = new ByteArrayInputStream(frame); StreamDecrypterImpl i = new StreamDecrypterImpl(in, frameCipher, - frameKey, FRAME_LENGTH); + frameKey); try { i.readFrame(new byte[MAX_PAYLOAD_LENGTH]); fail(); @@ -93,11 +94,12 @@ public class StreamDecrypterImplTest extends BriarTestCase { @Test public void testShortNonFinalFrameThrowsException() throws Exception { // Generate a short non-final frame - byte[] frame = generateFrame(0, FRAME_LENGTH - 1, 123, false, false); + byte[] frame = generateFrame(0, MAX_FRAME_LENGTH - 1, 123, false, + false); // Try to read the frame, which should fail due to invalid length ByteArrayInputStream in = new ByteArrayInputStream(frame); StreamDecrypterImpl i = new StreamDecrypterImpl(in, frameCipher, - frameKey, FRAME_LENGTH); + frameKey); try { i.readFrame(new byte[MAX_PAYLOAD_LENGTH]); fail(); @@ -107,11 +109,11 @@ public class StreamDecrypterImplTest extends BriarTestCase { @Test public void testShortFinalFrameDoesNotThrowException() throws Exception { // Generate a short final frame - byte[] frame = generateFrame(0, FRAME_LENGTH - 1, 123, true, false); + byte[] frame = generateFrame(0, MAX_FRAME_LENGTH - 1, 123, true, false); // Read the frame ByteArrayInputStream in = new ByteArrayInputStream(frame); StreamDecrypterImpl i = new StreamDecrypterImpl(in, frameCipher, - frameKey, FRAME_LENGTH); + frameKey); int length = i.readFrame(new byte[MAX_PAYLOAD_LENGTH]); assertEquals(123, length); } @@ -119,12 +121,12 @@ public class StreamDecrypterImplTest extends BriarTestCase { @Test public void testInvalidPayloadLengthThrowsException() throws Exception { // Generate a frame with an invalid payload length - byte[] frame = generateFrame(0, FRAME_LENGTH, MAX_PAYLOAD_LENGTH + 1, - false, false); + byte[] frame = generateFrame(0, MAX_FRAME_LENGTH, 123, false, false); + ByteUtils.writeUint16(MAX_PAYLOAD_LENGTH + 1, frame, 0); // Try to read the frame, which should fail due to invalid length ByteArrayInputStream in = new ByteArrayInputStream(frame); StreamDecrypterImpl i = new StreamDecrypterImpl(in, frameCipher, - frameKey, FRAME_LENGTH); + frameKey); try { i.readFrame(new byte[MAX_PAYLOAD_LENGTH]); fail(); @@ -134,11 +136,11 @@ public class StreamDecrypterImplTest extends BriarTestCase { @Test public void testNonZeroPaddingThrowsException() throws Exception { // Generate a frame with bad padding - byte[] frame = generateFrame(0, FRAME_LENGTH, 123, false, true); + byte[] frame = generateFrame(0, MAX_FRAME_LENGTH, 123, false, true); // Try to read the frame, which should fail due to bad padding ByteArrayInputStream in = new ByteArrayInputStream(frame); StreamDecrypterImpl i = new StreamDecrypterImpl(in, frameCipher, - frameKey, FRAME_LENGTH); + frameKey); try { i.readFrame(new byte[MAX_PAYLOAD_LENGTH]); fail(); @@ -148,17 +150,18 @@ public class StreamDecrypterImplTest extends BriarTestCase { @Test public void testCannotReadBeyondFinalFrame() throws Exception { // Generate a valid final frame and another valid final frame after it - byte[] frame = generateFrame(0, FRAME_LENGTH, MAX_PAYLOAD_LENGTH, true, - false); - byte[] frame1 = generateFrame(1, FRAME_LENGTH, 123, true, false); + byte[] frame = generateFrame(0, MAX_FRAME_LENGTH, MAX_PAYLOAD_LENGTH, + true, false); + byte[] frame1 = generateFrame(1, MAX_FRAME_LENGTH, 123, true, false); // Concatenate the frames - byte[] extraFrame = new byte[FRAME_LENGTH * 2]; - System.arraycopy(frame, 0, extraFrame, 0, FRAME_LENGTH); - System.arraycopy(frame1, 0, extraFrame, FRAME_LENGTH, FRAME_LENGTH); + byte[] extraFrame = new byte[MAX_FRAME_LENGTH * 2]; + System.arraycopy(frame, 0, extraFrame, 0, MAX_FRAME_LENGTH); + System.arraycopy(frame1, 0, extraFrame, MAX_FRAME_LENGTH, + MAX_FRAME_LENGTH); // Read the final frame, which should first read the tag ByteArrayInputStream in = new ByteArrayInputStream(extraFrame); StreamDecrypterImpl i = new StreamDecrypterImpl(in, frameCipher, - frameKey, FRAME_LENGTH); + frameKey); byte[] payload = new byte[MAX_PAYLOAD_LENGTH]; assertEquals(MAX_PAYLOAD_LENGTH, i.readFrame(payload)); // The frame after the final frame should not be read diff --git a/briar-tests/src/org/briarproject/crypto/StreamEncrypterImplTest.java b/briar-tests/src/org/briarproject/crypto/StreamEncrypterImplTest.java index d4f8b33a5b767f1fb128594fc551884ef2808145..8b5c3d74c8052234462255edfa9b5aceaf0d502f 100644 --- a/briar-tests/src/org/briarproject/crypto/StreamEncrypterImplTest.java +++ b/briar-tests/src/org/briarproject/crypto/StreamEncrypterImplTest.java @@ -4,6 +4,7 @@ import static org.briarproject.api.transport.TransportConstants.AAD_LENGTH; import static org.briarproject.api.transport.TransportConstants.HEADER_LENGTH; 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.MAX_FRAME_LENGTH; import static org.briarproject.api.transport.TransportConstants.TAG_LENGTH; import java.io.ByteArrayOutputStream; @@ -24,8 +25,6 @@ public class StreamEncrypterImplTest extends BriarTestCase { // FIXME: This is an integration test, not a unit test - private static final int FRAME_LENGTH = 1024; - private final CryptoComponent crypto; private final AuthenticatedCipher frameCipher; @@ -40,8 +39,8 @@ public class StreamEncrypterImplTest extends BriarTestCase { public void testEncryptionWithoutTag() throws Exception { int payloadLength = 123; byte[] iv = new byte[IV_LENGTH], aad = new byte[AAD_LENGTH]; - byte[] plaintext = new byte[FRAME_LENGTH - MAC_LENGTH]; - byte[] ciphertext = new byte[FRAME_LENGTH]; + byte[] plaintext = new byte[MAX_FRAME_LENGTH - MAC_LENGTH]; + byte[] ciphertext = new byte[MAX_FRAME_LENGTH]; SecretKey frameKey = crypto.generateSecretKey(); // Calculate the expected ciphertext FrameEncoder.encodeIv(iv, 0); @@ -51,12 +50,12 @@ public class StreamEncrypterImplTest extends BriarTestCase { frameCipher.doFinal(plaintext, 0, plaintext.length, ciphertext, 0); // Check that the actual ciphertext matches what's expected ByteArrayOutputStream out = new ByteArrayOutputStream(); - StreamEncrypterImpl o = new StreamEncrypterImpl(out, - frameCipher, frameKey, FRAME_LENGTH, null); + StreamEncrypterImpl o = new StreamEncrypterImpl(out, frameCipher, + frameKey, null); o.writeFrame(new byte[payloadLength], payloadLength, false); byte[] actual = out.toByteArray(); - assertEquals(FRAME_LENGTH, actual.length); - for(int i = 0; i < FRAME_LENGTH; i++) + assertEquals(MAX_FRAME_LENGTH, actual.length); + for(int i = 0; i < MAX_FRAME_LENGTH; i++) assertEquals(ciphertext[i], actual[i]); } @@ -66,8 +65,8 @@ public class StreamEncrypterImplTest extends BriarTestCase { new Random().nextBytes(tag); int payloadLength = 123; byte[] iv = new byte[IV_LENGTH], aad = new byte[AAD_LENGTH]; - byte[] plaintext = new byte[FRAME_LENGTH - MAC_LENGTH]; - byte[] ciphertext = new byte[FRAME_LENGTH]; + byte[] plaintext = new byte[MAX_FRAME_LENGTH - MAC_LENGTH]; + byte[] ciphertext = new byte[MAX_FRAME_LENGTH]; SecretKey frameKey = crypto.generateSecretKey(); // Calculate the expected ciphertext FrameEncoder.encodeIv(iv, 0); @@ -77,13 +76,13 @@ public class StreamEncrypterImplTest extends BriarTestCase { frameCipher.doFinal(plaintext, 0, plaintext.length, ciphertext, 0); // Check that the actual tag and ciphertext match what's expected ByteArrayOutputStream out = new ByteArrayOutputStream(); - StreamEncrypterImpl o = new StreamEncrypterImpl(out, - frameCipher, frameKey, FRAME_LENGTH, tag); + StreamEncrypterImpl o = new StreamEncrypterImpl(out, frameCipher, + frameKey, tag); o.writeFrame(new byte[payloadLength], payloadLength, false); byte[] actual = out.toByteArray(); - assertEquals(TAG_LENGTH + FRAME_LENGTH, actual.length); + assertEquals(TAG_LENGTH + MAX_FRAME_LENGTH, actual.length); for(int i = 0; i < TAG_LENGTH; i++) assertEquals(tag[i], actual[i]); - for(int i = 0; i < FRAME_LENGTH; i++) + for(int i = 0; i < MAX_FRAME_LENGTH; i++) assertEquals(ciphertext[i], actual[TAG_LENGTH + i]); } @@ -93,10 +92,10 @@ public class StreamEncrypterImplTest extends BriarTestCase { new Random().nextBytes(tag); ByteArrayOutputStream out = new ByteArrayOutputStream(); // Initiator's constructor - StreamEncrypterImpl o = new StreamEncrypterImpl(out, - frameCipher, crypto.generateSecretKey(), FRAME_LENGTH, tag); + StreamEncrypterImpl o = new StreamEncrypterImpl(out, frameCipher, + crypto.generateSecretKey(), tag); // Write an empty final frame without having written any other frames - o.writeFrame(new byte[FRAME_LENGTH - MAC_LENGTH], 0, true); + o.writeFrame(new byte[MAX_FRAME_LENGTH - MAC_LENGTH], 0, true); // The tag and the empty frame should be written to the output stream assertEquals(TAG_LENGTH + HEADER_LENGTH + MAC_LENGTH, out.size()); } diff --git a/briar-tests/src/org/briarproject/messaging/SimplexMessagingIntegrationTest.java b/briar-tests/src/org/briarproject/messaging/SimplexMessagingIntegrationTest.java index d0a8359af4da6399c71cbbeb3b5acbbdc493552f..75583607001c8e619b3dd5771deb991acec71b8a 100644 --- a/briar-tests/src/org/briarproject/messaging/SimplexMessagingIntegrationTest.java +++ b/briar-tests/src/org/briarproject/messaging/SimplexMessagingIntegrationTest.java @@ -3,7 +3,6 @@ package org.briarproject.messaging; import static org.briarproject.api.AuthorConstants.MAX_PUBLIC_KEY_LENGTH; import static org.briarproject.api.messaging.MessagingConstants.GROUP_SALT_LENGTH; import static org.briarproject.api.transport.TransportConstants.MAX_CLOCK_DIFFERENCE; -import static org.briarproject.api.transport.TransportConstants.MAX_FRAME_LENGTH; import static org.briarproject.api.transport.TransportConstants.TAG_LENGTH; import java.io.ByteArrayInputStream; @@ -143,8 +142,8 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase { ByteArrayOutputStream out = new ByteArrayOutputStream(); StreamWriterFactory streamWriterFactory = alice.getInstance(StreamWriterFactory.class); - OutputStream streamWriter = streamWriterFactory.createStreamWriter(out, - MAX_FRAME_LENGTH, ctx); + OutputStream streamWriter = + streamWriterFactory.createStreamWriter(out, ctx); // Create an outgoing messaging session EventBus eventBus = alice.getInstance(EventBus.class); PacketWriterFactory packetWriterFactory = @@ -205,8 +204,8 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase { // Create a stream reader StreamReaderFactory streamReaderFactory = bob.getInstance(StreamReaderFactory.class); - InputStream streamReader = streamReaderFactory.createStreamReader(in, - MAX_FRAME_LENGTH, ctx); + InputStream streamReader = + streamReaderFactory.createStreamReader(in, ctx); // Create an incoming messaging session EventBus eventBus = bob.getInstance(EventBus.class); MessageVerifier messageVerifier = diff --git a/briar-tests/src/org/briarproject/plugins/bluetooth/BluetoothClientTest.java b/briar-tests/src/org/briarproject/plugins/bluetooth/BluetoothClientTest.java index 3b86da8a1bd3a8f80c79445f80d14082261921c9..b046f3a6bc615862785b3c9c564c45342fd25bdd 100644 --- a/briar-tests/src/org/briarproject/plugins/bluetooth/BluetoothClientTest.java +++ b/briar-tests/src/org/briarproject/plugins/bluetooth/BluetoothClientTest.java @@ -23,12 +23,12 @@ public class BluetoothClientTest extends DuplexClientTest { p.put("address", serverAddress); p.put("uuid", BluetoothTest.EMPTY_UUID); Map<ContactId, TransportProperties> remote = - Collections.singletonMap(contactId, p); + Collections.singletonMap(contactId, p); // Create the plugin callback = new ClientCallback(new TransportConfig(), new TransportProperties(), remote); plugin = new BluetoothPlugin(executor, new SystemClock(), - new SecureRandom(), callback, 0, 0, 0); + new SecureRandom(), callback, 0, 0); } public static void main(String[] args) throws Exception { diff --git a/briar-tests/src/org/briarproject/plugins/bluetooth/BluetoothServerTest.java b/briar-tests/src/org/briarproject/plugins/bluetooth/BluetoothServerTest.java index 1dfbf841dcc52f64bf50f2e94e2d5a5422186c8a..121f71b4031db95c9a114cc1540e7397e565f405 100644 --- a/briar-tests/src/org/briarproject/plugins/bluetooth/BluetoothServerTest.java +++ b/briar-tests/src/org/briarproject/plugins/bluetooth/BluetoothServerTest.java @@ -23,7 +23,7 @@ public class BluetoothServerTest extends DuplexServerTest { callback = new ServerCallback(new TransportConfig(), local, Collections.singletonMap(contactId, new TransportProperties())); plugin = new BluetoothPlugin(executor, new SystemClock(), - new SecureRandom(), callback, 0, 0, 0); + new SecureRandom(), callback, 0, 0); } public static void main(String[] args) throws Exception { diff --git a/briar-tests/src/org/briarproject/plugins/file/RemovableDrivePluginTest.java b/briar-tests/src/org/briarproject/plugins/file/RemovableDrivePluginTest.java index b8e4ee88b24ac4fe00e2a7babdb3c973d32f465e..5ae0bbb5030235a60ebb45aa0e05fb146155a34a 100644 --- a/briar-tests/src/org/briarproject/plugins/file/RemovableDrivePluginTest.java +++ b/briar-tests/src/org/briarproject/plugins/file/RemovableDrivePluginTest.java @@ -1,6 +1,5 @@ package org.briarproject.plugins.file; -import static org.briarproject.api.transport.TransportConstants.MAX_FRAME_LENGTH; import static org.briarproject.api.transport.TransportConstants.MIN_STREAM_LENGTH; import java.io.File; @@ -58,7 +57,7 @@ public class RemovableDrivePluginTest extends BriarTestCase { }}); RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor, - fileUtils, callback, finder, monitor, MAX_FRAME_LENGTH, 0); + fileUtils, callback, finder, monitor, 0); plugin.start(); assertNull(plugin.createWriter(contactId)); @@ -93,7 +92,7 @@ public class RemovableDrivePluginTest extends BriarTestCase { }}); RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor, - fileUtils, callback, finder, monitor, MAX_FRAME_LENGTH, 0); + fileUtils, callback, finder, monitor, 0); plugin.start(); assertNull(plugin.createWriter(contactId)); @@ -130,7 +129,7 @@ public class RemovableDrivePluginTest extends BriarTestCase { }}); RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor, - fileUtils, callback, finder, monitor, MAX_FRAME_LENGTH, 0); + fileUtils, callback, finder, monitor, 0); plugin.start(); assertNull(plugin.createWriter(contactId)); @@ -169,7 +168,7 @@ public class RemovableDrivePluginTest extends BriarTestCase { }}); RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor, - fileUtils, callback, finder, monitor, MAX_FRAME_LENGTH, 0); + fileUtils, callback, finder, monitor, 0); plugin.start(); assertNull(plugin.createWriter(contactId)); @@ -208,7 +207,7 @@ public class RemovableDrivePluginTest extends BriarTestCase { }}); RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor, - fileUtils, callback, finder, monitor, MAX_FRAME_LENGTH, 0); + fileUtils, callback, finder, monitor, 0); plugin.start(); assertNotNull(plugin.createWriter(contactId)); @@ -251,7 +250,7 @@ public class RemovableDrivePluginTest extends BriarTestCase { }}); RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor, - fileUtils, callback, finder, monitor, MAX_FRAME_LENGTH, 0); + fileUtils, callback, finder, monitor, 0); plugin.start(); TransportConnectionWriter writer = plugin.createWriter(contactId); @@ -290,7 +289,7 @@ public class RemovableDrivePluginTest extends BriarTestCase { }}); RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor, - fileUtils, callback, finder, monitor, MAX_FRAME_LENGTH, 0); + fileUtils, callback, finder, monitor, 0); plugin.start(); plugin.driveInserted(testDir); @@ -310,7 +309,7 @@ public class RemovableDrivePluginTest extends BriarTestCase { context.mock(RemovableDriveMonitor.class); RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor, - fileUtils, callback, finder, monitor, MAX_FRAME_LENGTH, 0); + fileUtils, callback, finder, monitor, 0); assertFalse(plugin.isPossibleConnectionFilename("abcdefg.dat")); assertFalse(plugin.isPossibleConnectionFilename("abcdefghi.dat")); @@ -339,7 +338,7 @@ public class RemovableDrivePluginTest extends BriarTestCase { RemovableDrivePlugin plugin = new RemovableDrivePlugin( new ImmediateExecutor(), fileUtils, callback, finder, monitor, - MAX_FRAME_LENGTH, 0); + 0); plugin.start(); File f = new File(testDir, "abcdefgh.dat"); diff --git a/briar-tests/src/org/briarproject/plugins/modem/ModemPluginTest.java b/briar-tests/src/org/briarproject/plugins/modem/ModemPluginTest.java index 3aa5dab235858e3c1295873284ed2b1f52e977f3..7966ef8c489d4de3d23f7a11786a1f6ad4f6e702 100644 --- a/briar-tests/src/org/briarproject/plugins/modem/ModemPluginTest.java +++ b/briar-tests/src/org/briarproject/plugins/modem/ModemPluginTest.java @@ -24,7 +24,7 @@ public class ModemPluginTest extends BriarTestCase { final SerialPortList serialPortList = context.mock(SerialPortList.class); final ModemPlugin plugin = new ModemPlugin(modemFactory, - serialPortList, null, 0, 0); + serialPortList, null, 0); final Modem modem = context.mock(Modem.class); context.checking(new Expectations() {{ oneOf(serialPortList).getPortNames(); @@ -58,7 +58,7 @@ public class ModemPluginTest extends BriarTestCase { final DuplexPluginCallback callback = context.mock(DuplexPluginCallback.class); final ModemPlugin plugin = new ModemPlugin(modemFactory, - serialPortList, callback, 0, 0); + serialPortList, callback, 0); final Modem modem = context.mock(Modem.class); final TransportProperties local = new TransportProperties(); local.put("iso3166", ISO_1336); @@ -99,7 +99,7 @@ public class ModemPluginTest extends BriarTestCase { final DuplexPluginCallback callback = context.mock(DuplexPluginCallback.class); final ModemPlugin plugin = new ModemPlugin(modemFactory, - serialPortList, callback, 0, 0); + serialPortList, callback, 0); final Modem modem = context.mock(Modem.class); final TransportProperties local = new TransportProperties(); local.put("iso3166", ISO_1336); @@ -140,7 +140,7 @@ public class ModemPluginTest extends BriarTestCase { final DuplexPluginCallback callback = context.mock(DuplexPluginCallback.class); final ModemPlugin plugin = new ModemPlugin(modemFactory, - serialPortList, callback, 0, 0); + serialPortList, callback, 0); final Modem modem = context.mock(Modem.class); final TransportProperties local = new TransportProperties(); local.put("iso3166", ISO_1336); diff --git a/briar-tests/src/org/briarproject/plugins/tcp/LanTcpClientTest.java b/briar-tests/src/org/briarproject/plugins/tcp/LanTcpClientTest.java index 3bf190ee8130118d23fd21b048ab8b7125f3272a..19168a5675aec21ec229602734a213081ac41285 100644 --- a/briar-tests/src/org/briarproject/plugins/tcp/LanTcpClientTest.java +++ b/briar-tests/src/org/briarproject/plugins/tcp/LanTcpClientTest.java @@ -15,7 +15,6 @@ import org.briarproject.plugins.DuplexClientTest; // is running on another machine public class LanTcpClientTest extends DuplexClientTest { - private static final int MAX_FRAME_LENGTH = 1024; private static final int MAX_LATENCY = 60 * 1000; private static final int MAX_IDLE_TIME = 30 * 1000; private static final int POLLING_INTERVAL = 60 * 1000; @@ -31,8 +30,8 @@ public class LanTcpClientTest extends DuplexClientTest { // Create the plugin callback = new ClientCallback(new TransportConfig(), new TransportProperties(), remote); - plugin = new LanTcpPlugin(executor, callback, MAX_FRAME_LENGTH, - MAX_LATENCY, MAX_IDLE_TIME, POLLING_INTERVAL); + plugin = new LanTcpPlugin(executor, callback, MAX_LATENCY, + MAX_IDLE_TIME, POLLING_INTERVAL); } public static void main(String[] args) throws Exception { diff --git a/briar-tests/src/org/briarproject/plugins/tcp/LanTcpPluginTest.java b/briar-tests/src/org/briarproject/plugins/tcp/LanTcpPluginTest.java index c65fe2f96ea3e0a357f6228436fb2ddb4e8c3d9a..f3a321bbcc0242b84c137c9e2cce7512c795c9a8 100644 --- a/briar-tests/src/org/briarproject/plugins/tcp/LanTcpPluginTest.java +++ b/briar-tests/src/org/briarproject/plugins/tcp/LanTcpPluginTest.java @@ -32,7 +32,7 @@ public class LanTcpPluginTest extends BriarTestCase { @Test public void testAddressesAreOnSameLan() { - LanTcpPlugin plugin = new LanTcpPlugin(null, null, 0, 0, 0, 0); + LanTcpPlugin plugin = new LanTcpPlugin(null, null, 0, 0, 0); // Local and remote in 10.0.0.0/8 should return true assertTrue(plugin.addressesAreOnSameLan(makeAddress(10, 0, 0, 0), makeAddress(10, 255, 255, 255))); @@ -81,7 +81,7 @@ public class LanTcpPluginTest extends BriarTestCase { } Callback callback = new Callback(); Executor executor = Executors.newCachedThreadPool(); - DuplexPlugin plugin = new LanTcpPlugin(executor, callback, 0, 0, 0, 0); + DuplexPlugin plugin = new LanTcpPlugin(executor, callback, 0, 0, 0); plugin.start(); // The plugin should have bound a socket and stored the port number assertTrue(callback.propertiesLatch.await(5, SECONDS)); @@ -113,7 +113,7 @@ public class LanTcpPluginTest extends BriarTestCase { } Callback callback = new Callback(); Executor executor = Executors.newCachedThreadPool(); - DuplexPlugin plugin = new LanTcpPlugin(executor, callback, 0, 0, 0, 0); + DuplexPlugin plugin = new LanTcpPlugin(executor, callback, 0, 0, 0); plugin.start(); // The plugin should have bound a socket and stored the port number assertTrue(callback.propertiesLatch.await(5, SECONDS)); diff --git a/briar-tests/src/org/briarproject/plugins/tcp/LanTcpServerTest.java b/briar-tests/src/org/briarproject/plugins/tcp/LanTcpServerTest.java index 198489c0062d9e2db88807dbbebe7259fa9ce9ce..7531978148639e5b2b1eb232ecacbb8caf505582 100644 --- a/briar-tests/src/org/briarproject/plugins/tcp/LanTcpServerTest.java +++ b/briar-tests/src/org/briarproject/plugins/tcp/LanTcpServerTest.java @@ -13,7 +13,6 @@ import org.briarproject.plugins.DuplexServerTest; // is running on another machine public class LanTcpServerTest extends DuplexServerTest { - private static final int MAX_FRAME_LENGTH = 1024; private static final int MAX_LATENCY = 60 * 1000; private static final int MAX_IDLE_TIME = 30 * 1000; private static final int POLLING_INTERVAL = 60 * 1000; @@ -22,8 +21,8 @@ public class LanTcpServerTest extends DuplexServerTest { callback = new ServerCallback(new TransportConfig(), new TransportProperties(), Collections.singletonMap(contactId, new TransportProperties())); - plugin = new LanTcpPlugin(executor, callback, MAX_FRAME_LENGTH, - MAX_LATENCY, MAX_IDLE_TIME, POLLING_INTERVAL); + plugin = new LanTcpPlugin(executor, callback, MAX_LATENCY, + MAX_IDLE_TIME, POLLING_INTERVAL); } public static void main(String[] args) throws Exception { diff --git a/briar-tests/src/org/briarproject/transport/StreamReaderImplTest.java b/briar-tests/src/org/briarproject/transport/StreamReaderImplTest.java index 988299852d0506172aebf4280feedeb6e8148789..3a71ce74cc4f7aafd0ff6a380b163735fad40494 100644 --- a/briar-tests/src/org/briarproject/transport/StreamReaderImplTest.java +++ b/briar-tests/src/org/briarproject/transport/StreamReaderImplTest.java @@ -2,6 +2,7 @@ package org.briarproject.transport; 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.MAX_FRAME_LENGTH; import org.briarproject.BriarTestCase; import org.briarproject.api.crypto.StreamDecrypter; @@ -11,9 +12,8 @@ import org.junit.Test; public class StreamReaderImplTest extends BriarTestCase { - private static final int FRAME_LENGTH = 1024; private static final int MAX_PAYLOAD_LENGTH = - FRAME_LENGTH - HEADER_LENGTH - MAC_LENGTH; + MAX_FRAME_LENGTH - HEADER_LENGTH - MAC_LENGTH; @Test public void testEmptyFramesAreSkipped() throws Exception { @@ -29,7 +29,7 @@ public class StreamReaderImplTest extends BriarTestCase { oneOf(decrypter).readFrame(with(any(byte[].class))); will(returnValue(-1)); // No more frames }}); - StreamReaderImpl r = new StreamReaderImpl(decrypter, FRAME_LENGTH); + StreamReaderImpl r = new StreamReaderImpl(decrypter); assertEquals(0, r.read()); // Skip the first empty frame, read a byte assertEquals(0, r.read()); // Read another byte assertEquals(-1, r.read()); // Skip the second empty frame, reach EOF @@ -52,7 +52,7 @@ public class StreamReaderImplTest extends BriarTestCase { oneOf(decrypter).readFrame(with(any(byte[].class))); will(returnValue(-1)); // No more frames }}); - StreamReaderImpl r = new StreamReaderImpl(decrypter, FRAME_LENGTH); + StreamReaderImpl r = new StreamReaderImpl(decrypter); byte[] buf = new byte[MAX_PAYLOAD_LENGTH]; // Skip the first empty frame, read the two payload bytes assertEquals(2, r.read(buf)); @@ -74,7 +74,7 @@ public class StreamReaderImplTest extends BriarTestCase { oneOf(decrypter).readFrame(with(any(byte[].class))); will(returnValue(-1)); // No more frames }}); - StreamReaderImpl r = new StreamReaderImpl(decrypter, FRAME_LENGTH); + StreamReaderImpl r = new StreamReaderImpl(decrypter); byte[] buf = new byte[MAX_PAYLOAD_LENGTH / 2]; // Read the first half of the payload assertEquals(MAX_PAYLOAD_LENGTH / 2, r.read(buf)); @@ -96,7 +96,7 @@ public class StreamReaderImplTest extends BriarTestCase { oneOf(decrypter).readFrame(with(any(byte[].class))); will(returnValue(-1)); // No more frames }}); - StreamReaderImpl r = new StreamReaderImpl(decrypter, FRAME_LENGTH); + StreamReaderImpl r = new StreamReaderImpl(decrypter); byte[] buf = new byte[MAX_PAYLOAD_LENGTH]; // Read the first half of the payload assertEquals(MAX_PAYLOAD_LENGTH / 2, r.read(buf, MAX_PAYLOAD_LENGTH / 2, diff --git a/briar-tests/src/org/briarproject/transport/StreamWriterImplTest.java b/briar-tests/src/org/briarproject/transport/StreamWriterImplTest.java index 688621bd1511766e0bc8f7bf6f1ff1a170e4c385..4ea8916dd0b6f984f3c976ac683f16170264dee2 100644 --- a/briar-tests/src/org/briarproject/transport/StreamWriterImplTest.java +++ b/briar-tests/src/org/briarproject/transport/StreamWriterImplTest.java @@ -2,6 +2,7 @@ package org.briarproject.transport; 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.MAX_FRAME_LENGTH; import org.briarproject.BriarTestCase; import org.briarproject.api.crypto.StreamEncrypter; @@ -11,9 +12,8 @@ import org.junit.Test; public class StreamWriterImplTest extends BriarTestCase { - private static final int FRAME_LENGTH = 1024; private static final int MAX_PAYLOAD_LENGTH = - FRAME_LENGTH - HEADER_LENGTH - MAC_LENGTH; + MAX_FRAME_LENGTH - HEADER_LENGTH - MAC_LENGTH; @Test public void testCloseWithoutWritingWritesFinalFrame() throws Exception { @@ -26,7 +26,7 @@ public class StreamWriterImplTest extends BriarTestCase { // Flush the stream oneOf(encrypter).flush(); }}); - StreamWriterImpl w = new StreamWriterImpl(encrypter, FRAME_LENGTH); + StreamWriterImpl w = new StreamWriterImpl(encrypter); w.close(); context.assertIsSatisfied(); } @@ -36,7 +36,7 @@ public class StreamWriterImplTest extends BriarTestCase { throws Exception { Mockery context = new Mockery(); final StreamEncrypter encrypter = context.mock(StreamEncrypter.class); - StreamWriterImpl w = new StreamWriterImpl(encrypter, FRAME_LENGTH); + StreamWriterImpl w = new StreamWriterImpl(encrypter); context.checking(new Expectations() {{ // Write a non-final frame with an empty payload oneOf(encrypter).writeFrame(with(any(byte[].class)), with(0), @@ -63,7 +63,7 @@ public class StreamWriterImplTest extends BriarTestCase { throws Exception { Mockery context = new Mockery(); final StreamEncrypter encrypter = context.mock(StreamEncrypter.class); - StreamWriterImpl w = new StreamWriterImpl(encrypter, FRAME_LENGTH); + StreamWriterImpl w = new StreamWriterImpl(encrypter); context.checking(new Expectations() {{ // Write a non-final frame with one payload byte oneOf(encrypter).writeFrame(with(any(byte[].class)), with(1), @@ -90,7 +90,7 @@ public class StreamWriterImplTest extends BriarTestCase { public void testSingleByteWritesWriteFullFrame() throws Exception { Mockery context = new Mockery(); final StreamEncrypter encrypter = context.mock(StreamEncrypter.class); - StreamWriterImpl w = new StreamWriterImpl(encrypter, FRAME_LENGTH); + StreamWriterImpl w = new StreamWriterImpl(encrypter); context.checking(new Expectations() {{ // Write a full non-final frame oneOf(encrypter).writeFrame(with(any(byte[].class)), @@ -116,7 +116,7 @@ public class StreamWriterImplTest extends BriarTestCase { public void testMultiByteWritesWriteFullFrames() throws Exception { Mockery context = new Mockery(); final StreamEncrypter encrypter = context.mock(StreamEncrypter.class); - StreamWriterImpl w = new StreamWriterImpl(encrypter, FRAME_LENGTH); + StreamWriterImpl w = new StreamWriterImpl(encrypter); context.checking(new Expectations() {{ // Write two full non-final frames exactly(2).of(encrypter).writeFrame(with(any(byte[].class)), @@ -147,7 +147,7 @@ public class StreamWriterImplTest extends BriarTestCase { public void testLargeMultiByteWriteWritesFullFrames() throws Exception { Mockery context = new Mockery(); final StreamEncrypter encrypter = context.mock(StreamEncrypter.class); - StreamWriterImpl w = new StreamWriterImpl(encrypter, FRAME_LENGTH); + StreamWriterImpl w = new StreamWriterImpl(encrypter); context.checking(new Expectations() {{ // Write two full non-final frames exactly(2).of(encrypter).writeFrame(with(any(byte[].class)), diff --git a/briar-tests/src/org/briarproject/transport/TestStreamDecrypter.java b/briar-tests/src/org/briarproject/transport/TestStreamDecrypter.java index b0438801e6beb25915c8566418921e6d04d6e9a7..b901678a6beca92fbad25d2065abda5ac8710fec 100644 --- a/briar-tests/src/org/briarproject/transport/TestStreamDecrypter.java +++ b/briar-tests/src/org/briarproject/transport/TestStreamDecrypter.java @@ -2,6 +2,7 @@ package org.briarproject.transport; 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.MAX_FRAME_LENGTH; import java.io.EOFException; import java.io.IOException; @@ -16,9 +17,9 @@ class TestStreamDecrypter implements StreamDecrypter { private final InputStream in; private final byte[] frame; - TestStreamDecrypter(InputStream in, int frameLength) { + TestStreamDecrypter(InputStream in) { this.in = in; - frame = new byte[frameLength]; + frame = new byte[MAX_FRAME_LENGTH]; } public int readFrame(byte[] payload) throws IOException { diff --git a/briar-tests/src/org/briarproject/transport/TestStreamEncrypter.java b/briar-tests/src/org/briarproject/transport/TestStreamEncrypter.java index 4ad4c667c6203ef7d0a7d01f9c56c5238f5d986f..6939c71b544595a6d337be1277a7354e8fd586de 100644 --- a/briar-tests/src/org/briarproject/transport/TestStreamEncrypter.java +++ b/briar-tests/src/org/briarproject/transport/TestStreamEncrypter.java @@ -2,6 +2,7 @@ package org.briarproject.transport; 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.MAX_FRAME_LENGTH; import java.io.IOException; import java.io.OutputStream; @@ -16,10 +17,10 @@ class TestStreamEncrypter implements StreamEncrypter { private boolean writeTag = true; - TestStreamEncrypter(OutputStream out, int frameLength, byte[] tag) { + TestStreamEncrypter(OutputStream out, byte[] tag) { this.out = out; this.tag = tag; - frame = new byte[frameLength]; + frame = new byte[MAX_FRAME_LENGTH]; } public void writeFrame(byte[] payload, int payloadLength, diff --git a/briar-tests/src/org/briarproject/transport/TransportIntegrationTest.java b/briar-tests/src/org/briarproject/transport/TransportIntegrationTest.java index f55e5b6e1a8ef83fc5d504ca5a5ef79fe6fb2a1b..af006350ae623ecc622a2c582f5b896389727be8 100644 --- a/briar-tests/src/org/briarproject/transport/TransportIntegrationTest.java +++ b/briar-tests/src/org/briarproject/transport/TransportIntegrationTest.java @@ -1,5 +1,6 @@ package org.briarproject.transport; +import static org.briarproject.api.transport.TransportConstants.MAX_FRAME_LENGTH; import static org.briarproject.api.transport.TransportConstants.TAG_LENGTH; import static org.junit.Assert.assertArrayEquals; @@ -17,8 +18,6 @@ import org.junit.Test; public class TransportIntegrationTest extends BriarTestCase { - private final int FRAME_LENGTH = 2048; - private final Random random; public TransportIntegrationTest() { @@ -40,31 +39,28 @@ public class TransportIntegrationTest extends BriarTestCase { byte[] tag = new byte[TAG_LENGTH]; random.nextBytes(tag); // Generate two frames with random payloads - byte[] payload1 = new byte[1234]; + byte[] payload1 = new byte[123]; random.nextBytes(payload1); byte[] payload2 = new byte[321]; random.nextBytes(payload2); // Write the tag and the frames ByteArrayOutputStream out = new ByteArrayOutputStream(); - StreamEncrypter encrypter = new TestStreamEncrypter(out, FRAME_LENGTH, - tag); - OutputStream streamWriter = new StreamWriterImpl(encrypter, - FRAME_LENGTH); + StreamEncrypter encrypter = new TestStreamEncrypter(out, tag); + OutputStream streamWriter = new StreamWriterImpl(encrypter); streamWriter.write(payload1); streamWriter.flush(); streamWriter.write(payload2); streamWriter.flush(); byte[] output = out.toByteArray(); - assertEquals(TAG_LENGTH + FRAME_LENGTH * 2, output.length); + assertEquals(TAG_LENGTH + MAX_FRAME_LENGTH * 2, output.length); // Read the tag back ByteArrayInputStream in = new ByteArrayInputStream(output); byte[] recoveredTag = new byte[tag.length]; read(in, recoveredTag); assertArrayEquals(tag, recoveredTag); // Read the frames back - StreamDecrypter decrypter = new TestStreamDecrypter(in, FRAME_LENGTH); - InputStream streamReader = new StreamReaderImpl(decrypter, - FRAME_LENGTH); + StreamDecrypter decrypter = new TestStreamDecrypter(in); + InputStream streamReader = new StreamReaderImpl(decrypter); byte[] recoveredPayload1 = new byte[payload1.length]; read(streamReader, recoveredPayload1); assertArrayEquals(payload1, recoveredPayload1);