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.

salt_len<br />

Length of the salt that will be used. The salt value is not actually entirely random.<br />

Three bytes of the salt are used to encode the iteration count and the public<br />

key size. The rest of it is random. We recommend that, if the salt is public,<br />

you use 16-byte salts. If the salt is kept private, you will not want to make them<br />

too large, because you will have to convert them into a printable format that the<br />

user has to carry around and enter. The minimum size AX allows is 11 bytes,<br />

which base64-encodes to 15 characters.<br />

out<br />

Pointer to a container into which credentials will be placed. You are expected to<br />

allocate this object.<br />

AX provides an API for serializing and deserializing credential objects:<br />

char *AX_CRED_serialize(AX_CRED *c, size_t *outlen);<br />

AX_CRED *AX_CRED_deserialize(char *buf, size_t buflen);<br />

These two functions each allocate their result with malloc( ) and return 0 on error.<br />

In addition, if the salt value is to stay private, you will need to retrieve it so that you<br />

can encode it and show it to the user. AX provides the following function for doing<br />

that:<br />

char *AX_get_salt(AX_CRED *creds, size_t *saltlen);<br />

The result is allocated by malloc( ). The size of the salt is placed into the memory<br />

pointed to by the second argument.<br />

Now that we can set up account information and store credentials in a database, we<br />

can look at how to actually set up a server to handle connections. The high-level AX<br />

API does most of the work for you. There’s an actual server abstraction, which is of<br />

type AX_SRV.<br />

You do need to define at least one callback, two if you want to log errors. In the first<br />

callback, you must return a credential object for the associated user. The callback<br />

should be a pointer to a function with the following signature:<br />

AX_CRED *AX_get_credentials_callback(AX_SRV *s, char *user, size_t ulen,<br />

char *extra, size_t elen);<br />

This function has the following arguments:<br />

s<br />

Pointer to the server object. If you have multiple servers in a single program, you<br />

can use this pointer to determine which server produced the request.<br />

user<br />

Username given to the server.<br />

ulen<br />

Length of the username.<br />

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