-rw-r--r-- | lib/consumer.cc | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/lib/consumer.cc b/lib/consumer.cc index 3c3b4f8..ebda262 100644 --- a/lib/consumer.cc +++ b/lib/consumer.cc | |||
@@ -133,49 +133,49 @@ namespace opkele { | |||
133 | return checkid_(mode_checkid_setup,identity,return_to,trust_root,ext); | 133 | return checkid_(mode_checkid_setup,identity,return_to,trust_root,ext); |
134 | } | 134 | } |
135 | string consumer_t::checkid_(mode_t mode,const string& identity,const string& return_to,const string& trust_root,extension_t *ext) { | 135 | string consumer_t::checkid_(mode_t mode,const string& identity,const string& return_to,const string& trust_root,extension_t *ext) { |
136 | params_t p; | 136 | params_t p; |
137 | if(mode==mode_checkid_immediate) | 137 | if(mode==mode_checkid_immediate) |
138 | p["mode"]="checkid_immediate"; | 138 | p["mode"]="checkid_immediate"; |
139 | else if(mode==mode_checkid_setup) | 139 | else if(mode==mode_checkid_setup) |
140 | p["mode"]="checkid_setup"; | 140 | p["mode"]="checkid_setup"; |
141 | else | 141 | else |
142 | throw bad_input(OPKELE_CP_ "unknown checkid_* mode"); | 142 | throw bad_input(OPKELE_CP_ "unknown checkid_* mode"); |
143 | string iurl = canonicalize(identity); | 143 | string iurl = canonicalize(identity); |
144 | string server, delegate; | 144 | string server, delegate; |
145 | retrieve_links(iurl,server,delegate); | 145 | retrieve_links(iurl,server,delegate); |
146 | p["identity"] = delegate.empty()?iurl:delegate; | 146 | p["identity"] = delegate.empty()?iurl:delegate; |
147 | if(!trust_root.empty()) | 147 | if(!trust_root.empty()) |
148 | p["trust_root"] = trust_root; | 148 | p["trust_root"] = trust_root; |
149 | p["return_to"] = return_to; | 149 | p["return_to"] = return_to; |
150 | try { | 150 | try { |
151 | string ah = find_assoc(server)->handle(); | 151 | string ah = find_assoc(server)->handle(); |
152 | p["assoc_handle"] = ah; | 152 | p["assoc_handle"] = ah; |
153 | }catch(failed_lookup& fl) { | 153 | }catch(failed_lookup& fl) { |
154 | string ah = associate(server)->handle(); | 154 | string ah = associate(server)->handle(); |
155 | p["assoc_handle"] = ah; | 155 | p["assoc_handle"] = ah; |
156 | } | 156 | } |
157 | if(ext) ext->checkid_hook(p,identity); | 157 | if(ext) ext->checkid_hook(p); |
158 | return p.append_query(server); | 158 | return p.append_query(server); |
159 | } | 159 | } |
160 | 160 | ||
161 | void consumer_t::id_res(const params_t& pin,const string& identity,extension_t *ext) { | 161 | void consumer_t::id_res(const params_t& pin,const string& identity,extension_t *ext) { |
162 | if(pin.has_param("openid.user_setup_url")) | 162 | if(pin.has_param("openid.user_setup_url")) |
163 | throw id_res_setup(OPKELE_CP_ "assertion failed, setup url provided",pin.get_param("openid.user_setup_url")); | 163 | throw id_res_setup(OPKELE_CP_ "assertion failed, setup url provided",pin.get_param("openid.user_setup_url")); |
164 | string server,delegate; | 164 | string server,delegate; |
165 | retrieve_links(identity.empty()?pin.get_param("openid.identity"):canonicalize(identity),server,delegate); | 165 | retrieve_links(identity.empty()?pin.get_param("openid.identity"):canonicalize(identity),server,delegate); |
166 | params_t ps; | 166 | params_t ps; |
167 | try { | 167 | try { |
168 | assoc_t assoc = retrieve_assoc(server,pin.get_param("openid.assoc_handle")); | 168 | assoc_t assoc = retrieve_assoc(server,pin.get_param("openid.assoc_handle")); |
169 | if(assoc->is_expired()) | 169 | if(assoc->is_expired()) |
170 | throw id_res_expired_on_delivery(OPKELE_CP_ "retrieve_assoc() has returned expired handle"); | 170 | throw id_res_expired_on_delivery(OPKELE_CP_ "retrieve_assoc() has returned expired handle"); |
171 | const string& sigenc = pin.get_param("openid.sig"); | 171 | const string& sigenc = pin.get_param("openid.sig"); |
172 | vector<unsigned char> sig; | 172 | vector<unsigned char> sig; |
173 | util::decode_base64(sigenc,sig); | 173 | util::decode_base64(sigenc,sig); |
174 | const string& slist = pin.get_param("openid.signed"); | 174 | const string& slist = pin.get_param("openid.signed"); |
175 | string kv; | 175 | string kv; |
176 | string::size_type p = 0; | 176 | string::size_type p = 0; |
177 | while(true) { | 177 | while(true) { |
178 | string::size_type co = slist.find(',',p); | 178 | string::size_type co = slist.find(',',p); |
179 | string f = (co==string::npos)?slist.substr(p):slist.substr(p,co-p); | 179 | string f = (co==string::npos)?slist.substr(p):slist.substr(p,co-p); |
180 | kv += f; | 180 | kv += f; |
181 | kv += ':'; | 181 | kv += ':'; |
@@ -201,49 +201,49 @@ namespace opkele { | |||
201 | string::size_type pp = 0; | 201 | string::size_type pp = 0; |
202 | params_t p; | 202 | params_t p; |
203 | while(true) { | 203 | while(true) { |
204 | string::size_type co = slist.find(',',pp); | 204 | string::size_type co = slist.find(',',pp); |
205 | string f = "openid."; | 205 | string f = "openid."; |
206 | f += (co==string::npos)?slist.substr(pp):slist.substr(pp,co-pp); | 206 | f += (co==string::npos)?slist.substr(pp):slist.substr(pp,co-pp); |
207 | p[f] = pin.get_param(f); | 207 | p[f] = pin.get_param(f); |
208 | if(co==string::npos) | 208 | if(co==string::npos) |
209 | break; | 209 | break; |
210 | pp = co+1; | 210 | pp = co+1; |
211 | } | 211 | } |
212 | p["openid.assoc_handle"] = pin.get_param("openid.assoc_handle"); | 212 | p["openid.assoc_handle"] = pin.get_param("openid.assoc_handle"); |
213 | p["openid.sig"] = pin.get_param("openid.sig"); | 213 | p["openid.sig"] = pin.get_param("openid.sig"); |
214 | p["openid.signed"] = pin.get_param("openid.signed"); | 214 | p["openid.signed"] = pin.get_param("openid.signed"); |
215 | try { | 215 | try { |
216 | string ih = pin.get_param("openid.invalidate_handle"); | 216 | string ih = pin.get_param("openid.invalidate_handle"); |
217 | p["openid.invalidate_handle"] = ih; | 217 | p["openid.invalidate_handle"] = ih; |
218 | }catch(failed_lookup& fl) { } | 218 | }catch(failed_lookup& fl) { } |
219 | try { | 219 | try { |
220 | check_authentication(server,p); | 220 | check_authentication(server,p); |
221 | }catch(failed_check_authentication& fca) { | 221 | }catch(failed_check_authentication& fca) { |
222 | throw id_res_failed(OPKELE_CP_ "failed to check_authentication()"); | 222 | throw id_res_failed(OPKELE_CP_ "failed to check_authentication()"); |
223 | } | 223 | } |
224 | } | 224 | } |
225 | if(ext) ext->id_res_hook(pin,ps,identity); | 225 | if(ext) ext->id_res_hook(pin,ps); |
226 | } | 226 | } |
227 | 227 | ||
228 | void consumer_t::check_authentication(const string& server,const params_t& p) { | 228 | void consumer_t::check_authentication(const string& server,const params_t& p) { |
229 | string request = "openid.mode=check_authentication"; | 229 | string request = "openid.mode=check_authentication"; |
230 | for(params_t::const_iterator i=p.begin();i!=p.end();++i) { | 230 | for(params_t::const_iterator i=p.begin();i!=p.end();++i) { |
231 | if(i->first!="openid.mode") { | 231 | if(i->first!="openid.mode") { |
232 | request += '&'; | 232 | request += '&'; |
233 | request += i->first; | 233 | request += i->first; |
234 | request += '='; | 234 | request += '='; |
235 | request += util::url_encode(i->second); | 235 | request += util::url_encode(i->second); |
236 | } | 236 | } |
237 | } | 237 | } |
238 | curl_pick_t curl = curl_pick_t::easy_init(); | 238 | curl_pick_t curl = curl_pick_t::easy_init(); |
239 | if(!curl) | 239 | if(!curl) |
240 | throw exception_curl(OPKELE_CP_ "failed to initialize curl"); | 240 | throw exception_curl(OPKELE_CP_ "failed to initialize curl"); |
241 | CURLcode r; | 241 | CURLcode r; |
242 | (r=curl.misc_sets()) | 242 | (r=curl.misc_sets()) |
243 | || (r=curl.easy_setopt(CURLOPT_URL,server.c_str())) | 243 | || (r=curl.easy_setopt(CURLOPT_URL,server.c_str())) |
244 | || (r=curl.easy_setopt(CURLOPT_POST,1)) | 244 | || (r=curl.easy_setopt(CURLOPT_POST,1)) |
245 | || (r=curl.easy_setopt(CURLOPT_POSTFIELDS,request.data())) | 245 | || (r=curl.easy_setopt(CURLOPT_POSTFIELDS,request.data())) |
246 | || (r=curl.easy_setopt(CURLOPT_POSTFIELDSIZE,request.length())) | 246 | || (r=curl.easy_setopt(CURLOPT_POSTFIELDSIZE,request.length())) |
247 | || (r=curl.set_write()) | 247 | || (r=curl.set_write()) |
248 | ; | 248 | ; |
249 | if(r) | 249 | if(r) |