From 418fc3f2032807a62903610a13a0033097fc9edb Mon Sep 17 00:00:00 2001 From: Tor Lillqvist Date: Tue, 22 Mar 2016 20:06:44 +0200 Subject: [PATCH] Use SSL here, too --- loolwsd/Connect.cpp | 45 +++++++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/loolwsd/Connect.cpp b/loolwsd/Connect.cpp index e0f82ea32..d53ae4346 100644 --- a/loolwsd/Connect.cpp +++ b/loolwsd/Connect.cpp @@ -12,25 +12,28 @@ #include #include -#include +#include +#include +#include #include #include +#include #include +#include #include +#include #include #include #include #include #include #include +#include #include #include #include #include #include -#include -#include -#include #include "Common.hpp" #include "LOOLProtocol.hpp" @@ -38,25 +41,26 @@ using namespace LOOLProtocol; -using Poco::Net::HTTPClientSession; +using Poco::Net::AcceptCertificateHandler; +using Poco::Net::Context; +using Poco::Net::HTTPSClientSession; using Poco::Net::HTTPRequest; using Poco::Net::HTTPResponse; +using Poco::Net::InvalidCertificateHandler; using Poco::Net::Socket; -using Poco::Net::SocketOutputStream; +using Poco::Net::SSLManager; using Poco::Net::StreamSocket; using Poco::Net::TCPServer; using Poco::Net::TCPServerConnection; using Poco::Net::WebSocket; using Poco::Net::WebSocketException; using Poco::Runnable; +using Poco::SharedPtr; using Poco::StringTokenizer; using Poco::TemporaryFile; using Poco::Thread; using Poco::URI; using Poco::Util::Application; -using Poco::Util::HelpFormatter; -using Poco::Util::Option; -using Poco::Util::OptionSet; class Output: public Runnable { @@ -113,7 +117,7 @@ class Connect: public Poco::Util::Application { public: Connect() : - _uri("http://127.0.0.1:" + std::to_string(DEFAULT_CLIENT_PORT_NUMBER) + "/ws") + _uri("https://127.0.0.1:" + std::to_string(DEFAULT_CLIENT_PORT_NUMBER) + "/ws") { } @@ -124,11 +128,24 @@ public: protected: int main(const std::vector& args) override { - if (args.size() > 0) - _uri = URI(args[0]); + if (args.size() < 1) + { + Log::error("Usage: connect documentURI [serverURI]"); + return Application::EXIT_USAGE; + } - HTTPClientSession cs(_uri.getHost(), _uri.getPort()); - HTTPRequest request(HTTPRequest::HTTP_GET, "/ws"); + if (args.size() > 1) + _uri = URI(args[1]); + + Poco::Net::initializeSSL(); + + SharedPtr invalidCertHandler = new AcceptCertificateHandler(false); + Context::Params sslParams; + Context::Ptr sslContext = new Poco::Net::Context(Poco::Net::Context::CLIENT_USE, sslParams); + SSLManager::instance().initializeClient(0, invalidCertHandler, sslContext); + + HTTPSClientSession cs(_uri.getHost(), _uri.getPort()); + HTTPRequest request(HTTPRequest::HTTP_GET, args[0]); HTTPResponse response; WebSocket ws(cs, request, response);