still broken
This commit is contained in:
parent
d7464ef04b
commit
dc438a22eb
114
frame.cpp
114
frame.cpp
@ -223,56 +223,17 @@ void Frame::OnDeleteConfiguration(wxCommandEvent&)
|
||||
}
|
||||
|
||||
using ro::bin2hex, ro::to_base64_string;
|
||||
|
||||
void Frame::NewWalletNewSecret(wxCommandEvent&) {
|
||||
wxMessageBox(_T("new wallet new secret event"), _T(""));
|
||||
/* If LastUsed is the empty string, check if default filename exists. If it exists, set Last Used to default file name
|
||||
If LastUsed is not the empty string, or no longer the empty string, attempt to open indicated file. If open fails, or reading the opened file produces bad results, abort with exception
|
||||
If LastUsed is still the empty string, attempt to create default filename. If creation fails, abort with exception. If it succeeds, set LastUsed to default filename.
|
||||
The exception in unit test should simply generate an error message, but if run during initialization, should bring up the more complex UI for constructing or selecting your wallet file.*/
|
||||
ILogMessage("\tWallet file");
|
||||
/*
|
||||
bool fWalletNameOk{ false };
|
||||
wxStandardPaths& StandardPaths(wxStandardPaths::Get());
|
||||
StandardPaths.UseAppInfo(3);
|
||||
std::unique_ptr<ISqlite3> db;
|
||||
if (fWalletNameOk) {
|
||||
if (!m_LastUsedSqlite.FileExists())
|
||||
throw MyException((std::string("Expected wallet:\n") + LastUsedSqlite.GetFullPath() + "\nfile not found").c_str());
|
||||
db.reset(Sqlite3_open(m_LastUsedSqlite.GetFullPath().ToUTF8()));
|
||||
sql_read_from_misc read_from_misc(db);
|
||||
if (!read_from_misc(1) || read_from_misc.value<int64_t>() != WALLET_FILE_IDENTIFIER)
|
||||
throw MyException(sz_unrecognizable_wallet_file_format);
|
||||
if (!read_from_misc(2) || read_from_misc.value<int64_t>() != WALLET_FILE_SCHEMA_VERSION_0_0)
|
||||
throw MyException(sz_unrecognized_wallet_schema);
|
||||
if (!read_from_misc(4))
|
||||
throw MyException(sz_mastersecret_missing);
|
||||
ristretto255::CMasterSecret MasterSecret(*read_from_misc.value<ristretto255::scalar>());
|
||||
ro::sql read_keys(db, R"|(SELECT * FROM "Keys" LIMIT 5;)|");
|
||||
sql_read_name read_name(db);
|
||||
// db.reset(nullptr);// Force error of premature destruction of Isqlite3
|
||||
while (read_keys.step() == Icompiled_sql::ROW) {
|
||||
auto pubkey = read_keys.column<ristretto255::point>(0);
|
||||
auto id = read_keys.column<int>(1);
|
||||
auto use = read_keys.column<int>(2);
|
||||
if (use != 1)throw MyException(sz_unknown_secret_key_algorithm);
|
||||
if (!read_name(id)) throw MyException(sz_no_corresponding_entry);
|
||||
const char* name = read_name.name();
|
||||
if (MasterSecret(name).timesBase() != *pubkey)throw MyException(sz_name_does_not_correspond);
|
||||
wxLogMessage(_T("\t\t\"%s\" has expected public key 0x%s"), name, (wxString)bin2hex(*pubkey));
|
||||
}
|
||||
}
|
||||
else {
|
||||
// At this point in the code the filename LastUsedSqlite is a bad filename, normally the empty string, and the default wallet file does not exist in the default location.
|
||||
// Construct default wallet and filename*//*
|
||||
wxFileName path{ StandardPaths.GetUserLocalDataDir() };
|
||||
try {
|
||||
// Disk operations to create wallet, which may throw.
|
||||
// This try/catch block exists to catch disk io issues.
|
||||
if (!path.DirExists())path.Mkdir();
|
||||
if (!DefaultSqlite.DirExists())DefaultSqlite.Mkdir();
|
||||
db.reset(Sqlite3_create(DefaultSqlite.GetFullPath().ToUTF8()));
|
||||
db->exec(R"|(
|
||||
void Frame::NewWallet(wxFileName& filename, ristretto255::hash<256>& secret) {
|
||||
/*If creation fails, abort with exception. If it succeeds, set LastUsed to default filename.
|
||||
The exception in unit test should simply generate an error message, but if run during initialization,
|
||||
should bring up the more complex UI for constructing or selecting your wallet file.*/
|
||||
wxLogMessage(_wx("New wallet file %s"), filename.GetFullPath());
|
||||
std::unique_ptr<ISqlite3> db{ nullptr };
|
||||
try {
|
||||
// Disk operations to create wallet, which may throw.
|
||||
// This try/catch block exists to catch disk io issues.
|
||||
db.reset(Sqlite3_create(filename.GetFullPath().ToUTF8()));
|
||||
db->exec(R"|(
|
||||
PRAGMA journal_mode = WAL;
|
||||
PRAGMA synchronous = 1;
|
||||
BEGIN TRANSACTION;
|
||||
@ -290,34 +251,29 @@ CREATE TABLE "Misc"(
|
||||
"m" BLOB
|
||||
);
|
||||
COMMIT;)|");
|
||||
LastUsedSqlite = DefaultSqlite;
|
||||
singletonApp->pConfig->Write(_T("LastUsed"), DefaultSqlite.GetFullPath());
|
||||
wxLogMessage("\t\tConstructing default wallet %s", DefaultSqlite.GetFullPath());
|
||||
// We now have a working wallet file with no valid data. Attempting to create a strong random secret, a name, and public and private keys for that name.
|
||||
|
||||
wxLogMessage("\t\tGenerating random 128 bit wallet secret");
|
||||
auto text_secret{ DeriveTextSecret(ristretto255::scalar::random(), 1) };
|
||||
ro::msec start_time{ ro::msec_since_epoch() };
|
||||
ristretto255::CMasterSecret MasterSecret(DeriveStrongSecret(&text_secret[0]));
|
||||
decltype(start_time) end_time{ ro::msec_since_epoch() };
|
||||
wxLogMessage("\t\tStrong secret derivation took %d milliseconds", (end_time - start_time).count());
|
||||
sql_update_to_misc update_to_misc(db);
|
||||
update_to_misc(1, WALLET_FILE_IDENTIFIER);
|
||||
update_to_misc(2, WALLET_FILE_SCHEMA_VERSION_0_0);
|
||||
update_to_misc(3, &text_secret[0]);
|
||||
update_to_misc(4, MasterSecret);
|
||||
sql_insert_name insert_name(db);
|
||||
const char* const cpsz("Unit Tester");
|
||||
insert_name(cpsz, MasterSecret(cpsz).timesBase());
|
||||
}
|
||||
catch (const MyException& e) {
|
||||
ILogError(R"|(Failed to create or failed to properly initialize wallet)|");
|
||||
errorCode = 20;
|
||||
szError = e.what();
|
||||
ILogError(szError.c_str());
|
||||
}
|
||||
} // End of wallet creation branch*/
|
||||
|
||||
wxLogMessage("\t\tConstructing default wallet %s", filename.GetFullPath());
|
||||
// We now have a working wallet file with no valid data. Attempting to create a strong random secret, a name, and public and private keys for that name.
|
||||
wxLogMessage("\t\tGenerating random 128 bit wallet secret");
|
||||
auto text_secret{ DeriveTextSecret(ristretto255::scalar::random(), 1) };
|
||||
ro::msec start_time{ ro::msec_since_epoch() };
|
||||
ristretto255::CMasterSecret MasterSecret(DeriveStrongSecret(&text_secret[0]));
|
||||
decltype(start_time) end_time{ ro::msec_since_epoch() };
|
||||
wxLogMessage("\t\tStrong secret derivation took %d milliseconds", (end_time - start_time).count());
|
||||
sql_update_to_misc update_to_misc(db);
|
||||
update_to_misc(1, WALLET_FILE_IDENTIFIER);
|
||||
update_to_misc(2, WALLET_FILE_SCHEMA_VERSION_0_0);
|
||||
update_to_misc(3, &text_secret[0]);
|
||||
update_to_misc(4, MasterSecret);
|
||||
sql_insert_name insert_name(db);
|
||||
const char* const cpsz("fred");
|
||||
insert_name(cpsz, MasterSecret(cpsz).timesBase());
|
||||
}
|
||||
catch (const MyException& e) {
|
||||
ILogError(R"|(Failed to create or failed to properly initialize wallet)|");
|
||||
errorCode = 20;
|
||||
szError = e.what();
|
||||
ILogError(szError.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -339,7 +295,7 @@ void Frame::OnSaveNew(wxCommandEvent& WXUNUSED(event))
|
||||
}
|
||||
auto wallet{ dialog.GetDirectory() + "/" + dialog.GetFilename() };
|
||||
wxLogMessage("new wallet created: %s", wallet);
|
||||
wxConfigBase::Get()->Write("Wallet", wallet);
|
||||
// wxConfigBase::Get()->Write("Wallet", wallet);
|
||||
}
|
||||
|
||||
void Frame::OnFileOpen(wxCommandEvent&) {
|
||||
|
Loading…
Reference in New Issue
Block a user