diff --git a/briar-core/src/org/briarproject/clients/BdfIncomingMessageHook.java b/briar-core/src/org/briarproject/clients/BdfIncomingMessageHook.java index 9d9f0d691c29f81622404f1c8ef6bd5983a08f0b..5380652c6d84dccb25ef4cab8c9a2ea837d5144d 100644 --- a/briar-core/src/org/briarproject/clients/BdfIncomingMessageHook.java +++ b/briar-core/src/org/briarproject/clients/BdfIncomingMessageHook.java @@ -29,8 +29,9 @@ public abstract class BdfIncomingMessageHook implements IncomingMessageHook, this.metadataParser = metadataParser; } - protected abstract void incomingMessage(Transaction txn, BdfList message, - BdfDictionary meta) throws DbException, FormatException; + protected abstract void incomingMessage(Transaction txn, Message m, + BdfList body, BdfDictionary meta) throws DbException, + FormatException; @Override public void incomingMessage(Transaction txn, Message m, Metadata meta) @@ -48,10 +49,10 @@ public abstract class BdfIncomingMessageHook implements IncomingMessageHook, int headerLength) throws DbException { try { byte[] raw = m.getRaw(); - BdfList message = clientHelper.toList(raw, headerLength, + BdfList body = clientHelper.toList(raw, headerLength, raw.length - headerLength); BdfDictionary metaDictionary = metadataParser.parse(meta); - incomingMessage(txn, message, metaDictionary); + incomingMessage(txn, m, body, metaDictionary); } catch (FormatException e) { throw new DbException(e); } diff --git a/briar-core/src/org/briarproject/clients/BdfMessageValidator.java b/briar-core/src/org/briarproject/clients/BdfMessageValidator.java index a2d97cfd315589a2d77ce09cf62f446cb0664863..19bc55db000f1dd841167c6f3eb4d0fd03a514e5 100644 --- a/briar-core/src/org/briarproject/clients/BdfMessageValidator.java +++ b/briar-core/src/org/briarproject/clients/BdfMessageValidator.java @@ -37,8 +37,8 @@ public abstract class BdfMessageValidator implements MessageValidator, this.clock = clock; } - protected abstract BdfDictionary validateMessage(BdfList message, Group g, - long timestamp) throws FormatException; + protected abstract BdfDictionary validateMessage(Message m, Group g, + BdfList body) throws FormatException; @Override public Metadata validateMessage(Message m, Group g) { @@ -63,9 +63,9 @@ public abstract class BdfMessageValidator implements MessageValidator, return null; } try { - BdfList message = clientHelper.toList(raw, headerLength, + BdfList body = clientHelper.toList(raw, headerLength, raw.length - headerLength); - BdfDictionary meta = validateMessage(message, g, m.getTimestamp()); + BdfDictionary meta = validateMessage(m, g, body); if (meta == null) { LOG.info("Invalid message"); return null; diff --git a/briar-core/src/org/briarproject/forum/ForumListValidator.java b/briar-core/src/org/briarproject/forum/ForumListValidator.java index 94a5ca684fd4aa040b7b7a36daafbe7766b4b2f0..9e6947a377f4d12b4d02bff1a6b380a1831798e6 100644 --- a/briar-core/src/org/briarproject/forum/ForumListValidator.java +++ b/briar-core/src/org/briarproject/forum/ForumListValidator.java @@ -6,6 +6,7 @@ import org.briarproject.api.data.BdfDictionary; import org.briarproject.api.data.BdfList; import org.briarproject.api.data.MetadataEncoder; import org.briarproject.api.sync.Group; +import org.briarproject.api.sync.Message; import org.briarproject.api.system.Clock; import org.briarproject.clients.BdfMessageValidator; @@ -20,15 +21,15 @@ class ForumListValidator extends BdfMessageValidator { } @Override - protected BdfDictionary validateMessage(BdfList message, Group g, - long timestamp) throws FormatException { + protected BdfDictionary validateMessage(Message m, Group g, + BdfList body) throws FormatException { // Version, forum list - checkSize(message, 2); + checkSize(body, 2); // Version - long version = message.getLong(0); + long version = body.getLong(0); if (version < 0) throw new FormatException(); // Forum list - BdfList forumList = message.getList(1); + BdfList forumList = body.getList(1); for (int i = 0; i < forumList.size(); i++) { BdfList forum = forumList.getList(i); // Name, salt diff --git a/briar-core/src/org/briarproject/forum/ForumPostValidator.java b/briar-core/src/org/briarproject/forum/ForumPostValidator.java index 8bc2734502bde6e0d654bca17a1356217b19611e..aac7b6265de9f221f248afeabd014770138fc47c 100644 --- a/briar-core/src/org/briarproject/forum/ForumPostValidator.java +++ b/briar-core/src/org/briarproject/forum/ForumPostValidator.java @@ -13,6 +13,7 @@ import org.briarproject.api.data.MetadataEncoder; import org.briarproject.api.identity.Author; import org.briarproject.api.identity.AuthorFactory; import org.briarproject.api.sync.Group; +import org.briarproject.api.sync.Message; import org.briarproject.api.system.Clock; import org.briarproject.clients.BdfMessageValidator; @@ -38,16 +39,16 @@ class ForumPostValidator extends BdfMessageValidator { } @Override - protected BdfDictionary validateMessage(BdfList message, Group g, - long timestamp) throws FormatException { + protected BdfDictionary validateMessage(Message m, Group g, + BdfList body) throws FormatException { // Parent ID, author, content type, forum post body, signature - checkSize(message, 5); + checkSize(body, 5); // Parent ID is optional - byte[] parent = message.getOptionalRaw(0); + byte[] parent = body.getOptionalRaw(0); checkLength(parent, UniqueId.LENGTH); // Author is optional Author author = null; - BdfList authorList = message.getOptionalList(1); + BdfList authorList = body.getOptionalList(1); if (authorList != null) { // Name, public key checkSize(authorList, 2); @@ -58,13 +59,13 @@ class ForumPostValidator extends BdfMessageValidator { author = authorFactory.createAuthor(name, publicKey); } // Content type - String contentType = message.getString(2); + String contentType = body.getString(2); checkLength(contentType, 0, MAX_CONTENT_TYPE_LENGTH); // Forum post body - byte[] body = message.getRaw(3); - checkLength(body, 0, MAX_FORUM_POST_BODY_LENGTH); + byte[] forumPostBody = body.getRaw(3); + checkLength(forumPostBody, 0, MAX_FORUM_POST_BODY_LENGTH); // Signature is optional - byte[] sig = message.getOptionalRaw(4); + byte[] sig = body.getOptionalRaw(4); checkLength(sig, 0, MAX_SIGNATURE_LENGTH); // If there's an author there must be a signature and vice versa if (author != null && sig == null) { @@ -82,7 +83,7 @@ class ForumPostValidator extends BdfMessageValidator { KeyParser keyParser = crypto.getSignatureKeyParser(); PublicKey key = keyParser.parsePublicKey(author.getPublicKey()); // Serialise the data to be signed - BdfList signed = BdfList.of(g.getId(), timestamp, parent, + BdfList signed = BdfList.of(g.getId(), m.getTimestamp(), parent, authorList, contentType, body); // Verify the signature Signature signature = crypto.getSignature(); @@ -99,7 +100,7 @@ class ForumPostValidator extends BdfMessageValidator { } // Return the metadata BdfDictionary meta = new BdfDictionary(); - meta.put("timestamp", timestamp); + meta.put("timestamp", m.getTimestamp()); if (parent != null) meta.put("parent", parent); if (author != null) { BdfDictionary authorMeta = new BdfDictionary(); diff --git a/briar-core/src/org/briarproject/messaging/PrivateMessageValidator.java b/briar-core/src/org/briarproject/messaging/PrivateMessageValidator.java index 0475da174b0d120de0c38f6628e1d2ec6f0fc10f..550da3f9c77d7ab8eaebc9365105275a35cb23af 100644 --- a/briar-core/src/org/briarproject/messaging/PrivateMessageValidator.java +++ b/briar-core/src/org/briarproject/messaging/PrivateMessageValidator.java @@ -7,6 +7,7 @@ import org.briarproject.api.data.BdfDictionary; import org.briarproject.api.data.BdfList; import org.briarproject.api.data.MetadataEncoder; import org.briarproject.api.sync.Group; +import org.briarproject.api.sync.Message; import org.briarproject.api.system.Clock; import org.briarproject.clients.BdfMessageValidator; @@ -21,22 +22,22 @@ class PrivateMessageValidator extends BdfMessageValidator { } @Override - protected BdfDictionary validateMessage(BdfList message, Group g, - long timestamp) throws FormatException { + protected BdfDictionary validateMessage(Message m, Group g, + BdfList body) throws FormatException { // Parent ID, content type, private message body - checkSize(message, 3); + checkSize(body, 3); // Parent ID is optional - byte[] parentId = message.getOptionalRaw(0); + byte[] parentId = body.getOptionalRaw(0); checkLength(parentId, UniqueId.LENGTH); // Content type - String contentType = message.getString(1); + String contentType = body.getString(1); checkLength(contentType, 0, MAX_CONTENT_TYPE_LENGTH); // Private message body - byte[] body = message.getRaw(2); - checkLength(body, 0, MAX_PRIVATE_MESSAGE_BODY_LENGTH); + byte[] privateMessageBody = body.getRaw(2); + checkLength(privateMessageBody, 0, MAX_PRIVATE_MESSAGE_BODY_LENGTH); // Return the metadata BdfDictionary meta = new BdfDictionary(); - meta.put("timestamp", timestamp); + meta.put("timestamp", m.getTimestamp()); if (parentId != null) meta.put("parent", parentId); meta.put("contentType", contentType); meta.put("local", false); diff --git a/briar-core/src/org/briarproject/properties/TransportPropertyValidator.java b/briar-core/src/org/briarproject/properties/TransportPropertyValidator.java index e6fcd69a6c6c96c9eb87033f2c882962ba6ea99b..55b913c7dd2f60aa935773158602a0fb27cf65a5 100644 --- a/briar-core/src/org/briarproject/properties/TransportPropertyValidator.java +++ b/briar-core/src/org/briarproject/properties/TransportPropertyValidator.java @@ -7,6 +7,7 @@ import org.briarproject.api.data.BdfDictionary; import org.briarproject.api.data.BdfList; import org.briarproject.api.data.MetadataEncoder; import org.briarproject.api.sync.Group; +import org.briarproject.api.sync.Message; import org.briarproject.api.system.Clock; import org.briarproject.clients.BdfMessageValidator; @@ -22,21 +23,21 @@ class TransportPropertyValidator extends BdfMessageValidator { } @Override - protected BdfDictionary validateMessage(BdfList message, Group g, - long timestamp) throws FormatException { + protected BdfDictionary validateMessage(Message m, Group g, + BdfList body) throws FormatException { // Device ID, transport ID, version, properties - checkSize(message, 4); + checkSize(body, 4); // Device ID - byte[] deviceId = message.getRaw(0); + byte[] deviceId = body.getRaw(0); checkLength(deviceId, UniqueId.LENGTH); // Transport ID - String transportId = message.getString(1); + String transportId = body.getString(1); checkLength(transportId, 1, MAX_TRANSPORT_ID_LENGTH); // Version - long version = message.getLong(2); + long version = body.getLong(2); if (version < 0) throw new FormatException(); // Properties - BdfDictionary dictionary = message.getDictionary(3); + BdfDictionary dictionary = body.getDictionary(3); checkSize(dictionary, 0, MAX_PROPERTIES_PER_TRANSPORT); for (String key : dictionary.keySet()) { checkLength(key, 0, MAX_PROPERTY_LENGTH);