loleaflet/dist/admin/admin.html | 7 +++ loleaflet/dist/admin/adminAnalytics.html | 7 +++ loleaflet/dist/admin/adminSettings.html | 7 +++ loleaflet/dist/loleaflet.html | 3 - loolwsd/Connect.cpp | 10 +++++ loolwsd/LOOLWSD.cpp | 15 +++++++- loolwsd/Storage.cpp | 13 +++++++ loolwsd/configure.ac | 8 ++++ loolwsd/loolwsd.spec.in | 6 ++- loolwsd/test/httpposttest.cpp | 7 +++ loolwsd/test/httpwstest.cpp | 57 +++++++++++++++++++++++++++++++ 11 files changed, 132 insertions(+), 8 deletions(-)
New commits: commit 3f0d5a7521d521f0bb89ad128f336f57d46a0100 Author: Andras Timar <[email protected]> Date: Fri Apr 8 12:53:45 2016 +0200 loleaflet: allow HTTP-only mode for testing/trial diff --git a/loleaflet/dist/admin/admin.html b/loleaflet/dist/admin/admin.html index 7b35ea0..d03a6ef 100644 --- a/loleaflet/dist/admin/admin.html +++ b/loleaflet/dist/admin/admin.html @@ -37,7 +37,12 @@ <script>vex.defaultOptions.className = 'vex-theme-plain';</script> <script> - host = 'wss://' + window.location.host + '/adminws/' + if (window.location.protocol == "https:") { + host = 'wss://' + window.location.host + '/adminws/' + } + else { + host = 'ws://' + window.location.host + '/adminws/' + } new AdminSocketOverview(host); </script> diff --git a/loleaflet/dist/admin/adminAnalytics.html b/loleaflet/dist/admin/adminAnalytics.html index cb33ccf..daa135c 100644 --- a/loleaflet/dist/admin/adminAnalytics.html +++ b/loleaflet/dist/admin/adminAnalytics.html @@ -38,7 +38,12 @@ <script src="admin-src.js"></script> <script> - host = 'wss://' + window.location.host + '/adminws/'; + if (window.location.protocol == "https:") { + host = 'wss://' + window.location.host + '/adminws/' + } + else { + host = 'ws://' + window.location.host + '/adminws/' + } new AdminSocketAnalytics(host); </script> diff --git a/loleaflet/dist/admin/adminSettings.html b/loleaflet/dist/admin/adminSettings.html index 9858656..307226c 100644 --- a/loleaflet/dist/admin/adminSettings.html +++ b/loleaflet/dist/admin/adminSettings.html @@ -37,7 +37,12 @@ <script src="admin-src.js"></script> <script> - host = 'wss://' + window.location.host + '/adminws/'; + if (window.location.protocol == "https:") { + host = 'wss://' + window.location.host + '/adminws/' + } + else { + host = 'ws://' + window.location.host + '/adminws/' + } new AdminSocketSettings(host); </script> diff --git a/loleaflet/dist/loleaflet.html b/loleaflet/dist/loleaflet.html index bc6abfa..38e60a8 100644 --- a/loleaflet/dist/loleaflet.html +++ b/loleaflet/dist/loleaflet.html @@ -276,9 +276,6 @@ if (host === '') { vex.dialog.alert('The host URL is empty, usage: host=wss://localhost:9980'); } - if (host.startsWith('ws:')) { - vex.dialog.alert('Please use wss: instead of ws: in the host URL, usage: host=wss://localhost:9980'); - } var docURL = wopiSrc !== '' ? wopiSrc : filePath; document.title = title; commit f75a27e3dba2c97a32739791bc44582e01606e28 Author: Andras Timar <[email protected]> Date: Fri Apr 8 11:24:52 2016 +0200 loolwsd: --disable-ssl option diff --git a/loolwsd/Connect.cpp b/loolwsd/Connect.cpp index e5f1c51..b48d2ba 100644 --- a/loolwsd/Connect.cpp +++ b/loolwsd/Connect.cpp @@ -14,6 +14,7 @@ #include <Poco/Net/AcceptCertificateHandler.h> #include <Poco/Net/Context.h> +#include <Poco/Net/HTTPClientSession.h> #include <Poco/Net/HTTPSClientSession.h> #include <Poco/Net/HTTPRequest.h> #include <Poco/Net/HTTPResponse.h> @@ -43,6 +44,7 @@ using namespace LOOLProtocol; using Poco::Net::AcceptCertificateHandler; using Poco::Net::Context; +using Poco::Net::HTTPClientSession; using Poco::Net::HTTPSClientSession; using Poco::Net::HTTPRequest; using Poco::Net::HTTPResponse; @@ -118,7 +120,11 @@ class Connect: public Poco::Util::Application { public: Connect() : +#ifdef ENABLE_SSL _uri("https://127.0.0.1:" + std::to_string(DEFAULT_CLIENT_PORT_NUMBER) + "/ws") +#else + _uri("http://127.0.0.1:" + std::to_string(DEFAULT_CLIENT_PORT_NUMBER) + "/ws") +#endif { } @@ -138,6 +144,7 @@ protected: if (args.size() > 1) _uri = URI(args[1]); +#ifdef ENABLE_SSL Poco::Net::initializeSSL(); SharedPtr<InvalidCertificateHandler> invalidCertHandler = new AcceptCertificateHandler(false); @@ -146,6 +153,9 @@ protected: SSLManager::instance().initializeClient(0, invalidCertHandler, sslContext); HTTPSClientSession cs(_uri.getHost(), _uri.getPort()); +#else + HTTPClientSession cs(_uri.getHost(), _uri.getPort()); +#endif HTTPRequest request(HTTPRequest::HTTP_GET, args[0]); HTTPResponse response; WebSocket ws(cs, request, response); diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp index 45ddac2..7cf37c4 100644 --- a/loolwsd/LOOLWSD.cpp +++ b/loolwsd/LOOLWSD.cpp @@ -556,7 +556,11 @@ private: const std::string mediaType = "text/xml"; const std::string action = "action"; const std::string urlsrc = "urlsrc"; +#ifdef ENABLE_SSL const std::string uriValue = "https://" + uri.getHost() + ":" + std::to_string(uri.getPort()) + "/loleaflet/dist/loleaflet.html?"; +#else + const std::string uriValue = "http://" + uri.getHost() + ":" + std::to_string(uri.getPort()) + "/loleaflet/dist/loleaflet.html?"; +#endif InputSource inputSrc(discoveryPath); AutoPtr<Poco::XML::Document> docXML = parser.parse(&inputSrc); @@ -1045,6 +1049,7 @@ void LOOLWSD::initialize(Application& self) ServerApplication::initialize(self); } +#ifdef ENABLE_SSL void LOOLWSD::initializeSSL() { const auto ssl_cert_file_path = getPathFromConfig("ssl.cert_file_path"); @@ -1083,6 +1088,7 @@ void LOOLWSD::initializeSSL() Poco::Net::Context::Ptr sslClientContext = new Poco::Net::Context(Poco::Net::Context::CLIENT_USE, sslClientParams); Poco::Net::SSLManager::instance().initializeClient(consoleClientHandler, invalidClientCertHandler, sslClientContext); } +#endif void LOOLWSD::uninitialize() { @@ -1251,8 +1257,9 @@ int LOOLWSD::main(const std::vector<std::string>& /*args*/) Log::error("Failed to load unit test library"); return Application::EXIT_USAGE; } - +#ifdef ENABLE_SSL initializeSSL(); +#endif char *locale = setlocale(LC_ALL, nullptr); if (locale == nullptr || std::strcmp(locale, "C") == 0) @@ -1368,7 +1375,11 @@ int LOOLWSD::main(const std::vector<std::string>& /*args*/) params2->setMaxThreads(MAX_SESSIONS); // Start a server listening on the port for clients +#ifdef ENABLE_SSL SecureServerSocket svs(ClientPortNumber); +#else + ServerSocket svs(ClientPortNumber); +#endif ThreadPool threadPool(NumPreSpawnedChildren*6, MAX_SESSIONS * 2); HTTPServer srv(new ClientRequestHandlerFactory(fileServer), threadPool, svs, params1); @@ -1553,8 +1564,10 @@ int LOOLWSD::main(const std::vector<std::string>& /*args*/) Util::removeFile(path, true); } +#ifdef ENABLE_SSL Poco::Net::uninitializeSSL(); Poco::Crypto::uninitializeCrypto(); +#endif Log::info("Process [loolwsd] finished."); diff --git a/loolwsd/Storage.cpp b/loolwsd/Storage.cpp index b15253a..c2ea816 100644 --- a/loolwsd/Storage.cpp +++ b/loolwsd/Storage.cpp @@ -13,6 +13,7 @@ #include <Poco/Net/HTTPResponse.h> #include <Poco/Net/HTTPRequest.h> +#include <Poco/Net/HTTPClientSession.h> #include <Poco/Net/HTTPSClientSession.h> #include <Poco/Net/SSLManager.h> #include <Poco/StreamCopier.h> @@ -156,7 +157,11 @@ StorageBase::FileInfo WopiStorage::getFileInfo(const Poco::URI& uri) Log::debug("Getting info for wopi uri [" + uri.toString() + "]."); Poco::URI uriObject(uri); +#ifdef ENABLE_SSL Poco::Net::HTTPSClientSession session(uriObject.getHost(), uriObject.getPort(), Poco::Net::SSLManager::instance().defaultClientContext()); +#else + Poco::Net::HTTPClientSession session(uriObject.getHost(), uriObject.getPort()); +#endif Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, uriObject.getPathAndQuery(), Poco::Net::HTTPMessage::HTTP_1_1); request.set("User-Agent", "LOOLWSD WOPI Agent"); session.sendRequest(request); @@ -212,7 +217,11 @@ std::string WopiStorage::loadStorageFileToLocal() const auto url = uriObject.getPath() + "/contents?" + uriObject.getQuery(); Log::debug("Wopi requesting: " + url); +#ifdef ENABLE_SSL Poco::Net::HTTPSClientSession session(uriObject.getHost(), uriObject.getPort(), Poco::Net::SSLManager::instance().defaultClientContext()); +#else + Poco::Net::HTTPClientSession session(uriObject.getHost(), uriObject.getPort()); +#endif Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, url, Poco::Net::HTTPMessage::HTTP_1_1); request.set("User-Agent", "LOOLWSD WOPI Agent"); session.sendRequest(request); @@ -253,7 +262,11 @@ bool WopiStorage::saveLocalFileToStorage() const auto url = uriObject.getPath() + "/contents?" + uriObject.getQuery(); Log::debug("Wopi posting: " + url); +#ifdef ENABLE_SSL Poco::Net::HTTPSClientSession session(uriObject.getHost(), uriObject.getPort(), Poco::Net::SSLManager::instance().defaultClientContext()); +#else + Poco::Net::HTTPClientSession session(uriObject.getHost(), uriObject.getPort()); +#endif Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_POST, url, Poco::Net::HTTPMessage::HTTP_1_1); request.set("X-WOPIOverride", "PUT"); request.setContentType("application/octet-stream"); diff --git a/loolwsd/configure.ac b/loolwsd/configure.ac index d50fce2..8878c16 100644 --- a/loolwsd/configure.ac +++ b/loolwsd/configure.ac @@ -68,6 +68,10 @@ AC_ARG_ENABLE([tests], AS_HELP_STRING([--disable-tests], [Build and run unit tests])) +AC_ARG_ENABLE([ssl], + AS_HELP_STRING([--disable-ssl], + [Compile without SSL support])) + # Handle options AS_IF([test "$enable_debug" = yes -a -n "$with_poco_libs"], [POCO_DEBUG_SUFFIX=d], @@ -148,6 +152,9 @@ AS_IF([test `uname -s` = Linux], AS_IF([test "$enable_tests" != "no"], [PKG_CHECK_MODULES([CPPUNIT], [cppunit])]) +AS_IF([test "$enable_ssl" != "no"], + [AC_DEFINE([ENABLE_SSL],[],[Enable SSL])]) + LIBS="$LIBS -lPocoNet${POCO_DEBUG_SUFFIX} -lPocoUtil${POCO_DEBUG_SUFFIX} -lPocoJSON${POCO_DEBUG_SUFFIX} -lPocoFoundation${POCO_DEBUG_SUFFIX} -lPocoXML${POCO_DEBUG_SUFFIX} -lPocoNetSSL${POCO_DEBUG_SUFFIX} -lPocoCrypto${POCO_DEBUG_SUFFIX}" AC_CHECK_HEADERS([LibreOfficeKit/LibreOfficeKit.h], @@ -212,6 +219,7 @@ Configuration: Build location: ${top_builddir} LOKit path ${lokit_msg} LO integration tests ${lo_msg} + SSL support ${enable_ssl} " dnl vim:set shiftwidth=4 softtabstop=4 expandtab: diff --git a/loolwsd/loolwsd.spec.in b/loolwsd/loolwsd.spec.in index 555a6fd..ad6206a 100644 --- a/loolwsd/loolwsd.spec.in +++ b/loolwsd/loolwsd.spec.in @@ -37,7 +37,11 @@ Requires: libcap libcap-progs libpng libPocoFoundation42 >= 1.7.1 libPocoN %setup -q %build -%configure --with-lokit-path=bundled/include +%configure \ + --with-lokit-path=bundled/include \ +%if %{ssl_support} == "NO" + --disable-ssl +%endif env BUILDING_FROM_RPMBUILD=yes make %{?_smp_mflags} diff --git a/loolwsd/test/httpposttest.cpp b/loolwsd/test/httpposttest.cpp index 2a39f58..35afcf7 100644 --- a/loolwsd/test/httpposttest.cpp +++ b/loolwsd/test/httpposttest.cpp @@ -33,6 +33,7 @@ class HTTPPostTest : public CPPUNIT_NS::TestFixture void testConvertTo(); +#ifdef ENABLE_SSL public: HTTPPostTest() { @@ -48,14 +49,20 @@ public: { Poco::Net::uninitializeSSL(); } +#endif }; void HTTPPostTest::testConvertTo() { const auto srcPath = Util::getTempFilePath(TDOC, "hello.odt"); +#ifdef ENABLE_SSL Poco::URI uri("https://127.0.0.1:" + std::to_string(DEFAULT_CLIENT_PORT_NUMBER)); Poco::Net::HTTPSClientSession session(uri.getHost(), uri.getPort()); +#else + Poco::URI uri("http://127.0.0.1:" + std::to_string(DEFAULT_CLIENT_PORT_NUMBER)); + Poco::Net::HTTPClientSession session(uri.getHost(), uri.getPort()); +#endif Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_POST, "/convert-to"); Poco::Net::HTMLForm form; diff --git a/loolwsd/test/httpwstest.cpp b/loolwsd/test/httpwstest.cpp index c41aceb..3591ae6 100644 --- a/loolwsd/test/httpwstest.cpp +++ b/loolwsd/test/httpwstest.cpp @@ -9,6 +9,7 @@ #include <Poco/Net/AcceptCertificateHandler.h> #include <Poco/Net/HTTPRequest.h> +#include <Poco/Net/HTTPClientSession.h> #include <Poco/Net/HTTPSClientSession.h> #include <Poco/Net/HTTPResponse.h> #include <Poco/Net/InvalidCertificateHandler.h> @@ -78,20 +79,28 @@ class HTTPWSTest : public CPPUNIT_NS::TestFixture const bool isLine); public: HTTPWSTest() +#ifdef ENABLE_SSL : _uri("https://127.0.0.1:" + std::to_string(DEFAULT_CLIENT_PORT_NUMBER)) +#else + : _uri("http://127.0.0.1:" + std::to_string(DEFAULT_CLIENT_PORT_NUMBER)) +#endif { +#ifdef ENABLE_SSL Poco::Net::initializeSSL(); // Just accept the certificate anyway for testing purposes Poco::SharedPtr<Poco::Net::InvalidCertificateHandler> invalidCertHandler = new Poco::Net::AcceptCertificateHandler(false); Poco::Net::Context::Params sslParams; Poco::Net::Context::Ptr sslContext = new Poco::Net::Context(Poco::Net::Context::CLIENT_USE, sslParams); Poco::Net::SSLManager::instance().initializeClient(0, invalidCertHandler, sslContext); +#endif } +#ifdef ENABLE_SSL ~HTTPWSTest() { Poco::Net::uninitializeSSL(); } +#endif void setUp() { @@ -117,7 +126,11 @@ void HTTPWSTest::testLoad() const std::string documentURL = "file://" + Poco::Path(documentPath).makeAbsolute().toString(); Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL); +#ifdef ENABLE_SSL Poco::Net::HTTPSClientSession session(_uri.getHost(), _uri.getPort()); +#else + Poco::Net::HTTPClientSession session(_uri.getHost(), _uri.getPort()); +#endif Poco::Net::WebSocket socket(session, request, _response); sendTextFrame(socket, "load url=" + documentURL); @@ -167,7 +180,11 @@ void HTTPWSTest::testBadLoad() const std::string documentURL = "file://" + Poco::Path(documentPath).makeAbsolute().toString(); Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL); +#ifdef ENABLE_SSL Poco::Net::HTTPSClientSession session(_uri.getHost(), _uri.getPort()); +#else + Poco::Net::HTTPClientSession session(_uri.getHost(), _uri.getPort()); +#endif Poco::Net::WebSocket socket(session, request, _response); // Before loading request status. @@ -217,7 +234,11 @@ void HTTPWSTest::testSaveOnDisconnect() const std::string documentURL = "file://" + Poco::Path(documentPath).makeAbsolute().toString(); Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL); +#ifdef ENABLE_SSL Poco::Net::HTTPSClientSession session(_uri.getHost(), _uri.getPort()); +#else + Poco::Net::HTTPClientSession session(_uri.getHost(), _uri.getPort()); +#endif Poco::Net::WebSocket socket(session, request, _response); sendTextFrame(socket, "load url=" + documentURL); @@ -242,7 +263,11 @@ void HTTPWSTest::testSaveOnDisconnect() const std::string documentURL = "file://" + Poco::Path(documentPath).makeAbsolute().toString(); Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL); +#ifdef ENABLE_SSL Poco::Net::HTTPSClientSession session(_uri.getHost(), _uri.getPort()); +#else + Poco::Net::HTTPClientSession session(_uri.getHost(), _uri.getPort()); +#endif Poco::Net::WebSocket socket(session, request, _response); sendTextFrame(socket, "load url=" + documentURL); @@ -292,7 +317,11 @@ void HTTPWSTest::testExcelLoad() const std::string documentURL = "file://" + Poco::Path(documentPath).makeAbsolute().toString(); Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL); +#ifdef ENABLE_SSL Poco::Net::HTTPSClientSession session(_uri.getHost(), _uri.getPort()); +#else + Poco::Net::HTTPClientSession session(_uri.getHost(), _uri.getPort()); +#endif Poco::Net::WebSocket socket(session, request, _response); sendTextFrame(socket, "load url=" + documentURL); @@ -341,7 +370,11 @@ void HTTPWSTest::testPaste() const std::string documentURL = "file://" + Poco::Path(documentPath).makeAbsolute().toString(); Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL); +#ifdef ENABLE_SSL Poco::Net::HTTPSClientSession session(_uri.getHost(), _uri.getPort()); +#else + Poco::Net::HTTPClientSession session(_uri.getHost(), _uri.getPort()); +#endif Poco::Net::WebSocket socket(session, request, _response); sendTextFrame(socket, "load url=" + documentURL); @@ -397,7 +430,11 @@ void HTTPWSTest::testLargePaste() const std::string documentURL = "file://" + Poco::Path(documentPath).makeAbsolute().toString(); Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL); +#ifdef ENABLE_SSL Poco::Net::HTTPSClientSession session(_uri.getHost(), _uri.getPort()); +#else + Poco::Net::HTTPClientSession session(_uri.getHost(), _uri.getPort()); +#endif Poco::Net::WebSocket socket(session, request, _response); sendTextFrame(socket, "load url=" + documentURL); @@ -451,7 +488,11 @@ void HTTPWSTest::testRenderingOptions() const std::string options = "{\"rendering\":{\".uno:HideWhitespace\":{\"type\":\"boolean\",\"value\":\"true\"}}}"; Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL); +#ifdef ENABLE_SSL Poco::Net::HTTPSClientSession session(_uri.getHost(), _uri.getPort()); +#else + Poco::Net::HTTPClientSession session(_uri.getHost(), _uri.getPort()); +#endif Poco::Net::WebSocket socket(session, request, _response); sendTextFrame(socket, "load url=" + documentURL + " options=" + options); @@ -505,7 +546,11 @@ void HTTPWSTest::testPasswordProtectedDocumentWithoutPassword() const std::string documentURL = "file://" + Poco::Path(documentPath).makeAbsolute().toString(); Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL); +#ifdef ENABLE_SSL Poco::Net::HTTPSClientSession session(_uri.getHost(), _uri.getPort()); +#else + Poco::Net::HTTPClientSession session(_uri.getHost(), _uri.getPort()); +#endif Poco::Net::WebSocket socket(session, request, _response); // Send a load request without password first @@ -542,7 +587,11 @@ void HTTPWSTest::testPasswordProtectedDocumentWithWrongPassword() const std::string documentURL = "file://" + Poco::Path(documentPath).makeAbsolute().toString(); Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL); +#ifdef ENABLE_SSL Poco::Net::HTTPSClientSession session(_uri.getHost(), _uri.getPort()); +#else + Poco::Net::HTTPClientSession session(_uri.getHost(), _uri.getPort()); +#endif Poco::Net::WebSocket socket(session, request, _response); // Send a load request with incorrect password @@ -579,7 +628,11 @@ void HTTPWSTest::testPasswordProtectedDocumentWithCorrectPassword() const std::string documentURL = "file://" + Poco::Path(documentPath).makeAbsolute().toString(); Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL); +#ifdef ENABLE_SSL Poco::Net::HTTPSClientSession session(_uri.getHost(), _uri.getPort()); +#else + Poco::Net::HTTPClientSession session(_uri.getHost(), _uri.getPort()); +#endif Poco::Net::WebSocket socket(session, request, _response); // Send a load request with correct password @@ -609,7 +662,11 @@ void HTTPWSTest::testImpressPartCountChanged() const std::string documentURL = "file://" + Poco::Path(documentPath).makeAbsolute().toString(); Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL); +#ifdef ENABLE_SSL Poco::Net::HTTPSClientSession session(_uri.getHost(), _uri.getPort()); +#else + Poco::Net::HTTPClientSession session(_uri.getHost(), _uri.getPort()); +#endif Poco::Net::WebSocket socket(session, request, _response); sendTextFrame(socket, "load url=" + documentURL); _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
