76 PWDS_MAGIC(p) = PWDS_MAGIC_CHAR; |
76 PWDS_MAGIC(p) = PWDS_MAGIC_CHAR; |
77 PWDS_VERSION(p) = 1; |
77 PWDS_VERSION(p) = 1; |
78 PWDS_ENC(p) = DAV_KEY_AES256; |
78 PWDS_ENC(p) = DAV_KEY_AES256; |
79 PWDS_PWFUNC(p) = DAV_PWFUNC_PBKDF2_SHA256; |
79 PWDS_PWFUNC(p) = DAV_PWFUNC_PBKDF2_SHA256; |
80 dav_rand_bytes(p->content->space+4, 16); |
80 dav_rand_bytes(p->content->space+4, 16); |
|
81 p->isdecrypted = 1; |
|
82 p->encoffset = PWDS_HEADER_SIZE; |
81 return p; |
83 return p; |
82 } |
84 } |
83 |
85 |
84 static int readval(UcxBuffer *in, char **val, int allowzero) { |
86 static int readval(UcxBuffer *in, char **val, int allowzero) { |
85 *val = NULL; |
87 *val = NULL; |
116 char *password = NULL; |
118 char *password = NULL; |
117 |
119 |
118 int res = 0; |
120 int res = 0; |
119 if((res += readval(in, &id, FALSE)) == 1) { |
121 if((res += readval(in, &id, FALSE)) == 1) { |
120 if((res += readval(in, &location, TRUE)) == 2) { |
122 if((res += readval(in, &location, TRUE)) == 2) { |
121 if((res += readval(in, &user, FALSE)) == 3) { |
123 if(!index) { |
122 res += readval(in, &password, FALSE); |
124 if((res += readval(in, &user, FALSE)) == 3) { |
|
125 res += readval(in, &password, FALSE); |
|
126 } |
123 } |
127 } |
124 } |
128 } |
125 } |
129 } |
126 |
130 |
127 int ret = 0; |
131 int ret = 0; |
204 void pwdstore_encsettings(PwdStore *p, uint8_t enc, uint8_t pwfunc) { |
211 void pwdstore_encsettings(PwdStore *p, uint8_t enc, uint8_t pwfunc) { |
205 PWDS_ENC(p) = enc; |
212 PWDS_ENC(p) = enc; |
206 PWDS_PWFUNC(p) = pwfunc; |
213 PWDS_PWFUNC(p) = pwfunc; |
207 } |
214 } |
208 |
215 |
209 static void free_entry(PwdEntry *e) { |
216 void pwdstore_free_entry(PwdEntry *e) { |
210 if(e->id) free(e->id); |
217 if(e->id) free(e->id); |
211 if(e->location) free(e->location); |
218 if(e->location) free(e->location); |
212 if(e->user) free(e->user); |
219 if(e->user) free(e->user); |
213 if(e->password) free(e->password); |
220 if(e->password) free(e->password); |
214 free(e); |
221 free(e); |
215 } |
222 } |
216 |
223 |
217 void pwdstore_free(PwdStore* p) { |
224 void pwdstore_free(PwdStore* p) { |
218 ucx_map_free_content(p->ids, (ucx_destructor)free_entry); |
225 ucx_map_free_content(p->ids, (ucx_destructor)pwdstore_free_entry); |
219 ucx_map_free(p->ids); |
226 ucx_map_free(p->ids); |
220 |
227 |
221 ucx_list_free(p->locations); |
228 ucx_list_free(p->locations); |
222 |
229 |
223 if(p->content) { |
230 if(p->content) { |
266 UcxBuffer *content = ucx_buffer_new(NULL, 2048, UCX_BUFFER_AUTOEXTEND); |
273 UcxBuffer *content = ucx_buffer_new(NULL, 2048, UCX_BUFFER_AUTOEXTEND); |
267 |
274 |
268 UcxMapIterator i = ucx_map_iterator(p->ids); |
275 UcxMapIterator i = ucx_map_iterator(p->ids); |
269 PwdEntry *value; |
276 PwdEntry *value; |
270 UCX_MAP_FOREACH(key, value, i) { |
277 UCX_MAP_FOREACH(key, value, i) { |
|
278 if(!value->id || !value->user || !value->password) { |
|
279 continue; |
|
280 } |
|
281 |
271 uint32_t idlen = strlen(value->id); |
282 uint32_t idlen = strlen(value->id); |
272 uint32_t locationlen = value->location ? strlen(value->location) : 0; |
283 uint32_t locationlen = value->location ? strlen(value->location) : 0; |
273 uint32_t ulen = strlen(value->user); |
284 uint32_t ulen = strlen(value->user); |
274 uint32_t plen = strlen(value->password); |
285 uint32_t plen = strlen(value->password); |
275 uint32_t netidlen = htonl(idlen); |
286 uint32_t netidlen = htonl(idlen); |