Only add transport properties and keys when the contact was added

This will be changed once we have a way to reset state for peers
that were contacts already at some point in the past.
One contact might have deleted the other, but not vice versa.
So they have mismatching state that needs to be reset.

See #2 for more information.
This commit is contained in:
Torsten Grote
2018-04-27 11:29:10 -03:00
parent 44f5a9db1e
commit 99dba69c87

View File

@@ -419,23 +419,22 @@ class IntroduceeProtocolEngine
s.getRemote().acceptTimestamp); s.getRemote().acceptTimestamp);
if (timestamp == -1) throw new AssertionError(); if (timestamp == -1) throw new AssertionError();
boolean contactAdded = false; Map<TransportId, KeySetId> keys = null;
try { try {
contactManager contactManager
.addContact(txn, s.getRemote().author, localAuthor.getId(), .addContact(txn, s.getRemote().author, localAuthor.getId(),
false, true); false, true);
contactAdded = true;
} catch (ContactExistsException e) { // Only add transport properties and keys when the contact was added
// Ignore this, because the other introducee might have deleted us. // This will be changed once we have a way to reset state for peers
// So we still want updated transport properties // that were contacts already at some point in the past.
// and new transport keys. Contact c = contactManager
} .getContact(txn, s.getRemote().author.getId(),
Contact c = contactManager.getContact(txn, s.getRemote().author.getId(),
localAuthor.getId()); localAuthor.getId());
// bind the keys to the new (or existing) contact // bind the keys to the new contact
//noinspection ConstantConditions //noinspection ConstantConditions
Map<TransportId, KeySetId> keys = keyManager keys = keyManager
.addUnboundKeys(txn, new SecretKey(s.getMasterKey()), .addUnboundKeys(txn, new SecretKey(s.getMasterKey()),
timestamp, s.getRemote().alice); timestamp, s.getRemote().alice);
keyManager.bindKeys(txn, c.getId(), keys); keyManager.bindKeys(txn, c.getId(), keys);
@@ -445,16 +444,19 @@ class IntroduceeProtocolEngine
transportPropertyManager.addRemoteProperties(txn, c.getId(), transportPropertyManager.addRemoteProperties(txn, c.getId(),
s.getRemote().transportProperties); s.getRemote().transportProperties);
// send ACTIVATE message with a MAC
byte[] mac = crypto.activateMac(s);
Message sent = sendActivateMessage(txn, s, getLocalTimestamp(s), mac);
if (contactAdded) {
// Broadcast IntroductionSucceededEvent, because contact got added // Broadcast IntroductionSucceededEvent, because contact got added
IntroductionSucceededEvent e = new IntroductionSucceededEvent(c); IntroductionSucceededEvent e = new IntroductionSucceededEvent(c);
txn.attach(e); txn.attach(e);
} catch (ContactExistsException e) {
// Ignore this, because the other introducee might have deleted us.
// So we still want updated transport properties
// and new transport keys.
} }
// send ACTIVATE message with a MAC
byte[] mac = crypto.activateMac(s);
Message sent = sendActivateMessage(txn, s, getLocalTimestamp(s), mac);
// Move to AWAIT_ACTIVATE state and clear key material from session // Move to AWAIT_ACTIVATE state and clear key material from session
return IntroduceeSession.awaitActivate(s, m, sent, keys); return IntroduceeSession.awaitActivate(s, m, sent, keys);
} }
@@ -469,12 +471,15 @@ class IntroduceeProtocolEngine
try { try {
crypto.verifyActivateMac(m.getMac(), s); crypto.verifyActivateMac(m.getMac(), s);
} catch (GeneralSecurityException e) { } catch (GeneralSecurityException e) {
// TODO remove transport keys?
return abort(txn, s); return abort(txn, s);
} }
// We might not have added transport keys
// if the contact existed when the remote AUTH was received.
if (s.getTransportKeys() != null) {
// Activate transport keys // Activate transport keys
keyManager.activateKeys(txn, s.getTransportKeys()); keyManager.activateKeys(txn, s.getTransportKeys());
}
// Move back to START state // Move back to START state
return IntroduceeSession.clear(s, START, s.getLastLocalMessageId(), return IntroduceeSession.clear(s, START, s.getLastLocalMessageId(),