🏡 index : ~doyle/titanirc.git

author Jordan Doyle <jordan@doyle.la> 2023-01-08 19:24:21.0 +00:00:00
committer Jordan Doyle <jordan@doyle.la> 2023-01-08 19:25:31.0 +00:00:00
commit
e383b00ff83c99bdf37c3cef37a3bd1da79ef911 [patch]
tree
955fdbb222a46e508406359a6824503627b098bf
parent
adfadc3e367e7c4dd80fb067e582e103e83852aa
download
e383b00ff83c99bdf37c3cef37a3bd1da79ef911.tar.gz

Return an error if a client attempts to authenticate again



Diff

 src/client.rs     |  8 +++++++-
 src/connection.rs | 20 ++++++++++++++++++++
 2 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/src/client.rs b/src/client.rs
index 073ba9d..1d015f6 100644
--- a/src/client.rs
+++ a/src/client.rs
@@ -12,7 +12,7 @@

use crate::{
    channel::Channel,
    connection::{InitiatedConnection, MessageSink},
    connection::{InitiatedConnection, MessageSink, SaslAlreadyAuthenticated},
    messages::{
        Broadcast, ChannelFetchTopic, ChannelInvite, ChannelJoin, ChannelKickUser, ChannelList,
        ChannelMemberList, ChannelMessage, ChannelPart, ChannelUpdateTopic, FetchClientDetails,
@@ -569,7 +569,11 @@
            Command::BOTSERV(_) => {}
            Command::HOSTSERV(_) => {}
            Command::MEMOSERV(_) => {}
            Command::AUTHENTICATE(_) => {}
            Command::AUTHENTICATE(_) => {
                self.writer.write(
                    SaslAlreadyAuthenticated(self.connection.nick.to_string()).into_message(),
                );
            }
            Command::ACCOUNT(_) => {}
            Command::METADATA(_, _, _) => {}
            Command::MONITOR(_, _) => {}
diff --git a/src/connection.rs b/src/connection.rs
index 1c3293c..774ba76 100644
--- a/src/connection.rs
+++ a/src/connection.rs
@@ -343,6 +343,26 @@
    }
}

/// Returned to the client if they try to call AUTHENTICATE again after negotiation.

pub struct SaslAlreadyAuthenticated(pub String);

impl SaslAlreadyAuthenticated {
    #[must_use]
    pub fn into_message(self) -> Message {
        Message {
            tags: None,
            prefix: None,
            command: Command::Response(
                Response::ERR_SASLALREADY,
                vec![
                    self.0,
                    "You have already authenticated using SASL".to_string(),
                ],
            ),
        }
    }
}

/// Returned to the client when an invalid SASL strategy is attempted.

pub struct SaslStrategyUnsupported(String);