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.

This function returns a pointer to an object of type AX_SRV. If there’s an error, an exception<br />

is thrown using the XXLexception-handling API (discussed in Recipe 13.1). All<br />

possible exceptions are standard POSIX error codes that would indicate some sort of<br />

failure when calling the underlying socket API.<br />

To close down the server and deallocate associated memory, pass the object to AX_<br />

srv_close( ).<br />

Once we have a server object, we need to wait for a connection to come in. Once a<br />

connection comes in, we can tell the server to perform a key exchange with that connection.<br />

To wait for a connection to come in, use the following function (which will<br />

always block):<br />

AX_CLIENT *AX_srv_accept(AX_SRV *s);<br />

This function returns a pointer to an AX_CLIENT object when there is a connection.<br />

Again, if there’s an error, an exception gets thrown, indicating an error caught by the<br />

underlying socket API.<br />

At this point, you should launch a new thread or process to deal with the connection,<br />

to prevent an attacker from launching a denial of service by stalling the key<br />

exchange.<br />

Once we have received a client object, we can perform a key exchange with the following<br />

function:<br />

int AX_srv_exchange(AX_CLIENT *c, char *key, size_t *kl, char *uname, size_t *ul,<br />

char *x, size_t *xl);<br />

This function has the following arguments:<br />

c<br />

Pointer to the client object returned by AX_srv_accept( ). This object will be<br />

deallocated automatically during the call.<br />

key<br />

Agreed-upon key.<br />

kl<br />

Pointer into which the length of the agreed-upon key in bytes is placed.<br />

uname<br />

Pointer to memory allocated by malloc( ) that stores the username of the entity<br />

on the other side. You are responsible for freeing this memory with free( ).<br />

ul<br />

Pointer into which the length of the username in bytes is placed.<br />

x<br />

Pointer to dynamically allocated memory representing application-specific data.<br />

The memory is allocated with malloc( ), and you are responsible for deallocating<br />

this memory as well.<br />

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