mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 23:09:52 +02:00
Wallet cleanup
This commit is contained in:
parent
ad5b8c438e
commit
350cee5f35
5 changed files with 15 additions and 32 deletions
|
@ -325,7 +325,7 @@ Rectangle {
|
||||||
onClicked: {
|
onClicked: {
|
||||||
if (passphraseSelection.validateAndSubmitPassphrase()) {
|
if (passphraseSelection.validateAndSubmitPassphrase()) {
|
||||||
root.lastPage = "choosePassphrase";
|
root.lastPage = "choosePassphrase";
|
||||||
commerce.balance(); // Do this here so that keys are generated. Order might change as backend changes?
|
commerce.generateKeyPair();
|
||||||
choosePassphraseContainer.visible = false;
|
choosePassphraseContainer.visible = false;
|
||||||
privateKeysReadyContainer.visible = true;
|
privateKeysReadyContainer.visible = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,7 +86,7 @@ void QmlCommerce::history() {
|
||||||
|
|
||||||
void QmlCommerce::setPassphrase(const QString& passphrase) {
|
void QmlCommerce::setPassphrase(const QString& passphrase) {
|
||||||
auto wallet = DependencyManager::get<Wallet>();
|
auto wallet = DependencyManager::get<Wallet>();
|
||||||
if (wallet->getPassphrase() && !wallet->getPassphrase()->isEmpty()) {
|
if(wallet->getPassphrase() && !wallet->getPassphrase()->isEmpty() && !passphrase.isEmpty()) {
|
||||||
wallet->changePassphrase(passphrase);
|
wallet->changePassphrase(passphrase);
|
||||||
} else {
|
} else {
|
||||||
wallet->setPassphrase(passphrase);
|
wallet->setPassphrase(passphrase);
|
||||||
|
@ -94,6 +94,12 @@ void QmlCommerce::setPassphrase(const QString& passphrase) {
|
||||||
getWalletAuthenticatedStatus();
|
getWalletAuthenticatedStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QmlCommerce::generateKeyPair() {
|
||||||
|
auto wallet = DependencyManager::get<Wallet>();
|
||||||
|
wallet->generateKeyPair();
|
||||||
|
getWalletAuthenticatedStatus();
|
||||||
|
}
|
||||||
|
|
||||||
void QmlCommerce::reset() {
|
void QmlCommerce::reset() {
|
||||||
auto ledger = DependencyManager::get<Ledger>();
|
auto ledger = DependencyManager::get<Ledger>();
|
||||||
auto wallet = DependencyManager::get<Wallet>();
|
auto wallet = DependencyManager::get<Wallet>();
|
||||||
|
|
|
@ -53,7 +53,7 @@ protected:
|
||||||
Q_INVOKABLE void balance();
|
Q_INVOKABLE void balance();
|
||||||
Q_INVOKABLE void inventory();
|
Q_INVOKABLE void inventory();
|
||||||
Q_INVOKABLE void history();
|
Q_INVOKABLE void history();
|
||||||
|
Q_INVOKABLE void generateKeyPair();
|
||||||
Q_INVOKABLE void reset();
|
Q_INVOKABLE void reset();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -245,6 +245,8 @@ RSA* readPrivateKey(const char* filename) {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
qCDebug(commerce) << "couldn't parse" << filename;
|
qCDebug(commerce) << "couldn't parse" << filename;
|
||||||
|
// if the passphrase is wrong, then let's not cache it
|
||||||
|
DependencyManager::get<Wallet>()->setPassphrase("");
|
||||||
}
|
}
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
} else {
|
} else {
|
||||||
|
@ -273,8 +275,6 @@ void Wallet::setPassphrase(const QString& passphrase) {
|
||||||
}
|
}
|
||||||
_passphrase = new QString(passphrase);
|
_passphrase = new QString(passphrase);
|
||||||
|
|
||||||
// no matter what, we now need to clear the keys as they
|
|
||||||
// need to be read using this passphrase
|
|
||||||
_publicKeys.clear();
|
_publicKeys.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -413,28 +413,10 @@ bool Wallet::walletIsAuthenticatedWithPassphrase() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Wallet::createIfNeeded() {
|
bool Wallet::generateKeyPair() {
|
||||||
if (_publicKeys.count() > 0) return false;
|
|
||||||
|
|
||||||
// FIXME: initialize OpenSSL elsewhere soon
|
// FIXME: initialize OpenSSL elsewhere soon
|
||||||
initialize();
|
initialize();
|
||||||
|
|
||||||
// try to read existing keys if they exist...
|
|
||||||
auto publicKey = readPublicKey(keyFilePath().toStdString().c_str());
|
|
||||||
if (publicKey.size() > 0) {
|
|
||||||
if (auto key = readPrivateKey(keyFilePath().toStdString().c_str()) ) {
|
|
||||||
qCDebug(commerce) << "read private key";
|
|
||||||
RSA_free(key);
|
|
||||||
// K -- add the public key since we have a legit private key associated with it
|
|
||||||
_publicKeys.push_back(publicKey.toBase64());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
qCInfo(commerce) << "Creating wallet.";
|
|
||||||
return generateKeyPair();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Wallet::generateKeyPair() {
|
|
||||||
qCInfo(commerce) << "Generating keypair.";
|
qCInfo(commerce) << "Generating keypair.";
|
||||||
auto keyPair = generateRSAKeypair();
|
auto keyPair = generateRSAKeypair();
|
||||||
sendKeyFilePathIfExists();
|
sendKeyFilePathIfExists();
|
||||||
|
@ -453,7 +435,6 @@ bool Wallet::generateKeyPair() {
|
||||||
|
|
||||||
QStringList Wallet::listPublicKeys() {
|
QStringList Wallet::listPublicKeys() {
|
||||||
qCInfo(commerce) << "Enumerating public keys.";
|
qCInfo(commerce) << "Enumerating public keys.";
|
||||||
createIfNeeded();
|
|
||||||
return _publicKeys;
|
return _publicKeys;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -572,12 +553,8 @@ void Wallet::reset() {
|
||||||
|
|
||||||
// tell the provider we got nothing
|
// tell the provider we got nothing
|
||||||
updateImageProvider();
|
updateImageProvider();
|
||||||
delete _passphrase;
|
_passphrase->clear();
|
||||||
|
|
||||||
// for now we need to maintain the hard-coded passphrase.
|
|
||||||
// FIXME: remove this line as part of wiring up the passphrase
|
|
||||||
// and probably set it to nullptr
|
|
||||||
_passphrase = new QString("pwd");
|
|
||||||
|
|
||||||
QFile keyFile(keyFilePath());
|
QFile keyFile(keyFilePath());
|
||||||
QFile imageFile(imageFilePath());
|
QFile imageFile(imageFilePath());
|
||||||
|
@ -608,6 +585,7 @@ bool Wallet::changePassphrase(const QString& newPassphrase) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
qCDebug(commerce) << "couldn't read keys";
|
qCDebug(commerce) << "couldn't decrypt keys with current passphrase, clearing";
|
||||||
|
setPassphrase(QString(""));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,6 @@ public:
|
||||||
|
|
||||||
~Wallet();
|
~Wallet();
|
||||||
// These are currently blocking calls, although they might take a moment.
|
// These are currently blocking calls, although they might take a moment.
|
||||||
bool createIfNeeded();
|
|
||||||
bool generateKeyPair();
|
bool generateKeyPair();
|
||||||
QStringList listPublicKeys();
|
QStringList listPublicKeys();
|
||||||
QString signWithKey(const QByteArray& text, const QString& key);
|
QString signWithKey(const QByteArray& text, const QString& key);
|
||||||
|
|
Loading…
Reference in a new issue