Wish [SOLVED] Integrate InitializeAcceptAll into internal HttpUtils2 library

AscySoft

Active Member
Licensed User
Longtime User
UPDATE: i did change HttpUtils2Service, it's seems to work, You should test anyway
I attach my OkHttpUtils2 (vers 2.83) in this post
Put it in the internal folder, replacing the old one (but remember to mantain this code with any new installation of B4A)
screen.png


In HttpUtils2Service,bas i added
B4X:
Public AcceptAllSSLCertificates As Boolean = False
And in Service_Create I changed the folowing
B4X:
Select AcceptAllSSLCertificates
        Case False
            hc.Initialize("hc")
        Case True
            hc.InitializeAcceptAll("hc")
 End Select

Then whenever you need to send a request, just befor this line set in code
B4X:
HttpUtils2Service.AcceptAllSSLCertificates = True

So the old code below will be..


This is a common error regarding using self signed certification on my NAS.
I was trying to execute the following code
B4X:
Dim Job As HttpJob 
'Job.InitializeAcceptAll("",Me)
Job.Initialize("", Me)'
Job.Username =""
Job.Password=""
HttpUtils2Service.AcceptAllSSLCertificates=True 'addition here
Job.Download($"${NEW_APK_Location}/version.txt"$)
Wait For (Job) JobDone(Job As HttpJob)
If Job.Success Then
            Log($"Dwnl success ${Job.GetString}"$)
Else
            Log($"Err down ${Job.ErrorMessage}"$)
 End If
Job.Release
The solution is to edit the source code found here https://www.b4x.com/android/forum/threads/b4x-okhttputils2-ihttputils2-httputils2-source-code.82632/ (vers 2.70 - internal one 2.82) and integrate "InitializeAcceptAll" as instructed here https://www.b4x.com/android/forum/t...-using-self-signed-openssl.76268/#post-483974

This is a wish (not because I am lazzy) but because the internal version is newer (and always will be)
I could modify by myself, then compile into library and replace, but this will be a repetitive task with each new release.

Sugestion, please @Erel /another staff member, put a new method in this module, keep "Initialize" and put "Initialize2" whatever to support self signed certificates.

Thanks.
screen.png
 

Attachments

  • OkHttpUtils2.b4xlib
    4 KB · Views: 346
Last edited:

AscySoft

Active Member
Licensed User
Longtime User
doesn't get updated very often
Indeed, but then again, I will need to mantain the modiffication again and again. That's why is a wish, maybe you decide to update this lib accordingly next time (with this wish).
Or at least, let me do the modiffication as needed (not only by me if you's search in the forum) I'll send you the file, and you'll publish next time with the added moddification. In this way (often or not) this lib will remain maintained.
I apreciate an onest and direct answer. I will argue no more after that. Thanks for your time.
 

inakigarm

Well-Known Member
Licensed User
Longtime User
I think it's a very reasonable wish; it may seem that only adding an Iniatilize2 method that covers InitializeAcceptAll will work for self signed certificates scenarios and will keep syncronized the code's app with the library version (not with the source class code)
There're a lot of questions on Forum regarding http problems on Self Signed Certificates communications ...(https://www.b4x.com/android/forum/pages/results/?query=initializeAcceptall&page=1)
 

AscySoft

Active Member
Licensed User
Longtime User
note pleas, if you wish to use OkHttpUtils with/or without selfsigned certificates, you should download my mod from first post (2.83), I don;t know why Erel will not include this in the next release, it won't affect any previouse writen code.
 
Top