Android Question https SSL error by using "okhttputils2"

Status
Not open for further replies.

youjunjer

Member
Licensed User
Longtime 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
Longtime 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?
 
Upvote 0

Jaume Guillem

Member
Licensed User
Longtime 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????
 
Upvote 0

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.
 
Upvote 0

Jaume Guillem

Member
Licensed User
Longtime 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
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime 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.
 
Upvote 0

Jaume Guillem

Member
Licensed User
Longtime 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
 
Upvote 0

BertI

Member
Licensed User
Longtime 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.
 
Upvote 0

Jaume Guillem

Member
Licensed User
Longtime 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.
 
Upvote 0

manuel_g

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.
Hi!

Did you finally figure it out? I'm getting the same problem and if I run the .php from an explorer it always works, but if I run from the app it doesn't.

Thanks
 
Upvote 0
Status
Not open for further replies.
Top