Cryptography Reference
In-Depth Information
However, because an SSL packet can be up to 16,384 bytes in length, either
the caller should always supply a buffer of this length, or ssl_recv needs to
deal with the case where the input buffer is smaller than the SSL packet. This
means that it needs to remember what was left over but not read and passes
that back to the caller on the next ssl_recv .
if ( !parameters->handshake_finished )
{
}
else
{
// If the handshake is finished, the app should be expecting data;
// return it
if ( message_len > target_bufsz )
{
memcpy( target_buffer, buffer, target_bufsz );
status = target_bufsz;
// Store the remaining data so that the next “read” call just
// picks it up
parameters->unread_length = message_len - target_bufsz;
parameters->unread_buffer = malloc( parameters->unread_length );
memcpy( parameters->unread_buffer, buffer + target_bufsz,
parameters->unread_length );
}
else
{
memcpy( target_buffer, buffer, message_len );
status = message_len;
}
}
Finally, near the top of ssl_recv , check to see if there was any unread data
from the previous call:
if ( parameters->unread_length )
{
buffer = parameters->unread_buffer;
message_len = parameters->unread_length;
parameters->unread_buffer = NULL;
parameters->unread_length = 0;
}
else
{
// New message - read the length first
if ( read( connection, &message_len, 2, 0 ) <= 0 )
{
return -1;
Search WWH ::




Custom Search