mirror of
https://github.com/meshtastic/firmware.git
synced 2025-12-20 17:52:35 +00:00
Key regen and MQTT fix (#4585)
* Add public key regen * Properly label and handle PKI MQTT packets * Extra debug message to indicate PKI_UNKNOWN_PUBKEY * Ternary! * Don't call non-existant function on stm32 * Actually fix STM32 compilation
This commit is contained in:
@@ -139,14 +139,24 @@ NodeDB::NodeDB()
|
||||
crypto->setDHPrivateKey(config.security.private_key.bytes);
|
||||
} else {
|
||||
#if !(MESHTASTIC_EXCLUDE_PKI_KEYGEN)
|
||||
LOG_INFO("Generating new PKI keys\n");
|
||||
crypto->generateKeyPair(config.security.public_key.bytes, config.security.private_key.bytes);
|
||||
config.security.public_key.size = 32;
|
||||
config.security.private_key.size = 32;
|
||||
|
||||
printBytes("New Pubkey", config.security.public_key.bytes, 32);
|
||||
owner.public_key.size = 32;
|
||||
memcpy(owner.public_key.bytes, config.security.public_key.bytes, 32);
|
||||
bool keygenSuccess = false;
|
||||
if (config.security.private_key.size == 32) {
|
||||
LOG_INFO("Calculating PKI Public Key\n");
|
||||
if (crypto->regeneratePublicKey(config.security.public_key.bytes, config.security.private_key.bytes)) {
|
||||
keygenSuccess = true;
|
||||
}
|
||||
} else {
|
||||
LOG_INFO("Generating new PKI keys\n");
|
||||
crypto->generateKeyPair(config.security.public_key.bytes, config.security.private_key.bytes);
|
||||
keygenSuccess = true;
|
||||
}
|
||||
if (keygenSuccess) {
|
||||
config.security.public_key.size = 32;
|
||||
config.security.private_key.size = 32;
|
||||
printBytes("New Pubkey", config.security.public_key.bytes, 32);
|
||||
owner.public_key.size = 32;
|
||||
memcpy(owner.public_key.bytes, config.security.public_key.bytes, 32);
|
||||
}
|
||||
#else
|
||||
LOG_INFO("No PKI keys set, and generation disabled!\n");
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user