2006-02-23 18:06:54 +03:00
|
|
|
/*
|
|
|
|
* Copyright 2006 John M Bell <jmb202@ecs.soton.ac.uk>
|
2010-10-05 23:14:46 +04:00
|
|
|
* Copyright 2010 Stephen Fryatt <stevef@netsurf-browser.org>
|
2007-08-08 20:16:03 +04:00
|
|
|
*
|
|
|
|
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
|
|
|
*
|
|
|
|
* NetSurf is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* NetSurf is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2006-02-23 18:06:54 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
* SSL Certificate verification UI (implementation)
|
|
|
|
*/
|
|
|
|
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "utils/config.h"
|
2006-02-23 18:06:54 +03:00
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "oslib/wimp.h"
|
2014-10-16 12:50:55 +04:00
|
|
|
|
|
|
|
#include "utils/log.h"
|
|
|
|
#include "utils/utils.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "content/content.h"
|
2010-04-07 21:37:54 +04:00
|
|
|
#include "content/hlcache.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "content/fetch.h"
|
|
|
|
#include "content/urldb.h"
|
|
|
|
#include "desktop/browser.h"
|
2013-08-12 14:44:13 +04:00
|
|
|
#include "desktop/sslcert_viewer.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "desktop/tree.h"
|
2014-06-06 02:01:37 +04:00
|
|
|
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "riscos/dialog.h"
|
2010-10-05 23:14:46 +04:00
|
|
|
#include "riscos/sslcert.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "riscos/textarea.h"
|
|
|
|
#include "riscos/treeview.h"
|
|
|
|
#include "riscos/wimp.h"
|
2009-03-28 04:00:31 +03:00
|
|
|
#include "riscos/wimp_event.h"
|
|
|
|
#include "riscos/wimputils.h"
|
2014-06-06 02:01:37 +04:00
|
|
|
#include "riscos/gui.h"
|
2006-02-23 18:06:54 +03:00
|
|
|
|
2006-07-16 04:21:15 +04:00
|
|
|
#define ICON_SSL_PANE 1
|
|
|
|
#define ICON_SSL_REJECT 3
|
|
|
|
#define ICON_SSL_ACCEPT 4
|
2006-02-23 18:06:54 +03:00
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
static wimp_window *ro_gui_cert_dialog_template;
|
|
|
|
static wimp_window *ro_gui_cert_tree_template;
|
|
|
|
|
|
|
|
struct ro_sslcert
|
|
|
|
{
|
|
|
|
wimp_w window;
|
|
|
|
wimp_w pane;
|
|
|
|
ro_treeview *tv;
|
|
|
|
struct sslcert_session_data *data;
|
2006-02-23 18:06:54 +03:00
|
|
|
};
|
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
static void ro_gui_cert_accept(wimp_pointer *pointer);
|
|
|
|
static void ro_gui_cert_reject(wimp_pointer *pointer);
|
|
|
|
static void ro_gui_cert_close_window(wimp_w w);
|
|
|
|
static void ro_gui_cert_release_window(struct ro_sslcert *s);
|
2006-02-23 18:06:54 +03:00
|
|
|
|
|
|
|
/**
|
2010-10-05 23:14:46 +04:00
|
|
|
* Load and initialise the certificate window template
|
2006-02-23 18:06:54 +03:00
|
|
|
*/
|
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
void ro_gui_cert_preinitialise(void)
|
2006-02-23 18:06:54 +03:00
|
|
|
{
|
2010-10-05 23:14:46 +04:00
|
|
|
/* Load templates for the SSL windows and adjust the tree window
|
|
|
|
* flags to suit.
|
|
|
|
*/
|
|
|
|
|
|
|
|
ro_gui_cert_dialog_template = ro_gui_dialog_load_template("sslcert");
|
|
|
|
ro_gui_cert_tree_template = ro_gui_dialog_load_template("tree");
|
2006-07-16 04:47:20 +04:00
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
ro_gui_cert_tree_template->flags &= ~(wimp_WINDOW_MOVEABLE |
|
2006-07-16 04:21:15 +04:00
|
|
|
wimp_WINDOW_BACK_ICON |
|
|
|
|
wimp_WINDOW_CLOSE_ICON |
|
|
|
|
wimp_WINDOW_TITLE_ICON |
|
|
|
|
wimp_WINDOW_SIZE_ICON |
|
|
|
|
wimp_WINDOW_TOGGLE_ICON);
|
2006-02-23 18:06:54 +03:00
|
|
|
}
|
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
/**
|
|
|
|
* Load and initialise the certificate window template
|
|
|
|
*/
|
|
|
|
|
|
|
|
void ro_gui_cert_postinitialise(void)
|
|
|
|
{
|
|
|
|
/* Initialise the SSL module. */
|
|
|
|
}
|
|
|
|
|
2006-02-23 18:06:54 +03:00
|
|
|
/**
|
2014-11-08 14:38:20 +03:00
|
|
|
* Prompt the user to verify a certificate with issuse.
|
2010-10-05 23:14:46 +04:00
|
|
|
*
|
2014-11-08 14:38:20 +03:00
|
|
|
* \param url The URL being verified.
|
|
|
|
* \param certs The certificate to be verified
|
|
|
|
* \param num The number of certificates to be verified.
|
|
|
|
* \param cb Callback upon user decision.
|
2014-11-08 15:35:11 +03:00
|
|
|
* \param cbpw Context pointer passed to cb
|
2006-02-23 18:06:54 +03:00
|
|
|
*/
|
2012-10-11 14:20:02 +04:00
|
|
|
void gui_cert_verify(nsurl *url,
|
2010-04-16 02:49:22 +04:00
|
|
|
const struct ssl_cert_info *certs, unsigned long num,
|
|
|
|
nserror (*cb)(bool proceed, void *pw), void *cbpw)
|
2006-02-23 18:06:54 +03:00
|
|
|
{
|
2010-10-05 23:14:46 +04:00
|
|
|
struct ro_sslcert *sslcert_window;
|
|
|
|
wimp_window_state state;
|
|
|
|
wimp_icon_state istate;
|
|
|
|
wimp_window_info info;
|
|
|
|
os_error *error;
|
|
|
|
bool set_extent;
|
2006-07-16 04:21:15 +04:00
|
|
|
|
2010-04-16 02:49:22 +04:00
|
|
|
assert(certs);
|
2006-02-23 18:06:54 +03:00
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
sslcert_window = malloc(sizeof(struct ro_sslcert));
|
|
|
|
if (sslcert_window == NULL) {
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("Failed to allocate memory for SSL Cert Dialog");
|
2006-07-16 04:21:15 +04:00
|
|
|
return;
|
|
|
|
}
|
2006-02-23 18:06:54 +03:00
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
/* Create the SSL window and its pane. */
|
|
|
|
|
|
|
|
error = xwimp_create_window(ro_gui_cert_dialog_template,
|
|
|
|
&(sslcert_window->window));
|
2006-07-16 04:21:15 +04:00
|
|
|
if (error) {
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("xwimp_create_window: 0x%x: %s", error->errnum, error->errmess);
|
2010-10-05 23:14:46 +04:00
|
|
|
free(sslcert_window);
|
2006-07-16 04:21:15 +04:00
|
|
|
return;
|
|
|
|
}
|
2006-07-16 04:47:20 +04:00
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
error = xwimp_create_window(ro_gui_cert_tree_template,
|
|
|
|
&(sslcert_window->pane));
|
2006-07-16 04:21:15 +04:00
|
|
|
if (error) {
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("xwimp_create_window: 0x%x: %s", error->errnum, error->errmess);
|
2010-10-05 23:14:46 +04:00
|
|
|
free(sslcert_window);
|
2006-07-16 04:21:15 +04:00
|
|
|
return;
|
|
|
|
}
|
2010-10-05 23:14:46 +04:00
|
|
|
|
|
|
|
/* Create the SSL data and build a tree from it. */
|
2013-08-12 14:44:13 +04:00
|
|
|
sslcert_viewer_create_session_data(num, url,
|
|
|
|
cb, cbpw, certs, &sslcert_window->data);
|
|
|
|
ssl_current_session = sslcert_window->data;
|
2010-10-05 23:14:46 +04:00
|
|
|
|
2011-02-21 02:16:33 +03:00
|
|
|
sslcert_window->tv = ro_treeview_create(sslcert_window->pane,
|
2013-08-13 16:48:53 +04:00
|
|
|
NULL, NULL, TREE_SSLCERT);
|
2010-10-05 23:14:46 +04:00
|
|
|
if (sslcert_window->tv == NULL) {
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("Failed to allocate treeview");
|
2010-10-05 23:14:46 +04:00
|
|
|
free(sslcert_window);
|
2006-02-23 18:06:54 +03:00
|
|
|
return;
|
|
|
|
}
|
2010-10-05 23:14:46 +04:00
|
|
|
|
|
|
|
/* Set up the certificate window event handling.
|
|
|
|
*
|
|
|
|
* (The action buttons are registered as button events, not OK and
|
|
|
|
* Cancel, as both need to carry out actions.)
|
|
|
|
*/
|
|
|
|
|
|
|
|
ro_gui_wimp_event_set_user_data(sslcert_window->window, sslcert_window);
|
|
|
|
ro_gui_wimp_event_register_close_window(sslcert_window->window,
|
|
|
|
ro_gui_cert_close_window);
|
|
|
|
ro_gui_wimp_event_register_button(sslcert_window->window,
|
|
|
|
ICON_SSL_REJECT, ro_gui_cert_reject);
|
|
|
|
ro_gui_wimp_event_register_button(sslcert_window->window,
|
|
|
|
ICON_SSL_ACCEPT, ro_gui_cert_accept);
|
|
|
|
|
|
|
|
ro_gui_dialog_open_persistent(NULL, sslcert_window->window, false);
|
|
|
|
|
|
|
|
/* Nest the tree window inside the pane window. To do this, we:
|
|
|
|
* - Get the current pane extent,
|
|
|
|
* - Get the parent window position and the location of the pane-
|
|
|
|
* locating icon inside it,
|
|
|
|
* - Set the visible area of the pane to suit,
|
|
|
|
* - Check that the pane extents are OK for this visible area, and
|
|
|
|
* increase them if necessary,
|
|
|
|
* - Before finally opening the pane as a nested part of the parent.
|
|
|
|
*/
|
|
|
|
|
|
|
|
info.w = sslcert_window->pane;
|
|
|
|
error = xwimp_get_window_info_header_only(&info);
|
|
|
|
if (error) {
|
|
|
|
ro_gui_cert_release_window(sslcert_window);
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("xwimp_get_window_info: 0x%x: %s", error->errnum, error->errmess);
|
2009-05-30 03:05:44 +04:00
|
|
|
return;
|
2006-07-16 04:21:15 +04:00
|
|
|
}
|
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
state.w = sslcert_window->window;
|
2006-07-16 04:21:15 +04:00
|
|
|
error = xwimp_get_window_state(&state);
|
|
|
|
if (error) {
|
2010-10-05 23:14:46 +04:00
|
|
|
ro_gui_cert_release_window(sslcert_window);
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("xwimp_get_window_state: 0x%x: %s", error->errnum, error->errmess);
|
2006-07-16 04:21:15 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
istate.w = sslcert_window->window;
|
2006-07-16 04:21:15 +04:00
|
|
|
istate.i = ICON_SSL_PANE;
|
|
|
|
error = xwimp_get_icon_state(&istate);
|
|
|
|
if (error) {
|
2010-10-05 23:14:46 +04:00
|
|
|
ro_gui_cert_release_window(sslcert_window);
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("xwimp_get_icon_state: 0x%x: %s", error->errnum, error->errmess);
|
2006-07-16 04:21:15 +04:00
|
|
|
return;
|
|
|
|
}
|
2010-10-05 23:14:46 +04:00
|
|
|
|
|
|
|
state.w = sslcert_window->pane;
|
2006-07-16 04:21:15 +04:00
|
|
|
state.visible.x1 = state.visible.x0 + istate.icon.extent.x1 - 20 -
|
2010-10-05 23:14:46 +04:00
|
|
|
ro_get_vscroll_width(sslcert_window->pane);
|
2006-07-16 04:21:15 +04:00
|
|
|
state.visible.x0 += istate.icon.extent.x0 + 20;
|
2011-03-24 03:09:49 +03:00
|
|
|
state.visible.y0 = state.visible.y1 + istate.icon.extent.y0 + 20 +
|
|
|
|
ro_get_hscroll_height(sslcert_window->pane);
|
2006-07-16 04:21:15 +04:00
|
|
|
state.visible.y1 += istate.icon.extent.y1 - 32;
|
2010-10-05 23:14:46 +04:00
|
|
|
|
|
|
|
set_extent = false;
|
|
|
|
|
|
|
|
if ((info.extent.x1 - info.extent.x0) <
|
|
|
|
(state.visible.x1 - state.visible.x0)) {
|
|
|
|
info.extent.x0 = 0;
|
|
|
|
info.extent.x1 = state.visible.x1 - state.visible.x0;
|
|
|
|
set_extent = true;
|
|
|
|
}
|
|
|
|
if ((info.extent.y1 - info.extent.y0) <
|
|
|
|
(state.visible.y1 - state.visible.y0)) {
|
|
|
|
info.extent.y1 = 0;
|
|
|
|
info.extent.x1 = state.visible.y0 - state.visible.y1;
|
|
|
|
set_extent = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (set_extent) {
|
|
|
|
error = xwimp_set_extent(sslcert_window->pane, &(info.extent));
|
|
|
|
if (error) {
|
|
|
|
ro_gui_cert_release_window(sslcert_window);
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("xwimp_set_extent: 0x%x: %s", error->errnum, error->errmess);
|
2010-10-05 23:14:46 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
error = xwimp_open_window_nested(PTR_WIMP_OPEN(&state),
|
|
|
|
sslcert_window->window,
|
2006-07-16 04:21:15 +04:00
|
|
|
wimp_CHILD_LINKS_PARENT_VISIBLE_BOTTOM_OR_LEFT
|
|
|
|
<< wimp_CHILD_XORIGIN_SHIFT |
|
|
|
|
wimp_CHILD_LINKS_PARENT_VISIBLE_TOP_OR_RIGHT
|
|
|
|
<< wimp_CHILD_YORIGIN_SHIFT |
|
|
|
|
wimp_CHILD_LINKS_PARENT_VISIBLE_BOTTOM_OR_LEFT
|
|
|
|
<< wimp_CHILD_LS_EDGE_SHIFT |
|
|
|
|
wimp_CHILD_LINKS_PARENT_VISIBLE_BOTTOM_OR_LEFT
|
|
|
|
<< wimp_CHILD_RS_EDGE_SHIFT);
|
|
|
|
if (error) {
|
2010-10-05 23:14:46 +04:00
|
|
|
ro_gui_cert_release_window(sslcert_window);
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("xwimp_open_window_nested: 0x%x: %s", error->errnum, error->errmess);
|
2010-10-05 23:14:46 +04:00
|
|
|
ro_gui_cert_release_window(sslcert_window);
|
2006-07-16 04:21:15 +04:00
|
|
|
return;
|
|
|
|
}
|
2011-03-24 03:09:49 +03:00
|
|
|
|
|
|
|
ro_treeview_set_origin(sslcert_window->tv, 0, 0);
|
2006-07-16 04:21:15 +04:00
|
|
|
}
|
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
/**
|
|
|
|
* Handle acceptance of certificate via event callback.
|
|
|
|
*
|
|
|
|
* \param *pointer The wimp pointer block.
|
|
|
|
*/
|
2006-07-16 04:47:20 +04:00
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
void ro_gui_cert_accept(wimp_pointer *pointer)
|
|
|
|
{
|
|
|
|
struct ro_sslcert *s;
|
2006-07-16 04:21:15 +04:00
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
s = (struct ro_sslcert *) ro_gui_wimp_event_get_user_data(pointer->w);
|
2006-07-16 04:47:20 +04:00
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
if (s != NULL) {
|
2013-08-12 14:44:13 +04:00
|
|
|
sslcert_viewer_accept(s->data);
|
2010-10-05 23:14:46 +04:00
|
|
|
ro_gui_dialog_close(s->window);
|
|
|
|
ro_gui_cert_release_window(s);
|
2006-06-26 05:14:33 +04:00
|
|
|
}
|
2006-02-23 18:06:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-10-05 23:14:46 +04:00
|
|
|
* Handle rejection of certificate via event callback.
|
|
|
|
*
|
2014-11-08 14:38:20 +03:00
|
|
|
* \param pointer The wimp pointer block.
|
2006-02-23 18:06:54 +03:00
|
|
|
*/
|
2006-07-16 04:21:15 +04:00
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
void ro_gui_cert_reject(wimp_pointer *pointer)
|
|
|
|
{
|
|
|
|
struct ro_sslcert *s;
|
2006-07-16 04:47:20 +04:00
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
s = (struct ro_sslcert *) ro_gui_wimp_event_get_user_data(pointer->w);
|
2010-04-16 02:49:22 +04:00
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
if (s != NULL) {
|
2013-08-12 14:44:13 +04:00
|
|
|
sslcert_viewer_reject(s->data);
|
2010-10-05 23:14:46 +04:00
|
|
|
ro_gui_dialog_close(s->window);
|
|
|
|
ro_gui_cert_release_window(s);
|
2006-07-16 04:21:15 +04:00
|
|
|
}
|
2010-10-05 23:14:46 +04:00
|
|
|
}
|
2006-07-16 04:47:20 +04:00
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
/**
|
|
|
|
* Callback to handle the closure of the SSL dialogue by other means.
|
|
|
|
*
|
|
|
|
* \param w The window being closed.
|
|
|
|
*/
|
2006-07-16 04:47:20 +04:00
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
static void ro_gui_cert_close_window(wimp_w w)
|
|
|
|
{
|
|
|
|
struct ro_sslcert *s;
|
|
|
|
|
|
|
|
s = (struct ro_sslcert *) ro_gui_wimp_event_get_user_data(w);
|
|
|
|
|
|
|
|
if (s != NULL)
|
|
|
|
ro_gui_cert_release_window(s);
|
2006-02-23 18:06:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-10-05 23:14:46 +04:00
|
|
|
* Handle closing of the RISC OS certificate verification dialog, deleting
|
|
|
|
* the windows and freeing up the treeview and data block.
|
|
|
|
*
|
|
|
|
* \param *s The data block associated with the dialogue.
|
2006-02-23 18:06:54 +03:00
|
|
|
*/
|
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
void ro_gui_cert_release_window(struct ro_sslcert *s)
|
|
|
|
{
|
|
|
|
os_error *error;
|
2006-02-23 18:06:54 +03:00
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
if (s == NULL)
|
|
|
|
return;
|
2010-04-16 02:49:22 +04:00
|
|
|
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("Releasing SSL data: 0x%x", (unsigned)s);
|
2010-04-16 02:49:22 +04:00
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
ro_gui_wimp_event_finalise(s->window);
|
|
|
|
ro_treeview_destroy(s->tv);
|
2006-02-23 18:06:54 +03:00
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
error = xwimp_delete_window(s->window);
|
|
|
|
if (error) {
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("xwimp_delete_window: 0x%x:%s", error->errnum, error->errmess);
|
2010-10-05 23:14:46 +04:00
|
|
|
warn_user("WimpError", error->errmess);
|
|
|
|
}
|
|
|
|
error = xwimp_delete_window(s->pane);
|
|
|
|
if (error) {
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("xwimp_delete_window: 0x%x:%s", error->errnum, error->errmess);
|
2010-10-05 23:14:46 +04:00
|
|
|
warn_user("WimpError", error->errmess);
|
|
|
|
}
|
2006-07-16 04:47:20 +04:00
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
free(s);
|
2006-02-23 18:06:54 +03:00
|
|
|
}
|
|
|
|
|