author | Michael Krelin <hacker@klever.net> | 2008-02-02 19:57:52 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2008-02-02 19:57:52 (UTC) |
commit | 529c53f0eb63040735b4cad7806cef6d5e65144b (patch) (unidiff) | |
tree | 711cd9e8d30a9f251de529cdfcfcd05ac0e871b3 | |
parent | 4efb668baed49ede14846c3cdac31cc561451cd1 (diff) | |
download | libopkele-529c53f0eb63040735b4cad7806cef6d5e65144b.zip libopkele-529c53f0eb63040735b4cad7806cef6d5e65144b.tar.gz libopkele-529c53f0eb63040735b4cad7806cef6d5e65144b.tar.bz2 |
check if return_to matches realm
Signed-off-by: Michael Krelin <hacker@klever.net>
-rw-r--r-- | include/opkele/exception.h | 9 | ||||
-rw-r--r-- | lib/basic_op.cc | 36 |
2 files changed, 45 insertions, 0 deletions
diff --git a/include/opkele/exception.h b/include/opkele/exception.h index 5c8418e..33f89cc 100644 --- a/include/opkele/exception.h +++ b/include/opkele/exception.h | |||
@@ -358,4 +358,13 @@ namespace opkele { | |||
358 | }; | 358 | }; |
359 | 359 | ||
360 | /** | ||
361 | * thrown if return_to URL doesn't match realm | ||
362 | */ | ||
363 | class bad_return_to : public exception { | ||
364 | public: | ||
365 | bad_return_to(OPKELE_E_PARS) | ||
366 | : exception(OPKELE_E_CONS) { } | ||
367 | }; | ||
368 | |||
360 | } | 369 | } |
361 | 370 | ||
diff --git a/lib/basic_op.cc b/lib/basic_op.cc index 22012bc..f7573aa 100644 --- a/lib/basic_op.cc +++ b/lib/basic_op.cc | |||
@@ -1,4 +1,5 @@ | |||
1 | #include <time.h> | 1 | #include <time.h> |
2 | #include <cassert> | 2 | #include <cassert> |
3 | #include <algorithm> | ||
3 | #include <openssl/sha.h> | 4 | #include <openssl/sha.h> |
4 | #include <openssl/hmac.h> | 5 | #include <openssl/hmac.h> |
@@ -10,4 +11,6 @@ | |||
10 | 11 | ||
11 | namespace opkele { | 12 | namespace opkele { |
13 | using std::pair; | ||
14 | using std::mismatch; | ||
12 | 15 | ||
13 | void basic_op::reset_vars() { | 16 | void basic_op::reset_vars() { |
@@ -318,3 +321,36 @@ namespace opkele { | |||
318 | } | 321 | } |
319 | 322 | ||
323 | void basic_op::verify_return_to() { | ||
324 | string nrealm = opkele::util::rfc_3986_normalize_uri(realm); | ||
325 | if(nrealm.find('#')!=string::npos) | ||
326 | throw opkele::bad_realm(OPKELE_CP_ "authentication realm contains URI fragment"); | ||
327 | string nrt = opkele::util::rfc_3986_normalize_uri(return_to); | ||
328 | string::size_type pr = nrealm.find("://"); | ||
329 | string::size_type prt = nrt.find("://"); | ||
330 | assert(!(pr==string::npos || prt==string::npos)); | ||
331 | pr += sizeof("://")-1; | ||
332 | prt += sizeof("://")-1; | ||
333 | if(!strncmp(nrealm.c_str()+pr,"*.",2)) { | ||
334 | pr = nrealm.find('.',pr); | ||
335 | prt = nrt.find('.',prt); | ||
336 | assert(pr!=string::npos); | ||
337 | if(prt==string::npos) | ||
338 | throw bad_return_to( | ||
339 | OPKELE_CP_ "return_to URL doesn't match realm"); | ||
340 | // TODO: check for overgeneralized realm | ||
341 | } | ||
342 | string::size_type lr = nrealm.length(); | ||
343 | string::size_type lrt = nrt.length(); | ||
344 | if( (lrt-prt) < (lr-pr) ) | ||
345 | throw bad_return_to( | ||
346 | OPKELE_CP_ "return_to URL doesn't match realm"); | ||
347 | pair<const char*,const char*> mp = mismatch( | ||
348 | nrealm.c_str()+pr,nrealm.c_str()+lr, | ||
349 | nrt.c_str()+prt); | ||
350 | if( (*(mp.first-1))!='/' | ||
351 | && !strchr("/?#",*mp.second) ) | ||
352 | throw bad_return_to( | ||
353 | OPKELE_CP_ "return_to URL doesn't match realm"); | ||
354 | } | ||
355 | |||
320 | } | 356 | } |