diff --git a/bridge.py b/bridge.py index f906372..436c164 100755 --- a/bridge.py +++ b/bridge.py @@ -102,30 +102,11 @@ class bridgeIPSC(IPSC): def xcmp_xnl(self, _network, _data): pass -class bridgeUnauthIPSC(bridgeIPSC): - - # There isn't a hash to build, so just return the data - # - def hashed_packet(self, _key, _data): - return _data - - # Remove the hash from a packet and return the payload... except don't - # - def strip_hash(self, _data): - return _data - - # Everything is validated, so just return True - # - def validate_auth(self, _key, _data): - return True if __name__ == '__main__': - logger.info('DMRlink \'bridge.py\' (c) 2013 N0MJS & the K0USY Group - SYSTEM STARTING...') + logger.info('DMRlink \'bridge.py\' (c) 2013, 2014 N0MJS & the K0USY Group - SYSTEM STARTING...') for ipsc_network in NETWORK: if NETWORK[ipsc_network]['LOCAL']['ENABLED']: - if NETWORK[ipsc_network]['LOCAL']['AUTH_ENABLED']: - networks[ipsc_network] = bridgeIPSC(ipsc_network) - else: - networks[ipsc_network] = bridgeUnauthIPSC(ipsc_network) + networks[ipsc_network] = bridgeIPSC(ipsc_network) reactor.listenUDP(NETWORK[ipsc_network]['LOCAL']['PORT'], networks[ipsc_network]) reactor.run() diff --git a/dmrlink.py b/dmrlink.py index e2510f0..b293254 100755 --- a/dmrlink.py +++ b/dmrlink.py @@ -591,6 +591,16 @@ class IPSC(DatagramProtocol): # logger.error('(%s) IPSC Instance Could Not be Created... Exiting', self._network) sys.exit() + + # Choose which set of fucntions to use - authenticated or not + if self._local['AUTH_ENABLED']: + self.hashed_packet = self.auth_hashed_packet + self.strip_hash = self.auth_strip_hash + self.validate_auth = self.auth_validate_auth + else: + self.hashed_packet = self.unauth_hashed_packet + self.strip_hash = self.unauth_strip_hash + self.validate_auth = self.unauth_validate_auth # This is called by REACTOR when it starts, We use it to set up the timed @@ -666,20 +676,24 @@ class IPSC(DatagramProtocol): if _peerid == self._master['RADIO_ID']: self._master_stat['KEEP_ALIVES_OUTSTANDING'] = 0 + # + # NEXT THREE FUNCITONS ARE FOR AUTHENTICATED PACKETS + # + # Take a packet to be SENT, calculate auth hash and return the whole thing # - def hashed_packet(self, _key, _data): + def auth_hashed_packet(self, _key, _data): _hash = binascii.a2b_hex((hmac_new(_key,_data,sha1)).hexdigest()[:20]) return _data + _hash # Remove the hash from a packet and return the payload # - def strip_hash(self, _data): + def auth_strip_hash(self, _data): return _data[:-10] # Take a RECEIVED packet, calculate the auth hash and verify authenticity # - def validate_auth(self, _key, _data): + def auth_validate_auth(self, _key, _data): _payload = self.strip_hash(_data) _hash = _data[-10:] _chk_hash = binascii.a2b_hex((hmac_new(_key,_payload,sha1)).hexdigest()[:20]) @@ -688,6 +702,25 @@ class IPSC(DatagramProtocol): return True else: return False + + # + # NEXT THREE FUNCITONS ARE FOR UN-AUTHENTICATED PACKETS + # + + # There isn't a hash to build, so just return the data + # + def unauth_hashed_packet(self, _key, _data): + return _data + + # Remove the hash from a packet and return the payload... except don't + # + def unauth_strip_hash(self, _data): + return _data + + # Everything is validated, so just return True + # + def unauth_validate_auth(self, _key, _data): + return True #************************************************ @@ -993,29 +1026,6 @@ class IPSC(DatagramProtocol): self.unknown_message(self._network, _packettype, _peerid, data) return - -#************************************************ -# Derived Class -# used in the rare event of an -# unauthenticated IPSC network. -#************************************************ - -class UnauthIPSC(IPSC): - - # There isn't a hash to build, so just return the data - # - def hashed_packet(self, _key, _data): - return _data - - # Remove the hash from a packet and return the payload... except don't - # - def strip_hash(self, _data): - return _data - - # Everything is validated, so just return True - # - def validate_auth(self, _key, _data): - return True #************************************************ @@ -1023,13 +1033,10 @@ class UnauthIPSC(IPSC): #************************************************ if __name__ == '__main__': - logger.info('DMRlink \'dmrlink.py\' (c) 2013 N0MJS & the K0USY Group - SYSTEM STARTING...') + logger.info('DMRlink \'dmrlink.py\' (c) 2013, 2014 N0MJS & the K0USY Group - SYSTEM STARTING...') networks = {} for ipsc_network in NETWORK: if NETWORK[ipsc_network]['LOCAL']['ENABLED']: - if NETWORK[ipsc_network]['LOCAL']['AUTH_ENABLED']: - networks[ipsc_network] = IPSC(ipsc_network) - else: - networks[ipsc_network] = UnauthIPSC(ipsc_network) + networks[ipsc_network] = IPSC(ipsc_network) reactor.listenUDP(NETWORK[ipsc_network]['LOCAL']['PORT'], networks[ipsc_network]) reactor.run() \ No newline at end of file diff --git a/log.py b/log.py index a012199..7c3e2c5 100755 --- a/log.py +++ b/log.py @@ -15,7 +15,7 @@ from twisted.internet import reactor from binascii import b2a_hex as h import time -from dmrlink import IPSC, UnauthIPSC, NETWORK, networks, get_info, int_id, subscriber_ids, peer_ids, talkgroup_ids, logger +from dmrlink import IPSC, NETWORK, networks, get_info, int_id, subscriber_ids, peer_ids, talkgroup_ids, logger __author__ = 'Cortney T. Buffington, N0MJS' __copyright__ = 'Copyright (c) 2013 Cortney T. Buffington, N0MJS and the K0USY Group' @@ -82,29 +82,11 @@ class logIPSC(IPSC): _src_sub = get_info(int_id(_src_sub), subscriber_ids) print('({}) Private Data Packet Received From: {} To: {}' .format(_network, _src_sub, _dst_sub)) -class logUnauthIPSC(logIPSC): - - # There isn't a hash to build, so just return the data - # - def hashed_packet(self, _key, _data): - return _data - - # Remove the hash from a packet and return the payload... except don't - # - def strip_hash(self, _data): - return _data - - # Everything is validated, so just return True - # - def validate_auth(self, _key, _data): - return True + if __name__ == '__main__': - logger.info('DMRlink \'log.py\' (c) 2013 N0MJS & the K0USY Group - SYSTEM STARTING...') + logger.info('DMRlink \'log.py\' (c) 2013, 2014 N0MJS & the K0USY Group - SYSTEM STARTING...') for ipsc_network in NETWORK: if NETWORK[ipsc_network]['LOCAL']['ENABLED']: - if NETWORK[ipsc_network]['LOCAL']['AUTH_ENABLED']: - networks[ipsc_network] = logIPSC(ipsc_network) - else: - networks[ipsc_network] = logUnauthIPSC(ipsc_network) + networks[ipsc_network] = logIPSC(ipsc_network) reactor.listenUDP(NETWORK[ipsc_network]['LOCAL']['PORT'], networks[ipsc_network]) reactor.run() \ No newline at end of file diff --git a/playback.py b/playback.py index c60f466..eb1d8cf 100755 --- a/playback.py +++ b/playback.py @@ -15,7 +15,7 @@ from twisted.internet import reactor from binascii import b2a_hex as h import sys, time -from dmrlink import IPSC, UnauthIPSC, NETWORK, networks, logger, dmr_nat, int_id, send_to_ipsc, hex_id +from dmrlink import IPSC, NETWORK, networks, logger, dmr_nat, int_id, send_to_ipsc, hex_id __author__ = 'Cortney T. Buffington, N0MJS' __copyright__ = 'Copyright (c) 2014 Cortney T. Buffington, N0MJS and the K0USY Group' @@ -65,31 +65,11 @@ class playbackIPSC(IPSC): time.sleep(0.06) self.CALL_DATA = [] - -class playbackUnauthIPSC(playbackIPSC): - - # There isn't a hash to build, so just return the data - # - def hashed_packet(self, _key, _data): - return _data - - # Remove the hash from a packet and return the payload... except don't - # - def strip_hash(self, _data): - return _data - - # Everything is validated, so just return True - # - def validate_auth(self, _key, _data): - return True if __name__ == '__main__': - logger.info('DMRlink \'playback.py\' (c) 2014 N0MJS & the K0USY Group - SYSTEM STARTING...') + logger.info('DMRlink \'playback.py\' (c) 2013, 2014 N0MJS & the K0USY Group - SYSTEM STARTING...') for ipsc_network in NETWORK: if NETWORK[ipsc_network]['LOCAL']['ENABLED']: - if NETWORK[ipsc_network]['LOCAL']['AUTH_ENABLED']: - networks[ipsc_network] = playbackIPSC(ipsc_network) - else: - networks[ipsc_network] = playbackUnauthIPSC(ipsc_network) + networks[ipsc_network] = playbackIPSC(ipsc_network) reactor.listenUDP(NETWORK[ipsc_network]['LOCAL']['PORT'], networks[ipsc_network]) reactor.run() \ No newline at end of file diff --git a/rcm.py b/rcm.py index e41a851..f753e01 100755 --- a/rcm.py +++ b/rcm.py @@ -21,7 +21,7 @@ from binascii import b2a_hex as h import time import binascii import dmrlink -from dmrlink import IPSC, UnauthIPSC, NETWORK, networks, get_info, int_id, subscriber_ids, peer_ids, talkgroup_ids, logger +from dmrlink import IPSC, NETWORK, networks, get_info, int_id, subscriber_ids, peer_ids, talkgroup_ids, logger __author__ = 'Cortney T. Buffington, N0MJS' __copyright__ = 'Copyright (c) 2013 Cortney T. Buffington, N0MJS and the K0USY Group' @@ -141,29 +141,11 @@ class rcmIPSC(IPSC): _source_name = get_info(_source_dec, peer_ids) print('({}) Repeater Wake-Up Packet Received: {} ({})' .format(_network, _source_name, _source_dec)) -class rcmUnauthIPSC(rcmIPSC): - - # There isn't a hash to build, so just return the data - # - def hashed_packet(self, _key, _data): - return _data - - # Remove the hash from a packet and return the payload... except don't - # - def strip_hash(self, _data): - return _data - - # Everything is validated, so just return True - # - def validate_auth(self, _key, _data): - return True + if __name__ == '__main__': - logger.info('DMRlink \'rcm.py\' (c) 2013 N0MJS & the K0USY Group - SYSTEM STARTING...') + logger.info('DMRlink \'rcm.py\' (c) 2013, 2014 N0MJS & the K0USY Group - SYSTEM STARTING...') for ipsc_network in NETWORK: - if (NETWORK[ipsc_network]['LOCAL']['ENABLED']): - if NETWORK[ipsc_network]['LOCAL']['AUTH_ENABLED'] == True: - networks[ipsc_network] = rcmIPSC(ipsc_network) - else: - networks[ipsc_network] = rcmUnauthIPSC(ipsc_network) + if NETWORK[ipsc_network]['LOCAL']['ENABLED']: + networks[ipsc_network] = rcmIPSC(ipsc_network) reactor.listenUDP(NETWORK[ipsc_network]['LOCAL']['PORT'], networks[ipsc_network]) reactor.run() \ No newline at end of file