mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-16 12:49:55 +01:00
Merge branch '2102-clear-introduction-state' into '1802-sync-via-removable-storage'
Clear keys from session when moving to AWAIT_ACTIVATE state See merge request briar/briar!1500
This commit is contained in:
@@ -49,6 +49,7 @@ import javax.inject.Inject;
|
|||||||
|
|
||||||
import static java.lang.Math.max;
|
import static java.lang.Math.max;
|
||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
|
import static org.briarproject.bramble.api.nullsafety.NullSafety.requireNonNull;
|
||||||
import static org.briarproject.bramble.api.system.Clock.MIN_REASONABLE_TIME_MS;
|
import static org.briarproject.bramble.api.system.Clock.MIN_REASONABLE_TIME_MS;
|
||||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||||
import static org.briarproject.briar.introduction.IntroduceeState.AWAIT_AUTH;
|
import static org.briarproject.briar.introduction.IntroduceeState.AWAIT_AUTH;
|
||||||
@@ -476,7 +477,7 @@ class IntroduceeProtocolEngine
|
|||||||
|
|
||||||
// add signed transport properties for the contact
|
// add signed transport properties for the contact
|
||||||
transportPropertyManager.addRemoteProperties(txn, contactId,
|
transportPropertyManager.addRemoteProperties(txn, contactId,
|
||||||
s.getRemote().transportProperties);
|
requireNonNull(s.getRemote().transportProperties));
|
||||||
} catch (ContactExistsException e) {
|
} catch (ContactExistsException e) {
|
||||||
// Ignore this, because the other introducee might have deleted us
|
// Ignore this, because the other introducee might have deleted us
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -116,8 +116,8 @@ class IntroduceeSession extends Session<IntroduceeState>
|
|||||||
|
|
||||||
static IntroduceeSession awaitActivate(IntroduceeSession s, AuthMessage m,
|
static IntroduceeSession awaitActivate(IntroduceeSession s, AuthMessage m,
|
||||||
Message sent, @Nullable Map<TransportId, KeySetId> transportKeys) {
|
Message sent, @Nullable Map<TransportId, KeySetId> transportKeys) {
|
||||||
Local local = new Local(s.local, sent.getId(), sent.getTimestamp());
|
Local local = Local.clear(s.local, sent.getId(), sent.getTimestamp());
|
||||||
Remote remote = new Remote(s.remote, m.getMessageId());
|
Remote remote = Remote.clear(s.remote, m.getMessageId());
|
||||||
return new IntroduceeSession(s.getSessionId(), AWAIT_ACTIVATE,
|
return new IntroduceeSession(s.getSessionId(), AWAIT_ACTIVATE,
|
||||||
s.getRequestTimestamp(), s.contactGroupId, s.introducer, local,
|
s.getRequestTimestamp(), s.contactGroupId, s.introducer, local,
|
||||||
remote, null, transportKeys);
|
remote, null, transportKeys);
|
||||||
@@ -228,11 +228,15 @@ class IntroduceeSession extends Session<IntroduceeState>
|
|||||||
this.ephemeralPrivateKey = ephemeralPrivateKey;
|
this.ephemeralPrivateKey = ephemeralPrivateKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Local(Local s, @Nullable MessageId lastMessageId,
|
/**
|
||||||
long lastMessageTimestamp) {
|
* Returns a copy of the given Local, updating the last message ID
|
||||||
this(s.alice, lastMessageId, lastMessageTimestamp,
|
* and timestamp and clearing the ephemeral keys.
|
||||||
s.ephemeralPublicKey, s.ephemeralPrivateKey,
|
*/
|
||||||
s.transportProperties, s.acceptTimestamp, s.macKey);
|
private static Local clear(Local s,
|
||||||
|
@Nullable MessageId lastMessageId, long lastMessageTimestamp) {
|
||||||
|
return new Local(s.alice, lastMessageId, lastMessageTimestamp,
|
||||||
|
null, null, s.transportProperties, s.acceptTimestamp,
|
||||||
|
s.macKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -249,10 +253,23 @@ class IntroduceeSession extends Session<IntroduceeState>
|
|||||||
this.author = author;
|
this.author = author;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a copy of the given Remote, updating the last message ID.
|
||||||
|
*/
|
||||||
private Remote(Remote s, @Nullable MessageId lastMessageId) {
|
private Remote(Remote s, @Nullable MessageId lastMessageId) {
|
||||||
this(s.alice, s.author, lastMessageId, s.ephemeralPublicKey,
|
this(s.alice, s.author, lastMessageId, s.ephemeralPublicKey,
|
||||||
s.transportProperties, s.acceptTimestamp, s.macKey);
|
s.transportProperties, s.acceptTimestamp, s.macKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a copy of the given Remote, updating the last message ID
|
||||||
|
* and clearing the ephemeral keys.
|
||||||
|
*/
|
||||||
|
private static Remote clear(Remote s,
|
||||||
|
@Nullable MessageId lastMessageId) {
|
||||||
|
return new Remote(s.alice, s.author, lastMessageId, null,
|
||||||
|
s.transportProperties, s.acceptTimestamp, s.macKey);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ import static org.briarproject.briar.introduction.IntroduceeState.AWAIT_AUTH;
|
|||||||
import static org.briarproject.briar.introduction.IntroduceeState.START;
|
import static org.briarproject.briar.introduction.IntroduceeState.START;
|
||||||
import static org.briarproject.briar.introduction.MessageType.ABORT;
|
import static org.briarproject.briar.introduction.MessageType.ABORT;
|
||||||
import static org.briarproject.briar.introduction.MessageType.ACTIVATE;
|
import static org.briarproject.briar.introduction.MessageType.ACTIVATE;
|
||||||
|
import static org.junit.Assert.assertArrayEquals;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
|
|
||||||
@@ -176,9 +177,14 @@ public class IntroduceeProtocolEngineTest extends BrambleMockTestCase {
|
|||||||
IntroduceeSession.Local afterLocal = after.getLocal();
|
IntroduceeSession.Local afterLocal = after.getLocal();
|
||||||
assertEquals(activateMessage.getId(), afterLocal.lastMessageId);
|
assertEquals(activateMessage.getId(), afterLocal.lastMessageId);
|
||||||
assertEquals(now, afterLocal.lastMessageTimestamp);
|
assertEquals(now, afterLocal.lastMessageTimestamp);
|
||||||
|
assertNull(afterLocal.ephemeralPublicKey);
|
||||||
|
assertNull(afterLocal.ephemeralPrivateKey);
|
||||||
|
assertArrayEquals(localMacKey.getBytes(), afterLocal.macKey);
|
||||||
|
|
||||||
IntroduceeSession.Remote afterRemote = after.getRemote();
|
IntroduceeSession.Remote afterRemote = after.getRemote();
|
||||||
assertEquals(authMessage.getMessageId(), afterRemote.lastMessageId);
|
assertEquals(authMessage.getMessageId(), afterRemote.lastMessageId);
|
||||||
|
assertNull(afterRemote.ephemeralPublicKey);
|
||||||
|
assertArrayEquals(remoteMacKey.getBytes(), afterRemote.macKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user