@@ -139,6 +139,27 @@ const uint8_t client_ack_none_random_id[] = { 0x28, 0xae, 0xb9, 0xaf, 0xe1, 0xf0
139
139
0xc8 , 0x01 , 0x00 , 0x00 , 0x00 , 0x00 , 0xdd , 0x85 ,
140
140
0xdb , 0x53 , 0x56 , 0x23 , 0xb0 , 0x2e };
141
141
142
+ /* no tls-auth, P_ACK_V1, acks 0,1, and 2 */
143
+ const uint8_t client_ack_123_none_random_id [] = {
144
+ 0x28 ,
145
+ 0xae , 0xb9 , 0xaf , 0xe1 , 0xf0 , 0x1d , 0x79 , 0xc8 ,
146
+ 0x03 ,
147
+ 0x00 , 0x00 , 0x00 , 0x00 ,
148
+ 0x00 , 0x00 , 0x00 , 0x01 ,
149
+ 0x00 , 0x00 , 0x00 , 0x02 ,
150
+ 0xdd , 0x85 , 0xdb , 0x53 , 0x56 , 0x23 , 0xb0 , 0x2e
151
+ };
152
+
153
+ /* no tls-auth, P_CONTROL_V1, acks 0, msg-id 2 */
154
+ const uint8_t client_control_none_random_id [] = {
155
+ 0x20 ,
156
+ 0xae , 0xb9 , 0xaf , 0xe1 , 0xf0 , 0x1d , 0x79 , 0xc8 ,
157
+ 0x01 ,
158
+ 0x00 , 0x00 , 0x00 , 0x00 ,
159
+ 0x02
160
+ };
161
+
162
+
142
163
struct tls_auth_standalone
143
164
init_tas_auth (int key_direction )
144
165
{
@@ -256,12 +277,10 @@ test_tls_decrypt_lite_auth(void **ut_state)
256
277
assert_int_equal (verdict , VERDICT_VALID_RESET_V2 );
257
278
free_tls_pre_decrypt_state (& state );
258
279
259
- free_tls_pre_decrypt_state (& state );
260
280
/* The pre decrypt function should not modify the buffer, so calling it
261
281
* again should have the same result */
262
282
verdict = tls_pre_decrypt_lite (& tas , & state , & from , & buf );
263
283
assert_int_equal (verdict , VERDICT_VALID_RESET_V2 );
264
- free_tls_pre_decrypt_state (& state );
265
284
266
285
/* and buf memory should be equal */
267
286
assert_memory_equal (BPTR (& buf ), client_reset_v2_tls_auth , sizeof (client_reset_v2_tls_auth ));
@@ -279,7 +298,6 @@ test_tls_decrypt_lite_auth(void **ut_state)
279
298
assert_int_equal (verdict , VERDICT_INVALID );
280
299
free_tls_pre_decrypt_state (& state );
281
300
282
- free_tls_pre_decrypt_state (& state );
283
301
/* Wrong key direction gives a wrong hmac key and should not validate */
284
302
free_key_ctx_bi (& tas .tls_wrap .opt .key_ctx_bi );
285
303
free_tas (& tas );
@@ -319,15 +337,12 @@ test_tls_decrypt_lite_none(void **ut_state)
319
337
assert_int_equal (verdict , VERDICT_VALID_RESET_V2 );
320
338
free_tls_pre_decrypt_state (& state );
321
339
322
- free_tls_pre_decrypt_state (& state );
323
340
buf_reset_len (& buf );
324
341
buf_write (& buf , client_reset_v2_tls_crypt , sizeof (client_reset_v2_none ));
325
342
verdict = tls_pre_decrypt_lite (& tas , & state , & from , & buf );
326
343
assert_int_equal (verdict , VERDICT_VALID_RESET_V2 );
327
344
free_tls_pre_decrypt_state (& state );
328
345
329
- free_tls_pre_decrypt_state (& state );
330
-
331
346
/* This is not a reset packet and should trigger the other response */
332
347
buf_reset_len (& buf );
333
348
buf_write (& buf , client_ack_tls_auth_randomid , sizeof (client_ack_tls_auth_randomid ));
@@ -405,7 +420,7 @@ test_verify_hmac_tls_auth(void **ut_state)
405
420
assert_int_equal (verdict , VERDICT_VALID_CONTROL_V1 );
406
421
407
422
/* This is a valid packet but containing a random id instead of an HMAC id*/
408
- bool valid = check_session_id_hmac (& state , & from .dest , hmac , 30 );
423
+ bool valid = check_session_hmac_and_pkt_id (& state , & from .dest , hmac , 30 , false );
409
424
assert_false (valid );
410
425
411
426
free_tls_pre_decrypt_state (& state );
@@ -436,7 +451,7 @@ test_verify_hmac_none(void **ut_state)
436
451
verdict = tls_pre_decrypt_lite (& tas , & state , & from , & buf );
437
452
assert_int_equal (verdict , VERDICT_VALID_ACK_V1 );
438
453
439
- bool valid = check_session_id_hmac (& state , & from .dest , hmac , 30 );
454
+ bool valid = check_session_hmac_and_pkt_id (& state , & from .dest , hmac , 30 , true );
440
455
assert_true (valid );
441
456
442
457
free_tls_pre_decrypt_state (& state );
@@ -445,6 +460,51 @@ test_verify_hmac_none(void **ut_state)
445
460
hmac_ctx_free (hmac );
446
461
}
447
462
463
+ static void
464
+ test_verify_hmac_none_out_of_range_ack (void * * ut_state )
465
+ {
466
+ hmac_ctx_t * hmac = session_id_hmac_init ();
467
+
468
+ struct link_socket_actual from = { 0 };
469
+ from .dest .addr .sa .sa_family = AF_INET ;
470
+
471
+ struct tls_auth_standalone tas = { 0 };
472
+ struct tls_pre_decrypt_state state = { 0 };
473
+
474
+ struct buffer buf = alloc_buf (1024 );
475
+ enum first_packet_verdict verdict ;
476
+
477
+ tas .tls_wrap .mode = TLS_WRAP_NONE ;
478
+
479
+ buf_reset_len (& buf );
480
+ buf_write (& buf , client_ack_123_none_random_id , sizeof (client_ack_123_none_random_id ));
481
+
482
+
483
+ verdict = tls_pre_decrypt_lite (& tas , & state , & from , & buf );
484
+ assert_int_equal (verdict , VERDICT_VALID_ACK_V1 );
485
+
486
+ /* should fail because it acks 2 */
487
+ bool valid = check_session_hmac_and_pkt_id (& state , & from .dest , hmac , 30 , true);
488
+ assert_false (valid );
489
+ free_tls_pre_decrypt_state (& state );
490
+
491
+ /* Try test with the control with a too high message id now */
492
+ buf_reset_len (& buf );
493
+ buf_write (& buf , client_control_none_random_id , sizeof (client_control_none_random_id ));
494
+
495
+ verdict = tls_pre_decrypt_lite (& tas , & state , & from , & buf );
496
+ assert_int_equal (verdict , VERDICT_VALID_CONTROL_V1 );
497
+
498
+ /* should fail because it has message id 2 */
499
+ valid = check_session_hmac_and_pkt_id (& state , & from .dest , hmac , 30 , true);
500
+ assert_false (valid );
501
+
502
+ free_tls_pre_decrypt_state (& state );
503
+ free_buf (& buf );
504
+ hmac_ctx_cleanup (hmac );
505
+ hmac_ctx_free (hmac );
506
+ }
507
+
448
508
static hmac_ctx_t *
449
509
init_static_hmac (void )
450
510
{
@@ -634,16 +694,20 @@ int
634
694
main (void )
635
695
{
636
696
openvpn_unit_test_setup ();
637
- const struct CMUnitTest tests [] = { cmocka_unit_test (test_tls_decrypt_lite_none ),
638
- cmocka_unit_test (test_tls_decrypt_lite_auth ),
639
- cmocka_unit_test (test_tls_decrypt_lite_crypt ),
640
- cmocka_unit_test (test_parse_ack ),
641
- cmocka_unit_test (test_calc_session_id_hmac_static ),
642
- cmocka_unit_test (test_verify_hmac_none ),
643
- cmocka_unit_test (test_verify_hmac_tls_auth ),
644
- cmocka_unit_test (test_generate_reset_packet_plain ),
645
- cmocka_unit_test (test_generate_reset_packet_tls_auth ),
646
- cmocka_unit_test (test_extract_control_message ) };
697
+
698
+ const struct CMUnitTest tests [] = {
699
+ cmocka_unit_test (test_tls_decrypt_lite_none ),
700
+ cmocka_unit_test (test_tls_decrypt_lite_auth ),
701
+ cmocka_unit_test (test_tls_decrypt_lite_crypt ),
702
+ cmocka_unit_test (test_parse_ack ),
703
+ cmocka_unit_test (test_calc_session_id_hmac_static ),
704
+ cmocka_unit_test (test_verify_hmac_none ),
705
+ cmocka_unit_test (test_verify_hmac_tls_auth ),
706
+ cmocka_unit_test (test_verify_hmac_none_out_of_range_ack ),
707
+ cmocka_unit_test (test_generate_reset_packet_plain ),
708
+ cmocka_unit_test (test_generate_reset_packet_tls_auth ),
709
+ cmocka_unit_test (test_extract_control_message )
710
+ };
647
711
648
712
#if defined(ENABLE_CRYPTO_OPENSSL )
649
713
OpenSSL_add_all_algorithms ();
0 commit comments