Fix cancelEvent warning and better logging+error checking
This commit is contained in:
@@ -75,10 +75,9 @@ FirstTimeWizard::FirstTimeWizard(bool dangerous, QString server)
|
|||||||
QString addressbook = dir.filePath("addresslabels.dat.enc");
|
QString addressbook = dir.filePath("addresslabels.dat.enc");
|
||||||
QFile file(addressbook);
|
QFile file(addressbook);
|
||||||
|
|
||||||
if (file.exists())
|
if (file.exists()) {
|
||||||
{
|
file.rename(dir.filePath("addresslabels.dat.enc-backup"));
|
||||||
file.rename(dir.filePath("addresslabels.dat.enc-backup"));
|
qDebug() << __func__ << ": backed up old addresslabels";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the pages
|
// Create the pages
|
||||||
@@ -146,7 +145,7 @@ NewOrRestorePage::NewOrRestorePage(FirstTimeWizard *parent) : QWizardPage(parent
|
|||||||
form.txtPassword->setEnabled(false);
|
form.txtPassword->setEnabled(false);
|
||||||
form.txtConfirmPassword->setEnabled(false);
|
form.txtConfirmPassword->setEnabled(false);
|
||||||
|
|
||||||
QObject::connect(form.TOS, &QRadioButton::clicked, [=](bool checked) {
|
QObject::connect(form.TOS, &QRadioButton::clicked, [=](bool checked) {
|
||||||
if (checked) {
|
if (checked) {
|
||||||
|
|
||||||
form.txtPassword->setEnabled(true);
|
form.txtPassword->setEnabled(true);
|
||||||
@@ -156,7 +155,7 @@ NewOrRestorePage::NewOrRestorePage(FirstTimeWizard *parent) : QWizardPage(parent
|
|||||||
parent->button(QWizard::CommitButton)->setEnabled(false);
|
parent->button(QWizard::CommitButton)->setEnabled(false);
|
||||||
parent->button(QWizard::NextButton)->setEnabled(false);
|
parent->button(QWizard::NextButton)->setEnabled(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
auto fnPasswordEdited = [=](const QString&) {
|
auto fnPasswordEdited = [=](const QString&) {
|
||||||
@@ -169,16 +168,15 @@ NewOrRestorePage::NewOrRestorePage(FirstTimeWizard *parent) : QWizardPage(parent
|
|||||||
if (!form.txtPassword->text().isEmpty() &&
|
if (!form.txtPassword->text().isEmpty() &&
|
||||||
form.txtPassword->text() == form.txtConfirmPassword->text() && passphraseBlank.size() >= 16 ){
|
form.txtPassword->text() == form.txtConfirmPassword->text() && passphraseBlank.size() >= 16 ){
|
||||||
|
|
||||||
form.lblPasswordMatch->setText("");
|
form.lblPasswordMatch->setText("");
|
||||||
|
|
||||||
|
form.radioRestoreWallet->setEnabled(true);
|
||||||
|
form.radioNewWallet->setEnabled(true);
|
||||||
|
form.radioNewWallet->setChecked(true);
|
||||||
|
parent->button(QWizard::NextButton)->setEnabled(false);
|
||||||
|
|
||||||
form.radioRestoreWallet->setEnabled(true);
|
int length = passphrase.length();
|
||||||
form.radioNewWallet->setEnabled(true);
|
qDebug() << __func__ << ": passphrase length=" << length;
|
||||||
form.radioNewWallet->setChecked(true);
|
|
||||||
parent->button(QWizard::NextButton)->setEnabled(false);
|
|
||||||
|
|
||||||
|
|
||||||
int length = passphrase.length();
|
|
||||||
|
|
||||||
char *sequence = NULL;
|
char *sequence = NULL;
|
||||||
sequence = new char[length+1];
|
sequence = new char[length+1];
|
||||||
@@ -186,7 +184,6 @@ NewOrRestorePage::NewOrRestorePage(FirstTimeWizard *parent) : QWizardPage(parent
|
|||||||
|
|
||||||
QString passphraseHash = blake3_PW(sequence);
|
QString passphraseHash = blake3_PW(sequence);
|
||||||
|
|
||||||
|
|
||||||
char *sequence1 = NULL;
|
char *sequence1 = NULL;
|
||||||
sequence1 = new char[length+1];
|
sequence1 = new char[length+1];
|
||||||
strncpy(sequence1, passphraseHash.toUtf8(), length+1);
|
strncpy(sequence1, passphraseHash.toUtf8(), length+1);
|
||||||
@@ -200,12 +197,13 @@ NewOrRestorePage::NewOrRestorePage(FirstTimeWizard *parent) : QWizardPage(parent
|
|||||||
|
|
||||||
unsigned char key[KEY_LEN];
|
unsigned char key[KEY_LEN];
|
||||||
|
|
||||||
if (crypto_pwhash
|
if (crypto_pwhash(key, sizeof key, PASSWORD, strlen(PASSWORD), hash,
|
||||||
(key, sizeof key, PASSWORD, strlen(PASSWORD), hash,
|
|
||||||
crypto_pwhash_OPSLIMIT_SENSITIVE, crypto_pwhash_MEMLIMIT_SENSITIVE,
|
crypto_pwhash_OPSLIMIT_SENSITIVE, crypto_pwhash_MEMLIMIT_SENSITIVE,
|
||||||
crypto_pwhash_ALG_DEFAULT) != 0) {
|
crypto_pwhash_ALG_DEFAULT) != 0) {
|
||||||
/* out of memory */
|
/* out of memory */
|
||||||
}
|
qDebug() << __func__ << ": crypto_pwhash failed! Possibly out of memory";
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
QString passphraseHash1 = QByteArray(reinterpret_cast<const char*>(key), KEY_LEN).toHex();
|
QString passphraseHash1 = QByteArray(reinterpret_cast<const char*>(key), KEY_LEN).toHex();
|
||||||
DataStore::getChatDataStore()->setPassword(passphraseHash1);
|
DataStore::getChatDataStore()->setPassword(passphraseHash1);
|
||||||
|
|
||||||
@@ -226,12 +224,8 @@ NewOrRestorePage::NewOrRestorePage(FirstTimeWizard *parent) : QWizardPage(parent
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
form.lblPasswordMatch->setText(tr("Passphrase don't match or You have entered too few letters (16 minimum)"));
|
form.lblPasswordMatch->setText(tr("Passphrase don't match or You have entered too few letters (16 minimum)"));
|
||||||
|
|
||||||
parent->button(QWizard::CommitButton)->setEnabled(false);
|
parent->button(QWizard::CommitButton)->setEnabled(false);
|
||||||
form.radioRestoreWallet->setEnabled(false);
|
form.radioRestoreWallet->setEnabled(false);
|
||||||
@@ -244,20 +238,16 @@ NewOrRestorePage::NewOrRestorePage(FirstTimeWizard *parent) : QWizardPage(parent
|
|||||||
layout->addWidget(pageWidget);
|
layout->addWidget(pageWidget);
|
||||||
setLayout(layout);
|
setLayout(layout);
|
||||||
|
|
||||||
|
|
||||||
QObject::connect(form.txtConfirmPassword, &QLineEdit::textChanged, fnPasswordEdited);
|
QObject::connect(form.txtConfirmPassword, &QLineEdit::textChanged, fnPasswordEdited);
|
||||||
QObject::connect(form.txtPassword, &QLineEdit::textChanged, fnPasswordEdited);
|
QObject::connect(form.txtPassword, &QLineEdit::textChanged, fnPasswordEdited);
|
||||||
registerField("intro.new", form.radioNewWallet);
|
registerField("intro.new", form.radioNewWallet);
|
||||||
form.radioRestoreWallet->setEnabled(false);
|
form.radioRestoreWallet->setEnabled(false);
|
||||||
form.radioNewWallet->setEnabled(false);
|
form.radioNewWallet->setEnabled(false);
|
||||||
setCommitPage(true);
|
setCommitPage(true);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NewSeedPage::NewSeedPage(FirstTimeWizard *parent) : QWizardPage(parent) {
|
NewSeedPage::NewSeedPage(FirstTimeWizard *parent) : QWizardPage(parent) {
|
||||||
|
qDebug() << __func__;
|
||||||
this->parent = parent;
|
this->parent = parent;
|
||||||
|
|
||||||
setTitle("Your new wallet");
|
setTitle("Your new wallet");
|
||||||
@@ -273,9 +263,11 @@ NewSeedPage::NewSeedPage(FirstTimeWizard *parent) : QWizardPage(parent) {
|
|||||||
|
|
||||||
void NewSeedPage::initializePage() {
|
void NewSeedPage::initializePage() {
|
||||||
// Call the library to create a new wallet.
|
// Call the library to create a new wallet.
|
||||||
|
qDebug() << __func__;
|
||||||
|
|
||||||
char* resp = litelib_initialize_new(parent->dangerous,parent->server.toStdString().c_str());
|
char* resp = litelib_initialize_new(parent->dangerous,parent->server.toStdString().c_str());
|
||||||
QString reply = litelib_process_response(resp);
|
QString reply = litelib_process_response(resp);
|
||||||
|
qDebug() << __func__ << ": reply=" << reply;
|
||||||
|
|
||||||
auto parsed = json::parse(reply.toStdString().c_str(), nullptr, false);
|
auto parsed = json::parse(reply.toStdString().c_str(), nullptr, false);
|
||||||
if (parsed.is_discarded() || parsed.is_null() || parsed.find("seed") == parsed.end()) {
|
if (parsed.is_discarded() || parsed.is_null() || parsed.find("seed") == parsed.end()) {
|
||||||
@@ -290,23 +282,24 @@ void NewSeedPage::initializePage() {
|
|||||||
parent->button(QWizard::CancelButton)->setEnabled(false);
|
parent->button(QWizard::CancelButton)->setEnabled(false);
|
||||||
disconnect(parent->button(QWizard::CancelButton ), SIGNAL( clicked() ), parent, SLOT( reject() ) );
|
disconnect(parent->button(QWizard::CancelButton ), SIGNAL( clicked() ), parent, SLOT( reject() ) );
|
||||||
connect(parent->button(QWizard::CancelButton ), SIGNAL( clicked() ), parent, SLOT( cancelEvent() ) );
|
connect(parent->button(QWizard::CancelButton ), SIGNAL( clicked() ), parent, SLOT( cancelEvent() ) );
|
||||||
|
qDebug() << __func__ << ": page initialized with birthday=" << birthday;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FirstTimeWizard::cancelEvent()
|
void FirstTimeWizard::cancelEvent() {
|
||||||
{
|
qDebug() << __func__;
|
||||||
if( QMessageBox::question( this, ( "Quit Setup" ), ( "Setup is not complete yet. Are you sure you want to quit setup?" ), QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) {
|
if( QMessageBox::question( this, ( "Quit Setup" ), ( "Setup is not complete yet. Are you sure you want to quit setup?" ), QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) {
|
||||||
// allow cancel
|
qDebug() << __func__ << ": wizard canceled";
|
||||||
reject();
|
// allow cancel
|
||||||
}
|
reject();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Will be called just before closing. Make sure we can save the seed in the wallet
|
// Will be called just before closing. Make sure we can save the seed in the wallet
|
||||||
// before we allow the page to be closed
|
// before we allow the page to be closed
|
||||||
bool NewSeedPage::validatePage() {
|
bool NewSeedPage::validatePage() {
|
||||||
|
qDebug() << __func__;
|
||||||
|
|
||||||
Ui_verifyseed verifyseed;
|
Ui_verifyseed verifyseed;
|
||||||
QDialog dialog(this);
|
QDialog dialog(this);
|
||||||
@@ -316,7 +309,6 @@ bool NewSeedPage::validatePage() {
|
|||||||
form.birthday->setVisible(false);
|
form.birthday->setVisible(false);
|
||||||
form.txtSeed->setVisible(false);
|
form.txtSeed->setVisible(false);
|
||||||
|
|
||||||
|
|
||||||
QString seed = parent->getSeed();
|
QString seed = parent->getSeed();
|
||||||
QString birthday = parent->getBirthday();
|
QString birthday = parent->getBirthday();
|
||||||
QString word1 = seed.split(" ").at(13);
|
QString word1 = seed.split(" ").at(13);
|
||||||
@@ -603,8 +595,7 @@ bool NewSeedPage::validatePage() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
|
qDebug()<<"Wrong Seed";
|
||||||
qDebug()<<"Falscher Seed";
|
|
||||||
QFile file(dirwalletencfirst);
|
QFile file(dirwalletencfirst);
|
||||||
QFile file1(dirwalletfirst);
|
QFile file1(dirwalletfirst);
|
||||||
|
|
||||||
@@ -638,7 +629,9 @@ RestoreSeedPage::RestoreSeedPage(FirstTimeWizard *parent) : QWizardPage(parent)
|
|||||||
bool RestoreSeedPage::validatePage() {
|
bool RestoreSeedPage::validatePage() {
|
||||||
// 1. Validate that we do have 24 words
|
// 1. Validate that we do have 24 words
|
||||||
QString seed = form.txtSeed->toPlainText().replace(QRegExp("[ \n\r\t]+"), " ");
|
QString seed = form.txtSeed->toPlainText().replace(QRegExp("[ \n\r\t]+"), " ");
|
||||||
if (seed.trimmed().split(" ").length() != 24) {
|
auto seedLength = seed.trimmed().split(" ").length();
|
||||||
|
qDebug() << __func__ << ": seed length=" << seedLength;
|
||||||
|
if (seedLength != 24) {
|
||||||
QMessageBox::warning(this, tr("Failed to restore wallet"),
|
QMessageBox::warning(this, tr("Failed to restore wallet"),
|
||||||
tr("SilentDragonLite needs 24 words to restore wallet"),
|
tr("SilentDragonLite needs 24 words to restore wallet"),
|
||||||
QMessageBox::Ok);
|
QMessageBox::Ok);
|
||||||
@@ -650,16 +643,16 @@ bool RestoreSeedPage::validatePage() {
|
|||||||
bool ok;
|
bool ok;
|
||||||
qint64 birthday = birthday_str.toUInt(&ok);
|
qint64 birthday = birthday_str.toUInt(&ok);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
|
qDebug() << __func__ << ": Failed to parse wallet birthday=" << birthday_str;
|
||||||
QMessageBox::warning(this, tr("Failed to parse wallet birthday"),
|
QMessageBox::warning(this, tr("Failed to parse wallet birthday"),
|
||||||
tr("Couldn't understand wallet birthday. This should be a block height from where to rescan the wallet. You can leave it as '0' if you don't know what it should be."),
|
tr("Couldn't understand wallet birthday. This should be a block height from where to rescan the wallet. You can leave it as '0' if you don't know what it should be."),
|
||||||
QMessageBox::Ok);
|
QMessageBox::Ok);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
///Number
|
///Number
|
||||||
|
QString number_str = form.number->text();
|
||||||
QString number_str = form.number->text();
|
qint64 number = number_str.toUInt();
|
||||||
qint64 number = number_str.toUInt();
|
|
||||||
// 3. Attempt to restore wallet with the seed phrase
|
// 3. Attempt to restore wallet with the seed phrase
|
||||||
{
|
{
|
||||||
char* resp = litelib_initialize_new_from_phrase(parent->dangerous, parent->server.toStdString().c_str(),
|
char* resp = litelib_initialize_new_from_phrase(parent->dangerous, parent->server.toStdString().c_str(),
|
||||||
@@ -681,6 +674,7 @@ qint64 number = number_str.toUInt();
|
|||||||
|
|
||||||
auto parsed = json::parse(reply.toStdString().c_str(), nullptr, false);
|
auto parsed = json::parse(reply.toStdString().c_str(), nullptr, false);
|
||||||
if (parsed.is_discarded() || parsed.is_null() || parsed.find("result") == parsed.end()) {
|
if (parsed.is_discarded() || parsed.is_null() || parsed.find("result") == parsed.end()) {
|
||||||
|
qDebug() << __func__ << ": Failed to save wallet, reply=" << reply;
|
||||||
QMessageBox::warning(this, tr("Failed to save wallet"),
|
QMessageBox::warning(this, tr("Failed to save wallet"),
|
||||||
tr("Couldn't save the wallet") + "\n" + reply,
|
tr("Couldn't save the wallet") + "\n" + reply,
|
||||||
QMessageBox::Ok);
|
QMessageBox::Ok);
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
class FirstTimeWizard: public QWizard
|
class FirstTimeWizard: public QWizard
|
||||||
{
|
{
|
||||||
|
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FirstTimeWizard(bool dangerous, QString server);
|
FirstTimeWizard(bool dangerous, QString server);
|
||||||
@@ -46,8 +46,6 @@ private:
|
|||||||
friend class NewSeedPage;
|
friend class NewSeedPage;
|
||||||
friend class RestoreSeedPage;
|
friend class RestoreSeedPage;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class NewOrRestorePage: public QWizardPage {
|
class NewOrRestorePage: public QWizardPage {
|
||||||
|
|||||||
Reference in New Issue
Block a user