getting sometimes "Trust anchor for certification path not found." - android

I just use SSL connections in my android project and it works fine but sometimes I get this error:
HTTP FAILED: javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:361)
at okhttp3.internal.connection.RealConnection.connectTls(RealConnection.java:299)
at okhttp3.internal.connection.RealConnection.establishProtocol(RealConnection.java:268)
at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:160)
at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:256)
at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:134)
at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:113)
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:125)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:211)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200)
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:147)
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
Caused by: java.security.cert.CertificateException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
at com.android.org.conscrypt.TrustManagerImpl.checkTrustedRecursive(TrustManagerImpl.java:549)
at com.android.org.conscrypt.TrustManagerImpl.checkTrusted(TrustManagerImpl.java:401)
at com.android.org.conscrypt.TrustManagerImpl.checkTrusted(TrustManagerImpl.java:375)
at com.android.org.conscrypt.TrustManagerImpl.getTrustedChainForServer(TrustManagerImpl.java:304)
at android.security.net.config.NetworkSecurityTrustManager.checkServerTrusted(NetworkSecurityTrustManager.java:94)
at android.security.net.config.RootTrustManager.checkServerTrusted(RootTrustManager.java:88)
at com.android.org.conscrypt.Platform.checkServerTrusted(Platform.java:178)
at com.android.org.conscrypt.OpenSSLSocketImpl.verifyCertificateChain(OpenSSLSocketImpl.java:596)
at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:357)
... 26 more
Caused by: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
... 36 more
as you can see it says that it cannot found my certificate but it happens sometimes not all the time.
my certificate is not a self-certificate type.
can anyone help me with that

Related

Android app on Chromebook throwing dlopen failed: "/lib/x86/libwebviewchromium.so" .dynamic section header was not found

I am getting following error from users who have install my app on Intel Braswell Chromebook. I have searched for similar issue but seems like no one faced it. How do I go about debugging and solving this one?
android.util.AndroidRuntimeException: java.lang.reflect.InvocationTargetException
at android.webkit.WebViewFactory.getProvider(WebViewFactory.java:270)
at android.webkit.CookieManager.getInstance(CookieManager.java:40)
at //my app redacted
at //my app redacted
at okhttp3.JavaNetCookieJar.loadForRequest(JavaNetCookieJar.java:59)
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:84)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:126)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at //my app redacted
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:250)
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:201)
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Method.java:-2)
at android.webkit.WebViewFactory.getProvider(WebViewFactory.java:265)
at android.webkit.CookieManager.getInstance(CookieManager.java:40)
at //my app redacted
at //my app redacted
at okhttp3.JavaNetCookieJar.loadForRequest(JavaNetCookieJar.java:59)
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:84)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:126)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at //my app redacted
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:250)
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:201)
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
Caused by: at: errorCode=2
at org.chromium.base.library_loader.LibraryLoader.a(PG:54)
at org.chromium.base.library_loader.LibraryLoader.a(PG:11)
at org.chromium.android_webview.AwBrowserProcess.a(PG:15)
at com.android.webview.chromium.WebViewChromiumFactoryProvider.a(PG:79)
at com.android.webview.chromium.WebViewChromiumFactoryProvider.<init>(PG:12)
at com.android.webview.chromium.WebViewChromiumFactoryProviderForP.<init>(PG:1)
at com.android.webview.chromium.WebViewChromiumFactoryProviderForP.create(PG:1)
at java.lang.reflect.Method.invoke(Method.java:-2)
at android.webkit.WebViewFactory.getProvider(WebViewFactory.java:265)
at android.webkit.CookieManager.getInstance(CookieManager.java:40)
at //my app redacted
at //my app redacted
at okhttp3.JavaNetCookieJar.loadForRequest(JavaNetCookieJar.java:59)
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:84)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:126)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at //my app redacted
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:250)
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:201)
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
Caused by: java.lang.UnsatisfiedLinkError: dlopen failed: "/data/app/com.google.android.webview-czSKGqLMd8tXGZBl2CdlZQ==/lib/x86/libwebviewchromium.so" .dynamic section header was not found
at java.lang.Runtime.loadLibrary0(Runtime.java:1016)
at java.lang.System.loadLibrary(System.java:1669)
at org.chromium.base.library_loader.LibraryLoader.a(PG:46)
at org.chromium.base.library_loader.LibraryLoader.a(PG:11)
at org.chromium.android_webview.AwBrowserProcess.a(PG:15)
at com.android.webview.chromium.WebViewChromiumFactoryProvider.a(PG:79)
at com.android.webview.chromium.WebViewChromiumFactoryProvider.<init>(PG:12)
at com.android.webview.chromium.WebViewChromiumFactoryProviderForP.<init>(PG:1)
at com.android.webview.chromium.WebViewChromiumFactoryProviderForP.create(PG:1)
at java.lang.reflect.Method.invoke(Method.java:-2)
at android.webkit.WebViewFactory.getProvider(WebViewFactory.java:265)
at android.webkit.CookieManager.getInstance(CookieManager.java:40)
at //my app redacted
at //my app redacted
at okhttp3.JavaNetCookieJar.loadForRequest(JavaNetCookieJar.java:59)
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:84)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:126)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at //my app redacted
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:250)
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:201)
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)

How to fix connection error while fetching API? Kept crashing whenever trying to authenticate

I am doing a project that includes different modules that can sign in with different department to take logical test, and training etc etc.
However the API of the database and test is fetching from a REST API.
Currently i am facing problem connecting to the API
"Security Policy" Error whenever i try to authenticate.
Hence, now i am trying to connect to a localhost to test what is the problem and i cannot connect too.
I am beginning to wonder is it my code problem or connection problem.
Please help!
Things i already tried :
Setting internet permission in the Manifest file
Create a network_security_config.xml
This is my Connection API :
interface MyApi
{
#FormUrlEncoded
#POST("admin/42/login")
suspend fun userLogin(
#Field("adminId") empID: String,
#Field("password") password: String
) : Response<AuthResponse>
companion object
{
operator fun invoke() : MyApi
{
return Retrofit.Builder()
.baseUrl("http://localhost:8090/")
.addConverterFactory(GsonConverterFactory.create())
.build()
.create(MyApi::class.java)
}
}
}
This is my error in RED :
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.quizbeta, PID: 6407
java.net.ConnectException: Failed to connect to localhost/127.0.0.1:8090
at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.java:248)
at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:166)
at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:257)
at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:135)
at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:114)
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:126)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:254)
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:200)
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)
Caused by: java.net.ConnectException: failed to connect to localhost/127.0.0.1 (port 8090) from /127.0.0.1 (port 59329) after 10000ms: isConnected failed: ECONNREFUSED (Connection refused)
at libcore.io.IoBridge.isConnected(IoBridge.java:273)
at libcore.io.IoBridge.connectErrno(IoBridge.java:188)
at libcore.io.IoBridge.connect(IoBridge.java:130)
at java.net.PlainSocketImpl.socketConnect(PlainSocketImpl.java:129)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:356)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:357)
at java.net.Socket.connect(Socket.java:616)
at okhttp3.internal.platform.AndroidPlatform.connectSocket(AndroidPlatform.java:73)
at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.java:246)
at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:166) 
at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:257) 
at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:135) 
at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:114) 
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42) 
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) 
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121) 
at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93) 
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) 
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121) 
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93) 
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) 
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:126) 
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) 
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121) 
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:254) 
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:200) 
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636) 
at java.lang.Thread.run(Thread.java:764) 
Caused by: android.system.ErrnoException: isConnected failed: ECONNREFUSED (Connection refused)
at libcore.io.IoBridge.isConnected(IoBridge.java:262)
at libcore.io.IoBridge.connectErrno(IoBridge.java:188) 
at libcore.io.IoBridge.connect(IoBridge.java:130) 
at java.net.PlainSocketImpl.socketConnect(PlainSocketImpl.java:129) 
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:356) 
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200) 
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182) 
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:357) 
at java.net.Socket.connect(Socket.java:616) 
at okhttp3.internal.platform.AndroidPlatform.connectSocket(AndroidPlatform.java:73) 
at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.java:246) 
at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:166) 
at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:257) 
at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:135) 
at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:114) 
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42) 
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) 
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121) 
at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93) 
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) 
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121) 
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93) 
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) 
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:126) 
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) 
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121) 
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:254) 
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:200) 
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636) 
at java.lang.Thread.run(Thread.java:764) 
Process 6407 terminated.
FOR SECURITY POLICY ISSUE
There is a policy allowing only HTTPS requests as clearText support disabled in android P.
create network_security_config.xml in xml folder inside res.
eg.
res/xml/network_security_config.xml
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">Your URL</domain>
</domain-config>
</network-security-config>
now in
manifest.xml
inside application tag
add flag
android:networkSecurityConfig="#xml/network_security_config"

How to get Android Studio to recognize DoD ssl certificates

I am trying to use a government api (https://api.usno.navy.mil/rstt/oneday?date=8/8/2019&coords=48.39,-115.56&tz=-7) to get sunrise and sunset type information and I get the error java.security.cert.CertPathValidatorException: Trust anchor for certification path not found. I was having the same problems using the Chrome browser on Windows 10 until I imported the government certificates.
However, I can not figure out how to get the Android Studio emulator to recognize the certs (I will worry about my Nexus 6 device after I get everything working in the emulator).
I have a file of the government certs and have added them to Android Studio using Settings/tools/ServerCertificates. The certs I have added are DOD ID SW CA-38, DoD Root CA 2, DoD Root CA 3, and DoD Root CA 4. When I look at the certificate path on the browser, it shows DoD Root CA 3, DOD ID SW CA-38 and api.usno.navy.mil. The api.usno.navy.mil cert was issued by DOD ID SW CA-38.
I have tried setting the Server Certificates to "Accept non-trusted certificates automatically" (not my favorite option).
All were no help. I have also looked through the stackoverflow messages that seem related and did not find a solution. I am trying to not use third party apps.
Although it was not apparently needed in the browser, could there be some other certificate specifically for the api.usno.navy.mil reference?
The usno (U.S. Naval Observatory) has requested certificates that are more generally acknowledged (versus the DoD certificates), but they don't know when the administrators will provide them.
How can I get the Android Studio emulator to recognize these DoD certificates?
Any suggestions would be appreciated. Thanks.
Complete stack trace follows:
4424-4451/com.drme.weathertest W/System.err: javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
4424-4451/com.drme.weathertest W/System.err: at com.google.android.gms.org.conscrypt.ConscryptFileDescriptorSocket.startHandshake(:com.google.android.gms#13280022#13.2.80 (040700-211705629):47)
4424-4451/com.drme.weathertest W/System.err: at com.android.okhttp.internal.io.RealConnection.connectTls(RealConnection.java:192)
4424-4451/com.drme.weathertest W/System.err: at com.android.okhttp.internal.io.RealConnection.connectSocket(RealConnection.java:149)
4424-4451/com.drme.weathertest W/System.err: at com.android.okhttp.internal.io.RealConnection.connect(RealConnection.java:112)
4424-4451/com.drme.weathertest W/System.err: at com.android.okhttp.internal.http.StreamAllocation.findConnection(StreamAllocation.java:184)
4424-4451/com.drme.weathertest W/System.err: at com.android.okhttp.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:126)
4424-4451/com.drme.weathertest W/System.err: at com.android.okhttp.internal.http.StreamAllocation.newStream(StreamAllocation.java:95)
4424-4451/com.drme.weathertest W/System.err: at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:281)
4424-4451/com.drme.weathertest W/System.err: at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:224)
4424-4451/com.drme.weathertest W/System.err: at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:461)
4424-4451/com.drme.weathertest W/System.err: at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:407)
4424-4451/com.drme.weathertest W/System.err: at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:244)
4424-4451/com.drme.weathertest W/System.err: at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getInputStream(DelegatingHttpsURLConnection.java:210)
4424-4451/com.drme.weathertest W/System.err: at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getInputStream(Unknown Source:0)
4424-4451/com.drme.weathertest W/System.err: at com.drme.weatherNoaa.NetworkHelpers.getUrlBytes(NetworkHelpers.java:123)
4424-4451/com.drme.weathertest W/System.err: at com.drme.weatherNoaa.SunMoonWebRunnable.run(SunMoonWebRunnable.java:108)
4424-4451/com.drme.weathertest W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
4424-4451/com.drme.weathertest W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
4424-4451/com.drme.weathertest W/System.err: at java.lang.Thread.run(Thread.java:764)
4424-4451/com.drme.weathertest W/System.err: Caused by: java.security.cert.CertificateException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
4424-4451/com.drme.weathertest W/System.err: at com.android.org.conscrypt.TrustManagerImpl.checkTrustedRecursive(TrustManagerImpl.java:646)
4424-4451/com.drme.weathertest W/System.err: at com.android.org.conscrypt.TrustManagerImpl.checkTrusted(TrustManagerImpl.java:495)
4424-4451/com.drme.weathertest W/System.err: at com.android.org.conscrypt.TrustManagerImpl.checkTrusted(TrustManagerImpl.java:418)
4424-4451/com.drme.weathertest W/System.err: at com.android.org.conscrypt.TrustManagerImpl.getTrustedChainForServer(TrustManagerImpl.java:339)
4424-4451/com.drme.weathertest W/System.err: at android.security.net.config.NetworkSecurityTrustManager.checkServerTrusted(NetworkSecurityTrustManager.java:94)
4424-4451/com.drme.weathertest W/System.err: at android.security.net.config.RootTrustManager.checkServerTrusted(RootTrustManager.java:88)
4424-4451/com.drme.weathertest W/System.err: at java.lang.reflect.Method.invoke(Native Method)
4424-4451/com.drme.weathertest W/System.err: at com.google.android.gms.org.conscrypt.Platform.checkTrusted(:com.google.android.gms#13280022#13.2.80 (040700-211705629):2)
4424-4451/com.drme.weathertest W/System.err: at com.google.android.gms.org.conscrypt.Platform.checkServerTrusted(:com.google.android.gms#13280022#13.2.80 (040700-211705629):1)
4424-4451/com.drme.weathertest W/System.err: at com.google.android.gms.org.conscrypt.ConscryptFileDescriptorSocket.verifyCertificateChain(:com.google.android.gms#13280022#13.2.80 (040700-211705629):5)
4424-4451/com.drme.weathertest W/System.err: at com.google.android.gms.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
4424-4451/com.drme.weathertest W/System.err: at com.google.android.gms.org.conscrypt.NativeSsl.doHandshake(:com.google.android.gms#13280022#13.2.80 (040700-211705629):8)
4424-4451/com.drme.weathertest W/System.err: at com.google.android.gms.org.conscrypt.ConscryptFileDescriptorSocket.startHandshake(:com.google.android.gms#13280022#13.2.80 (040700-211705629):15)
4424-4451/com.drme.weathertest W/System.err: ... 18 more

Retrofit2 async task error even when using enqueue

so i'm getting a crash on this app i'm building every-time i try to upload a photo to the server. heres the error message
android.os.NetworkOnMainThreadException
at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1303)
at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:86)
at java.net.Inet6AddressImpl.lookupAllHostAddr(Inet6AddressImpl.java:74)
at java.net.InetAddress.getAllByName(InetAddress.java:752)
at okhttp3.Dns$1.lookup(Dns.java:40)
at okhttp3.internal.connection.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:185)
at okhttp3.internal.connection.RouteSelector.nextProxy(RouteSelector.java:149)
at okhttp3.internal.connection.RouteSelector.next(RouteSelector.java:84)
at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:214)
at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:135)
at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:114)
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:126)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:212)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200)
at okhttp3.RealCall.execute(RealCall.java:77)
at retrofit2.OkHttpCall.execute(OkHttpCall.java:180)
at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall.execute(ExecutorCallAdapterFactory.java:91)
at com.quantamfig.docuflow.SubmitActivity.postValuesRetro(SubmitActivity.java:274)
at com.quantamfig.docuflow.SubmitActivity$2.onClick(SubmitActivity.java:206)
at android.view.View.performClick(View.java:5647)
at android.view.View$PerformClick.run(View.java:22465)
at android.os.Handler.handleCallback(Handler.java:754)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:163)
at android.app.ActivityThread.main(ActivityThread.java:6228)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
as you can see, im getting a NetworkonMainThreadExeption error () even though im running the code asynchronously using enqueue.Please someone help me figure this out
so the problem was, i was trying to log a call Object method(callObj.execute) outside the enqeue and therefore on the main thread. i took it out and it worked.

How to support TLS 1.0 with okhttp in android 4.4 to 5.0

I am using the source code to connect the website with https://
I am using this code:
client = new OkHttpClient.Builder().connectTimeout(30, TimeUnit.SECONDS).writeTimeout(3600, TimeUnit.SECONDS).readTimeout(3600, TimeUnit.SECONDS).build();
but it will send back this result:
W: javax.net.ssl.SSLHandshakeException: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0xb8b214a0: Failure in SSL library, usually a protocol error
error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure (external/openssl/ssl/s23_clnt.c:741 0x84dcb770:0x00000000)
at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:448)
at okhttp3.internal.connection.RealConnection.connectTls(RealConnection.java:302)
at okhttp3.internal.connection.RealConnection.establishProtocol(RealConnection.java:270)
at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:162)
at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:257)
at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:135)
at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:114)
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:126)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200)
I am using the Android 4.4 with okhttp 3.10.0

Categories

Resources