1524bc
From 0d2898429e7eb2ca144885d5a1f9485cca620464 Mon Sep 17 00:00:00 2001
1524bc
From: Andreas Schneider <asn@samba.org>
1524bc
Date: Mon, 8 Jul 2019 18:21:18 +0200
1524bc
Subject: [PATCH 028/187] libcli:auth: Use
1524bc
 samba_gnutls_arcfour_confounded_md5() in decode_wkssvc_join_password_buffer()
1524bc
1524bc
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14031
1524bc
1524bc
Signed-off-by: Andreas Schneider <asn@samba.org>
1524bc
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
1524bc
(cherry picked from commit bcf7808d3aa8a5932a40955e4b764f55061e07d7)
1524bc
---
1524bc
 libcli/auth/smbencrypt.c | 71 ++++++++++++++--------------------------
1524bc
 1 file changed, 24 insertions(+), 47 deletions(-)
1524bc
1524bc
diff --git a/libcli/auth/smbencrypt.c b/libcli/auth/smbencrypt.c
1524bc
index 823e16a3387..cc5e1fbb899 100644
1524bc
--- a/libcli/auth/smbencrypt.c
1524bc
+++ b/libcli/auth/smbencrypt.c
1524bc
@@ -1011,70 +1011,47 @@ WERROR decode_wkssvc_join_password_buffer(TALLOC_CTX *mem_ctx,
1524bc
 					  DATA_BLOB *session_key,
1524bc
 					  char **pwd)
1524bc
 {
1524bc
-	gnutls_hash_hd_t hash_hnd = NULL;
1524bc
-	uint8_t buffer[516];
1524bc
-	size_t pwd_len;
1524bc
-	WERROR result;
1524bc
+	uint8_t _confounder[8];
1524bc
+	DATA_BLOB confounder = data_blob_const(_confounder, 8);
1524bc
+	uint8_t pwbuf[516] = {0};
1524bc
+	DATA_BLOB decrypt_pwbuf = data_blob_const(pwbuf, 516);
1524bc
 	bool ok;
1524bc
 	int rc;
1524bc
 
1524bc
-	DATA_BLOB confounded_session_key;
1524bc
-
1524bc
-	int confounder_len = 8;
1524bc
-	uint8_t confounder[8];
1524bc
-
1524bc
-	*pwd = NULL;
1524bc
-
1524bc
-	if (!pwd_buf) {
1524bc
+	if (pwd_buf == NULL) {
1524bc
 		return WERR_INVALID_PASSWORD;
1524bc
 	}
1524bc
 
1524bc
+	*pwd = NULL;
1524bc
+
1524bc
 	if (session_key->length != 16) {
1524bc
 		DEBUG(10,("invalid session key\n"));
1524bc
 		return WERR_INVALID_PASSWORD;
1524bc
 	}
1524bc
 
1524bc
-	confounded_session_key = data_blob_talloc(mem_ctx, NULL, 16);
1524bc
+	confounder = data_blob_const(&pwd_buf->data[0], 8);
1524bc
+	memcpy(&pwbuf, &pwd_buf->data[8], 516);
1524bc
 
1524bc
-	memcpy(&confounder, &pwd_buf->data[0], confounder_len);
1524bc
-	memcpy(&buffer, &pwd_buf->data[8], 516);
1524bc
-
1524bc
-	rc = gnutls_hash_init(&hash_hnd, GNUTLS_DIG_MD5);
1524bc
-	if (rc < 0) {
1524bc
-		result = gnutls_error_to_werror(rc, WERR_CONTENT_BLOCKED);
1524bc
-		goto out;
1524bc
-	}
1524bc
-
1524bc
-	rc = gnutls_hash(hash_hnd, session_key->data, session_key->length);
1524bc
-	if (rc < 0) {
1524bc
-		gnutls_hash_deinit(hash_hnd, NULL);
1524bc
-		result = gnutls_error_to_werror(rc, WERR_CONTENT_BLOCKED);
1524bc
-		goto out;
1524bc
-	}
1524bc
-	rc = gnutls_hash(hash_hnd, confounder, confounder_len);
1524bc
+	rc = samba_gnutls_arcfour_confounded_md5(session_key,
1524bc
+						 &confounder,
1524bc
+						 &decrypt_pwbuf,
1524bc
+						 SAMBA_GNUTLS_ENCRYPT);
1524bc
 	if (rc < 0) {
1524bc
-		gnutls_hash_deinit(hash_hnd, NULL);
1524bc
-		result = gnutls_error_to_werror(rc, WERR_CONTENT_BLOCKED);
1524bc
-		goto out;
1524bc
+		ZERO_ARRAY(_confounder);
1524bc
+		TALLOC_FREE(pwd_buf);
1524bc
+		return gnutls_error_to_werror(rc, WERR_CONTENT_BLOCKED);
1524bc
 	}
1524bc
-	gnutls_hash_deinit(hash_hnd, confounded_session_key.data);
1524bc
 
1524bc
-	arcfour_crypt_blob(buffer, 516, &confounded_session_key);
1524bc
-
1524bc
-	ok = decode_pw_buffer(mem_ctx, buffer, pwd, &pwd_len, CH_UTF16);
1524bc
-
1524bc
-	ZERO_ARRAY(confounder);
1524bc
-	ZERO_ARRAY(buffer);
1524bc
-
1524bc
-	data_blob_clear_free(&confounded_session_key);
1524bc
+	ok = decode_pw_buffer(mem_ctx,
1524bc
+			      decrypt_pwbuf.data,
1524bc
+			      pwd,
1524bc
+			      &decrypt_pwbuf.length,
1524bc
+			      CH_UTF16);
1524bc
+	ZERO_ARRAY(pwbuf);
1524bc
 
1524bc
 	if (!ok) {
1524bc
-		result = WERR_INVALID_PASSWORD;
1524bc
-		goto out;
1524bc
+		return WERR_INVALID_PASSWORD;
1524bc
 	}
1524bc
 
1524bc
-	result = WERR_OK;
1524bc
-out:
1524bc
-	return result;
1524bc
+	return WERR_OK;
1524bc
 }
1524bc
-
1524bc
-- 
1524bc
2.23.0
1524bc