2 namespace TYPO3\CMS\Saltedpasswords\Tests\Unit\Salt;
36 $this->objectInstance = $this->getMock(\TYPO3\CMS\Saltedpasswords\Salt\BlowfishSalt::class, array(
'dummy'));
46 if (!CRYPT_BLOWFISH) {
47 $this->markTestSkipped(
'Blowfish is not supported on your platform.');
56 $hasCorrectBaseClass = get_class($this->objectInstance) === \TYPO3\CMS\Saltedpasswords\Salt\BlowfishSalt::class;
58 if (!$hasCorrectBaseClass &&
false != get_parent_class($this->objectInstance)) {
59 $hasCorrectBaseClass = is_subclass_of($this->objectInstance, \TYPO3\CMS\Saltedpasswords\Salt\BlowfishSalt::class);
61 $this->assertTrue($hasCorrectBaseClass);
69 $this->assertTrue($this->objectInstance->getSaltLength() > 0);
78 $this->assertNull($this->objectInstance->getHashedPassword($password));
88 $this->assertNotNull($this->objectInstance->getHashedPassword($password));
97 $password =
'password';
98 $saltedHashPassword = $this->objectInstance->getHashedPassword($password);
99 $this->assertTrue($this->objectInstance->isValidSaltedPW($saltedHashPassword));
108 $password =
'password';
110 $randomBytes = \TYPO3\CMS\Core\Utility\GeneralUtility::generateRandomBytes($this->objectInstance->getSaltLength());
111 $salt = $this->objectInstance->base64Encode($randomBytes, $this->objectInstance->getSaltLength());
112 $this->assertTrue($this->objectInstance->isValidSalt($salt));
113 $saltedHashPassword = $this->objectInstance->getHashedPassword($password, $salt);
114 $this->assertTrue($this->objectInstance->isValidSaltedPW($saltedHashPassword));
123 $password =
'password';
124 $minHashCount = $this->objectInstance->getMinHashCount();
125 $this->objectInstance->setHashCount($minHashCount);
126 $saltedHashPassword = $this->objectInstance->getHashedPassword($password);
127 $this->assertTrue($this->objectInstance->isValidSaltedPW($saltedHashPassword));
129 $this->objectInstance->setHashCount(null);
143 $password =
'aEjOtY';
144 $saltedHashPassword = $this->objectInstance->getHashedPassword($password);
145 $this->assertTrue($this->objectInstance->checkPassword($password, $saltedHashPassword));
160 $saltedHashPassword = $this->objectInstance->getHashedPassword($password);
161 $this->assertTrue($this->objectInstance->checkPassword($password, $saltedHashPassword));
175 $password =
' !"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~';
176 $saltedHashPassword = $this->objectInstance->getHashedPassword($password);
177 $this->assertTrue($this->objectInstance->checkPassword($password, $saltedHashPassword));
192 for ($i = 160; $i <= 191; $i++) {
193 $password .= chr($i);
195 $password .= chr(215) . chr(247);
196 $saltedHashPassword = $this->objectInstance->getHashedPassword($password);
197 $this->assertTrue($this->objectInstance->checkPassword($password, $saltedHashPassword));
212 for ($i = 192; $i <= 214; $i++) {
213 $password .= chr($i);
215 for ($i = 216; $i <= 246; $i++) {
216 $password .= chr($i);
218 for ($i = 248; $i <= 255; $i++) {
219 $password .= chr($i);
221 $saltedHashPassword = $this->objectInstance->getHashedPassword($password);
222 $this->assertTrue($this->objectInstance->checkPassword($password, $saltedHashPassword));
231 $password =
'password';
232 $password1 = $password .
'INVALID';
233 $saltedHashPassword = $this->objectInstance->getHashedPassword($password);
234 $this->assertFalse($this->objectInstance->checkPassword($password1, $saltedHashPassword));
245 $criticalPwLength = 0;
247 $saltedHashPasswordCurrent = $salt = $this->objectInstance->getHashedPassword($pad);
248 for ($i = 0; $i <= 128; $i += 8) {
249 $password = str_repeat($pad, max($i, 1));
250 $saltedHashPasswordPrevious = $saltedHashPasswordCurrent;
251 $saltedHashPasswordCurrent = $this->objectInstance->getHashedPassword($password, $salt);
252 if ($i > 0 && $saltedHashPasswordPrevious === $saltedHashPasswordCurrent) {
253 $criticalPwLength = $i;
257 $this->assertTrue($criticalPwLength == 0 || $criticalPwLength > 32,
'Duplicates of hashed passwords with plaintext password of length ' . $criticalPwLength .
'+.');
265 $minHashCount = $this->objectInstance->getMinHashCount();
266 $this->objectInstance->setMinHashCount($minHashCount - 1);
267 $this->assertTrue($this->objectInstance->getMinHashCount() < $minHashCount);
268 $this->objectInstance->setMinHashCount($minHashCount + 1);
269 $this->assertTrue($this->objectInstance->getMinHashCount() > $minHashCount);
277 $maxHashCount = $this->objectInstance->getMaxHashCount();
278 $this->objectInstance->setMaxHashCount($maxHashCount + 1);
279 $this->assertTrue($this->objectInstance->getMaxHashCount() > $maxHashCount);
280 $this->objectInstance->setMaxHashCount($maxHashCount - 1);
281 $this->assertTrue($this->objectInstance->getMaxHashCount() < $maxHashCount);
289 $hashCount = $this->objectInstance->getHashCount();
290 $this->objectInstance->setMaxHashCount($hashCount + 1);
291 $this->objectInstance->setHashCount($hashCount + 1);
292 $this->assertTrue($this->objectInstance->getHashCount() > $hashCount);
293 $this->objectInstance->setMinHashCount($hashCount - 1);
294 $this->objectInstance->setHashCount($hashCount - 1);
295 $this->assertTrue($this->objectInstance->getHashCount() < $hashCount);
297 $this->objectInstance->setHashCount(null);
306 $password =
'password';
307 $saltedHashPassword = $this->objectInstance->getHashedPassword($password);
308 $this->assertFalse($this->objectInstance->isHashUpdateNeeded($saltedHashPassword));
316 $password =
'password';
317 $saltedHashPassword = $this->objectInstance->getHashedPassword($password);
318 $increasedHashCount = $this->objectInstance->getHashCount() + 1;
319 $this->objectInstance->setMaxHashCount($increasedHashCount);
320 $this->objectInstance->setHashCount($increasedHashCount);
321 $this->assertTrue($this->objectInstance->isHashUpdateNeeded($saltedHashPassword));
323 $this->objectInstance->setHashCount(null);
332 $password =
'password';
333 $saltedHashPassword = $this->objectInstance->getHashedPassword($password);
334 $decreasedHashCount = $this->objectInstance->getHashCount() - 1;
335 $this->objectInstance->setMinHashCount($decreasedHashCount);
336 $this->objectInstance->setHashCount($decreasedHashCount);
337 $this->assertFalse($this->objectInstance->isHashUpdateNeeded($saltedHashPassword));
339 $this->objectInstance->setHashCount(null);