Browse Source

set passphrase on initial install #64

pull/130/head
DenioD 4 years ago
parent
commit
c5c3eab002
  1. 12
      src/DataStore/ChatDataStore.cpp
  2. 5
      src/DataStore/ChatDataStore.h
  3. 4
      src/chatmodel.cpp
  4. 8
      src/controller.cpp
  5. 61
      src/firsttimewizard.cpp
  6. 12
      src/firsttimewizard.h
  7. 17
      src/mainwindow.cpp
  8. 12
      src/mainwindow.h
  9. 28
      src/newseed.ui
  10. 87
      src/newwallet.ui

12
src/DataStore/ChatDataStore.cpp

@ -33,6 +33,18 @@ ChatItem ChatDataStore::getData(QString key)
return this->data[key]; return this->data[key];
} }
QString ChatDataStore::getPassword()
{
return _password;
}
void ChatDataStore::setPassword(QString password)
{
_password = password;
}
QString ChatDataStore::dump() QString ChatDataStore::dump()
{ {
json chats; json chats;

5
src/DataStore/ChatDataStore.h

@ -25,6 +25,11 @@ class ChatDataStore
std::map<QString, ChatItem> getAllNewContactRequests(); std::map<QString, ChatItem> getAllNewContactRequests();
std::map<QString, ChatItem> getAllOldContactRequests(); std::map<QString, ChatItem> getAllOldContactRequests();
std::map<QString, ChatItem> getAllMemos(); std::map<QString, ChatItem> getAllMemos();
QString getPassword();
void setPassword(QString Password);
QString _password;
QString dump(); QString dump();
~ChatDataStore() ~ChatDataStore()

4
src/chatmodel.cpp

@ -454,7 +454,7 @@ Tx MainWindow::createTxFromChatPage() {
QString pubkey = this->getPubkeyByAddress(addr); QString pubkey = this->getPubkeyByAddress(addr);
QString passphrase = this->getPassword(); QString passphrase = DataStore::getChatDataStore()->getPassword();
QString hashEncryptionKey = passphrase; QString hashEncryptionKey = passphrase;
int length = hashEncryptionKey.length(); int length = hashEncryptionKey.length();
@ -783,7 +783,7 @@ Tx MainWindow::createTxForSafeContactRequest()
QString memo = contactRequest.getMemo(); QString memo = contactRequest.getMemo();
// QString privkey = rpc->fetchPrivKey(myAddr); // QString privkey = rpc->fetchPrivKey(myAddr);
QString passphrase = this->getPassword(); QString passphrase = DataStore::getChatDataStore()->getPassword();
QString hashEncryptionKey = passphrase; QString hashEncryptionKey = passphrase;
int length = hashEncryptionKey.length(); int length = hashEncryptionKey.length();

8
src/controller.cpp

@ -11,10 +11,6 @@
#include "Model/ChatItem.h" #include "Model/ChatItem.h"
#include "DataStore/DataStore.h" #include "DataStore/DataStore.h"
/*template<>
DataStore<QString>* DataStore<QString>::instance = nullptr;
template<>
bool DataStore<QString>::instanced = false;*/
ChatModel *chatModel = new ChatModel(); ChatModel *chatModel = new ChatModel();
Chat *chat = new Chat(); Chat *chat = new Chat();
ContactModel *contactModel = new ContactModel(); ContactModel *contactModel = new ContactModel();
@ -971,7 +967,7 @@ void Controller::refreshTransactions() {
if ((memo.startsWith("{") == false) && (headerbytes.length() > 20)) if ((memo.startsWith("{") == false) && (headerbytes.length() > 20))
{ {
QString passphrase = main->getPassword(); QString passphrase = DataStore::getChatDataStore()->getPassword();
QString hashEncryptionKey = passphrase; QString hashEncryptionKey = passphrase;
int length = hashEncryptionKey.length(); int length = hashEncryptionKey.length();
@ -1227,7 +1223,7 @@ void Controller::refreshTransactions() {
chatModel->addMemo(txid, headerbytes); chatModel->addMemo(txid, headerbytes);
}else{} }else{}
QString passphrase = main->getPassword(); QString passphrase = DataStore::getChatDataStore()->getPassword();
QString hashEncryptionKey = passphrase; QString hashEncryptionKey = passphrase;
int length = hashEncryptionKey.length(); int length = hashEncryptionKey.length();

61
src/firsttimewizard.cpp

@ -3,6 +3,8 @@
#include "ui_newseed.h" #include "ui_newseed.h"
#include "ui_restoreseed.h" #include "ui_restoreseed.h"
#include "ui_newwallet.h" #include "ui_newwallet.h"
#include "mainwindow.h"
#include "DataStore/DataStore.h"
#include "../lib/silentdragonlitelib.h" #include "../lib/silentdragonlitelib.h"
@ -38,31 +40,75 @@ int FirstTimeWizard::nextId() const {
NewOrRestorePage::NewOrRestorePage(FirstTimeWizard *parent) : QWizardPage(parent) { NewOrRestorePage::NewOrRestorePage(FirstTimeWizard *parent) : QWizardPage(parent) {
setTitle("Create or Restore wallet."); setTitle("Create or Restore wallet.");
QWidget* pageWidget = new QWidget(); QWidget* pageWidget = new QWidget();
Ui_CreateWalletForm form; Ui_CreateWalletForm form;
form.setupUi(pageWidget); form.setupUi(pageWidget);
// Exclusive buttons auto fnPasswordEdited = [=](const QString&) {
// Enable the Finish button if the passwords match.
QString Password = form.txtPassword->text();
if (!form.txtPassword->text().isEmpty() &&
form.txtPassword->text() == form.txtConfirmPassword->text() && Password.size() >= 16) {
form.lblPasswordMatch->setText("");
parent->button(QWizard::CommitButton)->setEnabled(true);
setButtonText(QWizard::CommitButton, "Next");
form.radioRestoreWallet->setEnabled(true);
form.radioNewWallet->setEnabled(true);
form.radioNewWallet->setChecked(true);
qDebug()<<"PW :"<<Password;
DataStore::getChatDataStore()->setPassword(Password);
//main->setPassword(Password);
//qDebug()<<"Objekt gesetzt";
// Exclusive buttons
QObject::connect(form.radioNewWallet, &QRadioButton::clicked, [=](bool checked) { QObject::connect(form.radioNewWallet, &QRadioButton::clicked, [=](bool checked) {
if (checked) { if (checked) {
form.radioRestoreWallet->setChecked(false); form.radioRestoreWallet->setChecked(false);
} }
}); });
QObject::connect(form.radioRestoreWallet, &QRadioButton::clicked, [=](bool checked) { QObject::connect(form.radioRestoreWallet, &QRadioButton::clicked, [=](bool checked) {
if (checked) { if (checked) {
form.radioNewWallet->setChecked(false); form.radioNewWallet->setChecked(false);
} }
}); });
form.radioNewWallet->setChecked(true);
registerField("intro.new", form.radioNewWallet);
} else {
form.lblPasswordMatch->setText(tr("Passphrase don't match or You have entered too few letters (16 minimum)"));
parent->button(QWizard::CommitButton)->setEnabled(false);
form.radioRestoreWallet->setEnabled(false);
form.radioNewWallet->setEnabled(false);
}
};
QVBoxLayout *layout = new QVBoxLayout; QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(pageWidget); layout->addWidget(pageWidget);
setLayout(layout); setLayout(layout);
QObject::connect(form.txtConfirmPassword, &QLineEdit::textChanged, fnPasswordEdited);
QObject::connect(form.txtPassword, &QLineEdit::textChanged, fnPasswordEdited);
registerField("intro.new", form.radioNewWallet);
form.radioRestoreWallet->setEnabled(false);
form.radioNewWallet->setEnabled(false);
setCommitPage(true); setCommitPage(true);
setButtonText(QWizard::CommitButton, "Next");
} }
NewSeedPage::NewSeedPage(FirstTimeWizard *parent) : QWizardPage(parent) { NewSeedPage::NewSeedPage(FirstTimeWizard *parent) : QWizardPage(parent) {
@ -81,6 +127,7 @@ 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.
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);
@ -90,7 +137,11 @@ void NewSeedPage::initializePage() {
} else { } else {
QString seed = QString::fromStdString(parsed["seed"].get<json::string_t>()); QString seed = QString::fromStdString(parsed["seed"].get<json::string_t>());
form.txtSeed->setPlainText(seed); form.txtSeed->setPlainText(seed);
} }
} }
// 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
@ -175,4 +226,4 @@ bool RestoreSeedPage::validatePage() {
return true; return true;
} }
} }
} }

12
src/firsttimewizard.h

@ -5,11 +5,18 @@
#include "ui_newseed.h" #include "ui_newseed.h"
#include "ui_restoreseed.h" #include "ui_restoreseed.h"
#include "mainwindow.h"
class FirstTimeWizard: public QWizard class FirstTimeWizard: public QWizard
{ {
public: public:
FirstTimeWizard(bool dangerous, QString server); FirstTimeWizard(bool dangerous, QString server);
protected: protected:
int nextId() const; int nextId() const;
@ -27,11 +34,16 @@ private:
friend class NewOrRestorePage; friend class NewOrRestorePage;
friend class NewSeedPage; friend class NewSeedPage;
friend class RestoreSeedPage; friend class RestoreSeedPage;
}; };
class NewOrRestorePage: public QWizardPage { class NewOrRestorePage: public QWizardPage {
public: public:
NewOrRestorePage(FirstTimeWizard* parent); NewOrRestorePage(FirstTimeWizard* parent);
}; };

17
src/mainwindow.cpp

@ -31,6 +31,7 @@
#include "Crypto/passwd.h" #include "Crypto/passwd.h"
#include "Crypto/FileEncryption.h" #include "Crypto/FileEncryption.h"
#include "DataStore/DataStore.h" #include "DataStore/DataStore.h"
#include "firsttimewizard.h"
using json = nlohmann::json; using json = nlohmann::json;
@ -52,8 +53,6 @@ auto dirwalletenc = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLo
auto dirwalletbackup = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)).filePath(".silentdragonlite/silentdragonlite-wallet.datBackup"); auto dirwalletbackup = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)).filePath(".silentdragonlite/silentdragonlite-wallet.datBackup");
#endif #endif
MainWindow::MainWindow(QWidget *parent) : MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent), QMainWindow(parent),
ui(new Ui::MainWindow) ui(new Ui::MainWindow)
@ -289,10 +288,10 @@ void MainWindow::closeEvent(QCloseEvent* event) {
s.sync(); s.sync();
// Let the RPC know to shut down any running service. // Let the RPC know to shut down any running service.
rpc->shutdownhushd(); rpc->shutdownhushd();
int passphraselenght = this->getPassword().length(); int passphraselenght = DataStore::getChatDataStore()->getPassword().length();
// Check is encryption is ON for SDl // Check is encryption is ON for SDl
if(passphraselenght > 0) if(passphraselenght > 0)
@ -305,7 +304,7 @@ void MainWindow::closeEvent(QCloseEvent* event) {
fileoldencryption.remove(); fileoldencryption.remove();
// Encrypt our wallet.dat // Encrypt our wallet.dat
QString str = this->getPassword(); QString str = DataStore::getChatDataStore()->getPassword();
// QString str = ed.txtPassword->text(); // data comes from user inputs // QString str = ed.txtPassword->text(); // data comes from user inputs
int length = str.length(); int length = str.length();
@ -401,7 +400,7 @@ void MainWindow::encryptWallet() {
QString passphrase = ed.txtPassword->text(); // data comes from user inputs QString passphrase = ed.txtPassword->text(); // data comes from user inputs
int length = passphrase.length(); int length = passphrase.length();
this->setPassword(passphrase); DataStore::getChatDataStore()->setPassword(passphrase);
char *sequence = NULL; char *sequence = NULL;
sequence = new char[length+1]; sequence = new char[length+1];
@ -561,7 +560,7 @@ void MainWindow::removeWalletEncryptionStartUp() {
{ {
QString password = ed.txtPassword->text(); // data comes from user inputs QString password = ed.txtPassword->text(); // data comes from user inputs
int length = password.length(); int length = password.length();
this->setPassword(password); DataStore::getChatDataStore()->setPassword(password);
char *sequence = NULL; char *sequence = NULL;
sequence = new char[length+1]; sequence = new char[length+1];
strncpy(sequence, password.toLocal8Bit(), length +1); strncpy(sequence, password.toLocal8Bit(), length +1);
@ -663,6 +662,7 @@ void MainWindow::setupStatusBar() {
loadingMovie->start(); loadingMovie->start();
loadingLabel->setAttribute(Qt::WA_NoSystemBackground); loadingLabel->setAttribute(Qt::WA_NoSystemBackground);
loadingLabel->setMovie(loadingMovie); loadingLabel->setMovie(loadingMovie);
ui->statusBar->addPermanentWidget(loadingLabel); ui->statusBar->addPermanentWidget(loadingLabel);
loadingLabel->setVisible(false); loadingLabel->setVisible(false);
@ -1159,7 +1159,6 @@ void MainWindow::setupBalancesTab() {
ui->lblSyncWarning->setVisible(false); ui->lblSyncWarning->setVisible(false);
ui->lblSyncWarningReceive->setVisible(false); ui->lblSyncWarningReceive->setVisible(false);
// Setup context menu on balances tab // Setup context menu on balances tab
ui->balancesTable->setContextMenuPolicy(Qt::CustomContextMenu); ui->balancesTable->setContextMenuPolicy(Qt::CustomContextMenu);
QObject::connect(ui->balancesTable, &QTableView::customContextMenuRequested, [=] (QPoint pos) { QObject::connect(ui->balancesTable, &QTableView::customContextMenuRequested, [=] (QPoint pos) {
@ -1191,6 +1190,8 @@ void MainWindow::setupBalancesTab() {
menu.exec(ui->balancesTable->viewport()->mapToGlobal(pos)); menu.exec(ui->balancesTable->viewport()->mapToGlobal(pos));
}); });
qDebug()<<"PW :"<<DataStore::getChatDataStore()->getPassword();
} }
void MainWindow::setuphushdTab() { void MainWindow::setuphushdTab() {

12
src/mainwindow.h

@ -5,7 +5,7 @@
#include "logger.h" #include "logger.h"
#include "recurring.h" #include "recurring.h"
#include "firsttimewizard.h"
// Forward declare to break circular dependency. // Forward declare to break circular dependency.
class Controller; class Controller;
@ -59,6 +59,7 @@ public:
void addPubkey(QString requestZaddr, QString pubkey); void addPubkey(QString requestZaddr, QString pubkey);
void replaceWormholeClient(WormholeClient* newClient); void replaceWormholeClient(WormholeClient* newClient);
bool isWebsocketListening(); bool isWebsocketListening();
@ -67,10 +68,7 @@ public:
void saveContact(); void saveContact();
void saveandsendContact(); void saveandsendContact();
void showRequesthush(); void showRequesthush();
// void setmaxlenChat(int len);
// void updateDisplay();
void balancesReady(); void balancesReady();
void payhushURI(QString uri = "", QString myAddr = ""); void payhushURI(QString uri = "", QString myAddr = "");
@ -113,6 +111,7 @@ private:
bool fileExists(QString path); bool fileExists(QString path);
void closeEvent(QCloseEvent* event); void closeEvent(QCloseEvent* event);
void closeEventpw(QCloseEvent* event); void closeEventpw(QCloseEvent* event);
QString _password;
void setupSendTab(); void setupSendTab();
@ -122,7 +121,6 @@ private:
void setuphushdTab(); void setuphushdTab();
void setupchatTab(); void setupchatTab();
void renderContactRequest(); void renderContactRequest();
// void setLenDisplayLabel(QLabel* label);
void updateContacts(); void updateContacts();
void updateChat(); void updateChat();
@ -131,7 +129,7 @@ private:
void setupStatusBar(); void setupStatusBar();
void clearSendForm(); void clearSendForm();
QString _password;
Tx createTxFromSendPage(); Tx createTxFromSendPage();
bool confirmTx(Tx tx, RecurringPaymentInfo* rpi); bool confirmTx(Tx tx, RecurringPaymentInfo* rpi);

28
src/newseed.ui

@ -6,15 +6,15 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>400</width> <width>427</width>
<height>300</height> <height>416</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>Form</string> <string>Form</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<item row="0" column="0"> <item row="0" column="0" colspan="2">
<widget class="QLabel" name="label"> <widget class="QLabel" name="label">
<property name="text"> <property name="text">
<string>This is your new wallet's seed phrase. PLEASE BACK IT UP SECURELY.</string> <string>This is your new wallet's seed phrase. PLEASE BACK IT UP SECURELY.</string>
@ -24,17 +24,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="0"> <item row="2" column="0" colspan="2">
<widget class="QLabel" name="label_2">
<property name="text">
<string>The seed phrase is the only way to restore the wallet. If you forget the seed phrase, THERE IS NO WAY TO RESTORE YOUR WALLET AND THE FUNDS in it</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QGroupBox" name="groupBox"> <widget class="QGroupBox" name="groupBox">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding"> <sizepolicy hsizetype="Preferred" vsizetype="Expanding">
@ -56,6 +46,16 @@
</layout> </layout>
</widget> </widget>
</item> </item>
<item row="1" column="0" colspan="2">
<widget class="QLabel" name="label_2">
<property name="text">
<string>The seed phrase is the only way to restore the wallet. If you forget the seed phrase, THERE IS NO WAY TO RESTORE YOUR WALLET AND THE FUNDS in it</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
<resources/> <resources/>

87
src/newwallet.ui

@ -6,16 +6,16 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>400</width> <width>437</width>
<height>300</height> <height>381</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>Form</string> <string>Form</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<item row="1" column="0"> <item row="0" column="0" colspan="3">
<widget class="QGroupBox" name="groupBox_2"> <widget class="QGroupBox" name="groupBox">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding"> <sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch> <horstretch>0</horstretch>
@ -25,18 +25,18 @@
<property name="title"> <property name="title">
<string/> <string/>
</property> </property>
<layout class="QGridLayout" name="gridLayout_3"> <layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0"> <item row="0" column="0">
<widget class="QRadioButton" name="radioRestoreWallet"> <widget class="QRadioButton" name="radioNewWallet">
<property name="text"> <property name="text">
<string>Restore wallet from seed</string> <string>Create a new Wallet</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="0"> <item row="1" column="0">
<widget class="QLabel" name="label_3"> <widget class="QLabel" name="label_2">
<property name="text"> <property name="text">
<string>Restore an existing wallet, using the 24-word seed. </string> <string>Create a new wallet with a randomly generated seed.</string>
</property> </property>
<property name="wordWrap"> <property name="wordWrap">
<bool>true</bool> <bool>true</bool>
@ -46,8 +46,63 @@
</layout> </layout>
</widget> </widget>
</item> </item>
<item row="0" column="0"> <item row="2" column="0" colspan="3">
<widget class="QGroupBox" name="groupBox"> <widget class="Line" name="line_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QLabel" name="lblPasswordMatch">
<property name="styleSheet">
<string notr="true">color: red;</string>
</property>
<property name="text">
<string>Passphrase don't match</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QLabel" name="label_5">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;16 letters minimum&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Encryption Passphrase:</string>
</property>
</widget>
</item>
<item row="4" column="1" colspan="2">
<widget class="QLineEdit" name="txtPassword">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Confirm Passphrase:</string>
</property>
</widget>
</item>
<item row="5" column="1" colspan="2">
<widget class="QLineEdit" name="txtConfirmPassword">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
<item row="1" column="0" colspan="3">
<widget class="QGroupBox" name="groupBox_2">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding"> <sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch> <horstretch>0</horstretch>
@ -57,18 +112,18 @@
<property name="title"> <property name="title">
<string/> <string/>
</property> </property>
<layout class="QGridLayout" name="gridLayout_2"> <layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0"> <item row="0" column="0">
<widget class="QRadioButton" name="radioNewWallet"> <widget class="QRadioButton" name="radioRestoreWallet">
<property name="text"> <property name="text">
<string>Create a new Wallet</string> <string>Restore wallet from seed</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="0"> <item row="1" column="0">
<widget class="QLabel" name="label_2"> <widget class="QLabel" name="label_3">
<property name="text"> <property name="text">
<string>Create a new wallet with a randomly generated seed.</string> <string>Restore an existing wallet, using the 24-word seed. </string>
</property> </property>
<property name="wordWrap"> <property name="wordWrap">
<bool>true</bool> <bool>true</bool>

Loading…
Cancel
Save