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

Ignore empty history files on start

This fixes an esoteric issue of enabling chat log encryption and then restarting before adding any messages
This commit is contained in:
Dubslow 2015-01-19 21:49:41 -06:00
parent b1180a2038
commit f645faff51
No known key found for this signature in database
GPG Key ID: 3DB8E05315C220AA
2 changed files with 13 additions and 10 deletions

View File

@ -106,7 +106,7 @@ QByteArray Core::getSaltFromFile(QString filename)
QFile file(filename);
if (!file.open(QIODevice::ReadOnly))
{
qWarning() << "Core: encrypted history file doesn't exist";
qWarning() << "Core: file" << filename << "doesn't exist";
return QByteArray();
}
QByteArray data = file.read(tox_pass_encryption_extra_length());
@ -172,9 +172,11 @@ bool Core::loadEncryptedSave(QByteArray& data)
void Core::checkEncryptedHistory()
{
QByteArray salt = getSaltFromFile(HistoryKeeper::getHistoryPath());
QString path = HistoryKeeper::getHistoryPath();
bool exists = QFile::exists(path);
if (salt.size() == 0)
QByteArray salt = getSaltFromFile(path);
if (exists && salt.size() == 0)
{ // maybe we should handle this better
Widget::getInstance()->showWarningMsgBox(tr("Encrypted History"), tr("No encrypted history file found, or it was corrupted.\nHistory will be disabled!"));
Settings::getInstance().setEncryptLogs(false);
@ -188,7 +190,7 @@ void Core::checkEncryptedHistory()
if (pwsaltedkeys[ptHistory])
{
if (HistoryKeeper::checkPassword())
if (!exists || HistoryKeeper::checkPassword())
return;
dialogtxt = tr("The stored chat log password failed. Please try another:", "used only when pw set before load() doesn't work");
}
@ -198,8 +200,11 @@ void Core::checkEncryptedHistory()
if (pwsaltedkeys[ptMain])
{
useOtherPassword(ptHistory);
if (HistoryKeeper::checkPassword())
if (!exists || HistoryKeeper::checkPassword())
{
qDebug() << "Core: using main password for history";
return;
}
clearPassword(ptHistory);
}
@ -218,7 +223,7 @@ void Core::checkEncryptedHistory()
else
setPassword(pw, ptHistory, reinterpret_cast<uint8_t*>(salt.data()));
error = !HistoryKeeper::checkPassword();
error = exists && !HistoryKeeper::checkPassword();
dialogtxt = a + " " + b;
} while (error);
}

View File

@ -73,8 +73,6 @@ QSqlQuery EncryptedDb::exec(const QString &query)
bool EncryptedDb::pullFileContent(const QString &fname, QByteArray &buf)
{
qDebug() << "EncryptedDb::pullFileContent()";
QFile dbFile(fname);
if (!dbFile.open(QIODevice::ReadOnly))
{
@ -87,13 +85,13 @@ bool EncryptedDb::pullFileContent(const QString &fname, QByteArray &buf)
while (!dbFile.atEnd())
{
QByteArray encrChunk = dbFile.read(encryptedChunkSize);
qDebug() << "got chunk:" << encrChunk.size();
qDebug() << "EncryptedDb::pullFileContent: got chunk:" << encrChunk.size();
buf = Core::getInstance()->decryptData(encrChunk, Core::ptHistory);
if (buf.size() > 0)
{
fileContent += buf;
} else {
qWarning() << "Encrypted history log is corrupted: can't decrypt, will be deleted";
qWarning() << "EncryptedDb::pullFileContent: Encrypted history log is corrupted: can't decrypt, will be deleted";
buf = QByteArray();
return false;
}