B4J Question [B4J] Trust all SSL Socket - Potential issue under B4J Version 9??

Bruce McGregor

Member
Licensed User
Greetings All,

The following worked perfectly when compiled under older versions of B4J, however, seems to be ineffective with current B4J Version 9. I was using it to connect to a Mosquitto MQTT broker without issue. However, I now have a situation where existing B4J MQTT Clients (compiled under older versions of B4J) are connecting to the broker BUT a new instance (exactly the same code) compiled under B4J Version 9 (today) gets rejected.

B4X:
'Depends on JavaObject and jNet or Net libraries
Sub TrustAll (mo As MqttConnectOptions)
    Dim SSLContext As JavaObject
    SSLContext = SSLContext.InitializeStatic("javax.net.ssl.SSLContext").RunMethod("getInstance", Array("TLS"))
    Dim tm As CustomTrustManager
    tm.InitializeAcceptAll
    SSLContext.RunMethod("init", Array(Null, tm, Null))
    Dim jmo As JavaObject = mo
    jmo.RunMethod("setSocketFactory", Array(SSLContext.RunMethod("getSocketFactory", Null)))
End Sub

Has anyone else noticed this? Any ideas as to how to rectify or prove otherwise??

Open to any/all suggestions. I may well be entirely wrong in relation to this so apologies in advance!

Thank you.
 

Bruce McGregor

Member
Licensed User
Java versions have remained the same. B4J Code has remained the same. Self-signed certificate has remained the same.

However, I'm now seeing the following when MQTT connects, it throws this error which I've never seen before:

java.security.cert.CertificateWxception: No name matching localhost found

As previously stated, from what I've observed, this has only started happening after upgrading to B4J Version 9.00

Any ideas anyone?
 
Upvote 0

Bruce McGregor

Member
Licensed User
I just tried it with version 8.50 and it connected to the Mosquitto broker first time as expected. I have not changed anything other than rolling back to Version 8.50. I'll try it now with 8.9. Thank you.
 
Upvote 0

Bruce McGregor

Member
Licensed User
I downloaded 8.9 from your link - thank you - and my code connected to the Mosquitto broker as expected (correctly, first time). So, from what I've observed, my code successfully connects to the external broker on B4J versions 8.5 and 8.9, but not on V9.0. If its not related to the B4J version - I'm totally confused (however, that's not a new thing). Any assistance appreciated. Thank you.
 
Upvote 0
Top