Exemple #1
0
/**
 * Returns decrypted note text if it is encrypted
 * The crypto key has to be set in the object
 */
QString Note::getDecryptedNoteText() {
    QString noteText = this->noteText;
    QString encryptedNoteText = getEncryptedNoteText();

    if (encryptedNoteText == "") {
        return noteText;
    }

    // decrypt the note text
    BotanWrapper botanWrapper;
    botanWrapper.setPassword(cryptoPassword);
    botanWrapper.setSalt(BOTAN_SALT);
    QString decryptedNoteText = botanWrapper.Decrypt(encryptedNoteText);

    // fallback to SimpleCrypt
    if (decryptedNoteText == "") {
        SimpleCrypt *crypto = new SimpleCrypt(static_cast<quint64>(cryptoKey));
        decryptedNoteText = crypto->decryptToString(encryptedNoteText);
    }

    if (decryptedNoteText == "") {
        return noteText;
    }

    // get regular expression for the encrypted string
    QRegularExpression re = getEncryptedNoteTextRegularExpression();

    // replace the encrypted text with the decrypted text
    noteText.replace(re, decryptedNoteText);
    return noteText;
}
void ProfileEditGui::buttonOk()
{
    QString strPassword = ui.lineEdit_password->text();

    // empty
    if (strPassword.isEmpty())
    {
        QMessageBox::critical(0, QString::null, tr("Password is empty!"));
        return;
    }

    // encrypt pass
    SimpleCrypt *pSimpleCrypt = new SimpleCrypt();
    strPassword = pSimpleCrypt->encrypt(strNick, strPassword);
    delete pSimpleCrypt;

    Config *pConfig = new Config(ProfileConfig, strNick);
    pConfig->set("pass", strPassword);
    delete pConfig;

    // current nick
    QString strMe = Settings::instance()->get("nick");
    if (strNick == strMe)
        Settings::instance()->set("pass", strPassword);

    // close
    this->close();
}
inline void VSCClientConfDefault(VidClientConf &pData)
{
	SimpleCrypt crypt;
	pData.set_nlang(VID_LANG_AUTO);
	pData.set_bautologin(false);
	/* Default passwd is admin */
	QString strPass = "******";
	pData.set_stradminpasswd(crypt.encryptToString(strPass).toStdString());

	return;
}
Exemple #4
0
void Settings::SaveSettings()
{
    pSettings->setValue("windowState", pMain->saveState());

    if(!pMain->isMaximized())
        pSettings->setValue("windowSize", pMain->saveGeometry());

    pSettings->setValue("windowMaximized", pMain->isMaximized());

    pSettings->setValue("splitterState", pMain->GetUi()->splitter->saveState());

    pSettings->setValue("rulesSplitterState", pMain->GetUi()->rulesSplitter->saveState());

    pSettings->setValue("browserSplitterState", pMain->GetUi()->browserSplitter->saveState());

    pSettings->setValue("browserTableState", pMain->GetUi()->browserTable->horizontalHeader()->saveState());

    pSettings->setValue("rulesTableState", pMain->GetUi()->rulesTable->horizontalHeader()->saveState());

    pSettings->setValue("playerTableState", pMain->GetUi()->playerTable->horizontalHeader()->saveState());

    pSettings->setValue("darkTheme", pMain->GetUi()->menuSettings->actions().at(0)->isChecked());

    pSettings->setValue("showLoggingInfo", pMain->showLoggingInfo);

    pSettings->setValue("logPort", pMain->u16logPort);

    pSettings->beginGroup("servers");

    pSettings->remove("");

    if(serverList.size() > 0)
    {
        for(int i = 0; i < serverList.size(); i++)
        {
            ServerInfo *info = serverList.at(i);
            QStringList list;
            list.append(info->ipPort);

            if(info->saveRcon && info->rconPassword.length() >0)
            {
                SimpleCrypt encrypt;
                encrypt.setKey(info->ipPort.toLongLong());
                list.append(encrypt.encryptToString(info->rconPassword));

            }
            pSettings->setValue(QString::number(i+1), list);
        }
    }

    pSettings->endGroup();
}
Exemple #5
0
/**
 * Checks if note text can be decrypted
 */
bool Note::canDecryptNoteText() {
    QString encryptedNoteText = getEncryptedNoteText();

    if (encryptedNoteText == "") {
        return false;
    }

    // decrypt the note text
    SimpleCrypt* crypto = new SimpleCrypt(static_cast<quint64>(cryptoKey));
    QString decryptedNoteText = crypto->decryptToString(encryptedNoteText);

    return decryptedNoteText != "";
}
void ProfileEditGui::setDefaultValues()
{
    Config *pConfig = new Config(ProfileConfig, strNick);
    QString strPassword = pConfig->get("pass");
    delete pConfig;

    // decrypt pass
    if (!strPassword.isEmpty())
    {
        SimpleCrypt *pSimpleCrypt = new SimpleCrypt();
        strPassword = pSimpleCrypt->decrypt(strNick, strPassword);
        delete pSimpleCrypt;
    }

    ui.lineEdit_nick->setText(strNick);
    ui.lineEdit_password->setText(strPassword);
}
Exemple #7
0
/**
 * Checks if note text can be decrypted
 */
bool Note::canDecryptNoteText() {
    QString encryptedNoteText = getEncryptedNoteText();

    if (encryptedNoteText == "") {
        return false;
    }

    // decrypt the note text
    BotanWrapper botanWrapper;
    botanWrapper.setPassword(cryptoPassword);
    botanWrapper.setSalt(BOTAN_SALT);
    QString decryptedNoteText = botanWrapper.Decrypt(encryptedNoteText);

    // fallback to SimpleCrypt
    if (decryptedNoteText == "") {
        SimpleCrypt *crypto = new SimpleCrypt(static_cast<quint64>(cryptoKey));
        decryptedNoteText = crypto->decryptToString(encryptedNoteText);
    }

    return decryptedNoteText != "";
}
inline bool ClientFactory::AuthUser(astring &strUser, astring &strPasswd)
{
    /* Admin is a Super User */
    if (strUser == "admin")
    {
        VidClientConf  cData;
        m_Conf.GetClientConf(cData);
        SimpleCrypt crypt;
        astring strDummy = cData.stradminpasswd().c_str();
        QString strDePasswd = cData.stradminpasswd().c_str();
        if (crypt.decryptToString(strDePasswd).toStdString() == strPasswd)
        {
            return true;
        } else
        {
            return false;
        }
    }

    return false;
}
Exemple #9
0
/**
 * Encrypts the note text with the note's crypto key
 */
QString Note::encryptNoteText() {
    // split the text into a string list
    QStringList noteTextLines = this->noteText.split(
            QRegExp("(\\r\\n)|(\\n\\r)|\\r|\\n"));

    // keep the first two lines unencrypted
    noteText = noteTextLines.at(0) + "\n" + noteTextLines.at(1) + "\n\n" +
            QString(NOTE_TEXT_ENCRYPTION_PRE_STRING) + "\n";

    // remove the first two lines for encryption
    noteTextLines.removeFirst();
    noteTextLines.removeFirst();

    // remove the 3rd line too if it is empty
    if (noteTextLines.at(0) == "") {
        noteTextLines.removeFirst();
    }

    // join the remaining lines
    QString text = noteTextLines.join("\n");

    // empty notes will be detected as "can't be decrypted",
    // so we will add a space
    if (text.isEmpty()) {
        text = " ";
    }

    // encrypt the text
    SimpleCrypt* crypto = new SimpleCrypt(static_cast<quint64>(cryptoKey));
    QString encryptedText = crypto->encryptToString(text);

    // add the encrypted text to the new note text
    noteText += encryptedText + "\n" +
            QString(NOTE_TEXT_ENCRYPTION_POST_STRING);

    // store note
    store();

    return noteText;
}
Exemple #10
0
/**
 * Returns decrypted note text if it is encrypted
 * The crypto key has to be set in the object
 */
QString Note::getDecryptedNoteText() {
    QString noteText = this->noteText;
    QString encryptedNoteText = getEncryptedNoteText();

    if (encryptedNoteText == "") {
        return noteText;
    }

    // decrypt the note text
    SimpleCrypt* crypto = new SimpleCrypt(static_cast<quint64>(cryptoKey));
    QString decryptedNoteText = crypto->decryptToString(encryptedNoteText);

    if (decryptedNoteText == "") {
        return noteText;
    }

    // get regular expression for the encrypted string
    QRegularExpression re = getEncryptedNoteTextRegularExpression();

    // replace the encrypted text with the decrypted text
    noteText.replace(re, decryptedNoteText);
    return noteText;
}
Exemple #11
0
void Settings::ReadSettings()
{
    if(!pSettings->value("windowMaximized", pMain->isMaximized()).toBool())
    {
        pMain->restoreGeometry(pSettings->value("windowSize", pMain->saveGeometry()).toByteArray());
    }

    pMain->restoreState(pSettings->value("windowState", pMain->saveState()).toByteArray());

    pMain->GetUi()->splitter->restoreState(pSettings->value("splitterState", pMain->GetUi()->splitter->saveState()).toByteArray());

    pMain->GetUi()->rulesSplitter->restoreState(pSettings->value("rulesSplitterState", pMain->GetUi()->rulesSplitter->saveState()).toByteArray());

    pMain->GetUi()->browserSplitter->restoreState(pSettings->value("browserSplitterState", pMain->GetUi()->browserSplitter->saveState()).toByteArray());

    pMain->GetUi()->browserTable->horizontalHeader()->restoreState(pSettings->value("browserTableState", pMain->GetUi()->browserTable->horizontalHeader()->saveState()).toByteArray());

    pMain->GetUi()->playerTable->horizontalHeader()->restoreState(pSettings->value("playerTableState", pMain->GetUi()->playerTable->horizontalHeader()->saveState()).toByteArray());

    pMain->GetUi()->rulesTable->horizontalHeader()->restoreState(pSettings->value("rulesTableState", pMain->GetUi()->rulesTable->horizontalHeader()->saveState()).toByteArray());

    bool darkTheme = pSettings->value("darkTheme", false).toBool();

    pMain->showLoggingInfo = pSettings->value("showLoggingInfo", true).toBool();

    uint temp = pSettings->value("logPort", pMain->u16logPort).toUInt();

    if(temp <= PORT_MAX && temp >= PORT_MIN)
    {
        pMain->u16logPort = temp;
    }

    if(darkTheme)
    {
        pMain->GetUi()->menuSettings->actions().at(0)->setChecked(true);
        pMain->darkThemeTriggered();
    }

    pSettings->beginGroup("servers");
    QStringList keys = pSettings->childKeys();

    for(int i = 1; i <= keys.size(); i++)
    {   
        QStringList list = pSettings->value(QString::number(i), QStringList()).toStringList();

        if(list.size() == 0 || list.size() > 2)
        {
            continue;
        }

        if(pMain->CheckServerList(list.at(0)) == AddServerError_None)
        {
            ServerInfo *info = new ServerInfo(list.at(0));
            serverList.append(info);

            int row = pMain->GetUi()->browserTable->rowCount();
            pMain->GetUi()->browserTable->insertRow(row);

            QTableWidgetItem *item = new QTableWidgetItem();
            QTableWidgetItem *id = new QTableWidgetItem();
            id->setData(Qt::DisplayRole, serverList.size());

            item->setTextColor(queryingColor);
            item->setText(QString("Querying server %1...").arg(info->ipPort));
            item->setToolTip(info->ipPort);
            pMain->GetUi()->browserTable->setItem(row, 0, id);
            pMain->GetUi()->browserTable->setItem(row, 4, item);

            InfoQuery *infoQuery = new InfoQuery(pMain);
            infoQuery->query(&info->host, info->port, id);

            if(list.size() == 2)
            {
                SimpleCrypt encrypt;
                encrypt.setKey(list.at(0).toLongLong());
                QString pass = encrypt.decryptToString(list.at(1));
                if(encrypt.lastError() == SimpleCrypt::ErrorNoError)
                {
                    info->rconPassword = pass;
                    info->saveRcon = true;
                }
            }
        }
    }
    pSettings->endGroup();
    this->SaveSettings();//Call this again to make sure we cleaned up any garbage entries
}
void ProfileAddGui::buttonOk()
{
    QString strNick = ui.lineEdit_nick->text().trimmed();
    QString strPassword = ui.lineEdit_password->text();

    // empty
    if (strNick.isEmpty())
    {
        QMessageBox::critical(0, QString::null, tr("Nick is empty!"));
        return;
    }

    // check nick
    QString strPass;
    if (ui.radioButton_unregistered_nick->isChecked())
    {
        // fix nick
        if (strNick.at(0) != '~')
            strNick = "~"+strNick;

        strPass = QString::null;
    }
    else if (ui.radioButton_registered_nick->isChecked())
    {
        // fix nick
        if (strNick.at(0) == '~')
            strNick.remove(0,1);

        strPass = ui.lineEdit_password->text();
    }

    // fix nick
    if ((strPass.isEmpty()) && (strNick.at(0) != '~'))
        strNick = '~'+strNick;

    // fix too long nick
    if ((strPass.isEmpty()) && (strNick.size() > 32))
        strNick = strNick.left(32);

    // exist profile
    if (profileManager->existProfile(strNick))
    {
        QMessageBox::critical(0, QString::null, tr("Profile already exists!"));
        return;
    }

    // encrypt pass
    if (!strPass.isEmpty())
    {
        SimpleCrypt *pSimpleCrypt = new SimpleCrypt();
        strPassword = pSimpleCrypt->encrypt(strNick, strPassword);
        delete pSimpleCrypt;
    }

    // save
    Config *pConfig = new Config(ProfileConfig, strNick);
    pConfig->set("nick", strNick);
    pConfig->set("pass", strPassword);
    delete pConfig;

    // refresh
    profileManager->refreshAllLists();

    // close
    this->close();
}