* Allow 9 digits long passcode for passcode bypass * Change name of 'Mobile Passcode' to 'Passcode' * Do not display any prompt when user is waiting * Add autopushPrompt option * Change name OTP method * Change enrolement message handling * Addded postrm script * [bugfix] Restart sshd service after rublon package instalation * Rename 01_rublon_ssh.conf to 01-rublon-ssh.conf * Prepared scripts for generating rpm for alma nad rocky * Adding public key authentication option * Add postinst script and ssh configuration for using pubkey * Add GCC 7 compatybility * Cleanup includes, cleanup std::array usage * Add Static String implementation * Remove memory_resources * Add monotonic_buffer_resource in experimental c++ imlpementation * Use case insensitive map * Remove not needed code * Stop using deprecated SHA256 functions * Changed app verstion to v2.0.4 * Fixed postinst script for ubuntu * CHanged vangrantfile not to show gui * Refactor cpack + add component builds for rpm based distros
127 lines
4.9 KiB
C++
Executable File
127 lines
4.9 KiB
C++
Executable File
#pragma once
|
|
|
|
#include <rublon/bits.hpp>
|
|
|
|
#include <rublon/authentication_step_interface.hpp>
|
|
#include <rublon/configuration.hpp>
|
|
#include <rublon/json.hpp>
|
|
#include <rublon/method/method_select.hpp>
|
|
|
|
#include <rublon/session.hpp>
|
|
|
|
#include <sys/utsname.h>
|
|
|
|
extern std::string g_tid;
|
|
|
|
namespace rublon {
|
|
|
|
template < class MethodSelect_t = MethodSelect >
|
|
class Init : public AuthenticationStep {
|
|
using base_t = AuthenticationStep;
|
|
|
|
const char * apiPath = "/api/transaction/init";
|
|
|
|
tl::expected< MethodSelect_t, Error > createMethod(const Document & coreResponse) const {
|
|
const auto & rublonResponse = coreResponse["result"];
|
|
std::string tid = rublonResponse["tid"].GetString();
|
|
g_tid = tid; /// TODO set tid in session
|
|
return MethodSelect_t{
|
|
this->_systemToken, tid, rublonResponse["methods"], _session.config().prompt, _session.config().autopushPrompt};
|
|
}
|
|
|
|
void addPamInfo(Document & coreRequest, const Pam_t & pam) const {
|
|
auto & alloc = coreRequest.GetAllocator();
|
|
coreRequest.AddMember("username", Value{pam.username().get(), alloc}, alloc);
|
|
}
|
|
|
|
void addParams(Document & coreRequest, const Pam_t & pam) const {
|
|
memory::MonotonicStackResource< 512 > stackResource;
|
|
std::pmr::string releaseInfo{&stackResource};
|
|
auto & alloc = coreRequest.GetAllocator();
|
|
|
|
const auto os = details::osName(&stackResource);
|
|
|
|
if(os == "unknown") {
|
|
log(LogLevel::Warning, "No OS information available");
|
|
}
|
|
|
|
Value osNamePretty{os.data(), static_cast< unsigned >(os.size()), alloc};
|
|
Value ip{pam.ip().get(), alloc};
|
|
|
|
Value params{rapidjson::kObjectType};
|
|
params.AddMember("userIP", ip, alloc);
|
|
params.AddMember("appVer", "2.0.4", alloc); /// TODO add version to cmake
|
|
params.AddMember("os", osNamePretty, alloc);
|
|
|
|
coreRequest.AddMember("params", std::move(params), alloc);
|
|
}
|
|
|
|
tl::expected< std::reference_wrapper< const Document >, Error > checkEnrolement(const Document & coreResponse, const Pam_t pam) const {
|
|
using namespace std::string_view_literals;
|
|
const auto & resp = coreResponse;
|
|
|
|
/// TODO refactor this
|
|
if(resp.HasMember("result") and resp["result"].IsObject() and resp["result"].HasMember("status")) {
|
|
const auto & status = resp["result"]["status"].GetString();
|
|
log(LogLevel::Warning, "Got enrolement message with stats %s", status);
|
|
if(status == "pending"sv) {
|
|
if(resp["result"].HasMember("webURI")) {
|
|
const auto & weburi = resp["result"]["webURI"].GetString();
|
|
pam.print("Visit %s", weburi);
|
|
}
|
|
} else if(status == "waiting"sv) {
|
|
return tl::unexpected{Error{RublonAuthenticationInterrupt{RublonAuthenticationInterrupt::UserWaiting}}};
|
|
} else if(status == "denied"sv) {
|
|
return tl::unexpected{Error{RublonAuthenticationInterrupt{RublonAuthenticationInterrupt::UserDenied}}};
|
|
}
|
|
}
|
|
|
|
return coreResponse;
|
|
}
|
|
|
|
public:
|
|
const char * _name = "Initialization";
|
|
|
|
const Session & _session;
|
|
|
|
Init(const Session & session) : base_t(std::string{session.config().systemToken.data(), 32}, ""), _session{session} {
|
|
log(LogLevel::Debug, "Init");
|
|
}
|
|
|
|
template < typename Hander_t >
|
|
tl::expected< MethodSelect_t, Error > handle(const CoreHandlerInterface< Hander_t > & coreHandler, const Pam_t & pam) const {
|
|
const auto createMethod = [&](const auto & coreResponse) { return this->createMethod(coreResponse); };
|
|
const auto checkEnrolement = [&](const auto & coreResponse) { return this->checkEnrolement(coreResponse, pam); };
|
|
|
|
RapidJSONPMRStackAlloc< 2048 > alloc{};
|
|
Document body{rapidjson::kObjectType, &alloc};
|
|
|
|
this->addSystemToken(body);
|
|
this->addPamInfo(body, pam);
|
|
this->addParams(body, pam);
|
|
|
|
return coreHandler
|
|
.request(alloc, apiPath, body) //
|
|
.and_then(checkEnrolement)
|
|
.and_then(createMethod);
|
|
}
|
|
|
|
// tl::expected< Transaction, Error > openTransaction() const {
|
|
// const auto createTransaction = [&](const auto & coreResponse) { return this->createTransaction(coreResponse); };
|
|
// const auto checkEnrolement = [&](const auto & coreResponse) { return this->checkEnrolement(coreResponse, _session.pam()); };
|
|
|
|
// RapidJSONPMRStackAlloc< 2048 > alloc{};
|
|
// Document body{rapidjson::kObjectType, &alloc};
|
|
|
|
// this->addSystemToken(body);
|
|
// this->addPamInfo(body, _session.pam());
|
|
// this->addParams(body, _session.pam());
|
|
|
|
// return _session.coreHandler()
|
|
// .request(alloc, apiPath, body) //
|
|
// .and_then(checkEnrolement)
|
|
// .and_then(createTransaction);
|
|
// }
|
|
};
|
|
} // namespace rublon
|