Add key manager method for contacts with handshake keys.

This commit is contained in:
akwizgran
2019-05-09 12:10:07 +01:00
parent 84e2402404
commit f42fc5213e
6 changed files with 118 additions and 14 deletions

View File

@@ -100,6 +100,18 @@ class KeyManagerImpl implements KeyManager, Service, EventListener {
return ids;
}
@Override
public Map<TransportId, KeySetId> addContact(Transaction txn,
ContactId c, SecretKey rootKey, boolean alice) throws DbException {
Map<TransportId, KeySetId> ids = new HashMap<>();
for (Entry<TransportId, TransportKeyManager> e : managers.entrySet()) {
TransportId t = e.getKey();
TransportKeyManager m = e.getValue();
ids.put(t, m.addContact(txn, c, rootKey, alice));
}
return ids;
}
@Override
public void activateKeys(Transaction txn, Map<TransportId, KeySetId> keys)
throws DbException {

View File

@@ -18,6 +18,9 @@ interface TransportKeyManager {
KeySetId addContact(Transaction txn, ContactId c, SecretKey rootKey,
long timestamp, boolean alice, boolean active) throws DbException;
KeySetId addContact(Transaction txn, ContactId c, SecretKey rootKey,
boolean alice) throws DbException;
void activateKeys(Transaction txn, KeySetId k) throws DbException;
void removeContact(ContactId c);

View File

@@ -213,6 +213,26 @@ class TransportKeyManagerImpl implements TransportKeyManager {
}
}
@Override
public KeySetId addContact(Transaction txn, ContactId c, SecretKey rootKey,
boolean alice) throws DbException {
lock.lock();
try {
// Work out what time period we're in
long timePeriod = clock.currentTimeMillis() / timePeriodLength;
// Derive the transport keys
TransportKeys k = transportCrypto.deriveHandshakeKeys(transportId,
rootKey, timePeriod, alice);
// Write the keys back to the DB
KeySetId keySetId = db.addTransportKeys(txn, c, k);
// Initialise mutable state for the contact
addKeys(keySetId, c, null, new MutableTransportKeys(k));
return keySetId;
} finally {
lock.unlock();
}
}
@Override
public void activateKeys(Transaction txn, KeySetId k) throws DbException {
lock.lock();