summaryrefslogtreecommitdiffabout
path: root/lib
Unidiff
Diffstat (limited to 'lib') (more/less context) (ignore whitespace changes)
-rw-r--r--lib/Makefile.am3
-rw-r--r--lib/consumer.cc16
-rw-r--r--lib/extension.cc15
-rw-r--r--lib/server.cc14
4 files changed, 35 insertions, 13 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 6f3f9f3..69c749e 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -1,24 +1,25 @@
1lib_LTLIBRARIES = libopkele.la 1lib_LTLIBRARIES = libopkele.la
2 2
3INCLUDES = \ 3INCLUDES = \
4 -I${top_srcdir}/include/ \ 4 -I${top_srcdir}/include/ \
5 ${KONFORKA_CFLAGS} \ 5 ${KONFORKA_CFLAGS} \
6 ${OPENSSL_CFLAGS} \ 6 ${OPENSSL_CFLAGS} \
7 ${MIMETIC_CFLAGS} \ 7 ${MIMETIC_CFLAGS} \
8 ${LIBCURL_CPPFLAGS} \ 8 ${LIBCURL_CPPFLAGS} \
9 ${PCREPP_CFLAGS} 9 ${PCREPP_CFLAGS}
10LDADD = \ 10LDADD = \
11 ${LIBCURL} \ 11 ${LIBCURL} \
12 ${PCREPP_LIBS} \ 12 ${PCREPP_LIBS} \
13 ${MIMETIC_LIBS} \ 13 ${MIMETIC_LIBS} \
14 ${OPENSSL_LIBS} \ 14 ${OPENSSL_LIBS} \
15 ${KONFORKA_LIBS} 15 ${KONFORKA_LIBS}
16 16
17libopkele_la_SOURCES = \ 17libopkele_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
diff --git a/lib/consumer.cc b/lib/consumer.cc
index bb6358c..10c2fa0 100644
--- a/lib/consumer.cc
+++ b/lib/consumer.cc
@@ -94,160 +94,164 @@ namespace opkele {
94 if(p.has_param("assoc_type") && p.get_param("assoc_type")!="HMAC-SHA1") 94 if(p.has_param("assoc_type") && p.get_param("assoc_type")!="HMAC-SHA1")
95 throw bad_input(OPKELE_CP_ "unsupported assoc_type"); 95 throw bad_input(OPKELE_CP_ "unsupported assoc_type");
96 string st; 96 string st;
97 if(p.has_param("session_type")) st = p.get_param("session_type"); 97 if(p.has_param("session_type")) st = p.get_param("session_type");
98 if((!st.empty()) && st!="DH-SHA1") 98 if((!st.empty()) && st!="DH-SHA1")
99 throw bad_input(OPKELE_CP_ "unsupported session_type"); 99 throw bad_input(OPKELE_CP_ "unsupported session_type");
100 secret_t secret; 100 secret_t secret;
101 if(st.empty()) { 101 if(st.empty()) {
102 secret.from_base64(p.get_param("mac_key")); 102 secret.from_base64(p.get_param("mac_key"));
103 }else{ 103 }else{
104 util::bignum_t s_pub = util::base64_to_bignum(p.get_param("dh_server_public")); 104 util::bignum_t s_pub = util::base64_to_bignum(p.get_param("dh_server_public"));
105 vector<unsigned char> ck(DH_size(dh)); 105 vector<unsigned char> ck(DH_size(dh));
106 int cklen = DH_compute_key(&(ck.front()),s_pub,dh); 106 int cklen = DH_compute_key(&(ck.front()),s_pub,dh);
107 if(cklen<0) 107 if(cklen<0)
108 throw exception_openssl(OPKELE_CP_ "failed to DH_compute_key()"); 108 throw exception_openssl(OPKELE_CP_ "failed to DH_compute_key()");
109 ck.resize(cklen); 109 ck.resize(cklen);
110 // OpenID algorithm requires extra zero in case of set bit here 110 // OpenID algorithm requires extra zero in case of set bit here
111 if(ck[0]&0x80) ck.insert(ck.begin(),1,0); 111 if(ck[0]&0x80) ck.insert(ck.begin(),1,0);
112 unsigned char key_sha1[SHA_DIGEST_LENGTH]; 112 unsigned char key_sha1[SHA_DIGEST_LENGTH];
113 SHA1(&(ck.front()),ck.size(),key_sha1); 113 SHA1(&(ck.front()),ck.size(),key_sha1);
114 secret.enxor_from_base64(key_sha1,p.get_param("enc_mac_key")); 114 secret.enxor_from_base64(key_sha1,p.get_param("enc_mac_key"));
115 } 115 }
116 int expires_in = 0; 116 int expires_in = 0;
117 if(p.has_param("expires_in")) { 117 if(p.has_param("expires_in")) {
118 expires_in = util::string_to_long(p.get_param("expires_in")); 118 expires_in = util::string_to_long(p.get_param("expires_in"));
119 }else if(p.has_param("issued") && p.has_param("expiry")) { 119 }else if(p.has_param("issued") && p.has_param("expiry")) {
120 expires_in = util::w3c_to_time(p.get_param("expiry"))-util::w3c_to_time(p.get_param("issued")); 120 expires_in = util::w3c_to_time(p.get_param("expiry"))-util::w3c_to_time(p.get_param("issued"));
121 }else 121 }else
122 throw bad_input(OPKELE_CP_ "no expiration information"); 122 throw bad_input(OPKELE_CP_ "no expiration information");
123 return store_assoc(server,p.get_param("assoc_handle"),secret,expires_in); 123 return store_assoc(server,p.get_param("assoc_handle"),secret,expires_in);
124 } 124 }
125 125
126 string consumer_t::checkid_immediate(const string& identity,const string& return_to,const string& trust_root) { 126 string consumer_t::checkid_immediate(const string& identity,const string& return_to,const string& trust_root,extension_t *ext) {
127 return checkid_(mode_checkid_immediate,identity,return_to,trust_root); 127 return checkid_(mode_checkid_immediate,identity,return_to,trust_root,ext);
128 } 128 }
129 string consumer_t::checkid_setup(const string& identity,const string& return_to,const string& trust_root) { 129 string consumer_t::checkid_setup(const string& identity,const string& return_to,const string& trust_root,extension_t *ext) {
130 return checkid_(mode_checkid_setup,identity,return_to,trust_root); 130 return checkid_(mode_checkid_setup,identity,return_to,trust_root,ext);
131 } 131 }
132 string consumer_t::checkid_(mode_t mode,const string& identity,const string& return_to,const string& trust_root) { 132 string consumer_t::checkid_(mode_t mode,const string& identity,const string& return_to,const string& trust_root,extension_t *ext) {
133 params_t p; 133 params_t p;
134 if(mode==mode_checkid_immediate) 134 if(mode==mode_checkid_immediate)
135 p["mode"]="checkid_immediate"; 135 p["mode"]="checkid_immediate";
136 else if(mode==mode_checkid_setup) 136 else if(mode==mode_checkid_setup)
137 p["mode"]="checkid_setup"; 137 p["mode"]="checkid_setup";
138 else 138 else
139 throw bad_input(OPKELE_CP_ "unknown checkid_* mode"); 139 throw bad_input(OPKELE_CP_ "unknown checkid_* mode");
140 string iurl = canonicalize(identity); 140 string iurl = canonicalize(identity);
141 string server, delegate; 141 string server, delegate;
142 retrieve_links(iurl,server,delegate); 142 retrieve_links(iurl,server,delegate);
143 p["identity"] = delegate.empty()?iurl:delegate; 143 p["identity"] = delegate.empty()?iurl:delegate;
144 if(!trust_root.empty()) 144 if(!trust_root.empty())
145 p["trust_root"] = trust_root; 145 p["trust_root"] = trust_root;
146 p["return_to"] = return_to; 146 p["return_to"] = return_to;
147 try { 147 try {
148 try { 148 try {
149 string ah = find_assoc(server)->handle(); 149 string ah = find_assoc(server)->handle();
150 p["assoc_handle"] = ah; 150 p["assoc_handle"] = ah;
151 }catch(failed_lookup& fl) { 151 }catch(failed_lookup& fl) {
152 string ah = associate(server)->handle(); 152 string ah = associate(server)->handle();
153 p["assoc_handle"] = ah; 153 p["assoc_handle"] = ah;
154 } 154 }
155 }catch(exception& e) { } 155 }catch(exception& e) { }
156 if(ext) ext->checkid_hook(p,identity);
156 return p.append_query(server); 157 return p.append_query(server);
157 } 158 }
158 159
159 void consumer_t::id_res(const params_t& pin,const string& identity) { 160 void consumer_t::id_res(const params_t& pin,const string& identity,extension_t *ext) {
160 if(pin.has_param("openid.user_setup_url")) 161 if(pin.has_param("openid.user_setup_url"))
161 throw id_res_setup(OPKELE_CP_ "assertion failed, setup url provided",pin.get_param("openid.user_setup_url")); 162 throw id_res_setup(OPKELE_CP_ "assertion failed, setup url provided",pin.get_param("openid.user_setup_url"));
162 string server,delegate; 163 string server,delegate;
163 retrieve_links(identity.empty()?pin.get_param("openid.identity"):canonicalize(identity),server,delegate); 164 retrieve_links(identity.empty()?pin.get_param("openid.identity"):canonicalize(identity),server,delegate);
165 params_t ps;
164 try { 166 try {
165 assoc_t assoc = retrieve_assoc(server,pin.get_param("openid.assoc_handle")); 167 assoc_t assoc = retrieve_assoc(server,pin.get_param("openid.assoc_handle"));
166 const string& sigenc = pin.get_param("openid.sig"); 168 const string& sigenc = pin.get_param("openid.sig");
167 mimetic::Base64::Decoder b; 169 mimetic::Base64::Decoder b;
168 vector<unsigned char> sig; 170 vector<unsigned char> sig;
169 mimetic::decode( 171 mimetic::decode(
170 sigenc.begin(),sigenc.end(), b, 172 sigenc.begin(),sigenc.end(), b,
171 back_insert_iterator<vector<unsigned char> >(sig) ); 173 back_insert_iterator<vector<unsigned char> >(sig) );
172 const string& slist = pin.get_param("openid.signed"); 174 const string& slist = pin.get_param("openid.signed");
173 string kv; 175 string kv;
174 string::size_type p = 0; 176 string::size_type p = 0;
175 while(true) { 177 while(true) {
176 string::size_type co = slist.find(',',p); 178 string::size_type co = slist.find(',',p);
177 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);
178 kv += f; 180 kv += f;
179 kv += ':'; 181 kv += ':';
180 f.insert(0,"openid."); 182 f.insert(0,"openid.");
181 kv += pin.get_param(f); 183 kv += pin.get_param(f);
182 kv += '\n'; 184 kv += '\n';
185 if(ext) ps[f.substr(sizeof("openid."))] = pin.get_param(f);
183 if(co==string::npos) 186 if(co==string::npos)
184 break; 187 break;
185 p = co+1; 188 p = co+1;
186 } 189 }
187 secret_t secret = assoc->secret(); 190 secret_t secret = assoc->secret();
188 unsigned int md_len = 0; 191 unsigned int md_len = 0;
189 unsigned char *md = HMAC( 192 unsigned char *md = HMAC(
190 EVP_sha1(), 193 EVP_sha1(),
191 &(secret.front()),secret.size(), 194 &(secret.front()),secret.size(),
192 (const unsigned char *)kv.data(),kv.length(), 195 (const unsigned char *)kv.data(),kv.length(),
193 0,&md_len); 196 0,&md_len);
194 if(sig.size()!=md_len || memcmp(&(sig.front()),md,md_len)) 197 if(sig.size()!=md_len || memcmp(&(sig.front()),md,md_len))
195 throw id_res_mismatch(OPKELE_CP_ "signature mismatch"); 198 throw id_res_mismatch(OPKELE_CP_ "signature mismatch");
196 }catch(failed_lookup& e) { /* XXX: more specific? */ 199 }catch(failed_lookup& e) { /* XXX: more specific? */
197 const string& slist = pin.get_param("openid.signed"); 200 const string& slist = pin.get_param("openid.signed");
198 string::size_type pp = 0; 201 string::size_type pp = 0;
199 params_t p; 202 params_t p;
200 while(true) { 203 while(true) {
201 string::size_type co = slist.find(',',pp); 204 string::size_type co = slist.find(',',pp);
202 string f = "openid."; 205 string f = "openid.";
203 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);
204 p[f] = pin.get_param(f); 207 p[f] = pin.get_param(f);
205 if(co==string::npos) 208 if(co==string::npos)
206 break; 209 break;
207 pp = co+1; 210 pp = co+1;
208 } 211 }
209 p["openid.assoc_handle"] = pin.get_param("openid.assoc_handle"); 212 p["openid.assoc_handle"] = pin.get_param("openid.assoc_handle");
210 p["openid.sig"] = pin.get_param("openid.sig"); 213 p["openid.sig"] = pin.get_param("openid.sig");
211 p["openid.signed"] = pin.get_param("openid.signed"); 214 p["openid.signed"] = pin.get_param("openid.signed");
212 try { 215 try {
213 string ih = pin.get_param("openid.invalidate_handle"); 216 string ih = pin.get_param("openid.invalidate_handle");
214 p["openid.invalidate_handle"] = ih; 217 p["openid.invalidate_handle"] = ih;
215 }catch(failed_lookup& fl) { } 218 }catch(failed_lookup& fl) { }
216 try { 219 try {
217 check_authentication(server,p); 220 check_authentication(server,p);
218 }catch(failed_check_authentication& fca) { 221 }catch(failed_check_authentication& fca) {
219 throw id_res_failed(OPKELE_CP_ "failed to check_authentication()"); 222 throw id_res_failed(OPKELE_CP_ "failed to check_authentication()");
220 } 223 }
221 } 224 }
225 if(ext) ext->id_res_hook(pin,ps,identity);
222 } 226 }
223 227
224 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) {
225 string request = "openid.mode=check_authentication"; 229 string request = "openid.mode=check_authentication";
226 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) {
227 if(i->first!="openid.mode") { 231 if(i->first!="openid.mode") {
228 request += '&'; 232 request += '&';
229 request += i->first; 233 request += i->first;
230 request += '='; 234 request += '=';
231 request += util::url_encode(i->second); 235 request += util::url_encode(i->second);
232 } 236 }
233 } 237 }
234 curl_t curl = curl_easy_init(); 238 curl_t curl = curl_easy_init();
235 if(!curl) 239 if(!curl)
236 throw exception_curl(OPKELE_CP_ "failed to curl_easy_init()"); 240 throw exception_curl(OPKELE_CP_ "failed to curl_easy_init()");
237 string response; 241 string response;
238 CURLcode r; 242 CURLcode r;
239 (r=curl_misc_sets(curl)) 243 (r=curl_misc_sets(curl))
240 || (r=curl_easy_setopt(curl,CURLOPT_URL,server.c_str())) 244 || (r=curl_easy_setopt(curl,CURLOPT_URL,server.c_str()))
241 || (r=curl_easy_setopt(curl,CURLOPT_POST,1)) 245 || (r=curl_easy_setopt(curl,CURLOPT_POST,1))
242 || (r=curl_easy_setopt(curl,CURLOPT_POSTFIELDS,request.data())) 246 || (r=curl_easy_setopt(curl,CURLOPT_POSTFIELDS,request.data()))
243 || (r=curl_easy_setopt(curl,CURLOPT_POSTFIELDSIZE,request.length())) 247 || (r=curl_easy_setopt(curl,CURLOPT_POSTFIELDSIZE,request.length()))
244 || (r=curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,_curl_tostring)) 248 || (r=curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,_curl_tostring))
245 || (r=curl_easy_setopt(curl,CURLOPT_WRITEDATA,&response)) 249 || (r=curl_easy_setopt(curl,CURLOPT_WRITEDATA,&response))
246 ; 250 ;
247 if(r) 251 if(r)
248 throw exception_curl(OPKELE_CP_ "failed to curl_easy_setopt()",r); 252 throw exception_curl(OPKELE_CP_ "failed to curl_easy_setopt()",r);
249 if(r=curl_easy_perform(curl)) 253 if(r=curl_easy_perform(curl))
250 throw exception_curl(OPKELE_CP_ "failed to curl_easy_perform()",r); 254 throw exception_curl(OPKELE_CP_ "failed to curl_easy_perform()",r);
251 params_t pp; pp.parse_keyvalues(response); 255 params_t pp; pp.parse_keyvalues(response);
252 if(pp.has_param("invalidate_handle")) 256 if(pp.has_param("invalidate_handle"))
253 invalidate_assoc(server,pp.get_param("invalidate_handle")); 257 invalidate_assoc(server,pp.get_param("invalidate_handle"));
diff --git a/lib/extension.cc b/lib/extension.cc
new file mode 100644
index 0000000..bd2195d
--- a/dev/null
+++ b/lib/extension.cc
@@ -0,0 +1,15 @@
1#include <opkele/exception.h>
2#include <opkele/extension.h>
3
4namespace opkele {
5
6 void extension_t::checkid_hook(params_t& p,const string& identity) {
7 throw not_implemented(OPKELE_CP_ "Consumer checkid_hook not implemented");
8 }
9 void id_res_hook(const params_t& p,const params_t& sp,const string& identity) {
10 throw not_implemented(OPKELE_CP_ "Consumer id_res_hook not implemented");
11 }
12 void checkid_hook(const params_t& pin,params_t& pout) {
13 throw not_implemented(OPKELE_CP_ "Server checkid_hook not implemented");
14 }
15}
diff --git a/lib/server.cc b/lib/server.cc
index 5eee1f3..8c29abb 100644
--- a/lib/server.cc
+++ b/lib/server.cc
@@ -38,104 +38,106 @@ namespace opkele {
38 vector<unsigned char> ck(DH_size(dh)); 38 vector<unsigned char> ck(DH_size(dh));
39 int cklen = DH_compute_key(&(ck.front()),c_pub,dh); 39 int cklen = DH_compute_key(&(ck.front()),c_pub,dh);
40 if(cklen<0) 40 if(cklen<0)
41 throw exception_openssl(OPKELE_CP_ "failed to DH_compute_key()"); 41 throw exception_openssl(OPKELE_CP_ "failed to DH_compute_key()");
42 ck.resize(cklen); 42 ck.resize(cklen);
43 // OpenID algorithm requires extra zero in case of set bit here 43 // OpenID algorithm requires extra zero in case of set bit here
44 if(ck[0]&0x80) ck.insert(ck.begin(),1,0); 44 if(ck[0]&0x80) ck.insert(ck.begin(),1,0);
45 SHA1(&(ck.front()),ck.size(),key_sha1); 45 SHA1(&(ck.front()),ck.size(),key_sha1);
46 st = sess_dh_sha1; 46 st = sess_dh_sha1;
47 } 47 }
48 assoc_t assoc = alloc_assoc(mode_associate); 48 assoc_t assoc = alloc_assoc(mode_associate);
49 time_t now = time(0); 49 time_t now = time(0);
50 pout.clear(); 50 pout.clear();
51 pout["assoc_type"] = assoc->assoc_type(); 51 pout["assoc_type"] = assoc->assoc_type();
52 pout["assoc_handle"] = assoc->handle(); 52 pout["assoc_handle"] = assoc->handle();
53 /* TODO: eventually remove deprecated stuff */ 53 /* TODO: eventually remove deprecated stuff */
54 pout["issued"] = util::time_to_w3c(now); 54 pout["issued"] = util::time_to_w3c(now);
55 pout["expiry"] = util::time_to_w3c(now+assoc->expires_in()); 55 pout["expiry"] = util::time_to_w3c(now+assoc->expires_in());
56 pout["expires_in"] = util::long_to_string(assoc->expires_in()); 56 pout["expires_in"] = util::long_to_string(assoc->expires_in());
57 secret_t secret = assoc->secret(); 57 secret_t secret = assoc->secret();
58 switch(st) { 58 switch(st) {
59 case sess_dh_sha1: 59 case sess_dh_sha1:
60 pout["session_type"] = "DH-SHA1"; 60 pout["session_type"] = "DH-SHA1";
61 pout["dh_server_public"] = util::bignum_to_base64(dh->pub_key); 61 pout["dh_server_public"] = util::bignum_to_base64(dh->pub_key);
62 secret.enxor_to_base64(key_sha1,pout["enc_mac_key"]); 62 secret.enxor_to_base64(key_sha1,pout["enc_mac_key"]);
63 break; 63 break;
64 default: 64 default:
65 secret.to_base64(pout["mac_key"]); 65 secret.to_base64(pout["mac_key"]);
66 break; 66 break;
67 } 67 }
68 } 68 }
69 69
70 void server_t::checkid_immediate(const params_t& pin,string& return_to,params_t& pout) { 70 void server_t::checkid_immediate(const params_t& pin,string& return_to,params_t& pout,extension_t *ext) {
71 checkid_(mode_checkid_immediate,pin,return_to,pout); 71 checkid_(mode_checkid_immediate,pin,return_to,pout,ext);
72 } 72 }
73 73
74 void server_t::checkid_setup(const params_t& pin,string& return_to,params_t& pout) { 74 void server_t::checkid_setup(const params_t& pin,string& return_to,params_t& pout,extension_t *ext) {
75 checkid_(mode_checkid_setup,pin,return_to,pout); 75 checkid_(mode_checkid_setup,pin,return_to,pout,ext);
76 } 76 }
77 77
78 void server_t::checkid_(mode_t mode,const params_t& pin,string& return_to,params_t& pout) { 78 void server_t::checkid_(mode_t mode,const params_t& pin,string& return_to,params_t& pout,extension_t *ext) {
79 if(mode!=mode_checkid_immediate && mode!=mode_checkid_setup) 79 if(mode!=mode_checkid_immediate && mode!=mode_checkid_setup)
80 throw bad_input(OPKELE_CP_ "invalid checkid_* mode"); 80 throw bad_input(OPKELE_CP_ "invalid checkid_* mode");
81 pout.clear(); 81 pout.clear();
82 assoc_t assoc; 82 assoc_t assoc;
83 try { 83 try {
84 assoc = retrieve_assoc(pin.get_param("openid.assoc_handle")); 84 assoc = retrieve_assoc(pin.get_param("openid.assoc_handle"));
85 }catch(failed_lookup& fl) { 85 }catch(failed_lookup& fl) {
86 // no handle specified or no valid handle found, going dumb 86 // no handle specified or no valid handle found, going dumb
87 assoc = alloc_assoc(mode_checkid_setup); 87 assoc = alloc_assoc(mode_checkid_setup);
88 if(pin.has_param("openid.assoc_handle")) 88 if(pin.has_param("openid.assoc_handle"))
89 pout["invalidate_handle"]=pin.get_param("openid.assoc_handle"); 89 pout["invalidate_handle"]=pin.get_param("openid.assoc_handle");
90 } 90 }
91 string trust_root; 91 string trust_root;
92 try { 92 try {
93 trust_root = pin.get_param("openid.trust_root"); 93 trust_root = pin.get_param("openid.trust_root");
94 }catch(failed_lookup& fl) { } 94 }catch(failed_lookup& fl) { }
95 string identity = pin.get_param("openid.identity"); 95 string identity = pin.get_param("openid.identity");
96 return_to = pin.get_param("openid.return_to"); 96 return_to = pin.get_param("openid.return_to");
97 validate(*assoc,pin,identity,trust_root); 97 validate(*assoc,pin,identity,trust_root);
98 pout["mode"] = "id_res"; 98 pout["mode"] = "id_res";
99 pout["assoc_handle"] = assoc->handle(); 99 pout["assoc_handle"] = assoc->handle();
100 if(pin.has_param("openid.assoc_handle") && assoc->stateless()) 100 if(pin.has_param("openid.assoc_handle") && assoc->stateless())
101 pout["invalidate_handle"] = pin.get_param("openid.assoc_handle"); 101 pout["invalidate_handle"] = pin.get_param("openid.assoc_handle");
102 pout["identity"] = identity; 102 pout["identity"] = identity;
103 pout["return_to"] = return_to; 103 pout["return_to"] = return_to;
104 /* TODO: eventually remove deprecated stuff */ 104 /* TODO: eventually remove deprecated stuff */
105 time_t now = time(0); 105 time_t now = time(0);
106 pout["issued"] = util::time_to_w3c(now); 106 pout["issued"] = util::time_to_w3c(now);
107 pout["valid_to"] = util::time_to_w3c(now+120); 107 pout["valid_to"] = util::time_to_w3c(now+120);
108 pout["exipres_in"] = "120"; 108 pout["exipres_in"] = "120";
109 pout.sign(assoc->secret(),pout["sig"],pout["signed"]="mode,identity,return_to"); 109 pout["signed"]="mode,identity,return_to";
110 if(ext) ext->checkid_hook(pin,pout);
111 pout.sign(assoc->secret(),pout["sig"],pout["signed"]);
110 } 112 }
111 113
112 void server_t::check_authentication(const params_t& pin,params_t& pout) { 114 void server_t::check_authentication(const params_t& pin,params_t& pout) {
113 vector<unsigned char> sig; 115 vector<unsigned char> sig;
114 mimetic::Base64::Decoder b; 116 mimetic::Base64::Decoder b;
115 const string& sigenc = pin.get_param("openid.sig"); 117 const string& sigenc = pin.get_param("openid.sig");
116 mimetic::decode( 118 mimetic::decode(
117 sigenc.begin(),sigenc.end(), b, 119 sigenc.begin(),sigenc.end(), b,
118 back_insert_iterator<vector<unsigned char> >(sig)); 120 back_insert_iterator<vector<unsigned char> >(sig));
119 assoc_t assoc; 121 assoc_t assoc;
120 try { 122 try {
121 assoc = retrieve_assoc(pin.get_param("openid.assoc_handle")); 123 assoc = retrieve_assoc(pin.get_param("openid.assoc_handle"));
122 }catch(failed_lookup& fl) { 124 }catch(failed_lookup& fl) {
123 throw failed_assertion(OPKELE_CP_ "invalid handle or handle not specified"); 125 throw failed_assertion(OPKELE_CP_ "invalid handle or handle not specified");
124 } 126 }
125 if(!assoc->stateless()) 127 if(!assoc->stateless())
126 throw stateful_handle(OPKELE_CP_ "will not do check_authentication on a stateful handle"); 128 throw stateful_handle(OPKELE_CP_ "will not do check_authentication on a stateful handle");
127 const string& slist = pin.get_param("openid.signed"); 129 const string& slist = pin.get_param("openid.signed");
128 string kv; 130 string kv;
129 string::size_type p =0; 131 string::size_type p =0;
130 while(true) { 132 while(true) {
131 string::size_type co = slist.find(',',p); 133 string::size_type co = slist.find(',',p);
132 string f = (co==string::npos)?slist.substr(p):slist.substr(p,co-p); 134 string f = (co==string::npos)?slist.substr(p):slist.substr(p,co-p);
133 kv += f; 135 kv += f;
134 kv += ':'; 136 kv += ':';
135 if(f=="mode") 137 if(f=="mode")
136 kv += "id_res"; 138 kv += "id_res";
137 else { 139 else {
138 f.insert(0,"openid."); 140 f.insert(0,"openid.");
139 kv += pin.get_param(f); 141 kv += pin.get_param(f);
140 } 142 }
141 kv += '\n'; 143 kv += '\n';