mirror of
https://github.com/TalAloni/SMBLibrary.git
synced 2025-07-05 01:03:18 +02:00
Added tests for geneating encryption / decryption keys
This commit is contained in:
parent
70bd235395
commit
f5d727ddf2
5 changed files with 53 additions and 2 deletions
|
@ -10,6 +10,7 @@ namespace SMBLibrary.Tests
|
||||||
{
|
{
|
||||||
new NTLMAuthenticationTests().TestAll();
|
new NTLMAuthenticationTests().TestAll();
|
||||||
new NTLMSigningTests().TestAll();
|
new NTLMSigningTests().TestAll();
|
||||||
|
new SMB2EncryptionTests().TestAll();
|
||||||
new RC4Tests().TestAll();
|
new RC4Tests().TestAll();
|
||||||
|
|
||||||
new NetBiosTests().TestAll();
|
new NetBiosTests().TestAll();
|
||||||
|
|
48
SMBLibrary.Tests/SMB2EncryptionTests.cs
Normal file
48
SMBLibrary.Tests/SMB2EncryptionTests.cs
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
/* Copyright (C) 2020 Tal Aloni <tal.aloni.il@gmail.com>. 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -44,6 +44,7 @@
|
||||||
<Compile Include="Program.cs" />
|
<Compile Include="Program.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="RPCTests.cs" />
|
<Compile Include="RPCTests.cs" />
|
||||||
|
<Compile Include="SMB2EncryptionTests.cs" />
|
||||||
<Compile Include="SMB2SigningTests.cs" />
|
<Compile Include="SMB2SigningTests.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
@ -3,8 +3,8 @@
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFrameworks>net40</TargetFrameworks>
|
<TargetFrameworks>net40</TargetFrameworks>
|
||||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||||
<AssemblyName>SMBServer.Tests</AssemblyName>
|
<AssemblyName>SMBLibrary.Tests</AssemblyName>
|
||||||
<RootNamespace>SMBServer.Tests</RootNamespace>
|
<RootNamespace>SMBLibrary.Tests</RootNamespace>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
|
|
@ -33,3 +33,4 @@ using System.Runtime.InteropServices;
|
||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
[assembly: AssemblyVersion("1.4.2.0")]
|
[assembly: AssemblyVersion("1.4.2.0")]
|
||||||
[assembly: AssemblyFileVersion("1.4.2.0")]
|
[assembly: AssemblyFileVersion("1.4.2.0")]
|
||||||
|
[assembly: InternalsVisibleTo("SMBLibrary.Tests")]
|
Loading…
Add table
Add a link
Reference in a new issue