refactor(e2ee): reduce unsafe spread

This commit is contained in:
Friedel Ziegelmayer
2019-09-28 13:20:33 -06:00
committed by GitHub
parent ca76cac314
commit 34b3ddf63b
7 changed files with 425 additions and 392 deletions

View File

@@ -610,7 +610,7 @@ unsafe fn add_parts(
let icnt = mime_parser.parts.len();
let mut txt_raw = None;
let is_ok = context
context
.sql
.prepare(
"INSERT INTO msgs \
@@ -697,13 +697,10 @@ unsafe fn add_parts(
Ok(())
},
)
.is_ok();
if !is_ok {
// i/o error - there is nothing more we can do - in other cases, we try to write at least an empty record
cleanup(mime_in_reply_to, mime_references);
bail!("Cannot write DB.");
}
.map_err(|err| {
cleanup(mime_in_reply_to, mime_references);
err
})?;
info!(
context,
@@ -1609,10 +1606,7 @@ fn check_verified_properties(
) -> Result<()> {
let contact = Contact::load_from_db(context, from_id)?;
ensure!(
mimeparser.e2ee_helper.encrypted,
"This message is not encrypted."
);
ensure!(mimeparser.encrypted, "This message is not encrypted.");
// ensure, the contact is verified
// and the message is signed with a verified key of the sender.
@@ -1633,7 +1627,7 @@ fn check_verified_properties(
if let Some(peerstate) = peerstate {
ensure!(
peerstate.has_verified_key(&mimeparser.e2ee_helper.signatures),
peerstate.has_verified_key(&mimeparser.signatures),
"The message was sent with non-verified encryption."
);
}
@@ -1660,7 +1654,7 @@ fn check_verified_properties(
let mut peerstate = Peerstate::from_addr(context, &context.sql, &to_addr);
// mark gossiped keys (if any) as verified
if mimeparser.e2ee_helper.gossipped_addr.contains(&to_addr) && peerstate.is_some() {
if mimeparser.gossipped_addr.contains(&to_addr) && peerstate.is_some() {
let peerstate = peerstate.as_mut().unwrap();
// if we're here, we know the gossip key is verified: