History

use OpenSSL to create signed wallet transaction using hard-code key

Stephen Birarda committed 12 years ago

Commit cb9a2c61 parent 74a107f4 files · +51 −12Browse files

Showing the changes to interface/src/SignedWalletTransaction.cpp (1 of 4 files). Show all

Unified · Split

interface/src/SignedWalletTransaction.cpp+32−4
@@ -13,6 +13,12 @@ · 12 unmodified lines
13#include <QtCore/QDebug>13#include <QtCore/QDebug>
14#include <QtCore/QFile>14#include <QtCore/QFile>
15 15
16#include <openssl/bio.h>
17#include <openssl/rsa.h>
18#include <openssl/pem.h>
19
20#include <AccountManager.h>
21
16#include "SignedWalletTransaction.h"22#include "SignedWalletTransaction.h"
17 23
18SignedWalletTransaction::SignedWalletTransaction(const QUuid& destinationUUID, qint64 amount,24SignedWalletTransaction::SignedWalletTransaction(const QUuid& destinationUUID, qint64 amount,
@@ -35,9 +41,7 @@ QByteArray SignedWalletTransaction::hexMessage() { · 16 unmodified lines
35 messageBinary.append(reinterpret_cast<const char*>(&_messageTimestamp), sizeof(_messageTimestamp));41 messageBinary.append(reinterpret_cast<const char*>(&_messageTimestamp), sizeof(_messageTimestamp));
36 messageBinary.append(reinterpret_cast<const char*>(&_expiryDelta), sizeof(_expiryDelta));42 messageBinary.append(reinterpret_cast<const char*>(&_expiryDelta), sizeof(_expiryDelta));
37 43
38 QUuid sourceUUID = QUuid::createUuid();44 messageBinary.append(AccountManager::getInstance().getAccountInfo().getWalletID().toRfc4122());
39 qDebug() << "The faked source UUID is" << sourceUUID;
40 messageBinary.append(sourceUUID.toRfc4122());
41 45
42 messageBinary.append(_destinationUUID.toRfc4122());46 messageBinary.append(_destinationUUID.toRfc4122());
43 47
@@ -47,5 +51,29 @@ QByteArray SignedWalletTransaction::hexMessage() { · 3 unmodified lines
47}51}
48 52
49QByteArray SignedWalletTransaction::messageDigest() {53QByteArray SignedWalletTransaction::messageDigest() {
50 return QCryptographicHash::hash(hexMessage(), QCryptographicHash::Sha256);54 return QCryptographicHash::hash(hexMessage(), QCryptographicHash::Sha256).toHex();
55}
56
57QByteArray SignedWalletTransaction::signedMessageDigest() {
58 // read the private key from file into memory
59 QFile privateKeyFile("/Users/birarda/Desktop/generated-private.pem");
60 privateKeyFile.open(QIODevice::ReadOnly);
61 QByteArray privateKeyData = privateKeyFile.readAll();
62
63 BIO* privateKeyBIO = NULL;
64 RSA* rsaPrivateKey = NULL;
65
66 privateKeyBIO = BIO_new_mem_buf(privateKeyData.data(), privateKeyData.size());
67 PEM_read_bio_RSAPrivateKey(privateKeyBIO, &rsaPrivateKey, NULL, NULL);
68
69 QByteArray digestToEncrypt = messageDigest();
70 qDebug() << "encrypting the following digest" << digestToEncrypt;
71 QByteArray encryptedDigest(RSA_size(rsaPrivateKey), 0);
72
73 int encryptReturn = RSA_private_encrypt(digestToEncrypt.size(),
74 reinterpret_cast<const unsigned char*>(digestToEncrypt.constData()),
75 reinterpret_cast<unsigned char*>(encryptedDigest.data()),
76 rsaPrivateKey, RSA_PKCS1_PADDING);
77
78 return encryptedDigest;
51}79}