Partial implementation of the invitation protocol (untested).

This commit is contained in:
akwizgran
2012-02-23 23:18:25 +00:00
parent 34cd8cddc3
commit c316ebcf7a
24 changed files with 586 additions and 74 deletions

View File

@@ -15,6 +15,11 @@ public interface CryptoComponent {
ErasableKey deriveMacKey(byte[] secret, boolean initiator);
byte[][] deriveInitialSecrets(byte[] theirPublicKey, KeyPair ourKeyPair,
int invitationCode, boolean initiator);
int deriveConfirmationCode(byte[] secret, boolean initiator);
byte[] deriveNextSecret(byte[] secret, int index, long connection);
KeyPair generateKeyPair();
@@ -25,6 +30,8 @@ public interface CryptoComponent {
MessageDigest getMessageDigest();
PseudoRandom getPseudoRandom(int seed);
SecureRandom getSecureRandom();
Cipher getTagCipher();

View File

@@ -0,0 +1,6 @@
package net.sf.briar.api.crypto;
public interface PseudoRandom {
byte[] nextBytes(int bytes);
}

View File

@@ -0,0 +1,6 @@
package net.sf.briar.api.plugins;
public interface IncomingInvitationCallback extends InvitationCallback {
int enterInvitationCode();
}

View File

@@ -0,0 +1,14 @@
package net.sf.briar.api.plugins;
public interface InvitationCallback {
boolean isCancelled();
int enterConfirmationCode(int code);
void showProgress(String... message);
void showFailure(String... message);
void showSuccess();
}

View File

@@ -0,0 +1,14 @@
package net.sf.briar.api.plugins;
public interface InvitationConstants {
static final long INVITATION_TIMEOUT = 60 * 1000; // 1 minute
static final int CODE_BITS = 19; // Codes must fit into six decimal digits
static final int MAX_CODE = 1 << CODE_BITS - 1;
static final int HASH_LENGTH = 48;
static final int MAX_PUBLIC_KEY_LENGTH = 120;
}

View File

@@ -0,0 +1,12 @@
package net.sf.briar.api.plugins;
import net.sf.briar.api.plugins.duplex.DuplexPlugin;
public interface InvitationStarter {
void startIncomingInvitation(DuplexPlugin plugin,
IncomingInvitationCallback callback);
void startOutgoingInvitation(DuplexPlugin plugin,
OutgoingInvitationCallback callback);
}

View File

@@ -0,0 +1,6 @@
package net.sf.briar.api.plugins;
public interface OutgoingInvitationCallback extends InvitationCallback {
void showInvitationCode(int code);
}

View File

@@ -1,5 +1,10 @@
package net.sf.briar.api.plugins;
import java.util.Collection;
import net.sf.briar.api.plugins.duplex.DuplexPlugin;
import net.sf.briar.api.plugins.simplex.SimplexPlugin;
public interface PluginManager {
/**
@@ -12,4 +17,10 @@ public interface PluginManager {
* Stops the plugins and returns the number of plugins successfully stopped.
*/
int stop();
/** Returns any duplex plugins that support invitations. */
Collection<DuplexPlugin> getDuplexInvitationPlugins();
/** Returns any simplex plugins that support invitations. */
Collection<SimplexPlugin> getSimplexInvitationPlugins();
}

View File

@@ -1,6 +1,7 @@
package net.sf.briar.api.plugins.duplex;
import net.sf.briar.api.ContactId;
import net.sf.briar.api.crypto.PseudoRandom;
import net.sf.briar.api.plugins.Plugin;
/** An interface for transport plugins that support duplex communication. */
@@ -17,11 +18,11 @@ public interface DuplexPlugin extends Plugin {
* Starts the invitation process from the inviter's side. Returns null if
* no connection can be established within the given timeout.
*/
DuplexTransportConnection sendInvitation(int code, long timeout);
DuplexTransportConnection sendInvitation(PseudoRandom r, long timeout);
/**
* Starts the invitation process from the invitee's side. Returns null if
* no connection can be established within the given timeout.
*/
DuplexTransportConnection acceptInvitation(int code, long timeout);
DuplexTransportConnection acceptInvitation(PseudoRandom r, long timeout);
}

View File

@@ -1,6 +1,7 @@
package net.sf.briar.api.plugins.simplex;
import net.sf.briar.api.ContactId;
import net.sf.briar.api.crypto.PseudoRandom;
import net.sf.briar.api.plugins.Plugin;
/** An interface for transport plugins that support simplex communication. */
@@ -24,23 +25,24 @@ public interface SimplexPlugin extends Plugin {
* Starts the invitation process from the inviter's side. Returns null if
* no connection can be established within the given timeout.
*/
SimplexTransportWriter sendInvitation(int code, long timeout);
SimplexTransportWriter sendInvitation(PseudoRandom r, long timeout);
/**
* Starts the invitation process from the invitee's side. Returns null if
* no connection can be established within the given timeout.
*/
SimplexTransportReader acceptInvitation(int code, long timeout);
SimplexTransportReader acceptInvitation(PseudoRandom r, long timeout);
/**
* Continues the invitation process from the invitee's side. Returns null
* if no connection can be established within the given timeout.
*/
SimplexTransportWriter sendInvitationResponse(int code, long timeout);
SimplexTransportWriter sendInvitationResponse(PseudoRandom r, long timeout);
/**
* Continues the invitation process from the inviter's side. Returns null
* if no connection can be established within the given timeout.
*/
SimplexTransportReader acceptInvitationResponse(int code, long timeout);
SimplexTransportReader acceptInvitationResponse(PseudoRandom r,
long timeout);
}