Home | History | Annotate | Line # | Download | only in tests
packetProcessing.c revision 1.1.1.9
      1      1.1  christos #include "config.h"
      2  1.1.1.6  christos 
      3      1.1  christos #include "sntptest.h"
      4      1.1  christos #include "networking.h"
      5      1.1  christos #include "ntp_stdlib.h"
      6      1.1  christos #include "unity.h"
      7      1.1  christos 
      8  1.1.1.8  christos #define CMAC		"AES128CMAC"
      9  1.1.1.8  christos #define CMAC_LENGTH	16
     10  1.1.1.8  christos 
     11  1.1.1.3  christos 
     12      1.1  christos const char * Version = "stub unit test Version string";
     13      1.1  christos 
     14  1.1.1.7  christos /* Hacks into the key database. */
     15      1.1  christos extern struct key* key_ptr;
     16      1.1  christos extern int key_cnt;
     17      1.1  christos 
     18      1.1  christos 
     19  1.1.1.3  christos void PrepareAuthenticationTest(int key_id,int key_len,const char* type,const void* key_seq);
     20  1.1.1.3  christos void PrepareAuthenticationTestMD5(int key_id,int key_len,const void* key_seq);
     21  1.1.1.3  christos void setUp(void);
     22  1.1.1.3  christos void tearDown(void);
     23  1.1.1.3  christos void test_TooShortLength(void);
     24  1.1.1.3  christos void test_LengthNotMultipleOfFour(void);
     25  1.1.1.3  christos void test_TooShortExtensionFieldLength(void);
     26  1.1.1.3  christos void test_UnauthenticatedPacketReject(void);
     27  1.1.1.3  christos void test_CryptoNAKPacketReject(void);
     28  1.1.1.3  christos void test_AuthenticatedPacketInvalid(void);
     29  1.1.1.3  christos void test_AuthenticatedPacketUnknownKey(void);
     30  1.1.1.3  christos void test_ServerVersionTooOld(void);
     31  1.1.1.3  christos void test_ServerVersionTooNew(void);
     32  1.1.1.3  christos void test_NonWantedMode(void);
     33  1.1.1.3  christos void test_KoDRate(void);
     34  1.1.1.3  christos void test_KoDDeny(void);
     35  1.1.1.3  christos void test_RejectUnsyncedServer(void);
     36  1.1.1.3  christos void test_RejectWrongResponseServerMode(void);
     37  1.1.1.3  christos void test_AcceptNoSentPacketBroadcastMode(void);
     38  1.1.1.3  christos void test_CorrectUnauthenticatedPacket(void);
     39  1.1.1.3  christos void test_CorrectAuthenticatedPacketMD5(void);
     40  1.1.1.3  christos void test_CorrectAuthenticatedPacketSHA1(void);
     41  1.1.1.8  christos void test_CorrectAuthenticatedPacketCMAC(void);
     42  1.1.1.3  christos 
     43  1.1.1.7  christos /* [Bug 2998] There are some issues whith the definition of 'struct pkt'
     44  1.1.1.7  christos  * when AUTOKEY is undefined -- the formal struct is too small to hold
     45  1.1.1.7  christos  * all the extension fields that are going to be tested. We have to make
     46  1.1.1.7  christos  * sure we have the extra bytes, or the test yield undefined results due
     47  1.1.1.7  christos  * to buffer overrun.
     48  1.1.1.7  christos  */
     49  1.1.1.7  christos #ifndef AUTOKEY
     50  1.1.1.7  christos # define EXTRA_BUFSIZE 256
     51  1.1.1.7  christos #else
     52  1.1.1.7  christos # define EXTRA_BUFSIZE 0
     53  1.1.1.7  christos #endif
     54  1.1.1.7  christos 
     55  1.1.1.7  christos union tpkt {
     56  1.1.1.7  christos 	struct pkt p;
     57  1.1.1.7  christos 	u_char     b[sizeof(struct pkt) + EXTRA_BUFSIZE];
     58  1.1.1.7  christos };
     59  1.1.1.3  christos 
     60  1.1.1.7  christos static union tpkt testpkt;
     61  1.1.1.7  christos static union tpkt testspkt;
     62      1.1  christos static sockaddr_u testsock;
     63      1.1  christos bool restoreKeyDb;
     64      1.1  christos 
     65  1.1.1.3  christos 
     66  1.1.1.3  christos void
     67  1.1.1.6  christos PrepareAuthenticationTest(
     68  1.1.1.6  christos 	int		key_id,
     69  1.1.1.6  christos 	int		key_len,
     70  1.1.1.6  christos 	const char *	type,
     71  1.1.1.6  christos 	const void *	key_seq
     72  1.1.1.6  christos 	)
     73  1.1.1.6  christos {
     74      1.1  christos 	char str[25];
     75  1.1.1.3  christos 	snprintf(str, 25, "%d", key_id);
     76      1.1  christos 	ActivateOption("-a", str);
     77      1.1  christos 
     78      1.1  christos 	key_cnt = 1;
     79  1.1.1.3  christos 	key_ptr = emalloc(sizeof(struct key));
     80      1.1  christos 	key_ptr->next = NULL;
     81      1.1  christos 	key_ptr->key_id = key_id;
     82      1.1  christos 	key_ptr->key_len = key_len;
     83  1.1.1.8  christos 	memcpy(key_ptr->typen, type, strlen(type) + 1);
     84      1.1  christos 
     85      1.1  christos 	TEST_ASSERT_TRUE(key_len < sizeof(key_ptr->key_seq));
     86      1.1  christos 
     87      1.1  christos 	memcpy(key_ptr->key_seq, key_seq, key_ptr->key_len);
     88      1.1  christos 	restoreKeyDb = true;
     89      1.1  christos }
     90      1.1  christos 
     91  1.1.1.3  christos 
     92  1.1.1.3  christos void
     93  1.1.1.6  christos PrepareAuthenticationTestMD5(
     94  1.1.1.6  christos 	int 		key_id,
     95  1.1.1.6  christos 	int 		key_len,
     96  1.1.1.6  christos 	const void *	key_seq
     97  1.1.1.6  christos 	)
     98  1.1.1.6  christos {
     99      1.1  christos 	PrepareAuthenticationTest(key_id, key_len, "MD5", key_seq);
    100      1.1  christos }
    101      1.1  christos 
    102  1.1.1.3  christos 
    103  1.1.1.3  christos void
    104  1.1.1.6  christos setUp(void)
    105  1.1.1.6  christos {
    106      1.1  christos 
    107      1.1  christos 	sntptest();
    108      1.1  christos 	restoreKeyDb = false;
    109      1.1  christos 
    110      1.1  christos 	/* Initialize the test packet and socket,
    111  1.1.1.6  christos 	 * so they contain at least some valid data.
    112  1.1.1.6  christos 	 */
    113  1.1.1.7  christos 	testpkt.p.li_vn_mode = PKT_LI_VN_MODE(LEAP_NOWARNING, NTP_VERSION,
    114      1.1  christos 										MODE_SERVER);
    115  1.1.1.7  christos 	testpkt.p.stratum = STRATUM_REFCLOCK;
    116  1.1.1.7  christos 	memcpy(&testpkt.p.refid, "GPS\0", 4);
    117      1.1  christos 
    118      1.1  christos 	/* Set the origin timestamp of the received packet to the
    119  1.1.1.6  christos 	 * same value as the transmit timestamp of the sent packet.
    120  1.1.1.6  christos 	 */
    121      1.1  christos 	l_fp tmp;
    122      1.1  christos 	tmp.l_ui = 1000UL;
    123      1.1  christos 	tmp.l_uf = 0UL;
    124      1.1  christos 
    125  1.1.1.7  christos 	HTONL_FP(&tmp, &testpkt.p.org);
    126  1.1.1.7  christos 	HTONL_FP(&tmp, &testspkt.p.xmt);
    127      1.1  christos }
    128      1.1  christos 
    129  1.1.1.3  christos 
    130  1.1.1.3  christos void
    131  1.1.1.6  christos tearDown(void)
    132  1.1.1.6  christos {
    133      1.1  christos 	if (restoreKeyDb) {
    134      1.1  christos 		key_cnt = 0;
    135      1.1  christos 		free(key_ptr);
    136      1.1  christos 		key_ptr = NULL;
    137      1.1  christos 	}
    138      1.1  christos 
    139  1.1.1.6  christos 	sntptest_destroy(); /* only on the final test!! if counter == 0 etc... */
    140      1.1  christos }
    141      1.1  christos 
    142      1.1  christos 
    143  1.1.1.3  christos void
    144  1.1.1.6  christos test_TooShortLength(void)
    145  1.1.1.6  christos {
    146      1.1  christos 	TEST_ASSERT_EQUAL(PACKET_UNUSEABLE,
    147  1.1.1.7  christos 			  process_pkt(&testpkt.p, &testsock, LEN_PKT_NOMAC - 1,
    148  1.1.1.7  christos 				      MODE_SERVER, &testspkt.p, "UnitTest"));
    149      1.1  christos 	TEST_ASSERT_EQUAL(PACKET_UNUSEABLE,
    150  1.1.1.7  christos 			  process_pkt(&testpkt.p, &testsock, LEN_PKT_NOMAC - 1,
    151  1.1.1.7  christos 				      MODE_BROADCAST, &testspkt.p, "UnitTest"));
    152      1.1  christos }
    153      1.1  christos 
    154  1.1.1.3  christos 
    155  1.1.1.3  christos void
    156  1.1.1.6  christos test_LengthNotMultipleOfFour(void)
    157  1.1.1.6  christos {
    158      1.1  christos 	TEST_ASSERT_EQUAL(PACKET_UNUSEABLE,
    159  1.1.1.7  christos 			  process_pkt(&testpkt.p, &testsock, LEN_PKT_NOMAC + 6,
    160  1.1.1.7  christos 				      MODE_SERVER, &testspkt.p, "UnitTest"));
    161      1.1  christos 	TEST_ASSERT_EQUAL(PACKET_UNUSEABLE,
    162  1.1.1.7  christos 			  process_pkt(&testpkt.p, &testsock, LEN_PKT_NOMAC + 3,
    163  1.1.1.7  christos 				      MODE_BROADCAST, &testspkt.p, "UnitTest"));
    164      1.1  christos }
    165      1.1  christos 
    166  1.1.1.3  christos 
    167  1.1.1.3  christos void
    168  1.1.1.6  christos test_TooShortExtensionFieldLength(void)
    169  1.1.1.6  christos {
    170  1.1.1.7  christos 	/* [Bug 2998] We have to get around the formal specification of
    171  1.1.1.7  christos 	 * the extension field if AUTOKEY is undefined. (At least CLANG
    172  1.1.1.7  christos 	 * issues a warning in this case. It's just a warning, but
    173  1.1.1.7  christos 	 * still...
    174  1.1.1.7  christos 	 */
    175  1.1.1.7  christos 	uint32_t * pe = testpkt.p.exten + 7;
    176  1.1.1.7  christos 
    177      1.1  christos 	/* The lower 16-bits are the length of the extension field.
    178      1.1  christos 	 * This lengths must be multiples of 4 bytes, which gives
    179  1.1.1.6  christos 	 * a minimum of 4 byte extension field length.
    180  1.1.1.6  christos 	 */
    181  1.1.1.7  christos 	*pe = htonl(3); /* 3 bytes is too short. */
    182      1.1  christos 
    183      1.1  christos 	/* We send in a pkt_len of header size + 4 byte extension
    184      1.1  christos 	 * header + 24 byte MAC, this prevents the length error to
    185  1.1.1.6  christos 	 * be caught at an earlier stage
    186  1.1.1.6  christos 	 */
    187      1.1  christos 	int pkt_len = LEN_PKT_NOMAC + 4 + 24;
    188      1.1  christos 
    189      1.1  christos 	TEST_ASSERT_EQUAL(PACKET_UNUSEABLE,
    190  1.1.1.7  christos 			  process_pkt(&testpkt.p, &testsock, pkt_len,
    191  1.1.1.7  christos 				      MODE_SERVER, &testspkt.p, "UnitTest"));
    192      1.1  christos }
    193      1.1  christos 
    194  1.1.1.3  christos 
    195  1.1.1.3  christos void
    196  1.1.1.6  christos test_UnauthenticatedPacketReject(void)
    197  1.1.1.6  christos {
    198  1.1.1.6  christos 	/* Activate authentication option */
    199      1.1  christos 	ActivateOption("-a", "123");
    200      1.1  christos 	TEST_ASSERT_TRUE(ENABLED_OPT(AUTHENTICATION));
    201      1.1  christos 
    202      1.1  christos 	int pkt_len = LEN_PKT_NOMAC;
    203      1.1  christos 
    204  1.1.1.6  christos 	/* We demand authentication, but no MAC header is present. */
    205      1.1  christos 	TEST_ASSERT_EQUAL(SERVER_AUTH_FAIL,
    206  1.1.1.7  christos 			  process_pkt(&testpkt.p, &testsock, pkt_len,
    207  1.1.1.7  christos 				      MODE_SERVER, &testspkt.p, "UnitTest"));
    208      1.1  christos }
    209      1.1  christos 
    210  1.1.1.3  christos 
    211  1.1.1.3  christos void
    212  1.1.1.6  christos test_CryptoNAKPacketReject(void)
    213  1.1.1.6  christos {
    214  1.1.1.6  christos 	/* Activate authentication option */
    215      1.1  christos 	ActivateOption("-a", "123");
    216      1.1  christos 	TEST_ASSERT_TRUE(ENABLED_OPT(AUTHENTICATION));
    217      1.1  christos 
    218  1.1.1.6  christos 	int pkt_len = LEN_PKT_NOMAC + 4; /* + 4 byte MAC = Crypto-NAK */
    219      1.1  christos 
    220      1.1  christos 	TEST_ASSERT_EQUAL(SERVER_AUTH_FAIL,
    221  1.1.1.7  christos 			  process_pkt(&testpkt.p, &testsock, pkt_len,
    222  1.1.1.7  christos 				      MODE_SERVER, &testspkt.p, "UnitTest"));
    223      1.1  christos }
    224      1.1  christos 
    225  1.1.1.3  christos 
    226  1.1.1.3  christos void
    227  1.1.1.6  christos test_AuthenticatedPacketInvalid(void)
    228  1.1.1.6  christos {
    229  1.1.1.6  christos 	/* Activate authentication option */
    230      1.1  christos 	PrepareAuthenticationTestMD5(50, 9, "123456789");
    231      1.1  christos 	TEST_ASSERT_TRUE(ENABLED_OPT(AUTHENTICATION));
    232      1.1  christos 
    233  1.1.1.6  christos 	/* Prepare the packet. */
    234      1.1  christos 	int pkt_len = LEN_PKT_NOMAC;
    235      1.1  christos 
    236  1.1.1.7  christos 	testpkt.p.exten[0] = htonl(50);
    237  1.1.1.7  christos 	int mac_len = make_mac(&testpkt.p, pkt_len,
    238  1.1.1.8  christos 			       MAX_MD5_LEN - KEY_MAC_LEN, key_ptr,
    239  1.1.1.7  christos 			       &testpkt.p.exten[1]);
    240      1.1  christos 
    241      1.1  christos 	pkt_len += 4 + mac_len;
    242      1.1  christos 
    243  1.1.1.6  christos 	/* Now, alter the MAC so it becomes invalid. */
    244  1.1.1.7  christos 	testpkt.p.exten[1] += 1;
    245      1.1  christos 
    246      1.1  christos 	TEST_ASSERT_EQUAL(SERVER_AUTH_FAIL,
    247  1.1.1.7  christos 			  process_pkt(&testpkt.p, &testsock, pkt_len,
    248  1.1.1.7  christos 				      MODE_SERVER, &testspkt.p, "UnitTest"));
    249      1.1  christos }
    250      1.1  christos 
    251  1.1.1.3  christos 
    252  1.1.1.3  christos void
    253  1.1.1.6  christos test_AuthenticatedPacketUnknownKey(void)
    254  1.1.1.6  christos {
    255  1.1.1.6  christos 	/* Activate authentication option */
    256      1.1  christos 	PrepareAuthenticationTestMD5(30, 9, "123456789");
    257      1.1  christos 	TEST_ASSERT_TRUE(ENABLED_OPT(AUTHENTICATION));
    258      1.1  christos 
    259  1.1.1.6  christos 	/* Prepare the packet. Note that the Key-ID expected is 30, but
    260  1.1.1.6  christos 	 * the packet has a key id of 50.
    261  1.1.1.6  christos 	 */
    262      1.1  christos 	int pkt_len = LEN_PKT_NOMAC;
    263      1.1  christos 
    264  1.1.1.7  christos 	testpkt.p.exten[0] = htonl(50);
    265  1.1.1.7  christos 	int mac_len = make_mac(&testpkt.p, pkt_len,
    266  1.1.1.8  christos 			       MAX_MD5_LEN - KEY_MAC_LEN, key_ptr,
    267  1.1.1.7  christos 			       &testpkt.p.exten[1]);
    268  1.1.1.8  christos 	pkt_len += KEY_MAC_LEN + mac_len;
    269      1.1  christos 
    270      1.1  christos 	TEST_ASSERT_EQUAL(SERVER_AUTH_FAIL,
    271  1.1.1.7  christos 			  process_pkt(&testpkt.p, &testsock, pkt_len,
    272  1.1.1.7  christos 				      MODE_SERVER, &testspkt.p, "UnitTest"));
    273      1.1  christos }
    274      1.1  christos 
    275  1.1.1.3  christos 
    276  1.1.1.3  christos void
    277  1.1.1.6  christos test_ServerVersionTooOld(void)
    278  1.1.1.6  christos {
    279      1.1  christos 	TEST_ASSERT_FALSE(ENABLED_OPT(AUTHENTICATION));
    280      1.1  christos 
    281  1.1.1.7  christos 	testpkt.p.li_vn_mode = PKT_LI_VN_MODE(LEAP_NOWARNING,
    282  1.1.1.7  christos 					      NTP_OLDVERSION - 1,
    283  1.1.1.7  christos 					      MODE_CLIENT);
    284  1.1.1.7  christos 	TEST_ASSERT_TRUE(PKT_VERSION(testpkt.p.li_vn_mode) < NTP_OLDVERSION);
    285      1.1  christos 
    286      1.1  christos 	int pkt_len = LEN_PKT_NOMAC;
    287      1.1  christos 
    288      1.1  christos 	TEST_ASSERT_EQUAL(SERVER_UNUSEABLE,
    289  1.1.1.7  christos 			  process_pkt(&testpkt.p, &testsock, pkt_len,
    290  1.1.1.7  christos 				      MODE_SERVER, &testspkt.p, "UnitTest"));
    291      1.1  christos }
    292      1.1  christos 
    293  1.1.1.3  christos 
    294  1.1.1.3  christos void
    295  1.1.1.6  christos test_ServerVersionTooNew(void)
    296  1.1.1.6  christos {
    297      1.1  christos 	TEST_ASSERT_FALSE(ENABLED_OPT(AUTHENTICATION));
    298      1.1  christos 
    299  1.1.1.7  christos 	testpkt.p.li_vn_mode = PKT_LI_VN_MODE(LEAP_NOWARNING,
    300  1.1.1.7  christos 					      NTP_VERSION + 1,
    301  1.1.1.7  christos 					      MODE_CLIENT);
    302  1.1.1.7  christos 	TEST_ASSERT_TRUE(PKT_VERSION(testpkt.p.li_vn_mode) > NTP_VERSION);
    303      1.1  christos 
    304      1.1  christos 	int pkt_len = LEN_PKT_NOMAC;
    305      1.1  christos 
    306      1.1  christos 	TEST_ASSERT_EQUAL(SERVER_UNUSEABLE,
    307  1.1.1.7  christos 			  process_pkt(&testpkt.p, &testsock, pkt_len,
    308  1.1.1.7  christos 				      MODE_SERVER, &testspkt.p, "UnitTest"));
    309      1.1  christos }
    310      1.1  christos 
    311  1.1.1.3  christos 
    312  1.1.1.3  christos void
    313  1.1.1.6  christos test_NonWantedMode(void)
    314  1.1.1.6  christos {
    315      1.1  christos 	TEST_ASSERT_FALSE(ENABLED_OPT(AUTHENTICATION));
    316      1.1  christos 
    317  1.1.1.7  christos 	testpkt.p.li_vn_mode = PKT_LI_VN_MODE(LEAP_NOWARNING,
    318  1.1.1.7  christos 					      NTP_VERSION,
    319  1.1.1.7  christos 					      MODE_CLIENT);
    320      1.1  christos 
    321  1.1.1.6  christos 	/* The packet has a mode of MODE_CLIENT, but process_pkt expects
    322  1.1.1.6  christos 	 * MODE_SERVER
    323  1.1.1.6  christos 	 */
    324      1.1  christos 	TEST_ASSERT_EQUAL(SERVER_UNUSEABLE,
    325  1.1.1.7  christos 			  process_pkt(&testpkt.p, &testsock, LEN_PKT_NOMAC,
    326  1.1.1.7  christos 				      MODE_SERVER, &testspkt.p, "UnitTest"));
    327      1.1  christos }
    328      1.1  christos 
    329  1.1.1.3  christos 
    330      1.1  christos /* Tests bug 1597 */
    331  1.1.1.3  christos void
    332  1.1.1.6  christos test_KoDRate(void)
    333  1.1.1.6  christos {
    334      1.1  christos 	TEST_ASSERT_FALSE(ENABLED_OPT(AUTHENTICATION));
    335      1.1  christos 
    336  1.1.1.7  christos 	testpkt.p.stratum = STRATUM_PKT_UNSPEC;
    337  1.1.1.7  christos 	memcpy(&testpkt.p.refid, "RATE", 4);
    338      1.1  christos 
    339      1.1  christos 	TEST_ASSERT_EQUAL(KOD_RATE,
    340  1.1.1.7  christos 			  process_pkt(&testpkt.p, &testsock, LEN_PKT_NOMAC,
    341  1.1.1.7  christos 				      MODE_SERVER, &testspkt.p, "UnitTest"));
    342      1.1  christos }
    343      1.1  christos 
    344  1.1.1.3  christos 
    345  1.1.1.3  christos void
    346  1.1.1.6  christos test_KoDDeny(void)
    347  1.1.1.6  christos {
    348      1.1  christos 	TEST_ASSERT_FALSE(ENABLED_OPT(AUTHENTICATION));
    349      1.1  christos 
    350  1.1.1.7  christos 	testpkt.p.stratum = STRATUM_PKT_UNSPEC;
    351  1.1.1.7  christos 	memcpy(&testpkt.p.refid, "DENY", 4);
    352      1.1  christos 
    353      1.1  christos 	TEST_ASSERT_EQUAL(KOD_DEMOBILIZE,
    354  1.1.1.7  christos 			  process_pkt(&testpkt.p, &testsock, LEN_PKT_NOMAC,
    355  1.1.1.7  christos 				      MODE_SERVER, &testspkt.p, "UnitTest"));
    356      1.1  christos }
    357      1.1  christos 
    358  1.1.1.3  christos 
    359  1.1.1.3  christos void
    360  1.1.1.6  christos test_RejectUnsyncedServer(void)
    361  1.1.1.6  christos {
    362      1.1  christos 	TEST_ASSERT_FALSE(ENABLED_OPT(AUTHENTICATION));
    363      1.1  christos 
    364  1.1.1.7  christos 	testpkt.p.li_vn_mode = PKT_LI_VN_MODE(LEAP_NOTINSYNC,
    365  1.1.1.7  christos 					      NTP_VERSION,
    366  1.1.1.7  christos 					      MODE_SERVER);
    367      1.1  christos 
    368      1.1  christos 	TEST_ASSERT_EQUAL(SERVER_UNUSEABLE,
    369  1.1.1.7  christos 			  process_pkt(&testpkt.p, &testsock, LEN_PKT_NOMAC,
    370  1.1.1.7  christos 				      MODE_SERVER, &testspkt.p, "UnitTest"));
    371      1.1  christos }
    372      1.1  christos 
    373  1.1.1.3  christos 
    374  1.1.1.3  christos void
    375  1.1.1.6  christos test_RejectWrongResponseServerMode(void)
    376  1.1.1.6  christos {
    377      1.1  christos 	TEST_ASSERT_FALSE(ENABLED_OPT(AUTHENTICATION));
    378      1.1  christos 
    379      1.1  christos 	l_fp tmp;
    380      1.1  christos 	tmp.l_ui = 1000UL;
    381      1.1  christos 	tmp.l_uf = 0UL;
    382  1.1.1.7  christos 	HTONL_FP(&tmp, &testpkt.p.org);
    383      1.1  christos 
    384      1.1  christos 	tmp.l_ui = 2000UL;
    385      1.1  christos 	tmp.l_uf = 0UL;
    386  1.1.1.7  christos 	HTONL_FP(&tmp, &testspkt.p.xmt);
    387      1.1  christos 
    388      1.1  christos 	TEST_ASSERT_EQUAL(PACKET_UNUSEABLE,
    389  1.1.1.7  christos 			  process_pkt(&testpkt.p, &testsock, LEN_PKT_NOMAC,
    390  1.1.1.7  christos 				      MODE_SERVER, &testspkt.p, "UnitTest"));
    391      1.1  christos }
    392      1.1  christos 
    393  1.1.1.3  christos 
    394  1.1.1.3  christos void
    395  1.1.1.6  christos test_AcceptNoSentPacketBroadcastMode(void)
    396  1.1.1.6  christos {
    397      1.1  christos 	TEST_ASSERT_FALSE(ENABLED_OPT(AUTHENTICATION));
    398      1.1  christos 
    399  1.1.1.7  christos 	testpkt.p.li_vn_mode = PKT_LI_VN_MODE(LEAP_NOWARNING,
    400  1.1.1.7  christos 					      NTP_VERSION,
    401  1.1.1.7  christos 					      MODE_BROADCAST);
    402      1.1  christos 
    403      1.1  christos 	TEST_ASSERT_EQUAL(LEN_PKT_NOMAC,
    404  1.1.1.7  christos 		  process_pkt(&testpkt.p, &testsock, LEN_PKT_NOMAC,
    405      1.1  christos 			      MODE_BROADCAST, NULL, "UnitTest"));
    406      1.1  christos }
    407      1.1  christos 
    408  1.1.1.3  christos 
    409  1.1.1.3  christos void
    410  1.1.1.6  christos test_CorrectUnauthenticatedPacket(void)
    411  1.1.1.6  christos {
    412      1.1  christos 	TEST_ASSERT_FALSE(ENABLED_OPT(AUTHENTICATION));
    413      1.1  christos 
    414      1.1  christos 	TEST_ASSERT_EQUAL(LEN_PKT_NOMAC,
    415  1.1.1.7  christos 			  process_pkt(&testpkt.p, &testsock, LEN_PKT_NOMAC,
    416  1.1.1.7  christos 				      MODE_SERVER, &testspkt.p, "UnitTest"));
    417      1.1  christos }
    418      1.1  christos 
    419  1.1.1.3  christos 
    420  1.1.1.3  christos void
    421  1.1.1.6  christos test_CorrectAuthenticatedPacketMD5(void)
    422  1.1.1.6  christos {
    423      1.1  christos 	PrepareAuthenticationTestMD5(10, 15, "123456789abcdef");
    424      1.1  christos 	TEST_ASSERT_TRUE(ENABLED_OPT(AUTHENTICATION));
    425      1.1  christos 
    426      1.1  christos 	int pkt_len = LEN_PKT_NOMAC;
    427      1.1  christos 
    428  1.1.1.6  christos 	/* Prepare the packet. */
    429  1.1.1.7  christos 	testpkt.p.exten[0] = htonl(10);
    430  1.1.1.7  christos 	int mac_len = make_mac(&testpkt.p, pkt_len,
    431  1.1.1.8  christos 			       MAX_MD5_LEN - KEY_MAC_LEN, key_ptr,
    432  1.1.1.7  christos 			       &testpkt.p.exten[1]);
    433      1.1  christos 
    434  1.1.1.8  christos 	pkt_len += KEY_MAC_LEN + mac_len;
    435      1.1  christos 
    436      1.1  christos 	TEST_ASSERT_EQUAL(pkt_len,
    437  1.1.1.7  christos 			  process_pkt(&testpkt.p, &testsock, pkt_len,
    438  1.1.1.7  christos 				      MODE_SERVER, &testspkt.p, "UnitTest"));
    439      1.1  christos }
    440      1.1  christos 
    441  1.1.1.3  christos 
    442  1.1.1.3  christos void
    443  1.1.1.6  christos test_CorrectAuthenticatedPacketSHA1(void)
    444  1.1.1.6  christos {
    445      1.1  christos 	PrepareAuthenticationTest(20, 15, "SHA1", "abcdefghijklmno");
    446      1.1  christos 	TEST_ASSERT_TRUE(ENABLED_OPT(AUTHENTICATION));
    447      1.1  christos 
    448      1.1  christos 	int pkt_len = LEN_PKT_NOMAC;
    449      1.1  christos 
    450  1.1.1.6  christos 	/* Prepare the packet. */
    451  1.1.1.7  christos 	testpkt.p.exten[0] = htonl(20);
    452  1.1.1.7  christos 	int mac_len = make_mac(&testpkt.p, pkt_len,
    453  1.1.1.8  christos 			       MAX_MDG_LEN, key_ptr,
    454  1.1.1.8  christos 			       &testpkt.p.exten[1]);
    455  1.1.1.8  christos 
    456  1.1.1.8  christos 	pkt_len += KEY_MAC_LEN + mac_len;
    457  1.1.1.8  christos 
    458  1.1.1.8  christos 	TEST_ASSERT_EQUAL(pkt_len,
    459  1.1.1.8  christos 			  process_pkt(&testpkt.p, &testsock, pkt_len,
    460  1.1.1.8  christos 				      MODE_SERVER, &testspkt.p, "UnitTest"));
    461  1.1.1.8  christos }
    462  1.1.1.8  christos 
    463  1.1.1.8  christos 
    464  1.1.1.8  christos void
    465  1.1.1.8  christos test_CorrectAuthenticatedPacketCMAC(void)
    466  1.1.1.8  christos {
    467  1.1.1.9  christos #if defined(OPENSSL) && defined(ENABLE_CMAC)
    468  1.1.1.9  christos 
    469  1.1.1.8  christos 	PrepareAuthenticationTest(30, CMAC_LENGTH, CMAC, "abcdefghijklmnop");
    470  1.1.1.8  christos 	TEST_ASSERT_TRUE(ENABLED_OPT(AUTHENTICATION));
    471  1.1.1.8  christos 
    472  1.1.1.8  christos 	int pkt_len = LEN_PKT_NOMAC;
    473  1.1.1.8  christos 
    474  1.1.1.8  christos 	/* Prepare the packet. */
    475  1.1.1.8  christos 	testpkt.p.exten[0] = htonl(30);
    476  1.1.1.8  christos 	int mac_len = make_mac(&testpkt.p, pkt_len,
    477  1.1.1.6  christos 			       MAX_MAC_LEN, key_ptr,
    478  1.1.1.7  christos 			       &testpkt.p.exten[1]);
    479      1.1  christos 
    480      1.1  christos 	pkt_len += 4 + mac_len;
    481      1.1  christos 
    482      1.1  christos 	TEST_ASSERT_EQUAL(pkt_len,
    483  1.1.1.7  christos 			  process_pkt(&testpkt.p, &testsock, pkt_len,
    484  1.1.1.7  christos 				      MODE_SERVER, &testspkt.p, "UnitTest"));
    485  1.1.1.9  christos 
    486  1.1.1.9  christos #else
    487  1.1.1.9  christos 
    488  1.1.1.9  christos 	TEST_IGNORE_MESSAGE("OpenSSL CMAC not used, skipping...");
    489  1.1.1.9  christos 
    490  1.1.1.9  christos #endif	/* OPENSSL */
    491      1.1  christos }
    492  1.1.1.8  christos 
    493