From 9cc8d4477842997e37db1c2869ff616a13383b35 Mon Sep 17 00:00:00 2001 From: akwizgran Date: Wed, 19 May 2021 10:42:47 +0100 Subject: [PATCH] Add a key manager method for adding a single set of transport keys. --- .../bramble/api/transport/KeyManager.java | 19 +++++++++++++++++-- .../bramble/transport/KeyManagerImpl.java | 16 ++++++++++++---- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/bramble-api/src/main/java/org/briarproject/bramble/api/transport/KeyManager.java b/bramble-api/src/main/java/org/briarproject/bramble/api/transport/KeyManager.java index 50f7d8aa0..086e46416 100644 --- a/bramble-api/src/main/java/org/briarproject/bramble/api/transport/KeyManager.java +++ b/bramble-api/src/main/java/org/briarproject/bramble/api/transport/KeyManager.java @@ -22,8 +22,23 @@ public interface KeyManager { /** * Derives and stores a set of rotation mode transport keys for - * communicating with the given contact over each transport and returns the - * key set IDs. + * communicating with the given contact over the given transport and + * returns the key set ID. + *

+ * {@link StreamContext StreamContexts} for the contact can be created + * after this method has returned. + * + * @param alice True if the local party is Alice + * @param active Whether the derived keys can be used for outgoing streams + */ + KeySetId addRotationKeys(Transaction txn, ContactId c, TransportId t, + SecretKey rootKey, long timestamp, boolean alice, + boolean active) throws DbException; + + /** + * Derives and stores a set of rotation mode transport keys for + * communicating with the given contact over each supported transport and + * returns the key set IDs. *

* {@link StreamContext StreamContexts} for the contact can be created * after this method has returned. diff --git a/bramble-core/src/main/java/org/briarproject/bramble/transport/KeyManagerImpl.java b/bramble-core/src/main/java/org/briarproject/bramble/transport/KeyManagerImpl.java index 58aeb7cea..ded31ab50 100644 --- a/bramble-core/src/main/java/org/briarproject/bramble/transport/KeyManagerImpl.java +++ b/bramble-core/src/main/java/org/briarproject/bramble/transport/KeyManagerImpl.java @@ -101,9 +101,17 @@ class KeyManagerImpl implements KeyManager, Service, EventListener { } @Override - public Map addRotationKeys( - Transaction txn, ContactId c, SecretKey rootKey, long timestamp, - boolean alice, boolean active) throws DbException { + public KeySetId addRotationKeys(Transaction txn, ContactId c, + TransportId t, SecretKey rootKey, long timestamp, boolean alice, + boolean active) throws DbException { + return withManager(t, m -> + m.addRotationKeys(txn, c, rootKey, timestamp, alice, active)); + } + + @Override + public Map addRotationKeys(Transaction txn, + ContactId c, SecretKey rootKey, long timestamp, boolean alice, + boolean active) throws DbException { Map ids = new HashMap<>(); for (Entry e : managers.entrySet()) { TransportId t = e.getKey(); @@ -137,7 +145,7 @@ class KeyManagerImpl implements KeyManager, Service, EventListener { PendingContactId p, PublicKey theirPublicKey, KeyPair ourKeyPair) throws DbException, GeneralSecurityException { SecretKey staticMasterKey = transportCrypto - .deriveStaticMasterKey(theirPublicKey, ourKeyPair); + .deriveStaticMasterKey(theirPublicKey, ourKeyPair); SecretKey rootKey = transportCrypto.deriveHandshakeRootKey(staticMasterKey, true); boolean alice = transportCrypto.isAlice(theirPublicKey, ourKeyPair);