--- a/dav/pwd.c Thu Sep 20 13:07:38 2018 +0200 +++ b/dav/pwd.c Thu Sep 20 17:14:55 2018 +0200 @@ -78,6 +78,8 @@ PWDS_ENC(p) = DAV_KEY_AES256; PWDS_PWFUNC(p) = DAV_PWFUNC_PBKDF2_SHA256; dav_rand_bytes(p->content->space+4, 16); + p->isdecrypted = 1; + p->encoffset = PWDS_HEADER_SIZE; return p; } @@ -118,8 +120,10 @@ int res = 0; if((res += readval(in, &id, FALSE)) == 1) { if((res += readval(in, &location, TRUE)) == 2) { - if((res += readval(in, &user, FALSE)) == 3) { - res += readval(in, &password, FALSE); + if(!index) { + if((res += readval(in, &user, FALSE)) == 3) { + res += readval(in, &password, FALSE); + } } } } @@ -167,6 +171,9 @@ if(!p->key) { return 1; } + if(p->isdecrypted) { + return 0; + } // decrypt contet size_t encsz = p->content->size - p->encoffset; @@ -206,7 +213,7 @@ PWDS_PWFUNC(p) = pwfunc; } -static void free_entry(PwdEntry *e) { +void pwdstore_free_entry(PwdEntry *e) { if(e->id) free(e->id); if(e->location) free(e->location); if(e->user) free(e->user); @@ -215,7 +222,7 @@ } void pwdstore_free(PwdStore* p) { - ucx_map_free_content(p->ids, (ucx_destructor)free_entry); + ucx_map_free_content(p->ids, (ucx_destructor)pwdstore_free_entry); ucx_map_free(p->ids); ucx_list_free(p->locations); @@ -237,7 +244,7 @@ PwdEntry* pwdstore_get(PwdStore *p, const char *id) { PwdEntry *e = ucx_map_cstr_get(p->ids, id); - if(e->user && e->password) { + if(e && e->user && e->password) { return e; } else { return NULL; @@ -268,6 +275,10 @@ UcxMapIterator i = ucx_map_iterator(p->ids); PwdEntry *value; UCX_MAP_FOREACH(key, value, i) { + if(!value->id || !value->user || !value->password) { + continue; + } + uint32_t idlen = strlen(value->id); uint32_t locationlen = value->location ? strlen(value->location) : 0; uint32_t ulen = strlen(value->user);