This addresses two types of introduction corner cases:

* force decline when two of our own identities are introduced to each
  other
* throw away introduction requests to the same identity
  (impossible to trigger from UI)

Closes #284
This commit is contained in:
Torsten Grote
2016-04-13 13:46:34 -03:00
parent 9f4cacd81c
commit d0036deaf7
11 changed files with 72 additions and 17 deletions

View File

@@ -243,6 +243,13 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
return db.containsGroup(txn, g);
}
@Override
public boolean containsLocalAuthor(Transaction transaction, AuthorId local)
throws DbException {
T txn = unbox(transaction);
return db.containsLocalAuthor(txn, local);
}
public void deleteMessage(Transaction transaction, MessageId m)
throws DbException {
if (transaction.isReadOnly()) throw new IllegalArgumentException();

View File

@@ -47,6 +47,7 @@ import static org.briarproject.api.introduction.IntroductionConstants.OUR_PUBLIC
import static org.briarproject.api.introduction.IntroductionConstants.OUR_TIME;
import static org.briarproject.api.introduction.IntroductionConstants.PUBLIC_KEY;
import static org.briarproject.api.introduction.IntroductionConstants.REMOTE_AUTHOR_ID;
import static org.briarproject.api.introduction.IntroductionConstants.REMOTE_AUTHOR_IS_US;
import static org.briarproject.api.introduction.IntroductionConstants.SESSION_ID;
import static org.briarproject.api.introduction.IntroductionConstants.STATE;
import static org.briarproject.api.introduction.IntroductionConstants.TASK;
@@ -328,10 +329,12 @@ public class IntroduceeEngine
String name = msg.getString(NAME);
String message = msg.getOptionalString(MSG);
boolean exists = localState.getBoolean(EXISTS);
boolean introducesOtherIdentity =
localState.getBoolean(REMOTE_AUTHOR_IS_US);
IntroductionRequest ir = new IntroductionRequest(sessionId, messageId,
time, false, false, false, false, authorId, name, false,
message, false, exists);
message, false, exists, introducesOtherIdentity);
return new IntroductionRequestReceivedEvent(contactId, ir);
}

View File

@@ -59,6 +59,7 @@ import static org.briarproject.api.introduction.IntroductionConstants.OUR_PUBLIC
import static org.briarproject.api.introduction.IntroductionConstants.OUR_TIME;
import static org.briarproject.api.introduction.IntroductionConstants.PUBLIC_KEY;
import static org.briarproject.api.introduction.IntroductionConstants.REMOTE_AUTHOR_ID;
import static org.briarproject.api.introduction.IntroductionConstants.REMOTE_AUTHOR_IS_US;
import static org.briarproject.api.introduction.IntroductionConstants.ROLE;
import static org.briarproject.api.introduction.IntroductionConstants.ROLE_INTRODUCEE;
import static org.briarproject.api.introduction.IntroductionConstants.STATE;
@@ -147,6 +148,17 @@ class IntroduceeManager {
d.put(EXISTS, exists);
d.put(REMOTE_AUTHOR_ID, remoteAuthorId);
// check if someone is trying to introduce us to ourselves
if(remoteAuthorId.equals(introducer.getLocalAuthorId())) {
LOG.warning("Received Introduction Request to Ourselves");
throw new FormatException();
}
// check if remote author is actually one of our other identities
boolean introducesOtherIdentity =
db.containsLocalAuthor(txn, remoteAuthorId);
d.put(REMOTE_AUTHOR_IS_US, introducesOtherIdentity);
// save local state to database
clientHelper.addLocalMessage(txn, localMsg,
IntroductionManagerImpl.CLIENT_ID, d, false);

View File

@@ -60,6 +60,7 @@ import static org.briarproject.api.introduction.IntroductionConstants.NAME;
import static org.briarproject.api.introduction.IntroductionConstants.NOT_OUR_RESPONSE;
import static org.briarproject.api.introduction.IntroductionConstants.READ;
import static org.briarproject.api.introduction.IntroductionConstants.REMOTE_AUTHOR_ID;
import static org.briarproject.api.introduction.IntroductionConstants.REMOTE_AUTHOR_IS_US;
import static org.briarproject.api.introduction.IntroductionConstants.RESPONSE_1;
import static org.briarproject.api.introduction.IntroductionConstants.RESPONSE_2;
import static org.briarproject.api.introduction.IntroductionConstants.ROLE;
@@ -186,9 +187,11 @@ class IntroductionManagerImpl extends BdfIncomingMessageHook
state = introduceeManager.initialize(txn, groupId, message);
} catch (FormatException e) {
if (LOG.isLoggable(WARNING)) {
LOG.warning("Could not initialize introducee state");
LOG.warning(
"Could not initialize introducee state, deleting...");
LOG.log(WARNING, e.toString(), e);
}
deleteMessage(txn, m.getId());
return;
}
try {
@@ -361,7 +364,7 @@ class IntroductionManagerImpl extends BdfIncomingMessageHook
list.add(ir);
} else if (type == TYPE_REQUEST) {
String message;
boolean answered, exists;
boolean answered, exists, introducesOtherIdentity;
if (state.getLong(ROLE) == ROLE_INTRODUCER) {
local = true;
authorId =
@@ -370,6 +373,7 @@ class IntroductionManagerImpl extends BdfIncomingMessageHook
message = msg.getOptionalString(MSG);
answered = false;
exists = false;
introducesOtherIdentity = false;
} else {
local = false;
authorId = new AuthorId(
@@ -378,11 +382,14 @@ class IntroductionManagerImpl extends BdfIncomingMessageHook
message = state.getOptionalString(MSG);
answered = state.getBoolean(ANSWERED);
exists = state.getBoolean(EXISTS);
introducesOtherIdentity =
state.getBoolean(REMOTE_AUTHOR_IS_US);
}
IntroductionRequest ir = new IntroductionRequest(
sessionId, messageId, time, local, s.isSent(),
s.isSeen(), read, authorId, name, accepted,
message, answered, exists);
message, answered, exists,
introducesOtherIdentity);
list.add(ir);
}
} catch (FormatException e) {