diff options
author | Vincent Sanders <vince@kyllikki.org> | 2020-02-24 18:55:50 +0000 |
---|---|---|
committer | Vincent Sanders <vince@kyllikki.org> | 2020-02-24 18:56:15 +0000 |
commit | 1a25234f20b6c634024196143677c14e8142576c (patch) | |
tree | c5993f26bc38ccb7d7ac1de47ba82caf2bfb578d | |
parent | 52bfae17822d289dcf16566acfa3eac2539d66d5 (diff) | |
download | netsurf-1a25234f20b6c634024196143677c14e8142576c.tar.gz netsurf-1a25234f20b6c634024196143677c14e8142576c.tar.bz2 |
implement browser_window_show_certificates
-rw-r--r-- | desktop/browser_window.c | 69 |
1 files changed, 65 insertions, 4 deletions
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 <strings.h> #include <math.h> #include <nsutils/time.h> +#include <nsutils/base64.h> #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; } |