Skip to content

Commit a4aba3d

Browse files
author
Johan Carlsson
committed
Add master key to ControlPanel initialization.
Signed-off-by: Johan Carlsson <johan.carlsson@teenage.engineering>
1 parent d7af9d1 commit a4aba3d

4 files changed

Lines changed: 9 additions & 7 deletions

File tree

osdp/_bus.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ def send_command(self, command: Command):
4444
else:
4545
log.warning("Device not found with address %s", command.address)
4646

47-
def add_device(self, address: int, use_crc: bool, use_secure_channel: bool) -> Device:
47+
def add_device(self, address: int, use_crc: bool, use_secure_channel: bool, master_key: bytes) -> Device:
4848
found_device = self._configured_devices.get(address)
4949
self._configured_devices_lock.acquire()
5050
if found_device is not None:
5151
self._configured_devices.pop(address)
52-
self._configured_devices[address] = Device(address, use_crc, use_secure_channel)
52+
self._configured_devices[address] = Device(address, use_crc, use_secure_channel, master_key)
5353
self._configured_devices_lock.release()
5454
return self._configured_devices[address]
5555

osdp/_control_panel.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@
2323

2424
class ControlPanel:
2525

26-
def __init__(self):
26+
def __init__(self, master_key: bytes = None):
2727
self._buses = {}
2828
self._reply_handlers = []
2929
self._reply_timeout = 5.0
30+
self._master_key = master_key
3031

3132
def start_connection(self, connection: OsdpConnection) -> UUID:
3233
bus = Bus(connection, self.on_reply_received)
@@ -100,7 +101,7 @@ def shutdown(self):
100101
def add_device(self, connection_id: UUID, address: int, use_crc: bool, use_secure_channel: bool):
101102
bus = self._buses.get(connection_id)
102103
if bus is not None:
103-
bus.add_device(address, use_crc, use_secure_channel)
104+
bus.add_device(address, use_crc, use_secure_channel, self._master_key)
104105

105106
def remove_device(self, connection_id: UUID, address: int):
106107
bus = self._buses.get(connection_id)

osdp/_device.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313

1414
class Device(object):
1515

16-
def __init__(self, address: int, use_crc: bool, use_secure_channel: bool):
16+
def __init__(self, address: int, use_crc: bool, use_secure_channel: bool, master_key: bytes):
1717
self._use_secure_channel = use_secure_channel
1818
self.address = address
1919
self.message_control = Control(0, use_crc, use_secure_channel)
2020

2121
self._commands = queue.Queue()
22-
self._secure_channel = SecureChannel()
22+
self._secure_channel = SecureChannel(master_key)
2323
self._last_valid_reply = datetime.datetime.utcfromtimestamp(0)
2424

2525
@property

osdp/_secure_channel.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class SecureChannel:
1010
0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F
1111
])
1212

13-
def __init__(self):
13+
def __init__(self, master_key: bytes):
1414
self._cmac = None
1515
self._enc = None
1616
self._rmac = None
@@ -21,6 +21,7 @@ def __init__(self):
2121
self.server_cryptogram = None
2222
self.is_initialized = False
2323
self.is_established = False
24+
self.master_key = master_key
2425
self.reset()
2526

2627
def initialize(self, cuid: bytes, client_random_number: bytes, client_cryptogram: bytes):

0 commit comments

Comments
 (0)