Mercurial > trustbridge
diff cinst/windowsstore.c @ 161:a4b1c77f3e6a
Change install_certificates_win to generic write_stores_win
This function will also handle the removal to avoid
redundancies in store handling
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Tue, 25 Mar 2014 10:08:31 +0000 |
parents | bd5a5d3e5674 |
children | 8cfcd38a9bb3 |
line wrap: on
line diff
--- a/cinst/windowsstore.c Tue Mar 25 10:07:12 2014 +0000 +++ b/cinst/windowsstore.c Tue Mar 25 10:08:31 2014 +0000 @@ -1,7 +1,11 @@ #ifdef WIN32 -#include <polarssl/base64.h> +#include <stdio.h> + #include "windowsstore.h" +#include "errorcodes.h" +#include "listutil.h" +#include "strhelp.h" static LPWSTR getLastErrorMsg() { LPWSTR bufPtr = NULL; @@ -25,9 +29,10 @@ return bufPtr; } -int install_certificates_win(const char **to_install, bool user_store) +int write_stores_win(char **to_install, char **to_remove, bool user_store) { int i = 0; + int ret = -1; HCERTSTORE hStore = NULL; if (user_store) { @@ -42,25 +47,12 @@ return ERR_STORE_ACCESS_DENIED; } - while (to_install[i]) { - size_t needed_len = 0; - size_t cert_len = strnlen(to_install[i], MAX_LINE_LENGTH); - int ret = -1; - unsigned char *buf; + for (i=0; to_install[i]; i++) { + size_t cert_len = strnlen(to_install[i], MAX_LINE_LENGTH), + buf_size = 0; + char *buf = NULL; - /* Check the needed size for the buffer */ - ret = base64_decode(NULL, &needed_len, - (unsigned char *)to_install[i], cert_len); - - if (ret != 0 && ret != POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL) { - return ERR_INVALID_INSTRUCTIONS; - } - - buf = xmalloc(needed_len); - memset (buf, 0, needed_len); - - ret = base64_decode(buf, &needed_len, - (unsigned char *)to_install[i], cert_len); + ret = str_base64_decode(&buf, &buf_size, to_install[i], cert_len); if (ret != 0) { return ERR_INVALID_INSTRUCTIONS; @@ -69,7 +61,7 @@ ret = CertAddEncodedCertificateToStore (hStore, X509_ASN_ENCODING, (PBYTE)buf, - needed_len, + buf_size, CERT_STORE_ADD_ALWAYS, NULL); @@ -84,6 +76,10 @@ free(buf); } + for (i=0; to_remove[i]; i++) { + // TODO + } + if(hStore) { CertCloseStore(hStore, 0); }