51 lines
1.5 KiB
C
51 lines
1.5 KiB
C
#ifndef ZK_HANDLERS_H
|
|
#define ZK_HANDLERS_H
|
|
|
|
#include "zk_auth.h"
|
|
#include <esp_http_server.h>
|
|
#include <esp_log.h>
|
|
#include <esp_timer.h>
|
|
#include <mbedtls/ctr_drbg.h>
|
|
#include <mbedtls/ecdsa.h>
|
|
#include <mbedtls/ecp.h>
|
|
#include <mbedtls/entropy.h>
|
|
#include <mbedtls/gcm.h>
|
|
#include <mbedtls/md.h>
|
|
#include <mbedtls/pkcs5.h>
|
|
#include <mbedtls/sha256.h>
|
|
#include <mbedtls/sha512.h>
|
|
#include <string.h>
|
|
|
|
// Global ZK Auth instance (to be initialized in main)
|
|
extern ZKAuth zk_auth;
|
|
extern httpd_handle_t server_http;
|
|
|
|
// API endpoint: Get device identity
|
|
static esp_err_t handle_zk_identity(httpd_req_t *req) {
|
|
char *json_response = zk_auth.get_identity_json();
|
|
if (json_response == NULL) {
|
|
httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR,
|
|
"Failed to get identity");
|
|
return ESP_FAIL;
|
|
}
|
|
|
|
httpd_resp_set_type(req, "application/json");
|
|
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
|
|
httpd_resp_sendstr(req, json_response);
|
|
free(json_response);
|
|
return ESP_OK;
|
|
}
|
|
|
|
// API endpoint: Process unlock request
|
|
// Handle CORS preflight
|
|
// Register all ZK auth routes to the HTTP server
|
|
void register_zk_handlers(httpd_handle_t server) {
|
|
httpd_uri_t identity_uri = {.uri = "/api/identity",
|
|
.method = HTTP_GET,
|
|
.handler = handle_zk_identity,
|
|
.user_ctx = NULL};
|
|
httpd_register_uri_handler(server, &identity_uri);
|
|
}
|
|
|
|
#endif // ZK_HANDLERS_H
|