Skip to content

Commit 17f2ab9

Browse files
committed
Remove encryption support from settings.
1 parent e743f43 commit 17f2ab9

File tree

3 files changed

+15
-63
lines changed

3 files changed

+15
-63
lines changed

source/base/settings/json_settings.cc

Lines changed: 10 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include "base/settings/json_settings.h"
2020

2121
#include "base/logging.h"
22-
#include "base/crypto/os_crypt.h"
2322
#include "base/files/base_paths.h"
2423
#include "base/files/file_util.h"
2524
#include "base/files/scoped_temp_file.h"
@@ -95,8 +94,7 @@ void parseObject(const T& object, std::vector<std::string_view>* segments, Setti
9594
} // namespace
9695

9796
//--------------------------------------------------------------------------------------------------
98-
JsonSettings::JsonSettings(std::string_view file_name, Encrypted encrypted)
99-
: encrypted_(encrypted)
97+
JsonSettings::JsonSettings(std::string_view file_name)
10098
{
10199
path_ = filePath(file_name);
102100
if (path_.empty())
@@ -108,9 +106,7 @@ JsonSettings::JsonSettings(std::string_view file_name, Encrypted encrypted)
108106
//--------------------------------------------------------------------------------------------------
109107
JsonSettings::JsonSettings(Scope scope,
110108
std::string_view application_name,
111-
std::string_view file_name,
112-
Encrypted encrypted)
113-
: encrypted_(encrypted)
109+
std::string_view file_name)
114110
{
115111
path_ = filePath(scope, application_name, file_name);
116112
if (path_.empty())
@@ -152,7 +148,7 @@ bool JsonSettings::isWritable() const
152148
//--------------------------------------------------------------------------------------------------
153149
void JsonSettings::sync()
154150
{
155-
readFile(path_, map(), encrypted_);
151+
readFile(path_, map());
156152
setChanged(false);
157153
}
158154

@@ -167,7 +163,7 @@ bool JsonSettings::flush()
167163
}
168164

169165
// Write to the configuration file.
170-
if (writeFile(path_, map(), encrypted_))
166+
if (writeFile(path_, map()))
171167
{
172168
LOG(LS_INFO) << "Configuration file '" << path_ << "' successfully written to disk";
173169
setChanged(false);
@@ -236,7 +232,7 @@ std::filesystem::path JsonSettings::filePath(Scope scope,
236232

237233
//--------------------------------------------------------------------------------------------------
238234
// static
239-
bool JsonSettings::readFile(const std::filesystem::path& file, Map& map, Encrypted encrypted)
235+
bool JsonSettings::readFile(const std::filesystem::path& file, Map& map)
240236
{
241237
map.clear();
242238

@@ -246,7 +242,7 @@ bool JsonSettings::readFile(const std::filesystem::path& file, Map& map, Encrypt
246242
if (!std::filesystem::exists(status))
247243
{
248244
// If the configuration file does not yet exist, then we write an empty file.
249-
writeFile(file, map, encrypted);
245+
writeFile(file, map);
250246

251247
// The absence of a configuration file is normal case.
252248
return true;
@@ -280,18 +276,6 @@ bool JsonSettings::readFile(const std::filesystem::path& file, Map& map, Encrypt
280276
return false;
281277
}
282278

283-
if (encrypted == Encrypted::YES)
284-
{
285-
std::string decrypted;
286-
if (!OSCrypt::decryptString(buffer, &decrypted))
287-
{
288-
LOG(LS_ERROR) << "Failed to decrypt config file: '" << file << "'";
289-
return false;
290-
}
291-
292-
buffer.swap(decrypted);
293-
}
294-
295279
rapidjson::StringStream stream(buffer.data());
296280
rapidjson::Document doc;
297281
doc.ParseStream(stream);
@@ -311,7 +295,7 @@ bool JsonSettings::readFile(const std::filesystem::path& file, Map& map, Encrypt
311295

312296
//--------------------------------------------------------------------------------------------------
313297
// static
314-
bool JsonSettings::writeFile(const std::filesystem::path& file, const Map& map, Encrypted encrypted)
298+
bool JsonSettings::writeFile(const std::filesystem::path& file, const Map& map)
315299
{
316300
std::error_code error_code;
317301
if (!std::filesystem::create_directories(file.parent_path(), error_code))
@@ -379,31 +363,10 @@ bool JsonSettings::writeFile(const std::filesystem::path& file, const Map& map,
379363

380364
std::string_view source_buffer(buffer.GetString(), buffer.GetSize());
381365

382-
if (encrypted == Encrypted::YES)
366+
if (!base::writeFile(file, source_buffer))
383367
{
384-
std::string cipher_buffer;
385-
386-
if (!OSCrypt::encryptString(source_buffer, &cipher_buffer))
387-
{
388-
LOG(LS_ERROR) << "Failed to encrypt config file";
389-
return false;
390-
}
391-
392-
if (!base::writeFile(file, cipher_buffer))
393-
{
394-
LOG(LS_ERROR) << "Failed to write config file";
395-
return false;
396-
}
397-
}
398-
else
399-
{
400-
DCHECK_EQ(encrypted, Encrypted::NO);
401-
402-
if (!base::writeFile(file, source_buffer))
403-
{
404-
LOG(LS_ERROR) << "Failed to write config file";
405-
return false;
406-
}
368+
LOG(LS_ERROR) << "Failed to write config file";
369+
return false;
407370
}
408371

409372
return true;

source/base/settings/json_settings.h

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,11 @@ class JsonSettings final : public Settings
3030
{
3131
public:
3232
enum class Scope { USER, SYSTEM };
33-
enum class Encrypted { YES, NO };
3433

35-
JsonSettings(std::string_view file_name,
36-
Encrypted encrypted = Encrypted::NO);
34+
explicit JsonSettings(std::string_view file_name);
3735
JsonSettings(Scope scope,
3836
std::string_view application_name,
39-
std::string_view file_name,
40-
Encrypted encrypted = Encrypted::NO);
37+
std::string_view file_name);
4138
~JsonSettings() final;
4239

4340
bool isWritable() const;
@@ -51,15 +48,10 @@ class JsonSettings final : public Settings
5148
std::string_view application_name,
5249
std::string_view file_name);
5350

54-
static bool readFile(const std::filesystem::path& file,
55-
Map& map,
56-
Encrypted encrypted = Encrypted::NO);
57-
static bool writeFile(const std::filesystem::path& file,
58-
const Map& map,
59-
Encrypted encrypted = Encrypted::NO);
51+
static bool readFile(const std::filesystem::path& file, Map& map);
52+
static bool writeFile(const std::filesystem::path& file, const Map& map);
6053

6154
private:
62-
const Encrypted encrypted_;
6355
std::filesystem::path path_;
6456

6557
DISALLOW_COPY_AND_ASSIGN(JsonSettings);

source/client/router_config_storage.cc

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@ namespace client {
2424

2525
//--------------------------------------------------------------------------------------------------
2626
RouterConfigStorage::RouterConfigStorage()
27-
: storage_(base::JsonSettings::Scope::USER,
28-
"aspia",
29-
"router_config",
30-
base::JsonSettings::Encrypted::YES)
27+
: storage_(base::JsonSettings::Scope::USER, "aspia", "router_config")
3128
{
3229
// Nothing
3330
}

0 commit comments

Comments
 (0)