1524bc
From 752f6efc6ac65cba6b8ebf125b19a6685a0d40c2 Mon Sep 17 00:00:00 2001
1524bc
From: Andreas Schneider <asn@samba.org>
1524bc
Date: Wed, 24 Jul 2019 16:49:53 +0200
1524bc
Subject: [PATCH 045/187] s4:torture: Use GnuTLS RC4 in
1524bc
 test_OemChangePasswordUser2
1524bc
1524bc
This uses STR_ASCII for password encoding!
1524bc
1524bc
Signed-off-by: Andreas Schneider <asn@samba.org>
1524bc
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
1524bc
(cherry picked from commit b512b5974494fe41010800f60df0f248b8ea850e)
1524bc
---
1524bc
 source4/torture/rpc/samr.c | 34 ++++++++++++++++++++++++++++++----
1524bc
 1 file changed, 30 insertions(+), 4 deletions(-)
1524bc
1524bc
diff --git a/source4/torture/rpc/samr.c b/source4/torture/rpc/samr.c
1524bc
index 530c457bbd9..eb032905dc8 100644
1524bc
--- a/source4/torture/rpc/samr.c
1524bc
+++ b/source4/torture/rpc/samr.c
1524bc
@@ -2032,6 +2032,11 @@ static bool test_OemChangePasswordUser2(struct dcerpc_pipe *p,
1524bc
 	char *newpass;
1524bc
 	struct dcerpc_binding_handle *b = p->binding_handle;
1524bc
 	uint8_t old_lm_hash[16], new_lm_hash[16];
1524bc
+	gnutls_cipher_hd_t cipher_hnd = NULL;
1524bc
+	gnutls_datum_t session_key = {
1524bc
+		.data = old_lm_hash,
1524bc
+		.size = 16
1524bc
+	};
1524bc
 
1524bc
 	struct samr_GetDomPwInfo dom_pw_info;
1524bc
 	struct samr_PwInfo info;
1524bc
@@ -2065,7 +2070,13 @@ static bool test_OemChangePasswordUser2(struct dcerpc_pipe *p,
1524bc
 	E_deshash(newpass, new_lm_hash);
1524bc
 
1524bc
 	encode_pw_buffer(lm_pass.data, newpass, STR_ASCII);
1524bc
-	arcfour_crypt(lm_pass.data, old_lm_hash, 516);
1524bc
+
1524bc
+	gnutls_cipher_init(&cipher_hnd,
1524bc
+			   GNUTLS_CIPHER_ARCFOUR_128,
1524bc
+			   &session_key,
1524bc
+			   NULL);
1524bc
+	gnutls_cipher_encrypt(cipher_hnd, lm_pass.data, 516);
1524bc
+	gnutls_cipher_deinit(cipher_hnd);
1524bc
 	E_old_pw_hash(new_lm_hash, old_lm_hash, lm_verifier.hash);
1524bc
 
1524bc
 	r.in.server = &server;
1524bc
@@ -2092,7 +2103,12 @@ static bool test_OemChangePasswordUser2(struct dcerpc_pipe *p,
1524bc
 	encode_pw_buffer(lm_pass.data, newpass, STR_ASCII);
1524bc
 	/* Break the old password */
1524bc
 	old_lm_hash[0]++;
1524bc
-	arcfour_crypt(lm_pass.data, old_lm_hash, 516);
1524bc
+	gnutls_cipher_init(&cipher_hnd,
1524bc
+			   GNUTLS_CIPHER_ARCFOUR_128,
1524bc
+			   &session_key,
1524bc
+			   NULL);
1524bc
+	gnutls_cipher_encrypt(cipher_hnd, lm_pass.data, 516);
1524bc
+	gnutls_cipher_deinit(cipher_hnd);
1524bc
 	/* unbreak it for the next operation */
1524bc
 	old_lm_hash[0]--;
1524bc
 	E_old_pw_hash(new_lm_hash, old_lm_hash, lm_verifier.hash);
1524bc
@@ -2116,7 +2132,12 @@ static bool test_OemChangePasswordUser2(struct dcerpc_pipe *p,
1524bc
 	}
1524bc
 
1524bc
 	encode_pw_buffer(lm_pass.data, newpass, STR_ASCII);
1524bc
-	arcfour_crypt(lm_pass.data, old_lm_hash, 516);
1524bc
+	gnutls_cipher_init(&cipher_hnd,
1524bc
+			   GNUTLS_CIPHER_ARCFOUR_128,
1524bc
+			   &session_key,
1524bc
+			   NULL);
1524bc
+	gnutls_cipher_encrypt(cipher_hnd, lm_pass.data, 516);
1524bc
+	gnutls_cipher_deinit(cipher_hnd);
1524bc
 
1524bc
 	r.in.server = &server;
1524bc
 	r.in.account = &account;
1524bc
@@ -2192,7 +2213,12 @@ static bool test_OemChangePasswordUser2(struct dcerpc_pipe *p,
1524bc
 	E_deshash(newpass, new_lm_hash);
1524bc
 
1524bc
 	encode_pw_buffer(lm_pass.data, newpass, STR_ASCII);
1524bc
-	arcfour_crypt(lm_pass.data, old_lm_hash, 516);
1524bc
+	gnutls_cipher_init(&cipher_hnd,
1524bc
+			   GNUTLS_CIPHER_ARCFOUR_128,
1524bc
+			   &session_key,
1524bc
+			   NULL);
1524bc
+	gnutls_cipher_encrypt(cipher_hnd, lm_pass.data, 516);
1524bc
+	gnutls_cipher_deinit(cipher_hnd);
1524bc
 	E_old_pw_hash(new_lm_hash, old_lm_hash, lm_verifier.hash);
1524bc
 
1524bc
 	r.in.server = &server;
1524bc
-- 
1524bc
2.23.0
1524bc