add dialog to Menu to insert wallet private key

This commit is contained in:
Stephen Birarda 2014-07-17 11:43:30 -07:00
parent 0c8c4a2cf9
commit 45ae9f614d
5 changed files with 42 additions and 11 deletions

View file

@ -74,7 +74,6 @@
#include "devices/OculusManager.h" #include "devices/OculusManager.h"
#include "devices/TV3DManager.h" #include "devices/TV3DManager.h"
#include "renderer/ProgramObject.h" #include "renderer/ProgramObject.h"
#include "SignedWalletTransaction.h"
#include "scripting/AccountScriptingInterface.h" #include "scripting/AccountScriptingInterface.h"
#include "scripting/AudioDeviceScriptingInterface.h" #include "scripting/AudioDeviceScriptingInterface.h"

View file

@ -112,7 +112,8 @@ Menu::Menu() :
_preferencesDialog(NULL), _preferencesDialog(NULL),
_loginDialog(NULL), _loginDialog(NULL),
_snapshotsLocation(), _snapshotsLocation(),
_scriptsLocation() _scriptsLocation(),
_walletPrivateKey()
{ {
Application *appInstance = Application::getInstance(); Application *appInstance = Application::getInstance();
@ -442,6 +443,8 @@ Menu::Menu() :
false, false,
&UserActivityLogger::getInstance(), &UserActivityLogger::getInstance(),
SLOT(disable(bool))); SLOT(disable(bool)));
addActionToQMenuAndActionHash(developerMenu, MenuOption::WalletPrivateKey, 0, this, SLOT(changePrivateKey()));
addDisabledActionAndSeparator(developerMenu, "Testing"); addDisabledActionAndSeparator(developerMenu, "Testing");
@ -639,6 +642,8 @@ void Menu::loadSettings(QSettings* settings) {
_viewFrustumOffset.distance = loadSetting(settings, "viewFrustumOffsetDistance", 0.0f); _viewFrustumOffset.distance = loadSetting(settings, "viewFrustumOffsetDistance", 0.0f);
_viewFrustumOffset.up = loadSetting(settings, "viewFrustumOffsetUp", 0.0f); _viewFrustumOffset.up = loadSetting(settings, "viewFrustumOffsetUp", 0.0f);
settings->endGroup(); settings->endGroup();
_walletPrivateKey = settings->value("privateKey").toByteArray();
scanMenuBar(&loadAction, settings); scanMenuBar(&loadAction, settings);
Application::getInstance()->getAvatar()->loadData(settings); Application::getInstance()->getAvatar()->loadData(settings);
@ -682,6 +687,7 @@ void Menu::saveSettings(QSettings* settings) {
settings->setValue("viewFrustumOffsetDistance", _viewFrustumOffset.distance); settings->setValue("viewFrustumOffsetDistance", _viewFrustumOffset.distance);
settings->setValue("viewFrustumOffsetUp", _viewFrustumOffset.up); settings->setValue("viewFrustumOffsetUp", _viewFrustumOffset.up);
settings->endGroup(); settings->endGroup();
settings->setValue("privateKey", _walletPrivateKey);
scanMenuBar(&saveAction, settings); scanMenuBar(&saveAction, settings);
Application::getInstance()->getAvatar()->saveData(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) { void Menu::goToDomain(const QString newDomain) {
if (NodeList::getInstance()->getDomainHandler().getHostname() != newDomain) { if (NodeList::getInstance()->getDomainHandler().getHostname() != newDomain) {
// send a node kill request, indicating to other clients that they should play the "disappeared" effect // send a node kill request, indicating to other clients that they should play the "disappeared" effect

View file

@ -159,6 +159,8 @@ public:
void static goToOrientation(QString orientation); void static goToOrientation(QString orientation);
void static goToDomain(const QString newDomain); void static goToDomain(const QString newDomain);
void static goTo(QString destination); void static goTo(QString destination);
const QByteArray& getWalletPrivateKey() const { return _walletPrivateKey; }
signals: signals:
void scriptLocationChanged(const QString& newPath); void scriptLocationChanged(const QString& newPath);
@ -197,6 +199,7 @@ private slots:
void editPreferences(); void editPreferences();
void editAttachments(); void editAttachments();
void editAnimations(); void editAnimations();
void changePrivateKey();
void goToDomainDialog(); void goToDomainDialog();
void goToLocation(); void goToLocation();
void nameLocation(); void nameLocation();
@ -293,6 +296,8 @@ private:
QAction* _chatAction; QAction* _chatAction;
QString _snapshotsLocation; QString _snapshotsLocation;
QString _scriptsLocation; QString _scriptsLocation;
QByteArray _walletPrivateKey;
}; };
namespace MenuOption { namespace MenuOption {
@ -444,6 +449,7 @@ namespace MenuOption {
const QString VoxelMode = "Cycle Voxel Mode"; const QString VoxelMode = "Cycle Voxel Mode";
const QString Voxels = "Voxels"; const QString Voxels = "Voxels";
const QString VoxelTextures = "Voxel Textures"; const QString VoxelTextures = "Voxel Textures";
const QString WalletPrivateKey = "Wallet Private Key";
} }
void sendFakeEnterEvent(); void sendFakeEnterEvent();

View file

@ -19,6 +19,8 @@
#include <AccountManager.h> #include <AccountManager.h>
#include "Menu.h"
#include "SignedWalletTransaction.h" #include "SignedWalletTransaction.h"
SignedWalletTransaction::SignedWalletTransaction(const QUuid& destinationUUID, qint64 amount, SignedWalletTransaction::SignedWalletTransaction(const QUuid& destinationUUID, qint64 amount,
@ -55,19 +57,16 @@ QByteArray SignedWalletTransaction::messageDigest() {
} }
QByteArray SignedWalletTransaction::signedMessageDigest() { QByteArray SignedWalletTransaction::signedMessageDigest() {
// read the private key from file into memory // pull the current private key from menu into RSA structure in memory
QFile privateKeyFile("/Users/birarda/Desktop/generated-private.pem"); QByteArray privateKeyByteArray = Menu::getInstance()->getWalletPrivateKey();
privateKeyFile.open(QIODevice::ReadOnly);
QByteArray privateKeyData = privateKeyFile.readAll();
BIO* privateKeyBIO = NULL; BIO* privateKeyBIO = NULL;
RSA* rsaPrivateKey = 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); PEM_read_bio_RSAPrivateKey(privateKeyBIO, &rsaPrivateKey, NULL, NULL);
QByteArray digestToEncrypt = messageDigest(); QByteArray digestToEncrypt = messageDigest();
qDebug() << "encrypting the following digest" << digestToEncrypt;
QByteArray encryptedDigest(RSA_size(rsaPrivateKey), 0); QByteArray encryptedDigest(RSA_size(rsaPrivateKey), 0);
int encryptReturn = RSA_private_encrypt(digestToEncrypt.size(), int encryptReturn = RSA_private_encrypt(digestToEncrypt.size(),
@ -75,5 +74,9 @@ QByteArray SignedWalletTransaction::signedMessageDigest() {
reinterpret_cast<unsigned char*>(encryptedDigest.data()), reinterpret_cast<unsigned char*>(encryptedDigest.data()),
rsaPrivateKey, RSA_PKCS1_PADDING); rsaPrivateKey, RSA_PKCS1_PADDING);
return encryptedDigest; // free the two structures used
BIO_free(privateKeyBIO);
RSA_free(rsaPrivateKey);
return (encryptReturn != -1) ? encryptedDigest : QByteArray();
} }

View file

@ -109,8 +109,6 @@ void DataServerAccountInfo::setProfileInfoFromJSON(const QJsonObject& jsonObject
setXMPPPassword(user["xmpp_password"].toString()); setXMPPPassword(user["xmpp_password"].toString());
setDiscourseApiKey(user["discourse_api_key"].toString()); setDiscourseApiKey(user["discourse_api_key"].toString());
setWalletID(QUuid(user["wallet_id"].toString())); setWalletID(QUuid(user["wallet_id"].toString()));
qDebug() << "Wallet is" << _walletID;
} }
QDataStream& operator<<(QDataStream &out, const DataServerAccountInfo& info) { QDataStream& operator<<(QDataStream &out, const DataServerAccountInfo& info) {