feat: connect through the OpenChamber private relay
A server can now be added by pasting an openchamber://connect pairing link. The one-time secret is redeemed over the first reachable candidate (direct addresses first, then the relay), and the device token is stored with the connection, so later launches reconnect without the link. The relay candidate carries the relay WebSocket URL, the host's routing id and its P-256 public key. The new transport opens one encrypted tunnel to the relay: P-256 ECDH + HKDF-SHA256 derive one AES-256-GCM key per direction; frames carry a version, a 12-byte IV and the GCM tag; a small mux carries HTTP, SSE and WebSocket sub-streams with fragmentation and ping/pong. Every request and the terminal socket ride it; WebSocket upgrades first mint the short-lived oc_url_token over the tunnel, since upgrades cannot send headers. Only the host's legacy path is negotiated (no batching, downstream flow control or body gzip). Pairing while connected switches servers like picking one in the list, which exposed and fixes a ChatScreen crash when app.chat is cleared during the switch. 0.4.4 (404).
This commit is contained in:
1 parent
a7bc380ac0
commit
902f1e18bb
20 files changed
+1918
-75
No files matched your search
+33
-2
@@ -15,6 +15,14 @@ class Connection {
|
||||
final bool insecure;
|
||||
final String fingerprint;
|
||||
final int lastUsedAt;
|
||||
|
||||
/// Set for a server reached through the private relay. The host's public
|
||||
/// key (JSON JWK) is the E2EE trust anchor from the pairing link.
|
||||
final String relayUrl;
|
||||
final String serverId;
|
||||
final String hostKey;
|
||||
final String grant;
|
||||
|
||||
Connection({
|
||||
required this.id,
|
||||
required this.label,
|
||||
@@ -23,8 +31,15 @@ class Connection {
|
||||
this.insecure = false,
|
||||
this.fingerprint = '',
|
||||
this.lastUsedAt = 0,
|
||||
this.relayUrl = '',
|
||||
this.serverId = '',
|
||||
this.hostKey = '',
|
||||
this.grant = '',
|
||||
});
|
||||
|
||||
bool get isRelay =>
|
||||
relayUrl.isNotEmpty && serverId.isNotEmpty && hostKey.isNotEmpty;
|
||||
|
||||
factory Connection.fromJson(Map<String, dynamic> j) => Connection(
|
||||
id: j['id'] as String? ?? '',
|
||||
label: j['label'] as String? ?? '',
|
||||
@@ -33,6 +48,10 @@ class Connection {
|
||||
insecure: j['insecure'] as bool? ?? false,
|
||||
fingerprint: j['fingerprint'] as String? ?? '',
|
||||
lastUsedAt: (j['lastUsedAt'] as num?)?.toInt() ?? 0,
|
||||
relayUrl: j['relayUrl'] as String? ?? '',
|
||||
serverId: j['serverId'] as String? ?? '',
|
||||
hostKey: j['hostKey'] as String? ?? '',
|
||||
grant: j['grant'] as String? ?? '',
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
@@ -43,6 +62,10 @@ class Connection {
|
||||
'insecure': insecure,
|
||||
'fingerprint': fingerprint,
|
||||
'lastUsedAt': lastUsedAt,
|
||||
if (relayUrl.isNotEmpty) 'relayUrl': relayUrl,
|
||||
if (serverId.isNotEmpty) 'serverId': serverId,
|
||||
if (hostKey.isNotEmpty) 'hostKey': hostKey,
|
||||
if (grant.isNotEmpty) 'grant': grant,
|
||||
};
|
||||
|
||||
Connection copyWith({
|
||||
@@ -52,6 +75,10 @@ class Connection {
|
||||
bool? insecure,
|
||||
String? fingerprint,
|
||||
int? lastUsedAt,
|
||||
String? relayUrl,
|
||||
String? serverId,
|
||||
String? hostKey,
|
||||
String? grant,
|
||||
}) =>
|
||||
Connection(
|
||||
id: id,
|
||||
@@ -61,6 +88,10 @@ class Connection {
|
||||
insecure: insecure ?? this.insecure,
|
||||
fingerprint: fingerprint ?? this.fingerprint,
|
||||
lastUsedAt: lastUsedAt ?? this.lastUsedAt,
|
||||
relayUrl: relayUrl ?? this.relayUrl,
|
||||
serverId: serverId ?? this.serverId,
|
||||
hostKey: hostKey ?? this.hostKey,
|
||||
grant: grant ?? this.grant,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -187,7 +218,7 @@ class Storage {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
var id = prefs.getString(_installKey);
|
||||
if (id == null || id.isEmpty) {
|
||||
id = _newId();
|
||||
id = newId();
|
||||
await prefs.setString(_installKey, id);
|
||||
}
|
||||
return id;
|
||||
@@ -210,7 +241,7 @@ class Storage {
|
||||
return 'openchamber.token.$digest';
|
||||
}
|
||||
|
||||
static String _newId() =>
|
||||
static String newId() =>
|
||||
'srv_${DateTime.now().microsecondsSinceEpoch.toRadixString(36)}${(_rand() & 0xffffff).toRadixString(36).padLeft(6, '0')}';
|
||||
|
||||
static int _rand() => DateTime.now().microsecondsSinceEpoch % 0xffffffff;
|
||||
|
||||
Reference in new issue
Block a user