Files
WoW-Hybrid-gateway/ops/native_stream_local.py
praxisandClaude Fable 5.2 8a24c445b0 Content pipeline and operator tools
367 files, from working commit b1a079a.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-19 01:32:48 +02:00

195 lines
14 KiB
Python

#!/usr/bin/env python3
"""Valid local-account test of the native library's complete packet stream.
Not a Forever engine test, proxy, service or claim of client compatibility.
No movement, character progression changes, raw packet/key/credential dumps.
"""
import ctypes as C
import json,socket,struct,time
from pathlib import Path
ROOT=Path(__file__).resolve().parents[1]
class Auth(C.Structure):
_fields_=[('abi',C.c_uint32),('port',C.c_uint16),('username',C.c_char_p),('password',C.c_char_p),('version',C.c_char_p)]
class Realm(C.Structure):
_fields_=[('type',C.c_uint32),('flags',C.c_uint32),('characters',C.c_uint32),('category',C.c_uint32),('wire',C.c_uint32),('population',C.c_float),('name',C.c_char*128),('address',C.c_char*256)]
class Character(C.Structure):
_fields_=[('guid',C.c_uint64),('level',C.c_uint32),('race',C.c_uint32),('class_id',C.c_uint32),('name',C.c_char*64)]
class Packet(C.Structure):
_fields_=[('opcode',C.c_uint32),('size',C.c_uint32)]
def require(okay):
if not okay:raise RuntimeError('Local native stream operation failed; credentials and raw data omitted')
def run():
options=json.loads((ROOT/'secrets/native-local-bootstrap.json').read_text());directory=Path(options['account_directory']).resolve()
require(directory.is_relative_to(ROOT/'secrets'))
account=json.loads((directory/'account.json').read_text());library=C.CDLL(str(ROOT/'build/libgateway_native.so'))
signatures={
'gw_native_authenticate':([C.POINTER(Auth),C.POINTER(C.c_void_p)],C.c_int),
'gw_native_discover':([C.c_void_p],C.c_int),'gw_native_realm_count':([C.c_void_p],C.c_uint32),
'gw_native_realm_at':([C.c_void_p,C.c_uint32,C.POINTER(Realm)],C.c_int),
'gw_native_select':([C.c_void_p,C.c_uint32,C.c_char_p,C.c_uint32,C.POINTER(C.c_void_p)],C.c_int),
'gw_native_character_count':([C.c_void_p],C.c_uint32),
'gw_native_character_at':([C.c_void_p,C.c_uint32,C.POINTER(Character)],C.c_int),
'gw_native_begin_world':([C.c_void_p,C.c_uint64],C.c_int),
'gw_native_receive':([C.c_void_p,C.POINTER(Packet),C.c_void_p,C.c_uint32],C.c_int),
'gw_native_send':([C.c_void_p,C.c_uint32,C.c_void_p,C.c_uint32],C.c_int),
'gw_native_close':([C.c_void_p],None),'gw_native_login_close':([C.c_void_p],None)}
for name,(arguments,result) in signatures.items():
function=getattr(library,name);function.argtypes=arguments;function.restype=result
login=C.c_void_p();session=C.c_void_p()
report={'kind':'local-native-library-ordered-stream','actual_forever_engine_test':False,'native_engine_world_entry':False,
'credential_values_exported':False,'position_changed_by_test':False,'packets':[]}
with socket.socket() as gateway:
gateway.settimeout(.2);report['external_gateway_port_absent']=gateway.connect_ex(('127.0.0.1',19085))!=0
started=time.monotonic()
try:
config=Auth(1,3724,account['username'].encode(),str(directory/'password.txt').encode(),str(directory/'version-hash.bin').encode())
require(library.gw_native_authenticate(C.byref(config),C.byref(login))==0)
report['legitimate_srp_and_server_proof_verified']=True
require(library.gw_native_discover(login)==0)
available=[]
for i in range(library.gw_native_realm_count(login)):
r=Realm();require(library.gw_native_realm_at(login,i,C.byref(r))==0)
if not r.flags&2 and bytes(r.address).startswith(b'127.0.0.1:'):available.append((i,r))
require(len(available)==1);index,realm=available[0]
report['selected_genuine_realm']={'name':bytes(realm.name).decode(),'address':bytes(realm.address).decode(),'type':realm.type,'flags':realm.flags}
require(library.gw_native_select(login,index,str(directory/'addon-tail.bin').encode(),5875,C.byref(session))==0)
selected=None
for i in range(library.gw_native_character_count(session)):
character=Character();require(library.gw_native_character_at(session,i,C.byref(character))==0)
if character.guid==options['character_guid']:selected=character
require(selected is not None);report['character']={'guid':selected.guid,'level':selected.level}
require(library.gw_native_begin_world(session,selected.guid)==0)
ping=C.create_string_buffer(struct.pack('<II',7,0));ping_start=time.monotonic()
require(library.gw_native_send(session,0x1dc,ping,8)==0)
buffer=C.create_string_buffer(16);capacity=16;world=False;pong=False;updates=0;retries=0
for _ in range(256):
packet=Packet();status=library.gw_native_receive(session,C.byref(packet),buffer,capacity)
if status==-3:
require(capacity<packet.size<=65533);expected=(packet.opcode,packet.size)
capacity=packet.size;buffer=C.create_string_buffer(capacity);retries+=1
status=library.gw_native_receive(session,C.byref(packet),buffer,capacity)
require((packet.opcode,packet.size)==expected)
require(status==0)
report['packets'].append({'opcode':hex(packet.opcode),'bytes':packet.size})
if packet.opcode==0x236:
require(packet.size==20);values=struct.unpack('<Iffff',buffer.raw[:20])
report['server_world']={'map':values[0],'x':values[1],'y':values[2],'z':values[3],'orientation':values[4]};world=True
elif packet.opcode in (0xa9,0x1f6):updates+=1
elif packet.opcode==0x1dd:
require(packet.size==4 and buffer.raw[:4]==struct.pack('<I',7));pong=True
report['ping_round_trip_seconds']=round(time.monotonic()-ping_start,6)
if world and pong and updates:break
require(world and pong and updates)
report['update_packets_received']=updates;report['capacity_retries_preserved']=retries
report['seconds']=round(time.monotonic()-started,4)
finally:
library.gw_native_close(session);library.gw_native_login_close(login)
(ROOT/'runtime/native-local-ordered-stream.json').write_text(json.dumps(report,indent=2)+'\n')
print(json.dumps(report))
class AuthIPv4(C.Structure):
_fields_=[('abi',C.c_uint32),('size',C.c_uint32),('port',C.c_uint16),('reserved',C.c_uint16),('address',C.c_char_p),('username',C.c_char_p),('password',C.POINTER(C.c_uint8)),('password_bytes',C.c_uint32),('version',C.c_char_p)]
class WireCall(C.Structure):
# Existing native/wine_wire_abi.h, unchanged fixed64-bit own-module ABI.
_fields_=[('abi',C.c_uint32),('size',C.c_uint32),('result',C.c_int32),('operation',C.c_uint32),('login',C.c_uint64),('transport',C.c_uint64),('auth',Auth)]+[(k,C.c_uint32)for k in ('index','build','opcode','input_bytes','capacity','required','consumed','value','realm_id','virtual_address','super_district','reserved')]+[('addon_path',C.c_char_p),('input',C.POINTER(C.c_uint8)),('output',C.POINTER(C.c_uint8)),('packet',Packet),('character',Character),('realm',Realm)]
def windows_source_auth_only(root,mailbox,context,*,_dispatch=None):
"""Consume the existing132B one-shot credential ABI; real existing op37 SRP.
Caller supplies qualified account memory, never a credential filename. No
game/process injection, world socket, character login or retry is performed.
"""
import ipaddress,os
from engine_login_input_binding import credentials_valid,wipe
root=Path(root);username=bytearray();password=bytearray();terminated=bytearray();token=0
report={'kind':'standalone-Windows-existing-backend-Source-auth-only','hostname':'praxis.go.ro','game_or_injection_used':False,'world_socket_opened':False,'credentials_exported':False,'password_file_used':False,'auth_attempted':False,'server_proof_verified':False,'realms':[]}
try:
if type(mailbox)is not bytearray or len(mailbox)!=132:raise ValueError('Existing mutable credential mailbox required')
abi,size,state,generation,ulen,plen,consumed,reserved=struct.unpack_from('<8I',mailbox)
if(abi,size,state)!=(1,132,1)or not generation or consumed or reserved or not 1<=ulen<=32 or not 1<=plen<=64 or mailbox[32+ulen]:raise ValueError('One-shot credential mailbox header differs')
username=bytearray(memoryview(mailbox)[32:32+ulen]);password=bytearray(memoryview(mailbox)[65:65+plen])
if not credentials_valid(username,password,None):raise ValueError('Private account input shape differs')
if(context.get('profile')!='praxis'or context.get('hostname')!='praxis.go.ro'or context.get('public_endpoint')is not True or context.get('expected')is not None or context.get('endpoint_kind')!=1 or context.get('auth_port')!=3724):raise ValueError('Reviewed external Source context required')
address=ipaddress.IPv4Address(context['auth_ipv4'])
if not address.is_global or address.is_multicast or int(address)>>28==15:raise ValueError('External Source IPv4 differs')
if Path(context['version']).resolve()!=(root/'compat/praxis/version-hash.bin').resolve():raise ValueError('Reviewed public version input required')
if C.sizeof(WireCall)!=640 or C.sizeof(AuthIPv4)!=56:raise ValueError('Fixed64-bit existing backend ABI required')
if _dispatch is None:
if os.name!='nt':raise ValueError('Native Windows auth adapter required')
library=C.WinDLL(str(root/'build/GWNativeBackend.dll'),winmode=0x100|0x1000)
dispatch=library.gw_native_wire_dispatch;dispatch.argtypes=[C.POINTER(WireCall)];dispatch.restype=C.c_int32
else:dispatch=_dispatch
terminated=bytearray(username);terminated.append(0);user=(C.c_char*len(terminated)).from_buffer(terminated);secret=(C.c_uint8*len(password)).from_buffer(password)
config=AuthIPv4(2,C.sizeof(AuthIPv4),3724,0,str(address).encode(),C.cast(user,C.c_char_p),secret,len(password),str(context['version']).encode())
call=WireCall();call.abi=1;call.size=C.sizeof(WireCall);call.operation=37;call.input=C.cast(C.pointer(config),C.POINTER(C.c_uint8));call.input_bytes=C.sizeof(config)
report['auth_attempted']=True;status=dispatch(C.byref(call));token=call.login
# The existing backend returns success only after real SRP M2 proof.
if status or call.result or not token:raise RuntimeError('Source authentication refused; no retry')
report['server_proof_verified']=True
def operation(op,index=0):
row=WireCall();row.abi=1;row.size=C.sizeof(row);row.operation=op;row.login=token;row.index=index
status=dispatch(C.byref(row))
if status or row.result:raise RuntimeError('Source realm metadata refused; no retry')
return row
operation(2);count=operation(3).value
if not 0<count<=64:raise ValueError('Advertised realm count bound')
for i in range(count):
row=operation(4,i).realm
report['realms'].append({'index':i,'type':row.type,'flags':row.flags,'category':row.category,'wire_id':row.wire,'name':bytes(row.name).decode('utf-8','replace'),'address':bytes(row.address).decode('utf-8','replace')})
report['status']='PASS_EXISTING_SOURCE_SRP_M2_AND_REALM_DISCOVERY_ONLY'
return report
except Exception as error:
report.update(status='FAILED_SOURCE_AUTH_ONLY_PRESERVED_NO_RETRY',error_type=type(error).__name__)
return report
finally:
try:
if token:
close=WireCall();close.abi=1;close.size=C.sizeof(close);close.operation=5;close.login=token
if dispatch(C.byref(close)) or close.result:
report.update(status='FAILED_SOURCE_AUTH_ONLY_CLEANUP_NO_RETRY',cleanup_failed=True)
except Exception:
report.update(status='FAILED_SOURCE_AUTH_ONLY_CLEANUP_NO_RETRY',cleanup_failed=True)
finally:
# Same one-shot memory policy as the native credential worker;
# failed cleanup must never skip erasure of the protected bytes.
wipe(username,password,terminated)
if type(mailbox)is bytearray:wipe(mailbox)
def windows_auth_entry(root,report_path):
"""Private caller must provide one existing132B mailbox via anonymous pipe."""
import os,sys
# Embedded Windows Python -I omits the script directory. Resolve only our
# actual helper directory before importing the existing owned binding.
sys.path.insert(0,str(Path(__file__).resolve().parent))
from engine_login_input_binding import wipe
import engine_login_input_binding as binding
root=Path(root).resolve();report_path=Path(report_path)
if report_path.exists():raise ValueError('Prior authentication result preserved; no retry')
if os.name!='nt' or C.sizeof(C.c_void_p)!=8:raise ValueError('Native64-bit Windows required')
import msvcrt
kernel=C.WinDLL('kernel32',use_last_error=True);kernel.GetFileType.argtypes=[C.c_void_p];kernel.GetFileType.restype=C.c_uint32
if kernel.GetFileType(msvcrt.get_osfhandle(sys.stdin.fileno()))!=3:raise ValueError('Qualified private anonymous-pipe account source required; no console/file fallback')
# Exclusive marker precedes private input/auth; never silently replay it.
with report_path.open('x')as output:output.write(json.dumps({'status':'ONE_PRIVATE_ACCOUNT_ATTEMPT_PENDING','credential_values_included':False})+'\n')
mailbox=bytearray(132)
try:
binding.ROOT=root;context=binding.prepare_context('octo')
cursor=0
while cursor<len(mailbox):
count=sys.stdin.buffer.readinto(memoryview(mailbox)[cursor:])
if not count:raise ValueError('Private credential mailbox truncated; no auth')
cursor+=count
report=windows_source_auth_only(root,mailbox,context)
except Exception:
report={'status':'SOURCE_AUTH_ONLY_FAILED_PRESERVED_NO_RETRY','credential_values_included':False,'game_or_world_verified':False}
finally:wipe(mailbox)
report_path.write_text(json.dumps(report,indent=2)+'\n')
return 0 if report.get('server_proof_verified')and report.get('status','').startswith('PASS_')else 1
if __name__=='__main__':
import argparse,sys
parser=argparse.ArgumentParser();parser.add_argument('--windows-auth-only',action='store_true');parser.add_argument('--root',type=Path,default=ROOT);parser.add_argument('--report',type=Path);args=parser.parse_args()
if args.windows_auth_only:
if args.report is None:parser.error('--report is required for the one-shot Source auth boundary')
raise SystemExit(windows_auth_entry(args.root,args.report))
run()