From: "cron2 (Code Review)" Date: Sat, 23 Aug 2025 16:01:55 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641..., max@...2606... Message-ID: <5c374002a1dfb9b99a32f5715d21121d05d7912a-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="Ybz5/l3qKkY="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: Check message id/acked ids too when doing sessionid cookie checks List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos , flichtenheld , MaxF Cc: openvpn-devel --Ybz5/l3qKkY= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has uploaded a new patch set (#7) to the change originally created by= plaisthos. ( http://gerrit.openvpn.net/c/openvpn/+/1067?usp=3Demail ) The following approvals got outdated and were removed: Code-Review+2 by MaxF Change subject: Check message id/acked ids too when doing sessionid cookie = checks ...................................................................... Check message id/acked ids too when doing sessionid cookie checks This fixes that control packets on a floating client can trigger creating a new session in special circumstances: To trigger this circumstance a connection needs to - starts on IP A - successfully floats to IP B by data packet - then has a control packet from IP A before any data packet can trigger the float back to IP A and all of this needs to happen in the 60s time that hmac cookie is valid in the default configuration. In this scenario we would trigger a new connection as the HMAC session id would be valid. This patch adds checking also of the message-id and acked ids to discern packet from the initial three-way handshake where these ids are 0 or 1 from any later packet. This will now trigger (at verb 4 or higher) a messaged like: Packet (P_ACK_V1) with invalid or missing SID instead. Also remove a few duplicated free_tls_pre_decrypt_state in test_ssl. Reported-By: Walter Doekes Tested-By: Walter Doekes Change-Id: I6752dcd5aff3e5cea2b439366479e86751a1c403 Signed-off-by: Arne Schwabe Acked-by: MaxF Message-Id: <20250819212214.16218-1-gert@...1296...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg32= 626.html Signed-off-by: Gert Doering --- M src/openvpn/mudp.c M src/openvpn/ssl_pkt.c M src/openvpn/ssl_pkt.h M tests/unit_tests/openvpn/test_pkt.c 4 files changed, 129 insertions(+), 24 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/67/1067/7 diff --git a/src/openvpn/mudp.c b/src/openvpn/mudp.c index 7259a4b..31134be 100644 --- a/src/openvpn/mudp.c +++ b/src/openvpn/mudp.c @@ -151,7 +151,8 @@ * need to contain the peer id */ struct gc_arena gc =3D gc_new(); - bool ret =3D check_session_id_hmac(state, from, hmac, handwindow); + bool pkt_is_ack =3D (verdict =3D=3D VERDICT_VALID_ACK_V1); + bool ret =3D check_session_hmac_and_pkt_id(state, from, hmac, hand= window, pkt_is_ack); const char *peer =3D print_link_socket_actual(&m->top.c2.from, &gc= ); uint8_t pkt_firstbyte =3D *BPTR(&m->top.c2.buf); @@ -159,7 +160,8 @@ if (!ret) { - msg(D_MULTI_MEDIUM, "Packet (%s) with invalid or missing SID f= rom %s", + msg(D_MULTI_MEDIUM, "Packet (%s) with invalid or missing SID f= rom" + " %s or wrong packet id", packet_opcode_name(op), peer); } else diff --git a/src/openvpn/ssl_pkt.c b/src/openvpn/ssl_pkt.c index b901f87..6ec05a7 100644 --- a/src/openvpn/ssl_pkt.c +++ b/src/openvpn/ssl_pkt.c @@ -496,8 +496,11 @@ } =20 bool -check_session_id_hmac(struct tls_pre_decrypt_state *state, const struct op= envpn_sockaddr *from, - hmac_ctx_t *hmac, int handwindow) +check_session_hmac_and_pkt_id(struct tls_pre_decrypt_state *state, + const struct openvpn_sockaddr *from, + hmac_ctx_t *hmac, + int handwindow, + bool pkt_is_ack) { if (!from) { @@ -512,6 +515,36 @@ return false; } + /* Check if the packet ID of the packet or ACKED packet is <=3D 1 */ + for (int i =3D 0; i < ack.len; i++) + { + /* This packet ACKs a packet that has a higher packet id than the + * ones expected in the three-way handshake, consider it as invalid + * for the session */ + if (ack.packet_id[i] > 1) + { + return false; + } + } + + if (!pkt_is_ack) + { + packet_id_type message_id; + /* Extract the packet ID from the packet */ + if (!reliable_ack_read_packet_id(&buf, &message_id)) + { + return false; + } + + /* similar check. Anything larger than 1 is not considered part of= the + * three-way handshake */ + if (message_id > 1) + { + return false; + } + } + + /* check adjacent timestamps too */ for (int offset =3D -2; offset <=3D 1; offset++) { diff --git a/src/openvpn/ssl_pkt.h b/src/openvpn/ssl_pkt.h index 8fe4880..96cdd68 100644 --- a/src/openvpn/ssl_pkt.h +++ b/src/openvpn/ssl_pkt.h @@ -178,14 +178,20 @@ /** * Checks if a control packet has a correct HMAC server session id * + * This will also consider packets that have a packet id higher + * than 1 or ack packets higher than 1 to be invalid as they are + * not part of the initial three way handshake of OpenVPN and should + * not create a new connection. + * * @param state session information * @param from link_socket from the client * @param hmac the hmac context to use for the calculation * @param handwindow the quantisation of the current time + * @param pkt_is_ack the packet being checked is a P_ACK_V1 * @return the expected server session id */ -bool check_session_id_hmac(struct tls_pre_decrypt_state *state, const stru= ct openvpn_sockaddr *from, - hmac_ctx_t *hmac, int handwindow); +bool check_session_hmac_and_pkt_id(struct tls_pre_decrypt_state *state, co= nst struct openvpn_sockaddr *from, + hmac_ctx_t *hmac, int handwindow, bool = pkt_is_ack); /* * Write a control channel authentication record. diff --git a/tests/unit_tests/openvpn/test_pkt.c b/tests/unit_tests/openvpn= /test_pkt.c index 65b31e7..5122766 100644 --- a/tests/unit_tests/openvpn/test_pkt.c +++ b/tests/unit_tests/openvpn/test_pkt.c @@ -139,6 +139,27 @@ 0xc8, 0x01, 0x00, 0x00, 0x00= , 0x00, 0xdd, 0x85, 0xdb, 0x53, 0x56, 0x23, 0xb0= , 0x2e }; +/* no tls-auth, P_ACK_V1, acks 0,1, and 2 */ +const uint8_t client_ack_123_none_random_id[] =3D { + 0x28, + 0xae, 0xb9, 0xaf, 0xe1, 0xf0, 0x1d, 0x79, 0xc8, + 0x03, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x02, + 0xdd, 0x85, 0xdb, 0x53, 0x56, 0x23, 0xb0, 0x2e +}; + +/* no tls-auth, P_CONTROL_V1, acks 0, msg-id 2 */ +const uint8_t client_control_none_random_id[] =3D { + 0x20, + 0xae, 0xb9, 0xaf, 0xe1, 0xf0, 0x1d, 0x79, 0xc8, + 0x01, + 0x00, 0x00, 0x00, 0x00, + 0x02 +}; + + struct tls_auth_standalone init_tas_auth(int key_direction) { @@ -256,12 +277,10 @@ assert_int_equal(verdict, VERDICT_VALID_RESET_V2); free_tls_pre_decrypt_state(&state); - free_tls_pre_decrypt_state(&state); /* The pre decrypt function should not modify the buffer, so calling it * again should have the same result */ verdict =3D tls_pre_decrypt_lite(&tas, &state, &from, &buf); assert_int_equal(verdict, VERDICT_VALID_RESET_V2); - free_tls_pre_decrypt_state(&state); /* and buf memory should be equal */ assert_memory_equal(BPTR(&buf), client_reset_v2_tls_auth, sizeof(clien= t_reset_v2_tls_auth)); @@ -279,7 +298,6 @@ assert_int_equal(verdict, VERDICT_INVALID); free_tls_pre_decrypt_state(&state); - free_tls_pre_decrypt_state(&state); /* Wrong key direction gives a wrong hmac key and should not validate = */ free_key_ctx_bi(&tas.tls_wrap.opt.key_ctx_bi); free_tas(&tas); @@ -319,15 +337,12 @@ assert_int_equal(verdict, VERDICT_VALID_RESET_V2); free_tls_pre_decrypt_state(&state); - free_tls_pre_decrypt_state(&state); buf_reset_len(&buf); buf_write(&buf, client_reset_v2_tls_crypt, sizeof(client_reset_v2_none= )); verdict =3D tls_pre_decrypt_lite(&tas, &state, &from, &buf); assert_int_equal(verdict, VERDICT_VALID_RESET_V2); free_tls_pre_decrypt_state(&state); - free_tls_pre_decrypt_state(&state); - /* This is not a reset packet and should trigger the other response */ buf_reset_len(&buf); buf_write(&buf, client_ack_tls_auth_randomid, sizeof(client_ack_tls_au= th_randomid)); @@ -405,7 +420,7 @@ assert_int_equal(verdict, VERDICT_VALID_CONTROL_V1); /* This is a valid packet but containing a random id instead of an HMA= C id*/ - bool valid =3D check_session_id_hmac(&state, &from.dest, hmac, 30); + bool valid =3D check_session_hmac_and_pkt_id(&state, &from.dest, hmac,= 30, false); assert_false(valid); free_tls_pre_decrypt_state(&state); @@ -436,7 +451,7 @@ verdict =3D tls_pre_decrypt_lite(&tas, &state, &from, &buf); assert_int_equal(verdict, VERDICT_VALID_ACK_V1); - bool valid =3D check_session_id_hmac(&state, &from.dest, hmac, 30); + bool valid =3D check_session_hmac_and_pkt_id(&state, &from.dest, hmac,= 30, true); assert_true(valid); free_tls_pre_decrypt_state(&state); @@ -445,6 +460,51 @@ hmac_ctx_free(hmac); } +static void +test_verify_hmac_none_out_of_range_ack(void **ut_state) +{ + hmac_ctx_t *hmac =3D session_id_hmac_init(); + + struct link_socket_actual from =3D { 0 }; + from.dest.addr.sa.sa_family =3D AF_INET; + + struct tls_auth_standalone tas =3D { 0 }; + struct tls_pre_decrypt_state state =3D { 0 }; + + struct buffer buf =3D alloc_buf(1024); + enum first_packet_verdict verdict; + + tas.tls_wrap.mode =3D TLS_WRAP_NONE; + + buf_reset_len(&buf); + buf_write(&buf, client_ack_123_none_random_id, sizeof(client_ack_123_n= one_random_id)); + + + verdict =3D tls_pre_decrypt_lite(&tas, &state, &from, &buf); + assert_int_equal(verdict, VERDICT_VALID_ACK_V1); + + /* should fail because it acks 2 */ + bool valid =3D check_session_hmac_and_pkt_id(&state, &from.dest, hmac,= 30, true); + assert_false(valid); + free_tls_pre_decrypt_state(&state); + + /* Try test with the control with a too high message id now */ + buf_reset_len(&buf); + buf_write(&buf, client_control_none_random_id, sizeof(client_control_n= one_random_id)); + + verdict =3D tls_pre_decrypt_lite(&tas, &state, &from, &buf); + assert_int_equal(verdict, VERDICT_VALID_CONTROL_V1); + + /* should fail because it has message id 2 */ + valid =3D check_session_hmac_and_pkt_id(&state, &from.dest, hmac, 30, = true); + assert_false(valid); + + free_tls_pre_decrypt_state(&state); + free_buf(&buf); + hmac_ctx_cleanup(hmac); + hmac_ctx_free(hmac); +} + static hmac_ctx_t * init_static_hmac(void) { @@ -634,16 +694,20 @@ main(void) { openvpn_unit_test_setup(); - const struct CMUnitTest tests[] =3D { cmocka_unit_test(test_tls_decryp= t_lite_none), - cmocka_unit_test(test_tls_decrypt_= lite_auth), - cmocka_unit_test(test_tls_decrypt_= lite_crypt), - cmocka_unit_test(test_parse_ack), - cmocka_unit_test(test_calc_session= _id_hmac_static), - cmocka_unit_test(test_verify_hmac_= none), - cmocka_unit_test(test_verify_hmac_= tls_auth), - cmocka_unit_test(test_generate_res= et_packet_plain), - cmocka_unit_test(test_generate_res= et_packet_tls_auth), - cmocka_unit_test(test_extract_cont= rol_message) }; + + const struct CMUnitTest tests[] =3D { + cmocka_unit_test(test_tls_decrypt_lite_none), + cmocka_unit_test(test_tls_decrypt_lite_auth), + cmocka_unit_test(test_tls_decrypt_lite_crypt), + cmocka_unit_test(test_parse_ack), + cmocka_unit_test(test_calc_session_id_hmac_static), + cmocka_unit_test(test_verify_hmac_none), + cmocka_unit_test(test_verify_hmac_tls_auth), + cmocka_unit_test(test_verify_hmac_none_out_of_range_ack), + cmocka_unit_test(test_generate_reset_packet_plain), + cmocka_unit_test(test_generate_reset_packet_tls_auth), + cmocka_unit_test(test_extract_control_message) + }; #if defined(ENABLE_CRYPTO_OPENSSL) OpenSSL_add_all_algorithms(); -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1067?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I6752dcd5aff3e5cea2b439366479e86751a1c403 Gerrit-Change-Number: 1067 Gerrit-PatchSet: 7 Gerrit-Owner: plaisthos Gerrit-Reviewer: MaxF Gerrit-Reviewer: flichtenheld Gerrit-CC: openvpn-devel Gerrit-MessageType: newpatchset --Ybz5/l3qKkY= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 uploaded patch set #7 to the change originally cr= eated by plaisthos.

View Change

The following approvals got outdate= d and were removed: Code-Review+2 by MaxF

Check message id/acked ids too when doing sessionid c=
ookie checks

This fixes that control packets on a floating client ca= n trigger
creating a new session in special circumstances:

To tri= gger this circumstance a connection needs to

- starts on IP A
- s= uccessfully floats to IP B by data packet
- then has a control packet fr= om IP A before any
data packet can trigger the float back to IP A
<= br>and all of this needs to happen in the 60s time
that hmac cookie is v= alid in the default
configuration.

In this scenario we would trig= ger a new connection as the HMAC
session id would be valid.

This = patch adds checking also of the message-id and acked ids to
discern pack= et from the initial three-way handshake where these
ids are 0 or 1 from = any later packet.

This will now trigger (at verb 4 or higher) a mess= aged like:

Packet (P_ACK_V1) with invalid or missing SID

i= nstead.

Also remove a few duplicated free_tls_pre_decrypt_state in t= est_ssl.

Reported-By: Walter Doekes <walter.openvpn@...2889...>= ;
Tested-By: Walter Doekes <walter.openvpn@...2889...>

Chan= ge-Id: I6752dcd5aff3e5cea2b439366479e86751a1c403
Signed-off-by: Arne Sch= wabe <arne@...1227...>
Acked-by: MaxF <max@...2606...>
Me= ssage-Id: <20250819212214.16218-1-gert@...1296...>
URL: https://ww= w.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg32626.html
Sig= ned-off-by: Gert Doering <gert@...1296...>
---
M src/openvpn/mu= dp.c
M src/openvpn/ssl_pkt.c
M src/openvpn/ssl_pkt.h
M tests/unit_= tests/openvpn/test_pkt.c
4 files changed, 129 insertions(+), 24 deletion= s(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes=
/67/1067/7
diff --git a/src/openvpn/mudp.c b/src/openvpn/mudp.c
index 7259a4b..31134be 100644
--- a/src/openvp= n/mudp.c
+++ b/src/openvpn/mudp.c
@@ -151,7= +151,8 @@
* need to contain the peer id */
struct gc_arena gc =3D gc_new();

- bool ret =3D check= _session_id_hmac(state, from, hmac, handwindow);
+ bool pkt_is_ack =3D (verdict =3D=3D VE= RDICT_VALID_ACK_V1);
= + bool ret =3D check_session_hmac_and_pkt_id(state, from, hmac, hand= window, pkt_is_ack);

const char = *peer =3D print_link_socket_actual(&m->top.c2.from, &gc);=
uint8_t pkt_firstbyte =3D *BPTR(&m->top.c2.buf);<= /span>
@@ -159,7 +160,8 @@

= if (!ret)
{
- msg(D_MULTI_MEDIUM, "Packet (%s) with i= nvalid or missing SID from %s",
+ msg(D_MULTI_MEDIUM, "Packet (%s) with inv= alid or missing SID from"
+ " %s or wrong packet id&quo= t;,
packet_opcode_name(op), peer);<= br> }
else
diff --gi= t a/src/openvpn/ssl_pkt.c b/src/openvpn/ssl_pkt.c
index b90= 1f87..6ec05a7 100644
--- a/src/openvpn/ssl_pkt.c
= +++ b/src/openvpn/ssl_pkt.c
@@ -496,8 +496,11 @@
}

bool
-check_session_id_hmac(struct tls_pre_decry= pt_state *state, const struct openvpn_sockaddr *from,
- hmac_ctx_t *hmac, int= handwindow)
+check_s= ession_hmac_and_pkt_id(struct tls_pre_decrypt_state *state,
+ const= struct openvpn_sockaddr *from,

+ hmac_ctx_t *hmac,
+ int h= andwindow,

+ = bool pkt_is_ack)
{
= if (!from)
{
@@ -512,6 +515,36 @@
return false;
}

+ /* Check if = the packet ID of the packet or ACKED packet is <=3D 1 */
+ for (int i =3D 0; i < ack.l= en; i++)

+ {
+ /* This packet AC= Ks a packet that has a higher packet id than the
+ * ones expected in the three-way hand= shake, consider it as invalid
+ * for the session */
+ if (ack.packet_id[i] > 1)
+ {
+ return false;
+ }
+ }
+
+ if (!= pkt_is_ack)
+ {
+ packet_id_type= message_id;
+ = /* Extract the packet ID from the packet */
+ if (!reliable_ack_read_packet_id(&buf,= &message_id))
+ = {
+ = return false;
+ = }
+
+ /* similar check. Anything= larger than 1 is not considered part of the

+ * three-way handshake */
+ if (message_id > 1)
+ {
+ return false;
+ }
+ }
+
+ * This will als= o consider packets that have a packet id higher
+ * than 1 or ack packets higher than 1 to be in= valid as they are
+ *= not part of the initial three way handshake of OpenVPN and should+ * not create a new connecti= on.
+ *
* @param state session information

* @param = from link_socket from the client
* @param hmac = the hmac context to use for the calculation
* @pa= ram handwindow the quantisation of the current time
+ * @param pkt_is_ack the packet being= checked is a P_ACK_V1
* @return the expecte= d server session id
*/
-bool check_session_id_hmac(struct tls_pre_decrypt_state = *state, const struct openvpn_sockaddr *from,
- hmac_ctx_t *hmac, int han= dwindow);
+bool check= _session_hmac_and_pkt_id(struct tls_pre_decrypt_state *state, const struct = openvpn_sockaddr *from,
+ hmac_ctx_t *hmac, int handwindow, bo= ol pkt_is_ack);

/*
* W= rite a control channel authentication record.
diff --git a/= tests/unit_tests/openvpn/test_pkt.c b/tests/unit_tests/openvpn/test_pkt.c
index 65b31e7..5122766 100644
--- a/tests/un= it_tests/openvpn/test_pkt.c
+++ b/tests/unit_tests/openvpn/= test_pkt.c
@@ -139,6 +139,27 @@
= 0xc8, 0x01, 0x00, 0x00, 0x00, 0x00, 0xd= d, 0x85,
0xd= b, 0x53, 0x56, 0x23, 0xb0, 0x2e };

+/* no tls-auth, P_ACK_V1, acks 0,1, and 2= */
+const uint8_t cl= ient_ack_123_none_random_id[] =3D {
+ 0x28,
+ 0xae, 0xb9, 0xaf, 0xe1, 0xf0, 0x1d, 0x79, 0xc8,
+ 0x03,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x01,
<= span style=3D"color: hsl(120, 100%, 40%);">+ 0x00, 0x00, 0x00, 0x02,
+ 0xdd, 0x85, 0xdb, 0= x53, 0x56, 0x23, 0xb0, 0x2e
+};
++/* no tls-auth, P_CONTROL_V1= , acks 0, msg-id 2 */
+const uint8_t client_control_none_random_id[] =3D {
+ 0x20,
+ 0xae, 0xb9, 0xaf, 0xe1, 0xf0, 0x1d, 0x79, 0xc8,=
+ 0x01,+ 0x00, 0x00, 0x00, 0x00,
+ 0x02
+};

+
+
struct tls_auth_standalone
init_t= as_auth(int key_direction)
{
@@ -256,12 +2= 77,10 @@
assert_int_equal(verdict, VERDICT_VALID_RESET= _V2);
free_tls_pre_decrypt_state(&state);
- free_tls= _pre_decrypt_state(&state);
/* The pre decrypt fun= ction should not modify the buffer, so calling it
* a= gain should have the same result */
verdict =3D tls_pr= e_decrypt_lite(&tas, &state, &from, &buf);
= assert_int_equal(verdict, VERDICT_VALID_RESET_V2);
- free_tls_pre_decrypt_state(&state= );

/* and buf memory should be equal= */
assert_memory_equal(BPTR(&buf), client_reset_v= 2_tls_auth, sizeof(client_reset_v2_tls_auth));
@@ -279,7 +2= 98,6 @@
assert_int_equal(verdict, VERDICT_INVALID);
free_tls_pre_decrypt_state(&state);
=
- free_tls_pre_dec= rypt_state(&state);
/* Wrong key direction gives a= wrong hmac key and should not validate */
free_key_ct= x_bi(&tas.tls_wrap.opt.key_ctx_bi);
free_tas(&= tas);
@@ -319,15 +337,12 @@
assert_int= _equal(verdict, VERDICT_VALID_RESET_V2);
free_tls_pre_= decrypt_state(&state);

- free_tls_pre_decrypt_state(&state); buf_reset_len(&buf);
buf_write(&b= uf, client_reset_v2_tls_crypt, sizeof(client_reset_v2_none));
verdict =3D tls_pre_decrypt_lite(&tas, &state, &from, &= amp;buf);

assert_int_equal(verdict, VERDICT_VALID_RESE= T_V2);
free_tls_pre_decrypt_state(&state);<= br>
- free_tl= s_pre_decrypt_state(&state);
-
/* This is not a reset packet and should t= rigger the other response */
buf_reset_len(&buf);<= /span>
buf_write(&buf, client_ack_tls_auth_randomid, size= of(client_ack_tls_auth_randomid));
@@ -405,7 +420,7 @@
assert_int_equal(verdict, VERDICT_VALID_CONTROL_V1);

/* This is a valid packet but containing = a random id instead of an HMAC id*/
- bool valid =3D check_session_id_hmac(&state, &fro= m.dest, hmac, 30);
+ = bool valid =3D check_session_hmac_and_pkt_id(&state, &from.dest,= hmac, 30, false);
assert_false(valid);

free_tls_pre_decrypt_state(&state);
= @@ -436,7 +451,7 @@
verdict =3D tls_pre_decrypt_= lite(&tas, &state, &from, &buf);
asser= t_int_equal(verdict, VERDICT_VALID_ACK_V1);

- bool valid =3D check_session_id= _hmac(&state, &from.dest, hmac, 30);

+ bool valid =3D check_session_hmac_and_pkt_id(&= amp;state, &from.dest, hmac, 30, true);
assert_tru= e(valid);

free_tls_pre_decrypt_state= (&state);
@@ -445,6 +460,51 @@
hma= c_ctx_free(hmac);
}

+static void
+test_verify_hmac_none_out_of_range_ack(void **ut= _state)
+{
= + hmac_ctx_t *hmac =3D sessi= on_id_hmac_init();
+<= /span>
+ struct link_sock= et_actual from =3D { 0 };
+ from.dest.addr.sa.sa_family =3D AF_INET;
+
+ struct tls_auth_standalone tas =3D { 0 };
+ struct tls_pre_decrypt_state stat= e =3D { 0 };
+=
+ struct buffer buf =3D = alloc_buf(1024);
+ = enum first_packet_verdict verdict;
+
+ = tas.tls_wrap.mode =3D TLS_WRAP_NONE;
+
+ = buf_reset_len(&buf);
+ buf_write(&buf, client_ack_123_none_random_id, sizeof(clien= t_ack_123_none_random_id));
+
+
= + verdict =3D tls_pre_decryp= t_lite(&tas, &state, &from, &buf);
+ assert_int_equal(verdict, VERDICT_VALID_= ACK_V1);
+
= + /* should fail because it = acks 2 */
+ bool v= alid =3D check_session_hmac_and_pkt_id(&state, &from.dest, hmac, 30= , true);
+ assert_= false(valid);
+ fr= ee_tls_pre_decrypt_state(&state);
+
+ = /* Try test with the control with a too high message id now */+ buf_reset_len(&buf);<= /span>
+ buf_write(&b= uf, client_control_none_random_id, sizeof(client_control_none_random_id));<= /span>
+
+ verdict =3D tls_pre_decrypt_lite(&a= mp;tas, &state, &from, &buf);
+ assert_int_equal(verdict, VERDICT_VALID_CONTROL_V= 1);
+
+ /* should fail because it has m= essage id 2 */

+ v= alid =3D check_session_hmac_and_pkt_id(&state, &from.dest, hmac, 30= , true);
+ assert_= false(valid);
+
+ free_tls_pre_decrypt_= state(&state);
+ = free_buf(&buf);
+ hmac_ctx_free(hmac);
+}
+
static hmac_ctx_t *
init_static_hmac(void)=
{
@@ -634,16 +694,20 @@
= main(void)
{
openvpn_unit_test_setup(= );
- const struct CM= UnitTest tests[] =3D { cmocka_unit_test(test_tls_decrypt_lite_none),=
- = cmocka_unit_test(test_tls_decrypt_lite_auth),
- = cmocka_unit_test(test_tls_decrypt_lite_crypt),
- cmocka_un= it_test(test_parse_ack),
- = cmocka_unit_test(test_verify_hmac_non= e),
- = cmocka_unit_test(test_verify_hmac_tls_auth),- = cmocka_unit_test(test_generate_reset_packet_plain),
- = cmocka_unit_test(test_generate_reset_packet_tls_auth),

- = cmocka_unit_test(test_extract_control_message) };

+
+ const struct CMUnitTest tests[] =3D {
+ cmocka_unit_test(test_tls_decr= ypt_lite_none),
+ = cmocka_unit_test(test_tls_decrypt_lite_auth),
+ cmocka_unit_test(test_tls_decrypt_lit= e_crypt),
+ cm= ocka_unit_test(test_parse_ack),
+ cmocka_unit_test(test_calc_session_id_hmac_static),
+ cmocka_unit_tes= t(test_verify_hmac_none),
+ cmocka_unit_test(test_verify_hmac_tls_auth),
+ cmocka_unit_test(test_verify= _hmac_none_out_of_range_ack),
+ cmocka_unit_test(test_generate_reset_packet_plain),
+ cmocka_unit_test(= test_generate_reset_packet_tls_auth),
+ cmocka_unit_test(test_extract_control_message)
+ };

#if defined(ENABLE_CRYPTO_OPENSSL)
= OpenSSL_add_all_algorithms();

To view,= visit c= hange 1067. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6752dcd5aff3e5cea2b43936647= 9e86751a1c403
Gerrit-Change-Number: 1067
Gerrit-PatchSet: 7
Gerrit-Owner: plaisthos <arne-openvpn@...1711...= 27...>
Gerrit-Reviewer: MaxF <max@...2606...> <= /div>
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-MessageType: newpatchset
--Ybz5/l3qKkY=--