1284990Scy#include "config.h" 2294569Sdelphij 3284990Scy#include "sntptest.h" 4284990Scy#include "networking.h" 5284990Scy#include "ntp_stdlib.h" 6284990Scy#include "unity.h" 7284990Scy 8330141Sdelphij#define CMAC "AES128CMAC" 9330141Sdelphij#define CMAC_LENGTH 16 10289997Sglebius 11330141Sdelphij 12284990Scyconst char * Version = "stub unit test Version string"; 13284990Scy 14309008Sdelphij/* Hacks into the key database. */ 15284990Scyextern struct key* key_ptr; 16284990Scyextern int key_cnt; 17284990Scy 18284990Scy 19289997Sglebiusvoid PrepareAuthenticationTest(int key_id,int key_len,const char* type,const void* key_seq); 20289997Sglebiusvoid PrepareAuthenticationTestMD5(int key_id,int key_len,const void* key_seq); 21289997Sglebiusvoid setUp(void); 22289997Sglebiusvoid tearDown(void); 23289997Sglebiusvoid test_TooShortLength(void); 24289997Sglebiusvoid test_LengthNotMultipleOfFour(void); 25289997Sglebiusvoid test_TooShortExtensionFieldLength(void); 26289997Sglebiusvoid test_UnauthenticatedPacketReject(void); 27289997Sglebiusvoid test_CryptoNAKPacketReject(void); 28289997Sglebiusvoid test_AuthenticatedPacketInvalid(void); 29289997Sglebiusvoid test_AuthenticatedPacketUnknownKey(void); 30289997Sglebiusvoid test_ServerVersionTooOld(void); 31289997Sglebiusvoid test_ServerVersionTooNew(void); 32289997Sglebiusvoid test_NonWantedMode(void); 33289997Sglebiusvoid test_KoDRate(void); 34289997Sglebiusvoid test_KoDDeny(void); 35289997Sglebiusvoid test_RejectUnsyncedServer(void); 36289997Sglebiusvoid test_RejectWrongResponseServerMode(void); 37289997Sglebiusvoid test_AcceptNoSentPacketBroadcastMode(void); 38289997Sglebiusvoid test_CorrectUnauthenticatedPacket(void); 39289997Sglebiusvoid test_CorrectAuthenticatedPacketMD5(void); 40289997Sglebiusvoid test_CorrectAuthenticatedPacketSHA1(void); 41330141Sdelphijvoid test_CorrectAuthenticatedPacketCMAC(void); 42289997Sglebius 43309008Sdelphij/* [Bug 2998] There are some issues whith the definition of 'struct pkt' 44309008Sdelphij * when AUTOKEY is undefined -- the formal struct is too small to hold 45309008Sdelphij * all the extension fields that are going to be tested. We have to make 46309008Sdelphij * sure we have the extra bytes, or the test yield undefined results due 47309008Sdelphij * to buffer overrun. 48309008Sdelphij */ 49309008Sdelphij#ifndef AUTOKEY 50309008Sdelphij# define EXTRA_BUFSIZE 256 51309008Sdelphij#else 52309008Sdelphij# define EXTRA_BUFSIZE 0 53309008Sdelphij#endif 54289997Sglebius 55309008Sdelphijunion tpkt { 56309008Sdelphij struct pkt p; 57309008Sdelphij u_char b[sizeof(struct pkt) + EXTRA_BUFSIZE]; 58309008Sdelphij}; 59309008Sdelphij 60309008Sdelphijstatic union tpkt testpkt; 61309008Sdelphijstatic union tpkt testspkt; 62284990Scystatic sockaddr_u testsock; 63284990Scybool restoreKeyDb; 64284990Scy 65289997Sglebius 66289997Sglebiusvoid 67294569SdelphijPrepareAuthenticationTest( 68294569Sdelphij int key_id, 69294569Sdelphij int key_len, 70294569Sdelphij const char * type, 71294569Sdelphij const void * key_seq 72294569Sdelphij ) 73294569Sdelphij{ 74284990Scy char str[25]; 75289997Sglebius snprintf(str, 25, "%d", key_id); 76284990Scy ActivateOption("-a", str); 77284990Scy 78284990Scy key_cnt = 1; 79289997Sglebius key_ptr = emalloc(sizeof(struct key)); 80284990Scy key_ptr->next = NULL; 81284990Scy key_ptr->key_id = key_id; 82284990Scy key_ptr->key_len = key_len; 83330141Sdelphij memcpy(key_ptr->typen, type, strlen(type) + 1); 84284990Scy 85284990Scy TEST_ASSERT_TRUE(key_len < sizeof(key_ptr->key_seq)); 86284990Scy 87284990Scy memcpy(key_ptr->key_seq, key_seq, key_ptr->key_len); 88284990Scy restoreKeyDb = true; 89284990Scy} 90284990Scy 91289997Sglebius 92289997Sglebiusvoid 93294569SdelphijPrepareAuthenticationTestMD5( 94294569Sdelphij int key_id, 95294569Sdelphij int key_len, 96294569Sdelphij const void * key_seq 97294569Sdelphij ) 98294569Sdelphij{ 99284990Scy PrepareAuthenticationTest(key_id, key_len, "MD5", key_seq); 100284990Scy} 101284990Scy 102284990Scy 103289997Sglebiusvoid 104294569SdelphijsetUp(void) 105294569Sdelphij{ 106289997Sglebius 107284990Scy sntptest(); 108284990Scy restoreKeyDb = false; 109284990Scy 110284990Scy /* Initialize the test packet and socket, 111294569Sdelphij * so they contain at least some valid data. 112294569Sdelphij */ 113309008Sdelphij testpkt.p.li_vn_mode = PKT_LI_VN_MODE(LEAP_NOWARNING, NTP_VERSION, 114284990Scy MODE_SERVER); 115309008Sdelphij testpkt.p.stratum = STRATUM_REFCLOCK; 116309008Sdelphij memcpy(&testpkt.p.refid, "GPS\0", 4); 117284990Scy 118284990Scy /* Set the origin timestamp of the received packet to the 119294569Sdelphij * same value as the transmit timestamp of the sent packet. 120294569Sdelphij */ 121284990Scy l_fp tmp; 122284990Scy tmp.l_ui = 1000UL; 123284990Scy tmp.l_uf = 0UL; 124284990Scy 125309008Sdelphij HTONL_FP(&tmp, &testpkt.p.org); 126309008Sdelphij HTONL_FP(&tmp, &testspkt.p.xmt); 127284990Scy} 128284990Scy 129289997Sglebius 130289997Sglebiusvoid 131294569SdelphijtearDown(void) 132294569Sdelphij{ 133284990Scy if (restoreKeyDb) { 134284990Scy key_cnt = 0; 135284990Scy free(key_ptr); 136284990Scy key_ptr = NULL; 137284990Scy } 138284990Scy 139294569Sdelphij sntptest_destroy(); /* only on the final test!! if counter == 0 etc... */ 140284990Scy} 141284990Scy 142284990Scy 143289997Sglebiusvoid 144294569Sdelphijtest_TooShortLength(void) 145294569Sdelphij{ 146284990Scy TEST_ASSERT_EQUAL(PACKET_UNUSEABLE, 147309008Sdelphij process_pkt(&testpkt.p, &testsock, LEN_PKT_NOMAC - 1, 148309008Sdelphij MODE_SERVER, &testspkt.p, "UnitTest")); 149284990Scy TEST_ASSERT_EQUAL(PACKET_UNUSEABLE, 150309008Sdelphij process_pkt(&testpkt.p, &testsock, LEN_PKT_NOMAC - 1, 151309008Sdelphij MODE_BROADCAST, &testspkt.p, "UnitTest")); 152284990Scy} 153284990Scy 154289997Sglebius 155289997Sglebiusvoid 156294569Sdelphijtest_LengthNotMultipleOfFour(void) 157294569Sdelphij{ 158284990Scy TEST_ASSERT_EQUAL(PACKET_UNUSEABLE, 159309008Sdelphij process_pkt(&testpkt.p, &testsock, LEN_PKT_NOMAC + 6, 160309008Sdelphij MODE_SERVER, &testspkt.p, "UnitTest")); 161284990Scy TEST_ASSERT_EQUAL(PACKET_UNUSEABLE, 162309008Sdelphij process_pkt(&testpkt.p, &testsock, LEN_PKT_NOMAC + 3, 163309008Sdelphij MODE_BROADCAST, &testspkt.p, "UnitTest")); 164284990Scy} 165284990Scy 166289997Sglebius 167289997Sglebiusvoid 168294569Sdelphijtest_TooShortExtensionFieldLength(void) 169294569Sdelphij{ 170309008Sdelphij /* [Bug 2998] We have to get around the formal specification of 171309008Sdelphij * the extension field if AUTOKEY is undefined. (At least CLANG 172309008Sdelphij * issues a warning in this case. It's just a warning, but 173309008Sdelphij * still... 174309008Sdelphij */ 175309008Sdelphij uint32_t * pe = testpkt.p.exten + 7; 176309008Sdelphij 177284990Scy /* The lower 16-bits are the length of the extension field. 178284990Scy * This lengths must be multiples of 4 bytes, which gives 179294569Sdelphij * a minimum of 4 byte extension field length. 180294569Sdelphij */ 181309008Sdelphij *pe = htonl(3); /* 3 bytes is too short. */ 182284990Scy 183284990Scy /* We send in a pkt_len of header size + 4 byte extension 184284990Scy * header + 24 byte MAC, this prevents the length error to 185294569Sdelphij * be caught at an earlier stage 186294569Sdelphij */ 187284990Scy int pkt_len = LEN_PKT_NOMAC + 4 + 24; 188284990Scy 189284990Scy TEST_ASSERT_EQUAL(PACKET_UNUSEABLE, 190309008Sdelphij process_pkt(&testpkt.p, &testsock, pkt_len, 191309008Sdelphij MODE_SERVER, &testspkt.p, "UnitTest")); 192284990Scy} 193284990Scy 194289997Sglebius 195289997Sglebiusvoid 196294569Sdelphijtest_UnauthenticatedPacketReject(void) 197294569Sdelphij{ 198294569Sdelphij /* Activate authentication option */ 199284990Scy ActivateOption("-a", "123"); 200284990Scy TEST_ASSERT_TRUE(ENABLED_OPT(AUTHENTICATION)); 201284990Scy 202284990Scy int pkt_len = LEN_PKT_NOMAC; 203284990Scy 204294569Sdelphij /* We demand authentication, but no MAC header is present. */ 205284990Scy TEST_ASSERT_EQUAL(SERVER_AUTH_FAIL, 206309008Sdelphij process_pkt(&testpkt.p, &testsock, pkt_len, 207309008Sdelphij MODE_SERVER, &testspkt.p, "UnitTest")); 208284990Scy} 209284990Scy 210289997Sglebius 211289997Sglebiusvoid 212294569Sdelphijtest_CryptoNAKPacketReject(void) 213294569Sdelphij{ 214294569Sdelphij /* Activate authentication option */ 215284990Scy ActivateOption("-a", "123"); 216284990Scy TEST_ASSERT_TRUE(ENABLED_OPT(AUTHENTICATION)); 217284990Scy 218294569Sdelphij int pkt_len = LEN_PKT_NOMAC + 4; /* + 4 byte MAC = Crypto-NAK */ 219284990Scy 220284990Scy TEST_ASSERT_EQUAL(SERVER_AUTH_FAIL, 221309008Sdelphij process_pkt(&testpkt.p, &testsock, pkt_len, 222309008Sdelphij MODE_SERVER, &testspkt.p, "UnitTest")); 223284990Scy} 224284990Scy 225289997Sglebius 226289997Sglebiusvoid 227294569Sdelphijtest_AuthenticatedPacketInvalid(void) 228294569Sdelphij{ 229294569Sdelphij /* Activate authentication option */ 230284990Scy PrepareAuthenticationTestMD5(50, 9, "123456789"); 231284990Scy TEST_ASSERT_TRUE(ENABLED_OPT(AUTHENTICATION)); 232284990Scy 233294569Sdelphij /* Prepare the packet. */ 234284990Scy int pkt_len = LEN_PKT_NOMAC; 235284990Scy 236309008Sdelphij testpkt.p.exten[0] = htonl(50); 237309008Sdelphij int mac_len = make_mac(&testpkt.p, pkt_len, 238330141Sdelphij MAX_MD5_LEN - KEY_MAC_LEN, key_ptr, 239309008Sdelphij &testpkt.p.exten[1]); 240284990Scy 241284990Scy pkt_len += 4 + mac_len; 242284990Scy 243294569Sdelphij /* Now, alter the MAC so it becomes invalid. */ 244309008Sdelphij testpkt.p.exten[1] += 1; 245284990Scy 246284990Scy TEST_ASSERT_EQUAL(SERVER_AUTH_FAIL, 247309008Sdelphij process_pkt(&testpkt.p, &testsock, pkt_len, 248309008Sdelphij MODE_SERVER, &testspkt.p, "UnitTest")); 249284990Scy} 250284990Scy 251289997Sglebius 252289997Sglebiusvoid 253294569Sdelphijtest_AuthenticatedPacketUnknownKey(void) 254294569Sdelphij{ 255294569Sdelphij /* Activate authentication option */ 256284990Scy PrepareAuthenticationTestMD5(30, 9, "123456789"); 257284990Scy TEST_ASSERT_TRUE(ENABLED_OPT(AUTHENTICATION)); 258284990Scy 259294569Sdelphij /* Prepare the packet. Note that the Key-ID expected is 30, but 260294569Sdelphij * the packet has a key id of 50. 261294569Sdelphij */ 262284990Scy int pkt_len = LEN_PKT_NOMAC; 263284990Scy 264309008Sdelphij testpkt.p.exten[0] = htonl(50); 265309008Sdelphij int mac_len = make_mac(&testpkt.p, pkt_len, 266330141Sdelphij MAX_MD5_LEN - KEY_MAC_LEN, key_ptr, 267309008Sdelphij &testpkt.p.exten[1]); 268330141Sdelphij pkt_len += KEY_MAC_LEN + mac_len; 269284990Scy 270284990Scy TEST_ASSERT_EQUAL(SERVER_AUTH_FAIL, 271309008Sdelphij process_pkt(&testpkt.p, &testsock, pkt_len, 272309008Sdelphij MODE_SERVER, &testspkt.p, "UnitTest")); 273284990Scy} 274284990Scy 275289997Sglebius 276289997Sglebiusvoid 277294569Sdelphijtest_ServerVersionTooOld(void) 278294569Sdelphij{ 279284990Scy TEST_ASSERT_FALSE(ENABLED_OPT(AUTHENTICATION)); 280284990Scy 281309008Sdelphij testpkt.p.li_vn_mode = PKT_LI_VN_MODE(LEAP_NOWARNING, 282309008Sdelphij NTP_OLDVERSION - 1, 283309008Sdelphij MODE_CLIENT); 284309008Sdelphij TEST_ASSERT_TRUE(PKT_VERSION(testpkt.p.li_vn_mode) < NTP_OLDVERSION); 285284990Scy 286284990Scy int pkt_len = LEN_PKT_NOMAC; 287284990Scy 288284990Scy TEST_ASSERT_EQUAL(SERVER_UNUSEABLE, 289309008Sdelphij process_pkt(&testpkt.p, &testsock, pkt_len, 290309008Sdelphij MODE_SERVER, &testspkt.p, "UnitTest")); 291284990Scy} 292284990Scy 293289997Sglebius 294289997Sglebiusvoid 295294569Sdelphijtest_ServerVersionTooNew(void) 296294569Sdelphij{ 297284990Scy TEST_ASSERT_FALSE(ENABLED_OPT(AUTHENTICATION)); 298284990Scy 299309008Sdelphij testpkt.p.li_vn_mode = PKT_LI_VN_MODE(LEAP_NOWARNING, 300309008Sdelphij NTP_VERSION + 1, 301309008Sdelphij MODE_CLIENT); 302309008Sdelphij TEST_ASSERT_TRUE(PKT_VERSION(testpkt.p.li_vn_mode) > NTP_VERSION); 303284990Scy 304284990Scy int pkt_len = LEN_PKT_NOMAC; 305284990Scy 306284990Scy TEST_ASSERT_EQUAL(SERVER_UNUSEABLE, 307309008Sdelphij process_pkt(&testpkt.p, &testsock, pkt_len, 308309008Sdelphij MODE_SERVER, &testspkt.p, "UnitTest")); 309284990Scy} 310284990Scy 311289997Sglebius 312289997Sglebiusvoid 313294569Sdelphijtest_NonWantedMode(void) 314294569Sdelphij{ 315284990Scy TEST_ASSERT_FALSE(ENABLED_OPT(AUTHENTICATION)); 316284990Scy 317309008Sdelphij testpkt.p.li_vn_mode = PKT_LI_VN_MODE(LEAP_NOWARNING, 318309008Sdelphij NTP_VERSION, 319309008Sdelphij MODE_CLIENT); 320284990Scy 321294569Sdelphij /* The packet has a mode of MODE_CLIENT, but process_pkt expects 322294569Sdelphij * MODE_SERVER 323294569Sdelphij */ 324284990Scy TEST_ASSERT_EQUAL(SERVER_UNUSEABLE, 325309008Sdelphij process_pkt(&testpkt.p, &testsock, LEN_PKT_NOMAC, 326309008Sdelphij MODE_SERVER, &testspkt.p, "UnitTest")); 327284990Scy} 328284990Scy 329289997Sglebius 330284990Scy/* Tests bug 1597 */ 331289997Sglebiusvoid 332294569Sdelphijtest_KoDRate(void) 333294569Sdelphij{ 334284990Scy TEST_ASSERT_FALSE(ENABLED_OPT(AUTHENTICATION)); 335284990Scy 336309008Sdelphij testpkt.p.stratum = STRATUM_PKT_UNSPEC; 337309008Sdelphij memcpy(&testpkt.p.refid, "RATE", 4); 338284990Scy 339284990Scy TEST_ASSERT_EQUAL(KOD_RATE, 340309008Sdelphij process_pkt(&testpkt.p, &testsock, LEN_PKT_NOMAC, 341309008Sdelphij MODE_SERVER, &testspkt.p, "UnitTest")); 342284990Scy} 343284990Scy 344289997Sglebius 345289997Sglebiusvoid 346294569Sdelphijtest_KoDDeny(void) 347294569Sdelphij{ 348284990Scy TEST_ASSERT_FALSE(ENABLED_OPT(AUTHENTICATION)); 349284990Scy 350309008Sdelphij testpkt.p.stratum = STRATUM_PKT_UNSPEC; 351309008Sdelphij memcpy(&testpkt.p.refid, "DENY", 4); 352284990Scy 353284990Scy TEST_ASSERT_EQUAL(KOD_DEMOBILIZE, 354309008Sdelphij process_pkt(&testpkt.p, &testsock, LEN_PKT_NOMAC, 355309008Sdelphij MODE_SERVER, &testspkt.p, "UnitTest")); 356284990Scy} 357284990Scy 358289997Sglebius 359289997Sglebiusvoid 360294569Sdelphijtest_RejectUnsyncedServer(void) 361294569Sdelphij{ 362284990Scy TEST_ASSERT_FALSE(ENABLED_OPT(AUTHENTICATION)); 363284990Scy 364309008Sdelphij testpkt.p.li_vn_mode = PKT_LI_VN_MODE(LEAP_NOTINSYNC, 365309008Sdelphij NTP_VERSION, 366309008Sdelphij MODE_SERVER); 367284990Scy 368284990Scy TEST_ASSERT_EQUAL(SERVER_UNUSEABLE, 369309008Sdelphij process_pkt(&testpkt.p, &testsock, LEN_PKT_NOMAC, 370309008Sdelphij MODE_SERVER, &testspkt.p, "UnitTest")); 371284990Scy} 372284990Scy 373289997Sglebius 374289997Sglebiusvoid 375294569Sdelphijtest_RejectWrongResponseServerMode(void) 376294569Sdelphij{ 377284990Scy TEST_ASSERT_FALSE(ENABLED_OPT(AUTHENTICATION)); 378284990Scy 379284990Scy l_fp tmp; 380284990Scy tmp.l_ui = 1000UL; 381284990Scy tmp.l_uf = 0UL; 382309008Sdelphij HTONL_FP(&tmp, &testpkt.p.org); 383284990Scy 384284990Scy tmp.l_ui = 2000UL; 385284990Scy tmp.l_uf = 0UL; 386309008Sdelphij HTONL_FP(&tmp, &testspkt.p.xmt); 387284990Scy 388284990Scy TEST_ASSERT_EQUAL(PACKET_UNUSEABLE, 389309008Sdelphij process_pkt(&testpkt.p, &testsock, LEN_PKT_NOMAC, 390309008Sdelphij MODE_SERVER, &testspkt.p, "UnitTest")); 391284990Scy} 392284990Scy 393289997Sglebius 394289997Sglebiusvoid 395294569Sdelphijtest_AcceptNoSentPacketBroadcastMode(void) 396294569Sdelphij{ 397284990Scy TEST_ASSERT_FALSE(ENABLED_OPT(AUTHENTICATION)); 398284990Scy 399309008Sdelphij testpkt.p.li_vn_mode = PKT_LI_VN_MODE(LEAP_NOWARNING, 400309008Sdelphij NTP_VERSION, 401309008Sdelphij MODE_BROADCAST); 402284990Scy 403284990Scy TEST_ASSERT_EQUAL(LEN_PKT_NOMAC, 404309008Sdelphij process_pkt(&testpkt.p, &testsock, LEN_PKT_NOMAC, 405284990Scy MODE_BROADCAST, NULL, "UnitTest")); 406284990Scy} 407284990Scy 408289997Sglebius 409289997Sglebiusvoid 410294569Sdelphijtest_CorrectUnauthenticatedPacket(void) 411294569Sdelphij{ 412284990Scy TEST_ASSERT_FALSE(ENABLED_OPT(AUTHENTICATION)); 413284990Scy 414284990Scy TEST_ASSERT_EQUAL(LEN_PKT_NOMAC, 415309008Sdelphij process_pkt(&testpkt.p, &testsock, LEN_PKT_NOMAC, 416309008Sdelphij MODE_SERVER, &testspkt.p, "UnitTest")); 417284990Scy} 418284990Scy 419289997Sglebius 420289997Sglebiusvoid 421294569Sdelphijtest_CorrectAuthenticatedPacketMD5(void) 422294569Sdelphij{ 423284990Scy PrepareAuthenticationTestMD5(10, 15, "123456789abcdef"); 424284990Scy TEST_ASSERT_TRUE(ENABLED_OPT(AUTHENTICATION)); 425284990Scy 426284990Scy int pkt_len = LEN_PKT_NOMAC; 427284990Scy 428294569Sdelphij /* Prepare the packet. */ 429309008Sdelphij testpkt.p.exten[0] = htonl(10); 430309008Sdelphij int mac_len = make_mac(&testpkt.p, pkt_len, 431330141Sdelphij MAX_MD5_LEN - KEY_MAC_LEN, key_ptr, 432309008Sdelphij &testpkt.p.exten[1]); 433284990Scy 434330141Sdelphij pkt_len += KEY_MAC_LEN + mac_len; 435284990Scy 436284990Scy TEST_ASSERT_EQUAL(pkt_len, 437309008Sdelphij process_pkt(&testpkt.p, &testsock, pkt_len, 438309008Sdelphij MODE_SERVER, &testspkt.p, "UnitTest")); 439284990Scy} 440284990Scy 441289997Sglebius 442289997Sglebiusvoid 443294569Sdelphijtest_CorrectAuthenticatedPacketSHA1(void) 444294569Sdelphij{ 445284990Scy PrepareAuthenticationTest(20, 15, "SHA1", "abcdefghijklmno"); 446284990Scy TEST_ASSERT_TRUE(ENABLED_OPT(AUTHENTICATION)); 447284990Scy 448284990Scy int pkt_len = LEN_PKT_NOMAC; 449284990Scy 450294569Sdelphij /* Prepare the packet. */ 451309008Sdelphij testpkt.p.exten[0] = htonl(20); 452309008Sdelphij int mac_len = make_mac(&testpkt.p, pkt_len, 453330141Sdelphij MAX_MDG_LEN, key_ptr, 454330141Sdelphij &testpkt.p.exten[1]); 455330141Sdelphij 456330141Sdelphij pkt_len += KEY_MAC_LEN + mac_len; 457330141Sdelphij 458330141Sdelphij TEST_ASSERT_EQUAL(pkt_len, 459330141Sdelphij process_pkt(&testpkt.p, &testsock, pkt_len, 460330141Sdelphij MODE_SERVER, &testspkt.p, "UnitTest")); 461330141Sdelphij} 462330141Sdelphij 463330141Sdelphij 464330141Sdelphijvoid 465330141Sdelphijtest_CorrectAuthenticatedPacketCMAC(void) 466330141Sdelphij{ 467338531Sdelphij#if defined(OPENSSL) && defined(ENABLE_CMAC) 468338531Sdelphij 469330141Sdelphij PrepareAuthenticationTest(30, CMAC_LENGTH, CMAC, "abcdefghijklmnop"); 470330141Sdelphij TEST_ASSERT_TRUE(ENABLED_OPT(AUTHENTICATION)); 471330141Sdelphij 472330141Sdelphij int pkt_len = LEN_PKT_NOMAC; 473330141Sdelphij 474330141Sdelphij /* Prepare the packet. */ 475330141Sdelphij testpkt.p.exten[0] = htonl(30); 476330141Sdelphij int mac_len = make_mac(&testpkt.p, pkt_len, 477294569Sdelphij MAX_MAC_LEN, key_ptr, 478309008Sdelphij &testpkt.p.exten[1]); 479284990Scy 480284990Scy pkt_len += 4 + mac_len; 481284990Scy 482284990Scy TEST_ASSERT_EQUAL(pkt_len, 483309008Sdelphij process_pkt(&testpkt.p, &testsock, pkt_len, 484309008Sdelphij MODE_SERVER, &testspkt.p, "UnitTest")); 485338531Sdelphij 486338531Sdelphij#else 487338531Sdelphij 488338531Sdelphij TEST_IGNORE_MESSAGE("OpenSSL CMAC not used, skipping..."); 489338531Sdelphij 490338531Sdelphij#endif /* OPENSSL */ 491284990Scy} 492330141Sdelphij 493