Skip to content

Commit

Permalink
Publish encrypted properties when PUBLISH_ADVDATA is 1
Browse files Browse the repository at this point in the history
  • Loading branch information
koenvervloesem committed Jul 16, 2023
1 parent 35dd5bf commit dbfa102
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions TheengsGateway/ble_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,11 @@ def detection_callback(
decrypted_data, data_json, decoded_json
)

# Keep encrypted properties
cipher = decoded_json["cipher"]
mic = decoded_json["mic"]
ctr = decoded_json["ctr"]

# Re-decode advertisement, this time unencrypted
decoded_json = decodeBLE(json.dumps(data_json))
if decoded_json:
Expand All @@ -389,6 +394,11 @@ def detection_callback(
data_json["servicedata"],
)

# Re-add encrypted properties
decoded_json["cipher"] = cipher
decoded_json["mic"] = mic
decoded_json["ctr"] = ctr

except KeyError:
logger.exception(
"Can't find bindkey for %s.", device.address
Expand All @@ -413,6 +423,9 @@ def detection_callback(
"cont",
"track",
"encr",
"cipher",
"mic",
"ctr",
):
decoded_json.pop(key, None)

Expand Down

0 comments on commit dbfa102

Please sign in to comment.