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

Hacky fix to cancelling a switch to an encrypted profile closing

It's either this or some fairly major refactoring, which is preferable,
but I've got another even bigger refactoring in mind, and fixing this
will be rolled into that.
Closes dubslow/qTox#4
This commit is contained in:
Dubslow 2015-01-27 14:16:28 -06:00
parent ed22dc9ca5
commit 60e819baee
No known key found for this signature in database
GPG Key ID: 3DB8E05315C220AA
3 changed files with 71 additions and 13 deletions

View File

@ -223,9 +223,19 @@ void Core::start()
{
if (loadPath.isEmpty())
{
qCritical() << "Core: loadConfiguration failed, exiting now";
emit failedToStart();
return;
QString profile;
if ((profile = loadOldInformation()).isEmpty())
{
qCritical() << "Core: loadConfiguration failed, exiting now";
emit failedToStart();
return;
}
else
{
loadPath = QDir(Settings::getSettingsDirPath()).filePath(profile + TOX_EXT);
Settings::getInstance().switchProfile(profile);
HistoryKeeper::resetInstance(); // I'm not actually sure if this is necessary
}
}
}
// loadPath is meaningless after this
@ -1255,6 +1265,7 @@ void Core::switchConfiguration(const QString& profile)
qDebug() << "Core: switching from" << Settings::getInstance().getCurrentProfile() << "to" << profile;
saveConfiguration();
saveCurrentInformation(); // part of a hack, see core.h
ready = false;
Widget::getInstance()->setEnabledThreadsafe(false);

View File

@ -299,7 +299,17 @@ private:
QMutex fileSendMutex, messageSendMutex;
bool ready;
uint8_t* pwsaltedkeys[PasswordType::ptCounter]; // use the pw's hash as the "pw"
uint8_t* pwsaltedkeys[PasswordType::ptCounter] = {nullptr}; // use the pw's hash as the "pw"
// Hack for reloading current profile if switching to an encrypted one fails.
// Testing the passwords before killing the current profile is perfectly doable,
// however it would require major refactoring;
// the Core class as a whole also requires major refactoring (especially to support multiple IDs at once),
// so I'm punting on this until then, when it would get fixed anyways
uint8_t* backupkeys[PasswordType::ptCounter] = {nullptr};
QString* backupProfile = nullptr;
void saveCurrentInformation();
QString loadOldInformation();
static const int videobufsize;
static uint8_t* videobuf;

View File

@ -65,6 +65,43 @@ void Core::clearPassword(PasswordType passtype)
pwsaltedkeys[passtype] = nullptr;
}
// part of a hack, see core.h
void Core::saveCurrentInformation()
{
if (pwsaltedkeys[ptMain])
{
backupkeys[ptMain] = new uint8_t[tox_pass_key_length()];
std::copy(pwsaltedkeys[ptMain], pwsaltedkeys[ptMain]+tox_pass_key_length(), backupkeys[ptMain]);
}
if (pwsaltedkeys[ptHistory])
{
backupkeys[ptHistory] = new uint8_t[tox_pass_key_length()];
std::copy(pwsaltedkeys[ptHistory], pwsaltedkeys[ptHistory]+tox_pass_key_length(), backupkeys[ptHistory]);
}
backupProfile = new QString(Settings::getInstance().getCurrentProfile());
}
QString Core::loadOldInformation()
{
QString out;
if (backupProfile)
{
out = *backupProfile;
delete backupProfile;
backupProfile = nullptr;
}
backupProfile = nullptr;
clearPassword(ptMain);
clearPassword(ptHistory);
// we can just copy the pointer, as long as we null out backupkeys
// (if backupkeys was null anyways, then this is a null-op)
pwsaltedkeys[ptMain] = backupkeys[ptMain];
pwsaltedkeys[ptHistory] = backupkeys[ptHistory];
backupkeys[ptMain] = nullptr;
backupkeys[ptHistory] = nullptr;
return out;
}
QByteArray Core::encryptData(const QByteArray& data, PasswordType passtype)
{
if (!pwsaltedkeys[passtype])