- 增加信令访问令牌、HTTPS 校验、限流及跨网段中继连接修复 - 同步三端媒体 v2 协议,实现 AES-GCM、防重放和乱序分片重组,升级 Rust ABI 6 - 修复文件鉴权、权限协商及剪贴板越权,完善上传校验和串流超时处理 - 增加跨端回归测试及部署文档,在 AGENTS.md 记录真机与真实跨网段待验收项目
87 lines
4.1 KiB
Python
87 lines
4.1 KiB
Python
"""Run the real receiver against Rust UDP ingestion; accept capture in device UI.
|
|
Usage: python rust_core/tests/device_media_smoke.py --core PATH --dump FILE
|
|
Start the Android receiver with host 10.0.2.2 and its normal standby/capture UI.
|
|
"""
|
|
import argparse
|
|
import ctypes as c
|
|
import json
|
|
import os
|
|
import time
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument('--core', required=True)
|
|
parser.add_argument('--dump', required=True)
|
|
parser.add_argument('--seconds', type=int, default=180)
|
|
parser.add_argument('--tls-fingerprint', default='')
|
|
args = parser.parse_args()
|
|
os.environ['TTSTD_DUMP_VIDEO'] = os.path.abspath(args.dump)
|
|
os.makedirs(os.path.dirname(os.environ['TTSTD_DUMP_VIDEO']), exist_ok=True)
|
|
with open(args.dump, 'wb'):
|
|
pass
|
|
lib = c.CDLL(os.path.abspath(args.core))
|
|
def bind(name, result, *params):
|
|
method = getattr(lib,name); method.restype=result; method.argtypes=params; return method
|
|
ptr, size = c.c_void_p, c.c_size_t
|
|
start=bind('ttstd_demo_start',c.c_int32,c.c_uint16,c.c_uint16,c.c_uint16)
|
|
set_tls=bind('ttstd_demo_set_tls_fingerprint',c.c_int32,ptr,size)
|
|
stop=bind('ttstd_demo_stop',None)
|
|
status=bind('ttstd_demo_status',c.c_int32,ptr,size)
|
|
events=bind('ttstd_event_next',c.c_int32,ptr,size)
|
|
stats=bind('ttstd_video_stats',c.c_int32,ptr,size)
|
|
send=bind('ttstd_demo_send_control',c.c_int32,c.c_uint16,c.c_uint8,ptr,size)
|
|
output=c.create_string_buffer(16384)
|
|
deadline=time.monotonic()+args.seconds
|
|
seq=0
|
|
def fetch(method):
|
|
count=method(output,len(output)); return json.loads(output.raw[:count]) if count>0 else None
|
|
def control(kind,payload):
|
|
nonlocal seq
|
|
seq+=1
|
|
assert send(seq,kind,payload,len(payload)) == 0
|
|
def wait(predicate,label):
|
|
while time.monotonic()<deadline:
|
|
value=predicate()
|
|
if value: return value
|
|
time.sleep(.1)
|
|
raise AssertionError('timeout: '+label)
|
|
def next_event():
|
|
event=fetch(events)
|
|
if event and event['type']==4:
|
|
raise AssertionError('view-only peer received clipboard content (redacted)')
|
|
if event: print('EVENT',json.dumps(event,ensure_ascii=False),flush=True)
|
|
return event
|
|
try:
|
|
fingerprint=args.tls_fingerprint.encode()
|
|
assert set_tls(fingerprint,len(fingerprint))==0
|
|
assert start(41001,41000,41002)==0, 'ports already occupied'
|
|
print('LISTENING: waiting for Android standby on TCP 41001',flush=True)
|
|
wait(lambda: (s if (s:=fetch(status))['keyEstablished'] else None),'ECDH')
|
|
print('ECDH established',flush=True)
|
|
legacy=json.dumps({'mediaProtocol':'legacy','access':'view','clipboardSync':False}).encode()
|
|
control(9,legacy)
|
|
time.sleep(.3)
|
|
control(8,b'\x00')
|
|
wait(lambda: (e if (e:=next_event()) and e['type']==8 and e['action']==5 else None),'legacy rejection')
|
|
print('PASS legacy mirror request rejected before capture',flush=True)
|
|
config=json.dumps({'mediaProtocol':'aes-gcm/2','audioEnabled':True,'bitrateMbps':2,'access':'view','clipboardSync':False}).encode()
|
|
control(9,config)
|
|
wait(lambda: (e if (e:=next_event()) and e['type']==10 and json.loads(e['text']).get('mediaProtocol')=='aes-gcm/2' else None),'media negotiation')
|
|
control(8,b'\x00')
|
|
print('NEGOTIATED: accept the normal Android mirror/capture dialogs',flush=True)
|
|
def video_progress():
|
|
event=next_event()
|
|
if event and event['type']==8 and event['action']==3 and event['text']=='确认超时':
|
|
control(8,b'\x00')
|
|
print('RETRY after confirmation timeout: accept the app dialog',flush=True)
|
|
value=fetch(stats)
|
|
return value if value['received']>=5 else None
|
|
video=wait(video_progress,'encrypted video')
|
|
print('PASS Android direct UDP AES-GCM video:',json.dumps(video),flush=True)
|
|
control(8,b'\x01')
|
|
print('STOP sent; screen capture stopped through protocol',flush=True)
|
|
finally:
|
|
stop()
|
|
|
|
if __name__=='__main__': main()
|