Forward secrecy.

Each connection's keys are derived from a secret that is erased after
deriving the keys and the secret for the next connection.
This commit is contained in:
akwizgran
2011-11-16 15:35:16 +00:00
parent d02a68edfc
commit f6ae4734ce
45 changed files with 506 additions and 430 deletions

View File

@@ -8,7 +8,10 @@ import java.util.Random;
import junit.framework.TestCase;
import net.sf.briar.TestDatabaseModule;
import net.sf.briar.api.ContactId;
import net.sf.briar.api.protocol.TransportIndex;
import net.sf.briar.api.transport.ConnectionContext;
import net.sf.briar.api.transport.ConnectionContextFactory;
import net.sf.briar.api.transport.ConnectionWriter;
import net.sf.briar.api.transport.ConnectionWriterFactory;
import net.sf.briar.crypto.CryptoModule;
@@ -26,8 +29,10 @@ import com.google.inject.Injector;
public class ConnectionWriterTest extends TestCase {
private final ConnectionContextFactory connectionContextFactory;
private final ConnectionWriterFactory connectionWriterFactory;
private final byte[] outSecret;
private final byte[] secret;
private final ContactId contactId = new ContactId(13);
private final TransportIndex transportIndex = new TransportIndex(13);
private final long connection = 12345L;
@@ -38,17 +43,22 @@ public class ConnectionWriterTest extends TestCase {
new ProtocolWritersModule(), new SerialModule(),
new TestDatabaseModule(), new TransportBatchModule(),
new TransportModule(), new TransportStreamModule());
connectionContextFactory =
i.getInstance(ConnectionContextFactory.class);
connectionWriterFactory = i.getInstance(ConnectionWriterFactory.class);
outSecret = new byte[32];
new Random().nextBytes(outSecret);
secret = new byte[32];
new Random().nextBytes(secret);
}
@Test
public void testOverhead() throws Exception {
ByteArrayOutputStream out =
new ByteArrayOutputStream(MIN_CONNECTION_LENGTH);
ConnectionContext ctx =
connectionContextFactory.createConnectionContext(contactId,
transportIndex, connection, secret);
ConnectionWriter w = connectionWriterFactory.createConnectionWriter(out,
MIN_CONNECTION_LENGTH, transportIndex, connection, outSecret);
MIN_CONNECTION_LENGTH, ctx);
// Check that the connection writer thinks there's room for a packet
long capacity = w.getRemainingCapacity();
assertTrue(capacity >= MAX_PACKET_LENGTH);