diff --git a/IPSC Decoding.txt b/IPSC Decoding.txt index 76d7d89..8cab7ab 100644 --- a/IPSC Decoding.txt +++ b/IPSC Decoding.txt @@ -9,6 +9,7 @@ PEER: 13120104 MASTER: +91 00 04 c2 c0 6a 00 00 80 5d 00 06 04 03 04 00 9b 1d 56 20 26 48 08 e3 60 ba 91 00 04 c2 c0 6a 00 00 80 5d 00 03 04 03 04 00 5c b8 4e e4 7e 44 b6 bb df dd |--SRC ID-| |MODE| | FLAGS ||PEERS||IPSC VER| |IPSC VER| |-1st 10 bytes of SHA-1 Hash-| 312000 diff --git a/ipsc.py b/ipsc.py index 83355d2..133c703 100644 --- a/ipsc.py +++ b/ipsc.py @@ -61,7 +61,17 @@ def hashed_packet(_key, _data): # Take a RECEIVED packet, calculate the auth hash and verify authenticity # def validate_auth(_key, _data): - return + _log = logger.info + _payload = _data[:-10] + _hash = _data[-10:] + _chk_hash = binascii.unhexlify((hmac.new(_key,_payload,hashlib.sha1)).hexdigest()[:20]) + + if _chk_hash == _hash: + _log(' AUTH: Valid - Payload: %s, Hash: %s', binascii.hexlify(_payload), binascii.hexlify(_hash)) + return True + else: + _log(' AUTH: Invalid - Payload: %s, Hash: %s', binascii.hexlify(_payload), binascii.hexlify(_hash)) + return False def process_peer_list(_data, _network): _log = logger.info @@ -305,6 +315,10 @@ class IPSC(DatagramProtocol): _packettype = data[0:1] _peerid = data[1:5] _dec_peerid = int(binascii.b2a_hex(_peerid), 16) + + if validate_auth(self._local['AUTH_KEY'], data) == False: + logger.error('AuthError: IPSC packet failed authentication. Type %s: Peer ID: %s', _packettype, _dec_peerid) + return if (_packettype == PEER_ALIVE_REQ): logger.debug('<<- (%s) Peer Keep-alive Request From Peer ID %s at:%s:%s', self._network, _dec_peerid, host, port) diff --git a/my_ipsc_config_SAMPLE.py b/my_ipsc_config_SAMPLE.py index 7501ef0..8e88c9d 100644 --- a/my_ipsc_config_SAMPLE.py +++ b/my_ipsc_config_SAMPLE.py @@ -43,6 +43,10 @@ NETWORK = { # 'PORT': 50000, # 'RADIO_ID': b'\x00\x00\x00\x00', # 'MODE': b'\x00, +# 'PEER_OPER': False, +# 'PEER_MODE': '', +# 'TS1_LINK': False, +# 'TS2_LINK': False, # 'FLAGS': b'\x00\x00\x00\x00', # 'STATUS': { # 'CONNECTED': False,