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