# HG changeset patch # User Dan # Date 1242512229 14400 # Node ID f34ecfa459abe51322d89403ce53b84aa2c0e785 # Parent 5a359c7ebc485c19fc539dda3be8acd2f8b9c2a8 Wrote my own Yubico-time-to-Unix-time conversion, as strtotime() was unreliable. diff -r 5a359c7ebc48 -r f34ecfa459ab plugins/yubikey/corelib.php --- a/plugins/yubikey/corelib.php Mon May 11 08:53:10 2009 -0400 +++ b/plugins/yubikey/corelib.php Sat May 16 18:17:09 2009 -0400 @@ -201,10 +201,9 @@ $tolerance = intval(getConfig('yubikey_api_ts_tolerance', 150)); $now = time(); - $timestamp = preg_replace('/Z[0-9]{3,5}$/', '', $timestamp); - $timestamp_seconds = strtotime($timestamp); + $timestamp_seconds = yk_strtotime($timestamp); - if ( !$timestamp || !$now ) + if ( !$timestamp || !$now || !$timestamp_seconds ) { return false; } @@ -217,6 +216,20 @@ return false; } +function yk_strtotime($timestamp) +{ + if ( !preg_match('/^([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})(?:Z[0-9]+)$/', $timestamp, $match) ) + return 0; + + $hour = intval($match[4]); + $minute = intval($match[5]); + $second = intval($match[6]); + $month = intval($match[2]); + $day = intval($match[3]); + $year = intval($match[1]); + + return gmmktime($hour, $minute, $second, $month, $day, $year); +} $plugins->attachHook('compile_template', 'yubikey_attach_headers($this);');