Ignore:
Timestamp:
Nov 15, 2014 9:34:39 PM (10 years ago)
Author:
anonymous
Message:

Many auth and crypto changes; various other bugfixes while working on pulso.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Utilities.inc.php

    r497 r500  
    945945 * environment variable set in httpd.conf is a good place.
    946946 *
     947 * TODO: consider using more bits-per-character, such as done with:
     948 * http://www.php.net/manual/en/function.sha1.php#86239
     949 * http://blog.kevburnsjr.com/php-unique-hash
     950 *
    947951 * @access  public
    948952 * @param   string  $val    The string to sign.
     
    964968    }
    965969
    966     // TODO: consider using more bits-per-character, such as done with:
    967     // http://www.php.net/manual/en/function.sha1.php#86239
    968     // http://blog.kevburnsjr.com/php-unique-hash
    969     return $val . '-' . mb_strtolower(mb_substr(md5($salt . md5($val . $salt)), 0, $length));
     970    switch ($app->getParam('signing_method')) {
     971    case 'sha512+base64':
     972        return $val . '-' . mb_substr(preg_replace('/[^\w]/', '', base64_encode(hash('sha512', $val . $salt, true))), 0, $length);
     973
     974    case 'md5':
     975    default:
     976        return $val . '-' . mb_strtolower(mb_substr(md5($salt . md5($val . $salt)), 0, $length));
     977    }
    970978}
    971979
     
    986994
    987995/**
    988  * Verifies a signature appened to a value by addSignature().
     996 * Verifies a signature appended to a value by addSignature().
    989997 *
    990998 * @access  public
     
    9951003function verifySignature($signed_val, $salt=null, $length=18)
    9961004{
    997     // All comparisons are done using lower-case strings.
    998     $signed_val = mb_strtolower($signed_val);
    9991005    // Strip the value from the signed value.
    10001006    $val = removeSignature($signed_val);
     
    10041010        return true;
    10051011    } else {
     1012        $app =& App::getInstance();
     1013        $app->logMsg(sprintf('Failed signature (%s should be %s)', $signed_val, addSignature($val, $salt, $length)), LOG_DEBUG, __FILE__, __LINE__);
    10061014        return false;
    10071015    }
     
    12551263    }
    12561264}
    1257 
Note: See TracChangeset for help on using the changeset viewer.