The FreeRADIUS server $Id: a4e7f8c94e8038b7627bcf52356b7ed15955c1d7 $
Loading...
Searching...
No Matches
Functions | Variables
tls_bio_tests.c File Reference

Tests for the datagram boundaries which the TLS dbuff bio records. More...

#include <freeradius-devel/util/test/acutest_common_init.h>
#include <freeradius-devel/util/test/acutest_helpers.h>
#include <freeradius-devel/tls/bio.h>
+ Include dependency graph for tls_bio_tests.c:

Go to the source code of this file.

Functions

static size_t cap_test_len (size_t i)
 Vary the datagram length, so that a mis-ordered queue is visible.
 
static BIO * datagram_bio_alloc (fr_tls_bio_dbuff_t **out)
 Allocate a bio with datagram boundaries turned on.
 
static BIO * stream_bio_alloc (fr_tls_bio_dbuff_t **out)
 Allocate a bio, without datagram boundaries.
 
static void test_clear_discards_boundaries (void)
 Clearing the buffer discards the boundaries with the data.
 
static void test_enable_is_idempotent (void)
 Enabling datagram mode twice is not an error.
 
static void test_flight_after_flight (void)
 A flight which is fully drained is followed by another.
 
static void test_flight_keeps_its_boundaries (void)
 Writes of different lengths come back in the order they were written.
 
static void test_one_write_one_datagram (void)
 One write is one datagram.
 
static void test_over_send (void)
 Sending more datagrams than were written is harmless.
 
static void test_partial_drain (void)
 Draining part of a flight leaves the rest in order.
 
static void test_partial_write_records_nothing (void)
 A datagram which does not fit records no boundary at all.
 
static void test_queue_cap (void)
 The queue is capped, a write past the cap fails, and draining makes room.
 
static void test_stream_has_no_boundaries (void)
 Without datagram mode the bio reports no boundaries at all.
 
static void tls_bio_test_init (void)
 Build the BIO_METHOD which fr_tls_bio_dbuff_alloc() clones.
 

Variables

 TEST_LIST
 

Detailed Description

Tests for the datagram boundaries which the TLS dbuff bio records.

The bio is the boundary between OpenSSL and the application. OpenSSL calls BIO_write() once per datagram, and a datagram transport has to send each of those as its own datagram. These tests write to the bio directly, so they need no socket, no session, and no handshake.

Definition in file tls_bio_tests.c.

Function Documentation

◆ cap_test_len()

static size_t cap_test_len ( size_t  i)
static

Vary the datagram length, so that a mis-ordered queue is visible.

A test which writes the same length every time cannot tell a correctly ordered queue from a shuffled one. The period is 7 and the test below drains 3, so a queue which is off by 3 reads differently at every entry. A period which divides the drain hides exactly the bug this is here to find.

Definition at line 256 of file tls_bio_tests.c.

+ Here is the caller graph for this function:

◆ datagram_bio_alloc()

static BIO * datagram_bio_alloc ( fr_tls_bio_dbuff_t **  out)
static

Allocate a bio with datagram boundaries turned on.

Definition at line 60 of file tls_bio_tests.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ stream_bio_alloc()

static BIO * stream_bio_alloc ( fr_tls_bio_dbuff_t **  out)
static

Allocate a bio, without datagram boundaries.

Definition at line 51 of file tls_bio_tests.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ test_clear_discards_boundaries()

static void test_clear_discards_boundaries ( void  )
static

Clearing the buffer discards the boundaries with the data.

Definition at line 367 of file tls_bio_tests.c.

+ Here is the call graph for this function:

◆ test_enable_is_idempotent()

static void test_enable_is_idempotent ( void  )
static

Enabling datagram mode twice is not an error.

Definition at line 388 of file tls_bio_tests.c.

+ Here is the call graph for this function:

◆ test_flight_after_flight()

static void test_flight_after_flight ( void  )
static

A flight which is fully drained is followed by another.

This is what actually happens on a connection: OpenSSL writes a flight, the application sends all of it, and the next flight arrives later. The queue has to be reusable rather than fill up once.

Definition at line 156 of file tls_bio_tests.c.

+ Here is the call graph for this function:

◆ test_flight_keeps_its_boundaries()

static void test_flight_keeps_its_boundaries ( void  )
static

Writes of different lengths come back in the order they were written.

This is the case the whole change exists for: OpenSSL writes a flight as several datagrams of unequal length, and joining them back together would produce one datagram larger than the MTU OpenSSL was given.

Definition at line 123 of file tls_bio_tests.c.

+ Here is the call graph for this function:

◆ test_one_write_one_datagram()

static void test_one_write_one_datagram ( void  )
static

One write is one datagram.

Definition at line 98 of file tls_bio_tests.c.

+ Here is the call graph for this function:

◆ test_over_send()

static void test_over_send ( void  )
static

Sending more datagrams than were written is harmless.

Definition at line 229 of file tls_bio_tests.c.

+ Here is the call graph for this function:

◆ test_partial_drain()

static void test_partial_drain ( void  )
static

Draining part of a flight leaves the rest in order.

Definition at line 195 of file tls_bio_tests.c.

+ Here is the call graph for this function:

◆ test_partial_write_records_nothing()

static void test_partial_write_records_nothing ( void  )
static

A datagram which does not fit records no boundary at all.

The buffer here cannot extend, so a write larger than the room left copies part of the data. Half a datagram is not a datagram, so the write has to fail rather than queue a length with nothing behind it.

Definition at line 326 of file tls_bio_tests.c.

+ Here is the call graph for this function:

◆ test_queue_cap()

static void test_queue_cap ( void  )
static

The queue is capped, a write past the cap fails, and draining makes room.

Filling the queue and then draining part of it is what makes the entries wrap, so this is also the test which covers moving them back down.

Definition at line 266 of file tls_bio_tests.c.

+ Here is the call graph for this function:

◆ test_stream_has_no_boundaries()

static void test_stream_has_no_boundaries ( void  )
static

Without datagram mode the bio reports no boundaries at all.

Definition at line 75 of file tls_bio_tests.c.

+ Here is the call graph for this function:

◆ tls_bio_test_init()

static void tls_bio_test_init ( void  )
static

Build the BIO_METHOD which fr_tls_bio_dbuff_alloc() clones.

The server calls this from fr_tls_init(). These tests do not start a server, so they call it themselves. acutest runs each test in its own process, so the flag is per test rather than per run.

Definition at line 39 of file tls_bio_tests.c.

+ Here is the caller graph for this function:

Variable Documentation

◆ TEST_LIST

TEST_LIST
Initial value:
= {
{ "stream_has_no_boundaries", test_stream_has_no_boundaries },
{ "one_write_one_datagram", test_one_write_one_datagram },
{ "flight_keeps_its_boundaries", test_flight_keeps_its_boundaries },
{ "flight_after_flight", test_flight_after_flight },
{ "partial_drain", test_partial_drain },
{ "over_send", test_over_send },
{ "queue_cap", test_queue_cap },
{ "partial_write_records_nothing", test_partial_write_records_nothing },
{ "clear_discards_boundaries", test_clear_discards_boundaries },
{ "enable_is_idempotent", test_enable_is_idempotent },
}
#define TEST_TERMINATOR
Definition acutest.h:77
static void test_partial_drain(void)
Draining part of a flight leaves the rest in order.
static void test_queue_cap(void)
The queue is capped, a write past the cap fails, and draining makes room.
static void test_clear_discards_boundaries(void)
Clearing the buffer discards the boundaries with the data.
static void test_one_write_one_datagram(void)
One write is one datagram.
static void test_flight_keeps_its_boundaries(void)
Writes of different lengths come back in the order they were written.
static void test_enable_is_idempotent(void)
Enabling datagram mode twice is not an error.
static void test_stream_has_no_boundaries(void)
Without datagram mode the bio reports no boundaries at all.
static void test_flight_after_flight(void)
A flight which is fully drained is followed by another.
static void test_over_send(void)
Sending more datagrams than were written is harmless.
static void test_partial_write_records_nothing(void)
A datagram which does not fit records no boundary at all.

Definition at line 407 of file tls_bio_tests.c.