ソースを参照

Perform discovery on identity select'd ids to ensure the IdP is allowed

to claim them
tags/0.5
Chris Smith 15年前
コミット
0380c4a45d
2個のファイルの変更23行の追加8行の削除
  1. 15
    5
      discoverer.inc.php
  2. 8
    3
      processor.php

+ 15
- 5
discoverer.inc.php ファイルの表示

@@ -25,13 +25,14 @@
25 25
 class Discoverer {
26 26
 
27 27
  private $server = null;
28
+ private $servers = array();
28 29
  private $delegate = '';
29 30
  private $identity = '';
30 31
  private $version = 1;
31 32
 
32
- public function __construct($uri) {
33
+ public function __construct($uri, $normalise = true) {
33 34
   if ($uri !== null) {
34
-   $this->discover($this->identity = $this->normalise($uri));
35
+   $this->discover($this->identity = ($normalise ? $this->normalise($uri) : $uri));
35 36
   }
36 37
  }
37 38
 
@@ -39,6 +40,10 @@ class Discoverer {
39 40
   return $this->server;
40 41
  }
41 42
 
43
+ public function hasServer($server) {
44
+  return array_search($server, $this->servers) !== false;
45
+ }
46
+
42 47
  public function getDelegate() {
43 48
   return $this->delegate;
44 49
  }
@@ -155,15 +160,18 @@ class Discoverer {
155 160
   }
156 161
 
157 162
   // TODO: Better handling of namespaces
163
+  $found = false;
158 164
   foreach ($sxml->XRD->Service as $service) {
159 165
    if ((String) $service->Type == 'http://specs.openid.net/auth/2.0/server') {
160 166
     $this->version = 2;
161 167
     $this->server = (String) $service->URI;
162 168
     $this->identity = $this->delegate = 'http://specs.openid.net/auth/2.0/identifier_select';
163
-    return true;
169
+    $this->servers[] = $this->server;
170
+    $found = true;
164 171
    } else if ((String) $service->Type == 'http://specs.openid.net/auth/2.0/signon') {
165 172
     $this->version = 2;
166 173
     $this->server = (String) $service->URI;
174
+    $this->servers[] = $this->server;
167 175
 
168 176
     if (isset($service->LocalID)) {
169 177
      $this->identity = (String) $service->LocalID;
@@ -172,11 +180,11 @@ class Discoverer {
172 180
     }
173 181
     $this->delegate = 'http://specs.openid.net/auth/2.0/identifier_select';
174 182
 
175
-    return true;
183
+    $found = true;
176 184
    }
177 185
   }
178 186
 
179
-  return false;
187
+  return $found;
180 188
  }
181 189
 
182 190
  private function parseYadisHTML($data) {
@@ -263,6 +271,7 @@ class Discoverer {
263 271
   if (isset($links['openid2.provider'])) {
264 272
    $this->version = 2;
265 273
    $this->server = $links['openid2.provider'];
274
+   $this->servers[] = $this->server;
266 275
 
267 276
    if (isset($links['openid2.local_id'])) {
268 277
     $this->delegate = $links['openid2.local_id'];
@@ -270,6 +279,7 @@ class Discoverer {
270 279
   } else if (isset($links['openid.server'])) {
271 280
    $this->version = 1;
272 281
    $this->server = $links['openid.server'];
282
+   $this->servers[] = $this->server;
273 283
 
274 284
    if (isset($links['openid.delegate'])) {
275 285
     $this->delegate = $links['openid.delegate'];

+ 8
- 3
processor.php ファイルの表示

@@ -244,9 +244,14 @@
244 244
  function processPositiveResponse($valid) {
245 245
   if ($_REQUEST['openid_identity'] != $_SESSION['openid']['delegate']) {
246 246
    if ($_SESSION['openid']['delegate'] == 'http://specs.openid.net/auth/2.0/identifier_select') {
247
-    $_SESSION['openid']['identity'] = $_REQUEST['openid_identity']; 
248
-    $_SESSION['openid']['delegate'] = $_REQUEST['openid_claimed_id'];
249
-    // TODO: This needs to be verified by perfoming discovery on the url
247
+    $disc = new Discoverer($_REQUEST['openid_claimed_id'], false);
248
+ 
249
+    if ($disc->hasServer($_SESSION['openid']['server'])) {
250
+     $_SESSION['openid']['identity'] = $_REQUEST['openid_identity']; 
251
+     $_SESSION['openid']['delegate'] = $_REQUEST['openid_claimed_id'];
252
+    } else {
253
+     error('diffid', 'The OP at ' . $_SESSION['openid']['server'] . ' is attmpting to claim ' . $_REQUEST['openid_claimed_id'] . ' but ' . ($disc->getServer() == null ? 'that isn\'t a valid identifier' : 'that identifier only authorises ' . $disc->getServer()));
254
+    }
250 255
    } else {
251 256
      error('diffid', 'Identity provider validated wrong identity. Expected it to '
252 257
   	             . 'validate ' . $_SESSION['openid']['delegate'] . ' but it '

読み込み中…
キャンセル
保存