Removed device ID from transport properties.

This commit is contained in:
akwizgran
2016-04-06 13:09:02 +01:00
parent befd916eba
commit 7de83b5624
12 changed files with 54 additions and 108 deletions

View File

@@ -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 {

View File

@@ -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";

View File

@@ -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. */

View File

@@ -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"

View File

@@ -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));
}
}

View File

@@ -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

View File

@@ -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;

View File

@@ -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;

View File

@@ -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

View File

@@ -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));

View File

@@ -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);

View File

@@ -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);
}
}