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

@ -178,7 +178,7 @@ void Core::make_tox()
{
qCritical() << "Core: bad proxy! no toxcore!";
emit badProxy();
}
}
else
{
qCritical() << "Tox core failed to start";
@ -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
@ -284,7 +294,7 @@ void Core::start()
}
else
qDebug() << "Core: Error loading self avatar";
ready = true;
process(); // starts its own timer
@ -1201,7 +1211,7 @@ bool Core::loadConfiguration(QString path)
QString name = getUsername();
if (!name.isEmpty())
emit usernameSet(name);
QString msg = getStatusMessage();
if (!msg.isEmpty())
emit statusMessageSet(msg);
@ -1229,7 +1239,7 @@ void Core::saveConfiguration()
qCritical() << "Error while creating directory " << dir;
return;
}
QString profile = Settings::getInstance().getCurrentProfile();
if (profile == "")
@ -1241,9 +1251,9 @@ void Core::saveConfiguration()
Settings::getInstance().switchProfile(profile);
}
QString path = directory.filePath(profile + TOX_EXT);
saveConfiguration(path);
}
@ -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

@ -46,7 +46,7 @@ public:
explicit Core(Camera* cam, QThread* coreThread, QString initialLoadPath);
static Core* getInstance(); ///< Returns the global widget's Core instance
~Core();
static const QString TOX_EXT;
static const QString CONFIG_FILE_NAME;
static QString sanitize(QString name);
@ -69,9 +69,9 @@ public:
void saveConfiguration();
void saveConfiguration(const QString& path);
QString getIDString() const; ///< Get the 12 first characters of our Tox ID
QString getUsername() const; ///< Returns our username, or an empty string on failure
QString getStatusMessage() const; ///< Returns our status message, or an empty string on failure
ToxID getSelfId() const; ///< Returns our Tox ID
@ -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])