From b4665b9cd514a9c1ebbf78ac691fbeabefec3b23 Mon Sep 17 00:00:00 2001 From: XinyuHou Date: Thu, 2 Apr 2015 14:43:23 +0100 Subject: [PATCH] Passed args into client and socket Conflicts: src/lib/client/Client.cpp src/lib/client/Client.h src/lib/synergy/ClientApp.cpp src/test/integtests/net/NetworkTests.cpp --- src/lib/client/Client.cpp | 11 ++++++----- src/lib/client/Client.h | 5 +++-- src/lib/net/TCPSocket.h | 1 + src/lib/plugin/ns/SecureSocket.cpp | 8 ++++++-- src/lib/plugin/ns/SecureSocket.h | 3 ++- src/lib/synergy/ArgParser.cpp | 2 +- src/lib/synergy/ClientApp.cpp | 3 +-- src/lib/synergy/ClientArgs.cpp | 2 +- src/lib/synergy/ClientArgs.h | 2 +- src/test/integtests/net/NetworkTests.cpp | 24 +++++++++++++++++++----- 10 files changed, 41 insertions(+), 20 deletions(-) diff --git a/src/lib/client/Client.cpp b/src/lib/client/Client.cpp index 456260f0..43717134 100644 --- a/src/lib/client/Client.cpp +++ b/src/lib/client/Client.cpp @@ -60,8 +60,7 @@ Client::Client( const String& name, const NetworkAddress& address, ISocketFactory* socketFactory, synergy::Screen* screen, - bool enableDragDrop, - bool enableCrypto) : + ClientArgs args) : m_mock(false), m_name(name), m_serverAddress(address), @@ -77,9 +76,9 @@ Client::Client( m_events(events), m_sendFileThread(NULL), m_writeToDropDirThread(NULL), - m_enableDragDrop(enableDragDrop), m_socket(NULL), m_useSecureNetwork(false) + m_args(args) { assert(m_socketFactory != NULL); assert(m_screen != NULL); @@ -94,7 +93,7 @@ Client::Client( new TMethodEventJob(this, &Client::handleResume)); - if (m_enableDragDrop) { + if (m_args.m_enableDragDrop) { m_events->adoptHandler(m_events->forIScreen().fileChunkSending(), this, new TMethodEventJob(this, @@ -162,6 +161,7 @@ Client::connect() // create the socket IDataSocket* socket = m_socketFactory->create(m_useSecureNetwork); m_socket = dynamic_cast(socket); + m_socket->setFingerprintFilename(m_args.m_certFingerprintFilename); // filter socket messages, including a packetizing filter m_stream = socket; @@ -780,7 +780,8 @@ Client::fileChunkReceived(String data) void Client::dragInfoReceived(UInt32 fileNum, String data) { - if (!m_enableDragDrop) { + // TODO: fix duplicate function from CServer + if (!m_args.m_enableDragDrop) { LOG((CLOG_DEBUG "drag drop not enabled, ignoring drag info.")); return; } diff --git a/src/lib/client/Client.h b/src/lib/client/Client.h index f869ef64..12baadb4 100644 --- a/src/lib/client/Client.h +++ b/src/lib/client/Client.h @@ -23,6 +23,7 @@ #include "synergy/IClipboard.h" #include "synergy/DragInformation.h" #include "synergy/INode.h" +#include "synergy/ClientArgs.h" #include "net/NetworkAddress.h" #include "base/EventTypes.h" @@ -59,8 +60,7 @@ public: const String& name, const NetworkAddress& address, ISocketFactory* socketFactory, synergy::Screen* screen, - bool enableDragDrop, - bool enableCrypto); + ClientArgs args); ~Client(); #ifdef TEST_ENV @@ -227,4 +227,5 @@ private: bool m_enableDragDrop; TCPSocket* m_socket; bool m_useSecureNetwork; + ClientArgs m_args; }; diff --git a/src/lib/net/TCPSocket.h b/src/lib/net/TCPSocket.h index 832cd128..57bb0169 100644 --- a/src/lib/net/TCPSocket.h +++ b/src/lib/net/TCPSocket.h @@ -59,6 +59,7 @@ public: virtual void secureConnect() {} virtual void secureAccept() {} + virtual void setFingerprintFilename(CString& f) {} protected: ArchSocket getSocket() { return m_socket; } diff --git a/src/lib/plugin/ns/SecureSocket.cpp b/src/lib/plugin/ns/SecureSocket.cpp index 8821a3e6..de63e333 100644 --- a/src/lib/plugin/ns/SecureSocket.cpp +++ b/src/lib/plugin/ns/SecureSocket.cpp @@ -46,7 +46,7 @@ CSecureSocket::CSecureSocket( CSocketMultiplexer* socketMultiplexer) : CTCPSocket(events, socketMultiplexer), m_secureReady(false), - m_certFingerprint() + m_certFingerprintFilename() { } @@ -405,6 +405,10 @@ CSecureSocket::disconnect() bool CSecureSocket::verifyCertFingerprint() { + if (m_certFingerprintFilename.empty()) { + return false; + } + // calculate received certificate fingerprint X509 *cert = cert = SSL_get_peer_certificate(m_ssl->m_ssl); EVP_MD* tempDigest; @@ -426,7 +430,7 @@ CSecureSocket::verifyCertFingerprint() CString fileLine; CString certificateFingerprint; std::ifstream file; - file.open(m_certFingerprint.c_str()); + file.open(m_certFingerprintFilename.c_str()); while (!file.eof()) { getline(file,fileLine); diff --git a/src/lib/plugin/ns/SecureSocket.h b/src/lib/plugin/ns/SecureSocket.h index 725d5da9..7f3f0028 100644 --- a/src/lib/plugin/ns/SecureSocket.h +++ b/src/lib/plugin/ns/SecureSocket.h @@ -43,6 +43,7 @@ public: void secureConnect(); void secureAccept(); + void setFingerprintFilename(CString& f) { m_certFingerprintFilename = f; } bool isReady() const { return m_secureReady; } bool isSecureReady(); bool isSecure() { return true; } @@ -76,5 +77,5 @@ private: private: Ssl* m_ssl; bool m_secureReady; - CString m_certFingerprint; + CString m_certFingerprintFilename; }; diff --git a/src/lib/synergy/ArgParser.cpp b/src/lib/synergy/ArgParser.cpp index 7ba85752..82186b3a 100644 --- a/src/lib/synergy/ArgParser.cpp +++ b/src/lib/synergy/ArgParser.cpp @@ -91,7 +91,7 @@ ArgParser::parseClientArgs(ClientArgs& args, int argc, const char* const* argv) } else if (isArg(i, argc, argv, NULL, "--certificate-fingerprint", 1)) { // define scroll - args.m_certFingerprint = argv[++i]; + args.m_certFingerprintFilename = argv[++i]; } else { if (i + 1 == argc) { diff --git a/src/lib/synergy/ClientApp.cpp b/src/lib/synergy/ClientApp.cpp index b9c00414..f27a8331 100644 --- a/src/lib/synergy/ClientApp.cpp +++ b/src/lib/synergy/ClientApp.cpp @@ -342,8 +342,7 @@ ClientApp::openClient(const String& name, const NetworkAddress& address, address, new TCPSocketFactory(m_events, getSocketMultiplexer()), screen, - args().m_enableDragDrop, - args().m_enableCrypto); + args()); try { m_events->adoptHandler( diff --git a/src/lib/synergy/ClientArgs.cpp b/src/lib/synergy/ClientArgs.cpp index efbbd90b..133d5423 100644 --- a/src/lib/synergy/ClientArgs.cpp +++ b/src/lib/synergy/ClientArgs.cpp @@ -19,6 +19,6 @@ CClientArgs::CClientArgs() : m_yscroll(0), - m_certFingerprint() + m_certFingerprintFilename() { } diff --git a/src/lib/synergy/ClientArgs.h b/src/lib/synergy/ClientArgs.h index c9ddb9e9..947ca619 100644 --- a/src/lib/synergy/ClientArgs.h +++ b/src/lib/synergy/ClientArgs.h @@ -27,5 +27,5 @@ public: public: int m_yscroll; - CString m_certFingerprint; + CString m_certFingerprintFilename; }; diff --git a/src/test/integtests/net/NetworkTests.cpp b/src/test/integtests/net/NetworkTests.cpp index 7e3d3bd5..b307ff51 100644 --- a/src/test/integtests/net/NetworkTests.cpp +++ b/src/test/integtests/net/NetworkTests.cpp @@ -140,7 +140,11 @@ TEST_F(NetworkTests, sendToClient_mockData) ON_CALL(clientScreen, getShape(_, _, _, _)).WillByDefault(Invoke(getScreenShape)); ON_CALL(clientScreen, getCursorPos(_, _)).WillByDefault(Invoke(getCursorPos)); - Client client(&m_events, "stub", serverAddress, clientSocketFactory, &clientScreen, true, false); + + ClientArgs args; + args.m_enableDragDrop = true; + args.m_enableCrypto = false; + Client client(&m_events, "stub", serverAddress, clientSocketFactory, &clientScreen, args); m_events.adoptHandler( m_events.forIScreen().fileRecieveCompleted(), &client, @@ -192,7 +196,11 @@ TEST_F(NetworkTests, sendToClient_mockFile) ON_CALL(clientScreen, getShape(_, _, _, _)).WillByDefault(Invoke(getScreenShape)); ON_CALL(clientScreen, getCursorPos(_, _)).WillByDefault(Invoke(getCursorPos)); - Client client(&m_events, "stub", serverAddress, clientSocketFactory, &clientScreen, true, false); + + ClientArgs args; + args.m_enableDragDrop = true; + args.m_enableCrypto = false; + Client client(&m_events, "stub", serverAddress, clientSocketFactory, &clientScreen, args); m_events.adoptHandler( m_events.forIScreen().fileRecieveCompleted(), &client, @@ -238,7 +246,10 @@ TEST_F(NetworkTests, sendToServer_mockData) ON_CALL(clientScreen, getShape(_, _, _, _)).WillByDefault(Invoke(getScreenShape)); ON_CALL(clientScreen, getCursorPos(_, _)).WillByDefault(Invoke(getCursorPos)); - Client client(&m_events, "stub", serverAddress, clientSocketFactory, &clientScreen, true, false); + ClientArgs args; + args.m_enableDragDrop = true; + args.m_enableCrypto = false; + Client client(&m_events, "stub", serverAddress, clientSocketFactory, &clientScreen, args); m_events.adoptHandler( m_events.forClientListener().connected(), &listener, @@ -290,8 +301,11 @@ TEST_F(NetworkTests, sendToServer_mockFile) ON_CALL(clientScreen, getShape(_, _, _, _)).WillByDefault(Invoke(getScreenShape)); ON_CALL(clientScreen, getCursorPos(_, _)).WillByDefault(Invoke(getCursorPos)); - Client client(&m_events, "stub", serverAddress, clientSocketFactory, &clientScreen, true, false); - + ClientArgs args; + args.m_enableDragDrop = true; + args.m_enableCrypto = false; + Client client(&m_events, "stub", serverAddress, clientSocketFactory, &clientScreen, args); + m_events.adoptHandler( m_events.forClientListener().connected(), &listener, new TMethodEventJob(