about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJosh Rickmar <jrick@devio.us>2013-05-22 11:06:52 -0400
committerJosh Rickmar <jrick@conformal.com>2013-06-05 17:12:51 -0400
commitb7a686e4a770a6cb0b87e2bfa936890954698ece (patch)
tree0f3e74ff4831e39100b920cfa3f9da0b66a70cb8
parent161448f1d53dba4692990d9c61117d7699902ffd (diff)
downloadxombrero-b7a686e4a770a6cb0b87e2bfa936890954698ece.tar.gz
Allow saving certs from :cert show page
This allows the user to avoid a race where, after verifying a cert via
:cert show, they must go back to the site and save the cert.  During
this time, the cert may have been modified, so saving it from the
:cert show page will use the PEM-encoded cert currently shown and
saved in memory instead.
-rw-r--r--xombrero.c16
-rw-r--r--xombrero.h3
2 files changed, 16 insertions, 3 deletions
diff --git a/xombrero.c b/xombrero.c
index 50f869d..34c826b 100644
--- a/xombrero.c
+++ b/xombrero.c
@@ -887,6 +887,12 @@ load_uri(struct tab *t, gchar *uri)
 		uri = newuri;
 	}
 
+	/* clear :cert show host */
+	if (t->about_cert_host) {
+		g_free(t->about_cert_host);
+		t->about_cert_host = NULL;
+	}
+
 	if (!strncmp(uri, XT_URI_ABOUT, XT_URI_ABOUT_LEN)) {
 		for (i = 0; i < about_list_size(); i++)
 			if (!strcmp(&uri[XT_URI_ABOUT_LEN], about_list[i].name) &&
@@ -1800,6 +1806,7 @@ cert_cmd(struct tab *t, struct karg *args)
 	size_t			cert_count;
 	gnutls_x509_crt_t	*certs;
 	SoupURI			*su;
+	char			*host;
 #if !GTK_CHECK_VERSION(3, 0, 0)
 	GdkColor		color;
 #endif
@@ -1826,6 +1833,7 @@ cert_cmd(struct tab *t, struct karg *args)
 		certs = get_local_cert_chain(uri, &cert_count, &error_str,
 		    certs_cache_dir);
 		if (error_str == NULL) {
+			t->about_cert_host = g_strdup(su->host);
 			show_certs(t, certs, cert_count, "Certificate Chain");
 			free_connection_certs(certs, cert_count);
 		} else {
@@ -1840,10 +1848,12 @@ cert_cmd(struct tab *t, struct karg *args)
 	if (error_str)
 		goto done;
 
-	if (args->i & XT_SHOW)
+	if (args->i & XT_SHOW) {
+		t->about_cert_host = g_strdup(su->host);
 		show_certs(t, certs, cert_count, "Certificate Chain");
-	else if (args->i & XT_SAVE) {
-		save_certs(t, certs, cert_count, su->host, certs_dir);
+	} else if (args->i & XT_SAVE) {
+		host = t->about_cert_host ? t->about_cert_host : su->host;
+		save_certs(t, certs, cert_count, host, certs_dir);
 #if GTK_CHECK_VERSION(3, 0, 0)
 		gtk_widget_set_name(t->uri_entry, XT_CSS_BLUE);
 		statusbar_modify_attr(t, XT_CSS_BLUE);
diff --git a/xombrero.h b/xombrero.h
index 210fb52..6137299 100644
--- a/xombrero.h
+++ b/xombrero.h
@@ -303,6 +303,9 @@ struct tab {
 
 	/* cert chain (pem) */
 	char			*cert_chain;
+
+	/* previous host (:cert show) */
+	char			*about_cert_host;
 };
 TAILQ_HEAD(tab_list, tab);