diff --git a/components/net/sf/briar/transport/ConnectionReaderFactoryImpl.java b/components/net/sf/briar/transport/ConnectionReaderFactoryImpl.java index 4149b376896943953b095de6a10e13c2b6fe1174..1a82bd8359cd65329db9198543c91f1035c54fb3 100644 --- a/components/net/sf/briar/transport/ConnectionReaderFactoryImpl.java +++ b/components/net/sf/briar/transport/ConnectionReaderFactoryImpl.java @@ -49,7 +49,7 @@ class ConnectionReaderFactoryImpl implements ConnectionReaderFactory { Cipher tagCipher = crypto.getTagCipher(); Cipher frameCipher = crypto.getFrameCipher(); Mac mac = crypto.getMac(); - FrameSource decrypter = new ConnectionDecrypter(in, tagCipher, + IncomingEncryptionLayer decrypter = new IncomingEncryptionLayerImpl(in, tagCipher, frameCipher, tagKey, frameKey, mac.getMacLength(), false); // Create the reader return new ConnectionReaderImpl(decrypter, mac, macKey); diff --git a/components/net/sf/briar/transport/ConnectionReaderImpl.java b/components/net/sf/briar/transport/ConnectionReaderImpl.java index 1d7b1de19e32d43bdd61387a2485be5dc2ab3757..9ee8b7180be6dbebc2acbc5df304498d1d3f6f3b 100644 --- a/components/net/sf/briar/transport/ConnectionReaderImpl.java +++ b/components/net/sf/briar/transport/ConnectionReaderImpl.java @@ -16,7 +16,7 @@ import net.sf.briar.api.transport.ConnectionReader; class ConnectionReaderImpl extends InputStream implements ConnectionReader { - private final FrameSource decrypter; + private final IncomingEncryptionLayer decrypter; private final Mac mac; private final int macLength; private final byte[] buf; @@ -24,7 +24,7 @@ class ConnectionReaderImpl extends InputStream implements ConnectionReader { private long frame = 0L; private int bufOffset = 0, bufLength = 0; - ConnectionReaderImpl(FrameSource decrypter, Mac mac, ErasableKey macKey) { + ConnectionReaderImpl(IncomingEncryptionLayer decrypter, Mac mac, ErasableKey macKey) { this.decrypter = decrypter; this.mac = mac; // Initialise the MAC diff --git a/components/net/sf/briar/transport/ConnectionWriterFactoryImpl.java b/components/net/sf/briar/transport/ConnectionWriterFactoryImpl.java index e368d1f39bbd740a29c5e7b115dc99a1100195c2..3af3e0a56ad096d252138843d5bfbf658d2599c7 100644 --- a/components/net/sf/briar/transport/ConnectionWriterFactoryImpl.java +++ b/components/net/sf/briar/transport/ConnectionWriterFactoryImpl.java @@ -48,7 +48,7 @@ class ConnectionWriterFactoryImpl implements ConnectionWriterFactory { // Create the encrypter Cipher tagCipher = crypto.getTagCipher(); Cipher frameCipher = crypto.getFrameCipher(); - ConnectionEncrypter encrypter = new ConnectionEncrypterImpl(out, + OutgoingEncryptionLayer encrypter = new OutgoingEncryptionLayerImpl(out, capacity, tagCipher, frameCipher, tagKey, frameKey, false); // Create the writer Mac mac = crypto.getMac(); diff --git a/components/net/sf/briar/transport/ConnectionWriterImpl.java b/components/net/sf/briar/transport/ConnectionWriterImpl.java index fd823dd0fd362b61baddf112d98cc4c87a720914..87e7089f9f1074a041bb77cf8673c7898f7cd7e9 100644 --- a/components/net/sf/briar/transport/ConnectionWriterImpl.java +++ b/components/net/sf/briar/transport/ConnectionWriterImpl.java @@ -22,14 +22,14 @@ import net.sf.briar.api.transport.ConnectionWriter; */ class ConnectionWriterImpl extends OutputStream implements ConnectionWriter { - private final ConnectionEncrypter encrypter; + private final OutgoingEncryptionLayer encrypter; private final Mac mac; private final byte[] buf; private int bufLength = FRAME_HEADER_LENGTH; private long frame = 0L; - ConnectionWriterImpl(ConnectionEncrypter encrypter, Mac mac, + ConnectionWriterImpl(OutgoingEncryptionLayer encrypter, Mac mac, ErasableKey macKey) { this.encrypter = encrypter; this.mac = mac; diff --git a/components/net/sf/briar/transport/FrameSink.java b/components/net/sf/briar/transport/FrameSink.java deleted file mode 100644 index 710f60a5e37f6a394c79bd4fd9f628971125b511..0000000000000000000000000000000000000000 --- a/components/net/sf/briar/transport/FrameSink.java +++ /dev/null @@ -1,9 +0,0 @@ -package net.sf.briar.transport; - -import java.io.IOException; - -interface FrameSink { - - /** Writes the given frame. */ - void writeFrame(byte[] b, int len) throws IOException; -} diff --git a/components/net/sf/briar/transport/FrameSource.java b/components/net/sf/briar/transport/IncomingEncryptionLayer.java similarity index 86% rename from components/net/sf/briar/transport/FrameSource.java rename to components/net/sf/briar/transport/IncomingEncryptionLayer.java index 7347b6ccbab2452ab9160661deae8ad6c7618301..bd4bd19829a000454397d49badc2bd9e7ce14d9a 100644 --- a/components/net/sf/briar/transport/FrameSource.java +++ b/components/net/sf/briar/transport/IncomingEncryptionLayer.java @@ -2,7 +2,7 @@ package net.sf.briar.transport; import java.io.IOException; -interface FrameSource { +interface IncomingEncryptionLayer { /** * Reads a frame into the given buffer and returns its length, or -1 if no diff --git a/components/net/sf/briar/transport/ConnectionDecrypter.java b/components/net/sf/briar/transport/IncomingEncryptionLayerImpl.java similarity index 93% rename from components/net/sf/briar/transport/ConnectionDecrypter.java rename to components/net/sf/briar/transport/IncomingEncryptionLayerImpl.java index 928f56ca7431062cf20556ed76b334910fbcf01d..b8f684d0aa6785580e8756fc9f1b776ac2fe8ea1 100644 --- a/components/net/sf/briar/transport/ConnectionDecrypter.java +++ b/components/net/sf/briar/transport/IncomingEncryptionLayerImpl.java @@ -16,7 +16,7 @@ import javax.crypto.spec.IvParameterSpec; import net.sf.briar.api.FormatException; import net.sf.briar.api.crypto.ErasableKey; -class ConnectionDecrypter implements FrameSource { +class IncomingEncryptionLayerImpl implements IncomingEncryptionLayer { private final InputStream in; private final Cipher tagCipher, frameCipher; @@ -27,9 +27,9 @@ class ConnectionDecrypter implements FrameSource { private long frame = 0L; - ConnectionDecrypter(InputStream in, Cipher tagCipher, Cipher frameCipher, - ErasableKey tagKey, ErasableKey frameKey, int macLength, - boolean tagEverySegment) { + IncomingEncryptionLayerImpl(InputStream in, Cipher tagCipher, + Cipher frameCipher, ErasableKey tagKey, ErasableKey frameKey, + int macLength, boolean tagEverySegment) { this.in = in; this.tagCipher = tagCipher; this.frameCipher = frameCipher; diff --git a/components/net/sf/briar/transport/SegmentedConnectionDecrypter.java b/components/net/sf/briar/transport/IncomingSegmentedEncryptionLayer.java similarity index 95% rename from components/net/sf/briar/transport/SegmentedConnectionDecrypter.java rename to components/net/sf/briar/transport/IncomingSegmentedEncryptionLayer.java index 59af5f185caeb076e30f90d4d57487dd853f21ea..dfa063c93be39bcbd552cb8de831fed8b0e0c191 100644 --- a/components/net/sf/briar/transport/SegmentedConnectionDecrypter.java +++ b/components/net/sf/briar/transport/IncomingSegmentedEncryptionLayer.java @@ -16,7 +16,7 @@ import net.sf.briar.api.crypto.ErasableKey; import net.sf.briar.api.plugins.Segment; import net.sf.briar.api.plugins.SegmentSource; -class SegmentedConnectionDecrypter implements FrameSource { +class IncomingSegmentedEncryptionLayer implements IncomingEncryptionLayer { private final SegmentSource in; private final Cipher tagCipher, frameCipher; @@ -28,7 +28,7 @@ class SegmentedConnectionDecrypter implements FrameSource { private long frame = 0L; - SegmentedConnectionDecrypter(SegmentSource in, Cipher tagCipher, + IncomingSegmentedEncryptionLayer(SegmentSource in, Cipher tagCipher, Cipher frameCipher, ErasableKey tagKey, ErasableKey frameKey, int macLength, boolean tagEverySegment) { this.in = in; diff --git a/components/net/sf/briar/transport/ConnectionEncrypter.java b/components/net/sf/briar/transport/OutgoingEncryptionLayer.java similarity index 70% rename from components/net/sf/briar/transport/ConnectionEncrypter.java rename to components/net/sf/briar/transport/OutgoingEncryptionLayer.java index 82bbf357af1b8adc0ecb632bd7927f21d1f0c6e7..bd902736a2e23db7b857461cc75512e96d4386cc 100644 --- a/components/net/sf/briar/transport/ConnectionEncrypter.java +++ b/components/net/sf/briar/transport/OutgoingEncryptionLayer.java @@ -3,7 +3,10 @@ package net.sf.briar.transport; import java.io.IOException; /** Encrypts authenticated data to be sent over a connection. */ -interface ConnectionEncrypter extends FrameSink { +interface OutgoingEncryptionLayer { + + /** Writes the given frame. */ + void writeFrame(byte[] b, int len) throws IOException; /** Flushes the output stream. */ void flush() throws IOException; diff --git a/components/net/sf/briar/transport/ConnectionEncrypterImpl.java b/components/net/sf/briar/transport/OutgoingEncryptionLayerImpl.java similarity index 92% rename from components/net/sf/briar/transport/ConnectionEncrypterImpl.java rename to components/net/sf/briar/transport/OutgoingEncryptionLayerImpl.java index 08e40577ac4ef8329e556e6c81f7a769a9f34ecf..33cb929435b8c46d5ca894d18ad0902ad98e5f08 100644 --- a/components/net/sf/briar/transport/ConnectionEncrypterImpl.java +++ b/components/net/sf/briar/transport/OutgoingEncryptionLayerImpl.java @@ -12,7 +12,7 @@ import javax.crypto.spec.IvParameterSpec; import net.sf.briar.api.crypto.ErasableKey; -class ConnectionEncrypterImpl implements ConnectionEncrypter { +class OutgoingEncryptionLayerImpl implements OutgoingEncryptionLayer { private final OutputStream out; private final Cipher tagCipher, frameCipher; @@ -22,7 +22,7 @@ class ConnectionEncrypterImpl implements ConnectionEncrypter { private long capacity, frame = 0L; - ConnectionEncrypterImpl(OutputStream out, long capacity, Cipher tagCipher, + OutgoingEncryptionLayerImpl(OutputStream out, long capacity, Cipher tagCipher, Cipher frameCipher, ErasableKey tagKey, ErasableKey frameKey, boolean tagEverySegment) { this.out = out; diff --git a/components/net/sf/briar/transport/SegmentedConnectionEncrypter.java b/components/net/sf/briar/transport/OutgoingSegmentedEncryptionLayer.java similarity index 94% rename from components/net/sf/briar/transport/SegmentedConnectionEncrypter.java rename to components/net/sf/briar/transport/OutgoingSegmentedEncryptionLayer.java index 29af654f2a422861a7b6e2d836a28c272a6963f3..99ce32f90d5bd56401bcb2e3ca2f123343c46196 100644 --- a/components/net/sf/briar/transport/SegmentedConnectionEncrypter.java +++ b/components/net/sf/briar/transport/OutgoingSegmentedEncryptionLayer.java @@ -14,7 +14,7 @@ import net.sf.briar.api.crypto.ErasableKey; import net.sf.briar.api.plugins.Segment; import net.sf.briar.api.plugins.SegmentSink; -class SegmentedConnectionEncrypter implements ConnectionEncrypter { +class OutgoingSegmentedEncryptionLayer implements OutgoingEncryptionLayer { private final SegmentSink out; private final Cipher tagCipher, frameCipher; @@ -25,7 +25,7 @@ class SegmentedConnectionEncrypter implements ConnectionEncrypter { private long capacity, frame = 0L; - SegmentedConnectionEncrypter(SegmentSink out, long capacity, + OutgoingSegmentedEncryptionLayer(SegmentSink out, long capacity, Cipher tagCipher, Cipher frameCipher, ErasableKey tagKey, ErasableKey frameKey, boolean tagEverySegment) { this.out = out; diff --git a/test/build.xml b/test/build.xml index f0d6316227a6e022b46645fe7daa51d23c04716a..a92959b5055890ff9efb1a7f154ce7561edbd5e2 100644 --- a/test/build.xml +++ b/test/build.xml @@ -49,8 +49,6 @@ <test name='net.sf.briar.serial.ReaderImplTest'/> <test name='net.sf.briar.serial.WriterImplTest'/> <test name='net.sf.briar.setup.SetupWorkerTest'/> - <test name='net.sf.briar.transport.ConnectionDecrypterTest'/> - <test name='net.sf.briar.transport.ConnectionEncrypterImplTest'/> <test name='net.sf.briar.transport.ConnectionReaderImplTest'/> <test name='net.sf.briar.transport.ConnectionRecogniserImplTest'/> <test name='net.sf.briar.transport.ConnectionRegistryImplTest'/> @@ -58,8 +56,10 @@ <test name='net.sf.briar.transport.ConnectionWriterImplTest'/> <test name='net.sf.briar.transport.ConnectionWriterTest'/> <test name='net.sf.briar.transport.FrameReadWriteTest'/> - <test name='net.sf.briar.transport.SegmentedConnectionDecrypterTest'/> - <test name='net.sf.briar.transport.SegmentedConnectionEncrypterTest'/> + <test name='net.sf.briar.transport.IncomingEncryptionLayerImplTest'/> + <test name='net.sf.briar.transport.IncomingSegmentedEncryptionLayerTest'/> + <test name='net.sf.briar.transport.OutgoingEncryptionLayerImplTest'/> + <test name='net.sf.briar.transport.OutgoingSegmentedEncryptionLayerTest'/> <test name='net.sf.briar.util.ByteUtilsTest'/> <test name='net.sf.briar.util.FileUtilsTest'/> <test name='net.sf.briar.util.StringUtilsTest'/> diff --git a/test/net/sf/briar/transport/ConnectionReaderImplTest.java b/test/net/sf/briar/transport/ConnectionReaderImplTest.java index 798f8e457224fee5fbb0ffaec7fbe63d1bf59f97..bb385b9192c81c76f7198de68cf133aa5f0bba81 100644 --- a/test/net/sf/briar/transport/ConnectionReaderImplTest.java +++ b/test/net/sf/briar/transport/ConnectionReaderImplTest.java @@ -31,7 +31,7 @@ public class ConnectionReaderImplTest extends TransportTest { mac.doFinal(frame, FRAME_HEADER_LENGTH + payloadLength); // Read the frame ByteArrayInputStream in = new ByteArrayInputStream(frame); - FrameSource d = new NullConnectionDecrypter(in, macLength); + IncomingEncryptionLayer d = new NullConnectionDecrypter(in, macLength); ConnectionReader r = new ConnectionReaderImpl(d, mac, macKey); // There should be no bytes available before EOF assertEquals(-1, r.getInputStream().read()); @@ -49,7 +49,7 @@ public class ConnectionReaderImplTest extends TransportTest { mac.doFinal(frame, FRAME_HEADER_LENGTH + payloadLength); // Read the frame ByteArrayInputStream in = new ByteArrayInputStream(frame); - FrameSource d = new NullConnectionDecrypter(in, macLength); + IncomingEncryptionLayer d = new NullConnectionDecrypter(in, macLength); ConnectionReader r = new ConnectionReaderImpl(d, mac, macKey); // There should be one byte available before EOF assertEquals(0, r.getInputStream().read()); @@ -75,7 +75,7 @@ public class ConnectionReaderImplTest extends TransportTest { out.write(frame1); // Read the first frame ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); - FrameSource d = new NullConnectionDecrypter(in, macLength); + IncomingEncryptionLayer d = new NullConnectionDecrypter(in, macLength); ConnectionReader r = new ConnectionReaderImpl(d, mac, macKey); byte[] read = new byte[maxPayloadLength]; TestUtils.readFully(r.getInputStream(), read); @@ -109,7 +109,7 @@ public class ConnectionReaderImplTest extends TransportTest { out.write(frame1); // Read the first frame ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); - FrameSource d = new NullConnectionDecrypter(in, macLength); + IncomingEncryptionLayer d = new NullConnectionDecrypter(in, macLength); ConnectionReader r = new ConnectionReaderImpl(d, mac, macKey); byte[] read = new byte[maxPayloadLength - paddingLength]; TestUtils.readFully(r.getInputStream(), read); @@ -135,7 +135,7 @@ public class ConnectionReaderImplTest extends TransportTest { mac.doFinal(frame, FRAME_HEADER_LENGTH + payloadLength + paddingLength); // Read the frame ByteArrayInputStream in = new ByteArrayInputStream(frame); - FrameSource d = new NullConnectionDecrypter(in, macLength); + IncomingEncryptionLayer d = new NullConnectionDecrypter(in, macLength); ConnectionReader r = new ConnectionReaderImpl(d, mac, macKey); // The non-zero padding should be rejected try { @@ -167,7 +167,7 @@ public class ConnectionReaderImplTest extends TransportTest { out.write(frame1); // Read the frames ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); - FrameSource d = new NullConnectionDecrypter(in, macLength); + IncomingEncryptionLayer d = new NullConnectionDecrypter(in, macLength); ConnectionReader r = new ConnectionReaderImpl(d, mac, macKey); byte[] read = new byte[payloadLength]; TestUtils.readFully(r.getInputStream(), read); @@ -191,7 +191,7 @@ public class ConnectionReaderImplTest extends TransportTest { frame[12] ^= 1; // Try to read the frame - not a single byte should be read ByteArrayInputStream in = new ByteArrayInputStream(frame); - FrameSource d = new NullConnectionDecrypter(in, macLength); + IncomingEncryptionLayer d = new NullConnectionDecrypter(in, macLength); ConnectionReader r = new ConnectionReaderImpl(d, mac, macKey); try { r.getInputStream().read(); @@ -213,7 +213,7 @@ public class ConnectionReaderImplTest extends TransportTest { frame[17] ^= 1; // Try to read the frame - not a single byte should be read ByteArrayInputStream in = new ByteArrayInputStream(frame); - FrameSource d = new NullConnectionDecrypter(in, macLength); + IncomingEncryptionLayer d = new NullConnectionDecrypter(in, macLength); ConnectionReader r = new ConnectionReaderImpl(d, mac, macKey); try { r.getInputStream().read(); diff --git a/test/net/sf/briar/transport/ConnectionWriterImplTest.java b/test/net/sf/briar/transport/ConnectionWriterImplTest.java index 7076deb49eda3933b78954edffa49e2343315e3f..43f6cf47cbd260cd6581952bd24e66577f9598d5 100644 --- a/test/net/sf/briar/transport/ConnectionWriterImplTest.java +++ b/test/net/sf/briar/transport/ConnectionWriterImplTest.java @@ -20,7 +20,7 @@ public class ConnectionWriterImplTest extends TransportTest { @Test public void testFlushWithoutWriteProducesNothing() throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); - ConnectionEncrypter e = new NullConnectionEncrypter(out); + OutgoingEncryptionLayer e = new NullConnectionEncrypter(out); ConnectionWriter w = new ConnectionWriterImpl(e, mac, macKey); w.getOutputStream().flush(); w.getOutputStream().flush(); @@ -40,7 +40,7 @@ public class ConnectionWriterImplTest extends TransportTest { mac.doFinal(frame, FRAME_HEADER_LENGTH + payloadLength); // Check that the ConnectionWriter gets the same results ByteArrayOutputStream out = new ByteArrayOutputStream(); - ConnectionEncrypter e = new NullConnectionEncrypter(out); + OutgoingEncryptionLayer e = new NullConnectionEncrypter(out); ConnectionWriter w = new ConnectionWriterImpl(e, mac, macKey); w.getOutputStream().write(0); w.getOutputStream().flush(); @@ -50,7 +50,7 @@ public class ConnectionWriterImplTest extends TransportTest { @Test public void testWriteByteToMaxLengthWritesFrame() throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); - ConnectionEncrypter e = new NullConnectionEncrypter(out); + OutgoingEncryptionLayer e = new NullConnectionEncrypter(out); ConnectionWriter w = new ConnectionWriterImpl(e, mac, macKey); OutputStream out1 = w.getOutputStream(); // The first maxPayloadLength - 1 bytes should be buffered @@ -64,7 +64,7 @@ public class ConnectionWriterImplTest extends TransportTest { @Test public void testWriteArrayToMaxLengthWritesFrame() throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); - ConnectionEncrypter e = new NullConnectionEncrypter(out); + OutgoingEncryptionLayer e = new NullConnectionEncrypter(out); ConnectionWriter w = new ConnectionWriterImpl(e, mac, macKey); OutputStream out1 = w.getOutputStream(); // The first maxPayloadLength - 1 bytes should be buffered @@ -99,7 +99,7 @@ public class ConnectionWriterImplTest extends TransportTest { byte[] expected = out.toByteArray(); // Check that the ConnectionWriter gets the same results out.reset(); - ConnectionEncrypter e = new NullConnectionEncrypter(out); + OutgoingEncryptionLayer e = new NullConnectionEncrypter(out); ConnectionWriter w = new ConnectionWriterImpl(e, mac, macKey); w.getOutputStream().write(new byte[123]); w.getOutputStream().flush(); diff --git a/test/net/sf/briar/transport/FrameReadWriteTest.java b/test/net/sf/briar/transport/FrameReadWriteTest.java index 051f9f66bc2c1adb17231e945945f9d3199bd09c..53b4a8f1cf8889a33abfddd1e897ad2dcb21d0dc 100644 --- a/test/net/sf/briar/transport/FrameReadWriteTest.java +++ b/test/net/sf/briar/transport/FrameReadWriteTest.java @@ -74,7 +74,7 @@ public class FrameReadWriteTest extends BriarTestCase { ErasableKey macCopy = macKey.copy(); // Write the frames ByteArrayOutputStream out = new ByteArrayOutputStream(); - ConnectionEncrypter encrypter = new ConnectionEncrypterImpl(out, + OutgoingEncryptionLayer encrypter = new OutgoingEncryptionLayerImpl(out, Long.MAX_VALUE, tagCipher, frameCipher, tagCopy, frameCopy, false); ConnectionWriter writer = new ConnectionWriterImpl(encrypter, mac, @@ -91,7 +91,7 @@ public class FrameReadWriteTest extends BriarTestCase { assertArrayEquals(tag, recoveredTag); assertTrue(TagEncoder.validateTag(tag, 0, tagCipher, tagKey)); // Read the frames back - FrameSource decrypter = new ConnectionDecrypter(in, tagCipher, + IncomingEncryptionLayer decrypter = new IncomingEncryptionLayerImpl(in, tagCipher, frameCipher, tagKey, frameKey, mac.getMacLength(), false); ConnectionReader reader = new ConnectionReaderImpl(decrypter, mac, macKey); diff --git a/test/net/sf/briar/transport/ConnectionDecrypterTest.java b/test/net/sf/briar/transport/IncomingEncryptionLayerImplTest.java similarity index 89% rename from test/net/sf/briar/transport/ConnectionDecrypterTest.java rename to test/net/sf/briar/transport/IncomingEncryptionLayerImplTest.java index b79bff4d42db7e877262830582996b77c70e6437..6ac04ef08a7790b47915dcf8c6ad99766956a17e 100644 --- a/test/net/sf/briar/transport/ConnectionDecrypterTest.java +++ b/test/net/sf/briar/transport/IncomingEncryptionLayerImplTest.java @@ -20,14 +20,14 @@ import org.junit.Test; import com.google.inject.Guice; import com.google.inject.Injector; -public class ConnectionDecrypterTest extends BriarTestCase { +public class IncomingEncryptionLayerImplTest extends BriarTestCase { private static final int MAC_LENGTH = 32; private final Cipher tagCipher, frameCipher; private final ErasableKey tagKey, frameKey; - public ConnectionDecrypterTest() { + public IncomingEncryptionLayerImplTest() { super(); Injector i = Guice.createInjector(new CryptoModule()); CryptoComponent crypto = i.getInstance(CryptoComponent.class); @@ -59,9 +59,9 @@ public class ConnectionDecrypterTest extends BriarTestCase { out.write(ciphertext); out.write(ciphertext1); ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); - // Use a ConnectionDecrypter to decrypt the ciphertext - FrameSource decrypter = new ConnectionDecrypter(in, tagCipher, - frameCipher, tagKey, frameKey, MAC_LENGTH, false); + // Use the encryption layer to decrypt the ciphertext + IncomingEncryptionLayer decrypter = new IncomingEncryptionLayerImpl(in, + tagCipher, frameCipher, tagKey, frameKey, MAC_LENGTH, false); // First frame byte[] decrypted = new byte[MAX_FRAME_LENGTH]; assertEquals(plaintext.length, decrypter.readFrame(decrypted)); @@ -99,9 +99,9 @@ public class ConnectionDecrypterTest extends BriarTestCase { out.write(ciphertext); out.write(ciphertext1); ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); - // Use a ConnectionDecrypter to decrypt the ciphertext - FrameSource decrypter = new ConnectionDecrypter(in, tagCipher, - frameCipher, tagKey, frameKey, MAC_LENGTH, true); + // Use the encryption layer to decrypt the ciphertext + IncomingEncryptionLayer decrypter = new IncomingEncryptionLayerImpl(in, + tagCipher, frameCipher, tagKey, frameKey, MAC_LENGTH, true); // First frame byte[] decrypted = new byte[MAX_FRAME_LENGTH]; assertEquals(plaintext.length, decrypter.readFrame(decrypted)); diff --git a/test/net/sf/briar/transport/SegmentedConnectionDecrypterTest.java b/test/net/sf/briar/transport/IncomingSegmentedEncryptionLayerTest.java similarity index 85% rename from test/net/sf/briar/transport/SegmentedConnectionDecrypterTest.java rename to test/net/sf/briar/transport/IncomingSegmentedEncryptionLayerTest.java index 539b6dd0b23230db17db79d0c2a2501e2e265189..d3e580ff5afef479f92c8fedebdc7f0080e12040 100644 --- a/test/net/sf/briar/transport/SegmentedConnectionDecrypterTest.java +++ b/test/net/sf/briar/transport/IncomingSegmentedEncryptionLayerTest.java @@ -21,14 +21,14 @@ import org.junit.Test; import com.google.inject.Guice; import com.google.inject.Injector; -public class SegmentedConnectionDecrypterTest extends BriarTestCase { +public class IncomingSegmentedEncryptionLayerTest extends BriarTestCase { private static final int MAC_LENGTH = 32; private final Cipher tagCipher, frameCipher; private final ErasableKey tagKey, frameKey; - public SegmentedConnectionDecrypterTest() { + public IncomingSegmentedEncryptionLayerTest() { super(); Injector i = Guice.createInjector(new CryptoModule()); CryptoComponent crypto = i.getInstance(CryptoComponent.class); @@ -55,11 +55,12 @@ public class SegmentedConnectionDecrypterTest extends BriarTestCase { frameCipher.init(Cipher.ENCRYPT_MODE, frameKey, ivSpec); byte[] ciphertext1 = frameCipher.doFinal(plaintext1, 0, plaintext1.length); - // Use a connection decrypter to decrypt the ciphertext + // Use the encryption layer to decrypt the ciphertext byte[][] frames = new byte[][] { ciphertext, ciphertext1 }; SegmentSource in = new ByteArraySegmentSource(frames); - FrameSource decrypter = new SegmentedConnectionDecrypter(in, tagCipher, - frameCipher, tagKey, frameKey, MAC_LENGTH, false); + IncomingEncryptionLayer decrypter = + new IncomingSegmentedEncryptionLayer(in, tagCipher, frameCipher, + tagKey, frameKey, MAC_LENGTH, false); // First frame byte[] decrypted = new byte[MAX_FRAME_LENGTH]; assertEquals(plaintext.length, decrypter.readFrame(decrypted)); @@ -92,11 +93,12 @@ public class SegmentedConnectionDecrypterTest extends BriarTestCase { frameCipher.init(Cipher.ENCRYPT_MODE, frameKey, ivSpec); frameCipher.doFinal(plaintext1, 0, plaintext1.length, ciphertext1, TAG_LENGTH); - // Use a connection decrypter to decrypt the ciphertext + // Use the encryption layer to decrypt the ciphertext byte[][] frames = new byte[][] { ciphertext, ciphertext1 }; SegmentSource in = new ByteArraySegmentSource(frames); - FrameSource decrypter = new SegmentedConnectionDecrypter(in, tagCipher, - frameCipher, tagKey, frameKey, MAC_LENGTH, true); + IncomingEncryptionLayer decrypter = + new IncomingSegmentedEncryptionLayer(in, tagCipher, frameCipher, + tagKey, frameKey, MAC_LENGTH, true); // First frame byte[] decrypted = new byte[MAX_FRAME_LENGTH]; assertEquals(plaintext.length, decrypter.readFrame(decrypted)); @@ -112,20 +114,20 @@ public class SegmentedConnectionDecrypterTest extends BriarTestCase { private static class ByteArraySegmentSource implements SegmentSource { - private final byte[][] frames; + private final byte[][] segments; - private int frame = 0; + private int segmentNumber = 0; private ByteArraySegmentSource(byte[][] frames) { - this.frames = frames; + this.segments = frames; } public boolean readSegment(Segment s) throws IOException { - if(frame == frames.length) return false; - byte[] src = frames[frame]; + if(segmentNumber == segments.length) return false; + byte[] src = segments[segmentNumber]; System.arraycopy(src, 0, s.getBuffer(), 0, src.length); s.setLength(src.length); - frame++; + segmentNumber++; return true; } } diff --git a/test/net/sf/briar/transport/NullConnectionDecrypter.java b/test/net/sf/briar/transport/NullConnectionDecrypter.java index 32b5a2164968b9f7d462e81fd8d48bfb737959d6..ac1a59ddc24c6dcbbb36f45d9994b99fddb41b6f 100644 --- a/test/net/sf/briar/transport/NullConnectionDecrypter.java +++ b/test/net/sf/briar/transport/NullConnectionDecrypter.java @@ -10,7 +10,7 @@ import java.io.InputStream; import net.sf.briar.api.FormatException; /** A connection decrypter that performs no decryption. */ -class NullConnectionDecrypter implements FrameSource { +class NullConnectionDecrypter implements IncomingEncryptionLayer { private final InputStream in; private final int macLength; diff --git a/test/net/sf/briar/transport/NullConnectionEncrypter.java b/test/net/sf/briar/transport/NullConnectionEncrypter.java index 5f59c78969ce1d2d93d12a7f5199a3a00cf07038..182f612ca0f82ee7209e30886b79b1a38b48a545 100644 --- a/test/net/sf/briar/transport/NullConnectionEncrypter.java +++ b/test/net/sf/briar/transport/NullConnectionEncrypter.java @@ -4,7 +4,7 @@ import java.io.IOException; import java.io.OutputStream; /** A ConnectionEncrypter that performs no encryption. */ -class NullConnectionEncrypter implements ConnectionEncrypter { +class NullConnectionEncrypter implements OutgoingEncryptionLayer { private final OutputStream out; diff --git a/test/net/sf/briar/transport/ConnectionEncrypterImplTest.java b/test/net/sf/briar/transport/OutgoingEncryptionLayerImplTest.java similarity index 79% rename from test/net/sf/briar/transport/ConnectionEncrypterImplTest.java rename to test/net/sf/briar/transport/OutgoingEncryptionLayerImplTest.java index ddc9325180c5cdb222a477ffe18410b8b366c42d..8aa93d68e8ddb87423717f4744eb8b4b16891d08 100644 --- a/test/net/sf/briar/transport/ConnectionEncrypterImplTest.java +++ b/test/net/sf/briar/transport/OutgoingEncryptionLayerImplTest.java @@ -18,14 +18,14 @@ import org.junit.Test; import com.google.inject.Guice; import com.google.inject.Injector; -public class ConnectionEncrypterImplTest extends BriarTestCase { +public class OutgoingEncryptionLayerImplTest extends BriarTestCase { private static final int MAC_LENGTH = 32; private final Cipher tagCipher, frameCipher; private final ErasableKey tagKey, frameKey; - public ConnectionEncrypterImplTest() { + public OutgoingEncryptionLayerImplTest() { super(); Injector i = Guice.createInjector(new CryptoModule()); CryptoComponent crypto = i.getInstance(CryptoComponent.class); @@ -58,16 +58,18 @@ public class ConnectionEncrypterImplTest extends BriarTestCase { out.write(ciphertext); out.write(ciphertext1); byte[] expected = out.toByteArray(); - // Use a ConnectionEncrypter to encrypt the plaintext + // Use the encryption layer to encrypt the plaintext out.reset(); - ConnectionEncrypter e = new ConnectionEncrypterImpl(out, Long.MAX_VALUE, - tagCipher, frameCipher, tagKey, frameKey, false); - e.writeFrame(plaintext, plaintext.length); - e.writeFrame(plaintext1, plaintext1.length); + OutgoingEncryptionLayer encrypter = new OutgoingEncryptionLayerImpl(out, + Long.MAX_VALUE, tagCipher, frameCipher, tagKey, frameKey, + false); + encrypter.writeFrame(plaintext, plaintext.length); + encrypter.writeFrame(plaintext1, plaintext1.length); byte[] actual = out.toByteArray(); // Check that the actual ciphertext matches the expected ciphertext assertArrayEquals(expected, actual); - assertEquals(Long.MAX_VALUE - actual.length, e.getRemainingCapacity()); + assertEquals(Long.MAX_VALUE - actual.length, + encrypter.getRemainingCapacity()); } @Test @@ -97,15 +99,16 @@ public class ConnectionEncrypterImplTest extends BriarTestCase { out.write(tag1); out.write(ciphertext1); byte[] expected = out.toByteArray(); - // Use a ConnectionEncrypter to encrypt the plaintext + // Use the encryption layer to encrypt the plaintext out.reset(); - ConnectionEncrypter e = new ConnectionEncrypterImpl(out, Long.MAX_VALUE, - tagCipher, frameCipher, tagKey, frameKey, true); - e.writeFrame(plaintext, plaintext.length); - e.writeFrame(plaintext1, plaintext1.length); + OutgoingEncryptionLayer encrypter = new OutgoingEncryptionLayerImpl(out, + Long.MAX_VALUE, tagCipher, frameCipher, tagKey, frameKey, true); + encrypter.writeFrame(plaintext, plaintext.length); + encrypter.writeFrame(plaintext1, plaintext1.length); byte[] actual = out.toByteArray(); // Check that the actual ciphertext matches the expected ciphertext assertArrayEquals(expected, actual); - assertEquals(Long.MAX_VALUE - actual.length, e.getRemainingCapacity()); + assertEquals(Long.MAX_VALUE - actual.length, + encrypter.getRemainingCapacity()); } } diff --git a/test/net/sf/briar/transport/SegmentedConnectionEncrypterTest.java b/test/net/sf/briar/transport/OutgoingSegmentedEncryptionLayerTest.java similarity index 80% rename from test/net/sf/briar/transport/SegmentedConnectionEncrypterTest.java rename to test/net/sf/briar/transport/OutgoingSegmentedEncryptionLayerTest.java index ab981dbef2d85f5cc18ccabca781c9ae690d62c1..ecbbbc1c68ed981bbdd92fea0af047d25330ed95 100644 --- a/test/net/sf/briar/transport/SegmentedConnectionEncrypterTest.java +++ b/test/net/sf/briar/transport/OutgoingSegmentedEncryptionLayerTest.java @@ -21,14 +21,14 @@ import org.junit.Test; import com.google.inject.Guice; import com.google.inject.Injector; -public class SegmentedConnectionEncrypterTest extends BriarTestCase { +public class OutgoingSegmentedEncryptionLayerTest extends BriarTestCase { private static final int MAC_LENGTH = 32; private final Cipher tagCipher, frameCipher; private final ErasableKey tagKey, frameKey; - public SegmentedConnectionEncrypterTest() { + public OutgoingSegmentedEncryptionLayerTest() { super(); Injector i = Guice.createInjector(new CryptoModule()); CryptoComponent crypto = i.getInstance(CryptoComponent.class); @@ -61,18 +61,19 @@ public class SegmentedConnectionEncrypterTest extends BriarTestCase { out.write(ciphertext); out.write(ciphertext1); byte[] expected = out.toByteArray(); - // Use a connection encrypter to encrypt the plaintext + // Use the encryption layer to encrypt the plaintext ByteArraySegmentSink sink = new ByteArraySegmentSink(); - ConnectionEncrypter e = new SegmentedConnectionEncrypter(sink, - Long.MAX_VALUE, tagCipher, frameCipher, tagKey, frameKey, - false); + OutgoingEncryptionLayer encrypter = + new OutgoingSegmentedEncryptionLayer(sink, Long.MAX_VALUE, + tagCipher, frameCipher, tagKey, frameKey, false); // The first frame's buffer must have enough space for the tag - e.writeFrame(plaintext, plaintext.length); - e.writeFrame(plaintext1, plaintext1.length); + encrypter.writeFrame(plaintext, plaintext.length); + encrypter.writeFrame(plaintext1, plaintext1.length); byte[] actual = out.toByteArray(); // Check that the actual ciphertext matches the expected ciphertext assertArrayEquals(expected, actual); - assertEquals(Long.MAX_VALUE - actual.length, e.getRemainingCapacity()); + assertEquals(Long.MAX_VALUE - actual.length, + encrypter.getRemainingCapacity()); } @Test @@ -102,16 +103,18 @@ public class SegmentedConnectionEncrypterTest extends BriarTestCase { out.write(tag1); out.write(ciphertext1); byte[] expected = out.toByteArray(); - // Use a connection encrypter to encrypt the plaintext + // Use the encryption layer to encrypt the plaintext SegmentSink sink = new ByteArraySegmentSink(); - ConnectionEncrypter e = new SegmentedConnectionEncrypter(sink, - Long.MAX_VALUE, tagCipher, frameCipher, tagKey, frameKey, true); - e.writeFrame(plaintext, plaintext.length); - e.writeFrame(plaintext1, plaintext1.length); + OutgoingEncryptionLayer encrypter = + new OutgoingSegmentedEncryptionLayer(sink, Long.MAX_VALUE, + tagCipher, frameCipher, tagKey, frameKey, true); + encrypter.writeFrame(plaintext, plaintext.length); + encrypter.writeFrame(plaintext1, plaintext1.length); byte[] actual = out.toByteArray(); // Check that the actual ciphertext matches the expected ciphertext assertArrayEquals(expected, actual); - assertEquals(Long.MAX_VALUE - actual.length, e.getRemainingCapacity()); + assertEquals(Long.MAX_VALUE - actual.length, + encrypter.getRemainingCapacity()); } private static class ByteArraySegmentSink extends ByteArrayOutputStream