mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-19 22:29:53 +01:00
Derive rendezvous key from static master key.
This commit is contained in:
@@ -21,7 +21,7 @@ public interface RendezvousConstants {
|
|||||||
long POLLING_INTERVAL_MS = MINUTES.toMillis(1);
|
long POLLING_INTERVAL_MS = MINUTES.toMillis(1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Label for deriving the rendezvous key from the handshake key pairs.
|
* Label for deriving the rendezvous key from the static master key.
|
||||||
*/
|
*/
|
||||||
String RENDEZVOUS_KEY_LABEL =
|
String RENDEZVOUS_KEY_LABEL =
|
||||||
"org.briarproject.bramble.rendezvous/RENDEZVOUS_KEY";
|
"org.briarproject.bramble.rendezvous/RENDEZVOUS_KEY";
|
||||||
|
|||||||
@@ -1,18 +1,13 @@
|
|||||||
package org.briarproject.bramble.api.rendezvous;
|
package org.briarproject.bramble.api.rendezvous;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.crypto.KeyPair;
|
|
||||||
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.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.bramble.api.plugin.TransportId;
|
import org.briarproject.bramble.api.plugin.TransportId;
|
||||||
|
|
||||||
import java.security.GeneralSecurityException;
|
|
||||||
|
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
public interface RendezvousCrypto {
|
public interface RendezvousCrypto {
|
||||||
|
|
||||||
SecretKey deriveRendezvousKey(PublicKey theirPublicKey, KeyPair ourKeyPair)
|
SecretKey deriveRendezvousKey(SecretKey staticMasterKey);
|
||||||
throws GeneralSecurityException;
|
|
||||||
|
|
||||||
KeyMaterialSource createKeyMaterialSource(SecretKey rendezvousKey,
|
KeyMaterialSource createKeyMaterialSource(SecretKey rendezvousKey,
|
||||||
TransportId t);
|
TransportId t);
|
||||||
|
|||||||
@@ -1,23 +1,17 @@
|
|||||||
package org.briarproject.bramble.rendezvous;
|
package org.briarproject.bramble.rendezvous;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.Bytes;
|
|
||||||
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.crypto.PublicKey;
|
|
||||||
import org.briarproject.bramble.api.crypto.SecretKey;
|
import org.briarproject.bramble.api.crypto.SecretKey;
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.bramble.api.plugin.TransportId;
|
import org.briarproject.bramble.api.plugin.TransportId;
|
||||||
import org.briarproject.bramble.api.rendezvous.KeyMaterialSource;
|
import org.briarproject.bramble.api.rendezvous.KeyMaterialSource;
|
||||||
import org.briarproject.bramble.api.rendezvous.RendezvousCrypto;
|
import org.briarproject.bramble.api.rendezvous.RendezvousCrypto;
|
||||||
|
|
||||||
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.rendezvous.RendezvousConstants.KEY_MATERIAL_LABEL;
|
import static org.briarproject.bramble.api.rendezvous.RendezvousConstants.KEY_MATERIAL_LABEL;
|
||||||
import static org.briarproject.bramble.api.rendezvous.RendezvousConstants.RENDEZVOUS_KEY_LABEL;
|
import static org.briarproject.bramble.api.rendezvous.RendezvousConstants.RENDEZVOUS_KEY_LABEL;
|
||||||
import static org.briarproject.bramble.api.rendezvous.RendezvousConstants.PROTOCOL_VERSION;
|
|
||||||
import static org.briarproject.bramble.util.StringUtils.toUtf8;
|
import static org.briarproject.bramble.util.StringUtils.toUtf8;
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
@@ -32,19 +26,8 @@ class RendezvousCryptoImpl implements RendezvousCrypto {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SecretKey deriveRendezvousKey(PublicKey theirPublicKey,
|
public SecretKey deriveRendezvousKey(SecretKey staticMasterKey) {
|
||||||
KeyPair ourKeyPair) throws GeneralSecurityException {
|
return crypto.deriveKey(RENDEZVOUS_KEY_LABEL, staticMasterKey);
|
||||||
byte[] ourPublicKeyBytes = ourKeyPair.getPublic().getEncoded();
|
|
||||||
byte[] theirPublicKeyBytes = theirPublicKey.getEncoded();
|
|
||||||
boolean alice = new Bytes(ourPublicKeyBytes).compareTo(
|
|
||||||
new Bytes(theirPublicKeyBytes)) < 0;
|
|
||||||
byte[][] inputs = {
|
|
||||||
new byte[] {PROTOCOL_VERSION},
|
|
||||||
alice ? ourPublicKeyBytes : theirPublicKeyBytes,
|
|
||||||
alice ? theirPublicKeyBytes : ourPublicKeyBytes
|
|
||||||
};
|
|
||||||
return crypto.deriveSharedSecret(RENDEZVOUS_KEY_LABEL, theirPublicKey,
|
|
||||||
ourKeyPair, inputs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import org.briarproject.bramble.api.contact.event.PendingContactAddedEvent;
|
|||||||
import org.briarproject.bramble.api.contact.event.PendingContactRemovedEvent;
|
import org.briarproject.bramble.api.contact.event.PendingContactRemovedEvent;
|
||||||
import org.briarproject.bramble.api.crypto.KeyPair;
|
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.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.event.Event;
|
import org.briarproject.bramble.api.event.Event;
|
||||||
@@ -71,6 +72,7 @@ class RendezvousPollerImpl implements RendezvousPoller, Service, EventListener {
|
|||||||
private final ScheduledExecutorService scheduler;
|
private final ScheduledExecutorService scheduler;
|
||||||
private final DatabaseComponent db;
|
private final DatabaseComponent db;
|
||||||
private final IdentityManager identityManager;
|
private final IdentityManager identityManager;
|
||||||
|
private final TransportCrypto transportCrypto;
|
||||||
private final RendezvousCrypto rendezvousCrypto;
|
private final RendezvousCrypto rendezvousCrypto;
|
||||||
private final PluginManager pluginManager;
|
private final PluginManager pluginManager;
|
||||||
private final ConnectionManager connectionManager;
|
private final ConnectionManager connectionManager;
|
||||||
@@ -91,6 +93,7 @@ class RendezvousPollerImpl implements RendezvousPoller, Service, EventListener {
|
|||||||
@Scheduler ScheduledExecutorService scheduler,
|
@Scheduler ScheduledExecutorService scheduler,
|
||||||
DatabaseComponent db,
|
DatabaseComponent db,
|
||||||
IdentityManager identityManager,
|
IdentityManager identityManager,
|
||||||
|
TransportCrypto transportCrypto,
|
||||||
RendezvousCrypto rendezvousCrypto,
|
RendezvousCrypto rendezvousCrypto,
|
||||||
PluginManager pluginManager,
|
PluginManager pluginManager,
|
||||||
ConnectionManager connectionManager,
|
ConnectionManager connectionManager,
|
||||||
@@ -99,6 +102,7 @@ class RendezvousPollerImpl implements RendezvousPoller, Service, EventListener {
|
|||||||
this.scheduler = scheduler;
|
this.scheduler = scheduler;
|
||||||
this.db = db;
|
this.db = db;
|
||||||
this.identityManager = identityManager;
|
this.identityManager = identityManager;
|
||||||
|
this.transportCrypto = transportCrypto;
|
||||||
this.rendezvousCrypto = rendezvousCrypto;
|
this.rendezvousCrypto = rendezvousCrypto;
|
||||||
this.pluginManager = pluginManager;
|
this.pluginManager = pluginManager;
|
||||||
this.connectionManager = connectionManager;
|
this.connectionManager = connectionManager;
|
||||||
@@ -145,8 +149,10 @@ class RendezvousPollerImpl implements RendezvousPoller, Service, EventListener {
|
|||||||
handshakeKeyPair = db.transactionWithResult(true,
|
handshakeKeyPair = db.transactionWithResult(true,
|
||||||
identityManager::getHandshakeKeys);
|
identityManager::getHandshakeKeys);
|
||||||
}
|
}
|
||||||
|
SecretKey staticMasterKey = transportCrypto
|
||||||
|
.deriveStaticMasterKey(p.getPublicKey(), handshakeKeyPair);
|
||||||
SecretKey rendezvousKey = rendezvousCrypto
|
SecretKey rendezvousKey = rendezvousCrypto
|
||||||
.deriveRendezvousKey(p.getPublicKey(), handshakeKeyPair);
|
.deriveRendezvousKey(staticMasterKey);
|
||||||
requireNull(rendezvousKeys.put(p.getId(), rendezvousKey));
|
requireNull(rendezvousKeys.put(p.getId(), rendezvousKey));
|
||||||
for (PluginState ps : pluginStates.values()) {
|
for (PluginState ps : pluginStates.values()) {
|
||||||
RendezvousEndpoint endpoint =
|
RendezvousEndpoint endpoint =
|
||||||
|
|||||||
Reference in New Issue
Block a user