mirror of
https://github.com/overte-org/overte.git
synced 2025-08-04 06:03:26 +02:00
Merge pull request #11325 from davidkelly/dk/UserHfcAccountRework
Use new hfc account endpoint
This commit is contained in:
commit
db0ecb61fd
7 changed files with 60 additions and 8 deletions
|
@ -33,12 +33,19 @@ Rectangle {
|
||||||
Hifi.QmlCommerce {
|
Hifi.QmlCommerce {
|
||||||
id: commerce;
|
id: commerce;
|
||||||
|
|
||||||
|
onAccountResult: {
|
||||||
|
if (result.status === "success") {
|
||||||
|
commerce.getKeyFilePathIfExists();
|
||||||
|
} else {
|
||||||
|
// unsure how to handle a failure here. We definitely cannot proceed.
|
||||||
|
}
|
||||||
|
}
|
||||||
onLoginStatusResult: {
|
onLoginStatusResult: {
|
||||||
if (!isLoggedIn && root.activeView !== "needsLogIn") {
|
if (!isLoggedIn && root.activeView !== "needsLogIn") {
|
||||||
root.activeView = "needsLogIn";
|
root.activeView = "needsLogIn";
|
||||||
} else if (isLoggedIn) {
|
} else if (isLoggedIn) {
|
||||||
root.activeView = "initialize";
|
root.activeView = "initialize";
|
||||||
commerce.getKeyFilePathIfExists();
|
commerce.account();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -176,3 +176,28 @@ void Ledger::resetFailure(QNetworkReply& reply) { failResponse("reset", reply);
|
||||||
void Ledger::reset() {
|
void Ledger::reset() {
|
||||||
send("reset_user_hfc_account", "resetSuccess", "resetFailure", QNetworkAccessManager::PutOperation, QJsonObject());
|
send("reset_user_hfc_account", "resetSuccess", "resetFailure", QNetworkAccessManager::PutOperation, QJsonObject());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Ledger::accountSuccess(QNetworkReply& reply) {
|
||||||
|
// lets set the appropriate stuff in the wallet now
|
||||||
|
auto wallet = DependencyManager::get<Wallet>();
|
||||||
|
QByteArray response = reply.readAll();
|
||||||
|
QJsonObject data = QJsonDocument::fromJson(response).object()["data"].toObject();
|
||||||
|
|
||||||
|
auto salt = QByteArray::fromBase64(data["salt"].toString().toUtf8());
|
||||||
|
auto iv = QByteArray::fromBase64(data["iv"].toString().toUtf8());
|
||||||
|
auto ckey = QByteArray::fromBase64(data["ckey"].toString().toUtf8());
|
||||||
|
|
||||||
|
wallet->setSalt(salt);
|
||||||
|
wallet->setIv(iv);
|
||||||
|
wallet->setCKey(ckey);
|
||||||
|
|
||||||
|
// none of the hfc account info should be emitted
|
||||||
|
emit accountResult(QJsonObject{ {"status", "success"} });
|
||||||
|
}
|
||||||
|
|
||||||
|
void Ledger::accountFailure(QNetworkReply& reply) {
|
||||||
|
failResponse("account", reply);
|
||||||
|
}
|
||||||
|
void Ledger::account() {
|
||||||
|
send("hfc_account", "accountSuccess", "accountFailure", QNetworkAccessManager::PutOperation, QJsonObject());
|
||||||
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@ public:
|
||||||
void balance(const QStringList& keys);
|
void balance(const QStringList& keys);
|
||||||
void inventory(const QStringList& keys);
|
void inventory(const QStringList& keys);
|
||||||
void history(const QStringList& keys);
|
void history(const QStringList& keys);
|
||||||
|
void account();
|
||||||
void reset();
|
void reset();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
@ -37,6 +38,7 @@ signals:
|
||||||
void balanceResult(QJsonObject result);
|
void balanceResult(QJsonObject result);
|
||||||
void inventoryResult(QJsonObject result);
|
void inventoryResult(QJsonObject result);
|
||||||
void historyResult(QJsonObject result);
|
void historyResult(QJsonObject result);
|
||||||
|
void accountResult(QJsonObject result);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void buySuccess(QNetworkReply& reply);
|
void buySuccess(QNetworkReply& reply);
|
||||||
|
@ -51,6 +53,8 @@ public slots:
|
||||||
void historyFailure(QNetworkReply& reply);
|
void historyFailure(QNetworkReply& reply);
|
||||||
void resetSuccess(QNetworkReply& reply);
|
void resetSuccess(QNetworkReply& reply);
|
||||||
void resetFailure(QNetworkReply& reply);
|
void resetFailure(QNetworkReply& reply);
|
||||||
|
void accountSuccess(QNetworkReply& reply);
|
||||||
|
void accountFailure(QNetworkReply& reply);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QJsonObject apiResponse(const QString& label, QNetworkReply& reply);
|
QJsonObject apiResponse(const QString& label, QNetworkReply& reply);
|
||||||
|
|
|
@ -27,6 +27,7 @@ QmlCommerce::QmlCommerce(QQuickItem* parent) : OffscreenQmlDialog(parent) {
|
||||||
connect(wallet.data(), &Wallet::securityImageResult, this, &QmlCommerce::securityImageResult);
|
connect(wallet.data(), &Wallet::securityImageResult, this, &QmlCommerce::securityImageResult);
|
||||||
connect(ledger.data(), &Ledger::historyResult, this, &QmlCommerce::historyResult);
|
connect(ledger.data(), &Ledger::historyResult, this, &QmlCommerce::historyResult);
|
||||||
connect(wallet.data(), &Wallet::keyFilePathIfExistsResult, this, &QmlCommerce::keyFilePathIfExistsResult);
|
connect(wallet.data(), &Wallet::keyFilePathIfExistsResult, this, &QmlCommerce::keyFilePathIfExistsResult);
|
||||||
|
connect(ledger.data(), &Ledger::accountResult, this, &QmlCommerce::accountResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlCommerce::getLoginStatus() {
|
void QmlCommerce::getLoginStatus() {
|
||||||
|
@ -106,3 +107,8 @@ void QmlCommerce::reset() {
|
||||||
ledger->reset();
|
ledger->reset();
|
||||||
wallet->reset();
|
wallet->reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QmlCommerce::account() {
|
||||||
|
auto ledger = DependencyManager::get<Ledger>();
|
||||||
|
ledger->account();
|
||||||
|
}
|
||||||
|
|
|
@ -39,6 +39,7 @@ signals:
|
||||||
void balanceResult(QJsonObject result);
|
void balanceResult(QJsonObject result);
|
||||||
void inventoryResult(QJsonObject result);
|
void inventoryResult(QJsonObject result);
|
||||||
void historyResult(QJsonObject result);
|
void historyResult(QJsonObject result);
|
||||||
|
void accountResult(QJsonObject result);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Q_INVOKABLE void getLoginStatus();
|
Q_INVOKABLE void getLoginStatus();
|
||||||
|
@ -55,6 +56,7 @@ protected:
|
||||||
Q_INVOKABLE void history();
|
Q_INVOKABLE void history();
|
||||||
Q_INVOKABLE void generateKeyPair();
|
Q_INVOKABLE void generateKeyPair();
|
||||||
Q_INVOKABLE void reset();
|
Q_INVOKABLE void reset();
|
||||||
|
Q_INVOKABLE void account();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_QmlCommerce_h
|
#endif // hifi_QmlCommerce_h
|
||||||
|
|
|
@ -55,9 +55,12 @@ QString imageFilePath() {
|
||||||
// use the cached _passphrase if it exists, otherwise we need to prompt
|
// use the cached _passphrase if it exists, otherwise we need to prompt
|
||||||
int passwordCallback(char* password, int maxPasswordSize, int rwFlag, void* u) {
|
int passwordCallback(char* password, int maxPasswordSize, int rwFlag, void* u) {
|
||||||
// just return a hardcoded pwd for now
|
// just return a hardcoded pwd for now
|
||||||
auto passphrase = DependencyManager::get<Wallet>()->getPassphrase();
|
auto wallet = DependencyManager::get<Wallet>();
|
||||||
|
auto passphrase = wallet->getPassphrase();
|
||||||
if (passphrase && !passphrase->isEmpty()) {
|
if (passphrase && !passphrase->isEmpty()) {
|
||||||
strcpy(password, passphrase->toLocal8Bit().constData());
|
QString saltedPassphrase(*passphrase);
|
||||||
|
saltedPassphrase.append(wallet->getSalt());
|
||||||
|
strcpy(password, saltedPassphrase.toUtf8().constData());
|
||||||
return static_cast<int>(passphrase->size());
|
return static_cast<int>(passphrase->size());
|
||||||
} else {
|
} else {
|
||||||
// this shouldn't happen - so lets log it to tell us we have
|
// this shouldn't happen - so lets log it to tell us we have
|
||||||
|
@ -254,13 +257,12 @@ RSA* readPrivateKey(const char* filename) {
|
||||||
}
|
}
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
static const unsigned char IVEC[16] = "IAmAnIVecYay123";
|
|
||||||
|
|
||||||
void initializeAESKeys(unsigned char* ivec, unsigned char* ckey, const QByteArray& salt) {
|
void initializeAESKeys(unsigned char* ivec, unsigned char* ckey, const QByteArray& salt) {
|
||||||
// first ivec
|
// use the ones in the wallet
|
||||||
memcpy(ivec, IVEC, 16);
|
auto wallet = DependencyManager::get<Wallet>();
|
||||||
auto hash = QCryptographicHash::hash(salt, QCryptographicHash::Sha256);
|
memcpy(ivec, wallet->getIv(), 16);
|
||||||
memcpy(ckey, hash.data(), 32);
|
memcpy(ckey, wallet->getCKey(), 32);
|
||||||
}
|
}
|
||||||
|
|
||||||
Wallet::~Wallet() {
|
Wallet::~Wallet() {
|
||||||
|
|
|
@ -35,6 +35,10 @@ public:
|
||||||
|
|
||||||
void setSalt(const QByteArray& salt) { _salt = salt; }
|
void setSalt(const QByteArray& salt) { _salt = salt; }
|
||||||
QByteArray getSalt() { return _salt; }
|
QByteArray getSalt() { return _salt; }
|
||||||
|
void setIv(const QByteArray& iv) { _iv = iv; }
|
||||||
|
QByteArray getIv() { return _iv; }
|
||||||
|
void setCKey(const QByteArray& ckey) { _ckey = ckey; }
|
||||||
|
QByteArray getCKey() { return _ckey; }
|
||||||
|
|
||||||
void setPassphrase(const QString& passphrase);
|
void setPassphrase(const QString& passphrase);
|
||||||
QString* getPassphrase() { return _passphrase; }
|
QString* getPassphrase() { return _passphrase; }
|
||||||
|
@ -52,6 +56,8 @@ private:
|
||||||
QStringList _publicKeys{};
|
QStringList _publicKeys{};
|
||||||
QPixmap* _securityImage { nullptr };
|
QPixmap* _securityImage { nullptr };
|
||||||
QByteArray _salt {"iamsalt!"};
|
QByteArray _salt {"iamsalt!"};
|
||||||
|
QByteArray _iv;
|
||||||
|
QByteArray _ckey;
|
||||||
QString* _passphrase { new QString("") };
|
QString* _passphrase { new QString("") };
|
||||||
|
|
||||||
void updateImageProvider();
|
void updateImageProvider();
|
||||||
|
|
Loading…
Reference in a new issue