Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix base64 encoding of key field in config #696

Merged
merged 1 commit into from
Oct 18, 2024

Conversation

fmoessbauer
Copy link
Contributor

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

@CLAassistant
Copy link

CLAassistant commented Oct 18, 2024

CLA assistant check
All committers have signed the CLA.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link

codecov bot commented Oct 18, 2024

Codecov Report

Attention: Patch coverage is 0% with 8 lines in your changes missing coverage. Please review.

Project coverage is 60.49%. Comparing base (da7fa31) to head (dfaf1a2).
Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
meshtastic/__main__.py 0.00% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #696      +/-   ##
==========================================
- Coverage   60.62%   60.49%   -0.13%     
==========================================
  Files          24       24              
  Lines        3774     3782       +8     
==========================================
  Hits         2288     2288              
- Misses       1486     1494       +8     
Flag Coverage Δ
unittests 60.49% <0.00%> (-0.13%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@fmoessbauer fmoessbauer changed the title fix base64 encoding of key field in config DRAFT: fix base64 encoding of key field in config Oct 18, 2024
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: meshtastic#678
@fmoessbauer fmoessbauer changed the title DRAFT: fix base64 encoding of key field in config fix base64 encoding of key field in config Oct 18, 2024
@ianmcorvidae
Copy link
Contributor

Cool, thanks for the PR! It might be good if we eventually do this for any bytes field, but I think that's a task for another time. Not letting the perfect be the enemy of the good and all that.

@ianmcorvidae ianmcorvidae merged commit feca49f into meshtastic:master Oct 18, 2024
9 of 11 checks passed
@fmoessbauer
Copy link
Contributor Author

Cool, thanks for the PR! It might be good if we eventually do this for any bytes field, but I think that's a task for another time. Not letting the perfect be the enemy of the good and all that.

Agree, I had a look into that as well. The root-cause is the type incorrectness of google.protobuf.json_format.MessageToDict. AFAIK there is no way to conserve the type. By that, we can either fix it for all well-known types manually, or we write a heuristic that checks if a string "could be" a base64 value and convert it back (or prefix it with base64:, which is BTW also non standard). IMHO this is quite risky as we can have arbitrary user-supplied strings.

A probably better solution is to interface with the protobuf definitions using the class interface instead of passing around plain dicts. This should conserve all types. But this requires a major refactoring.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

configure does not survive PKI keys
3 participants