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.

for (exp = *attempts - allowed_fails - 1; exp; exp--)<br />

delay *= 2;<br />

return delay;<br />

}<br />

8.9 Performing Password-Based<br />

Authentication with crypt( )<br />

<strong>Problem</strong><br />

You need to use the standard Unix crypt( ) function for password-based authentication.<br />

Solution<br />

The standard Unix crypt( ) function typically uses a weak one-way algorithm to perform<br />

its encryption, which is usually also slow and insecure. You should, therefore,<br />

use crypt( ) only for compatibility reasons.<br />

Despite this limitation, you might want to use crypt( ) for compatibility purposes. If<br />

so, to encrypt a password, choose a random salt and call crypt( ) with the plaintext<br />

password and the chosen salt. To verify a password encrypted with crypt( ), encrypt<br />

the plaintext password using the already encrypted password as the salt, then compare<br />

the result with the already encrypted password. If they match, the password is<br />

correct.<br />

Discussion<br />

What we are doing here isn’t really encrypting a password. Actually,<br />

we are creating a password validator. We use the term encryption<br />

because it is in common use and is a more concise way to explain the<br />

process.<br />

The crypt( ) function is normally found in use only on older Unix systems that still<br />

exclusively use the /etc/passwd file for storing user information. Modern Unix systems<br />

typically use stronger algorithms and alternate storage methods for user information,<br />

such as the Lightweight Directory Access Protocol (LDAP), Kerberos (see<br />

Recipe 8.13), NIS, or some other type of directory service.<br />

The traditional implementation of crypt( ) uses DES (see Recipe 5.2 for a discussion<br />

of symmetric ciphers, including DES) to perform its encryption. DES is a symmetric<br />

cipher, which essentially means that if you have the key used to encrypt, you can<br />

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