From f94d68ae81e4894bf011160a4c86a020a95dc061 Mon Sep 17 00:00:00 2001 From: KF7EEL Date: Thu, 3 Jun 2021 09:49:35 -0700 Subject: [PATCH] implement burn list --- config.py | 3 +++ hblink.py | 63 ++++++++++++++++++++++++++++++++----------------------- 2 files changed, 40 insertions(+), 26 deletions(-) diff --git a/config.py b/config.py index ec1b6f1..ca9b345 100755 --- a/config.py +++ b/config.py @@ -160,6 +160,9 @@ def build_config(_config_file): 'APPEND_INT': config.getint(section, 'APPEND_INT'), 'SHARED_SECRET': config.get(section, 'SHARED_SECRET'), 'SHORTEN_PASSPHRASE': config.getboolean(section, 'SHORTEN_PASSPHRASE'), + 'BURN_FILE': config.get(section, 'BURN_FILE'), + 'BURN_INT': config.getint(section, 'BURN_INT'), + }) diff --git a/hblink.py b/hblink.py index 8126ddd..0fc7f06 100755 --- a/hblink.py +++ b/hblink.py @@ -255,33 +255,44 @@ class HBSYSTEM(DatagramProtocol): return {'allow':True} def calc_passphrase(self, peer_id, _salt_str): - try: - if self.ums_response['mode'] == 'legacy': - _calc_hash = bhex(sha256(_salt_str+self._config['PASSPHRASE']).hexdigest()) - if self.ums_response['mode'] == 'override': - _calc_hash = bhex(sha256(_salt_str+str.encode(self.ums_response['value'])).hexdigest()) - if self.ums_response['mode'] == 'normal': - _new_peer_id = bytes_4(int(str(int_id(peer_id))[:7])) - #print(self._CONFIG['USER_MANAGER']['APPEND_INT']) - calc_passphrase = base64.b64encode(bytes.fromhex(str(hex(libscrc.ccitt((_new_peer_id) + self._CONFIG['USER_MANAGER']['APPEND_INT'].to_bytes(2, 'big') + bytes.fromhex(str(hex(libscrc.posix((_new_peer_id) + self._CONFIG['USER_MANAGER']['APPEND_INT'].to_bytes(2, 'big'))))[2:].zfill(8)))))[2:].zfill(4)) + (_new_peer_id) + self._CONFIG['USER_MANAGER']['APPEND_INT'].to_bytes(2, 'big') + bytes.fromhex(str(hex(libscrc.posix((_new_peer_id) + self._CONFIG['USER_MANAGER']['APPEND_INT'].to_bytes(2, 'big'))))[2:].zfill(8))) - if self._CONFIG['USER_MANAGER']['SHORTEN_PASSPHRASE'] == True: - calc_passphrase = calc_passphrase[-8:] - if self._CONFIG['USER_MANAGER']['SHORTEN_PASSPHRASE'] == False: - pass - _calc_hash = bhex(sha256(_salt_str+calc_passphrase).hexdigest()) - #ums_down = False - #If exception, assume UMS down and default to calculated passphrase - except Exception as e: - # If UMS down, default to base 64 auth - _new_peer_id = bytes_4(int(str(int_id(peer_id))[:7])) + burn_id = ast.literal_eval(os.popen('cat ' + self._CONFIG['USER_MANAGER']['BURN_FILE']).read()) + peer_id_trimmed = int(str(int_id(peer_id))[:7]) + #print(self._CONFIG) + try: + if self.ums_response['mode'] == 'legacy': + _calc_hash = bhex(sha256(_salt_str+self._config['PASSPHRASE']).hexdigest()) + if self.ums_response['mode'] == 'override': + _calc_hash = bhex(sha256(_salt_str+str.encode(self.ums_response['value'])).hexdigest()) + if self.ums_response['mode'] == 'normal': + _new_peer_id = bytes_4(int(str(int_id(peer_id))[:7])) + if peer_id_trimmed in burn_id: + logger.info('User ID has been burned. Requiring passphrase version: ' + str(burn_id[peer_id_trimmed])) + calc_passphrase = base64.b64encode(bytes.fromhex(str(hex(libscrc.ccitt((_new_peer_id) + burn_id[peer_id_trimmed].to_bytes(2, 'big') + self._CONFIG['USER_MANAGER']['BURN_INT'].to_bytes(2, 'big') + self._CONFIG['USER_MANAGER']['APPEND_INT'].to_bytes(2, 'big') + bytes.fromhex(str(hex(libscrc.posix((_new_peer_id) + burn_id[peer_id_trimmed].to_bytes(2, 'big') + self._CONFIG['USER_MANAGER']['BURN_INT'].to_bytes(2, 'big') + self._CONFIG['USER_MANAGER']['APPEND_INT'].to_bytes(2, 'big'))))[2:].zfill(8)))))[2:].zfill(4)) + (_new_peer_id) + burn_id[peer_id_trimmed].to_bytes(2, 'big') + self._CONFIG['USER_MANAGER']['BURN_INT'].to_bytes(2, 'big') + self._CONFIG['USER_MANAGER']['APPEND_INT'].to_bytes(2, 'big') + bytes.fromhex(str(hex(libscrc.posix((_new_peer_id) + burn_id[peer_id_trimmed].to_bytes(2, 'big') + self._CONFIG['USER_MANAGER']['BURN_INT'].to_bytes(2, 'big') + self._CONFIG['USER_MANAGER']['APPEND_INT'].to_bytes(2, 'big'))))[2:].zfill(8))) + else: calc_passphrase = base64.b64encode(bytes.fromhex(str(hex(libscrc.ccitt((_new_peer_id) + self._CONFIG['USER_MANAGER']['APPEND_INT'].to_bytes(2, 'big') + bytes.fromhex(str(hex(libscrc.posix((_new_peer_id) + self._CONFIG['USER_MANAGER']['APPEND_INT'].to_bytes(2, 'big'))))[2:].zfill(8)))))[2:].zfill(4)) + (_new_peer_id) + self._CONFIG['USER_MANAGER']['APPEND_INT'].to_bytes(2, 'big') + bytes.fromhex(str(hex(libscrc.posix((_new_peer_id) + self._CONFIG['USER_MANAGER']['APPEND_INT'].to_bytes(2, 'big'))))[2:].zfill(8))) - if self._CONFIG['USER_MANAGER']['SHORTEN_PASSPHRASE'] == True: - calc_passphrase = calc_passphrase[-8:] - if self._CONFIG['USER_MANAGER']['SHORTEN_PASSPHRASE'] == False: - pass - _calc_hash = bhex(sha256(_salt_str+calc_passphrase).hexdigest()) - #ums_down = True - return _calc_hash + if self._CONFIG['USER_MANAGER']['SHORTEN_PASSPHRASE'] == True: + calc_passphrase = calc_passphrase[-8:] + if self._CONFIG['USER_MANAGER']['SHORTEN_PASSPHRASE'] == False: + pass + _calc_hash = bhex(sha256(_salt_str+calc_passphrase).hexdigest()) + #If exception, assume UMS down and default to calculated passphrase + except Exception as e: + logger.info('Execption, UMS possibly down') + _new_peer_id = bytes_4(int(str(int_id(peer_id))[:7])) + if peer_id_trimmed in burn_id: + logger.info('User ID has been burned. Requiring passphrase version: ' + str(burn_id[peer_id_trimmed])) + calc_passphrase = base64.b64encode(bytes.fromhex(str(hex(libscrc.ccitt((_new_peer_id) + burn_id[peer_id_trimmed].to_bytes(2, 'big') + self._CONFIG['USER_MANAGER']['BURN_INT'].to_bytes(2, 'big') + self._CONFIG['USER_MANAGER']['APPEND_INT'].to_bytes(2, 'big') + bytes.fromhex(str(hex(libscrc.posix((_new_peer_id) + burn_id[peer_id_trimmed].to_bytes(2, 'big') + self._CONFIG['USER_MANAGER']['BURN_INT'].to_bytes(2, 'big') + self._CONFIG['USER_MANAGER']['APPEND_INT'].to_bytes(2, 'big'))))[2:].zfill(8)))))[2:].zfill(4)) + (_new_peer_id) + burn_id[peer_id_trimmed].to_bytes(2, 'big') + self._CONFIG['USER_MANAGER']['BURN_INT'].to_bytes(2, 'big') + self._CONFIG['USER_MANAGER']['APPEND_INT'].to_bytes(2, 'big') + bytes.fromhex(str(hex(libscrc.posix((_new_peer_id) + burn_id[peer_id_trimmed].to_bytes(2, 'big') + self._CONFIG['USER_MANAGER']['BURN_INT'].to_bytes(2, 'big') + self._CONFIG['USER_MANAGER']['APPEND_INT'].to_bytes(2, 'big'))))[2:].zfill(8))) + else: + calc_passphrase = base64.b64encode(bytes.fromhex(str(hex(libscrc.ccitt((_new_peer_id) + self._CONFIG['USER_MANAGER']['APPEND_INT'].to_bytes(2, 'big') + bytes.fromhex(str(hex(libscrc.posix((_new_peer_id) + self._CONFIG['USER_MANAGER']['APPEND_INT'].to_bytes(2, 'big'))))[2:].zfill(8)))))[2:].zfill(4)) + (_new_peer_id) + self._CONFIG['USER_MANAGER']['APPEND_INT'].to_bytes(2, 'big') + bytes.fromhex(str(hex(libscrc.posix((_new_peer_id) + self._CONFIG['USER_MANAGER']['APPEND_INT'].to_bytes(2, 'big'))))[2:].zfill(8))) + + #calc_passphrase = base64.b64encode(bytes.fromhex(str(hex(libscrc.ccitt((_new_peer_id) + self._CONFIG['USER_MANAGER']['APPEND_INT'].to_bytes(2, 'big') + bytes.fromhex(str(hex(libscrc.posix((_new_peer_id) + self._CONFIG['USER_MANAGER']['APPEND_INT'].to_bytes(2, 'big'))))[2:].zfill(8)))))[2:].zfill(4)) + (_new_peer_id) + self._CONFIG['USER_MANAGER']['APPEND_INT'].to_bytes(2, 'big') + bytes.fromhex(str(hex(libscrc.posix((_new_peer_id) + self._CONFIG['USER_MANAGER']['APPEND_INT'].to_bytes(2, 'big'))))[2:].zfill(8))) + if self._CONFIG['USER_MANAGER']['SHORTEN_PASSPHRASE'] == True: + calc_passphrase = calc_passphrase[-8:] + if self._CONFIG['USER_MANAGER']['SHORTEN_PASSPHRASE'] == False: + pass + _calc_hash = bhex(sha256(_salt_str+calc_passphrase).hexdigest()) + print((calc_passphrase)) + return _calc_hash def startProtocol(self):