1524bc
From 0f56ee5720764eec28ce23bc82a01c16411df5fb Mon Sep 17 00:00:00 2001
1524bc
From: Andrew Bartlett <abartlet@samba.org>
1524bc
Date: Thu, 25 Jul 2019 13:07:48 +1200
1524bc
Subject: [PATCH 054/187] s4:torture: Use samba_gnutls_arcfour_confounded_md5()
1524bc
 in test_ChangePasswordRandomBytes
1524bc
1524bc
This ensures GnuTLS is used as the underlying RC4 crypto engine
1524bc
1524bc
Signed-off-by: Andrew Bartlett <abartlet@samba.org>
1524bc
Reviewed-by: Andreas Schneider <asn@samba.org>
1524bc
(cherry picked from commit 5740e9516f3587e3a9f72cf52cfe1eedd940b2a9)
1524bc
---
1524bc
 source4/torture/rpc/samr.c | 25 +++++++++++++++----------
1524bc
 1 file changed, 15 insertions(+), 10 deletions(-)
1524bc
1524bc
diff --git a/source4/torture/rpc/samr.c b/source4/torture/rpc/samr.c
1524bc
index 10bdd52fd47..4b3ad093bf6 100644
1524bc
--- a/source4/torture/rpc/samr.c
1524bc
+++ b/source4/torture/rpc/samr.c
1524bc
@@ -42,6 +42,7 @@
1524bc
 #include "torture/util.h"
1524bc
 #include "source4/librpc/rpc/dcerpc.h"
1524bc
 #include "source3/rpc_client/init_samr.h"
1524bc
+#include "lib/crypto/gnutls_helpers.h"
1524bc
 
1524bc
 #define TEST_ACCOUNT_NAME "samrtorturetest"
1524bc
 #define TEST_ACCOUNT_NAME_PWD "samrpwdlastset"
1524bc
@@ -2777,9 +2778,6 @@ bool test_ChangePasswordRandomBytes(struct dcerpc_pipe *p, struct torture_contex
1524bc
 	struct samr_SetUserInfo s;
1524bc
 	union samr_UserInfo u;
1524bc
 	DATA_BLOB session_key;
1524bc
-	DATA_BLOB confounded_session_key = data_blob_talloc(tctx, NULL, 16);
1524bc
-	uint8_t confounder[16];
1524bc
-	gnutls_hash_hd_t hash_hnd;
1524bc
 
1524bc
 	bool ret = true;
1524bc
 	struct lsa_String server, account;
1524bc
@@ -2797,6 +2795,11 @@ bool test_ChangePasswordRandomBytes(struct dcerpc_pipe *p, struct torture_contex
1524bc
 	struct samr_DomInfo1 *dominfo = NULL;
1524bc
 	struct userPwdChangeFailureInformation *reject = NULL;
1524bc
 	gnutls_cipher_hd_t cipher_hnd = NULL;
1524bc
+	uint8_t _confounder[16] = {0};
1524bc
+	DATA_BLOB confounder
1524bc
+		= data_blob_const(_confounder,
1524bc
+				  sizeof(_confounder));
1524bc
+	DATA_BLOB pw_data;
1524bc
 	gnutls_datum_t old_nt_key = {
1524bc
 		.data = old_nt_hash,
1524bc
 		.size = sizeof(old_nt_hash),
1524bc
@@ -2821,6 +2824,8 @@ bool test_ChangePasswordRandomBytes(struct dcerpc_pipe *p, struct torture_contex
1524bc
 
1524bc
 	set_pw_in_buffer(u.info25.password.data, &new_random_pass);
1524bc
 
1524bc
+	pw_data = data_blob_const(u.info25.password.data, 516);
1524bc
+
1524bc
 	status = dcerpc_fetch_session_key(p, &session_key);
1524bc
 	if (!NT_STATUS_IS_OK(status)) {
1524bc
 		torture_result(tctx, TORTURE_FAIL, "SetUserInfo level %u - no session key - %s\n",
1524bc
@@ -2828,15 +2833,15 @@ bool test_ChangePasswordRandomBytes(struct dcerpc_pipe *p, struct torture_contex
1524bc
 		return false;
1524bc
 	}
1524bc
 
1524bc
-	generate_random_buffer((uint8_t *)confounder, 16);
1524bc
+	generate_random_buffer(_confounder,
1524bc
+			       sizeof(_confounder));
1524bc
 
1524bc
-	gnutls_hash_init(&hash_hnd, GNUTLS_DIG_MD5);
1524bc
-	gnutls_hash(hash_hnd, confounder, 16);
1524bc
-	gnutls_hash(hash_hnd, session_key.data, session_key.length);
1524bc
-	gnutls_hash_deinit(hash_hnd, confounded_session_key.data);
1524bc
+	samba_gnutls_arcfour_confounded_md5(&confounder,
1524bc
+					    &session_key,
1524bc
+					    &pw_data,
1524bc
+					    SAMBA_GNUTLS_ENCRYPT);
1524bc
 
1524bc
-	arcfour_crypt_blob(u.info25.password.data, 516, &confounded_session_key);
1524bc
-	memcpy(&u.info25.password.data[516], confounder, 16);
1524bc
+	memcpy(&u.info25.password.data[516], _confounder, sizeof(_confounder));
1524bc
 
1524bc
 	torture_comment(tctx, "Testing SetUserInfo level 25 (set password ex) with a password made up of only random bytes\n");
1524bc
 
1524bc
-- 
1524bc
2.23.0
1524bc