Skip to content

Commit

Permalink
wsd: remove unnecessary anonymization bits
Browse files Browse the repository at this point in the history
These are old globals that are now redundant
as we've encapsulated them in the Anonymizer
class. We can safely remove them as they are
pure overhead and noise.

Change-Id: I5b8cc2486eb880b3058dd378e05a49daea01dd2f
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
  • Loading branch information
Ashod committed Dec 19, 2024
1 parent 6c1ec81 commit f3f7871
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 30 deletions.
19 changes: 2 additions & 17 deletions common/FileUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -608,29 +608,14 @@ namespace FileUtil
return true;
}

namespace {
bool AnonymizeUserData = false;
std::uint64_t AnonymizationSalt = 82589933;
}

void setUrlAnonymization(bool anonymize, const std::uint64_t salt)
{
AnonymizeUserData = anonymize;
AnonymizationSalt = salt;
Anonymizer::initialize(anonymize, salt);
}

/// Anonymize the basename of filenames, preserving the path and extension.
std::string anonymizeUrl(const std::string& url)
{
return AnonymizeUserData ? Anonymizer::anonymizeUrl(url) : url;
}
std::string anonymizeUrl(const std::string& url) { return Anonymizer::anonymizeUrl(url); }

/// Anonymize user names and IDs.
/// Will use the Obfuscated User ID if one is provided via WOPI.
std::string anonymizeUsername(const std::string& username)
{
return AnonymizeUserData ? Anonymizer::anonymize(username) : username;
return Anonymizer::anonymize(username);
}

std::string extractFileExtension(const std::string& path)
Expand Down
18 changes: 6 additions & 12 deletions kit/Kit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,6 @@ _LibreOfficeKit* loKitPtr = nullptr;
/// flush sockets with a 'processtoidle' -> 'idle' reply.
static std::chrono::steady_clock::time_point ProcessToIdleDeadline;

#ifndef BUILDING_TESTS
static bool AnonymizeUserData = false;
static uint64_t AnonymizationSalt = 82589933;
#endif

static bool EnableWebsocketURP = false;
static int URPStartCount = 0;

Expand Down Expand Up @@ -2148,7 +2143,7 @@ bool Document::forwardToChild(const std::string& prefix, const std::vector<char>

std::string abbrMessage;
#ifndef BUILDING_TESTS
if (AnonymizeUserData)
if (Anonymizer::enabled())
{
abbrMessage = "...";
}
Expand Down Expand Up @@ -3155,12 +3150,11 @@ void lokit_main(

if (const char* anonymizationSalt = std::getenv("COOL_ANONYMIZATION_SALT"))
{
AnonymizationSalt = std::stoull(anonymizationSalt);
AnonymizeUserData = true;
Anonymizer::initialize(AnonymizeUserData, AnonymizationSalt);
const auto salt = std::stoull(anonymizationSalt);
Anonymizer::initialize(true, salt);
}

LOG_INF("User-data anonymization is " << (AnonymizeUserData ? "enabled." : "disabled."));
LOG_INF("User-data anonymization is " << (Anonymizer::enabled() ? "enabled." : "disabled."));

const char* enableWebsocketURP = std::getenv("ENABLE_WEBSOCKET_URP");
EnableWebsocketURP = enableWebsocketURP && std::string(enableWebsocketURP) == "true";
Expand Down Expand Up @@ -3804,7 +3798,7 @@ TileWireId getCurrentWireId(bool increment)
std::string anonymizeUrl(const std::string& url)
{
#ifndef BUILDING_TESTS
return AnonymizeUserData ? Anonymizer::anonymizeUrl(url) : url;
return Anonymizer::anonymizeUrl(url);
#else
return url;
#endif
Expand Down Expand Up @@ -3956,7 +3950,7 @@ bool globalPreinit(const std::string &loTemplate)
std::string anonymizeUsername(const std::string& username)
{
#ifndef BUILDING_TESTS
return AnonymizeUserData ? Anonymizer::anonymize(username) : username;
return Anonymizer::anonymize(username);
#else
return username;
#endif
Expand Down
2 changes: 2 additions & 0 deletions tools/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,8 @@ int Config::main(const std::vector<std::string>& args)
std::cout << "Anonymization Salt: [" << AnonymizationSalt << "]." << std::endl;
}

Anonymizer::initialize(true, AnonymizationSalt);

for (std::size_t i = 1; i < args.size(); ++i)
{
std::cout << '[' << args[i] << "]: " << Anonymizer::anonymizeUrl(args[i]) << std::endl;
Expand Down
3 changes: 2 additions & 1 deletion wsd/COOLWSD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1468,7 +1468,8 @@ void COOLWSD::innerInitialize(Poco::Util::Application& self)
const std::string anonymizationSaltStr = std::to_string(anonymizationSalt);
setenv("COOL_ANONYMIZATION_SALT", anonymizationSaltStr.c_str(), true);
}
FileUtil::setUrlAnonymization(AnonymizeUserData, anonymizationSalt);

Anonymizer::initialize(AnonymizeUserData, anonymizationSalt);

{
bool enableWebsocketURP =
Expand Down

0 comments on commit f3f7871

Please sign in to comment.