Wrote my own Yubico-time-to-Unix-time conversion, as strtotime() was unreliable.
authorDan
Sat, 16 May 2009 18:17:09 -0400
changeset 21 f34ecfa459ab
parent 20 5a359c7ebc48
child 22 9b8688df52d5
Wrote my own Yubico-time-to-Unix-time conversion, as strtotime() was unreliable.
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);');