b6b438
From 4dc911798e6e5a534c194cb2519c955a0589bf66 Mon Sep 17 00:00:00 2001
b6b438
From: Andreas Schneider <asn@samba.org>
b6b438
Date: Thu, 14 Mar 2019 10:10:34 +0100
b6b438
Subject: [PATCH 116/187] s3:smbd: Use smb2_signing_key structure for the
b6b438
 decryption key
b6b438
b6b438
Signed-off-by: Andreas Schneider <asn@samba.org>
b6b438
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
b6b438
(cherry picked from commit b51c4293f7430b5ce6a81599fb0c7be5dc444c46)
b6b438
---
b6b438
 source3/librpc/idl/smbXsrv.idl |  1 +
b6b438
 source3/smbd/smb2_server.c     |  2 +-
b6b438
 source3/smbd/smb2_sesssetup.c  | 24 +++++++++++++++++-------
b6b438
 3 files changed, 19 insertions(+), 8 deletions(-)
b6b438
b6b438
diff --git a/source3/librpc/idl/smbXsrv.idl b/source3/librpc/idl/smbXsrv.idl
b6b438
index f7acb2198fb..330c6896114 100644
b6b438
--- a/source3/librpc/idl/smbXsrv.idl
b6b438
+++ b/source3/librpc/idl/smbXsrv.idl
b6b438
@@ -231,6 +231,7 @@ interface smbXsrv
b6b438
 		[noprint] DATA_BLOB			encryption_key_blob;
b6b438
 		[ignore] smb2_signing_key		*encryption_key;
b6b438
 		[noprint] DATA_BLOB			decryption_key_blob;
b6b438
+		[ignore] smb2_signing_key		*decryption_key;
b6b438
 		[noprint] DATA_BLOB			application_key;
b6b438
 		[range(1, 1024)] uint32			num_channels;
b6b438
 		smbXsrv_channel_global0			channels[num_channels];
b6b438
diff --git a/source3/smbd/smb2_server.c b/source3/smbd/smb2_server.c
b6b438
index b708fdb90b9..56e7b70696b 100644
b6b438
--- a/source3/smbd/smb2_server.c
b6b438
+++ b/source3/smbd/smb2_server.c
b6b438
@@ -432,7 +432,7 @@ static NTSTATUS smbd_smb2_inbuf_parse_compound(struct smbXsrv_connection *xconn,
b6b438
 			tf_iov[1].iov_base = (void *)hdr;
b6b438
 			tf_iov[1].iov_len = enc_len;
b6b438
 
b6b438
-			status = smb2_signing_decrypt_pdu(s->global->decryption_key_blob,
b6b438
+			status = smb2_signing_decrypt_pdu(s->global->decryption_key->blob,
b6b438
 							  xconn->smb2.server.cipher,
b6b438
 							  tf_iov, 2);
b6b438
 			if (!NT_STATUS_IS_OK(status)) {
b6b438
diff --git a/source3/smbd/smb2_sesssetup.c b/source3/smbd/smb2_sesssetup.c
b6b438
index c2725825d7a..d6900665a95 100644
b6b438
--- a/source3/smbd/smb2_sesssetup.c
b6b438
+++ b/source3/smbd/smb2_sesssetup.c
b6b438
@@ -373,18 +373,28 @@ static NTSTATUS smbd_smb2_auth_generic_return(struct smbXsrv_session *session,
b6b438
 	if (xconn->protocol >= PROTOCOL_SMB2_24) {
b6b438
 		struct _derivation *d = &derivation.decryption;
b6b438
 
b6b438
-		x->global->decryption_key_blob = data_blob_talloc(x->global,
b6b438
-							     session_key,
b6b438
-							     sizeof(session_key));
b6b438
-		if (x->global->decryption_key_blob.data == NULL) {
b6b438
+		x->global->decryption_key =
b6b438
+			talloc_zero(x->global, struct smb2_signing_key);
b6b438
+		if (x->global->decryption_key == NULL) {
b6b438
+			ZERO_STRUCT(session_key);
b6b438
+			return NT_STATUS_NO_MEMORY;
b6b438
+		}
b6b438
+
b6b438
+		x->global->decryption_key->blob =
b6b438
+			x->global->decryption_key_blob =
b6b438
+				data_blob_talloc(x->global->decryption_key,
b6b438
+						 session_key,
b6b438
+						 sizeof(session_key));
b6b438
+		if (!smb2_signing_key_valid(x->global->decryption_key)) {
b6b438
 			ZERO_STRUCT(session_key);
b6b438
 			return NT_STATUS_NO_MEMORY;
b6b438
 		}
b6b438
+		talloc_keep_secret(x->global->decryption_key->blob.data);
b6b438
 
b6b438
 		status = smb2_key_derivation(session_key, sizeof(session_key),
b6b438
 					     d->label.data, d->label.length,
b6b438
 					     d->context.data, d->context.length,
b6b438
-					     x->global->decryption_key_blob.data);
b6b438
+					     x->global->decryption_key->blob.data);
b6b438
 		if (!NT_STATUS_IS_OK(status)) {
b6b438
 			return status;
b6b438
 		}
b6b438
@@ -484,8 +494,8 @@ static NTSTATUS smbd_smb2_auth_generic_return(struct smbXsrv_session *session,
b6b438
 		/* In server code, ServerIn is the decryption key */
b6b438
 
b6b438
 		DEBUGADD(0, ("ServerIn Key  "));
b6b438
-		dump_data(0, x->global->decryption_key_blob.data,
b6b438
-			  x->global->decryption_key_blob.length);
b6b438
+		dump_data(0, x->global->decryption_key->blob.data,
b6b438
+			  x->global->decryption_key->blob.length);
b6b438
 		DEBUGADD(0, ("ServerOut Key "));
b6b438
 		dump_data(0, x->global->encryption_key->blob.data,
b6b438
 			  x->global->encryption_key->blob.length);
b6b438
-- 
b6b438
2.23.0
b6b438