56 lines
1.4 KiB
C++
56 lines
1.4 KiB
C++
#include "sasl_thread.hpp"
|
|
|
|
#include <mybase64.hpp>
|
|
|
|
#include <boost/log/trivial.hpp>
|
|
|
|
#include "connection.hpp"
|
|
#include "write_irc.hpp"
|
|
#include "irc_parse_thread.hpp"
|
|
#include "ircmsg.hpp"
|
|
|
|
auto SaslThread::start(Connection& connection) -> std::shared_ptr<SaslThread>
|
|
{
|
|
auto thread = std::make_shared<SaslThread>(connection);
|
|
|
|
connection.add_listener<IrcMsgEvent>([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<SaslMessage>(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
|
|
}
|
|
}
|