Moved auth system from nostr_core_lib back into ginxsom. Still debugging but so many changes I wanted to commit.
This commit is contained in:
@@ -14,7 +14,6 @@
|
||||
#include <fcgi_stdio.h>
|
||||
#include <sqlite3.h>
|
||||
#include "../nostr_core_lib/cjson/cJSON.h"
|
||||
#include "../nostr_core_lib/nostr_core/nostr_core.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -43,8 +42,67 @@ void handle_head_request(const char* uri);
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// NOTE: Old authentication functions removed - now handled by nostr_core_lib unified system
|
||||
// Use nostr_validate_request() from request_validator.h for all authentication needs
|
||||
// Request validation system - implemented in request_validator.c
|
||||
// Functions implemented in src/request_validator.c
|
||||
|
||||
// NOSTR result constants
|
||||
#define NOSTR_SUCCESS 0
|
||||
#define NOSTR_ERROR_INVALID_JSON -1
|
||||
#define NOSTR_ERROR_MISSING_FIELD -2
|
||||
#define NOSTR_ERROR_INVALID_SIGNATURE -3
|
||||
#define NOSTR_ERROR_INVALID_PUBKEY -4
|
||||
#define NOSTR_ERROR_DATABASE -10
|
||||
#define NOSTR_ERROR_UNAUTHORIZED -11
|
||||
#define NOSTR_ERROR_MEMORY -12
|
||||
|
||||
// NIP-42 modes
|
||||
typedef enum {
|
||||
NIP42_MODE_DISABLED = 0,
|
||||
NIP42_MODE_OPTIONAL = 1,
|
||||
NIP42_MODE_REQUIRED = 2
|
||||
} nip42_mode_t;
|
||||
|
||||
// Request validation types and enums (matching ginxsom usage)
|
||||
typedef struct {
|
||||
const char* operation; // Operation type ("upload", "delete", "list", "publish", "admin")
|
||||
const char* auth_header; // Raw authorization header (optional)
|
||||
cJSON* event; // Parsed NOSTR event for validation (optional)
|
||||
const char* resource_hash; // Resource hash (SHA-256, optional)
|
||||
const char* mime_type; // MIME type (optional)
|
||||
long file_size; // File size (optional)
|
||||
const char* relay_url; // Relay URL for NIP-42 validation (optional)
|
||||
const char* challenge_id; // Challenge ID for NIP-42 verification (optional)
|
||||
int nip42_mode; // NIP-42 mode: 0=disabled, 1=optional, 2=required
|
||||
const char* client_ip; // Client IP address (optional)
|
||||
void* app_context; // Application context (unused, for compatibility)
|
||||
} nostr_request_t;
|
||||
|
||||
typedef struct {
|
||||
int valid; // 0 = invalid/denied, 1 = valid/allowed
|
||||
int error_code; // NOSTR_SUCCESS or specific error code
|
||||
char reason[256]; // Human-readable reason for denial/acceptance
|
||||
char pubkey[65]; // Extracted pubkey from validated event (if available)
|
||||
} nostr_request_result_t;
|
||||
|
||||
// Challenge structure for NIP-42
|
||||
typedef struct {
|
||||
char challenge_id[65];
|
||||
time_t expires_at;
|
||||
} nostr_nip42_challenge_t;
|
||||
|
||||
// Function declarations for nostr_core_lib functions used by ginxsom
|
||||
int nostr_validate_event(cJSON* event);
|
||||
int nostr_validate_event_structure(cJSON* event);
|
||||
int nostr_verify_event_signature(cJSON* event);
|
||||
int nostr_sha256(const unsigned char* data, size_t len, unsigned char* hash);
|
||||
void nostr_bytes_to_hex(const unsigned char* bytes, size_t len, char* hex_out);
|
||||
int nostr_crypto_init(void);
|
||||
|
||||
int nostr_validate_request(const nostr_request_t* request, nostr_request_result_t* result);
|
||||
int nostr_request_validator_init(const char* db_path, const char* app_name);
|
||||
int nostr_auth_rules_enabled(void);
|
||||
void nostr_request_validator_cleanup(void);
|
||||
int nostr_request_validator_generate_nip42_challenge(void* challenge_struct, const char* client_ip);
|
||||
|
||||
// Upload handling
|
||||
void handle_upload_request(void);
|
||||
|
||||
Reference in New Issue
Block a user