From 6adf6e456bf9efb8f3f8ff291874626bf1f20121 Mon Sep 17 00:00:00 2001 From: Simon Date: Mon, 7 Feb 2022 00:53:34 +0000 Subject: [PATCH] Emergency fix - unique packets break hashing --- const.py | 2 +- hblink.py | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/const.py b/const.py index 1da03cb..69ae539 100755 --- a/const.py +++ b/const.py @@ -81,7 +81,7 @@ BCST = b'BCST' BCVE = b'BCVE' #Protocol version -VER = 2 +VER = 3 # Higheset peer ID permitted by HBP PEER_MAX = 4294967295 diff --git a/hblink.py b/hblink.py index 42ae6df..ec4e2d2 100755 --- a/hblink.py +++ b/hblink.py @@ -156,7 +156,15 @@ class OPENBRIDGE(DatagramProtocol): if _packet[:3] == DMR and self._config['TARGET_IP']: - if 'VER' in self._config and self._config['VER'] > 1: + if 'VER' in self._config and self._config['VER'] >= 3: + _packet = b''.join([DMRF,_packet[4:11], self._CONFIG['GLOBAL']['SERVER_ID'],_packet[15:]]) + _h = blake2b(key=self._config['PASSPHRASE'], digest_size=16) + _h.update(_packet) + _hash = _h.digest() + _packet = b''.join([_packet,time_ns().to_bytes(8,'big'), _hops, _hash]) + self.transport.write(_packet, (self._config['TARGET_IP'], self._config['TARGET_PORT'])) + + if 'VER' in self._config and self._config['VER'] = 2: _packet = b''.join([DMRF,_packet[4:11], self._CONFIG['GLOBAL']['SERVER_ID'],_packet[15:], time_ns().to_bytes(8,'big')]) _h = blake2b(key=self._config['PASSPHRASE'], digest_size=16) _h.update(_packet) @@ -327,7 +335,10 @@ class OPENBRIDGE(DatagramProtocol): _hash = _packet[62:] #_ckhs = hmac_new(self._config['PASSPHRASE'],_data,sha1).digest() _h = blake2b(key=self._config['PASSPHRASE'], digest_size=16) - _h.update(_packet[:61]) + if 'VER' in self._config and self._config['VER'] = 2: + _h.update(_packet[:61]) + elif 'VER' in self._config and self._config['VER'] >= 3: + _h.update(_packet[:53]) _ckhs = _h.digest() if compare_digest(_hash, _ckhs) and (_sockaddr == self._config['TARGET_SOCK'] or self._config['RELAX_CHECKS']):