feat(security): 完善信令认证与媒体加密
- 增加信令访问令牌、HTTPS 校验、限流及跨网段中继连接修复 - 同步三端媒体 v2 协议,实现 AES-GCM、防重放和乱序分片重组,升级 Rust ABI 6 - 修复文件鉴权、权限协商及剪贴板越权,完善上传校验和串流超时处理 - 增加跨端回归测试及部署文档,在 AGENTS.md 记录真机与真实跨网段待验收项目
This commit is contained in:
1 parent
4c9d006d11
commit
f6b7730684
58 files changed
+2167
-218
No files matched your search
@@ -0,0 +1,78 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:ttstd_sender/core/control_file_client.dart';
|
||||
|
||||
void main() {
|
||||
late Directory temp;
|
||||
setUp(() async {
|
||||
temp = await Directory.systemTemp.createTemp('ttstd-upload-');
|
||||
});
|
||||
tearDown(() async {
|
||||
await temp.delete(recursive: true);
|
||||
});
|
||||
|
||||
test('uploads a SHA-256 manifest and preserves chunk bytes', () async {
|
||||
final file = File('${temp.path}/test.txt');
|
||||
await file.writeAsString('abc');
|
||||
final chunks = <int>[];
|
||||
final client = ControlFileClient(send: (request) async {
|
||||
if (request['op'] == 'prepare') {
|
||||
final manifest =
|
||||
(jsonDecode(request['body'] as String)['files'] as List).single;
|
||||
expect(manifest['sha256'],
|
||||
'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad');
|
||||
return {
|
||||
'sessionId': 'session',
|
||||
'tokens': {manifest['id']: 'token'}
|
||||
};
|
||||
}
|
||||
chunks.addAll(base64Decode(request['dataB64'] as String));
|
||||
return {'ok': true};
|
||||
});
|
||||
expect(await client.upload(file.path), 'test.txt');
|
||||
expect(chunks, utf8.encode('abc'));
|
||||
});
|
||||
|
||||
test('empty files are prepared with the empty SHA-256 and no chunks',
|
||||
() async {
|
||||
final file = await File('${temp.path}/empty').create();
|
||||
var requests = 0;
|
||||
final client = ControlFileClient(send: (request) async {
|
||||
requests++;
|
||||
expect(request['op'], 'prepare');
|
||||
final manifest =
|
||||
(jsonDecode(request['body'] as String)['files'] as List).single;
|
||||
expect(manifest['sha256'],
|
||||
'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855');
|
||||
return {
|
||||
'sessionId': 'session',
|
||||
'tokens': {manifest['id']: 'token'}
|
||||
};
|
||||
});
|
||||
await client.upload(file.path);
|
||||
expect(requests, 1);
|
||||
});
|
||||
|
||||
test('a truncated local file cancels the remote session', () async {
|
||||
final file = File('${temp.path}/changed');
|
||||
await file.writeAsString('abc');
|
||||
var cancelled = false;
|
||||
final client = ControlFileClient(send: (request) async {
|
||||
if (request['op'] == 'prepare') {
|
||||
final manifest =
|
||||
(jsonDecode(request['body'] as String)['files'] as List).single;
|
||||
await file.writeAsString('');
|
||||
return {
|
||||
'sessionId': 'session',
|
||||
'tokens': {manifest['id']: 'token'}
|
||||
};
|
||||
}
|
||||
if (request['op'] == 'cancel') cancelled = true;
|
||||
return {};
|
||||
});
|
||||
await expectLater(
|
||||
client.upload(file.path), throwsA(isA<ControlFileException>()));
|
||||
expect(cancelled, isTrue);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:ttstd_sender/core/signaling_endpoint.dart';
|
||||
import 'package:ttstd_sender/core/models.dart';
|
||||
import 'package:ttstd_sender/core/watch_client.dart';
|
||||
import 'dart:io';
|
||||
import 'package:ttstd_sender/core/settings_store.dart';
|
||||
|
||||
void main() {
|
||||
test('credentials stay in headers and never in WebSocket URLs', () {
|
||||
final endpoint =
|
||||
SignalingEndpoint.withToken('https://example.com/api/', 'secret+token');
|
||||
expect(SignalingEndpoint.headers(endpoint),
|
||||
{'Authorization': 'Bearer secret+token'});
|
||||
expect(SignalingWatch.watchUri(endpoint).toString(),
|
||||
'wss://example.com/api/watch');
|
||||
expect(SignalingEndpoint.publicUrl(endpoint), 'https://example.com/api/');
|
||||
});
|
||||
test('settings roundtrip preserves signaling credentials', () {
|
||||
final settings = AppSettings.fromJson(
|
||||
const AppSettings(signalingToken: 'secret').toJson());
|
||||
expect(settings.copyWith(audioEnabled: false).signalingToken, 'secret');
|
||||
expect(AppSettings.fromJson({}).signalingToken, '');
|
||||
});
|
||||
test('settings persist across store instances', () async {
|
||||
final temp = await Directory.systemTemp.createTemp('ttstd-settings-');
|
||||
try {
|
||||
final file = File('${temp.path}/settings.json');
|
||||
expect(SettingsStore(file: file).load().signalingToken, '');
|
||||
await SettingsStore(file: file).save(const AppSettings(
|
||||
signalingToken: 'private', useLocalSignaling: false));
|
||||
expect(SettingsStore(file: file).load().signalingToken, 'private');
|
||||
await SettingsStore(file: file)
|
||||
.save(const AppSettings(signalingToken: 'rotated'));
|
||||
expect(SettingsStore(file: file).load().signalingToken, 'rotated');
|
||||
} finally {
|
||||
await temp.delete(recursive: true);
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user