This commit is contained in:
holger krekel
2019-09-28 02:45:28 +02:00
parent 3a16ad89bd
commit ca76cac314
3 changed files with 29 additions and 24 deletions

View File

@@ -336,16 +336,16 @@ impl E2eeHelper {
if let Some(ref mut peerstate) = peerstate { if let Some(ref mut peerstate) = peerstate {
if let Some(ref header) = autocryptheader { if let Some(ref header) = autocryptheader {
peerstate.apply_header(&header, message_time); peerstate.apply_header(&header, message_time);
peerstate.save_to_db(&context.sql, false).unwrap(); peerstate.save_to_db(&context.sql, false)?;
} else if message_time > peerstate.last_seen_autocrypt } else if message_time > peerstate.last_seen_autocrypt
&& !contains_report(in_out_message) && !contains_report(in_out_message)
{ {
peerstate.degrade_encryption(message_time); peerstate.degrade_encryption(message_time);
peerstate.save_to_db(&context.sql, false).unwrap(); peerstate.save_to_db(&context.sql, false)?;
} }
} else if let Some(ref header) = autocryptheader { } else if let Some(ref header) = autocryptheader {
let p = Peerstate::from_header(context, header, message_time); let p = Peerstate::from_header(context, header, message_time);
p.save_to_db(&context.sql, true).unwrap(); p.save_to_db(&context.sql, true)?;
peerstate = Some(p); peerstate = Some(p);
} }
} }
@@ -364,7 +364,7 @@ impl E2eeHelper {
} }
if let Some(ref peerstate) = peerstate { if let Some(ref peerstate) = peerstate {
if peerstate.degrade_event.is_some() { if peerstate.degrade_event.is_some() {
handle_degrade_event(context, &peerstate); handle_degrade_event(context, &peerstate)?;
} }
if let Some(ref key) = peerstate.gossip_key { if let Some(ref key) = peerstate.gossip_key {
public_keyring_for_validate.add_ref(key); public_keyring_for_validate.add_ref(key);
@@ -395,7 +395,7 @@ impl E2eeHelper {
message_time, message_time,
imffields, imffields,
gossip_headers, gossip_headers,
) )?;
} }
} }
} }
@@ -493,7 +493,7 @@ unsafe fn update_gossip_peerstates(
message_time: i64, message_time: i64,
imffields: *mut mailimf_fields, imffields: *mut mailimf_fields,
gossip_headers: *const mailimf_fields, gossip_headers: *const mailimf_fields,
) -> HashSet<String> { ) -> Result<HashSet<String>> {
// XXX split the parsing from the modification part // XXX split the parsing from the modification part
let mut recipients: Option<HashSet<String>> = None; let mut recipients: Option<HashSet<String>> = None;
let mut gossipped_addr: HashSet<String> = Default::default(); let mut gossipped_addr: HashSet<String> = Default::default();
@@ -522,15 +522,15 @@ unsafe fn update_gossip_peerstates(
Peerstate::from_addr(context, &context.sql, &header.addr); Peerstate::from_addr(context, &context.sql, &header.addr);
if let Some(ref mut peerstate) = peerstate { if let Some(ref mut peerstate) = peerstate {
peerstate.apply_gossip(header, message_time); peerstate.apply_gossip(header, message_time);
peerstate.save_to_db(&context.sql, false).unwrap(); peerstate.save_to_db(&context.sql, false)?;
} else { } else {
let p = Peerstate::from_gossip(context, header, message_time); let p = Peerstate::from_gossip(context, header, message_time);
p.save_to_db(&context.sql, true).unwrap(); p.save_to_db(&context.sql, true)?;
peerstate = Some(p); peerstate = Some(p);
} }
if let Some(peerstate) = peerstate { if let Some(peerstate) = peerstate {
if peerstate.degrade_event.is_some() { if peerstate.degrade_event.is_some() {
handle_degrade_event(context, &peerstate); handle_degrade_event(context, &peerstate)?;
} }
} }
@@ -547,7 +547,7 @@ unsafe fn update_gossip_peerstates(
} }
} }
gossipped_addr Ok(gossipped_addr)
} }
fn decrypt_if_autocrypt_message( fn decrypt_if_autocrypt_message(

View File

@@ -718,21 +718,24 @@ fn encrypted_and_signed(mimeparser: &MimeParser, expected_fingerprint: impl AsRe
} }
} }
pub fn handle_degrade_event(context: &Context, peerstate: &Peerstate) { pub fn handle_degrade_event(context: &Context, peerstate: &Peerstate) -> Result<(), Error> {
// - we do not issue an warning for DC_DE_ENCRYPTION_PAUSED as this is quite normal // - we do not issue an warning for DC_DE_ENCRYPTION_PAUSED as this is quite normal
// - currently, we do not issue an extra warning for DC_DE_VERIFICATION_LOST - this always comes // - currently, we do not issue an extra warning for DC_DE_VERIFICATION_LOST - this always comes
// together with DC_DE_FINGERPRINT_CHANGED which is logged, the idea is not to bother // together with DC_DE_FINGERPRINT_CHANGED which is logged, the idea is not to bother
// with things they cannot fix, so the user is just kicked from the verified group // with things they cannot fix, so the user is just kicked from the verified group
// (and he will know this and can fix this) // (and he will know this and can fix this)
if Some(DegradeEvent::FingerprintChanged) == peerstate.degrade_event { if Some(DegradeEvent::FingerprintChanged) == peerstate.degrade_event {
let contact_id: i32 = context let contact_id: i32 = match context.sql.query_get_value(
.sql context,
.query_get_value( "SELECT id FROM contacts WHERE addr=?;",
context, params![&peerstate.addr],
"SELECT id FROM contacts WHERE addr=?;", ) {
params![&peerstate.addr], None => bail!(
) "contact with peerstate.addr {:?} not found",
.unwrap_or_default(); &peerstate.addr
),
Some(contact_id) => contact_id,
};
if contact_id > 0 { if contact_id > 0 {
let (contact_chat_id, _) = let (contact_chat_id, _) =
chat::create_or_lookup_by_contact_id(context, contact_id as u32, Blocked::Deaddrop) chat::create_or_lookup_by_contact_id(context, contact_id as u32, Blocked::Deaddrop)
@@ -748,4 +751,5 @@ pub fn handle_degrade_event(context: &Context, peerstate: &Peerstate) {
emit_event!(context, Event::ChatModified(contact_chat_id)); emit_event!(context, Event::ChatModified(contact_chat_id));
} }
} }
Ok(())
} }

View File

@@ -36,7 +36,6 @@ pub fn get_ct_subtype(mime: *mut Mailmime) -> Option<String> {
let ct: *mut mailmime_content = (*mime).mm_content_type; let ct: *mut mailmime_content = (*mime).mm_content_type;
if !ct.is_null() && !(*ct).ct_subtype.is_null() { if !ct.is_null() && !(*ct).ct_subtype.is_null() {
println!("ct_subtype: {}", to_string((*ct).ct_subtype));
Some(to_string((*ct).ct_subtype)) Some(to_string((*ct).ct_subtype))
} else { } else {
None None
@@ -48,10 +47,12 @@ pub fn get_autocrypt_mime(
mime_undetermined: *mut Mailmime, mime_undetermined: *mut Mailmime,
) -> Result<(*mut Mailmime, *mut Mailmime), Error> { ) -> Result<(*mut Mailmime, *mut Mailmime), Error> {
/* return Result with two mime pointers: /* return Result with two mime pointers:
First mime pointer is to the multipart-mime message
(which is replaced with a decrypted version later) First mime pointer is to the multipart-mime message
Second one is to the encrypted payload. (which is replaced with a decrypted version later)
For non-autocrypt message an Error is returned.
Second one is to the encrypted payload.
For non-autocrypt message an Error is returned.
*/ */
unsafe { unsafe {
ensure!( ensure!(