JeffLIrion / adb_shell

A Python implementation of ADB with shell and FileSync functionality.
Apache License 2.0
543 stars 60 forks source link

Asked to approve the adb connection at each HA restart #145

Closed koying closed 3 years ago

koying commented 3 years ago

Description

Each time I restart HA, I'm asked to approve the adb key, even if I check "Always authorize" The key thumbprint is always the same.

As the adb connection works with "plain" adb, I assume it is an issue or with the lib, or with my specific setup.

Log

2021-01-11 10:31:53 DEBUG (MainThread) [adb_shell.adb_device_async] bulk_write: b'CNXN\x00\x00\x00\x01\x00\x00\x10\x00\x0c\x00\x00\x00~\x03\x00\x00\xbc\xb1\xa7\xb1'
2021-01-11 10:31:54 DEBUG (MainThread) [adb_shell.adb_device_async] bulk_write: b'host::RPI-4\x00'
2021-01-11 10:31:55 DEBUG (MainThread) [adb_shell.adb_device_async] bulk_read(24): b'AUTH\x01\x00\x00\x00\x00\x00\x00\x00\x14\x00\x00\x00Z\x0c\x00\x00\xbe\xaa\xab\xb7'
2021-01-11 10:31:55 DEBUG (MainThread) [adb_shell.adb_device_async] bulk_read(20): b'\x88\xd9\xee\x0f\xf0\xb8\xa4~\x89\x15\xe2\xaa\x8f_\x81\xf0\xf5\xf7yD'
2021-01-11 10:31:55 DEBUG (MainThread) [adb_shell.adb_device_async] bulk_write: b'AUTH\x02\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\xfc{\x00\x00\xbe\xaa\xab\xb7'
2021-01-11 10:31:55 DEBUG (MainThread) [adb_shell.adb_device_async] bulk_write: b"y\xb4E\xe1{\xc2\xcb\xa7\x1dD\xa6}u\r\x04%\xbd\x9e\x15s\x07\xd2E\xa1?\xa7\x7f\xf7An\xd8+X\xc0{7\xd9\xa6(\xa18\xcar\xc2<\xc2\xc4\x85\xcb\xfd\xe3`\xcfS,?\x84\x7f\x9c_\x0b`\xfdEz\xa8\xbc{N\xf9\xb9\xefU[P\x94\x0b\x8cf\xdb\x8bX\x9e*\x0f\x0b/\xfe\x87\x95\xb9\xda\xc7$\xfb W\xc7\xc3\xd7\xe1(\x1d\xa6ra\xdd\xd5\xdc#p\x93'\x14\xe8\xd8\xd8\x078\x85\xd0\x18k\xb3\x9d\xaa\xfdK\xae\xa7 \x8es\x98\xc7\x98\xdc,\x9cYi\x7f^\x92KZ\xee\xa1\x13\x0fJ\xa0u\xe9\x0b\x10?Q\xc3*6\x05\xe5\xfa\xb1\xfcE\x07f\xe0'\x89Y\xa5\x8an\xd2\x12\xb5\\H\xd1S\xe1\x9e\xdc1Cu\xc2:3\xab\xee\x02H\xc6}\x1dz\x9aA\xa0r\xafR\x0b\x8aJ\xd9\xf3\x15ap\xcc[\xf4#b\\\xe4s\x1e\xd7\x8dy\xea\x91\x07\x90\x98\x03\x0b\xbdZ5#\x96\x13\xcc\xb9Cw\x1b1\x9eU/\x94$F\x87|5\x88\xa7"
2021-01-11 10:31:55 DEBUG (MainThread) [adb_shell.adb_device_async] bulk_read(24): b'AUTH\x01\x00\x00\x00\x00\x00\x00\x00\x14\x00\x00\x00\xb6\x08\x00\x00\xbe\xaa\xab\xb7'
2021-01-11 10:31:55 DEBUG (MainThread) [adb_shell.adb_device_async] bulk_read(20): b'\xfc\x19\xeaK\xc3\x18\x03L\x1c@l\x97\x89C\xd8Y\x9a\x06\x8c\xba'
2021-01-11 10:31:55 DEBUG (MainThread) [adb_shell.adb_device_async] bulk_write: b'AUTH\x03\x00\x00\x00\x00\x00\x00\x00\xc6\x02\x00\x00\xef\xec\x00\x00\xbe\xaa\xab\xb7'
2021-01-11 10:31:55 DEBUG (MainThread) [adb_shell.adb_device_async] bulk_write: bytearray(b'QAAAAFWm+h8D2cpCU4aMqSfgJCTxknD0b3pe0mTg4KbKhosqbxMI9qI50zz0yc5Ju7AcFoux9hMPOlro0f3btMzx1KMldrsbVz+tWvEkEAQgglh1/ntBe0+FISbHSaV0mLV3RAte/ISQ8WsuY+QAB2IghPgnWM7VflJf4QZLovaMvBCj9NlzAk4DEvTivqRQv4KltfW0O+cUwDxqWms6H3rzN6oefZSQlCje4BXArsDz3GZwilyvyBi81qFNdPk6MHnSqyyFQKXoVhdEW0X5mZEQPRBjWc4tLPmWzEpJLr8f0Dn55hOwfL9mezd++tC1MCaqgtBM0AVADrNsvviM+qDG4V104Uuw9/kJDq/AL8shn8XkeOtkg46DvvDVr1phZhAs2vLyz7rkVRm38uX9MlfhFzd9jdMktPktN+isAiNI7I0itFCmJH5ztOvWC51pYmoEvpQbC+uw/282kF8DhGG+R8uGtSJmplWlhP2lnKye2mwNVRA3iBis7ZheORc8jwz+z0lN2XsrkCy6iRWiauK/4aITHWJ5KRaIq4hwhEEAIc1uM/U61i7Jun0RE5X0SO+4RYJG8GkvAT/IfD5NqVW9qzuZhYlZdzpDavkrsWTI22ZFWWhJ3rW7F8C6l9PVCdsUXMLUk8dKfX0SD2Ad6r8LaWBkiVfzQPUP6Gm9229tYyK7pNLCBwEAAQA= @unknown\x00')
2021-01-11 10:32:02 WARNING (MainThread) [homeassistant.components.media_player] Setup of media_player platform androidtv is taking over 10 seconds.
2021-01-11 10:32:05 WARNING (MainThread) [androidtv.adb_manager.adb_manager_async] Couldn't connect to amazon-4c8a85df4.lan:5555.  TcpTimeoutException: Reading from amazon-4c8a85df4.lan:5555 timed out (10.0 seconds)
2021-01-11 10:32:05 WARNING (MainThread) [homeassistant.components.androidtv.media_player] Could not connect to AFTV 4K at amazon-4c8a85df4.lan:5555 using Python ADB implementation with adbkey='/config/adbkey'
2021-01-11 10:32:05 WARNING (MainThread) [homeassistant.components.media_player] Platform androidtv not ready yet. Retrying in 30 seconds.
koying commented 3 years ago

Ah, nevermind (I guess). Using an auto-generated key works, so probably an issue of mine with the key I was using.

JeffLIrion commented 3 years ago

Thanks for providing the log.

How did you obtain the key?

I'm by no means an expert on cryptography, so I don't know what the problem is. But it sounds like you resolved this. Can this issue be closed?

koying commented 3 years ago

The key came from a pure adb installation (i.e. a ".android") Once approved, there is no issues, so it's not a crypto issue per se.

But yeah, auto-generated is fine (and even better) so I'll close.

JeffLIrion commented 3 years ago

Do you have two key files: /config/adbkey and /config/adbkey.pub?

I think config validation checks for both. But there was an issue a while back where the public key wasn't getting loaded and that caused behavior like what you're describing.

My last guess is line endings (LF vs. CRLF) causing issues with the private and/or public key files.

koying commented 3 years ago

Yes, I have both, with same EOL type and final EOL.

Doing more tests, I might not actually have used that key to connect to the devices with "plain" adb before. I now did, and now it works from HA as well, without re-asking for authorization.

Peculiar... Maybe some hidden stuff in the protocol?