Replace vfs_encryption_enabled by QSettings to avoid keychain check at startup.

vfs_encryption_enabled is now used only to check if vfs is mandatory on first start.
This commit is contained in:
Julien Wadel 2023-04-04 16:53:07 +02:00
parent 06eedaaf6f
commit 1f7f79c702
6 changed files with 77 additions and 39 deletions

View file

@ -43,15 +43,7 @@ AppController::AppController (int &argc, char *argv[]) {
Q_ASSERT(!mApp);
// Disable QML cache. Avoid malformed cache.
qputenv("QML_DISABLE_DISK_CACHE", "true");
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
// Useful to share camera on Fullscreen (other context)
QApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
// Do not use APPLICATION_NAME here.
// The EXECUTABLE_NAME will be used in qt standard paths. It's our goal.
QCoreApplication::setApplicationName(EXECUTABLE_NAME);
QApplication::setOrganizationDomain(EXECUTABLE_NAME);
QCoreApplication::setApplicationVersion(APPLICATION_SEMVER);
initQtAppDetails();
#ifdef ENABLE_APP_WEBVIEW
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
mApp = new App(argc, argv);
@ -126,4 +118,16 @@ void AppController::stopApp(){
}
catch(...){
}
}
void AppController::initQtAppDetails(){
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
// Useful to share camera on Fullscreen (other context)
QApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
// Do not use APPLICATION_NAME here.
// The EXECUTABLE_NAME will be used in qt standard paths. It's our goal.
QCoreApplication::setApplicationName(EXECUTABLE_NAME);
QApplication::setOrganizationDomain(EXECUTABLE_NAME);
QCoreApplication::setApplicationVersion(APPLICATION_SEMVER);
}

View file

@ -35,6 +35,7 @@ public:
return mApp;
}
void stopApp();
static void initQtAppDetails();
private:
App *mApp = nullptr;
};

View file

@ -62,7 +62,7 @@ int main (int argc, char *argv[]) {
#endif
#ifdef ENABLE_QT_KEYCHAIN
bool vfsEncrypted = VfsUtils::updateSDKWithKey();
bool vfsEncrypted = VfsUtils::updateSDKWithKey(argc, argv);
#else
bool vfsEncrypted = false;
#endif

View file

@ -73,7 +73,9 @@ SettingsModel::SettingsModel (QObject *parent) : QObject(parent) {
connect(&mVfsUtils, &VfsUtils::keyRead, this, [&](const QString& key, const QString& value){
if(key == mVfsUtils.getApplicationVfsEncryptionKey()){
if(!getVfsEncrypted()){
mConfig->setBool(UiSection, "vfs_encryption_enabled", true);
QSettings settings;
settings.beginGroup("keychain");
settings.setValue("enabled", true);
emit vfsEncryptedChanged();
}
}
@ -81,14 +83,18 @@ SettingsModel::SettingsModel (QObject *parent) : QObject(parent) {
connect(&mVfsUtils, &VfsUtils::keyWritten, this, [&](const QString& key){
if(key == mVfsUtils.getApplicationVfsEncryptionKey()){
if(!getVfsEncrypted()){
mConfig->setBool(UiSection, "vfs_encryption_enabled", true);
QSettings settings;
settings.beginGroup("keychain");
settings.setValue("enabled", true);
emit vfsEncryptedChanged();
}
}
});
connect(&mVfsUtils, &VfsUtils::keyDeleted, this, [&](const QString& key){
if(key == mVfsUtils.getApplicationVfsEncryptionKey()){
mConfig->setBool(UiSection, "vfs_encryption_enabled", false);
QSettings settings;
settings.beginGroup("keychain");
settings.setValue("enabled", false);
emit vfsEncryptedChanged();
if(mVfsUtils.needToDeleteUserData())
Utils::deleteAllUserData();
@ -1865,7 +1871,9 @@ bool SettingsModel::getFullLogsEnabled (const shared_ptr<linphone::Config> &conf
// ---------------------------------------------------------------------------
bool SettingsModel::getVfsEncrypted (){
return mConfig->getBool(UiSection, "vfs_encryption_enabled", false);
QSettings settings;
settings.beginGroup("keychain");
return settings.value("enabled", false).toBool();
}
void SettingsModel::setVfsEncrypted (bool encrypted, const bool deleteUserData){

View file

@ -24,6 +24,7 @@
#include <linphone/api/c-factory.h>
#include <linphone++/factory.hh>
#include "app/AppController.hpp"
#include <app/paths/Paths.hpp>
#include <components/settings/SettingsModel.hpp>
#include <utils/Utils.hpp>
@ -125,32 +126,54 @@ bool VfsUtils::newEncryptionKey(){
vfs.newEncryptionKeyAsync();
return vfsSetter.exec() != -1;
}
bool VfsUtils::updateSDKWithKey() {
int argc = 1;
const char * argv = "dummy";
QCoreApplication vfsSetter(argc,(char**)&argv);
VfsUtils vfs;
QObject::connect(&vfs, &VfsUtils::keyRead, &vfsSetter, [&vfsSetter, &vfs] (const QString& key, const QString& value){
VfsUtils::updateSDKWithKey(value);
vfs.mVfsEncrypted = true;
vfsSetter.quit();
}, Qt::QueuedConnection);
QObject::connect(&vfs, &VfsUtils::error, &vfsSetter, [&vfsSetter](const QString& errorText){
vfsSetter.quit();
}, Qt::QueuedConnection);
vfs.readKey(vfs.getApplicationVfsEncryptionKey());
vfsSetter.exec();
bool VfsUtils::updateSDKWithKey(int argc, char *argv[]){
QCoreApplication core(argc,argv);
AppController::initQtAppDetails(); // Set settings context.
QSettings settings;
return updateSDKWithKey(&settings);
}
bool VfsUtils::updateSDKWithKey(){
QSettings settings;
return updateSDKWithKey(&settings);
}
if(!vfs.mVfsEncrypted){// Doesn't have key. Check in factory if it is mandatory.
auto config = linphone::Factory::get()->createConfigWithFactory("", Paths::getFactoryConfigFilePath());
if(config->getBool(SettingsModel::UiSection, "vfs_encryption_enabled", false)){
return VfsUtils::newEncryptionKey();// Return false on error.
}
bool VfsUtils::updateSDKWithKey(QSettings * settings){ // Update SDK if key exists. Return true if encrypted.
bool isEnabled = false;
//Check in factory if it is mandatory.
auto config = linphone::Factory::get()->createConfigWithFactory("", Paths::getFactoryConfigFilePath());
if(config->getBool(SettingsModel::UiSection, "vfs_encryption_enabled", false)){
isEnabled = true;
}
return vfs.mVfsEncrypted;
settings->beginGroup("keychain");
bool settingsValue = settings->value("enabled", false).toBool();
if( isEnabled && !settingsValue)
settings->setValue("enabled", isEnabled);
else if(!isEnabled)
isEnabled = settingsValue;
if( isEnabled){
int argc = 1;
const char * argv = "dummy";
QCoreApplication vfsSetter(argc,(char**)&argv);
VfsUtils vfs;
QObject::connect(&vfs, &VfsUtils::keyRead, &vfsSetter, [&vfsSetter, &vfs] (const QString& key, const QString& value){
VfsUtils::updateSDKWithKey(value);
vfs.mVfsEncrypted = true;
vfsSetter.quit();
}, Qt::QueuedConnection);
QObject::connect(&vfs, &VfsUtils::error, &vfsSetter, [&vfsSetter](const QString& errorText){
vfsSetter.quit();
}, Qt::QueuedConnection);
vfs.readKey(vfs.getApplicationVfsEncryptionKey());
vfsSetter.exec();
if(!vfs.mVfsEncrypted){// Doesn't have key.
return VfsUtils::newEncryptionKey();// Return false on error.
}
return vfs.mVfsEncrypted;
}else
return false;
}
void VfsUtils::updateSDKWithKey(const QString& key){

View file

@ -23,7 +23,7 @@
#include <QObject>
#include <EQt5Keychain/keychain.h>
#include <QSettings>
// =============================================================================
class VfsUtils : public QObject {
@ -40,7 +40,9 @@ public:
void newEncryptionKeyAsync(); // Generate a key, store it and update SDK. Wait for keyWritten() or error().
static bool newEncryptionKey(); // Generate a key, store it and update SDK.
static bool updateSDKWithKey(); // Update SDK if key exists. Return true if encrypted.
static bool updateSDKWithKey(int argc, char *argv[]); // Can be calle outside application.
static bool updateSDKWithKey(QSettings * settings); // Update SDK if key exists. Return true if encrypted.
static bool updateSDKWithKey();// Need it to pass QSettings
static void updateSDKWithKey(const QString& key);// SDK->setVfsEncryption(key)
QString getApplicationVfsEncryptionKey() const;// Get the key in store keys for VFS encryyption