Skip to content

Commit

Permalink
fix base64 encoding of key field in config
Browse files Browse the repository at this point in the history
The security.privateKey and security.publicKey fields are of type bytes,
but the protobuf MessageToDict converts them to base64 encoded strings.
When importing the config again, this is read as a string, which breaks
the import. Instead, the value needs to be prefixed with "base64:", so
the type handling logic on import kicks in and decodes the value to a
bytes array again.

Fixes: #678
  • Loading branch information
fmoessbauer committed Oct 18, 2024
1 parent da7fa31 commit dfaf1a2
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions meshtastic/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1034,6 +1034,15 @@ def export_config(interface):
prefs[meshtastic.util.snake_to_camel(pref)] = config[pref]
else:
prefs[pref] = config[pref]
# mark base64 encoded fields as such
if pref == "security":
if 'privateKey' in prefs[pref]:
prefs[pref]['privateKey'] = 'base64:' + prefs[pref]['privateKey']
if 'publicKey' in prefs[pref]:
prefs[pref]['publicKey'] = 'base64:' + prefs[pref]['publicKey']
if 'adminKey' in prefs[pref]:
for i in range(len(prefs[pref]['adminKey'])):
prefs[pref]['adminKey'][i] = 'base64:' + prefs[pref]['adminKey'][i]

Check warning on line 1045 in meshtastic/__main__.py

View check run for this annotation

Codecov / codecov/patch

meshtastic/__main__.py#L1038-L1045

Added lines #L1038 - L1045 were not covered by tests
if mt_config.camel_case:
configObj["config"] = config
else:
Expand Down

0 comments on commit dfaf1a2

Please sign in to comment.