mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 14:03:55 +02:00
fire off generation of key-pair in conjunction with login, store private key
This commit is contained in:
parent
69402e275c
commit
7ce806b746
5 changed files with 53 additions and 0 deletions
|
@ -19,9 +19,11 @@
|
|||
#include <QtCore/QUrlQuery>
|
||||
#include <QtNetwork/QHttpMultiPart>
|
||||
#include <QtNetwork/QNetworkRequest>
|
||||
#include <qthread.h>
|
||||
|
||||
#include "NodeList.h"
|
||||
#include "PacketHeaders.h"
|
||||
#include "RSAKeypairGenerator.h"
|
||||
|
||||
#include "AccountManager.h"
|
||||
|
||||
|
@ -417,6 +419,7 @@ void AccountManager::requestAccessTokenFinished() {
|
|||
}
|
||||
|
||||
requestProfile();
|
||||
generateNewKeypair();
|
||||
}
|
||||
} else {
|
||||
// TODO: error handling
|
||||
|
@ -478,3 +481,39 @@ void AccountManager::requestProfileError(QNetworkReply::NetworkError error) {
|
|||
// TODO: error handling
|
||||
qDebug() << "AccountManager requestProfileError - " << error;
|
||||
}
|
||||
|
||||
void AccountManager::generateNewKeypair() {
|
||||
// setup a new QThread to generate the keypair on, in case it takes a while
|
||||
QThread* generateThread = new QThread(this);
|
||||
|
||||
// setup a keypair generator
|
||||
RSAKeypairGenerator* keypairGenerator = new RSAKeypairGenerator();
|
||||
|
||||
connect(generateThread, &QThread::started, keypairGenerator, &RSAKeypairGenerator::generateKeypair);
|
||||
connect(keypairGenerator, &RSAKeypairGenerator::generatedKeypair, this, &AccountManager::processGeneratedKeypair);
|
||||
connect(keypairGenerator, &RSAKeypairGenerator::errorGeneratingKeypair,
|
||||
this, &AccountManager::handleKeypairGenerationError);
|
||||
connect(keypairGenerator, &QObject::destroyed, generateThread, &QThread::quit);
|
||||
connect(generateThread, &QThread::finished, generateThread, &QThread::deleteLater);
|
||||
|
||||
keypairGenerator->moveToThread(generateThread);
|
||||
|
||||
qDebug() << "Starting worker thread to generate 2048-bit RSA key-pair.";
|
||||
generateThread->start();
|
||||
}
|
||||
|
||||
void AccountManager::processGeneratedKeypair(const QByteArray& publicKey, const QByteArray& privateKey) {
|
||||
|
||||
qDebug() << "Generated 2048-bit RSA key-pair. Storing private key and uploading public key.";
|
||||
|
||||
// set the private key on our data-server account info
|
||||
_accountInfo.setPrivateKey(privateKey);
|
||||
|
||||
// get rid of the keypair generator now that we don't need it anymore
|
||||
sender()->deleteLater();
|
||||
}
|
||||
|
||||
void AccountManager::handleKeypairGenerationError() {
|
||||
// for now there isn't anything we do with this except get the worker thread to clean up
|
||||
sender()->deleteLater();
|
||||
}
|
||||
|
|
|
@ -91,6 +91,8 @@ signals:
|
|||
void balanceChanged(qint64 newBalance);
|
||||
private slots:
|
||||
void processReply();
|
||||
void handleKeypairGenerationError();
|
||||
void processGeneratedKeypair(const QByteArray& publicKey, const QByteArray& privateKey);
|
||||
private:
|
||||
AccountManager();
|
||||
AccountManager(AccountManager const& other); // not implemented
|
||||
|
@ -98,6 +100,8 @@ private:
|
|||
|
||||
void passSuccessToCallback(QNetworkReply* reply);
|
||||
void passErrorToCallback(QNetworkReply* reply);
|
||||
|
||||
void generateNewKeypair();
|
||||
|
||||
Q_INVOKABLE void invokedRequest(const QString& path,
|
||||
bool requiresAuthentication,
|
||||
|
|
|
@ -41,6 +41,8 @@ public:
|
|||
|
||||
const QUuid& getWalletID() const { return _walletID; }
|
||||
void setWalletID(const QUuid& walletID);
|
||||
|
||||
void setPrivateKey(const QByteArray& privateKey) { _privateKey = privateKey; }
|
||||
|
||||
qint64 getBalance() const { return _balance; }
|
||||
float getBalanceInSatoshis() const { return _balance / SATOSHIS_PER_CREDIT; }
|
||||
|
|
|
@ -17,6 +17,12 @@
|
|||
|
||||
#include "RSAKeypairGenerator.h"
|
||||
|
||||
RSAKeypairGenerator::RSAKeypairGenerator(QObject* parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void RSAKeypairGenerator::generateKeypair() {
|
||||
|
||||
RSA* keyPair = RSA_new();
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
|
||||
class RSAKeypairGenerator : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
RSAKeypairGenerator(QObject* parent = 0);
|
||||
public slots:
|
||||
void generateKeypair();
|
||||
signals:
|
||||
|
|
Loading…
Reference in a new issue