native windows http get for premium auth

This commit is contained in:
Nick Bolton
2014-02-04 19:41:29 +00:00
parent b0a02fc94b
commit 7f08036ff3
21 changed files with 606 additions and 43 deletions

View File

@@ -40,7 +40,8 @@ SOURCES += src/main.cpp \
src/IpcReader.cpp \
src/Ipc.cpp \
src/SynergyLocale.cpp \
src/QUtility.cpp
src/QUtility.cpp \
src/PremiumAuth.cpp
HEADERS += src/MainWindow.h \
src/AboutDialog.h \
src/ServerConfig.h \
@@ -55,7 +56,7 @@ HEADERS += src/MainWindow.h \
src/HotkeyDialog.h \
src/ActionDialog.h \
src/Hotkey.h \
src/Action.h \
src/Action.h \
src/KeySequence.h \
src/KeySequenceWidget.h \
src/SettingsDialog.h \
@@ -67,7 +68,8 @@ HEADERS += src/MainWindow.h \
src/IpcReader.h \
src/Ipc.h \
src/SynergyLocale.h \
src/QUtility.h
src/QUtility.h \
src/PremiumAuth.h
RESOURCES += res/Synergy.qrc
RC_FILE = res/win/Synergy.rc
macx {

View File

@@ -0,0 +1,48 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2014 Bolton Software 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 "PremiumAuth.h"
#include "QUtility.h"
#include <QProcess>
#include <QCoreApplication>
// we use syntool to authenticate because Qt's http library is very
// unreliable, and since we're writing platform specific code, use the
// synergy code since there we can use integ tests.
QString PremiumAuth::auth(const QString& email, const QString& password)
{
QString program(QCoreApplication::applicationDirPath() + "/syntool");
QStringList args("--premium-auth");
QProcess process;
process.setReadChannel(QProcess::StandardOutput);
process.start(program, args);
if (process.waitForStarted())
{
// hash password in case it contains interesting chars.
QString credentials(email + ":" + hash(password) + "\n");
process.write(credentials.toStdString().c_str());
if (process.waitForFinished()) {
return process.readLine();
}
}
return "";
}

26
src/gui/src/PremiumAuth.h Normal file
View File

@@ -0,0 +1,26 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2014 Bolton Software 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 <QString>
class PremiumAuth
{
public:
QString auth(const QString& email, const QString& password);
};

View File

@@ -19,6 +19,7 @@
#include "MainWindow.h"
#include "QSynergyApplication.h"
#include "QUtility.h"
#include "PremiumAuth.h"
#include <QMessageBox>
#include <QDesktopServices>
@@ -26,8 +27,6 @@
#include <QNetworkRequest>
#include <QNetworkReply>
//#define PREMIUM_AUTH_URL "http://localhost/synergy/premium/json/auth/"
#define PREMIUM_AUTH_URL "http://synergy-foss.org/premium/json/auth/"
#define PREMIUM_REGISTER_URL "http://synergy-foss.org/donate/?source=gui-wizard"
SetupWizard::SetupWizard(MainWindow& mainWindow, bool startMain) :
@@ -250,39 +249,11 @@ void SetupWizard::on_m_pRadioButtonPremiumLogin_toggled(bool checked)
bool SetupWizard::isPremiumLoginValid(QMessageBox& message)
{
// hash the email and password and send it over plain-text,
// it would be nice to use SSL, but unfortunately the Qt
// implementation is unreliable.
QString email = hash(m_pLineEditPremiumEmail->text());
QString password = hash(m_pLineEditPremiumPassword->text());
QString email = m_pLineEditPremiumEmail->text();
QString password = m_pLineEditPremiumPassword->text();
QString requestJson = "{\"email\":\"" + email + "\",\"password\":\"" + password + "\"}";
QByteArray requestData(requestJson.toStdString().c_str());
QString version = m_MainWindow.versionChecker().getVersion();
QString userAgent = "Synergy GUI " + version;
QByteArray userAgentData(userAgent.toStdString().c_str());
QNetworkRequest request(QUrl(PREMIUM_AUTH_URL));
request.setRawHeader("User-Agent", userAgentData);
QUrl params;
params.addEncodedQueryItem("json", requestData);
QNetworkReply* reply = m_Network.post(request, params.encodedQuery());
// use loop instead of waitForReadyRead (which doesnt seem to work).
QEventLoop loop;
connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
loop.exec();
if (reply->error() != QNetworkReply::NoError) {
message.setText(tr("Login failed, an error occurred.\n\nError: %1").arg(reply->errorString()));
message.exec();
return false;
}
QByteArray responseData = reply->readAll();
QString responseJson(responseData);
PremiumAuth auth;
QString responseJson = auth.auth(email, password);
// this feels like a lot of work, but its cheaper than getting a json
// parsing library involved.

View File

@@ -46,7 +46,6 @@ private:
MainWindow& m_MainWindow;
bool m_StartMain;
SynergyLocale m_Locale;
QNetworkAccessManager m_Network;
private slots:
void on_m_pCheckBoxEnableCrypto_stateChanged(int );