ddvk / rmfakecloud-proxy

MIT License
7 stars 5 forks source link

Any way to make this work on Android? #5

Open murchu27 opened 2 years ago

murchu27 commented 2 years ago

Currently the only way to use the mobile companion app is to modify the hosts file on the router. Of course, not everyone has a router that can install OpenWRT, so this isn't an option for everyone!

I naively tried to follow the "Variant 1" instructions on Android to see how far I would get.

I modified my hosts file (using this advice) as necessary:

OnePlus7Pro:/ # cat /etc/hosts
127.0.0.1       localhost
::1             ip6-localhost

# rmfake_start
127.0.0.1 hwr-production-dot-remarkable-production.appspot.com
127.0.0.1 service-manager-production-dot-remarkable-production.appspot.com
127.0.0.1 local.appspot.com
127.0.0.1 my.remarkable.com
127.0.0.1 ping.remarkable.com
127.0.0.1 internal.cloud.remarkable.com
# rmfake_end

Then downloaded the 64-bit rmfake-proxy binary to my phone (seemed to be the closest match to an Android's architecture), made it executable, and tried running. Of course, it didn't work - presumably an incompatible architecture.

OnePlus7Pro:/scripts # ls -l
total 5332
-rwxr--r-- 1 root root 5459968 2021-09-26 23:28 rmfake-proxy64
OnePlus7Pro:/scripts # ./rmfake-proxy64
/system/bin/sh: ./rmfake-proxy64: not executable: 64-bit ELF file

Any thoughts?

ddvk commented 2 years ago

you need a aarm64 build GOARCH=arm64 go build

murchu27 commented 2 years ago

Thanks, don't know much at all about go so wasn't sure if this was an option. Will give this a try tomorrow

murchu27 commented 2 years ago

Got a chance to look at it tonight after all. Built an arm64 binary, and it runs on android (through adb shell). But when I try to login on the companion app, I just get the same issue as #4 - the app gets stuck without signing in, and stdout in adb shell shows repeated "TLS handshake error".

ddvk commented 2 years ago

i tested it and it did work, i had to add a /etc/resolv.conf with a nameserver.

did you install the ca.crt correctly?

murchu27 commented 2 years ago

No I didn't realise that installing the ca.crt was necessary when using a reverse proxy. The Windows instructions only say to trust the cert when connecting without reverse proxy, so I hadn't realised!

I think I've installed it correctly now. I copied ca.crt to my phone, and installed it in the "Encryption and credentials" settings menu. My list of trusted credentials now includes one called "rmfakecloud".

This isn't enough by itself, I'm still getting the handshake error. What nameserver did you put in your /etc/resolv.conf?

ddvk commented 2 years ago

i was getting ::53 read failed, so I just put my own router's dns but you can put 8.8.8.8

murchu27 commented 2 years ago

Same error...

I'm gonna go through all my steps, to make sure I'm not missing anything, using the wrong file, etc.

Here are all the files that got created on my tablet by the installer.sh script:

reMarkable: ~/rmfakecloud/ ls
ca.crt            ca.srl            proxy.bundle.crt  proxy.crt         proxy.key         rmfake-proxy
ca.key            csr.conf          proxy.cfg         proxy.csr         proxy.pubkey

I copied the below files to my phone. Even verified sha256 hashes just to be sure, they all transfer just fine.

On my phone, I started a root shell, and added /etc/hosts and /etc/resolv.conf files:

❯ adb root
adbd is already running as root
❯ adb remount
remount succeeded
❯ adb shell
OnePlus7Pro:/ # cat /etc/hosts
127.0.0.1       localhost
::1             ip6-localhost

# rmfake_start
127.0.0.1 hwr-production-dot-remarkable-production.appspot.com
127.0.0.1 service-manager-production-dot-remarkable-production.appspot.com
127.0.0.1 local.appspot.com
127.0.0.1 my.remarkable.com
127.0.0.1 ping.remarkable.com
127.0.0.1 internal.cloud.remarkable.com
# rmfake_end
OnePlus7Pro:/ # cat /etc/resolv.conf
nameserver 8.8.8.8

I installed the ca.crt file as mentioned in my above comment. It seems to have worked fine: image4

Finally, I built an arm64 binary of rmfake-proxy, copied that to my phone, and made it executable with chmod. I moved everything I needed to /scripts/rmfake-proxy, including a config.yml file:

OnePlus7Pro:/scripts/rmfake-proxy # ls
ca.crt  config.yml  proxy.bundle.crt  proxy.key  rmfake-proxy-android
OnePlus7Pro:/scripts/rmfake-proxy # cat config.yml
cert: proxy.bundle.crt
key: proxy.key
upstream: https://my.server

The program starts fine. But then when I try to sign in on the companion app, the TLS handshake error appears, and repeats indefinitely:

OnePlus7Pro:/scripts/rmfake-proxy # ./rmfake-proxy-android -c config.yml
2021/12/14 16:29:13 cert-file=proxy.bundle.crt key-file=proxy.key listen-addr=:443 upstream-url=https://my.server
2021/12/14 16:29:29 http: TLS handshake error from 127.0.0.1:49910: EOF
2021/12/14 16:29:29 http: TLS handshake error from 127.0.0.1:49912: EOF
2021/12/14 16:29:30 http: TLS handshake error from 127.0.0.1:49914: EOF
2021/12/14 16:29:32 http: TLS handshake error from 127.0.0.1:49916: EOF
2021/12/14 16:29:34 http: TLS handshake error from 127.0.0.1:49918: EOF
2021/12/14 16:29:38 http: TLS handshake error from 127.0.0.1:49920: EOF
2021/12/14 16:29:45 http: TLS handshake error from 127.0.0.1:49922: EOF
2021/12/14 16:29:55 http: TLS handshake error from 127.0.0.1:49928: EOF
2021/12/14 16:30:11 http: TLS handshake error from 127.0.0.1:49930: EOF

Anything standing out that I may have missed or done wrong?

ddvk commented 2 years ago

I use the proxy.crt instead of the bundled shouldn't make a difference. i also installed the ca.crt in the system (by generating the hash and adb push to /system certs something

murchu27 commented 2 years ago

What do you mean by generating the hash? Do you think the cert wasn't installed properly on my device

ddvk commented 2 years ago

https://docs.mitmproxy.org/stable/howto-install-system-trusted-ca-android/

murchu27 commented 2 years ago

Success! What an absolute pain though. I also happened to install an update this evening, and everything besides the added lines in /etc/hosts got deleted! I'll do some work to try make this easier, because at the moment this isn't a reasonable way to use the Android app.

murchu27 commented 2 years ago

Thanks for all your help!

murchu27 commented 2 years ago

At the moment, I can confirm that this works on a rooted OnePlus 7 Pro running LineageOS 18.1 (based on Android 11). Once everything is setup (more on that later), I can run ./rmfake-proxy -c config.yml in Termux (with the tsu package installed), and the Android app can successfully connect to the cloud.

Based on your link above, I'd say there's probably no way to do this without root.

ddvk commented 2 years ago

you can also create a service in /system/etc/init/ to start it after boot, but yes, needs a rooted device