27025e
From 83b889c238282b210f874a3ad81bb56299767495 Mon Sep 17 00:00:00 2001
27025e
From: Petr Mensik <pemensik@redhat.com>
27025e
Date: Mon, 5 Aug 2019 11:54:03 +0200
27025e
Subject: [PATCH] Allow explicit disabling of autodisabled MD5
27025e
27025e
Default security policy might include explicitly disabled RSAMD5
27025e
algorithm. Current FIPS code automatically disables in FIPS mode. But if
27025e
RSAMD5 is included in security policy, it fails to start, because that
27025e
algorithm is not recognized. Allow it disabled, but fail on any
27025e
other usage.
27025e
---
27025e
 bin/named/server.c |  4 ++--
27025e
 lib/bind9/check.c  |  4 ++++
27025e
 lib/dns/rcode.c    | 33 +++++++++++++++------------------
27025e
 3 files changed, 21 insertions(+), 20 deletions(-)
27025e
27025e
diff --git a/bin/named/server.c b/bin/named/server.c
27025e
index 5b57371..51702ab 100644
27025e
--- a/bin/named/server.c
27025e
+++ b/bin/named/server.c
27025e
@@ -1547,12 +1547,12 @@ disable_algorithms(const cfg_obj_t *disabled, dns_resolver_t *resolver) {
27025e
 		r.length = strlen(r.base);
27025e
 
27025e
 		result = dns_secalg_fromtext(&alg, &r);
27025e
-		if (result != ISC_R_SUCCESS) {
27025e
+		if (result != ISC_R_SUCCESS && result != ISC_R_DISABLED) {
27025e
 			uint8_t ui;
27025e
 			result = isc_parse_uint8(&ui, r.base, 10);
27025e
 			alg = ui;
27025e
 		}
27025e
-		if (result != ISC_R_SUCCESS) {
27025e
+		if (result != ISC_R_SUCCESS && result != ISC_R_DISABLED) {
27025e
 			cfg_obj_log(cfg_listelt_value(element),
27025e
 				    ns_g_lctx, ISC_LOG_ERROR,
27025e
 				    "invalid algorithm");
27025e
diff --git a/lib/bind9/check.c b/lib/bind9/check.c
27025e
index e0803d4..8023784 100644
27025e
--- a/lib/bind9/check.c
27025e
+++ b/lib/bind9/check.c
27025e
@@ -302,6 +302,10 @@ disabled_algorithms(const cfg_obj_t *disabled, isc_log_t *logctx) {
27025e
 		r.length = strlen(r.base);
27025e
 
27025e
 		tresult = dns_secalg_fromtext(&alg, &r);
27025e
+		if (tresult == ISC_R_DISABLED) {
27025e
+			// Recognize disabled algorithms, disable it explicitly
27025e
+			tresult = ISC_R_SUCCESS;
27025e
+		}
27025e
 		if (tresult != ISC_R_SUCCESS) {
27025e
 			cfg_obj_log(cfg_listelt_value(element), logctx,
27025e
 				    ISC_LOG_ERROR, "invalid algorithm '%s'",
27025e
diff --git a/lib/dns/rcode.c b/lib/dns/rcode.c
27025e
index f51d548..c49b8d1 100644
27025e
--- a/lib/dns/rcode.c
27025e
+++ b/lib/dns/rcode.c
27025e
@@ -126,7 +126,6 @@
27025e
 #endif
27025e
 
27025e
 #define SECALGNAMES \
27025e
-	MD5_SECALGNAMES \
27025e
 	DH_SECALGNAMES \
27025e
 	DSA_SECALGNAMES \
27025e
 	{ DNS_KEYALG_ECC, "ECC", 0 }, \
27025e
@@ -178,6 +177,7 @@ static struct tbl rcodes[] = { RCODENAMES ERCODENAMES };
27025e
 static struct tbl tsigrcodes[] = { RCODENAMES TSIGRCODENAMES };
27025e
 static struct tbl certs[] = { CERTNAMES };
27025e
 static struct tbl secalgs[] = { SECALGNAMES };
27025e
+static struct tbl md5_secalgs[] = { MD5_SECALGNAMES };
27025e
 static struct tbl secprotos[] = { SECPROTONAMES };
27025e
 static struct tbl hashalgs[] = { HASHALGNAMES };
27025e
 static struct tbl dsdigests[] = { DSDIGESTNAMES };
27025e
@@ -358,33 +358,30 @@ dns_cert_totext(dns_cert_t cert, isc_buffer_t *target) {
27025e
 	return (dns_mnemonic_totext(cert, target, certs));
27025e
 }
27025e
 
27025e
-static inline struct tbl *
27025e
-secalgs_tbl_start() {
27025e
-	struct tbl *algs = secalgs;
27025e
-
27025e
-#ifndef PK11_MD5_DISABLE
27025e
-	if (!isc_md5_available()) {
27025e
-		while (algs->name != NULL &&
27025e
-		       algs->value == DNS_KEYALG_RSAMD5)
27025e
-			++algs;
27025e
-	}
27025e
-#endif
27025e
-	return algs;
27025e
-}
27025e
-
27025e
 isc_result_t
27025e
 dns_secalg_fromtext(dns_secalg_t *secalgp, isc_textregion_t *source) {
27025e
 	unsigned int value;
27025e
+	isc_result_t result;
27025e
 
27025e
-	RETERR(dns_mnemonic_fromtext(&value, source,
27025e
-	                             secalgs_tbl_start(), 0xff));
27025e
+	result = dns_mnemonic_fromtext(&value, source,
27025e
+	                               secalgs, 0xff);
27025e
+	if (result != ISC_R_SUCCESS) {
27025e
+		result = dns_mnemonic_fromtext(&value, source,
27025e
+	                                       md5_secalgs, 0xff);
27025e
+		if (result != ISC_R_SUCCESS) {
27025e
+			return (result);
27025e
+		} else if (!isc_md5_available()) {
27025e
+			*secalgp = value;
27025e
+			return (ISC_R_DISABLED);
27025e
+		}
27025e
+	}
27025e
 	*secalgp = value;
27025e
 	return (ISC_R_SUCCESS);
27025e
 }
27025e
 
27025e
 isc_result_t
27025e
 dns_secalg_totext(dns_secalg_t secalg, isc_buffer_t *target) {
27025e
-	return (dns_mnemonic_totext(secalg, target, secalgs_tbl_start()));
27025e
+	return (dns_mnemonic_totext(secalg, target, secalgs));
27025e
 }
27025e
 
27025e
 void
27025e
-- 
27025e
2.20.1
27025e