B4J Question InitializeSSLAcceptAll not allowed in B4J?

gpa

Member
Licensed User
Longtime User
Hi...

I modified the b4j network example to use SSL - as clip below.
Compiling gets the error:
"Error description: Unknown member: initializesslacceptall"

Is this unsupported in b4j? Or is there another way to do it?

Thanks!


B4X:
Sub btnConnect_Action
    Dim m As Matcher = Regex.Matcher("(\d+\.\d+\.\d+\.\d+):(\d+)", txtServerIP.Text)
    If m.Find Then
        CloseExistingConnection
        Dim c As Socket
'        c.Initialize("client")
        c.InitializeSSLAcceptAll("client")
        c.Connect(m.Group(1), m.Group(2), 10000)
        Wait For Client_Connected (Successful As Boolean)
        If Successful Then
            NewConnection(c)
        End If
    Else
        fx.Msgbox(MainForm, "Invalid address", "")
    End If
End Sub
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
 
Upvote 0

gpa

Member
Licensed User
Longtime User
It works fine but as soon as the line "Return Factory" executes, the following warnings occur:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by anywheresoftware.b4j.object.JavaObject (file:/C:/Program%20Files%20(x86)/Anywhere%20Software/B4J/Libraries/JavaObject.jar) to method sun.security.ssl.SSLSocketFactoryImpl.createSocket()
WARNING: Please consider reporting this to the maintainers of anywheresoftware.b4j.object.JavaObject
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

Any thoughts?

B4X:
Private Sub CreateTrustAllSSLSocket (EventName As String) As Socket
   Dim socket As Socket
   socket.Initialize(EventName)
   Dim jo As JavaObject = socket
   jo.SetField("socket", CreateTrustAllSSLSocketFactory.RunMethod("createSocket", Null))
   Return socket
End Sub

Sub CreateTrustAllSSLSocketFactory As JavaObject
   Dim tm As CustomTrustManager
   tm.InitializeAcceptAll
   Dim SSLContext As JavaObject
   SSLContext = SSLContext.InitializeStatic("javax.net.ssl.SSLContext").RunMethod("getInstance", Array("TLS"))
   SSLContext.RunMethod("init", Array(Null, tm, Null))
   Dim Factory As JavaObject = SSLContext.RunMethod("getSocketFactory", Null)
   Return Factory
End Sub
Usage:
 
Upvote 0
Top