Cryptography Reference
In-Depth Information
Here,
http_get
and
display_result
change only slightly, as shown in Listing
6-3; they take an extra parameter indicating the new
tls_context
, and they call
tls_send
and
tls_recv
to send and receive data; otherwise, they're identical to
the functions presented in Chapter 1:
Listing 6-3:
“https.c” http_get and display_result
int http_get( int connection, const char *path, const char *host,
TLSParameters *tls_context )
{
static char get_command[ MAX_GET_COMMAND ];
sprintf( get_command, “GET /%s HTTP/1.1\r\n”, path );
if ( tls_send( connection, get_command,
strlen( get_command ), 0, tls_context ) == -1 )
{
return -1;
}
sprintf( get_command, “Host: %s\r\n”, host );
if ( tls_send( connection, get_command,
strlen( get_command ), 0, tls_context ) == -1 )
{
return -1;
}
strcpy( get_command, “Connection: Close\r\n\r\n” );
if ( tls_send( connection, get_command,
strlen( get_command ), 0, tls_context ) == -1 )
{
return -1;
}
return 0;
}
void display_result( int connection,
TLSParameters *tls_context
)
{
…
while ( ( received = tls_recv( connection, recv_buf,
BUFFER_SIZE, 0, tls_context ) ) >= 0 )
{
recv_buf[ received ] = '\0';
printf( “data: %s”, recv_buf );
}
…
Notice that the proxy negotiation part of
http_get
is missing from
Listing 6-3. Negotiating proxies is a major complication for SSL; by now you can
probably see why. The proxy performs the HTTP connection on behalf of the
client and then returns the results back to it. Unfortunately this is by defi nition a
Search WWH ::
Custom Search