New option - ENHANCED_OBP

Extends OpenBridge protocol

Added authenticated KeepAlives to protocol.
This commit is contained in:
Simon 2021-04-04 18:19:28 +01:00
parent b096d5dfa5
commit dda0470ff2
4 changed files with 20 additions and 14 deletions

View File

@ -54,4 +54,6 @@ TARGET_PORT: 62044
USE_ACL: True
SUB_ACL: DENY:1
TGID_ACL: PERMIT:ALL
RELAX_CHECKS: True
ENHANCED_OBP: True

View File

@ -149,6 +149,7 @@ USE_ACL: True
SUB_ACL: DENY:1
TGID_ACL: PERMIT:ALL
RELAX_CHECKS: False
ENHANCED_OBP: False
# MASTER INSTANCES - DUPLICATE SECTION FOR MULTIPLE MASTERS
# HomeBrew Protocol Master instances go here.

View File

@ -303,6 +303,7 @@ def build_config(_config_file):
'TG1_ACL': config.get(section, 'TGID_ACL'),
'TG2_ACL': 'PERMIT:ALL',
'RELAX_CHECKS': config.getboolean(section, 'RELAX_CHECKS')
'ENHANCED_OBP': config.getboolean(section, 'ENHANCED_OBP')
}})

View File

@ -114,8 +114,9 @@ class OPENBRIDGE(DatagramProtocol):
self._laststrid = deque([], 20)
def startProtocol(self):
self._bcka = task.LoopingCall(self.send_bcka)
self._bcka = self._bcka.start(10)
if self._config['ENHANCED_OBP']:
self._bcka = task.LoopingCall(self.send_bcka)
self._bcka = self._bcka.start(10)
def dereg(self):
logger.info('(%s) is mode OPENBRIDGE. No De-Registration required, continuing shutdown', self._system)
@ -205,18 +206,19 @@ class OPENBRIDGE(DatagramProtocol):
h,p = _sockaddr
logger.info('(%s) OpenBridge HMAC failed, packet discarded - OPCODE: %s DATA: %s HMAC LENGTH: %s HMAC: %s SRC IP: %s SRC PORT: %s', self._system, _packet[:4], repr(_packet[:53]), len(_packet[53:]), repr(_packet[53:]),h,p)
if _packet[:2] == BC: # Bridge Control packet (Extended OBP)
if _packet[:4] == BCKA:
_data = _packet[:53]
_hash = _packet[53:]
_ckhs = hmac_new(self._config['PASSPHRASE'],_data,sha1).digest()
if compare_digest(_hash, _ckhs):
logger.debug('(%s) Bridge Control Keep Alive received')
self._config['_bc']['_ka'] = time()
else:
h,p = _sockaddr
logger.info('(%s) OpenBridge BCKA invalid KeepAlive, packet discarded - OPCODE: %s DATA: %s HMAC LENGTH: %s HMAC: %s SRC IP: %s SRC PORT: %s', self._system, _packet[:4], repr(_packet[:53]), len(_packet[53:]), repr(_packet[53:]),h,p)
if self._config['ENHANCED_OBP']:
if _packet[:2] == BC: # Bridge Control packet (Extended OBP)
if _packet[:4] == BCKA:
#_data = _packet[:53]
_hash = _packet[4:]
_ckhs = hmac_new(self._config['PASSPHRASE'],_packet[:4],sha1).digest()
if compare_digest(_hash, _ckhs):
logger.debug('(%s) Bridge Control Keep Alive received',self._system)
self._config['_bcka'] = time()
else:
h,p = _sockaddr
logger.info('(%s) OpenBridge BCKA invalid KeepAlive, packet discarded - OPCODE: %s DATA: %s HMAC LENGTH: %s HMAC: %s SRC IP: %s SRC PORT: %s', self._system, _packet[:4], repr(_packet[:53]), len(_packet[53:]), repr(_packet[53:]),h,p)
#************************************************