Removed Class & Inheritance for Unauth IPSCs
Previously, an unauthenticated network used a different class that subclassed IPSC and overrode the the three functions that affect authentication. Now, during class instantiation ( with __init__ ), the set of functions are “aliased” depending on whether or not the IPSC’s auth flag is set in dmrlink.cfg
This commit is contained in:
parent
10012548e9
commit
43e11ea19a
23
bridge.py
23
bridge.py
@ -102,30 +102,11 @@ class bridgeIPSC(IPSC):
|
|||||||
def xcmp_xnl(self, _network, _data):
|
def xcmp_xnl(self, _network, _data):
|
||||||
pass
|
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__':
|
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:
|
for ipsc_network in NETWORK:
|
||||||
if NETWORK[ipsc_network]['LOCAL']['ENABLED']:
|
if NETWORK[ipsc_network]['LOCAL']['ENABLED']:
|
||||||
if NETWORK[ipsc_network]['LOCAL']['AUTH_ENABLED']:
|
networks[ipsc_network] = bridgeIPSC(ipsc_network)
|
||||||
networks[ipsc_network] = bridgeIPSC(ipsc_network)
|
|
||||||
else:
|
|
||||||
networks[ipsc_network] = bridgeUnauthIPSC(ipsc_network)
|
|
||||||
reactor.listenUDP(NETWORK[ipsc_network]['LOCAL']['PORT'], networks[ipsc_network])
|
reactor.listenUDP(NETWORK[ipsc_network]['LOCAL']['PORT'], networks[ipsc_network])
|
||||||
reactor.run()
|
reactor.run()
|
||||||
|
69
dmrlink.py
69
dmrlink.py
@ -591,6 +591,16 @@ class IPSC(DatagramProtocol):
|
|||||||
#
|
#
|
||||||
logger.error('(%s) IPSC Instance Could Not be Created... Exiting', self._network)
|
logger.error('(%s) IPSC Instance Could Not be Created... Exiting', self._network)
|
||||||
sys.exit()
|
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
|
# 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']:
|
if _peerid == self._master['RADIO_ID']:
|
||||||
self._master_stat['KEEP_ALIVES_OUTSTANDING'] = 0
|
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
|
# 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])
|
_hash = binascii.a2b_hex((hmac_new(_key,_data,sha1)).hexdigest()[:20])
|
||||||
return _data + _hash
|
return _data + _hash
|
||||||
|
|
||||||
# Remove the hash from a packet and return the payload
|
# Remove the hash from a packet and return the payload
|
||||||
#
|
#
|
||||||
def strip_hash(self, _data):
|
def auth_strip_hash(self, _data):
|
||||||
return _data[:-10]
|
return _data[:-10]
|
||||||
|
|
||||||
# Take a RECEIVED packet, calculate the auth hash and verify authenticity
|
# 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)
|
_payload = self.strip_hash(_data)
|
||||||
_hash = _data[-10:]
|
_hash = _data[-10:]
|
||||||
_chk_hash = binascii.a2b_hex((hmac_new(_key,_payload,sha1)).hexdigest()[:20])
|
_chk_hash = binascii.a2b_hex((hmac_new(_key,_payload,sha1)).hexdigest()[:20])
|
||||||
@ -688,6 +702,25 @@ class IPSC(DatagramProtocol):
|
|||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
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)
|
self.unknown_message(self._network, _packettype, _peerid, data)
|
||||||
return
|
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__':
|
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 = {}
|
networks = {}
|
||||||
for ipsc_network in NETWORK:
|
for ipsc_network in NETWORK:
|
||||||
if NETWORK[ipsc_network]['LOCAL']['ENABLED']:
|
if NETWORK[ipsc_network]['LOCAL']['ENABLED']:
|
||||||
if NETWORK[ipsc_network]['LOCAL']['AUTH_ENABLED']:
|
networks[ipsc_network] = IPSC(ipsc_network)
|
||||||
networks[ipsc_network] = IPSC(ipsc_network)
|
|
||||||
else:
|
|
||||||
networks[ipsc_network] = UnauthIPSC(ipsc_network)
|
|
||||||
reactor.listenUDP(NETWORK[ipsc_network]['LOCAL']['PORT'], networks[ipsc_network])
|
reactor.listenUDP(NETWORK[ipsc_network]['LOCAL']['PORT'], networks[ipsc_network])
|
||||||
reactor.run()
|
reactor.run()
|
26
log.py
26
log.py
@ -15,7 +15,7 @@ from twisted.internet import reactor
|
|||||||
from binascii import b2a_hex as h
|
from binascii import b2a_hex as h
|
||||||
|
|
||||||
import time
|
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'
|
__author__ = 'Cortney T. Buffington, N0MJS'
|
||||||
__copyright__ = 'Copyright (c) 2013 Cortney T. Buffington, N0MJS and the K0USY Group'
|
__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)
|
_src_sub = get_info(int_id(_src_sub), subscriber_ids)
|
||||||
print('({}) Private Data Packet Received From: {} To: {}' .format(_network, _src_sub, _dst_sub))
|
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__':
|
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:
|
for ipsc_network in NETWORK:
|
||||||
if NETWORK[ipsc_network]['LOCAL']['ENABLED']:
|
if NETWORK[ipsc_network]['LOCAL']['ENABLED']:
|
||||||
if NETWORK[ipsc_network]['LOCAL']['AUTH_ENABLED']:
|
networks[ipsc_network] = logIPSC(ipsc_network)
|
||||||
networks[ipsc_network] = logIPSC(ipsc_network)
|
|
||||||
else:
|
|
||||||
networks[ipsc_network] = logUnauthIPSC(ipsc_network)
|
|
||||||
reactor.listenUDP(NETWORK[ipsc_network]['LOCAL']['PORT'], networks[ipsc_network])
|
reactor.listenUDP(NETWORK[ipsc_network]['LOCAL']['PORT'], networks[ipsc_network])
|
||||||
reactor.run()
|
reactor.run()
|
26
playback.py
26
playback.py
@ -15,7 +15,7 @@ from twisted.internet import reactor
|
|||||||
from binascii import b2a_hex as h
|
from binascii import b2a_hex as h
|
||||||
|
|
||||||
import sys, time
|
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'
|
__author__ = 'Cortney T. Buffington, N0MJS'
|
||||||
__copyright__ = 'Copyright (c) 2014 Cortney T. Buffington, N0MJS and the K0USY Group'
|
__copyright__ = 'Copyright (c) 2014 Cortney T. Buffington, N0MJS and the K0USY Group'
|
||||||
@ -65,31 +65,11 @@ class playbackIPSC(IPSC):
|
|||||||
time.sleep(0.06)
|
time.sleep(0.06)
|
||||||
self.CALL_DATA = []
|
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__':
|
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:
|
for ipsc_network in NETWORK:
|
||||||
if NETWORK[ipsc_network]['LOCAL']['ENABLED']:
|
if NETWORK[ipsc_network]['LOCAL']['ENABLED']:
|
||||||
if NETWORK[ipsc_network]['LOCAL']['AUTH_ENABLED']:
|
networks[ipsc_network] = playbackIPSC(ipsc_network)
|
||||||
networks[ipsc_network] = playbackIPSC(ipsc_network)
|
|
||||||
else:
|
|
||||||
networks[ipsc_network] = playbackUnauthIPSC(ipsc_network)
|
|
||||||
reactor.listenUDP(NETWORK[ipsc_network]['LOCAL']['PORT'], networks[ipsc_network])
|
reactor.listenUDP(NETWORK[ipsc_network]['LOCAL']['PORT'], networks[ipsc_network])
|
||||||
reactor.run()
|
reactor.run()
|
28
rcm.py
28
rcm.py
@ -21,7 +21,7 @@ from binascii import b2a_hex as h
|
|||||||
import time
|
import time
|
||||||
import binascii
|
import binascii
|
||||||
import dmrlink
|
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'
|
__author__ = 'Cortney T. Buffington, N0MJS'
|
||||||
__copyright__ = 'Copyright (c) 2013 Cortney T. Buffington, N0MJS and the K0USY Group'
|
__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)
|
_source_name = get_info(_source_dec, peer_ids)
|
||||||
print('({}) Repeater Wake-Up Packet Received: {} ({})' .format(_network, _source_name, _source_dec))
|
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__':
|
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:
|
for ipsc_network in NETWORK:
|
||||||
if (NETWORK[ipsc_network]['LOCAL']['ENABLED']):
|
if NETWORK[ipsc_network]['LOCAL']['ENABLED']:
|
||||||
if NETWORK[ipsc_network]['LOCAL']['AUTH_ENABLED'] == True:
|
networks[ipsc_network] = rcmIPSC(ipsc_network)
|
||||||
networks[ipsc_network] = rcmIPSC(ipsc_network)
|
|
||||||
else:
|
|
||||||
networks[ipsc_network] = rcmUnauthIPSC(ipsc_network)
|
|
||||||
reactor.listenUDP(NETWORK[ipsc_network]['LOCAL']['PORT'], networks[ipsc_network])
|
reactor.listenUDP(NETWORK[ipsc_network]['LOCAL']['PORT'], networks[ipsc_network])
|
||||||
reactor.run()
|
reactor.run()
|
Loading…
x
Reference in New Issue
Block a user