Reject old timestamps when deriving rotation mode keys.

This commit is contained in:
akwizgran
2021-06-09 11:54:10 +01:00
committed by Torsten Grote
parent 07afb955f7
commit d8230afae3
11 changed files with 343 additions and 42 deletions

View File

@@ -15,10 +15,10 @@ import org.junit.Test;
import java.util.concurrent.atomic.AtomicBoolean;
import static junit.framework.TestCase.assertTrue;
import static org.briarproject.bramble.api.lifecycle.LifecycleManager.MAX_REASONABLE_TIME_MS;
import static org.briarproject.bramble.api.lifecycle.LifecycleManager.MIN_REASONABLE_TIME_MS;
import static org.briarproject.bramble.api.lifecycle.LifecycleManager.StartResult.CLOCK_ERROR;
import static org.briarproject.bramble.api.lifecycle.LifecycleManager.StartResult.SUCCESS;
import static org.briarproject.bramble.api.system.Clock.MAX_REASONABLE_TIME_MS;
import static org.briarproject.bramble.api.system.Clock.MIN_REASONABLE_TIME_MS;
import static org.briarproject.bramble.test.TestUtils.getSecretKey;
import static org.junit.Assert.assertEquals;

View File

@@ -19,6 +19,7 @@ import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
import static org.briarproject.bramble.api.crypto.CryptoConstants.MAX_AGREEMENT_PUBLIC_KEY_BYTES;
import static org.briarproject.bramble.api.plugin.TransportId.MAX_TRANSPORT_ID_LENGTH;
import static org.briarproject.bramble.api.system.Clock.MIN_REASONABLE_TIME_MS;
import static org.briarproject.bramble.api.versioning.ClientVersioningManager.CLIENT_ID;
import static org.briarproject.bramble.api.versioning.ClientVersioningManager.MAJOR_VERSION;
import static org.briarproject.bramble.test.TestUtils.getGroup;
@@ -109,6 +110,27 @@ public class TransportKeyAgreementValidatorTest extends BrambleMockTestCase {
assertArrayEquals(publicKey, d.getRaw(MSG_KEY_PUBLIC_KEY));
}
@Test
public void testAcceptsMinTimestampKeyMsg() throws Exception {
Message message =
getMessage(group.getId(), 1234, MIN_REASONABLE_TIME_MS);
TransportId transportId = new TransportId(getRandomString(1));
context.checking(new Expectations() {{
oneOf(messageEncoder)
.encodeMessageMetadata(transportId, KEY, false);
will(returnValue(new BdfDictionary()));
}});
byte[] publicKey = getRandomBytes(1);
BdfList body =
BdfList.of(KEY.getValue(), transportId.getString(), publicKey);
BdfMessageContext msgCtx =
validator.validateMessage(message, group, body);
assertEquals(emptyList(), msgCtx.getDependencies());
BdfDictionary d = msgCtx.getDictionary();
assertArrayEquals(publicKey, d.getRaw(MSG_KEY_PUBLIC_KEY));
}
@Test(expected = FormatException.class)
public void testRejectsTooLongKeyMsg() throws Exception {
BdfList body = BdfList.of(KEY.getValue(), getRandomString(1),
@@ -168,6 +190,15 @@ public class TransportKeyAgreementValidatorTest extends BrambleMockTestCase {
validator.validateMessage(message, group, body);
}
@Test(expected = FormatException.class)
public void testRejectsTooOldTimestampKeyMsg() throws Exception {
Message message =
getMessage(group.getId(), 1234, MIN_REASONABLE_TIME_MS - 1);
BdfList body = BdfList.of(KEY.getValue(), getRandomString(1),
getRandomBytes(1));
validator.validateMessage(message, group, body);
}
@Test
public void testAcceptsActivateMsg() throws Exception {
TransportId transportId = new TransportId(getRandomString(1));