Skip to content
This repository was archived by the owner on Oct 18, 2024. It is now read-only.

Commit 789b692

Browse files
author
Chris Board
committed
Fix for MariaDB 10.4
Fixes issue relating to MariaDB and getting a result set
1 parent 0e5ff70 commit 789b692

File tree

12 files changed

+58
-15
lines changed

12 files changed

+58
-15
lines changed
0 Bytes
Binary file not shown.

.idea/caches/gradle_models.ser

0 Bytes
Binary file not shown.

.idea/gradle.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Android-MySQL-Connector.zip

172 KB
Binary file not shown.

AndroidMySQLConnector/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ else
2020
}
2121

2222
archivesBaseName="AndroidMySQLConnector"
23-
version '0.30'
23+
version '0.31'
2424
group 'com.BoardiesITSolutions'
2525

2626

@@ -30,8 +30,8 @@ android {
3030
//applicationId "com.BoardiesITSolutions.AndroidMySQLConnector"
3131
minSdkVersion 19
3232
targetSdkVersion 29
33-
versionCode 21
34-
versionName "0.30"
33+
versionCode 22
34+
versionName "0.31"
3535
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
3636
}
3737
buildTypes {

AndroidMySQLConnector/src/main/java/com/BoardiesITSolutions/AndroidMySQLConnector/Connection.java

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public class Connection
4141
private int port = 3306;
4242

4343
//Connection Details
44+
private boolean isMariaDB = false;
4445
private int majorVersion;
4546
private int minorVersion;
4647
private int subMinorVersion;
@@ -137,6 +138,11 @@ public Charset getCharset() {
137138
}
138139
}
139140

141+
public boolean isMariaDB()
142+
{
143+
return isMariaDB;
144+
}
145+
140146
public int getServerLanguage()
141147
{
142148
return serverLanguage;
@@ -316,6 +322,12 @@ private void processWelcomePacket() throws MySQLConnException, IOException {
316322

317323
serverVersion = mysqlIO.extractData(false);
318324

325+
if (serverVersion.contains("MariaDB"))
326+
{
327+
Log.d("MySQL Connection", "Detected Server as MariaDB");
328+
this.isMariaDB = true;
329+
}
330+
319331
//Pass the server version in to the major, minor and subminor versions - these could
320332
//be used if things need to be done differently based on the server we're connecting to
321333
parseVersionNumber();
@@ -377,6 +389,8 @@ private void processWelcomePacket() throws MySQLConnException, IOException {
377389
if (this.getMajorVersion() >= 8)
378390
{
379391
clientCapabilities &= ~CLIENT_OPTIONAL_RESULTSET_METADATA;
392+
clientCapabilities &= ~CLIENT_SSL;
393+
380394
}
381395

382396
//Check if the server is set to don't allow database.table, if so unset it so we can
@@ -435,7 +449,7 @@ private void processWelcomePacket() throws MySQLConnException, IOException {
435449
}
436450

437451
//Check if we're using TLS connection, if so we need to send an SSL Request Packet
438-
if ((Connection.this.serverCapabilities & CLIENT_SSL) == CLIENT_SSL)
452+
if ((Connection.this.serverCapabilities & CLIENT_SSL) == CLIENT_SSL && getMajorVersion() < 8)
439453
{
440454
sendSSLRequest();
441455
}
@@ -536,17 +550,22 @@ private void performSSLHandshake()
536550
List<String> allowedCiphers = null;
537551
boolean disableDHAlgorithm = true;
538552

539-
if (disableDHAlgorithm) {
540-
allowedCiphers = new ArrayList<String>();
541-
for (String cipher : sslSocket.getEnabledCipherSuites()) {
542-
if (!(disableDHAlgorithm && (cipher.indexOf("_DHE_") > -1 || cipher.indexOf("_DH_") > -1))) {
543-
allowedCiphers.add(cipher);
544-
}
553+
if (this.getMajorVersion() == 8)
554+
{
555+
disableDHAlgorithm = false;
556+
}
557+
558+
String[] enabledCipherSuites = sslSocket.getEnabledCipherSuites();
559+
560+
allowedCiphers = new ArrayList<String>();
561+
for (String cipher : enabledCipherSuites) {
562+
if (!(disableDHAlgorithm && (cipher.indexOf("_DHE_") > -1 || cipher.indexOf("_DH_") > -1))) {
563+
allowedCiphers.add(cipher);
545564
}
546565
}
547566

548567
// if some ciphers were filtered into allowedCiphers
549-
if (allowedCiphers != null) {
568+
if (allowedCiphers.size() > 0) {
550569
sslSocket.setEnabledCipherSuites(allowedCiphers.toArray(new String[0]));
551570
}
552571

AndroidMySQLConnector/src/main/java/com/BoardiesITSolutions/AndroidMySQLConnector/PacketManager/AuthResponse.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ private void createAuthenticationPacket() throws IOException
106106
if (this.mysqlConn.isConnectedVersionLessThan(5,5,0)) {
107107
dataOutPacket.writeByte(0x14);
108108
}
109+
Log.d("AuthResponse", "Length of Hash: " + password.length + " Expected: " + this.mysqlConn.getAuthPluginDataLength());
109110
dataOutPacket.write(password);
110111

111112
//The documentation states the password should be NULL terminated, however, if its null
@@ -152,10 +153,15 @@ private void createAuthenticationPacket() throws IOException
152153
for (byte b : hash1)
153154
{
154155
hash3[i] = (byte) (b ^ hash2[i++]);
156+
//hash3[i] = (byte)((int)b ^ (int)hash2[i++]);
155157
}
156-
158+
//hash3[hash3.length-1] = 0x00;
159+
Log.d("AuthResponse", "Length of Hash: " + hash3.length + " Expected: " + this.mysqlConn.getAuthPluginDataLength());
160+
dataOutPacket.writeByte(0x20);
157161
dataOutPacket.write(hash3);
158162

163+
164+
//dataOutPacket.writeByte(0);
159165
//byte[] hash1 = sha256String(password);
160166
//byte[] hash2 = sha256Bytes(hash1);
161167

AndroidMySQLConnector/src/main/java/com/BoardiesITSolutions/AndroidMySQLConnector/PacketManager/COM_QueryResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ private void processPacketData()
7575

7676
//MySQL 5.1 appears to add an extra packet between the column definitions and the rows so we'll pass
7777
//it in case we need it - don't think we do though!
78-
if (this.mysqlConn.isConnectedVersionLessThan(5,5,60))
78+
if (this.mysqlConn.isConnectedVersionLessThan(5,5,60) && !this.mysqlConn.isMariaDB())
7979
{
8080
int packetLength = this.mysqlConn.getMysqlIO().fromByteArray((byte[]) this.mysqlConn.getMysqlIO().extractData(3));
8181
int packetNumber = (byte) this.mysqlConn.getMysqlIO().extractData(1);

demoapplication/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ dependencies {
3030
implementation fileTree(dir: 'libs', include: ['*.jar'])
3131

3232
implementation 'androidx.appcompat:appcompat:1.1.0'
33-
implementation 'com.github.BoardiesITSolutions:Android-MySQL-Connector:0.30_MySQL8'
33+
implementation 'com.github.BoardiesITSolutions:Android-MySQL-Connector:0.31_MySQL8'
3434
}

demoapplication/src/main/java/com/boardiesitsolutions/demoapplication/MainActivity.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public class MainActivity extends AppCompatActivity
4747
private Button btnSaveDetails;
4848
private SharedPreferences settings;
4949
private Button btnAddRandomRecord;
50+
private Button btnSelectRecords;
5051

5152
//Create class instance of your connection. You should re-use this connection for
5253
//every action on your database.
@@ -79,6 +80,9 @@ protected void onCreate(Bundle savedInstanceState)
7980

8081
btnAddRandomRecord = findViewById(R.id.btnAddRandomRecord);
8182
btnAddRandomRecord.setOnClickListener(mBtnAddRandomRecordClickListener);
83+
84+
btnSelectRecords = findViewById(R.id.btnSelectRecords);
85+
btnSelectRecords.setOnClickListener(mBtnSelectRecordsClickListener);
8286
}
8387

8488
/**
@@ -126,7 +130,7 @@ public void actionCompleted()
126130
public void run()
127131
{
128132
Toast.makeText(MainActivity.this, "Connected to database successfully", Toast.LENGTH_SHORT).show();
129-
selectTableRecords();
133+
//selectTableRecords();
130134
}
131135
});
132136
}
@@ -228,6 +232,14 @@ public void handleException(Exception exception)
228232
}
229233
};
230234

235+
private View.OnClickListener mBtnSelectRecordsClickListener = new View.OnClickListener() {
236+
@Override
237+
public void onClick(View v)
238+
{
239+
selectTableRecords();
240+
}
241+
};
242+
231243
/**
232244
* Retrieves all records from the database and displays it
233245
*/

0 commit comments

Comments
 (0)