diff --git a/src/lib/client/CServerProxy.h b/src/lib/client/CServerProxy.h index 5d1a9504..d0f589ed 100644 --- a/src/lib/client/CServerProxy.h +++ b/src/lib/client/CServerProxy.h @@ -57,7 +57,7 @@ public: //@} #ifdef TEST_ENV - void handleDataForTest() { handleData(NULL, NULL); } + void handleDataForTest() { handleData(CEvent(), NULL); } #endif protected: @@ -76,7 +76,7 @@ private: // modifier key translation KeyID translateKey(KeyID) const; - KeyModifierMask translateModifierMask(KeyModifierMask) const; + KeyModifierMask translateModifierMask(KeyModifierMask) const; // event handlers void handleData(const CEvent&, void*); @@ -110,7 +110,7 @@ private: typedef EResult (CServerProxy::*MessageParser)(const UInt8*); CClient* m_client; - synergy::IStream* m_stream; + synergy::IStream* m_stream; UInt32 m_seqNum; @@ -121,13 +121,13 @@ private: bool m_ignoreMouse; - KeyModifierID m_modifierTranslationTable[kKeyModifierIDLast]; + KeyModifierID m_modifierTranslationTable[kKeyModifierIDLast]; double m_keepAliveAlarm; - CEventQueueTimer* m_keepAliveAlarmTimer; + CEventQueueTimer* m_keepAliveAlarmTimer; - MessageParser m_parser; - IEventQueue* m_eventQueue; + MessageParser m_parser; + IEventQueue* m_eventQueue; }; #endif diff --git a/src/lib/synergy/CCryptoMode.cpp b/src/lib/synergy/CCryptoMode.cpp index 90d66537..dcc5b1ac 100644 --- a/src/lib/synergy/CCryptoMode.cpp +++ b/src/lib/synergy/CCryptoMode.cpp @@ -16,6 +16,7 @@ */ #include "CCryptoMode.h" +#include "XSynergy.h" using namespace CryptoPP; @@ -46,7 +47,7 @@ CCryptoMode::CCryptoMode(ECryptoMode mode, bool encryption) : break; default: - throw std::exception("crypto mode not set"); + throw XBadCryptoMode(); } } else { @@ -71,7 +72,7 @@ CCryptoMode::CCryptoMode(ECryptoMode mode, bool encryption) : break; default: - throw std::exception("crypto mode not set"); + throw XBadCryptoMode(); } } } diff --git a/src/lib/synergy/CCryptoMode.h b/src/lib/synergy/CCryptoMode.h index 6c3f52d5..9b7e8ada 100644 --- a/src/lib/synergy/CCryptoMode.h +++ b/src/lib/synergy/CCryptoMode.h @@ -17,8 +17,8 @@ #pragma once -#include -#include +#include +#include #include #include "ECryptoMode.h" #include "CString.h" @@ -50,7 +50,7 @@ private: typedef CryptoPP::CTR_Mode::Decryption CCtrModeDec; typedef CryptoPP::GCM::Decryption CGcmModeDec; - static CCryptoMode::ECryptoMode parseMode(CString& mode); + static ECryptoMode parseMode(CString& mode); ECryptoMode m_mode; void* m_crypto; diff --git a/src/lib/synergy/CCryptoOptions.cpp b/src/lib/synergy/CCryptoOptions.cpp index c87b8397..54a02bdd 100644 --- a/src/lib/synergy/CCryptoOptions.cpp +++ b/src/lib/synergy/CCryptoOptions.cpp @@ -16,6 +16,7 @@ */ #include "CCryptoOptions.h" +#include "XSynergy.h" CCryptoOptions::CCryptoOptions( const CString& modeString, @@ -48,6 +49,6 @@ CCryptoOptions::parseMode(CString modeString) return kGcm; } else { - throw std::exception("invalid crypto mode"); + throw XBadCryptoMode(); } } diff --git a/src/lib/synergy/CCryptoStream.cpp b/src/lib/synergy/CCryptoStream.cpp index e2e3b7e6..fe140242 100644 --- a/src/lib/synergy/CCryptoStream.cpp +++ b/src/lib/synergy/CCryptoStream.cpp @@ -15,12 +15,13 @@ * along with this program. If not, see . */ -#include "CCryptoStream.h" -#include "CLog.h" -#include -#include -#include "CCryptoOptions.h" - +#include "CCryptoStream.h" +#include "CLog.h" +#include "CCryptoOptions.h" +#include +#include +#include + using namespace CryptoPP; using namespace synergy::crypto; @@ -96,7 +97,7 @@ CCryptoStream::createKey(byte* out, const CString& password, UInt8 keyLength, UI assert(keyLength <= SHA256::DIGESTSIZE); byte temp[SHA256::DIGESTSIZE]; - byte* in = reinterpret_cast(const_cast(password.c_str())); + byte* in = reinterpret_cast(const_cast(password.c_str())); SHA256().CalculateDigest(temp, in, password.length()); byte* tempKey = new byte[SHA256::DIGESTSIZE]; @@ -119,28 +120,28 @@ CCryptoStream::setIv(const byte* iv) m_decryption.setKeyWithIv(m_key, kKeyLength, iv); } -void -CCryptoStream::newIv(byte* out) -{ - m_autoSeedRandomPool.GenerateBlock(out, CRYPTO_IV_SIZE); - setIv(out); -} - -void -CCryptoStream::logBuffer(const char* name, const byte* buf, int length) -{ - if (CLOG->getFilter() < kDEBUG4) { - return; - } - - std::stringstream ss; - ss << "crypto: " << name << ":"; - - char buffer[4]; - for (int i = 0; i < length; i++) { - sprintf(buffer, " %02X", buf[i]); - ss << buffer; - } - - LOG((CLOG_DEBUG4 "%s", ss.str().c_str())); +void +CCryptoStream::newIv(byte* out) +{ + m_autoSeedRandomPool.GenerateBlock(out, CRYPTO_IV_SIZE); + setIv(out); +} + +void +CCryptoStream::logBuffer(const char* name, const byte* buf, int length) +{ + if (CLOG->getFilter() < kDEBUG4) { + return; + } + + std::stringstream ss; + ss << "crypto: " << name << ":"; + + char buffer[4]; + for (int i = 0; i < length; i++) { + sprintf(buffer, " %02X", buf[i]); + ss << buffer; + } + + LOG((CLOG_DEBUG4 "%s", ss.str().c_str())); } diff --git a/src/lib/synergy/CCryptoStream.h b/src/lib/synergy/CCryptoStream.h index 8c606094..a19ed29e 100644 --- a/src/lib/synergy/CCryptoStream.h +++ b/src/lib/synergy/CCryptoStream.h @@ -18,11 +18,12 @@ #pragma once #include "BasicTypes.h" -#include "CStreamFilter.h" -#include "CCryptoMode.h" -#include "CCryptoOptions.h" +#include "CStreamFilter.h" +#include "CCryptoMode.h" #include -#include "cryptopp562/sha.h" +#include + +class CCryptoOptions; #define CRYPTO_IV_SIZE CryptoPP::AES::BLOCKSIZE @@ -51,8 +52,8 @@ public: */ virtual void write(const void* in, UInt32 n); - //! Set the IV - void setIv(const byte* iv); + //! Set the IV + void setIv(const byte* iv); //! Get a new IV /*! @@ -67,11 +68,11 @@ public: private: void logBuffer(const char* name, const byte* buf, int length); - byte* m_key; - CCryptoMode m_encryption; + byte* m_key; + CCryptoMode m_encryption; CCryptoMode m_decryption; CryptoPP::AutoSeededRandomPool m_autoSeedRandomPool; -}; +}; namespace synergy { namespace crypto { diff --git a/src/lib/synergy/XSynergy.cpp b/src/lib/synergy/XSynergy.cpp index e42cd43d..12738614 100644 --- a/src/lib/synergy/XSynergy.cpp +++ b/src/lib/synergy/XSynergy.cpp @@ -29,6 +29,15 @@ XBadClient::getWhat() const throw() return "XBadClient"; } +// +// XBadCryptoMode +// +CString +XBadCryptoMode::getWhat() const throw() +{ + return "XBadCryptoMode"; +} + // // XIncompatibleClient diff --git a/src/lib/synergy/XSynergy.h b/src/lib/synergy/XSynergy.h index ca763475..9fcf49fb 100644 --- a/src/lib/synergy/XSynergy.h +++ b/src/lib/synergy/XSynergy.h @@ -30,6 +30,12 @@ Thrown when the client fails to follow the protocol. */ XBASE_SUBCLASS_WHAT(XBadClient, XSynergy); +//! Bad crypto mode +/*! +Thrown when the user enters an invalid crypto mode. +*/ +XBASE_SUBCLASS_WHAT(XBadCryptoMode, XSynergy); + //! Incompatible client exception /*! Thrown when a client attempting to connect has an incompatible version. diff --git a/src/test/unittests/synergy/CCryptoStreamTests.cpp b/src/test/unittests/synergy/CCryptoStreamTests.cpp index 578379dd..12a38cae 100644 --- a/src/test/unittests/synergy/CCryptoStreamTests.cpp +++ b/src/test/unittests/synergy/CCryptoStreamTests.cpp @@ -20,6 +20,7 @@ #include "CMockStream.h" #include "CMockEventQueue.h" #include "CPacketStreamFilter.h" +#include "CCryptoOptions.h" using ::testing::_; using ::testing::Invoke; diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 831b1012..ad4f3fff 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -7,45 +7,47 @@ # # This package is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License -# along with this program. If not, see . +# along with this program. If not, see . set(cpp_dir cryptopp562) file(GLOB cpp_src ${cpp_dir}/*.cpp) if (WIN32) - file(GLOB cpp_hdr ${cpp_dir}/*.h) + file(GLOB cpp_hdr ${cpp_dir}/*.h) list(APPEND cpp_src ${cpp_hdr}) endif() file(GLOB cpp_ignore - ${cpp_dir}/simple.cpp - ${cpp_dir}/strciphr.cpp - ${cpp_dir}/polynomi.cpp - ${cpp_dir}/eprecomp.cpp - ${cpp_dir}/eccrypto.cpp - ${cpp_dir}/algebra.cpp) + ${cpp_dir}/simple.cpp + ${cpp_dir}/strciphr.cpp + ${cpp_dir}/polynomi.cpp + ${cpp_dir}/eprecomp.cpp + ${cpp_dir}/eccrypto.cpp + ${cpp_dir}/algebra.cpp) list(REMOVE_ITEM cpp_src ${cpp_ignore}) -# 64-bit windows - compile asm file. -if(CMAKE_CL_64) - list(APPEND cpp_src ${cpp_dir}/x64dll.asm ${cpp_dir}/x64masm.asm) - - add_custom_command(OUTPUT $(IntDir)x64dll.obj - COMMAND ml64.exe /c /nologo /Fo$(IntDir)x64dll.obj /Zi - "${CMAKE_CURRENT_SOURCE_DIR}/${cpp_dir}/x64dll.asm" - MAIN_DEPENDENCY ${cpp_dir}/x64dll.asm - VERBATIM) - - add_custom_command(OUTPUT $(IntDir)x64masm.obj - COMMAND ml64.exe /c /nologo /Fo$(IntDir)x64masm.obj /Zi - "${CMAKE_CURRENT_SOURCE_DIR}/${cpp_dir}/x64masm.asm" - MAIN_DEPENDENCY ${cpp_dir}/x64masm.asm - VERBATIM) +# if 64-bit windows, compile asm file. +if (CMAKE_CL_64) + list(APPEND cpp_src ${cpp_dir}/x64dll.asm ${cpp_dir}/x64masm.asm) + + add_custom_command(OUTPUT $(IntDir)x64dll.obj + COMMAND ml64.exe /c /nologo /Fo$(IntDir)x64dll.obj /Zi + "${CMAKE_CURRENT_SOURCE_DIR}/${cpp_dir}/x64dll.asm" + MAIN_DEPENDENCY ${cpp_dir}/x64dll.asm + VERBATIM) + + add_custom_command(OUTPUT $(IntDir)x64masm.obj + COMMAND ml64.exe /c /nologo /Fo$(IntDir)x64masm.obj /Zi + "${CMAKE_CURRENT_SOURCE_DIR}/${cpp_dir}/x64masm.asm" + MAIN_DEPENDENCY ${cpp_dir}/x64masm.asm + VERBATIM) +else() + add_definitions(-DCRYPTOPP_DISABLE_ASM) endif() if (APPLE)