ardevd / habitat

Z-way client for Android
MIT License
3 stars 1 forks source link

Can't seem to connect to any of my servers recently. #9

Closed blakejrobinson closed 6 years ago

blakejrobinson commented 6 years ago

Not sure if it's the latest update, or that I'm on Android 9/Pixel 2, but I can't connect to any of my zway servers anymore.

2018-10-16 22 15 57

I've tried all options, and also tried uninstall and reinstalling the app. Also cleared cache and app data. Also removed and reinstalled the Habitat app on the zway server itself. Tried with three different zway servers around the house and no luck.

Let me know if there's any other info that would be helpful!

blakejrobinson commented 6 years ago

Zway servers tried are 2.3.7 and 2.3.8. Just remembered that extra detail!

ardevd commented 6 years ago

Hi there and thanks for reporting the issue.

I'm using a Pixel 2 XL running Android 9 myself and I'm not able to reproduce this issue. However, I notice from the screenshots that your mobile data service seems to be disabled.

The error message you're seeing "No network connection available" is thrown by Android's own Volley API so I cant think of anything related to the Habitat app itself that might be causing it. Have you changed anything else on your device recently except updating Habitat? I would imagine that if Habitat throws this error, any other app relying on the same networking API's would have the same issue. Could you enable cellular data services just to see if that makes any difference?

blakejrobinson commented 6 years ago

No problem!

Ah sorry, the reason for the cellular data being disabled was to test if that was the problem. I originally had cell data turned on, and turned it off to see if that helped anything. I have since turned it back on and it doesn't seem to have made a difference.

Is there anything else related to the network I should try? I have also tried turning my VPN on and off, and deleting the VPN connection itself, but that didn't seem to do anything either.

Network-wise I'm just using a standard DSL router and a switch. The same configuration it was originally working for.

ardevd commented 6 years ago

Very interesting.

The only difference from my setup is that you're using the IP and I use DNS. Would it be possible for you to use DNS for your Z-Way server and see if it helps?

Also, if you could use a terminal emulator (or adb shell) and ping 10.1.1.9 and see if you get a response?

blakejrobinson commented 6 years ago

Odd indeed!

By DNS, do you mean the zway.me remote access thing, or do you mean using my local router's DNS? I just tried using my router's DNS name and had no joy with that.

Also just tried pinging 10.1.1.9 from the phone and that seemed to work fine.

2018-10-18 15 34 27.

Just tried setting my phone to have manual IP/gateway/etc. rather than DHCP and that didn't seem to make a difference. Could it be anything to do with my router supporting ip6? I can't seem to figure out a way to turn that off to see if it's causing issues.

ardevd commented 6 years ago

This is very strange indeed. I guess we could try this: Install the attached .apk. It's the previous version of the app. If that works then we know it's the app. If it doesnt, then there must be something else that's wrong.

Sorry for making you jump through all these hoops but I'm just not able to reproduce your issue myself so any help you can provide is really appreciated.

habitat_v54.tar.gz

blakejrobinson commented 6 years ago

No joy with that apk either, unfortunately - same message.

I'm trying to think of the last time I successfully used the app, and what's different since then.

ardevd commented 6 years ago

Well, let's try this then:

On your phone, open up your web browser and navigate to your z-way instance, which I'm assuming is http://10.1.1.9:8083 - Log in to the zway interface.

Next, navigate to the following url: http://10.1.1.9:8083/ZAutomation/api/v1/devices

Do you get JSON output with your device info there?

If you're not using port 8083, then you need to specify that when setting up Habitat.

blakejrobinson commented 6 years ago

I do indeed get the JSON. I can also access the actual web interface on 10.1.1.9:8083 on my phone, and the official zway.me app appears to work correctly. My own diagnosis webpage (HTML with some AJAX/websockets to access 10.1.1.9) also seems to work okay.

It's very strange. It's as if the app believes there is no network connection at all.

ardevd commented 6 years ago

Ok, let's try this then: when setting up habitat, try to include the port number in the hostname. So 10.1.1.9:8083. See if that makes a difference. If not I'll build a debug version of the app for you so we can see exactly what it's trying to communicate with

blakejrobinson commented 6 years ago

No joy with the port being included either.

ardevd commented 6 years ago

What a mystery! Is there any app that might interfere with Habitat? Firewall, etc?

blakejrobinson commented 6 years ago

Nothing that I can think of. The official app, and web pages all seem to work. It just seems to be Habitat.

Should Habitat have asked for any permissions? It lists none asked for in android apps setting.

Out of curiosity, I whipped up a quick nodejs http server locally on my 10.1.1.2 machine and listened on port 8083. I get the same 'No network connection available' message putting in 10.1.1.2 / 10.1.1.2:8083 and the http server shows no incoming HTTP requests at all.

Very strange!

ardevd commented 6 years ago

Yeah, I must admit I'm pretty baffled. Did the new update help at all? If not, I'll compile a debug build with some Toast messages. Perhaps that will give us some answers.

ardevd commented 6 years ago

Also, ensure that there are no whitespaces in the hostname field. :) Appending a white space is the only way I've been able to reproduce the error message you're seeing. I'll push out a new update tonight where I ensure any non-visible characters in the hostname field is removed. Who knows, perhaps it will help.

ardevd commented 6 years ago

Also, check if the new Habitat app update makes any difference.

blakejrobinson commented 6 years ago

No joy with the latest update :( Also made sure of Whitespace and that all seems okay.

If it's any help in figuring this weirdness out, I just tried entering exactly the same server address on my Pixel C tablet and Habitat connected to the server all fine - it just seems to be that it's not working on my Pixel 2 phone.

ardevd commented 6 years ago

Interesting. So it works on your Pixel C (Running Android 8.1.0 I presume), and it works on my Pixel 2 XL running Android 9, but your Pixel 2 with Android 9 does not. Very peculiar. There must be something we're missing here.

mjsambol commented 6 years ago

I've got the exact same issue. Have gone through all the suggestions here other than the local "quick nodejs http server" and have the same results. Also a Pixel 2 XL with Android 9.

mjsambol commented 6 years ago

OK, have confirmed with locally running PHP and nodejs servers - web browsers can connect fine, but the app only shows "no network connection available" and no sign of activity in the server log.

ardevd commented 6 years ago

@mjsambol Thanks for reporting the issue. It's a big mystery. We now have 3 Pixel 2 XL's running Android 9 and 2/3 of them exhibit the issue. Very strange.

ardevd commented 6 years ago

Ok, I have done some digging and in order to figure out the exact issue here I will push out a new app update that will insert a more verbose log entry into the app log database when the NoConnectionError occurs. This should hopefully give us a better indicator of what the actual issue is. I'll post instructions once the update is out.

ardevd commented 6 years ago

@mjsambol @blakejrobinson Could you install the attached APK and tell me what error message shows up when you attempt to log in?

habitat-1.1.7-debug.tar.gz

mjsambol commented 6 years ago

java.io.IOException: Cleartext HTTP traffic to not permitted

https://stackoverflow.com/questions/45940861/android-8-cleartext-http-traffic-not-permitted

On Wed, 31 Oct 2018 at 21:45, ardevd notifications@github.com wrote:

@mjsambol https://github.com/mjsambol @blakejrobinson https://github.com/blakejrobinson Could you install the attached APK and tell me what error message shows up when you attempt to log in?

habitat-1.1.7-debug.tar.gz https://github.com/ardevd/habitat/files/2536107/habitat-1.1.7-debug.tar.gz

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ardevd/habitat/issues/9#issuecomment-434820693, or mute the thread https://github.com/notifications/unsubscribe-auth/Ah7PX3aqKuS8neYGWTD5N4ZQe3880QBmks5uqf3VgaJpZM4XiV4J .

ardevd commented 6 years ago

@mjsambol Oh, interesting! So that explains it I guess. Not quite sure why I cant reproduce the issue locally but maybe I overlooked something as I have always used TLS with my Z-way controller. Thanks for reporting this.

Please try the attached APK and see if the problem is resolved.

habitat-1.1.7-cleartext.tar.gz

mjsambol commented 6 years ago

The good news is that I now get past that screen. The bad news is I am prompted for Authentication, and although I'm certain I'm providing the right credentials, I can only get "Authentication error". Might need more debug info...

On Thu, 1 Nov 2018 at 23:40, ardevd notifications@github.com wrote:

@mjsambol https://github.com/mjsambol Oh, interesting! So that explains it I guess. Not quite sure why I cant reproduce the issue locally but maybe I overlooked something as I have always used TLS with my Z-way controller. Thanks for reporting this.

Please try the attached APK and see if the problem is resolved.

habitat-1.1.7-cleartext.tar.gz https://github.com/ardevd/habitat/files/2540210/habitat-1.1.7-cleartext.tar.gz

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ardevd/habitat/issues/9#issuecomment-435196756, or mute the thread https://github.com/notifications/unsubscribe-auth/Ah7PX0DCRAlcK75-2ri-PSC3bZ1cTnsWks5uq2pAgaJpZM4XiV4J .

ardevd commented 6 years ago

@mjsambol Ok, one step forward at least. Authentication error typically occurs when credentials are not correct but when manually installing various versions of the app it might also screw with the Android keystore entries for Habitat. Could you try uninstalling and re-installing the apk provided above and check if you still get the same error? I'm assuming you have not ticked the box for "anonymous access" and that the Z-way user you are trying to log in as requires credentials?

Here is an apk with more verbose error messaging when authentication fails. I will be implementing overall more detailed error messaging in the next update of the app so thank you for testing this.

habitat-1.1.8-authdebug.tar.gz

mjsambol commented 6 years ago

Thanks for the quick iteration. I deleted the previous install, installed the new apk, but now unfortunately after I enter the IP of my server and hit submit, the app crashes.

I can try to send you a crash report but not sure if I can do that via a github issue, is there a better way? Do you use slack or something like that?

On Fri, 2 Nov 2018 at 10:34, ardevd notifications@github.com wrote:

@mjsambol https://github.com/mjsambol Ok, one step forward at least. Authentication error typically occurs when credentials are not correct but when manually installing various versions of the app it might also screw with the Android keystore entries for Habitat. Could you try uninstalling and re-installing the apk provided above and check if you still get the same error? I'm assuming you have not ticked the box for "anonymous access" and that the Z-way user you are trying to log in as requires credentials?

Here is an apk with more verbose error messaging when authentication fails. I will be implementing overall more detailed error messaging in the next update of the app so thank you for testing this.

habitat-1.1.8-authdebug.tar.gz https://github.com/ardevd/habitat/files/2541623/habitat-1.1.8-authdebug.tar.gz

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ardevd/habitat/issues/9#issuecomment-435307503, or mute the thread https://github.com/notifications/unsubscribe-auth/Ah7PX9GeTlOyzqgW7NLi117R33q736qzks5urAN-gaJpZM4XiV4J .

ardevd commented 6 years ago

@mjsambol Thanks for the quick feedback. After some more debugging on my end I think I've found the issue that's causing both the crash you just encountered and why you get the auth failure error to begin with. Give me a few minutes and I'll see I can figure out a fix and upload another apk for you to try. Thanks a ton!

ardevd commented 6 years ago

@mjsambol Unfortunately, the reason the app crashed for you now was because there was no detailed error message to show. The only thing we know is that your Z-way server is returning HTTP error code 401.

This would either be because your credentials are incorrect but it could potentially also be a KeyStore issue. I've attached an apk which will print your decrypted Z-Way credentials to logcat on your device. You will need adb on your computer in order to view the log.

Once you've installed the app, start logcat on your computer and look for entries with the "HABITAT" tag. So with adb installed, simply call:

adb logcat -s "HABITAT"

Then run through the setup and once you have tried submitting your credentials, look at the logcat output and see if you see your credentials printed out there or if you get a "decryption failed" error. You will see that message when you submit your hostname though since you're not providing credentials at all at that point. However, if you dont see your credentials printed out at all, then the decryption process has failed and you will need to look at the stack trace to figure out why it failed. Running the following adb command will narrow things down.

adb logcat -s "System.err"

Hope this made sense, if you need more detailed help, let me know and we can do this on IRC or something.

habitat-1.1.8-credsdebug.tar.gz

mjsambol commented 6 years ago

Hi, I am happy to help but have substantial other work taking my attention today, so before I run through this, I have to ask: the app is crashing before I enter any credentials at all. I just put in the IP and hit submit and it crashes. This is after clean uninstall. So are you sure there isn't something else going on?

On Fri, 2 Nov 2018 at 11:10, ardevd notifications@github.com wrote:

@mjsambol https://github.com/mjsambol Unfortunately, the reason the app crashed for you now was because there was no detailed error message to show. The only thing we know is that your Z-way server is returning HTTP error code 401.

This would either be because your credentials are incorrect but it could potentially also be a KeyStore issue. I've attached an apk which will print your decrypted Z-Way credentials to logcat on your device. You will need adb on your computer in order to view the log.

Once you've installed the app, start logcat on your computer and look for entries with the "HABITAT" tag. So with adb installed, simply call:

adb logcat -s "HABITAT"

Then run through the setup and once you have tried submitting your credentials, look at the logcat output and see if you see your credentials printed out there or if you get a "decryption failed" error. You will see that message when you submit your hostname though since you're not providing credentials at all at that point. However, if you dont see your credentials printed out at all, then the decryption process has failed and you will need to look at the stack trace to figure out why it failed. Running the following adb command will narrow things down.

adb logcat -s "System.err"

Hope this made sense, if you need more detailed help, let me know and we can do this on IRC or something.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ardevd/habitat/issues/9#issuecomment-435316211, or mute the thread https://github.com/notifications/unsubscribe-auth/Ah7PX-OO-jBbtvaVsRq6xej04__DR1Loks5urAwggaJpZM4XiV4J .

ardevd commented 6 years ago

@mjsambol The apk attached to the previous post (habitat-1.1.8-credsdebug.tar.gz) also crashes for you when you submit the hostname?

mjsambol commented 6 years ago

I had't checked, thought from your explanation that you had just added more debug info. I've checked it now and it doesn't crash, so will go through the rest of the steps you suggested.

On Fri, 2 Nov 2018 at 12:50, ardevd notifications@github.com wrote:

@mjsambol https://github.com/mjsambol The apk attached to the previous post (habitat-1.1.8-credsdebug.tar.gz) also crashes for you when you submit the hostname?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ardevd/habitat/issues/9#issuecomment-435341127, or mute the thread https://github.com/notifications/unsubscribe-auth/Ah7PX7friFGBg1icMp3CsJ-_qq-zmmtVks5urCNygaJpZM4XiV4J .

ardevd commented 6 years ago

Thanks man! Really appreciate your effort.

mjsambol commented 6 years ago

I'm not sure I'm doing this right, but adb logcat -s "HABITAT" didn't give me anything, whereas with adb logcat -s "System.err" I get:

11-02 14:20:59.293 21845 21885 W System.err: android.security.keystore.StrongBoxUnavailableException: Failed to generate key 11-02 14:20:59.293 21845 21885 W System.err: at android.security.keystore.AndroidKeyStoreKeyGeneratorSpi.engineGenerateKey(AndroidKeyStoreKeyGeneratorSpi.java:321) 11-02 14:20:59.293 21845 21885 W System.err: at javax.crypto.KeyGenerator.generateKey(KeyGenerator.java:612) 11-02 14:20:59.293 21845 21885 W System.err: at no.aegisdynamics.habitat.util.p.a(Unknown Source:66) 11-02 14:20:59.293 21845 21885 W System.err: at no.aegisdynamics.habitat.util.p.a(Unknown Source:17) 11-02 14:20:59.293 21845 21885 W System.err: at no.aegisdynamics.habitat.e.a.a(Unknown Source:73) 11-02 14:20:59.293 21845 21885 W System.err: at no.aegisdynamics.habitat.data.c.g$10.getHeaders(Unknown Source:2) 11-02 14:20:59.293 21845 21885 W System.err: at com.a.a.a.j.a(Unknown Source:12) 11-02 14:20:59.293 21845 21885 W System.err: at com.a.a.a.c.a(Unknown Source:74) 11-02 14:20:59.293 21845 21885 W System.err: at com.a.a.i.a(Unknown Source:47) 11-02 14:20:59.293 21845 21885 W System.err: at com.a.a.i.run(Unknown Source:5) 11-02 14:20:59.296 21845 21885 W System.err: Caused by: android.security.KeyStoreException: No StrongBox available 11-02 14:20:59.296 21845 21885 W System.err: ... 10 more 11-02 14:20:59.491 21845 21885 W System.err: android.security.keystore.StrongBoxUnavailableException: Failed to generate key 11-02 14:20:59.492 21845 21885 W System.err: at android.security.keystore.AndroidKeyStoreKeyGeneratorSpi.engineGenerateKey(AndroidKeyStoreKeyGeneratorSpi.java:321) 11-02 14:20:59.492 21845 21885 W System.err: at javax.crypto.KeyGenerator.generateKey(KeyGenerator.java:612) 11-02 14:20:59.492 21845 21885 W System.err: at no.aegisdynamics.habitat.util.p.a(Unknown Source:66) 11-02 14:20:59.492 21845 21885 W System.err: at no.aegisdynamics.habitat.util.p.a(Unknown Source:17) 11-02 14:20:59.492 21845 21885 W System.err: at no.aegisdynamics.habitat.e.a.a(Unknown Source:73) 11-02 14:20:59.492 21845 21885 W System.err: at no.aegisdynamics.habitat.data.c.g$10.getHeaders(Unknown Source:2) 11-02 14:20:59.492 21845 21885 W System.err: at com.a.a.a.j.a(Unknown Source:12) 11-02 14:20:59.492 21845 21885 W System.err: at com.a.a.a.c.a(Unknown Source:74) 11-02 14:20:59.492 21845 21885 W System.err: at com.a.a.i.a(Unknown Source:47) 11-02 14:20:59.492 21845 21885 W System.err: at com.a.a.i.run(Unknown Source:5) 11-02 14:20:59.492 21845 21885 W System.err: Caused by: android.security.KeyStoreException: No StrongBox available 11-02 14:20:59.492 21845 21885 W System.err: ... 10 more 11-02 14:20:59.564 21845 21845 W System.err: com.a.a.a 11-02 14:20:59.564 21845 21845 W System.err: at com.a.a.a.c.a(Unknown Source:393) 11-02 14:20:59.564 21845 21845 W System.err: at com.a.a.i.a(Unknown Source:47) 11-02 14:20:59.564 21845 21845 W System.err: at com.a.a.i.run(Unknown Source:5)

On Fri, 2 Nov 2018 at 13:10, ardevd notifications@github.com wrote:

Thanks man! Really appreciate your effort.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ardevd/habitat/issues/9#issuecomment-435345932, or mute the thread https://github.com/notifications/unsubscribe-auth/Ah7PX0E0hAn8qU8-Ml1HSW-GPtpNnTLbks5urCg_gaJpZM4XiV4J .

ardevd commented 6 years ago

That was very useful! It seems Google's new StrongBox keyprovider API has some kind of bug. It seemingly cant use StrongBox on your Pixel 2 even though the Pixel 2 has the necessary security hardware. Give the attached apk a try and I suspect it should work now.

habitat-1.1.8-nostrongbox.tar.gz

mjsambol commented 6 years ago

I'm in! It works, well done!

Can you share some more details about the suspected bug?

On Fri, 2 Nov 2018 at 15:18, ardevd notifications@github.com wrote:

That was very useful! It seems Google's new StrongBox keyprovider API has some kind of bug. It seemingly cant use StrongBox on your Pixel 2 even though the Pixel 2 has the necessary security hardware. Give the attached apk a try and I suspect it should work now.

habitat-1.1.8-nostrongbox.tar.gz https://github.com/ardevd/habitat/files/2542561/habitat-1.1.8-nostrongbox.tar.gz

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ardevd/habitat/issues/9#issuecomment-435377433, or mute the thread https://github.com/notifications/unsubscribe-auth/Ah7PX2qNw528fRb_7V4X4LFwhMQeHaGfks5urEYmgaJpZM4XiV4J .

ardevd commented 6 years ago

Awesome, cool!

Whether it's actually a bug or not is a bit unclear but there are two issues here.

Firstly, the Pixel 2 has a hardware based security module (which in the Pixel 3 is called Titan-M). It's a complete SoC with its own CPU, memory, random generator, etc that can be used for cryptographic operations. It uses the TEE to corroborates key integrity and is a pretty cool feature. With it, you can use a special keymaster called StrongBox which is more secure than the standard keystore.

For some reason, your Pixel throws a StrongBoxUnavailableException indicating that StrongBox is unavilable. I don't know why that's the case.

Secondly, the Android Keystore documentation states that the aforementioned exception will be thrown if the Strongbox keymaster is not available but it doesnt say when the exception will be thrown. Is it when you actually try go generate the key? Is it when you define the KeyGenParameterSpec? or is it when you actually attempt to encrypt/decrypt data? I've submitted a bug ticket regarding the documentation issue.

mjsambol commented 6 years ago

A bit of feedback about first impressions with the app, let me know if there's a better channel for this:

My main motivation for switching to this from the official Z-way app is support for non-admin users, which seems broken in the official app. Seems to work fine in Habitat as far as visibility of rooms, devices, events and modules, so well done. However, it looks like a non-admin user can restart the controller! That doesn't seem right.

There's an interesting looking "Automation" section in the app which is also lacking in the official one, but I can't find any information about how to use it. Specifically, what are legitimate input values for the Command section?

On Fri, 2 Nov 2018 at 15:31, Moshe Sambol moshe.sambol@gmail.com wrote:

I'm in! It works, well done!

Can you share some more details about the suspected bug?

On Fri, 2 Nov 2018 at 15:18, ardevd notifications@github.com wrote:

That was very useful! It seems Google's new StrongBox keyprovider API has some kind of bug. It seemingly cant use StrongBox on your Pixel 2 even though the Pixel 2 has the necessary security hardware. Give the attached apk a try and I suspect it should work now.

habitat-1.1.8-nostrongbox.tar.gz https://github.com/ardevd/habitat/files/2542561/habitat-1.1.8-nostrongbox.tar.gz

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ardevd/habitat/issues/9#issuecomment-435377433, or mute the thread https://github.com/notifications/unsubscribe-auth/Ah7PX2qNw528fRb_7V4X4LFwhMQeHaGfks5urEYmgaJpZM4XiV4J .

ardevd commented 6 years ago

Feedback is always appreciated. Should probably be its own issue instead of merged into this one, but I will go ahead and answer here anyway.

I havent used the app much with non-admin users to be honest but that's something I'll look into to. Are you saying that non-admin users cannot restart the controller? I'll test it on my end and see what happens. If it's not possible I will indicate as much in the app and disable the action for non-admin users. If it is possible, then its something that would need to be fixed in the Z-way API.

The automation engine currently requires you to manually input the commands you want to fire. Different device types support different commands and since I havent implemented a command-picker system yet you're left with manual entry. I will look into improving this aspect in the very near future and at the very list let you easily look up supported commands. But basically, binary switch devices supports commands such as 'on'and 'off', locks support 'open' and 'close'and thermostats can be set using 'exact?level=15.0' for 15 degrees.

ardevd commented 6 years ago

I will go ahead and close this issue but please feel free to submit more issues and/or any questions you might have. Since I'm the only developer it's hard to accommodate devices and use cases I havent encountered myself so feedback from users like yourself is the only way to get those kind of things fixed and improved. So consider it your chance to get a developer to make your life easier for free :)

blakejrobinson commented 6 years ago

Been on vacation but just had a chance to try the latest .gz you posted. All working great now for me too - I can log in and control the house again. Thanks for taking the time to investigate and fix!

ardevd commented 6 years ago

Hi there.

No need to use the posted apk. I pushed out a new update on Google Play today so get the app from there and you should be all set :)

Thanks for reporting the issue.