From ba96b9595491cf3c204a2f2ebdb1f9bc9ba50c32 Mon Sep 17 00:00:00 2001 From: Pranav Kant Date: Wed, 30 Mar 2016 21:27:17 +0530 Subject: [PATCH] loolwsd: Setup client SSL We act as a client when we communicate with owncloud server. For time being, just accept whatever certificates owncloud server gives us. We might want to get more strict here in future. Change-Id: I4813d19412b66ecf57d6cdef9c3ac94fbbaa521f --- loolwsd/LOOLWSD.cpp | 12 ++++++++++++ loolwsd/Storage.hpp | 8 +++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp index 7e75e80e1..0fb89a9e9 100644 --- a/loolwsd/LOOLWSD.cpp +++ b/loolwsd/LOOLWSD.cpp @@ -70,6 +70,7 @@ DEALINGS IN THE SOFTWARE. #include #include #include +#include #include #include #include @@ -955,6 +956,17 @@ void LOOLWSD::initializeSSL() Poco::Net::Context::Ptr sslContext = new Poco::Net::Context(Poco::Net::Context::SERVER_USE, sslParams); Poco::Net::SSLManager::instance().initializeServer(consoleHandler, invalidCertHandler, sslContext); + + // Init client + Poco::Net::Context::Params sslClientParams; + // TODO: Be more strict and setup SSL key/certs for owncloud server and us + sslClientParams.verificationMode = Poco::Net::Context::VERIFY_NONE; + + Poco::SharedPtr consoleClientHandler = new Poco::Net::KeyConsoleHandler(false); + Poco::SharedPtr invalidClientCertHandler = new Poco::Net::AcceptCertificateHandler(false); + + Poco::Net::Context::Ptr sslClientContext = new Poco::Net::Context(Poco::Net::Context::CLIENT_USE, sslClientParams); + Poco::Net::SSLManager::instance().initializeClient(consoleClientHandler, invalidClientCertHandler, sslClientContext); } void LOOLWSD::uninitialize() diff --git a/loolwsd/Storage.hpp b/loolwsd/Storage.hpp index 1f92541c0..08bec04ac 100644 --- a/loolwsd/Storage.hpp +++ b/loolwsd/Storage.hpp @@ -16,6 +16,8 @@ #include #include +#include +#include #include #include #include @@ -195,7 +197,7 @@ public: Log::debug("Getting info for wopi uri [" + uri.toString() + "]."); Poco::URI uriObject(uri); - Poco::Net::HTTPClientSession session(uriObject.getHost(), uriObject.getPort()); + Poco::Net::HTTPSClientSession session(uriObject.getHost(), uriObject.getPort(), Poco::Net::SSLManager::instance().defaultClientContext()); 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); @@ -251,7 +253,7 @@ public: const auto url = uriObject.getPath() + "/contents?" + uriObject.getQuery(); Log::debug("Wopi requesting: " + url); - Poco::Net::HTTPClientSession session(uriObject.getHost(), uriObject.getPort()); + Poco::Net::HTTPSClientSession session(uriObject.getHost(), uriObject.getPort(), Poco::Net::SSLManager::instance().defaultClientContext()); 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); @@ -292,7 +294,7 @@ public: const auto url = uriObject.getPath() + "/contents?" + uriObject.getQuery(); Log::debug("Wopi posting: " + url); - Poco::Net::HTTPClientSession session(uriObject.getHost(), uriObject.getPort()); + Poco::Net::HTTPSClientSession session(uriObject.getHost(), uriObject.getPort(), Poco::Net::SSLManager::instance().defaultClientContext()); 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");