mirror of
https://github.com/meshtastic/firmware.git
synced 2025-06-09 06:32:06 +00:00
Very rough start on key verification routine
This commit is contained in:
parent
41c1b29d70
commit
0c93c8592b
46
src/modules/KeyVerificationModule.cpp
Normal file
46
src/modules/KeyVerificationModule.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
#include "KeyVerificationModule.h"
|
||||
#include "RTC.h"
|
||||
#include "modules/AdminModule.h"
|
||||
|
||||
KeyVerificationModule::KeyVerificationModule()
|
||||
: SinglePortModule("KeyVerificationModule", meshtastic_PortNum_KEY_VERIFICATION_APP)
|
||||
{
|
||||
}
|
||||
|
||||
AdminMessageHandleResult KeyVerificationModule::handleAdminMessageForModule(const meshtastic_MeshPacket &mp,
|
||||
meshtastic_AdminMessage *request,
|
||||
meshtastic_AdminMessage *response)
|
||||
{
|
||||
if (request->which_payload_variant == meshtastic_AdminMessage_key_verification_tag) {
|
||||
LOG_DEBUG("Handling Key Verification Admin Message");
|
||||
if (mp.from == 0) {
|
||||
meshtastic_MeshPacket *p = allocDataPacket();
|
||||
// check current state, do rate limiting.
|
||||
}
|
||||
return AdminMessageHandleResult::HANDLED;
|
||||
}
|
||||
return AdminMessageHandleResult::NOT_HANDLED;
|
||||
}
|
||||
|
||||
// handle messages to this port
|
||||
|
||||
bool KeyVerificationModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshtastic_KeyVerification *r)
|
||||
{
|
||||
// for each incoming message, do the state timeout check
|
||||
// then if the state is not idle, sanity check for the same nonce and the right current state for the received message
|
||||
//
|
||||
meshtastic_MeshPacket *p = allocDataPacket();
|
||||
}
|
||||
|
||||
bool KeyVerificationModule::sendInitialRequest(NodeNum remoteNode)
|
||||
{
|
||||
// generate nonce
|
||||
currentNonce = random(1, __UINT64_MAX__);
|
||||
currentNonceTimestamp = getTime();
|
||||
currentRemoteNode = remoteNode;
|
||||
}
|
||||
|
||||
bool KeyVerificationModule::sendResponse(const meshtastic_MeshPacket &mp, meshtastic_KeyVerification *r)
|
||||
{
|
||||
currentNonce = r->nonce;
|
||||
}
|
55
src/modules/KeyVerificationModule.h
Normal file
55
src/modules/KeyVerificationModule.h
Normal file
@ -0,0 +1,55 @@
|
||||
#pragma once
|
||||
|
||||
#include "ProtobufModule.h"
|
||||
#include "SinglePortModule.h"
|
||||
|
||||
enum KeyVerificationState {
|
||||
KEY_VERIFICATION_IDLE,
|
||||
KEY_VERIFICATION_SENDER_HAS_INITIATED,
|
||||
KEY_VERIFICATION_SENDER_AWAITING_NUMBER,
|
||||
KEY_VERIFICATION_SENDER_AWAITING_USER,
|
||||
KEY_VERIFICATION_RECEIVER_AWAITING_USER,
|
||||
};
|
||||
|
||||
class KeyVerificationModule
|
||||
: public SinglePortModule //, public ProtobufModule<meshtastic_KeyVerification> //, private concurrency::OSThread //
|
||||
{
|
||||
// CallbackObserver<KeyVerificationModule, const meshtastic::Status *> nodeStatusObserver =
|
||||
// CallbackObserver<KeyVerificationModule, const meshtastic::Status *>(this, &KeyVerificationModule::handleStatusUpdate);
|
||||
|
||||
public:
|
||||
KeyVerificationModule();
|
||||
/* : concurrency::OSThread("KeyVerification"),
|
||||
ProtobufModule("KeyVerification", meshtastic_PortNum_KEY_VERIFICATION_APP, &meshtastic_KeyVerification_msg)
|
||||
{
|
||||
nodeStatusObserver.observe(&nodeStatus->onNewStatus);
|
||||
setIntervalFromNow(setStartDelay()); // Wait until NodeInfo is sent
|
||||
}*/
|
||||
virtual bool wantUIFrame() { return false; };
|
||||
bool sendInitialRequest(NodeNum remoteNode);
|
||||
bool sendResponse(const meshtastic_MeshPacket &, meshtastic_KeyVerification *);
|
||||
|
||||
protected:
|
||||
/* Called to handle a particular incoming message
|
||||
@return true if you've guaranteed you've handled this message and no other handlers should be considered for it
|
||||
*/
|
||||
virtual bool handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshtastic_KeyVerification *p);
|
||||
// virtual meshtastic_MeshPacket *allocReply() override;
|
||||
|
||||
// rather than add to the craziness that is the admin module, just handle those requests here.
|
||||
virtual AdminMessageHandleResult handleAdminMessageForModule(const meshtastic_MeshPacket &mp,
|
||||
meshtastic_AdminMessage *request,
|
||||
meshtastic_AdminMessage *response) override;
|
||||
/*
|
||||
* Send our Telemetry into the mesh
|
||||
*/
|
||||
bool sendMetrics();
|
||||
|
||||
private:
|
||||
uint64_t currentNonce = 0;
|
||||
uint32_t currentNonceTimestamp = 0;
|
||||
NodeNum currentRemoteNode = 0;
|
||||
KeyVerificationState currentstate = KEY_VERIFICATION_IDLE;
|
||||
|
||||
void updateState(); // check the timeouts and maybe reset the state to idle
|
||||
};
|
Loading…
Reference in New Issue
Block a user