b6b438
From d56d8f629ea89a9a3cc7aecc17331ac5c57a61fa Mon Sep 17 00:00:00 2001
b6b438
From: Andreas Schneider <asn@samba.org>
b6b438
Date: Wed, 24 Jul 2019 15:58:06 +0200
b6b438
Subject: [PATCH 042/187] s4:torture: Use init_samr_CryptPassword in
b6b438
 test_SetUserPassEx
b6b438
b6b438
Signed-off-by: Andreas Schneider <asn@samba.org>
b6b438
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
b6b438
(cherry picked from commit e398ecbd8e32bb428073f3635d9178abfae28255)
b6b438
---
b6b438
 source4/torture/rpc/samr.c | 33 +++++++++++++++++----------------
b6b438
 1 file changed, 17 insertions(+), 16 deletions(-)
b6b438
b6b438
diff --git a/source4/torture/rpc/samr.c b/source4/torture/rpc/samr.c
b6b438
index 543ef64e9ac..0e9989449be 100644
b6b438
--- a/source4/torture/rpc/samr.c
b6b438
+++ b/source4/torture/rpc/samr.c
b6b438
@@ -781,14 +781,12 @@ static bool test_SetUserPassEx(struct dcerpc_pipe *p, struct torture_context *tc
b6b438
 	union samr_UserInfo u;
b6b438
 	bool ret = true;
b6b438
 	DATA_BLOB session_key;
b6b438
-	DATA_BLOB confounded_session_key = data_blob_talloc(tctx, NULL, 16);
b6b438
-	uint8_t confounder[16];
b6b438
 	char *newpass;
b6b438
 	struct dcerpc_binding_handle *b = p->binding_handle;
b6b438
-	gnutls_hash_hd_t hash_hnd;
b6b438
 	struct samr_GetUserPwInfo pwp;
b6b438
 	struct samr_PwInfo info;
b6b438
 	int policy_min_pw_len = 0;
b6b438
+
b6b438
 	pwp.in.user_handle = handle;
b6b438
 	pwp.out.info = &info;
b6b438
 
b6b438
@@ -807,7 +805,6 @@ static bool test_SetUserPassEx(struct dcerpc_pipe *p, struct torture_context *tc
b6b438
 	s.in.info = &u;
b6b438
 	s.in.level = 26;
b6b438
 
b6b438
-	encode_pw_buffer(u.info26.password.data, newpass, STR_UNICODE);
b6b438
 	u.info26.password_expired = 0;
b6b438
 
b6b438
 	status = dcerpc_fetch_session_key(p, &session_key);
b6b438
@@ -817,15 +814,12 @@ static bool test_SetUserPassEx(struct dcerpc_pipe *p, struct torture_context *tc
b6b438
 		return false;
b6b438
 	}
b6b438
 
b6b438
-	generate_random_buffer((uint8_t *)confounder, 16);
b6b438
-
b6b438
-	gnutls_hash_init(&hash_hnd, GNUTLS_DIG_MD5);
b6b438
-	gnutls_hash(hash_hnd, confounder, 16);
b6b438
-	gnutls_hash(hash_hnd, session_key.data, session_key.length);
b6b438
-	gnutls_hash_deinit(hash_hnd, confounded_session_key.data);
b6b438
-
b6b438
-	arcfour_crypt_blob(u.info26.password.data, 516, &confounded_session_key);
b6b438
-	memcpy(&u.info26.password.data[516], confounder, 16);
b6b438
+	status = init_samr_CryptPasswordEx(newpass,
b6b438
+					   &session_key,
b6b438
+					   &u.info26.password);
b6b438
+	torture_assert_ntstatus_ok(tctx,
b6b438
+				   status,
b6b438
+				   "init_samr_CryptPasswordEx failed");
b6b438
 
b6b438
 	torture_comment(tctx, "Testing SetUserInfo level 26 (set password ex)\n");
b6b438
 
b6b438
@@ -843,10 +837,17 @@ static bool test_SetUserPassEx(struct dcerpc_pipe *p, struct torture_context *tc
b6b438
 	}
b6b438
 
b6b438
 	/* This should break the key nicely */
b6b438
-	confounded_session_key.data[0]++;
b6b438
+	session_key.data[0]++;
b6b438
 
b6b438
-	arcfour_crypt_blob(u.info26.password.data, 516, &confounded_session_key);
b6b438
-	memcpy(&u.info26.password.data[516], confounder, 16);
b6b438
+	status = init_samr_CryptPasswordEx(newpass,
b6b438
+					   &session_key,
b6b438
+					   &u.info26.password);
b6b438
+	torture_assert_ntstatus_ok(tctx,
b6b438
+				   status,
b6b438
+				   "init_samr_CryptPasswordEx failed");
b6b438
+
b6b438
+	/* Reset the key */
b6b438
+	session_key.data[0]--;
b6b438
 
b6b438
 	torture_comment(tctx, "Testing SetUserInfo level 26 (set password ex) with wrong session key\n");
b6b438
 
b6b438
-- 
b6b438
2.23.0
b6b438