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