removed password keys

Mon, 21 Mar 2016 13:56:16 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Mon, 21 Mar 2016 13:56:16 +0100
changeset 228
c0175372c35d
parent 227
bf485439222a
child 229
df158262f802

removed password keys

dav/config.c file | annotate | diff | comparison | revisions
dav/config.h file | annotate | diff | comparison | revisions
dav/main.c file | annotate | diff | comparison | revisions
dav/sync.c file | annotate | diff | comparison | revisions
libidav/utils.c file | annotate | diff | comparison | revisions
libidav/utils.h file | annotate | diff | comparison | revisions
libidav/webdav.c file | annotate | diff | comparison | revisions
libidav/webdav.h file | annotate | diff | comparison | revisions
--- a/dav/config.c	Sun Mar 20 16:13:41 2016 +0100
+++ b/dav/config.c	Mon Mar 21 13:56:16 2016 +0100
@@ -361,8 +361,9 @@
                     key->type = KEY_AES128;
                 } else if(!strcmp(value, "aes256")) {
                     key->type = KEY_AES256;
-                } else if(!strcmp(value, "password")) {
-                    key->type = KEY_PASSWORD;
+                } else {
+                    fprintf(stderr, "Error: unknown key type %s\n", value);
+                    error = 1;
                 }
             }
                 
@@ -394,14 +395,6 @@
             }
             key->length = 32;
         }
-        if(key->type == KEY_PASSWORD) {
-            key->length = 0;
-            if(key->data) {
-                // make sure the pw-key is not loaded from a file
-                free(key->data);
-                key->data = NULL;
-            }
-        }
         
         // add key to context
         if(!error) {
--- a/dav/config.h	Sun Mar 20 16:13:41 2016 +0100
+++ b/dav/config.h	Mon Mar 21 13:56:16 2016 +0100
@@ -47,7 +47,6 @@
 enum key_type {
     KEY_AES128 = 0,
     KEY_AES256,
-    KEY_PASSWORD
 };
 
 typedef enum key_type KeyType;
--- a/dav/main.c	Sun Mar 20 16:13:41 2016 +0100
+++ b/dav/main.c	Mon Mar 21 13:56:16 2016 +0100
@@ -94,11 +94,6 @@
         return -1;
     }
     
-    if(cmd_getoption(args, "noinput")) {
-        ctx->key_input = NULL;
-    } else {
-        ctx->key_input = util_key_input;
-    }
     
     int ret = -1;
     if(!strcasecmp(cmd, "list") || !strcasecmp(cmd, "ls")) {
--- a/dav/sync.c	Sun Mar 20 16:13:41 2016 +0100
+++ b/dav/sync.c	Mon Mar 21 13:56:16 2016 +0100
@@ -82,7 +82,6 @@
         xmlGenericErrorFunc fnc = xmlerrorfnc;
         initGenericErrorDefaultFunc(&fnc);
         ctx = dav_context_new();
-        ctx->key_input = util_key_input;
         load_config(ctx);
 
         // copy proxy config
--- a/libidav/utils.c	Sun Mar 20 16:13:41 2016 +0100
+++ b/libidav/utils.c	Mon Mar 21 13:56:16 2016 +0100
@@ -661,30 +661,6 @@
     return str;
 }
 
-void util_generate_key(DavKey *key, char *password) {
-    key->data = malloc(SHA256_DIGEST_LENGTH);
-    key->length = SHA256_DIGEST_LENGTH;
-    key->type =  DAV_KEY_AES256;
-#ifdef __sun
-    SHA256_CTX sha256;
-    SHA256Init(&sha256);
-    SHA256Update(&sha256, password, strlen(password));
-    SHA256Final(key->data, &sha256);
-#else
-    SHA256_CTX sha256;
-    SHA256_Init(&sha256);
-    SHA256_Update(&sha256, password, strlen(password));
-    SHA256_Final(key->data, &sha256);
-#endif
-}
-
-char* util_key_input(DavContext *ctx, DavKey *key) {
-    sstr_t prompt = ucx_sprintf("Enter password for key (%s): ", key->name);
-    char *password = util_password_input(prompt.ptr);
-    free(prompt.ptr);
-    return password;
-}
-
 
 char* util_hexstr(unsigned char *data, size_t len) {
     size_t buflen = 2*len + 4;
--- a/libidav/utils.h	Sun Mar 20 16:13:41 2016 +0100
+++ b/libidav/utils.h	Mon Mar 21 13:56:16 2016 +0100
@@ -92,9 +92,6 @@
 sstr_t util_readline(FILE *stream);
 char* util_password_input(char *prompt);
 
-void util_generate_key(DavKey *key, char *password);
-char* util_key_input(DavContext *ctx, DavKey *key);
-
 char* util_hexstr(unsigned char *data, size_t len);
 
 #ifdef	__cplusplus
--- a/libidav/webdav.c	Sun Mar 20 16:13:41 2016 +0100
+++ b/libidav/webdav.c	Mon Mar 21 13:56:16 2016 +0100
@@ -184,25 +184,7 @@
 }
 
 DavKey* dav_context_get_key(DavContext *context, char *name) {
-    if(name) {
-        DavKey *key = ucx_map_cstr_get(context->keys, name);
-        if(key && key->type == DAV_KEY_PASSWORD && !key->data) {
-            char *pw = NULL;
-            if(context->key_input && (pw = context->key_input(context, key))) {
-                // generate key
-                util_generate_key(key, pw);
-            } else {
-                // cannot generate key from password
-                key = NULL;
-            }
-            if(pw) {
-                free(pw);
-            }
-        }
-        return key;
-    } else {
-        return NULL;
-    }
+    return ucx_map_cstr_get(context->keys, name);
 }
 
 int dav_add_namespace(DavContext *context, char *prefix, char *name) {
--- a/libidav/webdav.h	Sun Mar 20 16:13:41 2016 +0100
+++ b/libidav/webdav.h	Mon Mar 21 13:56:16 2016 +0100
@@ -135,7 +135,6 @@
     UcxList *sessions;
     DavProxy *http_proxy;
     DavProxy *https_proxy;
-    char* (*key_input)(DavContext *ctx, DavKey *key);
 };
 
 struct DavProxy {
@@ -163,7 +162,6 @@
 
 #define DAV_KEY_AES128     0
 #define DAV_KEY_AES256     1
-#define DAV_KEY_PASSWORD   2
 
 struct DavKey {
     char    *name;

mercurial