mirror of
https://gitlab.linphone.org/BC/public/linphone-desktop.git
synced 2026-01-29 01:39:19 +00:00
VFS sync API to write a key.
Set a key if it is mandatory at startup.
This commit is contained in:
parent
a622900e8b
commit
8f596c7e6b
3 changed files with 33 additions and 4 deletions
|
|
@ -1745,7 +1745,7 @@ void SettingsModel::setVfsEncrypted (bool encrypted, const bool deleteUserData){
|
|||
#ifdef ENABLE_QT_KEYCHAIN
|
||||
if(getVfsEncrypted() != encrypted){
|
||||
if(encrypted) {
|
||||
mVfsUtils.newEncryptionKey();
|
||||
mVfsUtils.newEncryptionKeyAsync();
|
||||
}else{// Remove key, stop core, delete data and initiate reboot
|
||||
mVfsUtils.needToDeleteUserData(deleteUserData);
|
||||
mVfsUtils.deleteKey(mVfsUtils.getApplicationVfsEncryptionKey());
|
||||
|
|
|
|||
|
|
@ -24,6 +24,8 @@
|
|||
#include <linphone/api/c-factory.h>
|
||||
#include <linphone++/factory.hh>
|
||||
|
||||
#include <app/paths/Paths.hpp>
|
||||
#include <components/settings/SettingsModel.hpp>
|
||||
#include <utils/Utils.hpp>
|
||||
#include <utils/Constants.hpp>
|
||||
|
||||
|
|
@ -96,7 +98,7 @@ void VfsUtils::needToDeleteUserData(const bool& need){
|
|||
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
|
||||
void VfsUtils::newEncryptionKey(){
|
||||
void VfsUtils::newEncryptionKeyAsync(){
|
||||
QString value;
|
||||
bctoolbox::RNG rng;
|
||||
auto key = rng.randomize(32);
|
||||
|
|
@ -108,6 +110,22 @@ void VfsUtils::newEncryptionKey(){
|
|||
writeKey(getApplicationVfsEncryptionKey(), value);
|
||||
}
|
||||
|
||||
bool VfsUtils::newEncryptionKey(){
|
||||
int argc = 1;
|
||||
const char * argv = "dummy";
|
||||
QCoreApplication vfsSetter(argc,(char**)&argv);
|
||||
VfsUtils vfs;
|
||||
QObject::connect(&vfs, &VfsUtils::keyWritten, &vfsSetter, [&vfsSetter, &vfs] (const QString& key){
|
||||
vfsSetter.quit();
|
||||
}, Qt::QueuedConnection);
|
||||
QObject::connect(&vfs, &VfsUtils::error, &vfsSetter, [&vfsSetter](const QString& errorText){
|
||||
qCritical() << "[VFS] " << errorText;
|
||||
vfsSetter.exit(-1);
|
||||
}, Qt::QueuedConnection);
|
||||
vfs.newEncryptionKeyAsync();
|
||||
return vfsSetter.exec() != -1;
|
||||
}
|
||||
|
||||
bool VfsUtils::updateSDKWithKey() {
|
||||
int argc = 1;
|
||||
const char * argv = "dummy";
|
||||
|
|
@ -118,11 +136,20 @@ bool VfsUtils::updateSDKWithKey() {
|
|||
vfs.mVfsEncrypted = true;
|
||||
vfsSetter.quit();
|
||||
}, Qt::QueuedConnection);
|
||||
QObject::connect(&vfs, &VfsUtils::error, &vfsSetter, [&vfsSetter](){
|
||||
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. 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.
|
||||
}
|
||||
}
|
||||
|
||||
return vfs.mVfsEncrypted;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -37,7 +37,9 @@ public:
|
|||
Q_INVOKABLE void writeKey(const QString& key, const QString& value); // Write a key and send error() or keyWritten()
|
||||
|
||||
|
||||
void newEncryptionKey(); // Generate a key, store it and update SDK.
|
||||
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 void updateSDKWithKey(const QString& key);// SDK->setVfsEncryption(key)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue