base64 encoded passwords in config.xml

Mon, 12 Aug 2013 15:34:40 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Mon, 12 Aug 2013 15:34:40 +0200
changeset 7
d9bdd5a22c1d
parent 6
9c64d2a3d101
child 8
4503498deb22

base64 encoded passwords in config.xml

dav/config.c file | annotate | diff | comparison | revisions
dav/utils.c file | annotate | diff | comparison | revisions
dav/utils.h file | annotate | diff | comparison | revisions
--- a/dav/config.c	Mon Aug 12 14:55:31 2013 +0200
+++ b/dav/config.c	Mon Aug 12 15:34:40 2013 +0200
@@ -90,8 +90,7 @@
             } else if(xstreq(node->name, "user")) {
                 repo->user = strdup(value);
             } else if(xstreq(node->name, "password")) {
-                // TODO: use base64
-                repo->password = strdup(value);
+                repo->password = util_base64decode(value);
             } else if(xstreq(node->name, "default-key")) {
                 repo->default_key = strdup(value);
             } else if(xstreq(node->name, "encrypt")) {
--- a/dav/utils.c	Mon Aug 12 14:55:31 2013 +0200
+++ b/dav/utils.c	Mon Aug 12 15:34:40 2013 +0200
@@ -34,6 +34,12 @@
 #include <libxml/tree.h>
 #include <curl/curl.h>
 
+#include <openssl/sha.h>
+#include <openssl/hmac.h>
+#include <openssl/evp.h>
+#include <openssl/bio.h>
+#include <openssl/buffer.h>
+
 #include "utils.h"
 
 
@@ -150,3 +156,19 @@
     return NULL;
 }
 
+
+
+char* util_base64decode(char* in) {
+    size_t len = strlen(in);
+    char *out = calloc(1, len);
+    
+    BIO* b = BIO_new_mem_buf(in, len);
+    BIO *d = BIO_new(BIO_f_base64());
+    BIO_set_flags(d, BIO_FLAGS_BASE64_NO_NL);
+    b = BIO_push(d, b);
+
+    BIO_read(b, out, len);
+    BIO_free_all(b);
+    
+    return out;
+}
--- a/dav/utils.h	Mon Aug 12 14:55:31 2013 +0200
+++ b/dav/utils.h	Mon Aug 12 15:34:40 2013 +0200
@@ -47,6 +47,8 @@
 
 char* util_xml_get_text(xmlNode *elm);
 
+char* util_base64decode(char* in);
+
 #ifdef	__cplusplus
 }
 #endif

mercurial