Android Networking Exception: Connection reset by peer - java

I have an Android application where I connect frequently to a web service that I control using SSL exclusively. The first thing a user does that results in network activity is login and I currently use the Ion library for this although I tend to think my issue is not specific to Ion. This works as expected except for one specific user that has limited all internet access on the Android device to only work with my web service. They have done this by using their router to create a firewall that blocks all traffic except the specified domains. When this firewall is turned on they can't login via the app because of the following error:
java.net.SocketException
recvfrom failed: ECONNRESET (Connection reset by peer)
They can use the browser to go to my website and access the same web service with the firewall turned on and everything works fine. In addition, they can turn the firewall off, login successfully (i.e. successfully initial the first connection), turn it back on and subsequent network connections continue to work. The user can even log off and log back in without issue. It continues to work with the filter on until they quit the app. When they then restart the app and try to login the error returns. This seems like very odd behavior and I'm not entirely sure it is an ion issue but I'm not sure what to do. Does anyone have any ideas on what could be causing this issue?
UPDATE:
Per a comment, I tested my application with Volley. It does appear that Volley works with the filter turned on. I would prefer to stick with Ion though due to some of its other feature so if anyone has any ideas on how to make Ion work in this scenario I would greatly appreciate the help.

Related

Access denied due to firewall policy violation

I have run into a very strange situation that I have never seen before and I could not find any relevant issues on the web into resolving my problem. The situation is the following:
When a user connected using a VPN connection to the local office network and tries to access a web application (apache tomcat / servlets / mySql) and on very specific requests the users receive an error:
Your access is
denied
Access denied due to firewall policy violation
Your issue ID for support is: 5e81fac2-1-1ae9967f-c0000000
This is how it looks like:
This error comes when a user presses a save button which performs a jQuery ajax request to the server. The error only appears so far when I have the word "find" in the ckEditor as shown above(<div>any-text find any-text</div>). When the find word is replaced everything works ok. Looking in the encoded message that is transferred it looks something like this:
Not Working:
clName=A+S+LTD&contactPerson=S+Ei&contactEmail=&contactPhone=002&problem=%3Cdiv%3Efind%3C%2Fdiv%3E%0A&subject=Support............
Working:
clName=A+S+LTD&contactPerson=S+Ei&contactEmail=&contactPhone=002&problem=%3Cdiv%3Eind%3C%2Fdiv%3E%0A&subject=Support............
clName=A+S+LTD&contactPerson=S+Ei&contactEmail=&contactPhone=002&problem=%3Cdiv%3Efxnd%3C%2Fdiv%3E%0A&subject=Support............
clName=A+S+LTD&contactPerson=S+Ei&contactEmail=&contactPhone=002&problem=find&subject=Support............
I have this issue for two users working remotely using a VPN connection (Checkpoint end point security). On my local network when everyone else is connected the same request works fine.
Does anyone have ANY clue where this message comes from or how can it be resolved?
Thanks in advance
It seems that #chrylis-on-strike was right. The problem indeed came from the Checkpoint firewall.
It seems that the word 'find' was detected as a 'command injection' and was blocked.
The solution was to add a rule on the firewall to just detect and not block this kind of requests coming from the VPN connected clients.

com.google.firebase.FirebaseException: An internal error has occurred. [ 7: ]

I used to create accounts and connect to my application with firebase but then soon when I disconnected I couldn't create accounts. After 1h of that, I managed to create an account and when I disconnected to see if the problem was resolved, I realize that it's still there.
By doing task.getException() in case of account creation failure, I get this error:
"com.google.firebase.FirebaseException: An internal error has occurred. [7:]"
Do you have an idea of ​​the cause of the problem?
I have same problem because my internet was not active.
Make sure you have active internet connection.
If you are sure you have an active Internet connection and you are testing from an Emulator, restart your emulator and it should work. Sometimes, the emulator disconnects from the Internet and these sort of problems occur.
I had a similar issue and got the same exception and code: 7. I was calling firebaseUser.getIdToken() in a Rx stream. So while testing the apps functionality while being offline, I found that the JWT token that is returned in firebaseUser.getIdToken() had expired and was throwing said error. It has a lifetime of 1h.
So I split out my implementation to separate functions, only calling firebaseUser.getIdToken() before a authorised call, which must be done while online anyway to be sure and secure.
Without seeing any code, it seems you are signed in/keep a reference to a expired firebase token. Make sure you signed out properly from firebaseAuth before calling your "account creation" piece.
Here is how I solved the same issue: Opened a browser on my emulator, typed something and searched. After that, I came back to my app and retried to connect to firebase and everything started to work well.
The reason of the issue was probably the emulator not being able to connect to internet until I searched something in Google.
I have the same issue too.
My application crashed on offline mode/airplane mode.
getIdToken returns the current token if it has not expired. Otherwise, this will refresh the token and return a new one, more info here
In my case, I called the getIdToken like this getIdToken(true) which means I force refresh regardless of token expiration.
In my case call, getIdToken(false) like this solves the issue.
I have tested the offline mode/airplane mode and it works great.

Android AWS Cognito: unable to resolve host

I am having difficulty getting Cognito registration and login to work for my app in Android Studio using this sample. When I attempt to log in via the simulator, the app works for a few seconds, then displays an error message: "Unable to execute HTTP request: Unable to resolve host 'cognito-idp.us-east-1.amazonaws.com': No address associated with hostname". This same error is the only error that appears in the console. I have seen similar questions and tried solutions such as checking to ensure my app has the permissions android.permission.INTERNET and android.permission.ACCESS_NETWORK_STATE, but the error persists. It also doesn't seem to be a network issue. I have updated to the latest version of the Android SDK as well as the AWS SDK, and the problem persists.
I currently I have a Cognito user pool set up which works properly for login on the iOS version of my app. Following the instructions in the readme for the sample code, I added an app to my existing user pool, and then copied and pasted the newly generated app client ID and app client secret into AppHelper.java for clientId and clientSecret respectively. I also set userPoolId to the ID listed for my user pool under "pool details" in the Cognito conosle, and cognitoRegion to US East, since this is the region of my user pool. I noticed that there was no need for me to set the pool name, as there was in the iOS version, so I'm wondering if that's something I need to do.
Sorry if this counts as a duplicate, but I wanted to post a question with the exact error message I encountered and the steps I took, and I'm wondering if someone has managed to get this specific sample working and what I should do.
The problem has been resolved, but unfortunately I'm not quite sure what fixed it since I didn't change anything in the code. All I did was install an update, so anyone with a similar problem should probably ensure that all SDKs used in the sample are properly updated, along with the simulator. It's also worth noting that I was using a different network than in my previous tests, so it's possible that it was a network issue after all.
I had the same issue.
The issue occurred when I used a VPN with emulator to test my program. The reason was that the internet connection in the emulator was too slow when connecting through a VPN.
This could also happen if your internet connection is not strong enough.
The solution is, use a real android device to test your code, if your internet connection is not good enough.
More info: https://github.com/aws-amplify/aws-sdk-android/issues/567

How to simulate different server responses, including offline?

An app I am working on relies on connecting to a private, remote server to login via an API.
The other day, I got an ANR message and I think it was due to the server being offline (its a Windows Server that was being updated).
In my app, I am using the following code:
new ReadJSONFeedTask().execute(url).get();
Which turns an AsyncTask into a synchronous task (I believe!)
And because the server was offline, I think the app got hung up, causing the ANR (it's my only lead at the moment, and all seems to make sense, despite the code above is inside a Service class, which shouldn't cause an ANR, should it?)
So, I want to try an simulate the server being offline. I tried replacing the URL with one that simply doesn't work, by removing some letters from the hostname, but that only triggered an "UnknownHostException".
Is there any way to achieve this kind of simulation? I know there are tools for browsers to simulate low bandwidth etc, but have no idea what could be done when my app is running on Android and is trying to connect to a remote server that I can't really reboot at will.

Why am I getting a UnknownHostException?

I'm trying to instantiate an URL object (in Java) with the address: http://www.cornellrams.com/rss.php. It gives me an UnknownHostException. The site is live and well, but I can't access the feed. Any ideas why it doesn't like me? This is on Android. I do have the internet permission in the manifest.
May be firewall is blocking network connection for the emulator. You need to set /allow emulator to use network connection and also set network connection sharing.
Double check the url ... chances are there's a typo in it somewhere. If not then DNS issue, but you can access the web browser ... so unlikely if you can browse.
Ensure you are using the correct protocol i.e http/https depending on whether you are using ssl
I often get issues with the wifi on my samsung gadgets. not sure what it is perhaps a request gets stuck so I'm forced to turn wifi off then back on again ... it happens a lot (especially with twitter app).
Also make sure that your timeout's are generous especially if using 3g rather than wifi.
I faced same problem once with my emulator. Restarting the emulator helped (maybe also with cleaning build).

Categories