Massive cleanup
This commit is contained in:
@@ -17,12 +17,6 @@ static const char *TAG = "TangServer";
|
||||
|
||||
// Include core components
|
||||
#include "atecc608a.h"
|
||||
#include "crypto.h"
|
||||
#include "encoding.h"
|
||||
#include "provision.h"
|
||||
#include "provision_handlers.h"
|
||||
#include "tang_handlers.h"
|
||||
#include "tang_storage.h"
|
||||
#include "zk_auth.h"
|
||||
#include "zk_handlers.h"
|
||||
|
||||
@@ -33,7 +27,6 @@ const char *wifi_password = CONFIG_WIFI_PASSWORD;
|
||||
// --- Global State ---
|
||||
bool unlocked = false; // Start inactive until provisioned and authenticated
|
||||
httpd_handle_t server_http = NULL;
|
||||
TangKeyStore keystore;
|
||||
ZKAuth zk_auth; // Zero-Knowledge Authentication
|
||||
|
||||
// WiFi event group
|
||||
@@ -103,19 +96,6 @@ void setup_wifi() {
|
||||
// --- Initial Setup ---
|
||||
bool perform_initial_setup() {
|
||||
|
||||
if (!P256::generate_keypair(keystore.exc_pub, keystore.exc_priv)) {
|
||||
ESP_LOGE(TAG, "ERROR: Failed to generate exchange key");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Save Tang keys directly (no encryption in prototype)
|
||||
if (!keystore.save_tang_keys()) {
|
||||
ESP_LOGE(TAG, "ERROR: Failed to save Tang keys");
|
||||
return false;
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "Configuration saved to NVS");
|
||||
|
||||
ESP_LOGI(TAG, "=======================================================");
|
||||
ESP_LOGI(TAG, "Setup complete! Device is ready to use");
|
||||
ESP_LOGI(TAG, "NOTE: Exchange key stored unencrypted for prototyping");
|
||||
@@ -134,44 +114,7 @@ httpd_handle_t setup_http_server() {
|
||||
httpd_handle_t server = NULL;
|
||||
|
||||
if (httpd_start(&server, &config) == ESP_OK) {
|
||||
register_provision_handlers(server);
|
||||
|
||||
register_zk_handlers(server);
|
||||
|
||||
// Register Tang protocol handlers
|
||||
httpd_uri_t adv_uri = {.uri = "/adv",
|
||||
.method = HTTP_GET,
|
||||
.handler = handle_adv,
|
||||
.user_ctx = NULL};
|
||||
httpd_register_uri_handler(server, &adv_uri);
|
||||
|
||||
httpd_uri_t adv_uri_slash = {.uri = "/adv/",
|
||||
.method = HTTP_GET,
|
||||
.handler = handle_adv,
|
||||
.user_ctx = NULL};
|
||||
httpd_register_uri_handler(server, &adv_uri_slash);
|
||||
|
||||
httpd_uri_t rec_uri = {.uri = "/rec",
|
||||
.method = HTTP_POST,
|
||||
.handler = handle_rec,
|
||||
.user_ctx = NULL};
|
||||
httpd_register_uri_handler(server, &rec_uri);
|
||||
|
||||
httpd_uri_t config_uri = {.uri = "/config",
|
||||
.method = HTTP_GET,
|
||||
.handler = handle_config,
|
||||
.user_ctx = NULL};
|
||||
httpd_register_uri_handler(server, &config_uri);
|
||||
|
||||
httpd_uri_t reboot_uri = {.uri = "/reboot",
|
||||
.method = HTTP_GET,
|
||||
.handler = handle_reboot,
|
||||
.user_ctx = NULL};
|
||||
httpd_register_uri_handler(server, &reboot_uri);
|
||||
|
||||
// Register custom error handler for 404
|
||||
httpd_register_err_handler(server, HTTPD_404_NOT_FOUND, handle_not_found);
|
||||
|
||||
ESP_LOGI(TAG, "HTTP server listening on port 80");
|
||||
} else {
|
||||
ESP_LOGE(TAG, "Failed to start HTTP server");
|
||||
@@ -182,7 +125,6 @@ httpd_handle_t setup_http_server() {
|
||||
|
||||
// --- Main Setup ---
|
||||
void setup() {
|
||||
ESP_LOGI(TAG, "\n\nESP32 Tang Server Starting...");
|
||||
|
||||
// Initialize NVS (required before any storage operations)
|
||||
esp_err_t ret = nvs_flash_init();
|
||||
@@ -194,26 +136,12 @@ void setup() {
|
||||
ESP_ERROR_CHECK(ret);
|
||||
ESP_LOGI(TAG, "NVS initialized");
|
||||
|
||||
// Initialize ATECC608A
|
||||
if (atecc608B_init()) {
|
||||
atecc608B_print_config();
|
||||
} else {
|
||||
ESP_LOGW(TAG, "WARNING: ATECC608A initialization failed");
|
||||
}
|
||||
|
||||
// Load or initialize configuration
|
||||
if (keystore.is_configured()) {
|
||||
ESP_LOGI(TAG, "Found existing configuration");
|
||||
// Auto-load Tang keys on startup (no activation needed in prototype)
|
||||
if (keystore.load_tang_keys()) {
|
||||
ESP_LOGI(TAG, "Loaded Tang keys - server ready");
|
||||
} else {
|
||||
ESP_LOGW(TAG, "Failed to load Tang keys");
|
||||
}
|
||||
} else {
|
||||
perform_initial_setup();
|
||||
}
|
||||
|
||||
// Initialize Zero-Knowledge Authentication
|
||||
ESP_LOGI(TAG, "Initializing Zero-Knowledge Authentication...");
|
||||
if (zk_auth.init()) {
|
||||
|
||||
Reference in New Issue
Block a user