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