# HG changeset patch # User Andre Heinecke # Date 1395742111 0 # Node ID a4b1c77f3e6ad3c5a594f941913953d7be9730c2 # Parent bf4bfd8843bd833a5db62cadbeb112c389b56341 Change install_certificates_win to generic write_stores_win This function will also handle the removal to avoid redundancies in store handling diff -r bf4bfd8843bd -r a4b1c77f3e6a cinst/main.c --- a/cinst/main.c Tue Mar 25 10:07:12 2014 +0000 +++ b/cinst/main.c Tue Mar 25 10:08:31 2014 +0000 @@ -233,8 +233,7 @@ } #ifdef WIN32 - return install_certificates_win((const char**) to_install, true); - //remove_certificates_win((const char**) to_remove, 1); + return write_stores_win (to_install, to_remove, true); #endif /* Make valgrind happy */ diff -r bf4bfd8843bd -r a4b1c77f3e6a cinst/windowsstore.c --- 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 +#include + #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); } diff -r bf4bfd8843bd -r a4b1c77f3e6a cinst/windowsstore.h --- a/cinst/windowsstore.h Tue Mar 25 10:07:12 2014 +0000 +++ b/cinst/windowsstore.h Tue Mar 25 10:08:31 2014 +0000 @@ -4,14 +4,19 @@ #include #include -/** @brief Install certificates into Windows store + +#include + +/** @brief Access the Windows certificate store * - * @param [in] to_install NULL terminated array of base64 encoded certificates. + * @param [in] to_install strv of DER encoded certificates to be added. + * @param [in] to_remove strv of DER encoded certificates to be remvoed. * @param [in] user_store set to True if the certificates should be installed * only for the current user. O for system wide installation. * @returns 0 on success an errorcode otherwise. */ -int install_certificates_win(const char **to_install, int user_store) +int write_stores_win (char **to_install, char **to_remove, + bool user_store); #endif // WINDOWSSTORE_H #endif // WIN32