v0.9.5: bubble for Android 0.7.8 — the relay is just a relay server: its address is a setting, and deploy-relay.sh reads scripts/relay.env
This commit is contained in:
@@ -53,7 +53,7 @@ final class Config {
|
||||
final List<Did> dids = new CopyOnWriteArrayList<>();
|
||||
private boolean hasSim;
|
||||
String defaultDid;
|
||||
/** The relay through jai (Relay.java): address, bearer token, and the 32-byte key that seals everything. */
|
||||
/** The relay server (Relay.java): address, bearer token, and the 32-byte key that seals everything. */
|
||||
String relayUrl, relayToken;
|
||||
byte[] relayKey;
|
||||
/** Made-up data for testing (android/tools/push_sandbox.py): never goes online. */
|
||||
@@ -127,8 +127,8 @@ final class Config {
|
||||
if (r != null) {
|
||||
String url = r.optString("url", ""), token = r.optString("token", "");
|
||||
byte[] key = android.util.Base64.decode(r.optString("key", ""), android.util.Base64.DEFAULT);
|
||||
// Only the addresses network_security_config lets through, and a real key.
|
||||
if (url.matches("http://(100\\.\\d+\\.\\d+\\.\\d+|127\\.0\\.0\\.1)(:\\d+)?|https://[^/]+") && !token.isEmpty() && key.length == 32) {
|
||||
// Plain http only to a tailscale (100.64/10) address or localhost, as the desktop allows, and a real key.
|
||||
if (url.matches("http://(100\\.(6[4-9]|[7-9]\\d|1[01]\\d|12[0-7])\\.\\d+\\.\\d+|127\\.0\\.0\\.1)(:\\d+)?|https://[^/]+") && !token.isEmpty() && key.length == 32) {
|
||||
cfg.relayUrl = url;
|
||||
cfg.relayToken = token;
|
||||
cfg.relayKey = key;
|
||||
|
||||
@@ -28,13 +28,13 @@ import javax.crypto.spec.GCMParameterSpec;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
|
||||
/**
|
||||
* The relay through jai (the desktop's src/main/relay.ts; server in
|
||||
* The relay server (the desktop's src/main/relay.ts; server in
|
||||
* server/bubble_relay.py): the SIM's texts go to the desktop, texts typed
|
||||
* there go out over the SIM here, and chat names and read/unread/archived
|
||||
* stay in step without a cable.
|
||||
*
|
||||
* Everything is AES-256-GCM sealed with the key the desktop handed over USB
|
||||
* (config.json "relay"); jai only passes blobs on. It runs with the checks
|
||||
* (config.json "relay"); the relay server only passes blobs on. It runs with the checks
|
||||
* the Rabbit already makes (PollJob) plus one network job after something
|
||||
* happens here (a text, a send, a swipe), never on a timer of its own: the
|
||||
* battery pays for nothing new while nothing's going on.
|
||||
@@ -141,7 +141,7 @@ final class Relay {
|
||||
|
||||
// ---- one sync ----
|
||||
|
||||
/** One round with jai (more while there's more). Off the main thread; quiet when jai's unreachable. */
|
||||
/** One round with the relay server (more while there's more). Off the main thread; quiet when it's unreachable. */
|
||||
static void sync(Context c) {
|
||||
Config cfg = Config.get(c);
|
||||
if (!configured(cfg)) return;
|
||||
@@ -241,11 +241,11 @@ final class Relay {
|
||||
h.put("Authorization", "Bearer " + cfg.relayToken);
|
||||
h.put("Content-Type", "application/json");
|
||||
Http.Response r = Http.request("POST", cfg.relayUrl + "/sync", h, body, 120_000);
|
||||
if (r.status == 401) throw new Exception("jai turned down the token (Sync to Rabbit from the desktop again)");
|
||||
if (r.status != 200) throw new Exception("jai answered " + r.status);
|
||||
if (r.status == 401) throw new Exception("The relay server turned down the token (Sync to Rabbit from the desktop again)");
|
||||
if (r.status != 200) throw new Exception("The relay server answered " + r.status);
|
||||
JSONObject res = new JSONObject(new String(r.body, StandardCharsets.UTF_8));
|
||||
|
||||
// jai has them now.
|
||||
// The relay server has them now.
|
||||
if (resultsPushed > 0) takeList(c, "results", resultsPushed);
|
||||
if (wantsDone > 0) takeList(c, "wants", wantsDone);
|
||||
SharedPreferences.Editor ed = p.edit().putLong("smsLast", newSms[0]).putLong("mmsLast", newMms[0]);
|
||||
|
||||
@@ -144,7 +144,7 @@ public final class SettingsActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
if (Relay.configured(cfg)) {
|
||||
section("Relay (jai)");
|
||||
section("Relay server");
|
||||
kv("Desktop link", Relay.status(c));
|
||||
note("Texts typed on the desktop for \"via SIM\" go out at this Rabbit's background check, and chat names and read status"
|
||||
+ " go both ways. Sealed with a key only the desktop and this Rabbit have.");
|
||||
|
||||
Reference in New Issue
Block a user