From 1a25234f20b6c634024196143677c14e8142576c Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Mon, 24 Feb 2020 18:55:50 +0000 Subject: implement browser_window_show_certificates --- desktop/browser_window.c | 69 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 65 insertions(+), 4 deletions(-) (limited to 'desktop/browser_window.c') diff --git a/desktop/browser_window.c b/desktop/browser_window.c index e12885263..f705ce901 100644 --- a/desktop/browser_window.c +++ b/desktop/browser_window.c @@ -35,6 +35,7 @@ #include #include #include +#include #include "utils/corestrings.h" #include "utils/log.h" @@ -4764,9 +4765,69 @@ nserror browser_window_show_cookies( } /* Exported interface, documented in browser_window.h */ -nserror browser_window_show_certificates( - const struct browser_window *bw) +nserror browser_window_show_certificates(const struct browser_window *bw) { - /** \todo Implement show certificates */ - return NSERROR_OK; + nserror res; + nsurl *url; + size_t allocsize; + size_t urlstrlen; + uint8_t *urlstr; + size_t depth; + + if (bw->current_cert_chain == NULL) { + return NSERROR_NOT_FOUND; + } + + allocsize = 20; + for (depth = 0; depth < bw->current_cert_chain->depth; depth++) { + allocsize += 7; /* allow for &cert= */ + allocsize += 4 * ((bw->current_cert_chain->certs[depth].der_length + 2) / 3); + } + + urlstr = malloc(allocsize); + if (urlstr == NULL) { + return NSERROR_NOMEM; + } + + urlstrlen = snprintf((char *)urlstr, allocsize, "about:certificate"); + for (depth = 0; depth < bw->current_cert_chain->depth; depth++) { + nsuerror nsures; + size_t output_length; + + urlstrlen += snprintf((char *)urlstr + urlstrlen, + allocsize - urlstrlen, + "&cert="); + + output_length = allocsize - urlstrlen; + nsures = nsu_base64_encode_url( + bw->current_cert_chain->certs[depth].der, + bw->current_cert_chain->certs[depth].der_length, + (uint8_t *)urlstr + urlstrlen, + &output_length); + if (nsures != NSUERROR_OK) { + free(urlstr); + return (nserror)nsures; + } + urlstrlen += output_length; + } + urlstr[17] = '?'; + urlstr[urlstrlen] = 0; + + res = nsurl_create((const char *)urlstr, &url); + free(urlstr); + if (res != NSERROR_OK) { + return res; + } + + res = browser_window_create(BW_CREATE_HISTORY | + BW_CREATE_FOREGROUND | + BW_CREATE_TAB, + url, + NULL, + bw, + NULL); + + nsurl_unref(url); + + return res; } -- cgit v1.2.3