SSL handshake Exception on App viewed from other countries.

My application is available for many countries. But which application does not work. this gives an exception and an SSL acknowledgment timeout exception. This only happens for a few countries, such as Saudi Arabia, Bahrain, the Vatican City, etc.

W/System.err: javax.net.ssl.SSLException: Connection closed by peer
W/System.err:     at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
W/System.err:     at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:406)
W/System.err:     at com.android.okhttp.Connection.upgradeToTls(Connection.java:146)
W/System.err:     at com.android.okhttp.Connection.connect(Connection.java:107)
W/System.err:     at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:294)
W/System.err:     at com.android.okhttp.internal.http.HttpEngine.sendSocketRequest(HttpEngine.java:255)
W/System.err:     at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:206)
W/System.err:     at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:345)
W/System.err:     at com.android.okhttp.internal.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:89)
W/System.err:     at com.android.okhttp.internal.http.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:161)

My Java Api Client Code

    connection = (HttpURLConnection) url.openConnection();

    connection.setRequestMethod(request.getRequestType());

    if (request.getHeaders() != null) {
        Boolean usApkTest = mSharedPreferencesManager.getUsApkTest();
        if (usApkTest) {
            request.getHeaders().put("COUNTRY", "US");
        }
        setConnectionHeaders(connection, request.getHeaders());
    }

    if (request.getBody() != null) {
        connection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
        JSONObject body;
        body = new JSONObject(request.getBody());
        OutputStreamWriter wr = new OutputStreamWriter(connection.getOutputStream());
        wr.write(body.toString());
        wr.close();
    } else if (request.getBodyJson() != null) {
        connection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
        OutputStreamWriter wr = new OutputStreamWriter(connection.getOutputStream());
        wr.write(request.getBodyJson().toString());
        wr.close();
    }

    connection.setReadTimeout(request.getRequestTimeout());
    connection.connect();

    responseCode = connection.getResponseCode();
    Logger.v("RESPONSE CODE", "RESPONSE CODE: " + responseCode);

    stringBuilder = new StringBuilder();
    String line = null;

    if (responseCode == 401 || responseCode == 422 || responseCode == 404 || responseCode == 403) {
        if (connection.getErrorStream() != null)
            reader = new BufferedReader(new InputStreamReader(connection.getErrorStream()));
    } else
        reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));

    while ((line = reader.readLine()) != null) {
        stringBuilder.append(line + "\n");
    }

Does anyone have any idea why this is happening.

I also came across one link https://www.reddit.com/r/Android/comments/p0y97/it_sucks_to_be_an_android_user_in_saudi_arabia/ Anyway, is this related to my problem?

+4
source share

All Articles