1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

add save encryption

This commit is contained in:
dubslow 2014-10-12 02:31:48 -05:00
parent 9df2b49d07
commit c33d387465
4 changed files with 35 additions and 4 deletions

View File

@ -1126,10 +1126,27 @@ void Core::saveConfiguration()
qDebug() << "Core: Saving";
uint32_t fileSize = tox_size(tox);
uint32_t fileSize;
if (Settings::getInstance().getEncryptTox())
fileSize = tox_encrypted_size(tox);
else
fileSize = tox_size(tox);
if (fileSize > 0 && fileSize <= INT32_MAX) {
uint8_t *data = new uint8_t[fileSize];
if (Settings::getInstance().getEncryptTox())
{
int ret = tox_encrypted_save(tox, data, pwhash, TOX_HASH_LENGTH);
if (ret == -1)
{
qCritical() << "Core::saveConfiguration: encryption of save file failed!!!";
return;
}
}
else
tox_save(tox, data);
configurationFile.write(reinterpret_cast<char *>(data), fileSize);
configurationFile.commit();
delete[] data;
@ -1435,13 +1452,12 @@ void Core::clearPassword()
delete[] pwhash;
pwhash = nullptr;
}
}
QByteArray Core::encryptData(const QByteArray& data)
{
if (!pwhash)
return;
return QByteArray();
uint8_t encrypted[data.size() + TOX_PASS_ENCRYPTION_EXTRA_LENGTH];
if (tox_pass_encrypt(data.data(), data.size(), pwhash, TOX_HASH_LENGTH, encrypted) == -1)
{

1
core.h
View File

@ -95,6 +95,7 @@ public slots:
void micMuteToggle(int callId);
void setPassword(QString& password);
void clearPassword();
bool encryptFile(const QString& path);
QByteArray encryptData(const QByteArray& data);

View File

@ -430,6 +430,16 @@ void Settings::setEncryptLogs(bool newValue)
encryptLogs = newValue;
}
bool Settings::getEncryptTox() const
{
return encryptTox;
}
void Settings::setEncryptTox(bool newValue)
{
encryptTox = newValue;
}
void Settings::setWidgetData(const QString& uniqueName, const QByteArray& data)
{
widgetSettings[uniqueName] = data;

View File

@ -73,6 +73,9 @@ public:
bool getEncryptLogs() const;
void setEncryptLogs(bool newValue);
bool getEncryptTox() const;
void setEncryptTox(bool newValue);
QPixmap getSavedAvatar(const QString& ownerId);
void saveAvatar(QPixmap& pic, const QString& ownerId);
@ -178,6 +181,7 @@ private:
bool enableLogging;
bool encryptLogs;
bool encryptTox;
QHash<QString, QByteArray> widgetSettings;