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.

it’s unique and unpredictable! You’ll always need some element of randomness in<br />

your session IDs, though, so we recommend that you always include at least a 64-bit,<br />

cryptographically strong, random number.<br />

Depending on how you choose to generate your session ID, you may require a<br />

lookup table keyed by the session ID. In the table, you’ll need at least to keep the<br />

username associated with the session ID so that you know which user you’re dealing<br />

with. You can also attach timing information to perform session expiration. If you<br />

don’t want to get that fancy, and all you need to keep track of is the user’s name or<br />

some kind of internal user ID, a good solution is to encrypt that information along<br />

with some other information. If you choose to do this, be sure to include a nonce,<br />

and properly MAC and encrypt the data (e.g., with CWC mode from Recipe 5.10, or<br />

as described in Recipe 6.18); the result will be the session ID. In some instances, you<br />

may want to bind the IP address into the cookie as well.<br />

See Also<br />

Recipes 5.10, 6.18<br />

You may be tempted to bind the IP address of the client into the session<br />

identifier. Think carefully before doing this because it is common<br />

for clients to change IP addresses, particularly if they are mobile or<br />

connecting to your server through a proxy that is actually a pool of<br />

machines, all with different IP addresses. Two connections from the<br />

same client are not guaranteed to have the same IP address.<br />

9.10 Securing Database Connections<br />

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

You’re using a database backend in your application, and you want to ensure that<br />

network traffic between your application and the database server is secured with<br />

SSL.<br />

Solution<br />

MySQL4.00, PostgreSQL7.1, and newer versions of each of these servers support<br />

SSL-enabled connections between clients and servers. If you’re using older versions<br />

or another server that’s not covered here that does not support SSLnatively, you may<br />

wish to use Stunnel (see Recipe 9.5) to secure connections to the server.<br />

Discussion<br />

In the following subsections we’ll look at the different issues for MySQLand PostgreSQL.<br />

Securing Database Connections | 487<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!