#include "sasl_thread.hpp" #include #include #include "connection.hpp" #include "write_irc.hpp" #include "irc_parse_thread.hpp" #include "ircmsg.hpp" auto SaslThread::start(Connection& connection) -> std::shared_ptr { auto thread = std::make_shared(connection); connection.add_listener([thread](IrcMsgEvent const& event){ if (event.command == IrcCommand::AUTHENTICATE) { thread->on_authenticate(event.irc.args[0]); } }); return thread; } auto SaslThread::on_authenticate(std::string_view chunk) -> void { if (chunk != "+") { buffer_ += chunk; } if (chunk.size() != 400) { std::string decoded; decoded.resize(mybase64::decoded_size(buffer_.size())); std::size_t len; if (mybase64::decode(buffer_, decoded.data(), &len)) { decoded.resize(len); connection_.make_event(std::move(decoded)); } else { BOOST_LOG_TRIVIAL(debug) << "Invalid AUTHENTICATE base64"; send_authenticate(connection_, "*"); // abort SASL } buffer_.clear(); } else if (buffer_.size() > MAX_BUFFER) { BOOST_LOG_TRIVIAL(debug) << "AUTHENTICATE buffer overflow"; buffer_.clear(); send_authenticate(connection_, "*"); // abort SASL } }