diff --git a/briar-api/src/org/briarproject/api/contact/ContactManager.java b/briar-api/src/org/briarproject/api/contact/ContactManager.java index a40a2b08c456db34f9b432795c2dfd01449fa54d..5573e3ea4591d342f8e33922903997e850c9eb38 100644 --- a/briar-api/src/org/briarproject/api/contact/ContactManager.java +++ b/briar-api/src/org/briarproject/api/contact/ContactManager.java @@ -45,11 +45,11 @@ public interface ContactManager { void setContactActive(ContactId c, boolean active) throws DbException; /** Return true if a contact with this name and public key already exists */ - boolean contactExists(Transaction txn, AuthorId remoteAuthorID, + boolean contactExists(Transaction txn, AuthorId remoteAuthorId, AuthorId localAuthorId) throws DbException; /** Return true if a contact with this name and public key already exists */ - boolean contactExists(AuthorId remoteAuthorID, AuthorId localAuthorId) + boolean contactExists(AuthorId remoteAuthorId, AuthorId localAuthorId) throws DbException; interface AddContactHook { diff --git a/briar-api/src/org/briarproject/api/introduction/IntroductionConstants.java b/briar-api/src/org/briarproject/api/introduction/IntroductionConstants.java index 64bc309830b2f18ea2e17d8f115a842c2970b6fe..1ccf2d48053a8f14e2151202982b580493370e71 100644 --- a/briar-api/src/org/briarproject/api/introduction/IntroductionConstants.java +++ b/briar-api/src/org/briarproject/api/introduction/IntroductionConstants.java @@ -23,7 +23,6 @@ public interface IntroductionConstants { String MSG = "msg"; String ACCEPT = "accept"; String TIME = "time"; - String DEVICE_ID = "deviceId"; String TRANSPORT = "transport"; String MESSAGE_ID = "messageId"; String MESSAGE_TIME = "timestamp"; diff --git a/briar-api/src/org/briarproject/api/properties/TransportPropertyManager.java b/briar-api/src/org/briarproject/api/properties/TransportPropertyManager.java index 445329ba95a6100c1def5d4a9f87363c5b3a3f94..8b63ae612bc4705e779b44e503e57e810fed4ccf 100644 --- a/briar-api/src/org/briarproject/api/properties/TransportPropertyManager.java +++ b/briar-api/src/org/briarproject/api/properties/TransportPropertyManager.java @@ -1,6 +1,5 @@ package org.briarproject.api.properties; -import org.briarproject.api.DeviceId; import org.briarproject.api.TransportId; import org.briarproject.api.contact.ContactId; import org.briarproject.api.db.DbException; @@ -14,7 +13,7 @@ public interface TransportPropertyManager { * Stores the given properties received while adding a contact - they will * be superseded by any properties synced from the contact. */ - void addRemoteProperties(Transaction txn, ContactId c, DeviceId dev, + void addRemoteProperties(Transaction txn, ContactId c, Map<TransportId, TransportProperties> props) throws DbException; /** Returns the local transport properties for all transports. */ diff --git a/briar-core/src/org/briarproject/db/JdbcDatabase.java b/briar-core/src/org/briarproject/db/JdbcDatabase.java index 536161562462bc9ce06144418701eb11d4b78510..475dbdc2ff87447739ffdd372dec1b82c4cb45ab 100644 --- a/briar-core/src/org/briarproject/db/JdbcDatabase.java +++ b/briar-core/src/org/briarproject/db/JdbcDatabase.java @@ -63,8 +63,8 @@ import static org.briarproject.db.ExponentialBackoff.calculateExpiry; */ abstract class JdbcDatabase implements Database<Connection> { - private static final int SCHEMA_VERSION = 22; - private static final int MIN_SCHEMA_VERSION = 22; + private static final int SCHEMA_VERSION = 23; + private static final int MIN_SCHEMA_VERSION = 23; private static final String CREATE_SETTINGS = "CREATE TABLE settings" diff --git a/briar-core/src/org/briarproject/introduction/IntroduceeEngine.java b/briar-core/src/org/briarproject/introduction/IntroduceeEngine.java index 7be3184086617a1e34fff0aab621b3f390e3fb3f..6f76540d081a4ef7baf314ead7d9709eccb4c664 100644 --- a/briar-core/src/org/briarproject/introduction/IntroduceeEngine.java +++ b/briar-core/src/org/briarproject/introduction/IntroduceeEngine.java @@ -34,7 +34,6 @@ import static org.briarproject.api.introduction.IntroduceeProtocolState.FINISHED import static org.briarproject.api.introduction.IntroductionConstants.ACCEPT; import static org.briarproject.api.introduction.IntroductionConstants.ANSWERED; import static org.briarproject.api.introduction.IntroductionConstants.CONTACT_ID_1; -import static org.briarproject.api.introduction.IntroductionConstants.DEVICE_ID; import static org.briarproject.api.introduction.IntroductionConstants.EXISTS; import static org.briarproject.api.introduction.IntroductionConstants.E_PUBLIC_KEY; import static org.briarproject.api.introduction.IntroductionConstants.GROUP_ID; @@ -108,7 +107,6 @@ public class IntroduceeEngine if (localState.getBoolean(ACCEPT)) { msg.put(TIME, localState.getLong(OUR_TIME)); msg.put(E_PUBLIC_KEY, localState.getRaw(OUR_PUBLIC_KEY)); - msg.put(DEVICE_ID, localAction.getRaw(DEVICE_ID)); msg.put(TRANSPORT, localAction.getDictionary(TRANSPORT)); } messages.add(msg); @@ -231,7 +229,6 @@ public class IntroduceeEngine if (msg.getBoolean(ACCEPT)) { localState.put(TIME, msg.getLong(TIME)); localState.put(E_PUBLIC_KEY, msg.getRaw(E_PUBLIC_KEY)); - localState.put(DEVICE_ID, msg.getRaw(DEVICE_ID)); localState.put(TRANSPORT, msg.getDictionary(TRANSPORT)); } } diff --git a/briar-core/src/org/briarproject/introduction/IntroduceeManager.java b/briar-core/src/org/briarproject/introduction/IntroduceeManager.java index 2049fba3ff5d636ee2acb8b48090184b3b77c715..be16ff1e495206ec06006de66e8e4708b808a19c 100644 --- a/briar-core/src/org/briarproject/introduction/IntroduceeManager.java +++ b/briar-core/src/org/briarproject/introduction/IntroduceeManager.java @@ -2,7 +2,6 @@ package org.briarproject.introduction; import org.briarproject.api.Bytes; -import org.briarproject.api.DeviceId; import org.briarproject.api.FormatException; import org.briarproject.api.TransportId; import org.briarproject.api.clients.ClientHelper; @@ -47,7 +46,6 @@ import static org.briarproject.api.introduction.IntroductionConstants.ADDED_CONT import static org.briarproject.api.introduction.IntroductionConstants.ANSWERED; import static org.briarproject.api.introduction.IntroductionConstants.CONTACT; import static org.briarproject.api.introduction.IntroductionConstants.CONTACT_ID_1; -import static org.briarproject.api.introduction.IntroductionConstants.DEVICE_ID; import static org.briarproject.api.introduction.IntroductionConstants.EXISTS; import static org.briarproject.api.introduction.IntroductionConstants.E_PUBLIC_KEY; import static org.briarproject.api.introduction.IntroductionConstants.GROUP_ID; @@ -167,7 +165,6 @@ class IntroduceeManager { // get data to connect and derive a shared secret later long now = clock.currentTimeMillis(); - byte[] deviceId = db.getDeviceId(txn).getBytes(); KeyPair keyPair = cryptoComponent.generateAgreementKeyPair(); byte[] publicKey = keyPair.getPublic().getEncoded(); byte[] privateKey = keyPair.getPrivate().getEncoded(); @@ -183,14 +180,12 @@ class IntroduceeManager { // define action BdfDictionary localAction = new BdfDictionary(); localAction.put(TYPE, TYPE_RESPONSE); - localAction.put(DEVICE_ID, deviceId); localAction.put(TRANSPORT, encodeTransportProperties(transportProperties)); // start engine and process its state update IntroduceeEngine engine = new IntroduceeEngine(); - processStateUpdate(txn, - engine.onLocalAction(state, localAction)); + processStateUpdate(txn, engine.onLocalAction(state, localAction)); } public void declineIntroduction(Transaction txn, final SessionId sessionId) @@ -313,11 +308,10 @@ class IntroduceeManager { localState.put(ADDED_CONTACT_ID, contactId.getInt()); // let the transport manager know how to connect to the contact - DeviceId deviceId = new DeviceId(localState.getRaw(DEVICE_ID)); Map<TransportId, TransportProperties> transportProperties = parseTransportProperties(localState); transportPropertyManager.addRemoteProperties(txn, contactId, - deviceId, transportProperties); + transportProperties); // delete the ephemeral private key by overwriting with NULL value // this ensures future ephemeral keys can not be recovered when diff --git a/briar-core/src/org/briarproject/introduction/IntroducerManager.java b/briar-core/src/org/briarproject/introduction/IntroducerManager.java index 1b35fc26c0363c8ccbde45b93accb2cdf165e30a..3cc906aedf32c085c132acd818a1152a773f19e2 100644 --- a/briar-core/src/org/briarproject/introduction/IntroducerManager.java +++ b/briar-core/src/org/briarproject/introduction/IntroducerManager.java @@ -20,8 +20,6 @@ import org.briarproject.util.StringUtils; import java.io.IOException; import java.util.logging.Logger; -import javax.inject.Inject; - import static java.util.logging.Level.WARNING; import static org.briarproject.api.introduction.IntroducerProtocolState.PREPARE_REQUESTS; import static org.briarproject.api.introduction.IntroductionConstants.AUTHOR_ID_1; diff --git a/briar-core/src/org/briarproject/introduction/IntroductionValidator.java b/briar-core/src/org/briarproject/introduction/IntroductionValidator.java index addf58ea49749522873ff662e506e42055d42dfa..b8af1be12f7e224b379ad7016f4a2e47bdde81cf 100644 --- a/briar-core/src/org/briarproject/introduction/IntroductionValidator.java +++ b/briar-core/src/org/briarproject/introduction/IntroductionValidator.java @@ -1,8 +1,6 @@ package org.briarproject.introduction; -import org.briarproject.api.DeviceId; import org.briarproject.api.FormatException; -import org.briarproject.api.TransportId; import org.briarproject.api.clients.ClientHelper; import org.briarproject.api.data.BdfDictionary; import org.briarproject.api.data.BdfList; @@ -13,10 +11,10 @@ import org.briarproject.api.sync.Message; import org.briarproject.api.system.Clock; import org.briarproject.clients.BdfMessageValidator; +import static org.briarproject.api.TransportId.MAX_TRANSPORT_ID_LENGTH; import static org.briarproject.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH; import static org.briarproject.api.identity.AuthorConstants.MAX_PUBLIC_KEY_LENGTH; import static org.briarproject.api.introduction.IntroductionConstants.ACCEPT; -import static org.briarproject.api.introduction.IntroductionConstants.DEVICE_ID; import static org.briarproject.api.introduction.IntroductionConstants.E_PUBLIC_KEY; import static org.briarproject.api.introduction.IntroductionConstants.MESSAGE_ID; import static org.briarproject.api.introduction.IntroductionConstants.MESSAGE_TIME; @@ -31,6 +29,7 @@ import static org.briarproject.api.introduction.IntroductionConstants.TYPE_ABORT import static org.briarproject.api.introduction.IntroductionConstants.TYPE_ACK; import static org.briarproject.api.introduction.IntroductionConstants.TYPE_REQUEST; import static org.briarproject.api.introduction.IntroductionConstants.TYPE_RESPONSE; +import static org.briarproject.api.properties.TransportPropertyConstants.MAX_PROPERTIES_PER_TRANSPORT; import static org.briarproject.api.properties.TransportPropertyConstants.MAX_PROPERTY_LENGTH; import static org.briarproject.api.sync.SyncConstants.MAX_MESSAGE_BODY_LENGTH; @@ -102,17 +101,16 @@ class IntroductionValidator extends BdfMessageValidator { private BdfDictionary validateResponse(BdfList message) throws FormatException { - checkSize(message, 3, 7); + checkSize(message, 3, 6); // parse accept/decline boolean accept = message.getBoolean(2); long time = 0; byte[] pubkey = null; - byte[] deviceId = null; BdfDictionary tp = new BdfDictionary(); if (accept) { - checkSize(message, 7); + checkSize(message, 6); // parse timestamp time = message.getLong(3); @@ -121,16 +119,13 @@ class IntroductionValidator extends BdfMessageValidator { pubkey = message.getRaw(4); checkLength(pubkey, 0, MAX_PUBLIC_KEY_LENGTH); - // parse device ID - deviceId = message.getRaw(5); - checkLength(deviceId, DeviceId.LENGTH); - // parse transport properties - tp = message.getDictionary(6); + tp = message.getDictionary(5); if (tp.size() < 1) throw new FormatException(); for (String tId : tp.keySet()) { - checkLength(tId, 1, TransportId.MAX_TRANSPORT_ID_LENGTH); + checkLength(tId, 1, MAX_TRANSPORT_ID_LENGTH); BdfDictionary tProps = tp.getDictionary(tId); + checkSize(tProps, MAX_PROPERTIES_PER_TRANSPORT); for (String propId : tProps.keySet()) { checkLength(propId, 0, MAX_PROPERTY_LENGTH); String prop = tProps.getString(propId); @@ -147,7 +142,6 @@ class IntroductionValidator extends BdfMessageValidator { if (accept) { d.put(TIME, time); d.put(E_PUBLIC_KEY, pubkey); - d.put(DEVICE_ID, deviceId); d.put(TRANSPORT, tp); } return d; diff --git a/briar-core/src/org/briarproject/introduction/MessageEncoder.java b/briar-core/src/org/briarproject/introduction/MessageEncoder.java index 87bf4d5e6a4e63a0a5d35f793d7e30b653020437..12153122cd51323d3975cfcbcc38b48fac39c15a 100644 --- a/briar-core/src/org/briarproject/introduction/MessageEncoder.java +++ b/briar-core/src/org/briarproject/introduction/MessageEncoder.java @@ -5,7 +5,6 @@ import org.briarproject.api.data.BdfDictionary; import org.briarproject.api.data.BdfList; import static org.briarproject.api.introduction.IntroductionConstants.ACCEPT; -import static org.briarproject.api.introduction.IntroductionConstants.DEVICE_ID; import static org.briarproject.api.introduction.IntroductionConstants.E_PUBLIC_KEY; import static org.briarproject.api.introduction.IntroductionConstants.MSG; import static org.briarproject.api.introduction.IntroductionConstants.NAME; @@ -21,7 +20,8 @@ import static org.briarproject.api.introduction.IntroductionConstants.TYPE_RESPO public class MessageEncoder { - public static BdfList encodeMessage(BdfDictionary d) throws FormatException { + public static BdfList encodeMessage(BdfDictionary d) + throws FormatException { BdfList body; long type = d.getLong(TYPE); @@ -39,7 +39,8 @@ public class MessageEncoder { return body; } - private static BdfList encodeRequest(BdfDictionary d) throws FormatException { + private static BdfList encodeRequest(BdfDictionary d) + throws FormatException { BdfList list = BdfList.of(TYPE_REQUEST, d.getRaw(SESSION_ID), d.getString(NAME), d.getRaw(PUBLIC_KEY)); @@ -49,14 +50,14 @@ public class MessageEncoder { return list; } - private static BdfList encodeResponse(BdfDictionary d) throws FormatException { + private static BdfList encodeResponse(BdfDictionary d) + throws FormatException { BdfList list = BdfList.of(TYPE_RESPONSE, d.getRaw(SESSION_ID), d.getBoolean(ACCEPT)); if (d.getBoolean(ACCEPT)) { list.add(d.getLong(TIME)); list.add(d.getRaw(E_PUBLIC_KEY)); - list.add(d.getRaw(DEVICE_ID)); list.add(d.getDictionary(TRANSPORT)); } // TODO Sign the response, see #256 diff --git a/briar-core/src/org/briarproject/properties/TransportPropertyManagerImpl.java b/briar-core/src/org/briarproject/properties/TransportPropertyManagerImpl.java index f393e3eaa29f9c49a88df097e189797d11e5d18c..5663b6151a823399eaf800f8031bdf2dfd281ea8 100644 --- a/briar-core/src/org/briarproject/properties/TransportPropertyManagerImpl.java +++ b/briar-core/src/org/briarproject/properties/TransportPropertyManagerImpl.java @@ -1,6 +1,5 @@ package org.briarproject.properties; -import org.briarproject.api.DeviceId; import org.briarproject.api.FormatException; import org.briarproject.api.TransportId; import org.briarproject.api.clients.Client; @@ -73,10 +72,9 @@ class TransportPropertyManagerImpl implements TransportPropertyManager, db.addGroup(txn, g); db.setVisibleToContact(txn, c.getId(), g.getId(), true); // Copy the latest local properties into the group - DeviceId dev = db.getDeviceId(txn); Map<TransportId, TransportProperties> local = getLocalProperties(txn); for (Entry<TransportId, TransportProperties> e : local.entrySet()) { - storeMessage(txn, g.getId(), dev, e.getKey(), e.getValue(), 1, + storeMessage(txn, g.getId(), e.getKey(), e.getValue(), 1, true, true); } } @@ -87,11 +85,11 @@ class TransportPropertyManagerImpl implements TransportPropertyManager, } @Override - public void addRemoteProperties(Transaction txn, ContactId c, DeviceId dev, + public void addRemoteProperties(Transaction txn, ContactId c, Map<TransportId, TransportProperties> props) throws DbException { Group g = getContactGroup(db.getContact(txn, c)); for (Entry<TransportId, TransportProperties> e : props.entrySet()) { - storeMessage(txn, g.getId(), dev, e.getKey(), e.getValue(), 0, + storeMessage(txn, g.getId(), e.getKey(), e.getValue(), 0, false, false); } } @@ -189,16 +187,15 @@ class TransportPropertyManagerImpl implements TransportPropertyManager, } if (changed) { // Store the merged properties in the local group - DeviceId dev = db.getDeviceId(txn); long version = latest == null ? 1 : latest.version + 1; - storeMessage(txn, localGroup.getId(), dev, t, merged, - version, true, false); + storeMessage(txn, localGroup.getId(), t, merged, version, + true, false); // Store the merged properties in each contact's group for (Contact c : db.getContacts(txn)) { Group g = getContactGroup(c); latest = findLatest(txn, g.getId(), t, true); version = latest == null ? 1 : latest.version + 1; - storeMessage(txn, g.getId(), dev, t, merged, version, + storeMessage(txn, g.getId(), t, merged, version, true, true); } } @@ -235,11 +232,11 @@ class TransportPropertyManagerImpl implements TransportPropertyManager, } } - private void storeMessage(Transaction txn, GroupId g, DeviceId dev, - TransportId t, TransportProperties p, long version, boolean local, - boolean shared) throws DbException { + private void storeMessage(Transaction txn, GroupId g, TransportId t, + TransportProperties p, long version, boolean local, boolean shared) + throws DbException { try { - BdfList body = encodeProperties(dev, t, p, version); + BdfList body = encodeProperties(t, p, version); long now = clock.currentTimeMillis(); Message m = clientHelper.createMessage(g, now, body); BdfDictionary meta = new BdfDictionary(); @@ -252,9 +249,9 @@ class TransportPropertyManagerImpl implements TransportPropertyManager, } } - private BdfList encodeProperties(DeviceId dev, TransportId t, - TransportProperties p, long version) { - return BdfList.of(dev, t.getString(), version, p); + private BdfList encodeProperties(TransportId t, TransportProperties p, + long version) { + return BdfList.of(t.getString(), version, p); } private Map<TransportId, LatestUpdate> findLatest(Transaction txn, @@ -295,8 +292,8 @@ class TransportPropertyManagerImpl implements TransportPropertyManager, private TransportProperties parseProperties(BdfList message) throws FormatException { - // Device ID, transport ID, version, properties - BdfDictionary dictionary = message.getDictionary(3); + // Transport ID, version, properties + BdfDictionary dictionary = message.getDictionary(2); TransportProperties p = new TransportProperties(); for (String key : dictionary.keySet()) p.put(key, dictionary.getString(key)); diff --git a/briar-core/src/org/briarproject/properties/TransportPropertyValidator.java b/briar-core/src/org/briarproject/properties/TransportPropertyValidator.java index b26775d7360abed07d1b69ec9a80b946f79071cb..fc40dd342a65ccc619fc7071119590270a66c6e4 100644 --- a/briar-core/src/org/briarproject/properties/TransportPropertyValidator.java +++ b/briar-core/src/org/briarproject/properties/TransportPropertyValidator.java @@ -1,7 +1,6 @@ package org.briarproject.properties; import org.briarproject.api.FormatException; -import org.briarproject.api.UniqueId; import org.briarproject.api.clients.ClientHelper; import org.briarproject.api.data.BdfDictionary; import org.briarproject.api.data.BdfList; @@ -25,19 +24,16 @@ public class TransportPropertyValidator extends BdfMessageValidator { @Override protected BdfDictionary validateMessage(Message m, Group g, BdfList body) throws FormatException { - // Device ID, transport ID, version, properties - checkSize(body, 4); - // Device ID - byte[] deviceId = body.getRaw(0); - checkLength(deviceId, UniqueId.LENGTH); + // Transport ID, version, properties + checkSize(body, 3); // Transport ID - String transportId = body.getString(1); + String transportId = body.getString(0); checkLength(transportId, 1, MAX_TRANSPORT_ID_LENGTH); // Version - long version = body.getLong(2); + long version = body.getLong(1); if (version < 0) throw new FormatException(); // Properties - BdfDictionary dictionary = body.getDictionary(3); + BdfDictionary dictionary = body.getDictionary(2); checkSize(dictionary, 0, MAX_PROPERTIES_PER_TRANSPORT); for (String key : dictionary.keySet()) { checkLength(key, 0, MAX_PROPERTY_LENGTH); diff --git a/briar-tests/src/org/briarproject/properties/TransportPropertyValidatorTest.java b/briar-tests/src/org/briarproject/properties/TransportPropertyValidatorTest.java index 94378cb0130a6d4c098e0d15d56b41e9bb334f7c..77a736018859ec608de9bded32b0dce61db5d21d 100644 --- a/briar-tests/src/org/briarproject/properties/TransportPropertyValidatorTest.java +++ b/briar-tests/src/org/briarproject/properties/TransportPropertyValidatorTest.java @@ -2,10 +2,8 @@ package org.briarproject.properties; import org.briarproject.BriarTestCase; import org.briarproject.TestUtils; -import org.briarproject.api.DeviceId; import org.briarproject.api.FormatException; import org.briarproject.api.TransportId; -import org.briarproject.api.UniqueId; import org.briarproject.api.clients.ClientHelper; import org.briarproject.api.data.BdfDictionary; import org.briarproject.api.data.BdfList; @@ -28,7 +26,6 @@ import static org.junit.Assert.assertEquals; public class TransportPropertyValidatorTest extends BriarTestCase { private final TransportId transportId; - private final DeviceId deviceId; private final BdfDictionary bdfDictionary; private final Group group; private final Message message; @@ -36,7 +33,6 @@ public class TransportPropertyValidatorTest extends BriarTestCase { public TransportPropertyValidatorTest() { transportId = new TransportId("test"); - deviceId = new DeviceId(TestUtils.getRandomId()); bdfDictionary = new BdfDictionary(); GroupId groupId = new GroupId(TestUtils.getRandomId()); @@ -61,54 +57,25 @@ public class TransportPropertyValidatorTest extends BriarTestCase { @Test public void testValidateProperMessage() throws IOException { - BdfList body = BdfList.of(deviceId, transportId.getString(), 4, - bdfDictionary); + BdfList body = BdfList.of(transportId.getString(), 4, bdfDictionary); BdfDictionary result = tpv.validateMessage(message, group, body); assertEquals("test", result.getString("transportId")); - assertEquals(result.getLong("version").longValue(), 4); + assertEquals(4, result.getLong("version").longValue()); } @Test(expected = FormatException.class) public void testValidateWrongVersionValue() throws IOException { - /* Will create a negative version number */ - BdfList body = BdfList.of(deviceId, transportId.getString(), -1, - bdfDictionary); + BdfList body = BdfList.of(transportId.getString(), -1, bdfDictionary); tpv.validateMessage(message, group, body); } @Test(expected = FormatException.class) public void testValidateWrongVersionType() throws IOException { - /* Instead of sending a version number I'm sending a dict */ - BdfList body = BdfList.of(deviceId, transportId.getString(), - bdfDictionary, bdfDictionary); - tpv.validateMessage(message, group, body); - } - - @Test(expected = FormatException.class) - public void testValidateShortDeviceId() throws IOException { - - /* Will create a Device Id with a short length, getRaw should work */ - BdfList body = BdfList.of(new byte[UniqueId.LENGTH - 1], - transportId.getString(), 1, bdfDictionary); - tpv.validateMessage(message, group, body); - } - - @Test(expected = FormatException.class) - public void testValidateLongDeviceId() throws IOException { - - BdfList body = BdfList.of(new byte[UniqueId.LENGTH + 1], - transportId.getString(), 1, bdfDictionary); - tpv.validateMessage(message, group, body); - } - - @Test(expected = FormatException.class) - public void testValidateWrongDeviceId() throws IOException { - - BdfList body = BdfList.of(bdfDictionary, transportId.getString(), 1, + BdfList body = BdfList.of(transportId.getString(), bdfDictionary, bdfDictionary); tpv.validateMessage(message, group, body); } @@ -116,22 +83,26 @@ public class TransportPropertyValidatorTest extends BriarTestCase { @Test(expected = FormatException.class) public void testValidateLongTransportId() throws IOException { - /* Generate a string or arbitrary length for the transport id*/ String wrongTransportIdString = TestUtils.getRandomString(MAX_TRANSPORT_ID_LENGTH + 1); - BdfList body = BdfList.of(deviceId, wrongTransportIdString, 4, - bdfDictionary); + BdfList body = BdfList.of(wrongTransportIdString, 4, bdfDictionary); tpv.validateMessage(message, group, body); } - @Test(expected = FormatException.class) + @Test(expected = FormatException.class) + public void testValidateEmptyTransportId() throws IOException { + + BdfList body = BdfList.of("", 4, bdfDictionary); + tpv.validateMessage(message, group, body); + } + + @Test(expected = FormatException.class) public void testValidateTooManyProperties() throws IOException { - /* Generate a big map for the BdfDictionary*/ BdfDictionary d = new BdfDictionary(); for (int i = 0; i < MAX_PROPERTIES_PER_TRANSPORT + 1; i++) d.put(String.valueOf(i), i); - BdfList body = BdfList.of(deviceId, transportId.getString(), 4, d); + BdfList body = BdfList.of(transportId.getString(), 4, d); tpv.validateMessage(message, group, body); } }