571 lines
35 KiB
Python
571 lines
35 KiB
Python
#!/usr/bin/env python3
|
|
"""Independent SRP server fixture. Never starts or modifies Tortoise/Trinity."""
|
|
import hashlib,os,re
|
|
import socket
|
|
import struct
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
import threading
|
|
import time
|
|
from pathlib import Path
|
|
|
|
N = int('894B645E89E1535BBDAD5B8B290650530801B18EBFBF5E8FAB3C82872A3E9BB7', 16)
|
|
USER, PASSWORD = b'TEST', b'LOCAL-ONLY'
|
|
SECOND_USER, SECOND_PASSWORD = b'VISITOR', b'SECOND-LOCAL-ONLY'
|
|
SALT = bytes(range(1, 33))
|
|
VERSION = bytes(range(20))
|
|
ADDONS = struct.pack('<I', 4) + b'fixture-only' # opaque fixture input, not genuine client data
|
|
|
|
def H(*parts):
|
|
return hashlib.sha1(b''.join(parts)).digest()
|
|
|
|
def nat(n):
|
|
return n.to_bytes((n.bit_length() + 7) // 8, 'little')
|
|
|
|
def trim(b):
|
|
return b.rstrip(b'\0')
|
|
|
|
def recv_exact(s, n):
|
|
b = bytearray()
|
|
while len(b) < n:
|
|
part = s.recv(n-len(b))
|
|
if not part:
|
|
raise EOFError('peer closed')
|
|
b.extend(part)
|
|
return bytes(b)
|
|
|
|
def fragmented(s, data):
|
|
for b in data:
|
|
s.sendall(bytes([b]))
|
|
|
|
class Cipher:
|
|
def __init__(self, key):
|
|
# Tortoise WorldSocket supplies BigNumber(K).AsByteArray(), not the
|
|
# padded SRP40 representation. Keep proof/digest derivation untouched.
|
|
self.key, self.index, self.prev = trim(key), 0, 0
|
|
assert self.key, 'source header key must be nonzero'
|
|
|
|
def transform(self, data, encrypt):
|
|
out = bytearray()
|
|
for b in data:
|
|
c = ((b ^ self.key[self.index]) + self.prev) & 255 if encrypt else ((b-self.prev) & 255) ^ self.key[self.index]
|
|
self.index = (self.index+1) % len(self.key)
|
|
self.prev = c if encrypt else b
|
|
out.append(c)
|
|
return bytes(out)
|
|
|
|
def frame(op, body):
|
|
return struct.pack('>H', len(body)+2) + struct.pack('<H', op) + body
|
|
|
|
def client_packet(s, cipher=None):
|
|
h = recv_exact(s, 6)
|
|
if cipher:
|
|
h = cipher.transform(h, False)
|
|
size, = struct.unpack('>H', h[:2])
|
|
op, = struct.unpack('<I', h[2:])
|
|
assert 4 <= size <= 10240
|
|
return op, recv_exact(s, size-4)
|
|
|
|
def listen():
|
|
s = socket.socket()
|
|
s.bind(('127.0.0.1', 0))
|
|
s.listen(1)
|
|
s.settimeout(5)
|
|
return s
|
|
|
|
def run_case(executable, directory, mode, discover=False,memory=False,stream=False,lifetime=False,wire=False,auth_host=False,ipv4=False,partial_roster=False,talent_control=False,movement_reject=False,reentry=False,preference=None,fixture_user=USER):
|
|
errors = []
|
|
full_account_test = mode in ('account-reentry', 'account-switch', 'account-wrong-self')
|
|
paladin_reentry = mode in ('countdown-paladin-logout', 'instant-paladin-logout')
|
|
talent_fixture = talent_control and mode == 'success'
|
|
auth, world = listen(), listen()
|
|
auth_port, world_port = auth.getsockname()[1], world.getsockname()[1]
|
|
def peer(account_round):
|
|
switched_account = mode == 'account-switch' and account_round == 2
|
|
user, password = (SECOND_USER, SECOND_PASSWORD) if switched_account or fixture_user == SECOND_USER else (USER, PASSWORD)
|
|
try:
|
|
with auth.accept()[0] as s:
|
|
s.settimeout(5)
|
|
prefix = recv_exact(s, 4)
|
|
assert prefix[:2] == b'\0\3'
|
|
length, = struct.unpack('<H', prefix[2:])
|
|
challenge = recv_exact(s, length)
|
|
assert challenge[:4] == b'WoW\0'
|
|
assert challenge[4:7] == bytes([1,18,1])
|
|
assert struct.unpack('<H', challenge[7:9])[0] == 7272
|
|
assert challenge[9:21] == b'68x\0niW\0SUne'
|
|
assert challenge[29] == len(user) and challenge[30:] == user
|
|
if mode == 'challenge-reject':
|
|
fragmented(s, b'\0\0\4')
|
|
return
|
|
x = int.from_bytes(H(SALT, H(user+b':'+password)), 'little')
|
|
v = pow(7, x, N)
|
|
private = 0x123456789ABCDEF102030405060708090A0B0C0D
|
|
B = (3*v + pow(7, private, N)) % N
|
|
B_wire = B.to_bytes(32, 'little') if mode != 'zero-public' else bytes(32)
|
|
group = N.to_bytes(32, 'little') if mode != 'wrong-group' else bytes(32)
|
|
security = 1 if mode == 'pin' else 0
|
|
challenge_reply = b'\0\0\0' + B_wire + b'\1\7\x20' + group
|
|
# The client rejects a bad modulus before reading salt/security.
|
|
# Sending that trailer bytewise races its genuine socket close
|
|
# (EPIPE). End at the rejection boundary and require peer EOF;
|
|
# a client that accepts the bad group will time out and fail.
|
|
if mode != 'wrong-group':
|
|
challenge_reply += SALT + bytes(16) + bytes([security])
|
|
fragmented(s, challenge_reply)
|
|
if mode in ('pin', 'zero-public', 'wrong-group'):
|
|
assert s.recv(1) == b''
|
|
return
|
|
proof = recv_exact(s, 75)
|
|
assert proof[0] == 1 and proof[-2:] == bytes(2)
|
|
A = int.from_bytes(proof[1:33], 'little')
|
|
assert A % N != 0
|
|
u = int.from_bytes(H(nat(A), nat(B)), 'little')
|
|
shared = pow((A * pow(v, u, N)) % N, private, N).to_bytes(32, 'little')
|
|
even, odd = H(shared[::2]), H(shared[1::2])
|
|
key = bytes(b for pair in zip(even, odd) for b in pair)
|
|
expected_width = os.environ.get('GW_TEST_HEADER_KEY_WIDTH')
|
|
if expected_width is not None:
|
|
assert len(trim(key)) == int(expected_width), 'forced source header width was not exercised'
|
|
ng = bytes(a ^ b for a, b in zip(H(nat(N)), H(nat(7))))
|
|
m1 = H(trim(ng), H(user), trim(SALT), nat(A), nat(B), trim(key))
|
|
assert proof[33:53] == m1, 'client SRP proof differs from server calculation'
|
|
assert proof[53:73] == H(proof[1:33], VERSION), 'version proof not bound to A'
|
|
if mode == 'proof-reject':
|
|
fragmented(s, b'\1\x09')
|
|
return
|
|
m2 = H(nat(A), trim(m1), trim(key))
|
|
if mode == 'bad-m2':
|
|
m2 = bytes(20)
|
|
fragmented(s, b'\1\0' + m2 + bytes(4))
|
|
if mode == 'bad-m2':
|
|
assert s.recv(1) == b''
|
|
return
|
|
if discover:
|
|
assert recv_exact(s,5)==b'\x10'+bytes(4)
|
|
def send_realms(order, refreshed=False):
|
|
rows=struct.pack('<IB',0,len(order))
|
|
for i in order:
|
|
address=f'127.0.0.1:{world_port}' if i<2 else '192.0.2.1:8090'
|
|
flags=2 if i==1 and mode!='multiple-realms' else 0
|
|
if refreshed and i==0:
|
|
if mode=='refresh-address': address='192.0.2.2:8090'
|
|
if mode=='refresh-offline': flags=2
|
|
rows+=struct.pack('<IB',6 if i==0 else 1,flags)
|
|
rows+=f'Realm{i}'.encode()+b'\0'+address.encode()+b'\0'
|
|
rows+=struct.pack('<fBBB',.75 if refreshed else .5,5 if refreshed else 4,1,0)
|
|
rows+=struct.pack('<H',2)
|
|
fragmented(s,b'\x10'+struct.pack('<H',len(rows))+rows)
|
|
send_realms(range(3))
|
|
if mode.startswith('refresh-'):
|
|
for _ in range(5 if mode=='refresh-stable' else 1):
|
|
assert recv_exact(s,5)==b'\x10'+bytes(4)
|
|
if mode=='refresh-disconnect': return
|
|
send_realms([2,0] if mode=='refresh-removed' else [2,0,1],True)
|
|
assert s.recv(1)==b''
|
|
return
|
|
if auth_host:
|
|
assert s.recv(1)==b''
|
|
return
|
|
with world.accept()[0] as w:
|
|
w.settimeout(5)
|
|
server_seed = 0x55667788
|
|
fragmented(w, frame(0x1EC, struct.pack('<I', server_seed)))
|
|
op, body = client_packet(w)
|
|
assert op == 0x1ED
|
|
assert struct.unpack('<II', body[:8]) == (5875 if discover else 7272, 0)
|
|
seed_offset = 8 + len(user) + 1
|
|
assert body[8:seed_offset] == user + b'\0'
|
|
client_seed = body[seed_offset:seed_offset + 4]
|
|
digest_offset = seed_offset + 4
|
|
assert body[digest_offset:digest_offset + 20] == H(user, bytes(4), client_seed, struct.pack('<I',server_seed), trim(key))
|
|
assert body[digest_offset + 20:] == ADDONS
|
|
if mode == 'world-reject-plain':
|
|
fragmented(w, frame(0x1EE, b'\x0d'))
|
|
assert w.recv(1) == b''
|
|
return
|
|
tx, rx = Cipher(key), Cipher(key)
|
|
def send(op, body):
|
|
packet = frame(op,body)
|
|
fragmented(w, tx.transform(packet[:4], True)+packet[4:])
|
|
if mode == 'warden':
|
|
send(0x2E6, b'challenge')
|
|
assert w.recv(1) == b''
|
|
return
|
|
if mode == 'world-reject':
|
|
send(0x1EE, b'\x0d')
|
|
assert w.recv(1) == b''
|
|
return
|
|
if mode == 'early-roster':
|
|
send(0x3B, b'\0')
|
|
assert w.recv(1) == b''
|
|
return
|
|
send(0x2EF, b'addon-response')
|
|
send(0x1EE, b'\x0c'+bytes(8)+(b'\x01' if mode=='billing-unsupported' else b'\0'))
|
|
if mode=='billing-unsupported':
|
|
assert w.recv(1)==b''
|
|
return
|
|
op, body = client_packet(w,rx)
|
|
assert op == 0x37 and not body
|
|
send(0xFD, bytes(32))
|
|
if mode == 'empty':
|
|
send(0x3B, b'\0')
|
|
elif mode == 'truncated-roster':
|
|
send(0x3B, b'\1\0')
|
|
else:
|
|
rows=((42,b'Fixture',6,1,60),(43,b'Custom',10,4,1),(44,b'Other',6,7,1)) if partial_roster else ((42,b'Fixture',1,1,60),)
|
|
if paladin_reentry:
|
|
rows=((42,b'Fixture',1,2,60),)
|
|
if account_round:
|
|
rows = [(42, b'Fixture', 1, 1, 60), (43, b'Other', 1, 1, 58)]
|
|
if switched_account:
|
|
rows = [(73, b'Traveler', 1, 1, 58), (72, b'Visitor', 1, 1, 60)]
|
|
elif account_round == 2:
|
|
rows.reverse()
|
|
roster=bytes([len(rows)])
|
|
for guid,name,race,cls,level in rows:
|
|
roster+=struct.pack('<Q',guid)+name+b'\0'+bytes([race,cls,0,0,0,0,0,0,level])
|
|
roster+=struct.pack('<IIfffIIBIII',12,0,1,-2,3.5,0,0,0,0,0,0)+bytes(20*5)
|
|
send(0x3B, roster)
|
|
if account_round:
|
|
selected_guid = 72 if switched_account else 42
|
|
assert client_packet(w, rx) == (0x3d, struct.pack('<Q', selected_guid))
|
|
send(0x236, struct.pack('<Iffff', 12, account_round, -2, 3.5, .1))
|
|
def create_player(guid, self_flag):
|
|
send(0xa9, struct.pack('<IB', 1, 0) + bytes([3, 1, guid, 4, self_flag, 2])
|
|
+ struct.pack('<III', 0, 1 << (34 - 32), 60))
|
|
if account_round == 2 and mode == 'account-wrong-self':
|
|
create_player(43, 1)
|
|
create_player(42, 0)
|
|
w.shutdown(socket.SHUT_WR)
|
|
assert w.recv(1) == b''
|
|
assert s.recv(1) == b''
|
|
return
|
|
create_player(selected_guid, 1)
|
|
assert client_packet(w, rx) == (0x4b, b'')
|
|
send(0x4c, bytes(5))
|
|
send(0x4d, b'')
|
|
assert w.recv(1) == b'', 'world connection remained open after logout'
|
|
assert s.recv(1) == b'', 'account connection remained open after logout'
|
|
return
|
|
if reentry:
|
|
def expect(opcode, expected):
|
|
actual, payload = client_packet(w, rx)
|
|
assert (actual, payload) == (opcode, expected)
|
|
def enter_world(level, x, spells):
|
|
send(0x236, struct.pack('<Iffff',12,x,-2,3.5,.1))
|
|
if paladin_reentry: spells=[*spells,26573]
|
|
known = b''.join(struct.pack('<HH', spell, 0) for spell in spells)
|
|
send(0x12a, struct.pack('<BH', 0, len(spells)) + known + bytes(2))
|
|
fields={34:level,36:513 if paladin_reentry else 257,1102:31}
|
|
movement=b''
|
|
if paladin_reentry:
|
|
fields[35]=1
|
|
movement=struct.pack('<IIffffI6f',0,100,x,-2,3.5,.1,0,2.5,7,4.5,4.72,2.5,3.14)
|
|
mask=[0]*(1102//32+1)
|
|
for index in fields: mask[index//32] |= 1 << (index%32)
|
|
create=struct.pack('<IB',1,0)+bytes([3,1,42,4,0x21 if paladin_reentry else 1])
|
|
create+=movement+bytes([len(mask)])
|
|
create+=b''.join(struct.pack('<I',word) for word in mask)
|
|
create+=b''.join(struct.pack('<I',fields[index]) for index in sorted(fields))
|
|
send(0xa9,create)
|
|
if paladin_reentry:
|
|
# Source CMSG_CAST_SPELL contains rank and target mask.
|
|
# Source carries the cast sequence by ordered START/GO.
|
|
expect(0x12e,struct.pack('<IH',26573,0))
|
|
owner_spell=b'\x01\x2a'*2+struct.pack('<I',26573)
|
|
send(0x131,owner_spell+struct.pack('<HIH',2,0,0))
|
|
send(0x132,owner_spell+struct.pack('<HBBHfff',0x100,0,0,0x40,x,-2,3.5))
|
|
expect(0x3d,struct.pack('<Q',42))
|
|
enter_world(60,1,[78,12664])
|
|
for cycle, (name, spell) in enumerate([(b'Refreshed',100),(b'Returned',772)], start=1):
|
|
expect(0x4b,b'')
|
|
instant = mode.startswith('instant-')
|
|
send(0x4c,struct.pack('<IB',0,instant))
|
|
if not instant:
|
|
expect(0x1dc,struct.pack('<II',20+cycle,12))
|
|
send(0x1dd,struct.pack('<I',20+cycle))
|
|
send(0x4d,b'')
|
|
# A character logout keeps this transport signed in.
|
|
expect(0x37,b'')
|
|
rows=[(43,b'Other',58),(42,name,60+cycle)]
|
|
if cycle == 2: rows.reverse()
|
|
refreshed=b'\2'
|
|
for guid,character_name,level in rows:
|
|
cls=2 if paladin_reentry and guid==42 else 1
|
|
refreshed+=struct.pack('<Q',guid)+character_name+b'\0'+bytes([1,cls,0,0,0,0,0,0,level])
|
|
refreshed+=struct.pack('<IIfffIIBIII',12,0,4,-2,3.5,0,0,0,0,0,0)+bytes(20*5)
|
|
send(0x3b,refreshed)
|
|
expect(0x3d,struct.pack('<Q',42))
|
|
enter_world(60+cycle,1+3*cycle,[78,spell])
|
|
expect(0x1dc,struct.pack('<II',8+cycle,12));send(0x1dd,struct.pack('<I',8+cycle))
|
|
assert w.recv(1)==b''
|
|
return
|
|
if lifetime:
|
|
op,body=client_packet(w,rx)
|
|
assert op==0x1dc and body==struct.pack('<II',11,12)
|
|
if mode=='lifetime-integrity':send(0x2e6,b'unsupported-fixture-challenge')
|
|
elif mode=='lifetime-bad-pong':send(0x1dd,struct.pack('<I',99))
|
|
elif mode=='lifetime-short-pong':send(0x1dd,b'\x0b')
|
|
elif mode=='lifetime-eof':return
|
|
elif mode=='lifetime-fragment-eof':
|
|
w.sendall(tx.transform(frame(0x1dd,struct.pack('<I',11))[:2],True));return
|
|
elif mode=='lifetime-deferred':
|
|
send(0x236,struct.pack('<Iffff',12,1,-2,3.5,.1))
|
|
op,body=client_packet(w,rx)
|
|
assert op==0x3d and body==struct.pack('<Q',42)
|
|
else:
|
|
# Force timeout across a fragmented encrypted
|
|
# header, then another across a partial body.
|
|
packet=frame(0x1dd,struct.pack('<I',11))
|
|
encrypted=tx.transform(packet[:4],True)+packet[4:]
|
|
w.sendall(encrypted[:2]);time.sleep(.04)
|
|
w.sendall(encrypted[2:6]);time.sleep(.04)
|
|
w.sendall(encrypted[6:])
|
|
op,body=client_packet(w,rx)
|
|
assert op==0x1dc and body==struct.pack('<II',12,12)
|
|
send(0x1dd,struct.pack('<I',12))
|
|
assert w.recv(1)==b''
|
|
if stream or wire:
|
|
op,body=client_packet(w,rx)
|
|
assert op==0x3d and body==struct.pack('<Q',42)
|
|
if mode=='stream-integrity':
|
|
send(0x2e6,b'unsupported-fixture-challenge')
|
|
assert w.recv(1)==b''
|
|
elif mode=='stream-eof':return
|
|
elif mode=='stream-bad-header':
|
|
fragmented(w,tx.transform(b'\0\0\0\0',True));assert w.recv(1)==b''
|
|
else:
|
|
send(0x236,struct.pack('<Iffff',12,1,-2,3.5,.1))
|
|
if talent_fixture:
|
|
send(0x12a,b'\0'+struct.pack('<HHHHHH',2,78,0,12664,0,0))
|
|
fields={34:60,36:257,1102:31}
|
|
mask=[0]*(1102//32+1)
|
|
for index in fields:mask[index//32]|=1<<(index%32)
|
|
# Genuine full Player create: packed42,
|
|
# type4, UPDATEFLAG_SELF, then sparse mask.
|
|
create=struct.pack('<IB',1,0)+bytes([3,1,42,4,1,len(mask)])
|
|
create+=b''.join(struct.pack('<I',word) for word in mask)
|
|
create+=b''.join(struct.pack('<I',fields[index]) for index in sorted(fields))
|
|
send(0xa9,create)
|
|
# This real incoming packet waits behind
|
|
# a materialized local presentation retry.
|
|
send(0x1dd,struct.pack('<I',17))
|
|
op,body=client_packet(w,rx)
|
|
assert op==0x95 and body==struct.pack('<II',0,0)+b'ordinary-after-local\0'
|
|
else:
|
|
if sys.argv[2:]==['--wire-reject-update']:
|
|
# #55 Mindvex: an update the codec cannot convert (here an unknown block
|
|
# type) is dropped as an empty bundle; the session keeps translating.
|
|
send(0xa9,struct.pack('<IB',1,0)+bytes([0x7f])+bytes(16))
|
|
else:
|
|
send(0xa9,bytes(5)) # Genuine empty update-list format.
|
|
if movement_reject:
|
|
from native_movement_rejection_fixture import expect_recovered_movement
|
|
expect_recovered_movement(w,rx,client_packet)
|
|
op,body=client_packet(w,rx)
|
|
assert op==0x1dc and body==struct.pack('<II',7,12)
|
|
if talent_fixture:
|
|
trainer=(0xf130<<48)|(9010<<24)|99
|
|
raw=trainer.to_bytes(8,'little')
|
|
packed=bytes([sum(1<<index for index,value in enumerate(raw) if value)])+bytes(value for value in raw if value)
|
|
fields={3:9010,22:100,28:100,34:60,36:257,147:16}
|
|
mask=[0]*(147//32+1)
|
|
for index in fields:mask[index//32]|=1<<(index%32)
|
|
create=struct.pack('<IBB',1,0,3)+packed+bytes([3,0x40])+struct.pack('<ffff',1,-2,3.5,.1)+bytes([len(mask)])
|
|
create+=b''.join(struct.pack('<I',word) for word in mask)
|
|
create+=b''.join(struct.pack('<I',fields[index]) for index in sorted(fields))
|
|
send(0xa9,create)
|
|
op,body=client_packet(w,rx)
|
|
assert op==0x60 and body==struct.pack('<IQ',9010,0)
|
|
template=struct.pack('<I',9010)+b'FixtureTrainer\0'+bytes(4)
|
|
template+=struct.pack('<7I',0,7,0,0,0,0,1)+bytes(2)
|
|
send(0x61,template)
|
|
send(0x2aa,struct.pack('<QI',trainer,10000))
|
|
op,body=client_packet(w,rx)
|
|
assert op==0x2aa and body==struct.pack('<Q',trainer)
|
|
# Decryption of the next real packet also
|
|
# proves failed sizing did not advance the
|
|
# source cipher or send a second reset.
|
|
op,body=client_packet(w,rx)
|
|
assert op==0x1dc and body==struct.pack('<II',18,12)
|
|
send(0x1dd,struct.pack('<I',7));send(0x4d,b'')
|
|
except ConnectionResetError as exc:
|
|
if mode not in ('pin', 'zero-public', 'wrong-group'):
|
|
errors.append(exc)
|
|
except BaseException as exc:
|
|
errors.append(exc)
|
|
def serve():
|
|
with auth, world:
|
|
for account_round in ((1, 2) if full_account_test else (0,)):
|
|
peer(account_round)
|
|
if errors:
|
|
return
|
|
thread = threading.Thread(target=serve, daemon=True)
|
|
thread.start()
|
|
password_path = directory/'password'
|
|
if fixture_user == SECOND_USER:
|
|
password_path = directory/'password-second'
|
|
password_path.write_bytes(SECOND_PASSWORD+b'\n')
|
|
cmd = [executable,'127.0.0.1',str(auth_port),str(world_port),fixture_user.decode('ascii').lower(),
|
|
str(password_path),str(directory/'version'),str(directory/'addons')]
|
|
if mode == 'account-switch':
|
|
second_password = directory/'password-second'
|
|
second_password.write_bytes(SECOND_PASSWORD+b'\n')
|
|
cmd.extend([SECOND_USER.decode('ascii').lower(), str(second_password)])
|
|
env=dict(os.environ)
|
|
if preference:env['GW_TEST_SDHD_PREFERENCE']=preference
|
|
else:env.pop('GW_TEST_SDHD_PREFERENCE',None)
|
|
if mode.startswith('refresh-'):
|
|
env['GW_TEST_REALM_REFRESH']=mode
|
|
else:
|
|
env.pop('GW_TEST_REALM_REFRESH',None)
|
|
if full_account_test:
|
|
env['GW_TEST_FULL_ACCOUNT_REENTRY'] = '1'
|
|
else:
|
|
env.pop('GW_TEST_FULL_ACCOUNT_REENTRY', None)
|
|
if mode == 'account-wrong-self':
|
|
env['GW_TEST_WRONG_WORLD_SELF'] = '1'
|
|
else:
|
|
env.pop('GW_TEST_WRONG_WORLD_SELF', None)
|
|
if reentry:env['GW_TEST_WORLD_REENTRY']='1'
|
|
else:env.pop('GW_TEST_WORLD_REENTRY',None)
|
|
if paladin_reentry:env['GW_TEST_PALADIN_REENTRY']='1'
|
|
else:env.pop('GW_TEST_PALADIN_REENTRY',None)
|
|
if wire:env['GW_TEST_NATIVE_TRANSPORT']='1'
|
|
else:env.pop('GW_TEST_NATIVE_TRANSPORT',None)
|
|
if mode=='billing-unsupported':env['GW_TEST_BILLING_PROFILE']='1'
|
|
else:env.pop('GW_TEST_BILLING_PROFILE',None)
|
|
if memory:env['GW_TEST_AUTH_MEMORY']='1'
|
|
else:env.pop('GW_TEST_AUTH_MEMORY',None)
|
|
if ipv4:env['GW_TEST_AUTH_IPV4']='1'
|
|
else:env.pop('GW_TEST_AUTH_IPV4',None)
|
|
if partial_roster:env['GW_TEST_PARTIAL_ROSTER']='1'
|
|
else:env.pop('GW_TEST_PARTIAL_ROSTER',None)
|
|
if movement_reject:env['GW_TEST_MOVEMENT_REJECT']='1'
|
|
else:env.pop('GW_TEST_MOVEMENT_REJECT',None)
|
|
if talent_fixture:env['GW_TEST_TALENT_CONTROL']='1'
|
|
else:env.pop('GW_TEST_TALENT_CONTROL',None)
|
|
if stream:env['GW_TEST_NATIVE_STREAM']='1'
|
|
else:env.pop('GW_TEST_NATIVE_STREAM',None)
|
|
env.pop('GW_TEST_STREAM_FAILURE',None)
|
|
if lifetime:env['GW_TEST_NATIVE_LIFETIME']=mode
|
|
else:env.pop('GW_TEST_NATIVE_LIFETIME',None)
|
|
if mode.startswith('stream-'):env['GW_TEST_STREAM_FAILURE']='integrity' if mode=='stream-integrity' else 'transport'
|
|
started=time.monotonic()
|
|
result = subprocess.run(cmd, capture_output=True, text=True, timeout=10,env=env,
|
|
cwd=directory if preference else None)
|
|
thread.join(6)
|
|
assert not thread.is_alive(), 'fixture thread hung'
|
|
# Only fixed fixture diagnostics may accompany a peer failure. Never dump
|
|
# arbitrary child output, packets, credentials or authentication material.
|
|
child_diagnostic = next((line for line in result.stderr.splitlines()
|
|
if re.fullmatch(r'reentry opcode mismatch expected=[0-9]+ actual=[0-9]+ step=[0-9]+',line) or
|
|
re.fullmatch(r'socket-free transport regression(?: at fixture-line=[0-9]{1,6})?',line) or
|
|
re.fullmatch(r'socket-free fixture NPC metadata count=[0-9]{1,4} opcodes=[0-9,]{1,176}',line) or
|
|
line in ('unexpected source codec in map fixture','native NPC serializer identity mismatch',
|
|
'movement rejection fixture: validation must reject nonfatally','movement rejection fixture: rejected movement wrote output',
|
|
'movement rejection fixture: validation damaged authentication','movement rejection fixture: sizing must retain active-mover plus movement',
|
|
'movement rejection fixture: short capacity changed output or prepared batch','movement rejection fixture: valid movement did not recover',
|
|
'movement rejection fixture: valid movement damaged authentication')), 'unclassified-child-failure')
|
|
assert not errors, f'{mode}: fixture failed: {errors}; child_returncode={result.returncode}; child_diagnostic={child_diagnostic}'
|
|
if mode.startswith('refresh-'):
|
|
assert result.returncode==0 and 'realm refresh verified' in result.stdout,mode
|
|
print(f'{mode}: passed',flush=True)
|
|
return
|
|
success = full_account_test or reentry or mode in ('success','empty','multiple-realms','billing-unsupported','stream-integrity','stream-eof','stream-bad-header') or mode.startswith('lifetime-')
|
|
assert result.returncode == (0 if success else 1), f'{mode}: {result.stdout} {result.stderr}'
|
|
if full_account_test:
|
|
assert result.stdout.splitlines().count('characters=2') == 2
|
|
marker = {'account-wrong-self': 'wrong second-world self rejected',
|
|
'account-switch': 'different account entered its own character and logged out PASS',
|
|
'account-reentry': 'same-account same-character world reentry after full logout PASS'}[mode]
|
|
assert marker in result.stdout
|
|
elif success:
|
|
assert ('unsupported billing profile rejected after real world auth' if mode=='billing-unsupported' else 'realms=3' if auth_host else f'characters={0 if mode == "empty" else 3 if partial_roster else 1}') in result.stdout
|
|
if mode not in ('empty','billing-unsupported') and not auth_host:
|
|
assert f'42 Fixture level=60 race={6 if partial_roster else 1} class={2 if paladin_reentry else 1}' in result.stdout
|
|
if partial_roster:assert 'source=3 preview=3 race-identities-preserved; valid43+44 sized; invalid-source-pairs rejected; valid42 login' in result.stdout
|
|
if reentry:assert 'two character logouts and three same-character world entries on one authenticated transport PASS' in result.stdout
|
|
if paladin_reentry:assert 'three Consecration requests and matching spell starts and completions PASS' in result.stdout
|
|
if stream:assert 'native ordered stream verified' in result.stdout
|
|
if lifetime:assert 'native session lifetime verified' in result.stdout
|
|
if movement_reject:assert 'movement decoder rejects, capacity retries and valid recovery verified' in result.stdout
|
|
if talent_fixture:assert 'local talent retry and unchanged source cipher verified' in result.stdout
|
|
if talent_fixture:assert 'reset sizing retries, single-use confirmation and unchanged source state verified' in result.stdout
|
|
else:
|
|
expected = {'bad-m2':'M2 mismatch','pin':'security challenge','zero-public':'invalid SRP',
|
|
'wrong-group':'modulus','proof-reject':'proof rejected','challenge-reject':'challenge rejected',
|
|
'warden':'integrity challenge','world-reject':'authentication rejected',
|
|
'world-reject-plain':'rejected before encryption','early-roster':'roster before','truncated-roster':'truncated packet'}[mode]
|
|
if not discover:assert expected in result.stderr, f'{mode}: {result.stderr}'
|
|
assert 'authenticated' not in result.stdout
|
|
elapsed=time.monotonic()-started
|
|
print(f'{mode}: passed'+(f' ({elapsed:.3f}s)' if os.environ.get('GW_FIXTURE_TIMINGS')=='1' else ''),flush=True)
|
|
|
|
def main():
|
|
with tempfile.TemporaryDirectory(prefix='gateway-fixture-') as tmp:
|
|
directory = Path(tmp)
|
|
(directory/'password').write_bytes(PASSWORD+b'\n')
|
|
(directory/'version').write_bytes(VERSION)
|
|
(directory/'addons').write_bytes(ADDONS)
|
|
if sys.argv[2:]==['--sdhd-preference']:
|
|
# Each helper process signs in anew. Only its private synthetic account store survives.
|
|
executable = str(Path(sys.argv[1]).resolve())
|
|
for user, mode in ((USER, 'set-sd'), (SECOND_USER, 'set-sd'),
|
|
(USER, 'reset-hd'), (USER, 'read-hd'), (SECOND_USER, 'read-sd')):
|
|
run_case(executable, directory, 'success', discover=True, wire=True,
|
|
talent_control=mode=='set-sd', preference=mode, fixture_user=user)
|
|
print('SD/HD roster persisted across five fresh synthetic transports and two accounts')
|
|
return
|
|
if sys.argv[2:]==['--realm-refresh']:
|
|
for mode in ('refresh-stable','refresh-address','refresh-offline','refresh-removed','refresh-disconnect'):
|
|
run_case(sys.argv[1],directory,mode,discover=True)
|
|
return
|
|
if sys.argv[2:]==['--cast-reentry']:
|
|
if not Path(os.environ.get('GW_TEST_CODEC_PATH','')).is_file():
|
|
print('Configured game world serializer unavailable')
|
|
sys.exit(77)
|
|
for mode in ('countdown-paladin-logout','instant-paladin-logout'):
|
|
run_case(sys.argv[1],directory,mode,discover=True,wire=True,reentry=True)
|
|
return
|
|
if sys.argv[2:]==['--account-reentry']:
|
|
run_case(sys.argv[1], directory, 'account-reentry', discover=True, memory=True)
|
|
run_case(sys.argv[1], directory, 'account-wrong-self', discover=True, memory=True)
|
|
run_case(sys.argv[1], directory, 'account-switch', discover=True, memory=True)
|
|
return
|
|
discover=len(sys.argv)>2 and sys.argv[2] in ('--discover','--discover-memory','--discover-memory-ipv4','--stream','--lifetime','--wire','--auth-host','--wire-memory-ipv4','--wire-partial-roster','--wire-talent','--wire-movement-reject','--wire-reentry','--wire-reject-update')
|
|
auth_host=len(sys.argv)>2 and sys.argv[2] in ('--auth-host','--wire-memory-ipv4')
|
|
memory=len(sys.argv)>2 and sys.argv[2]=='--discover-memory'
|
|
ipv4=len(sys.argv)>2 and sys.argv[2] in ('--discover-memory-ipv4','--wire-memory-ipv4')
|
|
stream=len(sys.argv)>2 and sys.argv[2]=='--stream'
|
|
lifetime=len(sys.argv)>2 and sys.argv[2]=='--lifetime'
|
|
partial_roster=len(sys.argv)>2 and sys.argv[2]=='--wire-partial-roster'
|
|
wire=len(sys.argv)>2 and sys.argv[2] in ('--wire','--wire-partial-roster','--wire-talent','--wire-movement-reject','--wire-reentry','--wire-reject-update')
|
|
talent_control=len(sys.argv)>2 and sys.argv[2]in('--wire-talent','--wire-movement-reject')
|
|
movement_reject=len(sys.argv)>2 and sys.argv[2]=='--wire-movement-reject'
|
|
reentry=len(sys.argv)>2 and sys.argv[2]=='--wire-reentry'
|
|
cases=('success','empty','bad-m2','pin','zero-public','wrong-group','proof-reject',
|
|
'challenge-reject','warden','world-reject','world-reject-plain','early-roster','truncated-roster')
|
|
if stream:cases+=('stream-integrity','stream-eof','stream-bad-header')
|
|
if lifetime:cases=('lifetime-success','lifetime-bad-pong','lifetime-short-pong','lifetime-integrity','lifetime-eof','lifetime-fragment-eof','lifetime-deferred')
|
|
if auth_host:cases=('success','multiple-realms','bad-m2','pin','zero-public','wrong-group','proof-reject','challenge-reject')
|
|
if wire:cases+=('billing-unsupported',)
|
|
if movement_reject:cases=('success',)
|
|
if reentry:cases=('countdown-character-logout','instant-character-logout')
|
|
for mode in cases:run_case(sys.argv[1], directory, mode,discover,memory,stream,lifetime,wire,auth_host,ipv4,partial_roster,talent_control,movement_reject,reentry)
|
|
if sys.argv[2:]==['--wire-reentry']:
|
|
from loopback_key_width_test import check_source_key_width
|
|
check_source_key_width(sys.argv[1], sys.modules[__name__])
|
|
if sys.argv[2:]==['--wire-memory-ipv4']:
|
|
from loopback_rejection_schedule_test import check_rejection_schedule
|
|
check_rejection_schedule(sys.argv[1], sys.modules[__name__])
|
|
if discover:return
|
|
denied = subprocess.run([sys.argv[1],'192.0.2.1','3724','8085','TEST','missing','missing','missing'],capture_output=True,text=True)
|
|
assert denied.returncode == 1 and '127.0.0.1' in denied.stderr
|
|
print('non-loopback refused: passed')
|
|
|
|
if __name__ == '__main__':
|
|
main()
|