From 3190fe1f325dd7851a605abc6df7d9fc88ad7745 Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Wed, 8 Nov 2017 11:44:21 -0800 Subject: [PATCH] Use keyfilepath instead of cached public keys --- .../qml/hifi/commerce/wallet/WalletHome.qml | 4 ++ interface/src/commerce/Ledger.cpp | 4 +- interface/src/commerce/QmlCommerce.cpp | 5 +++ interface/src/commerce/QmlCommerce.h | 1 + interface/src/commerce/Wallet.cpp | 45 +++++++++++-------- 5 files changed, 39 insertions(+), 20 deletions(-) diff --git a/interface/resources/qml/hifi/commerce/wallet/WalletHome.qml b/interface/resources/qml/hifi/commerce/wallet/WalletHome.qml index fd7ce0fdfd..44d3d54f58 100644 --- a/interface/resources/qml/hifi/commerce/wallet/WalletHome.qml +++ b/interface/resources/qml/hifi/commerce/wallet/WalletHome.qml @@ -43,6 +43,10 @@ Item { calculatePendingAndInvalidated(); } + + if (transactionHistoryModel.count === 0) { + commerce.setMustRegenerateKeypair(true); + } refreshTimer.start(); } } diff --git a/interface/src/commerce/Ledger.cpp b/interface/src/commerce/Ledger.cpp index 01c11347fd..519c906fd8 100644 --- a/interface/src/commerce/Ledger.cpp +++ b/interface/src/commerce/Ledger.cpp @@ -94,7 +94,9 @@ void Ledger::receiveAtSuccess(QNetworkReply& reply) { QByteArray response = reply.readAll(); QJsonObject data = QJsonDocument::fromJson(response).object(); - if (data["status"] == "fail") { // Not on "The List" for receiving HFC + // ZRF FIXME! Change to something like `data["status"] == fail` + // Not on "The List" for receiving HFC + if (true) { wallet->setMustRegenerateKeypair(true); } } diff --git a/interface/src/commerce/QmlCommerce.cpp b/interface/src/commerce/QmlCommerce.cpp index f29e46d843..ebd2d9ae7c 100644 --- a/interface/src/commerce/QmlCommerce.cpp +++ b/interface/src/commerce/QmlCommerce.cpp @@ -57,6 +57,11 @@ void QmlCommerce::getWalletAuthenticatedStatus() { emit walletAuthenticatedStatusResult(wallet->walletIsAuthenticatedWithPassphrase()); } +void QmlCommerce::setMustRegenerateKeypair(const bool& val) { + auto wallet = DependencyManager::get(); + wallet->setMustRegenerateKeypair(val); +} + void QmlCommerce::getSecurityImage() { auto wallet = DependencyManager::get(); wallet->getSecurityImage(); diff --git a/interface/src/commerce/QmlCommerce.h b/interface/src/commerce/QmlCommerce.h index d4f4aa35d2..a4e2ab8f42 100644 --- a/interface/src/commerce/QmlCommerce.h +++ b/interface/src/commerce/QmlCommerce.h @@ -54,6 +54,7 @@ protected: Q_INVOKABLE void getKeyFilePathIfExists(); Q_INVOKABLE void getSecurityImage(); Q_INVOKABLE void getWalletAuthenticatedStatus(); + Q_INVOKABLE void setMustRegenerateKeypair(const bool& val); Q_INVOKABLE void chooseSecurityImage(const QString& imageFile); Q_INVOKABLE void setPassphrase(const QString& passphrase); diff --git a/interface/src/commerce/Wallet.cpp b/interface/src/commerce/Wallet.cpp index fa72d02cca..07861d0633 100644 --- a/interface/src/commerce/Wallet.cpp +++ b/interface/src/commerce/Wallet.cpp @@ -328,9 +328,9 @@ Wallet::Wallet() { auto walletScriptingInterface = DependencyManager::get(); uint status; - if (_mustRegenerateKeypair || (!_passphrase->isEmpty() && _publicKeys.count() == 0)) { + if (_mustRegenerateKeypair || getKeyFilePath() == "") { qCDebug(commerce) << "Regenerating keys and resetting user_hfc_account. _mustRegenerateKeypair:" - << _mustRegenerateKeypair << "_publicKeys.count():" << _publicKeys.count(); + << _mustRegenerateKeypair << "keyFilePath:" << getKeyFilePath(); _mustRegenerateKeypair = false; resetKeysOnly(); ledger->reset(); @@ -535,25 +535,32 @@ bool Wallet::generateKeyPair() { // FIXME: initialize OpenSSL elsewhere soon initialize(); - qCInfo(commerce) << "Generating keypair."; - auto keyPair = generateRSAKeypair(); - - writeBackupInstructions(); - - // TODO: redo this soon -- need error checking and so on - writeSecurityImage(_securityImage, keyFilePath()); + qCInfo(commerce) << "Generating keypair..."; + QPair keyPair = generateRSAKeypair(); QString oldKey = _publicKeys.count() == 0 ? "" : _publicKeys.last(); - QString key = keyPair.first->toBase64(); - _publicKeys.push_back(key); - qCDebug(commerce) << "public key:" << key; + if (keyPair.first) { + writeBackupInstructions(); - // It's arguable whether we want to change the receiveAt every time, but: - // 1. It's certainly needed the first time, when createIfNeeded answers true. - // 2. It is maximally private, and we can step back from that later if desired. - // 3. It maximally exercises all the machinery, so we are most likely to surface issues now. - auto ledger = DependencyManager::get(); - QString machineFingerprint = uuidStringWithoutCurlyBraces(FingerprintUtils::getMachineFingerprint()); - return ledger->receiveAt(key, oldKey, machineFingerprint); + // TODO: redo this soon -- need error checking and so on + if (_securityImage) { + writeSecurityImage(_securityImage, keyFilePath()); + } + + QString key = keyPair.first->toBase64(); + _publicKeys.push_back(key); + qCDebug(commerce) << "public key:" << key; + + // It's arguable whether we want to change the receiveAt every time, but: + // 1. It's certainly needed the first time, when createIfNeeded answers true. + // 2. It is maximally private, and we can step back from that later if desired. + // 3. It maximally exercises all the machinery, so we are most likely to surface issues now. + auto ledger = DependencyManager::get(); + QString machineFingerprint = uuidStringWithoutCurlyBraces(FingerprintUtils::getMachineFingerprint()); + return ledger->receiveAt(key, oldKey, machineFingerprint); + } else { + qCDebug(commerce) << "Failure generating keys!"; + return false; + } } QStringList Wallet::listPublicKeys() {