B4J Question Intermittent SSLPeerUnverifiedException: Hostname MYHOSTNAME not verified (no certificates)

gravel

Member
Licensed User
Longtime User
I've a B4J server which serves a website and is also the backend for a B4A app. The server has a LetsEncrpt cert.

I want to pull some data off the server every minute to do some offline processing away from the server.

I've a B4J app to do the download from the server and do the processing and it is intermitently, but at regular intervals, generating the following error.

B4X:
javax.net.ssl.SSLPeerUnverifiedException: Hostname MYHOSTNAME not verified (no certificates)
    at okhttp3.internal.connection.RealConnection.connectTls(RealConnection.java:337)
    at okhttp3.internal.connection.RealConnection.establishProtocol(RealConnection.java:284)
    at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:169)
    at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:258)
    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:127)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
    at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:257)
    at okhttp3.RealCall.execute(RealCall.java:93)
    at anywheresoftware.b4h.okhttp.OkHttpClientWrapper.executeWithTimeout(OkHttpClientWrapper.java:173)
    at anywheresoftware.b4h.okhttp.OkHttpClientWrapper.access$0(OkHttpClientWrapper.java:170)
    at anywheresoftware.b4h.okhttp.OkHttpClientWrapper$ExecuteHelper.run(OkHttpClientWrapper.java:218)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:834)
ResponseError. Reason: javax.net.ssl.SSLPeerUnverifiedException: Hostname MYHOSTNAME not verified (no certificates), Response:

This example code shows how I'm trying to do it, and it exhibits the problem in the same way as the actual code.

B4X:
'Non-UI application (console / server application)
#Region Project Attributes
    #CommandLineArgs:
    #MergeLibraries: True
#End Region

Sub Process_Globals
    Dim Timer1 As Timer
End Sub

Sub AppStart (Args() As String)
    Timer1.Initialize("Timer1", 60000)
    Timer1.Enabled = True
    Timer1_Tick
    StartMessageLoop
End Sub

Sub Timer1_Tick()
    DownloadUpdates
End Sub

Sub DownloadUpdates()
    Dim J1 As HttpJob
    J1.Initialize("GetIncluded", Me)
    J1.Download2("https://MYHOSTNAME/IncludedB4XRequest", Array As String("Version", "40", "Model", "Test", "Set", "1"))
    Wait For (J1) JobDone(J1 As HttpJob)
    If J1.Success Then
        Log(J1.JobName & " success")
    Else
        Log(J1.JobName & " " & J1.ErrorMessage)
    End If
    J1.Release      
End Sub

Downloading at a 15 second interval all seems OK. At 30 second intervals about 1 in 5 generates errors and at both 1 minute & 5 minute intervals I get a sequence of Success, Error, Success, Error .... etc. In all cases the first download works.

Is there something wrong in how I'm trying to do this, or what else is causing it?

The B4A app downloads which occur, typically, every 4 minutes using the same IncludedB4XRequest handler work succesfully and have done for years.
 

gravel

Member
Licensed User
Longtime User
expect failures
A 50% failure rate seems a bit much! Retrying the download after 5 secs seems successful, but I'm trying to replicate some of the functionality of a B4A app in B4J and after the download is processed, if the app has found any entities which are 'new' from the point of view of it's own processing it can make further requests to the server for more detail about the 'new' entity ... and then those fail as well ... a right old mess!

Are there any ideas about what the underlying cause might be that I can eperiement with?
 
Upvote 0
Top