From 547a038e48d4b73449fe6a12c3fc624f75126c89 Mon Sep 17 00:00:00 2001 From: sudden6 Date: Wed, 23 Oct 2019 01:05:04 +0200 Subject: [PATCH 1/6] refactor: remove AppImage update bridge When re-evaluating our dependencies we decided that the update bridge has a high potential for security issues because it's not widely used. Additionally similar functionality is already present in qTox. --- CMakeLists.txt | 17 ------- appimage/build.sh | 19 -------- src/net/updatecheck.cpp | 64 -------------------------- src/net/updatecheck.h | 26 ----------- src/widget/form/settings/aboutform.cpp | 11 ----- src/widget/form/settings/aboutform.h | 6 --- 6 files changed, 143 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f6d9da221..2e914f7c3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,7 +26,6 @@ set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) option(PLATFORM_EXTENSIONS "Enable platform specific extensions, requires extra dependencies" ON) option(USE_FILTERAUDIO "Enable the echo canceling backend" ON) option(UPDATE_CHECK "Enable automatic update check" ON) -option(APPIMAGE_UPDATER_BRIDGE "Use AppImageUpdaterBridge to do the update" OFF) option(USE_CCACHE "Use ccache when available" ON) option(SPELL_CHECK "Enable spell cheching support" ON) option(SVGZ_ICON "Compress the SVG icon of qTox" ON) @@ -56,11 +55,6 @@ if(APPLE) /usr/local/opt/openal-soft/lib/pkgconfig:$ENV{PKG_CONFIG_PATH}) endif() -if(${APPIMAGE_UPDATER_BRIDGE}) - set(ENV{PKG_CONFIG_PATH} - /usr/local/lib/pkgconfig:$ENV{PKG_CONFIG_PATH}) -endif() - execute_process( COMMAND brew --prefix qt5 OUTPUT_VARIABLE QT_PREFIX_PATH @@ -648,17 +642,6 @@ endif() if(${UPDATE_CHECK}) add_definitions(-DUPDATE_CHECK_ENABLED=1) - if(${APPIMAGE_UPDATER_BRIDGE}) - search_dependency(AIUB PACKAGE AppImageUpdaterBridge) - if(AIUB_FOUND) - message(STATUS "using AppImageUpdaterBridge") - add_definitions(-DAPPIMAGE_UPDATER_BRIDGE_ENABLED=1) - else() - message(STATUS "cannot find AppImageUpdaterBridge , ignoring cmake flag") - endif() - else() - message(STATUS "not using AppImageUpdaterBridge") - endif() set(${PROJECT_NAME}_SOURCES ${${PROJECT_NAME}_SOURCES} src/net/updatecheck.cpp src/net/updatecheck.h) diff --git a/appimage/build.sh b/appimage/build.sh index 1ab2296fe..eaa80c31c 100755 --- a/appimage/build.sh +++ b/appimage/build.sh @@ -47,12 +47,6 @@ readonly APT_FLAGS="-y --no-install-recommends" readonly SNORE_GIT="https://github.com/KDE/snorenotify" # snorenotify build directory readonly SNORE_BUILD_DIR="$BUILD_DIR"/snorenotify -# "appimage updater bridge" becomes aub -readonly AUB_SRC_DIR="$BUILD_DIR"/aub -# aub source -readonly AUB_GIT="https://github.com/antony-jr/AppImageUpdaterBridge" -# aub build dir -readonly AUB_BUILD_DIR="$BUILD_DIR"/aub/build # update information to be embeded in AppImage if [ "cron" == "${TRAVIS_EVENT_TYPE:-}" ] @@ -110,18 +104,6 @@ LDFLAGS="-lcrypto" make make install -# build aub into a static library and later use it in -# qTox -git clone "$AUB_GIT" "$AUB_SRC_DIR" -cd "$AUB_SRC_DIR" # we need to checkout first -git checkout tags/v1.1.2 -mkdir $AUB_BUILD_DIR -cd $AUB_BUILD_DIR -cmake .. -DLOGGING_DISABLED=ON - -make -make install - # copy qtox source cp -r "$QTOX_SRC_DIR" "$QTOX_BUILD_DIR" cd "$QTOX_BUILD_DIR" @@ -138,7 +120,6 @@ cd _build # need to build with -DDESKTOP_NOTIFICATIONS=True for snorenotify cmake -DDESKTOP_NOTIFICATIONS=True \ -DUPDATE_CHECK=True \ - -DAPPIMAGE_UPDATER_BRIDGE=True \ ../ make diff --git a/src/net/updatecheck.cpp b/src/net/updatecheck.cpp index d7075150e..c5ad70452 100644 --- a/src/net/updatecheck.cpp +++ b/src/net/updatecheck.cpp @@ -19,14 +19,7 @@ #include "src/net/updatecheck.h" #include "src/persistence/settings.h" -#ifndef APPIMAGE_UPDATER_BRIDGE_ENABLED #include -#else -#include -#include -#include -#include -#endif #include #include #include @@ -36,34 +29,16 @@ #include #include -#ifndef APPIMAGE_UPDATER_BRIDGE_ENABLED namespace { const QString versionUrl{QStringLiteral("https://api.github.com/repos/qTox/qTox/releases/latest")}; } // namespace -#else -using AppImageUpdaterBridge::AppImageDeltaRevisioner; -using AppImageUpdaterBridge::AppImageUpdaterDialog; -#endif UpdateCheck::UpdateCheck(const Settings& settings) : settings(settings) { updateTimer.start(1000 * 60 * 60 * 24 /* 1 day */); connect(&updateTimer, &QTimer::timeout, this, &UpdateCheck::checkForUpdate); -#ifndef APPIMAGE_UPDATER_BRIDGE_ENABLED connect(&manager, &QNetworkAccessManager::finished, this, &UpdateCheck::handleResponse); -#else - connect(&revisioner, &AppImageDeltaRevisioner::updateAvailable, this, &UpdateCheck::handleUpdate); - connect(&revisioner, &AppImageDeltaRevisioner::error, this, &UpdateCheck::updateCheckFailed, - Qt::DirectConnection); - - updateDialog.reset(new AppImageUpdaterDialog(QPixmap(":/img/icons/qtox.svg"))); - connect(updateDialog.data(), &AppImageUpdaterDialog::quit, QApplication::instance(), - &QApplication::quit, Qt::QueuedConnection); - connect(updateDialog.data(), &AppImageUpdaterDialog::canceled, this, &UpdateCheck::handleUpdateEnd); - connect(updateDialog.data(), &AppImageUpdaterDialog::finished, this, &UpdateCheck::handleUpdateEnd); - connect(updateDialog.data(), &AppImageUpdaterDialog::error, this, &UpdateCheck::handleUpdateEnd); -#endif } void UpdateCheck::checkForUpdate() @@ -72,30 +47,11 @@ void UpdateCheck::checkForUpdate() // still run the timer to check periodically incase setting changes return; } -#ifndef APPIMAGE_UPDATER_BRIDGE_ENABLED manager.setProxy(settings.getProxy()); QNetworkRequest request{versionUrl}; manager.get(request); -#else - revisioner.clear(); - revisioner.setProxy(settings.getProxy()); - revisioner.checkForUpdate(); -#endif } -#ifdef APPIMAGE_UPDATER_BRIDGE_ENABLED -void UpdateCheck::initUpdate() -{ - disconnect(&revisioner, &AppImageDeltaRevisioner::updateAvailable, this, - &UpdateCheck::handleUpdate); - disconnect(&revisioner, &AppImageDeltaRevisioner::error, this, &UpdateCheck::updateCheckFailed); - updateDialog->move(QGuiApplication::primaryScreen()->geometry().center() - - updateDialog->rect().center()); - updateDialog->init(&revisioner); -} -#endif - -#ifndef APPIMAGE_UPDATER_BRIDGE_ENABLED void UpdateCheck::handleResponse(QNetworkReply* reply) { assert(reply != nullptr); @@ -135,23 +91,3 @@ void UpdateCheck::handleResponse(QNetworkReply* reply) } reply->deleteLater(); } -#else -void UpdateCheck::handleUpdate(bool aval) -{ - if (aval) { - qInfo() << "Update available"; - emit updateAvailable(); - return; - } - qInfo() << "qTox is up to date"; - emit upToDate(); -} - -void UpdateCheck::handleUpdateEnd() -{ - connect(&revisioner, &AppImageDeltaRevisioner::error, this, &UpdateCheck::updateCheckFailed, - (Qt::ConnectionType)(Qt::DirectConnection | Qt::UniqueConnection)); - connect(&revisioner, &AppImageDeltaRevisioner::updateAvailable, this, - &UpdateCheck::handleUpdate, Qt::UniqueConnection); -} -#endif // APPIMAGE_UPDATER_BRIDGE_ENABLED diff --git a/src/net/updatecheck.h b/src/net/updatecheck.h index b732017cf..30edeedb9 100644 --- a/src/net/updatecheck.h +++ b/src/net/updatecheck.h @@ -20,12 +20,6 @@ #include #include -#ifdef APPIMAGE_UPDATER_BRIDGE_ENABLED -#include -#include -#include -#endif // APPIMAGE_UPDATER_BRIDGE_ENABLED - #include class Settings; @@ -41,35 +35,15 @@ public: void checkForUpdate(); signals: -#ifndef APPIMAGE_UPDATER_BRIDGE_ENABLED void updateAvailable(QString latestVersion, QUrl link); -#else - void updateAvailable(); -#endif void upToDate(); void updateCheckFailed(); -#ifndef APPIMAGE_UPDATER_BRIDGE_ENABLED private slots: void handleResponse(QNetworkReply* reply); -#endif - -#ifdef APPIMAGE_UPDATER_BRIDGE_ENABLED -public slots: - void initUpdate(); - -private slots: - void handleUpdate(bool); - void handleUpdateEnd(); -#endif private: -#ifndef APPIMAGE_UPDATER_BRIDGE_ENABLED QNetworkAccessManager manager; -#else - AppImageUpdaterBridge::AppImageDeltaRevisioner revisioner; - QScopedPointer updateDialog; -#endif // APPIMAGE_UPDATER_BRIDGE_ENABLED QTimer updateTimer; const Settings& settings; }; diff --git a/src/widget/form/settings/aboutform.cpp b/src/widget/form/settings/aboutform.cpp index da495ed1b..86189e75a 100644 --- a/src/widget/form/settings/aboutform.cpp +++ b/src/widget/form/settings/aboutform.cpp @@ -96,10 +96,6 @@ void AboutForm::replaceVersions() connect(updateCheck, &UpdateCheck::updateAvailable, this, &AboutForm::onUpdateAvailable); connect(updateCheck, &UpdateCheck::upToDate, this, &AboutForm::onUpToDate); connect(updateCheck, &UpdateCheck::updateCheckFailed, this, &AboutForm::onUpdateCheckFailed); -#ifdef APPIMAGE_UPDATER_BRIDGE_ENABLED - connect(bodyUI->updateAvailableButton, &QPushButton::clicked, updateCheck, - &UpdateCheck::initUpdate); -#endif } else { qWarning() << "AboutForm passed null UpdateCheck!"; } @@ -169,7 +165,6 @@ void AboutForm::replaceVersions() bodyUI->authorInfo->setText(authorInfo); } -#ifndef APPIMAGE_UPDATER_BRIDGE_ENABLED void AboutForm::onUpdateAvailable(QString latestVersion, QUrl link) { QObject::disconnect(linkConnection); @@ -177,12 +172,6 @@ void AboutForm::onUpdateAvailable(QString latestVersion, QUrl link) [link]() { QDesktopServices::openUrl(link); }); bodyUI->updateStack->setCurrentIndex(static_cast(updateIndex::available)); } -#else -void AboutForm::onUpdateAvailable() -{ - bodyUI->updateStack->setCurrentIndex(static_cast(updateIndex::available)); -} -#endif void AboutForm::onUpToDate() { diff --git a/src/widget/form/settings/aboutform.h b/src/widget/form/settings/aboutform.h index 5cccecfe0..9f4e2b7e7 100644 --- a/src/widget/form/settings/aboutform.h +++ b/src/widget/form/settings/aboutform.h @@ -45,11 +45,7 @@ public: } public slots: -#ifndef APPIMAGE_UPDATER_BRIDGE_ENABLED void onUpdateAvailable(QString latestVersion, QUrl link); -#else - void onUpdateAvailable(); -#endif void onUpToDate(); void onUpdateCheckFailed(); @@ -62,9 +58,7 @@ private: Ui::AboutSettings* bodyUI; QTimer* progressTimer; UpdateCheck* updateCheck; -#ifndef APPIMAGE_UPDATER_BRIDGE_ENABLED QMetaObject::Connection linkConnection; -#endif }; #endif // ABOUTFORM_H From 6fff5a59a478eaeb7a522260f795b4385b3600ad Mon Sep 17 00:00:00 2001 From: sudden6 Date: Wed, 23 Oct 2019 01:24:53 +0200 Subject: [PATCH 2/6] chore: update AppImage build tools --- appimage/build.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/appimage/build.sh b/appimage/build.sh index eaa80c31c..3c40f1d61 100755 --- a/appimage/build.sh +++ b/appimage/build.sh @@ -126,8 +126,8 @@ make make DESTDIR="$QTOX_APP_DIR" install ; find "$QTOX_APP_DIR" -# is master as of 2018-04-25 -LDQT_HASH="9c90a882ac744b5f704598e9588450ddfe487c67" +# is release #6 as of 2019-10-23 +LDQT_HASH="37631e5640d8f7c31182fa72b31266bbdf6939fc" # build linuxdeployqt git clone https://github.com/probonopd/linuxdeployqt.git "$LDQT_BUILD_DIR" cd "$LDQT_BUILD_DIR" @@ -136,8 +136,8 @@ qmake make make install -# is master as of 2018-04-25 -AITOOL_HASH="5d93115f279d94a4d23dfd64fb8ccd109e98f039" +# is release #12 as of 2019-10-23 +AITOOL_HASH="effcebc1d81c5e174a48b870cb420f490fb5fb4d" # build appimagetool git clone -b master --single-branch --recursive \ https://github.com/AppImage/AppImageKit "$AITOOL_BUILD_DIR" From 1fa35bfcb5287df60e4bc1e6596b0e77f4a1a685 Mon Sep 17 00:00:00 2001 From: sudden6 Date: Wed, 23 Oct 2019 01:29:16 +0200 Subject: [PATCH 3/6] chore: remove Debian bug workaround --- appimage/build.sh | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/appimage/build.sh b/appimage/build.sh index 3c40f1d61..e7a16dd44 100755 --- a/appimage/build.sh +++ b/appimage/build.sh @@ -35,8 +35,6 @@ readonly QTOX_APP_DIR="$BUILD_DIR"/appdir readonly LDQT_BUILD_DIR="$BUILD_DIR"/ldqt # "appimagetool" becomes aitool readonly AITOOL_BUILD_DIR="$BUILD_DIR"/aitool -# sqlcipher build directory -readonly SQLCIPHER_BUILD_DIR="$BUILD_DIR"/sqlcipher # ldqt binary readonly LDQT_BIN="/usr/lib/x86_64-linux-gnu/qt5/bin/linuxdeployqt" # aitool binary @@ -70,7 +68,7 @@ check checkinstall libavdevice-dev libexif-dev libgdk-pixbuf2.0-dev \ libgtk2.0-dev libopenal-dev libopus-dev libqrencode-dev libqt5opengl5-dev \ libqt5svg5-dev libsodium-dev libtool libvpx-dev libxss-dev \ qt5-default qttools5-dev qttools5-dev-tools qtdeclarative5-dev \ -fcitx-frontend-qt5 uim-qt5 +fcitx-frontend-qt5 uim-qt5 libsqlcipher-dev # get version cd "$QTOX_SRC_DIR" @@ -93,17 +91,6 @@ make install cd "$BUILD_DIR" -# we need a custom built sqlcipher version because of a Debian bug -# https://bugs.debian.org/850421 -git clone https://github.com/sqlcipher/sqlcipher.git "$SQLCIPHER_BUILD_DIR" -cd "$SQLCIPHER_BUILD_DIR" -git checkout tags/v3.4.2 -./configure --enable-tempstore=yes CFLAGS="-DSQLITE_HAS_CODEC" \ -LDFLAGS="-lcrypto" - -make -make install - # copy qtox source cp -r "$QTOX_SRC_DIR" "$QTOX_BUILD_DIR" cd "$QTOX_BUILD_DIR" From cf672375be4855e8d56c1fe4a6aabd089327c8e3 Mon Sep 17 00:00:00 2001 From: Anthony Bilinski Date: Wed, 16 Oct 2019 16:11:15 -0700 Subject: [PATCH 4/6] revert(toxme): remove toxme from qTox - the service is offline permanently As of 2019-10-09, toxme.io was taken offline permanently. Remove UI and code in qTox relating to it. Revert this commit if it comes back online in the future. Fix #5897 --- CMakeLists.txt | 4 - cmake/Testing.cmake | 1 - src/chatlog/textformatter.cpp | 1 - src/net/toxme.cpp | 295 ------------------------------ src/net/toxme.h | 56 ------ src/net/toxmedata.cpp | 194 -------------------- src/net/toxmedata.h | 55 ------ src/net/toxuri.cpp | 6 +- src/persistence/settings.cpp | 109 ----------- src/persistence/settings.h | 25 --- src/widget/form/addfriendform.cpp | 17 +- src/widget/form/profileform.cpp | 106 ----------- src/widget/form/profileform.h | 3 - src/widget/form/profileform.ui | 164 ----------------- test/net/toxmedata_test.cpp | 289 ----------------------------- 15 files changed, 7 insertions(+), 1318 deletions(-) delete mode 100644 src/net/toxme.cpp delete mode 100644 src/net/toxme.h delete mode 100644 src/net/toxmedata.cpp delete mode 100644 src/net/toxmedata.h delete mode 100644 test/net/toxmedata_test.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 2e914f7c3..fd3878dbc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -375,10 +375,6 @@ set(${PROJECT_NAME}_SOURCES src/net/bootstrapnodeupdater.h src/net/avatarbroadcaster.cpp src/net/avatarbroadcaster.h - src/net/toxme.cpp - src/net/toxme.h - src/net/toxmedata.cpp - src/net/toxmedata.h src/net/toxuri.cpp src/net/toxuri.h src/nexus.cpp diff --git a/cmake/Testing.cmake b/cmake/Testing.cmake index a142ca375..ff248070b 100644 --- a/cmake/Testing.cmake +++ b/cmake/Testing.cmake @@ -39,7 +39,6 @@ auto_test(core contactid) auto_test(core toxid) auto_test(core toxstring) auto_test(chatlog textformatter) -auto_test(net toxmedata) auto_test(net bsu) auto_test(persistence paths) auto_test(persistence dbschema) diff --git a/src/chatlog/textformatter.cpp b/src/chatlog/textformatter.cpp index 40a5d65ef..51617042b 100644 --- a/src/chatlog/textformatter.cpp +++ b/src/chatlog/textformatter.cpp @@ -89,7 +89,6 @@ static const QVector URI_WORD_PATTERNS = { QRegularExpression(QStringLiteral(R"((?<=^|\s)\S*((file|smb)://([\S| ]*)))")), QRegularExpression(QStringLiteral(R"((?<=^|\s)\S*(tox:[a-zA-Z\d]{76}))")), QRegularExpression(QStringLiteral(R"((?<=^|\s)\S*(mailto:\S+@\S+\.\S+))")), - QRegularExpression(QStringLiteral(R"((?<=^|\s)\S*(tox:\S+@\S+))")), QRegularExpression(QStringLiteral(R"((?<=^|\s)\S*(magnet:[?]((xt(.\d)?=urn:)|(mt=)|(kt=)|(tr=)|(dn=)|(xl=)|(xs=)|(as=)|(x.))[\S| ]+))")), }; diff --git a/src/net/toxme.cpp b/src/net/toxme.cpp deleted file mode 100644 index 227222c02..000000000 --- a/src/net/toxme.cpp +++ /dev/null @@ -1,295 +0,0 @@ -/* - Copyright © 2015-2019 by The qTox Project Contributors - - This file is part of qTox, a Qt-based graphical interface for Tox. - - qTox is libre software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - qTox 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 qTox. If not, see . -*/ - -#include "toxme.h" -#include "src/core/core.h" -#include "src/core/toxpk.h" -#include "src/net/toxmedata.h" -#include "src/persistence/settings.h" - -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -static ToxmeData toxmeData; - -/** - * @class Toxme - * @brief This class implements a client for the toxme.se API - * - * @note The class is thread safe - * @note May process events while waiting for blocking calls - */ - -QByteArray Toxme::makeJsonRequest(QString url, QString json, QNetworkReply::NetworkError& error) -{ - if (error) - return QByteArray(); - - QNetworkAccessManager netman; - netman.setProxy(Settings::getInstance().getProxy()); - QNetworkRequest request{url}; - request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); - QNetworkReply* reply = netman.post(request, json.toUtf8()); - - while (!reply->isFinished()) { - QThread::msleep(1); - qApp->processEvents(); - } - - QByteArray result = reply->readAll(); - delete reply; - return result; -} - -QByteArray Toxme::getServerPubkey(QString url, QNetworkReply::NetworkError& error) -{ - if (error) - return QByteArray(); - - // Get key - QNetworkAccessManager netman; - netman.setProxy(Settings::getInstance().getProxy()); - QNetworkRequest request{url}; - request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); - QNetworkReply* reply = netman.get(request); - - while (!reply->isFinished()) { - QThread::msleep(1); - qApp->processEvents(); - } - - error = reply->error(); - if (error) { - qWarning() << "getServerPubkey: A network error occured:" << reply->errorString(); - return QByteArray(); - } - - QString json = reply->readAll(); - delete reply; - return toxmeData.parsePublicKey(json); -} - -QByteArray Toxme::prepareEncryptedJson(QString url, int action, QString payload) -{ - QPair keypair = Core::getInstance()->getKeypair(); - if (keypair.first.isEmpty() || keypair.second.isEmpty()) { - qWarning() << "prepareEncryptedJson: Couldn't get our keypair, aborting"; - return QByteArray(); - } - - QNetworkReply::NetworkError error = QNetworkReply::NoError; - QByteArray key = getServerPubkey(url, error); - if (error != QNetworkReply::NoError) - return QByteArray(); - - QByteArray nonce(crypto_box_NONCEBYTES, 0); - randombytes((uint8_t*)nonce.data(), crypto_box_NONCEBYTES); - - QByteArray payloadData = payload.toUtf8(); - const size_t cypherlen = crypto_box_MACBYTES + payloadData.size(); - unsigned char* payloadEnc = new unsigned char[cypherlen]; - - int cryptResult = crypto_box_easy(payloadEnc, (uint8_t*)payloadData.data(), payloadData.size(), - (uint8_t*)nonce.data(), (unsigned char*)key.constData(), - (uint8_t*)keypair.second.data()); - - if (cryptResult != 0) // error - return QByteArray(); - - QByteArray payloadEncData(reinterpret_cast(payloadEnc), cypherlen); - delete[] payloadEnc; - - return toxmeData.encryptedJson(action, keypair.first, payloadEncData, nonce).toUtf8(); -} - -/** - * @brief Converts a toxme address to a Tox ID. - * @param address Toxme address. - * @return Found ToxId (an empty ID on error). - */ -ToxId Toxme::lookup(QString address) -{ - // JSON injection ? - address = address.trimmed(); - address.replace('\\', "\\\\"); - address.replace('"', "\""); - - const QString json = toxmeData.lookupRequest(address); - - QString apiUrl = "https://" + address.split(QLatin1Char('@')).last() + "/api"; - QNetworkReply::NetworkError error = QNetworkReply::NoError; - QString response = makeJsonRequest(apiUrl, json, error); - - if (error != QNetworkReply::NoError) - return ToxId(); - - return toxmeData.lookup(response); -} - -/** - * @brief Creates a new toxme address associated with a Tox ID. - * @param[out] code Tox error code @see getErrorMessage. - * @param[in] server Create toxme account on this server. - * @param[in] id ToxId of current user. - * @param[in] address Create toxme account with this adress. - * @param[in] keepPrivate If true, the address will not be published on toxme site. - * @param[in] bio A short optional description of yourself if you want to publish your address. - * @return password on success, else sets code parameter and returns an empty QString. - */ -QString Toxme::createAddress(ToxmeData::ExecCode& code, QString server, ToxId id, QString address, - bool keepPrivate, QString bio) -{ - // JSON injection ? - bio.replace('\\', "\\\\"); - bio.replace('"', "\""); - - address.replace('\\', "\\\\"); - address.replace('"', "\""); - - bio = bio.trimmed(); - address = address.trimmed(); - server = server.trimmed(); - if (!server.contains("://")) - server = "https://" + server; - - const QString payload = toxmeData.createAddressRequest(id, address, bio, keepPrivate); - QString pubkeyUrl = server + "/pk"; - QString apiUrl = server + "/api"; - QNetworkReply::NetworkError error = QNetworkReply::NoError; - QByteArray encrypted = prepareEncryptedJson(pubkeyUrl, 1, payload); - QByteArray response = makeJsonRequest(apiUrl, encrypted, error); - - code = toxmeData.extractCode(response); - if ((code != ToxmeData::Ok && code != ToxmeData::Updated) || error != QNetworkReply::NoError) - return QString(); - - return toxmeData.getPass(response, code); -} - -/** - * @brief Deletes the address associated with your current Tox ID. - * @param server Server to delete the address from. - * @param id ToxId to delete. - * @return Status code returned from server. - */ -ToxmeData::ExecCode Toxme::deleteAddress(QString server, ToxPk pk) -{ - const QString payload = toxmeData.deleteAddressRequest(pk); - - server = server.trimmed(); - if (!server.contains("://")) - server = "https://" + server; - - QString pubkeyUrl = server + "/pk"; - QString apiUrl = server + "/api"; - QNetworkReply::NetworkError error = QNetworkReply::NoError; - QByteArray response = makeJsonRequest(apiUrl, prepareEncryptedJson(pubkeyUrl, 2, payload), error); - - return toxmeData.extractCode(response); -} - -/** - * @brief Return string of the corresponding error code - * @param errorCode Code to get error message - * @return Source error message - */ -QString Toxme::getErrorMessage(int errorCode) -{ - switch (errorCode) { - case ToxmeData::IncorrectResponse: - return "Incorrect response"; - case ToxmeData::NoPassword: - return "No password in response"; - case ToxmeData::ServerError: - return "Server doesn't support Toxme"; - case -1: - return "You must send POST requests to /api"; - case -2: - return "Problem with HTTPS connection"; - case -3: - return "I was unable to read your encrypted payload"; - case -4: - return "You're making too many requests. Wait an hour and try again"; - case -25: - return "This name is already in use"; - case -26: - return "This Tox ID is already registered under another name"; - case -27: - return "Please don't use a space in your name"; - case -28: - return "Password incorrect"; - case -29: - return "You can't use this name"; - case -30: - return "Name not found"; - case -31: - return "Tox ID not sent"; - case -41: - return "Lookup failed because the server replied with invalid data"; - case -42: - return "That user does not exist"; - case -43: - return "Internal lookup error. Please file a bug"; - default: - return QString("Unknown error (%1)").arg(errorCode); - } -} - -/** - * @brief Return translated error message - * @param errorCode Code to translate - * @return Translated Toxme error message - */ -QString Toxme::translateErrorMessage(int errorCode) -{ - switch (errorCode) { - case ToxmeData::ServerError: - return QObject::tr("Server doesn't support Toxme"); - case -2: - return QObject::tr("Problem with HTTPS connection"); - case -4: - return QObject::tr("You're making too many requests. Wait an hour and try again"); - case -25: - return QObject::tr("This name is already in use"); - case -26: - return QObject::tr("This Tox ID is already registered under another name"); - case -27: - return QObject::tr("Please don't use a space in your name"); - case -28: - return QObject::tr("Password incorrect"); - case -29: - return QObject::tr("You can't use this name"); - case -30: - return QObject::tr("Name not found"); - case -31: - return QObject::tr("Tox ID not sent"); - case -42: - return QObject::tr("That user does not exist"); - default: - return QObject::tr("Internal ToxMe error"); - } -} diff --git a/src/net/toxme.h b/src/net/toxme.h deleted file mode 100644 index cb0a285ab..000000000 --- a/src/net/toxme.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - Copyright © 2015-2019 by The qTox Project Contributors - - This file is part of qTox, a Qt-based graphical interface for Tox. - - qTox is libre software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - qTox 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 qTox. If not, see . -*/ - - -#ifndef TOXME_H -#define TOXME_H - -#include "src/core/toxid.h" -#include "src/net/toxmedata.h" -#include -#include -#include -#include -#include - -class QNetworkAccessManager; - -class Toxme -{ -public: - static ToxId lookup(QString address); - static QString createAddress(ToxmeData::ExecCode& code, QString server, ToxId id, - QString address, bool keepPrivate = true, QString bio = QString()); - static ToxmeData::ExecCode deleteAddress(QString server, ToxPk id); - static QString getErrorMessage(int errorCode); - static QString translateErrorMessage(int errorCode); - -private: - Toxme() = delete; - static QByteArray makeJsonRequest(QString url, QString json, QNetworkReply::NetworkError& error); - static QByteArray prepareEncryptedJson(QString url, int action, QString payload); - static QByteArray getServerPubkey(QString url, QNetworkReply::NetworkError& error); - static ToxmeData::ExecCode extractError(QString json); - -private: - static const QMap pubkeyUrls; - static const QMap apiUrls; -}; - -#endif // TOXME_H diff --git a/src/net/toxmedata.cpp b/src/net/toxmedata.cpp deleted file mode 100644 index 100fbe597..000000000 --- a/src/net/toxmedata.cpp +++ /dev/null @@ -1,194 +0,0 @@ -/* - Copyright © 2017-2019 by The qTox Project Contributors - - This file is part of qTox, a Qt-based graphical interface for Tox. - - qTox is libre software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - qTox 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 qTox. If not, see . -*/ - -#include "toxmedata.h" -#include "src/core/toxid.h" - -#include -#include -#include -#include - -namespace { -namespace consts { -namespace keys { -const QString Key{QStringLiteral("key")}; -const QString Action{QStringLiteral("action")}; -const QString PublicKey{QStringLiteral("public_key")}; -const QString Encrypted{QStringLiteral("encrypted")}; -const QString Nonce{QStringLiteral("nonce")}; -const QString Name{QStringLiteral("name")}; -const QString ToxId{QStringLiteral("tox_id")}; -const QString Code{QStringLiteral("c")}; -const QString Bio{QStringLiteral("bio")}; -const QString Privacy{QStringLiteral("privacy")}; -const QString Timestamp{QStringLiteral("timestamp")}; -const QString Password{QStringLiteral("password")}; -} -} -} - -static qint64 getCurrentTime() -{ - return QDateTime::currentDateTimeUtc().toMSecsSinceEpoch() / 1000; -} - -/** - * @brief Get server public key from Json. - * @param text Json text. - * @return Server public key. - */ -QByteArray ToxmeData::parsePublicKey(const QString& text) const -{ - const QJsonObject json = QJsonDocument::fromJson(text.toLatin1()).object(); - const QString& key = json[consts::keys::Key].toString(); - return QByteArray::fromHex(key.toLatin1()); -} - -/** - * @brief Build Json with encrypted payload. - * @param action Action number. - * @param pk User public key - * @param encrypted Encrypted payload. - * @param nonce Crypto nonce. - * @return Json with action and encrypted payload. - */ -QString ToxmeData::encryptedJson(int action, const QByteArray& pk, const QByteArray& encrypted, - const QByteArray& nonce) const -{ - const QJsonObject json = { - { consts::keys::Action, action }, - { consts::keys::PublicKey, QString{pk.toHex()} }, - { consts::keys::Encrypted, QString{encrypted.toBase64()} }, - { consts::keys::Nonce, QString{nonce.toBase64()} }, - }; - - return QJsonDocument{json}.toJson(QJsonDocument::Compact); -} - -/** - * @brief Build lookup request Json. - * @param address Address to lookup. - * @return Json to lookup. - */ -QString ToxmeData::lookupRequest(const QString& address) const -{ - const QJsonObject json = { - { consts::keys::Action, 3 }, - { consts::keys::Name, address }, - }; - - return QJsonDocument{json}.toJson(QJsonDocument::Compact); -} - -/** - * @brief Extract ToxId from lookup Json. - * @param inText Json text. - * @return User ToxId. - */ -ToxId ToxmeData::lookup(const QString& inText) const -{ - const QJsonObject json = QJsonDocument::fromJson(inText.toLatin1()).object(); - const QString& text = json[consts::keys::ToxId].toString(); - return ToxId{text}; -} - -/** - * @brief Extract toxme result code. - * @param srcJson Json text. - * @return Toxme code result. - */ -ToxmeData::ExecCode ToxmeData::extractCode(const QString& srcJson) const -{ - const QJsonObject json = QJsonDocument::fromJson(srcJson.toLatin1()).object(); - if (json.isEmpty()) { - return ServerError; - } - - const int code = json[consts::keys::Code].toInt(INT32_MAX); - if (code == INT32_MAX) { - return IncorrectResponse; - } - - return ExecCode(code); -} - -/** - * @brief Build create address request Json. - * @param id Self ToxId. - * @param address Preferred address. - * @param bio Self biography. - * @param keepPrivate If true, the address will not be published on toxme site. - * @return Json to register Toxme address. - */ -QString ToxmeData::createAddressRequest(const ToxId id, const QString& address, const QString& bio, - bool keepPrivate) const -{ - const QJsonObject json = { - { consts::keys::Bio, bio }, - { consts::keys::Name, address }, - { consts::keys::ToxId, id.toString() }, - { consts::keys::Privacy, keepPrivate ? 0 : 2 }, - { consts::keys::Timestamp, getCurrentTime() }, - }; - - return QJsonDocument{json}.toJson(QJsonDocument::Compact); -} - -/** - * @brief Extrace password from Json answer. - * @param srcJson[in] Json text. - * @param code[out] Result code. Changed if password not extracted. - * @return Extracted password. - */ -QString ToxmeData::getPass(const QString& srcJson, ToxmeData::ExecCode& code) -{ - const QJsonObject json = QJsonDocument::fromJson(srcJson.toLatin1()).object(); - if (json.isEmpty()) { - code = ToxmeData::NoPassword; - return QString{}; - } - - const QJsonValue pass = json[consts::keys::Password]; - if (pass.isNull()) { - code = ToxmeData::Updated; - return QString{}; - } - - if (!pass.isString()) { - code = ToxmeData::IncorrectResponse; - return QString{}; - } - - return pass.toString(); -} - -/** - * @brief Build Json to delete address. - * @param pk Self public key. - * @return Json to delete address. - */ -QString ToxmeData::deleteAddressRequest(const ToxPk& pk) -{ - QJsonObject json = { - { consts::keys::PublicKey, pk.toString() }, - { consts::keys::Timestamp, getCurrentTime() }, - }; - return QJsonDocument{json}.toJson(QJsonDocument::Compact); -} diff --git a/src/net/toxmedata.h b/src/net/toxmedata.h deleted file mode 100644 index b68270e31..000000000 --- a/src/net/toxmedata.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - Copyright © 2017-2019 by The qTox Project Contributors - - This file is part of qTox, a Qt-based graphical interface for Tox. - - qTox is libre software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - qTox 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 qTox. If not, see . -*/ - -#ifndef TOXME_DATA_H -#define TOXME_DATA_H - -#include - -#include "src/core/toxid.h" - -class QString; - -class ToxmeData -{ -public: - enum ExecCode - { - ExecError = -50, - Ok = 0, - Updated = 1, - ServerError = 2, - IncorrectResponse = 3, - NoPassword = 4 - }; - - QByteArray parsePublicKey(const QString& text) const; - QString encryptedJson(int action, const QByteArray& pk, const QByteArray& encrypted, - const QByteArray& nonce) const; - QString lookupRequest(const QString& address) const; - ToxId lookup(const QString& text) const; - - ExecCode extractCode(const QString& json) const; - QString createAddressRequest(const ToxId id, const QString& address, const QString& bio, - bool keepPrivate) const; - QString getPass(const QString& json, ToxmeData::ExecCode& code); - QString deleteAddressRequest(const ToxPk& pk); -}; - -#endif // TOXME_DATA_H diff --git a/src/net/toxuri.cpp b/src/net/toxuri.cpp index 93ac4ce07..be8859d1b 100644 --- a/src/net/toxuri.cpp +++ b/src/net/toxuri.cpp @@ -19,7 +19,6 @@ #include "src/net/toxuri.h" #include "src/core/core.h" -#include "src/net/toxme.h" #include "src/nexus.h" #include "src/widget/gui.h" #include "src/widget/tool/friendrequestdialog.h" @@ -66,10 +65,7 @@ bool handleToxURI(const QString& toxURI) ToxId toxId(toxaddr); QString error = QString(); if (!toxId.isValid()) { - toxId = Toxme::lookup(toxaddr); - if (!toxId.isValid()) { - error = QMessageBox::tr("%1 is not a valid Toxme address.").arg(toxaddr); - } + error = QMessageBox::tr("%1 is not a valid Tox address.").arg(toxaddr); } else if (toxId == core->getSelfId()) { error = QMessageBox::tr("You can't add yourself as a friend!", "When trying to add your own Tox ID as friend"); diff --git a/src/persistence/settings.cpp b/src/persistence/settings.cpp index 4187f3f04..29d1c0946 100644 --- a/src/persistence/settings.cpp +++ b/src/persistence/settings.cpp @@ -53,9 +53,6 @@ * @warning Don't use it to save every single thing you want to save, use it * for some general purpose widgets, such as MainWindows or Splitters, * which have widget->saveX() and widget->loadX() methods. - * - * @var QString Settings::toxmeInfo - * @brief Toxme info like name@server */ const QString Settings::globalSettingsFile = "qtox.ini"; @@ -581,15 +578,6 @@ void Settings::loadPersonal(QString profileName, const ToxEncrypt* passKey) ps.endArray(); } ps.endGroup(); - - ps.beginGroup("Toxme"); - { - toxmeInfo = ps.value("info", "").toString(); - toxmeBio = ps.value("bio", "").toString(); - toxmePriv = ps.value("priv", false).toBool(); - toxmePass = ps.value("pass", "").toString(); - } - ps.endGroup(); } void Settings::resetToDefault() @@ -851,16 +839,6 @@ void Settings::savePersonal(QString profileName, const ToxEncrypt* passkey) ps.setValue("blackList", blackList.join('\n')); } ps.endGroup(); - - ps.beginGroup("Toxme"); - { - ps.setValue("info", toxmeInfo); - ps.setValue("bio", toxmeBio); - ps.setValue("priv", toxmePriv); - ps.setValue("pass", toxmePass); - } - ps.endGroup(); - ps.save(); } @@ -1276,93 +1254,6 @@ void Settings::setTranslation(const QString& newValue) } } -void Settings::deleteToxme() -{ - setToxmeInfo(""); - setToxmeBio(""); - setToxmePriv(false); - setToxmePass(""); -} - -void Settings::setToxme(QString name, QString server, QString bio, bool priv, QString pass) -{ - setToxmeInfo(name + "@" + server); - setToxmeBio(bio); - setToxmePriv(priv); - if (!pass.isEmpty()) - setToxmePass(pass); -} - -QString Settings::getToxmeInfo() const -{ - QMutexLocker locker{&bigLock}; - return toxmeInfo; -} - -void Settings::setToxmeInfo(const QString& info) -{ - QMutexLocker locker{&bigLock}; - - if (info != toxmeInfo) { - if (info.split("@").size() == 2) { - toxmeInfo = info; - emit toxmeInfoChanged(toxmeInfo); - } else { - qWarning() << info << "is not a valid toxme string -> value ignored."; - } - } -} - -QString Settings::getToxmeBio() const -{ - QMutexLocker locker{&bigLock}; - return toxmeBio; -} - -void Settings::setToxmeBio(const QString& bio) -{ - QMutexLocker locker{&bigLock}; - - if (bio != toxmeBio) { - toxmeBio = bio; - emit toxmeBioChanged(toxmeBio); - } -} - -bool Settings::getToxmePriv() const -{ - QMutexLocker locker{&bigLock}; - return toxmePriv; -} - -void Settings::setToxmePriv(bool priv) -{ - QMutexLocker locker{&bigLock}; - - if (priv != toxmePriv) { - toxmePriv = priv; - emit toxmePrivChanged(toxmePriv); - } -} - -QString Settings::getToxmePass() const -{ - QMutexLocker locker{&bigLock}; - return toxmePass; -} - -void Settings::setToxmePass(const QString& pass) -{ - QMutexLocker locker{&bigLock}; - - if (pass != toxmePass) { - toxmePass = pass; - - // password is not exposed for security reasons - emit toxmePassChanged(); - } -} - bool Settings::getForceTCP() const { QMutexLocker locker{&bigLock}; diff --git a/src/persistence/settings.h b/src/persistence/settings.h index 1712fefcd..780e3fc70 100644 --- a/src/persistence/settings.h +++ b/src/persistence/settings.h @@ -190,10 +190,6 @@ signals: void notifyHideChanged(bool enabled); void groupAlwaysNotifyChanged(bool enabled); void translationChanged(const QString& translation); - void toxmeInfoChanged(const QString& info); - void toxmeBioChanged(const QString& bio); - void toxmePrivChanged(bool priv); - void toxmePassChanged(); void currentProfileIdChanged(quint32 id); void enableLoggingChanged(bool enabled); void autoAwayTimeChanged(int minutes); @@ -276,21 +272,6 @@ public: QString getTranslation() const; void setTranslation(const QString& newValue); - // Toxme - void deleteToxme(); - void setToxme(QString name, QString server, QString bio, bool priv, QString pass = ""); - QString getToxmeInfo() const; - void setToxmeInfo(const QString& info); - - QString getToxmeBio() const; - void setToxmeBio(const QString& bio); - - bool getToxmePriv() const; - void setToxmePriv(bool priv); - - QString getToxmePass() const; - void setToxmePass(const QString& pass); - void setAutoSaveEnabled(bool newValue); bool getAutoSaveEnabled() const; @@ -642,12 +623,6 @@ private: QString currentProfile; uint32_t currentProfileId; - // Toxme Info - QString toxmeInfo; - QString toxmeBio; - bool toxmePriv; - QString toxmePass; - bool enableLogging; int autoAwayTime; diff --git a/src/widget/form/addfriendform.cpp b/src/widget/form/addfriendform.cpp index bd6d9973d..5519eed2d 100644 --- a/src/widget/form/addfriendform.cpp +++ b/src/widget/form/addfriendform.cpp @@ -19,7 +19,6 @@ #include "addfriendform.h" #include "src/core/core.h" -#include "src/net/toxme.h" #include "src/nexus.h" #include "src/persistence/settings.h" #include "src/widget/contentlayout.h" @@ -53,8 +52,7 @@ namespace bool checkIsValidId(const QString& id) { - static const QRegularExpression dnsIdExpression("^\\S+@\\S+$"); - return ToxId::isToxId(id) || id.contains(dnsIdExpression); + return ToxId::isToxId(id); } } @@ -112,7 +110,7 @@ AddFriendForm::AddFriendForm() // accessibility stuff toxIdLabel.setAccessibleDescription( - tr("Tox ID, either 76 hexadecimal characters or name@example.com")); + tr("Tox ID, 76 hexadecimal characters")); toxId.setAccessibleDescription(tr("Type in Tox ID of your friend")); messageLabel.setAccessibleDescription(tr("Friend request message")); message.setAccessibleDescription(tr( @@ -202,12 +200,9 @@ void AddFriendForm::addFriend(const QString& idText) ToxId friendId(idText); if (!friendId.isValid()) { - friendId = Toxme::lookup(idText); // Try Toxme - if (!friendId.isValid()) { - GUI::showWarning(tr("Couldn't add friend"), - tr("%1 Tox ID is invalid or does not exist", "Toxme error").arg(idText)); - return; - } + GUI::showWarning(tr("Couldn't add friend"), + tr("%1 Tox ID is invalid", "Tox address error").arg(idText)); + return; } deleteFriendRequest(friendId); @@ -289,7 +284,7 @@ void AddFriendForm::onIdChanged(const QString& id) //: Tox ID of the person you're sending a friend request to const QString toxIdText(tr("Tox ID")); //: Tox ID format description - const QString toxIdComment(tr("either 76 hexadecimal characters or name@example.com")); + const QString toxIdComment(tr("76 hexadecimal characters")); const QString labelText = isValidId ? QStringLiteral("%1 (%2)") : QStringLiteral("%1 (%2)"); diff --git a/src/widget/form/profileform.cpp b/src/widget/form/profileform.cpp index 91454142f..9b75b084c 100644 --- a/src/widget/form/profileform.cpp +++ b/src/widget/form/profileform.cpp @@ -21,7 +21,6 @@ #include "ui_profileform.h" #include "src/core/core.h" #include "src/model/profile/iprofileinfo.h" -#include "src/net/toxme.h" #include "src/persistence/profile.h" #include "src/persistence/profilelocker.h" #include "src/persistence/settings.h" @@ -120,22 +119,8 @@ ProfileForm::ProfileForm(IProfileInfo* profileInfo, QWidget* parent) delete toxIdGroup->replaceWidget(bodyUI->toxId, toxId); // Original toxId is in heap, delete it bodyUI->toxId->hide(); - /* Toxme section init */ - bodyUI->toxmeServersList->addItem("toxme.io"); - QString toxmeInfo = Settings::getInstance().getToxmeInfo(); - // User not registered - if (toxmeInfo.isEmpty()) { - showRegisterToxme(); - } else { - showExistingToxme(); - } - bodyUI->qrLabel->setWordWrap(true); - QRegExp re("[^@ ]+"); - QRegExpValidator* validator = new QRegExpValidator(re, this); - bodyUI->toxmeUsername->setValidator(validator); - profilePicture = new MaskablePixmapWidget(this, QSize(64, 64), ":/img/avatar_mask.svg"); profilePicture->setPixmap(QPixmap(":/img/contact_dark.svg")); profilePicture->setContextMenuPolicy(Qt::CustomContextMenu); @@ -180,10 +165,6 @@ ProfileForm::ProfileForm(IProfileInfo* profileInfo, QWidget* parent) this, &ProfileForm::setPasswordButtonsText); connect(bodyUI->saveQr, &QPushButton::clicked, this, &ProfileForm::onSaveQrClicked); connect(bodyUI->copyQr, &QPushButton::clicked, this, &ProfileForm::onCopyQrClicked); - connect(bodyUI->toxmeRegisterButton, &QPushButton::clicked, - this, &ProfileForm::onRegisterButtonClicked); - connect(bodyUI->toxmeUpdateButton, &QPushButton::clicked, - this, &ProfileForm::onRegisterButtonClicked); connect(profileInfo, &IProfileInfo::usernameChanged, this, [=](const QString& val) { bodyUI->userName->setText(val); }); @@ -485,90 +466,3 @@ void ProfileForm::retranslateUi() "you.\nShare it with your friends to communicate.\n\n" "This ID includes the NoSpam code (in blue), and the checksum (in gray).")); } - -void ProfileForm::showRegisterToxme() -{ - bodyUI->toxmeUsername->setText(""); - bodyUI->toxmeBio->setText(""); - bodyUI->toxmePrivacy->setChecked(false); - - bodyUI->toxmeRegisterButton->show(); - bodyUI->toxmeUpdateButton->hide(); - bodyUI->toxmePassword->hide(); - bodyUI->toxmePasswordLabel->hide(); -} - -void ProfileForm::showExistingToxme() -{ - QStringList info = Settings::getInstance().getToxmeInfo().split("@"); - bodyUI->toxmeUsername->setText(info[0]); - bodyUI->toxmeServersList->addItem(info[1]); - - QString bio = Settings::getInstance().getToxmeBio(); - bodyUI->toxmeBio->setText(bio); - - bool priv = Settings::getInstance().getToxmePriv(); - bodyUI->toxmePrivacy->setChecked(priv); - - QString pass = Settings::getInstance().getToxmePass(); - bodyUI->toxmePassword->setText(pass); - bodyUI->toxmePassword->show(); - bodyUI->toxmePasswordLabel->show(); - - bodyUI->toxmeRegisterButton->hide(); - bodyUI->toxmeUpdateButton->show(); -} - -void ProfileForm::onRegisterButtonClicked() -{ - QString name = bodyUI->toxmeUsername->text(); - if (name.isEmpty()) { - return; - } - - bodyUI->toxmeRegisterButton->setEnabled(false); - bodyUI->toxmeUpdateButton->setEnabled(false); - bodyUI->toxmeRegisterButton->setText(tr("Register (processing)")); - bodyUI->toxmeUpdateButton->setText(tr("Update (processing)")); - - QString id = toxId->text(); - id.remove(QRegularExpression("<[^>]*>")); - QString bio = bodyUI->toxmeBio->text(); - QString server = bodyUI->toxmeServersList->currentText(); - bool privacy = bodyUI->toxmePrivacy->isChecked(); - - Core* oldCore = Core::getInstance(); - - ToxmeData::ExecCode code = ToxmeData::ExecCode::Ok; - QString response = Toxme::createAddress(code, server, ToxId(id), name, privacy, bio); - - Core* newCore = Core::getInstance(); - // Make sure the user didn't logout (or logout and login) - // before the request is finished, else qTox will crash. - if (oldCore == newCore) { - switch (code) { - case ToxmeData::Updated: - GUI::showInfo(tr("Done!"), tr("Account %1@%2 updated successfully").arg(name, server)); - Settings::getInstance().setToxme(name, server, bio, privacy); - showExistingToxme(); - break; - case ToxmeData::Ok: - GUI::showInfo(tr("Done!"), - tr("Successfully added %1@%2 to the database. Save your password") - .arg(name, server)); - Settings::getInstance().setToxme(name, server, bio, privacy, response); - showExistingToxme(); - break; - default: - QString errorMessage = Toxme::getErrorMessage(code); - qWarning() << errorMessage; - QString translated = Toxme::translateErrorMessage(code); - GUI::showWarning(tr("Toxme error"), translated); - } - - bodyUI->toxmeRegisterButton->setEnabled(true); - bodyUI->toxmeUpdateButton->setEnabled(true); - bodyUI->toxmeRegisterButton->setText(tr("Register")); - bodyUI->toxmeUpdateButton->setText(tr("Update")); - } -} diff --git a/src/widget/form/profileform.h b/src/widget/form/profileform.h index ec2403a96..6555d8c31 100644 --- a/src/widget/form/profileform.h +++ b/src/widget/form/profileform.h @@ -80,15 +80,12 @@ private slots: void onChangePassClicked(); void onAvatarClicked(); void showProfilePictureContextMenu(const QPoint& point); - void onRegisterButtonClicked(); private: - void showExistingToxme(); void retranslateUi(); void prFileLabelUpdate(); bool eventFilter(QObject* object, QEvent* event); void refreshProfiles(); - void showRegisterToxme(); static QString getSupportedImageFilter(); private: diff --git a/src/widget/form/profileform.ui b/src/widget/form/profileform.ui index b629533a0..bd5533f51 100644 --- a/src/widget/form/profileform.ui +++ b/src/widget/form/profileform.ui @@ -264,163 +264,6 @@ Share it with your friends to communicate. - - - - Register on ToxMe - - - - - - - - My username - - - - - - - Name for the ToxMe service. - - - ToxMe username to be shown on ToxMe - - - false - - - - - - - Optional. Something about you. Or your cat. - - - My biography - - - - - - - Optional. Something about you. Or your cat. - - - Optional ToxMe biography to be shown on ToxMe - - - - - - - ToxMe service to register on. - - - Server - - - - - - - true - - - ToxMe service to register on. - - - ToxMe service address - - - true - - - -1 - - - - - - - If not set, ToxMe entries are publicly visible. - - - Visibility on the ToxMe service - - - Hide my name from the public list - - - - - - - true - - - Register on ToxMe - - - Register - - - false - - - false - - - false - - - - - - - true - - - Your password - - - - - - - Password - - - false - - - true - - - false - - - - - - - - - Update ToxMe entry - - - Update - - - - - - - - - - @@ -618,13 +461,6 @@ Profile does not contain your history. toxId saveQr copyQr - toxmeUsername - toxmeBio - toxmeServersList - toxmePrivacy - toxmeRegisterButton - toxmeUpdateButton - toxmePassword renameButton deleteButton exportButton diff --git a/test/net/toxmedata_test.cpp b/test/net/toxmedata_test.cpp deleted file mode 100644 index d2a657ea9..000000000 --- a/test/net/toxmedata_test.cpp +++ /dev/null @@ -1,289 +0,0 @@ -/* - Copyright © 2017-2019 by The qTox Project Contributors - - This file is part of qTox, a Qt-based graphical interface for Tox. - - qTox is libre software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - qTox 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 qTox. If not, see . -*/ - -#include "src/net/toxmedata.h" - -#include - -#include -#include -#include -#include - -const QByteArray testToxId = - QByteArrayLiteral("\xC7\x71\x9C\x68\x08\xC1\x4B\x77\x34\x80\x04\x95\x6D\x1D\x98\x04" - "\x6C\xE0\x9A\x34\x37\x0E\x76\x08\x15\x0E\xAD\x74\xC3\x81\x5D\x30" - "\xC8\xBA\x3A\xB9\xBE\xB9"); -const QByteArray testPublicKey = - QByteArrayLiteral("\xC7\x71\x9C\x68\x08\xC1\x4B\x77\x34\x80\x04\x95\x6D\x1D\x98\x04" - "\x6C\xE0\x9A\x34\x37\x0E\x76\x08\x15\x0E\xAD\x74\xC3\x81\x5D\x30"); - -class TestToxmeData : public QObject -{ - Q_OBJECT -private slots: - void parsePublicKeyTest(); - void encryptedJsonTest(); - void lookupRequestTest(); - - void lookup_data(); - void lookup(); - - void extractCode_data(); - void extractCode(); - - void createAddressRequest(); - - void getPassTest_data(); - void getPassTest(); - - void deleteAddressRequestTest(); -}; - -/** - * @brief Test if parse public key works correctly. - */ -void TestToxmeData::parsePublicKeyTest() -{ - ToxmeData data; - QString publicKeyStr = testPublicKey.toHex(); - QString json = QStringLiteral(R"({"key": "%1"})").arg(publicKeyStr); - QByteArray result = data.parsePublicKey(json); - QCOMPARE(result, testPublicKey); - - json = QStringLiteral("Some wrong string"); - result = data.parsePublicKey(json); - QVERIFY(result.isEmpty()); -} - -/** - * @brief Test if generation action json with encrypted payload is correct. - */ -void TestToxmeData::encryptedJsonTest() -{ - ToxmeData data; - int action = 123; - QByteArray encrypted{QStringLiteral("sometext").toLatin1()}; - QByteArray nonce{QStringLiteral("nonce").toLatin1()}; - QString text = data.encryptedJson(action, testPublicKey, encrypted, nonce); - QJsonObject json = QJsonDocument::fromJson(text.toLatin1()).object(); - - int actionRes = json["action"].toInt(); - QCOMPARE(actionRes, 123); - - QByteArray pkRes = QByteArray::fromHex(json["public_key"].toString().toLatin1()); - QCOMPARE(pkRes, testPublicKey); - - QByteArray encRes = QByteArray::fromBase64(json["encrypted"].toString().toLatin1()); - QCOMPARE(encRes, encrypted); - - QByteArray nonceRes = QByteArray::fromBase64(json["nonce"].toString().toLatin1()); - QCOMPARE(nonceRes, nonce); -} - -/** - * @brief Test if request for lookup generated correctly. - */ -void TestToxmeData::lookupRequestTest() -{ - ToxmeData data; - QString json = QStringLiteral(R"({"action":3,"name":"testname"})"); - QString result = data.lookupRequest("testname"); - QCOMPARE(result, json); -} - -Q_DECLARE_METATYPE(ToxId) - -/** - * @brief Data function for lookup test. - */ -void TestToxmeData::lookup_data() -{ - qRegisterMetaType("ToxId"); - QTest::addColumn("input", nullptr); - QTest::addColumn("result", nullptr); - QString sToxId = testToxId.toHex(); - - QTest::newRow("Valid ToxId") << QStringLiteral(R"({"tox_id": "%1"})").arg(sToxId) - << ToxId(testToxId); - - QTest::newRow("Invalid ToxId") << QStringLiteral(R"({"tox_id": "SomeTextHere"})") - << ToxId{}; - QTest::newRow("Not json") << QStringLiteral("Not json string") - << ToxId{}; -} - -/** - * @brief Test if ToxId parsed from lookup response correcly. - */ -void TestToxmeData::lookup() -{ - QFETCH(QString, input); - QFETCH(ToxId, result); - ToxmeData data; - ToxId toxId = data.lookup(input); - QCOMPARE(result, toxId); -} - -Q_DECLARE_METATYPE(ToxmeData::ExecCode) - -/** - * @brief Data function for extractCode test. - */ -void TestToxmeData::extractCode_data() -{ - qRegisterMetaType("ToxmeData::ExecCode"); - QTest::addColumn("input", nullptr); - QTest::addColumn("result", nullptr); - - QTest::newRow("Custom code") << QStringLiteral(R"({"c": 123})") - << ToxmeData::ExecCode(123); - QTest::newRow("Ok code") << QStringLiteral(R"({"c": 0})") - << ToxmeData::ExecCode::Ok; - - QTest::newRow("String code") << QStringLiteral(R"({"c": "string here"})") - << ToxmeData::ExecCode::IncorrectResponse; - QTest::newRow("Invalid code") << QStringLiteral(R"({"c": text})") - << ToxmeData::ExecCode::ServerError; - QTest::newRow("Not json") << QStringLiteral("Not json string") - << ToxmeData::ExecCode::ServerError; -} - -/** - * @brief Test if exec code extracts correctly. - */ -void TestToxmeData::extractCode() -{ - QFETCH(QString, input); - QFETCH(ToxmeData::ExecCode, result); - ToxmeData data; - ToxmeData::ExecCode code = data.extractCode(input); - QCOMPARE(result, code); -} - -/** - * @brief Test if request for address creation is correct. - */ -void TestToxmeData::createAddressRequest() -{ - ToxmeData data; - ToxId id{testToxId}; - QString name{"Test address"}; - QString bio{"Bio text"}; - bool keepPrivate = true; - int timestamp = static_cast(time(nullptr)); - QString text = data.createAddressRequest(id, name, bio, keepPrivate); - QJsonObject json = QJsonDocument::fromJson(text.toLatin1()).object(); - - QByteArray toxIdData = QByteArray::fromHex(json["tox_id"].toString().toLatin1()); - ToxId toxIdRes{toxIdData}; - QCOMPARE(toxIdRes, id); - - QString nameRes = json["name"].toString(); - QCOMPARE(nameRes, name); - - bool privRes = json["privacy"].toInt(); - QCOMPARE(privRes, privRes); - - QString bioRes = json["bio"].toString(); - QCOMPARE(bioRes, bio); - - int timeRes = json["timestamp"].toInt(); - // Test will be failed if `createAddressRequest` will take more - // than 100 seconds - QVERIFY(qAbs(timeRes - timestamp) < 100); -} - -/** - * @brief Data function for getPassTest. - */ -void TestToxmeData::getPassTest_data() -{ - qRegisterMetaType("ToxmeData::ExecCode"); - QTest::addColumn("input", nullptr); - QTest::addColumn("result", nullptr); - QTest::addColumn("code", nullptr); - - QTest::newRow("Valid password") << QStringLiteral(R"({"password": "123qwe"})") - << QStringLiteral("123qwe") - << ToxmeData::ExecCode::Ok; - - QTest::newRow("Null password") << QStringLiteral(R"({"password": null})") - << QStringLiteral("") - << ToxmeData::ExecCode::Updated; - - QTest::newRow("Valid password with null") << QStringLiteral(R"({"password": "null"})") - << QStringLiteral("null") - << ToxmeData::ExecCode::Ok; - - // ERROR: password value with invalid text, but started with 'null' interpreted as Update -#if 0 - QTest::newRow("Invalid null password") << QStringLiteral(R"({"password": nulla})") - << QStringLiteral("") - << ToxmeData::ExecCode::IncorrectResponse; -#endif - - QTest::newRow("Invalid int password") << QStringLiteral(R"({"password": 123})") - << QStringLiteral("") - << ToxmeData::ExecCode::IncorrectResponse; - - QTest::newRow("Not json") << QStringLiteral("Not json") - << QStringLiteral("") - << ToxmeData::ExecCode::NoPassword; - -} - -/** - * @brief Test if password extraction is correct. - */ -void TestToxmeData::getPassTest() -{ - QFETCH(QString, input); - QFETCH(QString, result); - QFETCH(ToxmeData::ExecCode, code); - - ToxmeData data; - ToxmeData::ExecCode resCode = ToxmeData::ExecCode::Ok; - QString password = data.getPass(input, resCode); - QCOMPARE(password, result); - QCOMPARE(resCode, code); -} - -/** - * @brief Test if request for address deletation generated correct. - */ -void TestToxmeData::deleteAddressRequestTest() -{ - ToxmeData data; - ToxPk pk{testPublicKey}; - int timestamp = static_cast(time(nullptr)); - QString text = data.deleteAddressRequest(pk); - QJsonObject json = QJsonDocument::fromJson(text.toLatin1()).object(); - - QByteArray pkRes = QByteArray::fromHex(json["public_key"].toString().toLatin1()); - QCOMPARE(pkRes, testPublicKey); - - int timeRes = json["timestamp"].toInt(); - // Test will be failed if `deleteAddressRequest` will take more - // than 100 seconds - QVERIFY(qAbs(timeRes - timestamp) < 100); -} - -QTEST_GUILESS_MAIN(TestToxmeData) -#include "toxmedata_test.moc" From bdb3b61ee0420fb43a5097dc950f302370716558 Mon Sep 17 00:00:00 2001 From: accelsao Date: Tue, 14 Jan 2020 09:04:55 +0800 Subject: [PATCH 5/6] fix(net): check if the node has all needed fields Fixes ##5766 --- src/net/bootstrapnodeupdater.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/net/bootstrapnodeupdater.cpp b/src/net/bootstrapnodeupdater.cpp index f87608282..347ec4f73 100644 --- a/src/net/bootstrapnodeupdater.cpp +++ b/src/net/bootstrapnodeupdater.cpp @@ -117,7 +117,7 @@ void BootstrapNodeUpdater::jsonNodeToDhtServer(const QJsonObject& node, QList Date: Sat, 18 Jan 2020 01:05:33 +0000 Subject: [PATCH 6/6] fix(build): appease appstream-glib validate Flathub builds fail if appdata file does not pass appstream-glib validate. --- res/io.github.qtox.qTox.appdata.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/res/io.github.qtox.qTox.appdata.xml b/res/io.github.qtox.qTox.appdata.xml index 69335fd36..f5ae32fa2 100644 --- a/res/io.github.qtox.qTox.appdata.xml +++ b/res/io.github.qtox.qTox.appdata.xml @@ -53,11 +53,11 @@ https://i.imgur.com/olb89CN.png - A sample conversation taking place on qTox. + A sample conversation taking place on qTox https://i.imgur.com/tmX8z9s.png - A sample groupchat discussion taking place on qTox. + A sample groupchat discussion taking place on qTox https://qtox.github.io