b6b438
From ed65e74773c0c8d3d3a9c23aa97b93baea31d9ae Mon Sep 17 00:00:00 2001
b6b438
From: Andreas Schneider <asn@samba.org>
b6b438
Date: Mon, 18 Nov 2019 10:24:56 +0100
b6b438
Subject: [PATCH 157/187] s3:winbindd: 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 10499507c4fd91751898696b866ce32b1e38f605)
b6b438
---
b6b438
 source3/winbindd/winbindd_cache.c | 23 ++++++++++++++++++++++-
b6b438
 1 file changed, 22 insertions(+), 1 deletion(-)
b6b438
b6b438
diff --git a/source3/winbindd/winbindd_cache.c b/source3/winbindd/winbindd_cache.c
b6b438
index 394b0c774a9..3e7afdaa546 100644
b6b438
--- a/source3/winbindd/winbindd_cache.c
b6b438
+++ b/source3/winbindd/winbindd_cache.c
b6b438
@@ -37,6 +37,9 @@
b6b438
 #include "libsmb/samlogon_cache.h"
b6b438
 #include "lib/namemap_cache.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
@@ -1364,6 +1367,8 @@ NTSTATUS wcache_save_creds(struct winbindd_domain *domain,
b6b438
 	uint32_t rid;
b6b438
 	uint8_t cred_salt[NT_HASH_LEN];
b6b438
 	uint8_t salted_hash[NT_HASH_LEN];
b6b438
+	gnutls_hash_hd_t hash_hnd = NULL;
b6b438
+	int rc;
b6b438
 
b6b438
 	if (is_null_sid(sid)) {
b6b438
 		return NT_STATUS_INVALID_SID;
b6b438
@@ -1384,7 +1389,23 @@ NTSTATUS wcache_save_creds(struct winbindd_domain *domain,
b6b438
 
b6b438
 	/* Create a salt and then salt the hash. */
b6b438
 	generate_random_buffer(cred_salt, NT_HASH_LEN);
b6b438
-	E_md5hash(cred_salt, nt_pass, salted_hash);
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, cred_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, 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
 	centry_put_hash16(centry, salted_hash);
b6b438
 	centry_put_hash16(centry, cred_salt);
b6b438
-- 
b6b438
2.23.0
b6b438