9#include <nvmconfig/vendor.h>
10#include <utils/logging.h>
12void net::auth::Gatekeeper::reset_defaults() {
13#ifdef ANABRID_UNSAFE_INTERNET
20 enable_whitelist =
false;
22 access_control_allow_origin =
"*";
24 users.reset_defaults();
25 whitelist.list.clear();
28void net::auth::UserPasswordAuthentification::reset_defaults() {
31 auto default_admin_password = nvmconfig::VendorOTP::get().default_admin_password;
35 auto default_user_password = nvmconfig::VendorOTP::get().default_user_password;
37 if (!default_admin_password.empty())
38 db[admin] = default_admin_password;
39 if (!default_user_password.empty())
40 db[user] = default_user_password;
42 LOG_ALWAYS(
"UserPasswordAuthentification::reset_defaults() resetting admin and default user.");
45void net::auth::UserPasswordAuthentification::fromJson(JsonObjectConst serialized_conf) {
47 for (JsonPairConst kv : serialized_conf) {
48 db[kv.key().c_str()] = kv.value().as<std::string>();
52void net::auth::UserPasswordAuthentification::toJson(JsonObject target)
const {
53 for (
auto const &kv : db) {
54 target[kv.first] = kv.second;
58void net::auth::UserPasswordAuthentification::status(JsonObject target) {
59 target[
"enabled"] = !is_disabled();
60 auto users = target.createNestedArray(
"users");
61 for (
auto const &kv : db)
66int net::auth::Gatekeeper::login(JsonObjectConst msg_in, JsonObject &msg_out,
67 net::auth::AuthentificationContext &user_context) {
68 if (!enable_auth && !enable_users) {
69 msg_out[
"error"] =
"No authentification neccessary. Auth system is currently disabled (either by firmware "
70 "build or user settings).";
73 std::string new_user = msg_in[
"user"];
74 if (user_context.hasBetterClearenceThen(new_user)) {
78 "Login can only upgrade privileges but you wold loose. Open a new connection instead.";
80 }
else if (!users.is_valid(new_user, msg_in[
"password"])) {
81 msg_out[
"error"] =
"Invalid username or password.";
100 user_context.login(new_user);
102 LOG_ALWAYS(
"New authentification");
109int net::auth::Gatekeeper::lock_acquire(JsonObjectConst msg_in, JsonObject &msg_out,
110 AuthentificationContext &user_context) {
112 if (lock.is_locked()) {
113 msg_out[
"error"] =
"Computer is already locked";
116 lock.enable_lock(user_context.user());
121int net::auth::Gatekeeper::lock_release(JsonObjectConst msg_in, JsonObject &msg_out,
122 AuthentificationContext &user_context) {
123 if (!enable_users || user_context.user() == lock.holder ||
124 user_context.can_do(SecurityLevel::RequiresAdmin)) {