From 45ae9f614d17b4d1d7bd02c2919e0011dac7bb6e Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 17 Jul 2014 11:43:30 -0700 Subject: [PATCH] add dialog to Menu to insert wallet private key --- interface/src/Application.cpp | 1 - interface/src/Menu.cpp | 27 ++++++++++++++++++- interface/src/Menu.h | 6 +++++ interface/src/SignedWalletTransaction.cpp | 17 +++++++----- .../networking/src/DataServerAccountInfo.cpp | 2 -- 5 files changed, 42 insertions(+), 11 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 2cef8293aa..1d5cbabd32 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -74,7 +74,6 @@ #include "devices/OculusManager.h" #include "devices/TV3DManager.h" #include "renderer/ProgramObject.h" -#include "SignedWalletTransaction.h" #include "scripting/AccountScriptingInterface.h" #include "scripting/AudioDeviceScriptingInterface.h" diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 1c3d0f25b8..38af5d4659 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -112,7 +112,8 @@ Menu::Menu() : _preferencesDialog(NULL), _loginDialog(NULL), _snapshotsLocation(), - _scriptsLocation() + _scriptsLocation(), + _walletPrivateKey() { Application *appInstance = Application::getInstance(); @@ -442,6 +443,8 @@ Menu::Menu() : false, &UserActivityLogger::getInstance(), SLOT(disable(bool))); + + addActionToQMenuAndActionHash(developerMenu, MenuOption::WalletPrivateKey, 0, this, SLOT(changePrivateKey())); addDisabledActionAndSeparator(developerMenu, "Testing"); @@ -639,6 +642,8 @@ void Menu::loadSettings(QSettings* settings) { _viewFrustumOffset.distance = loadSetting(settings, "viewFrustumOffsetDistance", 0.0f); _viewFrustumOffset.up = loadSetting(settings, "viewFrustumOffsetUp", 0.0f); settings->endGroup(); + + _walletPrivateKey = settings->value("privateKey").toByteArray(); scanMenuBar(&loadAction, settings); Application::getInstance()->getAvatar()->loadData(settings); @@ -682,6 +687,7 @@ void Menu::saveSettings(QSettings* settings) { settings->setValue("viewFrustumOffsetDistance", _viewFrustumOffset.distance); settings->setValue("viewFrustumOffsetUp", _viewFrustumOffset.up); settings->endGroup(); + settings->setValue("privateKey", _walletPrivateKey); scanMenuBar(&saveAction, settings); Application::getInstance()->getAvatar()->saveData(settings); @@ -996,6 +1002,25 @@ void Menu::editAnimations() { } } +void Menu::changePrivateKey() { + // setup the dialog + QInputDialog privateKeyDialog(Application::getInstance()->getWindow()); + privateKeyDialog.setWindowTitle("Change Private Key"); + privateKeyDialog.setLabelText("RSA 2048-bit Private Key:"); + privateKeyDialog.setWindowFlags(Qt::Sheet); + privateKeyDialog.setTextValue(QString(_walletPrivateKey)); + privateKeyDialog.resize(privateKeyDialog.parentWidget()->size().width() * DIALOG_RATIO_OF_WINDOW, + privateKeyDialog.size().height()); + + int dialogReturn = privateKeyDialog.exec(); + if (dialogReturn == QDialog::Accepted) { + // pull the private key from the dialog + _walletPrivateKey = privateKeyDialog.textValue().toUtf8(); + } + + sendFakeEnterEvent(); +} + void Menu::goToDomain(const QString newDomain) { if (NodeList::getInstance()->getDomainHandler().getHostname() != newDomain) { // send a node kill request, indicating to other clients that they should play the "disappeared" effect diff --git a/interface/src/Menu.h b/interface/src/Menu.h index 2e61bf8fd8..9554d4e888 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -159,6 +159,8 @@ public: void static goToOrientation(QString orientation); void static goToDomain(const QString newDomain); void static goTo(QString destination); + + const QByteArray& getWalletPrivateKey() const { return _walletPrivateKey; } signals: void scriptLocationChanged(const QString& newPath); @@ -197,6 +199,7 @@ private slots: void editPreferences(); void editAttachments(); void editAnimations(); + void changePrivateKey(); void goToDomainDialog(); void goToLocation(); void nameLocation(); @@ -293,6 +296,8 @@ private: QAction* _chatAction; QString _snapshotsLocation; QString _scriptsLocation; + QByteArray _walletPrivateKey; + }; namespace MenuOption { @@ -444,6 +449,7 @@ namespace MenuOption { const QString VoxelMode = "Cycle Voxel Mode"; const QString Voxels = "Voxels"; const QString VoxelTextures = "Voxel Textures"; + const QString WalletPrivateKey = "Wallet Private Key"; } void sendFakeEnterEvent(); diff --git a/interface/src/SignedWalletTransaction.cpp b/interface/src/SignedWalletTransaction.cpp index 4d81835e3c..d29207e4f5 100644 --- a/interface/src/SignedWalletTransaction.cpp +++ b/interface/src/SignedWalletTransaction.cpp @@ -19,6 +19,8 @@ #include +#include "Menu.h" + #include "SignedWalletTransaction.h" SignedWalletTransaction::SignedWalletTransaction(const QUuid& destinationUUID, qint64 amount, @@ -55,19 +57,16 @@ QByteArray SignedWalletTransaction::messageDigest() { } QByteArray SignedWalletTransaction::signedMessageDigest() { - // read the private key from file into memory - QFile privateKeyFile("/Users/birarda/Desktop/generated-private.pem"); - privateKeyFile.open(QIODevice::ReadOnly); - QByteArray privateKeyData = privateKeyFile.readAll(); + // pull the current private key from menu into RSA structure in memory + QByteArray privateKeyByteArray = Menu::getInstance()->getWalletPrivateKey(); BIO* privateKeyBIO = NULL; RSA* rsaPrivateKey = NULL; - privateKeyBIO = BIO_new_mem_buf(privateKeyData.data(), privateKeyData.size()); + privateKeyBIO = BIO_new_mem_buf(privateKeyByteArray.data(), privateKeyByteArray.size()); PEM_read_bio_RSAPrivateKey(privateKeyBIO, &rsaPrivateKey, NULL, NULL); QByteArray digestToEncrypt = messageDigest(); - qDebug() << "encrypting the following digest" << digestToEncrypt; QByteArray encryptedDigest(RSA_size(rsaPrivateKey), 0); int encryptReturn = RSA_private_encrypt(digestToEncrypt.size(), @@ -75,5 +74,9 @@ QByteArray SignedWalletTransaction::signedMessageDigest() { reinterpret_cast(encryptedDigest.data()), rsaPrivateKey, RSA_PKCS1_PADDING); - return encryptedDigest; + // free the two structures used + BIO_free(privateKeyBIO); + RSA_free(rsaPrivateKey); + + return (encryptReturn != -1) ? encryptedDigest : QByteArray(); } \ No newline at end of file diff --git a/libraries/networking/src/DataServerAccountInfo.cpp b/libraries/networking/src/DataServerAccountInfo.cpp index 376aa274c7..9bdb012f70 100644 --- a/libraries/networking/src/DataServerAccountInfo.cpp +++ b/libraries/networking/src/DataServerAccountInfo.cpp @@ -109,8 +109,6 @@ void DataServerAccountInfo::setProfileInfoFromJSON(const QJsonObject& jsonObject setXMPPPassword(user["xmpp_password"].toString()); setDiscourseApiKey(user["discourse_api_key"].toString()); setWalletID(QUuid(user["wallet_id"].toString())); - - qDebug() << "Wallet is" << _walletID; } QDataStream& operator<<(QDataStream &out, const DataServerAccountInfo& info) {