mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-15 20:29:52 +01:00
Offer IDs no longer need to be calculated or echoed in requests.
The initiator flag in the transport protocol makes this unnecessary by linking the two sides of a stream-mode connection, making it impossible for an attacker to replay the responder's side of a different connection.
This commit is contained in:
@@ -27,7 +27,6 @@ import net.sf.briar.api.protocol.Message;
|
||||
import net.sf.briar.api.protocol.MessageEncoder;
|
||||
import net.sf.briar.api.protocol.MessageId;
|
||||
import net.sf.briar.api.protocol.Offer;
|
||||
import net.sf.briar.api.protocol.OfferId;
|
||||
import net.sf.briar.api.protocol.ProtocolReader;
|
||||
import net.sf.briar.api.protocol.ProtocolReaderFactory;
|
||||
import net.sf.briar.api.protocol.Request;
|
||||
@@ -79,7 +78,6 @@ public class FileReadWriteTest extends TestCase {
|
||||
private final Message message, message1, message2, message3;
|
||||
private final String authorName = "Alice";
|
||||
private final String messageBody = "Hello world";
|
||||
private final OfferId offerId;
|
||||
private final Map<String, Map<String, String>> transports;
|
||||
|
||||
public FileReadWriteTest() throws Exception {
|
||||
@@ -120,7 +118,6 @@ public class FileReadWriteTest extends TestCase {
|
||||
message3 = messageEncoder.encodeMessage(MessageId.NONE, group1,
|
||||
groupKeyPair.getPrivate(), author, authorKeyPair.getPrivate(),
|
||||
messageBody.getBytes("UTF-8"));
|
||||
offerId = new OfferId(TestUtils.getRandomId());
|
||||
transports = Collections.singletonMap("foo",
|
||||
Collections.singletonMap("bar", "baz"));
|
||||
}
|
||||
@@ -160,7 +157,7 @@ public class FileReadWriteTest extends TestCase {
|
||||
BitSet requested = new BitSet(4);
|
||||
requested.set(1);
|
||||
requested.set(3);
|
||||
r.writeRequest(offerId, requested, 4);
|
||||
r.writeRequest(requested, 4);
|
||||
|
||||
SubscriptionWriter s =
|
||||
protocolWriterFactory.createSubscriptionWriter(out);
|
||||
@@ -229,7 +226,6 @@ public class FileReadWriteTest extends TestCase {
|
||||
// Read the request
|
||||
assertTrue(protocolReader.hasRequest());
|
||||
Request req = protocolReader.readRequest();
|
||||
assertEquals(offerId, req.getOfferId());
|
||||
BitSet requested = req.getBitmap();
|
||||
assertFalse(requested.get(0));
|
||||
assertTrue(requested.get(1));
|
||||
|
||||
@@ -25,7 +25,6 @@ import net.sf.briar.api.protocol.GroupId;
|
||||
import net.sf.briar.api.protocol.Message;
|
||||
import net.sf.briar.api.protocol.MessageId;
|
||||
import net.sf.briar.api.protocol.Offer;
|
||||
import net.sf.briar.api.protocol.OfferId;
|
||||
import net.sf.briar.api.protocol.SubscriptionUpdate;
|
||||
import net.sf.briar.api.protocol.TransportUpdate;
|
||||
import net.sf.briar.api.protocol.writers.AckWriter;
|
||||
@@ -50,7 +49,6 @@ public abstract class DatabaseComponentTest extends TestCase {
|
||||
protected final ContactId contactId;
|
||||
protected final GroupId groupId;
|
||||
protected final MessageId messageId, parentId;
|
||||
protected final OfferId offerId;
|
||||
private final long timestamp;
|
||||
private final int size;
|
||||
private final byte[] raw;
|
||||
@@ -67,7 +65,6 @@ public abstract class DatabaseComponentTest extends TestCase {
|
||||
groupId = new GroupId(TestUtils.getRandomId());
|
||||
messageId = new MessageId(TestUtils.getRandomId());
|
||||
parentId = new MessageId(TestUtils.getRandomId());
|
||||
offerId = new OfferId(TestUtils.getRandomId());
|
||||
timestamp = System.currentTimeMillis();
|
||||
size = 1234;
|
||||
raw = new byte[size];
|
||||
@@ -1036,9 +1033,7 @@ public abstract class DatabaseComponentTest extends TestCase {
|
||||
will(returnValue(true)); // Visible - do not request message # 1
|
||||
oneOf(database).setStatusSeenIfVisible(txn, contactId, messageId2);
|
||||
will(returnValue(false)); // Not visible - request message # 2
|
||||
oneOf(offer).getId();
|
||||
will(returnValue(offerId));
|
||||
oneOf(requestWriter).writeRequest(offerId, expectedRequest, 3);
|
||||
oneOf(requestWriter).writeRequest(expectedRequest, 3);
|
||||
}});
|
||||
DatabaseComponent db = createDatabaseComponent(database, cleaner);
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@ import net.sf.briar.api.protocol.Message;
|
||||
import net.sf.briar.api.protocol.MessageEncoder;
|
||||
import net.sf.briar.api.protocol.MessageId;
|
||||
import net.sf.briar.api.protocol.Offer;
|
||||
import net.sf.briar.api.protocol.OfferId;
|
||||
import net.sf.briar.api.protocol.ProtocolReader;
|
||||
import net.sf.briar.api.protocol.ProtocolReaderFactory;
|
||||
import net.sf.briar.api.protocol.Request;
|
||||
@@ -47,7 +46,6 @@ public class ProtocolReadWriteTest extends TestCase {
|
||||
private final Group group;
|
||||
private final Message message;
|
||||
private final String messageBody = "Hello world";
|
||||
private final OfferId offerId;
|
||||
private final BitSet bitSet;
|
||||
private final Map<Group, Long> subscriptions;
|
||||
private final Map<String, Map<String, String>> transports;
|
||||
@@ -65,7 +63,6 @@ public class ProtocolReadWriteTest extends TestCase {
|
||||
MessageEncoder messageEncoder = i.getInstance(MessageEncoder.class);
|
||||
message = messageEncoder.encodeMessage(MessageId.NONE, group,
|
||||
messageBody.getBytes("UTF-8"));
|
||||
offerId = new OfferId(TestUtils.getRandomId());
|
||||
bitSet = new BitSet();
|
||||
bitSet.set(3);
|
||||
bitSet.set(7);
|
||||
@@ -92,7 +89,7 @@ public class ProtocolReadWriteTest extends TestCase {
|
||||
o.finish();
|
||||
|
||||
RequestWriter r = writerFactory.createRequestWriter(out);
|
||||
r.writeRequest(offerId, bitSet, 10);
|
||||
r.writeRequest(bitSet, 10);
|
||||
|
||||
SubscriptionWriter s = writerFactory.createSubscriptionWriter(out);
|
||||
s.writeSubscriptions(subscriptions, timestamp);
|
||||
|
||||
@@ -6,11 +6,9 @@ import java.util.BitSet;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import net.sf.briar.api.FormatException;
|
||||
import net.sf.briar.api.protocol.OfferId;
|
||||
import net.sf.briar.api.protocol.ProtocolConstants;
|
||||
import net.sf.briar.api.protocol.Request;
|
||||
import net.sf.briar.api.protocol.Tags;
|
||||
import net.sf.briar.api.protocol.UniqueId;
|
||||
import net.sf.briar.api.serial.Reader;
|
||||
import net.sf.briar.api.serial.ReaderFactory;
|
||||
import net.sf.briar.api.serial.Writer;
|
||||
@@ -41,8 +39,7 @@ public class RequestReaderTest extends TestCase {
|
||||
@Test
|
||||
public void testFormatExceptionIfRequestIsTooLarge() throws Exception {
|
||||
RequestFactory requestFactory = context.mock(RequestFactory.class);
|
||||
RequestReader requestReader =
|
||||
new RequestReader(new OfferIdReader(), requestFactory);
|
||||
RequestReader requestReader = new RequestReader(requestFactory);
|
||||
|
||||
byte[] b = createRequest(true);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
||||
@@ -60,12 +57,10 @@ public class RequestReaderTest extends TestCase {
|
||||
public void testNoFormatExceptionIfRequestIsMaximumSize() throws Exception {
|
||||
final RequestFactory requestFactory =
|
||||
context.mock(RequestFactory.class);
|
||||
RequestReader requestReader =
|
||||
new RequestReader(new OfferIdReader(), requestFactory);
|
||||
RequestReader requestReader = new RequestReader(requestFactory);
|
||||
final Request request = context.mock(Request.class);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(requestFactory).createRequest(with(any(OfferId.class)),
|
||||
with(any(BitSet.class)));
|
||||
oneOf(requestFactory).createRequest(with(any(BitSet.class)));
|
||||
will(returnValue(request));
|
||||
}});
|
||||
|
||||
@@ -101,8 +96,8 @@ public class RequestReaderTest extends TestCase {
|
||||
// Deserialise the request
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
||||
Reader reader = readerFactory.createReader(in);
|
||||
RequestReader requestReader = new RequestReader(new OfferIdReader(),
|
||||
new RequestFactoryImpl());
|
||||
RequestReader requestReader =
|
||||
new RequestReader(new RequestFactoryImpl());
|
||||
reader.addObjectReader(Tags.REQUEST, requestReader);
|
||||
Request r = reader.readUserDefined(Tags.REQUEST, Request.class);
|
||||
BitSet decoded = r.getBitmap();
|
||||
@@ -121,14 +116,9 @@ public class RequestReaderTest extends TestCase {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
Writer w = writerFactory.createWriter(out);
|
||||
w.writeUserDefinedTag(Tags.REQUEST);
|
||||
w.writeUserDefinedTag(Tags.OFFER_ID);
|
||||
w.writeBytes(new byte[UniqueId.LENGTH]);
|
||||
// Allow one byte for the REQUEST tag, one byte for the OFFER_ID tag,
|
||||
// one byte for the BYTES tag, one byte for the length as a uint7,
|
||||
// UniqueID.LENGTH bytes for the offer ID, one byte for the BYTES tag,
|
||||
// Allow one byte for the REQUEST tag, one byte for the BYTES tag,
|
||||
// and five bytes for the length as an int32
|
||||
int overhead = UniqueId.LENGTH + 10;
|
||||
int size = ProtocolConstants.MAX_PACKET_LENGTH - overhead;
|
||||
int size = ProtocolConstants.MAX_PACKET_LENGTH - 7;
|
||||
if(tooBig) size++;
|
||||
w.writeBytes(new byte[size]);
|
||||
assertEquals(tooBig, out.size() > ProtocolConstants.MAX_PACKET_LENGTH);
|
||||
@@ -139,8 +129,6 @@ public class RequestReaderTest extends TestCase {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
Writer w = writerFactory.createWriter(out);
|
||||
w.writeUserDefinedTag(Tags.REQUEST);
|
||||
w.writeUserDefinedTag(Tags.OFFER_ID);
|
||||
w.writeBytes(new byte[UniqueId.LENGTH]);
|
||||
w.writeBytes(bitmap);
|
||||
return out.toByteArray();
|
||||
}
|
||||
|
||||
@@ -108,8 +108,7 @@ public class ConstantsTest extends TestCase {
|
||||
// Create an offer with the maximum number of message IDs
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream(
|
||||
ProtocolConstants.MAX_PACKET_LENGTH);
|
||||
OfferWriter o = new OfferWriterImpl(out, writerFactory,
|
||||
crypto.getMessageDigest());
|
||||
OfferWriter o = new OfferWriterImpl(out, writerFactory);
|
||||
for(int i = 0; i < Offer.MAX_IDS_PER_OFFER; i++) {
|
||||
assertTrue(o.writeMessageId(new MessageId(
|
||||
TestUtils.getRandomId())));
|
||||
|
||||
@@ -5,8 +5,6 @@ import java.io.IOException;
|
||||
import java.util.BitSet;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import net.sf.briar.api.protocol.OfferId;
|
||||
import net.sf.briar.api.protocol.UniqueId;
|
||||
import net.sf.briar.api.protocol.writers.RequestWriter;
|
||||
import net.sf.briar.api.serial.WriterFactory;
|
||||
import net.sf.briar.serial.SerialModule;
|
||||
@@ -20,13 +18,11 @@ import com.google.inject.Injector;
|
||||
public class RequestWriterImplTest extends TestCase {
|
||||
|
||||
private final WriterFactory writerFactory;
|
||||
private final OfferId offerId;
|
||||
|
||||
public RequestWriterImplTest() {
|
||||
super();
|
||||
Injector i = Guice.createInjector(new SerialModule());
|
||||
writerFactory = i.getInstance(WriterFactory.class);
|
||||
offerId = new OfferId(new byte[UniqueId.LENGTH]);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -45,14 +41,10 @@ public class RequestWriterImplTest extends TestCase {
|
||||
b.set(11);
|
||||
b.set(12);
|
||||
b.set(15);
|
||||
r.writeRequest(offerId, b, 16);
|
||||
// Short user tag 11, short user tag 10, bytes with length 32 as a
|
||||
// uint7, 32 zero bytes, short bytes with length 2, 0xD959
|
||||
r.writeRequest(b, 16);
|
||||
// Short user tag 11, short bytes with length 2, 0xD959
|
||||
byte[] output = out.toByteArray();
|
||||
assertEquals("CB" + "CA" + "F6" + "20"
|
||||
+ "00000000000000000000000000000000"
|
||||
+ "00000000000000000000000000000000"
|
||||
+ "92" + "D959", StringUtils.toHexString(output));
|
||||
assertEquals("CB" + "92" + "D959", StringUtils.toHexString(output));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -70,13 +62,9 @@ public class RequestWriterImplTest extends TestCase {
|
||||
b.set(9);
|
||||
b.set(11);
|
||||
b.set(12);
|
||||
r.writeRequest(offerId, b, 13);
|
||||
// Short user tag 11, short user tag 10, bytes with length 32 as a
|
||||
// uint7, 32 zero bytes, short bytes with length 2, 0x59D8
|
||||
r.writeRequest(b, 13);
|
||||
// Short user tag 11, short bytes with length 2, 0x59D8
|
||||
byte[] output = out.toByteArray();
|
||||
assertEquals("CB" + "CA" + "F6" + "20"
|
||||
+ "00000000000000000000000000000000"
|
||||
+ "00000000000000000000000000000000"
|
||||
+ "92" + "59D8", StringUtils.toHexString(output));
|
||||
assertEquals("CB" + "92" + "59D8", StringUtils.toHexString(output));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user