From fbc0847db06fa91765d5b83b34dabee85f65d4ec Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Sat, 9 May 2020 22:42:12 +0100 Subject: move ssl certificate serialisation into a url to the ssl_cert utility code --- desktop/browser_window.c | 62 ++++++++---------------------------------------- 1 file changed, 10 insertions(+), 52 deletions(-) (limited to 'desktop') diff --git a/desktop/browser_window.c b/desktop/browser_window.c index 03943f163..8ef2c7704 100644 --- a/desktop/browser_window.c +++ b/desktop/browser_window.c @@ -4769,65 +4769,23 @@ nserror browser_window_show_certificates(struct browser_window *bw) { 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 = cert_chain_to_query(bw->current_cert_chain, &url); + if (res == NSERROR_OK) { + res = browser_window_create(BW_CREATE_HISTORY | + BW_CREATE_FOREGROUND | + BW_CREATE_TAB, + url, + NULL, + bw, + NULL); - res = nsurl_create((const char *)urlstr, &url); - free(urlstr); - if (res != NSERROR_OK) { - return res; + nsurl_unref(url); } - 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