mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-20 22:59:54 +01:00
Add abstract superclass for transport keys.
This commit is contained in:
@@ -0,0 +1,58 @@
|
|||||||
|
package org.briarproject.bramble.api.transport;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.plugin.TransportId;
|
||||||
|
|
||||||
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract superclass for {@link TransportKeys} and
|
||||||
|
* {@link StaticTransportKeys}.
|
||||||
|
*/
|
||||||
|
@Immutable
|
||||||
|
@NotNullByDefault
|
||||||
|
public abstract class AbstractTransportKeys {
|
||||||
|
|
||||||
|
private final TransportId transportId;
|
||||||
|
private final IncomingKeys inPrev, inCurr, inNext;
|
||||||
|
private final OutgoingKeys outCurr;
|
||||||
|
|
||||||
|
AbstractTransportKeys(TransportId transportId, IncomingKeys inPrev,
|
||||||
|
IncomingKeys inCurr, IncomingKeys inNext, OutgoingKeys outCurr) {
|
||||||
|
if (inPrev.getTimePeriod() != outCurr.getTimePeriod() - 1)
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
if (inCurr.getTimePeriod() != outCurr.getTimePeriod())
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
if (inNext.getTimePeriod() != outCurr.getTimePeriod() + 1)
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
this.transportId = transportId;
|
||||||
|
this.inPrev = inPrev;
|
||||||
|
this.inCurr = inCurr;
|
||||||
|
this.inNext = inNext;
|
||||||
|
this.outCurr = outCurr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TransportId getTransportId() {
|
||||||
|
return transportId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IncomingKeys getPreviousIncomingKeys() {
|
||||||
|
return inPrev;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IncomingKeys getCurrentIncomingKeys() {
|
||||||
|
return inCurr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IncomingKeys getNextIncomingKeys() {
|
||||||
|
return inNext;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OutgoingKeys getCurrentOutgoingKeys() {
|
||||||
|
return outCurr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getTimePeriod() {
|
||||||
|
return outCurr.getTimePeriod();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,9 +6,13 @@ import org.briarproject.bramble.api.plugin.TransportId;
|
|||||||
|
|
||||||
import javax.annotation.concurrent.Immutable;
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Keys for communicating with a given contact over a given transport. Unlike
|
||||||
|
* {@link TransportKeys} these do not provide forward secrecy.
|
||||||
|
*/
|
||||||
@Immutable
|
@Immutable
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
public class StaticTransportKeys extends TransportKeys {
|
public class StaticTransportKeys extends AbstractTransportKeys {
|
||||||
|
|
||||||
private final SecretKey rootKey;
|
private final SecretKey rootKey;
|
||||||
private final boolean alice;
|
private final boolean alice;
|
||||||
|
|||||||
@@ -6,52 +6,15 @@ import org.briarproject.bramble.api.plugin.TransportId;
|
|||||||
import javax.annotation.concurrent.Immutable;
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Keys for communicating with a given contact over a given transport.
|
* Keys for communicating with a given contact over a given transport. Unlike
|
||||||
|
* {@link StaticTransportKeys}, these keys provide forward secrecy.
|
||||||
*/
|
*/
|
||||||
@Immutable
|
@Immutable
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
public class TransportKeys {
|
public class TransportKeys extends AbstractTransportKeys {
|
||||||
|
|
||||||
private final TransportId transportId;
|
|
||||||
private final IncomingKeys inPrev, inCurr, inNext;
|
|
||||||
private final OutgoingKeys outCurr;
|
|
||||||
|
|
||||||
public TransportKeys(TransportId transportId, IncomingKeys inPrev,
|
public TransportKeys(TransportId transportId, IncomingKeys inPrev,
|
||||||
IncomingKeys inCurr, IncomingKeys inNext, OutgoingKeys outCurr) {
|
IncomingKeys inCurr, IncomingKeys inNext, OutgoingKeys outCurr) {
|
||||||
if (inPrev.getTimePeriod() != outCurr.getTimePeriod() - 1)
|
super(transportId, inPrev, inCurr, inNext, outCurr);
|
||||||
throw new IllegalArgumentException();
|
|
||||||
if (inCurr.getTimePeriod() != outCurr.getTimePeriod())
|
|
||||||
throw new IllegalArgumentException();
|
|
||||||
if (inNext.getTimePeriod() != outCurr.getTimePeriod() + 1)
|
|
||||||
throw new IllegalArgumentException();
|
|
||||||
this.transportId = transportId;
|
|
||||||
this.inPrev = inPrev;
|
|
||||||
this.inCurr = inCurr;
|
|
||||||
this.inNext = inNext;
|
|
||||||
this.outCurr = outCurr;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TransportId getTransportId() {
|
|
||||||
return transportId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IncomingKeys getPreviousIncomingKeys() {
|
|
||||||
return inPrev;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IncomingKeys getCurrentIncomingKeys() {
|
|
||||||
return inCurr;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IncomingKeys getNextIncomingKeys() {
|
|
||||||
return inNext;
|
|
||||||
}
|
|
||||||
|
|
||||||
public OutgoingKeys getCurrentOutgoingKeys() {
|
|
||||||
return outCurr;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getTimePeriod() {
|
|
||||||
return outCurr.getTimePeriod();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ package org.briarproject.bramble.crypto;
|
|||||||
|
|
||||||
import org.briarproject.bramble.api.Bytes;
|
import org.briarproject.bramble.api.Bytes;
|
||||||
import org.briarproject.bramble.api.crypto.SecretKey;
|
import org.briarproject.bramble.api.crypto.SecretKey;
|
||||||
|
import org.briarproject.bramble.api.transport.AbstractTransportKeys;
|
||||||
import org.briarproject.bramble.api.transport.IncomingKeys;
|
import org.briarproject.bramble.api.transport.IncomingKeys;
|
||||||
import org.briarproject.bramble.api.transport.OutgoingKeys;
|
import org.briarproject.bramble.api.transport.OutgoingKeys;
|
||||||
import org.briarproject.bramble.api.transport.TransportKeys;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@@ -16,9 +16,9 @@ import static org.junit.Assert.assertTrue;
|
|||||||
|
|
||||||
class KeyDerivationTestUtils {
|
class KeyDerivationTestUtils {
|
||||||
|
|
||||||
static void assertAllDifferent(TransportKeys... transportKeys) {
|
static void assertAllDifferent(AbstractTransportKeys... transportKeys) {
|
||||||
List<SecretKey> secretKeys = new ArrayList<>();
|
List<SecretKey> secretKeys = new ArrayList<>();
|
||||||
for (TransportKeys k : transportKeys) {
|
for (AbstractTransportKeys k : transportKeys) {
|
||||||
secretKeys.add(k.getPreviousIncomingKeys().getTagKey());
|
secretKeys.add(k.getPreviousIncomingKeys().getTagKey());
|
||||||
secretKeys.add(k.getPreviousIncomingKeys().getHeaderKey());
|
secretKeys.add(k.getPreviousIncomingKeys().getHeaderKey());
|
||||||
secretKeys.add(k.getCurrentIncomingKeys().getTagKey());
|
secretKeys.add(k.getCurrentIncomingKeys().getTagKey());
|
||||||
|
|||||||
Reference in New Issue
Block a user