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