mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-18 05:39:53 +01:00
Generate handshake keys when creating local author.
This commit is contained in:
@@ -4,8 +4,6 @@ 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.CryptoComponent;
|
||||
import org.briarproject.bramble.api.crypto.KeyPair;
|
||||
import org.briarproject.bramble.api.data.BdfDictionary;
|
||||
import org.briarproject.bramble.api.data.BdfEntry;
|
||||
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 {
|
||||
|
||||
private final CryptoComponent cryptoComponent;
|
||||
private final AuthorFactory authorFactory;
|
||||
private final BlogFactory blogFactory;
|
||||
private final ClientHelper clientHelper;
|
||||
private final Clock clock;
|
||||
|
||||
@Inject
|
||||
FeedFactoryImpl(CryptoComponent cryptoComponent,
|
||||
AuthorFactory authorFactory, BlogFactory blogFactory,
|
||||
FeedFactoryImpl(AuthorFactory authorFactory, BlogFactory blogFactory,
|
||||
ClientHelper clientHelper, Clock clock) {
|
||||
this.cryptoComponent = cryptoComponent;
|
||||
this.authorFactory = authorFactory;
|
||||
this.blogFactory = blogFactory;
|
||||
this.clientHelper = clientHelper;
|
||||
@@ -55,10 +50,7 @@ class FeedFactoryImpl implements FeedFactory {
|
||||
if (title == null) title = "RSS";
|
||||
else title = StringUtils.truncateUtf8(title, MAX_AUTHOR_NAME_LENGTH);
|
||||
|
||||
KeyPair keyPair = cryptoComponent.generateSignatureKeyPair();
|
||||
LocalAuthor localAuthor = authorFactory.createLocalAuthor(title,
|
||||
keyPair.getPublic().getEncoded(),
|
||||
keyPair.getPrivate().getEncoded());
|
||||
LocalAuthor localAuthor = authorFactory.createLocalAuthor(title, false);
|
||||
Blog blog = blogFactory.createFeedBlog(localAuthor);
|
||||
long added = clock.currentTimeMillis();
|
||||
|
||||
@@ -80,9 +72,9 @@ class FeedFactoryImpl implements FeedFactory {
|
||||
BdfList authorList = d.getList(KEY_FEED_AUTHOR);
|
||||
byte[] privateKey = d.getRaw(KEY_FEED_PRIVATE_KEY);
|
||||
Author author = clientHelper.parseAndValidateAuthor(authorList);
|
||||
LocalAuthor localAuthor = authorFactory.createLocalAuthor(
|
||||
LocalAuthor localAuthor = new LocalAuthor(author.getId(),
|
||||
author.getFormatVersion(), author.getName(),
|
||||
author.getPublicKey(), privateKey);
|
||||
author.getPublicKey(), privateKey, 0);
|
||||
Blog blog = blogFactory.createFeedBlog(localAuthor);
|
||||
|
||||
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.ContactId;
|
||||
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.data.BdfDictionary;
|
||||
import org.briarproject.bramble.api.db.DatabaseComponent;
|
||||
@@ -74,7 +72,6 @@ public class TestDataCreatorImpl implements TestDataCreator {
|
||||
private final ClientHelper clientHelper;
|
||||
private final MessageTracker messageTracker;
|
||||
private final BlogPostFactory blogPostFactory;
|
||||
private final CryptoComponent cryptoComponent;
|
||||
|
||||
private final DatabaseComponent db;
|
||||
private final IdentityManager identityManager;
|
||||
@@ -94,9 +91,8 @@ public class TestDataCreatorImpl implements TestDataCreator {
|
||||
TestDataCreatorImpl(AuthorFactory authorFactory, Clock clock,
|
||||
PrivateMessageFactory privateMessageFactory,
|
||||
ClientHelper clientHelper, MessageTracker messageTracker,
|
||||
BlogPostFactory blogPostFactory, CryptoComponent cryptoComponent,
|
||||
DatabaseComponent db, IdentityManager identityManager,
|
||||
ContactManager contactManager,
|
||||
BlogPostFactory blogPostFactory, DatabaseComponent db,
|
||||
IdentityManager identityManager, ContactManager contactManager,
|
||||
TransportPropertyManager transportPropertyManager,
|
||||
MessagingManager messagingManager, BlogManager blogManager,
|
||||
ForumManager forumManager, @IoExecutor Executor ioExecutor) {
|
||||
@@ -106,7 +102,6 @@ public class TestDataCreatorImpl implements TestDataCreator {
|
||||
this.clientHelper = clientHelper;
|
||||
this.messageTracker = messageTracker;
|
||||
this.blogPostFactory = blogPostFactory;
|
||||
this.cryptoComponent = cryptoComponent;
|
||||
this.db = db;
|
||||
this.identityManager = identityManager;
|
||||
this.contactManager = contactManager;
|
||||
@@ -150,14 +145,14 @@ public class TestDataCreatorImpl implements TestDataCreator {
|
||||
List<Contact> contacts = new ArrayList<>(numContacts);
|
||||
LocalAuthor localAuthor = identityManager.getLocalAuthor();
|
||||
for (int i = 0; i < numContacts; i++) {
|
||||
LocalAuthor author = getRandomAuthor();
|
||||
Contact contact = addContact(localAuthor.getId(), author);
|
||||
LocalAuthor remote = getRandomAuthor();
|
||||
Contact contact = addContact(localAuthor.getId(), remote);
|
||||
contacts.add(contact);
|
||||
}
|
||||
return contacts;
|
||||
}
|
||||
|
||||
private Contact addContact(AuthorId localAuthorId, LocalAuthor author)
|
||||
private Contact addContact(AuthorId localAuthorId, LocalAuthor remote)
|
||||
throws DbException {
|
||||
|
||||
// prepare to add contact
|
||||
@@ -173,7 +168,7 @@ public class TestDataCreatorImpl implements TestDataCreator {
|
||||
Transaction txn = db.startTransaction(false);
|
||||
try {
|
||||
ContactId contactId = contactManager
|
||||
.addContact(txn, author, localAuthorId, secretKey,
|
||||
.addContact(txn, remote, localAuthorId, secretKey,
|
||||
timestamp, true, verified, true);
|
||||
if (random.nextBoolean()) {
|
||||
contactManager
|
||||
@@ -187,24 +182,18 @@ public class TestDataCreatorImpl implements TestDataCreator {
|
||||
}
|
||||
|
||||
if (LOG.isLoggable(INFO)) {
|
||||
LOG.info("Added contact " + author.getName());
|
||||
LOG.info("Added contact " + remote.getName());
|
||||
LOG.info("with transport properties: " + props.toString());
|
||||
}
|
||||
localAuthors.put(contact, author);
|
||||
localAuthors.put(contact, remote);
|
||||
return contact;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Contact addContact(String name) throws DbException {
|
||||
LocalAuthor localAuthor = identityManager.getLocalAuthor();
|
||||
return addContact(localAuthor.getId(), getAuthor(name));
|
||||
}
|
||||
|
||||
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);
|
||||
LocalAuthor remote = authorFactory.createLocalAuthor(name, false);
|
||||
return addContact(localAuthor.getId(), remote);
|
||||
}
|
||||
|
||||
private String getRandomAuthorName() {
|
||||
@@ -213,7 +202,7 @@ public class TestDataCreatorImpl implements TestDataCreator {
|
||||
}
|
||||
|
||||
private LocalAuthor getRandomAuthor() {
|
||||
return getAuthor(getRandomAuthorName());
|
||||
return authorFactory.createLocalAuthor(getRandomAuthorName(), false);
|
||||
}
|
||||
|
||||
private SecretKey getSecretKey() {
|
||||
|
||||
@@ -21,9 +21,7 @@ import java.util.Iterator;
|
||||
|
||||
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_PUBLIC_KEY_LENGTH;
|
||||
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.briar.api.blog.MessageType.COMMENT;
|
||||
import static org.briarproject.briar.api.blog.MessageType.POST;
|
||||
@@ -51,9 +49,7 @@ public class BlogManagerIntegrationTest
|
||||
author0 = identityManager0.getLocalAuthor();
|
||||
author1 = identityManager1.getLocalAuthor();
|
||||
rssAuthor = c0.getAuthorFactory().createLocalAuthor(
|
||||
getRandomString(MAX_AUTHOR_NAME_LENGTH),
|
||||
getRandomBytes(MAX_PUBLIC_KEY_LENGTH),
|
||||
getRandomBytes(123));
|
||||
getRandomString(MAX_AUTHOR_NAME_LENGTH), false);
|
||||
|
||||
blogManager0 = c0.getBlogManager();
|
||||
blogManager1 = c1.getBlogManager();
|
||||
|
||||
@@ -58,10 +58,8 @@ public class IntroductionCryptoIntegrationTest extends BrambleTestCase {
|
||||
crypto = new IntroductionCryptoImpl(cryptoComponent, clientHelper);
|
||||
|
||||
introducer = getRealAuthor(authorFactory);
|
||||
LocalAuthor introducee1 =
|
||||
getRealLocalAuthor(cryptoComponent, authorFactory);
|
||||
LocalAuthor introducee2 =
|
||||
getRealLocalAuthor(cryptoComponent, authorFactory);
|
||||
LocalAuthor introducee1 = getRealLocalAuthor(authorFactory);
|
||||
LocalAuthor introducee2 = getRealLocalAuthor(authorFactory);
|
||||
boolean isAlice =
|
||||
crypto.isAlice(introducee1.getId(), introducee2.getId());
|
||||
alice = isAlice ? introducee1 : introducee2;
|
||||
|
||||
@@ -2,7 +2,6 @@ package org.briarproject.briar.messaging;
|
||||
|
||||
import org.briarproject.bramble.api.UniqueId;
|
||||
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.LocalAuthor;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
@@ -70,12 +69,8 @@ public class MessageSizeIntegrationTest extends BriarTestCase {
|
||||
@Test
|
||||
public void testForumPostFitsIntoRecord() throws Exception {
|
||||
// Create a maximum-length author
|
||||
int formatVersion = Integer.MAX_VALUE;
|
||||
String authorName = getRandomString(MAX_AUTHOR_NAME_LENGTH);
|
||||
byte[] authorPublic = new byte[MAX_PUBLIC_KEY_LENGTH];
|
||||
PrivateKey privateKey = crypto.generateSignatureKeyPair().getPrivate();
|
||||
LocalAuthor author = authorFactory.createLocalAuthor(formatVersion,
|
||||
authorName, authorPublic, privateKey.getEncoded());
|
||||
LocalAuthor author = authorFactory.createLocalAuthor(authorName, false);
|
||||
// Create a maximum-length forum post
|
||||
GroupId groupId = new GroupId(getRandomId());
|
||||
long timestamp = Long.MAX_VALUE;
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
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.identity.Author;
|
||||
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.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.test.TestUtils.getRandomBytes;
|
||||
import static org.briarproject.bramble.util.StringUtils.getRandomString;
|
||||
@@ -27,23 +26,21 @@ public class BriarTestUtils {
|
||||
}
|
||||
|
||||
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);
|
||||
assertEquals(msgCount, c1.getMsgCount());
|
||||
assertEquals(unreadCount, c1.getUnreadCount());
|
||||
}
|
||||
|
||||
public static Author getRealAuthor(AuthorFactory authorFactory) {
|
||||
return authorFactory.createAuthor(getRandomString(5),
|
||||
getRandomBytes(MAX_PUBLIC_KEY_LENGTH));
|
||||
String name = getRandomString(MAX_AUTHOR_NAME_LENGTH);
|
||||
byte[] publicKey = getRandomBytes(MAX_PUBLIC_KEY_LENGTH);
|
||||
return authorFactory.createAuthor(name, publicKey);
|
||||
}
|
||||
|
||||
public static LocalAuthor getRealLocalAuthor(
|
||||
CryptoComponent cryptoComponent, AuthorFactory authorFactory) {
|
||||
KeyPair keyPair = cryptoComponent.generateSignatureKeyPair();
|
||||
return authorFactory.createLocalAuthor(getRandomString(5),
|
||||
keyPair.getPublic().getEncoded(),
|
||||
keyPair.getPrivate().getEncoded());
|
||||
public static LocalAuthor getRealLocalAuthor(AuthorFactory authorFactory) {
|
||||
String name = getRandomString(MAX_AUTHOR_NAME_LENGTH);
|
||||
return authorFactory.createLocalAuthor(name, false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user