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.

Discussion<br />

Session caching is normally not enabled by default, but enabling it is a relatively<br />

painless process. OpenSSLdoes most of the work for you, although you can override<br />

much of the default behavior (for example, you might build your own caching<br />

mechanism on the server side). By default, OpenSSLuses an in-memory session<br />

cache, but if you will be caching a large number of sessions, or if you want sessions<br />

to persist across boots, you may be better off using some kind of disk-based cache.<br />

Most of the work required to enable session caching has to be done on the server<br />

side, but there’s not all that much that needs to be done:<br />

1. Set a session ID context. The purpose of the session ID context is to make sure<br />

the session is reused for the same purpose for which it was created. For instance,<br />

a session created for an SSLweb server should not be automatically allowed for<br />

an SSLFTP server. A session ID context can be any arbitrary binary data up to<br />

32 bytes in length. There are no requirements for what the data should be, other<br />

than that it should be unique for the purpose your server serves—you don’t<br />

want to find your server getting sessions from other servers.<br />

2. Set a session timeout. The OpenSSLdefault is 300 seconds, which is probably a<br />

reasonable default for most applications. When a session times out, it is not<br />

immediately purged from the server’s cache, but it will not be accepted when<br />

presented by the client. If a client attempts to use an expired session, the server<br />

will remove it from its cache.<br />

3. Set a caching mode. OpenSSLsupports a number of possible mode options,<br />

specified as a bit mask:<br />

SSL_SESS_CACHE_OFF<br />

Setting this mode disables session caching altogether. If you want to disable<br />

session caching, you should specify this flag by itself; you do not need to set<br />

a session ID context or a timeout.<br />

SSL_SESS_CACHE_SERVER<br />

Setting this mode causes sessions that are generated by the server to be<br />

cached. This is the default mode and should be included whenever you’re<br />

setting any of the other flags described here, except for SSL_SESS_CACHE_OFF.<br />

SSL_SESS_CACHE_NO_AUTO_CLEAR<br />

By default, the session cache is checked for expired entries once for every<br />

255 connections that are established. Sometimes this can cause an undesirable<br />

delay, so it may be desirable to disable this automatic flushing of the<br />

cache. If you set this mode, you should make sure that you periodically call<br />

SSL_CTX_flush_sessions( ) yourself.<br />

SSL_SESS_CACHE_NO_INTERNAL_LOOKUP<br />

If you want to replace OpenSSL’s internal caching mechanism with one of<br />

your own devising, you should set this mode. We do not include a recipe<br />

Using Session Caching to Make SSL Servers More Efficient | 461<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!