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.

This call will throw an XXLexception if there’s a socket error. Otherwise, it will<br />

return an object dynamically allocated with malloc( ) that contains the key exchange<br />

state.<br />

If the user is expected to know the salt (i.e., if the server will not send it over the network),<br />

you must enter it at this time, with the following function:<br />

void AX_set_salt(AX *p, char *salt, size_t saltlen);<br />

AX_set_salt( ) expects the binary encoding that the server-side API produced. It is<br />

your responsibility to make sure the user can enter this value. Note that this function<br />

copies a reference to the salt and does not copy the actual value, so do not modify<br />

the memory associated with your salt until the AX context is deallocated (which<br />

happens as a side effect of the key exchange process; see the following discussion).<br />

Note that, the first time you make the user type in the salt on a particular client<br />

machine, you should save the salt to disk. We strongly recommend encrypting the<br />

salt with the user’s supplied password, using an authenticated encryption mode and<br />

the key derivation function from Recipe 4.10.<br />

Once the client knows the salt, it can initiate key exchange using the following function:<br />

int AX_exchange(AX *p, char *pw, size_t pwlen, size_t keylen, char *key);<br />

This function has the following arguments:<br />

p<br />

Pointer to the context object that represents the connection to the server.<br />

pw<br />

Password, treated as a binary string (i.e., not NULL-terminated).<br />

pwlen<br />

Length of the associated password in bytes.<br />

keylen<br />

Key length the client desires in the exchange. The server must be prepared to<br />

serve up keys of this length; otherwise, the exchange will fail.<br />

key<br />

Buffer into which the key will be placed if authentication and exchange are successful.<br />

On success, AX_exchange( ) will return a connected socket descriptor in blocking<br />

mode that you can then use to talk to the server. On failure, an XXLexception will<br />

be raised. The value of the exception will be either AX_CAUTH_ERR if we believe the<br />

server refused our credentials or AX_SAUTH_ERR if we refused the server’s credentials.<br />

In both cases, it is possible that an attacker’s tampering with the data stream caused<br />

the error. On the other hand, it could be that the two parties could not agree on the<br />

protocol version or key size.<br />

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