comparison src/c/openid.c @ 6:99496175078b

Added preliminary versions of all the authentication verification steps
author Adam Chlipala <adam@chlipala.net>
date Mon, 27 Dec 2010 13:18:02 -0500
parents 2d409aff8800
children 976121190b2d
comparison
equal deleted inserted replaced
5:443f27cd1572 6:99496175078b
1 #include <string.h> 1 #include <string.h>
2 2
3 #include <openssl/bio.h>
4 #include <openssl/evp.h>
5 #include <openssl/buffer.h>
3 #include <openssl/sha.h> 6 #include <openssl/sha.h>
4 #include <curl/curl.h> 7 #include <curl/curl.h>
5 #include <expat.h> 8 #include <expat.h>
6 9
7 #include <openid.h> 10 #include <openid.h>
249 uw_OpenidFfi_outputs uw_OpenidFfi_indirect(uw_context ctx, uw_Basis_string fields) { 252 uw_OpenidFfi_outputs uw_OpenidFfi_indirect(uw_context ctx, uw_Basis_string fields) {
250 uw_OpenidFfi_outputs b = malloc(sizeof(uw_buffer)); 253 uw_OpenidFfi_outputs b = malloc(sizeof(uw_buffer));
251 254
252 uw_buffer_init(BUF_MAX, b, BUF_INIT); 255 uw_buffer_init(BUF_MAX, b, BUF_INIT);
253 256
257 fields = uw_strdup(ctx, fields);
258
254 while (*fields) { 259 while (*fields) {
255 char *equal = strchr(fields, '='), *and, *s; 260 char *equal = strchr(fields, '='), *and, *s;
256 261
257 if (!equal) 262 if (!equal)
258 break; 263 break;
274 } 279 }
275 280
276 uw_buffer_append(b, "", 1); 281 uw_buffer_append(b, "", 1);
277 return b; 282 return b;
278 } 283 }
284
285 static uw_Basis_string base64(uw_context ctx, unsigned char *input, int length) {
286 BIO *bmem, *b64;
287 BUF_MEM *bptr;
288
289 b64 = BIO_new(BIO_f_base64());
290 bmem = BIO_new(BIO_s_mem());
291 b64 = BIO_push(b64, bmem);
292 BIO_write(b64, input, length);
293 (void)BIO_flush(b64);
294 BIO_get_mem_ptr(b64, &bptr);
295
296 char *buff = uw_malloc(ctx, bptr->length);
297 memcpy(buff, bptr->data, bptr->length-1);
298 buff[bptr->length-1] = 0;
299
300 BIO_free_all(b64);
301
302 return buff;
303 }
304
305 uw_Basis_string uw_OpenidFfi_sha256(uw_context ctx, uw_Basis_string s) {
306 unsigned char out[SHA256_DIGEST_LENGTH];
307
308 SHA256((unsigned char *)s, strlen(s), out);
309
310 return base64(ctx, out, sizeof out);
311 }