//virtual void MTAssetDetails::refresh(QString strID, QString strName) { if (!strID.isEmpty() && (NULL != ui)) { QWidget * pHeaderWidget = MTEditDetails::CreateDetailHeaderWidget(m_Type, strID, strName, "", "", ":/icons/icons/assets.png", false); pHeaderWidget->setObjectName(QString("DetailHeader")); // So the stylesheet doesn't get applied to all its sub-widgets. if (m_pHeaderWidget) { ui->verticalLayout->removeWidget(m_pHeaderWidget); m_pHeaderWidget->setParent(NULL); m_pHeaderWidget->disconnect(); m_pHeaderWidget->deleteLater(); m_pHeaderWidget = NULL; } ui->verticalLayout->insertWidget(0, pHeaderWidget); m_pHeaderWidget = pHeaderWidget; // ---------------------------------- QString qstrContents = QString::fromStdString(opentxs::OTAPI_Wrap::It()->LoadAssetContract(strID.toStdString())); if (m_pPlainTextEdit) m_pPlainTextEdit->setPlainText(qstrContents); // -------------------------- QString qstrNymID(""); ui->pushButton->setVisible(false); if (!qstrContents.isEmpty()) { std::string str_signer_nym = opentxs::OTAPI_Wrap::It()->GetSignerNymID(qstrContents.toStdString()); if (!str_signer_nym.empty()) { qstrNymID = QString::fromStdString(str_signer_nym); // -------------------------- if (opentxs::OTAPI_Wrap::It()->VerifyUserPrivateKey(str_signer_nym)) { ui->pushButton->setVisible(true); } } } // -------------------------- ui->lineEditID ->setText(strID); ui->lineEditName ->setText(strName); ui->lineEditNymID->setText(qstrNymID); FavorLeftSideForIDs(); } }
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()) }