Compare commits

...

3 Commits

2 changed files with 84 additions and 39 deletions

View File

@@ -503,8 +503,8 @@ int socket_name_random(char *out, size_t out_len);
/* Version information (auto-updated by build/version tooling) */
#define NSIGNER_VERSION_MAJOR 0
#define NSIGNER_VERSION_MINOR 0
#define NSIGNER_VERSION_PATCH 38
#define NSIGNER_VERSION "v0.0.38"
#define NSIGNER_VERSION_PATCH 41
#define NSIGNER_VERSION "v0.0.41"
/* NSIGNER_HEADERLESS_DECLS_END */
@@ -1626,9 +1626,7 @@ static int prompt_transport_selection(void) {
(selected & TRANSPORT_QREXEC_BRIDGE) ? "x" : " ");
printf(" [%s] 3. TCP listener (FIPS mesh or local network)\n",
(selected & TRANSPORT_TCP) ? "x" : " ");
printf(" [%s] 4. Qrexec one-shot (legacy, one request per invocation)\n",
(selected & TRANSPORT_QREXEC_ONESHOT) ? "x" : " ");
printf("\n [a] select all (except 4) Enter = confirm\n");
printf("\n [a] select all Enter = confirm\n");
printf("> ");
fflush(stdout);
@@ -1651,15 +1649,6 @@ static int prompt_transport_selection(void) {
printf("At least one transport must be selected.\n");
continue;
}
/* Qrexec one-shot is mutually exclusive with persistent listeners */
if ((selected & TRANSPORT_QREXEC_ONESHOT) && (selected & ~TRANSPORT_QREXEC_ONESHOT)) {
printf("Qrexec one-shot cannot combine with other transports. Deselecting it.\n");
selected &= ~TRANSPORT_QREXEC_ONESHOT;
if (selected == 0) {
selected = TRANSPORT_UNIX;
}
continue;
}
break;
}
@@ -1674,16 +1663,67 @@ static int prompt_transport_selection(void) {
selected ^= TRANSPORT_QREXEC_BRIDGE;
} else if (input[0] == '3') {
selected ^= TRANSPORT_TCP;
} else if (input[0] == '4') {
selected ^= TRANSPORT_QREXEC_ONESHOT;
} else {
printf("Invalid input. Type 1-4, 'a', or Enter to confirm.\n");
printf("Invalid input. Type 1-3, 'a', or Enter to confirm.\n");
}
}
return selected;
}
/*
* Interactive index whitelist prompt.
* Shown after transport selection when no --allow-index flag was given.
* Returns a malloc'd spec string (caller must free), or NULL for "all".
*/
static char *prompt_index_whitelist(void) {
char input[256];
for (;;) {
tui_render_content_screen(NULL, "Index whitelist — restrict which nostr_index values this session can access");
printf("Enter allowed indices, or press Enter for 'all' (no restriction):\n\n");
printf(" Examples:\n");
printf(" all (default — allow all indices)\n");
printf(" 0 (only index 0)\n");
printf(" 0,1,3 (specific indices)\n");
printf(" 0-3 (range 0 through 3)\n");
printf(" 0,2-3,7 (mixed list and ranges)\n");
printf("\n Enter = all\n");
printf("> ");
fflush(stdout);
if (read_line_stdin(input, sizeof(input)) != 0) {
return NULL;
}
/* Trim trailing whitespace */
{
size_t len = strlen(input);
while (len > 0 && (input[len-1] == '\n' || input[len-1] == '\r' ||
input[len-1] == ' ' || input[len-1] == '\t')) {
input[--len] = '\0';
}
}
if (input[0] == '\0') {
/* Enter pressed — default to "all" */
return NULL;
}
/* Validate by parsing into a temp whitelist */
{
server_ctx_t tmp;
memset(&tmp, 0, sizeof(tmp));
if (server_set_index_whitelist(&tmp, input) != 0) {
printf("Invalid spec: '%s'. Try again or press Enter for 'all'.\n", input);
continue;
}
}
return strdup(input);
}
}
int main(int argc, char *argv[]) {
mnemonic_state_t mnemonic;
role_table_t role_table;
@@ -1982,11 +2022,14 @@ int main(int argc, char *argv[]) {
return 1;
}
/* Qrexec one-shot: use existing single-listener path */
if (transport_mask & TRANSPORT_QREXEC_ONESHOT) {
listen_mode = NSIGNER_LISTEN_QREXEC;
listen_mode_explicit = 1;
} else {
/* Index whitelist prompt (only if --allow-index wasn't given on CLI) */
if (allow_index_spec == NULL) {
char *wl_spec = prompt_index_whitelist();
if (wl_spec != NULL) {
allow_index_spec = wl_spec; /* will be freed at program exit */
}
}
/* Persistent listeners — configure from menu selection */
multi_listen = 1;
@@ -2007,7 +2050,6 @@ int main(int argc, char *argv[]) {
/* Will be started as a second listener */
}
}
}
if (listen_mode == NSIGNER_LISTEN_UNIX && !socket_name_explicit) {
if (socket_name_random(generated_socket_name, sizeof(generated_socket_name)) != 0) {

View File

@@ -1680,7 +1680,7 @@ int server_handle_one(server_ctx_t *ctx, server_activity_cb cb, void *cb_data) {
response = strdup("{\"id\":\"null\",\"error\":{\"code\":2002,\"message\":\"index_not_allowed\"}}");
pchk = POLICY_DENY;
verdict = "DENIED";
source_label = "index-whitelist";
source_label = "index-not-approved";
hard_selector_error = -100; /* sentinel: skip policy_check */
}
@@ -1778,6 +1778,9 @@ int server_handle_one(server_ctx_t *ctx, server_activity_cb cb, void *cb_data) {
source_label = "session-grant";
} else if (pchk == POLICY_ALLOW) {
source_label = "prompt";
} else if (hard_selector_error == -100) {
/* Index whitelist denial — keep the label set by the whitelist check */
/* source_label already set to "index-not-approved" above */
} else {
source_label = "no-match";
}