private static void EnqueueResponseChain(ConnectionState state, List <SMB2Command> responseChain) { byte[] signingKey = null; if (state is SMB2ConnectionState) { // Note: multiple sessions MAY be multiplexed on the same connection, so theoretically // we could have compounding unrelated requests from different sessions. // In practice however this is not a real problem. ulong sessionID = responseChain[0].Header.SessionID; if (sessionID != 0) { SMB2Session session = ((SMB2ConnectionState)state).GetSession(sessionID); if (session != null) { signingKey = session.SigningKey; } } } SessionMessagePacket packet = new SessionMessagePacket(); SMB2Dialect smb2Dialect = (signingKey != null) ? ToSMB2Dialect(state.Dialect) : SMB2Dialect.SMB2xx; packet.Trailer = SMB2Command.GetCommandChainBytes(responseChain, signingKey, smb2Dialect); state.SendQueue.Enqueue(packet); state.LogToServer(Severity.Verbose, "SMB2 response chain queued: Response count: {0}, First response: {1}, Packet length: {2}", responseChain.Count, responseChain[0].CommandName.ToString(), packet.Length); }