author | Michael Krelin <hacker@klever.net> | 2008-02-03 16:17:47 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2008-02-03 16:17:47 (UTC) |
commit | 434d42b37ecab09fc91ac8e6c752d3292c10a3b1 (patch) (unidiff) | |
tree | ec069e72e22cc2861e681e912d6f9e3ef4a65a2b /lib | |
parent | 23a6d48436e24d3d145b742984ef68ec3bae2bfd (diff) | |
download | libopkele-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>
-rw-r--r-- | lib/Makefile.am | 5 | ||||
-rw-r--r-- | lib/verify_op.cc | 53 |
2 files changed, 55 insertions, 3 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am index ac312d1..e8bfbf5 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am | |||
@@ -1,35 +1,34 @@ | |||
1 | lib_LTLIBRARIES = libopkele.la | 1 | lib_LTLIBRARIES = libopkele.la |
2 | 2 | ||
3 | AM_CPPFLAGS = ${CPPFLAGS_DEBUG} | 3 | AM_CPPFLAGS = ${CPPFLAGS_DEBUG} |
4 | DEFAULT_INCLUDES = -I${top_builddir} | 4 | DEFAULT_INCLUDES = -I${top_builddir} |
5 | INCLUDES = \ | 5 | INCLUDES = \ |
6 | -I${top_builddir}/include/ -I${top_srcdir}/include/ \ | 6 | -I${top_builddir}/include/ -I${top_srcdir}/include/ \ |
7 | ${KONFORKA_CFLAGS} \ | 7 | ${KONFORKA_CFLAGS} \ |
8 | ${OPENSSL_CFLAGS} \ | 8 | ${OPENSSL_CFLAGS} \ |
9 | ${LIBCURL_CPPFLAGS} \ | 9 | ${LIBCURL_CPPFLAGS} \ |
10 | ${PCRE_CFLAGS} ${EXPAT_CFLAGS} ${TIDY_CFLAGS} | 10 | ${PCRE_CFLAGS} ${EXPAT_CFLAGS} ${TIDY_CFLAGS} |
11 | libopkele_la_LIBADD = \ | 11 | libopkele_la_LIBADD = \ |
12 | ${LIBCURL} \ | 12 | ${LIBCURL} \ |
13 | ${PCRE_LIBS} ${EXPAT_LIBS} \ | 13 | ${PCRE_LIBS} ${EXPAT_LIBS} \ |
14 | ${OPENSSL_LIBS} \ | 14 | ${OPENSSL_LIBS} \ |
15 | ${KONFORKA_LIBS} ${TIDY_LIBS} | 15 | ${KONFORKA_LIBS} ${TIDY_LIBS} |
16 | 16 | ||
17 | libopkele_la_SOURCES = \ | 17 | libopkele_la_SOURCES = \ |
18 | params.cc \ | 18 | params.cc \ |
19 | util.cc \ | 19 | util.cc \ |
20 | server.cc \ | 20 | server.cc \ |
21 | secret.cc \ | 21 | secret.cc \ |
22 | data.cc \ | 22 | data.cc \ |
23 | consumer.cc \ | 23 | consumer.cc \ |
24 | exception.cc \ | 24 | exception.cc \ |
25 | extension.cc \ | 25 | extension.cc \ |
26 | sreg.cc \ | 26 | sreg.cc \ |
27 | extension_chain.cc \ | 27 | extension_chain.cc \ |
28 | curl.cc expat.cc \ | 28 | curl.cc expat.cc \ |
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 |
34 | libopkele_la_LDFLAGS = \ | 33 | libopkele_la_LDFLAGS = \ |
35 | -version-info 2:0:0 | 34 | -version-info 2:0:0 |
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 | } | ||