use blake3 to hash the passphrase
This commit is contained in:
@@ -13,6 +13,7 @@ extern char * litelib_initialize_new_from_phrase
|
|||||||
extern char * litelib_initialize_existing (bool dangerous, const char* server);
|
extern char * litelib_initialize_existing (bool dangerous, const char* server);
|
||||||
extern char * litelib_execute (const char* s, const char* args);
|
extern char * litelib_execute (const char* s, const char* args);
|
||||||
extern void litelib_rust_free_string (char* s);
|
extern void litelib_rust_free_string (char* s);
|
||||||
|
extern char * blake3_PW (char* pw);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,30 @@ pub extern fn litelib_wallet_exists(chain_name: *const c_char) -> bool {
|
|||||||
|
|
||||||
println!("Wallet exists: {}", config.wallet_exists());
|
println!("Wallet exists: {}", config.wallet_exists());
|
||||||
config.wallet_exists()
|
config.wallet_exists()
|
||||||
|
}
|
||||||
|
|
||||||
|
//////hash blake3
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern fn blake3_PW(pw: *const c_char) -> *mut c_char{
|
||||||
|
|
||||||
|
let passwd = unsafe {
|
||||||
|
assert!(!pw.is_null());
|
||||||
|
|
||||||
|
CStr::from_ptr(pw).to_string_lossy().into_owned()
|
||||||
|
};
|
||||||
|
|
||||||
|
let data = passwd.as_bytes();
|
||||||
|
// Hash an input all at once.
|
||||||
|
let hash1 = blake3::hash(data).to_hex();
|
||||||
|
println!("\nBlake3 Hash: {}", hash1);
|
||||||
|
|
||||||
|
//let sttring = CString::new(hash1).unwrap();
|
||||||
|
let e_str = CString::new(format!("{}", hash1)).unwrap();
|
||||||
|
return e_str.into_raw();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new wallet and return the seed for the newly created wallet.
|
/// Create a new wallet and return the seed for the newly created wallet.
|
||||||
|
|||||||
@@ -16,6 +16,18 @@ FirstTimeWizard::FirstTimeWizard(bool dangerous, QString server)
|
|||||||
this->dangerous = dangerous;
|
this->dangerous = dangerous;
|
||||||
this->server = server;
|
this->server = server;
|
||||||
|
|
||||||
|
////backup addresslabels.dat if there is one, to restore it later
|
||||||
|
|
||||||
|
auto dir = QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation));
|
||||||
|
QString addressbook = dir.filePath("addresslabels.dat.enc");
|
||||||
|
QFile file(addressbook);
|
||||||
|
|
||||||
|
if (file.exists())
|
||||||
|
{
|
||||||
|
file.rename(dir.filePath("addresslabels.dat.enc-backup"));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// Create the pages
|
// Create the pages
|
||||||
setPage(Page_NewOrRestore, new NewOrRestorePage(this));
|
setPage(Page_NewOrRestore, new NewOrRestorePage(this));
|
||||||
setPage(Page_New, new NewSeedPage(this));
|
setPage(Page_New, new NewSeedPage(this));
|
||||||
@@ -60,9 +72,18 @@ NewOrRestorePage::NewOrRestorePage(FirstTimeWizard *parent) : QWizardPage(parent
|
|||||||
form.radioRestoreWallet->setEnabled(true);
|
form.radioRestoreWallet->setEnabled(true);
|
||||||
form.radioNewWallet->setEnabled(true);
|
form.radioNewWallet->setEnabled(true);
|
||||||
form.radioNewWallet->setChecked(true);
|
form.radioNewWallet->setChecked(true);
|
||||||
|
int length = Password.length();
|
||||||
|
char *sequence = NULL;
|
||||||
|
sequence = new char[length+1];
|
||||||
|
strncpy(sequence, Password.toUtf8(), length +1);
|
||||||
|
|
||||||
|
QString str = blake3_PW(sequence);
|
||||||
|
qDebug() << str;
|
||||||
|
DataStore::getChatDataStore()->setPassword(str);
|
||||||
|
|
||||||
DataStore::getChatDataStore()->setPassword(Password);
|
char *sequence1 = NULL;
|
||||||
|
sequence1 = new char[length];
|
||||||
|
strncpy(sequence1, str.toUtf8(), length);
|
||||||
//main->setPassword(Password);
|
//main->setPassword(Password);
|
||||||
|
|
||||||
//qDebug()<<"Objekt gesetzt";
|
//qDebug()<<"Objekt gesetzt";
|
||||||
|
|||||||
@@ -33,6 +33,7 @@
|
|||||||
#include "Crypto/FileEncryption.h"
|
#include "Crypto/FileEncryption.h"
|
||||||
#include "DataStore/DataStore.h"
|
#include "DataStore/DataStore.h"
|
||||||
#include "firsttimewizard.h"
|
#include "firsttimewizard.h"
|
||||||
|
#include "../lib/silentdragonlitelib.h"
|
||||||
|
|
||||||
using json = nlohmann::json;
|
using json = nlohmann::json;
|
||||||
|
|
||||||
@@ -305,53 +306,28 @@ void MainWindow::closeEvent(QCloseEvent* event) {
|
|||||||
fileoldencryption.remove();
|
fileoldencryption.remove();
|
||||||
|
|
||||||
// Encrypt our wallet.dat
|
// Encrypt our wallet.dat
|
||||||
QString str = DataStore::getChatDataStore()->getPassword();
|
QString passphraseHash = DataStore::getChatDataStore()->getPassword();
|
||||||
// QString str = ed.txtPassword->text(); // data comes from user inputs
|
int length = passphraseHash.length();
|
||||||
int length = str.length();
|
|
||||||
|
|
||||||
char *sequence = NULL;
|
char *sequence1 = NULL;
|
||||||
sequence = new char[length+1];
|
sequence1 = new char[length+1];
|
||||||
strncpy(sequence, str.toLocal8Bit(), length +1);
|
strncpy(sequence1, passphraseHash.toUtf8(), length+1);
|
||||||
|
|
||||||
#define MESSAGE ((const unsigned char *) sequence)
|
#define PassphraseHashEnd ((const unsigned char *) sequence1)
|
||||||
#define MESSAGE_LEN length
|
#define MESSAGE_LEN length
|
||||||
|
|
||||||
unsigned char hash[crypto_secretstream_xchacha20poly1305_KEYBYTES];
|
#define PASSWORD sequence
|
||||||
|
#define KEY_LEN crypto_box_SEEDBYTES
|
||||||
crypto_hash_sha256(hash,MESSAGE, MESSAGE_LEN);
|
|
||||||
|
|
||||||
#define PASSWORD sequence
|
|
||||||
#define KEY_LEN crypto_box_SEEDBYTES
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/////////we use the Hash of the Password as Salt, not perfect but still a good solution.
|
|
||||||
|
|
||||||
unsigned char key[KEY_LEN];
|
|
||||||
|
|
||||||
if (crypto_pwhash
|
|
||||||
(key, sizeof key, PASSWORD, strlen(PASSWORD), hash,
|
|
||||||
crypto_pwhash_OPSLIMIT_SENSITIVE, crypto_pwhash_MEMLIMIT_SENSITIVE,
|
|
||||||
crypto_pwhash_ALG_DEFAULT) != 0) {
|
|
||||||
/* out of memory */
|
|
||||||
}
|
|
||||||
|
|
||||||
auto dir = QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation));
|
auto dir = QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation));
|
||||||
// auto dirHome = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation));
|
|
||||||
QString source_file = dir.filePath("addresslabels.dat");
|
|
||||||
QString target_enc_file = dir.filePath("addresslabels.dat.enc");
|
|
||||||
QString sourceWallet_file = dirwallet;
|
QString sourceWallet_file = dirwallet;
|
||||||
QString target_encWallet_file = dirwalletenc;
|
QString target_encWallet_file = dirwalletenc;
|
||||||
|
|
||||||
FileEncryption::encrypt(target_enc_file, source_file, key);
|
// FileEncryption::encrypt(target_enc_file, source_file, key);
|
||||||
FileEncryption::encrypt(target_encWallet_file, sourceWallet_file, key);
|
FileEncryption::encrypt(target_encWallet_file, sourceWallet_file, PassphraseHashEnd);
|
||||||
|
|
||||||
///////////////// we rename the plaintext wallet.dat to Backup, for testing.
|
|
||||||
|
|
||||||
QFile wallet(dirwallet);
|
QFile wallet(dirwallet);
|
||||||
QFile address(dir.filePath("addresslabels.dat"));
|
|
||||||
wallet.remove();
|
wallet.remove();
|
||||||
address.remove();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -401,49 +377,34 @@ 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();
|
||||||
DataStore::getChatDataStore()->setPassword(passphrase);
|
|
||||||
|
|
||||||
char *sequence = NULL;
|
|
||||||
sequence = new char[length+1];
|
|
||||||
strncpy(sequence, passphrase.toLocal8Bit(), length +1);
|
|
||||||
|
|
||||||
#define MESSAGE ((const unsigned char *) sequence)
|
|
||||||
#define MESSAGE_LEN length
|
|
||||||
|
|
||||||
unsigned char hash[crypto_secretstream_xchacha20poly1305_KEYBYTES];
|
|
||||||
|
|
||||||
crypto_hash_sha256(hash,MESSAGE, MESSAGE_LEN);
|
|
||||||
|
|
||||||
#define PASSWORD sequence
|
|
||||||
#define KEY_LEN crypto_box_SEEDBYTES
|
|
||||||
|
|
||||||
|
|
||||||
|
char *sequence = NULL;
|
||||||
|
sequence = new char[length+1];
|
||||||
|
strncpy(sequence, passphrase.toUtf8(), length +1);
|
||||||
|
|
||||||
/////////we use the Hash of the Password as Salt, not perfect but still a good solution.
|
QString passphraseHash = blake3_PW(sequence);
|
||||||
|
DataStore::getChatDataStore()->setPassword(passphraseHash);
|
||||||
|
|
||||||
unsigned char key[KEY_LEN];
|
char *sequence1 = NULL;
|
||||||
|
sequence1 = new char[length+1];
|
||||||
|
strncpy(sequence1, passphraseHash.toUtf8(), length+1);
|
||||||
|
|
||||||
if (crypto_pwhash
|
#define MESSAGE1 ((const unsigned char *) sequence1)
|
||||||
(key, sizeof key, PASSWORD, strlen(PASSWORD), hash,
|
#define MESSAGE_LEN length
|
||||||
crypto_pwhash_OPSLIMIT_SENSITIVE, crypto_pwhash_MEMLIMIT_SENSITIVE,
|
|
||||||
crypto_pwhash_ALG_DEFAULT) != 0) {
|
#define PASSWORD sequence
|
||||||
/* out of memory */
|
#define KEY_LEN crypto_box_SEEDBYTES
|
||||||
}
|
|
||||||
|
|
||||||
auto dir = QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation));
|
auto dir = QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation));
|
||||||
auto dirHome = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation));
|
auto dirHome = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation));
|
||||||
QString source_file = dir.filePath("addresslabels.dat");
|
|
||||||
QString target_enc_file = dir.filePath("addresslabels.dat.enc");
|
|
||||||
QString sourceWallet_file = dirwallet;
|
QString sourceWallet_file = dirwallet;
|
||||||
QString target_encWallet_file = dirwalletenc;
|
QString target_encWallet_file = dirwalletenc;
|
||||||
|
|
||||||
FileEncryption::encrypt(target_enc_file, source_file, key);
|
FileEncryption::encrypt(target_encWallet_file, sourceWallet_file, MESSAGE1);
|
||||||
FileEncryption::encrypt(target_encWallet_file, sourceWallet_file, key);
|
|
||||||
|
|
||||||
QFile wallet(dirwallet);
|
QFile wallet(dirwallet);
|
||||||
QFile address(dir.filePath("addresslabels.dat"));
|
|
||||||
wallet.rename(dirwalletbackup);
|
wallet.rename(dirwalletbackup);
|
||||||
address.rename(dir.filePath("addresslabels.datBackup"));
|
|
||||||
|
|
||||||
QMessageBox::information(this, tr("Wallet Encryption Success"),
|
QMessageBox::information(this, tr("Wallet Encryption Success"),
|
||||||
QString("Successfully encrypted your wallet"),
|
QString("Successfully encrypted your wallet"),
|
||||||
@@ -484,47 +445,34 @@ void MainWindow::removeWalletEncryption() {
|
|||||||
|
|
||||||
if (d.exec() == QDialog::Accepted)
|
if (d.exec() == QDialog::Accepted)
|
||||||
{
|
{
|
||||||
QString str = ed.txtPassword->text(); // data comes from user inputs
|
QString passphrase = ed.txtPassword->text(); // data comes from user inputs
|
||||||
int length = str.length();
|
int length = passphrase.length();
|
||||||
|
|
||||||
char *sequence = NULL;
|
char *sequence = NULL;
|
||||||
sequence = new char[length+1];
|
sequence = new char[length+1];
|
||||||
strncpy(sequence, str.toLocal8Bit(), length +1);
|
strncpy(sequence, passphrase.toUtf8(), length +1);
|
||||||
|
|
||||||
#define MESSAGE ((const unsigned char *) sequence)
|
QString passphraseHash = blake3_PW(sequence);
|
||||||
#define MESSAGE_LEN length
|
|
||||||
|
|
||||||
unsigned char hash[crypto_secretstream_xchacha20poly1305_KEYBYTES];
|
char *sequence1 = NULL;
|
||||||
|
sequence1 = new char[length+1];
|
||||||
|
strncpy(sequence1, passphraseHash.toUtf8(), length+1);
|
||||||
|
|
||||||
|
#define MESSAGE3 ((const unsigned char *) sequence1)
|
||||||
|
#define MESSAGE3_LEN length
|
||||||
|
|
||||||
crypto_hash_sha256(hash,MESSAGE, MESSAGE_LEN);
|
|
||||||
|
|
||||||
#define PASSWORD sequence
|
#define PASSWORD sequence
|
||||||
#define KEY_LEN crypto_box_SEEDBYTES
|
#define KEY_LEN crypto_box_SEEDBYTES
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/////////we use the Hash of the Password as Salt, not perfect but still a good solution.
|
|
||||||
|
|
||||||
unsigned char key[KEY_LEN];
|
|
||||||
|
|
||||||
if (crypto_pwhash
|
|
||||||
(key, sizeof key, PASSWORD, strlen(PASSWORD), hash,
|
|
||||||
crypto_pwhash_OPSLIMIT_SENSITIVE, crypto_pwhash_MEMLIMIT_SENSITIVE,
|
|
||||||
crypto_pwhash_ALG_DEFAULT) != 0) {
|
|
||||||
/* out of memory */
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
auto dir = QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation));
|
auto dir = QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation));
|
||||||
auto dirHome = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation));
|
auto dirHome = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation));
|
||||||
QString target_encwallet_file = dirwalletenc;
|
QString target_encwallet_file = dirwalletenc;
|
||||||
QString target_decwallet_file = dirwallet;
|
QString target_decwallet_file = dirwallet;
|
||||||
QString target_encaddr_file = dir.filePath("addresslabels.dat.enc");
|
|
||||||
QString target_decaddr_file = dir.filePath("addresslabels.dat");
|
|
||||||
|
|
||||||
FileEncryption::decrypt(target_decwallet_file, target_encwallet_file, key);
|
FileEncryption::decrypt(target_decwallet_file, target_encwallet_file, MESSAGE3);
|
||||||
FileEncryption::decrypt(target_decaddr_file, target_encaddr_file, key);
|
|
||||||
|
|
||||||
QFile filencrypted(dirwalletenc);
|
QFile filencrypted(dirwalletenc);
|
||||||
QFile wallet(dirwallet);
|
QFile wallet(dirwallet);
|
||||||
@@ -559,53 +507,39 @@ void MainWindow::removeWalletEncryptionStartUp() {
|
|||||||
|
|
||||||
if (d.exec() == QDialog::Accepted)
|
if (d.exec() == QDialog::Accepted)
|
||||||
{
|
{
|
||||||
QString password = ed.txtPassword->text(); // data comes from user inputs
|
QString passphrase = ed.txtPassword->text(); // data comes from user inputs
|
||||||
int length = password.length();
|
int length = passphrase.length();
|
||||||
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, passphrase.toUtf8(), length +1);
|
||||||
|
|
||||||
|
QString passphraseHash = blake3_PW(sequence);
|
||||||
|
DataStore::getChatDataStore()->setPassword(passphraseHash);
|
||||||
|
|
||||||
|
char *sequence1 = NULL;
|
||||||
|
sequence1 = new char[length+1];
|
||||||
|
strncpy(sequence1, passphraseHash.toUtf8(), length+1);
|
||||||
|
|
||||||
#define MESSAGE ((const unsigned char *) sequence)
|
#define MESSAGE ((const unsigned char *) sequence)
|
||||||
#define MESSAGE_LEN length
|
#define MESSAGE_LEN length
|
||||||
|
#define hash ((const unsigned char *) sequence1)
|
||||||
unsigned char hash[crypto_secretstream_xchacha20poly1305_KEYBYTES];
|
|
||||||
|
|
||||||
crypto_hash_sha256(hash,MESSAGE, MESSAGE_LEN);
|
|
||||||
|
|
||||||
#define PASSWORD sequence
|
#define PASSWORD sequence
|
||||||
#define KEY_LEN crypto_box_SEEDBYTES
|
#define KEY_LEN crypto_box_SEEDBYTES
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/////////we use the Hash of the Password as Salt, not perfect but still a good solution.
|
|
||||||
|
|
||||||
unsigned char key[KEY_LEN];
|
|
||||||
|
|
||||||
if (crypto_pwhash
|
|
||||||
(key, sizeof key, PASSWORD, strlen(PASSWORD), hash,
|
|
||||||
crypto_pwhash_OPSLIMIT_SENSITIVE, crypto_pwhash_MEMLIMIT_SENSITIVE,
|
|
||||||
crypto_pwhash_ALG_DEFAULT) != 0) {
|
|
||||||
/* out of memory */
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
auto dir = QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation));
|
auto dir = QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation));
|
||||||
auto dirHome = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation));
|
auto dirHome = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation));
|
||||||
QString target_encwallet_file = dirwalletenc;
|
QString target_encwallet_file = dirwalletenc;
|
||||||
QString target_decwallet_file = dirwallet;
|
QString target_decwallet_file = dirwallet;
|
||||||
QString target_encaddr_file = dir.filePath("addresslabels.dat.enc");
|
|
||||||
QString target_decaddr_file = dir.filePath("addresslabels.dat");
|
|
||||||
|
|
||||||
FileEncryption::decrypt(target_decwallet_file, target_encwallet_file, key);
|
FileEncryption::decrypt(target_decwallet_file, target_encwallet_file, hash);
|
||||||
FileEncryption::decrypt(target_decaddr_file, target_encaddr_file, key);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto dirHome = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation));
|
auto dirHome = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation));
|
||||||
QFile wallet(dirwallet);
|
QFile wallet(dirwallet);
|
||||||
//QFile backup(dirHome.filePath(".silentdragonlite/silentdragonlite-wallet.datBACKUP"));*/
|
|
||||||
|
|
||||||
if (wallet.size() > 0)
|
if (wallet.size() > 0)
|
||||||
{
|
{
|
||||||
@@ -1169,7 +1103,7 @@ void MainWindow::setupBalancesTab() {
|
|||||||
QList<QString> allAddresses;
|
QList<QString> allAddresses;
|
||||||
|
|
||||||
allAddresses = getRPC()->getModel()->getAllZAddresses();
|
allAddresses = getRPC()->getModel()->getAllZAddresses();
|
||||||
QString depositzaddr = allAddresses[1];
|
QString depositzaddr = allAddresses[0];
|
||||||
deposithush.qrcodeDisplayDeposit->setQrcodeString(depositzaddr);
|
deposithush.qrcodeDisplayDeposit->setQrcodeString(depositzaddr);
|
||||||
deposithush.zaddr->setText(depositzaddr);
|
deposithush.zaddr->setText(depositzaddr);
|
||||||
|
|
||||||
@@ -1344,6 +1278,8 @@ void MainWindow::setupTransactionsTab() {
|
|||||||
|
|
||||||
void MainWindow::setupchatTab() {
|
void MainWindow::setupchatTab() {
|
||||||
|
|
||||||
|
ui->memoTxtChat->setEnabled(false);
|
||||||
|
|
||||||
/////////////Setting Icons for Chattab and different themes
|
/////////////Setting Icons for Chattab and different themes
|
||||||
|
|
||||||
auto theme = Settings::getInstance()->get_theme_name();
|
auto theme = Settings::getInstance()->get_theme_name();
|
||||||
@@ -1530,6 +1466,7 @@ void MainWindow::setupchatTab() {
|
|||||||
ui->listContactWidget->addAction(HushAction);
|
ui->listContactWidget->addAction(HushAction);
|
||||||
ui->listContactWidget->addAction(requestHushAction);
|
ui->listContactWidget->addAction(requestHushAction);
|
||||||
ui->listContactWidget->addAction(subatomicAction);
|
ui->listContactWidget->addAction(subatomicAction);
|
||||||
|
ui->memoTxtChat->setEnabled(true);
|
||||||
|
|
||||||
/*QObject::connect(requestHushAction, &QAction::triggered, [=]() {
|
/*QObject::connect(requestHushAction, &QAction::triggered, [=]() {
|
||||||
QModelIndex index = ui->listContactWidget->currentIndex();
|
QModelIndex index = ui->listContactWidget->currentIndex();
|
||||||
|
|||||||
Reference in New Issue
Block a user