mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-11 18:29:05 +01:00
Updated java.library.path.
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -21,3 +21,5 @@ local.properties
|
|||||||
.gradle
|
.gradle
|
||||||
build/
|
build/
|
||||||
*.iml
|
*.iml
|
||||||
|
.gitignore
|
||||||
|
src/test/
|
||||||
|
|||||||
104
bramble-android/build.gradle
Normal file
104
bramble-android/build.gradle
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
import de.undercouch.gradle.tasks.download.Download
|
||||||
|
import de.undercouch.gradle.tasks.download.Verify
|
||||||
|
|
||||||
|
apply plugin: 'com.android.library'
|
||||||
|
apply plugin: 'witness'
|
||||||
|
apply plugin: 'de.undercouch.download'
|
||||||
|
|
||||||
|
android {
|
||||||
|
compileSdkVersion 23
|
||||||
|
buildToolsVersion "23.0.3"
|
||||||
|
|
||||||
|
defaultConfig {
|
||||||
|
minSdkVersion 14
|
||||||
|
targetSdkVersion 22
|
||||||
|
versionCode 1
|
||||||
|
versionName "1.0"
|
||||||
|
consumerProguardFiles 'proguard-rules.txt'
|
||||||
|
}
|
||||||
|
|
||||||
|
compileOptions {
|
||||||
|
sourceCompatibility JavaVersion.VERSION_1_7
|
||||||
|
targetCompatibility JavaVersion.VERSION_1_7
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
compile project(':bramble-core')
|
||||||
|
compile fileTree(dir: 'libs', include: ['*.jar'])
|
||||||
|
provided 'javax.annotation:jsr250-api:1.0'
|
||||||
|
}
|
||||||
|
|
||||||
|
def torBinaryDir = 'src/main/res/raw'
|
||||||
|
|
||||||
|
task downloadTorGeoIp(type: Download) {
|
||||||
|
src 'https://briarproject.org/build/geoip-2015-12-01.zip'
|
||||||
|
dest "$torBinaryDir/geoip.zip"
|
||||||
|
onlyIfNewer true
|
||||||
|
}
|
||||||
|
|
||||||
|
task downloadTorBinaryArm(type: Download) {
|
||||||
|
src 'https://briarproject.org/build/tor-0.2.7.6-arm.zip'
|
||||||
|
dest "$torBinaryDir/tor_arm.zip"
|
||||||
|
onlyIfNewer true
|
||||||
|
}
|
||||||
|
|
||||||
|
task downloadTorBinaryArmPie(type: Download) {
|
||||||
|
src 'https://briarproject.org/build/tor-0.2.7.6-arm-pie.zip'
|
||||||
|
dest "$torBinaryDir/tor_arm_pie.zip"
|
||||||
|
onlyIfNewer true
|
||||||
|
}
|
||||||
|
|
||||||
|
task downloadTorBinaryX86(type: Download) {
|
||||||
|
src 'https://briarproject.org/build/tor-0.2.7.6-x86.zip'
|
||||||
|
dest "$torBinaryDir/tor_x86.zip"
|
||||||
|
onlyIfNewer true
|
||||||
|
}
|
||||||
|
|
||||||
|
task downloadTorBinaryX86Pie(type: Download) {
|
||||||
|
src 'https://briarproject.org/build/tor-0.2.7.6-x86-pie.zip'
|
||||||
|
dest "$torBinaryDir/tor_x86_pie.zip"
|
||||||
|
onlyIfNewer true
|
||||||
|
}
|
||||||
|
|
||||||
|
task verifyTorGeoIp(type: Verify, dependsOn: 'downloadTorGeoIp') {
|
||||||
|
src "$torBinaryDir/geoip.zip"
|
||||||
|
algorithm 'SHA-256'
|
||||||
|
checksum '9bcdaf0a7ba0933735328d8ec466c25c25dbb459efc2bce9e55c774eabea5162'
|
||||||
|
}
|
||||||
|
|
||||||
|
task verifyTorBinaryArm(type: Verify, dependsOn: 'downloadTorBinaryArm') {
|
||||||
|
src "$torBinaryDir/tor_arm.zip"
|
||||||
|
algorithm 'SHA-256'
|
||||||
|
checksum '83272962eda701cd5d74d2418651c4ff0f0b1dff51f558a292d1a1c42bf12146'
|
||||||
|
}
|
||||||
|
|
||||||
|
task verifyTorBinaryArmPie(type: Verify, dependsOn: 'downloadTorBinaryArmPie') {
|
||||||
|
src "$torBinaryDir/tor_arm_pie.zip"
|
||||||
|
algorithm 'SHA-256'
|
||||||
|
checksum 'd0300d1e45de11ebb24ed62b9c492be9c2e88590b7822195ab38c7a76ffcf646'
|
||||||
|
}
|
||||||
|
|
||||||
|
task verifyTorBinaryX86(type: Verify, dependsOn: 'downloadTorBinaryX86') {
|
||||||
|
src "$torBinaryDir/tor_x86.zip"
|
||||||
|
algorithm 'SHA-256'
|
||||||
|
checksum 'b8813d97b01ee1b9c9a4233c1b9bbe9f9f6b494ae6f9cbd84de8a3911911615e'
|
||||||
|
}
|
||||||
|
|
||||||
|
task verifyTorBinaryX86Pie(type: Verify, dependsOn: 'downloadTorBinaryX86Pie') {
|
||||||
|
src "$torBinaryDir/tor_x86_pie.zip"
|
||||||
|
algorithm 'SHA-256'
|
||||||
|
checksum '9c66e765aa196dc089951a1b2140cc8290305c2fcbf365121f99e01a233baf4e'
|
||||||
|
}
|
||||||
|
|
||||||
|
project.afterEvaluate {
|
||||||
|
preBuild.dependsOn {
|
||||||
|
[
|
||||||
|
'verifyTorGeoIp',
|
||||||
|
'verifyTorBinaryArm',
|
||||||
|
'verifyTorBinaryArmPie',
|
||||||
|
'verifyTorBinaryX86',
|
||||||
|
'verifyTorBinaryX86Pie'
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
15
bramble-android/proguard-rules.txt
Normal file
15
bramble-android/proguard-rules.txt
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
-keep,includedescriptorclasses class org.briarproject.** { *; }
|
||||||
|
|
||||||
|
-keep class org.h2.** { *; }
|
||||||
|
-dontwarn org.h2.**
|
||||||
|
-dontnote org.h2.**
|
||||||
|
|
||||||
|
-keep class dagger.** { *; }
|
||||||
|
-dontwarn dagger.**
|
||||||
|
-dontnote dagger.**
|
||||||
|
|
||||||
|
-dontwarn sun.misc.Unsafe
|
||||||
|
-dontnote com.google.common.**
|
||||||
|
|
||||||
|
# UPnP library isn't used
|
||||||
|
-dontwarn org.bitlet.weupnp.**
|
||||||
24
bramble-android/src/main/AndroidManifest.xml
Normal file
24
bramble-android/src/main/AndroidManifest.xml
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<manifest
|
||||||
|
package="org.briarproject.bramble"
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
|
<uses-feature android:name="android.hardware.bluetooth"/>
|
||||||
|
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
|
||||||
|
<uses-permission android:name="android.permission.BLUETOOTH"/>
|
||||||
|
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
|
||||||
|
<uses-permission android:name="android.permission.INTERNET"/>
|
||||||
|
<uses-permission android:name="android.permission.READ_LOGS"/>
|
||||||
|
<uses-permission android:name="android.permission.WAKE_LOCK"/>
|
||||||
|
<!-- Since API 23, this is needed to add contacts via Bluetooth -->
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
|
||||||
|
|
||||||
|
<application
|
||||||
|
android:allowBackup="false"
|
||||||
|
android:label="@string/app_name"
|
||||||
|
android:supportsRtl="true">
|
||||||
|
|
||||||
|
</application>
|
||||||
|
|
||||||
|
</manifest>
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package org.briarproject.bramble;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.plugin.AndroidPluginModule;
|
||||||
|
import org.briarproject.bramble.system.AndroidSystemModule;
|
||||||
|
|
||||||
|
import dagger.Module;
|
||||||
|
|
||||||
|
@Module(includes = {
|
||||||
|
AndroidPluginModule.class,
|
||||||
|
AndroidSystemModule.class
|
||||||
|
})
|
||||||
|
public class BrambleAndroidModule {
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.briarproject.android.api;
|
package org.briarproject.bramble.api.system;
|
||||||
|
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
@@ -1,20 +1,21 @@
|
|||||||
package org.briarproject.plugins;
|
package org.briarproject.bramble.plugin;
|
||||||
|
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import org.briarproject.android.api.AndroidExecutor;
|
import org.briarproject.bramble.api.event.EventBus;
|
||||||
import org.briarproject.api.event.EventBus;
|
import org.briarproject.bramble.api.lifecycle.IoExecutor;
|
||||||
import org.briarproject.api.lifecycle.IoExecutor;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.api.plugins.BackoffFactory;
|
import org.briarproject.bramble.api.plugin.BackoffFactory;
|
||||||
import org.briarproject.api.plugins.PluginConfig;
|
import org.briarproject.bramble.api.plugin.PluginConfig;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexPluginFactory;
|
import org.briarproject.bramble.api.plugin.duplex.DuplexPluginFactory;
|
||||||
import org.briarproject.api.plugins.simplex.SimplexPluginFactory;
|
import org.briarproject.bramble.api.plugin.simplex.SimplexPluginFactory;
|
||||||
import org.briarproject.api.reporting.DevReporter;
|
import org.briarproject.bramble.api.reporting.DevReporter;
|
||||||
import org.briarproject.api.system.LocationUtils;
|
import org.briarproject.bramble.api.system.AndroidExecutor;
|
||||||
import org.briarproject.plugins.droidtooth.DroidtoothPluginFactory;
|
import org.briarproject.bramble.api.system.LocationUtils;
|
||||||
import org.briarproject.plugins.tcp.AndroidLanTcpPluginFactory;
|
import org.briarproject.bramble.plugin.droidtooth.DroidtoothPluginFactory;
|
||||||
import org.briarproject.plugins.tor.TorPluginFactory;
|
import org.briarproject.bramble.plugin.tcp.AndroidLanTcpPluginFactory;
|
||||||
|
import org.briarproject.bramble.plugin.tor.TorPluginFactory;
|
||||||
|
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -28,10 +29,10 @@ import dagger.Module;
|
|||||||
import dagger.Provides;
|
import dagger.Provides;
|
||||||
|
|
||||||
@Module
|
@Module
|
||||||
public class AndroidPluginsModule {
|
public class AndroidPluginModule {
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
public PluginConfig providePluginConfig(@IoExecutor Executor ioExecutor,
|
PluginConfig providePluginConfig(@IoExecutor Executor ioExecutor,
|
||||||
AndroidExecutor androidExecutor, SecureRandom random,
|
AndroidExecutor androidExecutor, SecureRandom random,
|
||||||
SocketFactory torSocketFactory, BackoffFactory backoffFactory,
|
SocketFactory torSocketFactory, BackoffFactory backoffFactory,
|
||||||
Application app, LocationUtils locationUtils, DevReporter reporter,
|
Application app, LocationUtils locationUtils, DevReporter reporter,
|
||||||
@@ -46,7 +47,8 @@ public class AndroidPluginsModule {
|
|||||||
backoffFactory, appContext);
|
backoffFactory, appContext);
|
||||||
final Collection<DuplexPluginFactory> duplex =
|
final Collection<DuplexPluginFactory> duplex =
|
||||||
Arrays.asList(bluetooth, tor, lan);
|
Arrays.asList(bluetooth, tor, lan);
|
||||||
return new PluginConfig() {
|
@NotNullByDefault
|
||||||
|
PluginConfig pluginConfig = new PluginConfig() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<DuplexPluginFactory> getDuplexFactories() {
|
public Collection<DuplexPluginFactory> getDuplexFactories() {
|
||||||
@@ -58,5 +60,6 @@ public class AndroidPluginsModule {
|
|||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
return pluginConfig;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.briarproject.plugins.droidtooth;
|
package org.briarproject.bramble.plugin.droidtooth;
|
||||||
|
|
||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothAdapter;
|
||||||
import android.bluetooth.BluetoothDevice;
|
import android.bluetooth.BluetoothDevice;
|
||||||
@@ -9,23 +9,23 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
|
|
||||||
import org.briarproject.android.api.AndroidExecutor;
|
import org.briarproject.bramble.api.FormatException;
|
||||||
import org.briarproject.android.util.AndroidUtils;
|
import org.briarproject.bramble.api.contact.ContactId;
|
||||||
import org.briarproject.api.FormatException;
|
import org.briarproject.bramble.api.crypto.PseudoRandom;
|
||||||
import org.briarproject.api.TransportId;
|
import org.briarproject.bramble.api.data.BdfList;
|
||||||
import org.briarproject.api.contact.ContactId;
|
import org.briarproject.bramble.api.keyagreement.KeyAgreementConnection;
|
||||||
import org.briarproject.api.crypto.PseudoRandom;
|
import org.briarproject.bramble.api.keyagreement.KeyAgreementListener;
|
||||||
import org.briarproject.api.data.BdfList;
|
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||||
import org.briarproject.api.keyagreement.KeyAgreementConnection;
|
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||||
import org.briarproject.api.keyagreement.KeyAgreementListener;
|
import org.briarproject.bramble.api.plugin.Backoff;
|
||||||
import org.briarproject.api.nullsafety.MethodsNotNullByDefault;
|
import org.briarproject.bramble.api.plugin.TransportId;
|
||||||
import org.briarproject.api.nullsafety.ParametersNotNullByDefault;
|
import org.briarproject.bramble.api.plugin.duplex.DuplexPlugin;
|
||||||
import org.briarproject.api.plugins.Backoff;
|
import org.briarproject.bramble.api.plugin.duplex.DuplexPluginCallback;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexPlugin;
|
import org.briarproject.bramble.api.plugin.duplex.DuplexTransportConnection;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexPluginCallback;
|
import org.briarproject.bramble.api.properties.TransportProperties;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexTransportConnection;
|
import org.briarproject.bramble.api.system.AndroidExecutor;
|
||||||
import org.briarproject.api.properties.TransportProperties;
|
import org.briarproject.bramble.util.AndroidUtils;
|
||||||
import org.briarproject.util.StringUtils;
|
import org.briarproject.bramble.util.StringUtils;
|
||||||
|
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -64,12 +64,12 @@ import static android.bluetooth.BluetoothDevice.EXTRA_DEVICE;
|
|||||||
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||||
import static java.util.logging.Level.INFO;
|
import static java.util.logging.Level.INFO;
|
||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
import static org.briarproject.api.keyagreement.KeyAgreementConstants.TRANSPORT_ID_BLUETOOTH;
|
import static org.briarproject.bramble.api.keyagreement.KeyAgreementConstants.TRANSPORT_ID_BLUETOOTH;
|
||||||
import static org.briarproject.api.plugins.BluetoothConstants.ID;
|
import static org.briarproject.bramble.api.plugin.BluetoothConstants.ID;
|
||||||
import static org.briarproject.api.plugins.BluetoothConstants.PROP_ADDRESS;
|
import static org.briarproject.bramble.api.plugin.BluetoothConstants.PROP_ADDRESS;
|
||||||
import static org.briarproject.api.plugins.BluetoothConstants.PROP_UUID;
|
import static org.briarproject.bramble.api.plugin.BluetoothConstants.PROP_UUID;
|
||||||
import static org.briarproject.api.plugins.BluetoothConstants.UUID_BYTES;
|
import static org.briarproject.bramble.api.plugin.BluetoothConstants.UUID_BYTES;
|
||||||
import static org.briarproject.util.PrivacyUtils.scrubMacAddress;
|
import static org.briarproject.bramble.util.PrivacyUtils.scrubMacAddress;
|
||||||
|
|
||||||
@MethodsNotNullByDefault
|
@MethodsNotNullByDefault
|
||||||
@ParametersNotNullByDefault
|
@ParametersNotNullByDefault
|
||||||
@@ -1,20 +1,25 @@
|
|||||||
package org.briarproject.plugins.droidtooth;
|
package org.briarproject.bramble.plugin.droidtooth;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import org.briarproject.android.api.AndroidExecutor;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.api.TransportId;
|
import org.briarproject.bramble.api.plugin.Backoff;
|
||||||
import org.briarproject.api.plugins.Backoff;
|
import org.briarproject.bramble.api.plugin.BackoffFactory;
|
||||||
import org.briarproject.api.plugins.BackoffFactory;
|
import org.briarproject.bramble.api.plugin.TransportId;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexPlugin;
|
import org.briarproject.bramble.api.plugin.duplex.DuplexPlugin;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexPluginCallback;
|
import org.briarproject.bramble.api.plugin.duplex.DuplexPluginCallback;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexPluginFactory;
|
import org.briarproject.bramble.api.plugin.duplex.DuplexPluginFactory;
|
||||||
|
import org.briarproject.bramble.api.system.AndroidExecutor;
|
||||||
|
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
import static org.briarproject.api.plugins.BluetoothConstants.ID;
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
|
import static org.briarproject.bramble.api.plugin.BluetoothConstants.ID;
|
||||||
|
|
||||||
|
@Immutable
|
||||||
|
@NotNullByDefault
|
||||||
public class DroidtoothPluginFactory implements DuplexPluginFactory {
|
public class DroidtoothPluginFactory implements DuplexPluginFactory {
|
||||||
|
|
||||||
private static final int MAX_LATENCY = 30 * 1000; // 30 seconds
|
private static final int MAX_LATENCY = 30 * 1000; // 30 seconds
|
||||||
@@ -1,14 +1,16 @@
|
|||||||
package org.briarproject.plugins.droidtooth;
|
package org.briarproject.bramble.plugin.droidtooth;
|
||||||
|
|
||||||
import android.bluetooth.BluetoothSocket;
|
import android.bluetooth.BluetoothSocket;
|
||||||
|
|
||||||
import org.briarproject.api.plugins.Plugin;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.api.plugins.duplex.AbstractDuplexTransportConnection;
|
import org.briarproject.bramble.api.plugin.Plugin;
|
||||||
|
import org.briarproject.bramble.api.plugin.duplex.AbstractDuplexTransportConnection;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
class DroidtoothTransportConnection extends AbstractDuplexTransportConnection {
|
class DroidtoothTransportConnection extends AbstractDuplexTransportConnection {
|
||||||
|
|
||||||
private final BluetoothSocket socket;
|
private final BluetoothSocket socket;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.briarproject.plugins.tcp;
|
package org.briarproject.bramble.plugin.tcp;
|
||||||
|
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -7,9 +7,9 @@ import android.content.IntentFilter;
|
|||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.NetworkInfo;
|
import android.net.NetworkInfo;
|
||||||
|
|
||||||
import org.briarproject.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.api.plugins.Backoff;
|
import org.briarproject.bramble.api.plugin.Backoff;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexPluginCallback;
|
import org.briarproject.bramble.api.plugin.duplex.DuplexPluginCallback;
|
||||||
|
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
@@ -1,18 +1,23 @@
|
|||||||
package org.briarproject.plugins.tcp;
|
package org.briarproject.bramble.plugin.tcp;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import org.briarproject.api.TransportId;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.api.plugins.Backoff;
|
import org.briarproject.bramble.api.plugin.Backoff;
|
||||||
import org.briarproject.api.plugins.BackoffFactory;
|
import org.briarproject.bramble.api.plugin.BackoffFactory;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexPlugin;
|
import org.briarproject.bramble.api.plugin.TransportId;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexPluginCallback;
|
import org.briarproject.bramble.api.plugin.duplex.DuplexPlugin;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexPluginFactory;
|
import org.briarproject.bramble.api.plugin.duplex.DuplexPluginCallback;
|
||||||
|
import org.briarproject.bramble.api.plugin.duplex.DuplexPluginFactory;
|
||||||
|
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
import static org.briarproject.api.plugins.LanTcpConstants.ID;
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
|
import static org.briarproject.bramble.api.plugin.LanTcpConstants.ID;
|
||||||
|
|
||||||
|
@Immutable
|
||||||
|
@NotNullByDefault
|
||||||
public class AndroidLanTcpPluginFactory implements DuplexPluginFactory {
|
public class AndroidLanTcpPluginFactory implements DuplexPluginFactory {
|
||||||
|
|
||||||
private static final int MAX_LATENCY = 30 * 1000; // 30 seconds
|
private static final int MAX_LATENCY = 30 * 1000; // 30 seconds
|
||||||
@@ -1,18 +1,18 @@
|
|||||||
package org.briarproject.plugins.tor;
|
package org.briarproject.bramble.plugin.tor;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class TorNetworkMetadata {
|
class TorNetworkMetadata {
|
||||||
|
|
||||||
// See https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
|
// See https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
|
||||||
// and https://trac.torproject.org/projects/tor/wiki/doc/OONI/censorshipwiki
|
// and https://trac.torproject.org/projects/tor/wiki/doc/OONI/censorshipwiki
|
||||||
// TODO: get a more complete list
|
// TODO: get a more complete list
|
||||||
private static final Set<String> BLOCKED_IN_COUNTRIES =
|
private static final Set<String> BLOCKED_IN_COUNTRIES =
|
||||||
new HashSet<String>(Arrays.asList("CN", "IR", "SY", "ZZ"));
|
new HashSet<>(Arrays.asList("CN", "IR", "SY", "ZZ"));
|
||||||
|
|
||||||
public static boolean isTorProbablyBlocked(String countryCode) {
|
static boolean isTorProbablyBlocked(String countryCode) {
|
||||||
return BLOCKED_IN_COUNTRIES.contains(countryCode);
|
return BLOCKED_IN_COUNTRIES.contains(countryCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.briarproject.plugins.tor;
|
package org.briarproject.bramble.plugin.tor;
|
||||||
|
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -7,6 +7,7 @@ import android.content.IntentFilter;
|
|||||||
import android.content.pm.PackageInfo;
|
import android.content.pm.PackageInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.PackageManager.NameNotFoundException;
|
import android.content.pm.PackageManager.NameNotFoundException;
|
||||||
|
import android.content.res.Resources;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.NetworkInfo;
|
import android.net.NetworkInfo;
|
||||||
import android.os.FileObserver;
|
import android.os.FileObserver;
|
||||||
@@ -15,27 +16,28 @@ import android.os.PowerManager;
|
|||||||
import net.freehaven.tor.control.EventHandler;
|
import net.freehaven.tor.control.EventHandler;
|
||||||
import net.freehaven.tor.control.TorControlConnection;
|
import net.freehaven.tor.control.TorControlConnection;
|
||||||
|
|
||||||
import org.briarproject.android.util.AndroidUtils;
|
import org.briarproject.bramble.api.contact.ContactId;
|
||||||
import org.briarproject.api.TransportId;
|
import org.briarproject.bramble.api.crypto.PseudoRandom;
|
||||||
import org.briarproject.api.contact.ContactId;
|
import org.briarproject.bramble.api.data.BdfList;
|
||||||
import org.briarproject.api.crypto.PseudoRandom;
|
import org.briarproject.bramble.api.event.Event;
|
||||||
import org.briarproject.api.data.BdfList;
|
import org.briarproject.bramble.api.event.EventListener;
|
||||||
import org.briarproject.api.event.Event;
|
import org.briarproject.bramble.api.keyagreement.KeyAgreementListener;
|
||||||
import org.briarproject.api.event.EventListener;
|
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||||
import org.briarproject.api.event.SettingsUpdatedEvent;
|
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||||
import org.briarproject.api.keyagreement.KeyAgreementListener;
|
import org.briarproject.bramble.api.plugin.Backoff;
|
||||||
import org.briarproject.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.plugin.TorConstants;
|
||||||
import org.briarproject.api.plugins.Backoff;
|
import org.briarproject.bramble.api.plugin.TransportId;
|
||||||
import org.briarproject.api.plugins.TorConstants;
|
import org.briarproject.bramble.api.plugin.duplex.DuplexPlugin;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexPlugin;
|
import org.briarproject.bramble.api.plugin.duplex.DuplexPluginCallback;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexPluginCallback;
|
import org.briarproject.bramble.api.plugin.duplex.DuplexTransportConnection;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexTransportConnection;
|
import org.briarproject.bramble.api.properties.TransportProperties;
|
||||||
import org.briarproject.api.properties.TransportProperties;
|
import org.briarproject.bramble.api.reporting.DevReporter;
|
||||||
import org.briarproject.api.reporting.DevReporter;
|
import org.briarproject.bramble.api.settings.Settings;
|
||||||
import org.briarproject.api.settings.Settings;
|
import org.briarproject.bramble.api.settings.event.SettingsUpdatedEvent;
|
||||||
import org.briarproject.api.system.LocationUtils;
|
import org.briarproject.bramble.api.system.LocationUtils;
|
||||||
import org.briarproject.util.IoUtils;
|
import org.briarproject.bramble.util.AndroidUtils;
|
||||||
import org.briarproject.util.StringUtils;
|
import org.briarproject.bramble.util.IoUtils;
|
||||||
|
import org.briarproject.bramble.util.StringUtils;
|
||||||
|
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
import java.io.EOFException;
|
import java.io.EOFException;
|
||||||
@@ -75,10 +77,11 @@ import static java.util.logging.Level.INFO;
|
|||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
import static net.freehaven.tor.control.TorControlCommands.HS_ADDRESS;
|
import static net.freehaven.tor.control.TorControlCommands.HS_ADDRESS;
|
||||||
import static net.freehaven.tor.control.TorControlCommands.HS_PRIVKEY;
|
import static net.freehaven.tor.control.TorControlCommands.HS_PRIVKEY;
|
||||||
import static org.briarproject.api.plugins.TorConstants.CONTROL_PORT;
|
import static org.briarproject.bramble.api.plugin.TorConstants.CONTROL_PORT;
|
||||||
import static org.briarproject.util.PrivacyUtils.scrubOnion;
|
import static org.briarproject.bramble.util.PrivacyUtils.scrubOnion;
|
||||||
|
|
||||||
@NotNullByDefault
|
@MethodsNotNullByDefault
|
||||||
|
@ParametersNotNullByDefault
|
||||||
class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||||
|
|
||||||
private static final String PROP_ONION = "onion";
|
private static final String PROP_ONION = "onion";
|
||||||
@@ -107,13 +110,9 @@ class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
|||||||
private final AtomicBoolean used = new AtomicBoolean(false);
|
private final AtomicBoolean used = new AtomicBoolean(false);
|
||||||
|
|
||||||
private volatile boolean running = false;
|
private volatile boolean running = false;
|
||||||
@Nullable
|
|
||||||
private volatile ServerSocket socket = null;
|
private volatile ServerSocket socket = null;
|
||||||
@Nullable
|
|
||||||
private volatile Socket controlSocket = null;
|
private volatile Socket controlSocket = null;
|
||||||
@Nullable
|
|
||||||
private volatile TorControlConnection controlConnection = null;
|
private volatile TorControlConnection controlConnection = null;
|
||||||
@Nullable
|
|
||||||
private volatile BroadcastReceiver networkStateReceiver = null;
|
private volatile BroadcastReceiver networkStateReceiver = null;
|
||||||
|
|
||||||
TorPlugin(Executor ioExecutor, Context appContext,
|
TorPlugin(Executor ioExecutor, Context appContext,
|
||||||
@@ -277,23 +276,29 @@ class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
|||||||
private InputStream getTorInputStream() throws IOException {
|
private InputStream getTorInputStream() throws IOException {
|
||||||
if (LOG.isLoggable(INFO))
|
if (LOG.isLoggable(INFO))
|
||||||
LOG.info("Installing Tor binary for " + architecture);
|
LOG.info("Installing Tor binary for " + architecture);
|
||||||
String filename = "tor-" + architecture + ".zip";
|
int resId = getResourceId("tor_" + architecture);
|
||||||
InputStream in = appContext.getResources().getAssets().open(filename);
|
InputStream in = appContext.getResources().openRawResource(resId);
|
||||||
ZipInputStream zin = new ZipInputStream(in);
|
ZipInputStream zin = new ZipInputStream(in);
|
||||||
if (zin.getNextEntry() == null) throw new IOException();
|
if (zin.getNextEntry() == null) throw new IOException();
|
||||||
return zin;
|
return zin;
|
||||||
}
|
}
|
||||||
|
|
||||||
private InputStream getGeoIpInputStream() throws IOException {
|
private InputStream getGeoIpInputStream() throws IOException {
|
||||||
String filename = "geoip.zip";
|
int resId = getResourceId("geoip");
|
||||||
InputStream in = appContext.getResources().getAssets().open(filename);
|
InputStream in = appContext.getResources().openRawResource(resId);
|
||||||
ZipInputStream zin = new ZipInputStream(in);
|
ZipInputStream zin = new ZipInputStream(in);
|
||||||
if (zin.getNextEntry() == null) throw new IOException();
|
if (zin.getNextEntry() == null) throw new IOException();
|
||||||
return zin;
|
return zin;
|
||||||
}
|
}
|
||||||
|
|
||||||
private InputStream getConfigInputStream() throws IOException {
|
private InputStream getConfigInputStream() throws IOException {
|
||||||
return appContext.getResources().getAssets().open("torrc");
|
int resId = getResourceId("torrc");
|
||||||
|
return appContext.getResources().openRawResource(resId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getResourceId(String filename) {
|
||||||
|
Resources res = appContext.getResources();
|
||||||
|
return res.getIdentifier(filename, "raw", appContext.getPackageName());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void tryToClose(@Nullable Closeable c) {
|
private void tryToClose(@Nullable Closeable c) {
|
||||||
@@ -1,25 +1,29 @@
|
|||||||
package org.briarproject.plugins.tor;
|
package org.briarproject.bramble.plugin.tor;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
|
||||||
import org.briarproject.android.util.AndroidUtils;
|
import org.briarproject.bramble.api.event.EventBus;
|
||||||
import org.briarproject.api.TransportId;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.api.event.EventBus;
|
import org.briarproject.bramble.api.plugin.Backoff;
|
||||||
import org.briarproject.api.plugins.Backoff;
|
import org.briarproject.bramble.api.plugin.BackoffFactory;
|
||||||
import org.briarproject.api.plugins.BackoffFactory;
|
import org.briarproject.bramble.api.plugin.TorConstants;
|
||||||
import org.briarproject.api.plugins.TorConstants;
|
import org.briarproject.bramble.api.plugin.TransportId;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexPlugin;
|
import org.briarproject.bramble.api.plugin.duplex.DuplexPlugin;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexPluginCallback;
|
import org.briarproject.bramble.api.plugin.duplex.DuplexPluginCallback;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexPluginFactory;
|
import org.briarproject.bramble.api.plugin.duplex.DuplexPluginFactory;
|
||||||
import org.briarproject.api.reporting.DevReporter;
|
import org.briarproject.bramble.api.reporting.DevReporter;
|
||||||
import org.briarproject.api.system.LocationUtils;
|
import org.briarproject.bramble.api.system.LocationUtils;
|
||||||
|
import org.briarproject.bramble.util.AndroidUtils;
|
||||||
|
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import javax.annotation.concurrent.Immutable;
|
||||||
import javax.net.SocketFactory;
|
import javax.net.SocketFactory;
|
||||||
|
|
||||||
|
@Immutable
|
||||||
|
@NotNullByDefault
|
||||||
public class TorPluginFactory implements DuplexPluginFactory {
|
public class TorPluginFactory implements DuplexPluginFactory {
|
||||||
|
|
||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
@@ -81,7 +85,7 @@ public class TorPluginFactory implements DuplexPluginFactory {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
// Use position-independent executable for SDK >= 16
|
// Use position-independent executable for SDK >= 16
|
||||||
if (Build.VERSION.SDK_INT >= 16) architecture += "-pie";
|
if (Build.VERSION.SDK_INT >= 16) architecture += "_pie";
|
||||||
|
|
||||||
Backoff backoff = backoffFactory.createBackoff(MIN_POLLING_INTERVAL,
|
Backoff backoff = backoffFactory.createBackoff(MIN_POLLING_INTERVAL,
|
||||||
MAX_POLLING_INTERVAL, BACKOFF_BASE);
|
MAX_POLLING_INTERVAL, BACKOFF_BASE);
|
||||||
@@ -1,13 +1,15 @@
|
|||||||
package org.briarproject.plugins.tor;
|
package org.briarproject.bramble.plugin.tor;
|
||||||
|
|
||||||
import org.briarproject.api.plugins.Plugin;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.api.plugins.duplex.AbstractDuplexTransportConnection;
|
import org.briarproject.bramble.api.plugin.Plugin;
|
||||||
|
import org.briarproject.bramble.api.plugin.duplex.AbstractDuplexTransportConnection;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
class TorTransportConnection extends AbstractDuplexTransportConnection {
|
class TorTransportConnection extends AbstractDuplexTransportConnection {
|
||||||
|
|
||||||
private final Socket socket;
|
private final Socket socket;
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
package org.briarproject.system;
|
package org.briarproject.bramble.system;
|
||||||
|
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
|
|
||||||
import org.briarproject.android.api.AndroidExecutor;
|
import org.briarproject.bramble.api.system.AndroidExecutor;
|
||||||
|
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.briarproject.system;
|
package org.briarproject.bramble.system;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
@@ -6,7 +6,8 @@ import android.content.Context;
|
|||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import org.briarproject.api.system.LocationUtils;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.system.LocationUtils;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
@@ -15,6 +16,7 @@ import javax.inject.Inject;
|
|||||||
|
|
||||||
import static android.content.Context.TELEPHONY_SERVICE;
|
import static android.content.Context.TELEPHONY_SERVICE;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
class AndroidLocationUtils implements LocationUtils {
|
class AndroidLocationUtils implements LocationUtils {
|
||||||
|
|
||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
@@ -23,7 +25,7 @@ class AndroidLocationUtils implements LocationUtils {
|
|||||||
private final Context appContext;
|
private final Context appContext;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public AndroidLocationUtils(Application app) {
|
AndroidLocationUtils(Application app) {
|
||||||
appContext = app.getApplicationContext();
|
appContext = app.getApplicationContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,6 +46,7 @@ class AndroidLocationUtils implements LocationUtils {
|
|||||||
* some reason - both that class and {@code Context.COUNTRY_CODE} are
|
* some reason - both that class and {@code Context.COUNTRY_CODE} are
|
||||||
* annotated {@code @hide}.
|
* annotated {@code @hide}.
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
@SuppressLint("DefaultLocale")
|
@SuppressLint("DefaultLocale")
|
||||||
public String getCurrentCountry() {
|
public String getCurrentCountry() {
|
||||||
String countryCode = getCountryFromPhoneNetwork();
|
String countryCode = getCountryFromPhoneNetwork();
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.briarproject.system;
|
package org.briarproject.bramble.system;
|
||||||
|
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
@@ -6,13 +6,18 @@ import android.content.Context;
|
|||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import javax.annotation.concurrent.Immutable;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import static android.provider.Settings.Secure.ANDROID_ID;
|
import static android.provider.Settings.Secure.ANDROID_ID;
|
||||||
|
|
||||||
|
@Immutable
|
||||||
|
@NotNullByDefault
|
||||||
class AndroidSeedProvider extends LinuxSeedProvider {
|
class AndroidSeedProvider extends LinuxSeedProvider {
|
||||||
|
|
||||||
private final Context appContext;
|
private final Context appContext;
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package org.briarproject.bramble.system;
|
||||||
|
|
||||||
|
import android.app.Application;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.system.AndroidExecutor;
|
||||||
|
import org.briarproject.bramble.api.system.LocationUtils;
|
||||||
|
import org.briarproject.bramble.api.system.SeedProvider;
|
||||||
|
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import dagger.Module;
|
||||||
|
import dagger.Provides;
|
||||||
|
|
||||||
|
@Module
|
||||||
|
public class AndroidSystemModule {
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
SeedProvider provideSeedProvider(Application app) {
|
||||||
|
return new AndroidSeedProvider(app);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
LocationUtils provideLocationUtils(Application app) {
|
||||||
|
return new AndroidLocationUtils(app);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
AndroidExecutor provideAndroidExecutor(Application app) {
|
||||||
|
return new AndroidExecutorImpl(app);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
package org.briarproject.bramble.util;
|
||||||
|
|
||||||
|
import android.bluetooth.BluetoothAdapter;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.Build;
|
||||||
|
import android.provider.Settings;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static android.content.Context.MODE_PRIVATE;
|
||||||
|
|
||||||
|
public class AndroidUtils {
|
||||||
|
|
||||||
|
// Fake Bluetooth address returned by BluetoothAdapter on API 23 and later
|
||||||
|
private static final String FAKE_BLUETOOTH_ADDRESS = "02:00:00:00:00:00";
|
||||||
|
|
||||||
|
private static final String STORED_REPORTS = "dev-reports";
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public static Collection<String> getSupportedArchitectures() {
|
||||||
|
List<String> abis = new ArrayList<>();
|
||||||
|
if (Build.VERSION.SDK_INT >= 21) {
|
||||||
|
abis.addAll(Arrays.asList(Build.SUPPORTED_ABIS));
|
||||||
|
} else {
|
||||||
|
abis.add(Build.CPU_ABI);
|
||||||
|
if (Build.CPU_ABI2 != null) abis.add(Build.CPU_ABI2);
|
||||||
|
}
|
||||||
|
return abis;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getBluetoothAddress(Context ctx,
|
||||||
|
BluetoothAdapter adapter) {
|
||||||
|
// Return the adapter's address if it's valid and not fake
|
||||||
|
String address = adapter.getAddress();
|
||||||
|
if (isValidBluetoothAddress(address)) return address;
|
||||||
|
// Return the address from settings if it's valid and not fake
|
||||||
|
address = Settings.Secure.getString(ctx.getContentResolver(),
|
||||||
|
"bluetooth_address");
|
||||||
|
if (isValidBluetoothAddress(address)) return address;
|
||||||
|
// Let the caller know we can't find the address
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isValidBluetoothAddress(String address) {
|
||||||
|
return !StringUtils.isNullOrEmpty(address)
|
||||||
|
&& BluetoothAdapter.checkBluetoothAddress(address)
|
||||||
|
&& !address.equals(FAKE_BLUETOOTH_ADDRESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void deleteAppData(Context ctx) {
|
||||||
|
File dataDir = new File(ctx.getApplicationInfo().dataDir);
|
||||||
|
File[] children = dataDir.listFiles();
|
||||||
|
if (children != null) {
|
||||||
|
for (File child : children) {
|
||||||
|
if (!child.getName().equals("lib"))
|
||||||
|
IoUtils.deleteFileOrDir(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Recreate the cache dir as some OpenGL drivers expect it to exist
|
||||||
|
new File(dataDir, "cache").mkdir();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static File getReportDir(Context ctx) {
|
||||||
|
return ctx.getDir(STORED_REPORTS, MODE_PRIVATE);
|
||||||
|
}
|
||||||
|
}
|
||||||
3
bramble-android/src/main/res/values/strings.xml
Normal file
3
bramble-android/src/main/res/values/strings.xml
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<resources>
|
||||||
|
<string name="app_name">Bramble</string>
|
||||||
|
</resources>
|
||||||
22
bramble-api/build.gradle
Normal file
22
bramble-api/build.gradle
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
apply plugin: 'java'
|
||||||
|
sourceCompatibility = 1.6
|
||||||
|
targetCompatibility = 1.6
|
||||||
|
|
||||||
|
apply plugin: 'witness'
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
compile "com.google.dagger:dagger:2.0.2"
|
||||||
|
compile 'com.google.dagger:dagger-compiler:2.0.2'
|
||||||
|
compile 'com.google.code.findbugs:jsr305:3.0.1'
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencyVerification {
|
||||||
|
verify = [
|
||||||
|
'com.google.dagger:dagger:84c0282ed8be73a29e0475d639da030b55dee72369e58dd35ae7d4fe6243dcf9',
|
||||||
|
'com.google.dagger:dagger-compiler:b74bc9de063dd4c6400b232231f2ef5056145b8fbecbf5382012007dd1c071b3',
|
||||||
|
'javax.inject:javax.inject:91c77044a50c481636c32d916fd89c9118a72195390452c81065080f957de7ff',
|
||||||
|
'com.google.dagger:dagger-producers:99ec15e8a0507ba569e7655bc1165ee5e5ca5aa914b3c8f7e2c2458f724edd6b',
|
||||||
|
'com.google.guava:guava:d664fbfc03d2e5ce9cab2a44fb01f1d0bf9dfebeccc1a473b1f9ea31f79f6f99',
|
||||||
|
'com.google.code.findbugs:jsr305:c885ce34249682bc0236b4a7d56efcc12048e6135a5baf7a9cde8ad8cda13fcd'
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -1,11 +1,17 @@
|
|||||||
package org.briarproject.api;
|
package org.briarproject.bramble.api;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
|
||||||
|
import javax.annotation.concurrent.ThreadSafe;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A wrapper around a byte array, to allow it to be stored in maps etc.
|
* A wrapper around a byte array, to allow it to be stored in maps etc.
|
||||||
*/
|
*/
|
||||||
|
@ThreadSafe
|
||||||
|
@NotNullByDefault
|
||||||
public class Bytes implements Comparable<Bytes> {
|
public class Bytes implements Comparable<Bytes> {
|
||||||
|
|
||||||
public static final BytesComparator COMPARATOR = new BytesComparator();
|
public static final BytesComparator COMPARATOR = new BytesComparator();
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package org.briarproject.bramble.api;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An exception that indicates an unrecoverable formatting error.
|
||||||
|
*/
|
||||||
|
public class FormatException extends IOException {
|
||||||
|
}
|
||||||
@@ -1,12 +1,10 @@
|
|||||||
package org.briarproject.api;
|
package org.briarproject.bramble.api;
|
||||||
|
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public abstract class StringMap extends Hashtable<String, String> {
|
public abstract class StringMap extends Hashtable<String, String> {
|
||||||
|
|
||||||
private static final long serialVersionUID = 2497176435908100448L;
|
|
||||||
|
|
||||||
protected StringMap(Map<String, String> m) {
|
protected StringMap(Map<String, String> m) {
|
||||||
super(m);
|
super(m);
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package org.briarproject.bramble.api;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
import javax.annotation.concurrent.ThreadSafe;
|
||||||
|
|
||||||
|
@ThreadSafe
|
||||||
|
@NotNullByDefault
|
||||||
|
public abstract class UniqueId extends Bytes {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The length of a unique identifier in bytes.
|
||||||
|
*/
|
||||||
|
public static final int LENGTH = 32;
|
||||||
|
|
||||||
|
protected UniqueId(byte[] id) {
|
||||||
|
super(id);
|
||||||
|
if (id.length != LENGTH) throw new IllegalArgumentException();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
package org.briarproject.api.clients;
|
package org.briarproject.bramble.api.client;
|
||||||
|
|
||||||
import org.briarproject.api.data.BdfDictionary;
|
import org.briarproject.bramble.api.data.BdfDictionary;
|
||||||
import org.briarproject.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.api.sync.MessageId;
|
import org.briarproject.bramble.api.sync.MessageId;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
package org.briarproject.bramble.api.client;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.FormatException;
|
||||||
|
import org.briarproject.bramble.api.data.BdfList;
|
||||||
|
import org.briarproject.bramble.api.data.MetadataEncoder;
|
||||||
|
import org.briarproject.bramble.api.db.Metadata;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.sync.Group;
|
||||||
|
import org.briarproject.bramble.api.sync.InvalidMessageException;
|
||||||
|
import org.briarproject.bramble.api.sync.Message;
|
||||||
|
import org.briarproject.bramble.api.sync.MessageContext;
|
||||||
|
import org.briarproject.bramble.api.sync.ValidationManager.MessageValidator;
|
||||||
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
|
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
|
import static org.briarproject.bramble.api.sync.SyncConstants.MESSAGE_HEADER_LENGTH;
|
||||||
|
import static org.briarproject.bramble.api.transport.TransportConstants.MAX_CLOCK_DIFFERENCE;
|
||||||
|
|
||||||
|
@Immutable
|
||||||
|
@NotNullByDefault
|
||||||
|
public abstract class BdfMessageValidator implements MessageValidator {
|
||||||
|
|
||||||
|
protected static final Logger LOG =
|
||||||
|
Logger.getLogger(BdfMessageValidator.class.getName());
|
||||||
|
|
||||||
|
protected final ClientHelper clientHelper;
|
||||||
|
protected final MetadataEncoder metadataEncoder;
|
||||||
|
protected final Clock clock;
|
||||||
|
|
||||||
|
protected BdfMessageValidator(ClientHelper clientHelper,
|
||||||
|
MetadataEncoder metadataEncoder, Clock clock) {
|
||||||
|
this.clientHelper = clientHelper;
|
||||||
|
this.metadataEncoder = metadataEncoder;
|
||||||
|
this.clock = clock;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract BdfMessageContext validateMessage(Message m, Group g,
|
||||||
|
BdfList body) throws InvalidMessageException, FormatException;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MessageContext validateMessage(Message m, Group g)
|
||||||
|
throws InvalidMessageException {
|
||||||
|
// Reject the message if it's too far in the future
|
||||||
|
long now = clock.currentTimeMillis();
|
||||||
|
if (m.getTimestamp() - now > MAX_CLOCK_DIFFERENCE) {
|
||||||
|
throw new InvalidMessageException(
|
||||||
|
"Timestamp is too far in the future");
|
||||||
|
}
|
||||||
|
byte[] raw = m.getRaw();
|
||||||
|
if (raw.length <= MESSAGE_HEADER_LENGTH) {
|
||||||
|
throw new InvalidMessageException("Message is too short");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
BdfList body = clientHelper.toList(raw, MESSAGE_HEADER_LENGTH,
|
||||||
|
raw.length - MESSAGE_HEADER_LENGTH);
|
||||||
|
BdfMessageContext result = validateMessage(m, g, body);
|
||||||
|
Metadata meta = metadataEncoder.encode(result.getDictionary());
|
||||||
|
return new MessageContext(meta, result.getDependencies());
|
||||||
|
} catch (FormatException e) {
|
||||||
|
throw new InvalidMessageException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,14 +1,14 @@
|
|||||||
package org.briarproject.api.clients;
|
package org.briarproject.bramble.api.client;
|
||||||
|
|
||||||
import org.briarproject.api.FormatException;
|
import org.briarproject.bramble.api.FormatException;
|
||||||
import org.briarproject.api.data.BdfDictionary;
|
import org.briarproject.bramble.api.data.BdfDictionary;
|
||||||
import org.briarproject.api.data.BdfList;
|
import org.briarproject.bramble.api.data.BdfList;
|
||||||
import org.briarproject.api.db.DbException;
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
import org.briarproject.api.db.Transaction;
|
import org.briarproject.bramble.api.db.Transaction;
|
||||||
import org.briarproject.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.api.sync.GroupId;
|
import org.briarproject.bramble.api.sync.GroupId;
|
||||||
import org.briarproject.api.sync.Message;
|
import org.briarproject.bramble.api.sync.Message;
|
||||||
import org.briarproject.api.sync.MessageId;
|
import org.briarproject.bramble.api.sync.MessageId;
|
||||||
|
|
||||||
import java.security.GeneralSecurityException;
|
import java.security.GeneralSecurityException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -48,7 +48,8 @@ public interface ClientHelper {
|
|||||||
BdfDictionary getGroupMetadataAsDictionary(Transaction txn, GroupId g)
|
BdfDictionary getGroupMetadataAsDictionary(Transaction txn, GroupId g)
|
||||||
throws DbException, FormatException;
|
throws DbException, FormatException;
|
||||||
|
|
||||||
BdfDictionary getMessageMetadataAsDictionary(MessageId m) throws DbException,
|
BdfDictionary getMessageMetadataAsDictionary(MessageId m)
|
||||||
|
throws DbException,
|
||||||
FormatException;
|
FormatException;
|
||||||
|
|
||||||
BdfDictionary getMessageMetadataAsDictionary(Transaction txn, MessageId m)
|
BdfDictionary getMessageMetadataAsDictionary(Transaction txn, MessageId m)
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package org.briarproject.bramble.api.client;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.contact.Contact;
|
||||||
|
import org.briarproject.bramble.api.identity.AuthorId;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.sync.ClientId;
|
||||||
|
import org.briarproject.bramble.api.sync.Group;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
|
public interface ContactGroupFactory {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a group that is not shared with any contacts.
|
||||||
|
*/
|
||||||
|
Group createLocalGroup(ClientId clientId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a group for the given client to share with the given contact.
|
||||||
|
*/
|
||||||
|
Group createContactGroup(ClientId clientId, Contact contact);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a group for the given client to share between the given authors
|
||||||
|
* identified by their AuthorIds.
|
||||||
|
*/
|
||||||
|
Group createContactGroup(ClientId clientId, AuthorId authorId1,
|
||||||
|
AuthorId authorId2);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,8 +1,13 @@
|
|||||||
package org.briarproject.api.contact;
|
package org.briarproject.bramble.api.contact;
|
||||||
|
|
||||||
import org.briarproject.api.identity.Author;
|
import org.briarproject.bramble.api.identity.Author;
|
||||||
import org.briarproject.api.identity.AuthorId;
|
import org.briarproject.bramble.api.identity.AuthorId;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
|
@Immutable
|
||||||
|
@NotNullByDefault
|
||||||
public class Contact {
|
public class Contact {
|
||||||
|
|
||||||
private final ContactId id;
|
private final ContactId id;
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package org.briarproject.bramble.api.contact;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.identity.Author;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
|
public interface ContactExchangeListener {
|
||||||
|
|
||||||
|
void contactExchangeSucceeded(Author remoteAuthor);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The exchange failed because the contact already exists.
|
||||||
|
*/
|
||||||
|
void duplicateContact(Author remoteAuthor);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A general failure.
|
||||||
|
*/
|
||||||
|
void contactExchangeFailed();
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package org.briarproject.bramble.api.contact;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.crypto.SecretKey;
|
||||||
|
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.plugin.TransportId;
|
||||||
|
import org.briarproject.bramble.api.plugin.duplex.DuplexTransportConnection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A task for conducting a contact information exchange with a remote peer.
|
||||||
|
*/
|
||||||
|
@NotNullByDefault
|
||||||
|
public interface ContactExchangeTask {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exchanges contact information with a remote peer.
|
||||||
|
*/
|
||||||
|
void startExchange(ContactExchangeListener listener,
|
||||||
|
LocalAuthor localAuthor, SecretKey masterSecret,
|
||||||
|
DuplexTransportConnection conn, TransportId transportId,
|
||||||
|
boolean alice);
|
||||||
|
}
|
||||||
@@ -1,9 +1,15 @@
|
|||||||
package org.briarproject.api.contact;
|
package org.briarproject.bramble.api.contact;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Type-safe wrapper for an integer that uniquely identifies a contact within
|
* Type-safe wrapper for an integer that uniquely identifies a contact within
|
||||||
* the scope of a single node.
|
* the scope of a single node.
|
||||||
*/
|
*/
|
||||||
|
@Immutable
|
||||||
|
@NotNullByDefault
|
||||||
public class ContactId {
|
public class ContactId {
|
||||||
|
|
||||||
private final int id;
|
private final int id;
|
||||||
@@ -1,19 +1,25 @@
|
|||||||
package org.briarproject.api.contact;
|
package org.briarproject.bramble.api.contact;
|
||||||
|
|
||||||
import org.briarproject.api.crypto.SecretKey;
|
import org.briarproject.bramble.api.crypto.SecretKey;
|
||||||
import org.briarproject.api.db.DbException;
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
import org.briarproject.api.db.Transaction;
|
import org.briarproject.bramble.api.db.Transaction;
|
||||||
import org.briarproject.api.identity.Author;
|
import org.briarproject.bramble.api.identity.Author;
|
||||||
import org.briarproject.api.identity.AuthorId;
|
import org.briarproject.bramble.api.identity.AuthorId;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
public interface ContactManager {
|
public interface ContactManager {
|
||||||
|
|
||||||
/** Registers a hook to be called whenever a contact is added. */
|
/**
|
||||||
|
* Registers a hook to be called whenever a contact is added.
|
||||||
|
*/
|
||||||
void registerAddContactHook(AddContactHook hook);
|
void registerAddContactHook(AddContactHook hook);
|
||||||
|
|
||||||
/** Registers a hook to be called whenever a contact is removed. */
|
/**
|
||||||
|
* Registers a hook to be called whenever a contact is removed.
|
||||||
|
*/
|
||||||
void registerRemoveContactHook(RemoveContactHook hook);
|
void registerRemoveContactHook(RemoveContactHook hook);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -32,27 +38,41 @@ public interface ContactManager {
|
|||||||
SecretKey master, long timestamp, boolean alice, boolean verified,
|
SecretKey master, long timestamp, boolean alice, boolean verified,
|
||||||
boolean active) throws DbException;
|
boolean active) throws DbException;
|
||||||
|
|
||||||
/** Returns the contact with the given ID. */
|
/**
|
||||||
|
* Returns the contact with the given ID.
|
||||||
|
*/
|
||||||
Contact getContact(ContactId c) throws DbException;
|
Contact getContact(ContactId c) throws DbException;
|
||||||
|
|
||||||
/** Returns all active contacts. */
|
/**
|
||||||
|
* Returns all active contacts.
|
||||||
|
*/
|
||||||
Collection<Contact> getActiveContacts() throws DbException;
|
Collection<Contact> getActiveContacts() throws DbException;
|
||||||
|
|
||||||
/** Removes a contact and all associated state. */
|
/**
|
||||||
|
* Removes a contact and all associated state.
|
||||||
|
*/
|
||||||
void removeContact(ContactId c) throws DbException;
|
void removeContact(ContactId c) throws DbException;
|
||||||
|
|
||||||
/** Removes a contact and all associated state. */
|
/**
|
||||||
|
* Removes a contact and all associated state.
|
||||||
|
*/
|
||||||
void removeContact(Transaction txn, ContactId c) throws DbException;
|
void removeContact(Transaction txn, ContactId c) throws DbException;
|
||||||
|
|
||||||
/** Marks a contact as active or inactive. */
|
/**
|
||||||
|
* Marks a contact as active or inactive.
|
||||||
|
*/
|
||||||
void setContactActive(Transaction txn, ContactId c, boolean active)
|
void setContactActive(Transaction txn, ContactId c, boolean active)
|
||||||
throws DbException;
|
throws DbException;
|
||||||
|
|
||||||
/** Return true if a contact with this name and public key already exists */
|
/**
|
||||||
|
* Return true if a contact with this name and public key already exists
|
||||||
|
*/
|
||||||
boolean contactExists(Transaction txn, AuthorId remoteAuthorId,
|
boolean contactExists(Transaction txn, AuthorId remoteAuthorId,
|
||||||
AuthorId localAuthorId) throws DbException;
|
AuthorId localAuthorId) throws DbException;
|
||||||
|
|
||||||
/** Return true if a contact with this name and public key already exists */
|
/**
|
||||||
|
* Return true if a contact with this name and public key already exists
|
||||||
|
*/
|
||||||
boolean contactExists(AuthorId remoteAuthorId, AuthorId localAuthorId)
|
boolean contactExists(AuthorId remoteAuthorId, AuthorId localAuthorId)
|
||||||
throws DbException;
|
throws DbException;
|
||||||
|
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package org.briarproject.bramble.api.contact.event;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.contact.ContactId;
|
||||||
|
import org.briarproject.bramble.api.event.Event;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An event that is broadcast when a contact is added.
|
||||||
|
*/
|
||||||
|
@Immutable
|
||||||
|
@NotNullByDefault
|
||||||
|
public class ContactAddedEvent extends Event {
|
||||||
|
|
||||||
|
private final ContactId contactId;
|
||||||
|
private final boolean active;
|
||||||
|
|
||||||
|
public ContactAddedEvent(ContactId contactId, boolean active) {
|
||||||
|
this.contactId = contactId;
|
||||||
|
this.active = active;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ContactId getContactId() {
|
||||||
|
return contactId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isActive() {
|
||||||
|
return active;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package org.briarproject.bramble.api.contact.event;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.contact.ContactId;
|
||||||
|
import org.briarproject.bramble.api.event.Event;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An event that is broadcast when a contact is removed.
|
||||||
|
*/
|
||||||
|
@Immutable
|
||||||
|
@NotNullByDefault
|
||||||
|
public class ContactRemovedEvent extends Event {
|
||||||
|
|
||||||
|
private final ContactId contactId;
|
||||||
|
|
||||||
|
public ContactRemovedEvent(ContactId contactId) {
|
||||||
|
this.contactId = contactId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ContactId getContactId() {
|
||||||
|
return contactId;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package org.briarproject.bramble.api.contact.event;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.contact.ContactId;
|
||||||
|
import org.briarproject.bramble.api.event.Event;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An event that is broadcast when a contact is marked active or inactive.
|
||||||
|
*/
|
||||||
|
@Immutable
|
||||||
|
@NotNullByDefault
|
||||||
|
public class ContactStatusChangedEvent extends Event {
|
||||||
|
|
||||||
|
private final ContactId contactId;
|
||||||
|
private final boolean active;
|
||||||
|
|
||||||
|
public ContactStatusChangedEvent(ContactId contactId, boolean active) {
|
||||||
|
this.contactId = contactId;
|
||||||
|
this.active = active;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ContactId getContactId() {
|
||||||
|
return contactId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isActive() {
|
||||||
|
return active;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package org.briarproject.bramble.api.contact.event;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.contact.ContactId;
|
||||||
|
import org.briarproject.bramble.api.event.Event;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An event that is broadcast when a contact is verified.
|
||||||
|
*/
|
||||||
|
@Immutable
|
||||||
|
@NotNullByDefault
|
||||||
|
public class ContactVerifiedEvent extends Event {
|
||||||
|
|
||||||
|
private final ContactId contactId;
|
||||||
|
|
||||||
|
public ContactVerifiedEvent(ContactId contactId) {
|
||||||
|
this.contactId = contactId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ContactId getContactId() {
|
||||||
|
return contactId;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package org.briarproject.api.crypto;
|
package org.briarproject.bramble.api.crypto;
|
||||||
|
|
||||||
import org.briarproject.api.TransportId;
|
import org.briarproject.bramble.api.plugin.TransportId;
|
||||||
import org.briarproject.api.transport.TransportKeys;
|
import org.briarproject.bramble.api.transport.TransportKeys;
|
||||||
|
|
||||||
import java.security.GeneralSecurityException;
|
import java.security.GeneralSecurityException;
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.briarproject.api.crypto;
|
package org.briarproject.bramble.api.crypto;
|
||||||
|
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.Target;
|
import java.lang.annotation.Target;
|
||||||
@@ -1,6 +1,14 @@
|
|||||||
package org.briarproject.api.crypto;
|
package org.briarproject.bramble.api.crypto;
|
||||||
|
|
||||||
/** A key pair consisting of a {@link PublicKey} and a {@link PrivateKey). */
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A key pair consisting of a {@link PublicKey} and a {@link PrivateKey).
|
||||||
|
*/
|
||||||
|
@Immutable
|
||||||
|
@NotNullByDefault
|
||||||
public class KeyPair {
|
public class KeyPair {
|
||||||
|
|
||||||
private final PublicKey publicKey;
|
private final PublicKey publicKey;
|
||||||
@@ -1,7 +1,10 @@
|
|||||||
package org.briarproject.api.crypto;
|
package org.briarproject.bramble.api.crypto;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
import java.security.GeneralSecurityException;
|
import java.security.GeneralSecurityException;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
public interface KeyParser {
|
public interface KeyParser {
|
||||||
|
|
||||||
PublicKey parsePublicKey(byte[] encodedKey) throws GeneralSecurityException;
|
PublicKey parsePublicKey(byte[] encodedKey) throws GeneralSecurityException;
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package org.briarproject.bramble.api.crypto;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
|
public interface MessageDigest {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see {@link java.security.MessageDigest#digest()}
|
||||||
|
*/
|
||||||
|
byte[] digest();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see {@link java.security.MessageDigest#digest(byte[])}
|
||||||
|
*/
|
||||||
|
byte[] digest(byte[] input);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see {@link java.security.MessageDigest#digest(byte[], int, int)}
|
||||||
|
*/
|
||||||
|
int digest(byte[] buf, int offset, int len);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see {@link java.security.MessageDigest#getDigestLength()}
|
||||||
|
*/
|
||||||
|
int getDigestLength();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see {@link java.security.MessageDigest#reset()}
|
||||||
|
*/
|
||||||
|
void reset();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see {@link java.security.MessageDigest#update(byte)}
|
||||||
|
*/
|
||||||
|
void update(byte input);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see {@link java.security.MessageDigest#update(byte[])}
|
||||||
|
*/
|
||||||
|
void update(byte[] input);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see {@link java.security.MessageDigest#update(byte[], int, int)}
|
||||||
|
*/
|
||||||
|
void update(byte[] input, int offset, int len);
|
||||||
|
}
|
||||||
@@ -1,5 +1,8 @@
|
|||||||
package org.briarproject.api.crypto;
|
package org.briarproject.bramble.api.crypto;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
public interface PasswordStrengthEstimator {
|
public interface PasswordStrengthEstimator {
|
||||||
|
|
||||||
float NONE = 0;
|
float NONE = 0;
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package org.briarproject.bramble.api.crypto;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The private half of a public/private {@link KeyPair}.
|
||||||
|
*/
|
||||||
|
@NotNullByDefault
|
||||||
|
public interface PrivateKey {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the encoded representation of this key.
|
||||||
|
*/
|
||||||
|
byte[] getEncoded();
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package org.briarproject.bramble.api.crypto;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A deterministic pseudo-random number generator.
|
||||||
|
*/
|
||||||
|
@NotNullByDefault
|
||||||
|
public interface PseudoRandom {
|
||||||
|
|
||||||
|
byte[] nextBytes(int bytes);
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package org.briarproject.bramble.api.crypto;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The public half of a public/private {@link KeyPair}.
|
||||||
|
*/
|
||||||
|
@NotNullByDefault
|
||||||
|
public interface PublicKey {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the encoded representation of this key.
|
||||||
|
*/
|
||||||
|
byte[] getEncoded();
|
||||||
|
}
|
||||||
@@ -1,9 +1,14 @@
|
|||||||
package org.briarproject.api.crypto;
|
package org.briarproject.bramble.api.crypto;
|
||||||
|
|
||||||
/** A secret key used for encryption and/or authentication. */
|
/**
|
||||||
|
* A secret key used for encryption and/or authentication.
|
||||||
|
*/
|
||||||
public class SecretKey {
|
public class SecretKey {
|
||||||
|
|
||||||
public static final int LENGTH = 32; // Bytes
|
/**
|
||||||
|
* The length of a secret key in bytes.
|
||||||
|
*/
|
||||||
|
public static final int LENGTH = 32;
|
||||||
|
|
||||||
private final byte[] key;
|
private final byte[] key;
|
||||||
|
|
||||||
@@ -1,13 +1,17 @@
|
|||||||
package org.briarproject.api.crypto;
|
package org.briarproject.bramble.api.crypto;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
public interface StreamDecrypter {
|
public interface StreamDecrypter {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads a frame, decrypts its payload into the given buffer and returns
|
* Reads a frame, decrypts its payload into the given buffer and returns
|
||||||
* the payload length, or -1 if no more frames can be read from the stream.
|
* the payload length, or -1 if no more frames can be read from the stream.
|
||||||
* @throws java.io.IOException if an error occurs while reading the frame,
|
*
|
||||||
|
* @throws IOException if an error occurs while reading the frame,
|
||||||
* or if authenticated decryption fails.
|
* or if authenticated decryption fails.
|
||||||
*/
|
*/
|
||||||
int readFrame(byte[] payload) throws IOException;
|
int readFrame(byte[] payload) throws IOException;
|
||||||
@@ -1,12 +1,16 @@
|
|||||||
package org.briarproject.api.crypto;
|
package org.briarproject.bramble.api.crypto;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.transport.StreamContext;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
import org.briarproject.api.transport.StreamContext;
|
@NotNullByDefault
|
||||||
|
|
||||||
public interface StreamDecrypterFactory {
|
public interface StreamDecrypterFactory {
|
||||||
|
|
||||||
/** Creates a {@link StreamDecrypter} for decrypting a transport stream. */
|
/**
|
||||||
|
* Creates a {@link StreamDecrypter} for decrypting a transport stream.
|
||||||
|
*/
|
||||||
StreamDecrypter createStreamDecrypter(InputStream in, StreamContext ctx);
|
StreamDecrypter createStreamDecrypter(InputStream in, StreamContext ctx);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package org.briarproject.bramble.api.crypto;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
|
public interface StreamEncrypter {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encrypts the given frame and writes it to the stream.
|
||||||
|
*/
|
||||||
|
void writeFrame(byte[] payload, int payloadLength, int paddingLength,
|
||||||
|
boolean finalFrame) throws IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flushes the stream.
|
||||||
|
*/
|
||||||
|
void flush() throws IOException;
|
||||||
|
}
|
||||||
@@ -1,12 +1,16 @@
|
|||||||
package org.briarproject.api.crypto;
|
package org.briarproject.bramble.api.crypto;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.transport.StreamContext;
|
||||||
|
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
|
||||||
import org.briarproject.api.transport.StreamContext;
|
@NotNullByDefault
|
||||||
|
|
||||||
public interface StreamEncrypterFactory {
|
public interface StreamEncrypterFactory {
|
||||||
|
|
||||||
/** Creates a {@link StreamEncrypter} for encrypting a transport stream. */
|
/**
|
||||||
|
* Creates a {@link StreamEncrypter} for encrypting a transport stream.
|
||||||
|
*/
|
||||||
StreamEncrypter createStreamEncrypter(OutputStream out, StreamContext ctx);
|
StreamEncrypter createStreamEncrypter(OutputStream out, StreamContext ctx);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package org.briarproject.api.data;
|
package org.briarproject.bramble.api.data;
|
||||||
|
|
||||||
import org.briarproject.api.Bytes;
|
import org.briarproject.bramble.api.Bytes;
|
||||||
import org.briarproject.api.FormatException;
|
import org.briarproject.bramble.api.FormatException;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentSkipListMap;
|
import java.util.concurrent.ConcurrentSkipListMap;
|
||||||
@@ -1,7 +1,13 @@
|
|||||||
package org.briarproject.api.data;
|
package org.briarproject.bramble.api.data;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
|
@Immutable
|
||||||
|
@NotNullByDefault
|
||||||
public class BdfEntry implements Entry<String, Object>, Comparable<BdfEntry> {
|
public class BdfEntry implements Entry<String, Object>, Comparable<BdfEntry> {
|
||||||
|
|
||||||
private final String key;
|
private final String key;
|
||||||
@@ -1,14 +1,15 @@
|
|||||||
package org.briarproject.api.data;
|
package org.briarproject.bramble.api.data;
|
||||||
|
|
||||||
import org.briarproject.api.Bytes;
|
import org.briarproject.bramble.api.Bytes;
|
||||||
import org.briarproject.api.FormatException;
|
import org.briarproject.bramble.api.FormatException;
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
import static org.briarproject.api.data.BdfDictionary.NULL_VALUE;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
import static org.briarproject.bramble.api.data.BdfDictionary.NULL_VALUE;
|
||||||
|
|
||||||
public class BdfList extends Vector<Object> {
|
public class BdfList extends Vector<Object> {
|
||||||
|
|
||||||
@@ -1,49 +1,75 @@
|
|||||||
package org.briarproject.api.data;
|
package org.briarproject.bramble.api.data;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
public interface BdfReader {
|
public interface BdfReader {
|
||||||
|
|
||||||
int DEFAULT_NESTED_LIMIT = 5;
|
int DEFAULT_NESTED_LIMIT = 5;
|
||||||
|
|
||||||
boolean eof() throws IOException;
|
boolean eof() throws IOException;
|
||||||
|
|
||||||
void close() throws IOException;
|
void close() throws IOException;
|
||||||
|
|
||||||
boolean hasNull() throws IOException;
|
boolean hasNull() throws IOException;
|
||||||
|
|
||||||
void readNull() throws IOException;
|
void readNull() throws IOException;
|
||||||
|
|
||||||
void skipNull() throws IOException;
|
void skipNull() throws IOException;
|
||||||
|
|
||||||
boolean hasBoolean() throws IOException;
|
boolean hasBoolean() throws IOException;
|
||||||
|
|
||||||
boolean readBoolean() throws IOException;
|
boolean readBoolean() throws IOException;
|
||||||
|
|
||||||
void skipBoolean() throws IOException;
|
void skipBoolean() throws IOException;
|
||||||
|
|
||||||
boolean hasLong() throws IOException;
|
boolean hasLong() throws IOException;
|
||||||
|
|
||||||
long readLong() throws IOException;
|
long readLong() throws IOException;
|
||||||
|
|
||||||
void skipLong() throws IOException;
|
void skipLong() throws IOException;
|
||||||
|
|
||||||
boolean hasDouble() throws IOException;
|
boolean hasDouble() throws IOException;
|
||||||
|
|
||||||
double readDouble() throws IOException;
|
double readDouble() throws IOException;
|
||||||
|
|
||||||
void skipDouble() throws IOException;
|
void skipDouble() throws IOException;
|
||||||
|
|
||||||
boolean hasString() throws IOException;
|
boolean hasString() throws IOException;
|
||||||
|
|
||||||
String readString(int maxLength) throws IOException;
|
String readString(int maxLength) throws IOException;
|
||||||
|
|
||||||
void skipString() throws IOException;
|
void skipString() throws IOException;
|
||||||
|
|
||||||
boolean hasRaw() throws IOException;
|
boolean hasRaw() throws IOException;
|
||||||
|
|
||||||
byte[] readRaw(int maxLength) throws IOException;
|
byte[] readRaw(int maxLength) throws IOException;
|
||||||
|
|
||||||
void skipRaw() throws IOException;
|
void skipRaw() throws IOException;
|
||||||
|
|
||||||
boolean hasList() throws IOException;
|
boolean hasList() throws IOException;
|
||||||
|
|
||||||
BdfList readList() throws IOException;
|
BdfList readList() throws IOException;
|
||||||
|
|
||||||
void readListStart() throws IOException;
|
void readListStart() throws IOException;
|
||||||
|
|
||||||
boolean hasListEnd() throws IOException;
|
boolean hasListEnd() throws IOException;
|
||||||
|
|
||||||
void readListEnd() throws IOException;
|
void readListEnd() throws IOException;
|
||||||
|
|
||||||
void skipList() throws IOException;
|
void skipList() throws IOException;
|
||||||
|
|
||||||
boolean hasDictionary() throws IOException;
|
boolean hasDictionary() throws IOException;
|
||||||
|
|
||||||
BdfDictionary readDictionary() throws IOException;
|
BdfDictionary readDictionary() throws IOException;
|
||||||
|
|
||||||
void readDictionaryStart() throws IOException;
|
void readDictionaryStart() throws IOException;
|
||||||
|
|
||||||
boolean hasDictionaryEnd() throws IOException;
|
boolean hasDictionaryEnd() throws IOException;
|
||||||
|
|
||||||
void readDictionaryEnd() throws IOException;
|
void readDictionaryEnd() throws IOException;
|
||||||
|
|
||||||
void skipDictionary() throws IOException;
|
void skipDictionary() throws IOException;
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,10 @@
|
|||||||
package org.briarproject.api.data;
|
package org.briarproject.bramble.api.data;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
public interface BdfReaderFactory {
|
public interface BdfReaderFactory {
|
||||||
|
|
||||||
BdfReader createReader(InputStream in);
|
BdfReader createReader(InputStream in);
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.briarproject.api.data;
|
package org.briarproject.bramble.api.data;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@@ -7,20 +7,30 @@ import java.util.Map;
|
|||||||
public interface BdfWriter {
|
public interface BdfWriter {
|
||||||
|
|
||||||
void flush() throws IOException;
|
void flush() throws IOException;
|
||||||
|
|
||||||
void close() throws IOException;
|
void close() throws IOException;
|
||||||
|
|
||||||
void writeNull() throws IOException;
|
void writeNull() throws IOException;
|
||||||
|
|
||||||
void writeBoolean(boolean b) throws IOException;
|
void writeBoolean(boolean b) throws IOException;
|
||||||
|
|
||||||
void writeLong(long l) throws IOException;
|
void writeLong(long l) throws IOException;
|
||||||
|
|
||||||
void writeDouble(double d) throws IOException;
|
void writeDouble(double d) throws IOException;
|
||||||
|
|
||||||
void writeString(String s) throws IOException;
|
void writeString(String s) throws IOException;
|
||||||
|
|
||||||
void writeRaw(byte[] b) throws IOException;
|
void writeRaw(byte[] b) throws IOException;
|
||||||
|
|
||||||
void writeList(Collection<?> c) throws IOException;
|
void writeList(Collection<?> c) throws IOException;
|
||||||
|
|
||||||
void writeListStart() throws IOException;
|
void writeListStart() throws IOException;
|
||||||
|
|
||||||
void writeListEnd() throws IOException;
|
void writeListEnd() throws IOException;
|
||||||
|
|
||||||
void writeDictionary(Map<?, ?> m) throws IOException;
|
void writeDictionary(Map<?, ?> m) throws IOException;
|
||||||
|
|
||||||
void writeDictionaryStart() throws IOException;
|
void writeDictionaryStart() throws IOException;
|
||||||
|
|
||||||
void writeDictionaryEnd() throws IOException;
|
void writeDictionaryEnd() throws IOException;
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package org.briarproject.bramble.api.data;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
import java.io.OutputStream;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
|
public interface BdfWriterFactory {
|
||||||
|
|
||||||
|
BdfWriter createWriter(OutputStream out);
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package org.briarproject.bramble.api.data;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.FormatException;
|
||||||
|
import org.briarproject.bramble.api.db.Metadata;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
|
public interface MetadataEncoder {
|
||||||
|
|
||||||
|
Metadata encode(BdfDictionary d) throws FormatException;
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package org.briarproject.bramble.api.data;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.FormatException;
|
||||||
|
import org.briarproject.bramble.api.db.Metadata;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
|
public interface MetadataParser {
|
||||||
|
|
||||||
|
BdfDictionary parse(Metadata m) throws FormatException;
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package org.briarproject.bramble.api.data;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
|
public interface ObjectReader<T> {
|
||||||
|
|
||||||
|
T readObject(BdfReader r) throws IOException;
|
||||||
|
}
|
||||||
@@ -1,9 +1,8 @@
|
|||||||
package org.briarproject.api.db;
|
package org.briarproject.bramble.api.db;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Thrown when a duplicate contact is added to the database. This exception may
|
* Thrown when a duplicate contact is added to the database. This exception may
|
||||||
* occur due to concurrent updates and does not indicate a database error.
|
* occur due to concurrent updates and does not indicate a database error.
|
||||||
*/
|
*/
|
||||||
public class ContactExistsException extends DbException {
|
public class ContactExistsException extends DbException {
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,34 +1,38 @@
|
|||||||
package org.briarproject.api.db;
|
package org.briarproject.bramble.api.db;
|
||||||
|
|
||||||
import org.briarproject.api.TransportId;
|
import org.briarproject.bramble.api.contact.Contact;
|
||||||
import org.briarproject.api.contact.Contact;
|
import org.briarproject.bramble.api.contact.ContactId;
|
||||||
import org.briarproject.api.contact.ContactId;
|
import org.briarproject.bramble.api.identity.Author;
|
||||||
import org.briarproject.api.identity.Author;
|
import org.briarproject.bramble.api.identity.AuthorId;
|
||||||
import org.briarproject.api.identity.AuthorId;
|
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||||
import org.briarproject.api.identity.LocalAuthor;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.api.settings.Settings;
|
import org.briarproject.bramble.api.plugin.TransportId;
|
||||||
import org.briarproject.api.sync.Ack;
|
import org.briarproject.bramble.api.settings.Settings;
|
||||||
import org.briarproject.api.sync.ClientId;
|
import org.briarproject.bramble.api.sync.Ack;
|
||||||
import org.briarproject.api.sync.Group;
|
import org.briarproject.bramble.api.sync.ClientId;
|
||||||
import org.briarproject.api.sync.Group.Visibility;
|
import org.briarproject.bramble.api.sync.Group;
|
||||||
import org.briarproject.api.sync.GroupId;
|
import org.briarproject.bramble.api.sync.Group.Visibility;
|
||||||
import org.briarproject.api.sync.Message;
|
import org.briarproject.bramble.api.sync.GroupId;
|
||||||
import org.briarproject.api.sync.MessageId;
|
import org.briarproject.bramble.api.sync.Message;
|
||||||
import org.briarproject.api.sync.MessageStatus;
|
import org.briarproject.bramble.api.sync.MessageId;
|
||||||
import org.briarproject.api.sync.Offer;
|
import org.briarproject.bramble.api.sync.MessageStatus;
|
||||||
import org.briarproject.api.sync.Request;
|
import org.briarproject.bramble.api.sync.Offer;
|
||||||
import org.briarproject.api.transport.TransportKeys;
|
import org.briarproject.bramble.api.sync.Request;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.briarproject.bramble.api.sync.ValidationManager;
|
||||||
|
import org.briarproject.bramble.api.transport.TransportKeys;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.briarproject.api.sync.ValidationManager.State;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
import static org.briarproject.bramble.api.sync.ValidationManager.State;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encapsulates the database implementation and exposes high-level operations
|
* Encapsulates the database implementation and exposes high-level operations
|
||||||
* to other components.
|
* to other components.
|
||||||
*/
|
*/
|
||||||
|
@NotNullByDefault
|
||||||
public interface DatabaseComponent {
|
public interface DatabaseComponent {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -330,10 +334,10 @@ public interface DatabaseComponent {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the IDs and states of all dependencies of the given message.
|
* Returns the IDs and states of all dependencies of the given message.
|
||||||
* Missing dependencies have the state {@link
|
* Missing dependencies have the state
|
||||||
* org.briarproject.api.sync.ValidationManager.State UNKNOWN}.
|
* {@link ValidationManager.State UNKNOWN}.
|
||||||
* Dependencies in other groups have the state {@link
|
* Dependencies in other groups have the state
|
||||||
* org.briarproject.api.sync.ValidationManager.State INVALID}.
|
* {@link ValidationManager.State INVALID}.
|
||||||
* Note that these states are not set on the dependencies themselves; the
|
* Note that these states are not set on the dependencies themselves; the
|
||||||
* returned states should only be taken in the context of the given message.
|
* returned states should only be taken in the context of the given message.
|
||||||
* <p/>
|
* <p/>
|
||||||
@@ -1,9 +1,13 @@
|
|||||||
package org.briarproject.api.db;
|
package org.briarproject.bramble.api.db;
|
||||||
|
|
||||||
import org.briarproject.api.crypto.SecretKey;
|
import org.briarproject.bramble.api.crypto.SecretKey;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
public interface DatabaseConfig {
|
public interface DatabaseConfig {
|
||||||
|
|
||||||
boolean databaseExists();
|
boolean databaseExists();
|
||||||
@@ -12,10 +16,12 @@ public interface DatabaseConfig {
|
|||||||
|
|
||||||
void setEncryptionKey(SecretKey key);
|
void setEncryptionKey(SecretKey key);
|
||||||
|
|
||||||
|
@Nullable
|
||||||
SecretKey getEncryptionKey();
|
SecretKey getEncryptionKey();
|
||||||
|
|
||||||
void setLocalAuthorName(String nickname);
|
void setLocalAuthorName(String nickname);
|
||||||
|
|
||||||
|
@Nullable
|
||||||
String getLocalAuthorName();
|
String getLocalAuthorName();
|
||||||
|
|
||||||
long getMaxSize();
|
long getMaxSize();
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.briarproject.api.db;
|
package org.briarproject.bramble.api.db;
|
||||||
|
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.Target;
|
import java.lang.annotation.Target;
|
||||||
@@ -20,6 +20,7 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
|||||||
* discarded.
|
* discarded.
|
||||||
*/
|
*/
|
||||||
@Qualifier
|
@Qualifier
|
||||||
@Target({ FIELD, METHOD, PARAMETER })
|
@Target({FIELD, METHOD, PARAMETER})
|
||||||
@Retention(RUNTIME)
|
@Retention(RUNTIME)
|
||||||
public @interface DatabaseExecutor {}
|
public @interface DatabaseExecutor {
|
||||||
|
}
|
||||||
@@ -1,8 +1,7 @@
|
|||||||
package org.briarproject.api.db;
|
package org.briarproject.bramble.api.db;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Thrown when a database operation is attempted and the database is closed.
|
* Thrown when a database operation is attempted and the database is closed.
|
||||||
*/
|
*/
|
||||||
public class DbClosedException extends DbException {
|
public class DbClosedException extends DbException {
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.briarproject.api.db;
|
package org.briarproject.bramble.api.db;
|
||||||
|
|
||||||
public class DbException extends Exception {
|
public class DbException extends Exception {
|
||||||
|
|
||||||
@@ -1,7 +1,10 @@
|
|||||||
package org.briarproject.api.db;
|
package org.briarproject.bramble.api.db;
|
||||||
|
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
|
|
||||||
|
import javax.annotation.concurrent.ThreadSafe;
|
||||||
|
|
||||||
|
@ThreadSafe
|
||||||
public class Metadata extends Hashtable<String, byte[]> {
|
public class Metadata extends Hashtable<String, byte[]> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.briarproject.api.db;
|
package org.briarproject.bramble.api.db;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Thrown when a database operation is attempted for a contact that is not in
|
* Thrown when a database operation is attempted for a contact that is not in
|
||||||
@@ -6,5 +6,4 @@ package org.briarproject.api.db;
|
|||||||
* not indicate a database error.
|
* not indicate a database error.
|
||||||
*/
|
*/
|
||||||
public class NoSuchContactException extends DbException {
|
public class NoSuchContactException extends DbException {
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.briarproject.api.db;
|
package org.briarproject.bramble.api.db;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Thrown when a database operation is attempted for a group that is not in the
|
* Thrown when a database operation is attempted for a group that is not in the
|
||||||
@@ -6,5 +6,4 @@ package org.briarproject.api.db;
|
|||||||
* indicate a database error.
|
* indicate a database error.
|
||||||
*/
|
*/
|
||||||
public class NoSuchGroupException extends DbException {
|
public class NoSuchGroupException extends DbException {
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.briarproject.api.db;
|
package org.briarproject.bramble.api.db;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Thrown when a database operation is attempted for a pseudonym that is not in
|
* Thrown when a database operation is attempted for a pseudonym that is not in
|
||||||
@@ -6,5 +6,4 @@ package org.briarproject.api.db;
|
|||||||
* not indicate a database error.
|
* not indicate a database error.
|
||||||
*/
|
*/
|
||||||
public class NoSuchLocalAuthorException extends DbException {
|
public class NoSuchLocalAuthorException extends DbException {
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.briarproject.api.db;
|
package org.briarproject.bramble.api.db;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Thrown when a database operation is attempted for a message that is not in
|
* Thrown when a database operation is attempted for a message that is not in
|
||||||
@@ -6,5 +6,4 @@ package org.briarproject.api.db;
|
|||||||
* not indicate a database error.
|
* not indicate a database error.
|
||||||
*/
|
*/
|
||||||
public class NoSuchMessageException extends DbException {
|
public class NoSuchMessageException extends DbException {
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.briarproject.api.db;
|
package org.briarproject.bramble.api.db;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Thrown when a database operation is attempted for a transport that is not in
|
* Thrown when a database operation is attempted for a transport that is not in
|
||||||
@@ -6,5 +6,4 @@ package org.briarproject.api.db;
|
|||||||
* not indicate a database error.
|
* not indicate a database error.
|
||||||
*/
|
*/
|
||||||
public class NoSuchTransportException extends DbException {
|
public class NoSuchTransportException extends DbException {
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,14 +1,17 @@
|
|||||||
package org.briarproject.api.db;
|
package org.briarproject.bramble.api.db;
|
||||||
|
|
||||||
import org.briarproject.api.event.Event;
|
import org.briarproject.bramble.api.event.Event;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.annotation.concurrent.NotThreadSafe;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A wrapper around a database transaction. Transactions are not thread-safe.
|
* A wrapper around a database transaction. Transactions are not thread-safe.
|
||||||
*/
|
*/
|
||||||
|
@NotThreadSafe
|
||||||
public class Transaction {
|
public class Transaction {
|
||||||
|
|
||||||
private final Object txn;
|
private final Object txn;
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package org.briarproject.bramble.api.event;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An abstract superclass for events.
|
||||||
|
*/
|
||||||
|
public abstract class Event {
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package org.briarproject.bramble.api.event;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
|
public interface EventBus {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a listener to be notified when events occur.
|
||||||
|
*/
|
||||||
|
void addListener(EventListener l);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a listener.
|
||||||
|
*/
|
||||||
|
void removeListener(EventListener l);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notifies all listeners of an event.
|
||||||
|
*/
|
||||||
|
void broadcast(Event e);
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package org.briarproject.bramble.api.event;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An interface for receiving notifications when events occur.
|
||||||
|
*/
|
||||||
|
@NotNullByDefault
|
||||||
|
public interface EventListener {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when an event is broadcast. Implementations of this method must
|
||||||
|
* not block.
|
||||||
|
*/
|
||||||
|
void eventOccurred(Event e);
|
||||||
|
}
|
||||||
@@ -1,11 +1,19 @@
|
|||||||
package org.briarproject.api.identity;
|
package org.briarproject.bramble.api.identity;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
|
|
||||||
/** A pseudonym for a user. */
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A pseudonym for a user.
|
||||||
|
*/
|
||||||
|
@Immutable
|
||||||
|
@NotNullByDefault
|
||||||
public class Author {
|
public class Author {
|
||||||
|
|
||||||
public enum Status { ANONYMOUS, UNKNOWN, UNVERIFIED, VERIFIED, OURSELVES }
|
public enum Status {ANONYMOUS, UNKNOWN, UNVERIFIED, VERIFIED, OURSELVES}
|
||||||
|
|
||||||
private final AuthorId id;
|
private final AuthorId id;
|
||||||
private final String name;
|
private final String name;
|
||||||
@@ -25,17 +33,23 @@ public class Author {
|
|||||||
this.publicKey = publicKey;
|
this.publicKey = publicKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the author's unique identifier. */
|
/**
|
||||||
|
* Returns the author's unique identifier.
|
||||||
|
*/
|
||||||
public AuthorId getId() {
|
public AuthorId getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the author's name. */
|
/**
|
||||||
|
* Returns the author's name.
|
||||||
|
*/
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the public key used to verify the pseudonym's signatures. */
|
/**
|
||||||
|
* Returns the public key used to verify the pseudonym's signatures.
|
||||||
|
*/
|
||||||
public byte[] getPublicKey() {
|
public byte[] getPublicKey() {
|
||||||
return publicKey;
|
return publicKey;
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,10 @@
|
|||||||
package org.briarproject.api.identity;
|
package org.briarproject.bramble.api.identity;
|
||||||
|
|
||||||
public interface AuthorConstants {
|
public interface AuthorConstants {
|
||||||
|
|
||||||
/** The maximum length of an author's name in UTF-8 bytes. */
|
/**
|
||||||
|
* The maximum length of an author's name in UTF-8 bytes.
|
||||||
|
*/
|
||||||
int MAX_AUTHOR_NAME_LENGTH = 50;
|
int MAX_AUTHOR_NAME_LENGTH = 50;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1,5 +1,8 @@
|
|||||||
package org.briarproject.api.identity;
|
package org.briarproject.bramble.api.identity;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
public interface AuthorFactory {
|
public interface AuthorFactory {
|
||||||
|
|
||||||
Author createAuthor(String name, byte[] publicKey);
|
Author createAuthor(String name, byte[] publicKey);
|
||||||
@@ -1,13 +1,18 @@
|
|||||||
package org.briarproject.api.identity;
|
package org.briarproject.bramble.api.identity;
|
||||||
|
|
||||||
import org.briarproject.api.UniqueId;
|
import org.briarproject.bramble.api.UniqueId;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
|
||||||
|
import javax.annotation.concurrent.ThreadSafe;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Type-safe wrapper for a byte array that uniquely identifies an
|
* Type-safe wrapper for a byte array that uniquely identifies an
|
||||||
* {@link org.briarproject.api.identity.Author Author}.
|
* {@link Author}.
|
||||||
*/
|
*/
|
||||||
|
@ThreadSafe
|
||||||
|
@NotNullByDefault
|
||||||
public class AuthorId extends UniqueId {
|
public class AuthorId extends UniqueId {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package org.briarproject.bramble.api.identity;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
|
import org.briarproject.bramble.api.db.Transaction;
|
||||||
|
import org.briarproject.bramble.api.identity.Author.Status;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
|
public interface IdentityManager {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores the local pseudonym.
|
||||||
|
*/
|
||||||
|
void registerLocalAuthor(LocalAuthor a) throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the cached main local identity, non-blocking, or loads it from
|
||||||
|
* the db, blocking
|
||||||
|
*/
|
||||||
|
LocalAuthor getLocalAuthor() throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the cached main local identity, non-blocking, or loads it from
|
||||||
|
* the db, blocking, within the given Transaction.
|
||||||
|
*/
|
||||||
|
LocalAuthor getLocalAuthor(Transaction txn) throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the trust-level status of the author
|
||||||
|
*/
|
||||||
|
Status getAuthorStatus(AuthorId a) throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the trust-level status of the author
|
||||||
|
*/
|
||||||
|
Status getAuthorStatus(Transaction txn, AuthorId a) throws DbException;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,6 +1,14 @@
|
|||||||
package org.briarproject.api.identity;
|
package org.briarproject.bramble.api.identity;
|
||||||
|
|
||||||
/** A pseudonym for the local user. */
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A pseudonym for the local user.
|
||||||
|
*/
|
||||||
|
@Immutable
|
||||||
|
@NotNullByDefault
|
||||||
public class LocalAuthor extends Author {
|
public class LocalAuthor extends Author {
|
||||||
|
|
||||||
private final byte[] privateKey;
|
private final byte[] privateKey;
|
||||||
@@ -13,7 +21,9 @@ public class LocalAuthor extends Author {
|
|||||||
this.created = created;
|
this.created = created;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the private key used to generate the pseudonym's signatures. */
|
/**
|
||||||
|
* Returns the private key used to generate the pseudonym's signatures.
|
||||||
|
*/
|
||||||
public byte[] getPrivateKey() {
|
public byte[] getPrivateKey() {
|
||||||
return privateKey;
|
return privateKey;
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package org.briarproject.bramble.api.identity.event;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.event.Event;
|
||||||
|
import org.briarproject.bramble.api.identity.AuthorId;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An event that is broadcast when a local pseudonym is added.
|
||||||
|
*/
|
||||||
|
@Immutable
|
||||||
|
@NotNullByDefault
|
||||||
|
public class LocalAuthorAddedEvent extends Event {
|
||||||
|
|
||||||
|
private final AuthorId authorId;
|
||||||
|
|
||||||
|
public LocalAuthorAddedEvent(AuthorId authorId) {
|
||||||
|
this.authorId = authorId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AuthorId getAuthorId() {
|
||||||
|
return authorId;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package org.briarproject.bramble.api.identity.event;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.event.Event;
|
||||||
|
import org.briarproject.bramble.api.identity.AuthorId;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An event that is broadcast when a local pseudonym is removed.
|
||||||
|
*/
|
||||||
|
@Immutable
|
||||||
|
@NotNullByDefault
|
||||||
|
public class LocalAuthorRemovedEvent extends Event {
|
||||||
|
|
||||||
|
private final AuthorId authorId;
|
||||||
|
|
||||||
|
public LocalAuthorRemovedEvent(AuthorId authorId) {
|
||||||
|
this.authorId = authorId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AuthorId getAuthorId() {
|
||||||
|
return authorId;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package org.briarproject.bramble.api.invitation;
|
||||||
|
|
||||||
|
public interface InvitationConstants {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The connection timeout in milliseconds.
|
||||||
|
*/
|
||||||
|
long CONNECTION_TIMEOUT = 60 * 1000;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The confirmation timeout in milliseconds.
|
||||||
|
*/
|
||||||
|
long CONFIRMATION_TIMEOUT = 60 * 1000;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The number of bits in an invitation or confirmation code. Codes must fit
|
||||||
|
* into six decimal digits.
|
||||||
|
*/
|
||||||
|
int CODE_BITS = 19;
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.briarproject.api.invitation;
|
package org.briarproject.bramble.api.invitation;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An interface for receiving updates about the state of an
|
* An interface for receiving updates about the state of an
|
||||||
@@ -1,5 +1,15 @@
|
|||||||
package org.briarproject.api.invitation;
|
package org.briarproject.bramble.api.invitation;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A snapshot of the state of an {@link InvitationTask}.
|
||||||
|
*/
|
||||||
|
@Immutable
|
||||||
|
@NotNullByDefault
|
||||||
public class InvitationState {
|
public class InvitationState {
|
||||||
|
|
||||||
private final int localInvitationCode, remoteInvitationCode;
|
private final int localInvitationCode, remoteInvitationCode;
|
||||||
@@ -7,13 +17,14 @@ public class InvitationState {
|
|||||||
private final boolean connected, connectionFailed;
|
private final boolean connected, connectionFailed;
|
||||||
private final boolean localCompared, remoteCompared;
|
private final boolean localCompared, remoteCompared;
|
||||||
private final boolean localMatched, remoteMatched;
|
private final boolean localMatched, remoteMatched;
|
||||||
|
@Nullable
|
||||||
private final String contactName;
|
private final String contactName;
|
||||||
|
|
||||||
public InvitationState(int localInvitationCode, int remoteInvitationCode,
|
public InvitationState(int localInvitationCode, int remoteInvitationCode,
|
||||||
int localConfirmationCode, int remoteConfirmationCode,
|
int localConfirmationCode, int remoteConfirmationCode,
|
||||||
boolean connected, boolean connectionFailed, boolean localCompared,
|
boolean connected, boolean connectionFailed, boolean localCompared,
|
||||||
boolean remoteCompared, boolean localMatched,
|
boolean remoteCompared, boolean localMatched,
|
||||||
boolean remoteMatched, String contactName) {
|
boolean remoteMatched, @Nullable String contactName) {
|
||||||
this.localInvitationCode = localInvitationCode;
|
this.localInvitationCode = localInvitationCode;
|
||||||
this.remoteInvitationCode = remoteInvitationCode;
|
this.remoteInvitationCode = remoteInvitationCode;
|
||||||
this.localConfirmationCode = localConfirmationCode;
|
this.localConfirmationCode = localConfirmationCode;
|
||||||
@@ -67,6 +78,7 @@ public class InvitationState {
|
|||||||
return remoteMatched;
|
return remoteMatched;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public String getContactName() {
|
public String getContactName() {
|
||||||
return contactName;
|
return contactName;
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,11 @@
|
|||||||
package org.briarproject.api.invitation;
|
package org.briarproject.bramble.api.invitation;
|
||||||
|
|
||||||
/** A task for exchanging invitations with a remote peer. */
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A task for exchanging invitations with a remote peer.
|
||||||
|
*/
|
||||||
|
@NotNullByDefault
|
||||||
public interface InvitationTask {
|
public interface InvitationTask {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -9,10 +14,14 @@ public interface InvitationTask {
|
|||||||
*/
|
*/
|
||||||
InvitationState addListener(InvitationListener l);
|
InvitationState addListener(InvitationListener l);
|
||||||
|
|
||||||
/** Removes the given listener. */
|
/**
|
||||||
|
* Removes the given listener.
|
||||||
|
*/
|
||||||
void removeListener(InvitationListener l);
|
void removeListener(InvitationListener l);
|
||||||
|
|
||||||
/** Asynchronously starts the connection process. */
|
/**
|
||||||
|
* Asynchronously starts the connection process.
|
||||||
|
*/
|
||||||
void connect();
|
void connect();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package org.briarproject.bramble.api.invitation;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates tasks for exchanging invitations with remote peers.
|
||||||
|
*/
|
||||||
|
@NotNullByDefault
|
||||||
|
public interface InvitationTaskFactory {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a task using the given local and remote invitation codes.
|
||||||
|
*/
|
||||||
|
InvitationTask createTask(int localCode, int remoteCode);
|
||||||
|
}
|
||||||
@@ -1,9 +1,15 @@
|
|||||||
package org.briarproject.api.keyagreement;
|
package org.briarproject.bramble.api.keyagreement;
|
||||||
|
|
||||||
import org.briarproject.api.TransportId;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexTransportConnection;
|
import org.briarproject.bramble.api.plugin.TransportId;
|
||||||
|
import org.briarproject.bramble.api.plugin.duplex.DuplexTransportConnection;
|
||||||
|
|
||||||
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
|
@Immutable
|
||||||
|
@NotNullByDefault
|
||||||
public class KeyAgreementConnection {
|
public class KeyAgreementConnection {
|
||||||
|
|
||||||
private final DuplexTransportConnection conn;
|
private final DuplexTransportConnection conn;
|
||||||
private final TransportId id;
|
private final TransportId id;
|
||||||
|
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package org.briarproject.bramble.api.keyagreement;
|
||||||
|
|
||||||
|
public interface KeyAgreementConstants {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The current version of the BQP protocol.
|
||||||
|
*/
|
||||||
|
byte PROTOCOL_VERSION = 2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The length of the record header in bytes.
|
||||||
|
*/
|
||||||
|
int RECORD_HEADER_LENGTH = 4;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The offset of the payload length in the record header, in bytes.
|
||||||
|
*/
|
||||||
|
int RECORD_HEADER_PAYLOAD_LENGTH_OFFSET = 2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The length of the BQP key commitment in bytes.
|
||||||
|
*/
|
||||||
|
int COMMIT_LENGTH = 16;
|
||||||
|
|
||||||
|
long CONNECTION_TIMEOUT = 20 * 1000; // Milliseconds
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The transport identifier for Bluetooth.
|
||||||
|
*/
|
||||||
|
int TRANSPORT_ID_BLUETOOTH = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The transport identifier for LAN.
|
||||||
|
*/
|
||||||
|
int TRANSPORT_ID_LAN = 1;
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
package org.briarproject.api.keyagreement;
|
package org.briarproject.bramble.api.keyagreement;
|
||||||
|
|
||||||
import org.briarproject.api.data.BdfList;
|
import org.briarproject.bramble.api.data.BdfList;
|
||||||
|
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
|
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
package org.briarproject.api.keyagreement;
|
package org.briarproject.bramble.api.keyagreement;
|
||||||
|
|
||||||
import org.briarproject.api.TransportId;
|
import org.briarproject.bramble.api.crypto.SecretKey;
|
||||||
import org.briarproject.api.crypto.SecretKey;
|
import org.briarproject.bramble.api.plugin.TransportId;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexTransportConnection;
|
import org.briarproject.bramble.api.plugin.duplex.DuplexTransportConnection;
|
||||||
|
|
||||||
public class KeyAgreementResult {
|
public class KeyAgreementResult {
|
||||||
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user