21.03.2013 Views

Problem - Kevin Tafuro

Problem - Kevin Tafuro

Problem - Kevin Tafuro

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

* Confirmation receipts must be received within one hour (3600 seconds) */<br />

#define SPC_CONFIRMATION_EXPIRE 3600<br />

typedef struct {<br />

char *address;<br />

char *id;<br />

time_t expire;<br />

} spc_confirmation_t;<br />

static unsigned long confirmation_count, confirmation_size;<br />

static spc_confirmation_t *confirmations;<br />

static int new_confirmation(const char *address, const char *id) {<br />

unsigned long i;<br />

spc_confirmation_t *tmp;<br />

/* first make sure that the address isn't already in the list */<br />

for (i = 0; i < confirmation_count; i++)<br />

if (!strcmp(confirmations[i].address, address)) return 0;<br />

if (confirmation_count = = confirmation_size) {<br />

tmp = (spc_confirmation_t *)realloc(confirmations,<br />

sizeof(spc_confirmation_t) * (confirmation_size + 1));<br />

if (!tmp) return 0;<br />

confirmations = tmp;<br />

confirmation_size++;<br />

}<br />

confirmations[confirmation_count].address = strdup(address);<br />

confirmations[confirmation_count].id = strdup(id);<br />

confirmations[confirmation_count].expire = time(0) + SPC_CONFIRMATION_EXPIRE;<br />

if (!confirmations[confirmation_count].address ||<br />

!confirmations[confirmation_count].id) {<br />

if (confirmations[confirmation_count].address)<br />

free(confirmations[confirmation_count].address);<br />

if (confirmations[confirmation_count].id)<br />

free(confirmations[confirmation_count].id);<br />

return 0;<br />

}<br />

confirmation_count++;<br />

return 1;<br />

}<br />

int spc_confirmation_create(const char *address, char **id) {<br />

unsigned char buf[16];<br />

if (!spc_rand(buf, sizeof(buf))) return 0;<br />

if (!(*id = (char *)spc_base64_encode(buf, sizeof(buf), 0))) return 0;<br />

if (!new_confirmation(address, *id)) {<br />

free(*id);<br />

return 0;<br />

}<br />

return 1;<br />

}<br />

450 | Chapter 8: Authentication and Key Exchange<br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!