mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 19:29:06 +01:00
Massive refactoring to use pseudonyms instead of nicknames for contacts.
The invitation and private messaging UIs are currently broken. Some key rotation bugs were fixed; others may have been created (unit tests needed). An encoding for private keys was added. Pseudonyms were moved out of the messaging package and ratings were moved in.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
package net.sf.briar.api.messaging;
|
||||
package net.sf.briar.api;
|
||||
|
||||
/** A pseudonymous author of {@link Message}s. */
|
||||
/** A pseudonym for a user. */
|
||||
public class Author {
|
||||
|
||||
private final AuthorId id;
|
||||
@@ -23,10 +23,7 @@ public class Author {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the public key that is used to verify messages signed by the
|
||||
* author.
|
||||
*/
|
||||
/** Returns the public key used to verify the pseudonym's signatures. */
|
||||
public byte[] getPublicKey() {
|
||||
return publicKey;
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package net.sf.briar.api.messaging;
|
||||
package net.sf.briar.api;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package net.sf.briar.api.messaging;
|
||||
package net.sf.briar.api;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@@ -3,12 +3,12 @@ package net.sf.briar.api;
|
||||
public class Contact {
|
||||
|
||||
private final ContactId id;
|
||||
private final String name;
|
||||
private final Author author;
|
||||
private final long lastConnected;
|
||||
|
||||
public Contact(ContactId id, String name, long lastConnected) {
|
||||
public Contact(ContactId id, Author author, long lastConnected) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.author = author;
|
||||
this.lastConnected = lastConnected;
|
||||
}
|
||||
|
||||
@@ -16,8 +16,8 @@ public class Contact {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
public Author getAuthor() {
|
||||
return author;
|
||||
}
|
||||
|
||||
public long getLastConnected() {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.sf.briar.api.messaging;
|
||||
package net.sf.briar.api;
|
||||
|
||||
/** A pseudonym that the user can use to sign {@link Message}s. */
|
||||
/** A pseudonym for the local user. */
|
||||
public class LocalAuthor extends Author {
|
||||
|
||||
private final byte[] privateKey;
|
||||
@@ -11,7 +11,7 @@ public class LocalAuthor extends Author {
|
||||
this.privateKey = privateKey;
|
||||
}
|
||||
|
||||
/** Returns the private key that is used to sign messages. */
|
||||
/** Returns the private key used to generate the pseudonym's signatures. */
|
||||
public byte[] getPrivateKey() {
|
||||
return privateKey;
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package net.sf.briar.api.messaging;
|
||||
package net.sf.briar.api;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package net.sf.briar.api.messaging;
|
||||
package net.sf.briar.api;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@@ -9,6 +9,61 @@ import javax.crypto.Cipher;
|
||||
|
||||
public interface CryptoComponent {
|
||||
|
||||
ErasableKey generateSecretKey();
|
||||
|
||||
MessageDigest getMessageDigest();
|
||||
|
||||
PseudoRandom getPseudoRandom(int seed1, int seed2);
|
||||
|
||||
SecureRandom getSecureRandom();
|
||||
|
||||
Signature getSignature();
|
||||
|
||||
KeyPair generateAgreementKeyPair();
|
||||
|
||||
KeyParser getAgreementKeyParser();
|
||||
|
||||
KeyPair generateSignatureKeyPair();
|
||||
|
||||
KeyParser getSignatureKeyParser();
|
||||
|
||||
/** Generates a random invitation code. */
|
||||
int generateInvitationCode();
|
||||
|
||||
/**
|
||||
* Derives two confirmation codes from the given master secret. The first
|
||||
* code is for Alice to give to Bob; the second is for Bob to give to
|
||||
* Alice.
|
||||
*/
|
||||
int[] deriveConfirmationCodes(byte[] secret);
|
||||
|
||||
/**
|
||||
* Derives two nonces from the given master secret. The first nonce is for
|
||||
* Alice to sign; the second is for Bob to sign.
|
||||
*/
|
||||
byte[][] deriveInvitationNonces(byte[] secret);
|
||||
|
||||
/**
|
||||
* Derives a shared master secret from two public keys and one of the
|
||||
* corresponding private keys.
|
||||
* @param alice indicates whether the private key belongs to Alice or Bob.
|
||||
*/
|
||||
byte[] deriveMasterSecret(byte[] theirPublicKey, KeyPair ourKeyPair,
|
||||
boolean alice) throws GeneralSecurityException;
|
||||
|
||||
/**
|
||||
* Derives an initial secret for the given transport from the given master
|
||||
* secret.
|
||||
*/
|
||||
byte[] deriveInitialSecret(byte[] secret, int transportIndex);
|
||||
|
||||
/**
|
||||
* Derives a temporary secret for the given period from the given secret,
|
||||
* which is either the initial shared secret or the previous period's
|
||||
* temporary secret.
|
||||
*/
|
||||
byte[] deriveNextSecret(byte[] secret, long period);
|
||||
|
||||
/**
|
||||
* Derives a tag key from the given temporary secret.
|
||||
* @param alice indicates whether the key is for connections initiated by
|
||||
@@ -28,57 +83,18 @@ public interface CryptoComponent {
|
||||
boolean initiator);
|
||||
|
||||
/**
|
||||
* Derives an initial shared secret from two public keys and one of the
|
||||
* corresponding private keys.
|
||||
* @param alice indicates whether the private key belongs to Alice or Bob.
|
||||
* Returns a cipher for generating the pseudo-random tags that are used to
|
||||
* recognise connections.
|
||||
*/
|
||||
byte[] deriveInitialSecret(byte[] theirPublicKey, KeyPair ourKeyPair,
|
||||
boolean alice) throws GeneralSecurityException;
|
||||
Cipher getTagCipher();
|
||||
|
||||
/**
|
||||
* Generates a random invitation code.
|
||||
*/
|
||||
int generateInvitationCode();
|
||||
|
||||
/**
|
||||
* Derives two confirmation codes from the given initial shared secret. The
|
||||
* first code is for Alice to give to Bob; the second is for Bob to give to
|
||||
* Alice.
|
||||
*/
|
||||
int[] deriveConfirmationCodes(byte[] secret);
|
||||
|
||||
/**
|
||||
* Derives a temporary secret for the given period from the previous
|
||||
* period's temporary secret.
|
||||
*/
|
||||
byte[] deriveNextSecret(byte[] secret, long period);
|
||||
/** Returns a cipher for encrypting and authenticating connections. */
|
||||
AuthenticatedCipher getFrameCipher();
|
||||
|
||||
/** Encodes the pseudo-random tag that is used to recognise a connection. */
|
||||
void encodeTag(byte[] tag, Cipher tagCipher, ErasableKey tagKey,
|
||||
long connection);
|
||||
|
||||
KeyPair generateAgreementKeyPair();
|
||||
|
||||
KeyParser getAgreementKeyParser();
|
||||
|
||||
KeyPair generateSignatureKeyPair();
|
||||
|
||||
KeyParser getSignatureKeyParser();
|
||||
|
||||
ErasableKey generateSecretKey();
|
||||
|
||||
MessageDigest getMessageDigest();
|
||||
|
||||
PseudoRandom getPseudoRandom(int seed1, int seed2);
|
||||
|
||||
SecureRandom getSecureRandom();
|
||||
|
||||
Cipher getTagCipher();
|
||||
|
||||
AuthenticatedCipher getFrameCipher();
|
||||
|
||||
Signature getSignature();
|
||||
|
||||
/**
|
||||
* Encrypts the given plaintext so it can be written to temporary storage.
|
||||
* The ciphertext will not be decryptable after the app restarts.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.sf.briar.api.crypto;
|
||||
|
||||
import net.sf.briar.api.ContactId;
|
||||
import net.sf.briar.api.messaging.TransportId;
|
||||
import net.sf.briar.api.TransportId;
|
||||
import net.sf.briar.api.transport.ConnectionContext;
|
||||
import net.sf.briar.api.transport.Endpoint;
|
||||
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
package net.sf.briar.api.crypto;
|
||||
|
||||
import java.security.PrivateKey;
|
||||
import java.security.PublicKey;
|
||||
import java.security.spec.InvalidKeySpecException;
|
||||
|
||||
public interface KeyParser {
|
||||
|
||||
PublicKey parsePublicKey(byte[] encodedKey) throws InvalidKeySpecException;
|
||||
|
||||
PrivateKey parsePrivateKey(byte[] encodedKey)
|
||||
throws InvalidKeySpecException;
|
||||
}
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
package net.sf.briar.api.crypto;
|
||||
|
||||
/**
|
||||
* Encapsulates a password. Implementations may keep the password encrypted in
|
||||
* memory to reduce the chances of writing it to the swapfile in plaintext.
|
||||
*/
|
||||
public interface Password {
|
||||
|
||||
/**
|
||||
* Returns the password as a character array, which should be filled with
|
||||
* zeroes as soon as it has been used.
|
||||
*/
|
||||
char[] getPassword();
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.sf.briar.api.crypto;
|
||||
|
||||
/** A deterministic PRNG. */
|
||||
public interface PseudoRandom {
|
||||
|
||||
byte[] nextBytes(int bytes);
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package net.sf.briar.api.db;
|
||||
|
||||
/**
|
||||
* Thrown when a duplicate contact is added to the database. This exception may
|
||||
* occur due to concurrent updates and does not indicate a database error.
|
||||
*/
|
||||
public class ContactExistsException extends DbException {
|
||||
|
||||
private static final long serialVersionUID = -6658762011691502411L;
|
||||
}
|
||||
@@ -4,28 +4,29 @@ import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
import net.sf.briar.api.Author;
|
||||
import net.sf.briar.api.AuthorId;
|
||||
import net.sf.briar.api.Contact;
|
||||
import net.sf.briar.api.ContactId;
|
||||
import net.sf.briar.api.Rating;
|
||||
import net.sf.briar.api.LocalAuthor;
|
||||
import net.sf.briar.api.TransportConfig;
|
||||
import net.sf.briar.api.TransportId;
|
||||
import net.sf.briar.api.TransportProperties;
|
||||
import net.sf.briar.api.db.event.DatabaseListener;
|
||||
import net.sf.briar.api.messaging.Ack;
|
||||
import net.sf.briar.api.messaging.AuthorId;
|
||||
import net.sf.briar.api.messaging.Group;
|
||||
import net.sf.briar.api.messaging.GroupId;
|
||||
import net.sf.briar.api.messaging.LocalAuthor;
|
||||
import net.sf.briar.api.messaging.LocalGroup;
|
||||
import net.sf.briar.api.messaging.Message;
|
||||
import net.sf.briar.api.messaging.MessageId;
|
||||
import net.sf.briar.api.messaging.Offer;
|
||||
import net.sf.briar.api.messaging.Rating;
|
||||
import net.sf.briar.api.messaging.Request;
|
||||
import net.sf.briar.api.messaging.RetentionAck;
|
||||
import net.sf.briar.api.messaging.RetentionUpdate;
|
||||
import net.sf.briar.api.messaging.SubscriptionAck;
|
||||
import net.sf.briar.api.messaging.SubscriptionUpdate;
|
||||
import net.sf.briar.api.messaging.TransportAck;
|
||||
import net.sf.briar.api.messaging.TransportId;
|
||||
import net.sf.briar.api.messaging.TransportUpdate;
|
||||
import net.sf.briar.api.transport.Endpoint;
|
||||
import net.sf.briar.api.transport.TemporarySecret;
|
||||
@@ -53,9 +54,10 @@ public interface DatabaseComponent {
|
||||
void removeListener(DatabaseListener d);
|
||||
|
||||
/**
|
||||
* Stores a contact with the given name and returns an ID for the contact.
|
||||
* Stores a contact with the given pseudonym, associated with the given
|
||||
* local pseudonym, and returns an ID for the contact.
|
||||
*/
|
||||
ContactId addContact(String name) throws DbException;
|
||||
ContactId addContact(Author remote, AuthorId local) throws DbException;
|
||||
|
||||
/** Stores an endpoint. */
|
||||
void addEndpoint(Endpoint ep) throws DbException;
|
||||
@@ -85,7 +87,7 @@ public interface DatabaseComponent {
|
||||
* Stores a transport and returns true if the transport was not previously
|
||||
* in the database.
|
||||
*/
|
||||
boolean addTransport(TransportId t) throws DbException;
|
||||
boolean addTransport(TransportId t, long maxLatency) throws DbException;
|
||||
|
||||
/**
|
||||
* Generates an acknowledgement for the given contact, or returns null if
|
||||
@@ -176,12 +178,19 @@ public interface DatabaseComponent {
|
||||
/** Returns the group with the given ID, if the user subscribes to it. */
|
||||
Group getGroup(GroupId g) throws DbException;
|
||||
|
||||
/** Returns the pseudonym with the given ID. */
|
||||
LocalAuthor getLocalAuthor(AuthorId a) throws DbException;
|
||||
|
||||
/** Returns all pseudonyms that the user can use to sign messages. */
|
||||
Collection<LocalAuthor> getLocalAuthors() throws DbException;
|
||||
|
||||
/** Returns all restricted groups to which the user can post messages. */
|
||||
Collection<LocalGroup> getLocalGroups() throws DbException;
|
||||
|
||||
/** Returns the local transport properties for all transports. */
|
||||
Map<TransportId, TransportProperties> getLocalProperties()
|
||||
throws DbException;
|
||||
|
||||
/** Returns the local transport properties for the given transport. */
|
||||
TransportProperties getLocalProperties(TransportId t) throws DbException;
|
||||
|
||||
@@ -222,6 +231,9 @@ public interface DatabaseComponent {
|
||||
/** Returns the set of groups to which the user subscribes. */
|
||||
Collection<Group> getSubscriptions() throws DbException;
|
||||
|
||||
/** Returns the maximum latencies of all local transports. */
|
||||
Map<TransportId, Long> getTransportLatencies() throws DbException;
|
||||
|
||||
/** Returns the number of unread messages in each subscribed group. */
|
||||
Map<GroupId, Integer> getUnreadMessageCounts() throws DbException;
|
||||
|
||||
@@ -317,6 +329,13 @@ public interface DatabaseComponent {
|
||||
*/
|
||||
boolean setReadFlag(MessageId m, boolean read) throws DbException;
|
||||
|
||||
/**
|
||||
* Sets the remote transport properties for the given contact, replacing
|
||||
* any existing properties.
|
||||
*/
|
||||
void setRemoteProperties(ContactId c,
|
||||
Map<TransportId, TransportProperties> p) throws DbException;
|
||||
|
||||
/** Records the given messages as having been seen by the given contact. */
|
||||
void setSeen(ContactId c, Collection<MessageId> seen) throws DbException;
|
||||
|
||||
|
||||
@@ -2,13 +2,11 @@ package net.sf.briar.api.db;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import net.sf.briar.api.crypto.Password;
|
||||
|
||||
public interface DatabaseConfig {
|
||||
|
||||
File getDataDirectory();
|
||||
|
||||
Password getPassword();
|
||||
char[] getPassword();
|
||||
|
||||
long getMaxSize();
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package net.sf.briar.api.db;
|
||||
|
||||
import net.sf.briar.api.Rating;
|
||||
import net.sf.briar.api.messaging.Author;
|
||||
import net.sf.briar.api.Author;
|
||||
import net.sf.briar.api.messaging.GroupId;
|
||||
import net.sf.briar.api.messaging.MessageId;
|
||||
import net.sf.briar.api.messaging.Rating;
|
||||
|
||||
public class GroupMessageHeader extends MessageHeader {
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.sf.briar.api.db.event;
|
||||
|
||||
import net.sf.briar.api.Rating;
|
||||
import net.sf.briar.api.messaging.AuthorId;
|
||||
import net.sf.briar.api.AuthorId;
|
||||
import net.sf.briar.api.messaging.Rating;
|
||||
|
||||
public class RatingChangedEvent extends DatabaseEvent {
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.sf.briar.api.db.event;
|
||||
|
||||
import net.sf.briar.api.ContactId;
|
||||
import net.sf.briar.api.messaging.TransportId;
|
||||
import net.sf.briar.api.TransportId;
|
||||
|
||||
/**
|
||||
* An event that is broadcast when a contact's remote transport properties
|
||||
|
||||
@@ -1,17 +1,23 @@
|
||||
package net.sf.briar.api.db.event;
|
||||
|
||||
import net.sf.briar.api.messaging.TransportId;
|
||||
import net.sf.briar.api.TransportId;
|
||||
|
||||
/** An event that is broadcast when a transport is added. */
|
||||
/** An event that is broadcast when a transport is added to the database. */
|
||||
public class TransportAddedEvent extends DatabaseEvent {
|
||||
|
||||
private final TransportId transportId;
|
||||
private final long maxLatency;
|
||||
|
||||
public TransportAddedEvent(TransportId transportId) {
|
||||
public TransportAddedEvent(TransportId transportId, long maxLatency) {
|
||||
this.transportId = transportId;
|
||||
this.maxLatency = maxLatency;
|
||||
}
|
||||
|
||||
public TransportId getTransportId() {
|
||||
return transportId;
|
||||
}
|
||||
|
||||
public long getMaxLatency() {
|
||||
return maxLatency;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.sf.briar.api.db.event;
|
||||
|
||||
import net.sf.briar.api.messaging.TransportId;
|
||||
import net.sf.briar.api.TransportId;
|
||||
|
||||
/** An event that is broadcast when a transport is removed. */
|
||||
public class TransportRemovedEvent extends DatabaseEvent {
|
||||
|
||||
@@ -9,7 +9,10 @@ public interface InvitationListener {
|
||||
/** Called if a connection is established and key agreement succeeds. */
|
||||
void connectionSucceeded(int localCode, int remoteCode);
|
||||
|
||||
/** Called if a connection cannot be established. */
|
||||
/**
|
||||
* Called if a connection cannot be established. This indicates that the
|
||||
* protocol has ended unsuccessfully.
|
||||
*/
|
||||
void connectionFailed();
|
||||
|
||||
/**
|
||||
@@ -20,7 +23,21 @@ public interface InvitationListener {
|
||||
|
||||
/**
|
||||
* Informs the local peer that the remote peer's confirmation check did
|
||||
* not succeed, or the connection was lost during confirmation.
|
||||
* not succeed, or the connection was lost during confirmation. This
|
||||
* indicates that the protocol has ended unsuccessfully.
|
||||
*/
|
||||
void remoteConfirmationFailed();
|
||||
|
||||
/**
|
||||
* Informs the local peer of the name used by the remote peer. Called if
|
||||
* the exchange of pseudonyms succeeds. This indicates that the protocol
|
||||
* has ended successfully.
|
||||
*/
|
||||
void pseudonymExchangeSucceeded(String remoteName);
|
||||
|
||||
/**
|
||||
* Called if the exchange of pseudonyms fails. This indicates that the
|
||||
* protocol has ended unsuccessfully.
|
||||
*/
|
||||
void pseudonymExchangeFailed();
|
||||
}
|
||||
|
||||
@@ -7,12 +7,13 @@ public class InvitationState {
|
||||
private final boolean connectionFailed;
|
||||
private final boolean localCompared, remoteCompared;
|
||||
private final boolean localMatched, remoteMatched;
|
||||
private final String contactName;
|
||||
|
||||
public InvitationState(int localInvitationCode, int remoteInvitationCode,
|
||||
int localConfirmationCode, int remoteConfirmationCode,
|
||||
boolean connectionFailed, boolean localCompared,
|
||||
boolean remoteCompared, boolean localMatched,
|
||||
boolean remoteMatched) {
|
||||
boolean remoteMatched, String contactName) {
|
||||
this.localInvitationCode = localInvitationCode;
|
||||
this.remoteInvitationCode = remoteInvitationCode;
|
||||
this.localConfirmationCode = localConfirmationCode;
|
||||
@@ -22,6 +23,7 @@ public class InvitationState {
|
||||
this.remoteCompared = remoteCompared;
|
||||
this.localMatched = localMatched;
|
||||
this.remoteMatched = remoteMatched;
|
||||
this.contactName = contactName;
|
||||
}
|
||||
|
||||
public int getLocalInvitationCode() {
|
||||
@@ -59,4 +61,8 @@ public class InvitationState {
|
||||
public boolean getRemoteMatched() {
|
||||
return remoteMatched;
|
||||
}
|
||||
|
||||
public String getContactName() {
|
||||
return contactName;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package net.sf.briar.api.invitation;
|
||||
|
||||
import net.sf.briar.api.AuthorId;
|
||||
|
||||
/** Creates tasks for exchanging invitations with remote peers. */
|
||||
public interface InvitationTaskFactory {
|
||||
|
||||
/** Creates a task using the given invitation codes. */
|
||||
InvitationTask createTask(int localCode, int remoteCode);
|
||||
/** Creates a task using the given pseudonym and invitation codes. */
|
||||
InvitationTask createTask(AuthorId localAuthorId, int localCode,
|
||||
int remoteCode);
|
||||
}
|
||||
|
||||
@@ -29,8 +29,9 @@ public class Group {
|
||||
}
|
||||
|
||||
/**
|
||||
* If the group is restricted, returns the public key that is used to
|
||||
* authorise all messages sent to the group. Otherwise returns null.
|
||||
* If the group is restricted, returns the public key used to verify the
|
||||
* signatures on all messages sent to the group. If the group is
|
||||
* unrestricted, returns null.
|
||||
*/
|
||||
public byte[] getPublicKey() {
|
||||
return publicKey;
|
||||
|
||||
@@ -2,6 +2,8 @@ package net.sf.briar.api.messaging;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import net.sf.briar.api.UniqueId;
|
||||
|
||||
/**
|
||||
* Type-safe wrapper for a byte array that uniquely identifies a {@link Group}.
|
||||
*/
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.sf.briar.api.messaging;
|
||||
|
||||
/** A restricted group to which the user can post messages. */
|
||||
/** A restricted group to which the local user can post messages. */
|
||||
public class LocalGroup extends Group {
|
||||
|
||||
private final byte[] privateKey;
|
||||
@@ -11,7 +11,7 @@ public class LocalGroup extends Group {
|
||||
this.privateKey = privateKey;
|
||||
}
|
||||
|
||||
/** Returns the private key that is used to sign messages. */
|
||||
/** Returns the private key used to sign all messages sent to the group. */
|
||||
public byte[] getPrivateKey() {
|
||||
return privateKey;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package net.sf.briar.api.messaging;
|
||||
|
||||
import net.sf.briar.api.Author;
|
||||
|
||||
public interface Message {
|
||||
|
||||
/** Returns the message's unique identifier. */
|
||||
@@ -18,8 +20,8 @@ public interface Message {
|
||||
Group getGroup();
|
||||
|
||||
/**
|
||||
* Returns the message's {@link Author}, or null if this is an anonymous
|
||||
* message.
|
||||
* Returns the message's {@link net.sf.briar.api.Author Author}, or null
|
||||
* if this is an anonymous message.
|
||||
*/
|
||||
Author getAuthor();
|
||||
|
||||
@@ -33,7 +35,7 @@ public interface Message {
|
||||
*/
|
||||
String getSubject();
|
||||
|
||||
/** Returns the timestamp created by the message's {@link Author}. */
|
||||
/** Returns the message's timestamp. */
|
||||
long getTimestamp();
|
||||
|
||||
/** Returns the serialised message. */
|
||||
|
||||
@@ -4,6 +4,8 @@ import java.io.IOException;
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.security.PrivateKey;
|
||||
|
||||
import net.sf.briar.api.Author;
|
||||
|
||||
public interface MessageFactory {
|
||||
|
||||
/** Creates a private message. */
|
||||
|
||||
@@ -2,6 +2,8 @@ package net.sf.briar.api.messaging;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import net.sf.briar.api.UniqueId;
|
||||
|
||||
/**
|
||||
* Type-safe wrapper for a byte array that uniquely identifies a
|
||||
* {@link Message}.
|
||||
|
||||
@@ -52,5 +52,5 @@ public interface MessagingConstants {
|
||||
* The timestamp of the oldest message in the database is rounded using
|
||||
* this modulus to avoid revealing the presence of any particular message.
|
||||
*/
|
||||
long RETENTION_MODULUS = 60 * 60 * 1000; // 1 hour
|
||||
int RETENTION_MODULUS = 60 * 60 * 1000; // 1 hour
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package net.sf.briar.api;
|
||||
package net.sf.briar.api.messaging;
|
||||
|
||||
/** The ratings that may be applied to an author in peer moderation. */
|
||||
public enum Rating {
|
||||
@@ -1,5 +1,7 @@
|
||||
package net.sf.briar.api.messaging;
|
||||
|
||||
import net.sf.briar.api.TransportId;
|
||||
|
||||
/** A packet acknowledging a {@link TransportUpdate}. */
|
||||
public class TransportAck {
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.sf.briar.api.messaging;
|
||||
|
||||
import net.sf.briar.api.TransportId;
|
||||
import net.sf.briar.api.TransportProperties;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package net.sf.briar.api.messaging;
|
||||
|
||||
/** A {@link Message} that has not yet had its signatures verified. */
|
||||
import net.sf.briar.api.Author;
|
||||
|
||||
/** A {@link Message} that has not yet had its signatures (if any) verified. */
|
||||
public class UnverifiedMessage {
|
||||
|
||||
private final MessageId parent;
|
||||
@@ -47,8 +49,8 @@ public class UnverifiedMessage {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the message's {@link Author}, or null if this is an anonymous
|
||||
* message.
|
||||
* Returns the message's {@link net.sf.briar.api.Author Author}, or null
|
||||
* if this is an anonymous message.
|
||||
*/
|
||||
public Author getAuthor() {
|
||||
return author;
|
||||
@@ -68,7 +70,7 @@ public class UnverifiedMessage {
|
||||
return subject;
|
||||
}
|
||||
|
||||
/** Returns the timestamp created by the message's {@link Author}. */
|
||||
/** Returns the message's timestamp. */
|
||||
public long getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
package net.sf.briar.api.messaging.duplex;
|
||||
|
||||
import net.sf.briar.api.ContactId;
|
||||
import net.sf.briar.api.messaging.TransportId;
|
||||
import net.sf.briar.api.TransportId;
|
||||
import net.sf.briar.api.plugins.duplex.DuplexTransportConnection;
|
||||
import net.sf.briar.api.transport.ConnectionContext;
|
||||
|
||||
public interface DuplexConnectionFactory {
|
||||
|
||||
void createIncomingConnection(ConnectionContext ctx, DuplexTransportConnection d);
|
||||
void createIncomingConnection(ConnectionContext ctx,
|
||||
DuplexTransportConnection d);
|
||||
|
||||
void createOutgoingConnection(ContactId c, TransportId t,
|
||||
DuplexTransportConnection d);
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
package net.sf.briar.api.messaging.simplex;
|
||||
|
||||
import net.sf.briar.api.ContactId;
|
||||
import net.sf.briar.api.messaging.TransportId;
|
||||
import net.sf.briar.api.TransportId;
|
||||
import net.sf.briar.api.plugins.simplex.SimplexTransportReader;
|
||||
import net.sf.briar.api.plugins.simplex.SimplexTransportWriter;
|
||||
import net.sf.briar.api.transport.ConnectionContext;
|
||||
|
||||
public interface SimplexConnectionFactory {
|
||||
|
||||
void createIncomingConnection(ConnectionContext ctx, SimplexTransportReader r);
|
||||
void createIncomingConnection(ConnectionContext ctx,
|
||||
SimplexTransportReader r);
|
||||
|
||||
void createOutgoingConnection(ContactId c, TransportId t,
|
||||
SimplexTransportWriter w);
|
||||
|
||||
@@ -4,7 +4,7 @@ import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
|
||||
import net.sf.briar.api.ContactId;
|
||||
import net.sf.briar.api.messaging.TransportId;
|
||||
import net.sf.briar.api.TransportId;
|
||||
|
||||
public interface Plugin {
|
||||
|
||||
|
||||
@@ -23,6 +23,6 @@ public interface PluginManager {
|
||||
*/
|
||||
int stop();
|
||||
|
||||
/** Returns any duplex plugins that support invitations. */
|
||||
/** Returns any running duplex plugins that support invitations. */
|
||||
Collection<DuplexPlugin> getInvitationPlugins();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.sf.briar.api.plugins.duplex;
|
||||
|
||||
import net.sf.briar.api.messaging.TransportId;
|
||||
import net.sf.briar.api.TransportId;
|
||||
|
||||
public interface DuplexPluginFactory {
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.sf.briar.api.plugins.simplex;
|
||||
|
||||
import net.sf.briar.api.messaging.TransportId;
|
||||
import net.sf.briar.api.TransportId;
|
||||
|
||||
public interface SimplexPluginFactory {
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.sf.briar.api.transport;
|
||||
|
||||
import net.sf.briar.api.ContactId;
|
||||
import net.sf.briar.api.messaging.TransportId;
|
||||
import net.sf.briar.api.TransportId;
|
||||
|
||||
public class ConnectionContext {
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.sf.briar.api.transport;
|
||||
|
||||
import net.sf.briar.api.ContactId;
|
||||
import net.sf.briar.api.messaging.TransportId;
|
||||
import net.sf.briar.api.TransportId;
|
||||
import net.sf.briar.api.plugins.duplex.DuplexTransportConnection;
|
||||
import net.sf.briar.api.plugins.simplex.SimplexTransportReader;
|
||||
import net.sf.briar.api.plugins.simplex.SimplexTransportWriter;
|
||||
|
||||
@@ -4,9 +4,11 @@ import java.io.InputStream;
|
||||
|
||||
public interface ConnectionReaderFactory {
|
||||
|
||||
/**
|
||||
* Creates a connection reader for one side of a connection.
|
||||
*/
|
||||
/** Creates a connection reader for one side of a connection. */
|
||||
ConnectionReader createConnectionReader(InputStream in,
|
||||
ConnectionContext ctx, boolean incoming, boolean initiator);
|
||||
|
||||
/** Creates a connection reader for one side of an invitation connection. */
|
||||
ConnectionReader createInvitationConnectionReader(InputStream in,
|
||||
byte[] secret, boolean alice);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package net.sf.briar.api.transport;
|
||||
|
||||
import net.sf.briar.api.ContactId;
|
||||
import net.sf.briar.api.TransportId;
|
||||
import net.sf.briar.api.db.DbException;
|
||||
import net.sf.briar.api.messaging.TransportId;
|
||||
|
||||
/**
|
||||
* Maintains the connection reordering windows and decides whether incoming
|
||||
|
||||
@@ -3,7 +3,7 @@ package net.sf.briar.api.transport;
|
||||
import java.util.Collection;
|
||||
|
||||
import net.sf.briar.api.ContactId;
|
||||
import net.sf.briar.api.messaging.TransportId;
|
||||
import net.sf.briar.api.TransportId;
|
||||
|
||||
/**
|
||||
* Keeps track of which contacts are currently connected by which transports.
|
||||
|
||||
@@ -4,9 +4,11 @@ import java.io.OutputStream;
|
||||
|
||||
public interface ConnectionWriterFactory {
|
||||
|
||||
/**
|
||||
* Creates a connection writer for one side of a connection.
|
||||
*/
|
||||
/** Creates a connection writer for one side of a connection. */
|
||||
ConnectionWriter createConnectionWriter(OutputStream out, long capacity,
|
||||
ConnectionContext ctx, boolean incoming, boolean initiator);
|
||||
|
||||
/** Creates a connection writer for one side of an invitation connection. */
|
||||
ConnectionWriter createInvitationConnectionWriter(OutputStream out,
|
||||
byte[] secret, boolean alice);
|
||||
}
|
||||
|
||||
@@ -1,22 +1,20 @@
|
||||
package net.sf.briar.api.transport;
|
||||
|
||||
import net.sf.briar.api.ContactId;
|
||||
import net.sf.briar.api.messaging.TransportId;
|
||||
import net.sf.briar.api.TransportId;
|
||||
|
||||
public class Endpoint {
|
||||
|
||||
private final ContactId contactId;
|
||||
private final TransportId transportId;
|
||||
private final long epoch, clockDiff, latency;
|
||||
private final long epoch;
|
||||
private final boolean alice;
|
||||
|
||||
public Endpoint(ContactId contactId, TransportId transportId,
|
||||
long epoch, long clockDiff, long latency, boolean alice) {
|
||||
public Endpoint(ContactId contactId, TransportId transportId, long epoch,
|
||||
boolean alice) {
|
||||
this.contactId = contactId;
|
||||
this.transportId = transportId;
|
||||
this.epoch = epoch;
|
||||
this.clockDiff = clockDiff;
|
||||
this.latency = latency;
|
||||
this.alice = alice;
|
||||
}
|
||||
|
||||
@@ -32,14 +30,6 @@ public class Endpoint {
|
||||
return epoch;
|
||||
}
|
||||
|
||||
public long getClockDifference() {
|
||||
return clockDiff;
|
||||
}
|
||||
|
||||
public long getLatency() {
|
||||
return latency;
|
||||
}
|
||||
|
||||
public boolean getAlice() {
|
||||
return alice;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package net.sf.briar.api.transport;
|
||||
|
||||
import static net.sf.briar.api.transport.TransportConstants.CONNECTION_WINDOW_SIZE;
|
||||
import net.sf.briar.api.ContactId;
|
||||
import net.sf.briar.api.messaging.TransportId;
|
||||
import net.sf.briar.api.TransportId;
|
||||
|
||||
public class TemporarySecret extends Endpoint {
|
||||
|
||||
@@ -11,10 +11,9 @@ public class TemporarySecret extends Endpoint {
|
||||
|
||||
/** Creates a temporary secret with the given connection window. */
|
||||
public TemporarySecret(ContactId contactId, TransportId transportId,
|
||||
long epoch, long clockDiff, long latency, boolean alice,
|
||||
long period, byte[] secret, long outgoing, long centre,
|
||||
byte[] bitmap) {
|
||||
super(contactId, transportId, epoch, clockDiff, latency, alice);
|
||||
long epoch, boolean alice, long period, byte[] secret,
|
||||
long outgoing, long centre, byte[] bitmap) {
|
||||
super(contactId, transportId, epoch, alice);
|
||||
this.period = period;
|
||||
this.secret = secret;
|
||||
this.outgoing = outgoing;
|
||||
@@ -24,17 +23,15 @@ public class TemporarySecret extends Endpoint {
|
||||
|
||||
/** Creates a temporary secret with a new connection window. */
|
||||
public TemporarySecret(ContactId contactId, TransportId transportId,
|
||||
long epoch, long clockDiff, long latency, boolean alice,
|
||||
long period, byte[] secret) {
|
||||
this(contactId, transportId, epoch, clockDiff, latency, alice, period,
|
||||
secret, 0, 0, new byte[CONNECTION_WINDOW_SIZE / 8]);
|
||||
long epoch, boolean alice, long period, byte[] secret) {
|
||||
this(contactId, transportId, epoch, alice, period, secret, 0, 0,
|
||||
new byte[CONNECTION_WINDOW_SIZE / 8]);
|
||||
}
|
||||
|
||||
/** Creates a temporary secret derived from the given endpoint. */
|
||||
public TemporarySecret(Endpoint ep, long period, byte[] secret) {
|
||||
this(ep.getContactId(), ep.getTransportId(), ep.getEpoch(),
|
||||
ep.getClockDifference(), ep.getLatency(), ep.getAlice(),
|
||||
period, secret);
|
||||
ep.getAlice(), period, secret);
|
||||
}
|
||||
|
||||
public long getPeriod() {
|
||||
|
||||
@@ -27,6 +27,9 @@ public interface TransportConstants {
|
||||
*/
|
||||
int MIN_CONNECTION_LENGTH = 1024 * 1024; // 2^20, 1 MiB
|
||||
|
||||
/** The maximum difference between two communicating devices' clocks. */
|
||||
int MAX_CLOCK_DIFFERENCE = 60 * 60 * 1000; // 1 hour
|
||||
|
||||
/** The size of the connection reordering window. */
|
||||
int CONNECTION_WINDOW_SIZE = 32;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user