B4J Question MySQL SSL Problem on Older System

mw71

Active Member
Licensed User
Longtime User
hi and HNY,

i connect to a MySQL DB, code like
B4X:
    mysql.InitializeAsync("mysql", driver, jdbcUrl, Username, Password)
    Wait For MySQL_Ready (Success As Boolean)

on old System (Windows 7 32 Bit, B4J ?) i get an error:
B4X:
Sun Jan 01 12:41:04 CET 2023 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet successfully received from the server was 3 milliseconds ago.  The last packet sent successfully to the server was 3 milliseconds ago.
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
    at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:990)
    at com.mysql.jdbc.ExportControlled.transformSocketToSSLSocket(ExportControlled.java:201)
    at com.mysql.jdbc.MysqlIO.negotiateSSLConnection(MysqlIO.java:4914)
    at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1663)
    at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1224)
    at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2199)
    at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2230)
    at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2025)
    at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:778)
    at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
    at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:386)
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:330)
    at java.sql.DriverManager.getConnection(DriverManager.java:664)
    at java.sql.DriverManager.getConnection(DriverManager.java:247)
    at anywheresoftware.b4j.objects.SQL.Initialize2(SQL.java:56)
    at anywheresoftware.b4j.objects.SQL$1.call(SQL.java:98)
    at anywheresoftware.b4j.objects.SQL$1.call(SQL.java:1)
    at anywheresoftware.b4a.BA$4.run(BA.java:290)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:750)
Caused by: javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate)
    at sun.security.ssl.HandshakeContext.<init>(HandshakeContext.java:171)
    at sun.security.ssl.ClientHandshakeContext.<init>(ClientHandshakeContext.java:106)
    at sun.security.ssl.TransportContext.kickstart(TransportContext.java:238)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:410)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:389)
    at com.mysql.jdbc.ExportControlled.transformSocketToSSLSocket(ExportControlled.java:186)
    ... 26 more

on a newer System (Windows 10, 64 Bit, B4J 9.8) it works fine

what can i do that it works also on the older System, preferably with ssl?
 
Last edited:

aminoacid

Active Member
Licensed User
Longtime User

Hi,

Windows 7 supports TLS 1.1 and TLS 1.2. But these protocol versions are not enabled on Windows 7 by default. However, these protocols are enabled by default on Windows 8 and higher versions.

See this:


 
Upvote 0

mw71

Active Member
Licensed User
Longtime User
hi,

thanks for your answer

- Update (kb3140245) is already installed, says Windows
- EasyFix applied
- HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.1\Client and the TLS 1.2.... adds


Unfortunately this does not help

ps: is there a way to test if TLS 1.2 is enabled?
 
Upvote 0

aminoacid

Active Member
Licensed User
Longtime User

There are many ways to do test. Just google it. Here's one:

 
Upvote 0

DarkoT

Active Member
Licensed User
Hi,
have you try to initialise connection with aditional parameters like this:
B4X:
Dim dbInit As String = $"jdbc:mysql://${Main.Server}:${Main.Port}/${Main.Db}?characterEncoding=utf8;useSSL=false"$
MySql.Initialize2("com.mysql.jdbc.Driver", dbInit, Main.Username, Main.Password )

All parameters are here:
 
Upvote 0

mw71

Active Member
Licensed User
Longtime User
hi & thank you,

it dont work?, i think this Statement is not o.k. for the Server:
java.sql.SQLException: Unsupported character encoding 'utf8;useSSL=false'.
 
Upvote 0

DarkoT

Active Member
Licensed User
hi & thank you,

it dont work?, i think this Statement is not o.k. for the Server:
java.sql.SQLException: Unsupported character encoding 'utf8;useSSL=false'.
Oh, sory... replace ; with char & and this will work...
B4X:
Dim dbInit As String = $"jdbc:mysql://${Main.Server}:${Main.Port}/${Main.Db}?useSSL=false&characterEncoding=utf8"$
MySql.Initialize2("com.mysql.jdbc.Driver", dbInit, Main.Username, Main.Password )

Or you can left out characterEncoding if you don't need it...
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…