summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--acinclude.m46
-rw-r--r--configure.ac49
-rw-r--r--lib/consumer.cc53
3 files changed, 92 insertions, 16 deletions
diff --git a/acinclude.m4 b/acinclude.m4
index 349d3cf..532f978 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -75,26 +75,26 @@ AC_DEFUN([AC_WITH_DOT],[
75 AC_SUBST([DOT]) 75 AC_SUBST([DOT])
76 $1 76 $1
77 fi 77 fi
78AC_SUBST([HAVE_DOT]) 78AC_SUBST([HAVE_DOT])
79 AM_CONDITIONAL([HAVE_DOT],[test "${HAVE_DOT}" = "yes"]) 79 AM_CONDITIONAL([HAVE_DOT],[test "${HAVE_DOT}" = "yes"])
80]) 80])
81 81
82dnl AC_WITH_PCRE([ACTION-IF-FOUND[,ACTION-IF-NOT-FOUND]]) 82dnl AC_WITH_PCRE([ACTION-IF-FOUND[,ACTION-IF-NOT-FOUND]])
83dnl Outputs: 83dnl Outputs:
84dnl AC_SUBST: PCRE_CONFIG PCRE_PREFIX PCRE_EXEC_PREFIX 84dnl AC_SUBST: PCRE_CONFIG PCRE_PREFIX PCRE_EXEC_PREFIX
85dnl PCRE_VERSION PCRE_CFLAGS PCRE_LIBS 85dnl PCRE_VERSION PCRE_CFLAGS PCRE_LIBS
86dnl PCRE_LIBS_POSIX PCRE_CFLAGS_POSIX 86dnl PCRE_LIBS_POSIX PCRE_CFLAGS_POSIX
87dnl AM_CONDITIONAL: HAVE_PCRE
88dnl AC_DEFINE: HAVE_PCRE PCRE_VERSION 87dnl AC_DEFINE: HAVE_PCRE PCRE_VERSION
88dnl env: HAVE_PCRE=yes|no
89AC_DEFUN([AC_WITH_PCRE],[ 89AC_DEFUN([AC_WITH_PCRE],[
90 HAVE_PCRE="no" 90 HAVE_PCRE="no"
91 PCRE_CONFIG="" 91 PCRE_CONFIG=""
92 PCRE_PREFIX="" 92 PCRE_PREFIX=""
93 PCRE_EXEC_PREFIX="" 93 PCRE_EXEC_PREFIX=""
94 PCRE_VERSION="" 94 PCRE_VERSION=""
95 PCRE_CFLAGS="" 95 PCRE_CFLAGS=""
96 PCRE_LIBS="" 96 PCRE_LIBS=""
97 PCRE_LOCATIONS="${PATH}:/usr/local/bin:/usr/bin" 97 PCRE_LOCATIONS="${PATH}:/usr/local/bin:/usr/bin"
98 test -z "$WANT_PCRE" && WANT_PCRE="" 98 test -z "$WANT_PCRE" && WANT_PCRE=""
99 AC_ARG_WITH([pcre], 99 AC_ARG_WITH([pcre],
100 AC_HELP_STRING([--with-pcre=location],[Look for pcre in specified locations]), 100 AC_HELP_STRING([--with-pcre=location],[Look for pcre in specified locations]),
@@ -133,33 +133,32 @@ AC_DEFUN([AC_WITH_PCRE],[
133 AC_SUBST([PCRE_EXEC_PREFIX]) 133 AC_SUBST([PCRE_EXEC_PREFIX])
134 AC_SUBST([PCRE_VERSION]) 134 AC_SUBST([PCRE_VERSION])
135 AC_SUBST([PCRE_CFLAGS]) 135 AC_SUBST([PCRE_CFLAGS])
136 AC_SUBST([PCRE_LIBS]) 136 AC_SUBST([PCRE_LIBS])
137 AC_SUBST([PCRE_CFLAGS_POSIX]) 137 AC_SUBST([PCRE_CFLAGS_POSIX])
138 AC_SUBST([PCRE_LIBS_POSIX]) 138 AC_SUBST([PCRE_LIBS_POSIX])
139 AC_DEFINE([HAVE_PCRE],,[pcre support]) 139 AC_DEFINE([HAVE_PCRE],,[pcre support])
140 AC_DEFINE_UNQUOTED([PCRE_VERSION],["${PCRE_VERSION}"],[pcre version]) 140 AC_DEFINE_UNQUOTED([PCRE_VERSION],["${PCRE_VERSION}"],[pcre version])
141 $1 141 $1
142 fi 142 fi
143 fi 143 fi
144 fi 144 fi
145 AM_CONDITIONAL([HAVE_PCRE],[test "${HAVE_PCRE}" = "yes"])
146]) 145])
147 146
148dnl AC_WITH_PCREPP([ACTION-IF-FOUND[,ACTION-IF-NOT-FOUND]]) 147dnl AC_WITH_PCREPP([ACTION-IF-FOUND[,ACTION-IF-NOT-FOUND]])
149dnl Outputs: 148dnl Outputs:
150dnl AC_SUBST: PCREPP_CONFIG PCREPP_PREFIX PCREPP_EXEC_PREFIX 149dnl AC_SUBST: PCREPP_CONFIG PCREPP_PREFIX PCREPP_EXEC_PREFIX
151dnl PCREPP_VERSION PCREPP_CFLAGS PCREPP_LIBS 150dnl PCREPP_VERSION PCREPP_CFLAGS PCREPP_LIBS
152dnl AM_CONDITIONAL: HAVE_PCREPP
153dnl AC_DEFINE: HAVE_PCREPP PCREPP_VERSION 151dnl AC_DEFINE: HAVE_PCREPP PCREPP_VERSION
152dnl env: HAVE_PCREPP=yes|no
154AC_DEFUN([AC_WITH_PCREPP],[ 153AC_DEFUN([AC_WITH_PCREPP],[
155 HAVE_PCREPP="no" 154 HAVE_PCREPP="no"
156 PCREPP_CONFIG="" 155 PCREPP_CONFIG=""
157 PCREPP_PREFIX="" 156 PCREPP_PREFIX=""
158 PCREPP_EXEC_PREFIX="" 157 PCREPP_EXEC_PREFIX=""
159 PCREPP_VERSION="" 158 PCREPP_VERSION=""
160 PCREPP_CFLAGS="" 159 PCREPP_CFLAGS=""
161 PCREPP_LIBS="" 160 PCREPP_LIBS=""
162 PCREPP_LOCATIONS="${PATH}:/usr/local/bin:/usr/bin" 161 PCREPP_LOCATIONS="${PATH}:/usr/local/bin:/usr/bin"
163 test -z "$WANT_PCREPP" && WANT_PCREPP="" 162 test -z "$WANT_PCREPP" && WANT_PCREPP=""
164 AC_ARG_WITH([pcrepp], 163 AC_ARG_WITH([pcrepp],
165 AC_HELP_STRING([--with-pcrepp=location],[Look for pcre++ in specified locations]), 164 AC_HELP_STRING([--with-pcrepp=location],[Look for pcre++ in specified locations]),
@@ -198,16 +197,15 @@ AC_DEFUN([AC_WITH_PCREPP],[
198 AC_SUBST([PCREPP_PREFIX]) 197 AC_SUBST([PCREPP_PREFIX])
199 AC_SUBST([PCREPP_EXEC_PREFIX]) 198 AC_SUBST([PCREPP_EXEC_PREFIX])
200 AC_SUBST([PCREPP_VERSION]) 199 AC_SUBST([PCREPP_VERSION])
201 AC_SUBST([PCREPP_CFLAGS]) 200 AC_SUBST([PCREPP_CFLAGS])
202 AC_SUBST([PCREPP_LIBS]) 201 AC_SUBST([PCREPP_LIBS])
203 AC_DEFINE([HAVE_PCREPP],,[pcre++ support]) 202 AC_DEFINE([HAVE_PCREPP],,[pcre++ support])
204 AC_DEFINE_UNQUOTED([PCREPP_VERSION],["${PCREPP_VERSION}"],[pcre++ version]) 203 AC_DEFINE_UNQUOTED([PCREPP_VERSION],["${PCREPP_VERSION}"],[pcre++ version])
205 $1 204 $1
206 fi 205 fi
207 fi 206 fi
208 fi 207 fi
209 fi 208 fi
210 AM_CONDITIONAL([HAVE_PCREPP],[test "${HAVE_PCREPP}" = "yes"])
211]) 209])
212 210
213m4_include([acinclude.d/libcurl.m4]) 211m4_include([acinclude.d/libcurl.m4])
diff --git a/configure.ac b/configure.ac
index 2094273..00c6bc4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -43,33 +43,70 @@ AC_ARG_ENABLE([doxygen],
43) 43)
44if test "${WANT_DOXYGEN}" = "yes" ; then 44if test "${WANT_DOXYGEN}" = "yes" ; then
45 AC_WITH_DOXYGEN 45 AC_WITH_DOXYGEN
46 AC_WITH_DOT 46 AC_WITH_DOT
47else 47else
48 AM_CONDITIONAL([HAVE_DOXYGEN],[false]) 48 AM_CONDITIONAL([HAVE_DOXYGEN],[false])
49 AM_CONDITIONAL([HAVE_DOT],[false]) 49 AM_CONDITIONAL([HAVE_DOT],[false])
50fi 50fi
51 51
52LIBCURL_CHECK_CONFIG(,,,[ 52LIBCURL_CHECK_CONFIG(,,,[
53 AC_MSG_ERROR([no required libcurl library. get one from http://curl.haxx.se/]) 53 AC_MSG_ERROR([no required libcurl library. get one from http://curl.haxx.se/])
54]) 54])
55AC_WITH_PCRE([ 55
56 AC_WITH_PCREPP(,[ 56want_pcre_impl=""
57 AC_MSG_ERROR([no pcre++ library found. get one at http://www.daemon.de/PCRE]) 57AC_ARG_WITH([pcre-bindings],
58 ]) 58 AC_HELP_STRING([--with-pcre-bindings=(pcrepp|none|libpcrecpp)],[Specify which pcre c++ bindings to use. 'pcrepp' stands for quite sensible library, found at http://www.daemon.de/PCRE/, 'libcrecpp' makes use of crappy bindings by google and 'none' disables internal implementation of OP discovery]),
59 ],[ 59 [
60 AC_MSG_ERROR([no pcre library found. get one at http://www.pcre.org/]) 60 case "$withval" in
61 pcrepp) want_pcre_impl="pcrepp" ;;
62 libpcrecpp) want_pcre_impl="libpcrecpp" ;;
63 none) want_pcre_impl="none";;
64 *) AC_MSG_ERROR([I'm not sure I understand what do you want for a pcre c++ bindings]) ;;
65 esac
61 ] 66 ]
62) 67)
63 68
69found_pcre_impl=""
70
71if test -z "$want_pcre_impl" -o "$want_pcre_impl" = "pcrepp" ; then
72 AC_WITH_PCRE([
73 AC_WITH_PCREPP([
74 found_pcre_impl=pcrepp
75 ])
76 ],[
77 AC_MSG_ERROR([no pcre library found. get one at http://www.pcre.org/])
78 ]
79 )
80 test "$want_pcre_impl,$found_pcre_impl" = "pcrepp," && AC_MSG_ERROR([no pcre++ library found. get one at http://www.daemon.de/PCRE])
81fi
82
83if test "$found_pcre_impl,$want_pcre_impl" = "," -o "$want_pcre_impl" = "libpcrecpp" ; then
84 test -z "$want_pcre_impl" || AC_MSG_NOTICE([You want to use crappy libpcre c++ bindings])
85 PKG_CHECK_MODULES([LIBPCRECPP],[libpcrecpp],[
86 found_pcre_impl=libpcrecpp
87 CXXFLAGS="$CXXFLAGS $LIBPCRECPP_CFLAGS"
88 LIBS="$LIBS $LIBPCRECPP_LIBS"
89 ],[
90 test -z "$want_pcre_impl" || AC_MSG_ERROR([no libpcre c++ bindings found. why would you want it if you don't have it installed?])
91 ]
92 )
93fi
94test "$want_pcre_impl,$found_pcre_impl" = "," && AC_MSG_ERROR([no pcre c++ bindings found, use --with-pcre-bindings=none to disable code that makes use of it])
95
96case "$found_pcre_impl" in
97 pcrepp) AC_DEFINE([USE_PCREPP],,[defined if pcre++ is to be used]) ;;
98 libpcrecpp) AC_DEFINE([USE_LIBPCRECPP],,[defined if crappy google bindings are to be used]) ;;
99esac
100
64curl_ssl_verify_host="true" 101curl_ssl_verify_host="true"
65AC_ARG_ENABLE([ssl-verify-host], 102AC_ARG_ENABLE([ssl-verify-host],
66 AC_HELP_STRING([--disable-ssl-verify-host],[disable cURL cert/host relationships verification]), 103 AC_HELP_STRING([--disable-ssl-verify-host],[disable cURL cert/host relationships verification]),
67 [ test "${enableval}" = "no" && curl_ssl_verify_host="false" ] 104 [ test "${enableval}" = "no" && curl_ssl_verify_host="false" ]
68) 105)
69${curl_ssl_verify_host} || AC_DEFINE([DISABLE_CURL_SSL_VERIFYHOST],,[defined if cURL is not to verify cert/host]) 106${curl_ssl_verify_host} || AC_DEFINE([DISABLE_CURL_SSL_VERIFYHOST],,[defined if cURL is not to verify cert/host])
70 107
71curl_ssl_verify_peer="true" 108curl_ssl_verify_peer="true"
72AC_ARG_ENABLE([ssl-verify-peer], 109AC_ARG_ENABLE([ssl-verify-peer],
73 AC_HELP_STRING([--disable-ssl-verify-peer],[disable cURL cert validity verification]), 110 AC_HELP_STRING([--disable-ssl-verify-peer],[disable cURL cert validity verification]),
74 [ test "${enableval}" = "no" && curl_ssl_verify_peer="false" ] 111 [ test "${enableval}" = "no" && curl_ssl_verify_peer="false" ]
75) 112)
diff --git a/lib/consumer.cc b/lib/consumer.cc
index 8f66688..299b3bc 100644
--- a/lib/consumer.cc
+++ b/lib/consumer.cc
@@ -1,27 +1,34 @@
1#include <algorithm> 1#include <algorithm>
2#include <cassert> 2#include <cassert>
3#include <opkele/util.h> 3#include <opkele/util.h>
4#include <opkele/exception.h> 4#include <opkele/exception.h>
5#include <opkele/data.h> 5#include <opkele/data.h>
6#include <opkele/consumer.h> 6#include <opkele/consumer.h>
7#include <openssl/sha.h> 7#include <openssl/sha.h>
8#include <openssl/hmac.h> 8#include <openssl/hmac.h>
9#include <curl/curl.h> 9#include <curl/curl.h>
10#include <pcre++.h>
11 10
12#include <iostream> 11#include <iostream>
13 12
14#include "config.h" 13#include "config.h"
15 14
15#if defined(USE_LIBPCRECPP)
16# include <pcrecpp.h>
17#elif defined(USE_PCREPP)
18# include <pcre++.h>
19#else
20 /* internal implementation won't be built */
21#endif
22
16namespace opkele { 23namespace opkele {
17 using namespace std; 24 using namespace std;
18 25
19 class curl_t { 26 class curl_t {
20 public: 27 public:
21 CURL *_c; 28 CURL *_c;
22 29
23 curl_t() : _c(0) { } 30 curl_t() : _c(0) { }
24 curl_t(CURL *c) : _c(c) { } 31 curl_t(CURL *c) : _c(c) { }
25 ~curl_t() throw() { if(_c) curl_easy_cleanup(_c); } 32 ~curl_t() throw() { if(_c) curl_easy_cleanup(_c); }
26 33
27 curl_t& operator=(CURL *c) { if(_c) curl_easy_cleanup(_c); _c=c; return *this; } 34 curl_t& operator=(CURL *c) { if(_c) curl_easy_cleanup(_c); _c=c; return *this; }
@@ -252,69 +259,103 @@ namespace opkele {
252 invalidate_assoc(server,pp.get_param("invalidate_handle")); 259 invalidate_assoc(server,pp.get_param("invalidate_handle"));
253 if(pp.has_param("is_valid")) { 260 if(pp.has_param("is_valid")) {
254 if(pp.get_param("is_valid")=="true") 261 if(pp.get_param("is_valid")=="true")
255 return; 262 return;
256 }else if(pp.has_param("lifetime")) { 263 }else if(pp.has_param("lifetime")) {
257 if(util::string_to_long(pp.get_param("lifetime"))) 264 if(util::string_to_long(pp.get_param("lifetime")))
258 return; 265 return;
259 } 266 }
260 throw failed_check_authentication(OPKELE_CP_ "failed to verify response"); 267 throw failed_check_authentication(OPKELE_CP_ "failed to verify response");
261 } 268 }
262 269
263 void consumer_t::retrieve_links(const string& url,string& server,string& delegate) { 270 void consumer_t::retrieve_links(const string& url,string& server,string& delegate) {
271#if defined(USE_LIBPCRECPP) || defined(USE_PCREPP)
264 server.erase(); 272 server.erase();
265 delegate.erase(); 273 delegate.erase();
266 curl_t curl = curl_easy_init(); 274 curl_t curl = curl_easy_init();
267 if(!curl) 275 if(!curl)
268 throw exception_curl(OPKELE_CP_ "failed to curl_easy_init()"); 276 throw exception_curl(OPKELE_CP_ "failed to curl_easy_init()");
269 string html; 277 string html;
270 CURLcode r; 278 CURLcode r;
271 (r=curl_misc_sets(curl)) 279 (r=curl_misc_sets(curl))
272 || (r=curl_easy_setopt(curl,CURLOPT_URL,url.c_str())) 280 || (r=curl_easy_setopt(curl,CURLOPT_URL,url.c_str()))
273 || (r=curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,_curl_tostring)) 281 || (r=curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,_curl_tostring))
274 || (r=curl_easy_setopt(curl,CURLOPT_WRITEDATA,&html)) 282 || (r=curl_easy_setopt(curl,CURLOPT_WRITEDATA,&html))
275 ; 283 ;
276 if(r) 284 if(r)
277 throw exception_curl(OPKELE_CP_ "failed to curl_easy_setopt()",r); 285 throw exception_curl(OPKELE_CP_ "failed to curl_easy_setopt()",r);
278 r = curl_easy_perform(curl); 286 r = curl_easy_perform(curl);
279 if(r && r!=CURLE_WRITE_ERROR) 287 if(r && r!=CURLE_WRITE_ERROR)
280 throw exception_curl(OPKELE_CP_ "failed to curl_easy_perform()",r); 288 throw exception_curl(OPKELE_CP_ "failed to curl_easy_perform()",r);
281 pcrepp::Pcre bre("<body\\b",PCRE_CASELESS);
282 // strip out everything past body 289 // strip out everything past body
290 static const char *re_hdre = "<head[^>]*>",
291 *re_lre = "<link\\b([^>]+)>",
292 *re_rre = "\\brel=['\"]([^'\"]+)['\"]",
293 *re_hre = "\\bhref=['\"]([^'\"]+)['\"]";
294#if defined(USE_LIBPCRECPP)
295 static pcrecpp::RE_Options ro(PCRE_CASELESS|PCRE_DOTALL);
296 static pcrecpp::RE
297 bre("<body\\b.*",ro), hdre(re_hdre,ro),
298 lre(re_lre,ro), rre(re_rre), hre(re_hre,ro);
299 bre.Replace("",&html);
300 pcrecpp::StringPiece hpiece(html);
301 if(!hdre.FindAndConsume(&hpiece))
302 throw bad_input(OPKELE_CP_ "failed to find head");
303 string attrs;
304 while(lre.FindAndConsume(&hpiece,&attrs)) {
305 pcrecpp::StringPiece rel, href;
306 if(!(rre.PartialMatch(attrs,&rel) && hre.PartialMatch(attrs,&href)))
307 continue;
308 if(rel=="openid.server") {
309 href.CopyToString(&server);
310 if(!delegate.empty())
311 break;
312 }else if(rel=="openid.delegate") {
313 href.CopyToString(&delegate);
314 if(!server.empty())
315 break;
316 }
317 }
318#elif defined(USE_PCREPP)
319 pcrepp::Pcre bre("<body\\b",PCRE_CASELESS);
283 if(bre.search(html)) 320 if(bre.search(html))
284 html.erase(bre.get_match_start()); 321 html.erase(bre.get_match_start());
285 pcrepp::Pcre hdre("<head[^>]*>",PCRE_CASELESS); 322 pcrepp::Pcre hdre(re_hdre,PCRE_CASELESS);
286 if(!hdre.search(html)) 323 if(!hdre.search(html))
287 throw bad_input(OPKELE_CP_ "failed to find head"); 324 throw bad_input(OPKELE_CP_ "failed to find head");
288 html.erase(0,hdre.get_match_end()+1); 325 html.erase(0,hdre.get_match_end()+1);
289 pcrepp::Pcre lre("<link\\b([^>]+)>",PCRE_CASELESS), 326 pcrepp::Pcre lre(re_lre,PCRE_CASELESS), rre(re_rre,PCRE_CASELESS), hre(re_hre,PCRE_CASELESS);
290 rre("\\brel=['\"]([^'\"]+)['\"]",PCRE_CASELESS),
291 hre("\\bhref=['\"]([^'\"]+)['\"]",PCRE_CASELESS);
292 while(lre.search(html)) { 327 while(lre.search(html)) {
293 string attrs = lre[0]; 328 string attrs = lre[0];
294 html.erase(0,lre.get_match_end()+1); 329 html.erase(0,lre.get_match_end()+1);
295 if(!(rre.search(attrs)&&hre.search(attrs))) 330 if(!(rre.search(attrs)&&hre.search(attrs)))
296 continue; 331 continue;
297 if(rre[0]=="openid.server") { 332 if(rre[0]=="openid.server") {
298 server = hre[0]; 333 server = hre[0];
299 if(!delegate.empty()) 334 if(!delegate.empty())
300 break; 335 break;
301 }else if(rre[0]=="openid.delegate") { 336 }else if(rre[0]=="openid.delegate") {
302 delegate = hre[0]; 337 delegate = hre[0];
303 if(!server.empty()) 338 if(!server.empty())
304 break; 339 break;
305 } 340 }
306 } 341 }
342#else
343 #error "I must have gone crazy"
344#endif
307 if(server.empty()) 345 if(server.empty())
308 throw failed_assertion(OPKELE_CP_ "The location has no openid.server declaration"); 346 throw failed_assertion(OPKELE_CP_ "The location has no openid.server declaration");
347#else /* none of the RE bindings enabled */
348 throw not_implemented(OPKELE_CP_ "No internal implementation of retrieve_links were provided at compile-time");
349#endif
309 } 350 }
310 351
311 assoc_t consumer_t::find_assoc(const string& server) { 352 assoc_t consumer_t::find_assoc(const string& server) {
312 throw failed_lookup(OPKELE_CP_ "no find_assoc() provided"); 353 throw failed_lookup(OPKELE_CP_ "no find_assoc() provided");
313 } 354 }
314 355
315 string consumer_t::normalize(const string& url) { 356 string consumer_t::normalize(const string& url) {
316 string rv = url; 357 string rv = url;
317 // strip leading and trailing spaces 358 // strip leading and trailing spaces
318 string::size_type i = rv.find_first_not_of(" \t\r\n"); 359 string::size_type i = rv.find_first_not_of(" \t\r\n");
319 if(i==string::npos) 360 if(i==string::npos)
320 throw bad_input(OPKELE_CP_ "empty URL"); 361 throw bad_input(OPKELE_CP_ "empty URL");