Use keyfilepath instead of cached public keys

This commit is contained in:
Zach Fox 2017-11-08 11:44:21 -08:00
parent 72fa0823ba
commit 3190fe1f32
5 changed files with 39 additions and 20 deletions

View file

@ -43,6 +43,10 @@ Item {
calculatePendingAndInvalidated();
}
if (transactionHistoryModel.count === 0) {
commerce.setMustRegenerateKeypair(true);
}
refreshTimer.start();
}
}

View file

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

View file

@ -57,6 +57,11 @@ void QmlCommerce::getWalletAuthenticatedStatus() {
emit walletAuthenticatedStatusResult(wallet->walletIsAuthenticatedWithPassphrase());
}
void QmlCommerce::setMustRegenerateKeypair(const bool& val) {
auto wallet = DependencyManager::get<Wallet>();
wallet->setMustRegenerateKeypair(val);
}
void QmlCommerce::getSecurityImage() {
auto wallet = DependencyManager::get<Wallet>();
wallet->getSecurityImage();

View file

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

View file

@ -328,9 +328,9 @@ Wallet::Wallet() {
auto walletScriptingInterface = DependencyManager::get<WalletScriptingInterface>();
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<QByteArray*, QByteArray*> 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<Ledger>();
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<Ledger>();
QString machineFingerprint = uuidStringWithoutCurlyBraces(FingerprintUtils::getMachineFingerprint());
return ledger->receiveAt(key, oldKey, machineFingerprint);
} else {
qCDebug(commerce) << "Failure generating keys!";
return false;
}
}
QStringList Wallet::listPublicKeys() {