Skip to contentSkip to conversation

EVP_DigestSignFinal siglen parameter correction

PATCH In review Juliusz Sosinowicz 3 participants 4 messages Mar 12, 2021 – Mar 17, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 EVP_DigestSignFinal siglen parameter correction

In the EVP_DigestSignFinal API, "before the call the siglen parameter should contain the length of the sig buffer".

---
 src/openvpn/crypto_openssl.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
src/openvpn/crypto_openssl.c +3 -1
index 49698e4b3..4486d246d 100644
@@ -1195,7 +1195,7 @@ tls1_P_hash(const EVP_MD *md, const unsigned char *sec,
     EVP_MD_CTX ctx, ctx_tmp, ctx_init;
     EVP_PKEY *mac_key;
     unsigned char A1[EVP_MAX_MD_SIZE];
-    size_t A1_len;
+    size_t A1_len = EVP_MAX_MD_SIZE;
     int ret = false;
 
     chunk = EVP_MD_size(md);
@@ -1249,6 +1249,7 @@ tls1_P_hash(const EVP_MD *md, const unsigned char *sec,
 
         if (olen > chunk)
         {
+            j = olen;
             if (!EVP_DigestSignFinal(&ctx, out, &j))
             {
                 goto err;
@@ -1263,6 +1264,7 @@ tls1_P_hash(const EVP_MD *md, const unsigned char *sec,
         }
         else
         {
+            A1_len = EVP_MAX_MD_SIZE;
             /* last one */
             if (!EVP_DigestSignFinal(&ctx, A1, &A1_len))
             {
Signature · 1 line
2.25.1
#1 lore raw

Am 12.03.21 um 16:06 schrieb Juliusz Sosinowicz:

Quoted 1 line

In the EVP_DigestSignFinal API, "before the call the siglen parameter should contain the length of the sig buffer".

This is probably correct but I need to take a closer look as this function is directly taken from OpenSSL's internal function and only has minimal adaptations. Note also that we plan to remove this compatibility path as soon as we drop OpenSSL 1.0.2 support.

Arne

Acked-by on v1 1/1
#2 lore raw
In reply to Juliusz Sosinowicz

Am 12.03.21 um 16:06 schrieb Juliusz Sosinowicz:

Quoted 30 lines

In the EVP_DigestSignFinal API, "before the call the siglen parameter should contain the length of the sig buffer".

---
 src/openvpn/crypto_openssl.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
src/openvpn/crypto_openssl.c +2 -1
index 49698e4b3..4486d246d 100644
@@ -1195,7 +1195,7 @@ tls1_P_hash(const EVP_MD *md, const unsigned char *sec,
     EVP_MD_CTX ctx, ctx_tmp, ctx_init;
     EVP_PKEY *mac_key;
     unsigned char A1[EVP_MAX_MD_SIZE];
-    size_t A1_len;
+    size_t A1_len = EVP_MAX_MD_SIZE;
     int ret = false;
 
     chunk = EVP_MD_size(md);
@@ -1249,6 +1249,7 @@ tls1_P_hash(const EVP_MD *md, const unsigned char *sec,
 
         if (olen > chunk)
         {
+            j = olen;
             if (!EVP_DigestSignFinal(&ctx, out, &j))
             {
                 goto err;

src/openvpn/crypto_openssl.c tls1_P_hash(const EVP_MD *md, const unsigned char *sec, · line 1270

Quoted 7 lines
src/openvpn/crypto_openssl.c +1 -0
@@ -1263,6 +1264,7 @@ tls1_P_hash(const EVP_MD *md, const unsigned char *sec,
         }
         else
         {
+            A1_len = EVP_MAX_MD_SIZE;
             /* last one */
             if (!EVP_DigestSignFinal(&ctx, A1, &A1_len))
             {

The uninitialised parameter should not work and the OpenSSL documentation says that it should contain the size of the buffer but the internal code of OpenVPN seems to ignore that and somehow it still works. But I cannot blame wolfSSL being lax about the OpenSSL API :)

#3 lore raw
In reply to Juliusz Sosinowicz

Your patch has been applied to the master branch.

Mildly tested on an OpenSSL 1.0.2u box, client side only. Works :-)

commit 476990d41ad78ac4419a3743cdab55c85c41b041

Author: Juliusz Sosinowicz
Date:   Fri Mar 12 16:06:29 2021 +0100
     EVP_DigestSignFinal siglen parameter correction

     Signed-off-by: Juliusz Sosinowicz <[email protected]...>
     Acked-by: Arne Schwabe <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg21663.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering