commit 71bc16365736f1cc3212d46f3947806c1e33867b from: Omar Polo date: Tue Feb 06 15:12:26 2024 UTC add client_cert_temp flag to the struct tab This way we can improve unload-certificate prompt. While here, move the cert handling in make_request(). commit - b658d4915d7f52e5f39fa819650af807c0bd88f3 commit + 71bc16365736f1cc3212d46f3947806c1e33867b blob - 8fe836bafd79157603410675781bc6f214e85bb5 blob + 34eb02ee9a44f1132f85dd5d6657d1ab5381c1be --- certs.c +++ certs.c @@ -310,12 +310,16 @@ find_cert_for(struct cstore *cstore, struct iri *iri, } const char * -cert_for(struct iri *iri) +cert_for(struct iri *iri, int *temporary) { struct ccert *c; - if ((c = find_cert_for(&temp_store, iri, NULL)) != NULL) + *temporary = 0; + + if ((c = find_cert_for(&temp_store, iri, NULL)) != NULL) { + *temporary = 1; return (c->cert); + } if ((c = find_cert_for(&cert_store, iri, NULL)) != NULL) return (c->cert); return (NULL); blob - f889567e82635d187d12dcc9b540471639eb0ddc blob + 04d0246480ec6f44be8df1d20dcf2aed524374ae --- certs.h +++ certs.h @@ -24,7 +24,7 @@ extern char **identities; int certs_init(const char *); const char *ccert(const char *); -const char *cert_for(struct iri *); +const char *cert_for(struct iri *, int *); int cert_save_for(const char *, struct iri *, int); int cert_delete_for(const char *, struct iri *, int); int cert_open(const char *); blob - 9dc9d7180bcae9f7a0f61ddc71d24858e9b1643c blob + 16927d7f8b2759c895120017509f67f0dd66d505 --- cmd.c +++ cmd.c @@ -1120,20 +1120,28 @@ cmd_client_certificate_info(struct buffer *buffer) static void unload_certificate_cb(int r, struct tab *tab) { + message("Won't use %s for this site.", tab->client_cert); cert_delete_for(tab->client_cert, &tab->iri, r); } void cmd_unload_certificate(struct buffer *buffer) { + struct tab *tab = current_tab; + GUARD_RECURSIVE_MINIBUFFER(); - if (current_tab->client_cert == NULL) { + if (tab->client_cert == NULL) { message("No client certificate in use!"); return; } - /* Sucks that we ask this even when the cert is already temporary */ + if (tab->client_cert_temp) { + message("Won't use %s for this site.", tab->client_cert); + cert_delete_for(tab->client_cert, &tab->iri, 0); + return; + } + yornp("Unload only for the current session?", unload_certificate_cb, current_tab); } blob - 555f69ecb0f9371d00a0c1cc99c4a50c56780bcc blob + b4c2cf15b1ed9eccbc3f0e842e26b165ac397ed9 --- telescope.c +++ telescope.c @@ -128,7 +128,7 @@ static void load_gopher_url(struct tab *, const char static void load_via_proxy(struct tab *, const char *, struct proxy *); static void make_request(struct tab *, struct get_req *, int, - const char *, int); + const char *); static void do_load_url(struct tab *, const char *, const char *, int); static pid_t start_child(enum telescope_process, const char *, int); static void send_url(const char *); @@ -598,23 +598,19 @@ load_finger_url(struct tab *tab, const char *url) strlcat(req.req, "\r\n", sizeof(req.req)); parser_init(tab, textplain_initparser); - make_request(tab, &req, PROTO_FINGER, NULL, 0); + make_request(tab, &req, PROTO_FINGER, NULL); } static void load_gemini_url(struct tab *tab, const char *url) { struct get_req req; - int use_cert = 0; - - if ((tab->client_cert = cert_for(&tab->iri)) != NULL) - use_cert = 1; memset(&req, 0, sizeof(req)); strlcpy(req.host, tab->iri.iri_host, sizeof(req.host)); strlcpy(req.port, tab->iri.iri_portstr, sizeof(req.port)); - make_request(tab, &req, PROTO_GEMINI, hist_cur(tab->hist), use_cert); + make_request(tab, &req, PROTO_GEMINI, hist_cur(tab->hist)); } static inline const char * @@ -685,7 +681,7 @@ load_gopher_url(struct tab *tab, const char *url) } strlcat(req.req, "\r\n", sizeof(req.req)); - make_request(tab, &req, PROTO_GOPHER, NULL, 0); + make_request(tab, &req, PROTO_GOPHER, NULL); } static void @@ -699,14 +695,18 @@ load_via_proxy(struct tab *tab, const char *url, struc tab->proxy = p; - make_request(tab, &req, p->proto, hist_cur(tab->hist), 0); + make_request(tab, &req, p->proto, hist_cur(tab->hist)); } static void -make_request(struct tab *tab, struct get_req *req, int proto, const char *r, - int use_cert) +make_request(struct tab *tab, struct get_req *req, int proto, const char *r) { - int fd = -1; + int use_cert = 0, fd = -1; + + if (proto == PROTO_GEMINI) { + tab->client_cert = cert_for(&tab->iri, &tab->client_cert_temp); + use_cert = (tab->client_cert != NULL); + } stop_tab(tab); tab->id = tab_new_id(); @@ -752,7 +752,7 @@ gopher_send_search_req(struct tab *tab, const char *te erase_buffer(&tab->buffer); parser_init(tab, gophermap_initparser); - make_request(tab, &req, PROTO_GOPHER, NULL, 0); + make_request(tab, &req, PROTO_GOPHER, NULL); } void blob - 69895df6b55abbe22eee103fa8d64bb8d882ea42 blob + cf1297fdfadd033ea352e0e23b27b1d18d0c8292 --- telescope.h +++ telescope.h @@ -192,6 +192,7 @@ struct tab { char *cert; enum trust_state trust; const char *client_cert; + int client_cert_temp; struct proxy *proxy; struct iri iri; struct hist *hist;