diff --git a/CHANGELOG.md b/CHANGELOG.md index 9289665..3f67f24 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,9 +6,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] ### Added -- SHA512 Whirlpool hashing algorithm -- phpass hashing implementation +- SHA512 Whirlpool hash algorithm +- WoltLab Community Framework 2.x hash algorithm +- phpass hash implementation - Support for salt column +- User quota synchronization + +### Changed +- Example SQL script in README file +- Fixed misspelling ### Changed - Support for Nextcloud 14 only @@ -18,18 +24,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Fixed - Table and column autocomplete in settings panel -## [4.0.0-rc2] +## [4.0.0-rc2] - 2018-06-14 ### Added - User active column ### Changed - Fixed "Use of undefined constant" error for Argon2 Crypt with PHP below 7.2. -## [4.0.0-rc1] +## [4.0.0-rc1] - 2018-06-13 ### Added -- New hashing algorithms: Argon2 Crypt (PHP 7.2 and above), Blowfish Crypt, Courier base64-encoded MD5, Courier base64-encoded SHA1, - Courier base64-encoded SHA256, Courier hexadecimal MD5, Extended DES Crypt, SHA256 Crypt, - SHA512 Crypt, SSHA512, Standard DES Crypt +- New hash algorithms: Argon2 Crypt (PHP 7.2 and above), Blowfish Crypt, Courier base64-encoded MD5, Courier base64-encoded SHA1, Courier base64-encoded SHA256, Courier hexadecimal MD5, Extended DES Crypt, SHA256 Crypt, SHA512 Crypt, SSHA512, Standard DES Crypt - Option to allow users to change their display names - Option to allow user to change its avatar - Database query results cache @@ -40,10 +44,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - The whole core implementation, which is NOT COMPATIBLE with the previous versions. - Minimum supported PHP version - 7.0 -## Removed -- MySQL ENCRYPT() hashing implementation - Function is deprecated as of MySQL 5.7.6 and will be removed in a future MySQL release. -- MySQL PASSWORD() hashing implementation - Function is deprecated as of MySQL 5.7.6 and will be removed in a future MySQL release. -- Redmine hashing implementation - Cannot implement in new core system. +### Removed +- MySQL ENCRYPT() hash implementation - Function is deprecated as of MySQL 5.7.6 and will be removed in a future MySQL release. +- MySQL PASSWORD() hash implementation - Function is deprecated as of MySQL 5.7.6 and will be removed in a future MySQL release. +- Redmine hash implementation - Cannot implement in new core system. - User active column - Use database view instead - Domain support diff --git a/README.md b/README.md index 82bfc17..92b63f3 100644 --- a/README.md +++ b/README.md @@ -50,8 +50,9 @@ Name | Description | Details **Allow display name change** | With this option enabled user can change its display name. The display name change is propagated to the database. | Optional.
Default: false.
Requires: user *Display name* column. **Allow password change** | Can user change its password. The password change is propagated to the database. See [Hash algorithms](#hash-algorithms). | Optional.
Default: false. **Use cache** | Use database query results cache. The cache can be cleared any time with the *Clear cache* button click. | Optional.
Default: false. -**Hashing algorithm** | How users passwords are stored in the database. See [Hash algorithms](#hash-algorithms). | Mandatory. -**Email sync** | Sync e-mail address with the Nextcloud.
- *None* - Disables this feature. This is the default option.
- *Synchronise only once* - Copy the e-mail address to the Nextcloud storage if its not set.
- *Nextcloud always wins* - Always copy the e-mail address to the database. This updates the user table.
- *SQL always wins* - Always copy the e-mail address to the Nextcloud storage. | Optional.
Default: *None*.
Requires: user *Email* column. +**Hash algorithm** | How users passwords are stored in the database. See [Hash algorithms](#hash-algorithms). | Mandatory. +**Email sync** | Sync e-mail address with the Nextcloud.
- *None* - Disables this feature. This is the default option.
- *Synchronise only once* - Copy the e-mail address to the Nextcloud preferences if its not set.
- *Nextcloud always wins* - Always copy the e-mail address to the database. This updates the user table.
- *SQL always wins* - Always copy the e-mail address to the Nextcloud preferences. | Optional.
Default: *None*.
Requires: user *Email* column. +**Quota sync** | Sync user quota with the Nextcloud.
- *None* - Disables this feature. This is the default option.
- *Synchronise only once* - Copy the user quota to the Nextcloud preferences if its not set.
- *Nextcloud always wins* - Always copy the user quota to the database. This updates the user table.
- *SQL always wins* - Always copy the user quota to the Nextcloud preferences. | Optional.
Default: *None*.
Requires: user *Quota* column. **Home mode** | User storage path.
- *Default* - Let the Nextcloud manage this. The default option.
- *Query* - Use location from the user table pointed by the *home* column.
- *Static* - Use static location. The `%u` variable is replaced with the username of the user. | Optional
Default: *Default*. **Home Location** | User storage path for the `static` *home mode*. | Mandatory if the *Home mode* is set to `Static`. @@ -64,11 +65,12 @@ Name | Description | Details **Table name** | The table name. | Mandatory for user backend. **Username** | Username column. | Mandatory for user backend. **Email** | E-mail column. | Mandatory for *Email sync* option. +**Quota** | Quota column. | Mandatory for *Quota sync* option. **Home** | Home path column. | Mandatory for `Query` *Home sync* option. **Password** | Password hash column. | Mandatory for user backend. **Display name** | Display name column. | Optional. **Active** | Flag indicating if user can log in. | Optional.
Default: true. -**Can change avatar** | Flag indicating if user can change its avatar. | Optional.
Default: false. +**Provide avatar** | Flag indicating if user can change its avatar. | Optional.
Default: false. **Salt** | Salt which is appended to password when checking or changing the password. | Optional. #### Group table @@ -106,36 +108,34 @@ but be aware that some functionalities requires data changes (update queries). If you don't have any database model yet you can use below tables (MySQL): ``` -CREATE TABLE sql_users +CREATE TABLE sql_user ( - id INT AUTO_INCREMENT PRIMARY KEY, - username VARCHAR(16) NOT NULL, - display_name TEXT NULL, - email TEXT NULL, - home TEXT NULL, - password TEXT NOT NULL, - active TINYINT(1) NOT NULL DEFAULT '1', - can_change_avatar BOOLEAN NOT NULL DEFAULT FALSE, - CONSTRAINT users_username_uindex UNIQUE (username) + username VARCHAR(16) PRIMARY KEY, + display_name TEXT NULL, + email TEXT NULL, + quota TEXT NULL, + home TEXT NULL, + password TEXT NOT NULL, + active TINYINT(1) NOT NULL DEFAULT '1', + provide_avatar BOOLEAN NOT NULL DEFAULT FALSE ); CREATE TABLE sql_group ( - id INT AUTO_INCREMENT PRIMARY KEY, - name VARCHAR(16) NOT NULL, + name VARCHAR(16) PRIMARY KEY, display_name TEXT NULL, - admin BOOLEAN NOT NULL DEFAULT FALSE, - CONSTRAINT group_name_uindex UNIQUE (name) + admin BOOLEAN NOT NULL DEFAULT FALSE ); CREATE TABLE sql_user_group ( - id INT AUTO_INCREMENT PRIMARY KEY, - group_name VARCHAR(16) NOT NULL, username VARCHAR(16) NOT NULL, - CONSTRAINT user_group_group_name_username_uindex UNIQUE (group_name, username), - INDEX user_group_group_name_index (group_name), - INDEX user_group_username_index (username) + group_name VARCHAR(16) NOT NULL, + PRIMARY KEY (username, group_name), + FOREIGN KEY (username) REFERENCES sql_user (username), + FOREIGN KEY (group_name) REFERENCES sql_group (name), + INDEX sql_user_group_username_idx (username), + INDEX sql_user_group_group_name_idx (group_name) ); ``` @@ -149,7 +149,7 @@ User table: wp_users Username column: user_login Password column: user_pass -Hashing algorithm: Unix (Crypt) or Portable PHP password +Hash algorithm: Unix (Crypt) or Portable PHP password ``` #### JHipster @@ -166,7 +166,7 @@ Password column: password_hash Email column: email Active column: activated -Hashing algorithm: Unix (Crypt) +Hash algorithm: Unix (Crypt) ``` ## Hash algorithms @@ -196,6 +196,7 @@ SHA1 | No salt supported. | 5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8 SHA512 Whirlpool | No salt supported. | a96b16ebb691dbe968b0d66d0d924cff5cf5de5e0885181d00761d87f295b2bf3d3c66187c050fc01c196ff3acaa48d3561ffd170413346e934a32280d632f2e SSHA256 | Generates 32 chars salt. | {SSHA256}+WxTB3JxprNteeovsuSYtgI+UkVPA9lfwGoYkz3Ff7hjd1FSdmlTMkNsSExyR21KM3NvNTZ5V0p4WXJMUjFzUg== SSHA512 | Generates 32 chars salt. | {SSHA512}It+v1kAEUBbhMJYJ2swAtz+RLE6ispv/FB6G/ALhK/YWwEmrloY+0jzrWIfmu+rWUXp8u0Tg4jLXypC5oXAW00IyYnRVdEZJbE9wak96bkNRVWFCYmlJNWxrdTA0QmhL +WoltLab Community Framework 2.x | Double salted bcrypt. | $2a$08$XEQDKNU/Vbootwxv5Gp7gujxFX/RUFsZLvQPYM435Dd3/p17fto02 ## Development @@ -205,7 +206,7 @@ Add a new class in the `OCA\UserSQL\Platform` namespace which extends the `Abstr Add this driver in `admin.php` template to `$drivers` variable and in method `getPlatform(Connection $connection)` of `PlatformFactory` class. -#### New hashing algorithm support +#### New hash algorithm support Create a new class in `OCA\UserSQL\Crypto` namespace which implements `IPasswordAlgorithm` interface. Do not forget to write unit tests. diff --git a/img/screenshot.png b/img/screenshot.png index d47dbd8..a8825c1 100644 Binary files a/img/screenshot.png and b/img/screenshot.png differ diff --git a/js/settings.js b/js/settings.js index c42bb4a..0a42eaf 100644 --- a/js/settings.js +++ b/js/settings.js @@ -76,7 +76,7 @@ user_sql.adminSettingsUI = function () { ); autocomplete( - "#db-table-user-column-uid, #db-table-user-column-email, #db-table-user-column-home, #db-table-user-column-password, #db-table-user-column-name, #db-table-user-column-active, #db-table-user-column-avatar, #db-table-user-column-salt", + "#db-table-user-column-uid, #db-table-user-column-email, #db-table-user-column-quota, #db-table-user-column-home, #db-table-user-column-password, #db-table-user-column-name, #db-table-user-column-active, #db-table-user-column-avatar, #db-table-user-column-salt", "/apps/user_sql/settings/autocomplete/table/user" ); diff --git a/lib/Action/EmailSync.php b/lib/Action/EmailSync.php index 3c9bc79..cded1c2 100644 --- a/lib/Action/EmailSync.php +++ b/lib/Action/EmailSync.php @@ -94,7 +94,7 @@ class EmailSync implements IUserAction $result = false; switch ($this->properties[Opt::EMAIL_SYNC]) { - case App::EMAIL_INITIAL: + case App::SYNC_INITIAL: if (empty($ncMail) && !empty($user->email)) { $this->config->setUserValue( $user->uid, "settings", "email", $user->email @@ -103,7 +103,7 @@ class EmailSync implements IUserAction $result = true; break; - case App::EMAIL_FORCE_NC: + case App::SYNC_FORCE_NC: if (!empty($ncMail) && $user->email !== $ncMail) { $user = $this->userRepository->findByUid($user->uid); if (!($user instanceof User)) { @@ -115,7 +115,7 @@ class EmailSync implements IUserAction } break; - case App::EMAIL_FORCE_SQL: + case App::SYNC_FORCE_SQL: if (!empty($user->email) && $user->email !== $ncMail) { $this->config->setUserValue( $user->uid, "settings", "email", $user->email diff --git a/lib/Action/QuotaSync.php b/lib/Action/QuotaSync.php new file mode 100644 index 0000000..7f73c9b --- /dev/null +++ b/lib/Action/QuotaSync.php @@ -0,0 +1,137 @@ + + * @author Marcin Łojewski + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +namespace OCA\UserSQL\Action; + +use OCA\UserSQL\Constant\App; +use OCA\UserSQL\Constant\Opt; +use OCA\UserSQL\Model\User; +use OCA\UserSQL\Properties; +use OCA\UserSQL\Repository\UserRepository; +use OCP\IConfig; +use OCP\ILogger; + +/** + * Synchronizes the user quota. + * + * @author Marcin Łojewski + */ +class QuotaSync implements IUserAction +{ + /** + * @var string The application name. + */ + private $appName; + /** + * @var ILogger The logger instance. + */ + private $logger; + /** + * @var Properties The properties array. + */ + private $properties; + /** + * @var IConfig The config instance. + */ + private $config; + /** + * @var UserRepository The user repository. + */ + private $userRepository; + + /** + * The default constructor. + * + * @param string $appName The application name. + * @param ILogger $logger The logger instance. + * @param Properties $properties The properties array. + * @param IConfig $config The config instance. + * @param UserRepository $userRepository The user repository. + */ + public function __construct( + $appName, ILogger $logger, Properties $properties, IConfig $config, + UserRepository $userRepository + ) { + $this->appName = $appName; + $this->logger = $logger; + $this->properties = $properties; + $this->config = $config; + $this->userRepository = $userRepository; + } + + /** + * @inheritdoc + * @throws \OCP\PreConditionNotMetException + */ + public function doAction(User $user) + { + $this->logger->debug( + "Entering QuotaSync#doAction($user->uid)", ["app" => $this->appName] + ); + + $ncQuota = $this->config->getUserValue( + $user->uid, "files", "quota", "" + ); + + $result = false; + + switch ($this->properties[Opt::QUOTA_SYNC]) { + case App::SYNC_INITIAL: + if (empty($ncQuota) && !empty($user->quota)) { + $this->config->setUserValue( + $user->uid, "files", "quota", $user->quota + ); + } + + $result = true; + break; + case App::SYNC_FORCE_NC: + if (!empty($ncQuota) && $user->quota !== $ncQuota) { + $user = $this->userRepository->findByUid($user->uid); + if (!($user instanceof User)) { + break; + } + + $user->quota = $ncQuota; + $result = $this->userRepository->save($user); + } + + break; + case App::SYNC_FORCE_SQL: + if (!empty($user->quota) && $user->quota !== $ncQuota) { + $this->config->setUserValue( + $user->uid, "files", "quota", $user->quota + ); + } + + $result = true; + break; + } + + $this->logger->debug( + "Returning QuotaSync#doAction($user->uid): " . ($result ? "true" + : "false"), + ["app" => $this->appName] + ); + + return $result; + } +} diff --git a/lib/Backend/UserBackend.php b/lib/Backend/UserBackend.php index 0955ccf..a39b8fd 100644 --- a/lib/Backend/UserBackend.php +++ b/lib/Backend/UserBackend.php @@ -23,6 +23,7 @@ namespace OCA\UserSQL\Backend; use OCA\UserSQL\Action\EmailSync; use OCA\UserSQL\Action\IUserAction; +use OCA\UserSQL\Action\QuotaSync; use OCA\UserSQL\Cache; use OCA\UserSQL\Constant\App; use OCA\UserSQL\Constant\DB; @@ -130,6 +131,14 @@ final class UserBackend extends ABackend implements $this->userRepository ); } + if (!empty($this->properties[Opt::QUOTA_SYNC]) + && !empty($this->properties[DB::USER_QUOTA_COLUMN]) + ) { + $this->actions[] = new QuotaSync( + $this->appName, $this->logger, $this->properties, $this->config, + $this->userRepository + ); + } } /** diff --git a/lib/Constant/App.php b/lib/Constant/App.php index a2973ce..e0e6b63 100644 --- a/lib/Constant/App.php +++ b/lib/Constant/App.php @@ -34,7 +34,7 @@ final class App const HOME_QUERY = "query"; const HOME_STATIC = "static"; - const EMAIL_FORCE_NC = "force_nc"; - const EMAIL_FORCE_SQL = "force_sql"; - const EMAIL_INITIAL = "initial"; + const SYNC_FORCE_NC = "force_nc"; + const SYNC_FORCE_SQL = "force_sql"; + const SYNC_INITIAL = "initial"; } diff --git a/lib/Constant/DB.php b/lib/Constant/DB.php index ce0da21..b05fc0f 100644 --- a/lib/Constant/DB.php +++ b/lib/Constant/DB.php @@ -51,6 +51,7 @@ final class DB const USER_HOME_COLUMN = "db.table.user.column.home"; const USER_NAME_COLUMN = "db.table.user.column.name"; const USER_PASSWORD_COLUMN = "db.table.user.column.password"; + const USER_QUOTA_COLUMN = "db.table.user.column.quota"; const USER_SALT_COLUMN = "db.table.user.column.salt"; const USER_UID_COLUMN = "db.table.user.column.uid"; } diff --git a/lib/Constant/Opt.php b/lib/Constant/Opt.php index 56ce8b2..a1f6617 100644 --- a/lib/Constant/Opt.php +++ b/lib/Constant/Opt.php @@ -34,5 +34,6 @@ final class Opt const HOME_MODE = "opt.home_mode"; const NAME_CHANGE = "opt.name_change"; const PASSWORD_CHANGE = "opt.password_change"; + const QUOTA_SYNC = "opt.quota_sync"; const USE_CACHE = "opt.use_cache"; } diff --git a/lib/Constant/Query.php b/lib/Constant/Query.php index f67183c..86511e0 100644 --- a/lib/Constant/Query.php +++ b/lib/Constant/Query.php @@ -39,9 +39,11 @@ final class Query const FIND_USERS = "find_users"; const SAVE_USER = "save_user"; + const EMAIL_PARAM = "email"; const GID_PARAM = "gid"; const NAME_PARAM = "name"; const PASSWORD_PARAM = "password"; + const QUOTA_PARAM = "quota"; const SEARCH_PARAM = "search"; const UID_PARAM = "uid"; } diff --git a/lib/Crypto/AbstractCrypt.php b/lib/Crypto/AbstractCrypt.php index c13e1b5..e27e957 100644 --- a/lib/Crypto/AbstractCrypt.php +++ b/lib/Crypto/AbstractCrypt.php @@ -22,8 +22,8 @@ namespace OCA\UserSQL\Crypto; /** - * Abstract Unix Crypt hashing implementation. - * The hashing algorithm depends on the chosen salt. + * Abstract Unix Crypt hash implementation. + * The hash algorithm depends on the chosen salt. * * @see crypt() * @author Marcin Łojewski @@ -52,12 +52,9 @@ abstract class AbstractCrypt extends AbstractAlgorithm } /** - * Generate a salt string for the hashing algorithm. + * Generate a salt string for the hash algorithm. * * @return string The salt string. */ - protected function getSalt() - { - return ""; - } + protected abstract function getSalt(); } diff --git a/lib/Crypto/CourierMD5.php b/lib/Crypto/CourierMD5.php index 6e8e71f..c2463e3 100644 --- a/lib/Crypto/CourierMD5.php +++ b/lib/Crypto/CourierMD5.php @@ -24,7 +24,7 @@ namespace OCA\UserSQL\Crypto; use OCP\IL10N; /** - * Courier MD5 hashing implementation. + * Courier MD5 hash implementation. * * @author Marcin Łojewski */ diff --git a/lib/Crypto/CourierMD5Raw.php b/lib/Crypto/CourierMD5Raw.php index 39fd3db..094eab3 100644 --- a/lib/Crypto/CourierMD5Raw.php +++ b/lib/Crypto/CourierMD5Raw.php @@ -24,7 +24,7 @@ namespace OCA\UserSQL\Crypto; use OCP\IL10N; /** - * Courier MD5 RAW hashing implementation. + * Courier MD5 RAW hash implementation. * * @author Marcin Łojewski */ diff --git a/lib/Crypto/CourierSHA1.php b/lib/Crypto/CourierSHA1.php index 15d2ef3..6a96a44 100644 --- a/lib/Crypto/CourierSHA1.php +++ b/lib/Crypto/CourierSHA1.php @@ -24,7 +24,7 @@ namespace OCA\UserSQL\Crypto; use OCP\IL10N; /** - * Courier SHA1 hashing implementation. + * Courier SHA1 hash implementation. * * @author Marcin Łojewski */ diff --git a/lib/Crypto/CourierSHA256.php b/lib/Crypto/CourierSHA256.php index 3bf0ed6..081cd9d 100644 --- a/lib/Crypto/CourierSHA256.php +++ b/lib/Crypto/CourierSHA256.php @@ -24,7 +24,7 @@ namespace OCA\UserSQL\Crypto; use OCP\IL10N; /** - * Courier SHA256 hashing implementation. + * Courier SHA256 hash implementation. * * @author Marcin Łojewski */ diff --git a/lib/Crypto/Crypt.php b/lib/Crypto/Crypt.php index c52be8d..c28763a 100644 --- a/lib/Crypto/Crypt.php +++ b/lib/Crypto/Crypt.php @@ -24,7 +24,7 @@ namespace OCA\UserSQL\Crypto; use OCP\IL10N; /** - * Unix Crypt hashing implementation. + * Unix Crypt hash implementation. * * @see crypt() * @author Marcin Łojewski @@ -56,4 +56,12 @@ class Crypt extends AbstractCrypt { return "Unix (Crypt)"; } + + /** + * Not used. + */ + protected function getSalt() + { + return null; + } } diff --git a/lib/Crypto/CryptArgon2.php b/lib/Crypto/CryptArgon2.php index 14efb64..ed4aafb 100644 --- a/lib/Crypto/CryptArgon2.php +++ b/lib/Crypto/CryptArgon2.php @@ -24,7 +24,7 @@ namespace OCA\UserSQL\Crypto; use OCP\IL10N; /** - * Argon2 Crypt hashing implementation. + * Argon2 Crypt hash implementation. * * @see crypt() * @author Marcin Łojewski diff --git a/lib/Crypto/CryptBlowfish.php b/lib/Crypto/CryptBlowfish.php index 8e4a35e..6e1b8a5 100644 --- a/lib/Crypto/CryptBlowfish.php +++ b/lib/Crypto/CryptBlowfish.php @@ -24,7 +24,7 @@ namespace OCA\UserSQL\Crypto; use OCP\IL10N; /** - * Blowfish Crypt hashing implementation. + * Blowfish Crypt hash implementation. * * @see crypt() * @author Marcin Łojewski diff --git a/lib/Crypto/CryptExtendedDES.php b/lib/Crypto/CryptExtendedDES.php index b09baab..d6654c4 100644 --- a/lib/Crypto/CryptExtendedDES.php +++ b/lib/Crypto/CryptExtendedDES.php @@ -24,7 +24,7 @@ namespace OCA\UserSQL\Crypto; use OCP\IL10N; /** - * Extended DES Crypt hashing implementation. + * Extended DES Crypt hash implementation. * * @see crypt() * @author Marcin Łojewski diff --git a/lib/Crypto/CryptMD5.php b/lib/Crypto/CryptMD5.php index 6ca2e3b..0211f7e 100644 --- a/lib/Crypto/CryptMD5.php +++ b/lib/Crypto/CryptMD5.php @@ -24,7 +24,7 @@ namespace OCA\UserSQL\Crypto; use OCP\IL10N; /** - * MD5 Crypt hashing implementation. + * MD5 Crypt hash implementation. * * @see crypt() * @author Marcin Łojewski diff --git a/lib/Crypto/CryptSHA256.php b/lib/Crypto/CryptSHA256.php index fad91b3..b4e2b41 100644 --- a/lib/Crypto/CryptSHA256.php +++ b/lib/Crypto/CryptSHA256.php @@ -24,7 +24,7 @@ namespace OCA\UserSQL\Crypto; use OCP\IL10N; /** - * SHA256 Crypt hashing implementation. + * SHA256 Crypt hash implementation. * * @see crypt() * @author Marcin Łojewski diff --git a/lib/Crypto/CryptSHA512.php b/lib/Crypto/CryptSHA512.php index 11f3b8f..e32238f 100644 --- a/lib/Crypto/CryptSHA512.php +++ b/lib/Crypto/CryptSHA512.php @@ -24,7 +24,7 @@ namespace OCA\UserSQL\Crypto; use OCP\IL10N; /** - * SHA512 Crypt hashing implementation. + * SHA512 Crypt hash implementation. * * @see crypt() * @author Marcin Łojewski diff --git a/lib/Crypto/CryptStandardDES.php b/lib/Crypto/CryptStandardDES.php index 7d8fa7d..bf2b4ec 100644 --- a/lib/Crypto/CryptStandardDES.php +++ b/lib/Crypto/CryptStandardDES.php @@ -24,7 +24,7 @@ namespace OCA\UserSQL\Crypto; use OCP\IL10N; /** - * Standard DES Crypt hashing implementation. + * Standard DES Crypt hash implementation. * * @author Marcin Łojewski */ diff --git a/lib/Crypto/Joomla.php b/lib/Crypto/Joomla.php index e5dd2ca..46af41c 100644 --- a/lib/Crypto/Joomla.php +++ b/lib/Crypto/Joomla.php @@ -24,7 +24,7 @@ namespace OCA\UserSQL\Crypto; use OCP\IL10N; /** - * Joomla hashing implementation. + * Joomla hash implementation. * * @author Marcin Łojewski */ diff --git a/lib/Crypto/MD5.php b/lib/Crypto/MD5.php index a4ba435..b995b9c 100644 --- a/lib/Crypto/MD5.php +++ b/lib/Crypto/MD5.php @@ -24,7 +24,7 @@ namespace OCA\UserSQL\Crypto; use OCP\IL10N; /** - * MD5 hashing implementation. + * MD5 hash implementation. * * @author Marcin Łojewski */ diff --git a/lib/Crypto/Phpass.php b/lib/Crypto/Phpass.php index 586658c..d193917 100644 --- a/lib/Crypto/Phpass.php +++ b/lib/Crypto/Phpass.php @@ -24,7 +24,7 @@ namespace OCA\UserSQL\Crypto; use OCP\IL10N; /** - * phpass hashing implementation. + * phpass hash implementation. * * @author Marcin Łojewski */ diff --git a/lib/Crypto/SHA1.php b/lib/Crypto/SHA1.php index a534212..6a1c707 100644 --- a/lib/Crypto/SHA1.php +++ b/lib/Crypto/SHA1.php @@ -24,7 +24,7 @@ namespace OCA\UserSQL\Crypto; use OCP\IL10N; /** - * SHA1 hashing implementation. + * SHA1 hash implementation. * * @author Marcin Łojewski */ diff --git a/lib/Crypto/SHA512Whirlpool.php b/lib/Crypto/SHA512Whirlpool.php index 1fd3988..4f36e9a 100644 --- a/lib/Crypto/SHA512Whirlpool.php +++ b/lib/Crypto/SHA512Whirlpool.php @@ -24,7 +24,7 @@ namespace OCA\UserSQL\Crypto; use OCP\IL10N; /** - * SHA512 Whirlpool hashing implementation. + * SHA512 Whirlpool hash implementation. * * @author Marcin Łojewski */ diff --git a/lib/Crypto/SSHA.php b/lib/Crypto/SSHA.php index f0f46d9..ddae4b2 100644 --- a/lib/Crypto/SSHA.php +++ b/lib/Crypto/SSHA.php @@ -24,7 +24,7 @@ namespace OCA\UserSQL\Crypto; use OCP\IL10N; /** - * SSHA* hashing implementation. + * SSHA* hash implementation. * * @author Marcin Łojewski */ diff --git a/lib/Crypto/SSHA256.php b/lib/Crypto/SSHA256.php index a01cdf9..40337bd 100644 --- a/lib/Crypto/SSHA256.php +++ b/lib/Crypto/SSHA256.php @@ -24,7 +24,7 @@ namespace OCA\UserSQL\Crypto; use OCP\IL10N; /** - * SSHA256 hashing implementation. + * SSHA256 hash implementation. * * @author Marcin Łojewski */ diff --git a/lib/Crypto/SSHA512.php b/lib/Crypto/SSHA512.php index 78e66a1..508fe53 100644 --- a/lib/Crypto/SSHA512.php +++ b/lib/Crypto/SSHA512.php @@ -24,7 +24,7 @@ namespace OCA\UserSQL\Crypto; use OCP\IL10N; /** - * SSHA512 hashing implementation. + * SSHA512 hash implementation. * * @author Marcin Łojewski */ diff --git a/lib/Crypto/WCF2.php b/lib/Crypto/WCF2.php new file mode 100644 index 0000000..498818a --- /dev/null +++ b/lib/Crypto/WCF2.php @@ -0,0 +1,63 @@ + + * @author Marcin Łojewski + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +namespace OCA\UserSQL\Crypto; + +/** + * WCF2 hash implementation. + * + * @author Marcin Łojewski + */ +class WCF2 extends AbstractCrypt +{ + /** + * @inheritdoc + */ + public function checkPassword($password, $dbHash) + { + return hash_equals($dbHash, crypt(crypt($password, $dbHash), $dbHash)); + } + + /** + * @inheritdoc + */ + public function getPasswordHash($password) + { + $salt = $this->getSalt(); + return crypt(crypt($password, $salt), $salt); + } + + /** + * @inheritdoc + */ + protected function getSalt() + { + return "$2a$08$" . Utils::randomString(22, self::SALT_ALPHABET) . "$"; + } + + /** + * @inheritdoc + */ + protected function getAlgorithmName() + { + return "WoltLab Community Framework 2.x"; + } +} diff --git a/lib/Model/User.php b/lib/Model/User.php index dcc9551..40ebf1c 100644 --- a/lib/Model/User.php +++ b/lib/Model/User.php @@ -36,6 +36,10 @@ class User * @var string The user's email address. */ public $email; + /** + * @var string The user quota. + */ + public $quota; /** * @var string The user's display name. */ diff --git a/lib/Query/QueryProvider.php b/lib/Query/QueryProvider.php index 49f2ac9..85a9f95 100644 --- a/lib/Query/QueryProvider.php +++ b/lib/Query/QueryProvider.php @@ -71,15 +71,18 @@ class QueryProvider implements \ArrayAccess $uHome = $this->properties[DB::USER_HOME_COLUMN]; $uName = $this->properties[DB::USER_NAME_COLUMN]; $uPassword = $this->properties[DB::USER_PASSWORD_COLUMN]; + $uQuota = $this->properties[DB::USER_QUOTA_COLUMN]; $uSalt = $this->properties[DB::USER_SALT_COLUMN]; $uUID = $this->properties[DB::USER_UID_COLUMN]; $ugGID = $this->properties[DB::USER_GROUP_GID_COLUMN]; $ugUID = $this->properties[DB::USER_GROUP_UID_COLUMN]; + $emailParam = Query::EMAIL_PARAM; $gidParam = Query::GID_PARAM; $nameParam = Query::NAME_PARAM; $passwordParam = Query::PASSWORD_PARAM; + $quotaParam = Query::QUOTA_PARAM; $searchParam = Query::SEARCH_PARAM; $uidParam = Query::UID_PARAM; @@ -91,6 +94,7 @@ class QueryProvider implements \ArrayAccess = "$uUID AS uid, " . (empty($uName) ? "null" : $uName) . " AS name, " . (empty($uEmail) ? "null" : $uEmail) . " AS email, " . + (empty($uQuota) ? "null" : $uQuota) . " AS quota, " . (empty($uHome) ? "null" : $uHome) . " AS home, " . (empty($uActive) ? "true" : $uActive) . " AS active, " . (empty($uAvatar) ? "false" : $uAvatar) . " AS avatar, " . @@ -156,7 +160,9 @@ class QueryProvider implements \ArrayAccess Query::SAVE_USER => "UPDATE $user " . "SET $uPassword = :$passwordParam, " . - "$uName = :$nameParam " . + "$uName = :$nameParam, " . + "$uEmail = :$emailParam, " . + "$uQuota = :$quotaParam " . "WHERE $uUID = :$uidParam", ]; } diff --git a/lib/Repository/UserRepository.php b/lib/Repository/UserRepository.php index 8f284b6..8ba593b 100644 --- a/lib/Repository/UserRepository.php +++ b/lib/Repository/UserRepository.php @@ -107,6 +107,8 @@ class UserRepository Query::SAVE_USER, [ Query::NAME_PARAM => $user->name, Query::PASSWORD_PARAM => $user->password, + Query::EMAIL_PARAM => $user->email, + Query::QUOTA_PARAM => $user->quota, Query::UID_PARAM => $user->uid ] ); diff --git a/templates/admin.php b/templates/admin.php index 176871f..7d2725f 100644 --- a/templates/admin.php +++ b/templates/admin.php @@ -71,6 +71,16 @@ function print_select_options( echo ""; } + +#54: Merge develop-14 into develop Conflicts +Resolved all conflicts +2 conflicting files +CHANGELOG.md +CHANGELOG.md +admin.php +templates/admin.php +templates/admin.php +Resolved echo ""; echo ""; } @@ -115,7 +125,7 @@ function print_select_options( "> getVisibleName(); + $hashes[$class] = $passwordAlgorithm->getVisibleName(); } } catch (Throwable $e) { } } - print_select_options($l, "opt-crypto_class", "Hashing algorithm", $hashing, $_["opt.crypto_class"]); + print_select_options($l, "opt-crypto_class", "Hash algorithm", $hashes, $_["opt.crypto_class"]); print_select_options($l, "opt-email_sync", "Email sync", ["" => "None", "initial" => "Synchronise only once", "force_nc"=>"Nextcloud always wins", "force_sql"=>"SQL always wins"], $_["opt.email_sync"]); + print_select_options($l, "opt-quota_sync", "Quota sync", ["" => "None", "initial" => "Synchronise only once", "force_nc"=>"Nextcloud always wins", "force_sql"=>"SQL always wins"], $_["opt.quota_sync"]); print_select_options($l, "opt-home_mode", "Home mode", ["" => "Default", "query" => "Query", "static" => "Static"], $_["opt.home_mode"]); print_text_input($l, "opt-home_location", "Home Location", $_["opt.home_location"]); ?> @@ -144,11 +155,12 @@ function print_select_options( diff --git a/tests/Crypto/CleartextTest.php b/tests/Crypto/CleartextTest.php index d4eaaef..67d5547 100644 --- a/tests/Crypto/CleartextTest.php +++ b/tests/Crypto/CleartextTest.php @@ -43,6 +43,12 @@ class CleartextTest extends TestCase $this->assertTrue($this->crypto->checkPassword("password", "password")); } + public function testPasswordHash() + { + $hash = $this->crypto->getPasswordHash("password"); + $this->assertTrue($this->crypto->checkPassword("password", $hash)); + } + protected function setUp() { parent::setUp(); diff --git a/tests/Crypto/CourierMD5RawTest.php b/tests/Crypto/CourierMD5RawTest.php index fe30008..5f443a7 100644 --- a/tests/Crypto/CourierMD5RawTest.php +++ b/tests/Crypto/CourierMD5RawTest.php @@ -47,6 +47,12 @@ class CourierMD5RawTest extends TestCase ); } + public function testPasswordHash() + { + $hash = $this->crypto->getPasswordHash("password"); + $this->assertTrue($this->crypto->checkPassword("password", $hash)); + } + protected function setUp() { parent::setUp(); diff --git a/tests/Crypto/CourierMD5Test.php b/tests/Crypto/CourierMD5Test.php index 0d1e82d..66d3d82 100644 --- a/tests/Crypto/CourierMD5Test.php +++ b/tests/Crypto/CourierMD5Test.php @@ -47,6 +47,12 @@ class CourierMD5Test extends TestCase ); } + public function testPasswordHash() + { + $hash = $this->crypto->getPasswordHash("password"); + $this->assertTrue($this->crypto->checkPassword("password", $hash)); + } + protected function setUp() { parent::setUp(); diff --git a/tests/Crypto/CourierSHA1Test.php b/tests/Crypto/CourierSHA1Test.php index 0621655..b60c3bc 100644 --- a/tests/Crypto/CourierSHA1Test.php +++ b/tests/Crypto/CourierSHA1Test.php @@ -47,6 +47,12 @@ class CourierSHA1Test extends TestCase ); } + public function testPasswordHash() + { + $hash = $this->crypto->getPasswordHash("password"); + $this->assertTrue($this->crypto->checkPassword("password", $hash)); + } + protected function setUp() { parent::setUp(); diff --git a/tests/Crypto/CourierSHA256Test.php b/tests/Crypto/CourierSHA256Test.php index ee86310..05cebe8 100644 --- a/tests/Crypto/CourierSHA256Test.php +++ b/tests/Crypto/CourierSHA256Test.php @@ -48,6 +48,12 @@ class CourierSHA256Test extends TestCase ); } + public function testPasswordHash() + { + $hash = $this->crypto->getPasswordHash("password"); + $this->assertTrue($this->crypto->checkPassword("password", $hash)); + } + protected function setUp() { parent::setUp(); diff --git a/tests/Crypto/CryptArgon2Test.php b/tests/Crypto/CryptArgon2Test.php index 7a44ddd..39855fe 100644 --- a/tests/Crypto/CryptArgon2Test.php +++ b/tests/Crypto/CryptArgon2Test.php @@ -48,6 +48,12 @@ class CryptArgon2Test extends TestCase ); } + public function testPasswordHash() + { + $hash = $this->crypto->getPasswordHash("password"); + $this->assertTrue($this->crypto->checkPassword("password", $hash)); + } + protected function setUp() { parent::setUp(); diff --git a/tests/Crypto/CryptBlowfishTest.php b/tests/Crypto/CryptBlowfishTest.php index ea4dc0c..1b878fd 100644 --- a/tests/Crypto/CryptBlowfishTest.php +++ b/tests/Crypto/CryptBlowfishTest.php @@ -48,6 +48,12 @@ class CryptBlowfishTest extends TestCase ); } + public function testPasswordHash() + { + $hash = $this->crypto->getPasswordHash("password"); + $this->assertTrue($this->crypto->checkPassword("password", $hash)); + } + protected function setUp() { parent::setUp(); diff --git a/tests/Crypto/CryptExtendedDESTest.php b/tests/Crypto/CryptExtendedDESTest.php index 31ca7c1..c5627e0 100644 --- a/tests/Crypto/CryptExtendedDESTest.php +++ b/tests/Crypto/CryptExtendedDESTest.php @@ -45,6 +45,12 @@ class CryptExtendedDESTest extends TestCase ); } + public function testPasswordHash() + { + $hash = $this->crypto->getPasswordHash("password"); + $this->assertTrue($this->crypto->checkPassword("password", $hash)); + } + protected function setUp() { parent::setUp(); diff --git a/tests/Crypto/CryptMD5Test.php b/tests/Crypto/CryptMD5Test.php index 0a6f405..aadc429 100644 --- a/tests/Crypto/CryptMD5Test.php +++ b/tests/Crypto/CryptMD5Test.php @@ -47,6 +47,12 @@ class CryptMD5Test extends TestCase ); } + public function testPasswordHash() + { + $hash = $this->crypto->getPasswordHash("password"); + $this->assertTrue($this->crypto->checkPassword("password", $hash)); + } + protected function setUp() { parent::setUp(); diff --git a/tests/Crypto/CryptSHA256Test.php b/tests/Crypto/CryptSHA256Test.php index 020bb61..b40736d 100644 --- a/tests/Crypto/CryptSHA256Test.php +++ b/tests/Crypto/CryptSHA256Test.php @@ -48,6 +48,12 @@ class CryptSHA256Test extends TestCase ); } + public function testPasswordHash() + { + $hash = $this->crypto->getPasswordHash("password"); + $this->assertTrue($this->crypto->checkPassword("password", $hash)); + } + protected function setUp() { parent::setUp(); diff --git a/tests/Crypto/CryptSHA512Test.php b/tests/Crypto/CryptSHA512Test.php index 7667d1f..6ea1035 100644 --- a/tests/Crypto/CryptSHA512Test.php +++ b/tests/Crypto/CryptSHA512Test.php @@ -48,6 +48,12 @@ class CryptSHA512Test extends TestCase ); } + public function testPasswordHash() + { + $hash = $this->crypto->getPasswordHash("password"); + $this->assertTrue($this->crypto->checkPassword("password", $hash)); + } + protected function setUp() { parent::setUp(); diff --git a/tests/Crypto/CryptStandardDESTest.php b/tests/Crypto/CryptStandardDESTest.php index ca8712b..b8d8cbf 100644 --- a/tests/Crypto/CryptStandardDESTest.php +++ b/tests/Crypto/CryptStandardDESTest.php @@ -45,6 +45,12 @@ class CryptStandardDESTest extends TestCase ); } + public function testPasswordHash() + { + $hash = $this->crypto->getPasswordHash("password"); + $this->assertTrue($this->crypto->checkPassword("password", $hash)); + } + protected function setUp() { parent::setUp(); diff --git a/tests/Crypto/CryptTest.php b/tests/Crypto/CryptTest.php index f556289..680b6cc 100644 --- a/tests/Crypto/CryptTest.php +++ b/tests/Crypto/CryptTest.php @@ -48,6 +48,12 @@ class CryptTest extends TestCase ); } + public function testPasswordHash() + { + $hash = $this->crypto->getPasswordHash("password"); + $this->assertTrue($this->crypto->checkPassword("password", $hash)); + } + protected function setUp() { parent::setUp(); diff --git a/tests/Crypto/JoomlaTest.php b/tests/Crypto/JoomlaTest.php index feaa96e..0777c3d 100644 --- a/tests/Crypto/JoomlaTest.php +++ b/tests/Crypto/JoomlaTest.php @@ -48,6 +48,12 @@ class JoomlaTest extends TestCase ); } + public function testPasswordHash() + { + $hash = $this->crypto->getPasswordHash("password"); + $this->assertTrue($this->crypto->checkPassword("password", $hash)); + } + protected function setUp() { parent::setUp(); diff --git a/tests/Crypto/MD5Test.php b/tests/Crypto/MD5Test.php index d8f2950..d302752 100644 --- a/tests/Crypto/MD5Test.php +++ b/tests/Crypto/MD5Test.php @@ -47,6 +47,12 @@ class MD5Test extends TestCase ); } + public function testPasswordHash() + { + $hash = $this->crypto->getPasswordHash("password"); + $this->assertTrue($this->crypto->checkPassword("password", $hash)); + } + protected function setUp() { parent::setUp(); diff --git a/tests/Crypto/PhpassTest.php b/tests/Crypto/PhpassTest.php index 22b1ecc..6ef9c42 100644 --- a/tests/Crypto/PhpassTest.php +++ b/tests/Crypto/PhpassTest.php @@ -47,6 +47,12 @@ class PhpassTest extends TestCase ); } + public function testPasswordHash() + { + $hash = $this->crypto->getPasswordHash("password"); + $this->assertTrue($this->crypto->checkPassword("password", $hash)); + } + protected function setUp() { parent::setUp(); diff --git a/tests/Crypto/SHA1Test.php b/tests/Crypto/SHA1Test.php index 2ed51ab..bdee003 100644 --- a/tests/Crypto/SHA1Test.php +++ b/tests/Crypto/SHA1Test.php @@ -47,6 +47,12 @@ class SHA1Test extends TestCase ); } + public function testPasswordHash() + { + $hash = $this->crypto->getPasswordHash("password"); + $this->assertTrue($this->crypto->checkPassword("password", $hash)); + } + protected function setUp() { parent::setUp(); diff --git a/tests/Crypto/SHA512WhirlpoolTest.php b/tests/Crypto/SHA512WhirlpoolTest.php index 558db94..3239776 100644 --- a/tests/Crypto/SHA512WhirlpoolTest.php +++ b/tests/Crypto/SHA512WhirlpoolTest.php @@ -48,6 +48,12 @@ class SHA512WhirlpoolTest extends TestCase ); } + public function testPasswordHash() + { + $hash = $this->crypto->getPasswordHash("password"); + $this->assertTrue($this->crypto->checkPassword("password", $hash)); + } + protected function setUp() { parent::setUp(); diff --git a/tests/Crypto/SSHA256Test.php b/tests/Crypto/SSHA256Test.php index f26b0e7..e3189d0 100644 --- a/tests/Crypto/SSHA256Test.php +++ b/tests/Crypto/SSHA256Test.php @@ -48,6 +48,12 @@ class SSHA256Test extends TestCase ); } + public function testPasswordHash() + { + $hash = $this->crypto->getPasswordHash("password"); + $this->assertTrue($this->crypto->checkPassword("password", $hash)); + } + protected function setUp() { parent::setUp(); diff --git a/tests/Crypto/SSHA512Test.php b/tests/Crypto/SSHA512Test.php index 10cfbd7..b6b5f72 100644 --- a/tests/Crypto/SSHA512Test.php +++ b/tests/Crypto/SSHA512Test.php @@ -48,6 +48,12 @@ class SSHA512Test extends TestCase ); } + public function testPasswordHash() + { + $hash = $this->crypto->getPasswordHash("password"); + $this->assertTrue($this->crypto->checkPassword("password", $hash)); + } + protected function setUp() { parent::setUp(); diff --git a/tests/Crypto/WCF2Test.php b/tests/Crypto/WCF2Test.php new file mode 100644 index 0000000..91faa91 --- /dev/null +++ b/tests/Crypto/WCF2Test.php @@ -0,0 +1,62 @@ + + * @author Marcin Łojewski + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +namespace Tests\UserSQL\Crypto; + +use OCA\UserSQL\Crypto\IPasswordAlgorithm; +use OCA\UserSQL\Crypto\WCF2; +use OCP\IL10N; +use Test\TestCase; + +/** + * Unit tests for class WCF2. + * + * @author Marcin Łojewski + */ +class WCF2Test extends TestCase +{ + /** + * @var IPasswordAlgorithm + */ + private $crypto; + + public function testCheckPassword() + { + $this->assertTrue( + $this->crypto->checkPassword( + "password", + "$2a$08\$XEQDKNU/Vbootwxv5Gp7gujxFX/RUFsZLvQPYM435Dd3/p17fto02" + ) + ); + } + + public function testPasswordHash() + { + $hash = $this->crypto->getPasswordHash("password"); + $this->assertTrue($this->crypto->checkPassword("password", $hash)); + } + + protected function setUp() + { + parent::setUp(); + $this->crypto = new WCF2($this->createMock(IL10N::class)); + } +}