summaryrefslogtreecommitdiffabout
path: root/lib
authorMichael Krelin <hacker@klever.net>2007-08-09 11:23:36 (UTC)
committer Michael Krelin <hacker@klever.net>2007-08-09 11:23:36 (UTC)
commit65bab7c9f984d6fe45ce72e7db014c40eba4d240 (patch) (unidiff)
tree28c4791aea6b7dc404ad0d27050c34f447a84314 /lib
parent1f347795ef5eba50892fd777c173a2a6db1755f2 (diff)
downloadlibopkele-65bab7c9f984d6fe45ce72e7db014c40eba4d240.zip
libopkele-65bab7c9f984d6fe45ce72e7db014c40eba4d240.tar.gz
libopkele-65bab7c9f984d6fe45ce72e7db014c40eba4d240.tar.bz2
associations robustness improvements and documentation updates
Diffstat (limited to 'lib') (more/less context) (ignore whitespace changes)
-rw-r--r--lib/consumer.cc4
1 files changed, 4 insertions, 0 deletions
diff --git a/lib/consumer.cc b/lib/consumer.cc
index dd8e150..af309c1 100644
--- a/lib/consumer.cc
+++ b/lib/consumer.cc
@@ -123,65 +123,69 @@ namespace opkele {
123 123
124 string consumer_t::checkid_immediate(const string& identity,const string& return_to,const string& trust_root,extension_t *ext) { 124 string consumer_t::checkid_immediate(const string& identity,const string& return_to,const string& trust_root,extension_t *ext) {
125 return checkid_(mode_checkid_immediate,identity,return_to,trust_root,ext); 125 return checkid_(mode_checkid_immediate,identity,return_to,trust_root,ext);
126 } 126 }
127 string consumer_t::checkid_setup(const string& identity,const string& return_to,const string& trust_root,extension_t *ext) { 127 string consumer_t::checkid_setup(const string& identity,const string& return_to,const string& trust_root,extension_t *ext) {
128 return checkid_(mode_checkid_setup,identity,return_to,trust_root,ext); 128 return checkid_(mode_checkid_setup,identity,return_to,trust_root,ext);
129 } 129 }
130 string consumer_t::checkid_(mode_t mode,const string& identity,const string& return_to,const string& trust_root,extension_t *ext) { 130 string consumer_t::checkid_(mode_t mode,const string& identity,const string& return_to,const string& trust_root,extension_t *ext) {
131 params_t p; 131 params_t p;
132 if(mode==mode_checkid_immediate) 132 if(mode==mode_checkid_immediate)
133 p["mode"]="checkid_immediate"; 133 p["mode"]="checkid_immediate";
134 else if(mode==mode_checkid_setup) 134 else if(mode==mode_checkid_setup)
135 p["mode"]="checkid_setup"; 135 p["mode"]="checkid_setup";
136 else 136 else
137 throw bad_input(OPKELE_CP_ "unknown checkid_* mode"); 137 throw bad_input(OPKELE_CP_ "unknown checkid_* mode");
138 string iurl = canonicalize(identity); 138 string iurl = canonicalize(identity);
139 string server, delegate; 139 string server, delegate;
140 retrieve_links(iurl,server,delegate); 140 retrieve_links(iurl,server,delegate);
141 p["identity"] = delegate.empty()?iurl:delegate; 141 p["identity"] = delegate.empty()?iurl:delegate;
142 if(!trust_root.empty()) 142 if(!trust_root.empty())
143 p["trust_root"] = trust_root; 143 p["trust_root"] = trust_root;
144 p["return_to"] = return_to; 144 p["return_to"] = return_to;
145 try { 145 try {
146 string ah = find_assoc(server)->handle(); 146 string ah = find_assoc(server)->handle();
147 if(ah->is_expired()) /* TODO: or should I throw some other exception to force programmer fix his implementation? */
148 throw failed_lookup(OPKELE_CP_ "find_assoc() has returned expired handle");
147 p["assoc_handle"] = ah; 149 p["assoc_handle"] = ah;
148 }catch(failed_lookup& fl) { 150 }catch(failed_lookup& fl) {
149 string ah = associate(server)->handle(); 151 string ah = associate(server)->handle();
150 p["assoc_handle"] = ah; 152 p["assoc_handle"] = ah;
151 } 153 }
152 if(ext) ext->checkid_hook(p,identity); 154 if(ext) ext->checkid_hook(p,identity);
153 return p.append_query(server); 155 return p.append_query(server);
154 } 156 }
155 157
156 void consumer_t::id_res(const params_t& pin,const string& identity,extension_t *ext) { 158 void consumer_t::id_res(const params_t& pin,const string& identity,extension_t *ext) {
157 if(pin.has_param("openid.user_setup_url")) 159 if(pin.has_param("openid.user_setup_url"))
158 throw id_res_setup(OPKELE_CP_ "assertion failed, setup url provided",pin.get_param("openid.user_setup_url")); 160 throw id_res_setup(OPKELE_CP_ "assertion failed, setup url provided",pin.get_param("openid.user_setup_url"));
159 string server,delegate; 161 string server,delegate;
160 retrieve_links(identity.empty()?pin.get_param("openid.identity"):canonicalize(identity),server,delegate); 162 retrieve_links(identity.empty()?pin.get_param("openid.identity"):canonicalize(identity),server,delegate);
161 params_t ps; 163 params_t ps;
162 try { 164 try {
163 assoc_t assoc = retrieve_assoc(server,pin.get_param("openid.assoc_handle")); 165 assoc_t assoc = retrieve_assoc(server,pin.get_param("openid.assoc_handle"));
166 if(assoc->is_expired()) /* TODO: or should I throw some other exception to force programmer fix his implementation? */
167 throw failed_lookup(OPKELE_CP_ "retrieve_assoc() has returned expired handle");
164 const string& sigenc = pin.get_param("openid.sig"); 168 const string& sigenc = pin.get_param("openid.sig");
165 vector<unsigned char> sig; 169 vector<unsigned char> sig;
166 util::decode_base64(sigenc,sig); 170 util::decode_base64(sigenc,sig);
167 const string& slist = pin.get_param("openid.signed"); 171 const string& slist = pin.get_param("openid.signed");
168 string kv; 172 string kv;
169 string::size_type p = 0; 173 string::size_type p = 0;
170 while(true) { 174 while(true) {
171 string::size_type co = slist.find(',',p); 175 string::size_type co = slist.find(',',p);
172 string f = (co==string::npos)?slist.substr(p):slist.substr(p,co-p); 176 string f = (co==string::npos)?slist.substr(p):slist.substr(p,co-p);
173 kv += f; 177 kv += f;
174 kv += ':'; 178 kv += ':';
175 f.insert(0,"openid."); 179 f.insert(0,"openid.");
176 kv += pin.get_param(f); 180 kv += pin.get_param(f);
177 kv += '\n'; 181 kv += '\n';
178 if(ext) ps[f.substr(sizeof("openid.")-1)] = pin.get_param(f); 182 if(ext) ps[f.substr(sizeof("openid.")-1)] = pin.get_param(f);
179 if(co==string::npos) 183 if(co==string::npos)
180 break; 184 break;
181 p = co+1; 185 p = co+1;
182 } 186 }
183 secret_t secret = assoc->secret(); 187 secret_t secret = assoc->secret();
184 unsigned int md_len = 0; 188 unsigned int md_len = 0;
185 unsigned char *md = HMAC( 189 unsigned char *md = HMAC(
186 EVP_sha1(), 190 EVP_sha1(),
187 &(secret.front()),secret.size(), 191 &(secret.front()),secret.size(),