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

Wrong message type is passed from device #154

Open
vladimirvolek opened this issue Aug 3, 2018 · 16 comments
Open

Wrong message type is passed from device #154

vladimirvolek opened this issue Aug 3, 2018 · 16 comments
Assignees

Comments

@vladimirvolek
Copy link
Contributor

How to reproduce:

  1. enable a passphrase on your device
  2. go to https://szymonlesisz.github.io/trezor-connect-explorer/#/getaddress
  3. click on 'GET ADDRESS' button (popup will show up on a screen + device will show confirmation "Where to enter your passphrase" Device / Host)
  4. close the popup and wait for a second
  5. click on 'Host' on the device
  6. click 'GET ADDRESS' button again

You should see
image

The current message from the device should be 'Features' not 'PassphraseRequest'. Maybe is cached?

console log:
image

@vladimirvolek vladimirvolek changed the title Wrong message type is passed from device. Wrong message type is passed from device Aug 3, 2018
@prusnak
Copy link
Member

prusnak commented Jan 15, 2019

@vladimirvolek is this still a thing?

@vladimirvolek
Copy link
Contributor Author

vladimirvolek commented Mar 27, 2019

@prusnak @tsusanka Yes. I just reproduced this issue.

image

image

@matejcik
Copy link

what I'm somewhat sure is happening here is this:

  1. connect calls the bridge and waits for answer
  2. by closing the pop-up, you cancel the wait, but Trezor is still in state "ready to send reply"
  3. when you select something on the device, the reply is sent out
  4. bridge's next attempt to read USB will return that reply - even though it's happened after a different write.

I'm not sure what's the appropriate place to resolve this. We might want bridge to clear the queue when reconnecting to the device. Or we might want Connect to send a Cancel when the pop-up is closed (i don't know if that's possible though). Or maybe bridge should send the Cancel when a wait is interrupted? Or it could poll the USB descriptor even when nobody is reading, to catch stray messages like this one.

Not much we can do on the firmware side though. As far as the device knows, nothing is wrong. You can't take back the USB message that you already sent.

@jpochyla
Copy link
Contributor

Or it could poll the USB descriptor even when nobody is reading, to catch stray messages like this one.

This is an interesting idea! cc @karel-3d

@karelbilek
Copy link
Contributor

karelbilek commented Mar 28, 2019 via email

@karelbilek
Copy link
Contributor

karelbilek commented Mar 28, 2019 via email

@tsusanka
Copy link
Contributor

I dare to say this is not a firmware issue, I'm suggesting to move this to trezord-go then. @prusnak could you move it? I don't think I have permissions for that.

@prusnak prusnak transferred this issue from trezor/trezor-core Mar 28, 2019
@prusnak
Copy link
Member

prusnak commented Mar 28, 2019

Transferred

@karelbilek
Copy link
Contributor

karelbilek commented Mar 29, 2019

Does the explorer work with UDP emulator? I can't see anything there.

....oh that's because it's on github.io and trezord has whitelisted origins for trezor.io.

Maybe it would be a good idea to add an option for whitelisting more origins? (#155)

@karelbilek
Copy link
Contributor

...well adding github.io to the allowed websites didn't help. I still see "no connected devices" in the explorer.

@karelbilek
Copy link
Contributor

And clicking on "get address" gets me this (forever loading)

Screen Shot 2019-03-29 at 1 16 43 PM

in the github.io site, I see the error

"postMessage: popupMessagePort not found"

@karelbilek
Copy link
Contributor

I got the same issue with the device itself. Tested FFX and Chrome, wallet works (through bridge), not sure where is the issue.

@karelbilek
Copy link
Contributor

Oh, I needed to manually remove #loading from the popup URL and it started working

@karelbilek
Copy link
Contributor

When I played with it, it is not easy to implement, because. On cancelling of the call, we automatically "release" the device, which automatically closes the device on USB level.

So now, we will need to periodically, when cancelled during waiting for call read, do

  • open the device (on USB level)
  • read from the device, with a short timeout
  • if nothing is read, keep this in a set of "devices, that we periodically check"
  • if something is read, just read all
  • when device is disconnected or another call is done on the device, remove it from the set of "devices that we periodically check" - and be sure it is done immediately, so the periodic check that throws away the message is not eating message for someone else
  • and work around all the mutexes that we have everywhere to prevent all the weird bugs

@karelbilek
Copy link
Contributor

Fixed in #156 but I am not sure it's worth the added complexity (and probably some new bugs in the new code).

@tsusanka
Copy link
Contributor

tsusanka commented Apr 16, 2020

Note that Connect (therefore Suite) now has a workaround for this (see trezor/connect#561 as linked).

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 a pull request may close this issue.

6 participants