mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-17 13:19:52 +01:00
Generate handshake keys when creating local author.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package org.briarproject.bramble.identity;
|
||||
|
||||
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.AuthorFactory;
|
||||
import org.briarproject.bramble.api.identity.AuthorId;
|
||||
@@ -43,17 +44,21 @@ class AuthorFactoryImpl implements AuthorFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalAuthor createLocalAuthor(String name, byte[] publicKey,
|
||||
byte[] privateKey) {
|
||||
return createLocalAuthor(FORMAT_VERSION, name, publicKey, privateKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalAuthor createLocalAuthor(int formatVersion, String name,
|
||||
byte[] publicKey, byte[] privateKey) {
|
||||
AuthorId id = getId(formatVersion, name, publicKey);
|
||||
return new LocalAuthor(id, formatVersion, name, publicKey, privateKey,
|
||||
clock.currentTimeMillis());
|
||||
public LocalAuthor createLocalAuthor(String name, boolean handshakeKeys) {
|
||||
KeyPair signatureKeyPair = crypto.generateSignatureKeyPair();
|
||||
byte[] sigPub = signatureKeyPair.getPublic().getEncoded();
|
||||
byte[] sigPriv = signatureKeyPair.getPrivate().getEncoded();
|
||||
AuthorId id = getId(FORMAT_VERSION, name, sigPub);
|
||||
if (handshakeKeys) {
|
||||
KeyPair handshakeKeyPair = crypto.generateAgreementKeyPair();
|
||||
byte[] handPub = handshakeKeyPair.getPublic().getEncoded();
|
||||
byte[] handPriv = handshakeKeyPair.getPrivate().getEncoded();
|
||||
return new LocalAuthor(id, FORMAT_VERSION, name, sigPub, sigPriv,
|
||||
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) {
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
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.DbException;
|
||||
import org.briarproject.bramble.api.db.Transaction;
|
||||
@@ -27,7 +25,6 @@ class IdentityManagerImpl implements IdentityManager {
|
||||
Logger.getLogger(IdentityManagerImpl.class.getName());
|
||||
|
||||
private final DatabaseComponent db;
|
||||
private final CryptoComponent crypto;
|
||||
private final AuthorFactory authorFactory;
|
||||
|
||||
// The local author is immutable so we can cache it
|
||||
@@ -35,21 +32,15 @@ class IdentityManagerImpl implements IdentityManager {
|
||||
private volatile LocalAuthor cachedAuthor;
|
||||
|
||||
@Inject
|
||||
IdentityManagerImpl(DatabaseComponent db, CryptoComponent crypto,
|
||||
AuthorFactory authorFactory) {
|
||||
IdentityManagerImpl(DatabaseComponent db, AuthorFactory authorFactory) {
|
||||
this.db = db;
|
||||
this.crypto = crypto;
|
||||
this.authorFactory = authorFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalAuthor createLocalAuthor(String name) {
|
||||
long start = now();
|
||||
KeyPair keyPair = crypto.generateSignatureKeyPair();
|
||||
byte[] publicKey = keyPair.getPublic().getEncoded();
|
||||
byte[] privateKey = keyPair.getPrivate().getEncoded();
|
||||
LocalAuthor localAuthor = authorFactory.createLocalAuthor(name,
|
||||
publicKey, privateKey);
|
||||
LocalAuthor localAuthor = authorFactory.createLocalAuthor(name, true);
|
||||
logDuration(LOG, "Creating local author", start);
|
||||
return localAuthor;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user