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

Store XORed wallet seed in-mem #200

Merged
merged 21 commits into from
Aug 6, 2019
Merged

Conversation

yeastplume
Copy link
Member

@yeastplume yeastplume commented Jul 29, 2019

Experimental, trying to figure out the most desirable way to store an XORed wallet seed and pass around the token to reconstruct it. My first inclination is to just ensure all calls to wallet.keychain() take an optional token so as ensure it's impossible to miss it anywhere in the code (as opposed to requiring an explicit call to an open(token) close(token) type function anywhere the wallet is called.

Edit: ready for merging, these are the features here.

  • Nothing should be changed from a user perspective, this is all rewiring underneath.
  • Require an Option<SecretKey> representing the mask to be passed along everywhere the keychain is needed. I think this is better than inserting open/close statements in the code (a bit more prone to bugs in future development).
  • There's a flag on open_wallet that determines whether the key gets masked. If this is false, it returns None and all wallet API calls can be made with None as the mask. If true, it returns the mask that needs to be provided.
  • A second implementation of the OwnerRpc API is provided which requires a mask to be passed in (this can be null but still needs to be named and provided). The idea is the older non-masked version of the API will still be present and usable, and the tokenized API will either be run in parallel or swapped out for the new one when the planned start_secure_api is called (will save details of that for the next PR.
  • Some tests now use a secure token, others don't (to exercise both options.)

It appears a lot of things have changed here, but the majority are just propagating the mask throughout and test updates. I'll go through and point out the interesting bits.

@DavidBurkett
Copy link
Contributor

I like the idea of not requiring pre-/post-conditions (open/close) on the wallet. Why optional though? It would always be required.
Also, token and keychain_mask both refer to the same thing, correct?

@yeastplume
Copy link
Member Author

Token and keychain_mask are the same, still working on naming.

Optional because a) I want to keep it as an option on the trait, rather than force other keychain implementations into using this and b) it still needs to be optional for backwards compatibility reasons with older functions, and right now it feels like it will be less hacky to have the XOR feature optional on the keychain rather than providing fake in-process tokens for the foreign API and/or directly linked wallets. Will see how it turns out and the Option can always be dropped in later versions.

@yeastplume yeastplume changed the title [WIP] Store XORed wallet seed in-mem Store XORed wallet seed in-mem Aug 2, 2019
@yeastplume
Copy link
Member Author

Should be ready for reviewing, I've updated the top comment and will point out a few things in the code

@@ -67,6 +68,8 @@ where
pub doctest_mode: bool,
/// foreign check middleware
middleware: Option<ForeignCheckMiddleware>,
/// Stored keychain mask (in case the stored wallet seed is tokenized)
keychain_mask: Option<SecretKey>,
Copy link
Member Author

Choose a reason for hiding this comment

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

This is now just stored by a Foreign API instance, for the case where you want to run a foreign and owner API in the same process but only reference a single instance of the wallet.

@@ -99,6 +103,8 @@ where
data_file_dir: String,
/// Keychain
pub keychain: Option<K>,
/// Check value for XORed keychain seed
pub master_checksum: Box<Option<Blake2bResult>>,
Copy link
Member Author

Choose a reason for hiding this comment

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

This is here because an incorrectly masked key is indistinguishable from the right key. The idea here is to keep a hash of the seed so we can verify whether the stored_seed^mask is correct and return an appropriate error if so. Otherwise it'll just look to the user like their outputs have disappeared when they provide the wrong mask.

@@ -131,7 +132,13 @@ where
Ok(())
}

fn open_wallet(&mut self, _name: Option<&str>, password: ZeroingString) -> Result<(), Error> {
fn open_wallet(
Copy link
Member Author

Choose a reason for hiding this comment

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

Modified to return the mask if create_mask is true.

Copy link

@chisa0a chisa0a left a comment

Choose a reason for hiding this comment

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

LGTM. As long as the XOR key is only used against one plaintext (the master seed), no issues. Looks like a new mask is generated for a new seed right? E.g. a wallet with a stored mask that generates a new seed won't use the same mask against the new seed?

@yeastplume
Copy link
Member Author

@chisa0a Thanks for the review, yes the XOR key is ephemeral, not stored anywhere and re-generated whenever open-wallet is called.

@yeastplume yeastplume merged commit f8c316a into mimblewimble:master Aug 6, 2019
@yeastplume yeastplume deleted the token_xor branch August 13, 2019 08:37
@yeastplume
Copy link
Member Author

#212

yyangli pushed a commit to mwcproject/mwc-wallet that referenced this pull request May 13, 2020
* experimental xor token work

* rustfmt

* test implementation of build_coinbase_t function

* rustfmt

* add separate foreign_rpc_s interface for secure functions

* rustfmt

* rustfmt

* fix http scheme to allow https as well

* add tokenized owner API, modify all functions to use token

* rustfmt

* fix for api doctests, tests passing up to api crate

* rustfmt

* controller crate compilation

* rustfmt

* controller tests passing and modified some to use masked keychains

* rustfmt

* fix wallet tests

* rustfmt

* build from github

* rustfmt
antiochp pushed a commit to antiochp/grin-wallet that referenced this pull request Aug 7, 2020
* experimental xor token work

* rustfmt

* test implementation of build_coinbase_t function

* rustfmt

* add separate foreign_rpc_s interface for secure functions

* rustfmt

* rustfmt

* fix http scheme to allow https as well

* add tokenized owner API, modify all functions to use token

* rustfmt

* fix for api doctests, tests passing up to api crate

* rustfmt

* controller crate compilation

* rustfmt

* controller tests passing and modified some to use masked keychains

* rustfmt

* fix wallet tests

* rustfmt

* build from github

* rustfmt
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.

3 participants