21.03.2013 Views

Problem - Kevin Tafuro

Problem - Kevin Tafuro

Problem - Kevin Tafuro

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

if (!(bio = BIO_new(BIO_s_mem( )))) goto error_exit;<br />

if (!(b64 = BIO_new(BIO_f_base64( )))) goto error_exit;<br />

BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);<br />

if (!(bio = BIO_push(b64, bio))) goto error_exit;<br />

b64 = 0;<br />

BIO_write(bio, *keydata, length);<br />

free(*keydata); *keydata = 0;<br />

if (!(length = BIO_get_mem_data(bio, &dummy))) goto error_exit;<br />

if (!(*keydata = (char *)malloc(length + 1))) goto error_exit;<br />

memcpy(*keydata, dummy, length);<br />

(*keydata)[length - 1] = '\0';<br />

return keytype;<br />

error_exit:<br />

if (b64) BIO_free_all(b64);<br />

if (bio) BIO_free_all(bio);<br />

if (*keydata) free(*keydata);<br />

*keydata = 0;<br />

return EVP_PKEY_NONE;<br />

}<br />

static int parse_line(char *line, char **ipnum, int *keytype, char **keydata) {<br />

char *end, *p, *tmp;<br />

/* we expect leading and trailing whitespace to be stripped already */<br />

for (p = line; *p && !isspace(*p); p++);<br />

if (!*p) return 0;<br />

*ipnum = line;<br />

for (*p++ = '\0'; *p && isspace(*p); p++);<br />

for (tmp = p; *p && !isspace(*p); p++);<br />

*keytype = (int)strtol(tmp, &end, 0);<br />

if (*end && !isspace(*end)) return 0;<br />

for (p = end; *p && isspace(*p); p++);<br />

for (tmp = p; *p && !isspace(*p); p++);<br />

if (*p) return 0;<br />

*keydata = tmp;<br />

return 1;<br />

}<br />

int spc_lookup_key(char *filename, char *ipnum, EVP_PKEY *key) {<br />

int bufsize = 0, length, keytype, lineno = 0, result = 0, store_keytype;<br />

char *buffer = 0, *keydata, *line, *store_ipnum, *store_keydata, tmp[1024];<br />

FILE *fp = 0;<br />

keytype = get_keydata(key, &keydata);<br />

if (keytype = = EVP_PKEY_NONE || !keydata) goto end;<br />

if (!(fp = fopen(filename, "r"))) goto end;<br />

while (fgets(tmp, sizeof(tmp), fp)) {<br />

length = strlen(tmp);<br />

442 | 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!