Skip to contentSkip to conversation

Translate OpenSSL 3.0 digest names to OpenSSL 1.1 digest names

PATCH In review Arne Schwabe 3 participants 6 messages May 23, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Translate OpenSSL 3.0 digest names to OpenSSL 1.1 digest names

Since we used the OpenSSL <=1.1 names as part of our OCC message, they are now unfortunately part of our wire protocol.

OpenSSL 3.0 will still accept the "old" names so we do not need to use this translation table for lookup only for returning the name with md_kt_name

---
 src/openvpn/crypto_openssl.c | 39 ++++++++++++++++++++++++++++++++++--
 1 file changed, 37 insertions(+), 2 deletions(-)
src/openvpn/crypto_openssl.c +37 -2
index 74685b386..8c28d2b5e 100644
@@ -379,7 +379,7 @@ show_available_ciphers(void)
 void
 print_digest(EVP_MD *digest, void *unused)
 {
-    printf("%s %d bit digest size\n", EVP_MD_name(digest),
+    printf("%s %d bit digest size\n", md_kt_name(digest),
            EVP_MD_size(digest) * 8);
 }
 
@@ -982,6 +982,28 @@ md_kt_get(const char *digest)
     return md;
 }
 
+/* Since we used the OpenSSL <=1.1 names as part of our OCC message, they
+ * are now unfortunately part of our wire protocol.
+ *
+ * OpenSSL 3.0 will still accept the "old" names so we do not need to use
+ * this translation table for lookup only for returning the name with
+ * md_kt_name */
+const cipher_name_pair digest_name_translation_table[] = {
+    { "BLAKE2s256", "BLAKE2S-256"},
+    { "BLAKE2b512", "BLAKE2B-512"},
+    { "RIPEMD160", "RIPEMD-160" },
+    { "SHA224", "SHA2-224"},
+    { "SHA256", "SHA2-256"},
+    { "SHA384", "SHA2-384"},
+    { "SHA512", "SHA2-512"},
+    { "SHA512-224", "SHA2-512/224"},
+    { "SHA512-256", "SHA2-512/256"},
+    { "SHAKE128", "SHAKE-128"},
+    { "SHAKE256", "SHAKE-256"},
+};
+const size_t digest_name_translation_table_count =
+    sizeof(digest_name_translation_table) / sizeof(*digest_name_translation_table);
+
 const char *
 md_kt_name(const EVP_MD *kt)
 {
@@ -989,7 +1011,20 @@ md_kt_name(const EVP_MD *kt)
     {
         return "[null-digest]";
     }
-    return EVP_MD_name(kt);
+
+    const char *name = EVP_MD_name(kt);
+
+    /* Search for a digest name translation */
+    for (size_t i = 0; i < digest_name_translation_table_count; i++)
+    {
+        const cipher_name_pair *pair = &digest_name_translation_table[i];
+        if (!strcmp(name, pair->lib_name))
+        {
+            name = pair->openvpn_name;
+        }
+    }
+
+    return name;
 }
 
 unsigned char
Signature · 1 line
2.32.0 (Apple Git-132)
#1 lore raw

PATCH 1/1 Translate OpenSSL 3.0 digest names to OpenSSL 1.1 digest names

Since we used the OpenSSL <=1.1 names as part of our OCC message, they are now unfortunately part of our wire protocol.

OpenSSL 3.0 will still accept the "old" names so we do not need to use this translation table for lookup only for returning the name with md_kt_name

---
 src/openvpn/crypto_openssl.c | 36 +++++++++++++++++++++++++++++++++++-
 1 file changed, 35 insertions(+), 1 deletion(-)
src/openvpn/crypto_openssl.c +35 -1
index 3bedc03f7..02b5f3ce5 100644
@@ -404,7 +404,7 @@ show_available_ciphers(void)
 void
 print_digest(EVP_MD *digest, void *unused)
 {
-    printf("%s %d bit digest size\n", EVP_MD_get0_name(digest),
+    printf("%s %d bit digest size\n", md_kt_name(EVP_MD_get0_name(digest)),
            EVP_MD_size(digest) * 8);
 }
 
@@ -1055,6 +1055,29 @@ md_valid(const char *digest)
     return valid;
 }
 
+
+/* Since we used the OpenSSL <=1.1 names as part of our OCC message, they
+ * are now unfortunately part of our wire protocol.
+ *
+ * OpenSSL 3.0 will still accept the "old" names so we do not need to use
+ * this translation table for lookup only for returning the name with
+ * md_kt_name */
+const cipher_name_pair digest_name_translation_table[] = {
+    { "BLAKE2s256", "BLAKE2S-256"},
+    { "BLAKE2b512", "BLAKE2B-512"},
+    { "RIPEMD160", "RIPEMD-160" },
+    { "SHA224", "SHA2-224"},
+    { "SHA256", "SHA2-256"},
+    { "SHA384", "SHA2-384"},
+    { "SHA512", "SHA2-512"},
+    { "SHA512-224", "SHA2-512/224"},
+    { "SHA512-256", "SHA2-512/256"},
+    { "SHAKE128", "SHAKE-128"},
+    { "SHAKE256", "SHAKE-256"},
+};
+const size_t digest_name_translation_table_count =
+    sizeof(digest_name_translation_table) / sizeof(*digest_name_translation_table);
+
 const char *
 md_kt_name(const char *mdname)
 {
@@ -1064,6 +1087,17 @@ md_kt_name(const char *mdname)
     }
     evp_md_type *kt = md_get(mdname);
     const char *name = EVP_MD_get0_name(kt);
+
+    /* Search for a digest name translation */
+    for (size_t i = 0; i < digest_name_translation_table_count; i++)
+    {
+        const cipher_name_pair *pair = &digest_name_translation_table[i];
+        if (!strcmp(name, pair->lib_name))
+        {
+            name = pair->openvpn_name;
+        }
+    }
+
     EVP_MD_free(kt);
     return name;
 }
Signature · 1 line
2.32.0 (Apple Git-132)
Acked-by on v1 1/1
#2 lore raw

Hi,

Quoted 5 lines · Arne Schwabe

Since we used the OpenSSL <=1.1 names as part of our OCC message, they are now unfortunately part of our wire protocol.

OpenSSL 3.0 will still accept the "old" names so we do not need to use this translation table for lookup only for returning the name with

something is missing here ^

...table for lookup", but" only for returning...

Same change should be applied to the in-code comment.

Quoted 3 lines

md_kt_name

Patch looks good and it's as small as it could be.

Quoted 65 lines
---
  src/openvpn/crypto_openssl.c | 36 +++++++++++++++++++++++++++++++++++-
  1 file changed, 35 insertions(+), 1 deletion(-)
src/openvpn/crypto_openssl.c +35 -1
index 3bedc03f7..02b5f3ce5 100644
@@ -404,7 +404,7 @@ show_available_ciphers(void)
  void
  print_digest(EVP_MD *digest, void *unused)
  {
-    printf("%s %d bit digest size\n", EVP_MD_get0_name(digest),
+    printf("%s %d bit digest size\n", md_kt_name(EVP_MD_get0_name(digest)),
             EVP_MD_size(digest) * 8);
  }
 
@@ -1055,6 +1055,29 @@ md_valid(const char *digest)
      return valid;
  }
 
+
+/* Since we used the OpenSSL <=1.1 names as part of our OCC message, they
+ * are now unfortunately part of our wire protocol.
+ *
+ * OpenSSL 3.0 will still accept the "old" names so we do not need to use
+ * this translation table for lookup only for returning the name with
+ * md_kt_name */
+const cipher_name_pair digest_name_translation_table[] = {
+    { "BLAKE2s256", "BLAKE2S-256"},
+    { "BLAKE2b512", "BLAKE2B-512"},
+    { "RIPEMD160", "RIPEMD-160" },
+    { "SHA224", "SHA2-224"},
+    { "SHA256", "SHA2-256"},
+    { "SHA384", "SHA2-384"},
+    { "SHA512", "SHA2-512"},
+    { "SHA512-224", "SHA2-512/224"},
+    { "SHA512-256", "SHA2-512/256"},
+    { "SHAKE128", "SHAKE-128"},
+    { "SHAKE256", "SHAKE-256"},
+};
+const size_t digest_name_translation_table_count =
+    sizeof(digest_name_translation_table) / sizeof(*digest_name_translation_table);
+
  const char *
  md_kt_name(const char *mdname)
  {
@@ -1064,6 +1087,17 @@ md_kt_name(const char *mdname)
      }
      evp_md_type *kt = md_get(mdname);
      const char *name = EVP_MD_get0_name(kt);
+
+    /* Search for a digest name translation */
+    for (size_t i = 0; i < digest_name_translation_table_count; i++)
+    {
+        const cipher_name_pair *pair = &digest_name_translation_table[i];
+        if (!strcmp(name, pair->lib_name))
+        {
+            name = pair->openvpn_name;
+        }
+    }
+
      EVP_MD_free(kt);
      return name;
  }
Signature · 1 line
Antonio Quartulli
#3 lore raw
In reply to Arne Schwabe

Wording mangled as instructed, and tested for the case reported today ("ossl3 client with --auth sha256 talking to oss1.1 server, reporting mismatch on sha2-256 <-> sha2").

--auth sha2-256 works as well (on the oss3 side), as expected.

Your patch has been applied to the master branch.

commit 88342ed8277c579704c0e67feb4278aeaa544027

Author: Arne Schwabe
Date:   Mon May 23 12:35:46 2022 +0200
     Translate OpenSSL 3.0 digest names to OpenSSL 1.1 digest names

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

--
kind regards,

Gert Doering

Acked-by on v1 1/1
#4 lore raw
In reply to Arne Schwabe

Hi,

Quoted 5 lines · Arne Schwabe

Since we used the OpenSSL <=1.1 names as part of our OCC message, they are now unfortunately part of our wire protocol.

OpenSSL 3.0 will still accept the "old" names so we do not need to use this translation table for lookup only for returning the name with

Same as for the patch for master:

something is missing here ^

...table for lookup", but" only for returning...

Same change should be applied to the in-code comment.

Quoted 3 lines

md_kt_name

Quoted 68 lines
---
  src/openvpn/crypto_openssl.c | 39 ++++++++++++++++++++++++++++++++++--
  1 file changed, 37 insertions(+), 2 deletions(-)
src/openvpn/crypto_openssl.c +37 -2
index 74685b386..8c28d2b5e 100644
@@ -379,7 +379,7 @@ show_available_ciphers(void)
  void
  print_digest(EVP_MD *digest, void *unused)
  {
-    printf("%s %d bit digest size\n", EVP_MD_name(digest),
+    printf("%s %d bit digest size\n", md_kt_name(digest),
             EVP_MD_size(digest) * 8);
  }
 
@@ -982,6 +982,28 @@ md_kt_get(const char *digest)
      return md;
  }
 
+/* Since we used the OpenSSL <=1.1 names as part of our OCC message, they
+ * are now unfortunately part of our wire protocol.
+ *
+ * OpenSSL 3.0 will still accept the "old" names so we do not need to use
+ * this translation table for lookup only for returning the name with
+ * md_kt_name */
+const cipher_name_pair digest_name_translation_table[] = {
+    { "BLAKE2s256", "BLAKE2S-256"},
+    { "BLAKE2b512", "BLAKE2B-512"},
+    { "RIPEMD160", "RIPEMD-160" },
+    { "SHA224", "SHA2-224"},
+    { "SHA256", "SHA2-256"},
+    { "SHA384", "SHA2-384"},
+    { "SHA512", "SHA2-512"},
+    { "SHA512-224", "SHA2-512/224"},
+    { "SHA512-256", "SHA2-512/256"},
+    { "SHAKE128", "SHAKE-128"},
+    { "SHAKE256", "SHAKE-256"},
+};
+const size_t digest_name_translation_table_count =
+    sizeof(digest_name_translation_table) / sizeof(*digest_name_translation_table);
+
  const char *
  md_kt_name(const EVP_MD *kt)
  {
@@ -989,7 +1011,20 @@ md_kt_name(const EVP_MD *kt)
      {
          return "[null-digest]";
      }
-    return EVP_MD_name(kt);
+
+    const char *name = EVP_MD_name(kt);
+
+    /* Search for a digest name translation */
+    for (size_t i = 0; i < digest_name_translation_table_count; i++)
+    {
+        const cipher_name_pair *pair = &digest_name_translation_table[i];
+        if (!strcmp(name, pair->lib_name))
+        {
+            name = pair->openvpn_name;
+        }
+    }
+
+    return name;
  }
 
  unsigned char
Signature · 1 line
Antonio Quartulli
#5 lore raw
In reply to Arne Schwabe

This is basically the same change as commit 88342ed8277c5797 (master), just without the Big MD Refactoring.

Tested, works :-) - --show-digests shows what to expect (without this patch, ossl 3 builds show "SHA2-256", with this patch, "SHA256"), and so does OCC.

Your patch has been applied to the release/2.5 branch.

commit b158125f67b49149ffd3e2617479fbd27860713c

Author: Arne Schwabe
Date:   Mon May 23 12:35:45 2022 +0200
     Translate OpenSSL 3.0 digest names to OpenSSL 1.1 digest names

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

--
kind regards,

Gert Doering