Browse Source

Handle IdPs rejecting assoc/session types

Poster now continues regardless of response code (as IdP may send 400 error
for bad assoc/session types, for example). This creates a dependency on
PHP 5.2.10.

Closes #1
tags/0.6
Chris Smith 14 years ago
parent
commit
79c33359e4
4 changed files with 35 additions and 7 deletions
  1. 26
    2
      keymanager.inc.php
  2. 2
    1
      poster.inc.php
  3. 1
    1
      test.php
  4. 6
    3
      urlbuilder.inc.php

+ 26
- 2
keymanager.inc.php View File

@@ -23,6 +23,7 @@
23 23
  */
24 24
 
25 25
  require_once(dirname(__FILE__) . '/bigmath.inc.php');
26
+ require_once(dirname(__FILE__) . '/logging.inc.php');
26 27
  require_once(dirname(__FILE__) . '/poster.inc.php');
27 28
  require_once(dirname(__FILE__) . '/urlbuilder.inc.php');
28 29
 
@@ -60,12 +61,14 @@
60 61
    *
61 62
    * @param String $server The server to associate with
62 63
    */
63
-  public static function associate($server) {
64
-   $data = URLBuilder::buildAssociate($server, $_SESSION['openid']['version']);
64
+  public static function associate($server, $assocType = null, $sessionType = null) {
65
+   Logger::log('Attempting to associate with %s, assocType: %s, sessionType: %s', $server, $assocType, $sessionType);
66
+   $data = URLBuilder::buildAssociate($server, $_SESSION['openid']['version'], $assocType, $sessionType);
65 67
 
66 68
    try {
67 69
     $res = Poster::post($server, $data);
68 70
    } catch (Exception $ex) {
71
+    Logger::log('Exception while posting: %s', $ex->getMessage());
69 72
     return;
70 73
    }
71 74
 
@@ -77,6 +80,27 @@
77 80
     }
78 81
    }
79 82
 
83
+   if (isset($data['error_code']) && $data['error_code'] == 'unsupported-type') {
84
+    $cont = false;
85
+
86
+    if (isset($data['session_type']) && $data['session_type'] != $sessionType) {
87
+     // TODO: Check we support it before actually trying
88
+     $sessionType = $data['session_type'];
89
+     $cont = true;
90
+    }
91
+
92
+    if (isset($data['assoc_type']) && $data['assoc_type'] != $assocType) {
93
+     $assocType = $data['assoc_type'];
94
+     $cont = true;
95
+    }
96
+
97
+    if ($cont) {
98
+     self::associate($server, $assocType, $sessionType);
99
+    }
100
+
101
+    return;
102
+   }
103
+
80 104
    try {
81 105
     $data = self::decodeKey($server, $data);
82 106
    } catch (Exception $ex) {

+ 2
- 1
poster.inc.php View File

@@ -28,7 +28,8 @@
28 28
    $params = array(
29 29
 	'http' => array(
30 30
 		'method' => 'POST',
31
-                 'content' => $data
31
+                'content' => $data,
32
+		'ignore_errors' => true
32 33
 	)
33 34
    );
34 35
 

+ 1
- 1
test.php View File

@@ -55,7 +55,7 @@
55 55
  }
56 56
 
57 57
  echo '<tr><th colspan="2">Poidsy requirements</th></tr>';
58
- doTest('PHP Version', version_compare(PHP_VERSION, '5.2.0', '>='), 'Poidsy requires PHP version 5.2.0 or greater to run');
58
+ doTest('PHP Version', version_compare(PHP_VERSION, '5.2.10', '>='), 'Poidsy requires PHP version 5.2.10 or greater to run');
59 59
  doTest('Allow_url_fopen', ini_get('allow_url_fopen'), 'Poidsy requires allow_url_fopen to be configured to true');
60 60
 
61 61
  echo '<tr><th colspan="2">Associate mode requirements</th></tr>';

+ 6
- 3
urlbuilder.inc.php View File

@@ -113,10 +113,13 @@
113 113
    }
114 114
   }
115 115
 
116
-  public static function buildAssociate($server, $version = 1) {
116
+  public static function buildAssociate($server, $version = 1, $assocType = null, $sessionType = null) {
117
+   if ($assocType == null) { $assocType = 'HMAC-SHA1'; }
118
+   if ($sessionType == null) { $sessionType = 'DH-SHA1'; }
119
+
117 120
    $args = array(
118 121
 	'openid.mode' => 'associate',
119
-	'openid.assoc_type' => 'HMAC-SHA1',
122
+	'openid.assoc_type' => $assocType,
120 123
    );
121 124
 
122 125
    if ($version >= self::MIN_VERSION_FOR_NS) {
@@ -124,7 +127,7 @@
124 127
    }
125 128
 
126 129
    if (KeyManager::supportsDH()) {
127
-    $args['openid.session_type'] = 'DH-SHA1';
130
+    $args['openid.session_type'] = $sessionType;
128 131
     $args['openid.dh_modulus'] = KeyManager::getDhModulus();
129 132
     $args['openid.dh_gen'] = KeyManager::getDhGen();
130 133
     $args['openid.dh_consumer_public'] = KeyManager::getDhPublicKey($server);

Loading…
Cancel
Save