-
Notifications
You must be signed in to change notification settings - Fork 960
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
Implement public/private key encryption for direct messages #1509
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -183,6 +183,11 @@ void printBytes(const char *label, const uint8_t *p, size_t numbytes) | |
DEBUG_MSG("\n"); | ||
} | ||
|
||
bool isDirectMessage(const MeshPacket *p) | ||
{ | ||
return p->to != -1 && (p->decoded.portnum == PortNum_ROUTING_APP) ? false : p->want_ack; | ||
} | ||
|
||
/** | ||
* Send a packet on a suitable interface. This routine will | ||
* later free() the packet to pool. This routine is not allowed to stall. | ||
|
@@ -239,6 +244,7 @@ ErrorCode Router::send(MeshPacket *p) | |
#endif | ||
|
||
auto encodeResult = perhapsEncode(p); | ||
if (isDirectMessage(p)) p->want_ack = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think isDirectMessage(p) will never be true if p->want_ack is not true already before, so this line will not do anything. |
||
if (encodeResult != Routing_Error_NONE) { | ||
abortSendAndNak(encodeResult, p); | ||
return encodeResult; // FIXME - this isn't a valid ErrorCode | ||
|
@@ -304,6 +310,8 @@ bool perhapsDecode(MeshPacket *p) | |
DEBUG_MSG("Invalid portnum (bad psk?)!\n"); | ||
} else { | ||
// parsing was successful | ||
if (isDirectMessage(p) && p->to == nodeDB.getNodeNum()) // This is a direct message to us so decrypt the payload | ||
crypto->decryptCurve25519_Blake2b(p->from, p->id, p->decoded.payload.size, p->decoded.payload.bytes); | ||
p->which_payloadVariant = MeshPacket_decoded_tag; // change type to decoded | ||
p->channel = chIndex; // change to store the index instead of the hash | ||
|
||
|
@@ -344,12 +352,15 @@ bool perhapsDecode(MeshPacket *p) | |
return false; | ||
} | ||
|
||
/** Return 0 for success or a Routing_Errror code for failure | ||
/** Return 0 for success or a Routing_Error code for failure | ||
*/ | ||
Routing_Error perhapsEncode(MeshPacket *p) | ||
{ | ||
// If the packet is not yet encrypted, do so now | ||
if (p->which_payloadVariant == MeshPacket_decoded_tag) { | ||
if (isDirectMessage(p)) // Encrypt the payload for the recipient node seperately from the rest of the packet | ||
crypto->encryptCurve25519_Blake2b(p->to, getFrom(p), p->id, p->decoded.payload.size, p->decoded.payload.bytes); | ||
|
||
static uint8_t bytes[MAX_RHPACKETLEN]; // we have to use a scratch buffer because a union | ||
|
||
size_t numbytes = pb_encode_to_bytes(bytes, sizeof(bytes), Data_fields, &p->decoded); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -159,7 +159,7 @@ extern const pb_msgdesc_t OEMStore_msg; | |
|
||
/* Maximum encoded size of messages (where known) */ | ||
#define ChannelFile_size 624 | ||
#define DeviceState_size 23728 | ||
#define DeviceState_size 26598 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ouch ... RAM usage... |
||
#define OEMStore_size 2106 | ||
|
||
#ifdef __cplusplus | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please initialize private_key, public_key and keyPairSet