bool Wallet::getSecurityImage() { unsigned char* data; int dataLen; // if already decrypted, don't do it again if (_securityImage) { updateImageProvider(); emit securityImageResult(true); return true; } bool success = false; // decrypt and return. Don't bother if we have no file to decrypt, or // no salt set yet. QFileInfo fileInfo(keyFilePath()); if (fileInfo.exists() && _salt.size() > 0 && readSecurityImage(keyFilePath(), &data, &dataLen)) { // create the pixmap _securityImage = new QPixmap(); _securityImage->loadFromData(data, dataLen, "jpg"); qCDebug(commerce) << "created pixmap from encrypted file"; updateImageProvider(); delete[] data; success = true; } emit securityImageResult(success); return success; }
void Wallet::chooseSecurityImage(const QString& filename) { if (_securityImage) { delete _securityImage; } QString path = PathUtils::resourcesPath(); path.append("/qml/hifi/dialogs/security/"); path.append(filename); // now create a new security image pixmap _securityImage = new QPixmap(); qCDebug(commerce) << "loading data for pixmap from" << path; _securityImage->load(path); // update the image now updateImageProvider(); // we could be choosing the _inital_ security image. If so, there // will be no hifikey file yet. If that is the case, we are done. If // there _is_ a keyfile, we need to update it (similar to changing the // passphrase, we need to do so into a temp file and move it). if (!QFile(keyFilePath()).exists()) { qCDebug(commerce) << "initial security pic set for empty wallet"; emit securityImageResult(true); return; } bool success = writeWallet(); qCDebug(commerce) << "updated security pic" << success; emit securityImageResult(success); }
void Wallet::clear() { _publicKeys.clear(); if (_securityImage) { delete _securityImage; } _securityImage = nullptr; // tell the provider we got nothing updateImageProvider(); _passphrase->clear(); }
Wallet::Wallet() { auto nodeList = DependencyManager::get<NodeList>(); auto ledger = DependencyManager::get<Ledger>(); auto& packetReceiver = nodeList->getPacketReceiver(); packetReceiver.registerListener(PacketType::ChallengeOwnership, this, "handleChallengeOwnershipPacket"); packetReceiver.registerListener(PacketType::ChallengeOwnershipRequest, this, "handleChallengeOwnershipPacket"); connect(ledger.data(), &Ledger::accountResult, this, [&]() { auto wallet = DependencyManager::get<Wallet>(); auto walletScriptingInterface = DependencyManager::get<WalletScriptingInterface>(); uint status; if (wallet->getKeyFilePath() == "" || !wallet->getSecurityImage()) { status = (uint)WalletStatus::WALLET_STATUS_NOT_SET_UP; } else if (!wallet->walletIsAuthenticatedWithPassphrase()) { status = (uint)WalletStatus::WALLET_STATUS_NOT_AUTHENTICATED; } else { status = (uint)WalletStatus::WALLET_STATUS_READY; } walletScriptingInterface->setWalletStatus(status); }); auto accountManager = DependencyManager::get<AccountManager>(); connect(accountManager.data(), &AccountManager::usernameChanged, this, [&]() { getWalletStatus(); _publicKeys.clear(); if (_securityImage) { delete _securityImage; } _securityImage = nullptr; // tell the provider we got nothing updateImageProvider(); _passphrase->clear(); }); }