mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-15 20:29:52 +01:00
Add initial API for rendezvous plugins.
This commit is contained in:
@@ -15,6 +15,7 @@ import org.briarproject.bramble.plugin.PluginModule;
|
||||
import org.briarproject.bramble.properties.PropertiesModule;
|
||||
import org.briarproject.bramble.record.RecordModule;
|
||||
import org.briarproject.bramble.reliability.ReliabilityModule;
|
||||
import org.briarproject.bramble.rendezvous.RendezvousModule;
|
||||
import org.briarproject.bramble.reporting.ReportingModule;
|
||||
import org.briarproject.bramble.settings.SettingsModule;
|
||||
import org.briarproject.bramble.socks.SocksModule;
|
||||
@@ -42,6 +43,7 @@ import dagger.Module;
|
||||
PropertiesModule.class,
|
||||
RecordModule.class,
|
||||
ReliabilityModule.class,
|
||||
RendezvousModule.class,
|
||||
ReportingModule.class,
|
||||
SettingsModule.class,
|
||||
SocksModule.class,
|
||||
|
||||
@@ -169,6 +169,14 @@ class PluginManagerImpl implements PluginManager, Service {
|
||||
return supported;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<DuplexPlugin> getRendezvousPlugins() {
|
||||
List<DuplexPlugin> supported = new ArrayList<>();
|
||||
for (DuplexPlugin d : duplexPlugins)
|
||||
if (d.supportsRendezvous()) supported.add(d);
|
||||
return supported;
|
||||
}
|
||||
|
||||
private class PluginStarter implements Runnable {
|
||||
|
||||
private final Plugin plugin;
|
||||
|
||||
@@ -22,6 +22,8 @@ import org.briarproject.bramble.api.plugin.event.BluetoothEnabledEvent;
|
||||
import org.briarproject.bramble.api.plugin.event.DisableBluetoothEvent;
|
||||
import org.briarproject.bramble.api.plugin.event.EnableBluetoothEvent;
|
||||
import org.briarproject.bramble.api.properties.TransportProperties;
|
||||
import org.briarproject.bramble.api.rendezvous.KeyMaterialSource;
|
||||
import org.briarproject.bramble.api.rendezvous.RendezvousHandler;
|
||||
import org.briarproject.bramble.api.settings.Settings;
|
||||
import org.briarproject.bramble.api.settings.event.SettingsUpdatedEvent;
|
||||
|
||||
@@ -390,6 +392,16 @@ abstract class BluetoothPlugin<SS> implements DuplexPlugin, EventListener {
|
||||
return macToString(mac);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsRendezvous() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RendezvousHandler createRendezvousHandler(KeyMaterialSource k) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void eventOccurred(Event e) {
|
||||
if (e instanceof EnableBluetoothEvent) {
|
||||
|
||||
@@ -12,6 +12,8 @@ import org.briarproject.bramble.api.plugin.PluginCallback;
|
||||
import org.briarproject.bramble.api.plugin.duplex.DuplexPlugin;
|
||||
import org.briarproject.bramble.api.plugin.duplex.DuplexTransportConnection;
|
||||
import org.briarproject.bramble.api.properties.TransportProperties;
|
||||
import org.briarproject.bramble.api.rendezvous.KeyMaterialSource;
|
||||
import org.briarproject.bramble.api.rendezvous.RendezvousHandler;
|
||||
import org.briarproject.bramble.util.IoUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -301,6 +303,16 @@ abstract class TcpPlugin implements DuplexPlugin {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsRendezvous() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RendezvousHandler createRendezvousHandler(KeyMaterialSource k) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
Collection<InetAddress> getLocalIpAddresses() {
|
||||
try {
|
||||
Enumeration<NetworkInterface> ifaces = getNetworkInterfaces();
|
||||
|
||||
@@ -25,6 +25,8 @@ import org.briarproject.bramble.api.plugin.TransportId;
|
||||
import org.briarproject.bramble.api.plugin.duplex.DuplexPlugin;
|
||||
import org.briarproject.bramble.api.plugin.duplex.DuplexTransportConnection;
|
||||
import org.briarproject.bramble.api.properties.TransportProperties;
|
||||
import org.briarproject.bramble.api.rendezvous.KeyMaterialSource;
|
||||
import org.briarproject.bramble.api.rendezvous.RendezvousHandler;
|
||||
import org.briarproject.bramble.api.settings.Settings;
|
||||
import org.briarproject.bramble.api.settings.event.SettingsUpdatedEvent;
|
||||
import org.briarproject.bramble.api.system.Clock;
|
||||
@@ -605,6 +607,16 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsRendezvous() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RendezvousHandler createRendezvousHandler(KeyMaterialSource k) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void circuitStatus(String status, String id, String path) {
|
||||
if (status.equals("BUILT") &&
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package org.briarproject.bramble.rendezvous;
|
||||
|
||||
import org.briarproject.bramble.api.crypto.SecretKey;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.rendezvous.KeyMaterialSource;
|
||||
import org.spongycastle.crypto.engines.Salsa20Engine;
|
||||
import org.spongycastle.crypto.params.KeyParameter;
|
||||
import org.spongycastle.crypto.params.ParametersWithIV;
|
||||
|
||||
import javax.annotation.concurrent.GuardedBy;
|
||||
import javax.annotation.concurrent.ThreadSafe;
|
||||
|
||||
@ThreadSafe
|
||||
@NotNullByDefault
|
||||
class KeyMaterialSourceImpl implements KeyMaterialSource {
|
||||
|
||||
@GuardedBy("this")
|
||||
private final Salsa20Engine cipher = new Salsa20Engine();
|
||||
|
||||
KeyMaterialSourceImpl(SecretKey sourceKey) {
|
||||
// Initialise the stream cipher with an all-zero nonce
|
||||
KeyParameter k = new KeyParameter(sourceKey.getBytes());
|
||||
cipher.init(true, new ParametersWithIV(k, new byte[8]));
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized byte[] getKeyMaterial(int length) {
|
||||
byte[] in = new byte[length];
|
||||
byte[] out = new byte[length];
|
||||
cipher.processBytes(in, 0, length, out, 0);
|
||||
return out;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package org.briarproject.bramble.rendezvous;
|
||||
|
||||
import org.briarproject.bramble.api.crypto.CryptoComponent;
|
||||
import org.briarproject.bramble.api.crypto.SecretKey;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.plugin.TransportId;
|
||||
import org.briarproject.bramble.api.rendezvous.KeyMaterialSource;
|
||||
import org.briarproject.bramble.api.rendezvous.RendezvousCrypto;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static org.briarproject.bramble.api.rendezvous.RendezvousConstants.KEY_MATERIAL_LABEL;
|
||||
import static org.briarproject.bramble.util.StringUtils.toUtf8;
|
||||
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
class RendezvousCryptoImpl implements RendezvousCrypto {
|
||||
|
||||
private final CryptoComponent crypto;
|
||||
|
||||
@Inject
|
||||
RendezvousCryptoImpl(CryptoComponent crypto) {
|
||||
this.crypto = crypto;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KeyMaterialSource createKeyMaterialSource(SecretKey masterKey,
|
||||
TransportId t) {
|
||||
SecretKey sourceKey = crypto.deriveKey(KEY_MATERIAL_LABEL, masterKey,
|
||||
toUtf8(t.getString()));
|
||||
return new KeyMaterialSourceImpl(sourceKey);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package org.briarproject.bramble.rendezvous;
|
||||
|
||||
import org.briarproject.bramble.api.rendezvous.RendezvousCrypto;
|
||||
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
|
||||
@Module
|
||||
public class RendezvousModule {
|
||||
|
||||
@Provides
|
||||
RendezvousCrypto provideKeyMaterialSourceFactory(
|
||||
RendezvousCryptoImpl keyMaterialSourceFactory) {
|
||||
return keyMaterialSourceFactory;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user