Added IPSC Authentication Validation Function

We can now pass the auth key, and a packet to this function and get a
pass/fail (True/False) return.
This commit is contained in:
Cort Buffington 2013-07-29 13:23:37 -05:00
parent 7c6899e49f
commit 724f9299cb
3 changed files with 20 additions and 1 deletions

View File

@ -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

16
ipsc.py
View File

@ -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)

View File

@ -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,