void LLPanelLogin::onLoginComboLostFocus(LLComboBox* combo_box) { if(combo_box->isTextDirty()) { clearPassword(); combo_box->resetTextDirty(); } }
bool Core::loadEncryptedSave(QByteArray& data) { if (!Settings::getInstance().getEncryptTox()) GUI::showWarning(tr("Encryption error"), tr("The .tox file is encrypted, but encryption was not checked, continuing regardless.")); size_t fileSize = data.size(); int error = -1; QString a(tr("Please enter the password for the %1 profile.", "used in load() when no pw is already set").arg(Settings::getInstance().getCurrentProfile())); QString b(tr("The previous password is incorrect; please try again:", "used on retries in load()")); QString dialogtxt; if (pwsaltedkeys[ptMain]) // password set, try it { QByteArray newData(fileSize-TOX_PASS_ENCRYPTION_EXTRA_LENGTH, 0); if (tox_pass_key_decrypt((uint8_t*)data.data(), fileSize, pwsaltedkeys[ptMain], (uint8_t*)newData.data(), nullptr)) { data = newData; Settings::getInstance().setEncryptTox(true); return true; } dialogtxt = tr("The profile password failed. Please try another?", "used only when pw set before load() doesn't work"); } else { dialogtxt = a; } uint8_t salt[TOX_PASS_SALT_LENGTH]; tox_get_salt(reinterpret_cast<uint8_t *>(data.data()), salt); do { QString pw = GUI::passwordDialog(tr("Change profile"), dialogtxt); if (pw.isEmpty()) { clearPassword(ptMain); return false; } else { setPassword(pw, ptMain, salt); } QByteArray newData(fileSize-TOX_PASS_ENCRYPTION_EXTRA_LENGTH, 0); error = !tox_pass_key_decrypt((uint8_t*)data.data(), data.size(), pwsaltedkeys[ptMain], (uint8_t*)newData.data(), nullptr); if (!error) data = newData; dialogtxt = a + "\n" + b; } while (error != 0); Settings::getInstance().setEncryptTox(true); return true; }
void Core::useOtherPassword(PasswordType type) { clearPassword(type); pwsaltedkeys[type] = new TOX_PASS_KEY; PasswordType other = (type == ptMain) ? ptHistory : ptMain; std::copy(pwsaltedkeys[other], pwsaltedkeys[other]+1, pwsaltedkeys[type]); }
void Core::switchConfiguration(const QString& _profile) { QString profile = QFileInfo(_profile).baseName(); // If we can't get a lock, then another instance is already using that profile while (!profile.isEmpty() && !ProfileLocker::lock(profile)) { qWarning() << "Profile "<<profile<<" is already in use, pick another"; GUI::showWarning(tr("Profile already in use"), tr("Your profile is already used by another qTox instance\n" "Please select another profile")); do { profile = Settings::getInstance().askProfiles(); } while (profile.isEmpty()); } if (profile.isEmpty()) qDebug() << "Core: creating new Id"; else qDebug() << "Core: switching from" << Settings::getInstance().getCurrentProfile() << "to" << profile; saveConfiguration(); saveCurrentInformation(); // part of a hack, see core.h ready = false; GUI::setEnabled(false); clearPassword(ptMain); clearPassword(ptHistory); toxTimer->stop(); deadifyTox(); emit selfAvatarChanged(QPixmap(":/img/contact_dark.svg")); emit blockingClearContacts(); // we need this to block, but signals are required for thread safety if (profile.isEmpty()) loadPath = ""; else loadPath = QDir(Settings::getSettingsDirPath()).filePath(profile + TOX_EXT); Settings::getInstance().switchProfile(profile); HistoryKeeper::resetInstance(); start(); }
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; }
// static void LLPanelLogin::onLoginComboLostFocus(LLFocusableElement* fe, void*) { if (sInstance) { LLComboBox* combo = sInstance->getChild<LLComboBox>("name_combo"); if(fe == combo && combo->isTextDirty()) { clearPassword(); combo->resetTextDirty(); } } }
// static void LLPanelLogin::onLoginComboLostFocus(LLFocusableElement* fe, void*) { if (sInstance) { LLComboBox* combo = sInstance->getChild<LLComboBox>("first_name_combo"); if(fe == combo) { if (combo->isTextDirty()) { clearPassword(); } onSelectLoginEntry(combo, NULL); } } }
// static void LLPanelLogin::onLastNameEditLostFocus(LLUICtrl* ctrl, void* data) { if (sInstance) { LLLineEditor* edit = sInstance->getChild<LLLineEditor>("last_name_edit"); if(ctrl == edit) { if (edit->isDirty()) { clearPassword(); LLViewerLogin::getInstance()->setNameEditted(true); } } } }
void Core::setPassword(QString& password, PasswordType passtype, uint8_t* salt) { clearPassword(passtype); if (password.isEmpty()) return; pwsaltedkeys[passtype] = new TOX_PASS_KEY; CString str(password); if (salt) tox_derive_key_with_salt(str.data(), str.size(), salt, pwsaltedkeys[passtype], nullptr); else tox_derive_key_from_pass(str.data(), str.size(), pwsaltedkeys[passtype], nullptr); password.clear(); }
void Core::checkEncryptedHistory() { QString path = HistoryKeeper::getHistoryPath(); bool exists = QFile::exists(path); QByteArray salt = getSaltFromFile(path); if (exists && salt.size() == 0) { // maybe we should handle this better GUI::showWarning(tr("Encrypted chat history"), tr("No encrypted chat history file found, or it was corrupted.\nHistory will be disabled!")); Settings::getInstance().setEncryptLogs(false); Settings::getInstance().setEnableLogging(false); HistoryKeeper::resetInstance(); return; } QString a(tr("Please enter the password for the chat history for the %1 profile.", "used in load() when no hist pw set").arg(Settings::getInstance().getCurrentProfile())); QString b(tr("The previous password is incorrect; please try again:", "used on retries in load()")); QString c(tr("\nDisabling chat history now will leave the encrypted history intact (but not usable); if you later remember the password, you may re-enable encryption from the Privacy tab with the correct password to use the history.", "part of history password dialog")); QString dialogtxt; if (pwsaltedkeys[ptHistory]) { if (!exists || HistoryKeeper::checkPassword()) return; dialogtxt = tr("The chat history password failed. Please try another?", "used only when pw set before load() doesn't work"); } else { dialogtxt = a; } dialogtxt += "\n" + c; if (pwsaltedkeys[ptMain]) { useOtherPassword(ptHistory); if (!exists || HistoryKeeper::checkPassword()) { qDebug() << "using main password for chat history"; return; } clearPassword(ptHistory); } bool error = true; do { QString pw = GUI::passwordDialog(tr("Disable chat history"), dialogtxt); if (pw.isEmpty()) { clearPassword(ptHistory); Settings::getInstance().setEncryptLogs(false); Settings::getInstance().setEnableLogging(false); HistoryKeeper::resetInstance(); return; } else { setPassword(pw, ptHistory, reinterpret_cast<uint8_t*>(salt.data())); } error = exists && !HistoryKeeper::checkPassword(); dialogtxt = a + "\n" + c + "\n" + b; } while (error); }
// static void LLPanelLogin::onSelectServer(LLUICtrl*, void*) { // *NOTE: The parameters for this method are ignored. // This function is only called by one thread, so we can use a static here. static bool looping; if (looping) return; looping = true; // LLPanelLogin::onServerComboLostFocus(LLFocusableElement* fe, void*) // calls this method. // The user twiddled with the grid choice ui. // apply the selection to the grid setting. std::string grid_name; S32 grid_index; LLComboBox* combo = sInstance->getChild<LLComboBox>("server_combo"); LLSD combo_val = combo->getValue(); if (LLSD::TypeInteger == combo_val.type()) { grid_index = combo->getValue().asInteger(); grid_name = combo->getSimple(); } else { // no valid selection, return other grid_index = (S32)GRID_INFO_OTHER; grid_name = combo_val.asString(); } // This new selection will override preset uris // from the command line. LLViewerLogin* vl = LLViewerLogin::getInstance(); if(grid_index != GRID_INFO_OTHER) { vl->setGridChoice((EGridInfo)grid_index); } else { vl->setGridChoice(grid_name); } // Find a saved login entry that uses this grid, if any. bool found = false; LLSavedLoginsList const& entries = sInstance->mLoginHistoryData.getEntries(); for (LLSavedLoginsList::const_reverse_iterator i = entries.rbegin(); i != entries.rend(); ++i) { if (!i->asLLSD().isMap()) { continue; } if (i->getGridName() == grid_name) { if (!vl->nameEditted()) { // Change the other fields to match this grid. LLPanelLogin::setFields(*i, false); } else // Probably creating a new account. { // Likely the current password is for a different grid. clearPassword(); } found = true; break; } } if (!found) { clearPassword(); // If the grid_name starts with 'http[s]://' then // we have to assume it's a new loginuri, set // on the commandline. if (grid_name.substr(0, 4) == "http") { // Use it as login uri. vl->setGridURI(grid_name); // And set the login page if it was given. std::string loginPage = gSavedSettings.getString("LoginPage"); std::string helperURI = gSavedSettings.getString("CmdLineHelperURI"); if (!loginPage.empty()) vl->setLoginPageURI(loginPage); if (!helperURI.empty()) vl->setHelperURI(helperURI); } } // grid changed so show new splash screen (possibly) loadLoginPage(); looping = false; }