1524bc
From 5b0f5925814742ca8b7e772f1a7f4558b770c45b Mon Sep 17 00:00:00 2001
1524bc
From: Andreas Schneider <asn@samba.org>
1524bc
Date: Fri, 1 Feb 2019 13:38:21 +0100
1524bc
Subject: [PATCH 022/187] s4:libnet: Use GnuTLS RC4 in
1524bc
 libnet_SetPassword_samr_handle_24()
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 18937f9ceb5aca23899555c5a34fe359f6fcb126)
1524bc
---
1524bc
 source4/libnet/libnet_passwd.c | 29 ++++++++++++++++++++++++++++-
1524bc
 1 file changed, 28 insertions(+), 1 deletion(-)
1524bc
1524bc
diff --git a/source4/libnet/libnet_passwd.c b/source4/libnet/libnet_passwd.c
1524bc
index b2105121523..064ef98879a 100644
1524bc
--- a/source4/libnet/libnet_passwd.c
1524bc
+++ b/source4/libnet/libnet_passwd.c
1524bc
@@ -386,6 +386,9 @@ static NTSTATUS libnet_SetPassword_samr_handle_24(struct libnet_context *ctx, TA
1524bc
 	struct samr_SetUserInfo2 sui;
1524bc
 	union samr_UserInfo u_info;
1524bc
 	DATA_BLOB session_key;
1524bc
+	gnutls_cipher_hd_t cipher_hnd = NULL;
1524bc
+	gnutls_datum_t enc_session_key;
1524bc
+	int rc;
1524bc
 
1524bc
 	if (r->samr_handle.in.info21) {
1524bc
 		return NT_STATUS_INVALID_PARAMETER_MIX;
1524bc
@@ -404,7 +407,28 @@ static NTSTATUS libnet_SetPassword_samr_handle_24(struct libnet_context *ctx, TA
1524bc
 		return status;
1524bc
 	}
1524bc
 
1524bc
-	arcfour_crypt_blob(u_info.info24.password.data, 516, &session_key);
1524bc
+	enc_session_key = (gnutls_datum_t) {
1524bc
+		.data = session_key.data,
1524bc
+		.size = session_key.length,
1524bc
+	};
1524bc
+
1524bc
+	rc = gnutls_cipher_init(&cipher_hnd,
1524bc
+				GNUTLS_CIPHER_ARCFOUR_128,
1524bc
+				&enc_session_key,
1524bc
+				NULL);
1524bc
+	if (rc < 0) {
1524bc
+		status = gnutls_error_to_ntstatus(rc, NT_STATUS_CRYPTO_SYSTEM_INVALID);
1524bc
+		goto out;
1524bc
+	}
1524bc
+
1524bc
+	rc = gnutls_cipher_encrypt(cipher_hnd,
1524bc
+				   u_info.info24.password.data,
1524bc
+				   516);
1524bc
+	gnutls_cipher_deinit(cipher_hnd);
1524bc
+	if (rc < 0) {
1524bc
+		status = gnutls_error_to_ntstatus(rc, NT_STATUS_CRYPTO_SYSTEM_INVALID);
1524bc
+		goto out;
1524bc
+	}
1524bc
 
1524bc
 	sui.in.user_handle = r->samr_handle.in.user_handle;
1524bc
 	sui.in.info = &u_info;
1524bc
@@ -421,6 +445,9 @@ static NTSTATUS libnet_SetPassword_samr_handle_24(struct libnet_context *ctx, TA
1524bc
 					  "SetUserInfo2 level 24 for [%s] failed: %s",
1524bc
 					  r->samr_handle.in.account_name, nt_errstr(status));
1524bc
 	}
1524bc
+
1524bc
+out:
1524bc
+	data_blob_clear(&session_key);
1524bc
 	return status;
1524bc
 }
1524bc
 
1524bc
-- 
1524bc
2.23.0
1524bc