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:
parent
ed22dc9ca5
commit
60e819baee
17
src/core.cpp
17
src/core.cpp
|
@ -223,9 +223,19 @@ void Core::start()
|
||||||
{
|
{
|
||||||
if (loadPath.isEmpty())
|
if (loadPath.isEmpty())
|
||||||
{
|
{
|
||||||
qCritical() << "Core: loadConfiguration failed, exiting now";
|
QString profile;
|
||||||
emit failedToStart();
|
if ((profile = loadOldInformation()).isEmpty())
|
||||||
return;
|
{
|
||||||
|
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
|
// loadPath is meaningless after this
|
||||||
|
@ -1255,6 +1265,7 @@ void Core::switchConfiguration(const QString& profile)
|
||||||
qDebug() << "Core: switching from" << Settings::getInstance().getCurrentProfile() << "to" << profile;
|
qDebug() << "Core: switching from" << Settings::getInstance().getCurrentProfile() << "to" << profile;
|
||||||
|
|
||||||
saveConfiguration();
|
saveConfiguration();
|
||||||
|
saveCurrentInformation(); // part of a hack, see core.h
|
||||||
|
|
||||||
ready = false;
|
ready = false;
|
||||||
Widget::getInstance()->setEnabledThreadsafe(false);
|
Widget::getInstance()->setEnabledThreadsafe(false);
|
||||||
|
|
12
src/core.h
12
src/core.h
|
@ -299,7 +299,17 @@ private:
|
||||||
QMutex fileSendMutex, messageSendMutex;
|
QMutex fileSendMutex, messageSendMutex;
|
||||||
bool ready;
|
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 const int videobufsize;
|
||||||
static uint8_t* videobuf;
|
static uint8_t* videobuf;
|
||||||
|
|
|
@ -65,6 +65,43 @@ void Core::clearPassword(PasswordType passtype)
|
||||||
pwsaltedkeys[passtype] = nullptr;
|
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)
|
QByteArray Core::encryptData(const QByteArray& data, PasswordType passtype)
|
||||||
{
|
{
|
||||||
if (!pwsaltedkeys[passtype])
|
if (!pwsaltedkeys[passtype])
|
||||||
|
|
Loading…
Reference in New Issue
Block a user