mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 03:44:02 +02:00
use OpenSSL to create signed wallet transaction using hard-code key
This commit is contained in:
parent
74a107f9f4
commit
cb9a2c615e
4 changed files with 51 additions and 12 deletions
|
@ -406,12 +406,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
|
|||
MIDIManager& midiManagerInstance = MIDIManager::getInstance();
|
||||
midiManagerInstance.openDefaultPort();
|
||||
#endif
|
||||
|
||||
|
||||
QUuid destinationWallet = QUuid::createUuid();
|
||||
|
||||
SignedWalletTransaction testTransaction(destinationWallet, 1000, QDateTime::currentDateTime().toTime_t(), 3600);
|
||||
qDebug() << "Message digest is" << testTransaction.hexMessage();
|
||||
}
|
||||
|
||||
Application::~Application() {
|
||||
|
|
|
@ -13,6 +13,12 @@
|
|||
#include <QtCore/QDebug>
|
||||
#include <QtCore/QFile>
|
||||
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/rsa.h>
|
||||
#include <openssl/pem.h>
|
||||
|
||||
#include <AccountManager.h>
|
||||
|
||||
#include "SignedWalletTransaction.h"
|
||||
|
||||
SignedWalletTransaction::SignedWalletTransaction(const QUuid& destinationUUID, qint64 amount,
|
||||
|
@ -35,9 +41,7 @@ QByteArray SignedWalletTransaction::hexMessage() {
|
|||
messageBinary.append(reinterpret_cast<const char*>(&_messageTimestamp), sizeof(_messageTimestamp));
|
||||
messageBinary.append(reinterpret_cast<const char*>(&_expiryDelta), sizeof(_expiryDelta));
|
||||
|
||||
QUuid sourceUUID = QUuid::createUuid();
|
||||
qDebug() << "The faked source UUID is" << sourceUUID;
|
||||
messageBinary.append(sourceUUID.toRfc4122());
|
||||
messageBinary.append(AccountManager::getInstance().getAccountInfo().getWalletID().toRfc4122());
|
||||
|
||||
messageBinary.append(_destinationUUID.toRfc4122());
|
||||
|
||||
|
@ -47,5 +51,29 @@ QByteArray SignedWalletTransaction::hexMessage() {
|
|||
}
|
||||
|
||||
QByteArray SignedWalletTransaction::messageDigest() {
|
||||
return QCryptographicHash::hash(hexMessage(), QCryptographicHash::Sha256);
|
||||
return QCryptographicHash::hash(hexMessage(), QCryptographicHash::Sha256).toHex();
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
BIO* privateKeyBIO = NULL;
|
||||
RSA* rsaPrivateKey = NULL;
|
||||
|
||||
privateKeyBIO = BIO_new_mem_buf(privateKeyData.data(), privateKeyData.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(),
|
||||
reinterpret_cast<const unsigned char*>(digestToEncrypt.constData()),
|
||||
reinterpret_cast<unsigned char*>(encryptedDigest.data()),
|
||||
rsaPrivateKey, RSA_PKCS1_PADDING);
|
||||
|
||||
return encryptedDigest;
|
||||
}
|
|
@ -18,6 +18,7 @@ DataServerAccountInfo::DataServerAccountInfo() :
|
|||
_username(),
|
||||
_xmppPassword(),
|
||||
_discourseApiKey(),
|
||||
_walletID(),
|
||||
_balance(0),
|
||||
_hasBalance(false)
|
||||
{
|
||||
|
@ -29,6 +30,7 @@ DataServerAccountInfo::DataServerAccountInfo(const DataServerAccountInfo& otherI
|
|||
_username = otherInfo._username;
|
||||
_xmppPassword = otherInfo._xmppPassword;
|
||||
_discourseApiKey = otherInfo._discourseApiKey;
|
||||
_walletID = otherInfo._walletID;
|
||||
_balance = otherInfo._balance;
|
||||
_hasBalance = otherInfo._hasBalance;
|
||||
}
|
||||
|
@ -46,6 +48,7 @@ void DataServerAccountInfo::swap(DataServerAccountInfo& otherInfo) {
|
|||
swap(_username, otherInfo._username);
|
||||
swap(_xmppPassword, otherInfo._xmppPassword);
|
||||
swap(_discourseApiKey, otherInfo._discourseApiKey);
|
||||
swap(_walletID, otherInfo._walletID);
|
||||
swap(_balance, otherInfo._balance);
|
||||
swap(_hasBalance, otherInfo._hasBalance);
|
||||
}
|
||||
|
@ -74,6 +77,12 @@ void DataServerAccountInfo::setDiscourseApiKey(const QString& discourseApiKey) {
|
|||
}
|
||||
}
|
||||
|
||||
void DataServerAccountInfo::setWalletID(const QUuid& walletID) {
|
||||
if (_walletID != walletID) {
|
||||
_walletID = walletID;
|
||||
}
|
||||
}
|
||||
|
||||
void DataServerAccountInfo::setBalance(qint64 balance) {
|
||||
if (!_hasBalance || _balance != balance) {
|
||||
_balance = balance;
|
||||
|
@ -99,14 +108,17 @@ void DataServerAccountInfo::setProfileInfoFromJSON(const QJsonObject& jsonObject
|
|||
setUsername(user["username"].toString());
|
||||
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) {
|
||||
out << info._accessToken << info._username << info._xmppPassword << info._discourseApiKey;
|
||||
out << info._accessToken << info._username << info._xmppPassword << info._discourseApiKey << info._walletID;
|
||||
return out;
|
||||
}
|
||||
|
||||
QDataStream& operator>>(QDataStream &in, DataServerAccountInfo& info) {
|
||||
in >> info._accessToken >> info._username >> info._xmppPassword >> info._discourseApiKey;
|
||||
in >> info._accessToken >> info._username >> info._xmppPassword >> info._discourseApiKey >> info._walletID;
|
||||
return in;
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#define hifi_DataServerAccountInfo_h
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QUuid>
|
||||
|
||||
#include "OAuthAccessToken.h"
|
||||
|
||||
|
@ -36,6 +37,9 @@ public:
|
|||
|
||||
const QString& getDiscourseApiKey() const { return _discourseApiKey; }
|
||||
void setDiscourseApiKey(const QString& discourseApiKey);
|
||||
|
||||
const QUuid& getWalletID() const { return _walletID; }
|
||||
void setWalletID(const QUuid& walletID);
|
||||
|
||||
qint64 getBalance() const { return _balance; }
|
||||
float getBalanceInSatoshis() const { return _balance / SATOSHIS_PER_CREDIT; }
|
||||
|
@ -59,6 +63,7 @@ private:
|
|||
QString _username;
|
||||
QString _xmppPassword;
|
||||
QString _discourseApiKey;
|
||||
QUuid _walletID;
|
||||
qint64 _balance;
|
||||
bool _hasBalance;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue