text stringlengths 0 357 |
|---|
struct mailimf_field* field = mailimf_find_field(imffields, MAILIMF_FIELD_FROM); |
if (field && field->fld_data.fld_from) { |
from = mailimf_find_first_addr(field->fld_data.fld_from->frm_mb_list); |
} |
field = mailimf_find_field(imffields, MAILIMF_FIELD_ORIG_DATE); |
if (field && field->fld_data.fld_orig_date) { |
struct mailimf_orig_date* orig_date = field->fld_data.fld_orig_date; |
if (orig_date) { |
message_time = dc_timestamp_from_date(orig_date->dt_date_time); /* is not yet checked against bad times! */ |
if (message_time!=DC_INVALID_TIMESTAMP && message_time > time(NULL)) { |
message_time = time(NULL); |
} |
} |
} |
} |
autocryptheader = dc_aheader_new_from_imffields(from, imffields); |
if (autocryptheader) { |
if (!dc_pgp_is_valid_key(context, autocryptheader->public_key)) { |
dc_aheader_unref(autocryptheader); |
autocryptheader = NULL; |
} |
} |
/* modify the peerstate (eg. if there is a peer but not autocrypt header, stop encryption) */ |
/* apply Autocrypt:-header */ |
if (message_time > 0 |
&& from) |
{ |
if (dc_apeerstate_load_by_addr(peerstate, context->sql, from)) { |
if (autocryptheader) { |
dc_apeerstate_apply_header(peerstate, autocryptheader, message_time); |
dc_apeerstate_save_to_db(peerstate, context->sql, 0/*no not create*/); |
} |
else { |
if (message_time > peerstate->last_seen_autocrypt |
&& !contains_report(in_out_message) /*reports are ususally not encrpyted; do not degrade decryption then*/){ |
dc_apeerstate_degrade_encryption(peerstate, message_time); |
dc_apeerstate_save_to_db(peerstate, context->sql, 0/*no not create*/); |
} |
} |
} |
else if (autocryptheader) { |
dc_apeerstate_init_from_header(peerstate, autocryptheader, message_time); |
dc_apeerstate_save_to_db(peerstate, context->sql, 1/*create*/); |
} |
} |
/* load private key for decryption */ |
if ((self_addr=dc_sqlite3_get_config(context->sql, "configured_addr", NULL))==NULL) { |
goto cleanup; |
} |
if (!dc_keyring_load_self_private_for_decrypting(private_keyring, self_addr, context->sql)) { |
goto cleanup; |
} |
/* if not yet done, load peer with public key for verification (should be last as the peer may be modified above) */ |
if (peerstate->last_seen==0) { |
dc_apeerstate_load_by_addr(peerstate, context->sql, from); |
} |
if (peerstate->degrade_event) { |
dc_handle_degrade_event(context, peerstate); |
} |
// offer both, gossip and public, for signature validation. |
// the caller may check the signature fingerprints as needed later. |
dc_keyring_add(public_keyring_for_validate, peerstate->gossip_key); |
dc_keyring_add(public_keyring_for_validate, peerstate->public_key); |
/* finally, decrypt. If sth. was decrypted, decrypt_recursive() returns "true" and we start over to decrypt maybe just added parts. */ |
helper->signatures = malloc(sizeof(dc_hash_t)); |
dc_hash_init(helper->signatures, DC_HASH_STRING, 1/*copy key*/); |
int iterations = 0; |
while (iterations < 10) { |
int has_unencrypted_parts = 0; |
if (!decrypt_recursive(context, in_out_message, private_keyring, |
public_keyring_for_validate, |
helper->signatures, &gossip_headers, &has_unencrypted_parts)) { |
break; |
} |
// if we're here, sth. was encrypted. if we're on top-level, and there are no |
// additional unencrypted parts in the message the encryption was fine |
// (signature is handled separately and returned as `signatures`) |
if (iterations==0 |
&& !has_unencrypted_parts) { |
helper->encrypted = 1; |
} |
iterations++; |
} |
/* check for Autocrypt-Gossip */ |
if (gossip_headers) { |
helper->gossipped_addr = update_gossip_peerstates(context, message_time, imffields, gossip_headers); |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.