Truncate all messages to valid length before sending.

This commit is contained in:
akwizgran
2016-10-19 14:23:24 +01:00
parent 9d2c56e75f
commit 06335c2c30
23 changed files with 279 additions and 163 deletions

View File

@@ -31,6 +31,7 @@ import static org.briarproject.api.introduction.IntroductionConstants.CONTACT_ID
import static org.briarproject.api.introduction.IntroductionConstants.CONTACT_ID_2;
import static org.briarproject.api.introduction.IntroductionConstants.GROUP_ID_1;
import static org.briarproject.api.introduction.IntroductionConstants.GROUP_ID_2;
import static org.briarproject.api.introduction.IntroductionConstants.MAX_INTRODUCTION_MESSAGE_LENGTH;
import static org.briarproject.api.introduction.IntroductionConstants.MESSAGE_TIME;
import static org.briarproject.api.introduction.IntroductionConstants.MSG;
import static org.briarproject.api.introduction.IntroductionConstants.PUBLIC_KEY1;
@@ -103,7 +104,7 @@ class IntroducerManager {
return d;
}
public void makeIntroduction(Transaction txn, Contact c1, Contact c2,
void makeIntroduction(Transaction txn, Contact c1, Contact c2,
String msg, long timestamp) throws DbException, FormatException {
// TODO check for existing session with those contacts?
@@ -116,6 +117,9 @@ class IntroducerManager {
BdfDictionary localAction = new BdfDictionary();
localAction.put(TYPE, TYPE_REQUEST);
if (!StringUtils.isNullOrEmpty(msg)) {
int msgLength = StringUtils.toUtf8(msg).length;
if (msgLength > MAX_INTRODUCTION_MESSAGE_LENGTH)
throw new IllegalArgumentException();
localAction.put(MSG, msg);
}
localAction.put(PUBLIC_KEY1, c1.getAuthor().getPublicKey());

View File

@@ -21,6 +21,7 @@ import static org.briarproject.api.introduction.IntroductionConstants.E_PUBLIC_K
import static org.briarproject.api.introduction.IntroductionConstants.GROUP_ID;
import static org.briarproject.api.introduction.IntroductionConstants.MAC;
import static org.briarproject.api.introduction.IntroductionConstants.MAC_LENGTH;
import static org.briarproject.api.introduction.IntroductionConstants.MAX_INTRODUCTION_MESSAGE_LENGTH;
import static org.briarproject.api.introduction.IntroductionConstants.MESSAGE_ID;
import static org.briarproject.api.introduction.IntroductionConstants.MESSAGE_TIME;
import static org.briarproject.api.introduction.IntroductionConstants.MSG;
@@ -37,7 +38,6 @@ import static org.briarproject.api.introduction.IntroductionConstants.TYPE_REQUE
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;
class IntroductionValidator extends BdfMessageValidator {
@@ -92,7 +92,7 @@ class IntroductionValidator extends BdfMessageValidator {
String msg = null;
if (message.size() == 5) {
msg = message.getString(4);
checkLength(msg, 0, MAX_MESSAGE_BODY_LENGTH);
checkLength(msg, 0, MAX_INTRODUCTION_MESSAGE_LENGTH);
}
// Return the metadata