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.

uffer = (char *)realloc(buffer, bufsize + length + 1);<br />

memcpy(buffer + bufsize, tmp, length + 1);<br />

bufsize += length;<br />

if (buffer[bufsize - 1] != '\n') continue;<br />

while (bufsize && (buffer[bufsize - 1] = = '\r' || buffer[bufsize - 1] = = '\n'))<br />

bufsize--;<br />

buffer[bufsize] = '\0';<br />

bufsize = 0;<br />

lineno++;<br />

for (line = buffer; isspace(*line); line++);<br />

for (length = strlen(line); length && isspace(line[length - 1]); length--);<br />

line[length - 1] = '\0';<br />

/* blank lines and lines beginning with # or ; are ignored */<br />

if (!length || line[0] = = '#' || line[0] = = ';') continue;<br />

if (!parse_line(line, &store_ipnum, &store_keytype, &store_keydata)) {<br />

fprintf(stderr, "%s:%d: parse error\n", filename, lineno);<br />

continue;<br />

}<br />

if (inet_addr(store_ipnum) != inet_addr(ipnum)) continue;<br />

if (store_keytype != keytype || strcasecmp(store_keydata, keydata))<br />

result = -1;<br />

else result = 1;<br />

break;<br />

}<br />

end:<br />

if (buffer) free(buffer);<br />

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

if (fp) fclose(fp);<br />

return result;<br />

}<br />

If spc_lookup_key( ) returns 0, indicating that we do not know anything about the<br />

key, the user should be prompted in much the same way we did for certificates. If the<br />

user elects to remember the key, the spc_remember_key( ) function will add the key<br />

information to the key store so that the next time spc_lookup_key( ) is called, it will<br />

be found.<br />

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

int keytype, result = 0;<br />

char *keydata;<br />

FILE *fp = 0;<br />

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

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

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

fprintf(fp, "%s %d %s\n", ipnum, keytype, keydata);<br />

result = 1;<br />

end:<br />

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

if (fp) fclose(fp);<br />

Minimizing the Window of Vulnerability When Authenticating Without a PKI | 443<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!