ClientACL: the replay floor survives a reboot -- a captured admin command no longer works after every boot
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7949fb4274
commit
1171d8f972
8 files changed
+410
-1
No files matched your search
@@ -0,0 +1,61 @@
|
||||
#pragma once
|
||||
|
||||
// In-memory stand-in for the nRF52 LittleFS, enough for ClientACL: whole-file
|
||||
// write, read, exists, remove. Tests reach into `files` to tear or drop a write.
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#define FILE_O_READ 0
|
||||
#define FILE_O_WRITE 1
|
||||
|
||||
namespace Adafruit_LittleFS_Namespace {
|
||||
|
||||
class File {
|
||||
std::map<std::string, std::string>* _files = nullptr;
|
||||
std::string _name;
|
||||
size_t _pos = 0;
|
||||
bool _write = false;
|
||||
|
||||
public:
|
||||
File() = default;
|
||||
File(std::map<std::string, std::string>* files, const std::string& name, bool write)
|
||||
: _files(files), _name(name), _write(write) {
|
||||
if (write) (*_files)[name] = "";
|
||||
}
|
||||
explicit operator bool() const { return _files != nullptr; }
|
||||
int read(uint8_t* buf, size_t len) {
|
||||
const std::string& d = (*_files)[_name];
|
||||
size_t n = std::min(len, d.size() - std::min(_pos, d.size()));
|
||||
std::memcpy(buf, d.data() + _pos, n);
|
||||
_pos += n;
|
||||
return (int)n;
|
||||
}
|
||||
size_t write(const uint8_t* buf, size_t len) {
|
||||
(*_files)[_name].append((const char*)buf, len);
|
||||
return len;
|
||||
}
|
||||
void close() {}
|
||||
};
|
||||
|
||||
} // namespace Adafruit_LittleFS_Namespace
|
||||
|
||||
class Adafruit_LittleFS {
|
||||
public:
|
||||
std::map<std::string, std::string> files;
|
||||
int writes = 0;
|
||||
|
||||
bool exists(const char* name) { return files.count(name) > 0; }
|
||||
bool remove(const char* name) { return files.erase(name) > 0; }
|
||||
bool mkdir(const char*) { return true; }
|
||||
Adafruit_LittleFS_Namespace::File open(const char* name, uint8_t mode = FILE_O_READ) {
|
||||
if (mode == FILE_O_WRITE) {
|
||||
writes++;
|
||||
return Adafruit_LittleFS_Namespace::File(&files, name, true);
|
||||
}
|
||||
if (!exists(name)) return Adafruit_LittleFS_Namespace::File();
|
||||
return Adafruit_LittleFS_Namespace::File(&files, name, false);
|
||||
}
|
||||
};
|
||||
@@ -28,6 +28,10 @@ public:
|
||||
for (size_t i = 0; i < hashLen; i++) {
|
||||
hash[i] = _state[i % 32];
|
||||
}
|
||||
// A short digest (4-byte checksum tags) must still depend on every byte.
|
||||
for (size_t i = hashLen; i < 32 && hashLen > 0; i++) {
|
||||
hash[i % hashLen] ^= _state[i];
|
||||
}
|
||||
}
|
||||
|
||||
void resetHMAC(const uint8_t* key, size_t keyLen) {}
|
||||
|
||||
Reference in new issue
Block a user