b6b438
From e3c6cd617dc324d86212a50555adbeffb966555c Mon Sep 17 00:00:00 2001
b6b438
From: Andreas Schneider <asn@samba.org>
b6b438
Date: Wed, 24 Jul 2019 16:01:02 +0200
b6b438
Subject: [PATCH 050/187] s4:torture: Use init_samr_CryptPassword in
b6b438
 test_ChangePasswordUser3
b6b438
b6b438
Signed-off-by: Andreas Schneider <asn@samba.org>
b6b438
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
b6b438
(cherry picked from commit 5b7c21fca576bf6e44233d69b47273058b9197c8)
b6b438
---
b6b438
 source4/torture/rpc/samr.c | 64 +++++++++++++++++++++++++++++---------
b6b438
 1 file changed, 49 insertions(+), 15 deletions(-)
b6b438
b6b438
diff --git a/source4/torture/rpc/samr.c b/source4/torture/rpc/samr.c
b6b438
index 307b0b03594..55059a26b43 100644
b6b438
--- a/source4/torture/rpc/samr.c
b6b438
+++ b/source4/torture/rpc/samr.c
b6b438
@@ -2472,6 +2472,8 @@ bool test_ChangePasswordUser3(struct dcerpc_pipe *p, struct torture_context *tct
b6b438
 	NTTIME t;
b6b438
 	struct samr_DomInfo1 *dominfo = NULL;
b6b438
 	struct userPwdChangeFailureInformation *reject = NULL;
b6b438
+	DATA_BLOB session_key = data_blob_const(old_nt_hash, 16);
b6b438
+	NTSTATUS status;
b6b438
 
b6b438
 	torture_comment(tctx, "Testing ChangePasswordUser3\n");
b6b438
 
b6b438
@@ -2500,12 +2502,22 @@ bool test_ChangePasswordUser3(struct dcerpc_pipe *p, struct torture_context *tct
b6b438
 	E_deshash(oldpass, old_lm_hash);
b6b438
 	E_deshash(newpass, new_lm_hash);
b6b438
 
b6b438
-	encode_pw_buffer(lm_pass.data, newpass, STR_UNICODE);
b6b438
-	arcfour_crypt(lm_pass.data, old_nt_hash, 516);
b6b438
+	status = init_samr_CryptPassword(newpass,
b6b438
+					 &session_key,
b6b438
+					 &lm_pass);
b6b438
+	torture_assert_ntstatus_ok(tctx,
b6b438
+				   status,
b6b438
+				   "init_samr_CryptPassword");
b6b438
+
b6b438
 	E_old_pw_hash(new_nt_hash, old_lm_hash, lm_verifier.hash);
b6b438
 
b6b438
-	encode_pw_buffer(nt_pass.data, newpass, STR_UNICODE);
b6b438
-	arcfour_crypt(nt_pass.data, old_nt_hash, 516);
b6b438
+	status = init_samr_CryptPassword(newpass,
b6b438
+					 &session_key,
b6b438
+					 &nt_pass);
b6b438
+	torture_assert_ntstatus_ok(tctx,
b6b438
+				   status,
b6b438
+				   "init_samr_CryptPassword");
b6b438
+
b6b438
 	E_old_pw_hash(new_nt_hash, old_nt_hash, nt_verifier.hash);
b6b438
 
b6b438
 	/* Break the verification */
b6b438
@@ -2534,16 +2546,28 @@ bool test_ChangePasswordUser3(struct dcerpc_pipe *p, struct torture_context *tct
b6b438
 		ret = false;
b6b438
 	}
b6b438
 
b6b438
-	encode_pw_buffer(lm_pass.data, newpass, STR_UNICODE);
b6b438
-	arcfour_crypt(lm_pass.data, old_nt_hash, 516);
b6b438
+	status = init_samr_CryptPassword(newpass,
b6b438
+					 &session_key,
b6b438
+					 &lm_pass);
b6b438
+	torture_assert_ntstatus_ok(tctx,
b6b438
+				   status,
b6b438
+				   "init_samr_CryptPassword");
b6b438
+
b6b438
 	E_old_pw_hash(new_nt_hash, old_lm_hash, lm_verifier.hash);
b6b438
 
b6b438
-	encode_pw_buffer(nt_pass.data, newpass, STR_UNICODE);
b6b438
-	/* Break the NT hash */
b6b438
-	old_nt_hash[0]++;
b6b438
-	arcfour_crypt(nt_pass.data, old_nt_hash, 516);
b6b438
+	/* Break the session key */
b6b438
+	session_key.data[0]++;
b6b438
+
b6b438
+	status = init_samr_CryptPassword(newpass,
b6b438
+					 &session_key,
b6b438
+					 &nt_pass);
b6b438
+	torture_assert_ntstatus_ok(tctx,
b6b438
+				   status,
b6b438
+				   "init_samr_CryptPassword");
b6b438
+
b6b438
 	/* Unbreak it again */
b6b438
-	old_nt_hash[0]--;
b6b438
+	session_key.data[0]--;
b6b438
+
b6b438
 	E_old_pw_hash(new_nt_hash, old_nt_hash, nt_verifier.hash);
b6b438
 
b6b438
 	r.in.server = &server;
b6b438
@@ -2590,12 +2614,22 @@ bool test_ChangePasswordUser3(struct dcerpc_pipe *p, struct torture_context *tct
b6b438
 	E_deshash(oldpass, old_lm_hash);
b6b438
 	E_deshash(newpass, new_lm_hash);
b6b438
 
b6b438
-	encode_pw_buffer(lm_pass.data, newpass, STR_UNICODE);
b6b438
-	arcfour_crypt(lm_pass.data, old_nt_hash, 516);
b6b438
+	status = init_samr_CryptPassword(newpass,
b6b438
+					 &session_key,
b6b438
+					 &lm_pass);
b6b438
+	torture_assert_ntstatus_ok(tctx,
b6b438
+				   status,
b6b438
+				   "init_samr_CryptPassword");
b6b438
+
b6b438
 	E_old_pw_hash(new_nt_hash, old_lm_hash, lm_verifier.hash);
b6b438
 
b6b438
-	encode_pw_buffer(nt_pass.data, newpass, STR_UNICODE);
b6b438
-	arcfour_crypt(nt_pass.data, old_nt_hash, 516);
b6b438
+	status = init_samr_CryptPassword(newpass,
b6b438
+					 &session_key,
b6b438
+					 &nt_pass);
b6b438
+	torture_assert_ntstatus_ok(tctx,
b6b438
+				   status,
b6b438
+				   "init_samr_CryptPassword");
b6b438
+
b6b438
 	E_old_pw_hash(new_nt_hash, old_nt_hash, nt_verifier.hash);
b6b438
 
b6b438
 	r.in.server = &server;
b6b438
-- 
b6b438
2.23.0
b6b438