Tests for key rotation.

This commit is contained in:
akwizgran
2013-04-10 17:30:26 +01:00
parent 5b5428bd8a
commit 72fae48aef
7 changed files with 1383 additions and 35 deletions

View File

@@ -135,6 +135,7 @@ abstract class DuplexConnection implements DatabaseListener {
public void eventOccurred(DatabaseEvent e) {
if(e instanceof ContactRemovedEvent) {
ContactRemovedEvent c = (ContactRemovedEvent) e;
// FIXME: Listeners should not block
if(contactId.equals(c.getContactId())) dispose(false, true);
} else if(e instanceof GroupMessageAddedEvent) {
if(canSendOffer.getAndSet(false))

View File

@@ -300,6 +300,7 @@ class KeyManagerImpl extends TimerTask implements KeyManager, DatabaseListener {
if(e instanceof ContactRemovedEvent) {
ContactId c = ((ContactRemovedEvent) e).getContactId();
connectionRecogniser.removeSecrets(c);
// FIXME: Listeners should not block
synchronized(this) {
removeAndEraseSecrets(c, oldSecrets);
removeAndEraseSecrets(c, currentSecrets);
@@ -307,12 +308,14 @@ class KeyManagerImpl extends TimerTask implements KeyManager, DatabaseListener {
}
} else if(e instanceof TransportAddedEvent) {
TransportAddedEvent t = (TransportAddedEvent) e;
// FIXME: Listeners should not block
synchronized(this) {
maxLatencies.put(t.getTransportId(), t.getMaxLatency());
}
} else if(e instanceof TransportRemovedEvent) {
TransportId t = ((TransportRemovedEvent) e).getTransportId();
connectionRecogniser.removeSecrets(t);
// FIXME: Listeners should not block
synchronized(this) {
maxLatencies.remove(t);
removeAndEraseSecrets(t, oldSecrets);

View File

@@ -20,6 +20,7 @@ import net.sf.briar.api.transport.ConnectionContext;
import net.sf.briar.api.transport.TemporarySecret;
import net.sf.briar.util.ByteUtils;
// FIXME: Don't make alien calls with a lock held
/** A connection recogniser for a specific transport. */
class TransportConnectionRecogniser {
@@ -56,15 +57,15 @@ class TransportConnectionRecogniser {
byte[] tag1 = new byte[TAG_LENGTH];
crypto.encodeTag(tag1, cipher, key, connection1);
if(connection1 < connection) {
TagContext old = tagMap.remove(new Bytes(tag1));
assert old != null;
ByteUtils.erase(old.context.getSecret());
TagContext removed = tagMap.remove(new Bytes(tag1));
assert removed != null;
ByteUtils.erase(removed.context.getSecret());
} else {
ConnectionContext ctx1 = new ConnectionContext(contactId,
transportId, secret.clone(), connection1, alice);
TagContext tctx1 = new TagContext(window, ctx1, period);
TagContext old = tagMap.put(new Bytes(tag1), tctx1);
assert old == null;
TagContext duplicate = tagMap.put(new Bytes(tag1), tctx1);
assert duplicate == null;
}
}
key.erase();
@@ -92,8 +93,8 @@ class TransportConnectionRecogniser {
ConnectionContext ctx = new ConnectionContext(contactId,
transportId, secret.clone(), connection, alice);
TagContext tctx = new TagContext(window, ctx, period);
TagContext old = tagMap.put(new Bytes(tag), tctx);
assert old == null;
TagContext duplicate = tagMap.put(new Bytes(tag), tctx);
assert duplicate == null;
}
key.erase();
// Create a removal context to remove the window later
@@ -116,9 +117,9 @@ class TransportConnectionRecogniser {
byte[] tag = new byte[TAG_LENGTH];
for(long connection : rctx.window.getUnseen()) {
crypto.encodeTag(tag, cipher, key, connection);
TagContext old = tagMap.remove(new Bytes(tag));
assert old != null;
ByteUtils.erase(old.context.getSecret());
TagContext removed = tagMap.remove(new Bytes(tag));
assert removed != null;
ByteUtils.erase(removed.context.getSecret());
}
key.erase();
ByteUtils.erase(rctx.secret);
@@ -170,8 +171,8 @@ class TransportConnectionRecogniser {
@Override
public boolean equals(Object o) {
if(o instanceof RemovalKey) {
RemovalKey w = (RemovalKey) o;
return contactId.equals(w.contactId) && period == w.period;
RemovalKey k = (RemovalKey) o;
return contactId.equals(k.contactId) && period == k.period;
}
return false;
}