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

feat(wallet): add change mnemonic password rpc #2317

Merged
merged 21 commits into from
Feb 12, 2025

Conversation

borngraced
Copy link
Member

@borngraced borngraced commented Jan 10, 2025

implement functionality to change the password for seed storage in kdf with it's rpc method

Example JSON Request

{
       "method": "change_mnemonic_password",
	"userpass": "rpc_password",
	"mmrpc": "2.0",
	"params": {
		"current_password": "old_password123",
		"new_password": "new_password456"
	}
 }

Example JSON Response

{
    "result": null
}

Comment on lines 590 to 593
let encrypted_data = encrypt_mnemonic(&mnemonic, &req.new_password)?;
// save new encrypted mnemonic data with new password
save_encrypted_passphrase(&ctx, &wallet_name, &encrypted_data).await?;

Copy link
Collaborator

Choose a reason for hiding this comment

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

could u actually verify whether this would play well in wasm?
this call eventually does table.add_item, which if the item already exists will error ConstraintError (as per this).

We should use table.replace_item to be able to supported updates.

Copy link
Member Author

@borngraced borngraced Jan 10, 2025

Choose a reason for hiding this comment

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

done thank you 9e50c9f

@laruh
Copy link
Member

laruh commented Jan 10, 2025

Why the result is bool and not Ok if password updated successfully or Err if failed?
image

@borngraced borngraced changed the title feat(wallet): add support for updating seed storage password feat(wallet): add update seed storage password rpc Jan 17, 2025
@shamardy
Copy link
Collaborator

One thing I need @CharlVS's opinion on regarding this PR: Should we update the password using an RPC or during KDF initialization? I think the GUI will provide users the option to update the password before starting KDF. Also, some CLI users will not want to pass the encryption password through RPC at all. Can we have the two modes if possible @borngraced?

@CharlVS
Copy link
Member

CharlVS commented Jan 23, 2025

@shamardy

using an RPC or during KDF initialization?

For the GUI, I'd strongly prefer it to be via RPC. Doing via startup-config for GUI is not ideal because:

  1. The user would have to sign out to change their password or change their password before signing in, which goes against what they'd expect based on the typical flow in other apps.
  2. The user would have to shut down their trading bot and also wait for swaps to complete.

This is outside my domain, but I'd expect it to be a non-issue for CLI users since they face a similar issue with private key RPCs. Those concerned about this would/should be using HTTPS mode. However, the damage from a single coin's leaked private key could be far less than that from a leaked password.

If you implement startup-config password changes, it's worth considering either terminating KDF after the password is updated, or make the fields named password and old_password so that it's idempotent. (Ignore old_password if password is valid)

@borngraced
Copy link
Member Author

borngraced commented Jan 24, 2025

One thing I need @CharlVS's opinion on regarding this PR: Should we update the password using an RPC or during KDF initialization? I think the GUI will provide users the option to update the password before starting KDF. Also, some CLI users will not want to pass the encryption password through RPC at all. Can we have the two modes if possible @borngraced?

Also, some CLI users will not want to pass the encryption password through RPC at all

seems to be a good reason why we would want to have the both.

make the fields named password and old_password so that it's idempotent. (Ignore old_password if password is valid)

  • If password is valid -> nothing is needed to be done
  • Else if old_password valid -> update password to new password
  • Else -> reject

cc. @CharlVS @shamardy

@mariocynicys
Copy link
Collaborator

Should we update the password using an RPC or during KDF initialization? I think the GUI will provide users the option to update the password before starting KDF.

Why would the GUI want to provide such a feat considering that RPC comm is internal on the same device (well if you want a GUI to re-launch KDF with different config, this means that GUI runs KDF internally).

Also, some CLI users will not want to pass the encryption password through RPC at all

If KDF is on the same device that shouldn't be an issue for a CLI user. If it's on a different device, they could log into the device/machine hosting KDF and do the RPC there (well if they wanted to go with changing the config route, this means they must have access to that device hosting KDF).
That's assuming that the hosting device isn't compromised. If it's compromised then having the password plainly in the config file is already dangerous.

mariocynicys
mariocynicys previously approved these changes Jan 24, 2025
Copy link
Collaborator

@mariocynicys mariocynicys left a comment

Choose a reason for hiding this comment

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

Thanks! LGTM
non-blocking comments inline.

@@ -217,6 +217,7 @@ async fn dispatcher_v2(request: MmRpcRequest, ctx: MmArc) -> DispatcherResult<Re
"trade_preimage" => handle_mmrpc(ctx, request, trade_preimage_rpc).await,
"trezor_connection_status" => handle_mmrpc(ctx, request, trezor_connection_status).await,
"update_nft" => handle_mmrpc(ctx, request, update_nft).await,
"update_seed_storage_password" => handle_mmrpc(ctx, request, update_seed_storage_password_rpc).await,
Copy link
Collaborator

Choose a reason for hiding this comment

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

i think we better drop the word storage here.

storage makes it feel as if the whole seed store (multiple seeds) is encrypted using a single pass and not just the single seed in question.
better alternatives imo: update_seed_password or update_seedphrase/passphrase_password

that's a non-blocking comment though since im not a certified linguist.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We should use the word mnemonic not seed since we have get_mnemonic RPC. How about change_mnemonic_password

Copy link
Collaborator

Choose a reason for hiding this comment

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

aha better

))))?;
// encrypt mnemonic with new passphrase.
let encrypted_data = encrypt_mnemonic(&mnemonic, &req.new_password)?;
// save new encrypted mnemonic data::default() with new password
Copy link
Collaborator

Choose a reason for hiding this comment

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

data::default() what?

Copy link
Member Author

Choose a reason for hiding this comment

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

typo, thanks for the catch

Copy link
Collaborator

Choose a reason for hiding this comment

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

well actually this is blocking 🤦‍♂️

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@shamardy
Copy link
Collaborator

Why would the GUI want to provide such a feat considering that RPC comm is internal on the same device

I thought that updating password flow will be like some websites where you do it without logging in, but @CharlVS cleared that.

If it's compromised then having the password plainly in the config file is already dangerous.

It's shouldn't be in the config file, it should be passed as args with the start KDF command.

@shamardy
Copy link
Collaborator

One thing I need @CharlVS's opinion on regarding this PR: Should we update the password using an RPC or during KDF initialization? I think the GUI will provide users the option to update the password before starting KDF. Also, some CLI users will not want to pass the encryption password through RPC at all. Can we have the two modes if possible @borngraced?

Also, some CLI users will not want to pass the encryption password through RPC at all

seems to be a good reason why we would want to have the both.

make the fields named password and old_password so that it's idempotent. (Ignore old_password if password is valid)

  • If password is valid -> nothing is needed to be done
  • Else if old_password valid -> update password to new password
  • Else -> reject

cc. @CharlVS @shamardy

No need to, let's have the RPC command only for now like it is now.

Copy link
Collaborator

@shamardy shamardy left a comment

Choose a reason for hiding this comment

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

A few comments from my side!

laruh
laruh previously approved these changes Jan 24, 2025
Copy link
Member

@laruh laruh left a comment

Choose a reason for hiding this comment

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

LGTM!

shamardy
shamardy previously approved these changes Jan 24, 2025
Copy link
Collaborator

@shamardy shamardy left a comment

Choose a reason for hiding this comment

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

LGTM! Only one nit.

Can you please add test coverage for the new RPC?

@borngraced borngraced changed the title feat(wallet): add update seed storage password rpc feat(wallet): add change mnemonic password rpc Jan 24, 2025
@borngraced borngraced dismissed stale reviews from shamardy and laruh via d9647de January 24, 2025 14:00
@borngraced
Copy link
Member Author

borngraced commented Jan 26, 2025

LGTM! Only one nit.

Can you please add test coverage for the new RPC?

done c782372 and c782372

@shamardy
Copy link
Collaborator

@borngraced please resolve conflicts

@shamardy
Copy link
Collaborator

please update this comment #2317 (comment) @borngraced

@borngraced borngraced force-pushed the implement-update-seed-storage-rpc branch from 965a020 to 8f87cdd Compare February 12, 2025 12:37
@shamardy shamardy merged commit 2e6f8bb into dev Feb 12, 2025
19 of 24 checks passed
@shamardy shamardy deleted the implement-update-seed-storage-rpc branch February 12, 2025 13:02
dimxy added a commit that referenced this pull request Feb 16, 2025
* dev:
  fix(derive_key_from_path): check length of current_key_material (#2356)
  chore(release): bump mm2 version to 2.4.0-beta (#2346)
  fix(tests): add additional testnet sepolia nodes to test code (#2358)
  fix(swaps): maintain legacy compatibility for negotiation messages (#2353)
  refactor(SwapOps): impl defaults for protocol specific swapops fns (#2354)
  feat(tpu-v2): provide swap protocol versioning (#2324)
  feat(wallet): add change mnemonic password rpc (#2317)
  fix(tpu-v2): fix tpu-v2 wait for payment spend and extract secret (#2261)
  feat(tendermint): unstaking/undelegation (#2330)
  fix(utxo-withdraw): get hw ctx only when `PrivKeyPolicy` is trezor (#2333)
  feat(event-streaming): API-driven subscription management (#2172)
  fix(hash-types): remove panic, enforce fixed-size arrays (#2279)
  fix(ARRR): store unconfirmed change output (#2276)
  feat(tendermint): staking/delegation (#2322)
  chore(deps): `timed-map` migration (#2247)
  fix(mem-leak): `running_swap` never shrinks (#2301)
  chore(dep-bump): libp2p (#2326)
  refactor(build script): rewrite the main build script (#2319)
dimxy added a commit that referenced this pull request Feb 16, 2025
* dev:
  fix(derive_key_from_path): check length of current_key_material (#2356)
  chore(release): bump mm2 version to 2.4.0-beta (#2346)
  fix(tests): add additional testnet sepolia nodes to test code (#2358)
  fix(swaps): maintain legacy compatibility for negotiation messages (#2353)
  refactor(SwapOps): impl defaults for protocol specific swapops fns (#2354)
  feat(tpu-v2): provide swap protocol versioning (#2324)
  feat(wallet): add change mnemonic password rpc (#2317)
  fix(tpu-v2): fix tpu-v2 wait for payment spend and extract secret (#2261)
  feat(tendermint): unstaking/undelegation (#2330)
  fix(utxo-withdraw): get hw ctx only when `PrivKeyPolicy` is trezor (#2333)
  feat(event-streaming): API-driven subscription management (#2172)
  fix(hash-types): remove panic, enforce fixed-size arrays (#2279)
  fix(ARRR): store unconfirmed change output (#2276)
  feat(tendermint): staking/delegation (#2322)
  chore(deps): `timed-map` migration (#2247)
  fix(mem-leak): `running_swap` never shrinks (#2301)
  chore(dep-bump): libp2p (#2326)
  refactor(build script): rewrite the main build script (#2319)
dimxy added a commit to dimxy/komodo-defi-framework that referenced this pull request Feb 24, 2025
* dev: (24 commits)
  fix(eth-tpu): remove state from funding validation (KomodoPlatform#2334)
  improvement(rpc-server): rpc server dynamic port allocation (KomodoPlatform#2342)
  fix(tests): fix or ignore unstable tests (KomodoPlatform#2365)
  fix(fs): make `filter_files_by_extension` return only files (KomodoPlatform#2364)
  fix(derive_key_from_path): check length of current_key_material (KomodoPlatform#2356)
  chore(release): bump mm2 version to 2.4.0-beta (KomodoPlatform#2346)
  fix(tests): add additional testnet sepolia nodes to test code (KomodoPlatform#2358)
  fix(swaps): maintain legacy compatibility for negotiation messages (KomodoPlatform#2353)
  refactor(SwapOps): impl defaults for protocol specific swapops fns (KomodoPlatform#2354)
  feat(tpu-v2): provide swap protocol versioning (KomodoPlatform#2324)
  feat(wallet): add change mnemonic password rpc (KomodoPlatform#2317)
  fix(tpu-v2): fix tpu-v2 wait for payment spend and extract secret (KomodoPlatform#2261)
  feat(tendermint): unstaking/undelegation (KomodoPlatform#2330)
  fix(utxo-withdraw): get hw ctx only when `PrivKeyPolicy` is trezor (KomodoPlatform#2333)
  feat(event-streaming): API-driven subscription management (KomodoPlatform#2172)
  fix(hash-types): remove panic, enforce fixed-size arrays (KomodoPlatform#2279)
  fix(ARRR): store unconfirmed change output (KomodoPlatform#2276)
  feat(tendermint): staking/delegation (KomodoPlatform#2322)
  chore(deps): `timed-map` migration (KomodoPlatform#2247)
  fix(mem-leak): `running_swap` never shrinks (KomodoPlatform#2301)
  ...
dimxy added a commit that referenced this pull request Mar 5, 2025
* dev:
  feat(rpc): add is_success field to legacy MySwapStatusResponse (#2371)
  fix(key-derivation): use stored Argon2 parameters instead of default values (#2360)
  fix(tests): stabilize `tendermint_coin::test_claim_staking_rewards` (#2373)
  improvement(RPCs): group staking rpcs under a namespace (#2372)
  feat(tendermint): claim delegation rewards (#2351)
  fix(eth-tpu): remove state from funding validation (#2334)
  improvement(rpc-server): rpc server dynamic port allocation (#2342)
  fix(tests): fix or ignore unstable tests (#2365)
  fix(fs): make `filter_files_by_extension` return only files (#2364)
  fix(derive_key_from_path): check length of current_key_material (#2356)
  chore(release): bump mm2 version to 2.4.0-beta (#2346)
  fix(tests): add additional testnet sepolia nodes to test code (#2358)
  fix(swaps): maintain legacy compatibility for negotiation messages (#2353)
  refactor(SwapOps): impl defaults for protocol specific swapops fns (#2354)
  feat(tpu-v2): provide swap protocol versioning (#2324)
  feat(wallet): add change mnemonic password rpc (#2317)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants