support providing custom decryption keys via command line args
This commit is contained in:
24
src/mqtt.js
24
src/mqtt.js
@ -29,6 +29,13 @@ const options = commandLineArgs([
|
||||
type: Boolean,
|
||||
description: "This option will save all received service envelopes to the database.",
|
||||
},
|
||||
{
|
||||
name: "decryption-keys",
|
||||
type: String,
|
||||
multiple: true,
|
||||
typeLabel: "<base64DecryptionKey>",
|
||||
description: "Decryption keys encoded in base64 to use when decrypting service envelopes.",
|
||||
},
|
||||
]);
|
||||
|
||||
// get options and fallback to default values
|
||||
@ -36,6 +43,9 @@ const mqttBrokerUrl = options["mqtt-broker-url"] ?? "mqtt://mqtt.meshtastic.org"
|
||||
const mqttUsername = options["mqtt-username"] ?? "meshdev";
|
||||
const mqttPassword = options["mqtt-password"] ?? "large4cats";
|
||||
const collectServiceEnvelopes = options["collect-service-envelopes"] ?? false;
|
||||
const decryptionKeys = options["decryption-keys"] ?? [
|
||||
"1PG7OiApB1nwvP+rz05pAQ==", // add default "AQ==" decryption key
|
||||
];
|
||||
|
||||
// create mqtt client
|
||||
const client = mqtt.connect(mqttBrokerUrl, {
|
||||
@ -83,10 +93,13 @@ function createNonce(packetId, fromNode) {
|
||||
* https://github.com/pdxlocations/Meshtastic-MQTT-Connect/blob/main/meshtastic-mqtt-connect.py#L381
|
||||
*/
|
||||
function decrypt(packet) {
|
||||
|
||||
// attempt to decrypt with all available decryption keys
|
||||
for(const decryptionKey of decryptionKeys){
|
||||
try {
|
||||
|
||||
// default encryption key
|
||||
const key = Buffer.from("1PG7OiApB1nwvP+rz05pAQ==", "base64");
|
||||
// convert encryption key to buffer
|
||||
const key = Buffer.from(decryptionKey, "base64");
|
||||
|
||||
// create decryption iv/nonce for this packet
|
||||
const nonceBuffer = createNonce(packet.id, packet.from);
|
||||
@ -100,9 +113,12 @@ function decrypt(packet) {
|
||||
// parse as data message
|
||||
return Data.decode(decryptedBuffer);
|
||||
|
||||
} catch(e) {
|
||||
return null;
|
||||
} catch(e){}
|
||||
}
|
||||
|
||||
// couldn't decrypt
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
// subscribe to everything when connected
|
||||
|
Reference in New Issue
Block a user