From 53670f5e814add7bb96c135eda6deaa6ef0356db Mon Sep 17 00:00:00 2001 From: Tobias Fella Date: Sat, 13 Mar 2021 21:23:10 +0100 Subject: [PATCH] Use QtKeychain on Android --- CMakeLists.txt | 12 ++++++------ src/controller.cpp | 17 ++--------------- 2 files changed, 8 insertions(+), 21 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f38a2536b..14e3a8567 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,18 +48,18 @@ set_package_properties(KF5Kirigami2 PROPERTIES PURPOSE "Kirigami application UI framework" ) +find_package(Qt5Keychain) +set_package_properties(Qt5Keychain PROPERTIES + TYPE REQUIRED + PURPOSE "Secure storage of account secrets" +) + if(ANDROID) find_package(OpenSSL) set_package_properties(OpenSSL PROPERTIES TYPE REQUIRED PURPOSE "Encrypted communications" ) -else() - find_package(Qt5Keychain) - set_package_properties(Qt5Keychain PROPERTIES - TYPE REQUIRED - PURPOSE "Secure storage of account secrets" - ) endif() if (NOT ANDROID AND NOT WIN32 AND NOT APPLE) diff --git a/src/controller.cpp b/src/controller.cpp index 63df1b056..e93c49cfa 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -6,9 +6,8 @@ */ #include "controller.h" -#ifndef Q_OS_ANDROID #include -#endif + #include #include #include @@ -145,7 +144,6 @@ void Controller::logout(Connection *conn, bool serverSideLogout) SettingsGroup("Accounts").remove(conn->userId()); QFile(accessTokenFileName(AccountSettings(conn->userId()))).remove(); -#ifndef Q_OS_ANDROID QKeychain::DeletePasswordJob job(qAppName()); job.setAutoDelete(true); job.setKey(conn->userId()); @@ -153,11 +151,7 @@ void Controller::logout(Connection *conn, bool serverSideLogout) QKeychain::DeletePasswordJob::connect(&job, &QKeychain::Job::finished, &loop, &QEventLoop::quit); job.start(); loop.exec(); -#else - KConfig config("neochat_tokens"); - KConfigGroup tokensGroup(&config, "Tokens"); - tokensGroup.deleteEntry(conn->userId()); -#endif + conn->stopSync(); Q_EMIT conn->stateChanged(); Q_EMIT conn->loggedOut(); @@ -340,7 +334,6 @@ bool Controller::saveAccessTokenToFile(const AccountSettings &account, const QBy bool Controller::saveAccessTokenToKeyChain(const AccountSettings &account, const QByteArray &accessToken) { -#ifndef Q_OS_ANDROID qDebug() << "Save the access token to the keychain for " << account.userId(); QKeychain::WritePasswordJob job(qAppName()); job.setAutoDelete(false); @@ -355,12 +348,6 @@ bool Controller::saveAccessTokenToKeyChain(const AccountSettings &account, const qWarning() << "Could not save access token to the keychain: " << qPrintable(job.errorString()); return saveAccessTokenToFile(account, accessToken); } - -#else - KConfig config("neochat_tokens"); - KConfigGroup tokensGroup(&config, "Tokens"); - tokensGroup.writeEntry(account.userId(), accessToken); -#endif return true; }