Allow certificate verification user prompt creation to return errors

This commit is contained in:
Vincent Sanders 2016-07-31 01:24:57 +01:00
parent 51725592c9
commit b939afe3fc
14 changed files with 55 additions and 33 deletions

View File

@ -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;

View File

@ -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,

View File

@ -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 */

View File

@ -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)

View File

@ -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);

View File

@ -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)

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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

View File

@ -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;
}

View File

@ -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);

View File

@ -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);

View File

@ -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;
}
/**

View File

@ -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