Add key set and key set ID classes for static keys.

This commit is contained in:
akwizgran
2019-04-16 16:56:50 +01:00
parent 7acbe56197
commit 0f5f440f1c
23 changed files with 313 additions and 184 deletions

View File

@@ -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;
}

View File

@@ -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;
/**

View File

@@ -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);
}
}

View File

@@ -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;
}
}

View File

@@ -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

View File

@@ -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);
}
}

View File

@@ -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;
}
}