Android Question https SSL error by using "okhttputils2"

youjunjer

Member
Licensed User
Dear all,
I need to connect to a web server for getting some data. The httpjob object worked fine before I upgrade my web server to SSL.
And now I always get the error message when httpjob connect to SSL web:
Error: javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
Any ideas will be fine for me, thank.
 

Pendrush

Well-Known Member
Licensed User
Probably certificate is some of self created/signed.
If you open your web page with web browser from your PC, do you see warning?
 

Jaume Guillem

Member
Licensed User
Following Erel instructions finally it works. But not always. It works 50% of time. And with the same behaviour in release or in debug mode. After two or three correct connections, the next one says

ResponseError. Reason: javax.net.ssl.SSLException: SSL handshake aborted: ssl=0x62b530b0: I/O error during system call, Connection reset by peer, Response:

Trying to the same address with a browser it works perfect. Is not a server problem. In my case is a commercial server (my isp provider)
Maybe a delay????
 

KMatle

Expert
Licensed User
Better: Use a server with a genuine and valid certificate. Otherwise your customers will not trust your app.
 

Semen Matusovskiy

Well-Known Member
Licensed User
First of all, it's necessary to check a root certificate. The list of trusted root certificates in Android and Windows are different.
Of course, Verisign, GlobalSign, Thawte and maybe Comodo will be in both lists, but the certificates of more young companies can be absent.

I am not completely sure in logic of OkHttp3/Okio also.
Meanwhile B4A uses enough old releases of these libraries. Probably, they already corrected bugs.
 

Jaume Guillem

Member
Licensed User
Thank you for your comments, but it really works. Only discontinuously
It is an SSL certificate purchased from the ISP provider and valid for one year.
If the problem were the certificate, it would never work.

With http has worked for a long time without any problem.
Trying https did not work until I changed okhttputils2 per code, as described by Erel.
Now it works, but 10 times I use the code, in six it works fine and in 4 it fails, giving this error:

ResponseError. Reason: javax.net.ssl.SSLException: SSL handshake aborted: ssl=0x62b530b0: I/O error during system call, Connection reset by peer, Response:

The connection is with a PHP file to extract data from MySql.
The code used to connect is:

B4X:
    Dim job As HttpJob
   Dim Valors As Map
   Valors.Initialize
   Valors.Put("p1",23)
   Valors.Put("p2",User)
   job.Initialize("Enter", Me)

  DBF="https://xxx.yyyyyy.com/test.php"  
   job.PostMultipart(DBF,Valors,Null)  
   Wait For (job) JobDone(job As HttpJob)
   If job.Success Then
       Dim Res As String
       Res = job.GetString
      
       Log(Res)
      
       Dim parser As JSONParser
       parser.Initialize(Res)
       Dim l As List
       l.Initialize
       l = parser.NextArray 'returns a list with maps
     End If
   Else
       ToastMessageShow("Error",True)  
   End If
   job.release
The same PHP accessed from a web page with https works perfectly always.

The connection from the app works, but it is not stable. My question is whether someone has had this discontinuous functioning problem or knows of any solution.

Thank you very much
 

Erel

Administrator
Staff member
Licensed User
My question is whether someone has had this discontinuous functioning problem or knows of any solution.
I never encountered such issues.
Maybe you are calling the server too frequently.

The way to solve such issues is by sleeping for a few seconds and then send the request again.
 

Jaume Guillem

Member
Licensed User
Yes, I had already thought something similar. That's why I was talking about a delay. But what intrigues me is that it is often the first connection that fails.
I will continue testing.
Thank you
 

BertI

Member
Licensed User
I don't know if it is in any way related, but I recently noticed an issue when using the webview object and https whereby on Android >=5.0 devices you get partially formed web pages and sometimes even hang ups. No problem if the same server site is demoted to using just http access and also no problem if using https access on Android 4 devices. So, if you are not doing so already, wonder if its worth trying on an Android 4 device just to see if this has any bearing.
 

Jaume Guillem

Member
Licensed User
I have tested with a samsung s4 with Android 4.4.2 and with a J5 version 7. The behavior is exactly the same.
I'm going to try another isp and another certificate.
 
Top