Blame SOURCES/net-snmp-5.9-ECC-cert.patch

bc6b3f
From a1968db524e087a36a19a351b89bf6f1633819aa Mon Sep 17 00:00:00 2001
bc6b3f
From: minfrin <minfrin@users.noreply.github.com>
bc6b3f
Date: Tue, 5 Jan 2021 23:17:14 +0000
bc6b3f
Subject: [PATCH] Add support for digests detected from ECC certificates
bc6b3f
bc6b3f
Previously, the digest could be detected on RSA certificates only. This
bc6b3f
patch adds detection for ECC certificates.
bc6b3f
bc6b3f
[ bvanassche: changed _htmap2 into a two-dimensional array and renamed _htmap2
bc6b3f
  back to _htmap ]
bc6b3f
---
bc6b3f
 snmplib/snmp_openssl.c | 60 +++++++++++++++++++++++++++++++++++-------
bc6b3f
 1 file changed, 50 insertions(+), 10 deletions(-)
bc6b3f
bc6b3f
diff --git a/snmplib/snmp_openssl.c b/snmplib/snmp_openssl.c
bc6b3f
index c092a007a..432cb5c27 100644
bc6b3f
--- a/snmplib/snmp_openssl.c
bc6b3f
+++ b/snmplib/snmp_openssl.c
bc6b3f
@@ -521,18 +521,54 @@ netsnmp_openssl_cert_dump_extensions(X509 *ocert)
bc6b3f
     }
bc6b3f
 }
bc6b3f
 
bc6b3f
-static int _htmap[NS_HASH_MAX + 1] = {
bc6b3f
-    0, NID_md5WithRSAEncryption, NID_sha1WithRSAEncryption,
bc6b3f
-    NID_sha224WithRSAEncryption, NID_sha256WithRSAEncryption,
bc6b3f
-    NID_sha384WithRSAEncryption, NID_sha512WithRSAEncryption };
bc6b3f
+static const struct {
bc6b3f
+    uint16_t nid;
bc6b3f
+    uint16_t ht;
bc6b3f
+} _htmap[] = {
bc6b3f
+    { 0, NS_HASH_NONE },
bc6b3f
+#ifdef NID_md5WithRSAEncryption
bc6b3f
+    { NID_md5WithRSAEncryption, NS_HASH_MD5 },
bc6b3f
+#endif
bc6b3f
+#ifdef NID_sha1WithRSAEncryption
bc6b3f
+    { NID_sha1WithRSAEncryption, NS_HASH_SHA1 },
bc6b3f
+#endif
bc6b3f
+#ifdef NID_ecdsa_with_SHA1
bc6b3f
+    { NID_ecdsa_with_SHA1, NS_HASH_SHA1 },
bc6b3f
+#endif
bc6b3f
+#ifdef NID_sha224WithRSAEncryption
bc6b3f
+    { NID_sha224WithRSAEncryption, NS_HASH_SHA224 },
bc6b3f
+#endif
bc6b3f
+#ifdef NID_ecdsa_with_SHA224
bc6b3f
+    { NID_ecdsa_with_SHA224, NS_HASH_SHA224 },
bc6b3f
+#endif
bc6b3f
+#ifdef NID_sha256WithRSAEncryption
bc6b3f
+    { NID_sha256WithRSAEncryption, NS_HASH_SHA256 },
bc6b3f
+#endif
bc6b3f
+#ifdef NID_ecdsa_with_SHA256
bc6b3f
+    { NID_ecdsa_with_SHA256, NS_HASH_SHA256 },
bc6b3f
+#endif
bc6b3f
+#ifdef NID_sha384WithRSAEncryption
bc6b3f
+    { NID_sha384WithRSAEncryption, NS_HASH_SHA384 },
bc6b3f
+#endif
bc6b3f
+#ifdef NID_ecdsa_with_SHA384
bc6b3f
+    { NID_ecdsa_with_SHA384, NS_HASH_SHA384 },
bc6b3f
+#endif
bc6b3f
+#ifdef NID_sha512WithRSAEncryption
bc6b3f
+    { NID_sha512WithRSAEncryption, NS_HASH_SHA512 },
bc6b3f
+#endif
bc6b3f
+#ifdef NID_ecdsa_with_SHA512
bc6b3f
+    { NID_ecdsa_with_SHA512, NS_HASH_SHA512 },
bc6b3f
+#endif
bc6b3f
+};
bc6b3f
 
bc6b3f
 int
bc6b3f
 _nid2ht(int nid)
bc6b3f
 {
bc6b3f
     int i;
bc6b3f
-    for (i=1; i<= NS_HASH_MAX; ++i) {
bc6b3f
-        if (nid == _htmap[i])
bc6b3f
-            return i;
bc6b3f
+
bc6b3f
+    for (i = 0; i < sizeof(_htmap) / sizeof(_htmap[0]); i++) {
bc6b3f
+        if (_htmap[i].nid == nid)
bc6b3f
+            return _htmap[i].ht;
bc6b3f
     }
bc6b3f
     return 0;
bc6b3f
 }
bc6b3f
@@ -541,9 +577,13 @@ _nid2ht(int nid)
bc6b3f
 int
bc6b3f
 _ht2nid(int ht)
bc6b3f
 {
bc6b3f
-    if ((ht < 0) || (ht > NS_HASH_MAX))
bc6b3f
-        return 0;
bc6b3f
-    return _htmap[ht];
bc6b3f
+    int i;
bc6b3f
+
bc6b3f
+    for (i = 0; i < sizeof(_htmap) / sizeof(_htmap[0]); i++) {
bc6b3f
+        if (_htmap[i].ht == ht)
bc6b3f
+            return _htmap[i].nid;
bc6b3f
+    }
bc6b3f
+    return 0;
bc6b3f
 }
bc6b3f
 #endif /* NETSNMP_FEATURE_REMOVE_OPENSSL_HT2NID */
bc6b3f
 
bc6b3f