Use PublicKey and PrivateKey everywhere.

This commit is contained in:
akwizgran
2019-04-23 13:31:09 +01:00
parent 0e77a47cc1
commit de8a60ea21
55 changed files with 558 additions and 463 deletions

View File

@@ -4,6 +4,8 @@ import com.rometools.rome.feed.synd.SyndFeed;
import org.briarproject.bramble.api.FormatException;
import org.briarproject.bramble.api.client.ClientHelper;
import org.briarproject.bramble.api.crypto.PrivateKey;
import org.briarproject.bramble.api.crypto.SignaturePrivateKey;
import org.briarproject.bramble.api.data.BdfDictionary;
import org.briarproject.bramble.api.data.BdfEntry;
import org.briarproject.bramble.api.data.BdfList;
@@ -70,7 +72,8 @@ class FeedFactoryImpl implements FeedFactory {
String url = d.getString(KEY_FEED_URL);
BdfList authorList = d.getList(KEY_FEED_AUTHOR);
byte[] privateKey = d.getRaw(KEY_FEED_PRIVATE_KEY);
PrivateKey privateKey =
new SignaturePrivateKey(d.getRaw(KEY_FEED_PRIVATE_KEY));
Author author = clientHelper.parseAndValidateAuthor(authorList);
LocalAuthor localAuthor = new LocalAuthor(author.getId(),
author.getFormatVersion(), author.getName(),

View File

@@ -5,6 +5,7 @@ import org.briarproject.bramble.api.client.ClientHelper;
import org.briarproject.bramble.api.client.ContactGroupFactory;
import org.briarproject.bramble.api.contact.Contact;
import org.briarproject.bramble.api.contact.ContactManager;
import org.briarproject.bramble.api.crypto.PublicKey;
import org.briarproject.bramble.api.data.BdfDictionary;
import org.briarproject.bramble.api.db.DatabaseComponent;
import org.briarproject.bramble.api.db.DbException;
@@ -83,7 +84,7 @@ abstract class AbstractProtocolEngine<S extends Session>
}
Message sendAcceptMessage(Transaction txn, PeerSession s, long timestamp,
byte[] ephemeralPublicKey, long acceptTimestamp,
PublicKey ephemeralPublicKey, long acceptTimestamp,
Map<TransportId, TransportProperties> transportProperties,
boolean visible) throws DbException {
Message m = messageEncoder

View File

@@ -1,5 +1,6 @@
package org.briarproject.briar.introduction;
import org.briarproject.bramble.api.crypto.PublicKey;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.bramble.api.plugin.TransportId;
import org.briarproject.bramble.api.properties.TransportProperties;
@@ -17,14 +18,13 @@ import javax.annotation.concurrent.Immutable;
class AcceptMessage extends AbstractIntroductionMessage {
private final SessionId sessionId;
private final byte[] ephemeralPublicKey;
private final PublicKey ephemeralPublicKey;
private final long acceptTimestamp;
private final Map<TransportId, TransportProperties> transportProperties;
protected AcceptMessage(MessageId messageId, GroupId groupId,
long timestamp, @Nullable MessageId previousMessageId,
SessionId sessionId,
byte[] ephemeralPublicKey,
SessionId sessionId, PublicKey ephemeralPublicKey,
long acceptTimestamp,
Map<TransportId, TransportProperties> transportProperties) {
super(messageId, groupId, timestamp, previousMessageId);
@@ -38,7 +38,7 @@ class AcceptMessage extends AbstractIntroductionMessage {
return sessionId;
}
public byte[] getEphemeralPublicKey() {
public PublicKey getEphemeralPublicKey() {
return ephemeralPublicKey;
}

View File

@@ -6,6 +6,8 @@ import org.briarproject.bramble.api.client.ContactGroupFactory;
import org.briarproject.bramble.api.contact.Contact;
import org.briarproject.bramble.api.contact.ContactManager;
import org.briarproject.bramble.api.crypto.KeyPair;
import org.briarproject.bramble.api.crypto.PrivateKey;
import org.briarproject.bramble.api.crypto.PublicKey;
import org.briarproject.bramble.api.crypto.SecretKey;
import org.briarproject.bramble.api.data.BdfDictionary;
import org.briarproject.bramble.api.db.ContactExistsException;
@@ -272,9 +274,9 @@ class IntroduceeProtocolEngine
markRequestsUnavailableToAnswer(txn, s);
// Create ephemeral key pair and get local transport properties
KeyPair keyPair = crypto.generateKeyPair();
byte[] publicKey = keyPair.getPublic().getEncoded();
byte[] privateKey = keyPair.getPrivate().getEncoded();
KeyPair keyPair = crypto.generateAgreementKeyPair();
PublicKey publicKey = keyPair.getPublic();
PrivateKey privateKey = keyPair.getPrivate();
Map<TransportId, TransportProperties> transportProperties =
transportPropertyManager.getLocalProperties(txn);

View File

@@ -1,5 +1,7 @@
package org.briarproject.briar.introduction;
import org.briarproject.bramble.api.crypto.PrivateKey;
import org.briarproject.bramble.api.crypto.PublicKey;
import org.briarproject.bramble.api.crypto.SecretKey;
import org.briarproject.bramble.api.identity.Author;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
@@ -70,7 +72,7 @@ class IntroduceeSession extends Session<IntroduceeState>
static IntroduceeSession addLocalAccept(IntroduceeSession s,
IntroduceeState state, Message acceptMessage,
byte[] ephemeralPublicKey, byte[] ephemeralPrivateKey,
PublicKey ephemeralPublicKey, PrivateKey ephemeralPrivateKey,
long acceptTimestamp,
Map<TransportId, TransportProperties> transportProperties) {
Local local = new Local(s.local.alice, acceptMessage.getId(),
@@ -190,7 +192,7 @@ class IntroduceeSession extends Session<IntroduceeState>
@Nullable
final MessageId lastMessageId;
@Nullable
final byte[] ephemeralPublicKey;
final PublicKey ephemeralPublicKey;
@Nullable
final Map<TransportId, TransportProperties> transportProperties;
final long acceptTimestamp;
@@ -198,7 +200,7 @@ class IntroduceeSession extends Session<IntroduceeState>
final byte[] macKey;
private Common(boolean alice, @Nullable MessageId lastMessageId,
@Nullable byte[] ephemeralPublicKey, @Nullable
@Nullable PublicKey ephemeralPublicKey, @Nullable
Map<TransportId, TransportProperties> transportProperties,
long acceptTimestamp, @Nullable byte[] macKey) {
this.alice = alice;
@@ -213,11 +215,12 @@ class IntroduceeSession extends Session<IntroduceeState>
static class Local extends Common {
final long lastMessageTimestamp;
@Nullable
final byte[] ephemeralPrivateKey;
final PrivateKey ephemeralPrivateKey;
Local(boolean alice, @Nullable MessageId lastMessageId,
long lastMessageTimestamp, @Nullable byte[] ephemeralPublicKey,
@Nullable byte[] ephemeralPrivateKey, @Nullable
long lastMessageTimestamp,
@Nullable PublicKey ephemeralPublicKey,
@Nullable PrivateKey ephemeralPrivateKey, @Nullable
Map<TransportId, TransportProperties> transportProperties,
long acceptTimestamp, @Nullable byte[] macKey) {
super(alice, lastMessageId, ephemeralPublicKey, transportProperties,
@@ -239,7 +242,7 @@ class IntroduceeSession extends Session<IntroduceeState>
Remote(boolean alice, Author author,
@Nullable MessageId lastMessageId,
@Nullable byte[] ephemeralPublicKey, @Nullable
@Nullable PublicKey ephemeralPublicKey, @Nullable
Map<TransportId, TransportProperties> transportProperties,
long acceptTimestamp, @Nullable byte[] macKey) {
super(alice, lastMessageId, ephemeralPublicKey, transportProperties,

View File

@@ -1,6 +1,7 @@
package org.briarproject.briar.introduction;
import org.briarproject.bramble.api.crypto.KeyPair;
import org.briarproject.bramble.api.crypto.PrivateKey;
import org.briarproject.bramble.api.crypto.SecretKey;
import org.briarproject.bramble.api.identity.Author;
import org.briarproject.bramble.api.identity.AuthorId;
@@ -28,7 +29,7 @@ interface IntroductionCrypto {
/**
* Generates an agreement key pair.
*/
KeyPair generateKeyPair();
KeyPair generateAgreementKeyPair();
/**
* Derives a session master key for Alice or Bob.
@@ -74,7 +75,7 @@ interface IntroductionCrypto {
* (from {@link LocalAuthor#getPrivateKey()})
* @return The signature as a byte array
*/
byte[] sign(SecretKey macKey, byte[] privateKey)
byte[] sign(SecretKey macKey, PrivateKey privateKey)
throws GeneralSecurityException;
/**

View File

@@ -4,7 +4,6 @@ import org.briarproject.bramble.api.FormatException;
import org.briarproject.bramble.api.client.ClientHelper;
import org.briarproject.bramble.api.crypto.CryptoComponent;
import org.briarproject.bramble.api.crypto.KeyPair;
import org.briarproject.bramble.api.crypto.KeyParser;
import org.briarproject.bramble.api.crypto.PrivateKey;
import org.briarproject.bramble.api.crypto.PublicKey;
import org.briarproject.bramble.api.crypto.SecretKey;
@@ -61,7 +60,7 @@ class IntroductionCryptoImpl implements IntroductionCrypto {
}
@Override
public KeyPair generateKeyPair() {
public KeyPair generateAgreementKeyPair() {
return crypto.generateAgreementKeyPair();
}
@@ -82,21 +81,17 @@ class IntroductionCryptoImpl implements IntroductionCrypto {
);
}
SecretKey deriveMasterKey(byte[] publicKey, byte[] privateKey,
byte[] remotePublicKey, boolean alice)
SecretKey deriveMasterKey(PublicKey publicKey, PrivateKey privateKey,
PublicKey remotePublicKey, boolean alice)
throws GeneralSecurityException {
KeyParser kp = crypto.getAgreementKeyParser();
PublicKey remoteEphemeralPublicKey = kp.parsePublicKey(remotePublicKey);
PublicKey ephemeralPublicKey = kp.parsePublicKey(publicKey);
PrivateKey ephemeralPrivateKey = kp.parsePrivateKey(privateKey);
KeyPair keyPair = new KeyPair(ephemeralPublicKey, ephemeralPrivateKey);
KeyPair keyPair = new KeyPair(publicKey, privateKey);
return crypto.deriveSharedSecret(
LABEL_MASTER_KEY,
remoteEphemeralPublicKey,
remotePublicKey,
keyPair,
new byte[] {MAJOR_VERSION},
alice ? publicKey : remotePublicKey,
alice ? remotePublicKey : publicKey
alice ? publicKey.getEncoded() : remotePublicKey.getEncoded(),
alice ? remotePublicKey.getEncoded() : publicKey.getEncoded()
);
}
@@ -177,13 +172,9 @@ class IntroductionCryptoImpl implements IntroductionCrypto {
}
@Override
public byte[] sign(SecretKey macKey, byte[] privateKey)
public byte[] sign(SecretKey macKey, PrivateKey privateKey)
throws GeneralSecurityException {
return crypto.sign(
LABEL_AUTH_SIGN,
getNonce(macKey),
privateKey
);
return crypto.sign(LABEL_AUTH_SIGN, getNonce(macKey), privateKey);
}
@Override
@@ -194,7 +185,7 @@ class IntroductionCryptoImpl implements IntroductionCrypto {
verifySignature(macKey, s.getRemote().author.getPublicKey(), signature);
}
void verifySignature(SecretKey macKey, byte[] publicKey,
void verifySignature(SecretKey macKey, PublicKey publicKey,
byte[] signature) throws GeneralSecurityException {
byte[] nonce = getNonce(macKey);
if (!crypto.verifySignature(signature, LABEL_AUTH_SIGN, nonce,

View File

@@ -15,10 +15,9 @@ import org.briarproject.bramble.api.sync.MessageId;
import org.briarproject.bramble.api.system.Clock;
import org.briarproject.briar.api.client.SessionId;
import java.util.Collections;
import javax.annotation.concurrent.Immutable;
import static java.util.Collections.singletonList;
import static org.briarproject.bramble.api.crypto.CryptoConstants.MAC_BYTES;
import static org.briarproject.bramble.api.crypto.CryptoConstants.MAX_SIGNATURE_BYTES;
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_PUBLIC_KEY_LENGTH;
@@ -84,8 +83,7 @@ class IntroductionValidator extends BdfMessageValidator {
return new BdfMessageContext(meta);
} else {
MessageId dependency = new MessageId(previousMessageId);
return new BdfMessageContext(meta,
Collections.singletonList(dependency));
return new BdfMessageContext(meta, singletonList(dependency));
}
}
@@ -101,6 +99,7 @@ class IntroductionValidator extends BdfMessageValidator {
byte[] ephemeralPublicKey = body.getRaw(3);
checkLength(ephemeralPublicKey, 0, MAX_PUBLIC_KEY_LENGTH);
clientHelper.parseAndValidateAgreementPublicKey(ephemeralPublicKey);
long timestamp = body.getLong(4);
if (timestamp < 0) throw new FormatException();
@@ -111,15 +110,13 @@ class IntroductionValidator extends BdfMessageValidator {
.parseAndValidateTransportPropertiesMap(transportProperties);
SessionId sessionId = new SessionId(sessionIdBytes);
BdfDictionary meta = messageEncoder
.encodeMetadata(ACCEPT, sessionId, m.getTimestamp(), false,
false, false);
BdfDictionary meta = messageEncoder.encodeMetadata(ACCEPT, sessionId,
m.getTimestamp(), false, false, false);
if (previousMessageId == null) {
return new BdfMessageContext(meta);
} else {
MessageId dependency = new MessageId(previousMessageId);
return new BdfMessageContext(meta,
Collections.singletonList(dependency));
return new BdfMessageContext(meta, singletonList(dependency));
}
}
@@ -140,12 +137,10 @@ class IntroductionValidator extends BdfMessageValidator {
checkLength(signature, 1, MAX_SIGNATURE_BYTES);
SessionId sessionId = new SessionId(sessionIdBytes);
BdfDictionary meta = messageEncoder
.encodeMetadata(AUTH, sessionId, m.getTimestamp(), false, false,
false);
BdfDictionary meta = messageEncoder.encodeMetadata(AUTH, sessionId,
m.getTimestamp(), false, false, false);
MessageId dependency = new MessageId(previousMessageId);
return new BdfMessageContext(meta,
Collections.singletonList(dependency));
return new BdfMessageContext(meta, singletonList(dependency));
}
private BdfMessageContext validateActivateMessage(Message m, BdfList body)
@@ -162,15 +157,13 @@ class IntroductionValidator extends BdfMessageValidator {
checkLength(mac, MAC_BYTES);
SessionId sessionId = new SessionId(sessionIdBytes);
BdfDictionary meta = messageEncoder
.encodeMetadata(ACTIVATE, sessionId, m.getTimestamp(), false,
false, false);
BdfDictionary meta = messageEncoder.encodeMetadata(ACTIVATE, sessionId,
m.getTimestamp(), false, false, false);
if (previousMessageId == null) {
return new BdfMessageContext(meta);
} else {
MessageId dependency = new MessageId(previousMessageId);
return new BdfMessageContext(meta,
Collections.singletonList(dependency));
return new BdfMessageContext(meta, singletonList(dependency));
}
}
@@ -185,15 +178,13 @@ class IntroductionValidator extends BdfMessageValidator {
checkLength(previousMessageId, UniqueId.LENGTH);
SessionId sessionId = new SessionId(sessionIdBytes);
BdfDictionary meta = messageEncoder
.encodeMetadata(type, sessionId, m.getTimestamp(), false, false,
false);
BdfDictionary meta = messageEncoder.encodeMetadata(type, sessionId,
m.getTimestamp(), false, false, false);
if (previousMessageId == null) {
return new BdfMessageContext(meta);
} else {
MessageId dependency = new MessageId(previousMessageId);
return new BdfMessageContext(meta,
Collections.singletonList(dependency));
return new BdfMessageContext(meta, singletonList(dependency));
}
}

View File

@@ -1,5 +1,6 @@
package org.briarproject.briar.introduction;
import org.briarproject.bramble.api.crypto.PublicKey;
import org.briarproject.bramble.api.data.BdfDictionary;
import org.briarproject.bramble.api.identity.Author;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
@@ -35,7 +36,7 @@ interface MessageEncoder {
Message encodeAcceptMessage(GroupId contactGroupId, long timestamp,
@Nullable MessageId previousMessageId, SessionId sessionId,
byte[] ephemeralPublicKey, long acceptTimestamp,
PublicKey ephemeralPublicKey, long acceptTimestamp,
Map<TransportId, TransportProperties> transportProperties);
Message encodeDeclineMessage(GroupId contactGroupId, long timestamp,

View File

@@ -2,6 +2,7 @@ package org.briarproject.briar.introduction;
import org.briarproject.bramble.api.FormatException;
import org.briarproject.bramble.api.client.ClientHelper;
import org.briarproject.bramble.api.crypto.PublicKey;
import org.briarproject.bramble.api.data.BdfDictionary;
import org.briarproject.bramble.api.data.BdfList;
import org.briarproject.bramble.api.identity.Author;
@@ -105,13 +106,13 @@ class MessageEncoderImpl implements MessageEncoder {
@Override
public Message encodeAcceptMessage(GroupId contactGroupId, long timestamp,
@Nullable MessageId previousMessageId, SessionId sessionId,
byte[] ephemeralPublicKey, long acceptTimestamp,
PublicKey ephemeralPublicKey, long acceptTimestamp,
Map<TransportId, TransportProperties> transportProperties) {
BdfList body = BdfList.of(
ACCEPT.getValue(),
sessionId,
previousMessageId,
ephemeralPublicKey,
ephemeralPublicKey.getEncoded(),
acceptTimestamp,
clientHelper.toDictionary(transportProperties)
);

View File

@@ -2,6 +2,8 @@ package org.briarproject.briar.introduction;
import org.briarproject.bramble.api.FormatException;
import org.briarproject.bramble.api.client.ClientHelper;
import org.briarproject.bramble.api.crypto.AgreementPublicKey;
import org.briarproject.bramble.api.crypto.PublicKey;
import org.briarproject.bramble.api.data.BdfDictionary;
import org.briarproject.bramble.api.data.BdfEntry;
import org.briarproject.bramble.api.data.BdfList;
@@ -86,7 +88,7 @@ class MessageParserImpl implements MessageParser {
byte[] previousMsgBytes = body.getOptionalRaw(2);
MessageId previousMessageId = (previousMsgBytes == null ? null :
new MessageId(previousMsgBytes));
byte[] ephemeralPublicKey = body.getRaw(3);
PublicKey ephemeralPublicKey = new AgreementPublicKey(body.getRaw(3));
long acceptTimestamp = body.getLong(4);
Map<TransportId, TransportProperties> transportProperties = clientHelper
.parseAndValidateTransportPropertiesMap(body.getDictionary(5));

View File

@@ -2,6 +2,10 @@ package org.briarproject.briar.introduction;
import org.briarproject.bramble.api.FormatException;
import org.briarproject.bramble.api.client.ClientHelper;
import org.briarproject.bramble.api.crypto.AgreementPrivateKey;
import org.briarproject.bramble.api.crypto.AgreementPublicKey;
import org.briarproject.bramble.api.crypto.PrivateKey;
import org.briarproject.bramble.api.crypto.PublicKey;
import org.briarproject.bramble.api.data.BdfDictionary;
import org.briarproject.bramble.api.data.BdfEntry;
import org.briarproject.bramble.api.identity.Author;
@@ -122,12 +126,12 @@ class SessionParserImpl implements SessionParser {
MessageId lastLocalMessageId =
getMessageId(d, SESSION_KEY_LAST_LOCAL_MESSAGE_ID);
long localTimestamp = d.getLong(SESSION_KEY_LOCAL_TIMESTAMP);
byte[] ephemeralPublicKey =
d.getOptionalRaw(SESSION_KEY_EPHEMERAL_PUBLIC_KEY);
PublicKey ephemeralPublicKey =
getEphemeralPublicKey(d, SESSION_KEY_EPHEMERAL_PUBLIC_KEY);
BdfDictionary tpDict =
d.getOptionalDictionary(SESSION_KEY_TRANSPORT_PROPERTIES);
byte[] ephemeralPrivateKey =
d.getOptionalRaw(SESSION_KEY_EPHEMERAL_PRIVATE_KEY);
PrivateKey ephemeralPrivateKey =
getEphemeralPrivateKey(d, SESSION_KEY_EPHEMERAL_PRIVATE_KEY);
Map<TransportId, TransportProperties> transportProperties =
tpDict == null ? null : clientHelper
.parseAndValidateTransportPropertiesMap(tpDict);
@@ -143,8 +147,8 @@ class SessionParserImpl implements SessionParser {
Author remoteAuthor = getAuthor(d, SESSION_KEY_REMOTE_AUTHOR);
MessageId lastRemoteMessageId =
getMessageId(d, SESSION_KEY_LAST_REMOTE_MESSAGE_ID);
byte[] ephemeralPublicKey =
d.getOptionalRaw(SESSION_KEY_EPHEMERAL_PUBLIC_KEY);
PublicKey ephemeralPublicKey =
getEphemeralPublicKey(d, SESSION_KEY_EPHEMERAL_PUBLIC_KEY);
BdfDictionary tpDict =
d.getOptionalDictionary(SESSION_KEY_TRANSPORT_PROPERTIES);
Map<TransportId, TransportProperties> transportProperties =
@@ -195,4 +199,17 @@ class SessionParserImpl implements SessionParser {
return map;
}
@Nullable
private PublicKey getEphemeralPublicKey(BdfDictionary d, String key)
throws FormatException {
byte[] keyBytes = d.getOptionalRaw(key);
return keyBytes == null ? null : new AgreementPublicKey(keyBytes);
}
@Nullable
private PrivateKey getEphemeralPrivateKey(BdfDictionary d, String key)
throws FormatException {
byte[] keyBytes = d.getOptionalRaw(key);
return keyBytes == null ? null : new AgreementPrivateKey(keyBytes);
}
}

View File

@@ -4,6 +4,7 @@ import org.briarproject.bramble.api.FormatException;
import org.briarproject.bramble.api.client.ClientHelper;
import org.briarproject.bramble.api.client.ContactGroupFactory;
import org.briarproject.bramble.api.contact.Contact;
import org.briarproject.bramble.api.crypto.PrivateKey;
import org.briarproject.bramble.api.data.BdfList;
import org.briarproject.bramble.api.identity.AuthorId;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
@@ -35,7 +36,7 @@ class GroupInvitationFactoryImpl implements GroupInvitationFactory {
@Override
public byte[] signInvitation(Contact c, GroupId privateGroupId,
long timestamp, byte[] privateKey) {
long timestamp, PrivateKey privateKey) {
AuthorId creatorId = c.getLocalAuthorId();
AuthorId memberId = c.getAuthor().getId();
BdfList token = createInviteToken(creatorId, memberId, privateGroupId,

View File

@@ -19,7 +19,6 @@ import org.briarproject.briar.api.privategroup.PrivateGroupFactory;
import javax.annotation.concurrent.Immutable;
import javax.inject.Inject;
import static org.briarproject.bramble.api.identity.Author.FORMAT_VERSION;
import static org.briarproject.briar.client.MessageTrackerConstants.MSG_KEY_READ;
import static org.briarproject.briar.privategroup.invitation.GroupInvitationConstants.MSG_KEY_AVAILABLE_TO_ANSWER;
import static org.briarproject.briar.privategroup.invitation.GroupInvitationConstants.MSG_KEY_INVITATION_ACCEPTED;
@@ -105,14 +104,7 @@ class MessageParserImpl implements MessageParser {
String text = body.getOptionalString(4);
byte[] signature = body.getRaw(5);
// Format version, name, public key
int formatVersion = creatorList.getLong(0).intValue();
if (formatVersion != FORMAT_VERSION) throw new FormatException();
String creatorName = creatorList.getString(1);
byte[] creatorPublicKey = creatorList.getRaw(2);
Author creator = authorFactory.createAuthor(formatVersion, creatorName,
creatorPublicKey);
Author creator = clientHelper.parseAndValidateAuthor(creatorList);
PrivateGroup privateGroup = privateGroupFactory.createPrivateGroup(
groupName, creator, salt);
return new InviteMessage(m.getId(), m.getGroupId(),

View File

@@ -4,7 +4,6 @@ import org.briarproject.bramble.api.FormatException;
import org.briarproject.bramble.api.client.ClientHelper;
import org.briarproject.bramble.api.data.BdfList;
import org.briarproject.bramble.api.identity.Author;
import org.briarproject.bramble.api.identity.AuthorFactory;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.briar.api.blog.Blog;
import org.briarproject.briar.api.blog.BlogFactory;
@@ -12,21 +11,16 @@ import org.briarproject.briar.api.blog.BlogFactory;
import javax.annotation.concurrent.Immutable;
import javax.inject.Inject;
import static org.briarproject.bramble.api.identity.Author.FORMAT_VERSION;
@Immutable
@NotNullByDefault
class BlogMessageParserImpl extends MessageParserImpl<Blog> {
private final BlogFactory blogFactory;
private final AuthorFactory authorFactory;
@Inject
BlogMessageParserImpl(ClientHelper clientHelper, BlogFactory blogFactory,
AuthorFactory authorFactory) {
BlogMessageParserImpl(ClientHelper clientHelper, BlogFactory blogFactory) {
super(clientHelper);
this.blogFactory = blogFactory;
this.authorFactory = authorFactory;
}
@Override
@@ -35,14 +29,7 @@ class BlogMessageParserImpl extends MessageParserImpl<Blog> {
BdfList authorList = descriptor.getList(0);
boolean rssFeed = descriptor.getBoolean(1);
// Format version, name, public key
int formatVersion = authorList.getLong(0).intValue();
if (formatVersion != FORMAT_VERSION) throw new FormatException();
String name = authorList.getString(1);
byte[] publicKey = authorList.getRaw(2);
Author author = authorFactory.createAuthor(formatVersion, name,
publicKey);
Author author = clientHelper.parseAndValidateAuthor(authorList);
if (rssFeed) return blogFactory.createFeedBlog(author);
else return blogFactory.createBlog(author);
}

View File

@@ -30,7 +30,7 @@ import static org.briarproject.briar.sharing.SharingConstants.MSG_KEY_VISIBLE_IN
abstract class MessageParserImpl<S extends Shareable>
implements MessageParser<S> {
private final ClientHelper clientHelper;
protected final ClientHelper clientHelper;
MessageParserImpl(ClientHelper clientHelper) {
this.clientHelper = clientHelper;

View File

@@ -3,6 +3,7 @@ package org.briarproject.briar.forum;
import org.briarproject.bramble.api.FormatException;
import org.briarproject.bramble.api.UniqueId;
import org.briarproject.bramble.api.client.BdfMessageContext;
import org.briarproject.bramble.api.crypto.PublicKey;
import org.briarproject.bramble.api.data.BdfDictionary;
import org.briarproject.bramble.api.data.BdfList;
import org.briarproject.bramble.api.identity.Author;
@@ -37,9 +38,9 @@ public class ForumPostValidatorTest extends ValidatorTestCase {
private final byte[] signature = getRandomBytes(MAX_SIGNATURE_LENGTH);
private final Author author = getAuthor();
private final String authorName = author.getName();
private final byte[] authorPublicKey = author.getPublicKey();
private final PublicKey authorPublicKey = author.getPublicKey();
private final BdfList authorList = BdfList.of(author.getFormatVersion(),
authorName, authorPublicKey);
authorName, authorPublicKey.getEncoded());
private final BdfList signedWithParent = BdfList.of(groupId, timestamp,
parentId.getBytes(), authorList, text);
private final BdfList signedWithoutParent = BdfList.of(groupId, timestamp,

View File

@@ -64,8 +64,8 @@ public class IntroductionCryptoIntegrationTest extends BrambleTestCase {
crypto.isAlice(introducee1.getId(), introducee2.getId());
alice = isAlice ? introducee1 : introducee2;
bob = isAlice ? introducee2 : introducee1;
aliceEphemeral = crypto.generateKeyPair();
bobEphemeral = crypto.generateKeyPair();
aliceEphemeral = crypto.generateAgreementKeyPair();
bobEphemeral = crypto.generateAgreementKeyPair();
}
@Test
@@ -86,30 +86,25 @@ public class IntroductionCryptoIntegrationTest extends BrambleTestCase {
@Test
public void testDeriveMasterKey() throws Exception {
SecretKey aliceMasterKey =
crypto.deriveMasterKey(aliceEphemeral.getPublic().getEncoded(),
aliceEphemeral.getPrivate().getEncoded(),
bobEphemeral.getPublic().getEncoded(), true);
SecretKey bobMasterKey =
crypto.deriveMasterKey(bobEphemeral.getPublic().getEncoded(),
bobEphemeral.getPrivate().getEncoded(),
aliceEphemeral.getPublic().getEncoded(), false);
SecretKey aliceMasterKey = crypto.deriveMasterKey(
aliceEphemeral.getPublic(), aliceEphemeral.getPrivate(),
bobEphemeral.getPublic(), true);
SecretKey bobMasterKey = crypto.deriveMasterKey(
bobEphemeral.getPublic(), bobEphemeral.getPrivate(),
aliceEphemeral.getPublic(), false);
assertArrayEquals(aliceMasterKey.getBytes(), bobMasterKey.getBytes());
}
@Test
public void testAliceAuthMac() throws Exception {
SecretKey aliceMacKey = crypto.deriveMacKey(masterKey, true);
Local local = new Local(true, null, -1,
aliceEphemeral.getPublic().getEncoded(),
aliceEphemeral.getPrivate().getEncoded(), aliceTransport,
Local local = new Local(true, null, -1, aliceEphemeral.getPublic(),
aliceEphemeral.getPrivate(), aliceTransport,
aliceAcceptTimestamp, aliceMacKey.getBytes());
Remote remote = new Remote(false, bob, null,
bobEphemeral.getPublic().getEncoded(), bobTransport,
bobAcceptTimestamp, null);
byte[] aliceMac =
crypto.authMac(aliceMacKey, introducer.getId(), alice.getId(),
local, remote);
Remote remote = new Remote(false, bob, null, bobEphemeral.getPublic(),
bobTransport, bobAcceptTimestamp, null);
byte[] aliceMac = crypto.authMac(aliceMacKey, introducer.getId(),
alice.getId(), local, remote);
// verify from Bob's perspective
crypto.verifyAuthMac(aliceMac, aliceMacKey, introducer.getId(),
@@ -119,16 +114,14 @@ public class IntroductionCryptoIntegrationTest extends BrambleTestCase {
@Test
public void testBobAuthMac() throws Exception {
SecretKey bobMacKey = crypto.deriveMacKey(masterKey, false);
Local local = new Local(false, null, -1,
bobEphemeral.getPublic().getEncoded(),
bobEphemeral.getPrivate().getEncoded(), bobTransport,
Local local = new Local(false, null, -1, bobEphemeral.getPublic(),
bobEphemeral.getPrivate(), bobTransport,
bobAcceptTimestamp, bobMacKey.getBytes());
Remote remote = new Remote(true, alice, null,
aliceEphemeral.getPublic().getEncoded(), aliceTransport,
aliceEphemeral.getPublic(), aliceTransport,
aliceAcceptTimestamp, null);
byte[] bobMac =
crypto.authMac(bobMacKey, introducer.getId(), bob.getId(),
local, remote);
byte[] bobMac = crypto.authMac(bobMacKey, introducer.getId(),
bob.getId(), local, remote);
// verify from Alice's perspective
crypto.verifyAuthMac(bobMac, bobMacKey, introducer.getId(),

View File

@@ -42,9 +42,8 @@ import java.util.Collection;
import java.util.Map;
import java.util.concurrent.TimeoutException;
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_PUBLIC_KEY_LENGTH;
import static org.briarproject.bramble.test.TestPluginConfigModule.TRANSPORT_ID;
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
import static org.briarproject.bramble.test.TestUtils.getAgreementPublicKey;
import static org.briarproject.bramble.test.TestUtils.getSecretKey;
import static org.briarproject.bramble.test.TestUtils.getTransportProperties;
import static org.briarproject.bramble.test.TestUtils.getTransportPropertiesMap;
@@ -1149,8 +1148,7 @@ public class IntroductionIntegrationTest
testModifiedResponse(
m -> new AcceptMessage(m.getMessageId(), m.getGroupId(),
m.getTimestamp(), m.getPreviousMessageId(),
m.getSessionId(),
getRandomBytes(MAX_PUBLIC_KEY_LENGTH),
m.getSessionId(), getAgreementPublicKey(),
m.getAcceptTimestamp(), m.getTransportProperties())
);
}
@@ -1216,8 +1214,8 @@ public class IntroductionIntegrationTest
@ParametersNotNullByDefault
private abstract class IntroductionListener implements EventListener {
protected volatile boolean aborted = false;
protected volatile Event latestEvent;
volatile boolean aborted = false;
volatile Event latestEvent;
@SuppressWarnings("WeakerAccess")
IntroductionResponse getResponse() {

View File

@@ -2,6 +2,7 @@ package org.briarproject.briar.introduction;
import org.briarproject.bramble.api.FormatException;
import org.briarproject.bramble.api.client.BdfMessageContext;
import org.briarproject.bramble.api.crypto.PublicKey;
import org.briarproject.bramble.api.data.BdfDictionary;
import org.briarproject.bramble.api.data.BdfEntry;
import org.briarproject.bramble.api.data.BdfList;
@@ -14,8 +15,9 @@ import org.junit.Test;
import javax.annotation.Nullable;
import static org.briarproject.bramble.api.crypto.CryptoConstants.MAC_BYTES;
import static org.briarproject.bramble.api.crypto.CryptoConstants.MAX_AGREEMENT_PUBLIC_KEY_BYTES;
import static org.briarproject.bramble.api.crypto.CryptoConstants.MAX_SIGNATURE_BYTES;
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_PUBLIC_KEY_LENGTH;
import static org.briarproject.bramble.test.TestUtils.getAgreementPublicKey;
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
import static org.briarproject.bramble.test.TestUtils.getRandomId;
import static org.briarproject.bramble.util.StringUtils.getRandomString;
@@ -40,6 +42,7 @@ public class IntroductionValidatorTest extends ValidatorTestCase {
private final MessageId previousMsgId = new MessageId(getRandomId());
private final String text = getRandomString(MAX_INTRODUCTION_TEXT_LENGTH);
private final BdfDictionary meta = new BdfDictionary();
private final PublicKey ephemeralPublicKey = getAgreementPublicKey();
private final long acceptTimestamp = 42;
private final BdfDictionary transportProperties = BdfDictionary.of(
new BdfEntry("transportId", new BdfDictionary())
@@ -123,8 +126,9 @@ public class IntroductionValidatorTest extends ValidatorTestCase {
@Test
public void testAcceptsAccept() throws Exception {
BdfList body = BdfList.of(ACCEPT.getValue(), sessionId.getBytes(),
previousMsgId.getBytes(), getRandomBytes(MAX_PUBLIC_KEY_LENGTH),
previousMsgId.getBytes(), ephemeralPublicKey.getEncoded(),
acceptTimestamp, transportProperties);
expectParsePublicKey();
context.checking(new Expectations() {{
oneOf(clientHelper).parseAndValidateTransportPropertiesMap(
transportProperties);
@@ -139,32 +143,31 @@ public class IntroductionValidatorTest extends ValidatorTestCase {
@Test(expected = FormatException.class)
public void testRejectsTooShortBodyForAccept() throws Exception {
BdfList body = BdfList.of(ACCEPT.getValue(), sessionId.getBytes(),
previousMsgId.getBytes(),
getRandomBytes(MAX_PUBLIC_KEY_LENGTH), acceptTimestamp);
previousMsgId.getBytes(), ephemeralPublicKey.getEncoded(),
acceptTimestamp);
validator.validateMessage(message, group, body);
}
@Test(expected = FormatException.class)
public void testRejectsTooLongBodyForAccept() throws Exception {
BdfList body = BdfList.of(ACCEPT.getValue(), sessionId.getBytes(),
previousMsgId.getBytes(), getRandomBytes(MAX_PUBLIC_KEY_LENGTH),
previousMsgId.getBytes(), ephemeralPublicKey.getEncoded(),
acceptTimestamp, transportProperties, null);
validator.validateMessage(message, group, body);
}
@Test(expected = FormatException.class)
public void testRejectsInvalidSessionIdForAccept() throws Exception {
BdfList body =
BdfList.of(ACCEPT.getValue(), null, previousMsgId.getBytes(),
getRandomBytes(MAX_PUBLIC_KEY_LENGTH), acceptTimestamp,
transportProperties);
BdfList body = BdfList.of(ACCEPT.getValue(), null,
previousMsgId.getBytes(), ephemeralPublicKey.getEncoded(),
acceptTimestamp, transportProperties);
validator.validateMessage(message, group, body);
}
@Test(expected = FormatException.class)
public void testRejectsInvalidPreviousMsgIdForAccept() throws Exception {
BdfList body = BdfList.of(ACCEPT.getValue(), sessionId.getBytes(), 1,
getRandomBytes(MAX_PUBLIC_KEY_LENGTH), acceptTimestamp,
ephemeralPublicKey.getEncoded(), acceptTimestamp,
transportProperties);
validator.validateMessage(message, group, body);
}
@@ -173,16 +176,17 @@ public class IntroductionValidatorTest extends ValidatorTestCase {
public void testRejectsTooLongPublicKeyForAccept() throws Exception {
BdfList body = BdfList.of(ACCEPT.getValue(), sessionId.getBytes(),
previousMsgId.getBytes(),
getRandomBytes(MAX_PUBLIC_KEY_LENGTH + 1), acceptTimestamp,
transportProperties);
getRandomBytes(MAX_AGREEMENT_PUBLIC_KEY_BYTES + 1),
acceptTimestamp, transportProperties);
validator.validateMessage(message, group, body);
}
@Test(expected = FormatException.class)
public void testRejectsNegativeTimestampForAccept() throws Exception {
BdfList body = BdfList.of(ACCEPT.getValue(), sessionId.getBytes(),
previousMsgId.getBytes(), getRandomBytes(MAX_PUBLIC_KEY_LENGTH),
previousMsgId.getBytes(), ephemeralPublicKey.getEncoded(),
-1, transportProperties);
expectParsePublicKey();
validator.validateMessage(message, group, body);
}
@@ -190,9 +194,9 @@ public class IntroductionValidatorTest extends ValidatorTestCase {
public void testRejectsEmptyTransportPropertiesForAccept()
throws Exception {
BdfList body = BdfList.of(ACCEPT.getValue(), sessionId.getBytes(),
previousMsgId.getBytes(),
getRandomBytes(MAX_PUBLIC_KEY_LENGTH + 1), acceptTimestamp,
new BdfDictionary());
previousMsgId.getBytes(), ephemeralPublicKey.getEncoded(),
acceptTimestamp, new BdfDictionary());
expectParsePublicKey();
validator.validateMessage(message, group, body);
}
@@ -271,8 +275,7 @@ public class IntroductionValidatorTest extends ValidatorTestCase {
@Test(expected = FormatException.class)
public void testRejectsInvalidPreviousMsgIdForAuth() throws Exception {
BdfList body = BdfList.of(AUTH.getValue(), sessionId.getBytes(),
1, getRandomBytes(MAC_BYTES),
signature);
1, getRandomBytes(MAC_BYTES), signature);
validator.validateMessage(message, group, body);
}
@@ -294,8 +297,8 @@ public class IntroductionValidatorTest extends ValidatorTestCase {
@Test(expected = FormatException.class)
public void testRejectsTooLongMacForAuth() throws Exception {
BdfList body = BdfList.of(AUTH.getValue(), sessionId.getBytes(),
previousMsgId.getBytes(),
getRandomBytes(MAC_BYTES + 1), signature);
previousMsgId.getBytes(), getRandomBytes(MAC_BYTES + 1),
signature);
validator.validateMessage(message, group, body);
}
@@ -360,9 +363,8 @@ public class IntroductionValidatorTest extends ValidatorTestCase {
@Test(expected = FormatException.class)
public void testRejectsInvalidSessionIdForActivate() throws Exception {
BdfList body =
BdfList.of(ACTIVATE.getValue(), null, previousMsgId.getBytes(),
mac);
BdfList body = BdfList.of(ACTIVATE.getValue(), null,
previousMsgId.getBytes(), mac);
validator.validateMessage(message, group, body);
}
@@ -375,9 +377,8 @@ public class IntroductionValidatorTest extends ValidatorTestCase {
@Test(expected = FormatException.class)
public void testRejectsPreviousMsgIdNullForActivate() throws Exception {
BdfList body =
BdfList.of(ACTIVATE.getValue(), sessionId.getBytes(), null,
mac);
BdfList body = BdfList.of(ACTIVATE.getValue(), sessionId.getBytes(),
null, mac);
validator.validateMessage(message, group, body);
}
@@ -434,6 +435,13 @@ public class IntroductionValidatorTest extends ValidatorTestCase {
// Introduction Helper Methods
//
private void expectParsePublicKey() throws Exception {
context.checking(new Expectations() {{
oneOf(clientHelper).parseAndValidateAgreementPublicKey(
ephemeralPublicKey.getEncoded());
will(returnValue(ephemeralPublicKey));
}});
}
private void expectEncodeRequestMetadata() {
context.checking(new Expectations() {{
oneOf(messageEncoder).encodeRequestMetadata(message.getTimestamp());
@@ -443,9 +451,8 @@ public class IntroductionValidatorTest extends ValidatorTestCase {
private void expectEncodeMetadata(MessageType type) {
context.checking(new Expectations() {{
oneOf(messageEncoder)
.encodeMetadata(type, sessionId, message.getTimestamp(),
false, false, false);
oneOf(messageEncoder).encodeMetadata(type, sessionId,
message.getTimestamp(), false, false, false);
will(returnValue(meta));
}});
}

View File

@@ -2,6 +2,7 @@ package org.briarproject.briar.introduction;
import org.briarproject.bramble.api.FormatException;
import org.briarproject.bramble.api.client.ClientHelper;
import org.briarproject.bramble.api.crypto.PublicKey;
import org.briarproject.bramble.api.data.BdfDictionary;
import org.briarproject.bramble.api.data.MetadataEncoder;
import org.briarproject.bramble.api.identity.Author;
@@ -24,7 +25,7 @@ import javax.inject.Inject;
import static org.briarproject.bramble.api.crypto.CryptoConstants.MAC_BYTES;
import static org.briarproject.bramble.api.crypto.CryptoConstants.MAX_SIGNATURE_BYTES;
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_PUBLIC_KEY_LENGTH;
import static org.briarproject.bramble.test.TestUtils.getAgreementPublicKey;
import static org.briarproject.bramble.test.TestUtils.getGroup;
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
import static org.briarproject.bramble.test.TestUtils.getRandomId;
@@ -66,8 +67,7 @@ public class MessageEncoderParserIntegrationTest extends BrambleTestCase {
private final MessageId previousMsgId = new MessageId(getRandomId());
private final Author author;
private final String text = getRandomString(MAX_INTRODUCTION_TEXT_LENGTH);
private final byte[] ephemeralPublicKey =
getRandomBytes(MAX_PUBLIC_KEY_LENGTH);
private final PublicKey ephemeralPublicKey = getAgreementPublicKey();
private final byte[] mac = getRandomBytes(MAC_BYTES);
private final byte[] signature = getRandomBytes(MAX_SIGNATURE_BYTES);
@@ -173,7 +173,8 @@ public class MessageEncoderParserIntegrationTest extends BrambleTestCase {
assertEquals(m.getTimestamp(), am.getTimestamp());
assertEquals(previousMsgId, am.getPreviousMessageId());
assertEquals(sessionId, am.getSessionId());
assertArrayEquals(ephemeralPublicKey, am.getEphemeralPublicKey());
assertArrayEquals(ephemeralPublicKey.getEncoded(),
am.getEphemeralPublicKey().getEncoded());
assertEquals(acceptTimestamp, am.getAcceptTimestamp());
assertEquals(transportProperties, am.getTransportProperties());
}

View File

@@ -2,6 +2,8 @@ package org.briarproject.briar.introduction;
import org.briarproject.bramble.api.FormatException;
import org.briarproject.bramble.api.client.ClientHelper;
import org.briarproject.bramble.api.crypto.PrivateKey;
import org.briarproject.bramble.api.crypto.PublicKey;
import org.briarproject.bramble.api.crypto.SecretKey;
import org.briarproject.bramble.api.data.BdfDictionary;
import org.briarproject.bramble.api.identity.Author;
@@ -21,7 +23,8 @@ import java.util.Map;
import javax.inject.Inject;
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_PUBLIC_KEY_LENGTH;
import static org.briarproject.bramble.test.TestUtils.getAgreementPrivateKey;
import static org.briarproject.bramble.test.TestUtils.getAgreementPublicKey;
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
import static org.briarproject.bramble.test.TestUtils.getRandomId;
import static org.briarproject.bramble.test.TestUtils.getTransportId;
@@ -37,6 +40,7 @@ import static org.briarproject.briar.test.BriarTestUtils.getRealAuthor;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
@@ -64,13 +68,10 @@ public class SessionEncoderParserIntegrationTest extends BrambleTestCase {
private final MessageId lastRemoteMessageId2 = new MessageId(getRandomId());
private final Author author1;
private final Author author2;
private final byte[] ephemeralPublicKey =
getRandomBytes(MAX_PUBLIC_KEY_LENGTH);
private final byte[] ephemeralPrivateKey =
getRandomBytes(MAX_PUBLIC_KEY_LENGTH);
private final PublicKey ephemeralPublicKey = getAgreementPublicKey();
private final PrivateKey ephemeralPrivateKey = getAgreementPrivateKey();
private final byte[] masterKey = getRandomBytes(SecretKey.LENGTH);
private final byte[] remoteEphemeralPublicKey =
getRandomBytes(MAX_PUBLIC_KEY_LENGTH);
private final PublicKey remoteEphemeralPublicKey = getAgreementPublicKey();
private final Map<TransportId, TransportProperties> transportProperties =
getTransportPropertiesMap(3);
private final Map<TransportId, TransportProperties>
@@ -193,13 +194,22 @@ public class SessionEncoderParserIntegrationTest extends BrambleTestCase {
assertEquals(localTimestamp, s1.getLocal().lastMessageTimestamp);
assertEquals(s1.getLocal().lastMessageTimestamp,
s2.getLocal().lastMessageTimestamp);
assertArrayEquals(ephemeralPublicKey, s1.getLocal().ephemeralPublicKey);
assertArrayEquals(s1.getLocal().ephemeralPublicKey,
s2.getLocal().ephemeralPublicKey);
assertArrayEquals(ephemeralPrivateKey,
s1.getLocal().ephemeralPrivateKey);
assertArrayEquals(s1.getLocal().ephemeralPrivateKey,
s2.getLocal().ephemeralPrivateKey);
PublicKey s1LocalEphemeralPub = s1.getLocal().ephemeralPublicKey;
PublicKey s2LocalEphemeralPub = s2.getLocal().ephemeralPublicKey;
assertNotNull(s1LocalEphemeralPub);
assertNotNull(s2LocalEphemeralPub);
assertArrayEquals(ephemeralPublicKey.getEncoded(),
s1LocalEphemeralPub.getEncoded());
assertArrayEquals(s1LocalEphemeralPub.getEncoded(),
s2LocalEphemeralPub.getEncoded());
PrivateKey s1LocalEphemeralPriv = s1.getLocal().ephemeralPrivateKey;
PrivateKey s2LocalEphemeralPriv = s2.getLocal().ephemeralPrivateKey;
assertNotNull(s1LocalEphemeralPriv);
assertNotNull(s2LocalEphemeralPriv);
assertArrayEquals(ephemeralPrivateKey.getEncoded(),
s1LocalEphemeralPriv.getEncoded());
assertArrayEquals(s1LocalEphemeralPriv.getEncoded(),
s2LocalEphemeralPriv.getEncoded());
assertEquals(transportProperties, s1.getLocal().transportProperties);
assertEquals(s1.getLocal().transportProperties,
s2.getLocal().transportProperties);
@@ -217,10 +227,14 @@ public class SessionEncoderParserIntegrationTest extends BrambleTestCase {
assertEquals(lastRemoteMessageId, s1.getRemote().lastMessageId);
assertEquals(s1.getRemote().lastMessageId,
s2.getRemote().lastMessageId);
assertArrayEquals(remoteEphemeralPublicKey,
s1.getRemote().ephemeralPublicKey);
assertArrayEquals(s1.getRemote().ephemeralPublicKey,
s2.getRemote().ephemeralPublicKey);
PublicKey s1RemoteEphemeralPub = s1.getRemote().ephemeralPublicKey;
PublicKey s2RemoteEphemeralPub = s2.getRemote().ephemeralPublicKey;
assertNotNull(s1RemoteEphemeralPub);
assertNotNull(s2RemoteEphemeralPub);
assertArrayEquals(remoteEphemeralPublicKey.getEncoded(),
s1RemoteEphemeralPub.getEncoded());
assertArrayEquals(s1RemoteEphemeralPub.getEncoded(),
s2RemoteEphemeralPub.getEncoded());
assertEquals(remoteTransportProperties,
s1.getRemote().transportProperties);
assertEquals(s1.getRemote().transportProperties,
@@ -311,7 +325,7 @@ public class SessionEncoderParserIntegrationTest extends BrambleTestCase {
ephemeralPublicKey, ephemeralPrivateKey, transportProperties,
acceptTimestamp, localMacKey);
Remote remote = new Remote(false, author2, lastRemoteMessageId,
remoteEphemeralPublicKey, remoteTransportProperties,
remoteEphemeralPublicKey, remoteTransportProperties,
remoteAcceptTimestamp, remoteMacKey);
return new IntroduceeSession(sessionId, LOCAL_ACCEPTED,
requestTimestamp, groupId1, author1, local, remote,

View File

@@ -29,6 +29,7 @@ import static org.briarproject.briar.api.privategroup.Visibility.INVISIBLE;
import static org.briarproject.briar.api.privategroup.Visibility.REVEALED_BY_CONTACT;
import static org.briarproject.briar.api.privategroup.Visibility.REVEALED_BY_US;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
/**
@@ -164,7 +165,7 @@ public class PrivateGroupIntegrationTest
getGroupMember(groupManager2, author1.getId()).getVisibility());
// 1 reveals the contact relationship to 2
assertTrue(contactId2From1 != null);
assertNotNull(contactId2From1);
groupInvitationManager1.revealRelationship(contactId2From1, groupId0);
sync1To2(1, true);
sync2To1(1, true);

View File

@@ -458,8 +458,8 @@ public class GroupInvitationIntegrationTest
sync1To0(1, true);
}
private void sendInvitation(long timestamp, @Nullable String text) throws
DbException {
private void sendInvitation(long timestamp, @Nullable String text)
throws DbException {
byte[] signature = groupInvitationFactory.signInvitation(contact1From0,
privateGroup0.getId(), timestamp, author0.getPrivateKey());
groupInvitationManager0