diff --git a/include/controller.h b/include/controller.h index 739d5cc..0850293 100644 --- a/include/controller.h +++ b/include/controller.h @@ -73,7 +73,7 @@ private: void processMessage(AuthenticatedMessage* message); SesameEvent verifyAndProcessReceivedMessage(AuthenticatedMessage* message); - uint16_t prepareResponseBuffer(SesameEvent event, uint8_t deviceId = 0); + void prepareResponseBuffer(SesameEvent event, uint8_t deviceId = 0); void sendPreparedLocalResponse(AsyncWebServerRequest *request); void sendPreparedServerResponse(); }; \ No newline at end of file diff --git a/src/controller.cpp b/src/controller.cpp index ce102e1..5e694c0 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -55,8 +55,7 @@ void SesameController::loop(uint32_t millis) { // MARK: Local -void -SesameController::handleLocalMessage(AsyncWebServerRequest *request) { +void SesameController::handleLocalMessage(AsyncWebServerRequest *request) { if (!request->hasParam(messageUrlParameter)) { Serial.println("Missing url parameter"); prepareResponseBuffer(SesameEvent::InvalidUrlParameter); @@ -147,19 +146,21 @@ bool allowMessageResponse(SesameEvent event) { } } -uint16_t SesameController::prepareResponseBuffer(SesameEvent event, uint8_t deviceId) { +void SesameController::prepareResponseBuffer(SesameEvent event, uint8_t deviceId) { *responseStatus = event; + responseSize = 1; if (!allowMessageResponse(event)) { - return 1; + return; } responseMessage->message.time = timeCheck.getEpochTime(); responseMessage->message.id = storage.getNextMessageCounter(deviceId); responseMessage->message.device = deviceId; + if (!authenticateMessage(responseMessage, keyConfig.localKey, keySize)) { *responseStatus = SesameEvent::InvalidResponseAuthentication; - return 1; + return; } - return 1 + AUTHENTICATED_MESSAGE_SIZE; + responseSize += AUTHENTICATED_MESSAGE_SIZE; } // MARK: Reconnecting