b6b438
From 89693b474a37c393ceb47afd668e8a96282a98b0 Mon Sep 17 00:00:00 2001
b6b438
From: Andreas Schneider <asn@samba.org>
b6b438
Date: Mon, 18 Nov 2019 10:28:59 +0100
b6b438
Subject: [PATCH 158/187] s3:winbind: Replace E_md5hash() with GnuTLS calls
b6b438
b6b438
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14195
b6b438
b6b438
Signed-off-by: Andreas Schneider <asn@samba.org>
b6b438
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
b6b438
(cherry picked from commit 4199d1040f09b5d95522d0cbdbaeec78b7d7b9a6)
b6b438
---
b6b438
 source3/winbindd/winbindd_pam.c | 23 ++++++++++++++++++++++-
b6b438
 1 file changed, 22 insertions(+), 1 deletion(-)
b6b438
b6b438
diff --git a/source3/winbindd/winbindd_pam.c b/source3/winbindd/winbindd_pam.c
b6b438
index c5b7c09b5c1..8946dd70f99 100644
b6b438
--- a/source3/winbindd/winbindd_pam.c
b6b438
+++ b/source3/winbindd/winbindd_pam.c
b6b438
@@ -48,6 +48,9 @@
b6b438
 #include "param/param.h"
b6b438
 #include "messaging/messaging.h"
b6b438
 
b6b438
+#include "lib/crypto/gnutls_helpers.h"
b6b438
+#include <gnutls/crypto.h>
b6b438
+
b6b438
 #undef DBGC_CLASS
b6b438
 #define DBGC_CLASS DBGC_WINBIND
b6b438
 
b6b438
@@ -1086,7 +1089,25 @@ static NTSTATUS winbindd_dual_pam_auth_cached(struct winbindd_domain *domain,
b6b438
 		/* In this case we didn't store the nt_hash itself,
b6b438
 		   but the MD5 combination of salt + nt_hash. */
b6b438
 		uchar salted_hash[NT_HASH_LEN];
b6b438
-		E_md5hash(cached_salt, new_nt_pass, salted_hash);
b6b438
+		gnutls_hash_hd_t hash_hnd = NULL;
b6b438
+		int rc;
b6b438
+
b6b438
+		rc = gnutls_hash_init(&hash_hnd, GNUTLS_DIG_MD5);
b6b438
+		if (rc < 0) {
b6b438
+			return gnutls_error_to_ntstatus(rc, NT_STATUS_HASH_NOT_SUPPORTED);
b6b438
+		}
b6b438
+
b6b438
+		rc = gnutls_hash(hash_hnd, cached_salt, 16);
b6b438
+		if (rc < 0) {
b6b438
+			gnutls_hash_deinit(hash_hnd, NULL);
b6b438
+			return gnutls_error_to_ntstatus(rc, NT_STATUS_HASH_NOT_SUPPORTED);
b6b438
+		}
b6b438
+		rc = gnutls_hash(hash_hnd, new_nt_pass, 16);
b6b438
+		if (rc < 0) {
b6b438
+			gnutls_hash_deinit(hash_hnd, NULL);
b6b438
+			return gnutls_error_to_ntstatus(rc, NT_STATUS_HASH_NOT_SUPPORTED);
b6b438
+		}
b6b438
+		gnutls_hash_deinit(hash_hnd, salted_hash);
b6b438
 
b6b438
 		password_good = (memcmp(cached_nt_pass, salted_hash,
b6b438
 					NT_HASH_LEN) == 0);
b6b438
-- 
b6b438
2.23.0
b6b438