mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-09 10:47:53 +02:00
add dialog to Menu to insert wallet private key
This commit is contained in:
parent
0c8c4a2cf9
commit
45ae9f614d
5 changed files with 42 additions and 11 deletions
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
|
||||
#include <AccountManager.h>
|
||||
|
||||
#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<unsigned char*>(encryptedDigest.data()),
|
||||
rsaPrivateKey, RSA_PKCS1_PADDING);
|
||||
|
||||
return encryptedDigest;
|
||||
// free the two structures used
|
||||
BIO_free(privateKeyBIO);
|
||||
RSA_free(rsaPrivateKey);
|
||||
|
||||
return (encryptReturn != -1) ? encryptedDigest : QByteArray();
|
||||
}
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue