Cryptography Reference
In-Depth Information
}
return 3;
}
}
if ( tls_connect( client_connection, &tls_context ) )
{
This makes use of the http_connect function shown in Listing 10-2.
Listing 10-2: “https.c” http_connect
int http_connect( int connection,
const char *host,
int port,
const char *proxy_user,
const char *proxy_password )
{
static char connect_command[ MAX_GET_COMMAND ];
int received = 0;
static char recv_buf[ BUFFER_SIZE + 1 ];
int http_status = 0;
sprintf( connect_command, “CONNECT %s:%d HTTP/1.1\r\n”, host, port );
if ( send( connection, connect_command,
strlen( connect_command ), 0 ) == -1 )
{
return -1;
}
sprintf( connect_command, “Host: %s:%d\r\n”, host, port );
if ( send( connection, connect_command,
strlen( connect_command ), 0 ) == -1 )
{
return -1;
}
if ( proxy_user )
{
int credentials_len = strlen( proxy_user ) +
strlen( proxy_password ) + 1;
char *proxy_credentials = malloc( credentials_len );
char *auth_string = malloc( ( ( credentials_len * 4 ) / 3 ) + 1 );
sprintf( proxy_credentials, “%s:%s”, proxy_user, proxy_password );
base64_encode( proxy_credentials, credentials_len, auth_string );
sprintf( connect_command, “Proxy-Authorization: BASIC %s\r\n”,
auth_string );
if ( send( connection, connect_command,
strlen( connect_command ), 0 ) == -1 )
{
free( proxy_credentials );
 
Search WWH ::




Custom Search