pull sasl config out of registration
This commit is contained in:
parent
7728bc6aee
commit
68429bc1e4
@ -4,6 +4,7 @@
|
|||||||
#include "connection.hpp"
|
#include "connection.hpp"
|
||||||
#include "openssl_utils.hpp"
|
#include "openssl_utils.hpp"
|
||||||
#include "registration.hpp"
|
#include "registration.hpp"
|
||||||
|
#include "sasl_mechanism.hpp"
|
||||||
#include "settings.hpp"
|
#include "settings.hpp"
|
||||||
#include "ref.hpp"
|
#include "ref.hpp"
|
||||||
#include "irc_coroutine.hpp"
|
#include "irc_coroutine.hpp"
|
||||||
@ -15,11 +16,37 @@
|
|||||||
#include <openssl/pem.h>
|
#include <openssl/pem.h>
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
using namespace std::literals;
|
using namespace std::literals;
|
||||||
|
|
||||||
|
auto configure_sasl(const Settings &settings) -> std::unique_ptr<SaslMechanism>
|
||||||
|
{
|
||||||
|
if (settings.sasl_mechanism == "PLAIN" &&
|
||||||
|
not settings.sasl_authcid.empty()
|
||||||
|
) {
|
||||||
|
return std::make_unique<SaslPlain>(
|
||||||
|
settings.sasl_authcid,
|
||||||
|
settings.sasl_authzid,
|
||||||
|
settings.sasl_password);
|
||||||
|
|
||||||
|
} else if (settings.sasl_mechanism == "EXTERNAL") {
|
||||||
|
return std::make_unique<SaslExternal>(settings.sasl_authzid);
|
||||||
|
|
||||||
|
} else if (
|
||||||
|
settings.sasl_mechanism == "ECDSA" &&
|
||||||
|
not settings.sasl_authcid.empty() &&
|
||||||
|
not settings.sasl_key_file.empty()
|
||||||
|
|
||||||
|
) {
|
||||||
|
if (auto sasl_key = key_from_file(settings.sasl_key_file, settings.sasl_key_password))
|
||||||
|
return std::make_unique<SaslEcdsa>(
|
||||||
|
settings.sasl_authcid,
|
||||||
|
settings.sasl_authzid,
|
||||||
|
std::move(sasl_key));
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
static auto start(boost::asio::io_context &io, const Settings &settings) -> void
|
static auto start(boost::asio::io_context &io, const Settings &settings) -> void
|
||||||
{
|
{
|
||||||
@ -35,11 +62,7 @@ static auto start(boost::asio::io_context &io, const Settings &settings) -> void
|
|||||||
tls_key = key_from_file(settings.tls_key_file, settings.tls_key_password);
|
tls_key = key_from_file(settings.tls_key_file, settings.tls_key_password);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<EVP_PKEY> sasl_key;
|
auto sasl_mech = configure_sasl(settings);
|
||||||
if (not settings.sasl_key_file.empty())
|
|
||||||
{
|
|
||||||
sasl_key = key_from_file(settings.sasl_key_file, settings.sasl_key_password);
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto connection = std::make_shared<Connection>(io);
|
const auto connection = std::make_shared<Connection>(io);
|
||||||
const auto client = Client::start(connection);
|
const auto client = Client::start(connection);
|
||||||
@ -48,11 +71,7 @@ static auto start(boost::asio::io_context &io, const Settings &settings) -> void
|
|||||||
.realname = settings.realname,
|
.realname = settings.realname,
|
||||||
.username = settings.username,
|
.username = settings.username,
|
||||||
.password = settings.password,
|
.password = settings.password,
|
||||||
.sasl_mechanism = settings.sasl_mechanism,
|
.sasl_mechanism = std::move(sasl_mech),
|
||||||
.sasl_authcid = settings.sasl_authcid,
|
|
||||||
.sasl_authzid = settings.sasl_authzid,
|
|
||||||
.sasl_password = settings.sasl_password,
|
|
||||||
.sasl_key = std::move(sasl_key),
|
|
||||||
}, client);
|
}, client);
|
||||||
const auto bot = Bot::start(client);
|
const auto bot = Bot::start(client);
|
||||||
|
|
||||||
|
@ -2,12 +2,10 @@
|
|||||||
|
|
||||||
#include "connection.hpp"
|
#include "connection.hpp"
|
||||||
#include "client.hpp"
|
#include "client.hpp"
|
||||||
#include "ref.hpp"
|
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <unordered_set>
|
|
||||||
|
|
||||||
class Registration : public std::enable_shared_from_this<Registration>
|
class Registration : public std::enable_shared_from_this<Registration>
|
||||||
{
|
{
|
||||||
@ -17,11 +15,7 @@ public:
|
|||||||
std::string username;
|
std::string username;
|
||||||
std::string realname;
|
std::string realname;
|
||||||
std::string password;
|
std::string password;
|
||||||
std::string sasl_mechanism;
|
std::unique_ptr<SaslMechanism> sasl_mechanism;
|
||||||
std::string sasl_authcid;
|
|
||||||
std::string sasl_authzid;
|
|
||||||
std::string sasl_password;
|
|
||||||
Ref<EVP_PKEY> sasl_key;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
#include "connection.hpp"
|
#include "connection.hpp"
|
||||||
#include "ircmsg.hpp"
|
#include "ircmsg.hpp"
|
||||||
#include "sasl_mechanism.hpp"
|
|
||||||
#include "openssl_utils.hpp"
|
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <random>
|
#include <random>
|
||||||
@ -71,7 +69,7 @@ auto Registration::on_cap_list(const std::unordered_map<std::string, std::string
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool do_sasl = not settings_.sasl_mechanism.empty() && caps.contains("sasl");
|
bool do_sasl = settings_.sasl_mechanism && caps.contains("sasl");
|
||||||
if (do_sasl) {
|
if (do_sasl) {
|
||||||
request.append("sasl ");
|
request.append("sasl ");
|
||||||
}
|
}
|
||||||
@ -82,19 +80,8 @@ auto Registration::on_cap_list(const std::unordered_map<std::string, std::string
|
|||||||
client_->get_connection().send_cap_req(request);
|
client_->get_connection().send_cap_req(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (do_sasl && settings_.sasl_mechanism == "PLAIN") {
|
if (do_sasl) {
|
||||||
client_->start_sasl(
|
client_->start_sasl(std::move(settings_.sasl_mechanism));
|
||||||
std::make_unique<SaslPlain>(
|
|
||||||
settings_.sasl_authcid,
|
|
||||||
settings_.sasl_authzid,
|
|
||||||
settings_.sasl_password));
|
|
||||||
} else if (do_sasl && settings_.sasl_mechanism == "EXTERNAL") {
|
|
||||||
client_->start_sasl(std::make_unique<SaslExternal>(settings_.sasl_authzid));
|
|
||||||
} else if (do_sasl && settings_.sasl_mechanism == "ECDSA") {
|
|
||||||
client_->start_sasl(std::make_unique<SaslEcdsa>(
|
|
||||||
settings_.sasl_authcid,
|
|
||||||
settings_.sasl_authzid,
|
|
||||||
settings_.sasl_key));
|
|
||||||
} else {
|
} else {
|
||||||
client_->get_connection().send_cap_end();
|
client_->get_connection().send_cap_end();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user