Skip to content

Commit

Permalink
More useful PKC logging (#4742)
Browse files Browse the repository at this point in the history
  • Loading branch information
jp-bennett authored Sep 17, 2024
1 parent 1137832 commit a967dd5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/mesh/CryptoEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ bool CryptoEngine::encryptCurve25519(uint32_t toNode, uint32_t fromNode, uint64_

// Calculate the shared secret with the destination node and encrypt
printBytes("Attempting encrypt using nonce: ", nonce, 13);
printBytes("Attempting encrypt using shared_key: ", shared_key, 32);
printBytes("Attempting encrypt using shared_key starting with: ", shared_key, 8);
aes_ccm_ae(shared_key, 32, nonce, 8, bytes, numBytes, nullptr, 0, bytesOut,
auth); // this can write up to 15 bytes longer than numbytes past bytesOut
*extraNonce = extraNonceTmp;
Expand Down Expand Up @@ -117,7 +117,7 @@ bool CryptoEngine::decryptCurve25519(uint32_t fromNode, uint64_t packetNum, size
}
initNonce(fromNode, packetNum, *extraNonce);
printBytes("Attempting decrypt using nonce: ", nonce, 13);
printBytes("Attempting decrypt using shared_key: ", shared_key, 32);
printBytes("Attempting decrypt using shared_key starting with: ", shared_key, 8);
return aes_ccm_ad(shared_key, 32, nonce, 8, bytes, numBytes - 12, nullptr, 0, auth, bytesOut);
}

Expand All @@ -137,11 +137,12 @@ bool CryptoEngine::setDHKey(uint32_t nodeNum)
LOG_DEBUG("Node %d or their public_key not found\n", nodeNum);
return false;
}

printBytes("Generating DH with remote pubkey: ", node->user.public_key.bytes, 32);
printBytes("And local pubkey: ", config.security.public_key.bytes, 32);
if (!setDHPublicKey(node->user.public_key.bytes))
return false;

printBytes("DH Output: ", shared_key, 32);
// printBytes("DH Output: ", shared_key, 32);

/**
* D.J. Bernstein reccomends hashing the shared key. We want to do this because there are
Expand Down
3 changes: 3 additions & 0 deletions src/mesh/Router.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,11 @@ bool perhapsDecode(meshtastic_MeshPacket *p)
// memcpy(bytes, ScratchEncrypted, rawSize); // TODO: Rename the bytes buffers
// chIndex = 8;
} else {
LOG_ERROR("PKC Decrypted, but pb_decode failed!\n");
return false;
}
} else {
LOG_WARN("PKC decrypt attempted but failed!\n");
}
}
#endif
Expand Down

0 comments on commit a967dd5

Please sign in to comment.