From: "plaisthos (Code Review)" Date: Fri, 20 Dec 2024 14:49:59 +0000 References: Reply-To: arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="MGJqC9CQcVE="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: Do not attempt to decrypt packets anymore after 2**36 failed decryptions List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: flichtenheld Cc: openvpn-devel --MGJqC9CQcVE= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: flichtenheld. Hello flichtenheld, I'd like you to do a code review. Please visit http://gerrit.openvpn.net/c/openvpn/+/843?usp=3Demail to review the following change. Change subject: Do not attempt to decrypt packets anymore after 2**36 faile= d decryptions ...................................................................... Do not attempt to decrypt packets anymore after 2**36 failed decryptions To avoid attacks (especially on Chacha20-Poly1305) we do not allow decryption anymore after 2**36 failed verifications. Change-Id: I81440ac28a1ad553652e201234e5ddfe03a8c190 Signed-off-by: Arne Schwabe --- M src/openvpn/crypto.c M src/openvpn/crypto.h M src/openvpn/ssl.c 3 files changed, 40 insertions(+), 1 deletion(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/43/843/1 diff --git a/src/openvpn/crypto.c b/src/openvpn/crypto.c index faf69fc..88a9f24 100644 --- a/src/openvpn/crypto.c +++ b/src/openvpn/crypto.c @@ -405,7 +405,13 @@ { static const char error_prefix[] =3D "AEAD Decrypt error"; struct packet_id_net pin =3D { 0 }; - const struct key_ctx *ctx =3D &opt->key_ctx_bi.decrypt; + struct key_ctx *ctx =3D &opt->key_ctx_bi.decrypt; + + if (cipher_decrypt_verify_fail_exceeded(ctx)) + { + CRYPT_DROP("Decryption failed verification limit reached."); + } + int outlen; struct gc_arena gc; @@ -416,6 +422,8 @@ ASSERT(buf->len > 0); ASSERT(ctx->cipher); + + dmsg(D_PACKET_CONTENT, "DECRYPT FROM: %s", format_hex(BPTR(buf), BLEN(buf), 80, &gc)); =20 @@ -511,6 +519,7 @@ if (!cipher_ctx_final_check_tag(ctx->cipher, BPTR(&work) + outlen, &outlen, tag_ptr, tag_size)) { + ctx->failed_verifications++; CRYPT_DROP("packet tag authentication failed"); } ASSERT(buf_inc_len(&work, outlen)); diff --git a/src/openvpn/crypto.h b/src/openvpn/crypto.h index 4579b65..bb417e1 100644 --- a/src/openvpn/crypto.h +++ b/src/openvpn/crypto.h @@ -181,6 +181,8 @@ * with the current key in number of 128 bit blocks (only used for * AEAD ciphers) */ uint64_t plaintext_blocks; + /** number of failed verification using this cipher */ + uint64_t failed_verifications; }; #define KEY_DIRECTION_BIDIRECTIONAL 0 /* same keys for both directions */ @@ -623,6 +625,29 @@ cipher_get_aead_limits(const char *ciphername); /** + * Check if the number of failed decryption is over the acceptable limit. + * We + */ +static inline bool +cipher_decrypt_verify_fail_exceeded(const struct key_ctx *ctx) +{ + /* Use 2**36, same as TLS 1.3 */ + return ctx->failed_verifications > (1ull << 36); +} + +/** + * Check if the number of failed decryption is approaching the limit and we + * should try to move to a new key + */ +static inline bool +cipher_decrypt_verify_fail_warn(const struct key_ctx *ctx) +{ + /* Use 2**35, half the amount after which we refuse to decrypt */ + return ctx->failed_verifications > (1ull << 35); +} + + +/** * Blocksize used for the AEAD limit caluclation * * Since cipher_ctx_block_size() is not reliable and will return 1 in many diff --git a/src/openvpn/ssl.c b/src/openvpn/ssl.c index c77c4ed..73201ef 100644 --- a/src/openvpn/ssl.c +++ b/src/openvpn/ssl.c @@ -3042,6 +3042,11 @@ return true; } + if (cipher_decrypt_verify_fail_warn(&key_ctx_bi->decrypt)) + { + return true; + } + return false; } /* -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/843?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: I81440ac28a1ad553652e201234e5ddfe03a8c190 Gerrit-Change-Number: 843 Gerrit-PatchSet: 1 Gerrit-Owner: plaisthos Gerrit-Reviewer: flichtenheld Gerrit-CC: openvpn-devel Gerrit-Attention: flichtenheld Gerrit-MessageType: newchange --MGJqC9CQcVE= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: flichtenheld.

plaisthos would like flichtenheld to review this change.

Vi= ew Change

Do not attempt to decrypt packets anymore after 2**36 failed =
decryptions

To avoid attacks (especially on Chacha20-Poly1305) we do= not allow
decryption anymore after 2**36 failed verifications.

C= hange-Id: I81440ac28a1ad553652e201234e5ddfe03a8c190
Signed-off-by: Arne = Schwabe <arne@...1227...>
---
M src/openvpn/crypto.c
M src/o= penvpn/crypto.h
M src/openvpn/ssl.c
3 files changed, 40 insertions(+)= , 1 deletion(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn r=
efs/changes/43/843/1
diff --git a/src/openvpn/crypto.c b/src/openvp=
n/crypto.c
index faf69fc..88a9f24 100644
--= - a/src/openvpn/crypto.c
+++ b/src/openvpn/crypto.c<= br>@@ -405,7 +405,13 @@
{
stati= c const char error_prefix[] =3D "AEAD Decrypt error";
<= span> struct packet_id_net pin =3D { 0 };
- const struct key_ctx *ctx =3D &opt->key_= ctx_bi.decrypt;
+ = struct key_ctx *ctx =3D &opt->key_ctx_bi.decrypt;
+
+ if (cipher_decrypt_verify_fail_exceeded(ctx))<= br>+ {
+ CRYPT_DROP("Decryption faile= d verification limit reached.");
+ }
+
int outlen;
struct gc_arena = gc;

@@ -416,6 +422,8 @@
= ASSERT(buf->len > 0);
ASSERT(ctx->cipher)= ;

+=
+
= dmsg(D_PACKET_CONTENT, "DECRYPT FROM: %s",
= format_hex(BPTR(buf), BLEN(buf), 80, &gc));

@@ -511,6 +519,7 @@
if (!cipher_ctx_fina= l_check_tag(ctx->cipher, BPTR(&work) + outlen,
= &outlen, tag_ptr, tag_size))
= {
+ = ctx->failed_verifications++;
CRYPT_DROP("= packet tag authentication failed");
}
<= span> ASSERT(buf_inc_len(&work, outlen));

diff --gi= t a/src/openvpn/crypto.h b/src/openvpn/crypto.h
index 4579b= 65..bb417e1 100644
--- a/src/openvpn/crypto.h
+++ b/src/openvpn/crypto.h
@@ -181,6 +181,8 @@ * with the current key in number of 128 bit blocks (only used = for
* AEAD ciphers) */
uint64_t = plaintext_blocks;
+ = /** number of failed verification using this cipher */
+ uint64_t failed_verifications;

};

#define KEY_DIRECTION_B= IDIRECTIONAL 0 /* same keys for both directions */
@@ -623,= 6 +625,29 @@
cipher_get_aead_limits(const char *ciphername= );

/**
+ * Check if the number of failed decryption is over t= he acceptable limit.
= + * We
+ */+static inline bool
= +cipher_decrypt_verify_fail_exc= eeded(const struct key_ctx *ctx)
+{
+ /= * Use 2**36, same as TLS 1.3 */
+ return ctx->failed_verifications > (1ull << 36= );
+}
+
+/**
+ * Check if the number of failed decryption is approaching the limit a= nd we
+ * should try = to move to a new key
= + */
+static inline b= ool
+cipher_decrypt_v= erify_fail_warn(const struct key_ctx *ctx)
+{
+ /* Use 2**35, half the amount after which we refuse to decrypt */<= /span>
+ return ctx->f= ailed_verifications > (1ull << 35);
+}
+
+
= +/**
* Blocks= ize used for the AEAD limit caluclation
*
* Since cipher_ctx_block_size() is not reliable and will return 1 in man= y

diff --git a/src/openvpn/ssl.c b/src/openvpn/ssl.c=
index c77c4ed..73201ef 100644
--- a/src/openvpn/s= sl.c
+++ b/src/openvpn/ssl.c
@@ -3042,6 +30= 42,11 @@
return true;
}


+ if = (cipher_decrypt_verify_fail_warn(&key_ctx_bi->decrypt))
+ {
+ return true;
+ }
+
return false;
}
/*

To view, visit change 843. = To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I81440ac28a1ad553652e201234e= 5ddfe03a8c190
Gerrit-Change-Number: 843
Gerrit-PatchSet: 1
Gerrit-Owner: plaisthos <arne-openvpn@...1711...= 27...>
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: flichtenheld <frank@...2375...= 41...>
Gerrit-MessageType: newchange
--MGJqC9CQcVE=--