summaryrefslogtreecommitdiff
path: root/inc
diff options
context:
space:
mode:
authorczaks <marcin@6irc.net>2016-05-05 06:43:22 +0200
committerczaks <marcin@6irc.net>2016-05-05 06:43:22 +0200
commit7c3126866cd291d515ab5cc83d4635c3c95c6d85 (patch)
tree8eb21f57b88e36c481da8f8a74c32ec52ce4f4ab /inc
parent2caad907557e38eb0172f96d1e740e1077e81267 (diff)
ease the migration process for the previous security patch (by introducing another migration); restore php 5.4 compatibility (introducing a polyfill system)
Diffstat (limited to 'inc')
-rwxr-xr-xinc/functions.php2
-rw-r--r--inc/mod/auth.php10
-rw-r--r--inc/mod/pages.php18
-rw-r--r--inc/polyfill.php28
4 files changed, 44 insertions, 14 deletions
diff --git a/inc/functions.php b/inc/functions.php
index 515e3e55..3f5ed3b0 100755
--- a/inc/functions.php
+++ b/inc/functions.php
@@ -18,6 +18,8 @@ require_once 'inc/template.php';
require_once 'inc/database.php';
require_once 'inc/events.php';
require_once 'inc/api.php';
+require_once 'inc/polyfill.php';
+
if (!extension_loaded('gettext')) {
require_once 'inc/lib/gettext/gettext.inc';
}
diff --git a/inc/mod/auth.php b/inc/mod/auth.php
index fa1a0f4f..d877b89f 100644
--- a/inc/mod/auth.php
+++ b/inc/mod/auth.php
@@ -76,20 +76,20 @@ function generate_salt() {
function login($username, $password) {
global $mod, $config;
- $query = prepare("SELECT `id`, `type`, `boards`, `password`, `salt` FROM ``mods`` WHERE `username` = :username");
+ $query = prepare("SELECT `id`, `type`, `boards`, `password`, `version` FROM ``mods`` WHERE `username` = :username");
$query->bindValue(':username', $username);
$query->execute() or error(db_error($query));
if ($user = $query->fetch(PDO::FETCH_ASSOC)) {
- list($version, $ok) = test_password($user['password'], $user['salt'], $password);
+ list($version, $ok) = test_password($user['password'], $user['version'], $password);
if ($ok) {
if ($config['password_crypt_version'] > $version) {
// It's time to upgrade the password hashing method!
- list ($user['salt'], $user['password']) = crypt_password($password);
- $query = prepare("UPDATE ``mods`` SET `password` = :password, `salt` = :salt WHERE `id` = :id");
+ list ($user['version'], $user['password']) = crypt_password($password);
+ $query = prepare("UPDATE ``mods`` SET `password` = :password, `version` = :version WHERE `id` = :id");
$query->bindValue(':password', $user['password']);
- $query->bindValue(':salt', $user['salt']);
+ $query->bindValue(':version', $user['version']);
$query->bindValue(':id', $user['id']);
$query->execute() or error(db_error($query));
}
diff --git a/inc/mod/pages.php b/inc/mod/pages.php
index a07de4c7..8b6f73c4 100644
--- a/inc/mod/pages.php
+++ b/inc/mod/pages.php
@@ -1734,12 +1734,12 @@ function mod_user($uid) {
}
if ($_POST['password'] != '') {
- list($salt, $password) = crypt_password($_POST['password']);
+ list($version, $password) = crypt_password($_POST['password']);
- $query = prepare('UPDATE ``mods`` SET `password` = :password, `salt` = :salt WHERE `id` = :id');
+ $query = prepare('UPDATE ``mods`` SET `password` = :password, `version` = :version WHERE `id` = :id');
$query->bindValue(':id', $uid);
$query->bindValue(':password', $password);
- $query->bindValue(':salt', $salt);
+ $query->bindValue(':version', $version);
$query->execute() or error(db_error($query));
modLog('Changed password for ' . utf8tohtml($_POST['username']) . ' <small>(#' . $user['id'] . ')</small>');
@@ -1760,12 +1760,12 @@ function mod_user($uid) {
if (hasPermission($config['mod']['change_password']) && $uid == $mod['id'] && isset($_POST['password'])) {
if ($_POST['password'] != '') {
- list($salt, $password) = crypt_password($_POST['password']);
+ list($version, $password) = crypt_password($_POST['password']);
- $query = prepare('UPDATE ``mods`` SET `password` = :password, `salt` = :salt WHERE `id` = :id');
+ $query = prepare('UPDATE ``mods`` SET `password` = :password, `version` = :version WHERE `id` = :id');
$query->bindValue(':id', $uid);
$query->bindValue(':password', $password);
- $query->bindValue(':salt', $salt);
+ $query->bindValue(':version', $version);
$query->execute() or error(db_error($query));
modLog('Changed own password');
@@ -1832,12 +1832,12 @@ function mod_user_new() {
if (!isset($config['mod']['groups'][$type]) || $type == DISABLED)
error(sprintf($config['error']['invalidfield'], 'type'));
- list($salt, $password) = crypt_password($_POST['password']);
+ list($version, $password) = crypt_password($_POST['password']);
- $query = prepare('INSERT INTO ``mods`` VALUES (NULL, :username, :password, :salt, :type, :boards)');
+ $query = prepare('INSERT INTO ``mods`` VALUES (NULL, :username, :password, :version, :type, :boards)');
$query->bindValue(':username', $_POST['username']);
$query->bindValue(':password', $password);
- $query->bindValue(':salt', $salt);
+ $query->bindValue(':version', $version);
$query->bindValue(':type', $type);
$query->bindValue(':boards', implode(',', $boards));
$query->execute() or error(db_error($query));
diff --git a/inc/polyfill.php b/inc/polyfill.php
new file mode 100644
index 00000000..ac40a00a
--- /dev/null
+++ b/inc/polyfill.php
@@ -0,0 +1,28 @@
+<?php
+
+// PHP 5.4
+
+if (!function_exists('hex2bin')) {
+ function hex2bin($data) {
+ return pack("H*" , $hex_string);
+ }
+}
+
+// PHP 5.6
+
+if (!function_exists('hash_equals')) {
+ function hash_equals($ours, $theirs) {
+ $ours = (string)$ours;
+ $theirs = (string)$theirs;
+
+ $tlen = strlen($theirs);
+ $olen = strlen($ours);
+
+ $answer = 0;
+ for ($i = 0; $i < $tlen; $i++) {
+ $answer |= ord($ours[$olen > $i ? $i : 0]) ^ ord($theirs[$i]);
+ }
+
+ return $answer === 0 && $olen === $tlen;
+ }
+}