Skip to content

Commit

Permalink
GUACAMOLE-1979: Allow setting required properties for connecting to M…
Browse files Browse the repository at this point in the history
…ySQL 8.4 and later.
  • Loading branch information
jmuehlner committed Aug 22, 2024
1 parent 3310272 commit 7a66ec9
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ public MySQLAuthenticationProviderModule(MySQLEnvironment environment)
myBatisProperties.setProperty("mybatis.pooled.pingEnabled", "true");
myBatisProperties.setProperty("mybatis.pooled.pingQuery", "SELECT 1");

// Set whether public key retrieval from the server is allowed
driverProperties.setProperty("allowPublicKeyRetrieval",
environment.getMYSQLAllowPublicKeyRetrieval() ? "true" : "false");

// Use UTF-8 in database
driverProperties.setProperty("characterEncoding", "UTF-8");

Expand Down Expand Up @@ -113,10 +117,22 @@ public MySQLAuthenticationProviderModule(MySQLEnvironment environment)
if (clientPassword != null)
driverProperties.setProperty("clientCertificateKeyStorePassword",
clientPassword);

// Get the MySQL-compatible driver to use.
mysqlDriver = environment.getMySQLDriver();

// Set the path to the server public key, if any
// Note that the property name casing is slightly different for MySQL
// and MariaDB drivers. See
// https://dev.mysql.com/doc/connector-j/en/connector-j-connp-props-security.html#cj-conn-prop_serverRSAPublicKeyFile
// and https://mariadb.com/kb/en/about-mariadb-connector-j/#infrequently-used-parameters
String publicKeyFile = environment.getMYSQLServerRSAPublicKeyFile();
if (publicKeyFile != null)
driverProperties.setProperty(
mysqlDriver == MySQLDriver.MYSQL
? "serverRSAPublicKeyFile" : "serverRsaPublicKeyFile",
publicKeyFile);

// If timezone is present, set it.
TimeZone serverTz = environment.getServerTimeZone();
if (serverTz != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,4 +442,35 @@ public boolean enforceAccessWindowsForActiveSessions() throws GuacamoleException
true);
}

/**
* Returns the absolute path to the public key for the server being connected to,
* if any, or null if the configuration property is unset.
*
* @return
* The absolute path to the public key for the server being connected to.
*
* @throws GuacamoleException
* If an error occurs retrieving the configuration value.
*/
public String getMYSQLServerRSAPublicKeyFile() throws GuacamoleException {
return getProperty(MySQLGuacamoleProperties.MYSQL_SERVER_RSA_PUBLIC_KEY_FILE);
}

/**
* Returns true if the database server public key should be automatically
* retrieved from the MySQL server, or false otherwise.
*
* @return
* Whether the database server public key should be automatically
* retrieved from the MySQL server.
*
* @throws GuacamoleException
* If an error occurs retrieving the configuration value.
*/
public boolean getMYSQLAllowPublicKeyRetrieval() throws GuacamoleException {
return getProperty(
MySQLGuacamoleProperties.MYSQL_ALLOW_PUBLIC_KEY_RETRIEVAL,
false);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,29 @@ private MySQLGuacamoleProperties() {}
@Override
public String getName() { return "mysql-batch-size"; }

};

};

/**
* The absolute path to the public key for the server being connected to, if any.
*/
public static final StringGuacamoleProperty MYSQL_SERVER_RSA_PUBLIC_KEY_FILE =
new StringGuacamoleProperty() {

@Override
public String getName() { return "mysql-server-rsa-public-key-file"; }

};

/**
* Whether or not the server public key should be automatically retreived from
* the MySQL server.
*/
public static final BooleanGuacamoleProperty MYSQL_ALLOW_PUBLIC_KEY_RETRIEVAL =
new BooleanGuacamoleProperty() {

@Override
public String getName() { return "mysql-allow-public-key-retrieval"; }

};

}

0 comments on commit 7a66ec9

Please sign in to comment.