mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-22 07:39:53 +01:00
Generate handshake keys when creating local author.
This commit is contained in:
@@ -18,14 +18,7 @@ public interface AuthorFactory {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a local author with the current format version and the given
|
* Creates a local author with the current format version and the given
|
||||||
* name and keys.
|
* name.
|
||||||
*/
|
*/
|
||||||
LocalAuthor createLocalAuthor(String name, byte[] publicKey,
|
LocalAuthor createLocalAuthor(String name, boolean handshakeKeys);
|
||||||
byte[] privateKey);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a local author with the given format version, name and keys.
|
|
||||||
*/
|
|
||||||
LocalAuthor createLocalAuthor(int formatVersion, String name,
|
|
||||||
byte[] publicKey, byte[] privateKey);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package org.briarproject.bramble.identity;
|
package org.briarproject.bramble.identity;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.crypto.CryptoComponent;
|
import org.briarproject.bramble.api.crypto.CryptoComponent;
|
||||||
|
import org.briarproject.bramble.api.crypto.KeyPair;
|
||||||
import org.briarproject.bramble.api.identity.Author;
|
import org.briarproject.bramble.api.identity.Author;
|
||||||
import org.briarproject.bramble.api.identity.AuthorFactory;
|
import org.briarproject.bramble.api.identity.AuthorFactory;
|
||||||
import org.briarproject.bramble.api.identity.AuthorId;
|
import org.briarproject.bramble.api.identity.AuthorId;
|
||||||
@@ -43,17 +44,21 @@ class AuthorFactoryImpl implements AuthorFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LocalAuthor createLocalAuthor(String name, byte[] publicKey,
|
public LocalAuthor createLocalAuthor(String name, boolean handshakeKeys) {
|
||||||
byte[] privateKey) {
|
KeyPair signatureKeyPair = crypto.generateSignatureKeyPair();
|
||||||
return createLocalAuthor(FORMAT_VERSION, name, publicKey, privateKey);
|
byte[] sigPub = signatureKeyPair.getPublic().getEncoded();
|
||||||
}
|
byte[] sigPriv = signatureKeyPair.getPrivate().getEncoded();
|
||||||
|
AuthorId id = getId(FORMAT_VERSION, name, sigPub);
|
||||||
@Override
|
if (handshakeKeys) {
|
||||||
public LocalAuthor createLocalAuthor(int formatVersion, String name,
|
KeyPair handshakeKeyPair = crypto.generateAgreementKeyPair();
|
||||||
byte[] publicKey, byte[] privateKey) {
|
byte[] handPub = handshakeKeyPair.getPublic().getEncoded();
|
||||||
AuthorId id = getId(formatVersion, name, publicKey);
|
byte[] handPriv = handshakeKeyPair.getPrivate().getEncoded();
|
||||||
return new LocalAuthor(id, formatVersion, name, publicKey, privateKey,
|
return new LocalAuthor(id, FORMAT_VERSION, name, sigPub, sigPriv,
|
||||||
clock.currentTimeMillis());
|
handPub, handPriv, clock.currentTimeMillis());
|
||||||
|
} else {
|
||||||
|
return new LocalAuthor(id, FORMAT_VERSION, name, sigPub, sigPriv,
|
||||||
|
clock.currentTimeMillis());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private AuthorId getId(int formatVersion, String name, byte[] publicKey) {
|
private AuthorId getId(int formatVersion, String name, byte[] publicKey) {
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package org.briarproject.bramble.identity;
|
package org.briarproject.bramble.identity;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.crypto.CryptoComponent;
|
|
||||||
import org.briarproject.bramble.api.crypto.KeyPair;
|
|
||||||
import org.briarproject.bramble.api.db.DatabaseComponent;
|
import org.briarproject.bramble.api.db.DatabaseComponent;
|
||||||
import org.briarproject.bramble.api.db.DbException;
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
import org.briarproject.bramble.api.db.Transaction;
|
import org.briarproject.bramble.api.db.Transaction;
|
||||||
@@ -27,7 +25,6 @@ class IdentityManagerImpl implements IdentityManager {
|
|||||||
Logger.getLogger(IdentityManagerImpl.class.getName());
|
Logger.getLogger(IdentityManagerImpl.class.getName());
|
||||||
|
|
||||||
private final DatabaseComponent db;
|
private final DatabaseComponent db;
|
||||||
private final CryptoComponent crypto;
|
|
||||||
private final AuthorFactory authorFactory;
|
private final AuthorFactory authorFactory;
|
||||||
|
|
||||||
// The local author is immutable so we can cache it
|
// The local author is immutable so we can cache it
|
||||||
@@ -35,21 +32,15 @@ class IdentityManagerImpl implements IdentityManager {
|
|||||||
private volatile LocalAuthor cachedAuthor;
|
private volatile LocalAuthor cachedAuthor;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
IdentityManagerImpl(DatabaseComponent db, CryptoComponent crypto,
|
IdentityManagerImpl(DatabaseComponent db, AuthorFactory authorFactory) {
|
||||||
AuthorFactory authorFactory) {
|
|
||||||
this.db = db;
|
this.db = db;
|
||||||
this.crypto = crypto;
|
|
||||||
this.authorFactory = authorFactory;
|
this.authorFactory = authorFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LocalAuthor createLocalAuthor(String name) {
|
public LocalAuthor createLocalAuthor(String name) {
|
||||||
long start = now();
|
long start = now();
|
||||||
KeyPair keyPair = crypto.generateSignatureKeyPair();
|
LocalAuthor localAuthor = authorFactory.createLocalAuthor(name, true);
|
||||||
byte[] publicKey = keyPair.getPublic().getEncoded();
|
|
||||||
byte[] privateKey = keyPair.getPrivate().getEncoded();
|
|
||||||
LocalAuthor localAuthor = authorFactory.createLocalAuthor(name,
|
|
||||||
publicKey, privateKey);
|
|
||||||
logDuration(LOG, "Creating local author", start);
|
logDuration(LOG, "Creating local author", start);
|
||||||
return localAuthor;
|
return localAuthor;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,5 @@
|
|||||||
package org.briarproject.bramble.identity;
|
package org.briarproject.bramble.identity;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.crypto.CryptoComponent;
|
|
||||||
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.db.DatabaseComponent;
|
import org.briarproject.bramble.api.db.DatabaseComponent;
|
||||||
import org.briarproject.bramble.api.db.DbException;
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
import org.briarproject.bramble.api.db.Transaction;
|
import org.briarproject.bramble.api.db.Transaction;
|
||||||
@@ -12,56 +8,30 @@ import org.briarproject.bramble.api.identity.IdentityManager;
|
|||||||
import org.briarproject.bramble.api.identity.LocalAuthor;
|
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||||
import org.briarproject.bramble.test.BrambleMockTestCase;
|
import org.briarproject.bramble.test.BrambleMockTestCase;
|
||||||
import org.briarproject.bramble.test.DbExpectations;
|
import org.briarproject.bramble.test.DbExpectations;
|
||||||
import org.jmock.Expectations;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
|
||||||
|
|
||||||
|
import static java.util.Collections.singletonList;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getLocalAuthor;
|
import static org.briarproject.bramble.test.TestUtils.getLocalAuthor;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
public class IdentityManagerImplTest extends BrambleMockTestCase {
|
public class IdentityManagerImplTest extends BrambleMockTestCase {
|
||||||
|
|
||||||
private final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
private final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||||
private final CryptoComponent crypto = context.mock(CryptoComponent.class);
|
|
||||||
private final AuthorFactory authorFactory =
|
private final AuthorFactory authorFactory =
|
||||||
context.mock(AuthorFactory.class);
|
context.mock(AuthorFactory.class);
|
||||||
private final PublicKey publicKey = context.mock(PublicKey.class);
|
|
||||||
private final PrivateKey privateKey = context.mock(PrivateKey.class);
|
|
||||||
|
|
||||||
private final Transaction txn = new Transaction(null, false);
|
private final Transaction txn = new Transaction(null, false);
|
||||||
private final LocalAuthor localAuthor = getLocalAuthor();
|
private final LocalAuthor localAuthor = getLocalAuthor();
|
||||||
private final Collection<LocalAuthor> localAuthors =
|
private final Collection<LocalAuthor> localAuthors =
|
||||||
Collections.singletonList(localAuthor);
|
singletonList(localAuthor);
|
||||||
private final String authorName = localAuthor.getName();
|
|
||||||
private final KeyPair keyPair = new KeyPair(publicKey, privateKey);
|
|
||||||
private final byte[] publicKeyBytes = localAuthor.getPublicKey();
|
|
||||||
private final byte[] privateKeyBytes = localAuthor.getPrivateKey();
|
|
||||||
private IdentityManager identityManager;
|
private IdentityManager identityManager;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
identityManager = new IdentityManagerImpl(db, crypto, authorFactory);
|
identityManager = new IdentityManagerImpl(db, authorFactory);
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testCreateLocalAuthor() {
|
|
||||||
context.checking(new Expectations() {{
|
|
||||||
oneOf(crypto).generateSignatureKeyPair();
|
|
||||||
will(returnValue(keyPair));
|
|
||||||
oneOf(publicKey).getEncoded();
|
|
||||||
will(returnValue(publicKeyBytes));
|
|
||||||
oneOf(privateKey).getEncoded();
|
|
||||||
will(returnValue(privateKeyBytes));
|
|
||||||
oneOf(authorFactory).createLocalAuthor(authorName,
|
|
||||||
publicKeyBytes, privateKeyBytes);
|
|
||||||
will(returnValue(localAuthor));
|
|
||||||
}});
|
|
||||||
|
|
||||||
assertEquals(localAuthor,
|
|
||||||
identityManager.createLocalAuthor(authorName));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -4,8 +4,6 @@ import com.rometools.rome.feed.synd.SyndFeed;
|
|||||||
|
|
||||||
import org.briarproject.bramble.api.FormatException;
|
import org.briarproject.bramble.api.FormatException;
|
||||||
import org.briarproject.bramble.api.client.ClientHelper;
|
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.data.BdfDictionary;
|
import org.briarproject.bramble.api.data.BdfDictionary;
|
||||||
import org.briarproject.bramble.api.data.BdfEntry;
|
import org.briarproject.bramble.api.data.BdfEntry;
|
||||||
import org.briarproject.bramble.api.data.BdfList;
|
import org.briarproject.bramble.api.data.BdfList;
|
||||||
@@ -32,17 +30,14 @@ import static org.briarproject.briar.api.feed.FeedConstants.KEY_FEED_URL;
|
|||||||
|
|
||||||
class FeedFactoryImpl implements FeedFactory {
|
class FeedFactoryImpl implements FeedFactory {
|
||||||
|
|
||||||
private final CryptoComponent cryptoComponent;
|
|
||||||
private final AuthorFactory authorFactory;
|
private final AuthorFactory authorFactory;
|
||||||
private final BlogFactory blogFactory;
|
private final BlogFactory blogFactory;
|
||||||
private final ClientHelper clientHelper;
|
private final ClientHelper clientHelper;
|
||||||
private final Clock clock;
|
private final Clock clock;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
FeedFactoryImpl(CryptoComponent cryptoComponent,
|
FeedFactoryImpl(AuthorFactory authorFactory, BlogFactory blogFactory,
|
||||||
AuthorFactory authorFactory, BlogFactory blogFactory,
|
|
||||||
ClientHelper clientHelper, Clock clock) {
|
ClientHelper clientHelper, Clock clock) {
|
||||||
this.cryptoComponent = cryptoComponent;
|
|
||||||
this.authorFactory = authorFactory;
|
this.authorFactory = authorFactory;
|
||||||
this.blogFactory = blogFactory;
|
this.blogFactory = blogFactory;
|
||||||
this.clientHelper = clientHelper;
|
this.clientHelper = clientHelper;
|
||||||
@@ -55,10 +50,7 @@ class FeedFactoryImpl implements FeedFactory {
|
|||||||
if (title == null) title = "RSS";
|
if (title == null) title = "RSS";
|
||||||
else title = StringUtils.truncateUtf8(title, MAX_AUTHOR_NAME_LENGTH);
|
else title = StringUtils.truncateUtf8(title, MAX_AUTHOR_NAME_LENGTH);
|
||||||
|
|
||||||
KeyPair keyPair = cryptoComponent.generateSignatureKeyPair();
|
LocalAuthor localAuthor = authorFactory.createLocalAuthor(title, false);
|
||||||
LocalAuthor localAuthor = authorFactory.createLocalAuthor(title,
|
|
||||||
keyPair.getPublic().getEncoded(),
|
|
||||||
keyPair.getPrivate().getEncoded());
|
|
||||||
Blog blog = blogFactory.createFeedBlog(localAuthor);
|
Blog blog = blogFactory.createFeedBlog(localAuthor);
|
||||||
long added = clock.currentTimeMillis();
|
long added = clock.currentTimeMillis();
|
||||||
|
|
||||||
@@ -80,9 +72,9 @@ class FeedFactoryImpl implements FeedFactory {
|
|||||||
BdfList authorList = d.getList(KEY_FEED_AUTHOR);
|
BdfList authorList = d.getList(KEY_FEED_AUTHOR);
|
||||||
byte[] privateKey = d.getRaw(KEY_FEED_PRIVATE_KEY);
|
byte[] privateKey = d.getRaw(KEY_FEED_PRIVATE_KEY);
|
||||||
Author author = clientHelper.parseAndValidateAuthor(authorList);
|
Author author = clientHelper.parseAndValidateAuthor(authorList);
|
||||||
LocalAuthor localAuthor = authorFactory.createLocalAuthor(
|
LocalAuthor localAuthor = new LocalAuthor(author.getId(),
|
||||||
author.getFormatVersion(), author.getName(),
|
author.getFormatVersion(), author.getName(),
|
||||||
author.getPublicKey(), privateKey);
|
author.getPublicKey(), privateKey, 0);
|
||||||
Blog blog = blogFactory.createFeedBlog(localAuthor);
|
Blog blog = blogFactory.createFeedBlog(localAuthor);
|
||||||
|
|
||||||
String desc = d.getOptionalString(KEY_FEED_DESC);
|
String desc = d.getOptionalString(KEY_FEED_DESC);
|
||||||
|
|||||||
@@ -5,8 +5,6 @@ import org.briarproject.bramble.api.client.ClientHelper;
|
|||||||
import org.briarproject.bramble.api.contact.Contact;
|
import org.briarproject.bramble.api.contact.Contact;
|
||||||
import org.briarproject.bramble.api.contact.ContactId;
|
import org.briarproject.bramble.api.contact.ContactId;
|
||||||
import org.briarproject.bramble.api.contact.ContactManager;
|
import org.briarproject.bramble.api.contact.ContactManager;
|
||||||
import org.briarproject.bramble.api.crypto.CryptoComponent;
|
|
||||||
import org.briarproject.bramble.api.crypto.KeyPair;
|
|
||||||
import org.briarproject.bramble.api.crypto.SecretKey;
|
import org.briarproject.bramble.api.crypto.SecretKey;
|
||||||
import org.briarproject.bramble.api.data.BdfDictionary;
|
import org.briarproject.bramble.api.data.BdfDictionary;
|
||||||
import org.briarproject.bramble.api.db.DatabaseComponent;
|
import org.briarproject.bramble.api.db.DatabaseComponent;
|
||||||
@@ -74,7 +72,6 @@ public class TestDataCreatorImpl implements TestDataCreator {
|
|||||||
private final ClientHelper clientHelper;
|
private final ClientHelper clientHelper;
|
||||||
private final MessageTracker messageTracker;
|
private final MessageTracker messageTracker;
|
||||||
private final BlogPostFactory blogPostFactory;
|
private final BlogPostFactory blogPostFactory;
|
||||||
private final CryptoComponent cryptoComponent;
|
|
||||||
|
|
||||||
private final DatabaseComponent db;
|
private final DatabaseComponent db;
|
||||||
private final IdentityManager identityManager;
|
private final IdentityManager identityManager;
|
||||||
@@ -94,9 +91,8 @@ public class TestDataCreatorImpl implements TestDataCreator {
|
|||||||
TestDataCreatorImpl(AuthorFactory authorFactory, Clock clock,
|
TestDataCreatorImpl(AuthorFactory authorFactory, Clock clock,
|
||||||
PrivateMessageFactory privateMessageFactory,
|
PrivateMessageFactory privateMessageFactory,
|
||||||
ClientHelper clientHelper, MessageTracker messageTracker,
|
ClientHelper clientHelper, MessageTracker messageTracker,
|
||||||
BlogPostFactory blogPostFactory, CryptoComponent cryptoComponent,
|
BlogPostFactory blogPostFactory, DatabaseComponent db,
|
||||||
DatabaseComponent db, IdentityManager identityManager,
|
IdentityManager identityManager, ContactManager contactManager,
|
||||||
ContactManager contactManager,
|
|
||||||
TransportPropertyManager transportPropertyManager,
|
TransportPropertyManager transportPropertyManager,
|
||||||
MessagingManager messagingManager, BlogManager blogManager,
|
MessagingManager messagingManager, BlogManager blogManager,
|
||||||
ForumManager forumManager, @IoExecutor Executor ioExecutor) {
|
ForumManager forumManager, @IoExecutor Executor ioExecutor) {
|
||||||
@@ -106,7 +102,6 @@ public class TestDataCreatorImpl implements TestDataCreator {
|
|||||||
this.clientHelper = clientHelper;
|
this.clientHelper = clientHelper;
|
||||||
this.messageTracker = messageTracker;
|
this.messageTracker = messageTracker;
|
||||||
this.blogPostFactory = blogPostFactory;
|
this.blogPostFactory = blogPostFactory;
|
||||||
this.cryptoComponent = cryptoComponent;
|
|
||||||
this.db = db;
|
this.db = db;
|
||||||
this.identityManager = identityManager;
|
this.identityManager = identityManager;
|
||||||
this.contactManager = contactManager;
|
this.contactManager = contactManager;
|
||||||
@@ -150,14 +145,14 @@ public class TestDataCreatorImpl implements TestDataCreator {
|
|||||||
List<Contact> contacts = new ArrayList<>(numContacts);
|
List<Contact> contacts = new ArrayList<>(numContacts);
|
||||||
LocalAuthor localAuthor = identityManager.getLocalAuthor();
|
LocalAuthor localAuthor = identityManager.getLocalAuthor();
|
||||||
for (int i = 0; i < numContacts; i++) {
|
for (int i = 0; i < numContacts; i++) {
|
||||||
LocalAuthor author = getRandomAuthor();
|
LocalAuthor remote = getRandomAuthor();
|
||||||
Contact contact = addContact(localAuthor.getId(), author);
|
Contact contact = addContact(localAuthor.getId(), remote);
|
||||||
contacts.add(contact);
|
contacts.add(contact);
|
||||||
}
|
}
|
||||||
return contacts;
|
return contacts;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Contact addContact(AuthorId localAuthorId, LocalAuthor author)
|
private Contact addContact(AuthorId localAuthorId, LocalAuthor remote)
|
||||||
throws DbException {
|
throws DbException {
|
||||||
|
|
||||||
// prepare to add contact
|
// prepare to add contact
|
||||||
@@ -173,7 +168,7 @@ public class TestDataCreatorImpl implements TestDataCreator {
|
|||||||
Transaction txn = db.startTransaction(false);
|
Transaction txn = db.startTransaction(false);
|
||||||
try {
|
try {
|
||||||
ContactId contactId = contactManager
|
ContactId contactId = contactManager
|
||||||
.addContact(txn, author, localAuthorId, secretKey,
|
.addContact(txn, remote, localAuthorId, secretKey,
|
||||||
timestamp, true, verified, true);
|
timestamp, true, verified, true);
|
||||||
if (random.nextBoolean()) {
|
if (random.nextBoolean()) {
|
||||||
contactManager
|
contactManager
|
||||||
@@ -187,24 +182,18 @@ public class TestDataCreatorImpl implements TestDataCreator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (LOG.isLoggable(INFO)) {
|
if (LOG.isLoggable(INFO)) {
|
||||||
LOG.info("Added contact " + author.getName());
|
LOG.info("Added contact " + remote.getName());
|
||||||
LOG.info("with transport properties: " + props.toString());
|
LOG.info("with transport properties: " + props.toString());
|
||||||
}
|
}
|
||||||
localAuthors.put(contact, author);
|
localAuthors.put(contact, remote);
|
||||||
return contact;
|
return contact;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Contact addContact(String name) throws DbException {
|
public Contact addContact(String name) throws DbException {
|
||||||
LocalAuthor localAuthor = identityManager.getLocalAuthor();
|
LocalAuthor localAuthor = identityManager.getLocalAuthor();
|
||||||
return addContact(localAuthor.getId(), getAuthor(name));
|
LocalAuthor remote = authorFactory.createLocalAuthor(name, false);
|
||||||
}
|
return addContact(localAuthor.getId(), remote);
|
||||||
|
|
||||||
private LocalAuthor getAuthor(String name) {
|
|
||||||
KeyPair keyPair = cryptoComponent.generateSignatureKeyPair();
|
|
||||||
byte[] publicKey = keyPair.getPublic().getEncoded();
|
|
||||||
byte[] privateKey = keyPair.getPrivate().getEncoded();
|
|
||||||
return authorFactory.createLocalAuthor(name, publicKey, privateKey);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getRandomAuthorName() {
|
private String getRandomAuthorName() {
|
||||||
@@ -213,7 +202,7 @@ public class TestDataCreatorImpl implements TestDataCreator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private LocalAuthor getRandomAuthor() {
|
private LocalAuthor getRandomAuthor() {
|
||||||
return getAuthor(getRandomAuthorName());
|
return authorFactory.createLocalAuthor(getRandomAuthorName(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private SecretKey getSecretKey() {
|
private SecretKey getSecretKey() {
|
||||||
|
|||||||
@@ -21,9 +21,7 @@ import java.util.Iterator;
|
|||||||
|
|
||||||
import static junit.framework.Assert.assertNotNull;
|
import static junit.framework.Assert.assertNotNull;
|
||||||
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH;
|
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH;
|
||||||
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_PUBLIC_KEY_LENGTH;
|
|
||||||
import static org.briarproject.bramble.api.identity.AuthorInfo.Status.NONE;
|
import static org.briarproject.bramble.api.identity.AuthorInfo.Status.NONE;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
|
||||||
import static org.briarproject.bramble.util.StringUtils.getRandomString;
|
import static org.briarproject.bramble.util.StringUtils.getRandomString;
|
||||||
import static org.briarproject.briar.api.blog.MessageType.COMMENT;
|
import static org.briarproject.briar.api.blog.MessageType.COMMENT;
|
||||||
import static org.briarproject.briar.api.blog.MessageType.POST;
|
import static org.briarproject.briar.api.blog.MessageType.POST;
|
||||||
@@ -51,9 +49,7 @@ public class BlogManagerIntegrationTest
|
|||||||
author0 = identityManager0.getLocalAuthor();
|
author0 = identityManager0.getLocalAuthor();
|
||||||
author1 = identityManager1.getLocalAuthor();
|
author1 = identityManager1.getLocalAuthor();
|
||||||
rssAuthor = c0.getAuthorFactory().createLocalAuthor(
|
rssAuthor = c0.getAuthorFactory().createLocalAuthor(
|
||||||
getRandomString(MAX_AUTHOR_NAME_LENGTH),
|
getRandomString(MAX_AUTHOR_NAME_LENGTH), false);
|
||||||
getRandomBytes(MAX_PUBLIC_KEY_LENGTH),
|
|
||||||
getRandomBytes(123));
|
|
||||||
|
|
||||||
blogManager0 = c0.getBlogManager();
|
blogManager0 = c0.getBlogManager();
|
||||||
blogManager1 = c1.getBlogManager();
|
blogManager1 = c1.getBlogManager();
|
||||||
|
|||||||
@@ -58,10 +58,8 @@ public class IntroductionCryptoIntegrationTest extends BrambleTestCase {
|
|||||||
crypto = new IntroductionCryptoImpl(cryptoComponent, clientHelper);
|
crypto = new IntroductionCryptoImpl(cryptoComponent, clientHelper);
|
||||||
|
|
||||||
introducer = getRealAuthor(authorFactory);
|
introducer = getRealAuthor(authorFactory);
|
||||||
LocalAuthor introducee1 =
|
LocalAuthor introducee1 = getRealLocalAuthor(authorFactory);
|
||||||
getRealLocalAuthor(cryptoComponent, authorFactory);
|
LocalAuthor introducee2 = getRealLocalAuthor(authorFactory);
|
||||||
LocalAuthor introducee2 =
|
|
||||||
getRealLocalAuthor(cryptoComponent, authorFactory);
|
|
||||||
boolean isAlice =
|
boolean isAlice =
|
||||||
crypto.isAlice(introducee1.getId(), introducee2.getId());
|
crypto.isAlice(introducee1.getId(), introducee2.getId());
|
||||||
alice = isAlice ? introducee1 : introducee2;
|
alice = isAlice ? introducee1 : introducee2;
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package org.briarproject.briar.messaging;
|
|||||||
|
|
||||||
import org.briarproject.bramble.api.UniqueId;
|
import org.briarproject.bramble.api.UniqueId;
|
||||||
import org.briarproject.bramble.api.crypto.CryptoComponent;
|
import org.briarproject.bramble.api.crypto.CryptoComponent;
|
||||||
import org.briarproject.bramble.api.crypto.PrivateKey;
|
|
||||||
import org.briarproject.bramble.api.identity.AuthorFactory;
|
import org.briarproject.bramble.api.identity.AuthorFactory;
|
||||||
import org.briarproject.bramble.api.identity.LocalAuthor;
|
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||||
import org.briarproject.bramble.api.sync.GroupId;
|
import org.briarproject.bramble.api.sync.GroupId;
|
||||||
@@ -70,12 +69,8 @@ public class MessageSizeIntegrationTest extends BriarTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void testForumPostFitsIntoRecord() throws Exception {
|
public void testForumPostFitsIntoRecord() throws Exception {
|
||||||
// Create a maximum-length author
|
// Create a maximum-length author
|
||||||
int formatVersion = Integer.MAX_VALUE;
|
|
||||||
String authorName = getRandomString(MAX_AUTHOR_NAME_LENGTH);
|
String authorName = getRandomString(MAX_AUTHOR_NAME_LENGTH);
|
||||||
byte[] authorPublic = new byte[MAX_PUBLIC_KEY_LENGTH];
|
LocalAuthor author = authorFactory.createLocalAuthor(authorName, false);
|
||||||
PrivateKey privateKey = crypto.generateSignatureKeyPair().getPrivate();
|
|
||||||
LocalAuthor author = authorFactory.createLocalAuthor(formatVersion,
|
|
||||||
authorName, authorPublic, privateKey.getEncoded());
|
|
||||||
// Create a maximum-length forum post
|
// Create a maximum-length forum post
|
||||||
GroupId groupId = new GroupId(getRandomId());
|
GroupId groupId = new GroupId(getRandomId());
|
||||||
long timestamp = Long.MAX_VALUE;
|
long timestamp = Long.MAX_VALUE;
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package org.briarproject.briar.test;
|
package org.briarproject.briar.test;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.crypto.CryptoComponent;
|
|
||||||
import org.briarproject.bramble.api.crypto.KeyPair;
|
|
||||||
import org.briarproject.bramble.api.db.DbException;
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
import org.briarproject.bramble.api.identity.Author;
|
import org.briarproject.bramble.api.identity.Author;
|
||||||
import org.briarproject.bramble.api.identity.AuthorFactory;
|
import org.briarproject.bramble.api.identity.AuthorFactory;
|
||||||
@@ -10,6 +8,7 @@ import org.briarproject.bramble.api.sync.GroupId;
|
|||||||
import org.briarproject.briar.api.client.MessageTracker;
|
import org.briarproject.briar.api.client.MessageTracker;
|
||||||
import org.briarproject.briar.api.client.MessageTracker.GroupCount;
|
import org.briarproject.briar.api.client.MessageTracker.GroupCount;
|
||||||
|
|
||||||
|
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH;
|
||||||
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_PUBLIC_KEY_LENGTH;
|
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_PUBLIC_KEY_LENGTH;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
||||||
import static org.briarproject.bramble.util.StringUtils.getRandomString;
|
import static org.briarproject.bramble.util.StringUtils.getRandomString;
|
||||||
@@ -27,23 +26,21 @@ public class BriarTestUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void assertGroupCount(MessageTracker tracker, GroupId g,
|
public static void assertGroupCount(MessageTracker tracker, GroupId g,
|
||||||
long msgCount, long unreadCount) throws DbException {
|
long msgCount, long unreadCount) throws DbException {
|
||||||
GroupCount c1 = tracker.getGroupCount(g);
|
GroupCount c1 = tracker.getGroupCount(g);
|
||||||
assertEquals(msgCount, c1.getMsgCount());
|
assertEquals(msgCount, c1.getMsgCount());
|
||||||
assertEquals(unreadCount, c1.getUnreadCount());
|
assertEquals(unreadCount, c1.getUnreadCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Author getRealAuthor(AuthorFactory authorFactory) {
|
public static Author getRealAuthor(AuthorFactory authorFactory) {
|
||||||
return authorFactory.createAuthor(getRandomString(5),
|
String name = getRandomString(MAX_AUTHOR_NAME_LENGTH);
|
||||||
getRandomBytes(MAX_PUBLIC_KEY_LENGTH));
|
byte[] publicKey = getRandomBytes(MAX_PUBLIC_KEY_LENGTH);
|
||||||
|
return authorFactory.createAuthor(name, publicKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static LocalAuthor getRealLocalAuthor(
|
public static LocalAuthor getRealLocalAuthor(AuthorFactory authorFactory) {
|
||||||
CryptoComponent cryptoComponent, AuthorFactory authorFactory) {
|
String name = getRandomString(MAX_AUTHOR_NAME_LENGTH);
|
||||||
KeyPair keyPair = cryptoComponent.generateSignatureKeyPair();
|
return authorFactory.createLocalAuthor(name, false);
|
||||||
return authorFactory.createLocalAuthor(getRandomString(5),
|
|
||||||
keyPair.getPublic().getEncoded(),
|
|
||||||
keyPair.getPrivate().getEncoded());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user