From b939afe3fc70be446d9ffd6e6071a4af5cf98a8a Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Sun, 31 Jul 2016 01:24:57 +0100 Subject: [PATCH] Allow certificate verification user prompt creation to return errors --- content/llcache.c | 9 +++++++++ desktop/gui_factory.c | 4 ++-- desktop/netsurf.c | 8 ++++++-- frontends/amiga/sslcert.c | 8 ++++++-- frontends/amiga/sslcert.h | 2 +- frontends/atari/gui.c | 4 ++-- frontends/cocoa/gui.m | 4 ++-- frontends/gtk/ssl_cert.c | 11 ++++++----- frontends/gtk/ssl_cert.h | 2 +- frontends/monkey/cert.c | 7 ++++--- frontends/monkey/cert.h | 2 +- frontends/riscos/gui.h | 2 +- frontends/riscos/sslcert.c | 22 ++++++++++++---------- include/netsurf/misc.h | 3 ++- 14 files changed, 55 insertions(+), 33 deletions(-) diff --git a/content/llcache.c b/content/llcache.c index 33a9b98aa..e338c1f3c 100644 --- a/content/llcache.c +++ b/content/llcache.c @@ -2214,6 +2214,11 @@ static nserror llcache_fetch_auth(llcache_object *object, const char *realm) error = llcache->query_cb(&query, llcache->query_cb_pw, llcache_query_handle_response, object); + if (error != NSERROR_OK) { + /* do not continue if error querying user */ + error = llcache_query_handle_response(false, + object); + } } else { llcache_event event; @@ -2269,6 +2274,10 @@ static nserror llcache_fetch_cert_error(llcache_object *object, error = llcache->query_cb(&query, llcache->query_cb_pw, llcache_query_handle_response, object); + if (error != NSERROR_OK) { + /* do not continue if error querying user */ + error = llcache_query_handle_response(false, object); + } } else { llcache_event event; diff --git a/desktop/gui_factory.c b/desktop/gui_factory.c index cecbe6e79..88bb9baf5 100644 --- a/desktop/gui_factory.c +++ b/desktop/gui_factory.c @@ -685,13 +685,13 @@ static nserror gui_default_launch_url(struct nsurl *url) } -static void gui_default_cert_verify(nsurl *url, +static nserror gui_default_cert_verify(nsurl *url, const struct ssl_cert_info *certs, unsigned long num, nserror (*cb)(bool proceed, void *pw), void *cbpw) { - cb(false, cbpw); + return NSERROR_NOT_IMPLEMENTED; } static void gui_default_401login_open(nsurl *url, const char *realm, diff --git a/desktop/netsurf.c b/desktop/netsurf.c index ffcec0420..f1daeab05 100644 --- a/desktop/netsurf.c +++ b/desktop/netsurf.c @@ -104,21 +104,25 @@ static void netsurf_lwc_iterator(lwc_string *str, void *pw) static nserror netsurf_llcache_query_handler(const llcache_query *query, void *pw, llcache_query_response cb, void *cbpw) { + nserror res = NSERROR_OK; + switch (query->type) { case LLCACHE_QUERY_AUTH: guit->misc->login(query->url, query->data.auth.realm, cb, cbpw); break; + case LLCACHE_QUERY_REDIRECT: /** \todo Need redirect query dialog */ /* For now, do nothing, as this query type isn't emitted yet */ break; + case LLCACHE_QUERY_SSL: - guit->misc->cert_verify(query->url, query->data.ssl.certs, + res = guit->misc->cert_verify(query->url, query->data.ssl.certs, query->data.ssl.num, cb, cbpw); break; } - return NSERROR_OK; + return res; } /* exported interface documented in netsurf/netsurf.h */ diff --git a/frontends/amiga/sslcert.c b/frontends/amiga/sslcert.c index ed7206127..83798f2e2 100644 --- a/frontends/amiga/sslcert.c +++ b/frontends/amiga/sslcert.c @@ -27,7 +27,7 @@ #include "amiga/tree.h" #include "amiga/sslcert.h" -void gui_cert_verify(nsurl *url, +nserror gui_cert_verify(nsurl *url, const struct ssl_cert_info *certs, unsigned long num, nserror (*cb)(bool proceed, void *pw), void *cbpw) { @@ -39,9 +39,13 @@ void gui_cert_verify(nsurl *url, ssl_current_session = data; ssl_window = ami_tree_create(TREE_SSLCERT, data); - if(!ssl_window) return; + if (!ssl_window) { + return NSERROR_INIT_FAILED; + } ami_tree_open(ssl_window, AMI_TREE_SSLCERT); + + return NSERROR_OK; } void ami_ssl_free(struct treeview_window *twin) diff --git a/frontends/amiga/sslcert.h b/frontends/amiga/sslcert.h index 953142e98..86ce9c476 100644 --- a/frontends/amiga/sslcert.h +++ b/frontends/amiga/sslcert.h @@ -19,7 +19,7 @@ #ifndef AMIGA_SSLCERT_H #define AMIGA_SSLCERT_H -void gui_cert_verify(nsurl *url, +nserror gui_cert_verify(nsurl *url, const struct ssl_cert_info *certs, unsigned long num, nserror (*cb)(bool proceed, void *pw), void *cbpw); diff --git a/frontends/atari/gui.c b/frontends/atari/gui.c index 713db8bb3..eb15777b4 100644 --- a/frontends/atari/gui.c +++ b/frontends/atari/gui.c @@ -771,7 +771,7 @@ static void gui_401login_open(nsurl *url, const char *realm, } -static void +static nserror gui_cert_verify(nsurl *url, const struct ssl_cert_info *certs, unsigned long num, nserror (*cb)(bool proceed, void *pw), void *cbpw) @@ -795,7 +795,7 @@ gui_cert_verify(nsurl *url, const struct ssl_cert_info *certs, &data); atari_sslcert_viewer_open(data); } - + return NSERROR_OK; } void gui_set_input_gui_window(struct gui_window *gw) diff --git a/frontends/cocoa/gui.m b/frontends/cocoa/gui.m index b1847ebf5..7e180fa24 100644 --- a/frontends/cocoa/gui.m +++ b/frontends/cocoa/gui.m @@ -285,13 +285,13 @@ static nserror gui_launch_url(nsurl *url) struct ssl_cert_info; -static void +static nserror gui_cert_verify(nsurl *url, const struct ssl_cert_info *certs, unsigned long num, nserror (*cb)(bool proceed,void *pw), void *cbpw) { - cb( false, cbpw ); + return NSERROR_NOT_IMPLEMENTED; } diff --git a/frontends/gtk/ssl_cert.c b/frontends/gtk/ssl_cert.c index 463f5cd60..e3bc8a7b2 100644 --- a/frontends/gtk/ssl_cert.c +++ b/frontends/gtk/ssl_cert.c @@ -64,7 +64,7 @@ static gboolean nsgtk_ssl_delete_event(GtkWidget *w, GdkEvent *event, gpointer return FALSE; } -void gtk_cert_verify(nsurl *url, const struct ssl_cert_info *certs, +nserror gtk_cert_verify(nsurl *url, const struct ssl_cert_info *certs, unsigned long num, nserror (*cb)(bool proceed, void *pw), void *cbpw) { @@ -82,15 +82,14 @@ void gtk_cert_verify(nsurl *url, const struct ssl_cert_info *certs, /* state while dlg is open */ session = calloc(sizeof(void *), 3); if (session == NULL) { - return; + return NSERROR_NOMEM; } res = nsgtk_builder_new_from_resname("ssl", &builder); if (res != NSERROR_OK) { LOG("SSL UI builder init failed"); free(session); - cb(false, cbpw); - return; + return NSERROR_INIT_FAILED; } gtk_builder_connect_signals(builder, NULL); @@ -114,7 +113,7 @@ void gtk_cert_verify(nsurl *url, const struct ssl_cert_info *certs, if (ssl_window == NULL) { free(session); g_object_unref(G_OBJECT(dlg)); - return; + return NSERROR_INIT_FAILED; } accept = GTK_BUTTON(gtk_builder_get_object(builder, "sslaccept")); @@ -133,4 +132,6 @@ void gtk_cert_verify(nsurl *url, const struct ssl_cert_info *certs, (gpointer)session); gtk_widget_show(GTK_WIDGET(dlg)); + + return NSERROR_OK; } diff --git a/frontends/gtk/ssl_cert.h b/frontends/gtk/ssl_cert.h index 48937d457..398f1cc29 100644 --- a/frontends/gtk/ssl_cert.h +++ b/frontends/gtk/ssl_cert.h @@ -31,6 +31,6 @@ struct ssl_cert_info; * \param cb Callback upon user decision. * \param cbpw Context pointer passed to cb */ -void gtk_cert_verify(struct nsurl *url, const struct ssl_cert_info *certs, unsigned long num, nserror (*cb)(bool proceed, void *pw), void *cbpw); +nserror gtk_cert_verify(struct nsurl *url, const struct ssl_cert_info *certs, unsigned long num, nserror (*cb)(bool proceed, void *pw), void *cbpw); #endif diff --git a/frontends/monkey/cert.c b/frontends/monkey/cert.c index ec1b1ce43..710e71098 100644 --- a/frontends/monkey/cert.c +++ b/frontends/monkey/cert.c @@ -35,15 +35,14 @@ typedef struct monkey_cert { static monkey_cert_t *cert_ring = NULL; static uint32_t cert_ctr = 0; -void +nserror gui_cert_verify(nsurl *url, const struct ssl_cert_info *certs, unsigned long num, nserror (*cb)(bool proceed, void *pw), void *cbpw) { monkey_cert_t *m4t = calloc(sizeof(*m4t), 1); if (m4t == NULL) { - cb(false, cbpw); - return; + return NSERROR_NOMEM; } m4t->cb = cb; m4t->pw = cbpw; @@ -53,6 +52,8 @@ gui_cert_verify(nsurl *url, const struct ssl_cert_info *certs, fprintf(stdout, "SSLCERT VERIFY CERT %u URL %s\n", m4t->num, nsurl_access(url)); + + return NSERROR_OK; } diff --git a/frontends/monkey/cert.h b/frontends/monkey/cert.h index 283817f3d..4470e2e72 100644 --- a/frontends/monkey/cert.h +++ b/frontends/monkey/cert.h @@ -21,7 +21,7 @@ struct ssl_cert_info; -void gui_cert_verify(nsurl *url, const struct ssl_cert_info *certs, +nserror gui_cert_verify(nsurl *url, const struct ssl_cert_info *certs, unsigned long num, nserror (*cb)(bool proceed, void *pw), void *cbpw); diff --git a/frontends/riscos/gui.h b/frontends/riscos/gui.h index 624f9e2fb..505e8e755 100644 --- a/frontends/riscos/gui.h +++ b/frontends/riscos/gui.h @@ -212,7 +212,7 @@ extern int ro_plot_origin_y; bool ro_gui_theme_install_apply(wimp_w w); /* in sslcert.c */ -void gui_cert_verify(struct nsurl *url, +nserror gui_cert_verify(struct nsurl *url, const struct ssl_cert_info *certs, unsigned long num, nserror (*cb)(bool proceed, void *pw), void *cbpw); diff --git a/frontends/riscos/sslcert.c b/frontends/riscos/sslcert.c index c7b8db431..8a8ddfb5b 100644 --- a/frontends/riscos/sslcert.c +++ b/frontends/riscos/sslcert.c @@ -101,7 +101,7 @@ void ro_gui_cert_postinitialise(void) * \param cb Callback upon user decision. * \param cbpw Context pointer passed to cb */ -void gui_cert_verify(nsurl *url, +nserror gui_cert_verify(nsurl *url, const struct ssl_cert_info *certs, unsigned long num, nserror (*cb)(bool proceed, void *pw), void *cbpw) { @@ -117,7 +117,7 @@ void gui_cert_verify(nsurl *url, sslcert_window = malloc(sizeof(struct ro_sslcert)); if (sslcert_window == NULL) { LOG("Failed to allocate memory for SSL Cert Dialog"); - return; + return NSERROR_NOMEM; } /* Create the SSL window and its pane. */ @@ -127,7 +127,7 @@ void gui_cert_verify(nsurl *url, if (error) { LOG("xwimp_create_window: 0x%x: %s", error->errnum, error->errmess); free(sslcert_window); - return; + return NSERROR_INIT_FAILED; } error = xwimp_create_window(ro_gui_cert_tree_template, @@ -135,7 +135,7 @@ void gui_cert_verify(nsurl *url, if (error) { LOG("xwimp_create_window: 0x%x: %s", error->errnum, error->errmess); free(sslcert_window); - return; + return NSERROR_INIT_FAILED; } /* Create the SSL data and build a tree from it. */ @@ -148,7 +148,7 @@ void gui_cert_verify(nsurl *url, if (sslcert_window->tv == NULL) { LOG("Failed to allocate treeview"); free(sslcert_window); - return; + return NSERROR_NOMEM; } /* Set up the certificate window event handling. @@ -182,7 +182,7 @@ void gui_cert_verify(nsurl *url, if (error) { ro_gui_cert_release_window(sslcert_window); LOG("xwimp_get_window_info: 0x%x: %s", error->errnum, error->errmess); - return; + return NSERROR_INIT_FAILED; } state.w = sslcert_window->window; @@ -190,7 +190,7 @@ void gui_cert_verify(nsurl *url, if (error) { ro_gui_cert_release_window(sslcert_window); LOG("xwimp_get_window_state: 0x%x: %s", error->errnum, error->errmess); - return; + return NSERROR_INIT_FAILED; } istate.w = sslcert_window->window; @@ -199,7 +199,7 @@ void gui_cert_verify(nsurl *url, if (error) { ro_gui_cert_release_window(sslcert_window); LOG("xwimp_get_icon_state: 0x%x: %s", error->errnum, error->errmess); - return; + return NSERROR_INIT_FAILED; } state.w = sslcert_window->pane; @@ -230,7 +230,7 @@ void gui_cert_verify(nsurl *url, if (error) { ro_gui_cert_release_window(sslcert_window); LOG("xwimp_set_extent: 0x%x: %s", error->errnum, error->errmess); - return; + return NSERROR_INIT_FAILED; } } @@ -248,10 +248,12 @@ void gui_cert_verify(nsurl *url, ro_gui_cert_release_window(sslcert_window); LOG("xwimp_open_window_nested: 0x%x: %s", error->errnum, error->errmess); ro_gui_cert_release_window(sslcert_window); - return; + return NSERROR_INIT_FAILED; } ro_treeview_set_origin(sslcert_window->tv, 0, 0); + + return NSERROR_OK; } /** diff --git a/include/netsurf/misc.h b/include/netsurf/misc.h index 7b354953c..2647b9a1c 100644 --- a/include/netsurf/misc.h +++ b/include/netsurf/misc.h @@ -89,8 +89,9 @@ struct gui_misc_table { * \param num The number of certificates to be verified. * \param cb Callback upon user decision. * \param cbpw Context pointer passed to cb + * \return NSERROR_OK on sucess else error and cb never called */ - void (*cert_verify)(struct nsurl *url, const struct ssl_cert_info *certs, unsigned long num, nserror (*cb)(bool proceed, void *pw), void *cbpw); + nserror (*cert_verify)(struct nsurl *url, const struct ssl_cert_info *certs, unsigned long num, nserror (*cb)(bool proceed, void *pw), void *cbpw); /** * Prompt user for login