diff --git a/xmpp/ChangeLog b/xmpp/ChangeLog index 3ae141434d298c8438af82805a573f9cbe5ed317..1a7c673ea9140ee73526bdd5ab3c058fd37484f4 100644 --- a/xmpp/ChangeLog +++ b/xmpp/ChangeLog @@ -32,6 +32,8 @@ XXXX-YY-ZZ [ RELEASER ] - Event::ChatMessageCorrection, Event::RoomMessageCorrection, and Event::RoomPrivateMessageCorrection signal XEP-0308 message corrections; they're not checked how old the corrected entry is, which has security concerns (!496) + - Event::AuthConfirm and Event::AuthReject signal XEP-0070 authentication requests and + responses. - Agent::new helper method. - Handle SIGINT, SIGTERM and SIGKILL in hello_bot example to avoid leaving hibernating resources around. diff --git a/xmpp/src/event.rs b/xmpp/src/event.rs index e54aacf9eb21be937904f4487c41a9738dae5b69..53edf226973ed58766c8929db5f6dd393ec2142c 100644 --- a/xmpp/src/event.rs +++ b/xmpp/src/event.rs @@ -9,6 +9,7 @@ use tokio_xmpp::jid::BareJid; use tokio_xmpp::jid::Jid; use tokio_xmpp::parsers::roster::Item as RosterItem; +use crate::parsers::confirm::Confirm; use crate::{delay::StanzaTimeInfo, Error, MessageId, RoomNick}; /// An Event notifying the client something has happened that may require attention. @@ -56,6 +57,16 @@ pub enum Event { /// - The [`String`] is the new body of the message, to replace the old one. /// - The [`StanzaTimeInfo`] is the time the message correction was sent/received ChatMessageCorrection(MessageId, BareJid, String, StanzaTimeInfo), + /// A XEP-0070 authentication request or confirmation was received. + /// - The [`BareJid`] is the sender's JID. + /// - The [`Confirm`] is the info about the authentication request. + /// - The [`StanzaTimeInfo`] about when message was received, and when the message was claimed sent. + AuthConfirm(BareJid, Confirm, StanzaTimeInfo), + /// A XEP-0070 authentication rejection was received. + /// - The [`BareJid`] is the sender's JID. + /// - The [`Confirm`] is the info about the authentication request that was rejected. + /// - The [`StanzaTimeInfo`] about when message was received, and when the message was claimed sent. + AuthReject(BareJid, Confirm, StanzaTimeInfo), /// Room joined; client may receive and send messages from/to this BareJid. RoomJoined(BareJid), /// Room left; client may not receive and send messages from/to this BareJid diff --git a/xmpp/src/message/receive/chat.rs b/xmpp/src/message/receive/chat.rs index 5614d62e0bd9c634e2b320af50d961c9cd56f9d1..49c542f652fbfc55e3b5ea221882045f1bd2780e 100644 --- a/xmpp/src/message/receive/chat.rs +++ b/xmpp/src/message/receive/chat.rs @@ -6,7 +6,7 @@ use tokio_xmpp::{ jid::Jid, - parsers::{message::Message, message_correct::Replace, muc::user::MucUser}, + parsers::{confirm::Confirm, message::Message, message_correct::Replace, muc::user::MucUser}, }; use crate::{delay::StanzaTimeInfo, Agent, Event, RoomNick}; @@ -27,6 +27,7 @@ pub async fn handle_message_chat( let is_muc_pm = message.extract_valid_payload::().is_some(); let correction = message.extract_valid_payload::(); + let confirm = message.extract_valid_payload::(); if is_muc_pm { if from.resource().is_none() { @@ -57,9 +58,24 @@ pub async fn handle_message_chat( let event = if let Some(correction) = correction { // TODO: Check that correction is valid (only for last N minutes or last N messages) Event::ChatMessageCorrection(correction.id, from.to_bare(), body.clone(), time_info) + } else if let Some(confirm) = confirm { + Event::AuthConfirm(from.to_bare(), confirm, time_info) } else { Event::ChatMessage(message.id.clone(), from.to_bare(), body, time_info) }; events.push(event); } } + +pub async fn handle_message_error( + _agent: &mut Agent, + events: &mut Vec, + from: Jid, + message: &mut Message, + time_info: StanzaTimeInfo, +) { + let confirm = message.extract_valid_payload::(); + if let Some(confirm) = confirm { + events.push(Event::AuthReject(from.to_bare(), confirm, time_info)); + } +} diff --git a/xmpp/src/message/receive/mod.rs b/xmpp/src/message/receive/mod.rs index 7861d027595aafe915a9dad721a5e1d3e5593e3f..815f290069b4e61cac2cf1eac53943181eb071a0 100644 --- a/xmpp/src/message/receive/mod.rs +++ b/xmpp/src/message/receive/mod.rs @@ -34,6 +34,10 @@ pub async fn handle_message(agent: &mut Agent, mut message: Message) -> Vec { + chat::handle_message_error(agent, &mut events, from.clone(), &mut message, time_info) + .await; + } _ => {} }