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