Skip to content

Commit 694b386

Browse files
nielsbbvanassche
authored andcommitted
Fix matching of certs by using SHA1 fingerprints.
PR#278 changed default for certs to SHA512, but now matching certs fails. Change the fingerprint reuqests to use SHA1 explicit.
1 parent e5d60f0 commit 694b386

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

snmplib/cert_util.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,7 +1040,7 @@ netsnmp_ocert_get(netsnmp_cert *cert)
10401040
}
10411041

10421042
if (NULL == cert->fingerprint) {
1043-
cert->hash_type = netsnmp_openssl_cert_get_hash_type(ocert);
1043+
cert->hash_type = NS_HASH_SHA1;
10441044
cert->fingerprint =
10451045
netsnmp_openssl_cert_get_fingerprint(ocert, cert->hash_type);
10461046
}
@@ -2061,7 +2061,7 @@ netsnmp_cert_trust(SSL_CTX *ctx, netsnmp_cert *thiscert)
20612061
SNMPERR_GENERR);
20622062

20632063
/* Put the certificate into the store */
2064-
fingerprint = netsnmp_openssl_cert_get_fingerprint(cert, -1);
2064+
fingerprint = netsnmp_openssl_cert_get_fingerprint(cert, NS_HASH_SHA1);
20652065
DEBUGMSGTL(("cert:trust",
20662066
"putting trusted cert %p = %s in certstore %p\n", cert,
20672067
fingerprint, certstore));
@@ -2769,7 +2769,7 @@ netsnmp_certToTSN_parse_common(char **line)
27692769
map->fingerprint = strdup(buf);
27702770
} else {
27712771
map->fingerprint =
2772-
netsnmp_openssl_cert_get_fingerprint(tmpcert->ocert, -1);
2772+
netsnmp_openssl_cert_get_fingerprint(tmpcert->ocert, NS_HASH_SHA1);
27732773
}
27742774

27752775
if (NULL == *line) {

snmplib/snmp_openssl.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
*/
1313

1414
#include <net-snmp/net-snmp-config.h>
15+
#include <net-snmp/library/openssl_config.h>
1516

1617
#include <net-snmp/net-snmp-includes.h>
1718

@@ -21,7 +22,6 @@
2122
#if defined(NETSNMP_USE_OPENSSL)
2223

2324
#include <string.h>
24-
#include <net-snmp/library/openssl_config.h>
2525
#include <openssl/dh.h>
2626

2727
#ifndef HAVE_DH_GET0_PQG
@@ -711,7 +711,7 @@ netsnmp_openssl_get_cert_chain(SSL *ssl)
711711
/*
712712
* get fingerprint and save it
713713
*/
714-
fingerprint = netsnmp_openssl_cert_get_fingerprint(ocert, -1);
714+
fingerprint = netsnmp_openssl_cert_get_fingerprint(ocert, NS_HASH_SHA1);
715715
if (NULL == fingerprint)
716716
return NULL;
717717

@@ -749,7 +749,7 @@ netsnmp_openssl_get_cert_chain(SSL *ssl)
749749
sk_num_res = sk_num((const void *)ochain);
750750
for(i = 0; i < sk_num_res; ++i) {
751751
ocert_tmp = (X509*)sk_value((const void *)ochain,i);
752-
fingerprint = netsnmp_openssl_cert_get_fingerprint(ocert_tmp, -1);
752+
fingerprint = netsnmp_openssl_cert_get_fingerprint(ocert_tmp, NS_HASH_SHA1);
753753
if (NULL == fingerprint)
754754
break;
755755
cert_map = netsnmp_cert_map_alloc(NULL, ocert);

snmplib/transports/snmpTLSBaseDomain.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ int verify_callback(int ok, X509_STORE_CTX *ctx) {
8181
/* things to do: */
8282

8383
X509_NAME_oneline(X509_get_subject_name(thecert), buf, sizeof(buf));
84-
fingerprint = netsnmp_openssl_cert_get_fingerprint(thecert, -1);
84+
fingerprint = netsnmp_openssl_cert_get_fingerprint(thecert, NS_HASH_SHA1);
8585
DEBUGMSGTL(("tls_x509:verify", "Cert: %s\n", buf));
8686
DEBUGMSGTL(("tls_x509:verify", " fp: %s\n", fingerprint ?
8787
fingerprint : "unknown"));
@@ -160,7 +160,7 @@ _netsnmp_tlsbase_verify_remote_fingerprint(X509 *remote_cert,
160160
char *fingerprint;
161161

162162
fingerprint =
163-
netsnmp_openssl_cert_get_fingerprint(remote_cert, -1);
163+
netsnmp_openssl_cert_get_fingerprint(remote_cert, NS_HASH_SHA1);
164164

165165
if (!fingerprint) {
166166
/* no peer cert */
@@ -177,7 +177,7 @@ _netsnmp_tlsbase_verify_remote_fingerprint(X509 *remote_cert,
177177

178178
if (peer_cert)
179179
tlsdata->their_fingerprint =
180-
netsnmp_openssl_cert_get_fingerprint(peer_cert->ocert, -1);
180+
netsnmp_openssl_cert_get_fingerprint(peer_cert->ocert, NS_HASH_SHA1);
181181
}
182182

183183
if (!tlsdata->their_fingerprint && try_default) {
@@ -189,7 +189,7 @@ _netsnmp_tlsbase_verify_remote_fingerprint(X509 *remote_cert,
189189

190190
if (peer_cert)
191191
tlsdata->their_fingerprint =
192-
netsnmp_openssl_cert_get_fingerprint(peer_cert->ocert, -1);
192+
netsnmp_openssl_cert_get_fingerprint(peer_cert->ocert, NS_HASH_SHA1);
193193
}
194194

195195
if (tlsdata->their_fingerprint) {

0 commit comments

Comments
 (0)