367 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
34 lines
1.7 KiB
Python
34 lines
1.7 KiB
Python
"""Shared proof-verified realm admission; no client UI or platform imports."""
|
|
import ipaddress
|
|
|
|
def require_genuine(account):
|
|
if (account.get('state') not in (2,5) or account.get('server_proof_verified')!=1 or
|
|
account.get('auth_result')!=0 or account.get('discovery_result')!=0 or
|
|
account.get('error')!=0 or account.get('auth_port')!=3724):
|
|
raise ValueError('Require genuine proof-verified authentication and discovery')
|
|
rows=account.get('realms')
|
|
if not isinstance(rows,list) or not 0<=len(rows)<=64 or account.get('realm_count')!=len(rows):
|
|
raise ValueError('Discovered realm count differs')
|
|
|
|
|
|
def require_realm(account,index,profile):
|
|
require_genuine(account)
|
|
rows=account['realms']
|
|
if type(index) is not int or not 0<=index<len(rows):raise ValueError('Invalid discovered realm index')
|
|
row=rows[index]
|
|
if row.get('index')!=index or type(row.get('flags')) is not int or row['flags']&2:
|
|
raise ValueError('Selected real realm is unavailable')
|
|
address=row.get('address')
|
|
if not isinstance(address,str) or address.count(':')!=1:raise ValueError('Unsupported realm endpoint')
|
|
host,port=address.split(':')
|
|
ip=ipaddress.IPv4Address(host)
|
|
if not port.isascii() or not port.isdecimal() or not 1<=int(port)<=65535:
|
|
raise ValueError('Unsupported realm port')
|
|
if profile=='local-explicit':
|
|
if address!='127.0.0.1:8090':raise ValueError('Require actual local Tortoise realm')
|
|
elif profile=='octo':
|
|
if not ip.is_global or ip.is_multicast or int(ip)>>28==15:
|
|
raise ValueError('Public realm must advertise supported global numeric IPv4')
|
|
else:raise ValueError('Unsupported fixed endpoint profile')
|
|
return row
|