Commit Diff


commit - c171304b1ea3f9decda9c0bfdbbcba6cf399ba26
commit + 4fdc9933599cda6387d6c15f757faf4dda1bbd0a
blob - cd2a4d10283bf4ad5deabc320552d4c15cff03a3
blob + 6eccb24711453dbf34c2acd10796c2752a10ed91
--- certs.c
+++ certs.c
@@ -289,7 +289,7 @@ path_under(const char *cpath, const char *tpath)
 }
 
 static struct ccert *
-find_cert_for(struct cstore *cstore, struct iri *iri)
+find_cert_for(struct cstore *cstore, struct iri *iri, size_t *n)
 {
 	struct ccert	*c;
 	size_t		 i;
@@ -299,8 +299,11 @@ find_cert_for(struct cstore *cstore, struct iri *iri)
 
 		if (!strcmp(c->host, iri->iri_host) &&
 		    !strcmp(c->port, iri->iri_portstr) &&
-		    path_under(c->path, iri->iri_path))
+		    path_under(c->path, iri->iri_path)) {
+			if (n)
+				*n = i;
 			return (c);
+		}
 	}
 
 	return (NULL);
@@ -311,9 +314,9 @@ cert_for(struct iri *iri)
 {
 	struct ccert	*c;
 
-	if ((c = find_cert_for(&temp_store, iri)) != NULL)
+	if ((c = find_cert_for(&temp_store, iri, NULL)) != NULL)
 		return (c->cert);
-	if ((c = find_cert_for(&cert_store, iri)) != NULL)
+	if ((c = find_cert_for(&cert_store, iri, NULL)) != NULL)
 		return (c->cert);
 	return (NULL);
 }
@@ -379,7 +382,7 @@ cert_save_for(const char *cert, struct iri *i, int per
 
 	cstore = persist ? &cert_store : &temp_store;
 
-	if ((c = find_cert_for(cstore, i)) != NULL) {
+	if ((c = find_cert_for(cstore, i, NULL)) != NULL) {
 		if ((d = strdup(cert)) == NULL)
 			return (-1);
 
@@ -398,7 +401,38 @@ cert_save_for(const char *cert, struct iri *i, int per
 
 	if (persist && write_cert_file() == -1)
 		return (-1);
+
+	return (0);
+}
+
+int
+cert_delete_for(const char *cert, struct iri *iri, int persist)
+{
+	struct ccert	*c;
+	size_t		 i;
+
+	if ((c = find_cert_for(&temp_store, iri, &i)) != NULL) {
+		free(c->host);
+		free(c->port);
+		free(c->path);
+		free(c->cert);
 
+		if (i == temp_store.len - 1) {
+			memset(c, 0, sizeof(*c));
+			temp_store.len--;
+		} else {
+			memmove(&temp_store.certs[i], &temp_store.certs[i + 1],
+			    sizeof(*temp_store.certs) * (temp_store.len - i));
+		}
+	}
+
+	if ((c = find_cert_for(&cert_store, iri, NULL)) != NULL) {
+		free(c->cert);
+		c->cert = NULL;
+
+		return (write_cert_file() == -1);
+	}
+
 	return (0);
 }
 
blob - 3512f77a2d20b2adb66315efa49e2a2f15052ba3
blob + f889567e82635d187d12dcc9b540471639eb0ddc
--- certs.h
+++ certs.h
@@ -26,5 +26,6 @@ int		 certs_init(const char *);
 const char	*ccert(const char *);
 const char	*cert_for(struct iri *);
 int		 cert_save_for(const char *, struct iri *, int);
+int		 cert_delete_for(const char *, struct iri *, int);
 int		 cert_open(const char *);
 int		 cert_new(const char *, const char *, const char *, int);
blob - 8e03671a0871634cb6c0fc02b16a394dde8bfaaa
blob + 90dacc925bd186000c1c3705c19c41db4f56cf5e
--- cmd.c
+++ cmd.c
@@ -20,6 +20,7 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include "certs.h"
 #include "cmd.h"
 #include "compl.h"
 #include "defaults.h"
@@ -1113,4 +1114,25 @@ cmd_client_certificate_info(struct buffer *buffer)
 		message("Using certificate %s", current_tab->client_cert);
 	else
 		message("Not using any client certificate.");
+}
+
+static void
+unload_certificate_cb(int r, struct tab *tab)
+{
+	cert_delete_for(tab->client_cert, &tab->iri, r);
+}
+
+void
+cmd_unload_certificate(struct buffer *buffer)
+{
+	GUARD_RECURSIVE_MINIBUFFER();
+
+	if (current_tab->client_cert == NULL) {
+		message("No client certificate in use!");
+		return;
+	}
+
+	/* Sucks that we ask this even when the cert is already temporary */
+	yornp("Unload only for the current session?", unload_certificate_cb,
+	    current_tab);
 }
blob - 630ad042c62f9bc77605cd74c29b29993a9ed5c0
blob + 08b3ebbfa77992e43b0792bda84d0cb5a9daf9e9
--- cmd.h
+++ cmd.h
@@ -82,6 +82,7 @@ CMD(cmd_toc,			"Jump to a heading using the minibuffer
 CMD(cmd_toggle_downloads,	"Toggle the downloads side window.");
 CMD(cmd_toggle_help,		"Toggle side window with help.");
 CMD(cmd_toggle_pre_wrap,	"Toggle the wrapping of preformatted blocks.");
+CMD(cmd_unload_certificate,	"Stop using the certificate.");
 CMD(cmd_up,			"Go up one level.");
 CMD(cmd_use_certificate,	"Use a certificate for the current page.");
 CMD(cmd_write_buffer,		"Save the current page to the disk.");