Skip to content

Commit 975401d

Browse files
committed
fix: add handling for MD5 on new MySQL and deprecate MD5 SQL function
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent 6147156 commit 975401d

3 files changed

Lines changed: 24 additions & 7 deletions

File tree

build/psalm-baseline.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,6 +1420,11 @@
14201420
<code><![CDATA[getUsersForUserValue]]></code>
14211421
</DeprecatedMethod>
14221422
</file>
1423+
<file src="apps/files/lib/Command/RepairTree.php">
1424+
<DeprecatedMethod>
1425+
<code><![CDATA[md5]]></code>
1426+
</DeprecatedMethod>
1427+
</file>
14231428
<file src="apps/files/lib/Command/Scan.php">
14241429
<DeprecatedMethod>
14251430
<code><![CDATA[listen]]></code>
@@ -3236,6 +3241,11 @@
32363241
<code><![CDATA[$this->request->server]]></code>
32373242
</NoInterfaceProperties>
32383243
</file>
3244+
<file src="core/Migrations/Version24000Date20211230140012.php">
3245+
<DeprecatedMethod>
3246+
<code><![CDATA[md5]]></code>
3247+
</DeprecatedMethod>
3248+
</file>
32393249
<file src="core/Migrations/Version25000Date20220515204012.php">
32403250
<DeprecatedConstant>
32413251
<code><![CDATA[Types::JSON]]></code>

lib/private/Setup/MySQL.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
namespace OC\Setup;
1010

11-
use Doctrine\DBAL\Platforms\MySQL80Platform;
1211
use Doctrine\DBAL\Platforms\MySQL84Platform;
1312
use OC\DatabaseSetupException;
1413
use OC\DB\ConnectionAdapter;
@@ -30,6 +29,19 @@ public function setupDatabase(): void {
3029
$connection = $this->connect(['dbname' => null]);
3130
}
3231

32+
// for MD5 support
33+
if ($connection->getDatabasePlatform() instanceof MySQL84Platform) {
34+
$statement = $connection->prepare("SHOW VARIABLES LIKE 'version';");
35+
$result = $statement->executeQuery();
36+
$row = $result->fetchAssociative();
37+
$version = $row['Value'];
38+
[$major, ] = explode('.', strtolower($version));
39+
if ((int)$major >= 9) {
40+
$statement = $connection->prepare("INSTALL COMPONENT 'file://component_classic_hashing';");
41+
$statement->executeStatement();
42+
}
43+
}
44+
3345
if ($this->tryCreateDbUser) {
3446
$this->createSpecificUser('oc_admin', new ConnectionAdapter($connection));
3547
}
@@ -103,12 +115,6 @@ private function createDBUser(IDBConnection $connection): void {
103115
$connection->executeStatement($query, [$name,$password]);
104116
$query = "CREATE USER ?@'%' IDENTIFIED WITH caching_sha2_password BY ?";
105117
$connection->executeStatement($query, [$name,$password]);
106-
} elseif ($connection->getDatabasePlatform() instanceof Mysql80Platform) {
107-
// TODO: Remove this elseif section as soon as MySQL 8.0 is out-of-support (after April 2026)
108-
$query = "CREATE USER ?@'localhost' IDENTIFIED WITH mysql_native_password BY ?";
109-
$connection->executeStatement($query, [$name,$password]);
110-
$query = "CREATE USER ?@'%' IDENTIFIED WITH mysql_native_password BY ?";
111-
$connection->executeStatement($query, [$name,$password]);
112118
} else {
113119
$query = "CREATE USER ?@'localhost' IDENTIFIED BY ?";
114120
$connection->executeStatement($query, [$name,$password]);

lib/public/DB/QueryBuilder/IFunctionBuilder.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ interface IFunctionBuilder {
2020
*
2121
* @return IQueryFunction
2222
* @since 12.0.0
23+
* @deprecated 35.0.0 - MD5 is not considered secure anymore, thus most databases have or will drop support for this function
2324
*/
2425
public function md5($input): IQueryFunction;
2526

0 commit comments

Comments
 (0)