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.

version<br />

Version string that is sent to the server. This string is generally used to indicate a<br />

version of the protocol that the client and server will speak to each other. It does<br />

not have anything to do with the Kerberos protocol or the version of Kerberos in<br />

use. The string may be anything you want, but both the client and server must<br />

agree on the same string for authentication to succeed.<br />

If authentication is successful, the return value from spc_krb5_client( ) will be 0,<br />

and the relevant fields in the spc_krb5bundle_t object will be filled in. The client may<br />

then proceed to use other Kerberos API functions to exchange encrypted and authenticated<br />

information with the server. Of particular interest is that a key suitable for use<br />

with a symmetric cipher is now available. (See Recipe 9.6 for an example of how to<br />

use the key effectively.)<br />

If any kind of error occurs while attempting to authenticate with the server, the<br />

return value from the following spc_krb5_client( ) function will be the error code<br />

returned by the Kerberos API function that failed. Complete lists of error codes are<br />

available in the Heimdal and MIT Kerberos header files.<br />

krb5_error_code spc_krb5_client(int sockfd, spc_krb5bundle_t *bundle,<br />

char *service, char *host, char *version) {<br />

int free_context = 0;<br />

krb5_principal server = 0;<br />

krb5_error_code rc;<br />

if (!bundle->ctx) {<br />

if ((rc = krb5_init_context(&(bundle->ctx))) != 0) goto error;<br />

free_context = 1;<br />

}<br />

if ((rc = krb5_sname_to_principal(bundle->ctx, host, service,<br />

KRB5_NT_SRV_HST, &server)) != 0) goto error;<br />

rc = krb5_sendauth(bundle->ctx, &(bundle->auth_ctx), &sockfd, version,<br />

0, server, AP_OPTS_MUTUAL_REQUIRED, 0, 0, 0, 0, 0, 0);<br />

if (!rc) {<br />

krb5_free_principal(bundle->ctx, server);<br />

return 0;<br />

}<br />

error:<br />

if (server) krb5_free_principal(bundle->ctx, server);<br />

if (bundle->ctx && free_context) {<br />

krb5_free_context(bundle->ctx);<br />

bundle->ctx = 0;<br />

}<br />

return rc;<br />

}<br />

The code for the server side of the connection is similar to the client side, although it<br />

is somewhat simplified because most of the information in the exchange comes from<br />

the client. The function spc_krb5_server( ), listed later in this section, performs the<br />

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