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

@@ -15,7 +15,7 @@ public interface CryptoComponent {
ErasableKey deriveMacKey(byte[] secret, boolean initiator);
byte[] deriveNextSecret(byte[] secret, long connection);
byte[] deriveNextSecret(byte[] secret, int index, long connection);
KeyPair generateKeyPair();

View File

@@ -57,8 +57,7 @@ public interface DatabaseComponent {
* Adds a new contact to the database with the given secrets and returns an
* ID for the contact.
*/
ContactId addContact(byte[] incomingSecret, byte[] outgoingSecret)
throws DbException;
ContactId addContact(byte[] inSecret, byte[] outSecret) throws DbException;
/** Adds a locally generated group message to the database. */
void addLocalGroupMessage(Message m) throws DbException;
@@ -160,9 +159,6 @@ public interface DatabaseComponent {
Map<ContactId, TransportProperties> getRemoteProperties(TransportId t)
throws DbException;
/** Returns the secret shared with the given contact. */
byte[] getSharedSecret(ContactId c, boolean incoming) throws DbException;
/** Returns the set of groups to which the user subscribes. */
Collection<Group> getSubscriptions() throws DbException;

View File

@@ -5,9 +5,9 @@ import net.sf.briar.api.protocol.TransportIndex;
public interface BatchConnectionFactory {
void createIncomingConnection(TransportIndex i, ContactId c,
void createIncomingConnection(ConnectionContext ctx,
BatchTransportReader r, byte[] encryptedIv);
void createOutgoingConnection(TransportIndex i, ContactId c,
void createOutgoingConnection(ContactId c, TransportIndex i,
BatchTransportWriter w);
}

View File

@@ -10,4 +10,6 @@ public interface ConnectionContext {
TransportIndex getTransportIndex();
long getConnectionNumber();
byte[] getSecret();
}

View File

@@ -6,5 +6,8 @@ import net.sf.briar.api.protocol.TransportIndex;
public interface ConnectionContextFactory {
ConnectionContext createConnectionContext(ContactId c, TransportIndex i,
long connection);
long connection, byte[] secret);
ConnectionContext createNextConnectionContext(ContactId c, TransportIndex i,
long connection, byte[] previousSecret);
}

View File

@@ -8,10 +8,10 @@ public interface ConnectionDispatcher {
void dispatchReader(TransportId t, BatchTransportReader r);
void dispatchWriter(TransportIndex i, ContactId c, BatchTransportWriter w);
void dispatchWriter(ContactId c, TransportIndex i, BatchTransportWriter w);
void dispatchIncomingConnection(TransportId t, StreamTransportConnection s);
void dispatchOutgoingConnection(TransportIndex i, ContactId c,
void dispatchOutgoingConnection(ContactId c, TransportIndex i,
StreamTransportConnection s);
}

View File

@@ -2,22 +2,19 @@ package net.sf.briar.api.transport;
import java.io.InputStream;
import net.sf.briar.api.protocol.TransportIndex;
public interface ConnectionReaderFactory {
/**
* Creates a connection reader for a batch-mode connection or the
* initiator's side of a stream-mode connection. The secret is erased before
* returning.
* initiator's side of a stream-mode connection.
*/
ConnectionReader createConnectionReader(InputStream in, TransportIndex i,
byte[] encryptedIv, byte[] secret);
ConnectionReader createConnectionReader(InputStream in,
ConnectionContext ctx, byte[] encryptedIv);
/**
* Creates a connection reader for the responder's side of a stream-mode
* connection. The secret is erased before returning.
* connection.
*/
ConnectionReader createConnectionReader(InputStream in, TransportIndex i,
long connection, byte[] secret);
ConnectionReader createConnectionReader(InputStream in,
ConnectionContext ctx);
}

View File

@@ -1,6 +1,6 @@
package net.sf.briar.api.transport;
import java.util.Collection;
import java.util.Map;
public interface ConnectionWindow {
@@ -8,5 +8,5 @@ public interface ConnectionWindow {
void setSeen(long connection);
Collection<Long> getUnseen();
Map<Long, byte[]> getUnseen();
}

View File

@@ -1,10 +1,13 @@
package net.sf.briar.api.transport;
import java.util.Collection;
import java.util.Map;
import net.sf.briar.api.protocol.TransportIndex;
public interface ConnectionWindowFactory {
ConnectionWindow createConnectionWindow();
ConnectionWindow createConnectionWindow(TransportIndex i, byte[] secret);
ConnectionWindow createConnectionWindow(Collection<Long> unseen);
ConnectionWindow createConnectionWindow(TransportIndex i,
Map<Long, byte[]> unseen);
}

View File

@@ -2,22 +2,19 @@ package net.sf.briar.api.transport;
import java.io.OutputStream;
import net.sf.briar.api.protocol.TransportIndex;
public interface ConnectionWriterFactory {
/**
* Creates a connection writer for a batch-mode connection or the
* initiator's side of a stream-mode connection. The secret is erased before
* returning.
* initiator's side of a stream-mode connection.
*/
ConnectionWriter createConnectionWriter(OutputStream out, long capacity,
TransportIndex i, long connection, byte[] secret);
ConnectionContext ctx);
/**
* Creates a connection writer for the responder's side of a stream-mode
* connection. The secret is erased before returning.
* connection.
*/
ConnectionWriter createConnectionWriter(OutputStream out, long capacity,
TransportIndex i, byte[] encryptedIv, byte[] secret);
ConnectionContext ctx, byte[] encryptedIv);
}

View File

@@ -5,9 +5,9 @@ import net.sf.briar.api.protocol.TransportIndex;
public interface StreamConnectionFactory {
void createIncomingConnection(TransportIndex i, ContactId c,
void createIncomingConnection(ConnectionContext ctx,
StreamTransportConnection s, byte[] encryptedIv);
void createOutgoingConnection(TransportIndex i, ContactId c,
void createOutgoingConnection(ContactId c, TransportIndex i,
StreamTransportConnection s);
}