Skip to content

Commit

Permalink
utils: added getpass
Browse files Browse the repository at this point in the history
spvnode: added getpass, clear and free for passphrase and error handling
such: added getpass, clear and free for passphrase
doc: updated passphrase in tools.md
seal: removed getpass
wallet: updated init exits to returns for error handling
  • Loading branch information
edtubbs committed Nov 21, 2023
1 parent 5a924bc commit 9558545
Show file tree
Hide file tree
Showing 7 changed files with 174 additions and 112 deletions.
20 changes: 10 additions & 10 deletions doc/tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Most of these commands require a flag following them to denote things like exist
| -m, --derived_path | derived_path | yes | derive_child_key -p <extended_private_key> -m <derived_path> |
| -e, --entropy | hex_entropy | yes | generate_mnemonic -e <hex_entropy> |
| -n, --mnemonic | seed_phrase | yes | mnemonic_to_key or mnemonic_to_addresses -n <seed_phrase> |
| -a, --pass_phrase | pass_phrase | yes | mnemonic_to_key or mnemonic_to_addresses -n <seed_phrase> -a <pass_phrase> |
| -a, --pass_phrase | pass_phrase | no | mnemonic_to_key or mnemonic_to_addresses -n <seed_phrase> -a |
| -o, --account_int | account_int | yes | mnemonic_to_key or mnemonic_to_addresses -n <seed_phrase> -o <account_int> |
| -g, --change_level | change_level | yes | mnemonic_to_key or mnemonic_to_addresses -n <seed_phrase> -g <change_level> |
| -i, --address_index | address_index | yes | mnemonic_to_key or mnemonic_to_addresses -n <seed_phrase> -i <address_index> |
Expand Down Expand Up @@ -277,13 +277,13 @@ To utilize checkpoints for faster initial sync, apply the -p flag:
| `-m`, `--maxnodes` | Max Peers | No | Set max peers: `./spvnode -m 8 scan` |
| `-a`, `--address` | Address | Yes | Use address: `./spvnode -a "your address here" scan` |
| `-n`, `--mnemonic` | Mnemonic Seed | Yes | Use BIP39 mnemonic: `./spvnode -n "your mnemonic here" scan` |
| `-s`, `--pass_phrase` | Passphrase | Yes | Passphrase for BIP39 seed: `./spvnode -s "your passphrase" scan` |
| `-f`, `--dbfile` | Database File | No | Headers DB file: `./spvnode -f ..db scan` |
| `-s`, `--pass_phrase` | Passphrase | No | Passphrase for BIP39 seed: `./spvnode -s scan` |
| `-f`, `--dbfile` | Database File | No | Headers DB file/mem-only (0): `./spvnode -f 0 scan` |
| `-c`, `--continuous` | Continuous Mode | No | Run continuously: `./spvnode -c scan` |
| `-b`, `--full_sync` | Full Sync | No | Perform a full sync: `./spvnode -b scan` |
| `-p`, `--checkpoint` | Checkpoint | No | Enable checkpoint sync: `./spvnode -p scan` |
| `-w`, `--wallet_file` | Wallet File | Yes | Specify wallet file: `./spvnode -w "./wallet.db" scan` |
| `-h`, `--headers_file` | Headers File | Yes | Specify headers DB file: `./spvnode -h "..db" scan` |
| `-h`, `--headers_file` | Headers File | Yes | Specify headers DB file: `./spvnode -h "./headers.db" scan` |
| `-y`, `--encrypted_file` | Encrypted File | Yes | Use encrypted file: `./spvnode -y 0 scan` |
| `-j`, `--use_tpm` | Use TPM | No | Utilize TPM for decryption: `./spvnode -j scan` |
| `-k`, `--master_key` | Master Key | No | Use master key decryption: `./spvnode -k scan` |
Expand Down Expand Up @@ -334,20 +334,20 @@ When using -n with a mnemonic, instead of main_wallet.db, spvnode will generate
#### Sync up, with encrypted mnemonic 0, show debug info, don't store headers in file, wait for new blocks:
./spvnode -d -f 0 -c -y 0 -b scan

#### Sync up, with encrypted mnemonic 0, pass phrase "test", show debug info, don't store headers in file, wait for new blocks:
./spvnode -d -f 0 -c -y 0 -s "test" -b scan
#### Sync up, with encrypted mnemonic 0, BIP39 passphrase, show debug info, don't store headers in file, wait for new blocks:
./spvnode -d -f 0 -c -y 0 -s -b scan

#### Sync up, with encrypted mnemonic 0, pass phrase "test", show debug info, don't store headers in file, wait for new blocks, use TPM:
./spvnode -d -f 0 -c -y 0 -s "test" -j -b scan
#### Sync up, with encrypted mnemonic 0, BIP39 passphrase, show debug info, don't store headers in file, wait for new blocks, use TPM:
./spvnode -d -f 0 -c -y 0 -s -j -b scan

#### Sync up, with encrypted key 0, show debug info, don't store headers in file, wait for new blocks, use master key:
./spvnode -d -f 0 -c -y 0 -k -b scan

#### Sync up, with encrypted key 0, show debug info, don't store headers in file, wait for new blocks, use master key, use TPM:
./spvnode -d -f 0 -c -y 0 -k -j -b scan

#### Sync up, with mnemonic "test", pass phrase "test", show debug info, don't store headers in file, wait for new blocks:
./spvnode -d -f 0 -c -n "test" -s "test" -b scan
#### Sync up, with mnemonic "test", BIP39 passphrase, show debug info, don't store headers in file, wait for new blocks:
./spvnode -d -f 0 -c -n "test" -s -b scan

#### Sync up, with a wallet file "main_wallet.db", with encrypted mnemonic 0, show debug info, don't store headers in file, wait for new blocks:
./spvnode -d -f 0 -c -w "./main_wallet.db" -y 0 -b scan
Expand Down
4 changes: 3 additions & 1 deletion include/dogecoin/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

#define TO_UINT8_HEX_BUF_LEN 2048
#define VARINT_LEN 20
#define MAX_LEN 128

#define BEGIN(a) ((char*)&(a))
#define END(a) ((char*)&((&(a))[1]))
Expand Down Expand Up @@ -82,6 +83,7 @@ LIBDOGECOIN_API char* concat(char* prefix, char* suffix);
LIBDOGECOIN_API void slice(const char *str, char *result, size_t start, size_t end);
LIBDOGECOIN_API void text_to_hex(char* in, char* out);
LIBDOGECOIN_API const char* get_build();
LIBDOGECOIN_API char* getpass(const char *prompt);
LIBDOGECOIN_API void dogecoin_str_reverse(char s[]);
LIBDOGECOIN_API void dogecoin_uitoa(int n, char s[]);
LIBDOGECOIN_API bool dogecoin_network_enabled();
Expand Down Expand Up @@ -115,7 +117,7 @@ static inline void dogecoin_btree_tdestroy(void *root, void (*freekey)(void *))
if (freekey) goto end;
if (r->left && !freekey) dogecoin_btree_tdestroy(r->left, freekey);
if (r->right && !freekey) dogecoin_btree_tdestroy(r->right, freekey);

end:
if (freekey) freekey(r->key);
dogecoin_free(r);
Expand Down
36 changes: 25 additions & 11 deletions src/cli/spvnode.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ static struct option long_options[] = {
{"debug", no_argument, NULL, 'd'},
{"maxnodes", no_argument, NULL, 'm'},
{"mnemonic", no_argument, NULL, 'n'},
{"pass_phrase", required_argument, NULL, 's'},
{"pass_phrase", no_argument, NULL, 's'},
{"dbfile", no_argument, NULL, 'f'},
{"continuous", no_argument, NULL, 'c'},
{"address", no_argument, NULL, 'a'},
Expand All @@ -198,9 +198,9 @@ static void print_version() {
static void print_usage() {
print_version();
printf("Usage: spvnode (-c|continuous) (-i|-ips <ip,ip,...]>) (-m[--maxpeers] <int>) (-f <headersfile|0 for in mem only>) \
(-a[--address] <address>) (-n|-mnemonic <seed_phrase>) (-s|-pass_phrase <pass_phrase>) (-y|-encrypted_file <file_num 0-999>) \
(-a[--address] <address>) (-n|-mnemonic <seed_phrase>) (-s|-pass_phrase) (-y|-encrypted_file <file_num 0-999>) \
(-w|-wallet_file <filename>) (-h|-headers_file <filename>) (-b[--full_sync]) (-p[--checkpoint]) (-k[--master_key] (-j[--use_tpm]) \
(-t[--testnet]) (-r[--regtest]) (-d[--debug]) (-s[--timeout] <secs>) <command>\n");
(-t[--testnet]) (-r[--regtest]) (-d[--debug]) <command>\n");
printf("Supported commands:\n");
printf(" scan (scan blocks up to the tip, creates header.db file)\n");
printf("\nExamples: \n");
Expand All @@ -220,16 +220,16 @@ static void print_usage() {
printf("> ./spvnode -d -c -a \"DSVw8wkkTXccdq78etZ3UwELrmpfvAiVt1\" -w \"./main_wallet.db\" -h \"./main_headers.db\" -b scan\n\n");
printf("Sync up, with encrypted mnemonic 0, show debug info, don't store headers in file, wait for new blocks:\n");
printf("> ./spvnode -d -f 0 -c -y 0 -b scan\n\n");
printf("Sync up, with encrypted mnemonic 0, pass phrase \"test\", show debug info, don't store headers in file, wait for new blocks:\n");
printf("> ./spvnode -d -f 0 -c -y 0 -s \"test\" -b scan\n\n");
printf("Sync up, with encrypted mnemonic 0, pass phrase \"test\", show debug info, don't store headers in file, wait for new blocks, use TPM:\n");
printf("> ./spvnode -d -f 0 -c -y 0 -s \"test\" -j -b scan\n\n");
printf("Sync up, with encrypted mnemonic 0, BIP39 passphrase, show debug info, don't store headers in file, wait for new blocks:\n");
printf("> ./spvnode -d -f 0 -c -y 0 -s -b scan\n\n");
printf("Sync up, with encrypted mnemonic 0, BIP39 passphrase, show debug info, don't store headers in file, wait for new blocks, use TPM:\n");
printf("> ./spvnode -d -f 0 -c -y 0 -s -j -b scan\n\n");
printf("Sync up, with encrypted key 0, show debug info, don't store headers in file, wait for new blocks, use master key:\n");
printf("> ./spvnode -d -f 0 -c -y 0 -k -b scan\n\n");
printf("Sync up, with encrypted key 0, show debug info, don't store headers in file, wait for new blocks, use master key, use TPM:\n");
printf("> ./spvnode -d -f 0 -c -y 0 -k -j -b scan\n\n");
printf("Sync up, with mnemonic \"test\", pass phrase \"test\", show debug info, don't store headers in file, wait for new blocks:\n");
printf("> ./spvnode -d -f 0 -c -n \"test\" -s \"test\" -b scan\n\n");
printf("Sync up, with mnemonic \"test\", BIP39 passphrase, show debug info, don't store headers in file, wait for new blocks:\n");
printf("> ./spvnode -d -f 0 -c -n \"test\" -s -b scan\n\n");
printf("Sync up, with a wallet file \"main_wallet.db\", with encrypted mnemonic 0, show debug info, don't store headers in file, wait for new blocks:\n");
printf("> ./spvnode -d -f 0 -c -w \"./main_wallet.db\" -y 0 -b scan\n\n");
printf("Sync up, with a wallet file \"main_wallet.db\", with encrypted mnemonic 0, show debug info, with a headers file \"main_headers.db\", wait for new blocks:\n");
Expand Down Expand Up @@ -303,7 +303,7 @@ int main(int argc, char* argv[]) {
data = argv[argc - 1];

/* get arguments */
while ((opt = getopt_long_only(argc, argv, "i:ctrds:m:n:f:y:a:w:h:bpzkj:", long_options, &long_index)) != -1) {
while ((opt = getopt_long_only(argc, argv, "i:ctrdsm:n:f:y:w:h:a:bpzkj:", long_options, &long_index)) != -1) {
switch (opt) {
case 'c':
quit_when_synced = false;
Expand All @@ -321,7 +321,7 @@ int main(int argc, char* argv[]) {
ips = optarg;
break;
case 's':
pass = optarg;
pass = getpass("BIP39 passphrase: \n");
break;
case 'n':
mnemonic_in = optarg;
Expand Down Expand Up @@ -375,6 +375,20 @@ int main(int argc, char* argv[]) {

#if WITH_WALLET
dogecoin_wallet* wallet = dogecoin_wallet_init(chain, address, name, mnemonic_in, pass, encrypted, tpm, file_num, master_key);
if (!wallet) {
printf("Could not initialize wallet...\n");
// clear and free the passphrase
if (pass) {
dogecoin_mem_zero (pass, strlen(pass));
dogecoin_free(pass);
}
return EXIT_FAILURE;
}
// clear and free the passphrase
if (pass) {
dogecoin_mem_zero (pass, strlen(pass));
dogecoin_free(pass);
}
print_utxos(wallet);
client->sync_transaction = dogecoin_wallet_check_transaction;
client->sync_transaction_ctx = wallet;
Expand Down
Loading

0 comments on commit 9558545

Please sign in to comment.