Skip to content

Commit d71f999

Browse files
committed
process Autocrypt
1 parent 6241543 commit d71f999

File tree

5 files changed

+13
-55
lines changed

5 files changed

+13
-55
lines changed

src/contact/contact_tests.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use deltachat_contact_tools::may_be_valid_addr;
33
use super::*;
44
use crate::chat::{get_chat_contacts, send_text_msg, Chat};
55
use crate::chatlist::Chatlist;
6-
use crate::peerstate::Peerstate;
76
use crate::receive_imf::receive_imf;
87
use crate::test_utils::{self, TestContext, TestContextManager, TimeShiftFalsePositiveNote};
98

@@ -1065,12 +1064,8 @@ async fn test_make_n_import_vcard() -> Result<()> {
10651064
let chat = bob.create_chat(alice).await;
10661065
let sent_msg = bob.send_text(chat.id, "moin").await;
10671066
let bob_id = alice.recv_msg(&sent_msg).await.from_id;
1068-
let key_base64 = Peerstate::from_addr(alice, &bob_addr)
1069-
.await?
1070-
.unwrap()
1071-
.peek_key(false)
1072-
.unwrap()
1073-
.to_base64();
1067+
let bob_contact = Contact::get_by_id(alice, bob_id).await?;
1068+
let key_base64 = bob_contact.openpgp_certificate(alice).await?.unwrap().to_base64();
10741069
let fiona_id = Contact::create(alice, "Fiona", "[email protected]").await?;
10751070

10761071
assert_eq!(make_vcard(alice, &[]).await?, "".to_string());

src/decrypt.rs

-46
Original file line numberDiff line numberDiff line change
@@ -143,52 +143,6 @@ pub(crate) fn validate_detached_signature<'a, 'b>(
143143
}
144144
}
145145

146-
/// Applies Autocrypt header to Autocrypt peer state and saves it into the database.
147-
///
148-
/// Returns updated peerstate.
149-
pub(crate) async fn get_autocrypt_peerstate(
150-
context: &Context,
151-
from: &str,
152-
autocrypt_header: Option<&Aheader>,
153-
message_time: i64,
154-
) -> Result<Option<Peerstate>> {
155-
let allow_change = !context.is_self_addr(from).await?;
156-
let mut peerstate;
157-
158-
// Apply Autocrypt header
159-
if let Some(header) = autocrypt_header {
160-
peerstate = Peerstate::from_addr(context, from).await?;
161-
162-
if let Some(ref mut peerstate) = peerstate {
163-
if addr_cmp(&peerstate.addr, from) {
164-
if allow_change {
165-
peerstate.apply_header(context, header, message_time);
166-
peerstate.save_to_db(&context.sql).await?;
167-
} else {
168-
info!(
169-
context,
170-
"Refusing to update existing peerstate of {}", &peerstate.addr
171-
);
172-
}
173-
}
174-
// If `peerstate.addr` and `from` differ, this means that
175-
// someone is using the same key but a different addr, probably
176-
// because they made an AEAP transition.
177-
// But we don't know if that's legit until we checked the
178-
// signatures, so wait until then with writing anything
179-
// to the database.
180-
} else {
181-
let p = Peerstate::from_header(header, message_time);
182-
p.save_to_db(&context.sql).await?;
183-
peerstate = Some(p);
184-
}
185-
} else {
186-
peerstate = Peerstate::from_addr(context, from).await?;
187-
}
188-
189-
Ok(peerstate)
190-
}
191-
192146
#[cfg(test)]
193147
mod tests {
194148
use super::*;

src/mimeparser.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use crate::constants;
2222
use crate::contact::ContactId;
2323
use crate::context::Context;
2424
use crate::decrypt::{
25-
get_autocrypt_peerstate, get_encrypted_mime, try_decrypt, validate_detached_signature,
25+
get_encrypted_mime, try_decrypt, validate_detached_signature,
2626
};
2727
use crate::dehtml::dehtml;
2828
use crate::events::EventType;
@@ -386,6 +386,15 @@ impl MimeMessage {
386386
None
387387
};
388388

389+
if let Some(autocrypt_header) = &autocrypt_header {
390+
let fingerprint = autocrypt_header.public_key.dc_fingerprint().hex();
391+
context.sql.execute("INSERT INTO public_keys (fingerprint, public_key)
392+
VALUES (?, ?)
393+
ON CONFLICT (fingerprint)
394+
DO NOTHING",
395+
(&fingerprint, autocrypt_header.public_key.to_bytes())).await?;
396+
}
397+
389398
let public_keyring = if incoming {
390399
if let Some(autocrypt_header) = autocrypt_header {
391400
vec![autocrypt_header.public_key]

src/receive_imf.rs

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use mailparse::SingleInfo;
1212
use num_traits::FromPrimitive;
1313
use regex::Regex;
1414

15-
use crate::aheader::EncryptPreference;
1615
use crate::chat::{self, Chat, ChatId, ChatIdBlocked, ProtectionStatus};
1716
use crate::config::Config;
1817
use crate::constants::{Blocked, Chattype, ShowEmails, DC_CHAT_ID_TRASH, EDITED_PREFIX};

src/receive_imf/receive_imf_tests.rs

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use crate::chat::{
99
get_chat_msgs, is_contact_in_chat, remove_contact_from_chat, send_text_msg, ChatItem,
1010
ChatVisibility,
1111
};
12+
use crate::aheader::EncryptPreference;
1213
use crate::chatlist::Chatlist;
1314
use crate::constants::{DC_GCL_FOR_FORWARDING, DC_GCL_NO_SPECIALS};
1415
use crate::contact;

0 commit comments

Comments
 (0)