changeset 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 bf4bfd8843bd
children 4a4b5e640d1a
files cinst/main.c cinst/windowsstore.c cinst/windowsstore.h
diffstat 3 files changed, 26 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- 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 */
--- 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);
     }
--- 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 <windows.h>
 #include <wincrypt.h>
-/** @brief Install certificates into Windows store
+
+#include <stdbool.h>
+
+/** @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

http://wald.intevation.org/projects/trustbridge/