Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use sslMode on MariaDB (remove warning) #2777

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/main/java/fr/xephi/authme/datasource/MySQL.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class MySQL extends AbstractSqlDataSource {
private boolean useSsl;
private boolean serverCertificateVerification;
private boolean allowPublicKeyRetrieval;
private String sslMode;
private String host;
private String port;
private String username;
Expand Down Expand Up @@ -121,6 +122,7 @@ private void setParameters(Settings settings, MySqlExtensionsFactory extensionsF
this.useSsl = settings.getProperty(DatabaseSettings.MYSQL_USE_SSL);
this.serverCertificateVerification = settings.getProperty(DatabaseSettings.MYSQL_CHECK_SERVER_CERTIFICATE);
this.allowPublicKeyRetrieval = settings.getProperty(DatabaseSettings.MYSQL_ALLOW_PUBLIC_KEY_RETRIEVAL);
this.sslMode = settings.getProperty(DatabaseSettings.SSL_MODE);
}

/**
Expand All @@ -145,12 +147,18 @@ private void setConnectionArguments() {
ds.setDriverClassName(this.getDriverClassName());

// Request mysql over SSL
ds.addDataSourceProperty("useSSL", String.valueOf(useSsl));
if (this instanceof MariaDB) {
ds.addDataSourceProperty("sslMode", sslMode);
}else {
ds.addDataSourceProperty("useSSL", String.valueOf(useSsl));

// Disabling server certificate verification on need
if (!serverCertificateVerification) {
ds.addDataSourceProperty("verifyServerCertificate", String.valueOf(false));
}
}

// Disabling server certificate verification on need
if (!serverCertificateVerification) {
ds.addDataSourceProperty("verifyServerCertificate", String.valueOf(false));
} // Disabling server certificate verification on need
if (allowPublicKeyRetrieval) {
ds.addDataSourceProperty("allowPublicKeyRetrieval", String.valueOf(true));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,17 @@ public final class DatabaseSettings implements SettingsHolder {
public static final Property<String> MYSQL_PORT =
newProperty("DataSource.mySQLPort", "3306");

@Comment("Connect to MySQL database over SSL")
@Comment({"Replacement of Mysql's useSsl (for MariaDB only).",
"- disable: No SSL",
"- trust: Trust blindly (no validation)",
"- verify_ca: Encryption, certificates validation, BUT no hostname verification",
"- verify_full: Encryption, certificate validation and hostname validation",
"Read more: https://bit.ly/mariadb-sslmode"})
public static final Property<String> SSL_MODE =
newProperty("DataSource.sslMode", "disabled");

@Comment({"Connect to MySQL database over SSL",
"If you're using MariaDB, use sslMode instead"})
public static final Property<Boolean> MYSQL_USE_SSL =
newProperty("DataSource.mySQLUseSSL", true);

Expand All @@ -38,7 +48,8 @@ public final class DatabaseSettings implements SettingsHolder {
newProperty( "DataSource.mySQLCheckServerCertificate", true );

@Comment({"Authorize client to retrieve RSA server public key.",
"Advanced option, ignore if you don't know what it means."})
"Advanced option, ignore if you don't know what it means.",
"If you're using MariaDB, use sslMode instead"})
public static final Property<Boolean> MYSQL_ALLOW_PUBLIC_KEY_RETRIEVAL =
newProperty( "DataSource.mySQLAllowPublicKeyRetrieval", true );

Expand Down