mirror of
https://github.com/kunkundi/crossdesk.git
synced 2026-11-09 17:06:24 +08:00
[feat] add application-layer trusted device authentication
This commit is contained in:
@@ -36,6 +36,14 @@ ConfigCenter::~ConfigCenter() {}
|
||||
int ConfigCenter::Load() {
|
||||
SI_Error rc = ini_->LoadFile(config_path_.c_str());
|
||||
if (rc < 0) {
|
||||
std::error_code error;
|
||||
if (std::filesystem::exists(config_path_, error) || error) {
|
||||
// An unreadable existing configuration must not silently disable access
|
||||
// restrictions or overwrite the user's settings with default values.
|
||||
trusted_devices_only_.store(true);
|
||||
LOG_ERROR("Cannot read existing configuration; restricting incoming connections");
|
||||
return -1;
|
||||
}
|
||||
Save();
|
||||
return -1;
|
||||
}
|
||||
@@ -141,6 +149,9 @@ int ConfigCenter::Load() {
|
||||
ini_->GetBoolValue(section_, "privacy_local_unlock_allowed", true));
|
||||
lock_on_disconnect_.store(
|
||||
ini_->GetBoolValue(section_, "lock_on_disconnect", true));
|
||||
trusted_devices_only_.store(
|
||||
ini_->GetValue(section_, "trusted_devices_only", nullptr) != nullptr &&
|
||||
ini_->GetBoolValue(section_, "trusted_devices_only", true));
|
||||
save_remote_previews_.store(
|
||||
ini_->GetBoolValue(section_, "save_remote_previews", true));
|
||||
portable_service_prompt_suppressed_ =
|
||||
@@ -239,6 +250,7 @@ int ConfigCenter::Save() {
|
||||
ini_->SetBoolValue(section_, "privacy_local_unlock_allowed",
|
||||
privacy_local_unlock_allowed_.load());
|
||||
ini_->SetBoolValue(section_, "lock_on_disconnect", lock_on_disconnect_.load());
|
||||
ini_->SetBoolValue(section_, "trusted_devices_only", trusted_devices_only_.load());
|
||||
ini_->SetBoolValue(section_, "save_remote_previews",
|
||||
save_remote_previews_.load());
|
||||
ini_->SetBoolValue(section_, "portable_service_prompt_suppressed",
|
||||
@@ -425,6 +437,13 @@ bool ConfigCenter::IsPrivacyLocalUnlockAllowed() const {
|
||||
return privacy_local_unlock_allowed_.load();
|
||||
}
|
||||
|
||||
int ConfigCenter::SetTrustedDevicesOnly(bool enabled) {
|
||||
if (StoreValues({{"trusted_devices_only", enabled ? "true" : "false"}}) != 0) return -1;
|
||||
trusted_devices_only_.store(enabled);
|
||||
return 0;
|
||||
}
|
||||
bool ConfigCenter::IsTrustedDevicesOnly() const { return trusted_devices_only_.load(); }
|
||||
|
||||
int ConfigCenter::SetLockOnDisconnect(bool enabled) {
|
||||
if (StoreValues({{"lock_on_disconnect", enabled ? "true" : "false"}}) != 0)
|
||||
return -1;
|
||||
|
||||
@@ -55,6 +55,7 @@ class ConfigCenter {
|
||||
int SetPrivacyScreen(bool enable_privacy_screen);
|
||||
int SetPrivacyLocalUnlock(bool allowed);
|
||||
int SetLockOnDisconnect(bool enabled);
|
||||
int SetTrustedDevicesOnly(bool enabled);
|
||||
int SetSaveRemotePreviews(bool enabled);
|
||||
int SetPortableServicePromptSuppressed(bool suppressed);
|
||||
int SetSponsorshipPromptDismissedVersion(const std::string& version);
|
||||
@@ -80,6 +81,7 @@ class ConfigCenter {
|
||||
bool IsEnablePrivacyScreen() const;
|
||||
bool IsPrivacyLocalUnlockAllowed() const;
|
||||
bool IsLockOnDisconnect() const;
|
||||
bool IsTrustedDevicesOnly() const;
|
||||
bool IsSaveRemotePreviews() const;
|
||||
bool IsPortableServicePromptSuppressed() const;
|
||||
std::string GetSponsorshipPromptDismissedVersion() const;
|
||||
@@ -113,6 +115,7 @@ class ConfigCenter {
|
||||
std::atomic<bool> enable_privacy_screen_{true};
|
||||
std::atomic<bool> privacy_local_unlock_allowed_{true};
|
||||
std::atomic<bool> lock_on_disconnect_{true};
|
||||
std::atomic<bool> trusted_devices_only_{false};
|
||||
std::atomic<bool> save_remote_previews_{true};
|
||||
bool portable_service_prompt_suppressed_ = false;
|
||||
std::string sponsorship_prompt_dismissed_version_;
|
||||
|
||||
Reference in New Issue
Block a user