text
stringlengths
0
357
}
static dc_hash_t* update_gossip_peerstates(dc_context_t* context, time_t message_time, struct mailimf_fields* imffields, const struct mailimf_fields* gossip_headers)
{
clistiter* cur1 = NULL;
dc_hash_t* recipients = NULL;
dc_hash_t* gossipped_addr = NULL;
for (cur1 = clist_begin(gossip_headers->fld_list); cur1!=NULL ; cur1=clist_next(cur1))
{
struct mailimf_field* field = (struct mailimf_field*)clist_content(cur1);
if (field->fld_type==MAILIMF_FIELD_OPTIONAL_FIELD)
{
const struct mailimf_optional_field* optional_field = field->fld_data.fld_optional_field;
if (optional_field && optional_field->fld_name && strcasecmp(optional_field->fld_name, "Autocrypt-Gossip")==0)
{
dc_aheader_t* gossip_header = dc_aheader_new();
if (dc_aheader_set_from_string(gossip_header, optional_field->fld_value)
&& dc_pgp_is_valid_key(context, gossip_header->public_key))
{
/* found an Autocrypt-Gossip entry, create recipents list and check if addr matches */
if (recipients==NULL) {
recipients = mailimf_get_recipients(imffields);
}
if (dc_hash_find(recipients, gossip_header->addr, strlen(gossip_header->addr)))
{
/* valid recipient: update peerstate */
dc_apeerstate_t* peerstate = dc_apeerstate_new(context);
if (!dc_apeerstate_load_by_addr(peerstate, context->sql, gossip_header->addr)) {
dc_apeerstate_init_from_gossip(peerstate, gossip_header, message_time);
dc_apeerstate_save_to_db(peerstate, context->sql, 1/*create*/);
}
else {
dc_apeerstate_apply_gossip(peerstate, gossip_header, message_time);
dc_apeerstate_save_to_db(peerstate, context->sql, 0/*do not create*/);
}
if (peerstate->degrade_event) {
dc_handle_degrade_event(context, peerstate);
}
dc_apeerstate_unref(peerstate);
// collect all gossipped addresses; we need them later to mark them as being
// verified when used in a verified group by a verified sender
if (gossipped_addr==NULL) {
gossipped_addr = malloc(sizeof(dc_hash_t));
dc_hash_init(gossipped_addr, DC_HASH_STRING, 1/*copy key*/);
}
dc_hash_insert(gossipped_addr, gossip_header->addr, strlen(gossip_header->addr), (void*)1);
}
else
{
dc_log_info(context, 0, "Ignoring gossipped \"%s\" as the address is not in To/Cc list.", gossip_header->addr);
}
}
dc_aheader_unref(gossip_header);
}
}
}
if (recipients) {
dc_hash_clear(recipients);
free(recipients);
}
return gossipped_addr;
}
void dc_e2ee_decrypt(dc_context_t* context, struct mailmime* in_out_message,
dc_e2ee_helper_t* helper)
{
/* return values: 0=nothing to decrypt/cannot decrypt, 1=sth. decrypted
(to detect parts that could not be decrypted, simply look for left "multipart/encrypted" MIME types */
struct mailimf_fields* imffields = mailmime_find_mailimf_fields(in_out_message); /*just a pointer into mailmime structure, must not be freed*/
dc_aheader_t* autocryptheader = NULL;
time_t message_time = 0;
dc_apeerstate_t* peerstate = dc_apeerstate_new(context);
char* from = NULL;
char* self_addr = NULL;
dc_keyring_t* private_keyring = dc_keyring_new();
dc_keyring_t* public_keyring_for_validate = dc_keyring_new();
struct mailimf_fields* gossip_headers = NULL;
if (helper) { memset(helper, 0, sizeof(dc_e2ee_helper_t)); }
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC || in_out_message==NULL
|| helper==NULL || imffields==NULL) {
goto cleanup;
}
/* Autocrypt preparations:
- Set message_time and from (both may be unset)
- Get the autocrypt header, if any.
- Do not abort on errors - we should try at last the decyption below */
if (imffields)
{