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

When enabling history encryption, check for and use previously-ignored encrypted history

Should close dubslow/qTox#5 and close dubslow/qTox#6
Note that the GUI isn't updated with the ignored history, that's a TODO
This commit is contained in:
Dubslow 2015-02-02 17:19:43 -06:00
parent 31ac5dbe46
commit ca5e9c324d
No known key found for this signature in database
GPG Key ID: 3DB8E05315C220AA

View File

@ -74,34 +74,45 @@ bool PrivacyForm::setChatLogsPassword()
else else
dialog = new SetPasswordDialog(body, QString(), this); dialog = new SetPasswordDialog(body, QString(), this);
if (int r = dialog->exec()) // check if an encrypted history exists because it was disabled earlier, and use it if possible
{ QString path = HistoryKeeper::getHistoryPath(QString(), 1);
QByteArray salt = core->getSaltFromFile(path);
bool haveEncHist = salt.size() > 0;
do {
int r = dialog->exec();
if (r == QDialog::Rejected)
break;
QList<HistoryKeeper::HistMessage> oldMessages = HistoryKeeper::exportMessagesDeleteFile(); QList<HistoryKeeper::HistMessage> oldMessages = HistoryKeeper::exportMessagesDeleteFile();
QString newpw = dialog->getPassword(); QString newpw = dialog->getPassword();
delete dialog;
if (r == 2) if (r == 2)
core->useOtherPassword(Core::ptHistory); core->useOtherPassword(Core::ptHistory);
else if (haveEncHist)
core->setPassword(newpw, Core::ptHistory, reinterpret_cast<uint8_t*>(salt.data()));
else else
core->setPassword(newpw, Core::ptHistory); core->setPassword(newpw, Core::ptHistory);
//if (!HistoryKeeper::checkPassword(true)) if (!haveEncHist || HistoryKeeper::checkPassword(1))
// if (checkContinue(tr("Old encrypted chat logs", "title"), {
// tr("Would you like to re-encrypt your old chat logs?\nOtherwise they will be deleted.", "body")))
// for now, don't bother asking. Why wouldn't you want to reencrypt?
Settings::getInstance().setEncryptLogs(true); Settings::getInstance().setEncryptLogs(true);
HistoryKeeper::getInstance()->importMessages(oldMessages); HistoryKeeper::getInstance()->importMessages(oldMessages);
// TODO: The old encrypted history is loaded, but doesn't appear in the GUI. @apprb ?
delete dialog;
return true; return true;
} }
else else
{ {
if (!Widget::getInstance()->askQuestion(tr("Old encrypted chat log", "popup title"), tr("There is currently an unused encrypted chat log, but the password you just entered doesn't match.\nWould you like to try again?")))
haveEncHist = false; // logically this is really just a `break`, but conceptually this is more accurate
}
} while (haveEncHist);
delete dialog; delete dialog;
return false; return false;
} }
}
void PrivacyForm::onEncryptLogsUpdated() void PrivacyForm::onEncryptLogsUpdated()
{ {