From 21b03745198420b353b72b5377c940dbaaa4f133 Mon Sep 17 00:00:00 2001 From: TalAloni Date: Tue, 26 Jan 2021 21:14:20 +0200 Subject: [PATCH] SMB2Client: Fixed InvalidCastException on failed login to SMB 3.0 server --- SMBLibrary/Client/SMB2Client.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/SMBLibrary/Client/SMB2Client.cs b/SMBLibrary/Client/SMB2Client.cs index aee5de1..cdd1af8 100644 --- a/SMBLibrary/Client/SMB2Client.cs +++ b/SMBLibrary/Client/SMB2Client.cs @@ -223,12 +223,15 @@ namespace SMBLibrary.Client if (response != null) { m_isLoggedIn = (response.Header.Status == NTStatus.STATUS_SUCCESS); - m_signingKey = SMB2Cryptography.GenerateSigningKey(m_sessionKey, m_dialect, null); - if (m_dialect == SMB2Dialect.SMB300) + if (m_isLoggedIn) { - m_encryptSessionData = (((SessionSetupResponse)response).SessionFlags & SessionFlags.EncryptData) > 0; - m_encryptionKey = SMB2Cryptography.GenerateClientEncryptionKey(m_sessionKey, SMB2Dialect.SMB300, null); - m_decryptionKey = SMB2Cryptography.GenerateClientDecryptionKey(m_sessionKey, SMB2Dialect.SMB300, null); + m_signingKey = SMB2Cryptography.GenerateSigningKey(m_sessionKey, m_dialect, null); + if (m_dialect == SMB2Dialect.SMB300) + { + m_encryptSessionData = (((SessionSetupResponse)response).SessionFlags & SessionFlags.EncryptData) > 0; + m_encryptionKey = SMB2Cryptography.GenerateClientEncryptionKey(m_sessionKey, SMB2Dialect.SMB300, null); + m_decryptionKey = SMB2Cryptography.GenerateClientDecryptionKey(m_sessionKey, SMB2Dialect.SMB300, null); + } } return response.Header.Status; }