[Libreoffice-commits] online.git: loolwsd/Common.hpp loolwsd/LOOLWSD.cpp loolwsd/LOOLWSD.hpp loolwsd/loolwsd.xml
Ashod Nakashian
ashod.nakashian at collabora.co.uk
Wed Mar 23 11:28:32 UTC 2016
loolwsd/Common.hpp | 2 -
loolwsd/LOOLWSD.cpp | 54 ++++++++++++++++++++++++++++++++++++----------------
loolwsd/LOOLWSD.hpp | 1
loolwsd/loolwsd.xml | 6 +++++
4 files changed, 45 insertions(+), 18 deletions(-)
New commits:
commit b4e4ccb666a594e40cd09fb9a0f8c6f0971b1f26
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date: Wed Mar 23 07:08:01 2016 -0400
loolwsd: configuration support
Configuration XML is added with SSL as sample use-case.
A 'desc' attribute can be used to describe the fields,
and another 'type' to help define the corresponding data
type in the code.
Since Poco allows accessing group nodes (that have the
same name) by index, order can be preserved.
SSL initialization refactored and cert/key file
paths moved to the config file.
Change-Id: I259826a19697bd851587bebcc4f0cd233ab6848b
Reviewed-on: https://gerrit.libreoffice.org/23464
Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
Tested-by: Ashod Nakashian <ashnakash at gmail.com>
diff --git a/loolwsd/Common.hpp b/loolwsd/Common.hpp
index 2f44df2..d96a09d 100644
--- a/loolwsd/Common.hpp
+++ b/loolwsd/Common.hpp
@@ -36,8 +36,6 @@ constexpr int SMALL_MESSAGE_SIZE = READ_BUFFER_SIZE / 2;
static const std::string JailedDocumentRoot = "/user/docs/";
static const std::string CHILD_URI = "/loolws/child?";
static const std::string LOLEAFLET_PATH = "/loleaflet/dist/loleaflet.html?";
-static const std::string SSL_CERT_FILE = "cert.pem";
-static const std::string SSL_KEY_FILE = "key.pem";
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index ae896a3..a8a3996 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -1042,6 +1042,42 @@ void LOOLWSD::initialize(Application& self)
ServerApplication::initialize(self);
}
+void LOOLWSD::initializeSSL()
+{
+ auto& conf = config();
+
+ auto ssl_cert_file_path = conf.getString("ssl.cert_file_path");
+ if (conf.getBool("ssl.cert_file_path[@relative]"))
+ {
+ ssl_cert_file_path = Poco::Path(Application::instance().commandPath()).parent().append(ssl_cert_file_path).toString();
+ }
+
+ Log::info("SSL Cert file: " + ssl_cert_file_path);
+
+ auto ssl_key_file_path = conf.getString("ssl.key_file_path");
+ if (conf.getBool("ssl.key_file_path[@relative]"))
+ {
+ ssl_key_file_path = Poco::Path(Application::instance().commandPath()).parent().append(ssl_key_file_path).toString();
+ }
+
+ Log::info("SSL Key file: " + ssl_key_file_path);
+
+ Poco::Crypto::initializeCrypto();
+
+ Poco::Net::initializeSSL();
+ Poco::Net::Context::Params sslParams;
+ sslParams.certificateFile = ssl_cert_file_path;
+ sslParams.privateKeyFile = ssl_key_file_path;
+ // Don't ask clients for certificate
+ sslParams.verificationMode = Poco::Net::Context::VERIFY_NONE;
+
+ Poco::SharedPtr<Poco::Net::PrivateKeyPassphraseHandler> consoleHandler = new Poco::Net::KeyConsoleHandler(true);
+ Poco::SharedPtr<Poco::Net::InvalidCertificateHandler> invalidCertHandler = new Poco::Net::ConsoleCertificateHandler(false);
+
+ Poco::Net::Context::Ptr sslContext = new Poco::Net::Context(Poco::Net::Context::SERVER_USE, sslParams);
+ Poco::Net::SSLManager::instance().initializeServer(consoleHandler, invalidCertHandler, sslContext);
+}
+
void LOOLWSD::uninitialize()
{
ServerApplication::uninitialize();
@@ -1184,21 +1220,7 @@ int LOOLWSD::main(const std::vector<std::string>& /*args*/)
return Application::EXIT_USAGE;
}
- Poco::Crypto::initializeCrypto();
-
- // SSL initialize
- Poco::Net::initializeSSL();
- Poco::Net::Context::Params sslParams;
- sslParams.certificateFile = Path(Application::instance().commandPath()).parent().toString() + SSL_CERT_FILE;
- sslParams.privateKeyFile = Path(Application::instance().commandPath()).parent().toString() + SSL_KEY_FILE;
- // Don't ask clients for certificate
- sslParams.verificationMode = Poco::Net::Context::VERIFY_NONE;
-
- Poco::SharedPtr<Poco::Net::PrivateKeyPassphraseHandler> consoleHandler = new Poco::Net::KeyConsoleHandler(true);
- Poco::SharedPtr<Poco::Net::InvalidCertificateHandler> invalidCertHandler = new Poco::Net::ConsoleCertificateHandler(false);
-
- Poco::Net::Context::Ptr sslContext = new Poco::Net::Context(Poco::Net::Context::SERVER_USE, sslParams);
- Poco::Net::SSLManager::instance().initializeServer(consoleHandler, invalidCertHandler, sslContext);
+ initializeSSL();
char *locale = setlocale(LC_ALL, nullptr);
if (locale == nullptr || std::strcmp(locale, "C") == 0)
@@ -1435,7 +1457,7 @@ int LOOLWSD::main(const std::vector<std::string>& /*args*/)
std::unique_lock<std::mutex> sessionsLock(sessionsMutex);
for (auto& it : sessions)
{
- if (it->lastMessageTime >= it->idleSaveTime &&
+ if (it->lastMessageTime >= it->idleSaveTime &&
it->lastMessageTime >= it->autoSaveTime)
{
// Trigger a .uno:Save
diff --git a/loolwsd/LOOLWSD.hpp b/loolwsd/LOOLWSD.hpp
index 61ce73e..f2a498e 100644
--- a/loolwsd/LOOLWSD.hpp
+++ b/loolwsd/LOOLWSD.hpp
@@ -66,6 +66,7 @@ protected:
int main(const std::vector<std::string>& args) override;
private:
+ void initializeSSL();
void displayHelp();
void displayVersion();
Poco::Process::PID createBroker();
diff --git a/loolwsd/loolwsd.xml b/loolwsd/loolwsd.xml
new file mode 100644
index 0000000..a2d0f2e
--- /dev/null
+++ b/loolwsd/loolwsd.xml
@@ -0,0 +1,6 @@
+<config>
+ <ssl desc="SSL settings">
+ <cert_file_path desc="path to the cert file" relative="true">cert.pem</cert_file_path>
+ <key_file_path desc="path to the key file" relative="true">key.pem</key_file_path>
+ </ssl>
+</config>
More information about the Libreoffice-commits
mailing list