Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI wallet: avoid directly overwriting wallet file on exit #1109 #1195

Merged
merged 11 commits into from
Aug 17, 2018

Conversation

cogutvalera
Copy link
Member

PR for #1109

@abitmore
Copy link
Member

The logic looks fine, although naming new file as ".backup" is not so good.

Copy link
Contributor

@pmconrad pmconrad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAICS fc::ofstream does not throw nor otherwise communicate failure on write(), flush() or close().

@cogutvalera
Copy link
Member Author

we should create another issue for fc::ofstream IMHO

@abitmore
Copy link
Member

AFAICS fc::ofstream does not throw nor otherwise communicate failure on write(), flush() or close().

It means we need to make sure the new (tmp) file is good before calling fc::rename, otherwise it's still possible to lose data. @cogutvalera creating a new issue is fine, but I think this issue/PR depends on the fix of it.

@cogutvalera
Copy link
Member Author

review lost commits, now checking tmp wallet file contents to be equal as required data before renaming this tmp wallet file

}
else
{
disable_umask_protection();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not necessary, because it already happens in the outer try/catch.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why it is not necessary ? I've tested & checked it and we won't get into outer try/catch code after throwing exception here that's why I've placed disable_umask_protection

Copy link
Contributor

@pmconrad pmconrad Jul 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using throw without specifying an exception is only allowed in a catch clause, otherwise it will terminate instead of actually throwing, see below.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, you're absolutely right ! I've checked it earlier, that's why I told you that disable_umask_protection is necessary there before using throw, if I will change throw to fc::exception subtype then I will remove disable_umask_protection call. Just couldn't understand why you told that disable_umask_protection isn't necessary before using throw.

else
{
disable_umask_protection();
throw;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please throw an fc::exception subtype with an appropriate error message.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then we also need to throw fc::exception subtype in outer try/catch block ? right ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, the outer catch should re-throw whatever it caught.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes sure, already done without any changes in outer try/catch block

@cogutvalera
Copy link
Member Author

rebased already

@abitmore
Copy link
Member

Travis-CI complains:

2393592ms th_a main.cpp:597 test_method ] e.to_detail_string(): 0 exception: unspecified
wallet file cannot be saved
{}
th_a wallet.cpp:824 save_wallet_file
2393594ms p2p thread.cpp:252 exec ] thread canceled: 9 canceled_exception: Canceled
cancellation reason: [none given]
{"reason":"[none given]"}
p2p thread_d.hpp:473 start_next_fiber
2393594ms th_a db_management.cpp:206 close ] Rewinding from 0 to 0
unknown location(0): fatal error in "account_history_pagination": unknown type
/home/travis/build/bitshares/bitshares-core/tests/cli/main.cpp(545): last checkpoint

@abitmore
Copy link
Member

Perhaps the Travis-CI environment has different read behavior or limitations? See #1203 (comment) for similar error.

@cogutvalera
Copy link
Member Author

going to check ... Thanks !

@abitmore
Copy link
Member

I'm playing https://github.com/bitshares/bitshares-core/blob/travis-test1/.travis.yml to check if it's related to disk space.

@cogutvalera
Copy link
Member Author

wow ! Thanks a lot ! I'm appreciate all your efforts !

@abitmore
Copy link
Member

Not a disk space issue.

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            3.7G  4.0K  3.7G   1% /dev
tmpfs           748M  300K  748M   1% /run
/dev/sda1        30G   18G   11G  62% /
none            4.0K     0  4.0K   0% /sys/fs/cgroup
none            5.0M     0  5.0M   0% /run/lock
none            3.7G     0  3.7G   0% /run/shm
none            100M     0  100M   0% /run/user
none            768M  179M  590M  24% /var/ramfs

@cogutvalera
Copy link
Member Author

cogutvalera commented Aug 1, 2018

1955015ms th_a       wallet.cpp:799                save_wallet_file     ] saving wallet to file wallet.json
1955016ms th_a       wallet.cpp:817                save_wallet_file     ] saved successfully wallet to tmp file wallet.json.tmp
1955016ms th_a       wallet.cpp:823                save_wallet_file     ] validated successfully tmp wallet file wallet.json.tmp
1955016ms th_a       wallet.cpp:827                save_wallet_file     ] renamed successfully tmp wallet file wallet.json.tmp
1955017ms th_a       wallet.cpp:834                save_wallet_file     ] successfully saved wallet to file wallet.json

@pmconrad
Copy link
Contributor

pmconrad commented Aug 1, 2018

Question: If saving fails, should the error message contain the JSON representing the wallet file? That might give the user another chance to save the data in an emergency situation, perhaps by screen-scraping it.

@abitmore
Copy link
Member

abitmore commented Aug 1, 2018

@pmconrad makes sense.

@cogutvalera
Copy link
Member Author

#1171 issue concerns about showing any secrets on console, so what is the best approach ? but I also agree with @pmconrad about his idea, it really makes sense and @abitmore was agreed too, let's decide the best approach to be applied everywhere the same way

@abitmore
Copy link
Member

abitmore commented Aug 1, 2018

Wallet file contains no secret. No password, no plain private key.

@cogutvalera
Copy link
Member Author

cogutvalera commented Aug 1, 2018

just for the info wallet file contains next info:

{ "chain_id": "4018d7844c78f6a6c41c6a552b898022310fc5dec06da467ee7905a8dad512c8", "my_accounts": [], "cipher_keys": "b30a0ede652bfb2d8d99f8aca77ff8c089f07d77bd047c6df526bc6a652378ed5c37fbbf1d46c408ac1970aec20e83004aee339f1c81e56c0300b00f98f8c142aaad737ddbf7293d339367127a569b1e", "extra_keys": [], "pending_account_registrations": [], "pending_witness_registrations": [], "labeled_keys": [], "blind_receipts": [], "ws_server": "wss://node.bitshares.eu", "ws_user": "", "ws_password": "" }

so no secret is here, just encrypted keys and empty "ws_password" field:

_wallet.cipher_keys = fc::aes_encrypt( data.checksum, plain_txt );

@cogutvalera
Copy link
Member Author

but what about "ws_password" field ? isn't it secret ?

@cogutvalera
Copy link
Member Author

cogutvalera commented Aug 1, 2018

in my case "ws_password" field is empty so it isn't secret, but it won't always be empty, otherwise we don't need the field that will be always empty

@abitmore
Copy link
Member

abitmore commented Aug 1, 2018

I'd say, remove the password before dumping.

_wallet.ws_password = "";
wlog("wallet file ${data}", ("data", fc::json::to_pretty_string( _wallet ) ) );
_wallet.ws_password = ws_password;
if (&_wallet != nullptr)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

&_wallet can never be null. It's a struct member of *this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it fixed travis error with violation memory access in cli_test as was before, strange behavior of travis that's why I've added this check

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The travis error is unrelated, please undo this change.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok sure

@abitmore
Copy link
Member

abitmore commented Aug 2, 2018

This is still not ready yet. Pushing to next release.

@cogutvalera
Copy link
Member Author

can we merge this PR and close related issue ? or this is not still ready and need some changes and improvements ? if YES, then which changes and improvements in your opinion ?

Thanks !

@pmconrad
Copy link
Contributor

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants