B4J Question [SOLVED] Exception on CreateTrustAllSSLSocket

CaptKronos

Active Member
Licensed User
Longtime User
I'm trying to create an SSL socket that doesn't verify the server certificate, so have followed the approach described here: https://www.b4x.com/android/forum/threads/b4x-trust-all-ssl-socket.101952. Namely:
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
However, I am getting the following exception on the "Return Factory" line.
B4X:
Error occurred on line: 583 (IMAP)
java.lang.IllegalAccessException: class anywheresoftware.b4j.object.JavaObject cannot access class sun.security.ssl.SSLSocketFactoryImpl (in module java.base) because module java.base does not export sun.security.ssl to unnamed module @54c0a14e
    at java.base/jdk.internal.reflect.Reflection.newIllegalAccessException(Reflection.java:420)
    at java.base/java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:709)
    at java.base/java.lang.reflect.Method.invoke(Method.java:569)
    at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:132)
    at uk.cyferltd.touchaccounts.imap._createtrustallsslsocket(imap.java:3315)
I haven't yet got to the point of creating a standalone pakage, but have added the line:
B4X:
 #PackagerProperty: VMArgs = --add-opens java.base/sun.security.ssl=b4j
I think it might be related to the warning described here https://www.b4x.com/android/forum/t...ceptall-not-allowed-in-b4j.129047/post-810467 and at that time the advice was to ignore the warning. Perhaps we can no longer ignore the warning, or am I doing something wrong?
 
Solution
Have you tried
B4X:
#VirtualMachineArgs: --add-opens java.base/sun.security.ssl=ALL-UNNAMED

(Despite appearances there is no space between ALL and -UNNAMED)

stevel05

Expert
Licensed User
Longtime User
Have you tried
B4X:
#VirtualMachineArgs: --add-opens java.base/sun.security.ssl=ALL-UNNAMED

(Despite appearances there is no space between ALL and -UNNAMED)
 
Last edited:
Upvote 1
Solution