From 5be9f2022e60864b4c161d9922a1f93468f6231c Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Fri, 13 Oct 2017 14:33:36 -0700 Subject: [PATCH] Fix writing backup instructions when restoring wallet backup --- interface/src/commerce/Wallet.cpp | 22 ++++++++++++---------- interface/src/commerce/Wallet.h | 1 + 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/interface/src/commerce/Wallet.cpp b/interface/src/commerce/Wallet.cpp index d7227a58f7..faa95b2a40 100644 --- a/interface/src/commerce/Wallet.cpp +++ b/interface/src/commerce/Wallet.cpp @@ -105,19 +105,19 @@ RSA* readKeys(const char* filename) { return key; } -bool writeBackupInstructions() { +bool Wallet::writeBackupInstructions() { QString inputFilename(PathUtils::resourcesPath() + "html/commerce/backup_instructions.html"); - QString filename = PathUtils::getAppDataFilePath(INSTRUCTIONS_FILE); - QFile outputFile(filename); + QString outputFilename = PathUtils::getAppDataFilePath(INSTRUCTIONS_FILE); + QFile outputFile(outputFilename); bool retval = false; - if (QFile::exists(filename)) + if (QFile::exists(outputFilename) || getKeyFilePath() == "") { - QFile::remove(filename); + return false; } - QFile::copy(inputFilename, filename); + QFile::copy(inputFilename, outputFilename); - if (QFile::exists(filename) && outputFile.open(QIODevice::ReadWrite)) { + if (QFile::exists(outputFilename) && outputFile.open(QIODevice::ReadWrite)) { QByteArray fileData = outputFile.readAll(); QString text(fileData); @@ -132,7 +132,7 @@ bool writeBackupInstructions() { retval = true; qCDebug(commerce) << "wrote html file successfully"; } else { - qCDebug(commerce) << "failed to open output html file" << filename; + qCDebug(commerce) << "failed to open output html file" << outputFilename; } return retval; } @@ -154,8 +154,6 @@ bool writeKeys(const char* filename, RSA* keys) { QFile(QString(filename)).remove(); return retval; } - - writeBackupInstructions(); retval = true; qCDebug(commerce) << "wrote keys successfully"; @@ -359,6 +357,8 @@ bool Wallet::setPassphrase(const QString& passphrase) { _publicKeys.clear(); + writeBackupInstructions(); + return true; } @@ -526,6 +526,8 @@ bool Wallet::generateKeyPair() { qCInfo(commerce) << "Generating keypair."; auto keyPair = generateRSAKeypair(); + writeBackupInstructions(); + // TODO: redo this soon -- need error checking and so on writeSecurityImage(_securityImage, keyFilePath()); QString oldKey = _publicKeys.count() == 0 ? "" : _publicKeys.last(); diff --git a/interface/src/commerce/Wallet.h b/interface/src/commerce/Wallet.h index 38c5299810..31df2df918 100644 --- a/interface/src/commerce/Wallet.h +++ b/interface/src/commerce/Wallet.h @@ -80,6 +80,7 @@ private: void updateImageProvider(); bool writeSecurityImage(const QPixmap* pixmap, const QString& outputFilePath); bool readSecurityImage(const QString& inputFilePath, unsigned char** outputBufferPtr, int* outputBufferLen); + bool writeBackupInstructions(); bool verifyOwnerChallenge(const QByteArray& encryptedText, const QString& publicKey, QString& decryptedText);