Browse Source

Add more logging to aid debugging

master
Chris Smith 13 years ago
parent
commit
0a0b480845
3 changed files with 23 additions and 0 deletions
  1. 14
    0
      keymanager.inc.php
  2. 7
    0
      processor.php
  3. 2
    0
      urlbuilder.inc.php

+ 14
- 0
keymanager.inc.php View File

@@ -43,6 +43,7 @@
43 43
    */
44 44
   private static function loadData() {
45 45
    if (self::$data == null) {
46
+    Logger::log('Loading data from %s/keycache.php', dirname(__FILE__));
46 47
     $data = file(dirname(__FILE__) . '/keycache.php');
47 48
     self::$header = array_shift($data);
48 49
     self::$data = unserialize(implode("\n", $data));
@@ -53,6 +54,7 @@
53 54
    * Saves the KeyManager's data array to disk.
54 55
    */
55 56
   private static function saveData() {
57
+   Logger::log('Saving data to %s/keycache.php', dirname(__FILE__));
56 58
    file_put_contents(dirname(__FILE__) . '/keycache.php', self::$header . serialize(self::$data));
57 59
   }
58 60
 
@@ -164,6 +166,7 @@
164 166
    self::loadData();
165 167
 
166 168
    if (!isset(self::$data[$server])) {
169
+    Logger::log('No data found for %s', $server);
167 170
     return null;
168 171
    }
169 172
 
@@ -171,6 +174,7 @@
171 174
     if ($handle == '__private') { continue; }
172 175
 
173 176
     if ($data['expires_at'] < time()) {
177
+     Logger::log('Handle for %s expired at %s, unsetting', $server, $data['expires_at']);
174 178
      unset(self::$data[$server][$handle]);
175 179
     } else {
176 180
      return $handle;
@@ -224,9 +228,12 @@
224 228
    * @return True if the message was authenticated, false if it's a fake
225 229
    */
226 230
   public static function authenticate($server, $args) {
231
+   Logger::log('Authenticating message from %s', $server);
232
+
227 233
    $data = self::getData($server, $args['openid_assoc_handle']);
228 234
 
229 235
    if ($data === null) {
236
+    Logger::log('Can\'t authenticate, no key available');
230 237
     throw new Exception('No key available for that server/handle');
231 238
    }
232 239
 
@@ -244,16 +251,20 @@
244 251
      $algo = 'sha256';
245 252
      break;
246 253
     default:
254
+     Logger::log('Can\'t authenticate, unknown assoc type %s', $data['assoc_type']);
247 255
      throw new Exception('Unable to handle association type ' . $data['assoc_type']);
248 256
    }
249 257
 
250 258
    $sig = base64_encode(hash_hmac($algo, $contents, base64_decode($data['mac_key']), true));
259
+   Logger::log('Expected signature %s, received signature %s', $sig, $args['openid_sig']);
251 260
 
252 261
    // Manually compare characters to prevent timing attacks
253 262
    $res = strlen($sig) == strlen($args['openid_sig']);
254 263
    for ($i = 0; $i < strlen($sig); $i++) {
255 264
     $res &= $sig[$i] == $args['openid_sig'][$i];
256 265
    }
266
+
267
+   Logger::log('Authentication result: %s', $res ? 'good' : 'bad');
257 268
    return $res;
258 269
   }
259 270
 
@@ -264,6 +275,8 @@
264 275
    * @return True if the request has been authenticated, false otherwise.
265 276
    */
266 277
   public static function dumbAuthenticate() {
278
+   Logger::log('Performing dumb authentication');
279
+
267 280
    $url = URLBuilder::buildAuth($_REQUEST, $_SESSION['openid']['version']);
268 281
 
269 282
    try {
@@ -279,6 +292,7 @@
279 292
     }
280 293
    }
281 294
 
295
+   Logger::log('Authentication result: %s', $valid ? 'good' : 'bad');
282 296
    return $valid;
283 297
   }
284 298
 

+ 7
- 0
processor.php View File

@@ -173,6 +173,8 @@
173 173
     error('notvalid', 'Claimed identity is not a valid identifier');
174 174
    }
175 175
 
176
+   Logger::log('Finished discovery on %s', $url);
177
+
176 178
    return $disc;
177 179
   } catch (Exception $e) {
178 180
    Logger::log('Error during discovery on %s: %s', $url, $e->getMessage());
@@ -190,13 +192,18 @@
190 192
   * @return The association handle of the server or null on failure
191 193
   */
192 194
  function getHandle($server) {
195
+  Logger::log('Attempting to find a handle for %s', $server);
196
+
193 197
   if (KEYMANAGER) {
198
+   Logger::log('Using the key manager...');
194 199
    if (!KeyManager::hasHandle($server)) {
200
+    Logger::log('Key manager has no handle, trying to associate with %s', $server);
195 201
     KeyManager::associate($server);
196 202
    }
197 203
 
198 204
    return KeyManager::getHandle($server);
199 205
   } else {
206
+   Logger::log('Not using key manager...');
200 207
    return null;
201 208
   }
202 209
  }

+ 2
- 0
urlbuilder.inc.php View File

@@ -22,6 +22,7 @@
22 22
  * SOFTWARE.
23 23
  */
24 24
 
25
+ require_once(dirname(__FILE__) . '/logging.inc.php');
25 26
  require_once(dirname(__FILE__) . '/keymanager.inc.php');
26 27
 
27 28
  class URLBuilder {
@@ -246,6 +247,7 @@
246 247
    * @param $url The URL to redirect the user to
247 248
    */
248 249
   public static function doRedirect($url) {
250
+   Logger::log('Redirecting to %s', $url);
249 251
    header('Location: ' . $url);
250 252
    echo '<html><head><title>Redirecting</title></head><body>';
251 253
    echo '<p>Redirecting to <a href="', htmlentities($url), '">';

Loading…
Cancel
Save