Cryptography Reference
In-Depth Information
Listing 7-1: “ssl_webserver.c” main routine
#define HTTPS_PORT 443
local_addr.sin_port = htons( HTTPS_PORT );
while ( ( connect_sock = accept( listen_sock,
( struct sockaddr * ) &client_addr,
&client_addr_len ) ) != -1 )
{
process_https_request( connect_sock );
}
As you can see, there's nothing TLS-specifi c here; you're just accepting con-
nections on a different port.
process_https_request is just like process_http_request , except that it
starts with a call to tls_accept in Listing 7-2.
Listing 7-2: “ssl_webserver.c” process_https_request
static void process_https_request( int connection )
{
char *request_line;
TLSParameters tls_context;
if ( tls_accept( connection, &tls_context ) )
{
perror( “Unable to establish SSL connection” );
}
else
{
request_line = read_line( connection , &tls_context );
if ( strncmp( request_line, “GET”, 3 ) )
{
// Only supports “GET” requests
build_error_response( connection, 400 , &tls_context );
}
else
{
// Skip over all header lines, don't care
while ( strcmp( read_line( connection , &tls_context ), “” ) )
{
printf( “skipped a header line\n” );
}
build_success_response( connection , &tls_context );
}
tls_shutdown( connection, &tls_context );
Search WWH ::




Custom Search