httptoolkit / httptoolkit-android

Automatic Android interception & debugging with HTTP Toolkit, for Android
https://httptoolkit.com
GNU Affero General Public License v3.0
487 stars 76 forks source link

Android TV compatibility #16

Closed dimitar71 closed 11 months ago

dimitar71 commented 11 months ago

Please consider an Android TV compatible client.

There is no easy solution to debug an Android TV app:

Your approach may look feasible to solve thie annoying Android TV pain.

pimterry commented 11 months ago

Hi @dimitar71, thanks for your feedback (I saw the message via the contact form too - I'll reply here).

You mentioned in your other message that the HTTP Toolkit Android app "is not compatible and cannot be run on Android TV". Can you explain what you mean? Any idea why the app isn't compatible? As far as I'm aware, everything the app does should work equally well on Android TV. Unfortunately I don't have one myself for testing.

As an alternative, if you can run Frida on the TV (requires root) then you could use https://github.com/httptoolkit/frida-interception-and-unpinning - these Frida scripts fully implement interception, so you don't need the VPN app or anything else. Integration of that into HTTP Toolkit is a work-in-progress, but those are intended to provide the base for a future single-app targeted interception option on rooted devices.

dimitar71 commented 11 months ago

Hey @pimterry Thanks for your quick reply!

There are several things which are causing AndroidTV to fail:

For Frida and alike, root is not an option for us, sadly.

pimterry commented 11 months ago

just make your activity tv one...

Would you be open to making a PR for this? The app is here: https://github.com/httptoolkit/httptoolkit-android/. That way you can test the changes directly to confirm they work for your case. I'd be very happy to accept changes there to make that TV-compatible.

QR scanner

That's more challenging - the text within is quite complicated since it includes the certificate data and potentially large numbers of network addresses, all then currently encoded as a long base64 string, so it'd be quite fiddly to enter manually.

Can you use ADB? There's generally preferable, as it will automatically handle setup, solves some connectivity problems, and doesn't rely on awkward camera scanning etc.

dimitar71 commented 11 months ago

OK, let me take a look at all this somewhere next weeks. A bit busy lately.

One way or another, I am personally interested this to be resolved, in order to help our team. Will let you know how it goes in time.

dimitar71 commented 11 months ago

Hey @pimterry Spent some time looking at the code.

Is there an option, in the Mac/Win app, Android Device via QR code, to show the whole link below in a text view? Or a button Copy which will copy the data link in memory.

This way we can use adb shell input text for for Android app, from Mac, to paste the link directly into MainActivity and do the connection.

pimterry commented 11 months ago

If you can use ADB, is there a reason you don't want to use the ADB-based interception option, instead of the QR code?

That basically does exactly what you're describing already - it just passes the QR code data to the VPN app via ADB.

dimitar71 commented 11 months ago

I can't read the value from the Mac app as-is. If you can provide that one as a simple string, then I can use adb to pass it to the TV app. Let me explain:

The 1st step would be the whole text of the QR image below it in the desktop app - visually if possible.

pimterry commented 11 months ago

Ignore the QR code option. Why can't you use the existing ADB option?

dimitar71 commented 11 months ago

I can't, the devices are not rooted. And we are not using an emulator.

You can use adb as a regular communication between device and your machine. And then you can use it for more advanced commands ONLY if device is rooted or an emulator.

Our devices are user-based (not rooted), hence we use adb just to pass some commads text from machine(s) to Android app(s).

dimitar71 commented 11 months ago

Here is what may help, a simple Copy to Clipboard button in the QA area, which will copy the same data url. And then I will tweak a bit the Android app to have the ability to accept that string via adb and execute it. Group 2

pimterry commented 11 months ago

And then I will tweak a bit the Android app to have the ability to accept that string via adb and execute it.

The Android app already has this - that's exactly what the ADB option does!

I can't, the devices are not rooted. And we are not using an emulator.

The ADB option doesn't require the device to be rooted, and it works for non emulators. If you can connect to ADB you should be able to use this, and if you can't then that's a bug and we should fix that.

You're getting distracted by the QR code here. I think it's very unlikely that changing that is the right option.

The ADB option already does exactly what you're describing doing manually. It takes the same data as the QR code and sends it to the app via ADB as an intent. It doesn't use any advanced commands to do this, and that works on normal OEM unrooted devices.

From the screenshot, it looks like the ADB option isn't enabled. Is that the issue? If so, can you please run adb devices on your computer and share the output?

dimitar71 commented 11 months ago

As I've mentioned, this is Android TV we are talking. It does not have preinstalled Chrome, hence you can't upload and install ANY certificates.

This part is not existing in any Android TV device.

Screenshot 2023-11-24 at 10 02 30 AM

pimterry commented 11 months ago

Chrome isn't required to install certificates. It's not related to Android's certificate management at all - it's just an application like any other that reads the certificates later.

That error message is correct - note that you would see the exact same thing with the QR code setup too, the process from this point is identical.

On all modern Android devices, installing CA certificates without root is a manual process, that should approximately follow the steps in that message. Of course, I can imagine that Android TVs might behave differently there... Do you have the Settings app installed, and do you see the sections as described in that message above? Is there a specific point in those steps where you get stuck?

If there is no way to install certificates then you're out of luck, and device-level interception will be impossible with any tool. Because of how the Android internals work though, I strongly suspect this is merely awkward & more difficult, not impossible. Let me know more detail about where you run into issues and I can help explain the available workarounds.

dimitar71 commented 11 months ago

Yeah, I tested it after using an online qa decoder and calling

adb shell am start -n tech.httptoolkit.android.v1/tech.httptoolkit.android.MainActivity -a tech.httptoolkit.android.ACTIVATE -d "https://android.httptoolkit.tech/connect/?data=eyJhZGRyZXNzZXMiOlsiMTkyLjE2OC4wLjI0NyIsIjEwMC42NC4xMDAuNiJdLCJwb3J0Ijo4MDAwLCJjZXJ0RmluZ2VycHJpbnQiOiJGRTF1em9VZXB5QlBTcnhLT1EvMkVzUUo5V2tFWTVjV2JzSWhydGQ0QUljPSJ9"

Ends up same place, to install the certificate.

So... no luck. The only viable option with Android TV is https://zahidrasheed.medium.com/charles-proxy-with-androidtv-fedc863e7039.

Such a PITA.

Well... please close this issue, it can't be done.

dimitar71 commented 11 months ago

Closing it since can't be done. Requires SSL certificate install just like using Charles Proxy and Proxyman. Which requires manual addition in Android TV apps.