Skip to content

Commit 948736b

Browse files
committed
Merge upstream pull request AuthMe#2777
1 parent 5e54b8b commit 948736b

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

src/main/java/fr/xephi/authme/datasource/MySQL.java

+13-4
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public class MySQL extends AbstractSqlDataSource {
4141
private boolean useSsl;
4242
private boolean serverCertificateVerification;
4343
private boolean allowPublicKeyRetrieval;
44+
private String mariaDbSslMode;
4445
private String host;
4546
private String port;
4647
private String username;
@@ -121,6 +122,7 @@ private void setParameters(Settings settings, MySqlExtensionsFactory extensionsF
121122
this.useSsl = settings.getProperty(DatabaseSettings.MYSQL_USE_SSL);
122123
this.serverCertificateVerification = settings.getProperty(DatabaseSettings.MYSQL_CHECK_SERVER_CERTIFICATE);
123124
this.allowPublicKeyRetrieval = settings.getProperty(DatabaseSettings.MYSQL_ALLOW_PUBLIC_KEY_RETRIEVAL);
125+
this.mariaDbSslMode = settings.getProperty(DatabaseSettings.MARIADB_SSL_MODE);
124126
}
125127

126128
/**
@@ -145,12 +147,19 @@ private void setConnectionArguments() {
145147
ds.setDriverClassName(this.getDriverClassName());
146148

147149
// Request mysql over SSL
148-
ds.addDataSourceProperty("useSSL", String.valueOf(useSsl));
150+
if (this instanceof MariaDB) {
151+
ds.addDataSourceProperty("sslMode", mariaDbSslMode);
152+
} else {
153+
ds.addDataSourceProperty("useSSL", String.valueOf(useSsl));
154+
155+
// Disabling server certificate verification on need
156+
if (!serverCertificateVerification) {
157+
ds.addDataSourceProperty("verifyServerCertificate", String.valueOf(false));
158+
}
159+
}
160+
149161

150162
// Disabling server certificate verification on need
151-
if (!serverCertificateVerification) {
152-
ds.addDataSourceProperty("verifyServerCertificate", String.valueOf(false));
153-
} // Disabling server certificate verification on need
154163
if (allowPublicKeyRetrieval) {
155164
ds.addDataSourceProperty("allowPublicKeyRetrieval", String.valueOf(true));
156165
}

src/main/java/fr/xephi/authme/settings/properties/DatabaseSettings.java

+15-4
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,31 @@ public final class DatabaseSettings implements SettingsHolder {
3131
public static final Property<String> MYSQL_PORT =
3232
newProperty("DataSource.mySQLPort", "3306");
3333

34-
@Comment("Connect to MySQL database over SSL")
34+
@Comment({"Replacement of Mysql's useSsl (for MariaDB only).",
35+
"- disable: No SSL",
36+
"- trust: Trust blindly (no validation)",
37+
"- verify_ca: Encryption, certificates validation, BUT no hostname verification",
38+
"- verify_full: Encryption, certificate validation and hostname validation",
39+
"Read more: https://bit.ly/mariadb-sslmode"})
40+
public static final Property<String> MARIADB_SSL_MODE =
41+
newProperty("DataSource.MariaDbSslMode", "disabled");
42+
43+
@Comment({"Connect to MySQL database over SSL",
44+
"If you're using MariaDB, use sslMode instead"})
3545
public static final Property<Boolean> MYSQL_USE_SSL =
3646
newProperty("DataSource.mySQLUseSSL", true);
3747

3848
@Comment({"Verification of server's certificate.",
3949
"We would not recommend to set this option to false.",
4050
"Set this option to false at your own risk if and only if you know what you're doing"})
4151
public static final Property<Boolean> MYSQL_CHECK_SERVER_CERTIFICATE =
42-
newProperty( "DataSource.mySQLCheckServerCertificate", true );
52+
newProperty( "DataSource.mySQLCheckServerCertificate", true);
4353

4454
@Comment({"Authorize client to retrieve RSA server public key.",
45-
"Advanced option, ignore if you don't know what it means."})
55+
"Advanced option, ignore if you don't know what it means.",
56+
"If you are using MariaDB, use MariaDbSslMode instead."})
4657
public static final Property<Boolean> MYSQL_ALLOW_PUBLIC_KEY_RETRIEVAL =
47-
newProperty( "DataSource.mySQLAllowPublicKeyRetrieval", true );
58+
newProperty( "DataSource.mySQLAllowPublicKeyRetrieval", true);
4859

4960
@Comment("Username to connect to the MySQL database")
5061
public static final Property<String> MYSQL_USERNAME =

0 commit comments

Comments
 (0)