2018-02-19 21:59:52 +01:00
|
|
|
<?php
|
|
|
|
|
2021-03-22 10:28:28 +01:00
|
|
|
class PaCryptTest extends \PHPUnit\Framework\TestCase
|
|
|
|
{
|
2021-04-13 22:19:16 +02:00
|
|
|
public function testMd5Crypt()
|
|
|
|
{
|
2018-02-19 21:59:52 +01:00
|
|
|
$hash = _pacrypt_md5crypt('test', '');
|
|
|
|
|
|
|
|
$this->assertNotEmpty($hash);
|
|
|
|
$this->assertNotEquals('test', $hash);
|
|
|
|
|
|
|
|
$this->assertEquals($hash, _pacrypt_md5crypt('test', $hash));
|
|
|
|
}
|
|
|
|
|
2021-04-13 22:19:16 +02:00
|
|
|
public function testCrypt()
|
|
|
|
{
|
2018-02-19 21:59:52 +01:00
|
|
|
// E_NOTICE if we pass in '' for the salt
|
|
|
|
$hash = _pacrypt_crypt('test', 'sa');
|
|
|
|
|
|
|
|
$this->assertNotEmpty($hash);
|
|
|
|
$this->assertNotEquals('test', $hash);
|
|
|
|
|
|
|
|
$this->assertEquals($hash, _pacrypt_crypt('test', $hash));
|
|
|
|
}
|
|
|
|
|
2021-04-13 22:19:16 +02:00
|
|
|
public function testMySQLEncrypt()
|
|
|
|
{
|
2018-02-19 22:01:23 +01:00
|
|
|
if (!db_mysql()) {
|
2018-02-19 21:59:52 +01:00
|
|
|
$this->markTestSkipped('Not using MySQL');
|
|
|
|
}
|
|
|
|
|
2021-01-18 23:15:56 +01:00
|
|
|
$hash = _pacrypt_mysql_encrypt('test1');
|
2018-02-19 21:59:52 +01:00
|
|
|
|
2021-01-18 23:15:56 +01:00
|
|
|
$hash2 = _pacrypt_mysql_encrypt('test2');
|
2018-04-29 22:53:46 +02:00
|
|
|
|
2018-02-19 21:59:52 +01:00
|
|
|
$this->assertNotEquals($hash, $hash2);
|
|
|
|
|
2019-02-15 22:31:21 +01:00
|
|
|
$this->assertNotEmpty($hash);
|
|
|
|
$this->assertNotEquals('test', $hash);
|
|
|
|
$this->assertNotEquals('test', $hash2);
|
|
|
|
|
2021-05-08 22:47:45 +02:00
|
|
|
$this->assertTrue(hash_equals($hash, _pacrypt_mysql_encrypt('test1', $hash)), "hashes should equal....");
|
2018-02-19 21:59:52 +01:00
|
|
|
}
|
|
|
|
|
2021-04-13 22:19:16 +02:00
|
|
|
public function testAuthlib()
|
|
|
|
{
|
2018-12-27 14:54:41 +01:00
|
|
|
global $CONF;
|
2018-04-29 22:53:46 +02:00
|
|
|
|
2018-02-19 22:01:23 +01:00
|
|
|
// too many options!
|
|
|
|
foreach (
|
2019-02-15 22:31:21 +01:00
|
|
|
[
|
|
|
|
'md5raw' => '098f6bcd4621d373cade4e832627b4f6',
|
2018-04-29 22:53:46 +02:00
|
|
|
'md5' => 'CY9rzUYh03PK3k6DJie09g==',
|
|
|
|
// crypt requires salt ...
|
2019-02-15 22:31:21 +01:00
|
|
|
'SHA' => 'qUqP5cyxm6YcTAhz05Hph5gvu9M='
|
2021-01-14 18:05:50 +01:00
|
|
|
] as $flavour => $hash
|
|
|
|
) {
|
2018-02-19 21:59:52 +01:00
|
|
|
$CONF['authlib_default_flavour'] = $flavour;
|
|
|
|
|
|
|
|
$stored = "{" . $flavour . "}$hash";
|
|
|
|
$hash = _pacrypt_authlib('test', $stored);
|
|
|
|
|
2018-02-19 22:01:23 +01:00
|
|
|
$this->assertEquals($hash, $stored, "Hash: $hash vs Stored: $stored");
|
2018-02-19 21:59:52 +01:00
|
|
|
//var_dump("Hash: $hash from $flavour");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-13 22:19:16 +02:00
|
|
|
public function testPacryptDovecot()
|
|
|
|
{
|
2018-02-19 21:59:52 +01:00
|
|
|
global $CONF;
|
2021-05-08 22:47:45 +02:00
|
|
|
|
2018-02-19 22:01:23 +01:00
|
|
|
if (!file_exists('/usr/bin/doveadm')) {
|
2018-02-19 21:59:52 +01:00
|
|
|
$this->markTestSkipped("No /usr/bin/doveadm");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$CONF['encrypt'] = 'dovecot:SHA1';
|
|
|
|
|
|
|
|
$expected_hash = '{SHA1}qUqP5cyxm6YcTAhz05Hph5gvu9M=';
|
|
|
|
|
|
|
|
$this->assertEquals($expected_hash, _pacrypt_dovecot('test', ''));
|
|
|
|
$this->assertEquals($expected_hash, _pacrypt_dovecot('test', $expected_hash));
|
2021-01-14 18:05:50 +01:00
|
|
|
|
|
|
|
// This should also work.
|
|
|
|
$sha512 = '{SHA512}ClAmHr0aOQ/tK/Mm8mc8FFWCpjQtUjIElz0CGTN/gWFqgGmwElh89WNfaSXxtWw2AjDBmyc1AO4BPgMGAb8kJQ=='; // foobar
|
|
|
|
$this->assertEquals($sha512, _pacrypt_dovecot('foobar', $sha512));
|
|
|
|
|
|
|
|
$sha512 = '{SHA512}ClAmHr0aOQ/tK/Mm8mc8FFWCpjQtUjIElz0CGTN/gWFqgGmwElh89WNfaSXxtWw2AjDBmyc1AO4BPgMGAb8kJQ=='; // foobar
|
|
|
|
$this->assertNotEquals($sha512, _pacrypt_dovecot('foobarbaz', $sha512));
|
2018-02-19 21:59:52 +01:00
|
|
|
}
|
2018-04-29 22:53:46 +02:00
|
|
|
|
2021-09-29 22:05:19 +02:00
|
|
|
|
2021-04-13 22:19:16 +02:00
|
|
|
public function testPhpCrypt()
|
2021-09-29 22:05:19 +02:00
|
|
|
{
|
|
|
|
$config = Config::getInstance();
|
|
|
|
Config::write('encrypt', 'php_crypt');
|
|
|
|
|
|
|
|
$CONF = Config::getInstance()->getAll();
|
|
|
|
|
|
|
|
$sha512_crypt = '$6$ijF8bgunALqnEHTo$LHVa6XQBpM5Gt16RMFQuXqrGAS0y0ymaLS8pnkeVUTSx3t2DrGqWwRj6q4ef3V3SWYkb5xkuN9bv7joxNd8kA1';
|
|
|
|
|
|
|
|
$enc = _pacrypt_php_crypt('foo', $sha512_crypt);
|
|
|
|
|
|
|
|
$this->assertEquals($enc, $sha512_crypt);
|
|
|
|
|
|
|
|
$fail = _pacrypt_php_crypt('bar', $sha512_crypt);
|
|
|
|
|
|
|
|
$this->assertNotEquals($fail, $sha512_crypt);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testPhpCryptMd5()
|
2021-04-13 22:19:16 +02:00
|
|
|
{
|
2023-03-09 22:57:58 +01:00
|
|
|
global $CONF;
|
|
|
|
|
2018-04-29 22:53:46 +02:00
|
|
|
$config = Config::getInstance();
|
|
|
|
Config::write('encrypt', 'php_crypt:MD5');
|
2023-03-09 22:57:58 +01:00
|
|
|
$CONF['encrypt'] = 'php_crypt:MD5';
|
|
|
|
|
|
|
|
$new = _pacrypt_php_crypt('foo', '');
|
|
|
|
$pac = pacrypt('foo', '');
|
|
|
|
|
|
|
|
$this->assertEquals(1, preg_match('!^\$1\$!', $new), $new);
|
2018-04-29 22:53:46 +02:00
|
|
|
|
2023-03-09 22:57:58 +01:00
|
|
|
$this->assertEquals(1, preg_match('!^\$1\$!', $pac), $pac);
|
2018-04-29 22:53:46 +02:00
|
|
|
|
|
|
|
$CONF = Config::getInstance()->getAll();
|
|
|
|
|
|
|
|
$expected = '$1$z2DG4z9d$jBu3Cl3BPQZrkNqnflnSO.';
|
|
|
|
|
|
|
|
$enc = _pacrypt_php_crypt('foo', $expected);
|
|
|
|
|
|
|
|
$this->assertEquals($enc, $expected);
|
|
|
|
|
|
|
|
$fail = _pacrypt_php_crypt('bar', $expected);
|
2020-04-01 22:31:16 +02:00
|
|
|
}
|
|
|
|
|
2021-04-13 22:19:16 +02:00
|
|
|
public function testPhpCryptHandlesPrefixAndOrRounds()
|
|
|
|
{
|
2020-04-01 22:31:16 +02:00
|
|
|
// try with 1000 rounds
|
|
|
|
Config::write('encrypt', 'php_crypt:SHA256:1000');
|
|
|
|
$password = 'hello';
|
|
|
|
|
|
|
|
$randomHash = '$5$VhqhhsXJtPFeBX9e$kz3/CMIEu80bKdtDAcISIrDfdwtc.ilR68Vb3hNhu/7';
|
|
|
|
$randomHashWithPrefix = '{SHA256-CRYPT}' . $randomHash;
|
|
|
|
|
|
|
|
$new = _pacrypt_php_crypt($password, '');
|
|
|
|
|
|
|
|
$this->assertNotEquals($randomHash, $new); // salts should be different.
|
|
|
|
|
|
|
|
$enc = _pacrypt_php_crypt($password, $randomHash);
|
|
|
|
$this->assertEquals($enc, $randomHash);
|
|
|
|
|
|
|
|
$this->assertEquals($randomHash, _pacrypt_php_crypt("hello", $randomHash));
|
|
|
|
$this->assertEquals($randomHash, _pacrypt_crypt("hello", $randomHash));
|
|
|
|
|
|
|
|
Config::write('encrypt', 'php_crypt:SHA256::{SHA256-CRYPT}');
|
|
|
|
|
|
|
|
$enc = _pacrypt_php_crypt("hello", $randomHash);
|
|
|
|
$this->assertEquals($randomHash, $enc); // we passed in something lacking the prefix, so we shouldn't have added it in.
|
|
|
|
$this->assertTrue(hash_equals($randomHash, $enc));
|
|
|
|
|
|
|
|
// should cope with this :
|
|
|
|
$enc = _pacrypt_php_crypt($password, '');
|
|
|
|
|
|
|
|
$this->assertEquals($enc, _pacrypt_php_crypt($password, $enc));
|
2018-04-29 22:53:46 +02:00
|
|
|
|
2020-04-01 22:31:16 +02:00
|
|
|
$this->assertRegExp('/^\{SHA256-CRYPT\}/', $enc);
|
|
|
|
$this->assertGreaterThan(20, strlen($enc));
|
2018-04-29 22:53:46 +02:00
|
|
|
}
|
|
|
|
|
2021-04-13 22:19:16 +02:00
|
|
|
public function testPhpCryptRandomString()
|
|
|
|
{
|
2018-04-29 22:53:46 +02:00
|
|
|
$str1 = _php_crypt_random_string('abcdefg123456789', 2);
|
|
|
|
$str2 = _php_crypt_random_string('abcdefg123456789', 2);
|
2019-02-15 22:31:21 +01:00
|
|
|
$str3 = _php_crypt_random_string('abcdefg123456789', 2);
|
2018-04-29 22:53:46 +02:00
|
|
|
|
|
|
|
$this->assertNotEmpty($str1);
|
|
|
|
$this->assertNotEmpty($str2);
|
2019-02-15 22:31:21 +01:00
|
|
|
$this->assertNotEmpty($str3);
|
|
|
|
|
|
|
|
// it should be difficult for us to get three salts of the same value back...
|
|
|
|
// not impossible though.
|
2020-04-01 22:31:16 +02:00
|
|
|
$this->assertFalse(strcmp($str1, $str2) == 0 && strcmp($str1, $str3) == 0);
|
2018-04-29 22:53:46 +02:00
|
|
|
}
|
2020-03-14 23:30:51 +01:00
|
|
|
|
|
|
|
|
2021-05-08 22:47:45 +02:00
|
|
|
public function testNewDovecotStuff()
|
|
|
|
{
|
|
|
|
global $CONF;
|
2020-03-14 23:30:51 +01:00
|
|
|
|
2021-09-29 22:05:19 +02:00
|
|
|
// should all be from 'test123', generated via dovecot.
|
|
|
|
|
|
|
|
$algo_to_example = [
|
|
|
|
'SHA1' => '{SHA1}cojt0Pw//L6ToM8G41aOKFIWh7w=',
|
|
|
|
'SHA1.B64' => '{SHA1.B64}cojt0Pw//L6ToM8G41aOKFIWh7w=',
|
|
|
|
'BLF-CRYPT' => '{BLF-CRYPT}$2y$05$cEEZv2h/NtLXII.emi2TP.rMZyB7VRSkyToXWBqqz6cXDoyay166q',
|
|
|
|
'BLF-CRYPT.B64' => '{BLF-CRYPT.B64}JDJ5JDA1JEhlR0lBeGFHR2tNUGxjRWpyeFc0eU9oRjZZZ1NuTWVOTXFxNWp4bmFwVjUwdGU3c2x2L1VT',
|
|
|
|
'SHA512-CRYPT' => '{SHA512-CRYPT}$6$MViNQUSbWyXWL9wZ$63VsBU2a/ZFb9f/dK4EmaXABE9jAcNltR7y6a2tXLKoV5F5jMezno.2KpmtD3U0FDjfa7A.pkCluVMlZJ.F64.',
|
|
|
|
'SHA512-CRYPT.B64' => '{SHA512-CRYPT.B64}JDYkR2JwY3NiZXNMWk9DdERXbiRYdXlhdEZTdy9oa3lyUFE0d24wenpGQTZrSlpTUE9QVWdPcjVRUC40bTRMTjEzdy81aWMvWTdDZllRMWVqSWlhNkd3Q2Z0ZnNjZEFpam9OWjl3OU5tLw==',
|
|
|
|
'SHA512' => '{SHA512}2u9JU7l4M2XK1mFSI3IFBsxGxRZ80Wq1APpZeqCP+WTrJPsZaH8012Zfd4/LbFNY/ApbgeFmLPkPc6JnHFP5kQ==',
|
|
|
|
|
|
|
|
// postfixadmin 'incorrectly' classes sha512.b64 as a sha512-crypted string that's b64 encoded.
|
|
|
|
// really SHA512.B64 should be base64_encode(hash('sha512', 'something', true));
|
|
|
|
'SHA512.B64' => '{SHA512-CRYPT.B64}JDYkMDBpOFJXQ0JwMlFMMDlobCRFMVFWLzJjbENPbEo4OTg0SjJyY1oxeXNTaFJIYVhJeVdFTDdHRGl3aHliYkhQUHBUQjZTM0lFMlYya2ZXczZWbHY0aDVNa3N0anpud0xuRTBWZVRELw==',
|
|
|
|
'CRYPT' => '{CRYPT}$2y$05$ORqzr0AagWr25v3ixHD5QuMXympIoNTbipEFZz6aAmovGNoij2vDO',
|
|
|
|
'MD5-CRYPT' => '{MD5-CRYPT}$1$AIjpWveQ$2s3eEAbZiqkJhMYUIVR240',
|
|
|
|
'PLAIN-MD5' => '{PLAIN-MD5}cc03e747a6afbbcbf8be7668acfebee5',
|
|
|
|
'SSHA' => '{SSHA}ZkqrSEAhvd0FTHaK1IxAQCRa5LWbxGQY',
|
|
|
|
'PLAIN' => '{PLAIN}test123',
|
|
|
|
'CLEAR' => '{CLEAR}test123',
|
|
|
|
'CLEARTEXT' => '{CLEARTEXT}test123',
|
|
|
|
'ARGON2I' => '{ARGON2I}$argon2i$v=19$m=32768,t=4,p=1$xoOcAGa27k0Sr6ZPbA9ODw$wl/KAZVmJooD/35IFG5oGwyQiAREXrLss5BPS1PDKfA',
|
|
|
|
'ARGON2ID' => '{ARGON2ID}$argon2id$v=19$m=65536,t=3,p=1$eaXP376O9/VxleLw9OQIxg$jOoDyECeRRV4eta3eSN/j0RdBgqaA1VBGAA/pbviI20',
|
|
|
|
'ARGON2ID.B64' => '{ARGON2ID.B64}JGFyZ29uMmlkJHY9MTkkbT02NTUzNix0PTMscD0xJEljdG9DWko1T04zWlYzM3I0TVMrNEEkMUVtNTJRWkdsRlJzNnBsRXpwVmtMeVd4dVNPRUZ2dUZnaVNhTmNlb08rOA==',
|
|
|
|
'SHA256' => '{SHA256}7NcYcNGWMxapfjrDQIyYNa2M8PPBvHA1J8MCZVNPda4=',
|
|
|
|
'SHA256-CRYPT' => '{SHA256-CRYPT}$5$CFly6wzfn2az3U8j$EhfQPTdjpMGAisfCjCKektLke5GGEmtdLVaCZSmsKw2',
|
|
|
|
'SHA256-CRYPT.B64' => '{SHA256-CRYPT.B64}JDUkUTZZS1ZzZS5sSVJoLndodCR6TWNOUVFVVkhtTmM1ME1SQk9TR3BEeGpRY2M1TzJTQ1lkbWhPN1YxeHlD',
|
2021-05-08 22:47:45 +02:00
|
|
|
];
|
|
|
|
|
2021-09-29 22:23:18 +02:00
|
|
|
// php 7.3 and below do not support these.
|
|
|
|
if (phpversion() < '7.3') {
|
|
|
|
unset($algo_to_example['ARGON2ID']);
|
|
|
|
unset($algo_to_example['ARGON2ID.B64']);
|
|
|
|
}
|
2021-09-29 22:05:19 +02:00
|
|
|
|
|
|
|
foreach ($algo_to_example as $algorithm => $example_hash) {
|
2021-05-08 22:47:45 +02:00
|
|
|
$CONF['encrypt'] = $algorithm;
|
|
|
|
$pfa_new_hash = pacrypt('test123');
|
2020-03-14 23:30:51 +01:00
|
|
|
|
2021-05-08 22:47:45 +02:00
|
|
|
$pacrypt_check = pacrypt('test123', $example_hash);
|
|
|
|
$pacrypt_sanity = pacrypt('zzzzzzz', $example_hash);
|
2020-03-14 23:30:51 +01:00
|
|
|
|
2021-09-29 22:05:19 +02:00
|
|
|
$this->assertNotEquals($example_hash, $pacrypt_sanity, "Should not match, zzzz password. $algorithm / $pacrypt_sanity");
|
2020-03-14 23:30:51 +01:00
|
|
|
|
2021-09-29 22:05:19 +02:00
|
|
|
$this->assertEquals($example_hash, $pacrypt_check, "Should match, algorithm: $algorithm generated:{$pacrypt_check} vs example:{$example_hash}");
|
2020-03-14 23:30:51 +01:00
|
|
|
|
2021-05-08 22:47:45 +02:00
|
|
|
$new_new = pacrypt('test123', $pfa_new_hash);
|
2020-03-14 23:30:51 +01:00
|
|
|
|
2021-05-08 22:47:45 +02:00
|
|
|
$this->assertEquals($pfa_new_hash, $new_new, "Trying: $algorithm => gave: $new_new with $pfa_new_hash ... ");
|
|
|
|
}
|
2020-03-14 23:30:51 +01:00
|
|
|
}
|
2021-05-09 22:31:53 +02:00
|
|
|
|
2021-05-11 22:56:48 +02:00
|
|
|
public function testWeCopeWithDifferentMethodThanConfigured()
|
|
|
|
{
|
2022-06-06 21:34:05 +02:00
|
|
|
global $CONF;
|
|
|
|
$CONF['encrypt'] = 'MD5-CRYPT';
|
2021-05-11 22:56:48 +02:00
|
|
|
|
2022-06-06 21:34:05 +02:00
|
|
|
$md5Crypt = '{MD5-CRYPT}$1$AIjpWveQ$2s3eEAbZiqkJhMYUIVR240';
|
2021-05-11 22:56:48 +02:00
|
|
|
|
2022-06-06 21:34:05 +02:00
|
|
|
$this->assertEquals($md5Crypt, pacrypt('test123', $md5Crypt));
|
|
|
|
$CONF['encrypt'] = 'MD5-CRYPT';
|
2021-05-11 22:56:48 +02:00
|
|
|
|
2022-06-06 21:34:05 +02:00
|
|
|
$this->assertEquals($md5Crypt, pacrypt('test123', $md5Crypt));
|
2021-05-11 22:56:48 +02:00
|
|
|
$sha1Crypt = '{SHA1}cojt0Pw//L6ToM8G41aOKFIWh7w=';
|
|
|
|
|
2022-06-06 21:34:05 +02:00
|
|
|
$this->assertEquals($sha1Crypt, pacrypt('test123', $sha1Crypt));
|
2021-05-11 22:56:48 +02:00
|
|
|
}
|
|
|
|
|
2021-05-09 22:31:53 +02:00
|
|
|
public function testSomeCourierHashes()
|
|
|
|
{
|
|
|
|
global $CONF;
|
|
|
|
|
|
|
|
$options = [
|
2021-05-11 22:56:48 +02:00
|
|
|
'courier:md5' => '{MD5}zAPnR6avu8v4vnZorP6+5Q==',
|
2021-05-09 22:31:53 +02:00
|
|
|
'courier:md5raw' => '{MD5RAW}cc03e747a6afbbcbf8be7668acfebee5',
|
2021-05-11 22:56:48 +02:00
|
|
|
'courier:ssha' => '{SSHA}pJTac1QSIHoi0qBPdqnBvgPdjfFtDRVY',
|
2021-05-09 22:31:53 +02:00
|
|
|
'courier:sha256' => '{SHA256}7NcYcNGWMxapfjrDQIyYNa2M8PPBvHA1J8MCZVNPda4=',
|
|
|
|
];
|
|
|
|
|
|
|
|
foreach ($options as $algorithm => $example_hash) {
|
|
|
|
$CONF['encrypt'] = $algorithm;
|
|
|
|
|
|
|
|
$pacrypt_check = pacrypt('test123', $example_hash);
|
|
|
|
$pacrypt_sanity = pacrypt('zzzzz', $example_hash);
|
|
|
|
$pfa_new_hash = pacrypt('test123');
|
|
|
|
|
|
|
|
$this->assertNotEquals($pacrypt_sanity, $pfa_new_hash);
|
|
|
|
$this->assertNotEquals($pacrypt_sanity, $example_hash);
|
|
|
|
|
2021-05-11 22:56:48 +02:00
|
|
|
$this->assertEquals($example_hash, $pacrypt_check, "Should match, algorithm: $algorithm generated:{$pacrypt_check} vs example:{$example_hash}");
|
2021-05-09 22:31:53 +02:00
|
|
|
|
|
|
|
$new = pacrypt('test123', $pfa_new_hash);
|
|
|
|
|
2021-05-11 22:56:48 +02:00
|
|
|
$this->assertEquals($new, $pfa_new_hash, "Trying: $algorithm => gave: $new with $pfa_new_hash");
|
2021-05-09 22:31:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-11 21:21:16 +02:00
|
|
|
/**
|
|
|
|
* @see https://github.com/postfixadmin/postfixadmin/issues/647
|
|
|
|
*/
|
|
|
|
public function testSha512B64SupportsMd5CryptMigration()
|
|
|
|
{
|
|
|
|
global $CONF;
|
|
|
|
|
|
|
|
Config::write('encrypt', 'sha512.b64');
|
|
|
|
$CONF['encrypt'] = 'sha512.b64';
|
|
|
|
|
|
|
|
$x = pacrypt('test123');
|
|
|
|
|
|
|
|
$this->assertRegExp('/^\{SHA512-CRYPT\.B64/', $x);
|
|
|
|
$this->assertTrue(strlen($x) > 50);
|
|
|
|
|
|
|
|
$this->assertEquals($x, pacrypt('test123', $x));
|
|
|
|
|
|
|
|
// while we're configured for SHA512-CRYPT.B64, we still support MD5-CRYPT format ...
|
|
|
|
$md5crypt = '{MD5-CRYPT}$1$c9809462$fC8eUPU2lq7arWRvxChMu1';
|
|
|
|
|
|
|
|
$x = pacrypt('test123', $md5crypt);
|
|
|
|
$this->assertEquals($x, $md5crypt);
|
|
|
|
}
|
|
|
|
|
2021-11-14 21:50:41 +01:00
|
|
|
public function testObviousMechanisms()
|
2021-09-25 21:31:20 +02:00
|
|
|
{
|
|
|
|
global $CONF;
|
|
|
|
|
|
|
|
$mechs = [
|
|
|
|
'md5crypt' => '$1$c9809462$fC8eUPU2lq7arWRvxChMu1',
|
|
|
|
'md5' => 'cc03e747a6afbbcbf8be7668acfebee5',
|
|
|
|
'cleartext' => 'test123',
|
|
|
|
'mysql_encrypt' => '$6$$KMCDSuWNoVgNrK5P1zDS12ZZt.LV4z9v9NtD0AG0T5Rv/n0wWVvZmHMSKKZQciP7lrqrlbrBrBd4lhBSGy1BU0',
|
2022-06-23 23:17:22 +02:00
|
|
|
'authlib' => '{MD5RAW}cc03e747a6afbbcbf8be7668acfebee5', // authpasswd md5raw (via courier-authdaemon package)
|
2021-09-29 19:32:46 +02:00
|
|
|
'php_crypt:SHA512' => '{SHA512-CRYPT}$6$IeqpXtDIXF09ADdc$IsE.SSK3zuwtS9fdWZ0oVxXQjPDj834xqxTiv3Qfidq3AbAjPb0DNyI28JyzmDVlbfC9uSfNxD9RUyeO1.7FV/',
|
2021-09-25 21:31:20 +02:00
|
|
|
'php_crypt:DES' => 'VXAXutUnpVYg6',
|
|
|
|
'php_crypt:MD5' => '$1$rGTbP.KE$wimpECWs/wQa7rnSwCmHU.',
|
|
|
|
'php_crypt:SHA256' => '$5$UaZs6ZuaLkVPx3bM$4JwAqdphXVutFYw7COgAkp/vj09S1DfjIftxtjqDrr/',
|
2021-11-14 21:50:41 +01:00
|
|
|
'php_crypt:BLOWFISH' => '$2y$10$4gbwQMAoJPcg.mWnENYNg.syH9mZNsbQu6KN7skK92g3tlPnvvBDW',
|
2021-09-25 21:31:20 +02:00
|
|
|
'sha512.b64' => '{SHA512-CRYPT.B64}JDYkMDBpOFJXQ0JwMlFMMDlobCRFMVFWLzJjbENPbEo4OTg0SjJyY1oxeXNTaFJIYVhJeVdFTDdHRGl3aHliYkhQUHBUQjZTM0lFMlYya2ZXczZWbHY0aDVNa3N0anpud0xuRTBWZVRELw==',
|
2021-09-29 22:27:28 +02:00
|
|
|
|
2022-06-23 23:17:22 +02:00
|
|
|
];
|
2021-11-14 21:50:41 +01:00
|
|
|
|
|
|
|
|
2021-09-25 21:31:20 +02:00
|
|
|
foreach ($mechs as $mech => $example_hash) {
|
|
|
|
if ($mech == 'mysql_encrypt' && Config::read_string('database_type') != 'mysql') {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
Config::write('encrypt', $mech);
|
|
|
|
|
|
|
|
$CONF['encrypt'] = $mech;
|
2021-11-14 21:50:41 +01:00
|
|
|
|
2021-09-25 21:31:20 +02:00
|
|
|
$x = pacrypt('test123');
|
|
|
|
$this->assertNotEmpty($x);
|
|
|
|
|
|
|
|
$y = pacrypt('test123', $x);
|
|
|
|
$this->assertEquals($x, $y); // $y == %x if the password was correct.
|
|
|
|
|
|
|
|
// should be valid against what's in the lookup array above
|
|
|
|
$x = pacrypt('test123', $example_hash);
|
|
|
|
|
|
|
|
$this->assertEquals($example_hash, $x);
|
|
|
|
}
|
|
|
|
}
|
2018-02-19 21:59:52 +01:00
|
|
|
}
|