Implemented KeyManager (untested).

A test is failing due to key derivation errors - must be fixed!
This commit is contained in:
akwizgran
2012-10-24 18:16:17 +01:00
parent cc6e9d53ad
commit 27e50b8495
25 changed files with 540 additions and 306 deletions

View File

@@ -6,10 +6,20 @@ import net.sf.briar.api.transport.ConnectionContext;
public interface KeyManager {
/**
* Starts the key manager and returns true if the manager started
* successfully. This method must be called after the database has been
* opened.
*/
boolean start();
/** Stops the key manager. */
void stop();
/**
* Returns a connection context for connecting to the given contact over
* the given transport, or null if the contact does not support the
* transport.
* the given transport, or null if an error occurs or the contact does not
* support the transport.
*/
ConnectionContext getConnectionContext(ContactId c, TransportId t);
}

View File

@@ -114,9 +114,6 @@ public interface DatabaseComponent {
/** Returns the IDs of all contacts. */
Collection<ContactId> getContacts() throws DbException;
/** Returns all contact transports. */
Collection<ContactTransport> getContactTransports() throws DbException;
/** Returns the local transport properties for the given transport. */
TransportProperties getLocalProperties(TransportId t) throws DbException;
@@ -150,9 +147,9 @@ public interface DatabaseComponent {
/**
* Increments the outgoing connection counter for the given contact
* transport in the given rotation period.
* transport in the given rotation period and returns the old value.
*/
void incrementConnectionCounter(ContactId c, TransportId t, long period)
long incrementConnectionCounter(ContactId c, TransportId t, long period)
throws DbException;
/** Processes an acknowledgement from the given contact. */

View File

@@ -1,20 +1,19 @@
package net.sf.briar.api.db;
import static net.sf.briar.api.transport.TransportConstants.CONNECTION_WINDOW_SIZE;
import net.sf.briar.api.ContactId;
import net.sf.briar.api.protocol.TransportId;
public class TemporarySecret {
public class TemporarySecret extends ContactTransport {
private final ContactId contactId;
private final TransportId transportId;
private final long period, outgoing, centre;
private final byte[] secret, bitmap;
public TemporarySecret(ContactId contactId, TransportId transportId,
long epoch, long clockDiff, long latency, boolean alice,
long period, byte[] secret, long outgoing, long centre,
byte[] bitmap) {
this.contactId = contactId;
this.transportId = transportId;
super(contactId, transportId, epoch, clockDiff, latency, alice);
this.period = period;
this.secret = secret;
this.outgoing = outgoing;
@@ -22,12 +21,14 @@ public class TemporarySecret {
this.bitmap = bitmap;
}
public ContactId getContactId() {
return contactId;
}
public TransportId getTransportId() {
return transportId;
public TemporarySecret(TemporarySecret old, long period, byte[] secret) {
super(old.getContactId(), old.getTransportId(), old.getEpoch(),
old.getClockDifference(), old.getLatency(), old.getAlice());
this.period = period;
this.secret = secret;
outgoing = 0L;
centre = 0L;
bitmap = new byte[CONNECTION_WINDOW_SIZE / 8];
}
public long getPeriod() {

View File

@@ -2,6 +2,7 @@ package net.sf.briar.api.transport;
import net.sf.briar.api.ContactId;
import net.sf.briar.api.db.DbException;
import net.sf.briar.api.db.TemporarySecret;
import net.sf.briar.api.protocol.TransportId;
/**
@@ -17,10 +18,11 @@ public interface ConnectionRecogniser {
ConnectionContext acceptConnection(TransportId t, byte[] tag)
throws DbException;
void addWindow(ContactId c, TransportId t, long period, boolean alice,
byte[] secret, long centre, byte[] bitmap) throws DbException;
void addSecret(TemporarySecret s) throws DbException;
void removeWindow(ContactId c, TransportId t, long period);
void removeSecret(ContactId c, TransportId t, long period);
void removeWindows(ContactId c);
void removeSecrets(ContactId c);
void removeSecrets();
}