deleted old home brew crypto #4313

This commit is contained in:
XinyuHou 2015-02-11 11:12:54 +00:00
parent 4fcec1d217
commit 80343c41eb
53 changed files with 352 additions and 1902 deletions

View File

@ -319,7 +319,6 @@ else() # not-unix
endif() endif()
add_subdirectory(src) add_subdirectory(src)
add_subdirectory(ext)
if (WIN32) if (WIN32)
# TODO: consider using /analyze to uncover potential bugs in the source code. # TODO: consider using /analyze to uncover potential bugs in the source code.

View File

@ -1,96 +0,0 @@
# synergy -- mouse and keyboard sharing utility
# Copyright (C) 2013 Synergy Si Ltd.
#
# This package is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# found in the file COPYING that should have accompanied this file.
#
# 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
# 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 <http://www.gnu.org/licenses/>.
set(cryptopp_dir cryptopp562)
# only compile the crypto++ files we need.
set(cryptopp_src
${cryptopp_dir}/3way.cpp
${cryptopp_dir}/algparam.cpp
${cryptopp_dir}/asn.cpp
${cryptopp_dir}/authenc.cpp
${cryptopp_dir}/basecode.cpp
${cryptopp_dir}/cpu.cpp
${cryptopp_dir}/cryptlib.cpp
${cryptopp_dir}/des.cpp
${cryptopp_dir}/dessp.cpp
${cryptopp_dir}/dll.cpp
${cryptopp_dir}/ec2n.cpp
${cryptopp_dir}/ecp.cpp
${cryptopp_dir}/filters.cpp
${cryptopp_dir}/fips140.cpp
${cryptopp_dir}/gcm.cpp
${cryptopp_dir}/gf2n.cpp
${cryptopp_dir}/gfpcrypt.cpp
${cryptopp_dir}/hex.cpp
${cryptopp_dir}/hmac.cpp
${cryptopp_dir}/hrtimer.cpp
${cryptopp_dir}/integer.cpp
${cryptopp_dir}/iterhash.cpp
${cryptopp_dir}/misc.cpp
${cryptopp_dir}/modes.cpp
${cryptopp_dir}/mqueue.cpp
${cryptopp_dir}/nbtheory.cpp
${cryptopp_dir}/oaep.cpp
${cryptopp_dir}/osrng.cpp
${cryptopp_dir}/pubkey.cpp
${cryptopp_dir}/queue.cpp
${cryptopp_dir}/randpool.cpp
${cryptopp_dir}/rdtables.cpp
${cryptopp_dir}/rijndael.cpp
${cryptopp_dir}/rng.cpp
${cryptopp_dir}/sha.cpp
)
# if 64-bit windows, compile asm file.
if (CMAKE_CL_64)
list(APPEND cryptopp_src ${cryptopp_dir}/x64dll.asm ${cryptopp_dir}/x64masm.asm)
add_custom_command(OUTPUT $(IntDir)x64dll.obj
COMMAND ml64.exe /c /nologo /Fo$(IntDir)x64dll.obj /Zi
"${CMAKE_CURRENT_SOURCE_DIR}/${cryptopp_dir}/x64dll.asm"
MAIN_DEPENDENCY ${cryptopp_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}/${cryptopp_dir}/x64masm.asm"
MAIN_DEPENDENCY ${cryptopp_dir}/x64masm.asm
VERBATIM)
endif()
if (UNIX)
add_definitions(-DCRYPTOPP_DISABLE_ASM)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O2 -pipe")
if (APPLE)
if (DARWIN_VERSION GREATER 10)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-tautological-compare")
endif()
else()
set(CRYPTOPP_ARCH "native")
if ("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "^arm.*")
set(CRYPTOPP_ARCH "armv6zk")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=${CRYPTOPP_ARCH}")
endif()
endif()
add_library(cryptopp STATIC ${cryptopp_src})
if (UNIX)
# ignore warnings in crypto++
set_target_properties(cryptopp PROPERTIES COMPILE_FLAGS "-w")
endif()

Binary file not shown.

View File

@ -247,9 +247,6 @@ class InternalCommands:
# by default, unknown # by default, unknown
macIdentity = None macIdentity = None
# cryptoPP dir with version number
cryptoPPDir = 'cryptopp562'
# gtest dir with version number # gtest dir with version number
gtestDir = 'gtest-1.6.0' gtestDir = 'gtest-1.6.0'
@ -320,22 +317,6 @@ class InternalCommands:
for target in targets: for target in targets:
self.configure(target) self.configure(target)
def checkCryptoPP(self):
dir = self.extDir + '/' + self.cryptoPPDir
if (os.path.isdir(dir)):
return
zipFilename = dir + '.zip'
if (not os.path.exists(zipFilename)):
raise Exception('Crypto++ zip not found at: ' + zipFilename)
if not os.path.exists(dir):
os.mkdir(dir)
zip = zipfile.ZipFile(zipFilename)
self.zipExtractAll(zip, dir)
def checkGTest(self): def checkGTest(self):
dir = self.extDir + '/' + self.gtestDir dir = self.extDir + '/' + self.gtestDir
@ -464,8 +445,6 @@ class InternalCommands:
# if not visual studio, use parent dir # if not visual studio, use parent dir
sourceDir = generator.getSourceDir() sourceDir = generator.getSourceDir()
# ensure that the cryptopp source exists
self.checkCryptoPP()
self.checkGTest() self.checkGTest()
self.checkGMock() self.checkGMock()

View File

@ -58,7 +58,7 @@ endif()
add_executable(synergyc ${sources}) add_executable(synergyc ${sources})
target_link_libraries(synergyc target_link_libraries(synergyc
arch base client common io mt net ipc platform server synergy cryptopp ${libs}) arch base client common io mt net ipc platform server synergy ${libs})
if (CONF_CPACK) if (CONF_CPACK)
install(TARGETS install(TARGETS

View File

@ -35,7 +35,7 @@ else()
endif() endif()
target_link_libraries(synergyd target_link_libraries(synergyd
arch base common io ipc mt net platform synergy cryptopp ${libs}) arch base common io ipc mt net platform synergy ${libs})
if (CONF_CPACK) if (CONF_CPACK)
install(TARGETS install(TARGETS

View File

@ -63,7 +63,7 @@ else()
endif() endif()
target_link_libraries(synergyp target_link_libraries(synergyp
arch base client common io mt net ipc platform server synergy client cryptopp ${libs}) arch base client common io mt net ipc platform server synergy client ${libs})
if (CONF_CPACK) if (CONF_CPACK)
install(TARGETS install(TARGETS

View File

@ -58,7 +58,7 @@ endif()
add_executable(synergys ${sources}) add_executable(synergys ${sources})
target_link_libraries(synergys target_link_libraries(synergys
arch base client common io mt net ipc platform server synergy cryptopp ${libs}) arch base client common io mt net ipc platform server synergy ${libs})
if (CONF_CPACK) if (CONF_CPACK)
install(TARGETS install(TARGETS

View File

@ -29,7 +29,7 @@ endif()
add_executable(syntool ${sources}) add_executable(syntool ${sources})
target_link_libraries(syntool target_link_libraries(syntool
synergy arch base client common io ipc mt net platform server cryptopp ${libs}) synergy arch base client common io ipc mt net platform server ${libs})
if (CONF_CPACK) if (CONF_CPACK)
install(TARGETS install(TARGETS

View File

@ -1,353 +1,326 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0"> <ui version="4.0">
<class>SettingsDialogBase</class> <class>SettingsDialogBase</class>
<widget class="QDialog" name="SettingsDialogBase"> <widget class="QDialog" name="SettingsDialogBase">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>368</width> <width>368</width>
<height>354</height> <height>377</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>Settings</string> <string>Settings</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<widget class="QGroupBox" name="m_pGroupAdvanced"> <widget class="QGroupBox" name="m_pGroupAdvanced">
<property name="title"> <property name="title">
<string>&amp;Miscellaneous</string> <string>&amp;Miscellaneous</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout_3"> <layout class="QGridLayout" name="gridLayout_3">
<item row="1" column="0"> <item row="1" column="0">
<widget class="QLabel" name="m_pLabel_19"> <widget class="QLabel" name="m_pLabel_19">
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>75</width> <width>75</width>
<height>0</height> <height>0</height>
</size> </size>
</property> </property>
<property name="text"> <property name="text">
<string>Sc&amp;reen name:</string> <string>Sc&amp;reen name:</string>
</property> </property>
<property name="buddy"> <property name="buddy">
<cstring>m_pLineEditScreenName</cstring> <cstring>m_pLineEditScreenName</cstring>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="1"> <item row="1" column="1">
<widget class="QLineEdit" name="m_pLineEditScreenName"> <widget class="QLineEdit" name="m_pLineEditScreenName">
<property name="enabled"> <property name="enabled">
<bool>true</bool> <bool>true</bool>
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="0"> <item row="2" column="0">
<widget class="QLabel" name="m_pLabel_20"> <widget class="QLabel" name="m_pLabel_20">
<property name="text"> <property name="text">
<string>P&amp;ort:</string> <string>P&amp;ort:</string>
</property> </property>
<property name="buddy"> <property name="buddy">
<cstring>m_pSpinBoxPort</cstring> <cstring>m_pSpinBoxPort</cstring>
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="1"> <item row="2" column="1">
<widget class="QSpinBox" name="m_pSpinBoxPort"> <widget class="QSpinBox" name="m_pSpinBoxPort">
<property name="enabled"> <property name="enabled">
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed"> <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="maximum"> <property name="maximum">
<number>65535</number> <number>65535</number>
</property> </property>
<property name="value"> <property name="value">
<number>24800</number> <number>24800</number>
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="0"> <item row="3" column="0">
<widget class="QLabel" name="m_pLabel_21"> <widget class="QLabel" name="m_pLabel_21">
<property name="text"> <property name="text">
<string>&amp;Interface:</string> <string>&amp;Interface:</string>
</property> </property>
<property name="buddy"> <property name="buddy">
<cstring>m_pLineEditInterface</cstring> <cstring>m_pLineEditInterface</cstring>
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="1"> <item row="3" column="1">
<widget class="QLineEdit" name="m_pLineEditInterface"> <widget class="QLineEdit" name="m_pLineEditInterface">
<property name="enabled"> <property name="enabled">
<bool>true</bool> <bool>true</bool>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="0"> <item row="0" column="0">
<widget class="QLabel" name="m_pLabel_27"> <widget class="QLabel" name="m_pLabel_27">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred"> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>75</width> <width>75</width>
<height>0</height> <height>0</height>
</size> </size>
</property> </property>
<property name="text"> <property name="text">
<string>&amp;Language:</string> <string>&amp;Language:</string>
</property> </property>
<property name="buddy"> <property name="buddy">
<cstring>m_pComboLanguage</cstring> <cstring>m_pComboLanguage</cstring>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1"> <item row="0" column="1">
<widget class="QComboBox" name="m_pComboLanguage"/> <widget class="QComboBox" name="m_pComboLanguage"/>
</item> </item>
<item row="4" column="0"> <item row="4" column="0">
<widget class="QCheckBox" name="m_pCheckBoxElevateMode"> <widget class="QCheckBox" name="m_pCheckBoxElevateMode">
<property name="text"> <property name="text">
<string>Elevate mode</string> <string>Elevate mode</string>
</property> </property>
</widget> </widget>
</item> </item>
</layout> </layout>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QGroupBox" name="m_pGroupCrypto"> <widget class="QGroupBox" name="m_pGroupCrypto">
<property name="enabled"> <property name="enabled">
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred"> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="title"> <property name="title">
<string>&amp;Encryption</string> <string>&amp;Encryption</string>
</property> </property>
<layout class="QFormLayout" name="formLayout"> <layout class="QFormLayout" name="formLayout">
<property name="fieldGrowthPolicy"> <property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum> <enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property> </property>
<item row="1" column="0"> <item row="0" column="0">
<widget class="QLabel" name="m_pLabel_23"> <widget class="QCheckBox" name="m_pCheckBoxEnableCrypto">
<property name="minimumSize"> <property name="text">
<size> <string>Enable</string>
<width>75</width> </property>
<height>0</height> </widget>
</size> </item>
</property> </layout>
<property name="text"> </widget>
<string>Pass&amp;word:</string> </item>
</property> <item>
<property name="buddy"> <widget class="QGroupBox" name="m_pGroupLog">
<cstring>m_pLineEditCryptoPass</cstring> <property name="sizePolicy">
</property> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
</widget> <horstretch>0</horstretch>
</item> <verstretch>0</verstretch>
<item row="1" column="1"> </sizepolicy>
<widget class="QLineEdit" name="m_pLineEditCryptoPass"> </property>
<property name="enabled"> <property name="title">
<bool>false</bool> <string>Logging</string>
</property> </property>
<property name="echoMode"> <property name="alignment">
<enum>QLineEdit::Password</enum> <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property> </property>
</widget> <property name="flat">
</item> <bool>false</bool>
<item row="0" column="0"> </property>
<widget class="QCheckBox" name="m_pCheckBoxEnableCrypto"> <layout class="QGridLayout" name="gridLayout_2">
<property name="text"> <item row="0" column="0">
<string>Enable</string> <widget class="QLabel" name="m_pLabel_3">
</property> <property name="minimumSize">
</widget> <size>
</item> <width>75</width>
</layout> <height>0</height>
</widget> </size>
</item> </property>
<item> <property name="text">
<widget class="QGroupBox" name="m_pGroupLog"> <string>&amp;Logging level:</string>
<property name="sizePolicy"> </property>
<sizepolicy hsizetype="Preferred" vsizetype="Preferred"> <property name="buddy">
<horstretch>0</horstretch> <cstring>m_pComboLogLevel</cstring>
<verstretch>0</verstretch> </property>
</sizepolicy> </widget>
</property> </item>
<property name="title"> <item row="0" column="1" colspan="2">
<string>Logging</string> <widget class="QComboBox" name="m_pComboLogLevel">
</property> <item>
<property name="alignment"> <property name="text">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set> <string>Error</string>
</property> </property>
<property name="flat"> </item>
<bool>false</bool> <item>
</property> <property name="text">
<layout class="QGridLayout" name="gridLayout_2"> <string>Warning</string>
<item row="0" column="0"> </property>
<widget class="QLabel" name="m_pLabel_3"> </item>
<property name="minimumSize"> <item>
<size> <property name="text">
<width>75</width> <string>Note</string>
<height>0</height> </property>
</size> </item>
</property> <item>
<property name="text"> <property name="text">
<string>&amp;Logging level:</string> <string>Info</string>
</property> </property>
<property name="buddy"> </item>
<cstring>m_pComboLogLevel</cstring> <item>
</property> <property name="text">
</widget> <string>Debug</string>
</item> </property>
<item row="0" column="1" colspan="2"> </item>
<widget class="QComboBox" name="m_pComboLogLevel"> <item>
<item> <property name="text">
<property name="text"> <string>Debug1</string>
<string>Error</string> </property>
</property> </item>
</item> <item>
<item> <property name="text">
<property name="text"> <string>Debug2</string>
<string>Warning</string> </property>
</property> </item>
</item> </widget>
<item> </item>
<property name="text"> <item row="1" column="0">
<string>Note</string> <widget class="QCheckBox" name="m_pCheckBoxLogToFile">
</property> <property name="text">
</item> <string>Log to file:</string>
<item> </property>
<property name="text"> </widget>
<string>Info</string> </item>
</property> <item row="1" column="1">
</item> <widget class="QLineEdit" name="m_pLineEditLogFilename">
<item> <property name="enabled">
<property name="text"> <bool>false</bool>
<string>Debug</string> </property>
</property> </widget>
</item> </item>
<item> <item row="1" column="2">
<property name="text"> <widget class="QPushButton" name="m_pButtonBrowseLog">
<string>Debug1</string> <property name="enabled">
</property> <bool>false</bool>
</item> </property>
<item> <property name="text">
<property name="text"> <string>Browse...</string>
<string>Debug2</string> </property>
</property> </widget>
</item> </item>
</widget> </layout>
</item> </widget>
<item row="1" column="0"> </item>
<widget class="QCheckBox" name="m_pCheckBoxLogToFile"> <item>
<property name="text"> <spacer name="verticalSpacer">
<string>Log to file:</string> <property name="orientation">
</property> <enum>Qt::Vertical</enum>
</widget> </property>
</item> <property name="sizeHint" stdset="0">
<item row="1" column="1"> <size>
<widget class="QLineEdit" name="m_pLineEditLogFilename"> <width>20</width>
<property name="enabled"> <height>40</height>
<bool>false</bool> </size>
</property> </property>
</widget> </spacer>
</item> </item>
<item row="1" column="2"> <item>
<widget class="QPushButton" name="m_pButtonBrowseLog"> <widget class="QDialogButtonBox" name="buttonBox">
<property name="enabled"> <property name="orientation">
<bool>false</bool> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="text"> <property name="standardButtons">
<string>Browse...</string> <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property> </property>
</widget> </widget>
</item> </item>
</layout> </layout>
</widget> </widget>
</item> <tabstops>
<item> <tabstop>m_pComboLanguage</tabstop>
<spacer name="verticalSpacer"> <tabstop>m_pLineEditScreenName</tabstop>
<property name="orientation"> <tabstop>m_pSpinBoxPort</tabstop>
<enum>Qt::Vertical</enum> <tabstop>m_pLineEditInterface</tabstop>
</property> <tabstop>m_pComboLogLevel</tabstop>
<property name="sizeHint" stdset="0"> <tabstop>m_pCheckBoxLogToFile</tabstop>
<size> <tabstop>m_pLineEditLogFilename</tabstop>
<width>20</width> <tabstop>m_pButtonBrowseLog</tabstop>
<height>40</height> <tabstop>buttonBox</tabstop>
</size> </tabstops>
</property> <resources/>
</spacer> <connections>
</item> <connection>
<item> <sender>buttonBox</sender>
<widget class="QDialogButtonBox" name="buttonBox"> <signal>accepted()</signal>
<property name="orientation"> <receiver>SettingsDialogBase</receiver>
<enum>Qt::Horizontal</enum> <slot>accept()</slot>
</property> <hints>
<property name="standardButtons"> <hint type="sourcelabel">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> <x>266</x>
</property> <y>340</y>
</widget> </hint>
</item> <hint type="destinationlabel">
</layout> <x>157</x>
</widget> <y>274</y>
<tabstops> </hint>
<tabstop>m_pComboLanguage</tabstop> </hints>
<tabstop>m_pLineEditScreenName</tabstop> </connection>
<tabstop>m_pSpinBoxPort</tabstop> <connection>
<tabstop>m_pLineEditInterface</tabstop> <sender>buttonBox</sender>
<tabstop>m_pLineEditCryptoPass</tabstop> <signal>rejected()</signal>
<tabstop>m_pComboLogLevel</tabstop> <receiver>SettingsDialogBase</receiver>
<tabstop>m_pCheckBoxLogToFile</tabstop> <slot>reject()</slot>
<tabstop>m_pLineEditLogFilename</tabstop> <hints>
<tabstop>m_pButtonBrowseLog</tabstop> <hint type="sourcelabel">
<tabstop>buttonBox</tabstop> <x>334</x>
</tabstops> <y>340</y>
<resources/> </hint>
<connections> <hint type="destinationlabel">
<connection> <x>286</x>
<sender>buttonBox</sender> <y>274</y>
<signal>accepted()</signal> </hint>
<receiver>SettingsDialogBase</receiver> </hints>
<slot>accept()</slot> </connection>
<hints> </connections>
<hint type="sourcelabel"> </ui>
<x>266</x>
<y>340</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>SettingsDialogBase</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>334</x>
<y>340</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -53,7 +53,6 @@ AppConfig::AppConfig(QSettings* settings) :
m_Interface(), m_Interface(),
m_LogLevel(0), m_LogLevel(0),
m_WizardLastRun(0), m_WizardLastRun(0),
m_CryptoPass(),
m_ProcessMode(DEFAULT_PROCESS_MODE), m_ProcessMode(DEFAULT_PROCESS_MODE),
m_AutoConfig(true), m_AutoConfig(true),
m_ElevateMode(false), m_ElevateMode(false),
@ -121,8 +120,6 @@ void AppConfig::loadSettings()
m_LogToFile = settings().value("logToFile", false).toBool(); m_LogToFile = settings().value("logToFile", false).toBool();
m_LogFilename = settings().value("logFilename", synergyLogDir() + "synergy.log").toString(); m_LogFilename = settings().value("logFilename", synergyLogDir() + "synergy.log").toString();
m_WizardLastRun = settings().value("wizardLastRun", 0).toInt(); m_WizardLastRun = settings().value("wizardLastRun", 0).toInt();
m_CryptoPass = settings().value("cryptoPass", "").toString();
m_CryptoEnabled = settings().value("cryptoEnabled", false).toBool();
m_Language = settings().value("language", QLocale::system().name()).toString(); m_Language = settings().value("language", QLocale::system().name()).toString();
m_StartedBefore = settings().value("startedBefore", false).toBool(); m_StartedBefore = settings().value("startedBefore", false).toBool();
m_AutoConfig = settings().value("autoConfig", true).toBool(); m_AutoConfig = settings().value("autoConfig", true).toBool();
@ -142,8 +139,6 @@ void AppConfig::saveSettings()
settings().setValue("logToFile", m_LogToFile); settings().setValue("logToFile", m_LogToFile);
settings().setValue("logFilename", m_LogFilename); settings().setValue("logFilename", m_LogFilename);
settings().setValue("wizardLastRun", kWizardVersion); settings().setValue("wizardLastRun", kWizardVersion);
settings().setValue("cryptoPass", m_CryptoPass);
settings().setValue("cryptoEnabled", m_CryptoEnabled);
settings().setValue("language", m_Language); settings().setValue("language", m_Language);
settings().setValue("startedBefore", m_StartedBefore); settings().setValue("startedBefore", m_StartedBefore);
settings().setValue("autoConfig", m_AutoConfig); settings().setValue("autoConfig", m_AutoConfig);
@ -154,22 +149,6 @@ void AppConfig::saveSettings()
settings().setValue("userToken", m_UserToken); settings().setValue("userToken", m_UserToken);
} }
void AppConfig::setCryptoPass(const QString &s)
{
// clear field to user doesn't get confused.
if (s.isEmpty())
{
m_CryptoPass.clear();
return;
}
// only hash if password changes -- don't re-hash the hash.
if (m_CryptoPass != s)
{
m_CryptoPass = hash(s);
}
}
void AppConfig::setAutoConfig(bool autoConfig) void AppConfig::setAutoConfig(bool autoConfig)
{ {
m_AutoConfig = autoConfig; m_AutoConfig = autoConfig;

View File

@ -61,9 +61,6 @@ class AppConfig
const QString& logFilename() const { return m_LogFilename; } const QString& logFilename() const { return m_LogFilename; }
const QString logFilenameCmd() const; const QString logFilenameCmd() const;
QString logLevelText() const; QString logLevelText() const;
const QString& cryptoPass() const { return m_CryptoPass; }
bool cryptoEnabled() const { return m_CryptoEnabled; }
QString cryptoModeString() const;
ProcessMode processMode() const { return m_ProcessMode; } ProcessMode processMode() const { return m_ProcessMode; }
bool wizardShouldRun() const { return m_WizardLastRun < kWizardVersion; } bool wizardShouldRun() const { return m_WizardLastRun < kWizardVersion; }
const QString& language() const { return m_Language; } const QString& language() const { return m_Language; }
@ -96,7 +93,6 @@ class AppConfig
void setLogLevel(int i) { m_LogLevel = i; } void setLogLevel(int i) { m_LogLevel = i; }
void setLogToFile(bool b) { m_LogToFile = b; } void setLogToFile(bool b) { m_LogToFile = b; }
void setLogFilename(const QString& s) { m_LogFilename = s; } void setLogFilename(const QString& s) { m_LogFilename = s; }
void setCryptoEnabled(bool b) { m_CryptoEnabled = b; }
void setWizardHasRun() { m_WizardLastRun = kWizardVersion; } void setWizardHasRun() { m_WizardLastRun = kWizardVersion; }
void setLanguage(const QString language) { m_Language = language; } void setLanguage(const QString language) { m_Language = language; }
void setStartedBefore(bool b) { m_StartedBefore = b; } void setStartedBefore(bool b) { m_StartedBefore = b; }
@ -105,8 +101,6 @@ class AppConfig
void loadSettings(); void loadSettings();
void saveSettings(); void saveSettings();
void setCryptoPass(const QString& s);
private: private:
QSettings* m_pSettings; QSettings* m_pSettings;
QString m_ScreenName; QString m_ScreenName;
@ -116,8 +110,6 @@ class AppConfig
bool m_LogToFile; bool m_LogToFile;
QString m_LogFilename; QString m_LogFilename;
int m_WizardLastRun; int m_WizardLastRun;
bool m_CryptoEnabled;
QString m_CryptoPass;
ProcessMode m_ProcessMode; ProcessMode m_ProcessMode;
QString m_Language; QString m_Language;
bool m_StartedBefore; bool m_StartedBefore;

View File

@ -418,11 +418,6 @@ void MainWindow::startSynergy()
args << "--name" << getScreenName(); args << "--name" << getScreenName();
if (appConfig().cryptoEnabled())
{
args << "--crypto-pass" << appConfig().cryptoPass();
}
if (desktopMode) if (desktopMode)
{ {
setSynergyProcess(new QProcess(this)); setSynergyProcess(new QProcess(this));

View File

@ -43,12 +43,7 @@ SettingsDialog::SettingsDialog(QWidget* parent, AppConfig& config) :
m_pComboLogLevel->setCurrentIndex(appConfig().logLevel()); m_pComboLogLevel->setCurrentIndex(appConfig().logLevel());
m_pCheckBoxLogToFile->setChecked(appConfig().logToFile()); m_pCheckBoxLogToFile->setChecked(appConfig().logToFile());
m_pLineEditLogFilename->setText(appConfig().logFilename()); m_pLineEditLogFilename->setText(appConfig().logFilename());
m_pCheckBoxEnableCrypto->setChecked(appConfig().cryptoEnabled());
setIndexFromItemData(m_pComboLanguage, appConfig().language()); setIndexFromItemData(m_pComboLanguage, appConfig().language());
if (appConfig().cryptoEnabled())
{
m_pLineEditCryptoPass->setText(appConfig().cryptoPass());
}
#if defined(Q_OS_WIN) #if defined(Q_OS_WIN)
m_SuppressElevateWarning = true; m_SuppressElevateWarning = true;
@ -62,26 +57,12 @@ SettingsDialog::SettingsDialog(QWidget* parent, AppConfig& config) :
void SettingsDialog::accept() void SettingsDialog::accept()
{ {
const QString& cryptoPass = m_pLineEditCryptoPass->text();
bool cryptoEnabled = m_pCheckBoxEnableCrypto->isChecked();
if (cryptoEnabled && cryptoPass.isEmpty())
{
QMessageBox message;
message.setWindowTitle("Settings");
message.setIcon(QMessageBox::Information);
message.setText(tr("Encryption password must not be empty."));
message.exec();
return;
}
appConfig().setScreenName(m_pLineEditScreenName->text()); appConfig().setScreenName(m_pLineEditScreenName->text());
appConfig().setPort(m_pSpinBoxPort->value()); appConfig().setPort(m_pSpinBoxPort->value());
appConfig().setInterface(m_pLineEditInterface->text()); appConfig().setInterface(m_pLineEditInterface->text());
appConfig().setLogLevel(m_pComboLogLevel->currentIndex()); appConfig().setLogLevel(m_pComboLogLevel->currentIndex());
appConfig().setLogToFile(m_pCheckBoxLogToFile->isChecked()); appConfig().setLogToFile(m_pCheckBoxLogToFile->isChecked());
appConfig().setLogFilename(m_pLineEditLogFilename->text()); appConfig().setLogFilename(m_pLineEditLogFilename->text());
appConfig().setCryptoEnabled(cryptoEnabled);
appConfig().setCryptoPass(cryptoPass);
appConfig().setLanguage(m_pComboLanguage->itemData(m_pComboLanguage->currentIndex()).toString()); appConfig().setLanguage(m_pComboLanguage->itemData(m_pComboLanguage->currentIndex()).toString());
appConfig().setElevateMode(m_pCheckBoxElevateMode->isChecked()); appConfig().setElevateMode(m_pCheckBoxElevateMode->isChecked());
appConfig().saveSettings(); appConfig().saveSettings();
@ -141,13 +122,6 @@ void SettingsDialog::on_m_pButtonBrowseLog_clicked()
void SettingsDialog::on_m_pCheckBoxEnableCrypto_stateChanged(int ) void SettingsDialog::on_m_pCheckBoxEnableCrypto_stateChanged(int )
{ {
bool cryptoEnabled = m_pCheckBoxEnableCrypto->isChecked();
m_pLineEditCryptoPass->setEnabled(cryptoEnabled);
if (!cryptoEnabled)
{
m_pLineEditCryptoPass->clear();
}
} }
void SettingsDialog::on_m_pComboLanguage_currentIndexChanged(int index) void SettingsDialog::on_m_pComboLanguage_currentIndexChanged(int index)

View File

@ -30,7 +30,6 @@
#include "synergy/FileChunker.h" #include "synergy/FileChunker.h"
#include "synergy/IPlatformScreen.h" #include "synergy/IPlatformScreen.h"
#include "mt/Thread.h" #include "mt/Thread.h"
#include "io/CryptoStream.h"
#include "net/TCPSocket.h" #include "net/TCPSocket.h"
#include "net/IDataSocket.h" #include "net/IDataSocket.h"
#include "net/ISocketFactory.h" #include "net/ISocketFactory.h"
@ -61,7 +60,6 @@ Client::Client(
const String& name, const NetworkAddress& address, const String& name, const NetworkAddress& address,
ISocketFactory* socketFactory, ISocketFactory* socketFactory,
synergy::Screen* screen, synergy::Screen* screen,
const CryptoOptions& crypto,
bool enableDragDrop) : bool enableDragDrop) :
m_mock(false), m_mock(false),
m_name(name), m_name(name),
@ -76,8 +74,6 @@ Client::Client(
m_suspended(false), m_suspended(false),
m_connectOnResume(false), m_connectOnResume(false),
m_events(events), m_events(events),
m_cryptoStream(NULL),
m_crypto(crypto),
m_sendFileThread(NULL), m_sendFileThread(NULL),
m_writeToDropDirThread(NULL), m_writeToDropDirThread(NULL),
m_enableDragDrop(enableDragDrop), m_enableDragDrop(enableDragDrop),
@ -165,12 +161,6 @@ Client::connect()
bool adopt = !m_useSecureNetwork; bool adopt = !m_useSecureNetwork;
m_stream = new PacketStreamFilter(m_events, m_stream, adopt); m_stream = new PacketStreamFilter(m_events, m_stream, adopt);
if (m_crypto.m_mode != kDisabled) {
m_cryptoStream = new CryptoStream(
m_events, m_stream, m_crypto, true);
m_stream = m_cryptoStream;
}
// connect // connect
LOG((CLOG_DEBUG1 "connecting to server")); LOG((CLOG_DEBUG1 "connecting to server"));
setupConnecting(); setupConnecting();
@ -211,14 +201,6 @@ Client::handshakeComplete()
sendEvent(m_events->forClient().connected(), NULL); sendEvent(m_events->forClient().connected(), NULL);
} }
void
Client::setDecryptIv(const UInt8* iv)
{
if (m_cryptoStream != NULL) {
m_cryptoStream->setDecryptIv(iv);
}
}
bool bool
Client::isConnected() const Client::isConnected() const
{ {

View File

@ -24,7 +24,6 @@
#include "synergy/DragInformation.h" #include "synergy/DragInformation.h"
#include "synergy/INode.h" #include "synergy/INode.h"
#include "net/NetworkAddress.h" #include "net/NetworkAddress.h"
#include "io/CryptoOptions.h"
#include "base/EventTypes.h" #include "base/EventTypes.h"
class EventQueueTimer; class EventQueueTimer;
@ -34,7 +33,6 @@ class IDataSocket;
class ISocketFactory; class ISocketFactory;
namespace synergy { class IStream; } namespace synergy { class IStream; }
class IEventQueue; class IEventQueue;
class CryptoStream;
class Thread; class Thread;
class TCPSocket; class TCPSocket;
@ -61,7 +59,6 @@ public:
const String& name, const NetworkAddress& address, const String& name, const NetworkAddress& address,
ISocketFactory* socketFactory, ISocketFactory* socketFactory,
synergy::Screen* screen, synergy::Screen* screen,
const CryptoOptions& crypto,
bool enableDragDrop); bool enableDragDrop);
~Client(); ~Client();
@ -91,9 +88,6 @@ public:
*/ */
virtual void handshakeComplete(); virtual void handshakeComplete();
//! Set crypto IV for decryption
virtual void setDecryptIv(const UInt8* iv);
//! Clears the file buffer //! Clears the file buffer
void clearReceivedFileData(); void clearReceivedFileData();
@ -223,8 +217,6 @@ private:
IClipboard::Time m_timeClipboard[kClipboardEnd]; IClipboard::Time m_timeClipboard[kClipboardEnd];
String m_dataClipboard[kClipboardEnd]; String m_dataClipboard[kClipboardEnd];
IEventQueue* m_events; IEventQueue* m_events;
CryptoStream* m_cryptoStream;
CryptoOptions m_crypto;
std::size_t m_expectedFileSize; std::size_t m_expectedFileSize;
String m_receivedFileData; String m_receivedFileData;
DragFileList m_dragFileList; DragFileList m_dragFileList;

View File

@ -24,7 +24,6 @@
#include "synergy/option_types.h" #include "synergy/option_types.h"
#include "synergy/protocol_types.h" #include "synergy/protocol_types.h"
#include "io/IStream.h" #include "io/IStream.h"
#include "io/CryptoStream.h"
#include "base/Log.h" #include "base/Log.h"
#include "base/IEventQueue.h" #include "base/IEventQueue.h"
#include "base/TMethodEventJob.h" #include "base/TMethodEventJob.h"
@ -295,10 +294,6 @@ ServerProxy::parseMessage(const UInt8* code)
setOptions(); setOptions();
} }
else if (memcmp(code, kMsgDCryptoIv, 4) == 0) {
cryptoIv();
}
else if (memcmp(code, kMsgDFileTransfer, 4) == 0) { else if (memcmp(code, kMsgDFileTransfer, 4) == 0) {
fileChunkReceived(); fileChunkReceived();
} }
@ -763,18 +758,6 @@ ServerProxy::mouseWheel()
m_client->mouseWheel(xDelta, yDelta); m_client->mouseWheel(xDelta, yDelta);
} }
void
ServerProxy::cryptoIv()
{
// parse
String s;
ProtocolUtil::readf(m_stream, kMsgDCryptoIv + 4, &s);
LOG((CLOG_DEBUG2 "recv crypto iv size=%i", s.size()));
// forward
m_client->setDecryptIv(reinterpret_cast<const UInt8*>(s.c_str()));
}
void void
ServerProxy::screensaver() ServerProxy::screensaver()
{ {

View File

@ -99,7 +99,6 @@ private:
void mouseMove(); void mouseMove();
void mouseRelativeMove(); void mouseRelativeMove();
void mouseWheel(); void mouseWheel();
void cryptoIv();
void screensaver(); void screensaver();
void resetOptions(); void resetOptions();
void setOptions(); void setOptions();

View File

@ -23,7 +23,6 @@ endif()
include_directories( include_directories(
../ ../
../../../ext
) )
if (UNIX) if (UNIX)
@ -33,7 +32,3 @@ if (UNIX)
endif() endif()
add_library(io STATIC ${sources}) add_library(io STATIC ${sources})
if (UNIX)
target_link_libraries(io cryptopp)
endif()

View File

@ -1,100 +0,0 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2013 Synergy Si Ltd.
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file COPYING that should have accompanied this file.
*
* 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
* 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 <http://www.gnu.org/licenses/>.
*/
#include "io/CryptoMode.h"
#include "io/XIO.h"
using namespace CryptoPP;
CryptoMode::CryptoMode(ECryptoMode mode, bool encryption) :
m_mode(mode),
m_crypto(NULL),
m_encryption(encryption)
{
if (m_encryption) {
switch (m_mode) {
case kCfb:
m_crypto = new CfbModeEnc;
break;
case kDisabled:
break;
default:
throw XIOBadCryptoMode();
}
}
else {
switch (m_mode) {
case kCfb:
m_crypto = new CfbModeDec;
break;
case kDisabled:
break;
default:
throw XIOBadCryptoMode();
}
}
}
CryptoMode::~CryptoMode()
{
if (m_crypto == NULL) {
return;
}
if (m_encryption) {
delete reinterpret_cast<CfbModeEnc*>(m_crypto);
}
else {
delete reinterpret_cast<CfbModeDec*>(m_crypto);
}
}
void
CryptoMode::processData(byte* out, const byte* in, size_t length)
{
if (m_crypto == NULL) {
return;
}
if (m_encryption) {
reinterpret_cast<CfbModeEnc*>(m_crypto)->ProcessData(out, in, length);
}
else {
reinterpret_cast<CfbModeDec*>(m_crypto)->ProcessData(out, in, length);
}
}
void
CryptoMode::setKeyWithIv(const byte* key, size_t length, const byte* iv)
{
if (m_crypto == NULL) {
return;
}
if (m_encryption) {
reinterpret_cast<CfbModeEnc*>(m_crypto)->SetKeyWithIV(key, length, iv);
}
else {
reinterpret_cast<CfbModeDec*>(m_crypto)->SetKeyWithIV(key, length, iv);
}
}

View File

@ -1,57 +0,0 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2013 Synergy Si Ltd.
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file COPYING that should have accompanied this file.
*
* 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
* 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 <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "io/ECryptoMode.h"
#include "io/CryptoMode_cryptopp.h"
#include "base/String.h"
//! Encapsulation of modes
/*!
Polymorphism is tricky in Crypto++, so we encapsulate all crypto modes
and switch based on an enum for ctor, dtor and all functions.
*/
class CryptoMode {
public:
CryptoMode(ECryptoMode mode, bool encryption = true);
~CryptoMode();
//! Encrypt or decrypt data
void processData(byte* out, const byte* in, size_t length);
//! Variable length key and initialization vector
void setKeyWithIv(const byte* key, size_t length, const byte* iv);
private:
typedef CryptoPP::OFB_Mode<CryptoPP::AES>::Encryption OfbModeEnc;
typedef CryptoPP::CFB_Mode<CryptoPP::AES>::Encryption CfbModeEnc;
typedef CryptoPP::CTR_Mode<CryptoPP::AES>::Encryption CtrModeEnc;
typedef CryptoPP::GCM<CryptoPP::AES>::Encryption GcmModeEnc;
typedef CryptoPP::OFB_Mode<CryptoPP::AES>::Decryption OfbModeDec;
typedef CryptoPP::CFB_Mode<CryptoPP::AES>::Decryption CfbModeDec;
typedef CryptoPP::CTR_Mode<CryptoPP::AES>::Decryption CtrModeDec;
typedef CryptoPP::GCM<CryptoPP::AES>::Decryption GcmModeDec;
static ECryptoMode parseMode(String& mode);
ECryptoMode m_mode;
void* m_crypto;
bool m_encryption;
};

View File

@ -1,30 +0,0 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2014 Synergy Si Ltd.
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file COPYING that should have accompanied this file.
*
* 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
* 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 <http://www.gnu.org/licenses/>.
*/
#pragma once
// HACK: gcc on osx106 doesn't give you an easy way to hide warnings
// from included headers, so use the system_header pragma. the downside
// is that everything in the header file following this also has warnings
// ignored, so we need to put it in a separate header file (this file).
#if __APPLE__
# pragma GCC system_header
#endif
#include <cryptopp562/gcm.h>
#include <cryptopp562/modes.h>
#include <cryptopp562/aes.h>

View File

@ -1,45 +0,0 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2013 Synergy Si Ltd.
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file COPYING that should have accompanied this file.
*
* 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
* 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 <http://www.gnu.org/licenses/>.
*/
#include "io/CryptoOptions.h"
#include "io/XIO.h"
CryptoOptions::CryptoOptions(
const String& modeString,
const String& pass) :
m_pass(pass),
m_mode(parseMode(modeString))
{
}
void
CryptoOptions::setMode(String modeString)
{
m_modeString = modeString;
m_mode = parseMode(modeString);
}
ECryptoMode
CryptoOptions::parseMode(String modeString)
{
if (modeString == "cfb") {
return kCfb;
}
else {
throw XIOBadCryptoMode();
}
}

View File

@ -1,38 +0,0 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2013 Synergy Si Ltd.
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file COPYING that should have accompanied this file.
*
* 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
* 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 <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "base/String.h"
#include "io/ECryptoMode.h"
//! Encapsulates basic crypto options
class CryptoOptions {
public:
CryptoOptions() : m_mode(kDisabled) { }
CryptoOptions(const String& modeString, const String& pass);
//! Return enum for mode string
static ECryptoMode parseMode(String modeString);
//! Parse and set mode string
void setMode(String modeString);
String m_pass;
ECryptoMode m_mode;
String m_modeString;
};

View File

@ -1,155 +0,0 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2013 Synergy Si Ltd.
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file COPYING that should have accompanied this file.
*
* 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
* 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 <http://www.gnu.org/licenses/>.
*/
#include "io/CryptoStream.h"
#include "io/CryptoOptions.h"
#include "base/Log.h"
#include <sstream>
#include <string>
#include <stdio.h>
using namespace CryptoPP;
using namespace synergy::crypto;
CryptoStream::CryptoStream(
IEventQueue* events,
synergy::IStream* stream,
const CryptoOptions& options,
bool adoptStream) :
StreamFilter(events, stream, adoptStream),
m_key(NULL),
m_encryption(options.m_mode, true),
m_decryption(options.m_mode, false)
{
LOG((CLOG_INFO "crypto mode: %s", options.m_modeString.c_str()));
m_key = new byte[kKeyLength];
if (!options.m_pass.empty()) {
createKey(m_key, options.m_pass, kKeyLength, static_cast<UInt8>(options.m_pass.length()));
byte iv[CRYPTO_IV_SIZE];
createKey(iv, options.m_pass, CRYPTO_IV_SIZE, static_cast<UInt8>(options.m_pass.length()) * 2);
setEncryptIv(iv);
setDecryptIv(iv);
}
}
CryptoStream::~CryptoStream()
{
delete[] m_key;
}
UInt32
CryptoStream::read(void* out, UInt32 n)
{
assert(m_key != NULL);
LOG((CLOG_DEBUG4 "crypto: read %i (decrypt)", n));
byte* cypher = new byte[n];
size_t result = getStream()->read(cypher, n);
if (result == 0) {
// nothing to read.
return 0;
}
if (result != n) {
LOG((CLOG_ERR "crypto: decrypt failed, only %i of %i bytes", result, n));
return 0;
}
logBuffer("cypher", cypher, n);
m_decryption.processData(static_cast<byte*>(out), cypher, n);
logBuffer("plaintext", static_cast<byte*>(out), n);
delete[] cypher;
return static_cast<UInt32>(result);
}
void
CryptoStream::write(const void* in, UInt32 n)
{
assert(m_key != NULL);
LOG((CLOG_DEBUG4 "crypto: write %i (encrypt)", n));
logBuffer("plaintext", static_cast<byte*>(const_cast<void*>(in)), n);
byte* cypher = new byte[n];
m_encryption.processData(cypher, static_cast<const byte*>(in), n);
logBuffer("cypher", cypher, n);
getStream()->write(cypher, n);
delete[] cypher;
}
void
CryptoStream::createKey(byte* out, const String& password, UInt8 keyLength, UInt8 hashCount)
{
assert(keyLength <= SHA256::DIGESTSIZE);
byte temp[SHA256::DIGESTSIZE];
byte* in = reinterpret_cast<byte*>(const_cast<char*>(password.c_str()));
SHA256().CalculateDigest(temp, in, password.length());
byte* tempKey = new byte[SHA256::DIGESTSIZE];
for (int i = 0; i < hashCount; ++i) {
memcpy(tempKey, temp, SHA256::DIGESTSIZE);
SHA256().CalculateDigest(temp, tempKey, SHA256::DIGESTSIZE);
}
delete[] tempKey;
memcpy(out, temp, keyLength);
}
void
CryptoStream::setEncryptIv(const byte* iv)
{
assert(m_key != NULL);
logBuffer("encrypt iv", iv, CRYPTO_IV_SIZE);
m_encryption.setKeyWithIv(m_key, kKeyLength, iv);
}
void
CryptoStream::setDecryptIv(const byte* iv)
{
assert(m_key != NULL);
logBuffer("decrypt iv", iv, CRYPTO_IV_SIZE);
m_decryption.setKeyWithIv(m_key, kKeyLength, iv);
}
void
CryptoStream::newIv(byte* out)
{
m_autoSeedRandomPool.GenerateBlock(out, CRYPTO_IV_SIZE);
}
void
CryptoStream::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()));
}

View File

@ -1,85 +0,0 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2013 Synergy Si Ltd.
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file COPYING that should have accompanied this file.
*
* 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
* 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 <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "io/StreamFilter.h"
#include "io/CryptoMode.h"
#include "io/CryptoStream_cryptopp.h"
#include "base/EventTypes.h"
class CryptoOptions;
#define CRYPTO_IV_SIZE CryptoPP::AES::BLOCKSIZE
//! Bidirectional encrypted stream
/*!
Encrypts (on write) and decrypts (on read) to and from an underlying stream.
*/
class CryptoStream : public StreamFilter {
public:
CryptoStream(IEventQueue* events, synergy::IStream* stream, const CryptoOptions& options, bool adoptStream = true);
virtual ~CryptoStream();
//! @name manipulators
//@{
//! Read from stream
/*!
Read up to \p n bytes into \p buffer to the stream using encryption.
Returns the number of bytes read by the underlying stream.
*/
virtual UInt32 read(void* out, UInt32 n);
//! Write to stream
/*!
Write \c n bytes from \c buffer to the stream using encryption.
*/
virtual void write(const void* in, UInt32 n);
//! Set the IV for encryption
void setEncryptIv(const byte* iv);
//! Set the IV for decryption
void setDecryptIv(const byte* iv);
//! Get a new IV
/*!
Writes a new IV to the \c out buffer, and also uses the IV for further
crypto.
*/
void newIv(byte* out);
//! Creates a key from a password
static void createKey(byte* out, const String& password, UInt8 keyLength, UInt8 hashCount);
private:
void logBuffer(const char* name, const byte* buf, int length);
byte* m_key;
CryptoMode m_encryption;
CryptoMode m_decryption;
CryptoPP::AutoSeededRandomPool m_autoSeedRandomPool;
};
namespace synergy {
namespace crypto {
const UInt32 kKeyLength = 32;
}
}

View File

@ -1,29 +0,0 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2014 Synergy Si Ltd.
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file COPYING that should have accompanied this file.
*
* 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
* 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 <http://www.gnu.org/licenses/>.
*/
#pragma once
// HACK: gcc on osx106 doesn't give you an easy way to hide warnings
// from included headers, so use the system_header pragma. the downside
// is that everything in the header file following this also has warnings
// ignored, so we need to put it in a separate header file (this file).
#if __APPLE__
# pragma GCC system_header
#endif
#include <cryptopp562/osrng.h>
#include <cryptopp562/sha.h>

View File

@ -1,24 +0,0 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2013 Synergy Si Ltd.
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file COPYING that should have accompanied this file.
*
* 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
* 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 <http://www.gnu.org/licenses/>.
*/
#pragma once
enum ECryptoMode {
kDisabled,
kCfb,
kNumOfModes
};

View File

@ -49,13 +49,3 @@ XIOWouldBlock::getWhat() const throw()
{ {
return format("XIOWouldBlock", "stream operation would block"); return format("XIOWouldBlock", "stream operation would block");
} }
//
// XBadCryptoMode
//
String
XIOBadCryptoMode::getWhat() const throw()
{
return "XBadCryptoMode";
}

View File

@ -47,9 +47,3 @@ XBASE_SUBCLASS_WHAT(XIOEndOfStream, XIO);
Thrown if an operation on a stream would block. Thrown if an operation on a stream would block.
*/ */
XBASE_SUBCLASS_WHAT(XIOWouldBlock, XIO); XBASE_SUBCLASS_WHAT(XIOWouldBlock, XIO);
//! I/O bad crypto mode exception
/*!
Thrown when the user enters an invalid crypto mode.
*/
XBASE_SUBCLASS_WHAT(XIOBadCryptoMode, XIO);

View File

@ -55,7 +55,7 @@ if (UNIX)
endif() endif()
target_link_libraries(ns target_link_libraries(ns
arch base client common io mt net ipc platform server synergy cryptopp ${libs} ${OPENSSL_LIBS}) arch base client common io mt net ipc platform server synergy ${libs} ${OPENSSL_LIBS})
if (WIN32) if (WIN32)
add_custom_command( add_custom_command(

View File

@ -25,8 +25,6 @@
#include "net/IListenSocket.h" #include "net/IListenSocket.h"
#include "net/ISocketFactory.h" #include "net/ISocketFactory.h"
#include "net/XSocket.h" #include "net/XSocket.h"
#include "io/CryptoStream.h"
#include "io/CryptoOptions.h"
#include "base/Log.h" #include "base/Log.h"
#include "base/IEventQueue.h" #include "base/IEventQueue.h"
#include "base/TMethodEventJob.h" #include "base/TMethodEventJob.h"
@ -43,11 +41,9 @@ static const char s_networkSecurity[] = { "libns" };
ClientListener::ClientListener(const NetworkAddress& address, ClientListener::ClientListener(const NetworkAddress& address,
ISocketFactory* socketFactory, ISocketFactory* socketFactory,
const CryptoOptions& crypto,
IEventQueue* events) : IEventQueue* events) :
m_socketFactory(socketFactory), m_socketFactory(socketFactory),
m_server(NULL), m_server(NULL),
m_crypto(crypto),
m_events(events) m_events(events)
{ {
assert(m_socketFactory != NULL); assert(m_socketFactory != NULL);
@ -149,12 +145,6 @@ ClientListener::handleClientConnecting(const Event&, void*)
// filter socket messages, including a packetizing filter // filter socket messages, including a packetizing filter
bool adopt = !m_useSecureNetwork; bool adopt = !m_useSecureNetwork;
stream = new PacketStreamFilter(m_events, stream, adopt); stream = new PacketStreamFilter(m_events, stream, adopt);
if (m_crypto.m_mode != kDisabled) {
CryptoStream* cryptoStream = new CryptoStream(
m_events, stream, m_crypto, true);
stream = cryptoStream;
}
assert(m_server != NULL); assert(m_server != NULL);

View File

@ -19,7 +19,6 @@
#pragma once #pragma once
#include "server/Config.h" #include "server/Config.h"
#include "io/CryptoOptions.h"
#include "base/EventTypes.h" #include "base/EventTypes.h"
#include "base/Event.h" #include "base/Event.h"
#include "common/stddeque.h" #include "common/stddeque.h"
@ -38,7 +37,6 @@ public:
// The factories are adopted. // The factories are adopted.
ClientListener(const NetworkAddress&, ClientListener(const NetworkAddress&,
ISocketFactory*, ISocketFactory*,
const CryptoOptions& crypto,
IEventQueue* events); IEventQueue* events);
~ClientListener(); ~ClientListener();
@ -84,7 +82,6 @@ private:
NewClients m_newClients; NewClients m_newClients;
WaitingClients m_waitingClients; WaitingClients m_waitingClients;
Server* m_server; Server* m_server;
CryptoOptions m_crypto;
IEventQueue* m_events; IEventQueue* m_events;
bool m_useSecureNetwork; bool m_useSecureNetwork;
}; };

View File

@ -49,8 +49,7 @@ public:
//! Get stream //! Get stream
/*! /*!
Returns a crypto stream if the user has this enabled, Returns the original stream passed to the c'tor.
otherwise returns the original stream passed to the c'tor.
*/ */
synergy::IStream* getStream() const; synergy::IStream* getStream() const;

View File

@ -20,7 +20,6 @@
#include "server/Server.h" #include "server/Server.h"
#include "synergy/ProtocolUtil.h" #include "synergy/ProtocolUtil.h"
#include "io/CryptoStream.h"
#include "base/Log.h" #include "base/Log.h"
#include "base/IEventQueue.h" #include "base/IEventQueue.h"
#include "base/TMethodEventJob.h" #include "base/TMethodEventJob.h"
@ -45,47 +44,23 @@ ClientProxy1_4::~ClientProxy1_4()
void void
ClientProxy1_4::keyDown(KeyID key, KeyModifierMask mask, KeyButton button) ClientProxy1_4::keyDown(KeyID key, KeyModifierMask mask, KeyButton button)
{ {
cryptoIv();
ClientProxy1_3::keyDown(key, mask, button); ClientProxy1_3::keyDown(key, mask, button);
} }
void void
ClientProxy1_4::keyRepeat(KeyID key, KeyModifierMask mask, SInt32 count, KeyButton button) ClientProxy1_4::keyRepeat(KeyID key, KeyModifierMask mask, SInt32 count, KeyButton button)
{ {
cryptoIv();
ClientProxy1_3::keyRepeat(key, mask, count, button); ClientProxy1_3::keyRepeat(key, mask, count, button);
} }
void void
ClientProxy1_4::keyUp(KeyID key, KeyModifierMask mask, KeyButton button) ClientProxy1_4::keyUp(KeyID key, KeyModifierMask mask, KeyButton button)
{ {
cryptoIv();
ClientProxy1_3::keyUp(key, mask, button); ClientProxy1_3::keyUp(key, mask, button);
} }
void void
ClientProxy1_4::keepAlive() ClientProxy1_4::keepAlive()
{ {
cryptoIv();
ClientProxy1_3::keepAlive(); ClientProxy1_3::keepAlive();
} }
void
ClientProxy1_4::cryptoIv()
{
CryptoStream* cryptoStream = dynamic_cast<CryptoStream*>(getStream());
if (cryptoStream == NULL) {
return;
}
byte iv[CRYPTO_IV_SIZE];
cryptoStream->newIv(iv);
String data(reinterpret_cast<const char*>(iv), CRYPTO_IV_SIZE);
LOG((CLOG_DEBUG2 "send crypto iv change to \"%s\"", getName().c_str()));
ProtocolUtil::writef(getStream(), kMsgDCryptoIv, &data);
// change IV only after we've sent the current IV, otherwise
// the client won't be able to decrypt the new IV.
cryptoStream->setEncryptIv(iv);
}

View File

@ -42,8 +42,5 @@ public:
virtual void keyUp(KeyID key, KeyModifierMask mask, KeyButton button); virtual void keyUp(KeyID key, KeyModifierMask mask, KeyButton button);
virtual void keepAlive(); virtual void keepAlive();
//! Send IV to make
void cryptoIv();
Server* m_server; Server* m_server;
}; };

View File

@ -163,7 +163,6 @@ private:
"* --restart restart the server automatically if it fails.\n" \ "* --restart restart the server automatically if it fails.\n" \
" -l --log <file> write log messages to file.\n" \ " -l --log <file> write log messages to file.\n" \
" --no-tray disable the system tray icon.\n" \ " --no-tray disable the system tray icon.\n" \
" --crypto-pass <pass> enable encryption, using the given password.\n" \
" --enable-drag-drop enable file drag & drop.\n" " --enable-drag-drop enable file drag & drop.\n"
#define HELP_COMMON_INFO_2 \ #define HELP_COMMON_INFO_2 \

View File

@ -245,10 +245,6 @@ ArgParser::parseGenericArgs(int argc, const char* const* argv, int& i)
else if (isArg(i, argc, argv, NULL, "--client")) { else if (isArg(i, argc, argv, NULL, "--client")) {
// HACK: stop error happening when using portable (synergyp) // HACK: stop error happening when using portable (synergyp)
} }
else if (isArg(i, argc, argv, NULL, "--crypto-pass")) {
argsBase().m_crypto.m_pass = argv[++i];
argsBase().m_crypto.setMode("cfb");
}
else if (isArg(i, argc, argv, NULL, "--enable-drag-drop")) { else if (isArg(i, argc, argv, NULL, "--enable-drag-drop")) {
bool useDragDrop = true; bool useDragDrop = true;

View File

@ -19,7 +19,6 @@
#pragma once #pragma once
#include "base/String.h" #include "base/String.h"
#include "io/CryptoOptions.h"
class ArgsBase { class ArgsBase {
public: public:
@ -36,7 +35,6 @@ public:
String m_name; String m_name;
bool m_disableTray; bool m_disableTray;
bool m_enableIpc; bool m_enableIpc;
CryptoOptions m_crypto;
bool m_enableDragDrop; bool m_enableDragDrop;
#if SYSAPI_WIN32 #if SYSAPI_WIN32
bool m_debugServiceWait; bool m_debugServiceWait;

View File

@ -334,7 +334,7 @@ ClientApp::handleClientDisconnected(const Event&, void*)
Client* Client*
ClientApp::openClient(const String& name, const NetworkAddress& address, ClientApp::openClient(const String& name, const NetworkAddress& address,
synergy::Screen* screen, const CryptoOptions& crypto) synergy::Screen* screen)
{ {
Client* client = new Client( Client* client = new Client(
m_events, m_events,
@ -342,7 +342,6 @@ ClientApp::openClient(const String& name, const NetworkAddress& address,
address, address,
new TCPSocketFactory(m_events, getSocketMultiplexer()), new TCPSocketFactory(m_events, getSocketMultiplexer()),
screen, screen,
crypto,
args().m_enableDragDrop); args().m_enableDragDrop);
try { try {
@ -401,7 +400,7 @@ ClientApp::startClient()
if (m_clientScreen == NULL) { if (m_clientScreen == NULL) {
clientScreen = openClientScreen(); clientScreen = openClientScreen();
m_client = openClient(args().m_name, m_client = openClient(args().m_name,
*m_serverAddress, clientScreen, args().m_crypto); *m_serverAddress, clientScreen);
m_clientScreen = clientScreen; m_clientScreen = clientScreen;
LOG((CLOG_NOTE "started client")); LOG((CLOG_NOTE "started client"));
} }

View File

@ -26,7 +26,6 @@ class Client;
class NetworkAddress; class NetworkAddress;
class Thread; class Thread;
class ClientArgs; class ClientArgs;
class CryptoOptions;
class ClientApp : public App { class ClientApp : public App {
public: public:
@ -66,7 +65,7 @@ public:
void handleClientFailed(const Event& e, void*); void handleClientFailed(const Event& e, void*);
void handleClientDisconnected(const Event&, void*); void handleClientDisconnected(const Event&, void*);
Client* openClient(const String& name, const NetworkAddress& address, Client* openClient(const String& name, const NetworkAddress& address,
synergy::Screen* screen, const CryptoOptions& crypto); synergy::Screen* screen);
void closeClient(Client* client); void closeClient(Client* client);
bool startClient(); bool startClient();
void stopClient(); void stopClient();

View File

@ -632,9 +632,7 @@ ServerApp::openClientListener(const NetworkAddress& address)
{ {
ClientListener* listen = new ClientListener( ClientListener* listen = new ClientListener(
address, address,
new TCPSocketFactory(m_events, getSocketMultiplexer()), new TCPSocketFactory(m_events, getSocketMultiplexer()), m_events);
args().m_crypto,
m_events);
m_events->adoptHandler( m_events->adoptHandler(
m_events->forClientListener().connected(), listen, m_events->forClientListener().connected(), listen,

View File

@ -44,7 +44,6 @@ const char* kMsgDMouseWheel1_0 = "DMWM%2i";
const char* kMsgDClipboard = "DCLP%1i%4i%s"; const char* kMsgDClipboard = "DCLP%1i%4i%s";
const char* kMsgDInfo = "DINF%2i%2i%2i%2i%2i%2i%2i"; const char* kMsgDInfo = "DINF%2i%2i%2i%2i%2i%2i%2i";
const char* kMsgDSetOptions = "DSOP%4I"; const char* kMsgDSetOptions = "DSOP%4I";
const char* kMsgDCryptoIv = "DCIV%s";
const char* kMsgDFileTransfer = "DFTR%1i%s"; const char* kMsgDFileTransfer = "DFTR%1i%s";
const char* kMsgDDragInfo = "DDRG%2i%s"; const char* kMsgDDragInfo = "DDRG%2i%s";
const char* kMsgQInfo = "QINF"; const char* kMsgQInfo = "QINF";

View File

@ -27,6 +27,7 @@
// 1.3: adds keep alive and deprecates heartbeats, // 1.3: adds keep alive and deprecates heartbeats,
// adds horizontal mouse scrolling // adds horizontal mouse scrolling
// 1.4: adds crypto support // 1.4: adds crypto support
// 1.5: adds file transfer and removes home brew crypto
// NOTE: with new version, synergy minor version should increment // NOTE: with new version, synergy minor version should increment
static const SInt16 kProtocolMajorVersion = 1; static const SInt16 kProtocolMajorVersion = 1;
static const SInt16 kProtocolMinorVersion = 5; static const SInt16 kProtocolMinorVersion = 5;
@ -251,11 +252,6 @@ extern const char* kMsgDInfo;
// pairs. // pairs.
extern const char* kMsgDSetOptions; extern const char* kMsgDSetOptions;
// crypto iv: primary -> secondary
// sends a new iv (initialization vector) to the client for the
// cryptography stream.
extern const char* kMsgDCryptoIv;
// file data: primary <-> secondary // file data: primary <-> secondary
// transfer file data. A mark is used in the first byte. // transfer file data. A mark is used in the first byte.
// 0 means the content followed is the file size. // 0 means the content followed is the file size.

View File

@ -236,7 +236,7 @@ static
bool bool
doKeyboardHookHandler(WPARAM wParam, LPARAM lParam) doKeyboardHookHandler(WPARAM wParam, LPARAM lParam)
{ {
DWORD vkCode = wParam; DWORD vkCode = static_cast<DWORD>(wParam);
bool kf_up = (lParam & (KF_UP << 16)) != 0; bool kf_up = (lParam & (KF_UP << 16)) != 0;
// check for special events indicating if we should start or stop // check for special events indicating if we should start or stop

View File

@ -68,4 +68,4 @@ endif()
add_executable(integtests ${sources}) add_executable(integtests ${sources})
target_link_libraries(integtests target_link_libraries(integtests
arch base client common io ipc mt net platform server synergy gtest gmock cryptopp ${libs}) arch base client common io ipc mt net platform server synergy gtest gmock ${libs})

View File

@ -32,7 +32,6 @@
#include "net/SocketMultiplexer.h" #include "net/SocketMultiplexer.h"
#include "net/NetworkAddress.h" #include "net/NetworkAddress.h"
#include "net/TCPSocketFactory.h" #include "net/TCPSocketFactory.h"
#include "io/CryptoOptions.h"
#include "mt/Thread.h" #include "mt/Thread.h"
#include "base/TMethodEventJob.h" #include "base/TMethodEventJob.h"
#include "base/TMethodJob.h" #include "base/TMethodJob.h"
@ -109,14 +108,13 @@ TEST_F(NetworkTests, sendToClient_mockData)
{ {
// server and client // server and client
NetworkAddress serverAddress(TEST_HOST, TEST_PORT); NetworkAddress serverAddress(TEST_HOST, TEST_PORT);
CryptoOptions cryptoOptions;
serverAddress.resolve(); serverAddress.resolve();
// server // server
SocketMultiplexer serverSocketMultiplexer; SocketMultiplexer serverSocketMultiplexer;
TCPSocketFactory* serverSocketFactory = new TCPSocketFactory(&m_events, &serverSocketMultiplexer); TCPSocketFactory* serverSocketFactory = new TCPSocketFactory(&m_events, &serverSocketMultiplexer);
ClientListener listener(serverAddress, serverSocketFactory, cryptoOptions, &m_events); ClientListener listener(serverAddress, serverSocketFactory, &m_events);
NiceMock<MockScreen> serverScreen; NiceMock<MockScreen> serverScreen;
NiceMock<MockPrimaryClient> primaryClient; NiceMock<MockPrimaryClient> primaryClient;
NiceMock<MockConfig> serverConfig; NiceMock<MockConfig> serverConfig;
@ -142,7 +140,7 @@ TEST_F(NetworkTests, sendToClient_mockData)
ON_CALL(clientScreen, getShape(_, _, _, _)).WillByDefault(Invoke(getScreenShape)); ON_CALL(clientScreen, getShape(_, _, _, _)).WillByDefault(Invoke(getScreenShape));
ON_CALL(clientScreen, getCursorPos(_, _)).WillByDefault(Invoke(getCursorPos)); ON_CALL(clientScreen, getCursorPos(_, _)).WillByDefault(Invoke(getCursorPos));
Client client(&m_events, "stub", serverAddress, clientSocketFactory, &clientScreen, cryptoOptions, true); Client client(&m_events, "stub", serverAddress, clientSocketFactory, &clientScreen, true);
m_events.adoptHandler( m_events.adoptHandler(
m_events.forIScreen().fileRecieveCompleted(), &client, m_events.forIScreen().fileRecieveCompleted(), &client,
@ -162,14 +160,13 @@ TEST_F(NetworkTests, sendToClient_mockFile)
{ {
// server and client // server and client
NetworkAddress serverAddress(TEST_HOST, TEST_PORT); NetworkAddress serverAddress(TEST_HOST, TEST_PORT);
CryptoOptions cryptoOptions;
serverAddress.resolve(); serverAddress.resolve();
// server // server
SocketMultiplexer serverSocketMultiplexer; SocketMultiplexer serverSocketMultiplexer;
TCPSocketFactory* serverSocketFactory = new TCPSocketFactory(&m_events, &serverSocketMultiplexer); TCPSocketFactory* serverSocketFactory = new TCPSocketFactory(&m_events, &serverSocketMultiplexer);
ClientListener listener(serverAddress, serverSocketFactory, cryptoOptions, &m_events); ClientListener listener(serverAddress, serverSocketFactory, &m_events);
NiceMock<MockScreen> serverScreen; NiceMock<MockScreen> serverScreen;
NiceMock<MockPrimaryClient> primaryClient; NiceMock<MockPrimaryClient> primaryClient;
NiceMock<MockConfig> serverConfig; NiceMock<MockConfig> serverConfig;
@ -195,7 +192,7 @@ TEST_F(NetworkTests, sendToClient_mockFile)
ON_CALL(clientScreen, getShape(_, _, _, _)).WillByDefault(Invoke(getScreenShape)); ON_CALL(clientScreen, getShape(_, _, _, _)).WillByDefault(Invoke(getScreenShape));
ON_CALL(clientScreen, getCursorPos(_, _)).WillByDefault(Invoke(getCursorPos)); ON_CALL(clientScreen, getCursorPos(_, _)).WillByDefault(Invoke(getCursorPos));
Client client(&m_events, "stub", serverAddress, clientSocketFactory, &clientScreen, cryptoOptions, true); Client client(&m_events, "stub", serverAddress, clientSocketFactory, &clientScreen, true);
m_events.adoptHandler( m_events.adoptHandler(
m_events.forIScreen().fileRecieveCompleted(), &client, m_events.forIScreen().fileRecieveCompleted(), &client,
@ -215,14 +212,12 @@ TEST_F(NetworkTests, sendToServer_mockData)
{ {
// server and client // server and client
NetworkAddress serverAddress(TEST_HOST, TEST_PORT); NetworkAddress serverAddress(TEST_HOST, TEST_PORT);
CryptoOptions cryptoOptions;
serverAddress.resolve(); serverAddress.resolve();
// server // server
SocketMultiplexer serverSocketMultiplexer; SocketMultiplexer serverSocketMultiplexer;
TCPSocketFactory* serverSocketFactory = new TCPSocketFactory(&m_events, &serverSocketMultiplexer); TCPSocketFactory* serverSocketFactory = new TCPSocketFactory(&m_events, &serverSocketMultiplexer);
ClientListener listener(serverAddress, serverSocketFactory, cryptoOptions, &m_events); ClientListener listener(serverAddress, serverSocketFactory, &m_events);
NiceMock<MockScreen> serverScreen; NiceMock<MockScreen> serverScreen;
NiceMock<MockPrimaryClient> primaryClient; NiceMock<MockPrimaryClient> primaryClient;
NiceMock<MockConfig> serverConfig; NiceMock<MockConfig> serverConfig;
@ -243,7 +238,7 @@ TEST_F(NetworkTests, sendToServer_mockData)
ON_CALL(clientScreen, getShape(_, _, _, _)).WillByDefault(Invoke(getScreenShape)); ON_CALL(clientScreen, getShape(_, _, _, _)).WillByDefault(Invoke(getScreenShape));
ON_CALL(clientScreen, getCursorPos(_, _)).WillByDefault(Invoke(getCursorPos)); ON_CALL(clientScreen, getCursorPos(_, _)).WillByDefault(Invoke(getCursorPos));
Client client(&m_events, "stub", serverAddress, clientSocketFactory, &clientScreen, cryptoOptions, true); Client client(&m_events, "stub", serverAddress, clientSocketFactory, &clientScreen, true);
m_events.adoptHandler( m_events.adoptHandler(
m_events.forClientListener().connected(), &listener, m_events.forClientListener().connected(), &listener,
@ -268,14 +263,13 @@ TEST_F(NetworkTests, sendToServer_mockFile)
{ {
// server and client // server and client
NetworkAddress serverAddress(TEST_HOST, TEST_PORT); NetworkAddress serverAddress(TEST_HOST, TEST_PORT);
CryptoOptions cryptoOptions;
serverAddress.resolve(); serverAddress.resolve();
// server // server
SocketMultiplexer serverSocketMultiplexer; SocketMultiplexer serverSocketMultiplexer;
TCPSocketFactory* serverSocketFactory = new TCPSocketFactory(&m_events, &serverSocketMultiplexer); TCPSocketFactory* serverSocketFactory = new TCPSocketFactory(&m_events, &serverSocketMultiplexer);
ClientListener listener(serverAddress, serverSocketFactory, cryptoOptions, &m_events); ClientListener listener(serverAddress, serverSocketFactory, &m_events);
NiceMock<MockScreen> serverScreen; NiceMock<MockScreen> serverScreen;
NiceMock<MockPrimaryClient> primaryClient; NiceMock<MockPrimaryClient> primaryClient;
NiceMock<MockConfig> serverConfig; NiceMock<MockConfig> serverConfig;
@ -296,7 +290,7 @@ TEST_F(NetworkTests, sendToServer_mockFile)
ON_CALL(clientScreen, getShape(_, _, _, _)).WillByDefault(Invoke(getScreenShape)); ON_CALL(clientScreen, getShape(_, _, _, _)).WillByDefault(Invoke(getScreenShape));
ON_CALL(clientScreen, getCursorPos(_, _)).WillByDefault(Invoke(getCursorPos)); ON_CALL(clientScreen, getCursorPos(_, _)).WillByDefault(Invoke(getCursorPos));
Client client(&m_events, "stub", serverAddress, clientSocketFactory, &clientScreen, cryptoOptions, true); Client client(&m_events, "stub", serverAddress, clientSocketFactory, &clientScreen, true);
m_events.adoptHandler( m_events.adoptHandler(
m_events.forClientListener().connected(), &listener, m_events.forClientListener().connected(), &listener,

View File

@ -1,32 +0,0 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2013 Synergy Si Ltd.
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file COPYING that should have accompanied this file.
*
* 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
* 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 <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "io/CryptoStream.h"
#include "io/CryptoOptions.h"
#include "test/global/gmock.h"
class MockCryptoStream : public CryptoStream
{
public:
MockCryptoStream(IEventQueue* eventQueue, IStream* stream) :
CryptoStream(eventQueue, stream, CryptoOptions("gcm", "stub"), false) { }
MOCK_METHOD2(read, UInt32(void*, UInt32));
MOCK_METHOD2(write, void(const void*, UInt32));
};

View File

@ -49,4 +49,4 @@ endif()
add_executable(unittests ${sources}) add_executable(unittests ${sources})
target_link_libraries(unittests target_link_libraries(unittests
arch base client server common io net platform server synergy mt ipc gtest gmock cryptopp ${libs}) arch base client server common io net platform server synergy mt ipc gtest gmock ${libs})

View File

@ -1,118 +0,0 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012 Synergy Si Ltd.
* Copyright (C) 2011 Nick Bolton
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file COPYING that should have accompanied this file.
*
* 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
* 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 <http://www.gnu.org/licenses/>.
*/
#define TEST_ENV
#include "test/mock/client/MockClient.h"
#include "test/mock/io/MockStream.h"
#include "test/mock/synergy/MockEventQueue.h"
#include "client/ServerProxy.h"
#include "synergy/protocol_types.h"
#include "test/global/gtest.h"
using ::testing::_;
using ::testing::Invoke;
using ::testing::NiceMock;
using ::testing::AnyNumber;
using ::testing::ReturnRef;
const UInt8 g_mouseMove_bufferLen = 16;
UInt8 g_mouseMove_buffer[g_mouseMove_bufferLen];
UInt32 g_mouseMove_bufferIndex;
UInt32 mouseMove_mockRead(void* buffer, UInt32 n);
const UInt8 g_readCryptoIv_bufferLen = 20;
UInt8 g_readCryptoIv_buffer[g_readCryptoIv_bufferLen];
UInt32 g_readCryptoIv_bufferIndex;
String g_readCryptoIv_result;
UInt32 readCryptoIv_mockRead(void* buffer, UInt32 n);
void readCryptoIv_setDecryptIv(const UInt8*);
TEST(ServerProxyTests, mouseMove)
{
g_mouseMove_bufferIndex = 0;
NiceMock<MockEventQueue> eventQueue;
NiceMock<MockStream> stream;
NiceMock<MockClient> client;
IStreamEvents streamEvents;
streamEvents.setEvents(&eventQueue);
ON_CALL(eventQueue, forIStream()).WillByDefault(ReturnRef(streamEvents));
ON_CALL(stream, read(_, _)).WillByDefault(Invoke(mouseMove_mockRead));
EXPECT_CALL(client, mouseMove(1, 2)).Times(1);
const char data[] = "DSOP\0\0\0\0DMMV\0\1\0\2";
memcpy(g_mouseMove_buffer, data, g_mouseMove_bufferLen);
ServerProxy serverProxy(&client, &stream, &eventQueue);
serverProxy.handleDataForTest();
}
TEST(ServerProxyTests, readCryptoIv)
{
g_readCryptoIv_bufferIndex = 0;
NiceMock<MockEventQueue> eventQueue;
NiceMock<MockClient> client;
NiceMock<MockStream> stream;
IStreamEvents streamEvents;
streamEvents.setEvents(&eventQueue);
ON_CALL(eventQueue, forIStream()).WillByDefault(ReturnRef(streamEvents));
ON_CALL(stream, read(_, _)).WillByDefault(Invoke(readCryptoIv_mockRead));
ON_CALL(client, setDecryptIv(_)).WillByDefault(Invoke(readCryptoIv_setDecryptIv));
const char data[] = "DSOP\0\0\0\0DCIV\0\0\0\4mock";
memcpy(g_readCryptoIv_buffer, data, g_readCryptoIv_bufferLen);
ServerProxy serverProxy(&client, &stream, &eventQueue);
serverProxy.handleDataForTest();
EXPECT_EQ("mock", g_readCryptoIv_result);
}
UInt32
mouseMove_mockRead(void* buffer, UInt32 n)
{
if (g_mouseMove_bufferIndex >= g_mouseMove_bufferLen) {
return 0;
}
memcpy(buffer, &g_mouseMove_buffer[g_mouseMove_bufferIndex], n);
g_mouseMove_bufferIndex += n;
return n;
}
UInt32
readCryptoIv_mockRead(void* buffer, UInt32 n)
{
if (g_readCryptoIv_bufferIndex >= g_readCryptoIv_bufferLen) {
return 0;
}
memcpy(buffer, &g_readCryptoIv_buffer[g_readCryptoIv_bufferIndex], n);
g_readCryptoIv_bufferIndex += n;
return n;
}
void
readCryptoIv_setDecryptIv(const UInt8* data)
{
g_readCryptoIv_result = reinterpret_cast<const char*>(data);
}

View File

@ -1,135 +0,0 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2013 Synergy Si Ltd.
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file COPYING that should have accompanied this file.
*
* 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
* 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 <http://www.gnu.org/licenses/>.
*/
#include "test/mock/server/MockServer.h"
#include "test/mock/io/MockStream.h"
#include "test/mock/io/MockCryptoStream.h"
#include "test/mock/synergy/MockEventQueue.h"
#include "server/ClientProxy1_4.h"
#include "test/global/gtest.h"
using ::testing::_;
using ::testing::NiceMock;
using ::testing::Invoke;
using ::testing::ReturnRef;
const UInt8 g_cryptoIvWrite_bufferLen = 200;
UInt8 g_cryptoIvWrite_buffer[g_cryptoIvWrite_bufferLen];
UInt32 g_cryptoIvWrite_writeBufferIndex;
UInt32 g_cryptoIvWrite_readBufferIndex;
void cryptoIv_mockWrite(const void* in, UInt32 n);
UInt8 cryptoIv_mockRead(void* out, UInt32 n);
TEST(ClientProxyTests, cryptoIvWrite)
{
g_cryptoIvWrite_writeBufferIndex = 0;
g_cryptoIvWrite_readBufferIndex = 0;
NiceMock<MockEventQueue> eventQueue;
NiceMock<MockStream> innerStream;
NiceMock<MockServer> server;
CryptoOptions options("cfb", "mock");
IStreamEvents streamEvents;
streamEvents.setEvents(&eventQueue);
CryptoStream* serverStream = new CryptoStream(&eventQueue, &innerStream, options, false);
CryptoStream* clientStream = new CryptoStream(&eventQueue, &innerStream, options, false);
byte iv[CRYPTO_IV_SIZE];
serverStream->newIv(iv);
serverStream->setEncryptIv(iv);
clientStream->setDecryptIv(iv);
ON_CALL(eventQueue, forIStream()).WillByDefault(ReturnRef(streamEvents));
ON_CALL(innerStream, write(_, _)).WillByDefault(Invoke(cryptoIv_mockWrite));
ON_CALL(innerStream, read(_, _)).WillByDefault(Invoke(cryptoIv_mockRead));
ClientProxy1_4 clientProxy("stub", serverStream, &server, &eventQueue);
UInt8 buffer[100];
clientStream->read(buffer, 4);
g_cryptoIvWrite_writeBufferIndex = 0;
g_cryptoIvWrite_readBufferIndex = 0;
// DCIV, then DKDN.
clientProxy.keyDown(1, 2, 3);
clientStream->read(buffer, 24);
EXPECT_EQ('D', buffer[0]);
EXPECT_EQ('C', buffer[1]);
EXPECT_EQ('I', buffer[2]);
EXPECT_EQ('V', buffer[3]);
clientStream->setDecryptIv(&buffer[8]);
clientStream->read(buffer, 10);
EXPECT_EQ('D', buffer[0]);
EXPECT_EQ('K', buffer[1]);
EXPECT_EQ('D', buffer[2]);
EXPECT_EQ('N', buffer[3]);
g_cryptoIvWrite_writeBufferIndex = 0;
g_cryptoIvWrite_readBufferIndex = 0;
// DCIV, then DKUP.
clientProxy.keyUp(1, 2, 3);
clientStream->read(buffer, 24);
EXPECT_EQ('D', buffer[0]);
EXPECT_EQ('C', buffer[1]);
EXPECT_EQ('I', buffer[2]);
EXPECT_EQ('V', buffer[3]);
clientStream->setDecryptIv(&buffer[8]);
clientStream->read(buffer, 10);
EXPECT_EQ('D', buffer[0]);
EXPECT_EQ('K', buffer[1]);
EXPECT_EQ('U', buffer[2]);
EXPECT_EQ('P', buffer[3]);
g_cryptoIvWrite_writeBufferIndex = 0;
g_cryptoIvWrite_readBufferIndex = 0;
// DCIV, then DKRP.
clientProxy.keyRepeat(1, 2, 4, 4);
clientStream->read(buffer, 24);
EXPECT_EQ('D', buffer[0]);
EXPECT_EQ('C', buffer[1]);
EXPECT_EQ('I', buffer[2]);
EXPECT_EQ('V', buffer[3]);
clientStream->setDecryptIv(&buffer[8]);
clientStream->read(buffer, 12);
EXPECT_EQ('D', buffer[0]);
EXPECT_EQ('K', buffer[1]);
EXPECT_EQ('R', buffer[2]);
EXPECT_EQ('P', buffer[3]);
}
void
cryptoIv_mockWrite(const void* in, UInt32 n)
{
assert(g_cryptoIvWrite_writeBufferIndex <= sizeof(g_cryptoIvWrite_buffer));
memcpy(&g_cryptoIvWrite_buffer[g_cryptoIvWrite_writeBufferIndex], in, n);
g_cryptoIvWrite_writeBufferIndex += n;
}
UInt8
cryptoIv_mockRead(void* out, UInt32 n)
{
assert(g_cryptoIvWrite_readBufferIndex <= sizeof(g_cryptoIvWrite_buffer));
memcpy(out, &g_cryptoIvWrite_buffer[g_cryptoIvWrite_readBufferIndex], n);
g_cryptoIvWrite_readBufferIndex += n;
return n;
}

View File

@ -1,351 +0,0 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2013 Synergy Si Ltd.
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file COPYING that should have accompanied this file.
*
* 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
* 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 <http://www.gnu.org/licenses/>.
*/
#include "test/mock/io/MockStream.h"
#include "test/mock/synergy/MockEventQueue.h"
#include "synergy/PacketStreamFilter.h"
#include "io/CryptoStream.h"
#include "io/CryptoOptions.h"
#include "test/global/gtest.h"
using ::testing::_;
using ::testing::Invoke;
using ::testing::NiceMock;
using namespace std;
const byte kIv[] = "aaaaaaaaaaaaaaaa"; // AES block size = 16 (\0 not used)
UInt8 g_write_buffer[4];
void write_mockWrite(const void* in, UInt32 n);
UInt8 g_read_buffer[4];
UInt8 read_mockRead(void* out, UInt32 n);
UInt8 g_write4Read1_buffer[4];
UInt32 g_write4Read1_bufferIndex;
void write4Read1_mockWrite(const void* in, UInt32 n);
UInt8 write4Read1_mockRead(void* out, UInt32 n);
UInt8 g_write1Read4_buffer[4];
UInt32 g_write1Read4_bufferIndex;
void write1Read4_mockWrite(const void* in, UInt32 n);
UInt8 write1Read4_mockRead(void* out, UInt32 n);
UInt8 g_readWriteIvChanged_buffer[4];
UInt32 g_readWriteIvChangeTrigger_writeBufferIndex;
UInt32 g_readWriteIvChangeTrigger_readBufferIndex;
void readWriteIvChanged_mockWrite(const void* in, UInt32 n);
UInt8 readWriteIvChanged_mockRead(void* out, UInt32 n);
UInt8 g_readWriteIvChangeTrigger_buffer[4 + 4 + 16]; // abcd, DCIV, 16-byte IV
void readWriteIvChangeTrigger_mockWrite(const void* in, UInt32 n);
UInt8 readWriteIvChangeTrigger_mockRead(void* out, UInt32 n);
UInt8 g_newIvDoesNotChangeIv_buffer[1];
void newIvDoesNotChangeIv_mockWrite(const void* in, UInt32 n);
TEST(CryptoStreamTests, write)
{
const UInt32 size = 4;
UInt8* buffer = new UInt8[size];
buffer[0] = 'D';
buffer[1] = 'K';
buffer[2] = 'D';
buffer[3] = 'N';
NiceMock<MockEventQueue> eventQueue;
NiceMock<MockStream> innerStream;
CryptoOptions options("cfb", "mock");
ON_CALL(innerStream, write(_, _)).WillByDefault(Invoke(write_mockWrite));
CryptoStream cs(&eventQueue, &innerStream, options, false);
cs.setEncryptIv(kIv);
cs.write(buffer, size);
EXPECT_EQ(95, g_write_buffer[0]);
EXPECT_EQ(107, g_write_buffer[1]);
EXPECT_EQ(152, g_write_buffer[2]);
EXPECT_EQ(220, g_write_buffer[3]);
}
TEST(CryptoStreamTests, read)
{
NiceMock<MockEventQueue> eventQueue;
NiceMock<MockStream> innerStream;
CryptoOptions options("cfb", "mock");
ON_CALL(innerStream, read(_, _)).WillByDefault(Invoke(read_mockRead));
CryptoStream cs(&eventQueue, &innerStream, options, false);
cs.setEncryptIv(kIv);
cs.setDecryptIv(kIv);
g_read_buffer[0] = 95;
g_read_buffer[1] = 107;
g_read_buffer[2] = 152;
g_read_buffer[3] = 220;
const UInt32 size = 4;
UInt8* buffer = new UInt8[size];
cs.read(buffer, size);
EXPECT_EQ('D', buffer[0]);
EXPECT_EQ('K', buffer[1]);
EXPECT_EQ('D', buffer[2]);
EXPECT_EQ('N', buffer[3]);
}
TEST(CryptoStreamTests, write4Read1)
{
g_write4Read1_bufferIndex = 0;
NiceMock<MockEventQueue> eventQueue;
NiceMock<MockStream> innerStream;
CryptoOptions options("cfb", "mock");
ON_CALL(innerStream, write(_, _)).WillByDefault(Invoke(write4Read1_mockWrite));
ON_CALL(innerStream, read(_, _)).WillByDefault(Invoke(write4Read1_mockRead));
CryptoStream cs1(&eventQueue, &innerStream, options, false);
cs1.setEncryptIv(kIv);
cs1.write("a", 1);
cs1.write("b", 1);
cs1.write("c", 1);
cs1.write("d", 1);
CryptoStream cs2(&eventQueue, &innerStream, options, false);
cs2.setDecryptIv(kIv);
UInt8 buffer[4];
cs2.read(buffer, 4);
EXPECT_EQ('a', buffer[0]);
EXPECT_EQ('b', buffer[1]);
EXPECT_EQ('c', buffer[2]);
EXPECT_EQ('d', buffer[3]);
}
TEST(CryptoStreamTests, write1Read4)
{
g_write1Read4_bufferIndex = 0;
NiceMock<MockEventQueue> eventQueue;
NiceMock<MockStream> innerStream;
CryptoOptions options("cfb", "mock");
ON_CALL(innerStream, write(_, _)).WillByDefault(Invoke(write1Read4_mockWrite));
ON_CALL(innerStream, read(_, _)).WillByDefault(Invoke(write1Read4_mockRead));
CryptoStream cs1(&eventQueue, &innerStream, options, false);
cs1.setEncryptIv(kIv);
UInt8 bufferIn[4];
bufferIn[0] = 'a';
bufferIn[1] = 'b';
bufferIn[2] = 'c';
bufferIn[3] = 'd';
cs1.write(bufferIn, 4);
CryptoStream cs2(&eventQueue, &innerStream, options, false);
cs2.setDecryptIv(kIv);
UInt8 bufferOut[4];
cs2.read(&bufferOut[0], 1);
cs2.read(&bufferOut[1], 1);
cs2.read(&bufferOut[2], 1);
cs2.read(&bufferOut[3], 1);
EXPECT_EQ('a', bufferOut[0]);
EXPECT_EQ('b', bufferOut[1]);
EXPECT_EQ('c', bufferOut[2]);
EXPECT_EQ('d', bufferOut[3]);
}
TEST(CryptoStreamTests, readWriteIvChanged)
{
g_readWriteIvChangeTrigger_writeBufferIndex = 0;
g_readWriteIvChangeTrigger_readBufferIndex = 0;
NiceMock<MockEventQueue> eventQueue;
NiceMock<MockStream> innerStream;
CryptoOptions options("cfb", "mock");
ON_CALL(innerStream, write(_, _)).WillByDefault(Invoke(readWriteIvChanged_mockWrite));
ON_CALL(innerStream, read(_, _)).WillByDefault(Invoke(readWriteIvChanged_mockRead));
// AES block size = 16 (\0 not used)
const byte iv1[] = "aaaaaaaaaaaaaaaa";
const byte iv2[] = "bbbbbbbbbbbbbbbb";
CryptoStream cs1(&eventQueue, &innerStream, options, false);
cs1.setEncryptIv(iv1);
UInt8 bufferIn[4];
bufferIn[0] = 'a';
bufferIn[1] = 'b';
bufferIn[2] = 'c';
bufferIn[3] = 'd';
cs1.write(bufferIn, 4);
CryptoStream cs2(&eventQueue, &innerStream, options, false);
cs1.setDecryptIv(iv2);
UInt8 bufferOut[4];
cs2.read(bufferOut, 4);
// assert that the values cannot be decrypted, since the second crypto
// class instance is using a different IV.
EXPECT_NE('a', bufferOut[0]);
EXPECT_NE('b', bufferOut[1]);
EXPECT_NE('c', bufferOut[2]);
EXPECT_NE('d', bufferOut[3]);
// generate a new IV and copy it to the second crypto class, and
// ensure that the new IV is used.
byte iv[CRYPTO_IV_SIZE];
cs1.newIv(iv);
cs1.setEncryptIv(iv);
cs2.setDecryptIv(iv);
cs1.write(bufferIn, 4);
cs2.read(bufferOut, 4);
EXPECT_EQ('a', bufferOut[0]);
EXPECT_EQ('b', bufferOut[1]);
EXPECT_EQ('c', bufferOut[2]);
EXPECT_EQ('d', bufferOut[3]);
}
TEST(CryptoStreamTests, createKey)
{
byte hash1[16];
CryptoStream::createKey(hash1, "MockLongPassword", 16, 16);
EXPECT_EQ(hash1[0], 149);
EXPECT_EQ(hash1[15], 235);
byte hash2[32];
CryptoStream::createKey(hash2, "MockLongPassword", 32, 16);
EXPECT_EQ(hash2[0], 149);
EXPECT_EQ(hash2[15], 235);
EXPECT_EQ(hash2[31], 7);
byte hash3[32];
CryptoStream::createKey(hash3, "7accbf2f86a9191da0947107d4fe7054", 32, 16);
EXPECT_EQ(hash3[0], 120);
EXPECT_EQ(hash3[15], 11);
EXPECT_EQ(hash3[31], 233);
}
TEST(CryptoStreamTests, newIvDoesNotChangeIv)
{
NiceMock<MockEventQueue> eventQueue;
NiceMock<MockStream> innerStream;
CryptoOptions options("cfb", "mock");
ON_CALL(innerStream, write(_, _)).WillByDefault(Invoke(newIvDoesNotChangeIv_mockWrite));
CryptoStream cs1(&eventQueue, &innerStream, options, false);
cs1.write("a", 1);
EXPECT_EQ(175, g_newIvDoesNotChangeIv_buffer[0]);
byte iv[CRYPTO_IV_SIZE];
cs1.newIv(iv);
cs1.write("a", 1);
EXPECT_EQ(92, g_newIvDoesNotChangeIv_buffer[0]);
}
void
write_mockWrite(const void* in, UInt32 n)
{
memcpy(g_write_buffer, in, n);
}
UInt8
read_mockRead(void* out, UInt32 n)
{
memcpy(out, g_read_buffer, n);
return n;
}
void
write4Read1_mockWrite(const void* in, UInt32 n)
{
UInt8* buffer = static_cast<UInt8*>(const_cast<void*>(in));
g_write4Read1_buffer[g_write4Read1_bufferIndex++] = buffer[0];
}
UInt8
write4Read1_mockRead(void* out, UInt32 n)
{
memcpy(out, g_write4Read1_buffer, n);
return n;
}
void
write1Read4_mockWrite(const void* in, UInt32 n)
{
memcpy(g_write1Read4_buffer, in, n);
}
UInt8
write1Read4_mockRead(void* out, UInt32 n)
{
UInt8* buffer = static_cast<UInt8*>(out);
buffer[0] = g_write1Read4_buffer[g_write1Read4_bufferIndex++];
return 1;
}
void
readWriteIvChanged_mockWrite(const void* in, UInt32 n)
{
memcpy(g_readWriteIvChanged_buffer, in, n);
}
UInt8
readWriteIvChanged_mockRead(void* out, UInt32 n)
{
memcpy(out, g_readWriteIvChanged_buffer, n);
return n;
}
void
readWriteIvChangeTrigger_mockWrite(const void* in, UInt32 n)
{
assert(g_readWriteIvChangeTrigger_writeBufferIndex <= sizeof(g_readWriteIvChangeTrigger_buffer));
memcpy(&g_readWriteIvChangeTrigger_buffer[g_readWriteIvChangeTrigger_writeBufferIndex], in, n);
g_readWriteIvChangeTrigger_writeBufferIndex += n;
}
UInt8
readWriteIvChangeTrigger_mockRead(void* out, UInt32 n)
{
assert(g_readWriteIvChangeTrigger_readBufferIndex <= sizeof(g_readWriteIvChangeTrigger_buffer));
memcpy(out, &g_readWriteIvChangeTrigger_buffer[g_readWriteIvChangeTrigger_readBufferIndex], n);
g_readWriteIvChangeTrigger_readBufferIndex += n;
return n;
}
void
newIvDoesNotChangeIv_mockWrite(const void* in, UInt32 n)
{
memcpy(g_newIvDoesNotChangeIv_buffer, in, 1);
}

View File

@ -278,23 +278,6 @@ TEST(GenericArgsParsingTests, parseGenericArgs_ipcCmd_enableIpcTrue)
EXPECT_EQ(1, i); EXPECT_EQ(1, i);
} }
TEST(GenericArgsParsingTests, parseGenericArgs_cryptoPassCmd_savePassword)
{
int i = 1;
const int argc = 3;
const char* kCryptoPassCmd[argc] = { "stub", "--crypto-pass", "mock_password" };
ArgParser argParser(NULL);
ArgsBase argsBase;
argParser.setArgsBase(argsBase);
argParser.parseGenericArgs(argc, kCryptoPassCmd, i);
EXPECT_EQ("mock_password", argsBase.m_crypto.m_pass);
EXPECT_EQ(1, argsBase.m_crypto.m_mode); // 1 == kCfb
EXPECT_EQ(2, i);
}
#ifndef WINAPI_XWINDOWS #ifndef WINAPI_XWINDOWS
TEST(GenericArgsParsingTests, parseGenericArgs_dragDropCmdOnNonLinux_enableDragDropTrue) TEST(GenericArgsParsingTests, parseGenericArgs_dragDropCmdOnNonLinux_enableDragDropTrue)
{ {