From 087085d618e57aea5f292a5bb57d46304574cc6a Mon Sep 17 00:00:00 2001 From: Robert Kaiser Date: Thu, 27 Oct 2016 01:49:06 +0200 Subject: [PATCH] actually use the on-disk site-specific nonce to 'pepper' passwords before hashing so that stealing the database won't even reveal weak passwords --- authsystem.inc.php | 4 +++- authutils.php-class | 7 +++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/authsystem.inc.php b/authsystem.inc.php index a30e2ab..322e17f 100644 --- a/authsystem.inc.php +++ b/authsystem.inc.php @@ -9,6 +9,8 @@ ini_set('display_errors', 1); error_reporting(E_ALL); // Read DB settings $dbdata = json_decode(file_get_contents('/etc/kairo/auth_db.json'), true); if (!is_array($dbdata)) { trigger_error('DB configuration not found', E_USER_ERROR); } +$settings = json_decode(file_get_contents('/etc/kairo/auth_settings.json'), true); +if (!is_array($settings)) { trigger_error('Auth settings not found', E_USER_ERROR); } // Extended DOM document class require_once('../kairo/include/cbsm/util/document.php-class'); @@ -16,7 +18,7 @@ require_once('../kairo/include/cbsm/util/document.php-class'); require_once('../kairo/include/classes/email.php-class'); // Class for sending emails require_once(__DIR__.'/authutils.php-class'); -$utils = new AuthUtils(array()); +$utils = new AuthUtils($settings); bindtextdomain('kairo_auth', 'en'); // XXX: Should negotiate locale. bind_textdomain_codeset('kairo_auth', 'utf-8'); diff --git a/authutils.php-class b/authutils.php-class index 2d4573f..0b7d4b1 100755 --- a/authutils.php-class +++ b/authutils.php-class @@ -15,6 +15,7 @@ class AuthUtils { // // private $pwd_nonces // The array of nonces to use for "peppering" passwords. For new hashes, the last one of those will be used. + // Generate a nonce with this command: |openssl rand -base64 48| // // function checkPasswordConstraints($new_password, $user_email) // Check password constraints and return an array of error messages (empty if all constraints are met). @@ -119,10 +120,12 @@ class AuthUtils { } function pwdVerify($password_to_verify, $userdata) { - if (preg_match('/^(\d+)\|/', $userdata['pwdhash'], $regs)) { + $pwdhash = $userdata['pwdhash']; + if (preg_match('/^(\d+)\|(.+)$/', $userdata['pwdhash'], $regs)) { $password_to_verify .= $this->pwd_nonces[$regs[1]]; + $pwdhash = $regs[2]; } - return password_verify($password_to_verify, $userdata['pwdhash']); + return password_verify($password_to_verify, $pwdhash); } function pwdNeedsRehash($userdata) { -- 2.35.3