Commit graph

49 commits

Author SHA1 Message Date
jenkins-bot
3da3519967 Merge "PasswordPbkdf2: remove the 'use-hash-extension' option" 2018-12-04 06:52:15 +00:00
Mogmog123
37a396796b Changing "===" on secrets to hash_equals to protect from timing attacks.
Bug: T207777
Change-Id: I1e12ef94f455f96b4d70af27a315414500c709ab
2018-12-01 14:26:02 +00:00
Max Semenik
9c4ce7e1cf PasswordPbkdf2: remove the 'use-hash-extension' option
It's misleading because even with this option the Hash extension is
still required due to usage of hash_hmac(), it's just to allow this
class to work on pre-5.5 PHP that had hash_hmac() but not hash_pbkdf().
Since we require 7.0, this option doesn't do anything anymore.

Change-Id: Ib60ab9377b44d78b7147c6139b07dc5467da007c
2018-11-30 18:21:03 -08:00
Reedy
519ff1a402 Add PasswordPolicy to check the password isn't in the large blacklist
Add wikimedia/password-blacklist 0.1.3, which contains 100,000 common passwords

Bug: T151425
Change-Id: I80572fcee6d23ea04ad9ee683157bab9378b660e
Depends-On: I8aea5a44248da9bb9ff7b328679bff6fcf41750d
2018-11-24 15:46:14 -08:00
jenkins-bot
a0b490bbe7 Merge "password: Move commonpasswords.cdb to includes/password/" 2018-08-14 23:53:19 +00:00
Aryeh Gregor
90d4f56fe4 Mass conversion of $wgContLang to service
Brought to you by vim macros.

Bug: T200246
Change-Id: I79e919f4553e3bd3eb714073fed7a43051b4fb2a
2018-08-11 22:44:29 -06:00
Kunal Mehta
fb73286fba Add PasswordFactory to MediaWikiServices
Instead of having basically every caller do:
 $pf = new PasswordFactory();
 $pf->init( RequestContext::getMain()->getConfig() );
Just create a single PasswordFactory via MediaWikiServices and pass that
around. Things that want to use their own config can still pass settings
via the new constructor.

This will eventually let us remove the init() function, removing the
only hard dependency upon MediaWiki, to make it easier to librarize
(T89742).

Change-Id: I0fc7520dc023b11a7fa66083eff7b88ebfe49c7b
2018-08-02 14:46:35 +01:00
Timo Tijhof
553b4b0cd4 password: Move commonpasswords.cdb to includes/password/
Similar to other non-php files used by various classes/libs.

This leaves the serialized/ empty (apart from dotfiles), and as
such the directory was removed.

Change-Id: I538ffe0828843220ac4e161cf2e119deb9bd7ac0
2018-08-01 22:40:30 +00:00
Max Semenik
9bab7de5f8 Clean up CSPRNG support for PHP7
Replace it all with random_bytes(), leave
only MWCryptRand::generateHex() as a convenience helper.

Change-Id: Ic30376a90e66d8f00dab86e7e6466fb3a750b87d
2018-06-10 00:52:04 +00:00
Bartosz Dziewoński
485f66f174 Use PHP 7 '??' operator instead of '?:' with 'isset()' where convenient
Find: /isset\(\s*([^()]+?)\s*\)\s*\?\s*\1\s*:\s*/
Replace with: '\1 ?? '

(Everywhere except includes/PHPVersionCheck.php)
(Then, manually fix some line length and indentation issues)

Then manually reviewed the replacements for cases where confusing
operator precedence would result in incorrect results
(fixing those in I478db046a1cc162c6767003ce45c9b56270f3372).

Change-Id: I33b421c8cb11cdd4ce896488c9ff5313f03a38cf
2018-05-30 18:06:13 -07:00
Kunal Mehta
230958d97c Autofix MediaWiki.Commenting.FunctionComment.SpacingDoc* errors
Change-Id: I63761ebce04c03b9b13237919c27cc10180f198f
2018-05-19 14:07:03 -07:00
Umherirrender
3124a990a2 Use ::class to resolve class names in includes files
This helps to find renamed or misspelled classes earlier.
Phan will check the class names

Change-Id: I07a925c2a9404b0865e8a8703864ded9d14aa769
2018-01-27 20:34:29 +01:00
Thiemo Mättig
409da2d8b3 Remove leading backslashes from "use \…" tags
Change-Id: I494b029de089a07e3b946ee78293a12d5036f63e
2017-12-28 16:30:05 +01:00
Tim Starling
a9911b2582 Improve test coverage in includes/password
From 21% to 82%.

* Added missing @covers, broadened @covers where appropriate.
* Added tests for some code that lacked them.
* Added a parameter to control the use of hash_pbkdf2() so that the pure
  PHP fallback could be tested. In the non-fallback test, force the use
  of the extension, and mark it skipped if it is not installed.

Bug: T167003
Change-Id: I987e1a89ec343907f4ead7f6192b2d4deb58ac16
2017-06-07 14:28:11 +10:00
Max Semenik
d4f3e554d7 Decrease the number of 'function says it should return something' errors
Change-Id: Ib5115fe5bbaa67d8a6e54cc3ba1ba7020e239e11
2016-12-15 16:05:52 -08:00
Brad Jorsch
5840c440ce Remove $purpose parameter from password validity check
This was added in I56b6600 in an attempt to work around a bug in
CentralAuth, but the bug has since been fixed in a better way. No hook
functions in Gerrit use the parameter (or ever have, as far as I can
tell), and anything that was passing a value other than the default
'login' has since been removed. So let's just get rid of it instead of
keeping it around doing nothing.

Change-Id: Ie604e03d268706221161ac93eb866f477e466fb4
2016-12-01 18:41:01 -05:00
jenkins-bot
c253b03fe5 Merge "Throw an exception if password hash would be truncated by DB" 2016-11-30 19:10:47 +00:00
Brian Wolff
e8589233bc Throw an exception if password hash would be truncated by DB
DB uses a tinyblob field. With layered encrypted passwords, the
length gets close to 255 and can exceed if you use a long name
for the password type. Previously these would be silently inserted
into the DB and truncated, which would lock user out of their
account.

Change-Id: Idf0d0248b181f42d92e3ad6c3220b5331cd4d4d0
2016-11-15 06:21:03 +00:00
jenkins-bot
af5f5ac4bb Merge "Fix multiple bugs in EncryptedPassword" 2016-11-15 05:25:34 +00:00
Tim Starling
6dbb8f2d78 Fix multiple bugs in EncryptedPassword
* openssl_decrypt() expects the encrypted string you give it to be the
  exact one that came out of openssl_encrypt(), it doesn't expect you to
  pre-decode the base64 encoding. So don't do that.
* Use the same IV when re-encrypting the underlying hash for comparison.
* Check the return value of OpenSSL functions, and report meaningful
  error messages, for sysadmin convenience and to avoid e.g. giving all
  users the same hash if an invalid cipher method was chosen (which was
  the previous behaviour).
* Fix EncryptedPassword::update(). Tested it with eval.php since there
  doesn't seem to be any callers.

Change-Id: I3a39de152d0329f93d16aa4ed43faf08f665b8e2
2016-11-15 15:15:24 +11:00
Tim Starling
7f40255ca2 Accept salted password hashes with :A: prefixes
Partially reverting Icb809274f9f63.

The broken :A: prefixed passwords generated by MW before that change
were apparently written back to the database -- there are 2.5M in enwiki
alone. Accepting them should not depend on $wgPasswordSalt, which is a
deprecated global and should soon be removed.

Change-Id: I772de0fb17245d080eb15a7d5df6bf3125e1f71a
2016-11-15 11:01:59 +11:00
Tim Starling
7a157e0bea Fix interpretation of "A-type" password hashes
An A-type hash is an unsalted hash. A B-type hash is a salted hash of
the form md5(salt "-" md5(password)). So it's not correct to have an
A-type hash with a salt. User::comparePasswords() and
CentralAuthUser::getPasswordFromString() already get this right, they
generate :B: prefixes for legacy salted hashes where the salt is not
specified in the database.

Change-Id: Icb809274f9f63641e54daf98332a5646fd58b550
2016-11-14 16:47:03 +11:00
csteipp
f91e47ce9e SECURITY: Throw exception on unknown hash algorithm
To prevent a bad password configuration from accidentally allowing
users to bypass authentication, throw an exception if either hash or
hash_pbkdf2 return false.

Also, ensure md5() returned a sane hash.

Bug: T127420
Change-Id: If3664941236e4065eb8db11b0a211fd6210de631

Signed-off-by: Chad Horohoe <chadh@wikimedia.org>
2016-05-20 09:48:59 -07:00
Brad Jorsch
54d58ef506 API changes for AuthManager
Changes here are:
* action=login is deprecated for use other than bot passwords
* list=users will indicate if a missing user name is creatable.
* Added action=query&meta=authmanagerinfo
* Added action=clientlogin is to be used to log into the main account
* action=createaccount is changed in a non-BC manner
* Added action=linkaccount
* Added action=unlinkaccount
* Added action=changeauthenticationdata
* Added action=removeauthenticationdata
* Added action=resetpassword

Bug: T110276
Bug: T110747
Bug: T110751
Bug: T32788
Bug: T67857
Bug: T28597
Bug: T76103
Change-Id: I244fa9b1e0623247d6d9fa30990411c6df94a496
2016-05-16 15:12:52 +00:00
Ricordisamoa
e64035522d Fix and standardize Doxygen tags
* Use "@param datatype $paramname description" format

* String → string, Integer → int etc.

* @return $string → @return string

Change-Id: I860d222382cb4c5699d313b0600bd22503c8c385
2016-04-30 12:10:17 +02:00
Kunal Mehta
6e9b4f0e9c Convert all array() syntax to []
Per wikitech-l consensus:
 https://lists.wikimedia.org/pipermail/wikitech-l/2016-February/084821.html

Notes:
* Disabled CallTimePassByReference due to false positives (T127163)

Change-Id: I2c8ce713ce6600a0bb7bf67537c87044c7a45c4b
2016-02-17 01:33:00 -08:00
Brad Jorsch
4826c44e9b [SECURITY] 0-pad to length in random string generation
Otherwise shorter strings might be generated.

Bug: T115522
Signed-off-by: Chad Horohoe <chadh@wikimedia.org>
Change-Id: I110d873d56762552060fd428c236c8b0e9a859b0
2015-12-18 01:22:35 -08:00
jenkins-bot
764dc6ae51 Merge "Add support for blacklisting common passwords" 2015-12-04 20:17:45 +00:00
Brian Wolff
2d15dcfc3f Add support for blacklisting common passwords
This changes the default config to not allow the top 25 passwords
to be used by Sysop/Crats. This should almost certainly be set to
a higher number, but I think its best to wait until after this is
comitted to argue over what the best value is.

I would expect that once this is comitted, there would be a config
change for wmf wikis, so that there is no change until this has
been discussed with the community.

The included common password file was generated from the first
10000 entries of
https://github.com/danielmiessler/SecLists/blob/master/Passwords/rockyou.txt?raw=true
10,000 was chosen based on csteipp's suggestion.

Change-Id: I26a9e8f2318a1eed33d7638b125695e8de3a9796
2015-11-25 17:02:33 -05:00
Reedy
00c426e3c2 Replace wfBaseConvert with Wikimedia\base_convert
Change-Id: Iadab3d018c3559daf79be90edb23d131729bdb68
2015-11-24 22:51:42 +00:00
jenkins-bot
07b407f558 Merge "Fix typo in doc comment on MWSaltedPassword.php" 2015-11-23 22:10:11 +00:00
Brian Wolff
3171dd7e9d Fix typo in doc comment on MWSaltedPassword.php
Change-Id: I4d08846f6692797b0cfea33d56bbf1afb33b27db
2015-11-23 16:55:18 -05:00
Reedy
c3b35bb187 Improve error message if check not defined for a password policy.
Bug: T118776
Change-Id: Ic1826f15424197545f4d6c2b1af49adbc4289e15
2015-11-16 20:50:53 +00:00
Brad Jorsch
3d0b4fea3d User: Mostly remove password handling
AuthManager is coming, which will make it easier to add alternative
methods of authentication. But in order to do that, we need to finally
get around to ripping the password-related bits out of the User class.

The password expiration handling isn't used anywhere in core or
extensions in Gerrit beyond testing for expired passwords on login and
resetting the expiry date on password change. Those bits have been
inlined and the functions removed; AuthManager will allow each
"authentication provider" to handle its own password expiration.

The methods for fetching passwords, including the fact that mPassword
and other fields are public, has also been removed. This is already
broken in combination with basically any extension that messes with
authentication, and the major use outside of that was in creating
system users like MassMessage's "MediaWiki message delivery" user.

Password setting methods are silently deprecated, since most of the
replacements won't be available until AuthManager. But uses in unit
testing can be replaced with TestUser::setPasswordForUser() immediately.

User::randomPassword() and User::getPasswordFactory() don't really
belong in User either. For the former a new PasswordFactory method has
been created, while the latter should just be replaced by the two lines
to create a PasswordFactory via its constructor.

Bug: T47716
Change-Id: I2c736ad72d946fa9b859e6cd335fa58aececc0d5
2015-10-13 16:10:41 -06:00
jeroendedauw
ce7912b22a Remove dead argument in EncryptedPassword.php
Change-Id: Ib0bb2733284262c233e6de4c7645f0b215690156
2015-09-16 17:03:35 +00:00
csteipp
6a69a4eb73 Add "purpose" to password validity check
Allow callers to specify why they are checking a passwords validity, so
some checks can be modified. Only check the default policy on creation,
since the account doesn't exist it's not a member of any groups.

Bug: T104615
Change-Id: I56b66002562aaa1493d94a90309bc8e4ae3841c8
2015-07-14 20:04:23 +00:00
csteipp
66147c798a Check install user's password as sysop/bureaucrat
Refactor password checking a little to allow skipping the normal flow
in a special situation like this.

Bug: T104092
Change-Id: Ib4a4e1f34b6963a6414c6f88893884b0ec369ca5
2015-06-29 16:46:55 -07:00
csteipp
1a20dc9362 Password validity by policy per group
Make password policies defined in a configurable policy, which is
defined by group. A user's password policy will be the maximum of
each group policy that the user belongs to.

Bug: T94774
Change-Id: Iad8e49ffcffed38df6293db0ef31a227d3962003
2015-06-10 10:34:17 -07:00
Marius Hoch
dd52464497 Fix creating non-parameterized hashes in ParameterizedPassword
I noticed MWOldPassword is broken while working on
I7024b287a7. When generating new passwords for it,
a superfluous : is being added to the serialized hash
within the database (and that breaks parsing so that
people can't ever log in).

As this is not really relevant in the real world (as
nobody is hopefully using plain MD5 passwords anymore),
this doesn't need any backward compatibility handling
for the broken hashes.

Change-Id: I753c135a6de39008488bd7462c2bfcda2cbac116
2014-10-20 22:58:17 +02:00
Marius Hoch
ee9166a10e Make TestUser way faster
By only updating the user row in the database, if needed
and by making use of md5 for passwords instead of slower
hashing.
This cut down run time of some Wikibase API tests to 20%
of the original value for me!
Also it reduces the run time of MediaWiki's test suite
by about 45s on jenkins.

Change-Id: I7024b287a71fe9b327dbcdc5427cd8edb5047606
2014-10-20 02:03:08 +02:00
Brad Jorsch
4dc1f5a175 PasswordFactory::newFromPlaintext( null ) needs to work
Various code passes null around to mean "an invalid password". It
shouldn't all have to test for null and specially handle that.

This also fixes a codepath where User::$mNewpassword could get set to an
empty string rather than a password object, which would cause problems
later when anything else tries to use it.

Bug: 71421
Change-Id: Ib5f94b52c07e7dba89328b98fb43c86db95ee09f
2014-09-29 21:42:33 +00:00
umherirrender
473b7d925e Fixed docs
- Use short form of boolean
- Use capital at begin of doc text

Change-Id: Ic5afacfa7298b1938d3b45ffd0cac5ce01f2f9db
2014-08-04 12:00:15 +02:00
Tyler Romeo
97762eec53 Added explicit type-cast to hash_pbkdf2
It seems HHVM does not like the use of
dynamic typing  in hash_pbkdf2() (also it's
kind of not the best idea in general), so
added explicit (int) casting to parameters.

Follows-up: I0a9c972931a0eff0cfb2619cef3ddffd03710285
Change-Id: I8adae3cc2cdf8029be59e2d62a3ab0fbfb73b7aa
2014-07-29 15:57:47 +00:00
jenkins-bot
878b970ccd Merge "Documentation fixes for Password API-related changes" 2014-07-29 15:25:12 +00:00
jenkins-bot
930df1bdd1 Merge "Documentation: Update $wgPasswordDefault and BcryptPassword" 2014-07-29 15:11:04 +00:00
withoutaname
72462041c0 Move PasswordError under includes/password/ file
Change-Id: I7256325492b2f6451223714efb8b3e07fca9ee3e
2014-07-29 02:07:50 -07:00
withoutaname
67defa3b68 Documentation: Update $wgPasswordDefault and BcryptPassword
Slight syntax code change for $wgPasswordDefault in DefaultSettings.php
and fixed reference to global in BcryptPassword.php.

Change-Id: I8d1d12c09ecd2f422f21a586e948f314e29fa605
2014-07-29 01:57:30 -07:00
Kunal Mehta
2a904107c5 Documentation fixes for Password API-related changes
A few @since 1.23 --> 1.24

Change-Id: I55d00ab9c3f9dae96ed804a22f19d713879663fa
Follows-Up: I0a9c972931a0eff0cfb2619cef3ddffd03710285
2014-07-29 05:17:26 +00:00
Tyler Anthony Romeo
95a8974c6b
Added password hashing API
Deprecated the old User::crypt, et. al password hashing
system and implemented an extensible password hashing
API.

The new Password class allows registering of child classes
and provides factory functions for creating new Password
objects. The built-in hash types are the old MediaWiki MD5
types, which are for backwards-compatibility only, and bcrypt.

Also included is support for wrapping existing hashes as well
as encrypting passwords with a configured encryption key.

Bug: 54948
Bug: 28419
Change-Id: I0a9c972931a0eff0cfb2619cef3ddffd03710285
2014-07-27 15:51:18 -04:00