mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-19 22:29:53 +01:00
Removed tag from connection context.
This commit is contained in:
@@ -7,15 +7,14 @@ public class ConnectionContext {
|
|||||||
|
|
||||||
private final ContactId contactId;
|
private final ContactId contactId;
|
||||||
private final TransportId transportId;
|
private final TransportId transportId;
|
||||||
private final byte[] tag, secret;
|
private final byte[] secret;
|
||||||
private final long connection;
|
private final long connection;
|
||||||
private final boolean alice;
|
private final boolean alice;
|
||||||
|
|
||||||
public ConnectionContext(ContactId contactId, TransportId transportId,
|
public ConnectionContext(ContactId contactId, TransportId transportId,
|
||||||
byte[] tag, byte[] secret, long connection, boolean alice) {
|
byte[] secret, long connection, boolean alice) {
|
||||||
this.contactId = contactId;
|
this.contactId = contactId;
|
||||||
this.transportId = transportId;
|
this.transportId = transportId;
|
||||||
this.tag = tag;
|
|
||||||
this.secret = secret;
|
this.secret = secret;
|
||||||
this.connection = connection;
|
this.connection = connection;
|
||||||
this.alice = alice;
|
this.alice = alice;
|
||||||
@@ -29,10 +28,6 @@ public class ConnectionContext {
|
|||||||
return transportId;
|
return transportId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] getTag() {
|
|
||||||
return tag;
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte[] getSecret() {
|
public byte[] getSecret() {
|
||||||
return secret;
|
return secret;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,8 +5,7 @@ import java.io.InputStream;
|
|||||||
public interface ConnectionReaderFactory {
|
public interface ConnectionReaderFactory {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a connection reader for a simplex connection or one side of a
|
* Creates a connection reader for one side of a connection.
|
||||||
* duplex connection. The secret is erased before this method returns.
|
|
||||||
*/
|
*/
|
||||||
ConnectionReader createConnectionReader(InputStream in,
|
ConnectionReader createConnectionReader(InputStream in,
|
||||||
ConnectionContext ctx, boolean initiator);
|
ConnectionContext ctx, boolean initiator);
|
||||||
|
|||||||
@@ -5,8 +5,7 @@ import java.io.OutputStream;
|
|||||||
public interface ConnectionWriterFactory {
|
public interface ConnectionWriterFactory {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a connection writer for a simplex connection or one side of a
|
* Creates a connection writer for one side of a connection.
|
||||||
* duplex connection. The secret is erased before this method returns.
|
|
||||||
*/
|
*/
|
||||||
ConnectionWriter createConnectionWriter(OutputStream out, long capacity,
|
ConnectionWriter createConnectionWriter(OutputStream out, long capacity,
|
||||||
ConnectionContext ctx, boolean initiator);
|
ConnectionContext ctx, boolean initiator);
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
package net.sf.briar.transport;
|
package net.sf.briar.transport;
|
||||||
|
|
||||||
import static net.sf.briar.api.transport.TransportConstants.MAX_FRAME_LENGTH;
|
import static net.sf.briar.api.transport.TransportConstants.MAX_FRAME_LENGTH;
|
||||||
|
import static net.sf.briar.api.transport.TransportConstants.TAG_LENGTH;
|
||||||
|
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
|
||||||
|
import javax.crypto.Cipher;
|
||||||
|
|
||||||
import net.sf.briar.api.crypto.CryptoComponent;
|
import net.sf.briar.api.crypto.CryptoComponent;
|
||||||
import net.sf.briar.api.crypto.ErasableKey;
|
import net.sf.briar.api.crypto.ErasableKey;
|
||||||
import net.sf.briar.api.transport.ConnectionContext;
|
import net.sf.briar.api.transport.ConnectionContext;
|
||||||
@@ -30,9 +33,12 @@ class ConnectionWriterFactoryImpl implements ConnectionWriterFactory {
|
|||||||
initiator);
|
initiator);
|
||||||
FrameWriter encryption;
|
FrameWriter encryption;
|
||||||
if(initiator) {
|
if(initiator) {
|
||||||
|
byte[] tag = new byte[TAG_LENGTH];
|
||||||
|
Cipher tagCipher = crypto.getTagCipher();
|
||||||
|
ErasableKey tagKey = crypto.deriveTagKey(secret, alice);
|
||||||
|
TagEncoder.encodeTag(tag, tagCipher, tagKey, connection);
|
||||||
encryption = new OutgoingEncryptionLayer(out, capacity,
|
encryption = new OutgoingEncryptionLayer(out, capacity,
|
||||||
crypto.getFrameCipher(), frameKey, MAX_FRAME_LENGTH,
|
crypto.getFrameCipher(), frameKey, MAX_FRAME_LENGTH, tag);
|
||||||
ctx.getTag());
|
|
||||||
} else {
|
} else {
|
||||||
encryption = new OutgoingEncryptionLayer(out, capacity,
|
encryption = new OutgoingEncryptionLayer(out, capacity,
|
||||||
crypto.getFrameCipher(), frameKey, MAX_FRAME_LENGTH);
|
crypto.getFrameCipher(), frameKey, MAX_FRAME_LENGTH);
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ class TransportConnectionRecogniser {
|
|||||||
assert old == null;
|
assert old == null;
|
||||||
} else {
|
} else {
|
||||||
ConnectionContext ctx1 = new ConnectionContext(contactId,
|
ConnectionContext ctx1 = new ConnectionContext(contactId,
|
||||||
transportId, tag1, secret, connection1, alice);
|
transportId, secret, connection1, alice);
|
||||||
WindowContext wctx1 = new WindowContext(window, ctx1, period);
|
WindowContext wctx1 = new WindowContext(window, ctx1, period);
|
||||||
WindowContext old = tagMap.put(new Bytes(tag1), wctx1);
|
WindowContext old = tagMap.put(new Bytes(tag1), wctx1);
|
||||||
assert old == null;
|
assert old == null;
|
||||||
@@ -83,7 +83,7 @@ class TransportConnectionRecogniser {
|
|||||||
byte[] tag = new byte[TAG_LENGTH];
|
byte[] tag = new byte[TAG_LENGTH];
|
||||||
TagEncoder.encodeTag(tag, cipher, key, connection);
|
TagEncoder.encodeTag(tag, cipher, key, connection);
|
||||||
ConnectionContext ctx = new ConnectionContext(contactId,
|
ConnectionContext ctx = new ConnectionContext(contactId,
|
||||||
transportId, tag, secret, connection, alice);
|
transportId, secret, connection, alice);
|
||||||
WindowContext wctx = new WindowContext(window, ctx, period);
|
WindowContext wctx = new WindowContext(window, ctx, period);
|
||||||
WindowContext old = tagMap.put(new Bytes(tag), wctx);
|
WindowContext old = tagMap.put(new Bytes(tag), wctx);
|
||||||
assert old == null;
|
assert old == null;
|
||||||
|
|||||||
@@ -141,9 +141,8 @@ public class ProtocolIntegrationTest extends BriarTestCase {
|
|||||||
|
|
||||||
private byte[] write() throws Exception {
|
private byte[] write() throws Exception {
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
byte[] tag = new byte[TAG_LENGTH];
|
|
||||||
ConnectionContext ctx = new ConnectionContext(contactId, transportId,
|
ConnectionContext ctx = new ConnectionContext(contactId, transportId,
|
||||||
tag, secret.clone(), 0L, true);
|
secret.clone(), 0L, true);
|
||||||
ConnectionWriter conn = connectionWriterFactory.createConnectionWriter(
|
ConnectionWriter conn = connectionWriterFactory.createConnectionWriter(
|
||||||
out, Long.MAX_VALUE, ctx, true);
|
out, Long.MAX_VALUE, ctx, true);
|
||||||
OutputStream out1 = conn.getOutputStream();
|
OutputStream out1 = conn.getOutputStream();
|
||||||
@@ -192,7 +191,7 @@ public class ProtocolIntegrationTest extends BriarTestCase {
|
|||||||
assertEquals(TAG_LENGTH, in.read(tag, 0, TAG_LENGTH));
|
assertEquals(TAG_LENGTH, in.read(tag, 0, TAG_LENGTH));
|
||||||
assertArrayEquals(new byte[TAG_LENGTH], tag);
|
assertArrayEquals(new byte[TAG_LENGTH], tag);
|
||||||
ConnectionContext ctx = new ConnectionContext(contactId, transportId,
|
ConnectionContext ctx = new ConnectionContext(contactId, transportId,
|
||||||
tag, secret.clone(), 0L, true);
|
secret.clone(), 0L, true);
|
||||||
ConnectionReader conn = connectionReaderFactory.createConnectionReader(
|
ConnectionReader conn = connectionReaderFactory.createConnectionReader(
|
||||||
in, ctx, true);
|
in, ctx, true);
|
||||||
InputStream in1 = conn.getInputStream();
|
InputStream in1 = conn.getInputStream();
|
||||||
|
|||||||
@@ -91,9 +91,8 @@ public class OutgoingSimplexConnectionTest extends BriarTestCase {
|
|||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
TestSimplexTransportWriter transport = new TestSimplexTransportWriter(
|
TestSimplexTransportWriter transport = new TestSimplexTransportWriter(
|
||||||
out, MAX_PACKET_LENGTH, true);
|
out, MAX_PACKET_LENGTH, true);
|
||||||
byte[] tag = new byte[TAG_LENGTH];
|
|
||||||
ConnectionContext ctx = new ConnectionContext(contactId, transportId,
|
ConnectionContext ctx = new ConnectionContext(contactId, transportId,
|
||||||
tag, secret, 0L, true);
|
secret, 0L, true);
|
||||||
OutgoingSimplexConnection connection = new OutgoingSimplexConnection(db,
|
OutgoingSimplexConnection connection = new OutgoingSimplexConnection(db,
|
||||||
connRegistry, connFactory, protoFactory, ctx, transport);
|
connRegistry, connFactory, protoFactory, ctx, transport);
|
||||||
connection.write();
|
connection.write();
|
||||||
@@ -109,9 +108,8 @@ public class OutgoingSimplexConnectionTest extends BriarTestCase {
|
|||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
TestSimplexTransportWriter transport = new TestSimplexTransportWriter(
|
TestSimplexTransportWriter transport = new TestSimplexTransportWriter(
|
||||||
out, MIN_CONNECTION_LENGTH, true);
|
out, MIN_CONNECTION_LENGTH, true);
|
||||||
byte[] tag = new byte[TAG_LENGTH];
|
|
||||||
ConnectionContext ctx = new ConnectionContext(contactId, transportId,
|
ConnectionContext ctx = new ConnectionContext(contactId, transportId,
|
||||||
tag, secret, 0L, true);
|
secret, 0L, true);
|
||||||
OutgoingSimplexConnection connection = new OutgoingSimplexConnection(db,
|
OutgoingSimplexConnection connection = new OutgoingSimplexConnection(db,
|
||||||
connRegistry, connFactory, protoFactory, ctx, transport);
|
connRegistry, connFactory, protoFactory, ctx, transport);
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
@@ -142,9 +140,8 @@ public class OutgoingSimplexConnectionTest extends BriarTestCase {
|
|||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
TestSimplexTransportWriter transport = new TestSimplexTransportWriter(
|
TestSimplexTransportWriter transport = new TestSimplexTransportWriter(
|
||||||
out, MIN_CONNECTION_LENGTH, true);
|
out, MIN_CONNECTION_LENGTH, true);
|
||||||
byte[] tag = new byte[TAG_LENGTH];
|
|
||||||
ConnectionContext ctx = new ConnectionContext(contactId, transportId,
|
ConnectionContext ctx = new ConnectionContext(contactId, transportId,
|
||||||
tag, secret, 0L, true);
|
secret, 0L, true);
|
||||||
OutgoingSimplexConnection connection = new OutgoingSimplexConnection(db,
|
OutgoingSimplexConnection connection = new OutgoingSimplexConnection(db,
|
||||||
connRegistry, connFactory, protoFactory, ctx, transport);
|
connRegistry, connFactory, protoFactory, ctx, transport);
|
||||||
final Ack ack = context.mock(Ack.class);
|
final Ack ack = context.mock(Ack.class);
|
||||||
|
|||||||
@@ -115,10 +115,8 @@ public class SimplexProtocolIntegrationTest extends BriarTestCase {
|
|||||||
alice.getInstance(ProtocolWriterFactory.class);
|
alice.getInstance(ProtocolWriterFactory.class);
|
||||||
TestSimplexTransportWriter transport = new TestSimplexTransportWriter(
|
TestSimplexTransportWriter transport = new TestSimplexTransportWriter(
|
||||||
out, Long.MAX_VALUE, false);
|
out, Long.MAX_VALUE, false);
|
||||||
// FIXME: Encode the tag
|
|
||||||
byte[] tag = new byte[TAG_LENGTH];
|
|
||||||
ConnectionContext ctx = new ConnectionContext(contactId, transportId,
|
ConnectionContext ctx = new ConnectionContext(contactId, transportId,
|
||||||
tag, aliceToBobSecret, 0L, true);
|
aliceToBobSecret, 0L, true);
|
||||||
OutgoingSimplexConnection simplex = new OutgoingSimplexConnection(db,
|
OutgoingSimplexConnection simplex = new OutgoingSimplexConnection(db,
|
||||||
connRegistry, connFactory, protoFactory, ctx, transport);
|
connRegistry, connFactory, protoFactory, ctx, transport);
|
||||||
// Write whatever needs to be written
|
// Write whatever needs to be written
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package net.sf.briar.transport;
|
|||||||
|
|
||||||
import static net.sf.briar.api.protocol.ProtocolConstants.MAX_PACKET_LENGTH;
|
import static net.sf.briar.api.protocol.ProtocolConstants.MAX_PACKET_LENGTH;
|
||||||
import static net.sf.briar.api.transport.TransportConstants.MIN_CONNECTION_LENGTH;
|
import static net.sf.briar.api.transport.TransportConstants.MIN_CONNECTION_LENGTH;
|
||||||
import static net.sf.briar.api.transport.TransportConstants.TAG_LENGTH;
|
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
import static org.junit.Assert.assertArrayEquals;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
@@ -128,9 +127,8 @@ public class TransportIntegrationTest extends BriarTestCase {
|
|||||||
public void testOverheadWithTag() throws Exception {
|
public void testOverheadWithTag() throws Exception {
|
||||||
ByteArrayOutputStream out =
|
ByteArrayOutputStream out =
|
||||||
new ByteArrayOutputStream(MIN_CONNECTION_LENGTH);
|
new ByteArrayOutputStream(MIN_CONNECTION_LENGTH);
|
||||||
byte[] tag = new byte[TAG_LENGTH];
|
|
||||||
ConnectionContext ctx = new ConnectionContext(contactId, transportId,
|
ConnectionContext ctx = new ConnectionContext(contactId, transportId,
|
||||||
tag, secret, 0L, true);
|
secret, 0L, true);
|
||||||
ConnectionWriter w = connectionWriterFactory.createConnectionWriter(out,
|
ConnectionWriter w = connectionWriterFactory.createConnectionWriter(out,
|
||||||
MIN_CONNECTION_LENGTH, ctx, true);
|
MIN_CONNECTION_LENGTH, ctx, true);
|
||||||
// Check that the connection writer thinks there's room for a packet
|
// Check that the connection writer thinks there's room for a packet
|
||||||
@@ -151,7 +149,7 @@ public class TransportIntegrationTest extends BriarTestCase {
|
|||||||
ByteArrayOutputStream out =
|
ByteArrayOutputStream out =
|
||||||
new ByteArrayOutputStream(MIN_CONNECTION_LENGTH);
|
new ByteArrayOutputStream(MIN_CONNECTION_LENGTH);
|
||||||
ConnectionContext ctx = new ConnectionContext(contactId, transportId,
|
ConnectionContext ctx = new ConnectionContext(contactId, transportId,
|
||||||
null, secret, 0L, true);
|
secret, 0L, true);
|
||||||
ConnectionWriter w = connectionWriterFactory.createConnectionWriter(out,
|
ConnectionWriter w = connectionWriterFactory.createConnectionWriter(out,
|
||||||
MIN_CONNECTION_LENGTH, ctx, false);
|
MIN_CONNECTION_LENGTH, ctx, false);
|
||||||
// Check that the connection writer thinks there's room for a packet
|
// Check that the connection writer thinks there's room for a packet
|
||||||
|
|||||||
Reference in New Issue
Block a user