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
-1
@@ -6,6 +6,7 @@ import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import '../version.dart';
|
||||
import 'models.dart';
|
||||
import 'terminal.dart';
|
||||
import 'transport.dart';
|
||||
@@ -24,7 +25,15 @@ class Client {
|
||||
/// Every request and the event stream go through here; today a direct
|
||||
/// connection, later one that can also be a relay tunnel.
|
||||
final Transport transport;
|
||||
String? token;
|
||||
String? _token;
|
||||
|
||||
/// The bearer this client authenticates with. A relay transport is told too,
|
||||
/// because it must mint URL-scoped tokens for WebSocket upgrades.
|
||||
String? get token => _token;
|
||||
set token(String? value) {
|
||||
_token = value;
|
||||
transport.setBearerToken(value);
|
||||
}
|
||||
|
||||
Client(
|
||||
this.base, {
|
||||
@@ -38,6 +47,29 @@ class Client {
|
||||
|
||||
String get baseUrl => base.toString();
|
||||
|
||||
/// Redeems a pairing link's one-time secret over whichever transport this
|
||||
/// client uses, and returns the device token.
|
||||
Future<({String token, Map<String, dynamic> response})> redeemPairing({
|
||||
required String pairingId,
|
||||
required String secret,
|
||||
required String installId,
|
||||
String clientLabel = 'OpenChamber Native',
|
||||
String clientKind = 'mobile',
|
||||
String? deviceName,
|
||||
}) async {
|
||||
final r = await _json('POST', '/api/client-auth/pairing/redeem', body: {
|
||||
'pairingId': pairingId,
|
||||
'secret': secret,
|
||||
'clientLabel': clientLabel,
|
||||
'clientKind': clientKind,
|
||||
'deviceName': deviceName ?? clientLabel,
|
||||
'devicePlatform': 'android',
|
||||
'dedupeKey': installId,
|
||||
'appVersion': appVersion,
|
||||
});
|
||||
return (token: r['clientToken'] as String? ?? '', response: r);
|
||||
}
|
||||
|
||||
Future<Map<String, dynamic>> sessionStatus() async {
|
||||
final r = await _json('GET', '/auth/session');
|
||||
return r;
|
||||
|
||||
Reference in new issue
Block a user