commit 5d1bac73bfa4fb96ce36495b0480d5f7ba5df8a2 from: Omar Polo date: Thu Mar 25 14:32:08 2021 UTC add y-or-n-p; ask user when encountering invalid certs commit - d6cd2fc18acd63daadbc6bd251be02fcc2f14341 commit + 5d1bac73bfa4fb96ce36495b0480d5f7ba5df8a2 blob - 18cd4bd46af8e7dbb703c81fa0dcff90c64f24a5 blob + 6459d502e21aaa62b46950634fa9708805486cf3 --- telescope.c +++ telescope.c @@ -25,6 +25,7 @@ static void die(void) __attribute__((__noreturn__)); static struct tab *tab_by_id(uint32_t); static void handle_imsg_err(struct imsg*, size_t); static void handle_imsg_check_cert(struct imsg*, size_t); +static void handle_check_cert_user_choice(int, unsigned int); static void handle_imsg_got_code(struct imsg*, size_t); static void handle_imsg_got_meta(struct imsg*, size_t); static void handle_imsg_buf(struct imsg*, size_t); @@ -118,14 +119,24 @@ handle_imsg_check_cert(struct imsg *imsg, size_t datal } else tofu_res = !strcmp(hash, e->hash); - if (tofu_res) + if (tofu_res) { tab->trust = e->verified ? TS_VERIFIED : TS_TRUSTED; - else { + imsg_compose(netibuf, IMSG_CERT_STATUS, imsg->hdr.peerid, 0, -1, + &tofu_res, sizeof(tofu_res)); + imsg_flush(netibuf); + } else { tab->trust = TS_UNTRUSTED; load_page_from_str(tab, "# Certificate mismatch\n"); + ui_yornp("Certificate mismatch. Proceed?", + handle_check_cert_user_choice); } - imsg_compose(netibuf, IMSG_CERT_STATUS, imsg->hdr.peerid, 0, -1, - &tofu_res, sizeof(tofu_res)); +} + +static void +handle_check_cert_user_choice(int accept, unsigned int tabid) +{ + imsg_compose(netibuf, IMSG_CERT_STATUS, tabid, 0, -1, + &accept, sizeof(accept)); imsg_flush(netibuf); } blob - d67ae95d13693918cc02720e02c7374c8695b685 blob + a96c2291c4d5e5c7a0c2cd4b7827e7a9e0330e58 --- telescope.h +++ telescope.h @@ -250,6 +250,7 @@ int ui_init(int, char * const*); void ui_on_tab_loaded(struct tab*); void ui_on_tab_refresh(struct tab*); void ui_require_input(struct tab*, int); +void ui_yornp(const char*, void (*)(int, unsigned int)); void ui_notify(const char*, ...) __attribute__((format(printf, 1, 2))); void ui_end(void); blob - cf5bdd939764a01767120aa57356e7b9af7b4d1b blob + c0d355c32a5456c87e2489c00b87eee85d3de27f --- ui.c +++ ui.c @@ -109,6 +109,8 @@ static void ir_select(void); static void lu_self_insert(void); static void lu_select(void); static void bp_select(void); +static void yornp_self_insert(void); +static void yornp_abort(void); static struct vline *nth_line(struct window*, size_t); static struct tab *current_tab(void); @@ -149,6 +151,8 @@ static uint32_t tab_counter; static char keybuf[64]; +static void (*yornp_cb)(int, unsigned int); + struct kmap global_map, minibuffer_map, *current_map, @@ -163,7 +167,7 @@ static int in_minibuffer; static struct { char *curmesg; - char prompt[32]; + char prompt[64]; void (*donefn)(void); void (*abortfn)(void); @@ -1063,6 +1067,25 @@ bp_select(void) add_to_bookmarks(ministate.buf); else message("Abort."); +} + +static void +yornp_self_insert(void) +{ + if (thiskey.key != 'y' && thiskey.key != 'n') { + message("Please answer y or n"); + return; + } + + yornp_cb(thiskey.key == 'y', current_tab()->id); + exit_minibuffer(); +} + +static void +yornp_abort(void) +{ + yornp_cb(0, current_tab()->id); + exit_minibuffer(); } static struct vline * @@ -1827,6 +1850,21 @@ ui_require_input(struct tab *tab, int hide) } void +ui_yornp(const char *prompt, void (*fn)(int, unsigned int)) +{ + size_t len; + + yornp_cb = fn; + enter_minibuffer(yornp_self_insert, yornp_self_insert, + yornp_abort, NULL); + + len = sizeof(ministate.prompt); + strlcpy(ministate.prompt, prompt, len); + strlcat(ministate.prompt, " (y or n) ", len); + redraw_tab(current_tab()); +} + +void ui_notify(const char *fmt, ...) { va_list ap;