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.

ut they shouldn’t tolerate reordering, because doing so means foregoing standard<br />

capture replay prevention. You can always drop out-of-order messages or explicitly<br />

keep track of recent message numbers that have been seen, then drop any duplicates<br />

or any messages with a number that comes before that window.<br />

Particularly if you’re using TCP, if a message fails to authenticate cryptographically,<br />

recovering is tremendously difficult. Accidental errors will almost always be caught<br />

at the TCP level, and you can assume that if the cryptography catches it, an attacker<br />

is tampering. In such a case, a smart attacker can cause a denial of service, no matter<br />

what. It’s generally easiest to terminate the connection, perhaps sending back an<br />

error packet first.<br />

Often, unrecoverable errors result in plaintext error messages. In such cases, you<br />

should be conservative and send no reason code signaling why you failed. There are<br />

instances in major protocols where verbose errors led to an important information<br />

leak.<br />

When you’re designing your protocol for client-server communications, you should<br />

include a sequence of messages between both parties to communicate to the other<br />

side that the connection is being terminated normally. That way, when a connection<br />

is prematurely terminated, both sides of the connection have some way of knowing<br />

whether the connection was terminated legitimately or was the result of a possible<br />

attack. In the latter case, you may wish to take appropriate action. For example, if<br />

the connection is prematurely terminated in the process of performing some database<br />

operation, you may want to roll back any changes that were made.<br />

The next consideration is what the message format should look like. Generally, a<br />

message format will start out with a plaintext, fixed-size field encoding the length of<br />

the remainder of the message. Then, there may or may not be plaintext values, such<br />

as the message number (the message number can go inside the ciphertext, but often<br />

it’s useful for computing the nonce, as opposed to assuming it). Finally comes the<br />

ciphertext and the MAC value (which may be one unit, depending on whether you<br />

use an authenticating encryption mode such as CWC).<br />

Any unencrypted data in the message should be authenticated in a secure manner<br />

along with the encrypted data. Modes like CWC and CCM allow you to authenticate<br />

both plaintext and ciphertext with a single MAC value. CMAC has the same<br />

capability. With other MACs, you can simulate this behavior by MAC’ing the length<br />

of the plaintext portion, concatenated with the plaintext portion, concatenated with<br />

the ciphertext. To do this correctly, however, you must always include the plaintext<br />

length, even if it is zero.<br />

Assume that we’ve established a TCP connection and exchanged a 128-bit key using<br />

a protocol such as PAX (as discussed in Recipe 8.15). Now, what should we do with<br />

that key? The answer depends on a few things. First, we might need separate keys for<br />

encryption and MAC’ing if we’re not using a dual-use mode such as CWC. Second,<br />

Building an Authenticated Secure Channel Without SSL | 493<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!