Cryptography Reference
In-Depth Information
Listing C-1 details the SSL function prototypes. Notice that there's no
ssl_shutdown routine; SSLv2 didn't explicitly mark the end of a secure session.
Listing C-1: “ssl.h” SSL function prototypes
int ssl_connect( int connection, SSLParameters *parameters );
int ssl_send( int connection, const char *application_data, int length,
int options, SSLParameters *parameters );
int ssl_recv( int connection, char *target_buffer, int buffer_size,
int options, SSLParameters *parameters );
You can modify the HTTP client implementation introduced in Chapter 1 as
shown in Listing C-2 to be SSL-enabled by replacing socket-layer function calls
with these new SSL library calls.
Listing C-2: “https.c” main routine with SSLv2 support
#define HTTPS_PORT 443
...
int main( int argc, char *argv[ ] )
{
...
SSLParameters ssl_context;
...
host_address.sin_family = AF_INET;
host_address.sin_port = htons( HTTPS_PORT );
memcpy( &host_address.sin_addr, host_name->h_addr_list[ 0 ],
sizeof( struct in_addr ) );
if ( connect( client_connection, ( struct sockaddr * ) &host_address,
sizeof( host_address ) ) == -1 )
{
perror( “Unable to connect to host” );
return 2;
}
if ( ssl_connect( client_connection, &ssl_context ) )
{
fprintf( stderr, “Error: unable to negotiate SSL connection.\n” );
return 3;
}
http_get( client_connection, path, host, &ssl_context );
display_result( client_connection, &ssl_context );
...
As you can see, the changes to the main routine, which establishes the HTTP
connection, are fairly minimal. The changes to the http_get routine in Listing
C-3 are similarly unobtrusive.
Search WWH ::




Custom Search