mirror of
https://github.com/chatmail/core.git
synced 2026-05-03 05:16:28 +03:00
Split ForcePlaintext param into two booleans
This allows to send encrypted messages without Autocrypt header.
This commit is contained in:
committed by
link2xt
parent
6fcc589655
commit
f657b2950c
@@ -842,12 +842,10 @@ impl Chat {
|
|||||||
/* check if we want to encrypt this message. If yes and circumstances change
|
/* check if we want to encrypt this message. If yes and circumstances change
|
||||||
so that E2EE is no longer available at a later point (reset, changed settings),
|
so that E2EE is no longer available at a later point (reset, changed settings),
|
||||||
we might not send the message out at all */
|
we might not send the message out at all */
|
||||||
if msg
|
if !msg
|
||||||
.param
|
.param
|
||||||
.get_int(Param::ForcePlaintext)
|
.get_bool(Param::ForcePlaintext)
|
||||||
.and_then::<ForcePlaintext, _>(num_traits::FromPrimitive::from_i32)
|
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
== ForcePlaintext::Dont
|
|
||||||
{
|
{
|
||||||
let mut can_encrypt = true;
|
let mut can_encrypt = true;
|
||||||
let mut all_mutual = context.get_config_bool(Config::E2eeEnabled).await;
|
let mut all_mutual = context.get_config_bool(Config::E2eeEnabled).await;
|
||||||
|
|||||||
@@ -220,10 +220,8 @@ async fn do_initiate_key_transfer(context: &Context) -> Result<String> {
|
|||||||
msg.param
|
msg.param
|
||||||
.set(Param::MimeType, "application/autocrypt-setup");
|
.set(Param::MimeType, "application/autocrypt-setup");
|
||||||
msg.param.set_cmd(SystemMessage::AutocryptSetupMessage);
|
msg.param.set_cmd(SystemMessage::AutocryptSetupMessage);
|
||||||
msg.param.set_int(
|
msg.param.set_int(Param::ForcePlaintext, 1);
|
||||||
Param::ForcePlaintext,
|
msg.param.set_int(Param::SkipAutocrypt, 1);
|
||||||
ForcePlaintext::NoAutocryptHeader as i32,
|
|
||||||
);
|
|
||||||
|
|
||||||
let msg_id = chat::send_msg(context, chat_id, &mut msg).await?;
|
let msg_id = chat::send_msg(context, chat_id, &mut msg).await?;
|
||||||
info!(context, "Wait for setup message being sent ...",);
|
info!(context, "Wait for setup message being sent ...",);
|
||||||
|
|||||||
@@ -237,23 +237,16 @@ impl<'a, 'b> MimeFactory<'a, 'b> {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
let force_plaintext: ForcePlaintext = self
|
!self
|
||||||
.msg
|
.msg
|
||||||
.param
|
.param
|
||||||
.get_int(Param::ForcePlaintext)
|
.get_bool(Param::ForcePlaintext)
|
||||||
.and_then(num_traits::FromPrimitive::from_i32)
|
.unwrap_or_default()
|
||||||
.unwrap_or_default();
|
&& self
|
||||||
|
|
||||||
if force_plaintext == ForcePlaintext::Dont {
|
|
||||||
return self
|
|
||||||
.msg
|
.msg
|
||||||
.param
|
.param
|
||||||
.get_int(Param::GuaranteeE2ee)
|
.get_bool(Param::GuaranteeE2ee)
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
!= 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
false
|
|
||||||
}
|
}
|
||||||
Loaded::MDN { .. } => false,
|
Loaded::MDN { .. } => false,
|
||||||
}
|
}
|
||||||
@@ -272,20 +265,30 @@ impl<'a, 'b> MimeFactory<'a, 'b> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn should_force_plaintext(&self) -> ForcePlaintext {
|
fn should_force_plaintext(&self) -> bool {
|
||||||
match &self.loaded {
|
match &self.loaded {
|
||||||
Loaded::Message { chat } => {
|
Loaded::Message { chat } => {
|
||||||
if chat.typ == Chattype::VerifiedGroup {
|
if chat.typ == Chattype::VerifiedGroup {
|
||||||
ForcePlaintext::Dont
|
false
|
||||||
} else {
|
} else {
|
||||||
self.msg
|
self.msg
|
||||||
.param
|
.param
|
||||||
.get_int(Param::ForcePlaintext)
|
.get_bool(Param::ForcePlaintext)
|
||||||
.and_then(num_traits::FromPrimitive::from_i32)
|
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loaded::MDN { .. } => ForcePlaintext::NoAutocryptHeader,
|
Loaded::MDN { .. } => true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn should_skip_autocrypt(&self) -> bool {
|
||||||
|
match &self.loaded {
|
||||||
|
Loaded::Message { .. } => self
|
||||||
|
.msg
|
||||||
|
.param
|
||||||
|
.get_bool(Param::SkipAutocrypt)
|
||||||
|
.unwrap_or_default(),
|
||||||
|
Loaded::MDN { .. } => true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -478,6 +481,7 @@ impl<'a, 'b> MimeFactory<'a, 'b> {
|
|||||||
let min_verified = self.min_verified();
|
let min_verified = self.min_verified();
|
||||||
let grpimage = self.grpimage();
|
let grpimage = self.grpimage();
|
||||||
let force_plaintext = self.should_force_plaintext();
|
let force_plaintext = self.should_force_plaintext();
|
||||||
|
let skip_autocrypt = self.should_skip_autocrypt();
|
||||||
let subject_str = self.subject_str().await;
|
let subject_str = self.subject_str().await;
|
||||||
let e2ee_guaranteed = self.is_e2ee_guaranteed();
|
let e2ee_guaranteed = self.is_e2ee_guaranteed();
|
||||||
let encrypt_helper = EncryptHelper::new(self.context).await?;
|
let encrypt_helper = EncryptHelper::new(self.context).await?;
|
||||||
@@ -501,7 +505,7 @@ impl<'a, 'b> MimeFactory<'a, 'b> {
|
|||||||
Loaded::MDN { .. } => self.render_mdn().await?,
|
Loaded::MDN { .. } => self.render_mdn().await?,
|
||||||
};
|
};
|
||||||
|
|
||||||
if force_plaintext != ForcePlaintext::NoAutocryptHeader {
|
if !skip_autocrypt {
|
||||||
// unless determined otherwise we add the Autocrypt header
|
// unless determined otherwise we add the Autocrypt header
|
||||||
let aheader = encrypt_helper.get_aheader().to_string();
|
let aheader = encrypt_helper.get_aheader().to_string();
|
||||||
unprotected_headers.push(Header::new("Autocrypt".into(), aheader));
|
unprotected_headers.push(Header::new("Autocrypt".into(), aheader));
|
||||||
@@ -512,7 +516,7 @@ impl<'a, 'b> MimeFactory<'a, 'b> {
|
|||||||
let peerstates = self.peerstates_for_recipients().await?;
|
let peerstates = self.peerstates_for_recipients().await?;
|
||||||
let should_encrypt =
|
let should_encrypt =
|
||||||
encrypt_helper.should_encrypt(self.context, e2ee_guaranteed, &peerstates)?;
|
encrypt_helper.should_encrypt(self.context, e2ee_guaranteed, &peerstates)?;
|
||||||
let is_encrypted = should_encrypt && force_plaintext == ForcePlaintext::Dont;
|
let is_encrypted = should_encrypt && !force_plaintext;
|
||||||
|
|
||||||
let rfc724_mid = match self.loaded {
|
let rfc724_mid = match self.loaded {
|
||||||
Loaded::Message { .. } => self.msg.rfc724_mid.clone(),
|
Loaded::Message { .. } => self.msg.rfc724_mid.clone(),
|
||||||
|
|||||||
29
src/param.rs
29
src/param.rs
@@ -43,6 +43,9 @@ pub enum Param {
|
|||||||
/// For Messages: force unencrypted message, a value from `ForcePlaintext` enum.
|
/// For Messages: force unencrypted message, a value from `ForcePlaintext` enum.
|
||||||
ForcePlaintext = b'u',
|
ForcePlaintext = b'u',
|
||||||
|
|
||||||
|
/// For Messages: do not include Autocrypt header.
|
||||||
|
SkipAutocrypt = b'o',
|
||||||
|
|
||||||
/// For Messages
|
/// For Messages
|
||||||
WantsMdn = b'r',
|
WantsMdn = b'r',
|
||||||
|
|
||||||
@@ -127,32 +130,6 @@ pub enum Param {
|
|||||||
MsgId = b'I',
|
MsgId = b'I',
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Possible values for `Param::ForcePlaintext`.
|
|
||||||
#[derive(PartialEq, Eq, Debug, Clone, Copy, FromPrimitive)]
|
|
||||||
#[repr(u8)]
|
|
||||||
pub enum ForcePlaintext {
|
|
||||||
/// Do not force plaintext
|
|
||||||
Dont = 0,
|
|
||||||
|
|
||||||
/// Force plaintext message with Autocrypt header
|
|
||||||
///
|
|
||||||
/// Used for `vc-request` and `vg-request` messages in
|
|
||||||
/// Verified Contact Protocol and
|
|
||||||
/// Verified Group Protocol.
|
|
||||||
AddAutocryptHeader = 1,
|
|
||||||
|
|
||||||
/// Force plaintext message without Autocrypt header
|
|
||||||
///
|
|
||||||
/// Used for MDNs.
|
|
||||||
NoAutocryptHeader = 2,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for ForcePlaintext {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self::Dont
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// An object for handling key=value parameter lists.
|
/// An object for handling key=value parameter lists.
|
||||||
///
|
///
|
||||||
/// The structure is serialized by calling `to_string()` on it.
|
/// The structure is serialized by calling `to_string()` on it.
|
||||||
|
|||||||
@@ -409,10 +409,7 @@ async fn send_handshake_msg(
|
|||||||
msg.param.set(Param::Arg4, grpid.as_ref());
|
msg.param.set(Param::Arg4, grpid.as_ref());
|
||||||
}
|
}
|
||||||
if step == "vg-request" || step == "vc-request" {
|
if step == "vg-request" || step == "vc-request" {
|
||||||
msg.param.set_int(
|
msg.param.set_int(Param::ForcePlaintext, 1);
|
||||||
Param::ForcePlaintext,
|
|
||||||
ForcePlaintext::AddAutocryptHeader as i32,
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
msg.param.set_int(Param::GuaranteeE2ee, 1);
|
msg.param.set_int(Param::GuaranteeE2ee, 1);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user