added enable crypto argument to synergys/c #4313

This commit is contained in:
XinyuHou 2015-02-12 15:50:08 +00:00
parent bbcca144f5
commit c4c0fc8a08
24 changed files with 106 additions and 66 deletions

View File

@ -56,7 +56,8 @@ AppConfig::AppConfig(QSettings* settings) :
m_ProcessMode(DEFAULT_PROCESS_MODE),
m_AutoConfig(true),
m_ElevateMode(false),
m_AutoConfigPrompted(false)
m_AutoConfigPrompted(false),
m_CryptoEnabled(false)
{
Q_ASSERT(m_pSettings);
@ -128,6 +129,7 @@ void AppConfig::loadSettings()
m_Edition = settings().value("edition", Unknown).toInt();
m_ActivateEmail = settings().value("activateEmail", "").toString();
m_UserToken = settings().value("userToken", "").toString();
m_CryptoEnabled = settings().value("cryptoEnabled", false).toBool();
}
void AppConfig::saveSettings()
@ -147,6 +149,7 @@ void AppConfig::saveSettings()
settings().setValue("edition", m_Edition);
settings().setValue("activateEmail", m_ActivateEmail);
settings().setValue("userToken", m_UserToken);
settings().setValue("cryptoEnabled", m_CryptoEnabled);
}
void AppConfig::setAutoConfig(bool autoConfig)

View File

@ -85,6 +85,9 @@ class AppConfig
void persistLogDir();
bool elevateMode();
void setCryptoEnabled(bool e) { m_CryptoEnabled = e; }
bool getCryptoEnabled() { return m_CryptoEnabled; }
protected:
QSettings& settings() { return *m_pSettings; }
void setScreenName(const QString& s) { m_ScreenName = s; }
@ -119,6 +122,7 @@ class AppConfig
int m_Edition;
QString m_ActivateEmail;
QString m_UserToken;
bool m_CryptoEnabled;
static const char m_SynergysName[];
static const char m_SynergycName[];

View File

@ -127,6 +127,8 @@ MainWindow::MainWindow(QSettings& settings, AppConfig& appConfig) :
m_SuppressAutoConfigWarning = false;
m_pComboServerList->hide();
updateEdition();
}
MainWindow::~MainWindow()
@ -442,6 +444,10 @@ void MainWindow::startSynergy()
#endif
if (m_AppConfig.getCryptoEnabled()) {
args << "--enable-crypto";
}
if ((synergyType() == synergyClient && !clientArgs(args, app))
|| (synergyType() == synergyServer && !serverArgs(args, app)))
{
@ -814,15 +820,8 @@ void MainWindow::changeEvent(QEvent* event)
retranslateUi(this);
retranslateMenuBar();
QString mac = getFirstMacAddress();
QString hashSrc = m_AppConfig.activateEmail() + mac;
QString hashResult = hash(hashSrc);
if (hashResult == m_AppConfig.userToken()) {
setEdition(m_AppConfig.edition());
}
else {
setEdition(Unknown);
}
updateEdition();
break;
}
default:
@ -1149,6 +1148,19 @@ void MainWindow::promptAutoConfig()
m_AppConfig.setAutoConfigPrompted(true);
}
void MainWindow::updateEdition()
{
QString mac = getFirstMacAddress();
QString hashSrc = m_AppConfig.activateEmail() + mac;
QString hashResult = hash(hashSrc);
if (hashResult == m_AppConfig.userToken()) {
setEdition(m_AppConfig.edition());
}
else {
setEdition(Unknown);
}
}
void MainWindow::on_m_pComboServerList_currentIndexChanged(QString )
{
if (m_pComboServerList->count() != 0) {

View File

@ -160,6 +160,7 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase
bool isBonjourRunning();
void downloadBonjour();
void promptAutoConfig();
void updateEdition();
private:
QSettings& m_Settings;

View File

@ -7,11 +7,12 @@
#include <QMovie>
#include <QThread>
PluginWizardPage::PluginWizardPage(QWidget *parent) :
PluginWizardPage::PluginWizardPage(AppConfig& appConfig, QWidget *parent) :
QWizardPage(parent),
m_Finished(false),
m_pWebClient(NULL),
m_pPluginManager(NULL)
m_pPluginManager(NULL),
m_AppConfig(appConfig)
{
setupUi(this);
@ -79,6 +80,10 @@ void PluginWizardPage::finished()
{
updateStatus(tr("Plugins are ready."));
stopSpinning();
// ideally this should check if ns plugin is ready
m_AppConfig.setCryptoEnabled(true);
m_Finished = true;
emit completeChanged();
}

View File

@ -1,6 +1,8 @@
#ifndef PLUGINWIZARDPAGE_H
#define PLUGINWIZARDPAGE_H
#include "AppConfig.h"
#include "ui_PluginWizardPageBase.h"
#include <QWizardPage>
@ -12,7 +14,7 @@ class PluginWizardPage : public QWizardPage, public Ui::PluginWizardPage {
Q_OBJECT
public:
PluginWizardPage(QWidget *parent = 0);
PluginWizardPage(AppConfig& appConfig, QWidget *parent = 0);
~PluginWizardPage();
void setFinished(bool b) { m_Finished = b; }
@ -44,5 +46,6 @@ private:
WebClient* m_pWebClient;
PluginManager* m_pPluginManager;
QThread* m_pPluginManagerThread;
AppConfig& m_AppConfig;
};
#endif // PLUGINWIZARDPAGE_H

View File

@ -53,6 +53,8 @@ SettingsDialog::SettingsDialog(QWidget* parent, AppConfig& config) :
// elevate checkbox is only useful on ms windows.
m_pCheckBoxElevateMode->hide();
#endif
m_pCheckBoxEnableCrypto->setChecked(m_AppConfig.getCryptoEnabled());
}
void SettingsDialog::accept()
@ -120,10 +122,6 @@ void SettingsDialog::on_m_pButtonBrowseLog_clicked()
}
}
void SettingsDialog::on_m_pCheckBoxEnableCrypto_stateChanged(int )
{
}
void SettingsDialog::on_m_pComboLanguage_currentIndexChanged(int index)
{
QString ietfCode = m_pComboLanguage->itemData(index).toString();
@ -147,3 +145,8 @@ void SettingsDialog::on_m_pCheckBoxElevateMode_toggled(bool checked)
}
}
}
void SettingsDialog::on_m_pCheckBoxEnableCrypto_toggled(bool checked)
{
m_AppConfig.setCryptoEnabled(checked);
}

View File

@ -47,8 +47,8 @@ class SettingsDialog : public QDialog, public Ui::SettingsDialogBase
bool m_SuppressElevateWarning;
private slots:
void on_m_pCheckBoxEnableCrypto_toggled(bool checked);
void on_m_pCheckBoxElevateMode_toggled(bool checked);
void on_m_pCheckBoxEnableCrypto_stateChanged(int );
void on_m_pComboLanguage_currentIndexChanged(int index);
void on_m_pCheckBoxLogToFile_stateChanged(int );
void on_m_pButtonBrowseLog_clicked();

View File

@ -30,7 +30,7 @@ SetupWizard::SetupWizard(MainWindow& mainWindow, bool startMain) :
m_Edition(Unknown)
{
setupUi(this);
m_pPluginPage = new PluginWizardPage();
m_pPluginPage = new PluginWizardPage(mainWindow.appConfig());
addPage(m_pPluginPage);
#if defined(Q_OS_MAC)

View File

@ -18,8 +18,6 @@
#pragma once
#define PLUGINS_DIR "plugins"
#include "common/IInterface.h"
#include "common/stdmap.h"
#include "base/String.h"

View File

@ -173,12 +173,7 @@ ArchPluginUnix::invoke(
String
ArchPluginUnix::getPluginsDir()
{
#if WINAPI_XWINDOWS
return "/usr/lib/synergy/plugin";
#else
// TODO: pluging should be in bundle in the final release
return "/Users/xinyu/Projects/synergy/bin/plugins";
#endif
return ARCH->getPluginDirectory();
}
void

View File

@ -163,24 +163,6 @@ ArchPluginWindows::invoke(
}
}
String
ArchPluginWindows::getModuleDir()
{
TCHAR c_modulePath[MAX_PATH];
if (GetModuleFileName(NULL, c_modulePath, MAX_PATH) == 0) {
throw XArch(new XArchEvalWindows);
}
String modulePath(c_modulePath);
size_t lastSlash = modulePath.find_last_of("\\");
if (lastSlash != String::npos) {
return modulePath.substr(0, lastSlash);
}
throw XArch("could not get module path.");
}
void
ArchPluginWindows::getFilenames(const String& pattern, std::vector<String>& filenames)
{
@ -201,7 +183,7 @@ ArchPluginWindows::getFilenames(const String& pattern, std::vector<String>& file
String ArchPluginWindows::getPluginsDir()
{
return getModuleDir().append("\\").append(PLUGINS_DIR);
return ARCH->getPluginDirectory();
}
void

View File

@ -44,7 +44,6 @@ public:
void** args);
private:
String getModuleDir();
void getFilenames(const String& pattern, std::vector<String>& filenames);
String getPluginsDir();

View File

@ -60,7 +60,8 @@ Client::Client(
const String& name, const NetworkAddress& address,
ISocketFactory* socketFactory,
synergy::Screen* screen,
bool enableDragDrop) :
bool enableDragDrop,
bool enableCrypto) :
m_mock(false),
m_name(name),
m_serverAddress(address),
@ -103,6 +104,13 @@ Client::Client(
new TMethodEventJob<Client>(this,
&Client::handleFileRecieveCompleted));
}
if (enableCrypto) {
m_useSecureNetwork = ARCH->plugin().exists(s_networkSecurity);
if (m_useSecureNetwork == false) {
LOG((CLOG_NOTE "crypto disabled because of ns plugin not available"));
}
}
}
Client::~Client()
@ -152,7 +160,6 @@ Client::connect()
}
// create the socket
m_useSecureNetwork = ARCH->plugin().exists(s_networkSecurity);
IDataSocket* socket = m_socketFactory->create(m_useSecureNetwork);
m_socket = dynamic_cast<TCPSocket*>(socket);

View File

@ -59,7 +59,8 @@ public:
const String& name, const NetworkAddress& address,
ISocketFactory* socketFactory,
synergy::Screen* screen,
bool enableDragDrop);
bool enableDragDrop,
bool enableCrypto);
~Client();
#ifdef TEST_ENV

View File

@ -23,6 +23,8 @@
#include "net/TSocketMultiplexerMethodJob.h"
#include "arch/XArch.h"
static const char s_certificateFilename[] = { "Synergy.pem" };
//
// SecureListenSocket
//
@ -57,7 +59,15 @@ SecureListenSocket::accept()
socket->initSsl(true);
// TODO: customized certificate path
socket->loadCertificates("C:\\Temp\\synergy.pem");
String certificateFilename = ARCH->getProfileDirectory();
#if SYSAPI_WIN32
certificateFilename.append("\\");
#elif SYSAPI_UNIX
certificateFilename.append("/");
#endif
certificateFilename.append(s_certificateFilename);
socket->loadCertificates(certificateFilename.c_str());
socket->secureAccept();
if (socket != NULL) {

View File

@ -41,16 +41,24 @@ static const char s_networkSecurity[] = { "libns" };
ClientListener::ClientListener(const NetworkAddress& address,
ISocketFactory* socketFactory,
IEventQueue* events) :
IEventQueue* events,
bool enableCrypto) :
m_socketFactory(socketFactory),
m_server(NULL),
m_events(events)
m_events(events),
m_useSecureNetwork(false)
{
assert(m_socketFactory != NULL);
try {
// create listen socket
m_useSecureNetwork = ARCH->plugin().exists(s_networkSecurity);
if (enableCrypto) {
m_useSecureNetwork = ARCH->plugin().exists(s_networkSecurity);
if (m_useSecureNetwork == false) {
LOG((CLOG_NOTE "crypto disabled because of ns plugin not available"));
}
}
m_listen = m_socketFactory->createListen(m_useSecureNetwork);
// bind listen address

View File

@ -37,7 +37,8 @@ public:
// The factories are adopted.
ClientListener(const NetworkAddress&,
ISocketFactory*,
IEventQueue* events);
IEventQueue* events,
bool enableCrypto);
~ClientListener();
//! @name manipulators

View File

@ -276,6 +276,9 @@ ArgParser::parseGenericArgs(int argc, const char* const* argv, int& i)
argsBase().m_enableDragDrop = true;
}
}
else if (isArg(i, argc, argv, NULL, "--enable-crypto")) {
argsBase().m_enableCrypto = true;
}
else {
// option not supported here
return false;

View File

@ -41,7 +41,8 @@ m_disableTray(false),
m_enableIpc(false),
m_enableDragDrop(false),
m_shouldExit(false),
m_synergyAddress()
m_synergyAddress(),
m_enableCrypto(false)
{
}

View File

@ -46,4 +46,5 @@ public:
#endif
bool m_shouldExit;
String m_synergyAddress;
bool m_enableCrypto;
};

View File

@ -342,7 +342,8 @@ ClientApp::openClient(const String& name, const NetworkAddress& address,
address,
new TCPSocketFactory(m_events, getSocketMultiplexer()),
screen,
args().m_enableDragDrop);
args().m_enableDragDrop,
args().m_enableCrypto);
try {
m_events->adoptHandler(

View File

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

View File

@ -114,7 +114,7 @@ TEST_F(NetworkTests, sendToClient_mockData)
// server
SocketMultiplexer serverSocketMultiplexer;
TCPSocketFactory* serverSocketFactory = new TCPSocketFactory(&m_events, &serverSocketMultiplexer);
ClientListener listener(serverAddress, serverSocketFactory, &m_events);
ClientListener listener(serverAddress, serverSocketFactory, &m_events, false);
NiceMock<MockScreen> serverScreen;
NiceMock<MockPrimaryClient> primaryClient;
NiceMock<MockConfig> serverConfig;
@ -140,7 +140,7 @@ TEST_F(NetworkTests, sendToClient_mockData)
ON_CALL(clientScreen, getShape(_, _, _, _)).WillByDefault(Invoke(getScreenShape));
ON_CALL(clientScreen, getCursorPos(_, _)).WillByDefault(Invoke(getCursorPos));
Client client(&m_events, "stub", serverAddress, clientSocketFactory, &clientScreen, true);
Client client(&m_events, "stub", serverAddress, clientSocketFactory, &clientScreen, true, false);
m_events.adoptHandler(
m_events.forIScreen().fileRecieveCompleted(), &client,
@ -166,7 +166,7 @@ TEST_F(NetworkTests, sendToClient_mockFile)
// server
SocketMultiplexer serverSocketMultiplexer;
TCPSocketFactory* serverSocketFactory = new TCPSocketFactory(&m_events, &serverSocketMultiplexer);
ClientListener listener(serverAddress, serverSocketFactory, &m_events);
ClientListener listener(serverAddress, serverSocketFactory, &m_events, false);
NiceMock<MockScreen> serverScreen;
NiceMock<MockPrimaryClient> primaryClient;
NiceMock<MockConfig> serverConfig;
@ -192,7 +192,7 @@ TEST_F(NetworkTests, sendToClient_mockFile)
ON_CALL(clientScreen, getShape(_, _, _, _)).WillByDefault(Invoke(getScreenShape));
ON_CALL(clientScreen, getCursorPos(_, _)).WillByDefault(Invoke(getCursorPos));
Client client(&m_events, "stub", serverAddress, clientSocketFactory, &clientScreen, true);
Client client(&m_events, "stub", serverAddress, clientSocketFactory, &clientScreen, true, false);
m_events.adoptHandler(
m_events.forIScreen().fileRecieveCompleted(), &client,
@ -217,7 +217,7 @@ TEST_F(NetworkTests, sendToServer_mockData)
// server
SocketMultiplexer serverSocketMultiplexer;
TCPSocketFactory* serverSocketFactory = new TCPSocketFactory(&m_events, &serverSocketMultiplexer);
ClientListener listener(serverAddress, serverSocketFactory, &m_events);
ClientListener listener(serverAddress, serverSocketFactory, &m_events, false);
NiceMock<MockScreen> serverScreen;
NiceMock<MockPrimaryClient> primaryClient;
NiceMock<MockConfig> serverConfig;
@ -238,7 +238,7 @@ TEST_F(NetworkTests, sendToServer_mockData)
ON_CALL(clientScreen, getShape(_, _, _, _)).WillByDefault(Invoke(getScreenShape));
ON_CALL(clientScreen, getCursorPos(_, _)).WillByDefault(Invoke(getCursorPos));
Client client(&m_events, "stub", serverAddress, clientSocketFactory, &clientScreen, true);
Client client(&m_events, "stub", serverAddress, clientSocketFactory, &clientScreen, true, false);
m_events.adoptHandler(
m_events.forClientListener().connected(), &listener,
@ -269,7 +269,7 @@ TEST_F(NetworkTests, sendToServer_mockFile)
// server
SocketMultiplexer serverSocketMultiplexer;
TCPSocketFactory* serverSocketFactory = new TCPSocketFactory(&m_events, &serverSocketMultiplexer);
ClientListener listener(serverAddress, serverSocketFactory, &m_events);
ClientListener listener(serverAddress, serverSocketFactory, &m_events, false);
NiceMock<MockScreen> serverScreen;
NiceMock<MockPrimaryClient> primaryClient;
NiceMock<MockConfig> serverConfig;
@ -290,7 +290,7 @@ TEST_F(NetworkTests, sendToServer_mockFile)
ON_CALL(clientScreen, getShape(_, _, _, _)).WillByDefault(Invoke(getScreenShape));
ON_CALL(clientScreen, getCursorPos(_, _)).WillByDefault(Invoke(getCursorPos));
Client client(&m_events, "stub", serverAddress, clientSocketFactory, &clientScreen, true);
Client client(&m_events, "stub", serverAddress, clientSocketFactory, &clientScreen, true, false);
m_events.adoptHandler(
m_events.forClientListener().connected(), &listener,