diff --git a/SMBLibrary.Tests/Program.cs b/SMBLibrary.Tests/Program.cs index b30253f..be02d4b 100644 --- a/SMBLibrary.Tests/Program.cs +++ b/SMBLibrary.Tests/Program.cs @@ -10,6 +10,7 @@ namespace SMBLibrary.Tests { new NTLMAuthenticationTests().TestAll(); new NTLMSigningTests().TestAll(); + new SMB2EncryptionTests().TestAll(); new RC4Tests().TestAll(); new NetBiosTests().TestAll(); diff --git a/SMBLibrary.Tests/SMB2EncryptionTests.cs b/SMBLibrary.Tests/SMB2EncryptionTests.cs new file mode 100644 index 0000000..ef9c428 --- /dev/null +++ b/SMBLibrary.Tests/SMB2EncryptionTests.cs @@ -0,0 +1,48 @@ +/* Copyright (C) 2020 Tal Aloni . All rights reserved. + * + * You can redistribute this program and/or modify it under the terms of + * the GNU Lesser Public License as published by the Free Software Foundation, + * either version 3 of the License, or (at your option) any later version. + */ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using SMBLibrary.SMB2; +using Utilities; + +namespace SMBLibrary.Tests +{ + [TestClass] + // https://docs.microsoft.com/en-us/archive/blogs/openspecification/encryption-in-smb-3-0-a-protocol-perspective + public class SMB2EncryptionTests + { + [TestMethod] + public void TestEncryptionKeyGeneration() + { + byte[] sessionKey = new byte[]{ 0xB4, 0x54, 0x67, 0x71, 0xB5, 0x15, 0xF7, 0x66, 0xA8, 0x67, 0x35, 0x53, 0x2D, 0xD6, 0xC4, 0xF0}; + + byte[] expectedEncryptionKey = new byte[] { 0x26, 0x1B, 0x72, 0x35, 0x05, 0x58, 0xF2, 0xE9, 0xDC, 0xF6, 0x13, 0x07, 0x03, 0x83, 0xED, 0xBF }; + + byte[] encryptionKey = SMB2Cryptography.GenerateEncryptionKey(sessionKey, SMB2Dialect.SMB300, null); + + Assert.IsTrue(ByteUtils.AreByteArraysEqual(expectedEncryptionKey, encryptionKey)); + } + + [TestMethod] + public void TestDecryptionKeyGeneration() + { + byte[] sessionKey = new byte[] { 0xB4, 0x54, 0x67, 0x71, 0xB5, 0x15, 0xF7, 0x66, 0xA8, 0x67, 0x35, 0x53, 0x2D, 0xD6, 0xC4, 0xF0 }; + + byte[] decryptionKey = SMB2Cryptography.GenerateDecryptionKey(sessionKey, SMB2Dialect.SMB300, null); + + byte[] expectedDecryptionKey = new byte[] { 0x8F, 0xE2, 0xB5, 0x7E, 0xC3, 0x4D, 0x2D, 0xB5, 0xB1, 0xA9, 0x72, 0x7F, 0x52, 0x6B, 0xBD, 0xB5 }; + + Assert.IsTrue(ByteUtils.AreByteArraysEqual(expectedDecryptionKey, decryptionKey)); + } + + public void TestAll() + { + TestEncryptionKeyGeneration(); + TestDecryptionKeyGeneration(); + } + } +} diff --git a/SMBLibrary.Tests/SMBLibrary.Tests.VS2005.csproj b/SMBLibrary.Tests/SMBLibrary.Tests.VS2005.csproj index 54c397c..dfe658a 100644 --- a/SMBLibrary.Tests/SMBLibrary.Tests.VS2005.csproj +++ b/SMBLibrary.Tests/SMBLibrary.Tests.VS2005.csproj @@ -44,6 +44,7 @@ + diff --git a/SMBLibrary.Tests/SMBLibrary.Tests.csproj b/SMBLibrary.Tests/SMBLibrary.Tests.csproj index f885fd9..6386f32 100644 --- a/SMBLibrary.Tests/SMBLibrary.Tests.csproj +++ b/SMBLibrary.Tests/SMBLibrary.Tests.csproj @@ -3,8 +3,8 @@ net40 false - SMBServer.Tests - SMBServer.Tests + SMBLibrary.Tests + SMBLibrary.Tests Exe diff --git a/SMBLibrary/Properties/AssemblyInfo.cs b/SMBLibrary/Properties/AssemblyInfo.cs index 89ec230..602ee34 100644 --- a/SMBLibrary/Properties/AssemblyInfo.cs +++ b/SMBLibrary/Properties/AssemblyInfo.cs @@ -33,3 +33,4 @@ using System.Runtime.InteropServices; // by using the '*' as shown below: [assembly: AssemblyVersion("1.4.2.0")] [assembly: AssemblyFileVersion("1.4.2.0")] +[assembly: InternalsVisibleTo("SMBLibrary.Tests")] \ No newline at end of file