From 76fb659c0221bbd2309ccd4b653ae4bb2333f6cf Mon Sep 17 00:00:00 2001 From: Liquid Date: Mon, 25 Mar 2024 20:16:14 -0500 Subject: [PATCH] Remove TorV2 checks for TorV3 addr verification Fix bool --- src/utils.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/utils.py b/src/utils.py index 95eebc9..000eefd 100644 --- a/src/utils.py +++ b/src/utils.py @@ -176,12 +176,13 @@ def ipmap(ip, port): try: ipv6map = '' - if len(ip) > 6 and ip.endswith('.onion'): - pchOnionCat = bytearray([0xFD, 0x87, 0xD8, 0x7E, 0xEB, 0x43]) + if len(ip) == 62 and ip.endswith('.onion'): + vchOnionPrefix = bytes([0x04, 32]) vchAddr = base64.b32decode(ip[0:-6], True) - if len(vchAddr) != 16 - len(pchOnionCat): - raise Exception('Invalid onion %s' % str(ip)) - return pchOnionCat.hex() + vchAddr.hex() + int(port).to_bytes(2, byteorder='big').hex() + vchAddrBytes = vchOnionPrefix + vchAddr[:32] + if len(vchAddr) != 35 and vchAddr[-1] != b'\x03': + raise Exception('Invalid TorV3 address %s' % str(ip)) + return vchAddrBytes.hex() + int(port).to_bytes(2, byteorder='big').hex() ipAddr = ip_address(ip)