mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-20 14:49:53 +01:00
Add key set and key set ID classes for static keys.
This commit is contained in:
@@ -20,8 +20,8 @@ import org.briarproject.bramble.api.sync.MessageStatus;
|
|||||||
import org.briarproject.bramble.api.sync.Offer;
|
import org.briarproject.bramble.api.sync.Offer;
|
||||||
import org.briarproject.bramble.api.sync.Request;
|
import org.briarproject.bramble.api.sync.Request;
|
||||||
import org.briarproject.bramble.api.sync.validation.MessageState;
|
import org.briarproject.bramble.api.sync.validation.MessageState;
|
||||||
import org.briarproject.bramble.api.transport.KeySet;
|
import org.briarproject.bramble.api.transport.TransportKeySet;
|
||||||
import org.briarproject.bramble.api.transport.KeySetId;
|
import org.briarproject.bramble.api.transport.TransportKeySetId;
|
||||||
import org.briarproject.bramble.api.transport.TransportKeys;
|
import org.briarproject.bramble.api.transport.TransportKeys;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@@ -129,7 +129,7 @@ public interface DatabaseComponent {
|
|||||||
* Stores the given transport keys for the given contact and returns a
|
* Stores the given transport keys for the given contact and returns a
|
||||||
* key set ID.
|
* key set ID.
|
||||||
*/
|
*/
|
||||||
KeySetId addTransportKeys(Transaction txn, ContactId c,
|
TransportKeySetId addTransportKeys(Transaction txn, ContactId c,
|
||||||
TransportKeys k) throws DbException;
|
TransportKeys k) throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -429,14 +429,14 @@ public interface DatabaseComponent {
|
|||||||
* <p/>
|
* <p/>
|
||||||
* Read-only.
|
* Read-only.
|
||||||
*/
|
*/
|
||||||
Collection<KeySet> getTransportKeys(Transaction txn, TransportId t)
|
Collection<TransportKeySet> getTransportKeys(Transaction txn, TransportId t)
|
||||||
throws DbException;
|
throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Increments the outgoing stream counter for the given transport keys.
|
* Increments the outgoing stream counter for the given transport keys.
|
||||||
*/
|
*/
|
||||||
void incrementStreamCounter(Transaction txn, TransportId t, KeySetId k)
|
void incrementStreamCounter(Transaction txn, TransportId t,
|
||||||
throws DbException;
|
TransportKeySetId k) throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Merges the given metadata with the existing metadata for the given
|
* Merges the given metadata with the existing metadata for the given
|
||||||
@@ -509,8 +509,8 @@ public interface DatabaseComponent {
|
|||||||
/**
|
/**
|
||||||
* Removes the given transport keys from the database.
|
* Removes the given transport keys from the database.
|
||||||
*/
|
*/
|
||||||
void removeTransportKeys(Transaction txn, TransportId t, KeySetId k)
|
void removeTransportKeys(Transaction txn, TransportId t,
|
||||||
throws DbException;
|
TransportKeySetId k) throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Marks the given contact as verified.
|
* Marks the given contact as verified.
|
||||||
@@ -556,18 +556,19 @@ public interface DatabaseComponent {
|
|||||||
* Sets the reordering window for the given key set and transport in the
|
* Sets the reordering window for the given key set and transport in the
|
||||||
* given time period.
|
* given time period.
|
||||||
*/
|
*/
|
||||||
void setReorderingWindow(Transaction txn, KeySetId k, TransportId t,
|
void setReorderingWindow(Transaction txn, TransportKeySetId k,
|
||||||
long timePeriod, long base, byte[] bitmap) throws DbException;
|
TransportId t, long timePeriod, long base, byte[] bitmap)
|
||||||
|
throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Marks the given transport keys as usable for outgoing streams.
|
* Marks the given transport keys as usable for outgoing streams.
|
||||||
*/
|
*/
|
||||||
void setTransportKeysActive(Transaction txn, TransportId t, KeySetId k)
|
void setTransportKeysActive(Transaction txn, TransportId t,
|
||||||
throws DbException;
|
TransportKeySetId k) throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stores the given transport keys, deleting any keys they have replaced.
|
* Stores the given transport keys, deleting any keys they have replaced.
|
||||||
*/
|
*/
|
||||||
void updateTransportKeys(Transaction txn, Collection<KeySet> keys)
|
void updateTransportKeys(Transaction txn, Collection<TransportKeySet> keys)
|
||||||
throws DbException;
|
throws DbException;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,14 +27,14 @@ public interface KeyManager {
|
|||||||
* @param alice true if the local party is Alice
|
* @param alice true if the local party is Alice
|
||||||
* @param active whether the derived keys can be used for outgoing streams
|
* @param active whether the derived keys can be used for outgoing streams
|
||||||
*/
|
*/
|
||||||
Map<TransportId, KeySetId> addContact(Transaction txn, ContactId c,
|
Map<TransportId, TransportKeySetId> addContact(Transaction txn, ContactId c,
|
||||||
SecretKey rootKey, long timestamp, boolean alice, boolean active)
|
SecretKey rootKey, long timestamp, boolean alice, boolean active)
|
||||||
throws DbException;
|
throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Marks the given transport keys as usable for outgoing streams.
|
* Marks the given transport keys as usable for outgoing streams.
|
||||||
*/
|
*/
|
||||||
void activateKeys(Transaction txn, Map<TransportId, KeySetId> keys)
|
void activateKeys(Transaction txn, Map<TransportId, TransportKeySetId> keys)
|
||||||
throws DbException;
|
throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -0,0 +1,69 @@
|
|||||||
|
package org.briarproject.bramble.api.transport;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.contact.ContactId;
|
||||||
|
import org.briarproject.bramble.api.contact.PendingContactId;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A set of transport keys for communicating with a contact or pending contact.
|
||||||
|
* Unlike a {@link TransportKeySet} these keys do not provide forward secrecy.
|
||||||
|
*/
|
||||||
|
@Immutable
|
||||||
|
@NotNullByDefault
|
||||||
|
public class StaticTransportKeySet {
|
||||||
|
|
||||||
|
private final StaticTransportKeySetId keySetId;
|
||||||
|
@Nullable
|
||||||
|
private final ContactId contactId;
|
||||||
|
@Nullable
|
||||||
|
private final PendingContactId pendingContactId;
|
||||||
|
private final StaticTransportKeys keys;
|
||||||
|
|
||||||
|
public StaticTransportKeySet(StaticTransportKeySetId keySetId,
|
||||||
|
ContactId contactId, StaticTransportKeys keys) {
|
||||||
|
this.keySetId = keySetId;
|
||||||
|
this.contactId = contactId;
|
||||||
|
this.keys = keys;
|
||||||
|
pendingContactId = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StaticTransportKeySet(StaticTransportKeySetId keySetId,
|
||||||
|
PendingContactId pendingContactId, StaticTransportKeys keys) {
|
||||||
|
this.keySetId = keySetId;
|
||||||
|
this.pendingContactId = pendingContactId;
|
||||||
|
this.keys = keys;
|
||||||
|
contactId = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StaticTransportKeySetId getKeySetId() {
|
||||||
|
return keySetId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public ContactId getContactId() {
|
||||||
|
return contactId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public PendingContactId getPendingContactId() {
|
||||||
|
return pendingContactId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StaticTransportKeys getKeys() {
|
||||||
|
return keys;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return keySetId.hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
return o instanceof StaticTransportKeySet &&
|
||||||
|
keySetId.equals(((StaticTransportKeySet) o).keySetId);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package org.briarproject.bramble.api.transport;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Type-safe wrapper for an integer that uniquely identifies a
|
||||||
|
* {@link StaticTransportKeySet set of static transport keys} within the scope
|
||||||
|
* of the local device.
|
||||||
|
*/
|
||||||
|
@Immutable
|
||||||
|
@NotNullByDefault
|
||||||
|
public class StaticTransportKeySetId {
|
||||||
|
|
||||||
|
private final int id;
|
||||||
|
|
||||||
|
public StaticTransportKeySetId(int id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getInt() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
return o instanceof StaticTransportKeySetId &&
|
||||||
|
id == ((StaticTransportKeySetId) o).id;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,8 +7,8 @@ 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
|
* Keys for communicating with a given contact or pending contact over a given
|
||||||
* {@link TransportKeys} these do not provide forward secrecy.
|
* transport. Unlike {@link TransportKeys} these do not provide forward secrecy.
|
||||||
*/
|
*/
|
||||||
@Immutable
|
@Immutable
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
|
|||||||
@@ -10,20 +10,20 @@ import javax.annotation.concurrent.Immutable;
|
|||||||
*/
|
*/
|
||||||
@Immutable
|
@Immutable
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
public class KeySet {
|
public class TransportKeySet {
|
||||||
|
|
||||||
private final KeySetId keySetId;
|
private final TransportKeySetId keySetId;
|
||||||
private final ContactId contactId;
|
private final ContactId contactId;
|
||||||
private final TransportKeys transportKeys;
|
private final TransportKeys keys;
|
||||||
|
|
||||||
public KeySet(KeySetId keySetId, ContactId contactId,
|
public TransportKeySet(TransportKeySetId keySetId, ContactId contactId,
|
||||||
TransportKeys transportKeys) {
|
TransportKeys keys) {
|
||||||
this.keySetId = keySetId;
|
this.keySetId = keySetId;
|
||||||
this.contactId = contactId;
|
this.contactId = contactId;
|
||||||
this.transportKeys = transportKeys;
|
this.keys = keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
public KeySetId getKeySetId() {
|
public TransportKeySetId getKeySetId() {
|
||||||
return keySetId;
|
return keySetId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,8 +31,8 @@ public class KeySet {
|
|||||||
return contactId;
|
return contactId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TransportKeys getTransportKeys() {
|
public TransportKeys getKeys() {
|
||||||
return transportKeys;
|
return keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -42,6 +42,7 @@ public class KeySet {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
return o instanceof KeySet && keySetId.equals(((KeySet) o).keySetId);
|
return o instanceof TransportKeySet &&
|
||||||
|
keySetId.equals(((TransportKeySet) o).keySetId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,18 +5,19 @@ import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
|||||||
import javax.annotation.concurrent.Immutable;
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Type-safe wrapper for an integer that uniquely identifies a set of transport
|
* Type-safe wrapper for an integer that uniquely identifies a
|
||||||
* keys within the scope of the local device.
|
* {@link TransportKeySet set of transport keys} within the scope of the local
|
||||||
|
* device.
|
||||||
* <p/>
|
* <p/>
|
||||||
* Key sets created on a given device must have increasing identifiers.
|
* Key sets created on a given device must have increasing identifiers.
|
||||||
*/
|
*/
|
||||||
@Immutable
|
@Immutable
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
public class KeySetId {
|
public class TransportKeySetId {
|
||||||
|
|
||||||
private final int id;
|
private final int id;
|
||||||
|
|
||||||
public KeySetId(int id) {
|
public TransportKeySetId(int id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,6 +32,7 @@ public class KeySetId {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
return o instanceof KeySetId && id == ((KeySetId) o).id;
|
return o instanceof TransportKeySetId &&
|
||||||
|
id == ((TransportKeySetId) o).id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,6 +5,7 @@ import org.briarproject.bramble.api.contact.ContactId;
|
|||||||
import org.briarproject.bramble.api.crypto.SecretKey;
|
import org.briarproject.bramble.api.crypto.SecretKey;
|
||||||
import org.briarproject.bramble.api.db.DataTooNewException;
|
import org.briarproject.bramble.api.db.DataTooNewException;
|
||||||
import org.briarproject.bramble.api.db.DataTooOldException;
|
import org.briarproject.bramble.api.db.DataTooOldException;
|
||||||
|
import org.briarproject.bramble.api.db.DatabaseComponent;
|
||||||
import org.briarproject.bramble.api.db.DbException;
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
import org.briarproject.bramble.api.db.MessageDeletedException;
|
import org.briarproject.bramble.api.db.MessageDeletedException;
|
||||||
import org.briarproject.bramble.api.db.Metadata;
|
import org.briarproject.bramble.api.db.Metadata;
|
||||||
@@ -23,8 +24,8 @@ import org.briarproject.bramble.api.sync.Message;
|
|||||||
import org.briarproject.bramble.api.sync.MessageId;
|
import org.briarproject.bramble.api.sync.MessageId;
|
||||||
import org.briarproject.bramble.api.sync.MessageStatus;
|
import org.briarproject.bramble.api.sync.MessageStatus;
|
||||||
import org.briarproject.bramble.api.sync.validation.MessageState;
|
import org.briarproject.bramble.api.sync.validation.MessageState;
|
||||||
import org.briarproject.bramble.api.transport.KeySet;
|
import org.briarproject.bramble.api.transport.TransportKeySet;
|
||||||
import org.briarproject.bramble.api.transport.KeySetId;
|
import org.briarproject.bramble.api.transport.TransportKeySetId;
|
||||||
import org.briarproject.bramble.api.transport.TransportKeys;
|
import org.briarproject.bramble.api.transport.TransportKeys;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@@ -33,11 +34,14 @@ import java.util.Map;
|
|||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A low-level interface to the database (DatabaseComponent provides a
|
* A low-level interface to the database ({@link DatabaseComponent} provides a
|
||||||
* high-level interface). Most operations take a transaction argument, which is
|
* high-level interface).
|
||||||
* obtained by calling {@link #startTransaction()}. Every transaction must be
|
* <p>
|
||||||
* terminated by calling either {@link #abortTransaction(Object) abortTransaction(T)} or
|
* Most operations take a transaction argument, which is obtained by calling
|
||||||
* {@link #commitTransaction(Object) commitTransaction(T)}, even if an exception is thrown.
|
* {@link #startTransaction()}. Every transaction must be terminated by calling
|
||||||
|
* either {@link #abortTransaction(Object) abortTransaction(T)} or
|
||||||
|
* {@link #commitTransaction(Object) commitTransaction(T)}, even if an
|
||||||
|
* exception is thrown.
|
||||||
*/
|
*/
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
interface Database<T> {
|
interface Database<T> {
|
||||||
@@ -131,7 +135,7 @@ interface Database<T> {
|
|||||||
* Stores the given transport keys for the given contact and returns a
|
* Stores the given transport keys for the given contact and returns a
|
||||||
* key set ID.
|
* key set ID.
|
||||||
*/
|
*/
|
||||||
KeySetId addTransportKeys(T txn, ContactId c, TransportKeys k)
|
TransportKeySetId addTransportKeys(T txn, ContactId c, TransportKeys k)
|
||||||
throws DbException;
|
throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -489,13 +493,13 @@ interface Database<T> {
|
|||||||
* <p/>
|
* <p/>
|
||||||
* Read-only.
|
* Read-only.
|
||||||
*/
|
*/
|
||||||
Collection<KeySet> getTransportKeys(T txn, TransportId t)
|
Collection<TransportKeySet> getTransportKeys(T txn, TransportId t)
|
||||||
throws DbException;
|
throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Increments the outgoing stream counter for the given transport keys.
|
* Increments the outgoing stream counter for the given transport keys.
|
||||||
*/
|
*/
|
||||||
void incrementStreamCounter(T txn, TransportId t, KeySetId k)
|
void incrementStreamCounter(T txn, TransportId t, TransportKeySetId k)
|
||||||
throws DbException;
|
throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -589,7 +593,7 @@ interface Database<T> {
|
|||||||
/**
|
/**
|
||||||
* Removes the given transport keys from the database.
|
* Removes the given transport keys from the database.
|
||||||
*/
|
*/
|
||||||
void removeTransportKeys(T txn, TransportId t, KeySetId k)
|
void removeTransportKeys(T txn, TransportId t, TransportKeySetId k)
|
||||||
throws DbException;
|
throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -637,13 +641,13 @@ interface Database<T> {
|
|||||||
* Sets the reordering window for the given key set and transport in the
|
* Sets the reordering window for the given key set and transport in the
|
||||||
* given time period.
|
* given time period.
|
||||||
*/
|
*/
|
||||||
void setReorderingWindow(T txn, KeySetId k, TransportId t,
|
void setReorderingWindow(T txn, TransportKeySetId k, TransportId t,
|
||||||
long timePeriod, long base, byte[] bitmap) throws DbException;
|
long timePeriod, long base, byte[] bitmap) throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Marks the given transport keys as usable for outgoing streams.
|
* Marks the given transport keys as usable for outgoing streams.
|
||||||
*/
|
*/
|
||||||
void setTransportKeysActive(T txn, TransportId t, KeySetId k)
|
void setTransportKeysActive(T txn, TransportId t, TransportKeySetId k)
|
||||||
throws DbException;
|
throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -657,5 +661,5 @@ interface Database<T> {
|
|||||||
/**
|
/**
|
||||||
* Updates the given transport keys following key rotation.
|
* Updates the given transport keys following key rotation.
|
||||||
*/
|
*/
|
||||||
void updateTransportKeys(T txn, KeySet ks) throws DbException;
|
void updateTransportKeys(T txn, TransportKeySet ks) throws DbException;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,8 +59,8 @@ import org.briarproject.bramble.api.sync.event.MessageToRequestEvent;
|
|||||||
import org.briarproject.bramble.api.sync.event.MessagesAckedEvent;
|
import org.briarproject.bramble.api.sync.event.MessagesAckedEvent;
|
||||||
import org.briarproject.bramble.api.sync.event.MessagesSentEvent;
|
import org.briarproject.bramble.api.sync.event.MessagesSentEvent;
|
||||||
import org.briarproject.bramble.api.sync.validation.MessageState;
|
import org.briarproject.bramble.api.sync.validation.MessageState;
|
||||||
import org.briarproject.bramble.api.transport.KeySet;
|
import org.briarproject.bramble.api.transport.TransportKeySet;
|
||||||
import org.briarproject.bramble.api.transport.KeySetId;
|
import org.briarproject.bramble.api.transport.TransportKeySetId;
|
||||||
import org.briarproject.bramble.api.transport.TransportKeys;
|
import org.briarproject.bramble.api.transport.TransportKeys;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -291,8 +291,8 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KeySetId addTransportKeys(Transaction transaction, ContactId c,
|
public TransportKeySetId addTransportKeys(Transaction transaction,
|
||||||
TransportKeys k) throws DbException {
|
ContactId c, TransportKeys k) throws DbException {
|
||||||
if (transaction.isReadOnly()) throw new IllegalArgumentException();
|
if (transaction.isReadOnly()) throw new IllegalArgumentException();
|
||||||
T txn = unbox(transaction);
|
T txn = unbox(transaction);
|
||||||
if (!db.containsContact(txn, c))
|
if (!db.containsContact(txn, c))
|
||||||
@@ -663,7 +663,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<KeySet> getTransportKeys(Transaction transaction,
|
public Collection<TransportKeySet> getTransportKeys(Transaction transaction,
|
||||||
TransportId t) throws DbException {
|
TransportId t) throws DbException {
|
||||||
T txn = unbox(transaction);
|
T txn = unbox(transaction);
|
||||||
if (!db.containsTransport(txn, t))
|
if (!db.containsTransport(txn, t))
|
||||||
@@ -673,7 +673,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void incrementStreamCounter(Transaction transaction, TransportId t,
|
public void incrementStreamCounter(Transaction transaction, TransportId t,
|
||||||
KeySetId k) throws DbException {
|
TransportKeySetId k) throws DbException {
|
||||||
if (transaction.isReadOnly()) throw new IllegalArgumentException();
|
if (transaction.isReadOnly()) throw new IllegalArgumentException();
|
||||||
T txn = unbox(transaction);
|
T txn = unbox(transaction);
|
||||||
if (!db.containsTransport(txn, t))
|
if (!db.containsTransport(txn, t))
|
||||||
@@ -856,7 +856,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeTransportKeys(Transaction transaction,
|
public void removeTransportKeys(Transaction transaction,
|
||||||
TransportId t, KeySetId k) throws DbException {
|
TransportId t, TransportKeySetId k) throws DbException {
|
||||||
if (transaction.isReadOnly()) throw new IllegalArgumentException();
|
if (transaction.isReadOnly()) throw new IllegalArgumentException();
|
||||||
T txn = unbox(transaction);
|
T txn = unbox(transaction);
|
||||||
if (!db.containsTransport(txn, t))
|
if (!db.containsTransport(txn, t))
|
||||||
@@ -955,9 +955,9 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setReorderingWindow(Transaction transaction, KeySetId k,
|
public void setReorderingWindow(Transaction transaction,
|
||||||
TransportId t, long timePeriod, long base, byte[] bitmap)
|
TransportKeySetId k, TransportId t, long timePeriod, long base,
|
||||||
throws DbException {
|
byte[] bitmap) throws DbException {
|
||||||
if (transaction.isReadOnly()) throw new IllegalArgumentException();
|
if (transaction.isReadOnly()) throw new IllegalArgumentException();
|
||||||
T txn = unbox(transaction);
|
T txn = unbox(transaction);
|
||||||
if (!db.containsTransport(txn, t))
|
if (!db.containsTransport(txn, t))
|
||||||
@@ -967,7 +967,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setTransportKeysActive(Transaction transaction, TransportId t,
|
public void setTransportKeysActive(Transaction transaction, TransportId t,
|
||||||
KeySetId k) throws DbException {
|
TransportKeySetId k) throws DbException {
|
||||||
if (transaction.isReadOnly()) throw new IllegalArgumentException();
|
if (transaction.isReadOnly()) throw new IllegalArgumentException();
|
||||||
T txn = unbox(transaction);
|
T txn = unbox(transaction);
|
||||||
if (!db.containsTransport(txn, t))
|
if (!db.containsTransport(txn, t))
|
||||||
@@ -977,11 +977,11 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateTransportKeys(Transaction transaction,
|
public void updateTransportKeys(Transaction transaction,
|
||||||
Collection<KeySet> keys) throws DbException {
|
Collection<TransportKeySet> keys) throws DbException {
|
||||||
if (transaction.isReadOnly()) throw new IllegalArgumentException();
|
if (transaction.isReadOnly()) throw new IllegalArgumentException();
|
||||||
T txn = unbox(transaction);
|
T txn = unbox(transaction);
|
||||||
for (KeySet ks : keys) {
|
for (TransportKeySet ks : keys) {
|
||||||
TransportId t = ks.getTransportKeys().getTransportId();
|
TransportId t = ks.getKeys().getTransportId();
|
||||||
if (db.containsTransport(txn, t))
|
if (db.containsTransport(txn, t))
|
||||||
db.updateTransportKeys(txn, ks);
|
db.updateTransportKeys(txn, ks);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,9 +27,9 @@ import org.briarproject.bramble.api.sync.MessageStatus;
|
|||||||
import org.briarproject.bramble.api.sync.validation.MessageState;
|
import org.briarproject.bramble.api.sync.validation.MessageState;
|
||||||
import org.briarproject.bramble.api.system.Clock;
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
import org.briarproject.bramble.api.transport.IncomingKeys;
|
import org.briarproject.bramble.api.transport.IncomingKeys;
|
||||||
import org.briarproject.bramble.api.transport.KeySet;
|
|
||||||
import org.briarproject.bramble.api.transport.KeySetId;
|
|
||||||
import org.briarproject.bramble.api.transport.OutgoingKeys;
|
import org.briarproject.bramble.api.transport.OutgoingKeys;
|
||||||
|
import org.briarproject.bramble.api.transport.TransportKeySet;
|
||||||
|
import org.briarproject.bramble.api.transport.TransportKeySetId;
|
||||||
import org.briarproject.bramble.api.transport.TransportKeys;
|
import org.briarproject.bramble.api.transport.TransportKeys;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
@@ -958,7 +958,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KeySetId addTransportKeys(Connection txn, ContactId c,
|
public TransportKeySetId addTransportKeys(Connection txn, ContactId c,
|
||||||
TransportKeys k) throws DbException {
|
TransportKeys k) throws DbException {
|
||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
@@ -985,7 +985,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
ps = txn.prepareStatement(sql);
|
ps = txn.prepareStatement(sql);
|
||||||
rs = ps.executeQuery();
|
rs = ps.executeQuery();
|
||||||
if (!rs.next()) throw new DbStateException();
|
if (!rs.next()) throw new DbStateException();
|
||||||
KeySetId keySetId = new KeySetId(rs.getInt(1));
|
TransportKeySetId keySetId = new TransportKeySetId(rs.getInt(1));
|
||||||
if (rs.next()) throw new DbStateException();
|
if (rs.next()) throw new DbStateException();
|
||||||
rs.close();
|
rs.close();
|
||||||
ps.close();
|
ps.close();
|
||||||
@@ -2191,8 +2191,8 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<KeySet> getTransportKeys(Connection txn, TransportId t)
|
public Collection<TransportKeySet> getTransportKeys(Connection txn,
|
||||||
throws DbException {
|
TransportId t) throws DbException {
|
||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
try {
|
try {
|
||||||
@@ -2225,11 +2225,12 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
ps = txn.prepareStatement(sql);
|
ps = txn.prepareStatement(sql);
|
||||||
ps.setString(1, t.getString());
|
ps.setString(1, t.getString());
|
||||||
rs = ps.executeQuery();
|
rs = ps.executeQuery();
|
||||||
Collection<KeySet> keys = new ArrayList<>();
|
Collection<TransportKeySet> keys = new ArrayList<>();
|
||||||
for (int i = 0; rs.next(); i++) {
|
for (int i = 0; rs.next(); i++) {
|
||||||
// There should be three times as many incoming keys
|
// There should be three times as many incoming keys
|
||||||
if (inKeys.size() < (i + 1) * 3) throw new DbStateException();
|
if (inKeys.size() < (i + 1) * 3) throw new DbStateException();
|
||||||
KeySetId keySetId = new KeySetId(rs.getInt(1));
|
TransportKeySetId keySetId =
|
||||||
|
new TransportKeySetId(rs.getInt(1));
|
||||||
ContactId contactId = new ContactId(rs.getInt(2));
|
ContactId contactId = new ContactId(rs.getInt(2));
|
||||||
long timePeriod = rs.getLong(3);
|
long timePeriod = rs.getLong(3);
|
||||||
SecretKey tagKey = new SecretKey(rs.getBytes(4));
|
SecretKey tagKey = new SecretKey(rs.getBytes(4));
|
||||||
@@ -2243,7 +2244,8 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
IncomingKeys inNext = inKeys.get(i * 3 + 2);
|
IncomingKeys inNext = inKeys.get(i * 3 + 2);
|
||||||
TransportKeys transportKeys = new TransportKeys(t, inPrev,
|
TransportKeys transportKeys = new TransportKeys(t, inPrev,
|
||||||
inCurr, inNext, outCurr);
|
inCurr, inNext, outCurr);
|
||||||
keys.add(new KeySet(keySetId, contactId, transportKeys));
|
keys.add(new TransportKeySet(keySetId, contactId,
|
||||||
|
transportKeys));
|
||||||
}
|
}
|
||||||
rs.close();
|
rs.close();
|
||||||
ps.close();
|
ps.close();
|
||||||
@@ -2257,7 +2259,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void incrementStreamCounter(Connection txn, TransportId t,
|
public void incrementStreamCounter(Connection txn, TransportId t,
|
||||||
KeySetId k) throws DbException {
|
TransportKeySetId k) throws DbException {
|
||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
try {
|
try {
|
||||||
String sql = "UPDATE outgoingKeys SET stream = stream + 1"
|
String sql = "UPDATE outgoingKeys SET stream = stream + 1"
|
||||||
@@ -2730,8 +2732,8 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeTransportKeys(Connection txn, TransportId t, KeySetId k)
|
public void removeTransportKeys(Connection txn, TransportId t,
|
||||||
throws DbException {
|
TransportKeySetId k) throws DbException {
|
||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
try {
|
try {
|
||||||
// Delete any existing outgoing keys - this will also remove any
|
// Delete any existing outgoing keys - this will also remove any
|
||||||
@@ -2934,8 +2936,9 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setReorderingWindow(Connection txn, KeySetId k, TransportId t,
|
public void setReorderingWindow(Connection txn, TransportKeySetId k,
|
||||||
long timePeriod, long base, byte[] bitmap) throws DbException {
|
TransportId t, long timePeriod, long base, byte[] bitmap)
|
||||||
|
throws DbException {
|
||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
try {
|
try {
|
||||||
String sql = "UPDATE incomingKeys SET base = ?, bitmap = ?"
|
String sql = "UPDATE incomingKeys SET base = ?, bitmap = ?"
|
||||||
@@ -2958,7 +2961,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setTransportKeysActive(Connection txn, TransportId t,
|
public void setTransportKeysActive(Connection txn, TransportId t,
|
||||||
KeySetId k) throws DbException {
|
TransportKeySetId k) throws DbException {
|
||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
try {
|
try {
|
||||||
String sql = "UPDATE outgoingKeys SET active = true"
|
String sql = "UPDATE outgoingKeys SET active = true"
|
||||||
@@ -3013,7 +3016,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateTransportKeys(Connection txn, KeySet ks)
|
public void updateTransportKeys(Connection txn, TransportKeySet ks)
|
||||||
throws DbException {
|
throws DbException {
|
||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
try {
|
try {
|
||||||
@@ -3022,7 +3025,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
+ " tagKey = ?, headerKey = ?, stream = ?"
|
+ " tagKey = ?, headerKey = ?, stream = ?"
|
||||||
+ " WHERE transportId = ? AND keySetId = ?";
|
+ " WHERE transportId = ? AND keySetId = ?";
|
||||||
ps = txn.prepareStatement(sql);
|
ps = txn.prepareStatement(sql);
|
||||||
TransportKeys k = ks.getTransportKeys();
|
TransportKeys k = ks.getKeys();
|
||||||
OutgoingKeys outCurr = k.getCurrentOutgoingKeys();
|
OutgoingKeys outCurr = k.getCurrentOutgoingKeys();
|
||||||
ps.setLong(1, outCurr.getTimePeriod());
|
ps.setLong(1, outCurr.getTimePeriod());
|
||||||
ps.setBytes(2, outCurr.getTagKey().getBytes());
|
ps.setBytes(2, outCurr.getTagKey().getBytes());
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ import org.briarproject.bramble.api.plugin.TransportId;
|
|||||||
import org.briarproject.bramble.api.plugin.duplex.DuplexPluginFactory;
|
import org.briarproject.bramble.api.plugin.duplex.DuplexPluginFactory;
|
||||||
import org.briarproject.bramble.api.plugin.simplex.SimplexPluginFactory;
|
import org.briarproject.bramble.api.plugin.simplex.SimplexPluginFactory;
|
||||||
import org.briarproject.bramble.api.transport.KeyManager;
|
import org.briarproject.bramble.api.transport.KeyManager;
|
||||||
import org.briarproject.bramble.api.transport.KeySetId;
|
|
||||||
import org.briarproject.bramble.api.transport.StreamContext;
|
import org.briarproject.bramble.api.transport.StreamContext;
|
||||||
|
import org.briarproject.bramble.api.transport.TransportKeySetId;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -95,10 +95,10 @@ class KeyManagerImpl implements KeyManager, Service, EventListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<TransportId, KeySetId> addContact(Transaction txn, ContactId c,
|
public Map<TransportId, TransportKeySetId> addContact(Transaction txn,
|
||||||
SecretKey rootKey, long timestamp, boolean alice, boolean active)
|
ContactId c, SecretKey rootKey, long timestamp, boolean alice,
|
||||||
throws DbException {
|
boolean active) throws DbException {
|
||||||
Map<TransportId, KeySetId> ids = new HashMap<>();
|
Map<TransportId, TransportKeySetId> ids = new HashMap<>();
|
||||||
for (Entry<TransportId, TransportKeyManager> e : managers.entrySet()) {
|
for (Entry<TransportId, TransportKeyManager> e : managers.entrySet()) {
|
||||||
TransportId t = e.getKey();
|
TransportId t = e.getKey();
|
||||||
TransportKeyManager m = e.getValue();
|
TransportKeyManager m = e.getValue();
|
||||||
@@ -108,9 +108,9 @@ class KeyManagerImpl implements KeyManager, Service, EventListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void activateKeys(Transaction txn, Map<TransportId, KeySetId> keys)
|
public void activateKeys(Transaction txn, Map<TransportId,
|
||||||
throws DbException {
|
TransportKeySetId> keys) throws DbException {
|
||||||
for (Entry<TransportId, KeySetId> e : keys.entrySet()) {
|
for (Entry<TransportId, TransportKeySetId> e : keys.entrySet()) {
|
||||||
TransportId t = e.getKey();
|
TransportId t = e.getKey();
|
||||||
TransportKeyManager m = managers.get(t);
|
TransportKeyManager m = managers.get(t);
|
||||||
if (m == null) {
|
if (m == null) {
|
||||||
|
|||||||
@@ -1,22 +1,22 @@
|
|||||||
package org.briarproject.bramble.transport;
|
package org.briarproject.bramble.transport;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.contact.ContactId;
|
import org.briarproject.bramble.api.contact.ContactId;
|
||||||
import org.briarproject.bramble.api.transport.KeySetId;
|
import org.briarproject.bramble.api.transport.TransportKeySetId;
|
||||||
|
|
||||||
class MutableKeySet {
|
class MutableKeySet {
|
||||||
|
|
||||||
private final KeySetId keySetId;
|
private final TransportKeySetId keySetId;
|
||||||
private final ContactId contactId;
|
private final ContactId contactId;
|
||||||
private final MutableTransportKeys transportKeys;
|
private final MutableTransportKeys transportKeys;
|
||||||
|
|
||||||
MutableKeySet(KeySetId keySetId, ContactId contactId,
|
MutableKeySet(TransportKeySetId keySetId, ContactId contactId,
|
||||||
MutableTransportKeys transportKeys) {
|
MutableTransportKeys transportKeys) {
|
||||||
this.keySetId = keySetId;
|
this.keySetId = keySetId;
|
||||||
this.contactId = contactId;
|
this.contactId = contactId;
|
||||||
this.transportKeys = transportKeys;
|
this.transportKeys = transportKeys;
|
||||||
}
|
}
|
||||||
|
|
||||||
KeySetId getKeySetId() {
|
TransportKeySetId getKeySetId() {
|
||||||
return keySetId;
|
return keySetId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ import org.briarproject.bramble.api.crypto.SecretKey;
|
|||||||
import org.briarproject.bramble.api.db.DbException;
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
import org.briarproject.bramble.api.db.Transaction;
|
import org.briarproject.bramble.api.db.Transaction;
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.bramble.api.transport.KeySetId;
|
|
||||||
import org.briarproject.bramble.api.transport.StreamContext;
|
import org.briarproject.bramble.api.transport.StreamContext;
|
||||||
|
import org.briarproject.bramble.api.transport.TransportKeySetId;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
@@ -15,10 +15,11 @@ interface TransportKeyManager {
|
|||||||
|
|
||||||
void start(Transaction txn) throws DbException;
|
void start(Transaction txn) throws DbException;
|
||||||
|
|
||||||
KeySetId addContact(Transaction txn, ContactId c, SecretKey rootKey,
|
TransportKeySetId addContact(Transaction txn, ContactId c,
|
||||||
long timestamp, boolean alice, boolean active) throws DbException;
|
SecretKey rootKey, long timestamp, boolean alice, boolean active)
|
||||||
|
throws DbException;
|
||||||
|
|
||||||
void activateKeys(Transaction txn, KeySetId k) throws DbException;
|
void activateKeys(Transaction txn, TransportKeySetId k) throws DbException;
|
||||||
|
|
||||||
void removeContact(ContactId c);
|
void removeContact(ContactId c);
|
||||||
|
|
||||||
|
|||||||
@@ -11,9 +11,9 @@ import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
|||||||
import org.briarproject.bramble.api.plugin.TransportId;
|
import org.briarproject.bramble.api.plugin.TransportId;
|
||||||
import org.briarproject.bramble.api.system.Clock;
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
import org.briarproject.bramble.api.system.Scheduler;
|
import org.briarproject.bramble.api.system.Scheduler;
|
||||||
import org.briarproject.bramble.api.transport.KeySet;
|
|
||||||
import org.briarproject.bramble.api.transport.KeySetId;
|
|
||||||
import org.briarproject.bramble.api.transport.StreamContext;
|
import org.briarproject.bramble.api.transport.StreamContext;
|
||||||
|
import org.briarproject.bramble.api.transport.TransportKeySet;
|
||||||
|
import org.briarproject.bramble.api.transport.TransportKeySetId;
|
||||||
import org.briarproject.bramble.api.transport.TransportKeys;
|
import org.briarproject.bramble.api.transport.TransportKeys;
|
||||||
import org.briarproject.bramble.transport.ReorderingWindow.Change;
|
import org.briarproject.bramble.transport.ReorderingWindow.Change;
|
||||||
|
|
||||||
@@ -56,7 +56,7 @@ class TransportKeyManagerImpl implements TransportKeyManager {
|
|||||||
private final ReentrantLock lock = new ReentrantLock();
|
private final ReentrantLock lock = new ReentrantLock();
|
||||||
|
|
||||||
// The following are locking: lock
|
// The following are locking: lock
|
||||||
private final Map<KeySetId, MutableKeySet> keys = new HashMap<>();
|
private final Map<TransportKeySetId, MutableKeySet> keys = new HashMap<>();
|
||||||
private final Map<Bytes, TagContext> inContexts = new HashMap<>();
|
private final Map<Bytes, TagContext> inContexts = new HashMap<>();
|
||||||
private final Map<ContactId, MutableKeySet> outContexts = new HashMap<>();
|
private final Map<ContactId, MutableKeySet> outContexts = new HashMap<>();
|
||||||
|
|
||||||
@@ -80,7 +80,8 @@ class TransportKeyManagerImpl implements TransportKeyManager {
|
|||||||
lock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
// Load the transport keys from the DB
|
// Load the transport keys from the DB
|
||||||
Collection<KeySet> loaded = db.getTransportKeys(txn, transportId);
|
Collection<TransportKeySet> loaded =
|
||||||
|
db.getTransportKeys(txn, transportId);
|
||||||
// Rotate the keys to the current time period
|
// Rotate the keys to the current time period
|
||||||
RotationResult rotationResult = rotateKeys(loaded, now);
|
RotationResult rotationResult = rotateKeys(loaded, now);
|
||||||
// Initialise mutable state for all contacts
|
// Initialise mutable state for all contacts
|
||||||
@@ -95,14 +96,16 @@ class TransportKeyManagerImpl implements TransportKeyManager {
|
|||||||
scheduleKeyRotation(now);
|
scheduleKeyRotation(now);
|
||||||
}
|
}
|
||||||
|
|
||||||
private RotationResult rotateKeys(Collection<KeySet> keys, long now) {
|
private RotationResult rotateKeys(Collection<TransportKeySet> keys,
|
||||||
|
long now) {
|
||||||
RotationResult rotationResult = new RotationResult();
|
RotationResult rotationResult = new RotationResult();
|
||||||
long timePeriod = now / timePeriodLength;
|
long timePeriod = now / timePeriodLength;
|
||||||
for (KeySet ks : keys) {
|
for (TransportKeySet ks : keys) {
|
||||||
TransportKeys k = ks.getTransportKeys();
|
TransportKeys k = ks.getKeys();
|
||||||
TransportKeys k1 =
|
TransportKeys k1 = transportCrypto.rotateTransportKeys(k,
|
||||||
transportCrypto.rotateTransportKeys(k, timePeriod);
|
timePeriod);
|
||||||
KeySet ks1 = new KeySet(ks.getKeySetId(), ks.getContactId(), k1);
|
TransportKeySet ks1 = new TransportKeySet(ks.getKeySetId(),
|
||||||
|
ks.getContactId(), k1);
|
||||||
if (k1.getTimePeriod() > k.getTimePeriod())
|
if (k1.getTimePeriod() > k.getTimePeriod())
|
||||||
rotationResult.rotated.add(ks1);
|
rotationResult.rotated.add(ks1);
|
||||||
rotationResult.current.add(ks1);
|
rotationResult.current.add(ks1);
|
||||||
@@ -111,15 +114,15 @@ class TransportKeyManagerImpl implements TransportKeyManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Locking: lock
|
// Locking: lock
|
||||||
private void addKeys(Collection<KeySet> keys) {
|
private void addKeys(Collection<TransportKeySet> keys) {
|
||||||
for (KeySet ks : keys) {
|
for (TransportKeySet ks : keys) {
|
||||||
addKeys(ks.getKeySetId(), ks.getContactId(),
|
addKeys(ks.getKeySetId(), ks.getContactId(),
|
||||||
new MutableTransportKeys(ks.getTransportKeys()));
|
new MutableTransportKeys(ks.getKeys()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Locking: lock
|
// Locking: lock
|
||||||
private void addKeys(KeySetId keySetId, ContactId contactId,
|
private void addKeys(TransportKeySetId keySetId, ContactId contactId,
|
||||||
MutableTransportKeys m) {
|
MutableTransportKeys m) {
|
||||||
MutableKeySet ks = new MutableKeySet(keySetId, contactId, m);
|
MutableKeySet ks = new MutableKeySet(keySetId, contactId, m);
|
||||||
keys.put(keySetId, ks);
|
keys.put(keySetId, ks);
|
||||||
@@ -130,7 +133,7 @@ class TransportKeyManagerImpl implements TransportKeyManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Locking: lock
|
// Locking: lock
|
||||||
private void encodeTags(KeySetId keySetId, ContactId contactId,
|
private void encodeTags(TransportKeySetId keySetId, ContactId contactId,
|
||||||
MutableIncomingKeys inKeys) {
|
MutableIncomingKeys inKeys) {
|
||||||
for (long streamNumber : inKeys.getWindow().getUnseen()) {
|
for (long streamNumber : inKeys.getWindow().getUnseen()) {
|
||||||
TagContext tagCtx =
|
TagContext tagCtx =
|
||||||
@@ -170,8 +173,9 @@ class TransportKeyManagerImpl implements TransportKeyManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KeySetId addContact(Transaction txn, ContactId c, SecretKey rootKey,
|
public TransportKeySetId addContact(Transaction txn, ContactId c,
|
||||||
long timestamp, boolean alice, boolean active) throws DbException {
|
SecretKey rootKey, long timestamp, boolean alice, boolean active)
|
||||||
|
throws DbException {
|
||||||
lock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
// Work out what time period the timestamp belongs to
|
// Work out what time period the timestamp belongs to
|
||||||
@@ -183,7 +187,7 @@ class TransportKeyManagerImpl implements TransportKeyManager {
|
|||||||
timePeriod = clock.currentTimeMillis() / timePeriodLength;
|
timePeriod = clock.currentTimeMillis() / timePeriodLength;
|
||||||
k = transportCrypto.rotateTransportKeys(k, timePeriod);
|
k = transportCrypto.rotateTransportKeys(k, timePeriod);
|
||||||
// Write the keys back to the DB
|
// Write the keys back to the DB
|
||||||
KeySetId keySetId = db.addTransportKeys(txn, c, k);
|
TransportKeySetId keySetId = db.addTransportKeys(txn, c, k);
|
||||||
// Initialise mutable state for the contact
|
// Initialise mutable state for the contact
|
||||||
addKeys(keySetId, c, new MutableTransportKeys(k));
|
addKeys(keySetId, c, new MutableTransportKeys(k));
|
||||||
return keySetId;
|
return keySetId;
|
||||||
@@ -193,7 +197,8 @@ class TransportKeyManagerImpl implements TransportKeyManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void activateKeys(Transaction txn, KeySetId k) throws DbException {
|
public void activateKeys(Transaction txn, TransportKeySetId k)
|
||||||
|
throws DbException {
|
||||||
lock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
MutableKeySet ks = keys.get(k);
|
MutableKeySet ks = keys.get(k);
|
||||||
@@ -323,10 +328,10 @@ class TransportKeyManagerImpl implements TransportKeyManager {
|
|||||||
lock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
// Rotate the keys to the current time period
|
// Rotate the keys to the current time period
|
||||||
Collection<KeySet> snapshot = new ArrayList<>(keys.size());
|
Collection<TransportKeySet> snapshot = new ArrayList<>(keys.size());
|
||||||
for (MutableKeySet ks : keys.values()) {
|
for (MutableKeySet ks : keys.values()) {
|
||||||
snapshot.add(new KeySet(ks.getKeySetId(), ks.getContactId(),
|
snapshot.add(new TransportKeySet(ks.getKeySetId(),
|
||||||
ks.getTransportKeys().snapshot()));
|
ks.getContactId(), ks.getTransportKeys().snapshot()));
|
||||||
}
|
}
|
||||||
RotationResult rotationResult = rotateKeys(snapshot, now);
|
RotationResult rotationResult = rotateKeys(snapshot, now);
|
||||||
// Rebuild the mutable state for all contacts
|
// Rebuild the mutable state for all contacts
|
||||||
@@ -346,12 +351,12 @@ class TransportKeyManagerImpl implements TransportKeyManager {
|
|||||||
|
|
||||||
private static class TagContext {
|
private static class TagContext {
|
||||||
|
|
||||||
private final KeySetId keySetId;
|
private final TransportKeySetId keySetId;
|
||||||
private final ContactId contactId;
|
private final ContactId contactId;
|
||||||
private final MutableIncomingKeys inKeys;
|
private final MutableIncomingKeys inKeys;
|
||||||
private final long streamNumber;
|
private final long streamNumber;
|
||||||
|
|
||||||
private TagContext(KeySetId keySetId, ContactId contactId,
|
private TagContext(TransportKeySetId keySetId, ContactId contactId,
|
||||||
MutableIncomingKeys inKeys, long streamNumber) {
|
MutableIncomingKeys inKeys, long streamNumber) {
|
||||||
this.keySetId = keySetId;
|
this.keySetId = keySetId;
|
||||||
this.contactId = contactId;
|
this.contactId = contactId;
|
||||||
@@ -362,7 +367,7 @@ class TransportKeyManagerImpl implements TransportKeyManager {
|
|||||||
|
|
||||||
private static class RotationResult {
|
private static class RotationResult {
|
||||||
|
|
||||||
private final Collection<KeySet> current = new ArrayList<>();
|
private final Collection<TransportKeySet> current = new ArrayList<>();
|
||||||
private final Collection<KeySet> rotated = new ArrayList<>();
|
private final Collection<TransportKeySet> rotated = new ArrayList<>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,9 +45,9 @@ import org.briarproject.bramble.api.sync.event.MessageToRequestEvent;
|
|||||||
import org.briarproject.bramble.api.sync.event.MessagesAckedEvent;
|
import org.briarproject.bramble.api.sync.event.MessagesAckedEvent;
|
||||||
import org.briarproject.bramble.api.sync.event.MessagesSentEvent;
|
import org.briarproject.bramble.api.sync.event.MessagesSentEvent;
|
||||||
import org.briarproject.bramble.api.transport.IncomingKeys;
|
import org.briarproject.bramble.api.transport.IncomingKeys;
|
||||||
import org.briarproject.bramble.api.transport.KeySet;
|
|
||||||
import org.briarproject.bramble.api.transport.KeySetId;
|
|
||||||
import org.briarproject.bramble.api.transport.OutgoingKeys;
|
import org.briarproject.bramble.api.transport.OutgoingKeys;
|
||||||
|
import org.briarproject.bramble.api.transport.TransportKeySet;
|
||||||
|
import org.briarproject.bramble.api.transport.TransportKeySetId;
|
||||||
import org.briarproject.bramble.api.transport.TransportKeys;
|
import org.briarproject.bramble.api.transport.TransportKeys;
|
||||||
import org.briarproject.bramble.test.BrambleMockTestCase;
|
import org.briarproject.bramble.test.BrambleMockTestCase;
|
||||||
import org.briarproject.bramble.test.CaptureArgumentAction;
|
import org.briarproject.bramble.test.CaptureArgumentAction;
|
||||||
@@ -111,7 +111,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
private final int maxLatency;
|
private final int maxLatency;
|
||||||
private final ContactId contactId;
|
private final ContactId contactId;
|
||||||
private final Contact contact;
|
private final Contact contact;
|
||||||
private final KeySetId keySetId;
|
private final TransportKeySetId keySetId;
|
||||||
|
|
||||||
public DatabaseComponentImplTest() {
|
public DatabaseComponentImplTest() {
|
||||||
clientId = getClientId();
|
clientId = getClientId();
|
||||||
@@ -132,7 +132,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
contactId = new ContactId(234);
|
contactId = new ContactId(234);
|
||||||
contact = new Contact(contactId, author, localAuthor.getId(), alias,
|
contact = new Contact(contactId, author, localAuthor.getId(), alias,
|
||||||
true, true);
|
true, true);
|
||||||
keySetId = new KeySetId(345);
|
keySetId = new TransportKeySetId(345);
|
||||||
}
|
}
|
||||||
|
|
||||||
private DatabaseComponent createDatabaseComponent(Database<Object> database,
|
private DatabaseComponent createDatabaseComponent(Database<Object> database,
|
||||||
@@ -1117,8 +1117,9 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void testTransportKeys() throws Exception {
|
public void testTransportKeys() throws Exception {
|
||||||
TransportKeys transportKeys = createTransportKeys();
|
TransportKeys transportKeys = createTransportKeys();
|
||||||
KeySet ks = new KeySet(keySetId, contactId, transportKeys);
|
TransportKeySet ks =
|
||||||
Collection<KeySet> keys = singletonList(ks);
|
new TransportKeySet(keySetId, contactId, transportKeys);
|
||||||
|
Collection<TransportKeySet> keys = singletonList(ks);
|
||||||
|
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
// startTransaction()
|
// startTransaction()
|
||||||
|
|||||||
@@ -21,9 +21,9 @@ import org.briarproject.bramble.api.sync.MessageStatus;
|
|||||||
import org.briarproject.bramble.api.sync.validation.MessageState;
|
import org.briarproject.bramble.api.sync.validation.MessageState;
|
||||||
import org.briarproject.bramble.api.system.Clock;
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
import org.briarproject.bramble.api.transport.IncomingKeys;
|
import org.briarproject.bramble.api.transport.IncomingKeys;
|
||||||
import org.briarproject.bramble.api.transport.KeySet;
|
|
||||||
import org.briarproject.bramble.api.transport.KeySetId;
|
|
||||||
import org.briarproject.bramble.api.transport.OutgoingKeys;
|
import org.briarproject.bramble.api.transport.OutgoingKeys;
|
||||||
|
import org.briarproject.bramble.api.transport.TransportKeySet;
|
||||||
|
import org.briarproject.bramble.api.transport.TransportKeySetId;
|
||||||
import org.briarproject.bramble.api.transport.TransportKeys;
|
import org.briarproject.bramble.api.transport.TransportKeys;
|
||||||
import org.briarproject.bramble.system.SystemClock;
|
import org.briarproject.bramble.system.SystemClock;
|
||||||
import org.briarproject.bramble.test.BrambleTestCase;
|
import org.briarproject.bramble.test.BrambleTestCase;
|
||||||
@@ -103,7 +103,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
|||||||
private final MessageId messageId;
|
private final MessageId messageId;
|
||||||
private final TransportId transportId;
|
private final TransportId transportId;
|
||||||
private final ContactId contactId;
|
private final ContactId contactId;
|
||||||
private final KeySetId keySetId, keySetId1;
|
private final TransportKeySetId keySetId, keySetId1;
|
||||||
private final Random random = new Random();
|
private final Random random = new Random();
|
||||||
|
|
||||||
JdbcDatabaseTest() {
|
JdbcDatabaseTest() {
|
||||||
@@ -117,8 +117,8 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
|||||||
messageId = message.getId();
|
messageId = message.getId();
|
||||||
transportId = getTransportId();
|
transportId = getTransportId();
|
||||||
contactId = new ContactId(1);
|
contactId = new ContactId(1);
|
||||||
keySetId = new KeySetId(1);
|
keySetId = new TransportKeySetId(1);
|
||||||
keySetId1 = new KeySetId(2);
|
keySetId1 = new TransportKeySetId(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract JdbcDatabase createDatabase(DatabaseConfig config,
|
protected abstract JdbcDatabase createDatabase(DatabaseConfig config,
|
||||||
@@ -673,15 +673,16 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
|||||||
assertEquals(keySetId1, db.addTransportKeys(txn, contactId, keys1));
|
assertEquals(keySetId1, db.addTransportKeys(txn, contactId, keys1));
|
||||||
|
|
||||||
// Retrieve the transport keys
|
// Retrieve the transport keys
|
||||||
Collection<KeySet> allKeys = db.getTransportKeys(txn, transportId);
|
Collection<TransportKeySet> allKeys =
|
||||||
|
db.getTransportKeys(txn, transportId);
|
||||||
assertEquals(2, allKeys.size());
|
assertEquals(2, allKeys.size());
|
||||||
for (KeySet ks : allKeys) {
|
for (TransportKeySet ks : allKeys) {
|
||||||
assertEquals(contactId, ks.getContactId());
|
assertEquals(contactId, ks.getContactId());
|
||||||
if (ks.getKeySetId().equals(keySetId)) {
|
if (ks.getKeySetId().equals(keySetId)) {
|
||||||
assertKeysEquals(keys, ks.getTransportKeys());
|
assertKeysEquals(keys, ks.getKeys());
|
||||||
} else {
|
} else {
|
||||||
assertEquals(keySetId1, ks.getKeySetId());
|
assertEquals(keySetId1, ks.getKeySetId());
|
||||||
assertKeysEquals(keys1, ks.getTransportKeys());
|
assertKeysEquals(keys1, ks.getKeys());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -689,19 +690,21 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
|||||||
TransportKeys rotated = createTransportKeys(timePeriod + 1, active);
|
TransportKeys rotated = createTransportKeys(timePeriod + 1, active);
|
||||||
TransportKeys rotated1 =
|
TransportKeys rotated1 =
|
||||||
createTransportKeys(timePeriod1 + 1, active);
|
createTransportKeys(timePeriod1 + 1, active);
|
||||||
db.updateTransportKeys(txn, new KeySet(keySetId, contactId, rotated));
|
db.updateTransportKeys(txn, new TransportKeySet(keySetId, contactId,
|
||||||
db.updateTransportKeys(txn, new KeySet(keySetId1, contactId, rotated1));
|
rotated));
|
||||||
|
db.updateTransportKeys(txn, new TransportKeySet(keySetId1, contactId,
|
||||||
|
rotated1));
|
||||||
|
|
||||||
// Retrieve the transport keys again
|
// Retrieve the transport keys again
|
||||||
allKeys = db.getTransportKeys(txn, transportId);
|
allKeys = db.getTransportKeys(txn, transportId);
|
||||||
assertEquals(2, allKeys.size());
|
assertEquals(2, allKeys.size());
|
||||||
for (KeySet ks : allKeys) {
|
for (TransportKeySet ks : allKeys) {
|
||||||
assertEquals(contactId, ks.getContactId());
|
assertEquals(contactId, ks.getContactId());
|
||||||
if (ks.getKeySetId().equals(keySetId)) {
|
if (ks.getKeySetId().equals(keySetId)) {
|
||||||
assertKeysEquals(rotated, ks.getTransportKeys());
|
assertKeysEquals(rotated, ks.getKeys());
|
||||||
} else {
|
} else {
|
||||||
assertEquals(keySetId1, ks.getKeySetId());
|
assertEquals(keySetId1, ks.getKeySetId());
|
||||||
assertKeysEquals(rotated1, ks.getTransportKeys());
|
assertKeysEquals(rotated1, ks.getKeys());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -766,12 +769,13 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
|||||||
// Increment the stream counter twice and retrieve the transport keys
|
// Increment the stream counter twice and retrieve the transport keys
|
||||||
db.incrementStreamCounter(txn, transportId, keySetId);
|
db.incrementStreamCounter(txn, transportId, keySetId);
|
||||||
db.incrementStreamCounter(txn, transportId, keySetId);
|
db.incrementStreamCounter(txn, transportId, keySetId);
|
||||||
Collection<KeySet> newKeys = db.getTransportKeys(txn, transportId);
|
Collection<TransportKeySet> newKeys =
|
||||||
|
db.getTransportKeys(txn, transportId);
|
||||||
assertEquals(1, newKeys.size());
|
assertEquals(1, newKeys.size());
|
||||||
KeySet ks = newKeys.iterator().next();
|
TransportKeySet ks = newKeys.iterator().next();
|
||||||
assertEquals(keySetId, ks.getKeySetId());
|
assertEquals(keySetId, ks.getKeySetId());
|
||||||
assertEquals(contactId, ks.getContactId());
|
assertEquals(contactId, ks.getContactId());
|
||||||
TransportKeys k = ks.getTransportKeys();
|
TransportKeys k = ks.getKeys();
|
||||||
assertEquals(transportId, k.getTransportId());
|
assertEquals(transportId, k.getTransportId());
|
||||||
OutgoingKeys outCurr = k.getCurrentOutgoingKeys();
|
OutgoingKeys outCurr = k.getCurrentOutgoingKeys();
|
||||||
assertEquals(timePeriod, outCurr.getTimePeriod());
|
assertEquals(timePeriod, outCurr.getTimePeriod());
|
||||||
@@ -810,12 +814,13 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
|||||||
random.nextBytes(bitmap);
|
random.nextBytes(bitmap);
|
||||||
db.setReorderingWindow(txn, keySetId, transportId, timePeriod,
|
db.setReorderingWindow(txn, keySetId, transportId, timePeriod,
|
||||||
base + 1, bitmap);
|
base + 1, bitmap);
|
||||||
Collection<KeySet> newKeys = db.getTransportKeys(txn, transportId);
|
Collection<TransportKeySet> newKeys =
|
||||||
|
db.getTransportKeys(txn, transportId);
|
||||||
assertEquals(1, newKeys.size());
|
assertEquals(1, newKeys.size());
|
||||||
KeySet ks = newKeys.iterator().next();
|
TransportKeySet ks = newKeys.iterator().next();
|
||||||
assertEquals(keySetId, ks.getKeySetId());
|
assertEquals(keySetId, ks.getKeySetId());
|
||||||
assertEquals(contactId, ks.getContactId());
|
assertEquals(contactId, ks.getContactId());
|
||||||
TransportKeys k = ks.getTransportKeys();
|
TransportKeys k = ks.getKeys();
|
||||||
assertEquals(transportId, k.getTransportId());
|
assertEquals(transportId, k.getTransportId());
|
||||||
IncomingKeys inCurr = k.getCurrentIncomingKeys();
|
IncomingKeys inCurr = k.getCurrentIncomingKeys();
|
||||||
assertEquals(timePeriod, inCurr.getTimePeriod());
|
assertEquals(timePeriod, inCurr.getTimePeriod());
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ import org.briarproject.bramble.api.identity.AuthorId;
|
|||||||
import org.briarproject.bramble.api.plugin.PluginConfig;
|
import org.briarproject.bramble.api.plugin.PluginConfig;
|
||||||
import org.briarproject.bramble.api.plugin.TransportId;
|
import org.briarproject.bramble.api.plugin.TransportId;
|
||||||
import org.briarproject.bramble.api.plugin.simplex.SimplexPluginFactory;
|
import org.briarproject.bramble.api.plugin.simplex.SimplexPluginFactory;
|
||||||
import org.briarproject.bramble.api.transport.KeySetId;
|
|
||||||
import org.briarproject.bramble.api.transport.StreamContext;
|
import org.briarproject.bramble.api.transport.StreamContext;
|
||||||
|
import org.briarproject.bramble.api.transport.TransportKeySetId;
|
||||||
import org.briarproject.bramble.test.BrambleMockTestCase;
|
import org.briarproject.bramble.test.BrambleMockTestCase;
|
||||||
import org.briarproject.bramble.test.DbExpectations;
|
import org.briarproject.bramble.test.DbExpectations;
|
||||||
import org.jmock.Expectations;
|
import org.jmock.Expectations;
|
||||||
@@ -51,7 +51,7 @@ public class KeyManagerImplTest extends BrambleMockTestCase {
|
|||||||
private final Transaction txn = new Transaction(null, false);
|
private final Transaction txn = new Transaction(null, false);
|
||||||
private final ContactId contactId = new ContactId(123);
|
private final ContactId contactId = new ContactId(123);
|
||||||
private final ContactId inactiveContactId = new ContactId(234);
|
private final ContactId inactiveContactId = new ContactId(234);
|
||||||
private final KeySetId keySetId = new KeySetId(345);
|
private final TransportKeySetId keySetId = new TransportKeySetId(345);
|
||||||
private final TransportId transportId = getTransportId();
|
private final TransportId transportId = getTransportId();
|
||||||
private final TransportId unknownTransportId = getTransportId();
|
private final TransportId unknownTransportId = getTransportId();
|
||||||
private final StreamContext streamContext =
|
private final StreamContext streamContext =
|
||||||
@@ -113,8 +113,8 @@ public class KeyManagerImplTest extends BrambleMockTestCase {
|
|||||||
will(returnValue(keySetId));
|
will(returnValue(keySetId));
|
||||||
}});
|
}});
|
||||||
|
|
||||||
Map<TransportId, KeySetId> ids = keyManager.addContact(txn, contactId,
|
Map<TransportId, TransportKeySetId> ids = keyManager.addContact(txn,
|
||||||
secretKey, timestamp, alice, active);
|
contactId, secretKey, timestamp, alice, active);
|
||||||
assertEquals(singletonMap(transportId, keySetId), ids);
|
assertEquals(singletonMap(transportId, keySetId), ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,10 +8,10 @@ import org.briarproject.bramble.api.db.Transaction;
|
|||||||
import org.briarproject.bramble.api.plugin.TransportId;
|
import org.briarproject.bramble.api.plugin.TransportId;
|
||||||
import org.briarproject.bramble.api.system.Clock;
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
import org.briarproject.bramble.api.transport.IncomingKeys;
|
import org.briarproject.bramble.api.transport.IncomingKeys;
|
||||||
import org.briarproject.bramble.api.transport.KeySet;
|
|
||||||
import org.briarproject.bramble.api.transport.KeySetId;
|
|
||||||
import org.briarproject.bramble.api.transport.OutgoingKeys;
|
import org.briarproject.bramble.api.transport.OutgoingKeys;
|
||||||
import org.briarproject.bramble.api.transport.StreamContext;
|
import org.briarproject.bramble.api.transport.StreamContext;
|
||||||
|
import org.briarproject.bramble.api.transport.TransportKeySet;
|
||||||
|
import org.briarproject.bramble.api.transport.TransportKeySetId;
|
||||||
import org.briarproject.bramble.api.transport.TransportKeys;
|
import org.briarproject.bramble.api.transport.TransportKeys;
|
||||||
import org.briarproject.bramble.test.BrambleMockTestCase;
|
import org.briarproject.bramble.test.BrambleMockTestCase;
|
||||||
import org.briarproject.bramble.test.DbExpectations;
|
import org.briarproject.bramble.test.DbExpectations;
|
||||||
@@ -60,8 +60,8 @@ public class TransportKeyManagerImplTest extends BrambleMockTestCase {
|
|||||||
private final long timePeriodLength = maxLatency + MAX_CLOCK_DIFFERENCE;
|
private final long timePeriodLength = maxLatency + MAX_CLOCK_DIFFERENCE;
|
||||||
private final ContactId contactId = new ContactId(123);
|
private final ContactId contactId = new ContactId(123);
|
||||||
private final ContactId contactId1 = new ContactId(234);
|
private final ContactId contactId1 = new ContactId(234);
|
||||||
private final KeySetId keySetId = new KeySetId(345);
|
private final TransportKeySetId keySetId = new TransportKeySetId(345);
|
||||||
private final KeySetId keySetId1 = new KeySetId(456);
|
private final TransportKeySetId keySetId1 = new TransportKeySetId(456);
|
||||||
private final SecretKey tagKey = TestUtils.getSecretKey();
|
private final SecretKey tagKey = TestUtils.getSecretKey();
|
||||||
private final SecretKey headerKey = TestUtils.getSecretKey();
|
private final SecretKey headerKey = TestUtils.getSecretKey();
|
||||||
private final SecretKey rootKey = TestUtils.getSecretKey();
|
private final SecretKey rootKey = TestUtils.getSecretKey();
|
||||||
@@ -71,9 +71,9 @@ public class TransportKeyManagerImplTest extends BrambleMockTestCase {
|
|||||||
public void testKeysAreRotatedAtStartup() throws Exception {
|
public void testKeysAreRotatedAtStartup() throws Exception {
|
||||||
TransportKeys shouldRotate = createTransportKeys(900, 0, true);
|
TransportKeys shouldRotate = createTransportKeys(900, 0, true);
|
||||||
TransportKeys shouldNotRotate = createTransportKeys(1000, 0, true);
|
TransportKeys shouldNotRotate = createTransportKeys(1000, 0, true);
|
||||||
Collection<KeySet> loaded = asList(
|
Collection<TransportKeySet> loaded = asList(
|
||||||
new KeySet(keySetId, contactId, shouldRotate),
|
new TransportKeySet(keySetId, contactId, shouldRotate),
|
||||||
new KeySet(keySetId1, contactId1, shouldNotRotate)
|
new TransportKeySet(keySetId1, contactId1, shouldNotRotate)
|
||||||
);
|
);
|
||||||
TransportKeys rotated = createTransportKeys(1000, 0, true);
|
TransportKeys rotated = createTransportKeys(1000, 0, true);
|
||||||
Transaction txn = new Transaction(null, false);
|
Transaction txn = new Transaction(null, false);
|
||||||
@@ -98,8 +98,8 @@ public class TransportKeyManagerImplTest extends BrambleMockTestCase {
|
|||||||
will(new EncodeTagAction());
|
will(new EncodeTagAction());
|
||||||
}
|
}
|
||||||
// Save the keys that were rotated
|
// Save the keys that were rotated
|
||||||
oneOf(db).updateTransportKeys(txn,
|
oneOf(db).updateTransportKeys(txn, singletonList(
|
||||||
singletonList(new KeySet(keySetId, contactId, rotated)));
|
new TransportKeySet(keySetId, contactId, rotated)));
|
||||||
// Schedule key rotation at the start of the next time period
|
// Schedule key rotation at the start of the next time period
|
||||||
oneOf(scheduler).schedule(with(any(Runnable.class)),
|
oneOf(scheduler).schedule(with(any(Runnable.class)),
|
||||||
with(timePeriodLength - 1), with(MILLISECONDS));
|
with(timePeriodLength - 1), with(MILLISECONDS));
|
||||||
@@ -313,8 +313,8 @@ public class TransportKeyManagerImplTest extends BrambleMockTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void testKeysAreRotatedToCurrentPeriod() throws Exception {
|
public void testKeysAreRotatedToCurrentPeriod() throws Exception {
|
||||||
TransportKeys transportKeys = createTransportKeys(1000, 0, true);
|
TransportKeys transportKeys = createTransportKeys(1000, 0, true);
|
||||||
Collection<KeySet> loaded =
|
Collection<TransportKeySet> loaded = singletonList(
|
||||||
singletonList(new KeySet(keySetId, contactId, transportKeys));
|
new TransportKeySet(keySetId, contactId, transportKeys));
|
||||||
TransportKeys rotated = createTransportKeys(1001, 0, true);
|
TransportKeys rotated = createTransportKeys(1001, 0, true);
|
||||||
Transaction txn = new Transaction(null, false);
|
Transaction txn = new Transaction(null, false);
|
||||||
Transaction txn1 = new Transaction(null, false);
|
Transaction txn1 = new Transaction(null, false);
|
||||||
@@ -359,8 +359,8 @@ public class TransportKeyManagerImplTest extends BrambleMockTestCase {
|
|||||||
will(new EncodeTagAction());
|
will(new EncodeTagAction());
|
||||||
}
|
}
|
||||||
// Save the keys that were rotated
|
// Save the keys that were rotated
|
||||||
oneOf(db).updateTransportKeys(txn1,
|
oneOf(db).updateTransportKeys(txn1, singletonList(
|
||||||
singletonList(new KeySet(keySetId, contactId, rotated)));
|
new TransportKeySet(keySetId, contactId, rotated)));
|
||||||
// Schedule key rotation at the start of the next time period
|
// Schedule key rotation at the start of the next time period
|
||||||
oneOf(scheduler).schedule(with(any(Runnable.class)),
|
oneOf(scheduler).schedule(with(any(Runnable.class)),
|
||||||
with(timePeriodLength), with(MILLISECONDS));
|
with(timePeriodLength), with(MILLISECONDS));
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import org.briarproject.bramble.api.sync.Message;
|
|||||||
import org.briarproject.bramble.api.sync.MessageId;
|
import org.briarproject.bramble.api.sync.MessageId;
|
||||||
import org.briarproject.bramble.api.system.Clock;
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
import org.briarproject.bramble.api.transport.KeyManager;
|
import org.briarproject.bramble.api.transport.KeyManager;
|
||||||
import org.briarproject.bramble.api.transport.KeySetId;
|
import org.briarproject.bramble.api.transport.TransportKeySetId;
|
||||||
import org.briarproject.briar.api.client.MessageTracker;
|
import org.briarproject.briar.api.client.MessageTracker;
|
||||||
import org.briarproject.briar.api.client.ProtocolStateException;
|
import org.briarproject.briar.api.client.ProtocolStateException;
|
||||||
import org.briarproject.briar.api.client.SessionId;
|
import org.briarproject.briar.api.client.SessionId;
|
||||||
@@ -430,7 +430,7 @@ class IntroduceeProtocolEngine
|
|||||||
s.getRemote().acceptTimestamp);
|
s.getRemote().acceptTimestamp);
|
||||||
if (timestamp == -1) throw new AssertionError();
|
if (timestamp == -1) throw new AssertionError();
|
||||||
|
|
||||||
Map<TransportId, KeySetId> keys = null;
|
Map<TransportId, TransportKeySetId> keys = null;
|
||||||
try {
|
try {
|
||||||
contactManager
|
contactManager
|
||||||
.addContact(txn, s.getRemote().author, localAuthor.getId(),
|
.addContact(txn, s.getRemote().author, localAuthor.getId(),
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import org.briarproject.bramble.api.properties.TransportProperties;
|
|||||||
import org.briarproject.bramble.api.sync.GroupId;
|
import org.briarproject.bramble.api.sync.GroupId;
|
||||||
import org.briarproject.bramble.api.sync.Message;
|
import org.briarproject.bramble.api.sync.Message;
|
||||||
import org.briarproject.bramble.api.sync.MessageId;
|
import org.briarproject.bramble.api.sync.MessageId;
|
||||||
import org.briarproject.bramble.api.transport.KeySetId;
|
import org.briarproject.bramble.api.transport.TransportKeySetId;
|
||||||
import org.briarproject.briar.api.client.SessionId;
|
import org.briarproject.briar.api.client.SessionId;
|
||||||
import org.briarproject.briar.api.introduction.Role;
|
import org.briarproject.briar.api.introduction.Role;
|
||||||
|
|
||||||
@@ -17,9 +17,9 @@ import java.util.Map;
|
|||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import javax.annotation.concurrent.Immutable;
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
|
import static org.briarproject.briar.api.introduction.Role.INTRODUCEE;
|
||||||
import static org.briarproject.briar.introduction.IntroduceeState.AWAIT_ACTIVATE;
|
import static org.briarproject.briar.introduction.IntroduceeState.AWAIT_ACTIVATE;
|
||||||
import static org.briarproject.briar.introduction.IntroduceeState.START;
|
import static org.briarproject.briar.introduction.IntroduceeState.START;
|
||||||
import static org.briarproject.briar.api.introduction.Role.INTRODUCEE;
|
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
@@ -33,12 +33,12 @@ class IntroduceeSession extends Session<IntroduceeState>
|
|||||||
@Nullable
|
@Nullable
|
||||||
private final byte[] masterKey;
|
private final byte[] masterKey;
|
||||||
@Nullable
|
@Nullable
|
||||||
private final Map<TransportId, KeySetId> transportKeys;
|
private final Map<TransportId, TransportKeySetId> transportKeys;
|
||||||
|
|
||||||
IntroduceeSession(SessionId sessionId, IntroduceeState state,
|
IntroduceeSession(SessionId sessionId, IntroduceeState state,
|
||||||
long requestTimestamp, GroupId contactGroupId, Author introducer,
|
long requestTimestamp, GroupId contactGroupId, Author introducer,
|
||||||
Local local, Remote remote, @Nullable byte[] masterKey,
|
Local local, Remote remote, @Nullable byte[] masterKey,
|
||||||
@Nullable Map<TransportId, KeySetId> transportKeys) {
|
@Nullable Map<TransportId, TransportKeySetId> transportKeys) {
|
||||||
super(sessionId, state, requestTimestamp);
|
super(sessionId, state, requestTimestamp);
|
||||||
this.contactGroupId = contactGroupId;
|
this.contactGroupId = contactGroupId;
|
||||||
this.introducer = introducer;
|
this.introducer = introducer;
|
||||||
@@ -113,7 +113,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, TransportKeySetId> transportKeys) {
|
||||||
Local local = new Local(s.local, sent.getId(), sent.getTimestamp());
|
Local local = new Local(s.local, sent.getId(), sent.getTimestamp());
|
||||||
Remote remote = new Remote(s.remote, m.getMessageId());
|
Remote remote = new Remote(s.remote, m.getMessageId());
|
||||||
return new IntroduceeSession(s.getSessionId(), AWAIT_ACTIVATE,
|
return new IntroduceeSession(s.getSessionId(), AWAIT_ACTIVATE,
|
||||||
@@ -180,7 +181,7 @@ class IntroduceeSession extends Session<IntroduceeState>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
Map<TransportId, KeySetId> getTransportKeys() {
|
Map<TransportId, TransportKeySetId> getTransportKeys() {
|
||||||
return transportKeys;
|
return transportKeys;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import org.briarproject.bramble.api.data.BdfEntry;
|
|||||||
import org.briarproject.bramble.api.identity.Author;
|
import org.briarproject.bramble.api.identity.Author;
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.bramble.api.plugin.TransportId;
|
import org.briarproject.bramble.api.plugin.TransportId;
|
||||||
import org.briarproject.bramble.api.transport.KeySetId;
|
import org.briarproject.bramble.api.transport.TransportKeySetId;
|
||||||
import org.briarproject.briar.introduction.IntroduceeSession.Common;
|
import org.briarproject.briar.introduction.IntroduceeSession.Common;
|
||||||
import org.briarproject.briar.introduction.IntroduceeSession.Local;
|
import org.briarproject.briar.introduction.IntroduceeSession.Local;
|
||||||
import org.briarproject.briar.introduction.IntroduceeSession.Remote;
|
import org.briarproject.briar.introduction.IntroduceeSession.Remote;
|
||||||
@@ -143,10 +143,10 @@ class SessionEncoderImpl implements SessionEncoder {
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private BdfDictionary encodeTransportKeys(
|
private BdfDictionary encodeTransportKeys(
|
||||||
@Nullable Map<TransportId, KeySetId> keys) {
|
@Nullable Map<TransportId, TransportKeySetId> keys) {
|
||||||
if (keys == null) return null;
|
if (keys == null) return null;
|
||||||
BdfDictionary d = new BdfDictionary();
|
BdfDictionary d = new BdfDictionary();
|
||||||
for (Map.Entry<TransportId, KeySetId> e : keys.entrySet()) {
|
for (Map.Entry<TransportId, TransportKeySetId> e : keys.entrySet()) {
|
||||||
d.put(e.getKey().getString(), e.getValue().getInt());
|
d.put(e.getKey().getString(), e.getValue().getInt());
|
||||||
}
|
}
|
||||||
return d;
|
return d;
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import org.briarproject.bramble.api.plugin.TransportId;
|
|||||||
import org.briarproject.bramble.api.properties.TransportProperties;
|
import org.briarproject.bramble.api.properties.TransportProperties;
|
||||||
import org.briarproject.bramble.api.sync.GroupId;
|
import org.briarproject.bramble.api.sync.GroupId;
|
||||||
import org.briarproject.bramble.api.sync.MessageId;
|
import org.briarproject.bramble.api.sync.MessageId;
|
||||||
import org.briarproject.bramble.api.transport.KeySetId;
|
import org.briarproject.bramble.api.transport.TransportKeySetId;
|
||||||
import org.briarproject.briar.api.client.SessionId;
|
import org.briarproject.briar.api.client.SessionId;
|
||||||
import org.briarproject.briar.api.introduction.Role;
|
import org.briarproject.briar.api.introduction.Role;
|
||||||
import org.briarproject.briar.introduction.IntroduceeSession.Local;
|
import org.briarproject.briar.introduction.IntroduceeSession.Local;
|
||||||
@@ -110,7 +110,7 @@ class SessionParserImpl implements SessionParser {
|
|||||||
Local local = parseLocal(d.getDictionary(SESSION_KEY_LOCAL));
|
Local local = parseLocal(d.getDictionary(SESSION_KEY_LOCAL));
|
||||||
Remote remote = parseRemote(d.getDictionary(SESSION_KEY_REMOTE));
|
Remote remote = parseRemote(d.getDictionary(SESSION_KEY_REMOTE));
|
||||||
byte[] masterKey = d.getOptionalRaw(SESSION_KEY_MASTER_KEY);
|
byte[] masterKey = d.getOptionalRaw(SESSION_KEY_MASTER_KEY);
|
||||||
Map<TransportId, KeySetId> transportKeys = parseTransportKeys(
|
Map<TransportId, TransportKeySetId> transportKeys = parseTransportKeys(
|
||||||
d.getOptionalDictionary(SESSION_KEY_TRANSPORT_KEYS));
|
d.getOptionalDictionary(SESSION_KEY_TRANSPORT_KEYS));
|
||||||
return new IntroduceeSession(sessionId, state, requestTimestamp,
|
return new IntroduceeSession(sessionId, state, requestTimestamp,
|
||||||
introducerGroupId, introducer, local, remote,
|
introducerGroupId, introducer, local, remote,
|
||||||
@@ -184,14 +184,13 @@ class SessionParserImpl implements SessionParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private Map<TransportId, KeySetId> parseTransportKeys(
|
private Map<TransportId, TransportKeySetId> parseTransportKeys(
|
||||||
@Nullable BdfDictionary d) throws FormatException {
|
@Nullable BdfDictionary d) throws FormatException {
|
||||||
if (d == null) return null;
|
if (d == null) return null;
|
||||||
Map<TransportId, KeySetId> map = new HashMap<>(d.size());
|
Map<TransportId, TransportKeySetId> map = new HashMap<>(d.size());
|
||||||
for (String key : d.keySet()) {
|
for (String key : d.keySet()) {
|
||||||
map.put(new TransportId(key),
|
map.put(new TransportId(key),
|
||||||
new KeySetId(d.getLong(key).intValue())
|
new TransportKeySetId(d.getLong(key).intValue()));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import org.briarproject.bramble.api.plugin.TransportId;
|
|||||||
import org.briarproject.bramble.api.properties.TransportProperties;
|
import org.briarproject.bramble.api.properties.TransportProperties;
|
||||||
import org.briarproject.bramble.api.sync.GroupId;
|
import org.briarproject.bramble.api.sync.GroupId;
|
||||||
import org.briarproject.bramble.api.sync.MessageId;
|
import org.briarproject.bramble.api.sync.MessageId;
|
||||||
import org.briarproject.bramble.api.transport.KeySetId;
|
import org.briarproject.bramble.api.transport.TransportKeySetId;
|
||||||
import org.briarproject.bramble.test.BrambleTestCase;
|
import org.briarproject.bramble.test.BrambleTestCase;
|
||||||
import org.briarproject.briar.api.client.SessionId;
|
import org.briarproject.briar.api.client.SessionId;
|
||||||
import org.briarproject.briar.introduction.IntroducerSession.Introducee;
|
import org.briarproject.briar.introduction.IntroducerSession.Introducee;
|
||||||
@@ -75,7 +75,8 @@ public class SessionEncoderParserIntegrationTest extends BrambleTestCase {
|
|||||||
getTransportPropertiesMap(3);
|
getTransportPropertiesMap(3);
|
||||||
private final Map<TransportId, TransportProperties>
|
private final Map<TransportId, TransportProperties>
|
||||||
remoteTransportProperties = getTransportPropertiesMap(3);
|
remoteTransportProperties = getTransportPropertiesMap(3);
|
||||||
private final Map<TransportId, KeySetId> transportKeys = new HashMap<>();
|
private final Map<TransportId, TransportKeySetId> transportKeys =
|
||||||
|
new HashMap<>();
|
||||||
private final byte[] localMacKey = getRandomBytes(SecretKey.LENGTH);
|
private final byte[] localMacKey = getRandomBytes(SecretKey.LENGTH);
|
||||||
private final byte[] remoteMacKey = getRandomBytes(SecretKey.LENGTH);
|
private final byte[] remoteMacKey = getRandomBytes(SecretKey.LENGTH);
|
||||||
|
|
||||||
@@ -88,9 +89,9 @@ public class SessionEncoderParserIntegrationTest extends BrambleTestCase {
|
|||||||
sessionParser = new SessionParserImpl(clientHelper);
|
sessionParser = new SessionParserImpl(clientHelper);
|
||||||
author1 = getRealAuthor(authorFactory);
|
author1 = getRealAuthor(authorFactory);
|
||||||
author2 = getRealAuthor(authorFactory);
|
author2 = getRealAuthor(authorFactory);
|
||||||
transportKeys.put(getTransportId(), new KeySetId(1));
|
transportKeys.put(getTransportId(), new TransportKeySetId(1));
|
||||||
transportKeys.put(getTransportId(), new KeySetId(2));
|
transportKeys.put(getTransportId(), new TransportKeySetId(2));
|
||||||
transportKeys.put(getTransportId(), new KeySetId(3));
|
transportKeys.put(getTransportId(), new TransportKeySetId(3));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user