diff -r 3e4c0285a868 -r dc3d70848c7c libidav/methods.c --- a/libidav/methods.c Fri Jul 12 16:59:08 2019 +0200 +++ b/libidav/methods.c Sun Jul 28 13:07:53 2019 +0200 @@ -135,6 +135,22 @@ return buf; } +UcxBuffer* create_cryptoprop_propfind_request(void) { + UcxBuffer *buf = ucx_buffer_new(NULL, 256, UCX_BUFFER_AUTOFREE); + scstr_t s; + + s = SC("\n"); + ucx_buffer_write(s.ptr, 1, s.length, buf); + + s = SC("\n"); + ucx_buffer_write(s.ptr, 1, s.length, buf); + + s = SC("\n"); + ucx_buffer_write(s.ptr, 1, s.length, buf); + + return buf; +} + UcxBuffer* create_propfind_request(DavSession *sn, UcxList *properties, char *rootelm, DavBool nocrypt) { UcxBuffer *buf = ucx_buffer_new(NULL, 512, UCX_BUFFER_AUTOEXTEND); sstr_t s; @@ -534,10 +550,35 @@ void add_properties(DavResource *res, ResponseTag *response) { res->iscollection = response->iscollection; + int decrypt_props = DAV_ENCRYPT_PROPERTIES(res->session); + xmlNode *crypto_prop = NULL; + char *crypto_key = NULL; + // add properties UCX_FOREACH(elm, response->properties) { xmlNode *prop = elm->data; resource_add_property(res, (char*)prop->ns->href, (char*)prop->name, prop->children); + + if (decrypt_props && + prop->children && + prop->children->type == XML_TEXT_NODE && + xstreq(prop->ns->href, DAV_NS)) + { + if(xstreq(prop->name, "crypto-prop")) { + crypto_prop = prop; + } else if(xstreq(prop->name, "crypto-key")) { + crypto_key = util_xml_get_text(prop); + } + } + } + + if(crypto_prop && crypto_key) { + char *crypto_prop_content = util_xml_get_text(crypto_prop); + DavKey *key = dav_context_get_key(res->session->context, crypto_key); + if(crypto_prop_content) { + UcxMap *cprops = parse_crypto_prop_str(res->session, key, crypto_prop_content); + resource_set_crypto_properties(res, cprops); + } } set_davprops(res); @@ -667,12 +708,35 @@ res->iscollection = iscollection; // add properties + int decrypt_props = DAV_ENCRYPT_PROPERTIES(res->session); + xmlNode *crypto_prop = NULL; + UCX_FOREACH(elm, properties) { xmlNode *prop = elm->data; resource_add_property(res, (char*)prop->ns->href, (char*)prop->name, prop->children); + + if (decrypt_props && + prop->children && + prop->children->type == XML_TEXT_NODE && + xstreq(prop->ns->href, DAV_NS)) + { + if(xstreq(prop->name, "crypto-prop")) { + crypto_prop = prop; + } + } } ucx_list_free(properties); + if(crypto_prop && crypto_key) { + char *crypto_prop_content = util_xml_get_text(crypto_prop); + DavKey *key = dav_context_get_key(res->session->context, crypto_key); + if(crypto_prop_content && key) { + UcxMap *cprops = parse_crypto_prop_str(res->session, key, crypto_prop_content); + resource_set_crypto_properties(res, cprops); + } + } + + set_davprops(res); if(res != resource) { resource_add_child(resource, res);