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

[r2r] Hardware Wallet enhancements #1633

Closed
wants to merge 11 commits into from
Closed

[r2r] Hardware Wallet enhancements #1633

wants to merge 11 commits into from

Conversation

sergeyboyko0791
Copy link

@sergeyboyko0791 sergeyboyko0791 commented Jan 26, 2023

* Add `MmCtx::shared_db_id`
* Add `get_shared_db_id` RPC
* Add `MmCtx::shared_sqlite_conn`
* Remove `mm2_rmd160` property from HD wallet storage
* Refactor SQL queries by using named params
* TODO implement `task::get_new_address::cancel`
* Add `MockableConfirmAddress` for tests
@sergeyboyko0791 sergeyboyko0791 linked an issue Jan 31, 2023 that may be closed by this pull request
@sergeyboyko0791 sergeyboyko0791 changed the title [wip] Implement a DB shared between Iguana and each HD accounts [r2r] Hardware Wallet enhancements Jan 31, 2023
@sergeyboyko0791 sergeyboyko0791 changed the title [r2r] Hardware Wallet enhancements [wip] Hardware Wallet enhancements Feb 1, 2023
@sergeyboyko0791 sergeyboyko0791 changed the title [wip] Hardware Wallet enhancements [r2r] Hardware Wallet enhancements Feb 1, 2023
shamardy
shamardy previously approved these changes Feb 3, 2023
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.

Great enhancement 🚀 ! Only non-blockers :)

mm2src/coins/hd_wallet_storage/mod.rs Outdated Show resolved Hide resolved
Copy link
Member

@borngraced borngraced left a comment

Choose a reason for hiding this comment

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

Great work! few suggestions and a question

mm2src/coins/hd_confirm_address.rs Outdated Show resolved Hide resolved
mm2src/crypto/src/shared_db_id.rs Outdated Show resolved Hide resolved
mm2src/crypto/src/shared_db_id.rs Outdated Show resolved Hide resolved
mm2src/coins/utxo/utxo_common.rs Show resolved Hide resolved
* Add `trezor_connection_status` RPC
* `HwCtx::trezor` should return `TrezorSession<'a>`
* Fix comments
* Use `EnumFromInner`, `EnumFromStringify` derive macros
* Rename `NullStringPassphrase` to `EmptyPassphrase`
@sergeyboyko0791
Copy link
Author

@shamardy @borngraced the PR is ready for the next review iteration!
Please note that I also implemented #1642 issue since the last review.
Hope it won't make the review process complicated

@@ -44,14 +45,14 @@ struct WebUsbLink {
impl Link for WebUsbLink {
async fn write_chunk(&mut self, chunk: Vec<u8>) -> TrezorResult<()> {
if !self.device.is_open().await? {
self.reconnect().await?;
return MmError::err(TrezorError::DeviceDisconnected);
Copy link
Member

Choose a reason for hiding this comment

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

does this mean device can no longer try to reconnect?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, exactly. The main reason is this issue https://github.com/KomodoPlatform/WebDEX/issues/672.
Once the device is disconnected, we no longer need to try to reconnect as the GUI should notify the user to reinitialize Hardware Wallet via a Connect Hardware Wallet button.

Copy link
Member

Choose a reason for hiding this comment

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

Ok that makes sense thanks.

Copy link
Member

@borngraced borngraced left a comment

Choose a reason for hiding this comment

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

Looks very good 🔥 💯 thank you for the great work!

@ca333 ca333 self-requested a review February 10, 2023 12:26
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.

Thanks for the additional fixes! Only a question and minor changes.

Comment on lines +60 to +61
"RUSTSEC-2022-0084",
"RUSTSEC-2023-0004",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you please add small comments about these vulnerabilities like it's done for others?

Copy link
Author

Choose a reason for hiding this comment

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

This will no longer be needed once I merge dev into my branch. Thank you!

None => return HwConnectionStatus::Connected,
};

#[cfg(target_arch = "wasm32")]
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe this is not needed anymore

Copy link
Author

Choose a reason for hiding this comment

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

You're right, will remove this compilation flag

Some(inner) => TrezorSession { inner },
None => return Ok(None),
};
let features = session.initialize_device().await?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just a question to better understand what is happening, try_init_new_session_if_not_occupied is used only in trezor_connection_status, why do we have to initialize the device when we are getting the status?

Copy link
Author

Choose a reason for hiding this comment

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

There are three ways to check if the device is still connected:

  1. Using webusb or libusb APIs that can provide such info. webusb provides an easy way to check the status, but libusb requires to sanitize much more actions to use its hotplug feature. It's also can be unimplemented on some OS.
  2. Trying to ping the device and receive a pong. The problem with this approach is that if the HW device is locked (but still connected), it will require the user to enter a PIN. Even if we cancel the PIN request immediately once the device asked us about it, the device will draw the PIN matrix for a few milliseconds. This looks unfriendly.
  3. Trying to initialize a new session by sending Initialize packet. It has little overhead since it returns the big Features response. But on the other hand, this request doesn't require the user to enter the PIN, so there is no any interaction on it.

I've chosen the last option as 1) requires more refactoring to implement the hotplug feature, and 2) looks unfriendly.
Btw, I just realized that is_connected is no more needed, will remove it.
https://github.com/KomodoPlatform/atomicDEX-API/blob/d28c11fb541dae04d1dcfb0200e9172676f309a6/mm2src/crypto/src/hw_ctx.rs#L100-L108

Also I'll add a comment that points to this discussion for better understanding.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks a lot for the detailed explanation

Btw, I just realized that is_connected is no more needed, will remove it.

I was actually asking this because I thought that part of this code can be removed/refactored :)

@sergeyboyko0791 sergeyboyko0791 mentioned this pull request Feb 19, 2023
8 tasks
@anarkiVan
Copy link

anarkiVan commented Feb 21, 2023

When the trezor security's option passphrase is enabled and i try to withdraw coin from WebDEX i got an error:
Internal error: Unexpected interaction request: PassphraseRequest
Also on each asset activation it asks to enter seed
ps: During connection to trezor i skip sending passphrase and our old logic just send empty string

@sergei-boiko
Copy link

All PR issues have been solved in #1672

@shamardy
Copy link
Collaborator

Superseded by #1672

@shamardy shamardy closed this Feb 22, 2023
@shamardy shamardy deleted the shared-db branch February 22, 2023 11:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants