Cryptography Reference
In-Depth Information
}
#ifdef WIN32
if ( closesocket( connection ) == -1 )
#else
if ( close( connection ) == -1 )
#endif
{
perror( “Unable to close connection” );
}
}
And, of course, read_line , build_error_response , and build_success_
response must be updated to invoke tls_send and tls_recv instead of send
and recv as in Listing 7-3.
Listing 7-3: “ssl_webserver.c” send and read modifi cations
char *read_line( int connection , TLSParameters *tls_context )
{
while ( ( size = tls_recv ( connection, &c, 1, 0, tls_context ) ) > = 0 )
{
static void build_success_response( int connection , TLSParameters *tls_context )
{
if ( tls_send( connection, buf, strlen( buf ), 0 , tls_context ) < strlen( buf ) )
static void build_error_response( int connection,
int error_code ,
TLSParameters *tls_context )
{
if ( tls_send ( connection, buf, strlen( buf ), 0 , tls_context ) < strlen( buf ) )
{
Other than tls_accept , all of the support functions referenced here were
implemented in Chapter 6 and can be used exactly as is.
Notice the HTTPS protocol at work. The server accepts a connection and
then immediately waits for a client hello message; if any attempt is made to
send any other data, an error occurs. Although this is not strictly required by
the TLS protocol itself, it is common when integrating TLS into an existing
protocol.
tls_accept is a mirror image of tls_connect ; it must wait for a client hello.
(Remember that the client must always initiate the TLS handshake.) After the
hello is received, the server responds with hello, certifi cate, and hello done
messages back-to-back, waits for the client's change cipher-spec and fi nished
message, sends its own, and returns. This is shown in Listing 7-4.
 
Search WWH ::




Custom Search