Implemented better testing and fixed skipepd frames
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
#include "Threads.h"
|
||||
#include "TimeoutType.h"
|
||||
#include "UDPSProtocol.h"
|
||||
#include <string.h>
|
||||
|
||||
namespace MARTe {
|
||||
|
||||
@@ -122,6 +123,12 @@ bool DebugService::Initialise(StructuredDataI &data) {
|
||||
suppressTimeoutLogs = (suppress == 1u);
|
||||
}
|
||||
|
||||
StreamString tempToken;
|
||||
if (data.Read("AuthToken", tempToken)) {
|
||||
authToken = tempToken;
|
||||
}
|
||||
clientAuthenticated = (authToken.Size() == 0u);
|
||||
|
||||
// Capture only the local subtree — do NOT call MoveToRoot() on the shared CDB.
|
||||
(void)data.Copy(fullConfig);
|
||||
|
||||
@@ -281,6 +288,8 @@ ErrorManagement::ErrorType DebugService::Server(ExecutionInfo &info) {
|
||||
cmdCountInWindow = 0u;
|
||||
cmdWindowStartMs = nowMs;
|
||||
lastDataTimeMs = nowMs;
|
||||
/* CR-5: require auth if an AuthToken is configured. */
|
||||
clientAuthenticated = (authToken.Size() == 0u);
|
||||
}
|
||||
} else {
|
||||
if (nowMs - lastDataTimeMs > CLIENT_IDLE_TIMEOUT_MS) {
|
||||
@@ -351,23 +360,101 @@ ErrorManagement::ErrorType DebugService::Server(ExecutionInfo &info) {
|
||||
uint32 cmdLen = len;
|
||||
command.Write(raw + lineStart, cmdLen);
|
||||
|
||||
// Dispatch via base HandleCommand, write response to socket.
|
||||
StreamString out;
|
||||
HandleCommand(command, out);
|
||||
if (out.Size() > 0u) {
|
||||
const char8 *wPtr = out.Buffer();
|
||||
uint32 remaining = (uint32)out.Size();
|
||||
lastDataTimeMs = (uint64)((float64)HighResolutionTimer::Counter() *
|
||||
HighResolutionTimer::Period() * 1000.0);
|
||||
while (remaining > 0u) {
|
||||
uint32 wrote = remaining;
|
||||
if (!activeClient->Write(wPtr, wrote) || wrote == 0u) {
|
||||
break;
|
||||
/* CR-5: Auth token gate. If an AuthToken is
|
||||
* configured, the client must send
|
||||
* "AUTH <token>" before any other command. */
|
||||
if (authToken.Size() > 0u) {
|
||||
const char8 *cmdPtr = command.Buffer();
|
||||
if (cmdLen >= 5u &&
|
||||
strncmp(cmdPtr, "AUTH ", 5u) == 0) {
|
||||
const char8 *recvToken = cmdPtr + 5u;
|
||||
uint32 recvLen = cmdLen - 5u;
|
||||
/* Strip trailing \r if present */
|
||||
if (recvLen > 0u &&
|
||||
recvToken[recvLen - 1u] == '\r') {
|
||||
recvLen--;
|
||||
}
|
||||
wPtr += wrote;
|
||||
remaining -= wrote;
|
||||
if (recvLen == authToken.Size() &&
|
||||
strncmp(recvToken,
|
||||
authToken.Buffer(),
|
||||
recvLen) == 0) {
|
||||
clientAuthenticated = true;
|
||||
const char8 *okResp =
|
||||
"OK AUTHENTICATED\n";
|
||||
uint32 respSz =
|
||||
static_cast<uint32>(
|
||||
strlen(okResp));
|
||||
(void) activeClient->Write(
|
||||
okResp, respSz);
|
||||
} else {
|
||||
const char8 *badResp =
|
||||
"ERR AUTH_FAILED\n";
|
||||
uint32 respSz =
|
||||
static_cast<uint32>(
|
||||
strlen(badResp));
|
||||
(void) activeClient->Write(
|
||||
badResp, respSz);
|
||||
}
|
||||
} else if (!clientAuthenticated) {
|
||||
const char8 *needAuth =
|
||||
"ERR AUTH_REQUIRED\n";
|
||||
uint32 respSz =
|
||||
static_cast<uint32>(
|
||||
strlen(needAuth));
|
||||
(void) activeClient->Write(
|
||||
needAuth, respSz);
|
||||
} else {
|
||||
// Dispatch via base HandleCommand,
|
||||
// write response to socket.
|
||||
StreamString out;
|
||||
HandleCommand(command, out);
|
||||
if (out.Size() > 0u) {
|
||||
const char8 *wPtr = out.Buffer();
|
||||
uint32 remaining =
|
||||
(uint32)out.Size();
|
||||
lastDataTimeMs =
|
||||
(uint64)((float64)
|
||||
HighResolutionTimer::Counter() *
|
||||
HighResolutionTimer::Period() *
|
||||
1000.0);
|
||||
while (remaining > 0u) {
|
||||
uint32 wrote = remaining;
|
||||
if (!activeClient->Write(
|
||||
wPtr, wrote) ||
|
||||
wrote == 0u) {
|
||||
break;
|
||||
}
|
||||
wPtr += wrote;
|
||||
remaining -= wrote;
|
||||
lastDataTimeMs =
|
||||
(uint64)((float64)
|
||||
HighResolutionTimer::Counter() *
|
||||
HighResolutionTimer::Period() *
|
||||
1000.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// No auth token configured — back-compat.
|
||||
// Dispatch via base HandleCommand, write
|
||||
// response to socket.
|
||||
StreamString out;
|
||||
HandleCommand(command, out);
|
||||
if (out.Size() > 0u) {
|
||||
const char8 *wPtr = out.Buffer();
|
||||
uint32 remaining = (uint32)out.Size();
|
||||
lastDataTimeMs = (uint64)((float64)HighResolutionTimer::Counter() *
|
||||
HighResolutionTimer::Period() * 1000.0);
|
||||
while (remaining > 0u) {
|
||||
uint32 wrote = remaining;
|
||||
if (!activeClient->Write(wPtr, wrote) || wrote == 0u) {
|
||||
break;
|
||||
}
|
||||
wPtr += wrote;
|
||||
remaining -= wrote;
|
||||
lastDataTimeMs = (uint64)((float64)HighResolutionTimer::Counter() *
|
||||
HighResolutionTimer::Period() * 1000.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user