-rw-r--r-- | lib/verify_op.cc | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/lib/verify_op.cc b/lib/verify_op.cc new file mode 100644 index 0000000..e7c26b5 --- a/dev/null +++ b/lib/verify_op.cc | |||
@@ -0,0 +1,53 @@ | |||
1 | #include <opkele/verify_op.h> | ||
2 | #include <opkele/discovery.h> | ||
3 | #include <opkele/exception.h> | ||
4 | #include <opkele/util.h> | ||
5 | #include <opkele/uris.h> | ||
6 | |||
7 | namespace opkele { | ||
8 | using std::output_iterator_tag; | ||
9 | |||
10 | class __RP_verifier_good_input : public exception { | ||
11 | public: | ||
12 | __RP_verifier_good_input(OPKELE_E_PARS) | ||
13 | : exception(OPKELE_E_CONS) { } | ||
14 | }; | ||
15 | |||
16 | class RP_verifier : public iterator<output_iterator_tag,openid_endpoint_t,void> { | ||
17 | public: | ||
18 | int seen; | ||
19 | const string& return_to; | ||
20 | |||
21 | RP_verifier(const string& rt) | ||
22 | : return_to(rt), seen(0) { } | ||
23 | |||
24 | RP_verifier& operator*() { return *this; } | ||
25 | RP_verifier& operator=(const openid_endpoint_t& oep) { | ||
26 | if(util::uri_matches_realm(return_to,oep.uri)) | ||
27 | throw __RP_verifier_good_input(OPKELE_CP_ "Found matching realm"); | ||
28 | return *this; | ||
29 | } | ||
30 | |||
31 | RP_verifier& operator++() { ++seen; return *this; } | ||
32 | RP_verifier& operator++(int) { +seen; return *this; } | ||
33 | }; | ||
34 | |||
35 | void verify_op::verify_return_to() { | ||
36 | basic_op::verify_return_to(); | ||
37 | try { | ||
38 | RP_verifier rpv(return_to); | ||
39 | string drealm = realm; | ||
40 | string::size_type csss = drealm.find("://*."); | ||
41 | if(csss==4 || csss==5) | ||
42 | drealm.replace(csss+3,1,"www"); | ||
43 | const char *rtt[] = { STURI_OPENID20_RT, 0 }; | ||
44 | yadiscover(rpv,drealm,rtt,false); | ||
45 | if(rpv.seen) | ||
46 | throw bad_return_to(OPKELE_CP_ "return_to URL doesn't match any found while doing discovery on RP"); | ||
47 | }catch(__RP_verifier_good_input&) { | ||
48 | }catch(bad_return_to& brt) { | ||
49 | throw; | ||
50 | }catch(exception_network&) { } | ||
51 | } | ||
52 | |||
53 | } | ||