Skip to content

Wrong keyboard events from Authorizer. #42

Closed

Description

@vi

I ask Authoritzer to type ttt on USB keyboard gadget, and get these events instead:

evdev-dump events
/dev/input/event21 1659630959.601249 EV_MSC MSC_SCAN 0x000700E0
/dev/input/event21 1659630959.601249 EV_KEY KEY_LEFTCTRL 0x00000001
/dev/input/event21 1659630959.601249 EV_MSC MSC_SCAN 0x000700E1
/dev/input/event21 1659630959.601249 EV_KEY KEY_LEFTSHIFT 0x00000001
/dev/input/event21 1659630959.601249 EV_MSC MSC_SCAN 0x000700E2
/dev/input/event21 1659630959.601249 EV_KEY KEY_LEFTALT 0x00000001
/dev/input/event21 1659630959.601249 EV_MSC MSC_SCAN 0x000700E4
/dev/input/event21 1659630959.601249 EV_KEY KEY_RIGHTCTRL 0x00000001
/dev/input/event21 1659630959.601249 EV_SYN SYN_REPORT 0x00000001
/dev/input/event21 1659630959.602216 EV_MSC MSC_SCAN 0x000700E0
/dev/input/event21 1659630959.602216 EV_KEY KEY_LEFTCTRL 0x00000000
/dev/input/event21 1659630959.602216 EV_MSC MSC_SCAN 0x000700E1
/dev/input/event21 1659630959.602216 EV_KEY KEY_LEFTSHIFT 0x00000000
/dev/input/event21 1659630959.602216 EV_MSC MSC_SCAN 0x000700E2
/dev/input/event21 1659630959.602216 EV_KEY KEY_LEFTALT 0x00000000
/dev/input/event21 1659630959.602216 EV_MSC MSC_SCAN 0x000700E4
/dev/input/event21 1659630959.602216 EV_KEY KEY_RIGHTCTRL 0x00000000
/dev/input/event21 1659630959.602216 EV_SYN SYN_REPORT 0x00000001
/dev/input/event21 1659630959.617249 EV_MSC MSC_SCAN 0x000700E0
/dev/input/event21 1659630959.617249 EV_KEY KEY_LEFTCTRL 0x00000001
/dev/input/event21 1659630959.617249 EV_MSC MSC_SCAN 0x000700E1
/dev/input/event21 1659630959.617249 EV_KEY KEY_LEFTSHIFT 0x00000001
/dev/input/event21 1659630959.617249 EV_MSC MSC_SCAN 0x000700E2
/dev/input/event21 1659630959.617249 EV_KEY KEY_LEFTALT 0x00000001
/dev/input/event21 1659630959.617249 EV_MSC MSC_SCAN 0x000700E4
/dev/input/event21 1659630959.617249 EV_KEY KEY_RIGHTCTRL 0x00000001
/dev/input/event21 1659630959.617249 EV_SYN SYN_REPORT 0x00000001
/dev/input/event21 1659630959.618250 EV_MSC MSC_SCAN 0x000700E0
/dev/input/event21 1659630959.618250 EV_KEY KEY_LEFTCTRL 0x00000000
/dev/input/event21 1659630959.618250 EV_MSC MSC_SCAN 0x000700E1
/dev/input/event21 1659630959.618250 EV_KEY KEY_LEFTSHIFT 0x00000000
/dev/input/event21 1659630959.618250 EV_MSC MSC_SCAN 0x000700E2
/dev/input/event21 1659630959.618250 EV_KEY KEY_LEFTALT 0x00000000
/dev/input/event21 1659630959.618250 EV_MSC MSC_SCAN 0x000700E4
/dev/input/event21 1659630959.618250 EV_KEY KEY_RIGHTCTRL 0x00000000
/dev/input/event21 1659630959.618250 EV_SYN SYN_REPORT 0x00000001
/dev/input/event21 1659630959.633248 EV_MSC MSC_SCAN 0x000700E0
/dev/input/event21 1659630959.633248 EV_KEY KEY_LEFTCTRL 0x00000001
/dev/input/event21 1659630959.633248 EV_MSC MSC_SCAN 0x000700E1
/dev/input/event21 1659630959.633248 EV_KEY KEY_LEFTSHIFT 0x00000001
/dev/input/event21 1659630959.633248 EV_MSC MSC_SCAN 0x000700E2
/dev/input/event21 1659630959.633248 EV_KEY KEY_LEFTALT 0x00000001
/dev/input/event21 1659630959.633248 EV_MSC MSC_SCAN 0x000700E4
/dev/input/event21 1659630959.633248 EV_KEY KEY_RIGHTCTRL 0x00000001
/dev/input/event21 1659630959.633248 EV_SYN SYN_REPORT 0x00000001
/dev/input/event21 1659630959.634251 EV_MSC MSC_SCAN 0x000700E0
/dev/input/event21 1659630959.634251 EV_KEY KEY_LEFTCTRL 0x00000000
/dev/input/event21 1659630959.634251 EV_MSC MSC_SCAN 0x000700E1
/dev/input/event21 1659630959.634251 EV_KEY KEY_LEFTSHIFT 0x00000000
/dev/input/event21 1659630959.634251 EV_MSC MSC_SCAN 0x000700E2
/dev/input/event21 1659630959.634251 EV_KEY KEY_LEFTALT 0x00000000
/dev/input/event21 1659630959.634251 EV_MSC MSC_SCAN 0x000700E4
/dev/input/event21 1659630959.634251 EV_KEY KEY_RIGHTCTRL 0x00000000
/dev/input/event21 1659630959.634251 EV_SYN SYN_REPORT 0x00000001

hid_gadget_test, for example, does type keys correctly, so I assume the problem is with Authorizer itself.

The same version of Authorizer work before on the same device on Android 11, but with Android 12 it seems to be failing.

Activity

  1. vi commented on Aug 4, 2022

    @vi
    ContributorAuthor

    I see the following command line being executed by Authorizer:

    printf '\x00\x00\x17\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x17\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x17\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' > /dev/hidg0
    

    Executing it manually also emits the same wrong keyboard events as from the Authorizer.

  2. vi commented on Aug 4, 2022

    @vi
    ContributorAuthor

    Looks like printf writes one byte at a time, which gadget drivers does not like.

    Workaround:

    printf '\x00\x00\x17\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x17\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x17\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' \
      | dd of=/dev/hidg0 bs=8
    
  3. added a commit that references this issue on Aug 4, 2022
    1c3d6bf
  4. tejado commented on Aug 5, 2022

    @tejado
    Owner

    Hi @vi
    Thanks a lot for analysing this issue and providing a solution. There was at least one previous issue by users mentioning a similar problem.
    I had never any issue with it. Do you know if this issue is part of every printf implementation? If not, I wonder why I did not hit it so far.
    Can you provide information about your environment at Android 12, e.g. your shell and version of it? Thanks!

  5. vi commented on Aug 5, 2022

    @vi
    ContributorAuthor

    What do you mean by "shell version"? /system/bin/sh does not seem to provide version information.

    $ /system/bin/printf --version
    toybox 0.8.4-android
    

    The system is crosshatch-sp1a.210812.016.c2 with Magisk 25.1 (25100).

  6. tejado commented on Aug 5, 2022

    @tejado
    Owner

    toybox

    Great thanks. And on your Android 11, was this also toybox or busybox and which version?

  7. vi commented on Aug 5, 2022

    @vi
    ContributorAuthor

    On another (unrooted) device with Android 11 I see:

    $ /system/bin/printf --version
    toybox 0.8.3-android
    

    I do not see any relevant changes in printf subcommand between toybox 0.8.3 and 0.8.4.

    Note that printf can also be a build-in command in shell.

    Also note that different Linux kernels may react differently to short writes to character devices.

  8. Alexander-Shukaev commented on Aug 5, 2022

    @Alexander-Shukaev

    Happy to test as per #38.

  9. vi commented on Aug 5, 2022

    @vi
    ContributorAuthor

    @Alexander-Shukaev , Does it work better with #43?

    Does echo g g | hid_gadget_test /dev/hidg0 keyboard work reliably for you?

  10. Alexander-Shukaev commented on Aug 5, 2022

    @Alexander-Shukaev

    I don't know how to test this without release really.

  11. tejado commented on Aug 5, 2022

    @tejado
    Owner

    I will provide tomorrow a test apk, so we can verify if this is working on several devices.

  12. vi commented on Aug 7, 2022

    @vi
    ContributorAuthor

    Here is the apk I use for myself.

    authorizer-debug.zip

  13. Alexander-Shukaev commented on Aug 7, 2022

    @Alexander-Shukaev

    How to install it on Android?

  14. vi commented on Aug 7, 2022

    @vi
    ContributorAuthor

    Rename it to authorizer-debug.apk, then adb install authorizer-debug.apk (if USB debugging is in use).
    Or copy it to the device, then open it with a file manager (you may need to accept that file manager as application installation source).

    Note that installing apks in this way (including ones downloaded from Github) is a security risk. If you want both root access and security, you should be prepared to configure Android development environment to build things from source code (and review that source at least superficially).

  15. Alexander-Shukaev commented on Aug 7, 2022

    @Alexander-Shukaev

    Installing directly on the device, it says "App not installed", so the installation basically fails... Any ideas?

  16. 1 remaining item

  17. Alexander-Shukaev commented on Aug 7, 2022

    @Alexander-Shukaev

    @vi and @tejado, thanks for the tips and working on this. I can confirm through several test cases, which failed before, that the debug version that @vi provided now types passwords as expected! Incredible 🥂 💯

  18. tejado commented on Aug 7, 2022

    @tejado
    Owner

    Great, thanks for the feedback @Alexander-Shukaev. It could be, that this issue hit me the first time today as well. So my priority on this increased and will check the fix as well asap.

  19. vi commented on Aug 23, 2022

    @vi
    ContributorAuthor

    Shall I expect an F-Droid build with my patch (or some another fix) someday?

  20. tejado commented on Aug 25, 2022

    @tejado
    Owner

    Shall I expect an F-Droid build with my patch (or some another fix) someday?

    Hi vi,
    unfortunately, my issue had nothing to do with your fix. I need still some time to prepare my environment, as I preparing the builds on a new (Pixel) device with a different custom rom.
    I hope I'm finishing this in the next days. If everything works fine, I will merge it and trigger an f-droid build.

  21. Alexander-Shukaev commented on Sep 8, 2022

    @Alexander-Shukaev

    Hi, it's been a while now since I tested the patch. @tejado, do you have some rough ETA for F-Droid please? Thanks!

  22. vi commented on Sep 8, 2022

    @vi
    ContributorAuthor

    Maybe it also worth to change it to avoid creating regular file /dev/hidg0 when character device does not exist along the way?

  23. tejado commented on Sep 12, 2022

    @tejado
    Owner

    Hi, it's been a while now since I tested the patch. @tejado, do you have some rough ETA for F-Droid please? Thanks!

    Give me a few more days. Latest end of next week. Having a summer break right now but I try my best to merge and schedule f-droid build asap.

    Maybe it also worth to change it to avoid creating regular file /dev/hidg0 when character device does not exist along the way?

    Sure - there are even more things to fix/implement. At first I need to update my own devices as mentioned above, as these are currently based on the Kernel patch which has not such issues. When I'm done with that, I will implement more fixes, e.g. adding gadgets at boot time, ...

  24. self-assigned this
    on Sep 12, 2022
  25. added a commit that references this issue on Sep 18, 2022
    5153e3a
  26. tejado commented on Sep 18, 2022

    @tejado
    Owner

    Change was merged and additionally bugs were resolved to create a new release with minimum efforts. F-Droid build process should pick it up in their next update phase (few days).

    @vi
    I will now start the work on v0.5.0 which will be using latest SDKs, e.g. to get it ready for Play Store. This will then also include better compatibility with android-usb-gadget, e.g. fixing #36.

  27. vi commented on Sep 18, 2022

    @vi
    ContributorAuthor

    Offtopic here, but does it make sense to bundle some of USB Gadget Tool functions (i.e. adding keyboard gadget if it does not exist) into Authorizer itself?

  28. tejado commented on Sep 18, 2022

    @tejado
    Owner

    Offtopic here, but does it make sense to bundle some of USB Gadget Tool functions (i.e. adding keyboard gadget if it does not exist) into Authorizer itself?

    Maybe at a later point. Currently, the USB Gadget Tool is very unstable on some devices. E.g. it is required to add a new gadget instead of just adding the HID function to the existing gadget. Doing this automatically, can cause other USB functions to fail so that a reboot will be required (e.g. to get adb working again). But I will have to check how the overall experience with Authorizer and USB Gadget Tool can look like as soon as I use it together on a daily basis.

  29. tejado commented on Sep 25, 2022

    @tejado
    Owner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions