[Libreoffice-commits] online.git: common/FileUtil.cpp common/FileUtil.hpp wsd/LOOLWSD.cpp wsd/LOOLWSD.hpp

Michael Meeks (via logerrit) logerrit at kemper.freedesktop.org
Sat Jan 18 19:05:53 UTC 2020


 common/FileUtil.cpp |   24 ++++++++++++++++++++++++
 common/FileUtil.hpp |   10 ++++++++++
 wsd/LOOLWSD.cpp     |    9 +++++----
 wsd/LOOLWSD.hpp     |    6 +++---
 4 files changed, 42 insertions(+), 7 deletions(-)

New commits:
commit e6a3364e9367bbf833ab4bf2265a04ee8c010324
Author:     Michael Meeks <michael.meeks at collabora.com>
AuthorDate: Fri Jan 17 22:31:41 2020 +0000
Commit:     Michael Meeks <michael.meeks at collabora.com>
CommitDate: Sat Jan 18 20:05:35 2020 +0100

    Move file url anonymization down from LOOLWSD into FileUtil.
    
    Change-Id: I415c73b10621d5c7c942367bbf38a3bbd9bf8f27
    Reviewed-on: https://gerrit.libreoffice.org/c/online/+/87024
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Michael Meeks <michael.meeks at collabora.com>

diff --git a/common/FileUtil.cpp b/common/FileUtil.cpp
index f94911606..5066d2938 100644
--- a/common/FileUtil.cpp
+++ b/common/FileUtil.cpp
@@ -343,6 +343,30 @@ 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;
+    }
+
+    /// Anonymize the basename of filenames, preserving the path and extension.
+    std::string anonymizeUrl(const std::string& url)
+    {
+        return AnonymizeUserData ? Util::anonymizeUrl(url, AnonymizationSalt) : url;
+    }
+
+    /// Anonymize user names and IDs.
+    /// Will use the Obfuscated User ID if one is provied via WOPI.
+    std::string anonymizeUsername(const std::string& username)
+    {
+        return AnonymizeUserData ? Util::anonymize(username, AnonymizationSalt) : username;
+    }
+
 } // namespace FileUtil
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/common/FileUtil.hpp b/common/FileUtil.hpp
index 84b42f65c..a57aa5414 100644
--- a/common/FileUtil.hpp
+++ b/common/FileUtil.hpp
@@ -17,6 +17,16 @@
 
 namespace FileUtil
 {
+    /// Used for anonymizing URLs
+    void setUrlAnonymization(bool anonymize, const std::uint64_t salt);
+
+    /// Anonymize the basename of filenames, preserving the path and extension.
+    std::string anonymizeUrl(const std::string& url);
+
+    /// Anonymize user names and IDs.
+    /// Will use the Obfuscated User ID if one is provied via WOPI.
+    std::string anonymizeUsername(const std::string& username);
+
     /// Create a secure, random directory path.
     std::string createRandomDir(const std::string& path);
 
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 3b45fd3de..e39bfa9d0 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -716,7 +716,6 @@ std::string LOOLWSD::ConfigFile = LOOLWSD_CONFIGDIR "/loolwsd.xml";
 std::string LOOLWSD::ConfigDir = LOOLWSD_CONFIGDIR "/conf.d";
 std::string LOOLWSD::LogLevel = "trace";
 bool LOOLWSD::AnonymizeUserData = false;
-std::uint64_t LOOLWSD::AnonymizationSalt = 82589933;
 #if ENABLE_SSL
 Util::RuntimeConstant<bool> LOOLWSD::SSLEnabled;
 Util::RuntimeConstant<bool> LOOLWSD::SSLTermination;
@@ -1003,14 +1002,16 @@ void LOOLWSD::initialize(Application& self)
         }
     }
 
+    std::uint64_t anonymizationSalt = 82589933;
     LOG_INF("Anonymization of user-data is " << (AnonymizeUserData ? "enabled." : "disabled."));
     if (AnonymizeUserData)
     {
         // Get the salt, if set, otherwise default, and set as envar, so the kits inherit it.
-        AnonymizationSalt = getConfigValue<std::uint64_t>(conf, "logging.anonymize.anonymization_salt", 82589933);
-        const std::string sAnonymizationSalt = std::to_string(AnonymizationSalt);
-        setenv("LOOL_ANONYMIZATION_SALT", sAnonymizationSalt.c_str(), true);
+        anonymizationSalt = getConfigValue<std::uint64_t>(conf, "logging.anonymize.anonymization_salt", 82589933);
+        const std::string anonymizationSaltStr = std::to_string(anonymizationSalt);
+        setenv("LOOL_ANONYMIZATION_SALT", anonymizationSaltStr.c_str(), true);
     }
+    FileUtil::setUrlAnonymization(AnonymizeUserData, anonymizationSalt);
 
     {
         std::string proto = getConfigValue<std::string>(conf, "net.proto", "");
diff --git a/wsd/LOOLWSD.hpp b/wsd/LOOLWSD.hpp
index 6e35bd796..71ddb2155 100644
--- a/wsd/LOOLWSD.hpp
+++ b/wsd/LOOLWSD.hpp
@@ -24,6 +24,7 @@
 #include <Poco/Util/ServerApplication.h>
 
 #include "Util.hpp"
+#include "FileUtil.hpp"
 
 class ChildProcess;
 class TraceFileWriter;
@@ -67,7 +68,6 @@ public:
     static std::string HostIdentifier; ///< A unique random hash that identifies this server
     static std::string LogLevel;
     static bool AnonymizeUserData;
-    static std::uint64_t AnonymizationSalt;
     static std::atomic<unsigned> NumConnections;
     static std::unique_ptr<TraceFileWriter> TraceDumper;
 #if !MOBILEAPP
@@ -184,14 +184,14 @@ public:
     /// Anonymize the basename of filenames, preserving the path and extension.
     static std::string anonymizeUrl(const std::string& url)
     {
-        return AnonymizeUserData ? Util::anonymizeUrl(url, AnonymizationSalt) : url;
+        return FileUtil::anonymizeUrl(url);
     }
 
     /// Anonymize user names and IDs.
     /// Will use the Obfuscated User ID if one is provied via WOPI.
     static std::string anonymizeUsername(const std::string& username)
     {
-        return AnonymizeUserData ? Util::anonymize(username, AnonymizationSalt) : username;
+        return FileUtil::anonymizeUsername(username);
     }
 
     /// get correct server URL with protocol + port number for this running server


More information about the Libreoffice-commits mailing list