summaryrefslogtreecommitdiffabout
authorMichael Krelin <hacker@klever.net>2008-02-03 16:17:47 (UTC)
committer Michael Krelin <hacker@klever.net>2008-02-03 16:17:47 (UTC)
commit434d42b37ecab09fc91ac8e6c752d3292c10a3b1 (patch) (unidiff)
treeec069e72e22cc2861e681e912d6f9e3ef4a65a2b
parent23a6d48436e24d3d145b742984ef68ec3bae2bfd (diff)
downloadlibopkele-434d42b37ecab09fc91ac8e6c752d3292c10a3b1.zip
libopkele-434d42b37ecab09fc91ac8e6c752d3292c10a3b1.tar.gz
libopkele-434d42b37ecab09fc91ac8e6c752d3292c10a3b1.tar.bz2
added verify_op that performs discovery on the relying party
Signed-off-by: Michael Krelin <hacker@klever.net>
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--include/Makefile.am5
-rw-r--r--include/opkele/verify_op.h16
-rw-r--r--lib/Makefile.am5
-rw-r--r--lib/verify_op.cc53
4 files changed, 73 insertions, 6 deletions
diff --git a/include/Makefile.am b/include/Makefile.am
index 37fb961..9f5982c 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -18,6 +18,5 @@ nobase_include_HEADERS = \
18 opkele/tr1-mem.h \ 18 opkele/tr1-mem.h \
19 opkele/basic_rp.h \ 19 opkele/basic_rp.h opkele/prequeue_rp.h \
20 opkele/prequeue_rp.h \
21 opkele/iterator.h \ 20 opkele/iterator.h \
22 opkele/basic_op.h \ 21 opkele/basic_op.h opkele/verify_op.h \
23 ${NODIST_HEADERS_} 22 ${NODIST_HEADERS_}
diff --git a/include/opkele/verify_op.h b/include/opkele/verify_op.h
new file mode 100644
index 0000000..f5c97b2
--- a/dev/null
+++ b/include/opkele/verify_op.h
@@ -0,0 +1,16 @@
1#ifndef __OPKELE_VERIFY_OP_H
2#define __OPKELE_VERIFY_OP_H
3
4#include <opkele/basic_op.h>
5
6namespace opkele {
7
8 class verify_op : public basic_op {
9 public:
10
11 void verify_return_to();
12 };
13
14}
15
16#endif /* __OPKELE_VERIFY_OP_H */
diff --git a/lib/Makefile.am b/lib/Makefile.am
index ac312d1..e8bfbf5 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -29,6 +29,5 @@ libopkele_la_SOURCES = \
29 discovery.cc \ 29 discovery.cc \
30 basic_rp.cc \ 30 basic_rp.cc prequeue_rp.cc \
31 prequeue_rp.cc \
32 openid_message.cc \ 31 openid_message.cc \
33 basic_op.cc 32 basic_op.cc verify_op.cc
34libopkele_la_LDFLAGS = \ 33libopkele_la_LDFLAGS = \
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
7namespace 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}