Reuse TransportCrypto#isAlice().

This commit is contained in:
akwizgran
2019-06-04 12:21:17 +01:00
parent d939fe80bd
commit 34a5b69100
3 changed files with 5 additions and 13 deletions

View File

@@ -10,9 +10,6 @@ import java.security.GeneralSecurityException;
@NotNullByDefault @NotNullByDefault
interface HandshakeCrypto { interface HandshakeCrypto {
boolean isLocalPeerAlice(PublicKey theirStaticPublicKey,
KeyPair ourStaticKeyPair);
KeyPair generateEphemeralKeyPair(); KeyPair generateEphemeralKeyPair();
/** /**

View File

@@ -11,7 +11,6 @@ import java.security.GeneralSecurityException;
import javax.annotation.concurrent.Immutable; import javax.annotation.concurrent.Immutable;
import javax.inject.Inject; import javax.inject.Inject;
import static org.briarproject.bramble.api.Bytes.compare;
import static org.briarproject.bramble.contact.HandshakeConstants.ALICE_PROOF_LABEL; import static org.briarproject.bramble.contact.HandshakeConstants.ALICE_PROOF_LABEL;
import static org.briarproject.bramble.contact.HandshakeConstants.BOB_PROOF_LABEL; import static org.briarproject.bramble.contact.HandshakeConstants.BOB_PROOF_LABEL;
import static org.briarproject.bramble.contact.HandshakeConstants.MASTER_KEY_LABEL; import static org.briarproject.bramble.contact.HandshakeConstants.MASTER_KEY_LABEL;
@@ -27,14 +26,6 @@ class HandshakeCryptoImpl implements HandshakeCrypto {
this.crypto = crypto; this.crypto = crypto;
} }
@Override
public boolean isLocalPeerAlice(PublicKey theirStaticPublicKey,
KeyPair ourStaticKeyPair) {
byte[] ours = ourStaticKeyPair.getPublic().getEncoded();
byte[] theirs = theirStaticPublicKey.getEncoded();
return compare(ours, theirs) < 0;
}
@Override @Override
public KeyPair generateEphemeralKeyPair() { public KeyPair generateEphemeralKeyPair() {
return crypto.generateAgreementKeyPair(); return crypto.generateAgreementKeyPair();

View File

@@ -11,6 +11,7 @@ import org.briarproject.bramble.api.crypto.AgreementPublicKey;
import org.briarproject.bramble.api.crypto.KeyPair; import org.briarproject.bramble.api.crypto.KeyPair;
import org.briarproject.bramble.api.crypto.PublicKey; import org.briarproject.bramble.api.crypto.PublicKey;
import org.briarproject.bramble.api.crypto.SecretKey; import org.briarproject.bramble.api.crypto.SecretKey;
import org.briarproject.bramble.api.crypto.TransportCrypto;
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.TransactionManager; import org.briarproject.bramble.api.db.TransactionManager;
@@ -54,6 +55,7 @@ class HandshakeManagerImpl implements HandshakeManager {
private final TransactionManager db; private final TransactionManager db;
private final IdentityManager identityManager; private final IdentityManager identityManager;
private final ContactManager contactManager; private final ContactManager contactManager;
private final TransportCrypto transportCrypto;
private final HandshakeCrypto handshakeCrypto; private final HandshakeCrypto handshakeCrypto;
private final RecordReaderFactory recordReaderFactory; private final RecordReaderFactory recordReaderFactory;
private final RecordWriterFactory recordWriterFactory; private final RecordWriterFactory recordWriterFactory;
@@ -62,12 +64,14 @@ class HandshakeManagerImpl implements HandshakeManager {
HandshakeManagerImpl(DatabaseComponent db, HandshakeManagerImpl(DatabaseComponent db,
IdentityManager identityManager, IdentityManager identityManager,
ContactManager contactManager, ContactManager contactManager,
TransportCrypto transportCrypto,
HandshakeCrypto handshakeCrypto, HandshakeCrypto handshakeCrypto,
RecordReaderFactory recordReaderFactory, RecordReaderFactory recordReaderFactory,
RecordWriterFactory recordWriterFactory) { RecordWriterFactory recordWriterFactory) {
this.db = db; this.db = db;
this.identityManager = identityManager; this.identityManager = identityManager;
this.contactManager = contactManager; this.contactManager = contactManager;
this.transportCrypto = transportCrypto;
this.handshakeCrypto = handshakeCrypto; this.handshakeCrypto = handshakeCrypto;
this.recordReaderFactory = recordReaderFactory; this.recordReaderFactory = recordReaderFactory;
this.recordWriterFactory = recordWriterFactory; this.recordWriterFactory = recordWriterFactory;
@@ -84,7 +88,7 @@ class HandshakeManagerImpl implements HandshakeManager {
}); });
PublicKey theirStaticPublicKey = keys.getFirst(); PublicKey theirStaticPublicKey = keys.getFirst();
KeyPair ourStaticKeyPair = keys.getSecond(); KeyPair ourStaticKeyPair = keys.getSecond();
boolean alice = handshakeCrypto.isLocalPeerAlice(theirStaticPublicKey, boolean alice = transportCrypto.isAlice(theirStaticPublicKey,
ourStaticKeyPair); ourStaticKeyPair);
RecordReader recordReader = recordReaderFactory.createRecordReader(in); RecordReader recordReader = recordReaderFactory.createRecordReader(in);
RecordWriter recordWriter = recordWriterFactory RecordWriter recordWriter = recordWriterFactory