2024-12-16 18:58:36 +00:00
|
|
|
#include "Auth.hpp"
|
|
|
|
|
#include "Pam.hpp"
|
|
|
|
|
#include "Fingerprint.hpp"
|
|
|
|
|
#include "../config/ConfigManager.hpp"
|
|
|
|
|
#include "../core/hyprlock.hpp"
|
|
|
|
|
#include "src/helpers/Log.hpp"
|
|
|
|
|
|
|
|
|
|
#include <hyprlang.hpp>
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
|
|
CAuth::CAuth() {
|
2025-01-29 22:10:27 +00:00
|
|
|
static const auto ENABLEPAM = g_pConfigManager->getValue<Hyprlang::INT>("auth:pam:enabled");
|
|
|
|
|
if (*ENABLEPAM)
|
2025-03-05 08:35:43 +01:00
|
|
|
m_vImpls.emplace_back(makeShared<CPam>());
|
2025-01-29 22:10:27 +00:00
|
|
|
static const auto ENABLEFINGERPRINT = g_pConfigManager->getValue<Hyprlang::INT>("auth:fingerprint:enabled");
|
|
|
|
|
if (*ENABLEFINGERPRINT)
|
2025-03-05 08:35:43 +01:00
|
|
|
m_vImpls.emplace_back(makeShared<CFingerprint>());
|
2024-12-16 18:58:36 +00:00
|
|
|
|
|
|
|
|
RASSERT(!m_vImpls.empty(), "At least one authentication method must be enabled!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CAuth::start() {
|
|
|
|
|
for (const auto& i : m_vImpls) {
|
|
|
|
|
i->init();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CAuth::submitInput(const std::string& input) {
|
|
|
|
|
for (const auto& i : m_vImpls) {
|
|
|
|
|
i->handleInput(input);
|
|
|
|
|
}
|
2025-03-17 11:25:51 +00:00
|
|
|
|
|
|
|
|
g_pHyprlock->clearPasswordBuffer();
|
2024-12-16 18:58:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CAuth::checkWaiting() {
|
2025-03-05 08:35:43 +01:00
|
|
|
return std::ranges::any_of(m_vImpls, [](const auto& i) { return i->checkWaiting(); });
|
2024-12-16 18:58:36 +00:00
|
|
|
}
|
|
|
|
|
|
2025-01-12 17:18:18 +00:00
|
|
|
const std::string& CAuth::getCurrentFailText() {
|
|
|
|
|
return m_sCurrentFail.failText;
|
2024-12-16 18:58:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::optional<std::string> CAuth::getFailText(eAuthImplementations implType) {
|
|
|
|
|
for (const auto& i : m_vImpls) {
|
|
|
|
|
if (i->getImplType() == implType)
|
|
|
|
|
return i->getLastFailText();
|
|
|
|
|
}
|
|
|
|
|
return std::nullopt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::optional<std::string> CAuth::getPrompt(eAuthImplementations implType) {
|
|
|
|
|
for (const auto& i : m_vImpls) {
|
|
|
|
|
if (i->getImplType() == implType)
|
|
|
|
|
return i->getLastPrompt();
|
|
|
|
|
}
|
|
|
|
|
return std::nullopt;
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-12 17:18:18 +00:00
|
|
|
size_t CAuth::getFailedAttempts() {
|
|
|
|
|
return m_sCurrentFail.failedAttempts;
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-05 08:35:43 +01:00
|
|
|
SP<IAuthImplementation> CAuth::getImpl(eAuthImplementations implType) {
|
2024-12-16 18:58:36 +00:00
|
|
|
for (const auto& i : m_vImpls) {
|
|
|
|
|
if (i->getImplType() == implType)
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CAuth::terminate() {
|
|
|
|
|
for (const auto& i : m_vImpls) {
|
|
|
|
|
i->terminate();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-30 09:12:40 +02:00
|
|
|
static void unlockCallback(std::shared_ptr<CTimer> self, void* data) {
|
2025-04-02 22:13:22 +02:00
|
|
|
g_pHyprlock->unlock();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CAuth::enqueueUnlock() {
|
2025-04-30 09:12:40 +02:00
|
|
|
g_pHyprlock->addTimer(std::chrono::milliseconds(0), unlockCallback, nullptr);
|
2025-04-02 22:13:22 +02:00
|
|
|
}
|
|
|
|
|
|
2024-12-16 18:58:36 +00:00
|
|
|
static void passwordFailCallback(std::shared_ptr<CTimer> self, void* data) {
|
2025-01-12 17:18:18 +00:00
|
|
|
g_pAuth->m_bDisplayFailText = true;
|
|
|
|
|
|
2024-12-16 18:58:36 +00:00
|
|
|
g_pHyprlock->enqueueForceUpdateTimers();
|
|
|
|
|
|
|
|
|
|
g_pHyprlock->renderAllOutputs();
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-02 22:13:22 +02:00
|
|
|
static void displayFailTimeoutCallback(std::shared_ptr<CTimer> self, void* data) {
|
|
|
|
|
if (g_pAuth->m_bDisplayFailText) {
|
|
|
|
|
g_pAuth->m_bDisplayFailText = false;
|
|
|
|
|
g_pHyprlock->renderAllOutputs();
|
|
|
|
|
}
|
2024-12-16 18:58:36 +00:00
|
|
|
}
|
|
|
|
|
|
2025-01-12 17:18:18 +00:00
|
|
|
void CAuth::enqueueFail(const std::string& failText, eAuthImplementations implType) {
|
2025-04-08 16:37:13 +02:00
|
|
|
static const auto FAILTIMEOUT = g_pConfigManager->getValue<Hyprlang::INT>("general:fail_timeout");
|
2025-04-02 22:13:22 +02:00
|
|
|
|
2025-01-12 17:18:18 +00:00
|
|
|
m_sCurrentFail.failText = failText;
|
|
|
|
|
m_sCurrentFail.failSource = implType;
|
|
|
|
|
m_sCurrentFail.failedAttempts++;
|
|
|
|
|
|
|
|
|
|
Debug::log(LOG, "Failed attempts: {}", m_sCurrentFail.failedAttempts);
|
|
|
|
|
|
2025-04-02 22:13:22 +02:00
|
|
|
if (m_resetDisplayFailTimer) {
|
|
|
|
|
m_resetDisplayFailTimer->cancel();
|
|
|
|
|
m_resetDisplayFailTimer.reset();
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-16 18:58:36 +00:00
|
|
|
g_pHyprlock->addTimer(std::chrono::milliseconds(0), passwordFailCallback, nullptr);
|
2025-04-02 22:13:22 +02:00
|
|
|
m_resetDisplayFailTimer = g_pHyprlock->addTimer(std::chrono::milliseconds(*FAILTIMEOUT), displayFailTimeoutCallback, nullptr);
|
2024-12-16 18:58:36 +00:00
|
|
|
}
|
|
|
|
|
|
2025-04-02 22:13:22 +02:00
|
|
|
void CAuth::resetDisplayFail() {
|
|
|
|
|
g_pAuth->m_bDisplayFailText = false;
|
|
|
|
|
m_resetDisplayFailTimer->cancel();
|
|
|
|
|
m_resetDisplayFailTimer.reset();
|
2024-12-16 18:58:36 +00:00
|
|
|
}
|