Fix writing backup instructions when restoring wallet backup

This commit is contained in:
Zach Fox 2017-10-13 14:33:36 -07:00
parent 6b7c997a4c
commit 5be9f2022e
2 changed files with 13 additions and 10 deletions

View file

@ -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();

View file

@ -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);