Esempio n. 1
0
string guiConstruct::getMetadata(char* text)
{
	string str_text(text);
	int position = str_text.find(":");
	if (position != -1)
	{
		str_text = str_text.substr(position + 1);
	}
	position = str_text.find(" ");
	while (position != -1)
	{
		str_text.erase(position, 1);
		position = str_text.find(" ", position);
	}
	return str_text;
}
Esempio n. 2
0
string guiConstruct::getNodeValue(char* text)
{
	string str_text(text);
	int position = str_text.find(":");
	if (position != -1)
	{
		str_text.erase(position);
	}
	position = str_text.find(" ");
	while (position != -1)
	{
		str_text.erase(position, 1);
		position = str_text.find(" ", position);
	}
	return str_text;
}
void MTPageNym_AltLocation::PrepareOutputData()
{
    // Step 1: wipe the old data.
    //
    MTWizardAddNym    * pWizardAdd  = dynamic_cast<MTWizardAddNym    *>(wizard());
    WizardEditProfile * pWizardEdit = dynamic_cast<WizardEditProfile *>(wizard());

    if (nullptr != pWizardAdd)       pWizardAdd ->listContactDataTuples_.clear();
    else if (nullptr != pWizardEdit) pWizardEdit->listContactDataTuples_.clear();

    // Step 2: reconstruct it from the widgets.
    QMap<uint32_t, QList<GroupBoxContactItems *> * >::iterator it_mapGroupBoxLists;

    for (it_mapGroupBoxLists  = mapGroupBoxLists_.begin();
         it_mapGroupBoxLists != mapGroupBoxLists_.end();
         it_mapGroupBoxLists++)
    {
        const uint32_t indexSection = it_mapGroupBoxLists.key();
        QList<GroupBoxContactItems *> * pList = it_mapGroupBoxLists.value();

        if (nullptr != pList)
        {
            QList<GroupBoxContactItems *>::iterator it_list;

            for (it_list  = pList->begin();
                 it_list != pList->end();
                 it_list++)
            {
                GroupBoxContactItems * pGroupBox = *it_list;

                if (nullptr != pGroupBox)
                {
                    uint32_t indexSectionType = pGroupBox->indexSectionType_;

                    for (int nItemIndex = 0; nItemIndex < pGroupBox->layout()->count(); ++nItemIndex)
                    {
                        QWidget * pItemWidget = pGroupBox->layout()->itemAt(nItemIndex)->widget();
                        QLineEdit * pLineEdit = VPtr<QLineEdit>::asPtr(pItemWidget->property("lineedit"));
                        QRadioButton * pBtnRadio = VPtr<QRadioButton>::asPtr(pItemWidget->property("radiobtn"));

                        const QString & qstrText = pLineEdit->text();

                        if (!qstrText.isEmpty())
                        {
                            std::string str_text(qstrText.toStdString());

                            if (nullptr != pWizardAdd)
                                pWizardAdd->listContactDataTuples_.push_back(
                                        tupleContactDataItem{indexSection,
                                                             indexSectionType,
                                                             str_text,
                                                             pBtnRadio->isChecked()} );

                            else if (nullptr != pWizardEdit)
                                pWizardEdit->listContactDataTuples_.push_back(
                                        tupleContactDataItem{indexSection,
                                                             indexSectionType,
                                                             str_text,
                                                             pBtnRadio->isChecked()} );
                        }
                    }
                }
            }
        }
    }
}
void DlgEncrypt::on_pushButtonEncrypt_clicked()
{
    QString qstrText = ui->plainTextEdit->toPlainText().trimmed();
    // --------------------------------
    if (qstrText.isEmpty())
    {
        // pop up a message box warning that the input text is empty.
        //
        QMessageBox::warning(this, tr("Input Text is Empty"),
                             tr("Please paste some text to be signed/encrypted."));
        return;
    }
    else
    {
        if (m_bSign)
        {
            if (m_nymId.isEmpty())
            {
                QMessageBox::warning(this, tr("Missing Signer"),
                                     tr("No signer is selected. Perhaps you need to create an identity first, to sign with."));
                return;
            }
            else
            {
                // Sign the contents.
                //
                std::string  str_nym    (m_nymId.toStdString());
                opentxs::String     strNym     (str_nym.c_str());
                opentxs::Identifier nym_id     (strNym);

                std::string  str_text   (qstrText.toStdString());
                opentxs::String     strText    (str_text.c_str());
//              opentxs::OTASCIIArmor ascText    (strText);
//              std::string  str_encoded(ascText.Get());
//              opentxs::String     strEncoded (str_encoded.c_str());
//              std::string  str_type   ("MESSAGE");

                if (!nym_id.IsEmpty())
                {
                    opentxs::OTPasswordData thePWData("Signer passphrase");

                    opentxs::Nym * pNym = opentxs::OTAPI_Wrap::OTAPI()->GetOrLoadPrivateNym(nym_id,
                                                                           false, //bChecking=false
                                                                           __FUNCTION__,
                                                                           &thePWData);
                    if (NULL == pNym)
                    {
                        QString qstrErrorMsg = QString("%1: %2").arg(tr("Failed loading the signer; unable to continue. NymID")).arg(m_nymId);
                        QMessageBox::warning(this, tr("Failed Loading Signer"), qstrErrorMsg);
                        return;
                    }
                    else
                    {
                        // FOR VERIFY STEP:
    //                  inline opentxs::String & opentxs::OTSignedFile::GetFilePayload()                       { return m_strSignedFilePayload;   }

                        opentxs::String     strSignedOutput;
                        opentxs::OTSignedFile theSignedFile;

                        theSignedFile.SetSignerNymID(strNym);

                        theSignedFile.SetFilePayload(strText);
                        theSignedFile.SignContract(*pNym, &thePWData);
                        theSignedFile.SaveContract();
                        theSignedFile.SaveContractRaw(strSignedOutput);

                        // Set the result onto qstrText
                        //
                        if (!strSignedOutput.Exists())
                        {
                            QMessageBox::warning(this, tr("Signing Failed"),
                                                 tr("Failed trying to sign, using the selected identity."));
                            return;
                        }
                        else if (!theSignedFile.VerifySignature(*pNym))
                        {
                            QMessageBox::warning(this, tr("Test Verification Failed"),
                                                 tr("Failed trying to test verify, immediately after signing. Trying authentication key..."));

                            if (!theSignedFile.VerifySigAuthent(*pNym))
                            {
                                QMessageBox::warning(this, tr("Authent Test Also Failed"),
                                                     tr("Failed trying to verify signature with authentication key as well."));
                                return;
                            }
                            else
                                QMessageBox::information(this, tr("SUCCESS USING AUTHENTICATION KEY"), tr("Tried authent key instead of signing key, and it worked!"));
                        }
                        else
                        {
                            std::string str_signed_output(strSignedOutput.Get());
                            qstrText = QString::fromStdString(str_signed_output);
                        }
                    } // else (we have pNym.)
                }
//              std::string  str_output (opentxs::OTAPI_Wrap::It()->FlatSign(str_nym, str_encoded, str_type));
            }
        }
        // --------------------------------
        // Encrypt qstrText and pop up a dialog with the encrypted result.
        //
        if (m_bEncrypt)
        {
            if (ui->listWidgetAdded->count() > 0)
            {
                std::set<const opentxs::Nym*> setRecipients;
                bool      bRecipientsShouldBeAvailable = false;

                // Loop through each NymID in listWidgetAdded, and put them on a opentxs::setOfNyms
                // so we can pass them along to opentxs::OTEnvelope (and so we can clean them up afterwards.)
                // UPDATE: Can't clean them up! Because the wallet only owns private nyms, not public
                // ones, we never know for sure which ones are safe to erase. TODO: Fix in OT by using
                // shared_ptr.
                //
                for (int nIndex = 0; nIndex < ui->listWidgetAdded->count(); ++nIndex)
                {
                    bRecipientsShouldBeAvailable = true;

                    QListWidgetItem   * pItem    = ui->listWidgetAdded->item(nIndex);
                    QVariant            qvarItem = pItem->data(Qt::UserRole);
                    QString             qstrNymID(qvarItem.toString());
                    std::string         str_nym(qstrNymID.toStdString());
                    opentxs::String     strNym(str_nym.c_str());
                    opentxs::Identifier nym_id(strNym);

                    if (!nym_id.IsEmpty())
                    {
                        opentxs::OTPasswordData thePWData("Sometimes need to load private part of nym in order to use its public key. (Fix that!)");

                        const opentxs::Nym * pNym = opentxs::OTAPI_Wrap::OTAPI()->GetOrLoadNym(nym_id,
                                                                               false, //bChecking=false
                                                                               __FUNCTION__,
                                                                               &thePWData);
                        if (NULL == pNym)
                        {
                            QString qstrErrorMsg = QString("%1: %2").arg(tr("Failed loading a recipient; attempting to continue without. NymID")).arg(qstrNymID);

                            QMessageBox::warning(this, tr("Failed Loading Recipient"), qstrErrorMsg);
                        }
                        else
                        {
                            setRecipients.insert(setRecipients.begin(), pNym);
                        }
                    }
                    // qstrNymID will be passed to opentxs::OTEnvelope on its recipient list.
                } // for (selected Nyms.)
                // ---------------------------------------------------
                // We might also want to encrypt to the Signer's Nym, if there is one.
                // We'll default this to ON, but give users the choice to deactivate it.
                //
                if (ui->checkBoxAlso->isVisible() &&
                    ui->checkBoxAlso->isEnabled() &&
                    ui->checkBoxAlso->isChecked() &&
                    !m_nymId.isEmpty())
                {
                    std::string str_signer_nym(m_nymId.toStdString());
                    opentxs::String strSignerNymID(str_signer_nym.c_str());
                    bool bSignerIsAlreadyThere = false;

                    //FOR_EACH(opentxs::setOfNyms(), setRecipients) // See if it's already there, in which case we don't need to do anything else.
                    for(auto it = setRecipients.begin(); it != setRecipients.end(); ++ it)
                    {
                        const opentxs::Nym       * pNym = *it;
                        opentxs::String            strNymID;
                        pNym->GetIdentifier(strNymID);

                        if (strSignerNymID.Compare(strNymID))
                            bSignerIsAlreadyThere = true;
                    }
                    // -------------------------
                    if (!bSignerIsAlreadyThere) // Not already there? Add signer to list of recipients.
                    {
                        bRecipientsShouldBeAvailable = true;

                        opentxs::Identifier signer_nym_id(strSignerNymID);

                        if (!signer_nym_id.IsEmpty())
                        {
                            opentxs::OTPasswordData thePWData("Sometimes need to load private part of nym in order to use its public key. (Fix that!)");

                            auto pNym =
                                opentxs::App::Me().Contract().Nym(signer_nym_id);
                            if (!pNym)
                            {
                                QString qstrErrorMsg = QString("%1: %2").
                                        arg(tr("Failed trying to load the signer; attempting to continue without. NymID")).arg(m_nymId);
                                QMessageBox::warning(this, tr("Failed Loading Signer"), qstrErrorMsg);
                            }
                            else
                            {
                                setRecipients.insert(setRecipients.begin(), pNym.get());
                            }
                        }
                    }
                }
                // ---------------------------------------------------
                if (setRecipients.size() > 0)
                {
                    opentxs::OTEnvelope theEnvelope;
                    opentxs::String   strInput(qstrText.toStdString().c_str());

                    if (!theEnvelope.Seal(setRecipients, strInput))
                    {
                        QMessageBox::warning(this, tr("Encryption Failed"),
                                             tr("Failed trying to encrypt message."));
                        return;
                    }
                    else
                    {
                        // Success encrypting!
                        //
                        opentxs::String     strOutput;
                        opentxs::OTASCIIArmor ascCiphertext(theEnvelope);

                        if (ascCiphertext.WriteArmoredString(strOutput, "ENVELOPE")) // -----BEGIN OT ARMORED ENVELOPE-----
                        {
                            std::string str_output(strOutput.Get());
                            qstrText = QString::fromStdString(str_output);
                        }
                    }
                }
                else if (bRecipientsShouldBeAvailable) // They should be, but they weren't.
                {
                    QMessageBox::warning(this, tr("Failed Loading Recipients"),
                                         tr("Due to failure loading any of the recipients, unable to commence."));
                    return;
                }
            } // if (listItems.size() > 0)
        } // if (m_bEncrypt)
        // -------------------
        // If it's NOT encrypted, but it IS signed, then we want to OT ARMOR it as well.
        // (We don't have to if it's encrypted, since that process already armors it for us.
        //  But this is for the case where it's signed and NOT encrypted.)
        //
        else if (m_bSign && !qstrText.isEmpty())
        {
            std::string  str_text(qstrText.toStdString());
            opentxs::String     strText (str_text.c_str());
            opentxs::String     strOutput;
            opentxs::OTASCIIArmor ascText (strText);

            if (ascText.WriteArmoredString(strOutput, "SIGNED FILE")) // -----BEGIN OT ARMORED SIGNED FILE-----
            {
                std::string str_output(strOutput.Get());
                qstrText = QString::fromStdString(str_output);
            }
        }
        // -----------------------------------------------
        // if qstrText still contains something, pop up a dialog to display the result to the user.
        //
        if (!qstrText.isEmpty())
        {
            QString qstrType("Output:");

            if (m_bSign)
            {
                qstrType = QString(tr("Signed Output:"));
            }
            // -----------
            if (m_bEncrypt)
            {
                if (m_bSign)
                    qstrType = QString(tr("Signed and Encrypted Output:"));
                else
                    qstrType = QString(tr("Encrypted Output:"));
            }
            // -----------
            QString qstrSubTitle(tr("Be sure to copy it somewhere before closing this dialog."));
            // -----------
            // Pop up the result dialog.
            //
            DlgExportedToPass dlgExported(this, qstrText,
                                          qstrType,
                                          qstrSubTitle, false);
            dlgExported.exec();
        }
    } // if (!qstrText.isEmpty())
}